11 #include <QApplication>
12 #include <QDesktopWidget>
17 #include <QStyleOptionViewItem>
25 class AADisplayEventFilter :
public QObject
27 QWidget *
const Display_;
29 explicit AADisplayEventFilter (QWidget *display)
35 bool eventFilter (QObject*, QEvent *event)
override
37 bool shouldClose =
false;
38 switch (event->type ())
40 case QEvent::KeyRelease:
41 shouldClose =
static_cast<QKeyEvent*
> (event)->key () == Qt::Key_Escape;
43 case QEvent::MouseButtonRelease:
53 QTimer::singleShot (0,
63 const auto scaleFactor = 0.9;
67 if (px.size ().width () > availGeom.width () ||
68 px.size ().height () > availGeom.height ())
69 px = px.scaled (availGeom, Qt::KeepAspectRatio, Qt::SmoothTransformation);
71 const auto label =
new QLabel;
72 label->setWindowFlags (Qt::Tool);
73 label->setAttribute (Qt::WA_DeleteOnClose);
74 label->setFixedSize (px.size ());
75 label->setPixmap (px);
77 label->activateWindow ();
78 label->installEventFilter (
new AADisplayEventFilter (label));
83 QColor
TintColors (
const QColor& c1,
const QColor& c2,
double alpha)
86 color.setRedF (alpha * c1.redF () + (1 - alpha) * c2.redF ());
87 color.setGreenF (alpha * c1.greenF () + (1 - alpha) * c2.greenF ());
88 color.setBlueF (alpha * c1.blueF () + (1 - alpha) * c2.blueF ());
94 return option.fontMetrics.elidedText (text, Qt::ElideRight, option.rect.width ());
99 auto palette = widget->palette ();
100 for (
auto role : roles)
101 palette.setColor (role,
TintColors (palette.color (role), color, alpha));
102 widget->setPalette (palette);
107 return "<em>" + name +
"</em>";
111 const QString& text, QFont font,
const QPen& pen,
const QBrush& brush)
113 const auto& iconSize = px.size () / px.devicePixelRatio ();
115 const auto fontHeight = iconSize.height () * 0.45;
116 const auto minFontHeight = 6.0;
117 font.setPixelSize (
static_cast<int> (
std::max (minFontHeight, fontHeight)));
119 const QFontMetrics fm (font);
120 const auto width = fm.horizontalAdvance (text) + 2. * iconSize.width () / 10.;
121 const auto height = fm.height () + 2. * iconSize.height () / 10.;
122 const bool tooSmall = width > iconSize.width ();
124 const QRectF textRect (iconSize.width () - width, iconSize.height () - height, width, height);
130 p.setRenderHint (QPainter::Antialiasing);
131 p.setRenderHint (QPainter::TextAntialiasing);
132 p.drawRoundedRect (textRect, 4, 4);
133 p.drawText (textRect,
135 tooSmall ? QStringLiteral (
"#") : text);