aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-11-02 11:39:31 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-11-02 14:55:26 +0100
commit7ba3e74e3a3f87b6eb2e1742bfe0c9a1f28320cb (patch)
tree50d9eff22c0bc1a46c62e18e87d9b738b25ebf12
parent4e10a6769fdcaa711dac34dd5dd326c83a27c6bd (diff)
Fix deprecation warnings related to QIcon::pixmap()
Change-Id: I5eb7441ce557773e5253d3ce623be637819bab0d Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/imports/nativestyle/qstyle/qquickcommonstyle.cpp64
1 files changed, 37 insertions, 27 deletions
diff --git a/src/imports/nativestyle/qstyle/qquickcommonstyle.cpp b/src/imports/nativestyle/qstyle/qquickcommonstyle.cpp
index 45f23f05..d3ad39fc 100644
--- a/src/imports/nativestyle/qstyle/qquickcommonstyle.cpp
+++ b/src/imports/nativestyle/qstyle/qquickcommonstyle.cpp
@@ -69,6 +69,11 @@
QT_BEGIN_NAMESPACE
+static inline qreal dpr(const QWindow *w)
+{
+ return w != nullptr ? w->devicePixelRatio() : qApp->devicePixelRatio();
+}
+
/*!
\class QCommonStyle
\brief The QCommonStyle class encapsulates the common Look and Feel of a GUI.
@@ -358,7 +363,7 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q
mode = QIcon::Disabled;
QIcon::State state = opt->state & State_Sunken ? QIcon::On : QIcon::Off;
- QPixmap pixmap = d->tabBarcloseButtonIcon.pixmap(opt->window, QSize(size, size), mode, state);
+ QPixmap pixmap = d->tabBarcloseButtonIcon.pixmap(QSize(size, size), dpr(opt->window), mode, state);
proxy()->drawItemPixmap(p, opt->rect, Qt::AlignCenter, pixmap);
break;
}
@@ -1216,7 +1221,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
if (button->state & State_On)
state = QIcon::On;
- QPixmap pixmap = button->icon.pixmap(opt->window, button->iconSize, mode, state);
+ QPixmap pixmap = button->icon.pixmap(button->iconSize, dpr(opt->window), mode, state);
int pixmapWidth = pixmap.width() / pixmap.devicePixelRatio();
int pixmapHeight = pixmap.height() / pixmap.devicePixelRatio();
int labelWidth = pixmapWidth;
@@ -1294,7 +1299,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
QPixmap pix;
QRect textRect = btn->rect;
if (!btn->icon.isNull()) {
- pix = btn->icon.pixmap(opt->window, btn->iconSize, btn->state & State_Enabled ? QIcon::Normal : QIcon::Disabled);
+ pix = btn->icon.pixmap(btn->iconSize, dpr(opt->window), btn->state & State_Enabled ? QIcon::Normal : QIcon::Disabled);
proxy()->drawItemPixmap(p, btn->rect, alignment, pix);
if (btn->direction == Qt::RightToLeft)
textRect.setRight(textRect.right() - btn->iconSize.width() - 4);
@@ -1332,7 +1337,8 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
if (!proxy()->styleHint(SH_UnderlineShortcut, mbi))
alignment |= Qt::TextHideMnemonic;
int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
- QPixmap pix = mbi->icon.pixmap(opt->window, QSize(iconExtent, iconExtent), (mbi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
+ QPixmap pix = mbi->icon.pixmap(QSize(iconExtent, iconExtent), dpr(opt->window),
+ mbi->state.testFlag(State_Enabled) ? QIcon::Normal : QIcon::Disabled);
if (!pix.isNull())
proxy()->drawItemPixmap(p,mbi->rect, alignment, pix);
else
@@ -1470,7 +1476,8 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
if (!header->icon.isNull()) {
int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
QPixmap pixmap
- = header->icon.pixmap(opt->window, QSize(iconExtent, iconExtent), (header->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
+ = header->icon.pixmap(QSize(iconExtent, iconExtent), dpr(opt->window),
+ header->state.testFlag(State_Enabled) ? QIcon::Normal : QIcon::Disabled);
int pixw = pixmap.width() / pixmap.devicePixelRatio();
QRect aligned = alignedRect(header->direction, QFlag(header->iconAlignment), pixmap.size() / pixmap.devicePixelRatio(), rect);
@@ -1529,7 +1536,8 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
mode = QIcon::Active;
else
mode = QIcon::Normal;
- pm = toolbutton->icon.pixmap(opt->window, toolbutton->rect.size().boundedTo(toolbutton->iconSize), mode, state);
+ pm = toolbutton->icon.pixmap(toolbutton->rect.size().boundedTo(toolbutton->iconSize),
+ dpr(opt->window), mode, state);
pmSize = pm.size() / pm.devicePixelRatio();
}
@@ -1744,7 +1752,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
bool enabled = tb->state & State_Enabled;
bool selected = tb->state & State_Selected;
int iconExtent = proxy()->pixelMetric(QStyle::PM_SmallIconSize, tb);
- QPixmap pm = tb->icon.pixmap(opt->window, QSize(iconExtent, iconExtent),
+ QPixmap pm = tb->icon.pixmap(QSize(iconExtent, iconExtent), dpr(opt->window),
enabled ? QIcon::Normal : QIcon::Disabled);
QRect cr = subElementRect(QStyle::SE_ToolBoxTabContents, tb);
@@ -1818,7 +1826,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
tr = proxy()->subElementRect(SE_TabBarTabText, opt); //we compute tr twice because the style may override subElementRect
if (!tab->icon.isNull()) {
- QPixmap tabIcon = tab->icon.pixmap(opt->window, tab->iconSize,
+ QPixmap tabIcon = tab->icon.pixmap(tab->iconSize, dpr(opt->window),
(tab->state & State_Enabled) ? QIcon::Normal
: QIcon::Disabled,
(tab->state & State_Selected) ? QIcon::On
@@ -2010,7 +2018,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
if (!cb->currentIcon.isNull()) {
QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
: QIcon::Disabled;
- QPixmap pixmap = cb->currentIcon.pixmap(opt->window, cb->iconSize, mode);
+ QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, dpr(opt->window), mode);
QRect iconRect(editRect);
iconRect.setWidth(cb->iconSize.width() + 4);
iconRect = alignedRect(cb->direction,
@@ -2285,7 +2293,7 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt) const
if (!btn->icon.isNull()) {
iconRect = itemPixmapRect(cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter
| Qt::TextShowMnemonic,
- btn->icon.pixmap(opt->window, btn->iconSize, QIcon::Normal));
+ btn->icon.pixmap(btn->iconSize, dpr(opt->window), QIcon::Normal));
if (!textRect.isEmpty())
textRect.translate(iconRect.right() + 4, 0);
}
@@ -2332,7 +2340,7 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt) const
}
if (!btn->icon.isNull()) {
iconRect = itemPixmapRect(cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic,
- btn->icon.pixmap(opt->window, btn->iconSize, QIcon::Normal));
+ btn->icon.pixmap(btn->iconSize, dpr(opt->window), QIcon::Normal));
if (!textRect.isEmpty())
textRect.translate(iconRect.right() + 4, 0);
}
@@ -3261,9 +3269,9 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl
ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarCloseButton);
down = tb->activeSubControls & SC_TitleBarCloseButton && (opt->state & State_Sunken);
if ((tb->titleBarFlags & Qt::WindowType_Mask) == Qt::Tool)
- pm = proxy()->standardIcon(SP_DockWidgetCloseButton, &tool).pixmap(opt->window, QSize(10, 10));
+ pm = proxy()->standardIcon(SP_DockWidgetCloseButton, &tool).pixmap(QSize(10, 10), dpr(opt->window));
else
- pm = proxy()->standardIcon(SP_TitleBarCloseButton, &tool).pixmap(opt->window, QSize(10, 10));
+ pm = proxy()->standardIcon(SP_TitleBarCloseButton, &tool).pixmap(QSize(10, 10), dpr(opt->window));
tool.rect = ir;
tool.state = down ? State_Sunken : State_Raised;
proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p);
@@ -3282,7 +3290,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl
ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarMaxButton);
down = tb->activeSubControls & SC_TitleBarMaxButton && (opt->state & State_Sunken);
- pm = proxy()->standardIcon(SP_TitleBarMaxButton, &tool).pixmap(opt->window, QSize(10, 10));
+ pm = proxy()->standardIcon(SP_TitleBarMaxButton, &tool).pixmap(QSize(10, 10), dpr(opt->window));
tool.rect = ir;
tool.state = down ? State_Sunken : State_Raised;
proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p);
@@ -3300,7 +3308,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl
&& !(tb->titleBarState & Qt::WindowMinimized)) {
ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarMinButton);
down = tb->activeSubControls & SC_TitleBarMinButton && (opt->state & State_Sunken);
- pm = proxy()->standardIcon(SP_TitleBarMinButton, &tool).pixmap(opt->window, QSize(10, 10));
+ pm = proxy()->standardIcon(SP_TitleBarMinButton, &tool).pixmap(QSize(10, 10), dpr(opt->window));
tool.rect = ir;
tool.state = down ? State_Sunken : State_Raised;
proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p);
@@ -3322,7 +3330,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl
if (drawNormalButton) {
ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarNormalButton);
down = tb->activeSubControls & SC_TitleBarNormalButton && (opt->state & State_Sunken);
- pm = proxy()->standardIcon(SP_TitleBarNormalButton, &tool).pixmap(opt->window, QSize(10, 10));
+ pm = proxy()->standardIcon(SP_TitleBarNormalButton, &tool).pixmap(QSize(10, 10), dpr(opt->window));
tool.rect = ir;
tool.state = down ? State_Sunken : State_Raised;
proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p);
@@ -3340,7 +3348,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl
&& !(tb->titleBarState & Qt::WindowMinimized)) {
ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarShadeButton);
down = (tb->activeSubControls & SC_TitleBarShadeButton && (opt->state & State_Sunken));
- pm = proxy()->standardIcon(SP_TitleBarShadeButton, &tool).pixmap(opt->window, QSize(10, 10));
+ pm = proxy()->standardIcon(SP_TitleBarShadeButton, &tool).pixmap(QSize(10, 10), dpr(opt->window));
tool.rect = ir;
tool.state = down ? State_Sunken : State_Raised;
proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p);
@@ -3358,7 +3366,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl
ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarUnshadeButton);
down = tb->activeSubControls & SC_TitleBarUnshadeButton && (opt->state & State_Sunken);
- pm = proxy()->standardIcon(SP_TitleBarUnshadeButton, &tool).pixmap(opt->window, QSize(10, 10));
+ pm = proxy()->standardIcon(SP_TitleBarUnshadeButton, &tool).pixmap(QSize(10, 10), dpr(opt->window));
tool.rect = ir;
tool.state = down ? State_Sunken : State_Raised;
proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p);
@@ -3374,7 +3382,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl
ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarContextHelpButton);
down = tb->activeSubControls & SC_TitleBarContextHelpButton && (opt->state & State_Sunken);
- pm = proxy()->standardIcon(SP_TitleBarContextHelpButton, &tool).pixmap(opt->window, QSize(10, 10));
+ pm = proxy()->standardIcon(SP_TitleBarContextHelpButton, &tool).pixmap(QSize(10, 10), dpr(opt->window));
tool.rect = ir;
tool.state = down ? State_Sunken : State_Raised;
proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p);
@@ -3391,7 +3399,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl
tb->icon.paint(p, ir);
} else {
int iconSize = proxy()->pixelMetric(PM_SmallIconSize, tb);
- pm = proxy()->standardIcon(SP_TitleBarMenuButton, &tool).pixmap(opt->window, QSize(iconSize, iconSize));
+ pm = proxy()->standardIcon(SP_TitleBarMenuButton, &tool).pixmap(QSize(iconSize, iconSize), dpr(opt->window));
tool.rect = ir;
p->save();
proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
@@ -3574,7 +3582,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl
}
btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiCloseButton);
proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p);
- QPixmap pm = proxy()->standardIcon(SP_TitleBarCloseButton).pixmap(opt->window, buttonIconSize);
+ QPixmap pm = proxy()->standardIcon(SP_TitleBarCloseButton).pixmap(buttonIconSize, dpr(opt->window));
proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm);
}
if (opt->subControls & QStyle::SC_MdiNormalButton) {
@@ -3591,7 +3599,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl
}
btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiNormalButton);
proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p);
- QPixmap pm = proxy()->standardIcon(SP_TitleBarNormalButton).pixmap(opt->window, buttonIconSize);
+ QPixmap pm = proxy()->standardIcon(SP_TitleBarNormalButton).pixmap(buttonIconSize, dpr(opt->window));
proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm);
}
if (opt->subControls & QStyle::SC_MdiMinButton) {
@@ -3608,7 +3616,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl
}
btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiMinButton);
proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p);
- QPixmap pm = proxy()->standardIcon(SP_TitleBarMinButton).pixmap(opt->window, buttonIconSize);
+ QPixmap pm = proxy()->standardIcon(SP_TitleBarMinButton).pixmap(buttonIconSize, dpr(opt->window));
proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm);
}
}
@@ -5644,10 +5652,11 @@ QIcon QCommonStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption
if (!linkIcon.isNull()) {
QIcon baseIcon = QCommonStyle::standardIcon(SP_FileIcon, option);
const QList<QSize> sizes = baseIcon.availableSizes(QIcon::Normal, QIcon::Off);
+ const qreal devicePixelRatio = dpr(option->window);
for (int i = 0 ; i < sizes.size() ; ++i) {
int size = sizes[i].width();
- QPixmap basePixmap = baseIcon.pixmap(option->window, QSize(size, size));
- QPixmap linkPixmap = linkIcon.pixmap(option->window, QSize(size / 2, size / 2));
+ QPixmap basePixmap = baseIcon.pixmap(QSize(size, size), devicePixelRatio);
+ QPixmap linkPixmap = linkIcon.pixmap(QSize(size / 2, size / 2), devicePixelRatio);
QPainter painter(&basePixmap);
painter.drawPixmap(size/2, size/2, linkPixmap);
icon.addPixmap(basePixmap);
@@ -5661,10 +5670,11 @@ QIcon QCommonStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption
if (!linkIcon.isNull()) {
QIcon baseIcon = QCommonStyle::standardIcon(SP_DirIcon, option);
const QList<QSize> sizes = baseIcon.availableSizes(QIcon::Normal, QIcon::Off);
+ const qreal devicePixelRatio = dpr(option->window);
for (int i = 0 ; i < sizes.size() ; ++i) {
int size = sizes[i].width();
- QPixmap basePixmap = baseIcon.pixmap(option->window, QSize(size, size));
- QPixmap linkPixmap = linkIcon.pixmap(option->window, QSize(size / 2, size / 2));
+ QPixmap basePixmap = baseIcon.pixmap(QSize(size, size), devicePixelRatio);
+ QPixmap linkPixmap = linkIcon.pixmap(QSize(size / 2, size / 2), devicePixelRatio);
QPainter painter(&basePixmap);
painter.drawPixmap(size/2, size/2, linkPixmap);
icon.addPixmap(basePixmap);