26#include <QTemporaryFile>
36 : QLabel(parent), pEnableToolTipPreview(true), mToolTipFile(NULL)
41 setAlignment(Qt::AlignCenter);
46 pDefaultPalette = palette();
47 pErrorPalette = pDefaultPalette;
49 pDefaultPalette.setColor(QPalette::Window,
QColor(255, 255, 255, 0));
50 pErrorPalette.setColor(QPalette::Window,
QColor(255, 0, 0, 60));
53 pGEcolor =
QColor(128, 255, 128, 8);
76 pLabelEnabled =
false;
83 pDisplayImage = displayimg;
84 pDisplayTooltip = tooltipimage;
86 pLabelEnabled = labelenabled;
92 pDisplayError = errorMessage;
94 pLabelEnabled = labelenabled;
99QPicture KLFDisplayLabel::calc_display_picture()
103 double dpr = devicePixelRatioF();
105 QImage img = pDisplayImage;
108 klfDbg(
"widget size()="<<size()<<
", mysize="<<mysize) ;
110 int r = pGEradius * dpr;
113 img = pDisplayImage.
scaled(mysize-msz, Qt::KeepAspectRatio, Qt::SmoothTransformation);
117 painter.translate(
QPoint(r, r));
121 img = pDisplayImage.
scaled(mysize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
129 QPainter pp(&labelpic);
130 if (!pLabelEnabled) {
133 QSize pixsizeuser = (QSizeF(pix.
size())/dpr).toSize();
134 pp.drawPixmap(QRect(QPoint((width()-pixsizeuser.
width())/2, (height()-pixsizeuser.
height())/2),
143void KLFDisplayLabel::display_state(DisplayState state)
146 pDisplayState = state;
147 if (state ==
Clear) {
148 setPicture(QPicture());
152 if (state ==
Error) {
154 setToolTip(pDisplayError);
155 _bigPreviewText = pDisplayError;
158 QPicture labelpic = calc_display_picture();
159 setPicture(labelpic);
169 _bigPreviewText =
"";
172 if ( ! pDisplayTooltip.isNull() ) {
174 mToolTipFile =
new QTemporaryFile(tempdir+
"/klf_tooltip_XXXXXX.png",
this);
175 if ( ! mToolTipFile->open() ) {
176 qWarning(
"WARNING: Failed open for ToolTip Temp Image!\n%s\n",
177 qPrintable(mToolTipFile->fileTemplate()));
181 mToolTipFile->setAutoRemove(
true);
182 bool res = pDisplayTooltip.save(mToolTipFile,
"PNG");
184 QMessageBox::critical(
this, tr(
"Error"), tr(
"Failed write to ToolTip Temp Image file %1!")
185 .arg(mToolTipFile->fileName()));
186 qWarning(
"WARNING: Failed write to Tooltip temp image to temporary file `%s' !\n",
187 qPrintable(mToolTipFile->fileTemplate()));
191 _bigPreviewText = QString(
"<img src=\"%1\" width=\"%2\" height=\"%3\" style=\"width:%2px; height:%3px;\">")
192 .arg(mToolTipFile->fileName())
193 .arg((
int)(pDisplayTooltip.width() / devicePixelRatioF()))
194 .arg((
int)(pDisplayTooltip.height() / devicePixelRatioF()));
195 klfDbg(
"big preview html = " << _bigPreviewText) ;
199 if (pEnableToolTipPreview) {
200 setToolTip(QString(
"<p style=\"padding: 8px 8px 8px 8px;\">%1</p>").arg(_bigPreviewText));
202 setToolTip(QString(
""));
207void KLFDisplayLabel::set_error(
bool error_on)
210 setProperty(
"realTimeLatexError", QVariant(error_on));
215 p = &pDefaultPalette;
217 setAutoFillBackground(
true);
218 setStyleSheet(styleSheet());
virtual void displayClear()
virtual ~KLFDisplayLabel()
virtual void displayError(bool labelenabled=false)
virtual void display(QImage displayimg, QImage tooltipimage, bool labelenabled=true)
KLFDisplayLabel(QWidget *parent)
virtual void mouseMoveEvent(QMouseEvent *e)
#define KLF_DEBUG_BLOCK(msg)
Utility to debug the execution of a block.
#define klfDbg(streamableItems)
print debug stream items
KLF_EXPORT void klfDrawGlowedImage(QPainter *p, const QImage &foreground, const QColor &glowcol, int r, bool also_draw_image)
Draws the given image with a glow effect.
QImage scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const
void setBoundingRect(const QRect &r)
void fill(const QColor &color)
QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags)
void setDevicePixelRatio(qreal scaleFactor)