diff options
Diffstat (limited to 'src/widgets/styles/qcommonstyle.cpp')
-rw-r--r-- | src/widgets/styles/qcommonstyle.cpp | 194 |
1 files changed, 116 insertions, 78 deletions
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 27fef46772..6fbae53804 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -321,22 +321,24 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) { QPen oldPen = p->pen(); if (header->sortIndicator & QStyleOptionHeader::SortUp) { - QPolygon pa(3); p->setPen(QPen(opt->palette.light(), 0)); p->drawLine(opt->rect.x() + opt->rect.width(), opt->rect.y(), opt->rect.x() + opt->rect.width() / 2, opt->rect.y() + opt->rect.height()); p->setPen(QPen(opt->palette.dark(), 0)); - pa.setPoint(0, opt->rect.x() + opt->rect.width() / 2, opt->rect.y() + opt->rect.height()); - pa.setPoint(1, opt->rect.x(), opt->rect.y()); - pa.setPoint(2, opt->rect.x() + opt->rect.width(), opt->rect.y()); - p->drawPolyline(pa); + const QPoint points[] = { + QPoint(opt->rect.x() + opt->rect.width() / 2, opt->rect.y() + opt->rect.height()), + QPoint(opt->rect.x(), opt->rect.y()), + QPoint(opt->rect.x() + opt->rect.width(), opt->rect.y()), + }; + p->drawPolyline(points, sizeof points / sizeof *points); } else if (header->sortIndicator & QStyleOptionHeader::SortDown) { - QPolygon pa(3); p->setPen(QPen(opt->palette.light(), 0)); - pa.setPoint(0, opt->rect.x(), opt->rect.y() + opt->rect.height()); - pa.setPoint(1, opt->rect.x() + opt->rect.width(), opt->rect.y() + opt->rect.height()); - pa.setPoint(2, opt->rect.x() + opt->rect.width() / 2, opt->rect.y()); - p->drawPolyline(pa); + const QPoint points[] = { + QPoint(opt->rect.x(), opt->rect.y() + opt->rect.height()), + QPoint(opt->rect.x() + opt->rect.width(), opt->rect.y() + opt->rect.height()), + QPoint(opt->rect.x() + opt->rect.width() / 2, opt->rect.y()), + }; + p->drawPolyline(points, sizeof points / sizeof *points); p->setPen(QPen(opt->palette.dark(), 0)); p->drawLine(opt->rect.x(), opt->rect.y() + opt->rect.height(), opt->rect.x() + opt->rect.width() / 2, opt->rect.y()); @@ -519,11 +521,6 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q if (pe == PE_IndicatorSpinUp && fw) --sy; - QPolygon a; - if (pe == PE_IndicatorSpinDown) - a.setPoints(3, 0, 1, sw-1, 1, sh-2, sh-1); - else - a.setPoints(3, 0, sh-1, sw-1, sh-1, sh-2, 1); int bsx = 0; int bsy = 0; if (opt->state & State_Sunken) { @@ -535,7 +532,13 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q p->setPen(opt->palette.buttonText().color()); p->setBrush(opt->palette.buttonText()); p->setRenderHint(QPainter::Qt4CompatiblePainting); - p->drawPolygon(a); + if (pe == PE_IndicatorSpinDown) { + const QPoint points[] = { QPoint(0, 1), QPoint(sw-1, 1), QPoint(sh-2, sh-1) }; + p->drawPolygon(points, sizeof points / sizeof *points); + } else { + const QPoint points[] = { QPoint(0, sh-1), QPoint(sw-1, sh-1), QPoint(sh-2, 1) }; + p->drawPolygon(points, sizeof points / sizeof *points); + } p->restore(); break; } #endif // QT_NO_SPINBOX @@ -1156,7 +1159,7 @@ void QCommonStylePrivate::startAnimation(QStyleAnimation *animation) const stopAnimation(animation->target()); q->connect(animation, SIGNAL(destroyed()), SLOT(_q_removeAnimation()), Qt::UniqueConnection); animations.insert(animation->target(), animation); - animation->start(QAbstractAnimation::DeleteWhenStopped); + animation->start(); } /*! \internal */ @@ -1644,30 +1647,33 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, break; case CE_ToolBoxTabShape: if (const QStyleOptionToolBox *tb = qstyleoption_cast<const QStyleOptionToolBox *>(opt)) { + p->setPen(tb->palette.mid().color().darker(150)); + bool oldQt4CompatiblePainting = p->testRenderHint(QPainter::Qt4CompatiblePainting); + p->setRenderHint(QPainter::Qt4CompatiblePainting); int d = 20 + tb->rect.height() - 3; - QPolygon a(7); if (tb->direction != Qt::RightToLeft) { - a.setPoint(0, -1, tb->rect.height() + 1); - a.setPoint(1, -1, 1); - a.setPoint(2, tb->rect.width() - d, 1); - a.setPoint(3, tb->rect.width() - 20, tb->rect.height() - 2); - a.setPoint(4, tb->rect.width() - 1, tb->rect.height() - 2); - a.setPoint(5, tb->rect.width() - 1, tb->rect.height() + 1); - a.setPoint(6, -1, tb->rect.height() + 1); + const QPoint points[] = { + QPoint(-1, tb->rect.height() + 1), + QPoint(-1, 1), + QPoint(tb->rect.width() - d, 1), + QPoint(tb->rect.width() - 20, tb->rect.height() - 2), + QPoint(tb->rect.width() - 1, tb->rect.height() - 2), + QPoint(tb->rect.width() - 1, tb->rect.height() + 1), + QPoint(-1, tb->rect.height() + 1), + }; + p->drawPolygon(points, sizeof points / sizeof *points); } else { - a.setPoint(0, tb->rect.width(), tb->rect.height() + 1); - a.setPoint(1, tb->rect.width(), 1); - a.setPoint(2, d - 1, 1); - a.setPoint(3, 20 - 1, tb->rect.height() - 2); - a.setPoint(4, 0, tb->rect.height() - 2); - a.setPoint(5, 0, tb->rect.height() + 1); - a.setPoint(6, tb->rect.width(), tb->rect.height() + 1); + const QPoint points[] = { + QPoint(tb->rect.width(), tb->rect.height() + 1), + QPoint(tb->rect.width(), 1), + QPoint(d - 1, 1), + QPoint(20 - 1, tb->rect.height() - 2), + QPoint(0, tb->rect.height() - 2), + QPoint(0, tb->rect.height() + 1), + QPoint(tb->rect.width(), tb->rect.height() + 1), + }; + p->drawPolygon(points, sizeof points / sizeof *points); } - - p->setPen(tb->palette.mid().color().darker(150)); - bool oldQt4CompatiblePainting = p->testRenderHint(QPainter::Qt4CompatiblePainting); - p->setRenderHint(QPainter::Qt4CompatiblePainting); - p->drawPolygon(a); p->setRenderHint(QPainter::Qt4CompatiblePainting, oldQt4CompatiblePainting); p->setPen(tb->palette.light().color()); if (tb->direction != Qt::RightToLeft) { @@ -2914,7 +2920,7 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt, QRect closeRect; if (canClose) { - QSize sz = standardIcon(QStyle::SP_TitleBarCloseButton, + QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarCloseButton, opt, widget).actualSize(QSize(iconSize, iconSize)); sz += QSize(buttonMargin, buttonMargin); if (verticalTitleBar) @@ -2931,7 +2937,7 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt, QRect floatRect; if (canFloat) { - QSize sz = standardIcon(QStyle::SP_TitleBarNormalButton, + QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarNormalButton, opt, widget).actualSize(QSize(iconSize, iconSize)); sz += QSize(buttonMargin, buttonMargin); if (verticalTitleBar) @@ -3039,7 +3045,18 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt, #ifndef QT_NO_DIAL -static QPolygonF calcArrow(const QStyleOptionSlider *dial, qreal &a) +// in lieu of std::array, minimal API +template <int N> +struct StaticPolygonF +{ + QPointF data[N]; + + Q_DECL_CONSTEXPR int size() const { return N; } + Q_DECL_CONSTEXPR const QPointF *cbegin() const { return data; } + Q_DECL_CONSTEXPR const QPointF &operator[](int idx) const { return data[idx]; } +}; + +static StaticPolygonF<3> calcArrow(const QStyleOptionSlider *dial, qreal &a) { int width = dial->rect.width(); int height = dial->rect.height(); @@ -3063,13 +3080,14 @@ static QPolygonF calcArrow(const QStyleOptionSlider *dial, qreal &a) len = 5; int back = len / 2; - QPolygonF arrow(3); - arrow[0] = QPointF(0.5 + xc + len * qCos(a), - 0.5 + yc - len * qSin(a)); - arrow[1] = QPointF(0.5 + xc + back * qCos(a + Q_PI * 5 / 6), - 0.5 + yc - back * qSin(a + Q_PI * 5 / 6)); - arrow[2] = QPointF(0.5 + xc + back * qCos(a - Q_PI * 5 / 6), - 0.5 + yc - back * qSin(a - Q_PI * 5 / 6)); + StaticPolygonF<3> arrow = {{ + QPointF(0.5 + xc + len * qCos(a), + 0.5 + yc - len * qSin(a)), + QPointF(0.5 + xc + back * qCos(a + Q_PI * 5 / 6), + 0.5 + yc - back * qSin(a + Q_PI * 5 / 6)), + QPointF(0.5 + xc + back * qCos(a - Q_PI * 5 / 6), + 0.5 + yc - back * qSin(a - Q_PI * 5 / 6)), + }}; return arrow; } @@ -3394,9 +3412,9 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl || qobject_cast<const QDockWidget *>(widget) #endif ) - pm = standardIcon(SP_DockWidgetCloseButton, &tool, widget).pixmap(10, 10); + pm = proxy()->standardIcon(SP_DockWidgetCloseButton, &tool, widget).pixmap(10, 10); else - pm = standardIcon(SP_TitleBarCloseButton, &tool, widget).pixmap(10, 10); + pm = proxy()->standardIcon(SP_TitleBarCloseButton, &tool, widget).pixmap(10, 10); tool.rect = ir; tool.state = down ? State_Sunken : State_Raised; proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget); @@ -3415,7 +3433,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarMaxButton, widget); down = tb->activeSubControls & SC_TitleBarMaxButton && (opt->state & State_Sunken); - pm = standardIcon(SP_TitleBarMaxButton, &tool, widget).pixmap(10, 10); + pm = proxy()->standardIcon(SP_TitleBarMaxButton, &tool, widget).pixmap(10, 10); tool.rect = ir; tool.state = down ? State_Sunken : State_Raised; proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget); @@ -3433,7 +3451,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl && !(tb->titleBarState & Qt::WindowMinimized)) { ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarMinButton, widget); down = tb->activeSubControls & SC_TitleBarMinButton && (opt->state & State_Sunken); - pm = standardIcon(SP_TitleBarMinButton, &tool, widget).pixmap(10, 10); + pm = proxy()->standardIcon(SP_TitleBarMinButton, &tool, widget).pixmap(10, 10); tool.rect = ir; tool.state = down ? State_Sunken : State_Raised; proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget); @@ -3455,7 +3473,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl if (drawNormalButton) { ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarNormalButton, widget); down = tb->activeSubControls & SC_TitleBarNormalButton && (opt->state & State_Sunken); - pm = standardIcon(SP_TitleBarNormalButton, &tool, widget).pixmap(10, 10); + pm = proxy()->standardIcon(SP_TitleBarNormalButton, &tool, widget).pixmap(10, 10); tool.rect = ir; tool.state = down ? State_Sunken : State_Raised; proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget); @@ -3473,7 +3491,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl && !(tb->titleBarState & Qt::WindowMinimized)) { ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarShadeButton, widget); down = (tb->activeSubControls & SC_TitleBarShadeButton && (opt->state & State_Sunken)); - pm = standardIcon(SP_TitleBarShadeButton, &tool, widget).pixmap(10, 10); + pm = proxy()->standardIcon(SP_TitleBarShadeButton, &tool, widget).pixmap(10, 10); tool.rect = ir; tool.state = down ? State_Sunken : State_Raised; proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget); @@ -3491,7 +3509,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarUnshadeButton, widget); down = tb->activeSubControls & SC_TitleBarUnshadeButton && (opt->state & State_Sunken); - pm = standardIcon(SP_TitleBarUnshadeButton, &tool, widget).pixmap(10, 10); + pm = proxy()->standardIcon(SP_TitleBarUnshadeButton, &tool, widget).pixmap(10, 10); tool.rect = ir; tool.state = down ? State_Sunken : State_Raised; proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget); @@ -3507,7 +3525,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarContextHelpButton, widget); down = tb->activeSubControls & SC_TitleBarContextHelpButton && (opt->state & State_Sunken); - pm = standardIcon(SP_TitleBarContextHelpButton, &tool, widget).pixmap(10, 10); + pm = proxy()->standardIcon(SP_TitleBarContextHelpButton, &tool, widget).pixmap(10, 10); tool.rect = ir; tool.state = down ? State_Sunken : State_Raised; proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget); @@ -3524,7 +3542,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl tb->icon.paint(p, ir); } else { int iconSize = proxy()->pixelMetric(PM_SmallIconSize, tb, widget); - pm = standardIcon(SP_TitleBarMenuButton, &tool, widget).pixmap(iconSize, iconSize); + pm = proxy()->standardIcon(SP_TitleBarMenuButton, &tool, widget).pixmap(iconSize, iconSize); tool.rect = ir; p->save(); proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm); @@ -3571,12 +3589,12 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl p->drawArc(br, 240 * 16, 180 * 16); qreal a; - QPolygonF arrow(calcArrow(dial, a)); + const StaticPolygonF<3> arrow = calcArrow(dial, a); p->setPen(Qt::NoPen); p->setBrush(pal.button()); p->setRenderHint(QPainter::Qt4CompatiblePainting); - p->drawPolygon(arrow); + p->drawPolygon(arrow.cbegin(), arrow.size()); a = QStyleHelper::angle(QPointF(width / 2, height / 2), arrow[0]); p->setBrush(Qt::NoBrush); @@ -3711,7 +3729,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl } btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiCloseButton, widget); proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget); - QPixmap pm = standardIcon(SP_TitleBarCloseButton).pixmap(16, 16); + QPixmap pm = proxy()->standardIcon(SP_TitleBarCloseButton).pixmap(16, 16); proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm); } if (opt->subControls & QStyle::SC_MdiNormalButton) { @@ -3728,7 +3746,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl } btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiNormalButton, widget); proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget); - QPixmap pm = standardIcon(SP_TitleBarNormalButton).pixmap(16, 16); + QPixmap pm = proxy()->standardIcon(SP_TitleBarNormalButton).pixmap(16, 16); proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm); } if (opt->subControls & QStyle::SC_MdiMinButton) { @@ -3745,7 +3763,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl } btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiMinButton, widget); proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget); - QPixmap pm = standardIcon(SP_TitleBarMinButton).pixmap(16, 16); + QPixmap pm = proxy()->standardIcon(SP_TitleBarMinButton).pixmap(16, 16); proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm); } } @@ -4679,6 +4697,9 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid case PM_SubMenuOverlap: ret = -proxy()->pixelMetric(QStyle::PM_MenuPanelWidth, opt, widget); break; + case PM_TreeViewIndentation: + ret = int(QStyleHelper::dpiScaled(20.)); + break; default: ret = 0; break; @@ -4932,6 +4953,9 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget ret = hint.toChar().unicode(); break; } + case SH_LineEdit_PasswordMaskDelay: + ret = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::PasswordMaskDelay).toInt(); + break; case SH_ToolBox_SelectedPageTitleBold: ret = 1; break; @@ -5108,6 +5132,9 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget case SH_TabBar_CloseButtonPosition: ret = QTabBar::RightSide; break; + case SH_TabBar_ChangeCurrentDelay: + ret = 500; + break; #endif case SH_DockWidget_ButtonsHaveFrame: ret = true; @@ -5155,6 +5182,17 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget return ret; } +static QPixmap cachedPixmapFromXPM(const char * const *xpm) +{ + QPixmap result; + const QString tag = QString().sprintf("xpm:0x%p", static_cast<const void*>(xpm)); + if (!QPixmapCache::find(tag, &result)) { + result = QPixmap(xpm); + QPixmapCache::insert(tag, result); + } + return result; +} + /*! \reimp */ QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *option, const QWidget *widget) const @@ -5350,13 +5388,13 @@ QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *opti im = im.convertToFormat(QImage::Format_ARGB32).mirrored(true, false); return QPixmap::fromImage(im); } - return QPixmap(tb_extension_arrow_h_xpm); + return cachedPixmapFromXPM(tb_extension_arrow_h_xpm); case SP_ToolBarVerticalExtensionButton: - return QPixmap(tb_extension_arrow_v_xpm); + return cachedPixmapFromXPM(tb_extension_arrow_v_xpm); case SP_FileDialogStart: - return QPixmap(filedialog_start_xpm); + return cachedPixmapFromXPM(filedialog_start_xpm); case SP_FileDialogEnd: - return QPixmap(filedialog_end_xpm); + return cachedPixmapFromXPM(filedialog_end_xpm); #endif #ifndef QT_NO_IMAGEFORMAT_PNG case SP_CommandLink: @@ -5472,31 +5510,31 @@ QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *opti #ifndef QT_NO_IMAGEFORMAT_XPM switch (sp) { case SP_TitleBarMenuButton: - return QPixmap(qt_menu_xpm); + return cachedPixmapFromXPM(qt_menu_xpm); case SP_TitleBarShadeButton: - return QPixmap(qt_shade_xpm); + return cachedPixmapFromXPM(qt_shade_xpm); case SP_TitleBarUnshadeButton: - return QPixmap(qt_unshade_xpm); + return cachedPixmapFromXPM(qt_unshade_xpm); case SP_TitleBarNormalButton: - return QPixmap(qt_normalizeup_xpm); + return cachedPixmapFromXPM(qt_normalizeup_xpm); case SP_TitleBarMinButton: - return QPixmap(qt_minimize_xpm); + return cachedPixmapFromXPM(qt_minimize_xpm); case SP_TitleBarMaxButton: - return QPixmap(qt_maximize_xpm); + return cachedPixmapFromXPM(qt_maximize_xpm); case SP_TitleBarCloseButton: - return QPixmap(qt_close_xpm); + return cachedPixmapFromXPM(qt_close_xpm); case SP_TitleBarContextHelpButton: - return QPixmap(qt_help_xpm); + return cachedPixmapFromXPM(qt_help_xpm); case SP_DockWidgetCloseButton: - return QPixmap(dock_widget_close_xpm); + return cachedPixmapFromXPM(dock_widget_close_xpm); case SP_MessageBoxInformation: - return QPixmap(information_xpm); + return cachedPixmapFromXPM(information_xpm); case SP_MessageBoxWarning: - return QPixmap(warning_xpm); + return cachedPixmapFromXPM(warning_xpm); case SP_MessageBoxCritical: - return QPixmap(critical_xpm); + return cachedPixmapFromXPM(critical_xpm); case SP_MessageBoxQuestion: - return QPixmap(question_xpm); + return cachedPixmapFromXPM(question_xpm); default: break; } |