32 #include <QApplication> 33 #include <QDesktopWidget> 36 #include <QDesktopWidget> 38 #include <QStyleOptionViewItem> 45 QPoint
FitRectScreen (QPoint
pos,
const QSize& size, FitFlags flags,
const QPoint& shiftAdd)
47 return FitRect (
pos, size, QApplication::desktop ()->screenGeometry (
pos), flags, shiftAdd);
50 QPoint
FitRect (QPoint
pos,
const QSize& size,
const QRect& geometry,
51 FitFlags flags,
const QPoint& shiftAdd)
53 int xDiff = std::max (0,
pos.x () + size.width () - (geometry.width () + geometry.x ()));
55 xDiff = std::min (0,
pos.x () - geometry.x ());
56 int yDiff = std::max (0,
pos.y () + size.height () - (geometry.height () + geometry.y ()));
58 yDiff = std::min (0,
pos.y () - geometry.y ());
62 auto overlapFixer = [] (
int& diff,
int dim)
65 diff = dim > diff ? dim : diff;
68 if (QRect (
pos - QPoint (xDiff, yDiff), size).contains (
pos) && yDiff < size.height ())
69 overlapFixer (yDiff, size.height ());
70 if (QRect (
pos - QPoint (xDiff, yDiff), size).contains (
pos) && xDiff < size.width ())
71 overlapFixer (xDiff, size.width ());
75 pos.rx () -= xDiff + shiftAdd.x ();
77 pos.ry () -= yDiff + shiftAdd.y ();
84 class AADisplayEventFilter :
public QObject
88 AADisplayEventFilter (QWidget *display)
94 bool eventFilter (QObject*, QEvent *event)
96 bool shouldClose =
false;
97 switch (event->type ())
99 case QEvent::KeyRelease:
100 shouldClose =
static_cast<QKeyEvent*
> (event)->key () == Qt::Key_Escape;
102 case QEvent::MouseButtonRelease:
112 QTimer::singleShot (0,
122 const auto& availGeom = QApplication::desktop ()->availableGeometry (
pos).size () * 0.9;
125 if (px.size ().width () > availGeom.width () ||
126 px.size ().height () > availGeom.height ())
127 px = px.scaled (availGeom, Qt::KeepAspectRatio, Qt::SmoothTransformation);
129 auto label =
new QLabel;
130 label->setWindowFlags (Qt::Tool);
131 label->setAttribute (Qt::WA_DeleteOnClose);
132 label->setFixedSize (px.size ());
133 label->setPixmap (px);
135 label->activateWindow ();
136 label->installEventFilter (
new AADisplayEventFilter (label));
141 QColor
TintColors (
const QColor& c1,
const QColor& c2,
double alpha)
144 color.setRedF (alpha * c1.redF () + (1 - alpha) * c2.redF ());
145 color.setGreenF (alpha * c1.greenF () + (1 - alpha) * c2.greenF ());
146 color.setBlueF (alpha * c1.blueF () + (1 - alpha) * c2.blueF ());
152 return option.fontMetrics.elidedText (text, Qt::ElideRight, option.rect.width ());
157 auto palette = widget->palette ();
158 for (
auto role : roles)
159 palette.setColor (role,
TintColors (palette.color (role), color, alpha));
160 widget->setPalette (palette);
165 return "<em>" + name +
"</em>";
QLabel * ShowPixmapLabel(const QPixmap &srcPx, const QPoint &pos)
Shows a pixmap at the given pos.
detail::ExprTree< detail::ExprType::LeafStaticPlaceholder, boost::mpl::int_< Idx > > pos
QString ElideProgressBarText(const QString &text, const QStyleOptionViewItem &option)
QPoint FitRectScreen(QPoint pos, const QSize &size, FitFlags flags, const QPoint &shiftAdd)
Tries to fit a rectangle (like a dialog or popup) into screen.
QColor TintColors(const QColor &c1, const QColor &c2, double alpha)
Mixes two colors with the given weights.
QString FormatName(const QString &name)
HTML-formats the name to let the user know it is not a part of the fixed dialog text.
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.
QPoint FitRect(QPoint pos, const QSize &size, const QRect &geometry, FitFlags flags, const QPoint &shiftAdd)
Tries to fit a rectangle (like a dialog or popup) into geometry.