diff options
Diffstat (limited to 'src/plugins/styles/mac/qmacstyle_mac.mm')
-rw-r--r-- | src/plugins/styles/mac/qmacstyle_mac.mm | 168 |
1 files changed, 66 insertions, 102 deletions
diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 62f089b654..b2bcdb3e5b 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -50,92 +50,30 @@ #define QMAC_QAQUASTYLE_SIZE_CONSTRAIN //#define DEBUG_SIZE_CONSTRAINT -#include <private/qcore_mac_p.h> -#if QT_CONFIG(tabbar) -#include <private/qtabbar_p.h> -#endif -#include <private/qpainter_p.h> -#include <qapplication.h> -#include <qbitmap.h> -#if QT_CONFIG(combobox) -#include <private/qcombobox_p.h> -#include <qcombobox.h> -#endif -#if QT_CONFIG(dialogbuttonbox) -#include <qdialogbuttonbox.h> -#endif -#if QT_CONFIG(dockwidget) -#include <qdockwidget.h> -#endif -#include <qevent.h> -#include <qfocusframe.h> -#include <qformlayout.h> -#include <qgroupbox.h> -#include <qhash.h> -#include <qheaderview.h> -#if QT_CONFIG(lineedit) -#include <qlineedit.h> -#endif -#if QT_CONFIG(mainwindow) -#include <qmainwindow.h> -#endif +#include <QtCore/qoperatingsystemversion.h> +#include <QtCore/qvariant.h> +#include <QtCore/qvarlengtharray.h> + +#include <QtCore/private/qcore_mac_p.h> + +#include <QtGui/private/qcoregraphics_p.h> +#include <QtGui/qpa/qplatformfontdatabase.h> +#include <QtGui/qpa/qplatformtheme.h> + +#include <QtWidgets/private/qstyleanimation_p.h> + #if QT_CONFIG(mdiarea) -#include <qmdisubwindow.h> -#endif -#if QT_CONFIG(menubar) -#include <qmenubar.h> -#endif -#include <qpaintdevice.h> -#include <qpainter.h> -#include <qpixmapcache.h> -#include <qpointer.h> -#if QT_CONFIG(progressbar) -#include <qprogressbar.h> -#endif -#if QT_CONFIG(pushbutton) -#include <qpushbutton.h> -#endif -#include <qradiobutton.h> -#if QT_CONFIG(rubberband) -#include <qrubberband.h> +#include <QtWidgets/qmdisubwindow.h> #endif #if QT_CONFIG(scrollbar) -#include <qscrollbar.h> -#endif -#if QT_CONFIG(sizegrip) -#include <qsizegrip.h> -#endif -#include <qstyleoption.h> -#include <qtoolbar.h> -#if QT_CONFIG(toolbutton) -#include <qtoolbutton.h> -#endif -#if QT_CONFIG(treeview) -#include <qtreeview.h> +#include <QtWidgets/qscrollbar.h> #endif -#if QT_CONFIG(tableview) -#include <qtableview.h> +#if QT_CONFIG(tabbar) +#include <QtWidgets/private/qtabbar_p.h> #endif -#include <qoperatingsystemversion.h> #if QT_CONFIG(wizard) -#include <qwizard.h> -#endif -#include <qdebug.h> -#if QT_CONFIG(datetimeedit) -#include <qdatetimeedit.h> -#endif -#include <qmath.h> -#include <QtWidgets/qgraphicsproxywidget.h> -#if QT_CONFIG(graphicsview) -#include <QtWidgets/qgraphicsview.h> +#include <QtWidgets/qwizard.h> #endif -#include <QtCore/qvariant.h> -#include <QtCore/qvarlengtharray.h> -#include <private/qstylehelper_p.h> -#include <private/qstyleanimation_p.h> -#include <qpa/qplatformfontdatabase.h> -#include <qpa/qplatformtheme.h> -#include <QtGui/private/qcoregraphics_p.h> #include <cmath> @@ -297,6 +235,7 @@ static QLinearGradient titlebarGradientInactive() return qt_mac_applicationIsInDarkMode() ? darkGradient : lightGradient; } +#if QT_CONFIG(tabwidget) static void clipTabBarFrame(const QStyleOption *option, const QMacStyle *style, CGContextRef ctx) { Q_ASSERT(option); @@ -316,6 +255,7 @@ static void clipTabBarFrame(const QStyleOption *option, const QMacStyle *style, CGContextClipToRects(ctx, &cgRects[0], size_t(cgRects.size())); } } +#endif static const QColor titlebarSeparatorLineActive(111, 111, 111); static const QColor titlebarSeparatorLineInactive(131, 131, 131); @@ -340,6 +280,7 @@ static const qreal titleBarButtonSpacing = 8; // hovered: tab is hovered bool isDarkMode() { return qt_mac_applicationIsInDarkMode(); } +#if QT_CONFIG(tabbar) static const QColor lightTabBarTabBackgroundActive(190, 190, 190); static const QColor darkTabBarTabBackgroundActive(38, 38, 38); static const QColor tabBarTabBackgroundActive() { return isDarkMode() ? darkTabBarTabBackgroundActive : lightTabBarTabBackgroundActive; } @@ -385,6 +326,7 @@ static const QColor tabBarCloseButtonCrossSelected(115, 115, 115); static const int closeButtonSize = 14; static const qreal closeButtonCornerRadius = 2.0; +#endif // QT_CONFIG(tabbar) static const int headerSectionArrowHeight = 6; static const int headerSectionSeparatorInset = 2; @@ -560,6 +502,7 @@ static bool isInMacUnifiedToolbarArea(QWindow *window, int windowY) } +#if QT_CONFIG(tabbar) static void drawTabCloseButton(QPainter *p, bool hover, bool selected, bool pressed, bool documentMode) { p->setRenderHints(QPainter::Antialiasing); @@ -597,7 +540,6 @@ static void drawTabCloseButton(QPainter *p, bool hover, bool selected, bool pres p->drawLine(margin, height - margin, width - margin, margin); } -#if QT_CONFIG(tabbar) QRect rotateTabPainter(QPainter *p, QTabBar::Shape shape, QRect tabRect) { const auto tabDirection = QMacStylePrivate::tabDirection(shape); @@ -613,10 +555,10 @@ QRect rotateTabPainter(QPainter *p, QTabBar::Shape shape, QRect tabRect) newRot = -90; } tabRect.setRect(0, 0, tabRect.height(), tabRect.width()); - QMatrix m; - m.translate(newX, newY); - m.rotate(newRot); - p->setMatrix(m, true); + QTransform transform; + transform.translate(newX, newY); + transform.rotate(newRot); + p->setTransform(transform, true); } return tabRect; } @@ -919,8 +861,10 @@ static QSize qt_aqua_get_known_size(QStyle::ContentsType ct, const QWidget *widg else if (qobject_cast<const QLineEdit *>(widg)) ct = QStyle::CT_LineEdit; #endif +#if QT_CONFIG(itemviews) else if (qobject_cast<const QHeaderView *>(widg)) ct = QStyle::CT_HeaderSection; +#endif #if QT_CONFIG(menubar) else if (qobject_cast<const QMenuBar *>(widg)) ct = QStyle::CT_MenuBar; @@ -2221,10 +2165,12 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW int ret = 0; switch (metric) { +#if QT_CONFIG(tabbar) case PM_TabCloseIndicatorWidth: case PM_TabCloseIndicatorHeight: ret = closeButtonSize; break; +#endif case PM_ToolBarIconSize: ret = proxy()->pixelMetric(PM_LargeIconSize); break; @@ -2348,11 +2294,11 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW } break; case PM_SmallIconSize: - ret = int(QStyleHelper::dpiScaled(16.)); + ret = int(QStyleHelper::dpiScaled(16., opt)); break; case PM_LargeIconSize: - ret = int(QStyleHelper::dpiScaled(32.)); + ret = int(QStyleHelper::dpiScaled(32., opt)); break; case PM_IconViewIconSize: @@ -2381,10 +2327,12 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW ret = 16; break; case QStyleHelper::SizeDefault: +#if QT_CONFIG(tabbar) const QStyleOptionTab *tb = qstyleoption_cast<const QStyleOptionTab *>(opt); if (tb && tb->documentMode) ret = 30; else +#endif ret = QCommonStyle::pixelMetric(metric, opt, widget); break; } @@ -2895,9 +2843,11 @@ int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w ret = [NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay; } break; +#if QT_CONFIG(itemviews) case SH_ItemView_ScrollMode: ret = QAbstractItemView::ScrollPerPixel; break; +#endif case SH_TitleBar_ShowToolTipsOnButtons: // min/max/close buttons on windows don't show tool tips ret = false; @@ -3001,24 +2951,24 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai } #endif - QMatrix matrix; - matrix.translate(opt->rect.center().x() + xOffset, opt->rect.center().y() + 2); + QTransform transform; + transform.translate(opt->rect.center().x() + xOffset, opt->rect.center().y() + 2); QPainterPath path; switch(pe) { default: case PE_IndicatorArrowDown: break; case PE_IndicatorArrowUp: - matrix.rotate(180); + transform.rotate(180); break; case PE_IndicatorArrowLeft: - matrix.rotate(90); + transform.rotate(90); break; case PE_IndicatorArrowRight: - matrix.rotate(-90); + transform.rotate(-90); break; } - p->setMatrix(matrix); + p->setTransform(transform); path.moveTo(-halfSize, -halfSize * 0.5); path.lineTo(0.0, halfSize * 0.5); @@ -3039,7 +2989,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai p->restore(); return; } - +#if QT_CONFIG(tabwidget) QRegion region(tbb->rect); region -= tbb->tabBarRect; p->save(); @@ -3063,6 +3013,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai } proxy()->drawPrimitive(PE_FrameTabWidget, &twf, p, w); p->restore(); +#endif } break; #endif @@ -3109,8 +3060,10 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai needTranslation = true; } d->drawNSViewInRect(box, adjustedRect, p, ^(CGContextRef ctx, const CGRect &rect) { +#if QT_CONFIG(tabwidget) if (QTabWidget *tabWidget = qobject_cast<QTabWidget *>(opt->styleObject)) clipTabBarFrame(opt, this, ctx); +#endif CGContextTranslateCTM(ctx, 0, rect.origin.y + rect.size.height); CGContextScaleCTM(ctx, 1, -1); if (QOperatingSystemVersion::current() < QOperatingSystemVersion::MacOSMojave @@ -3404,6 +3357,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai } break; case PE_FrameStatusBarItem: break; +#if QT_CONFIG(tabbar) case PE_IndicatorTabClose: { // Make close button visible only on the hovered tab. QTabBar *tabBar = qobject_cast<QTabBar*>(w->parentWidget()); @@ -3428,6 +3382,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai } } } break; +#endif // QT_CONFIG(tabbar) case PE_PanelStatusBar: { // Fill the status bar with the titlebar gradient. QLinearGradient linearGrad; @@ -4598,6 +4553,7 @@ QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt, const int controlSize = getControlSize(opt, widget); switch (sr) { +#if QT_CONFIG(itemviews) case SE_ItemViewItemText: if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(opt)) { int fw = proxy()->pixelMetric(PM_FocusFrameHMargin, opt, widget); @@ -4607,6 +4563,7 @@ QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt, rect.adjust(-fw, 0, 0, 0); } break; +#endif case SE_ToolBoxTabContents: rect = QCommonStyle::subElementRect(sr, opt, widget); break; @@ -5317,9 +5274,20 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex } d->drawNSViewInRect(slider, opt->rect, p, ^(CGContextRef ctx, const CGRect &rect) { - if (isHorizontal && sl->upsideDown) { - CGContextTranslateCTM(ctx, rect.size.width, 0); - CGContextScaleCTM(ctx, -1, 1); + + // Since the GC is flipped, upsideDown means *not* inverted when vertical. + const bool verticalFlip = !isHorizontal && !sl->upsideDown; // FIXME: && !isSierraOrLater + + if (isHorizontal) { + if (sl->upsideDown) { + CGContextTranslateCTM(ctx, rect.size.width, rect.origin.y); + CGContextScaleCTM(ctx, -1, 1); + } else { + CGContextTranslateCTM(ctx, 0, rect.origin.y); + } + } else if (verticalFlip) { + CGContextTranslateCTM(ctx, rect.origin.x, rect.size.height); + CGContextScaleCTM(ctx, 1, -1); } if (hasDoubleTicks) { @@ -5330,9 +5298,6 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex CGContextTranslateCTM(ctx, 1, 0); } - // Since the GC is flipped, upsideDown means *not* inverted when vertical. - const bool verticalFlip = !isHorizontal && !sl->upsideDown; // FIXME: && !isSierraOrLater - #if 0 // FIXME: Sadly, this part doesn't work. It seems to somehow polute the // NSSlider's internal state and, when we need to use the "else" part, @@ -5396,9 +5361,6 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex // This ain't HIG kosher: force round knob look. if (hasDoubleTicks) slider.numberOfTickMarks = 0; - // Draw the knob in the symmetrical position instead of flipping. - if (verticalFlip) - slider.intValue = slider.maxValue - slider.intValue + slider.minValue; [cell drawKnob]; } } @@ -6436,12 +6398,14 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, sz = sz.expandedTo(QSize(sz.width(), minimumSize)); } break; +#if QT_CONFIG(itemviews) case CT_ItemViewItem: if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(opt)) { sz = QCommonStyle::sizeFromContents(ct, vopt, csz, widget); sz.setHeight(sz.height() + 2); } break; +#endif default: sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget); |