mirror of https://github.com/KLayout/klayout.git
[consider merging] Fixed rendering of color selector buttons on high-DPI screens
This commit is contained in:
parent
7634c77c23
commit
7a91a4fd42
|
|
@ -972,17 +972,31 @@ SimpleColorButton::set_color_internal (QColor c)
|
||||||
m_color = c;
|
m_color = c;
|
||||||
|
|
||||||
QFontMetrics fm (font (), this);
|
QFontMetrics fm (font (), this);
|
||||||
QRect rt (fm.boundingRect (QObject::tr ("Auto"))); // dummy text to be compliant with the other color button
|
QRect rt (fm.boundingRect (QObject::tr ("XXXXXXX")));
|
||||||
QPixmap pxmp (rt.width () + 24, rt.height ());
|
|
||||||
|
#if QT_VERSION >= 0x050000
|
||||||
|
double dpr = devicePixelRatio ();
|
||||||
|
#else
|
||||||
|
double dpr = 1.0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QPixmap pxmp (rt.width () * dpr, rt.height () * dpr);
|
||||||
|
#if QT_VERSION >= 0x050000
|
||||||
|
pxmp.setDevicePixelRatio (dpr);
|
||||||
|
#endif
|
||||||
|
|
||||||
QPainter pxpainter (&pxmp);
|
QPainter pxpainter (&pxmp);
|
||||||
QColor text_color = palette ().color (QPalette::Active, QPalette::Text);
|
QColor text_color = palette ().color (QPalette::Active, QPalette::Text);
|
||||||
pxpainter.setPen (QPen (text_color));
|
|
||||||
pxpainter.setBrush (QBrush (c.isValid () ? c : QColor (128, 128, 128)));
|
pxpainter.setBrush (QBrush (c.isValid () ? c : QColor (128, 128, 128)));
|
||||||
QRect r (0, 0, pxmp.width () - 1, pxmp.height () - 1);
|
QPen frame_pen (text_color);
|
||||||
|
frame_pen.setWidthF (1.0);
|
||||||
|
frame_pen.setJoinStyle (Qt::MiterJoin);
|
||||||
|
pxpainter.setPen (frame_pen);
|
||||||
|
int dpri = int (dpr);
|
||||||
|
QRectF r ((dpri / 2) / dpr, (dpri / 2) / dpr, rt.width () - 1.0, rt.height () - 1.0);
|
||||||
pxpainter.drawRect (r);
|
pxpainter.drawRect (r);
|
||||||
|
|
||||||
setIconSize (pxmp.size ());
|
setIconSize (QSize (rt.width (), rt.height ()));
|
||||||
setIcon (QIcon (pxmp));
|
setIcon (QIcon (pxmp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1216,22 +1230,25 @@ ColorButton::set_color_internal (QColor c)
|
||||||
#if QT_VERSION >= 0x50000
|
#if QT_VERSION >= 0x50000
|
||||||
pixmap.setDevicePixelRatio (dpr);
|
pixmap.setDevicePixelRatio (dpr);
|
||||||
#endif
|
#endif
|
||||||
pixmap.fill (QColor (0, 0, 0, 0));
|
|
||||||
|
|
||||||
QColor text_color = palette ().color (QPalette::Active, QPalette::Text);
|
QColor text_color = palette ().color (QPalette::Active, QPalette::Text);
|
||||||
QPainter pxpainter (&pixmap);
|
QPainter pxpainter (&pixmap);
|
||||||
pxpainter.setPen (QPen (text_color));
|
QPen frame_pen (text_color);
|
||||||
|
frame_pen.setWidthF (1.0);
|
||||||
|
frame_pen.setJoinStyle (Qt::MiterJoin);
|
||||||
|
pxpainter.setPen (frame_pen);
|
||||||
|
|
||||||
|
int dpri = int (dpr);
|
||||||
|
QRectF r ((dpri / 2) / dpr, (dpri / 2) / dpr, rt.width () - 1.0, rt.height () - 1.0);
|
||||||
|
|
||||||
if (! m_color.isValid ()) {
|
if (! m_color.isValid ()) {
|
||||||
|
|
||||||
pxpainter.setFont (font ());
|
pxpainter.setFont (font ());
|
||||||
QRectF r (0, 0, rt.width () - pxpainter.pen ().widthF (), rt.height () - pxpainter.pen ().widthF ());
|
|
||||||
pxpainter.drawText (r, Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine, QObject::tr ("Auto"));
|
pxpainter.drawText (r, Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine, QObject::tr ("Auto"));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
pxpainter.setBrush (QBrush (c));
|
pxpainter.setBrush (QBrush (c));
|
||||||
QRectF r (0, 0, rt.width () - pxpainter.pen ().widthF (), rt.height () - pxpainter.pen ().widthF ());
|
|
||||||
pxpainter.drawRect (r);
|
pxpainter.drawRect (r);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue