diff options
Diffstat (limited to 'src/plugins/styles')
-rw-r--r-- | src/plugins/styles/mac/qmacstyle_mac.mm | 67 | ||||
-rw-r--r-- | src/plugins/styles/mac/qmacstyle_mac_p_p.h | 10 | ||||
-rw-r--r-- | src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h | 2 | ||||
-rw-r--r-- | src/plugins/styles/windowsvista/qwindowsxpstyle.cpp | 12 |
4 files changed, 73 insertions, 18 deletions
diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 1379295623..7e54025d6e 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -81,21 +81,27 @@ #include <qpushbutton.h> #endif #include <qradiobutton.h> +#if QT_CONFIG(rubberband) #include <qrubberband.h> +#endif #include <qscrollbar.h> #include <qsizegrip.h> #include <qstyleoption.h> #include <qtoolbar.h> #include <qtoolbutton.h> #include <qtreeview.h> +#if QT_CONFIG(tableview) #include <qtableview.h> +#endif #include <qoperatingsystemversion.h> #if QT_CONFIG(wizard) #include <qwizard.h> #endif #include <qdebug.h> #include <qlibrary.h> +#if QT_CONFIG(datetimeedit) #include <qdatetimeedit.h> +#endif #include <qmath.h> #include <QtWidgets/qgraphicsproxywidget.h> #include <QtWidgets/qgraphicsview.h> @@ -317,7 +323,7 @@ static bool isInMacUnifiedToolbarArea(QWindow *window, int windowY) } -void drawTabCloseButton(QPainter *p, bool hover, bool selected, bool pressed) +static void drawTabCloseButton(QPainter *p, bool hover, bool selected, bool pressed, bool documentMode) { p->setRenderHints(QPainter::Antialiasing); QRect rect(0, 0, closeButtonSize, closeButtonSize); @@ -328,10 +334,16 @@ void drawTabCloseButton(QPainter *p, bool hover, bool selected, bool pressed) // draw background circle QColor background; if (selected) { - background = pressed ? tabBarCloseButtonBackgroundSelectedPressed : tabBarCloseButtonBackgroundSelectedHovered; + if (documentMode) + background = pressed ? tabBarCloseButtonBackgroundSelectedPressed : tabBarCloseButtonBackgroundSelectedHovered; + else + background = QColor(255, 255, 255, pressed ? 150 : 100); // Translucent white } else { background = pressed ? tabBarCloseButtonBackgroundPressed : tabBarCloseButtonBackgroundHovered; + if (!documentMode) + background = background.lighter(pressed ? 135 : 140); // Lighter tab background, lighter color } + p->setPen(Qt::transparent); p->setBrush(background); p->drawRoundedRect(rect, closeButtonCornerRadius, closeButtonCornerRadius); @@ -340,7 +352,7 @@ void drawTabCloseButton(QPainter *p, bool hover, bool selected, bool pressed) // draw cross const int margin = 3; QPen crossPen; - crossPen.setColor(selected ? tabBarCloseButtonCrossSelected : tabBarCloseButtonCross); + crossPen.setColor(selected ? (documentMode ? tabBarCloseButtonCrossSelected : Qt::white) : tabBarCloseButtonCross); crossPen.setWidthF(1.1); crossPen.setCapStyle(Qt::FlatCap); p->setPen(crossPen); @@ -1186,9 +1198,10 @@ void QMacStylePrivate::drawFocusRing(QPainter *p, const QRect &targetRect, int h } #ifndef QT_NO_TABBAR -void QMacStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect) const +void QMacStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *iconRect) const { Q_ASSERT(textRect); + Q_ASSERT(iconRect); QRect tr = opt->rect; const bool verticalTabs = opt->shape == QTabBar::RoundedEast || opt->shape == QTabBar::RoundedWest @@ -1222,6 +1235,26 @@ void QMacStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *widg tr.setLeft(tr.left() + 4 + buttonSize); } + // icon + if (!opt->icon.isNull()) { + QSize iconSize = opt->iconSize; + if (!iconSize.isValid()) { + int iconExtent = proxyStyle->pixelMetric(QStyle::PM_SmallIconSize); + iconSize = QSize(iconExtent, iconExtent); + } + QSize tabIconSize = opt->icon.actualSize(iconSize, + (opt->state & QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled, + (opt->state & QStyle::State_Selected) ? QIcon::On : QIcon::Off); + // High-dpi icons do not need adjustment; make sure tabIconSize is not larger than iconSize + tabIconSize = QSize(qMin(tabIconSize.width(), iconSize.width()), qMin(tabIconSize.height(), iconSize.height())); + + *iconRect = QRect(tr.left(), tr.center().y() - tabIconSize.height() / 2, + tabIconSize.width(), tabIconSize.height()); + if (!verticalTabs) + *iconRect = proxyStyle->visualRect(opt->direction, opt->rect, *iconRect); + tr.setLeft(tr.left() + tabIconSize.width() + 4); + } + if (!verticalTabs) tr = proxyStyle->visualRect(opt->direction, opt->rect, tr); @@ -1487,7 +1520,7 @@ void QMacStylePrivate::initComboboxBdi(const QStyleOptionComboBox *combo, HIThem // an extra check here before using the mini and small buttons. int h = combo->rect.size().height(); if (combo->editable){ -#ifndef QT_NO_DATETIMEEDIT +#if QT_CONFIG(datetimeedit) if (qobject_cast<const QDateTimeEdit *>(widget)) { // Except when, you know, we get a QDateTimeEdit with calendarPopup // enabled. And then things get weird, basically because it's a @@ -2354,6 +2387,8 @@ void QMacStyle::polish(QWidget* w) QPalette p = w->palette(); p.setColor(QPalette::WindowText, QColor(17, 17, 17)); w->setPalette(p); + w->setAttribute(Qt::WA_SetPalette, false); + w->setAttribute(Qt::WA_SetFont, false); } } #endif @@ -2395,6 +2430,15 @@ void QMacStyle::unpolish(QWidget* w) } #endif +#ifndef QT_NO_TABBAR + if (qobject_cast<QTabBar*>(w)) { + if (!w->testAttribute(Qt::WA_SetFont)) + w->setFont(qApp->font(w)); + if (!w->testAttribute(Qt::WA_SetPalette)) + w->setPalette(qApp->palette(w)); + } +#endif + if (QRubberBand *rubber = qobject_cast<QRubberBand*>(w)) { rubber->setWindowOpacity(1.0); rubber->setAttribute(Qt::WA_PaintOnScreen, true); @@ -3579,14 +3623,16 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai case PE_IndicatorTabClose: { // Make close button visible only on the hovered tab. if (QTabBar *tabBar = qobject_cast<QTabBar*>(w->parentWidget())) { + const bool documentMode = tabBar->documentMode(); const QTabBarPrivate *tabBarPrivate = static_cast<QTabBarPrivate *>(QObjectPrivate::get(tabBar)); const int hoveredTabIndex = tabBarPrivate->hoveredTabIndex(); - if (hoveredTabIndex != -1 && ((w == tabBar->tabButton(hoveredTabIndex, QTabBar::LeftSide)) || - (w == tabBar->tabButton(hoveredTabIndex, QTabBar::RightSide)))) { + if (!documentMode || + (hoveredTabIndex != -1 && ((w == tabBar->tabButton(hoveredTabIndex, QTabBar::LeftSide)) || + (w == tabBar->tabButton(hoveredTabIndex, QTabBar::RightSide))))) { const bool hover = (opt->state & State_MouseOver); const bool selected = (opt->state & State_Selected); const bool pressed = (opt->state & State_Sunken); - drawTabCloseButton(p, hover, selected, pressed); + drawTabCloseButton(p, hover, selected, pressed, documentMode); } } } break; @@ -3729,7 +3775,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter CGRect bounds = ir.toCGRect(); bool noVerticalHeader = true; -#ifndef QT_NO_TABLEVIEW +#if QT_CONFIG(tableview) if (w) if (const QTableView *table = qobject_cast<const QTableView *>(w->parentWidget())) noVerticalHeader = !table->verticalHeader()->isVisible(); @@ -4831,7 +4877,8 @@ QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt, break; case SE_TabBarTabText: if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) { - d->tabLayout(tab, widget, &rect); + QRect dummyIconRect; + d->tabLayout(tab, widget, &rect, &dummyIconRect); } break; case SE_TabBarTabLeftButton: diff --git a/src/plugins/styles/mac/qmacstyle_mac_p_p.h b/src/plugins/styles/mac/qmacstyle_mac_p_p.h index 7c9c0f8f3c..f1c355e621 100644 --- a/src/plugins/styles/mac/qmacstyle_mac_p_p.h +++ b/src/plugins/styles/mac/qmacstyle_mac_p_p.h @@ -82,7 +82,9 @@ #include <qpushbutton.h> #endif #include <qradiobutton.h> +#if QT_CONFIG(rubberband) #include <qrubberband.h> +#endif #include <qsizegrip.h> #include <qspinbox.h> #include <qsplitter.h> @@ -92,9 +94,13 @@ #include <qtoolbar.h> #include <qtoolbutton.h> #include <qtreeview.h> +#if QT_CONFIG(tableview) #include <qtableview.h> +#endif #include <qdebug.h> +#if QT_CONFIG(datetimeedit) #include <qdatetimeedit.h> +#endif #include <qmath.h> #include <qpair.h> #include <qvector.h> @@ -164,7 +170,7 @@ typedef void (^QCocoaDrawRectBlock)(CGContextRef, const CGRect &); do { \ static const int sizes[] = { (large), (small), (mini) }; \ return sizes[controlSize]; \ - } while (0) + } while (false) #if QT_CONFIG(pushbutton) bool qt_mac_buttonIsRenderedFlat(const QPushButton *pushButton, const QStyleOptionButton *option); @@ -242,7 +248,7 @@ public: void drawFocusRing(QPainter *p, const QRect &targetRect, int hMargin, int vMargin, qreal radius = 0) const; #ifndef QT_NO_TABBAR - void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect) const; + void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *iconRect) const; #endif public: diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h b/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h index ee3a12c641..36c8f9d818 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h @@ -82,7 +82,9 @@ #include <qdialogbuttonbox.h> #endif #include <qinputdialog.h> +#if QT_CONFIG(tableview) #include <qtableview.h> +#endif #include <qdatetime.h> #include <qcommandlinkbutton.h> diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp index a21ce4b531..e670794cd3 100644 --- a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp @@ -1165,7 +1165,7 @@ void QWindowsXPStyle::polish(QWidget *widget) widget->setAttribute(Qt::WA_Hover); } -#ifndef QT_NO_RUBBERBAND +#if QT_CONFIG(rubberband) if (qobject_cast<QRubberBand*>(widget)) { widget->setWindowOpacity(0.6); } @@ -1200,7 +1200,7 @@ void QWindowsXPStyle::polish(QPalette &pal) /*! \reimp */ void QWindowsXPStyle::unpolish(QWidget *widget) { -#ifndef QT_NO_RUBBERBAND +#if QT_CONFIG(rubberband) if (qobject_cast<QRubberBand*>(widget)) { widget->setWindowOpacity(1.0); } @@ -2418,7 +2418,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op } break; #endif // QT_NO_DOCKWIDGET -#ifndef QT_NO_RUBBERBAND +#if QT_CONFIG(rubberband) case CE_RubberBand: if (qstyleoption_cast<const QStyleOptionRubberBand *>(option)) { QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight); @@ -2434,7 +2434,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op return; } break; -#endif // QT_NO_RUBBERBAND +#endif // QT_CONFIG(rubberband) case CE_HeaderEmptyArea: if (option->state & State_Horizontal) { @@ -3758,12 +3758,12 @@ int QWindowsXPStyle::styleHint(StyleHint hint, const QStyleOption *option, const } } break; -#ifndef QT_NO_RUBBERBAND +#if QT_CONFIG(rubberband) case SH_RubberBand_Mask: if (qstyleoption_cast<const QStyleOptionRubberBand *>(option)) res = 0; break; -#endif // QT_NO_RUBBERBAND +#endif // QT_CONFIG(rubberband) case SH_ItemView_DrawDelegateFrame: res = 1; |