26 #include <QTemporaryFile> 27 #include <QMessageBox> 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));
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;
99 QPicture 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);
121 img = pDisplayImage.
scaled(mysize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
130 if (!pLabelEnabled) {
146 pDisplayState = state;
147 if (state ==
Clear) {
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",
182 bool res = pDisplayTooltip.
save(mToolTipFile,
"PNG");
184 QMessageBox::critical(
this, tr(
"Error"), tr(
"Failed write to ToolTip Temp Image file %1!")
186 qWarning(
"WARNING: Failed write to Tooltip temp image to temporary file `%s' !\n",
191 _bigPreviewText =
QString(
"<img src=\"%1\" width=\"%2\" height=\"%3\" style=\"width:%2px; height:%3px;\">")
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));
207 void KLFDisplayLabel::set_error(
bool error_on)
210 setProperty(
"realTimeLatexError",
QVariant(error_on));
215 p = &pDefaultPalette;
217 setAutoFillBackground(
true);
218 setStyleSheet(styleSheet());
void setOpacity(qreal opacity)
void fill(const QColor &color)
void setColor(ColorGroup group, ColorRole role, const QColor &color)
bool save(const QString &fileName, const char *format, int quality) const
#define klfDbg(streamableItems)
print debug stream items
QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags)
#define KLF_DEBUG_BLOCK(msg)
Utility to debug the execution of a block.
virtual void displayClear()
void setBoundingRect(const QRect &r)
void setAutoRemove(bool b)
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
KLFDisplayLabel(QWidget *parent)
virtual QString fileName() const
virtual void displayError(bool labelenabled=false)
virtual ~KLFDisplayLabel()
void translate(const QPointF &offset)
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.
virtual void mouseMoveEvent(QMouseEvent *e)
virtual void display(QImage displayimg, QImage tooltipimage, bool labelenabled=true)
QString fileTemplate() const
void setDevicePixelRatio(qreal scaleFactor)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const
QImage scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const