diff options
Diffstat (limited to 'src/widgets/styles')
-rw-r--r-- | src/widgets/styles/qcommonstyle.cpp | 20 | ||||
-rw-r--r-- | src/widgets/styles/qfusionstyle.cpp | 10 | ||||
-rw-r--r-- | src/widgets/styles/qstyle.cpp | 4 | ||||
-rw-r--r-- | src/widgets/styles/qstyleoption.cpp | 2 | ||||
-rw-r--r-- | src/widgets/styles/qstylesheetstyle.cpp | 60 | ||||
-rw-r--r-- | src/widgets/styles/qwindowsstyle.cpp | 29 |
6 files changed, 55 insertions, 70 deletions
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 9e701995a4..7b53f5272c 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -1253,12 +1253,12 @@ void QCommonStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *w *iconRect = QRect(tr.left() + offsetX, tr.center().y() - tabIconSize.height() / 2, tabIconSize.width(), tabIconSize.height()); if (!verticalTabs) - *iconRect = proxyStyle->visualRect(opt->direction, opt->rect, *iconRect); + *iconRect = QStyle::visualRect(opt->direction, opt->rect, *iconRect); tr.setLeft(tr.left() + tabIconSize.width() + 4); } if (!verticalTabs) - tr = proxyStyle->visualRect(opt->direction, opt->rect, tr); + tr = QStyle::visualRect(opt->direction, opt->rect, tr); *textRect = tr; } @@ -4835,7 +4835,7 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid break; case PM_MessageBoxIconSize: #ifdef Q_OS_MAC - if (QApplication::desktopSettingsAware()) { + if (QGuiApplication::desktopSettingsAware()) { ret = 64; // No DPI scaling, it's handled elsewhere. } else #endif @@ -5460,14 +5460,14 @@ static QIcon clearTextIcon(bool rtl) QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *option, const QWidget *widget) const { - const bool rtl = (option && option->direction == Qt::RightToLeft) || (!option && QApplication::isRightToLeft()); + const bool rtl = (option && option->direction == Qt::RightToLeft) || (!option && QGuiApplication::isRightToLeft()); #ifdef QT_NO_IMAGEFORMAT_PNG Q_UNUSED(widget); Q_UNUSED(sp); #else QPixmap pixmap; - if (QApplication::desktopSettingsAware() && !QIcon::themeName().isEmpty()) { + if (QGuiApplication::desktopSettingsAware() && !QIcon::themeName().isEmpty()) { switch (sp) { case SP_DialogYesButton: case SP_DialogOkButton: @@ -5829,7 +5829,7 @@ QIcon QCommonStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption const QWidget *widget) const { QIcon icon; - const bool rtl = (option && option->direction == Qt::RightToLeft) || (!option && QApplication::isRightToLeft()); + const bool rtl = (option && option->direction == Qt::RightToLeft) || (!option && QGuiApplication::isRightToLeft()); #ifdef Q_OS_WIN switch (standardIcon) { @@ -5881,7 +5881,7 @@ QIcon QCommonStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption #endif - if (QApplication::desktopSettingsAware() && !QIcon::themeName().isEmpty()) { + if (QGuiApplication::desktopSettingsAware() && !QIcon::themeName().isEmpty()) { switch (standardIcon) { case SP_DirHomeIcon: icon = QIcon::fromTheme(QLatin1String("user-home")); @@ -6057,13 +6057,13 @@ QIcon QCommonStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption default: break; } - } // if (QApplication::desktopSettingsAware() && !QIcon::themeName().isEmpty()) + } // if (QGuiApplication::desktopSettingsAware() && !QIcon::themeName().isEmpty()) if (!icon.isNull()) return icon; #if defined(Q_OS_MAC) - if (QApplication::desktopSettingsAware()) { + if (QGuiApplication::desktopSettingsAware()) { switch (standardIcon) { case SP_DirIcon: { // A rather special case @@ -6129,7 +6129,7 @@ QIcon QCommonStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption default: break; } - } // if (QApplication::desktopSettingsAware()) + } // if (QGuiApplication::desktopSettingsAware()) #endif // Q_OS_MAC switch (standardIcon) { diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index f3961b2a99..34cc3c93db 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -2769,8 +2769,16 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption buttonOption.state &= ~State_MouseOver; } - if (comboBox->frame) + if (comboBox->frame) { + cachePainter.save(); + cachePainter.setRenderHint(QPainter::Antialiasing, true); + cachePainter.translate(0.5, 0.5); + cachePainter.setPen(Qt::NoPen); + cachePainter.setBrush(buttonOption.palette.base()); + cachePainter.drawRoundedRect(rect.adjusted(0, 0, -1, -1), 2, 2); + cachePainter.restore(); proxy()->drawPrimitive(PE_FrameLineEdit, &buttonOption, &cachePainter, widget); + } // Draw button clipped cachePainter.save(); diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index 2c1132da19..6cbed34c3a 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -560,7 +560,7 @@ QRect QStyle::itemPixmapRect(const QRect &rect, int alignment, const QPixmap &pi x += w - pixmapWidth; else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter) x += w/2 - pixmapWidth/2; - else if ((alignment & Qt::AlignLeft) != Qt::AlignLeft && QApplication::isRightToLeft()) + else if ((alignment & Qt::AlignLeft) != Qt::AlignLeft && QGuiApplication::isRightToLeft()) x += w - pixmapWidth; result = QRect(x, y, pixmapWidth, pixmapHeight); return result; @@ -624,7 +624,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const { qreal scale = pixmap.devicePixelRatio(); - QRect aligned = alignedRect(QApplication::layoutDirection(), QFlag(alignment), pixmap.size() / scale, rect); + QRect aligned = alignedRect(QGuiApplication::layoutDirection(), QFlag(alignment), pixmap.size() / scale, rect); QRect inter = aligned.intersected(rect); painter->drawPixmap(inter.x(), inter.y(), pixmap, inter.x() - aligned.x(), inter.y() - aligned.y(), inter.width() * scale, inter.height() *scale); diff --git a/src/widgets/styles/qstyleoption.cpp b/src/widgets/styles/qstyleoption.cpp index 88031a9f1e..4faf98a0a3 100644 --- a/src/widgets/styles/qstyleoption.cpp +++ b/src/widgets/styles/qstyleoption.cpp @@ -151,7 +151,7 @@ QT_BEGIN_NAMESPACE QStyleOption::QStyleOption(int version, int type) : version(version), type(type), state(QStyle::State_None), - direction(QApplication::layoutDirection()), fontMetrics(QFont()), styleObject(0) + direction(QGuiApplication::layoutDirection()), fontMetrics(QFont()), styleObject(0) { } diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 025e1e0044..ea653459d3 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -909,7 +909,7 @@ static QStyle::StandardPixmap subControlIcon(int pe) QRenderRule::QRenderRule(const QVector<Declaration> &declarations, const QObject *object) : features(0), hasFont(false), pal(0), b(0), bg(0), bd(0), ou(0), geo(0), p(0), img(0), clipset(0) { - QPalette palette = QApplication::palette(); // ###: ideally widget's palette + QPalette palette = QGuiApplication::palette(); // ###: ideally widget's palette ValueExtractor v(declarations, palette); features = v.extractStyleFeatures(); @@ -2734,7 +2734,7 @@ static void updateObjects(const QList<const QObject *>& objects) for (const QObject *object : objects) { if (auto widget = qobject_cast<QWidget*>(const_cast<QObject*>(object))) { widget->style()->polish(widget); - QApplication::sendEvent(widget, &event); + QCoreApplication::sendEvent(widget, &event); } } } @@ -3706,17 +3706,6 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q bool dis = !(opt->state & QStyle::State_Enabled), act = opt->state & QStyle::State_Selected; - int checkableOffset = 0; - if (checkable) { - QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark); - QStyleOptionMenuItem newMi = mi; - newMi.rect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction); - // align with icons if there are some - checkableOffset = std::max(m->maxIconWidth, newMi.rect.width()); - if (subSubRule.hasDrawable() || checked) - drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, w); - } - if (!mi.icon.isNull()) { QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal; if (act && !dis) @@ -3733,24 +3722,28 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q } QRect iconRect = positionRect(w, subRule, iconRule, PseudoElement_MenuIcon, opt->rect, opt->direction); if (opt->direction == Qt::LeftToRight) - iconRect.moveLeft(iconRect.left() + checkableOffset); + iconRect.moveLeft(iconRect.left()); else - iconRect.moveRight(iconRect.right() - checkableOffset); + iconRect.moveRight(iconRect.right()); iconRule.drawRule(p, iconRect); QRect pmr(0, 0, pixw, pixh); pmr.moveCenter(iconRect.center()); p->drawPixmap(pmr.topLeft(), pixmap); + } else if (checkable) { + QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark); + if (subSubRule.hasDrawable() || checked) { + QStyleOptionMenuItem newMi = mi; + if (!dis) + newMi.state |= State_Enabled; + if (act) + newMi.state |= State_On; + newMi.rect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction); + drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, w); + } } - int textOffset = 0; - // padding overrules it all - if (!subRule.hasBox() || subRule.box()->paddings[LeftEdge] == 0) { - textOffset = checkableOffset; - if (!m->icon.isNull() || !checkable) - textOffset += m->maxIconWidth; - } QRect textRect = subRule.contentsRect(opt->rect); - textRect.setLeft(textRect.left() + textOffset); + textRect.setLeft(textRect.left() + m->maxIconWidth); textRect.setWidth(textRect.width() - mi.tabWidth); const QRect vTextRect = visualRect(opt->direction, m->rect, textRect); @@ -5106,27 +5099,20 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op if (mi->text.contains(QLatin1Char('\t'))) sz.rwidth() += 12; //as in QCommonStyle bool checkable = mi->checkType != QStyleOptionMenuItem::NotCheckable; - int checkableWidth = 0; - if (checkable) { + if (!mi->icon.isNull()) { + const int pmSmall = pixelMetric(PM_SmallIconSize); + const QSize pmSize = mi->icon.actualSize(QSize(pmSmall, pmSmall)); + sz.rwidth() += pmSize.width() + 4; + } else if (checkable) { QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark); QRect checkmarkRect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction); - checkableWidth = std::max(mi->maxIconWidth, checkmarkRect.width()); - } - if (!mi->icon.isNull()) { - QPixmap pixmap = mi->icon.pixmap(pixelMetric(PM_SmallIconSize)); - sz.rwidth() += pixmap.width(); + sz.rwidth() += std::max(mi->maxIconWidth, checkmarkRect.width()) + 4; } if (subRule.hasFont) { QFontMetrics fm(subRule.font); const QRect r = fm.boundingRect(QRect(), Qt::TextSingleLine | Qt::TextShowMnemonic, mi->text); sz = sz.expandedTo(r.size()); } - // padding overrules it all - if (!subRule.hasBox() || subRule.box()->paddings[LeftEdge] == 0) { - sz.rwidth() += checkableWidth; - if (!mi->icon.isNull() || !checkable) - sz.rwidth() += mi->maxIconWidth; - } return subRule.boxSize(subRule.adjustSize(sz)); } } @@ -6087,7 +6073,7 @@ void QStyleSheetStyle::updateStyleSheetFont(QWidget* w) const w->d_func()->directFontResolveMask = font.resolve(); QEvent e(QEvent::FontChange); - QApplication::sendEvent(w, &e); + QCoreApplication::sendEvent(w, &e); } } diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 7b5da9bfa8..c13f6e637d 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -84,6 +84,7 @@ #include <qpa/qplatformscreen.h> #include <private/qguiapplication_p.h> #include <private/qhighdpiscaling_p.h> +#include <private/qwidget_p.h> #include <private/qstylehelper_p.h> #if QT_CONFIG(animation) @@ -244,11 +245,12 @@ void QWindowsStyle::polish(QApplication *app) if (!proxy()->styleHint(SH_UnderlineShortcut, 0) && app) app->installEventFilter(this); - d->activeCaptionColor = app->palette().highlight().color(); - d->activeGradientCaptionColor = app->palette().highlight() .color(); - d->inactiveCaptionColor = app->palette().dark().color(); - d->inactiveGradientCaptionColor = app->palette().dark().color(); - d->inactiveCaptionText = app->palette().window().color(); + const auto &palette = QGuiApplication::palette(); + d->activeGradientCaptionColor = palette.highlight().color(); + d->activeCaptionColor = d->activeGradientCaptionColor; + d->inactiveGradientCaptionColor = palette.dark().color(); + d->inactiveCaptionColor = d->inactiveGradientCaptionColor; + d->inactiveCaptionText = palette.window().color(); #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) //fetch native title bar colors if(app->desktopSettingsAware()){ @@ -380,23 +382,12 @@ int QWindowsStylePrivate::fixedPixelMetric(QStyle::PixelMetric pm) return QWindowsStylePrivate::InvalidMetric; } -static QWindow *windowOf(const QWidget *w) +static QScreen *screenOf(const QWidget *w) { - QWindow *result = nullptr; if (w) { - result = w->windowHandle(); - if (!result) { - if (const QWidget *np = w->nativeParentWidget()) - result = np->windowHandle(); - } + if (auto screen = qt_widget_private(const_cast<QWidget *>(w))->associatedScreen()) + return screen; } - return result; -} - -static QScreen *screenOf(const QWidget *w) -{ - if (const QWindow *window = windowOf(w)) - return window->screen(); return QGuiApplication::primaryScreen(); } |