diff options
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/styles/qmacstyle_mac.mm | 153 | ||||
-rw-r--r-- | src/widgets/styles/qmacstyle_mac_p_p.h | 16 | ||||
-rw-r--r-- | src/widgets/widgets/qplaintextedit.cpp | 2 |
3 files changed, 118 insertions, 53 deletions
diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 01a2f2b3bd..82718eea7f 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -93,6 +93,7 @@ #include <qmath.h> #include <QtWidgets/qgraphicsproxywidget.h> #include <QtWidgets/qgraphicsview.h> +#include <QtCore/qvariant.h> #include <private/qstylehelper_p.h> #include <private/qstyleanimation_p.h> #include <qpa/qplatformfontdatabase.h> @@ -1728,7 +1729,7 @@ QMacStylePrivate::QMacStylePrivate() QMacStylePrivate::~QMacStylePrivate() { - Q_FOREACH (NSView *b, buttons) + Q_FOREACH (NSView *b, cocoaControls) [b release]; } @@ -1749,43 +1750,92 @@ ThemeDrawState QMacStylePrivate::getDrawState(QStyle::State flags) return tds; } -NSView *QMacStylePrivate::buttonOfKind(ThemeButtonKind kind, QPoint *offset) const +static QCocoaWidget cocoaWidgetFromHIThemeButtonKind(ThemeButtonKind kind) { - NSView *bv = buttons[kind]; + QCocoaWidget w; + + switch (kind) { + case kThemePopupButton: + case kThemePopupButtonSmall: + case kThemePopupButtonMini: + w.first = QCocoaPopupButton; + break; + case kThemeComboBox: + w.first = QCocoaComboBox; + break; + case kThemeArrowButton: + w.first = QCocoaArrowButton; + break; + case kThemeCheckBox: + case kThemeCheckBoxSmall: + case kThemeCheckBoxMini: + w.first = QCocoaCheckBox; + break; + case kThemeRadioButton: + case kThemeRadioButtonSmall: + case kThemeRadioButtonMini: + w.first = QCocoaRadioButton; + break; + case kThemePushButton: + case kThemePushButtonSmall: + case kThemePushButtonMini: + w.first = QCocoaPushButton; + break; + default: + break; + } + + switch (kind) { + case kThemePushButtonSmall: + case kThemePopupButtonSmall: + case kThemeCheckBoxSmall: + case kThemeRadioButtonSmall: + w.second = QAquaSizeSmall; + break; + case kThemePushButtonMini: + case kThemePopupButtonMini: + case kThemeCheckBoxMini: + case kThemeRadioButtonMini: + w.second = QAquaSizeMini; + break; + default: + w.second = QAquaSizeLarge; + break; + } + + return w; +} + +NSView *QMacStylePrivate::cocoaControl(QCocoaWidget widget, QPoint *offset) const +{ + NSView *bv = cocoaControls[widget]; if (!bv) { - if (kind == kThemePopupButton - || kind == kThemePopupButtonSmall - || kind == kThemePopupButtonMini) + + if (widget.first == QCocoaPopupButton) bv = [[NSPopUpButton alloc] init]; - else if (kind == kThemeComboBox) + else if (widget.first == QCocoaComboBox) bv = [[NSComboBox alloc] init]; else bv = [[NSButton alloc] init]; - switch (kind) { - case kThemeArrowButton: { + switch (widget.first) { + case QCocoaArrowButton: { NSButton *bc = (NSButton *)bv; bc.buttonType = NSOnOffButton; bc.bezelStyle = NSDisclosureBezelStyle; break; } - case kThemeCheckBox: - case kThemeCheckBoxSmall: - case kThemeCheckBoxMini: { + case QCocoaCheckBox: { NSButton *bc = (NSButton *)bv; bc.buttonType = NSSwitchButton; break; } - case kThemeRadioButton: - case kThemeRadioButtonSmall: - case kThemeRadioButtonMini: { + case QCocoaRadioButton: { NSButton *bc = (NSButton *)bv; bc.buttonType = NSRadioButton; break; } - case kThemePushButton: - case kThemePushButtonSmall: - case kThemePushButtonMini: { + case QCocoaPushButton: { NSButton *bc = (NSButton *)bv; bc.buttonType = NSMomentaryPushButton; bc.bezelStyle = NSRoundedBezelStyle; @@ -1798,19 +1848,15 @@ NSView *QMacStylePrivate::buttonOfKind(ThemeButtonKind kind, QPoint *offset) con if ([bv isKindOfClass:[NSButton class]]) { NSButton *bc = (NSButton *)bv; bc.title = nil; + } - NSCell *bcell = bc.cell; - switch (kind) { - case kThemePushButtonSmall: - case kThemePopupButtonSmall: - case kThemeCheckBoxSmall: - case kThemeRadioButtonSmall: + if ([bv isKindOfClass:[NSControl class]]) { + NSCell *bcell = [(NSControl *)bv cell]; + switch (widget.second) { + case QAquaSizeSmall: bcell.controlSize = NSSmallControlSize; break; - case kThemePushButtonMini: - case kThemePopupButtonMini: - case kThemeCheckBoxMini: - case kThemeRadioButtonMini: + case QAquaSizeMini: bcell.controlSize = NSMiniControlSize; break; default: @@ -1818,36 +1864,25 @@ NSView *QMacStylePrivate::buttonOfKind(ThemeButtonKind kind, QPoint *offset) con } } - const_cast<QMacStylePrivate *>(this)->buttons.insert(kind, bv); + const_cast<QMacStylePrivate *>(this)->cocoaControls.insert(widget, bv); } if (offset) { - switch (kind) { - case kThemeRadioButton: + if (widget == QCocoaWidget(QCocoaRadioButton, QAquaSizeLarge)) offset->setY(2); - break; - case kThemeRadioButtonSmall: + else if (widget == QCocoaWidget(QCocoaRadioButton, QAquaSizeSmall)) *offset = QPoint(-1, 2); - break; - case kThemeRadioButtonMini: + else if (widget == QCocoaWidget(QCocoaRadioButton, QAquaSizeMini)) offset->setY(2); - break; - case kThemePopupButtonSmall: - case kThemeCheckBox: + else if (widget == QCocoaWidget(QCocoaPopupButton, QAquaSizeSmall) + || widget == QCocoaWidget(QCocoaCheckBox, QAquaSizeLarge)) offset->setY(1); - break; - case kThemeCheckBoxSmall: + else if (widget == QCocoaWidget(QCocoaCheckBox, QAquaSizeSmall)) offset->setX(-1); - break; - case kThemeCheckBoxMini: + else if (widget == QCocoaWidget(QCocoaCheckBox, QAquaSizeMini)) *offset = QPoint(7, 5); - break; - case kThemePopupButtonMini: + else if (widget == QCocoaWidget(QCocoaPopupButton, QAquaSizeMini)) *offset = QPoint(2, -1); - break; - default: - break; - } } return bv; @@ -1967,7 +2002,7 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD pm = QPixmap::fromImage(image); } else if ((usingYosemiteOrLater && combo && !editableCombo) || button) { QPoint offset; - NSButton *bc = (NSButton *)buttonOfKind(bdi->kind, &offset); + NSButton *bc = (NSButton *)cocoaControl(cocoaWidgetFromHIThemeButtonKind(bdi->kind), &offset); [bc highlight:pressed]; bc.enabled = bdi->state != kThemeStateUnavailable && bdi->state != kThemeStateUnavailableInactive; bc.allowsMixedState = YES; @@ -5792,7 +5827,25 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex drawToolbarButtonArrow(tb->rect, tds, cg); } if (tb->state & State_On) { - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { + if (QSysInfo::MacintoshVersion > QSysInfo::MV_MAVERICKS) { + QWindow *window = 0; + if (widget && widget->window()) + window = widget->window()->windowHandle(); + else if (opt->styleObject) + window = opt->styleObject->property("_q_styleObjectWindow").value<QWindow *>(); + + NSView *view = window ? (NSView *)window->winId() : nil; + bool isKey = false; + if (view) + isKey = [view.window isKeyWindow]; + + QBrush brush(isKey ? QColor(0, 0, 0, 28) + : QColor(0, 0, 0, 21)); + QPainterPath path; + path.addRoundedRect(QRectF(tb->rect.x(), tb->rect.y(), tb->rect.width(), tb->rect.height() + 4), 4, 4); + p->setRenderHint(QPainter::Antialiasing); + p->fillPath(path, brush); + } else if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { static QPixmap pm(QLatin1String(":/qt-project.org/mac/style/images/leopard-unified-toolbar-on.png")); p->setRenderHint(QPainter::SmoothPixmapTransform); QStyleHelper::drawBorderPixmap(pm, p, tb->rect, 2, 2, 2, 2); diff --git a/src/widgets/styles/qmacstyle_mac_p_p.h b/src/widgets/styles/qmacstyle_mac_p_p.h index d145ff620b..b6267c43e6 100644 --- a/src/widgets/styles/qmacstyle_mac_p_p.h +++ b/src/widgets/styles/qmacstyle_mac_p_p.h @@ -85,6 +85,7 @@ #include <qlibrary.h> #include <qdatetimeedit.h> #include <qmath.h> +#include <qpair.h> #include <qset.h> #include <QtWidgets/qgraphicsproxywidget.h> #include <QtWidgets/qgraphicsview.h> @@ -120,6 +121,17 @@ QT_BEGIN_NAMESPACE enum QAquaWidgetSize { QAquaSizeLarge = 0, QAquaSizeSmall = 1, QAquaSizeMini = 2, QAquaSizeUnknown = -1 }; +enum QCocoaWidgetKind { + QCocoaArrowButton, // Disclosure triangle, like in QTreeView + QCocoaCheckBox, + QCocoaComboBox, // Editable QComboBox + QCocoaPopupButton, // Non-editable QComboBox + QCocoaPushButton, + QCocoaRadioButton +}; + +typedef QPair<QCocoaWidgetKind, QAquaWidgetSize> QCocoaWidget; + #define SIZE(large, small, mini) \ (controlSize == QAquaSizeLarge ? (large) : controlSize == QAquaSizeSmall ? (small) : (mini)) @@ -187,7 +199,7 @@ public: void setAutoDefaultButton(QObject *button) const; - NSView *buttonOfKind(ThemeButtonKind kind, QPoint *offset) const; + NSView *cocoaControl(QCocoaWidget widget, QPoint *offset) const; void drawNSViewInRect(NSView *view, const QRect &rect, QPainter *p) const; void resolveCurrentNSView(QWindow *window); @@ -211,7 +223,7 @@ public: #endif void *indicatorBranchButtonCell; NSView *backingStoreNSView; - QHash<ThemeButtonKind , NSView *> buttons; + QHash<QCocoaWidget, NSView *> cocoaControls; }; QT_END_NAMESPACE diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index d33ac5fd7b..b6a21f183a 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -281,7 +281,7 @@ void QPlainTextDocumentLayout::documentChanged(int from, int charsRemoved, int c Q_D(QPlainTextDocumentLayout); QTextDocument *doc = document(); int newBlockCount = doc->blockCount(); - int charsChanged = qMax(charsRemoved, charsAdded); + int charsChanged = charsRemoved + charsAdded; QTextBlock changeStartBlock = doc->findBlock(from); QTextBlock changeEndBlock = doc->findBlock(qMax(0, from + charsChanged - 1)); |