32 #include <QApplication> 33 #include <QDesktopWidget> 37 #include <QStyleOptionViewItem> 47 class AADisplayEventFilter :
public QObject
51 explicit AADisplayEventFilter (QWidget *display)
57 bool eventFilter (QObject*, QEvent *event)
override 59 bool shouldClose =
false;
60 switch (event->type ())
62 case QEvent::KeyRelease:
63 shouldClose =
static_cast<QKeyEvent*
> (event)->key () == Qt::Key_Escape;
65 case QEvent::MouseButtonRelease:
75 QTimer::singleShot (0,
88 if (px.size ().width () > availGeom.width () ||
89 px.size ().height () > availGeom.height ())
90 px = px.scaled (availGeom, Qt::KeepAspectRatio, Qt::SmoothTransformation);
92 auto label =
new QLabel;
93 label->setWindowFlags (Qt::Tool);
94 label->setAttribute (Qt::WA_DeleteOnClose);
95 label->setFixedSize (px.size ());
96 label->setPixmap (px);
98 label->activateWindow ();
99 label->installEventFilter (
new AADisplayEventFilter (label));
104 QColor
TintColors (
const QColor& c1,
const QColor& c2,
double alpha)
107 color.setRedF (alpha * c1.redF () + (1 - alpha) * c2.redF ());
108 color.setGreenF (alpha * c1.greenF () + (1 - alpha) * c2.greenF ());
109 color.setBlueF (alpha * c1.blueF () + (1 - alpha) * c2.blueF ());
115 return option.fontMetrics.elidedText (text, Qt::ElideRight, option.rect.width ());
120 auto palette = widget->palette ();
121 for (
auto role : roles)
122 palette.setColor (role,
TintColors (palette.color (role), color, alpha));
123 widget->setPalette (palette);
128 return "<em>" + name +
"</em>";
QString FormatName(const QString &name)
HTML-formats the name to let the user know it is not a part of the fixed dialog text.
QString ElideProgressBarText(const QString &text, const QStyleOptionViewItem &option)
QRect AvailableGeometry(const QPoint &p)
void TintPalette(QWidget *widget, const QColor &color, double alpha, const QList< QPalette::ColorRole > &roles)
Mixes some of the widget's palette roles with the given color.
QColor TintColors(const QColor &c1, const QColor &c2, double alpha)
Mixes two colors with the given weights.
QLabel * ShowPixmapLabel(const QPixmap &srcPx, const QPoint &pos)
Shows a pixmap at the given pos.