32 #include <QApplication> 33 #include <QDesktopWidget> 36 #include <QDesktopWidget> 44 QPoint
FitRectScreen (QPoint
pos,
const QSize& size, FitFlags flags,
const QPoint& shiftAdd)
46 return FitRect (pos, size, QApplication::desktop ()->screenGeometry (pos), flags, shiftAdd);
49 QPoint
FitRect (QPoint
pos,
const QSize& size,
const QRect& geometry,
50 FitFlags flags,
const QPoint& shiftAdd)
52 int xDiff = std::max (0, pos.x () + size.width () - (geometry.width () + geometry.x ()));
54 xDiff = std::min (0, pos.x () - geometry.x ());
55 int yDiff = std::max (0, pos.y () + size.height () - (geometry.height () + geometry.y ()));
57 yDiff = std::min (0, pos.y () - geometry.y ());
61 auto overlapFixer = [] (
int& diff,
int dim)
64 diff = dim > diff ? dim : diff;
67 if (QRect (pos - QPoint (xDiff, yDiff), size).contains (pos) && yDiff < size.height ())
68 overlapFixer (yDiff, size.height ());
69 if (QRect (pos - QPoint (xDiff, yDiff), size).contains (pos) && xDiff < size.width ())
70 overlapFixer (xDiff, size.width ());
74 pos.rx () -= xDiff + shiftAdd.x ();
76 pos.ry () -= yDiff + shiftAdd.y ();
83 class AADisplayEventFilter :
public QObject
87 AADisplayEventFilter (QWidget *display)
93 bool eventFilter (QObject*, QEvent *event)
95 bool shouldClose =
false;
96 switch (event->type ())
98 case QEvent::KeyRelease:
99 shouldClose =
static_cast<QKeyEvent*
> (event)->key () == Qt::Key_Escape;
101 case QEvent::MouseButtonRelease:
111 QTimer::singleShot (0,
121 const auto& availGeom = QApplication::desktop ()->availableGeometry (pos).size () * 0.9;
124 if (px.size ().width () > availGeom.width () ||
125 px.size ().height () > availGeom.height ())
126 px = px.scaled (availGeom, Qt::KeepAspectRatio, Qt::SmoothTransformation);
128 auto label =
new QLabel;
129 label->setWindowFlags (Qt::Tool);
130 label->setAttribute (Qt::WA_DeleteOnClose);
131 label->setFixedSize (px.size ());
132 label->setPixmap (px);
134 label->activateWindow ();
135 label->installEventFilter (
new AADisplayEventFilter (label));
140 QColor
TintColors (
const QColor& c1,
const QColor& c2,
double alpha)
143 color.setRedF (alpha * c1.redF () + (1 - alpha) * c2.redF ());
144 color.setGreenF (alpha * c1.greenF () + (1 - alpha) * c2.greenF ());
145 color.setBlueF (alpha * c1.blueF () + (1 - alpha) * c2.blueF ());
151 auto palette = widget->palette ();
152 for (
auto role : roles)
153 palette.setColor (role,
TintColors (palette.color (role), color, alpha));
154 widget->setPalette (palette);
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
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.
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.