diff options
Diffstat (limited to 'src/widgets/styles')
-rw-r--r-- | src/widgets/styles/qcommonstyle.cpp | 2 | ||||
-rw-r--r-- | src/widgets/styles/qdrawutil.cpp | 6 | ||||
-rw-r--r-- | src/widgets/styles/qdrawutil.h | 4 | ||||
-rw-r--r-- | src/widgets/styles/qfusionstyle.cpp | 4 | ||||
-rw-r--r-- | src/widgets/styles/qmacstyle.qdoc | 39 | ||||
-rw-r--r-- | src/widgets/styles/qmacstyle_mac.mm | 436 | ||||
-rw-r--r-- | src/widgets/styles/qmacstyle_mac_p.h | 4 | ||||
-rw-r--r-- | src/widgets/styles/qwindowsvistastyle.cpp | 3 |
8 files changed, 186 insertions, 312 deletions
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 7971bd0b8b..c174a7af26 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -4872,6 +4872,8 @@ QSize QCommonStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, QRect decorationRect, displayRect, checkRect; d->viewItemLayout(vopt, &checkRect, &decorationRect, &displayRect, true); sz = (decorationRect|displayRect|checkRect).size(); + if (decorationRect.isValid() && sz.height() == decorationRect.height()) + sz.rheight() += 2; // Prevent icons from overlapping. } break; #endif // QT_NO_ITEMVIEWS diff --git a/src/widgets/styles/qdrawutil.cpp b/src/widgets/styles/qdrawutil.cpp index fa80a7a6ca..0b0583ea94 100644 --- a/src/widgets/styles/qdrawutil.cpp +++ b/src/widgets/styles/qdrawutil.cpp @@ -797,7 +797,11 @@ typedef QVarLengthArray<QPainter::PixmapFragment, 16> QPixmapFragmentsArray; void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargins &targetMargins, const QPixmap &pixmap, const QRect &sourceRect,const QMargins &sourceMargins, - const QTileRules &rules, QDrawBorderPixmap::DrawingHints hints) + const QTileRules &rules +#ifndef Q_CLANG_QDOC + , QDrawBorderPixmap::DrawingHints hints +#endif + ) { QPainter::PixmapFragment d; d.opacity = 1.0; diff --git a/src/widgets/styles/qdrawutil.h b/src/widgets/styles/qdrawutil.h index 121221dfc9..d5582f2c90 100644 --- a/src/widgets/styles/qdrawutil.h +++ b/src/widgets/styles/qdrawutil.h @@ -119,7 +119,7 @@ struct QTileRules Qt::TileRule vertical; }; -#ifndef Q_QDOC +#ifndef Q_CLANG_QDOC // For internal use only. namespace QDrawBorderPixmap { @@ -151,7 +151,7 @@ Q_WIDGETS_EXPORT void qDrawBorderPixmap(QPainter *painter, const QRect &sourceRect, const QMargins &sourceMargins, const QTileRules &rules = QTileRules() -#ifndef Q_QDOC +#ifndef Q_CLANG_QDOC , QDrawBorderPixmap::DrawingHints hints = QDrawBorderPixmap::DrawingHints() #endif ); diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index e08cd3ac70..75c50bb146 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -2437,7 +2437,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption int oldMin = styleObject->property("_q_stylemin").toInt(); int oldMax = styleObject->property("_q_stylemax").toInt(); QRect oldRect = styleObject->property("_q_stylerect").toRect(); - int oldState = styleObject->property("_q_stylestate").toInt(); + QStyle::State oldState = static_cast<QStyle::State>(styleObject->property("_q_stylestate").value<QStyle::State::Int>()); uint oldActiveControls = styleObject->property("_q_stylecontrols").toUInt(); // a scrollbar is transient when the the scrollbar itself and @@ -2460,7 +2460,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption styleObject->setProperty("_q_stylemin", scrollBar->minimum); styleObject->setProperty("_q_stylemax", scrollBar->maximum); styleObject->setProperty("_q_stylerect", scrollBar->rect); - styleObject->setProperty("_q_stylestate", static_cast<int>(scrollBar->state)); + styleObject->setProperty("_q_stylestate", static_cast<QStyle::State::Int>(scrollBar->state)); styleObject->setProperty("_q_stylecontrols", static_cast<uint>(scrollBar->activeSubControls)); #ifndef QT_NO_ANIMATION diff --git a/src/widgets/styles/qmacstyle.qdoc b/src/widgets/styles/qmacstyle.qdoc index f8bd1f57a9..a77843a4dd 100644 --- a/src/widgets/styles/qmacstyle.qdoc +++ b/src/widgets/styles/qmacstyle.qdoc @@ -143,45 +143,6 @@ \reimp */ -/*! - \enum QMacStyle::FocusRectPolicy - - This type is used to signify a widget's focus rectangle policy. - - \value FocusEnabled show a focus rectangle when the widget has focus. - \value FocusDisabled never show a focus rectangle for the widget. - \value FocusDefault show a focus rectangle when the widget has - focus and the widget is a QSpinWidget, QDateTimeEdit, QLineEdit, - QListBox, QListView, editable QTextEdit, or one of their - subclasses. -*/ - -/*! \fn void QMacStyle::setFocusRectPolicy(QWidget *w, FocusRectPolicy policy) - \obsolete - Sets the focus rectangle policy of \a w. The \a policy can be one of - \l{QMacStyle::FocusRectPolicy}. - - This is now simply an interface to the Qt::WA_MacShowFocusRect attribute and the - FocusDefault value does nothing anymore. If you want to set a widget back - to its default value, you must save the old value of the attribute before - you change it. - - \sa focusRectPolicy(), QWidget::setAttribute() -*/ - -/*! \fn QMacStyle::FocusRectPolicy QMacStyle::focusRectPolicy(const QWidget *w) - \obsolete - Returns the focus rectangle policy for the widget \a w. - - The focus rectangle policy can be one of \l{QMacStyle::FocusRectPolicy}. - - In 4.3 and up this function will simply test for the - Qt::WA_MacShowFocusRect attribute and will never return - QMacStyle::FocusDefault. - - \sa setFocusRectPolicy(), QWidget::testAttribute() -*/ - /*! \fn void QMacStyle::setWidgetSizePolicy(const QWidget *widget, WidgetSizePolicy policy) \obsolete diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 007ce20175..cc895e2c33 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -84,6 +84,7 @@ #include <qtoolbutton.h> #include <qtreeview.h> #include <qtableview.h> +#include <qoperatingsystemversion.h> #include <qwizard.h> #include <qdebug.h> #include <qlibrary.h> @@ -1016,7 +1017,7 @@ static QAquaWidgetSize qt_aqua_guess_size(const QWidget *widg, QSize large, QSiz void QMacStylePrivate::drawFocusRing(QPainter *p, const QRect &targetRect, int hMargin, int vMargin, qreal radius) const { - qreal pixelRatio = p->device()->devicePixelRatioF(); + const qreal pixelRatio = p->device()->devicePixelRatioF(); static const QString keyFormat = QLatin1String("$qt_focusring%1-%2-%3-%4"); const QString &key = keyFormat.arg(hMargin).arg(vMargin).arg(radius).arg(pixelRatio); QPixmap focusRingPixmap; @@ -1027,20 +1028,38 @@ void QMacStylePrivate::drawFocusRing(QPainter *p, const QRect &targetRect, int h focusRingPixmap.fill(Qt::transparent); focusRingPixmap.setDevicePixelRatio(pixelRatio); { + const CGFloat focusRingWidth = radius > 0 ? 3.5 : 6; QMacAutoReleasePool pool; + QMacCGContext ctx(&focusRingPixmap); + CGContextBeginTransparencyLayer(ctx, NULL); + CGContextSetAlpha(ctx, 0.5); // As applied to the stroke color below + + [NSGraphicsContext saveGraphicsState]; + [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithCGContext:ctx + flipped:NO]]; + CGRect focusRingRect = CGRectMake(hMargin, vMargin, size, size); NSBezierPath *focusRingPath; - if (radius > 0) - focusRingPath = [NSBezierPath bezierPathWithRoundedRect:NSMakeRect(hMargin, vMargin, size, size) + if (radius > 0) { + const CGFloat roundedRectInset = -1.5; + focusRingPath = [NSBezierPath bezierPathWithRoundedRect:CGRectInset(focusRingRect, roundedRectInset, roundedRectInset) xRadius:radius yRadius:radius]; - else - focusRingPath = [NSBezierPath bezierPathWithRect:NSMakeRect(hMargin, vMargin, size, size)]; - [NSGraphicsContext saveGraphicsState]; - QMacCGContext gc(&focusRingPixmap); - [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:(CGContextRef)gc - flipped:NO]]; - NSSetFocusRingStyle(NSFocusRingOnly); - [focusRingPath fill]; + } else { + const CGFloat outerClipInset = -focusRingWidth / 2; + NSBezierPath *focusRingClipPath = [NSBezierPath bezierPathWithRect:CGRectInset(focusRingRect, outerClipInset, outerClipInset)]; + const CGFloat innerClipInset = 1; + NSBezierPath *focusRingInnerClipPath = [NSBezierPath bezierPathWithRect:CGRectInset(focusRingRect, innerClipInset, innerClipInset)]; + [focusRingClipPath appendBezierPath:focusRingInnerClipPath.bezierPathByReversingPath]; + [focusRingClipPath setClip]; + focusRingPath = [NSBezierPath bezierPathWithRect:focusRingRect]; + focusRingPath.lineJoinStyle = NSRoundLineJoinStyle; + } + + focusRingPath.lineWidth = focusRingWidth; + [[NSColor keyboardFocusIndicatorColor] setStroke]; + [focusRingPath stroke]; + + CGContextEndTransparencyLayer(ctx); [NSGraphicsContext restoreGraphicsState]; } QPixmapCache::insert(key, focusRingPixmap); @@ -1312,8 +1331,6 @@ void QMacStylePrivate::initComboboxBdi(const QStyleOptionComboBox *combo, HIThem bdi->adornment = kThemeAdornmentFocus; if (combo->activeSubControls & QStyle::SC_ComboBoxArrow) bdi->state = kThemeStatePressed; - else if (tds == kThemeStateInactive && QSysInfo::MacintoshVersion < QSysInfo::MV_10_10) - bdi->state = kThemeStateActive; else bdi->state = tds; @@ -1634,7 +1651,7 @@ void QMacStylePrivate::getSliderInfo(QStyle::ComplexControl cc, const QStyleOpti || slider->tickPosition == QSlider::TicksBothSides; tdi->bounds = qt_hirectForQRect(slider->rect); - if (isScrollbar || QSysInfo::MacintoshVersion < QSysInfo::MV_10_10) { + if (isScrollbar) { tdi->min = slider->minimum; tdi->max = slider->maximum; tdi->value = slider->sliderPosition; @@ -1946,7 +1963,6 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD const bool button = opt->type == QStyleOption::SO_Button; const bool viewItem = opt->type == QStyleOption::SO_ViewItem; const bool pressed = bdi->state == kThemeStatePressed; - const bool usingYosemiteOrLater = QSysInfo::MacintoshVersion >= QSysInfo::MV_10_10; if (button && pressed) { if (bdi->kind == kThemePushButton) { @@ -1985,7 +2001,7 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD HIRect newRect = CGRectMake(xoff, yoff, macRect.size.width, macRect.size.height); if (button && pressed) bdi->state = kThemeStateActive; - else if (usingYosemiteOrLater && viewItem) + else if (viewItem) bdi->state = kThemeStateInactive; HIThemeDrawButton(&newRect, bdi, cg, kHIThemeOrientationNormal, 0); } @@ -1993,34 +2009,7 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD if (!combo && !button && bdi->value == kThemeButtonOff) { pm = activePixmap; - } else if (!usingYosemiteOrLater && (combo || button)) { - QImage image = activePixmap.toImage(); - - for (int y = 0; y < height; ++y) { - QRgb *scanLine = reinterpret_cast<QRgb *>(image.scanLine(y)); - - for (int x = 0; x < width; ++x) { - QRgb &pixel = scanLine[x]; - - int darkest = qRed(pixel); - int mid = qGreen(pixel); - int lightest = qBlue(pixel); - - if (darkest > mid) - qSwap(darkest, mid); - if (mid > lightest) - qSwap(mid, lightest); - if (darkest > mid) - qSwap(darkest, mid); - - int gray = (mid + 2 * lightest) / 3; - if (pressed) - gray *= 0.88; - pixel = qRgba(gray, gray, gray, qAlpha(pixel)); - } - } - pm = QPixmap::fromImage(image); - } else if ((usingYosemiteOrLater && combo && !editableCombo) || button) { + } else if ((combo && !editableCombo) || button) { QCocoaWidget cw = cocoaWidgetFromHIThemeButtonKind(bdi->kind); NSButton *bc = (NSButton *)cocoaControl(cw); [bc highlight:pressed]; @@ -2034,7 +2023,7 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD rect.adjust(0, 0, -5, 0); drawNSViewInRect(cw, bc, rect, p); return; - } else if (usingYosemiteOrLater && (editableCombo || viewItem)) { + } else if (editableCombo || viewItem) { QImage image = activePixmap.toImage(); for (int y = 0; y < height; ++y) { @@ -3100,23 +3089,6 @@ QPixmap QMacStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOpt return icon.pixmap(qt_getWindow(widget), QSize(size, size)); } -void QMacStyle::setFocusRectPolicy(QWidget *w, FocusRectPolicy policy) -{ - switch (policy) { - case FocusDefault: - break; - case FocusEnabled: - case FocusDisabled: - w->setAttribute(Qt::WA_MacShowFocusRect, policy == FocusEnabled); - break; - } -} - -QMacStyle::FocusRectPolicy QMacStyle::focusRectPolicy(const QWidget *w) -{ - return w->testAttribute(Qt::WA_MacShowFocusRect) ? FocusEnabled : FocusDisabled; -} - void QMacStyle::setWidgetSizePolicy(const QWidget *widget, WidgetSizePolicy policy) { QWidget *wadget = const_cast<QWidget *>(widget); @@ -3317,32 +3289,60 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai } break; case PE_IndicatorMenuCheckMark: { - const int checkw = 8; - const int checkh = 8; - const int xoff = qMax(0, (opt->rect.width() - checkw) / 2); - const int yoff = qMax(0, (opt->rect.width() - checkh) / 2); - const int x1 = xoff + opt->rect.x(); - const int y1 = yoff + opt->rect.y() + checkw/2; - const int x2 = xoff + opt->rect.x() + checkw/4; - const int y2 = yoff + opt->rect.y() + checkh; - const int x3 = xoff + opt->rect.x() + checkw; - const int y3 = yoff + opt->rect.y(); - - QVector<QLineF> a(2); - a << QLineF(x1, y1, x2, y2); - a << QLineF(x2, y2, x3, y3); - if (opt->palette.currentColorGroup() == QPalette::Active) { - if (opt->state & State_On) - p->setPen(QPen(opt->palette.highlightedText().color(), 3)); - else - p->setPen(QPen(opt->palette.text().color(), 3)); - } else { - p->setPen(QPen(QColor(100, 100, 100), 3)); - } - p->save(); - p->setRenderHint(QPainter::Antialiasing); - p->drawLines(a); - p->restore(); + if (!(opt->state & State_On)) + break; + QColor pc; + if (opt->state & State_Selected) + pc = opt->palette.highlightedText().color(); + else + pc = opt->palette.text().color(); + QCFType<CGColorRef> checkmarkColor = CGColorCreateGenericRGB(static_cast<CGFloat>(pc.redF()), + static_cast<CGFloat>(pc.greenF()), + static_cast<CGFloat>(pc.blueF()), + static_cast<CGFloat>(pc.alphaF())); + // kCTFontUIFontSystem and others give the same result + // as kCTFontUIFontMenuItemMark. However, the latter is + // more reminiscent to HITheme's kThemeMenuItemMarkFont. + // See also the font for small- and mini-sized widgets, + // where we end up using the generic system font type. + const CTFontUIFontType fontType = (opt->state & State_Mini) ? kCTFontUIFontMiniSystem : + (opt->state & State_Small) ? kCTFontUIFontSmallSystem : + kCTFontUIFontMenuItemMark; + // Similarly for the font size, where there is a small difference + // between regular combobox and item view items, and and menu items. + // However, we ignore any difference for small- and mini-sized widgets. + const CGFloat fontSize = fontType == kCTFontUIFontMenuItemMark ? opt->fontMetrics.height() : 0.0; + QCFType<CTFontRef> checkmarkFont = CTFontCreateUIFontForLanguage(fontType, fontSize, NULL); + + CGContextSaveGState(cg); + CGContextSetShouldSmoothFonts(cg, NO); // Same as HITheme and Cocoa menu checkmarks + + // Baseline alignment tweaks for QComboBox and QMenu + const CGFloat vOffset = (opt->state & State_Mini) ? 0.0 : + (opt->state & State_Small) ? 1.0 : + 0.75; + + CGContextTranslateCTM(cg, 0, opt->rect.bottom()); + CGContextScaleCTM(cg, 1, -1); + // Translate back to the original position and add rect origin and offset + CGContextTranslateCTM(cg, opt->rect.x(), vOffset); + + // CTFont has severe difficulties finding the checkmark character among its + // glyphs. Fortunately, CTLine knows its ways inside the Cocoa labyrinth. + static const CFStringRef keys[] = { kCTFontAttributeName, kCTForegroundColorAttributeName }; + static const int numValues = sizeof(keys) / sizeof(keys[0]); + const CFTypeRef values[] = { (CFTypeRef)checkmarkFont, (CFTypeRef)checkmarkColor }; + Q_STATIC_ASSERT((sizeof(values) / sizeof(values[0])) == numValues); + QCFType<CFDictionaryRef> attributes = CFDictionaryCreate(kCFAllocatorDefault, (const void **)keys, (const void **)values, + numValues, NULL, NULL); + // U+2713: CHECK MARK + QCFType<CFAttributedStringRef> checkmarkString = CFAttributedStringCreate(kCFAllocatorDefault, (CFStringRef)@"\u2713", attributes); + QCFType<CTLineRef> line = CTLineCreateWithAttributedString(checkmarkString); + + CTLineDraw((CTLineRef)line, cg); + CGContextFlush(cg); // CTLineDraw's documentation says it doesn't flush + + CGContextRestoreGState(cg); break; } case PE_IndicatorViewItemCheck: case PE_IndicatorRadioButton: @@ -3581,7 +3581,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter QWindow *window = w && w->window() ? w->window()->windowHandle() : QStyleHelper::styleObjectWindow(opt->styleObject); const_cast<QMacStylePrivate *>(d)->resolveCurrentNSView(window); - const bool usingYosemiteOrLater = QSysInfo::MacintoshVersion >= QSysInfo::MV_10_10; switch (ce) { case CE_HeaderSection: if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) { @@ -3802,10 +3801,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter // takes precedence over a normal default button if (btn->features & QStyleOptionButton::AutoDefaultButton && opt->state & State_Active && opt->state & State_HasFocus) { - if (usingYosemiteOrLater) - d->autoDefaultButton = opt->styleObject; - else - d->setAutoDefaultButton(opt->styleObject); + d->autoDefaultButton = opt->styleObject; } else if (d->autoDefaultButton == opt->styleObject) { d->setAutoDefaultButton(0); } @@ -3813,8 +3809,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter if (!d->autoDefaultButton) { if (btn->features & QStyleOptionButton::DefaultButton && opt->state & State_Active) { d->defaultButton = opt->styleObject; - if (!usingYosemiteOrLater && !d->animation(opt->styleObject)) - d->startAnimation(new QStyleAnimation(opt->styleObject)); } else if (d->defaultButton == opt->styleObject) { if (QStyleAnimation *animation = d->animation(opt->styleObject)) { animation->updateTarget(); @@ -3835,42 +3829,18 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter HIThemeButtonDrawInfo bdi; d->initHIThemePushButton(btn, w, tds, &bdi); - if (usingYosemiteOrLater) { - if (!hasMenu) { - // HITheme is not drawing a nice focus frame around buttons. - // We'll do it ourselves further down. - bdi.adornment &= ~kThemeAdornmentFocus; - - // We can't rely on an animation existing to test for the default look. That means a bit - // more logic (notice that the logic is slightly different for the bevel and the label). - if (tds == kThemeStateActive - && (btn->features & QStyleOptionButton::DefaultButton - || (btn->features & QStyleOptionButton::AutoDefaultButton - && d->autoDefaultButton == btn->styleObject))) - bdi.adornment |= kThemeAdornmentDefault; - } - } else { - // the default button animation is paused meanwhile any button - // is pressed or an auto-default button is animated instead - if (QStyleAnimation *defaultAnimation = d->animation(d->defaultButton)) { - if (d->pressedButton || d->autoDefaultButton) { - if (defaultAnimation->state() == QStyleAnimation::Running) { - defaultAnimation->pause(); - defaultAnimation->updateTarget(); - } - } else if (defaultAnimation->state() == QStyleAnimation::Paused) { - defaultAnimation->resume(); - } - } - - if (!d->pressedButton) { - QStyleAnimation* animation = d->animation(opt->styleObject); - if (animation && animation->state() == QStyleAnimation::Running) { - bdi.adornment |= kThemeAdornmentDefault; - bdi.animation.time.start = d->defaultButtonStart; - bdi.animation.time.current = CFAbsoluteTimeGetCurrent(); - } - } + if (!hasMenu) { + // HITheme is not drawing a nice focus frame around buttons. + // We'll do it ourselves further down. + bdi.adornment &= ~kThemeAdornmentFocus; + + // We can't rely on an animation existing to test for the default look. That means a bit + // more logic (notice that the logic is slightly different for the bevel and the label). + if (tds == kThemeStateActive + && (btn->features & QStyleOptionButton::DefaultButton + || (btn->features & QStyleOptionButton::AutoDefaultButton + && d->autoDefaultButton == btn->styleObject))) + bdi.adornment |= kThemeAdornmentDefault; } // Unlike Carbon, we want the button to always be drawn inside its bounds. @@ -3888,7 +3858,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter newRect.size.width -= QMacStylePrivate::PushButtonRightOffset - 4; } - if (hasMenu && usingYosemiteOrLater && bdi.kind != kThemeBevelButton) { + if (hasMenu && bdi.kind != kThemeBevelButton) { QCocoaWidget cw = cocoaWidgetFromHIThemeButtonKind(bdi.kind); cw.first = QCocoaPullDownButton; NSPopUpButton *pdb = (NSPopUpButton *)d->cocoaControl(cw); @@ -3902,7 +3872,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter else HIThemeDrawButton(&newRect, &bdi, cg, kHIThemeOrientationNormal, 0); - if (usingYosemiteOrLater && btn->state & State_HasFocus) { + if (btn->state & State_HasFocus) { CGRect focusRect = newRect; if (bdi.kind == kThemePushButton) focusRect.size.height += 1; // Another thing HITheme and Cocoa seem to disagree about. @@ -3932,7 +3902,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter d->drawFocusRing(p, focusTargetRect.adjusted(-hMargin, -vMargin, hMargin, vMargin), hMargin, vMargin, radius); } - if (hasMenu && (!usingYosemiteOrLater || bdi.kind == kThemeBevelButton)) { + if (hasMenu && bdi.kind == kThemeBevelButton) { int mbi = proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, w); QRect ir = btn->rect; int arrowXOffset = bdi.kind == kThemePushButton ? 6 : @@ -3973,7 +3943,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter bool hasIcon = !btn.icon.isNull(); bool hasText = !btn.text.isEmpty(); - if (!hasMenu && QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_10) { + if (!hasMenu) { if (tds == kThemeStatePressed || (tds == kThemeStateActive && ((btn.features & QStyleOptionButton::DefaultButton && !d->autoDefaultButton) @@ -4077,10 +4047,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { QStyleOptionComboBox comboCopy = *cb; comboCopy.direction = Qt::LeftToRight; - if (opt->state & QStyle::State_Small) - comboCopy.rect.translate(0, w ? 0 : (QSysInfo::macVersion() >= QSysInfo::MV_10_10 ? 0 : -2)); // Supports Qt Quick Controls - else if (QSysInfo::macVersion() == QSysInfo::MV_10_9) - comboCopy.rect.translate(0, 1); QCommonStyle::drawControl(CE_ComboBoxLabel, &comboCopy, p, w); } break; @@ -4143,12 +4109,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter tdi.adornment = kHIThemeTabAdornmentNone; tdi.kind = kHIThemeTabKindNormal; - if (!usingYosemiteOrLater) { - if (!verticalTabs) - tabRect.setY(tabRect.y() - 1); - else - tabRect.setX(tabRect.x() - 1); - } QStyleOptionTab::TabPosition tp = tabOpt->position; QStyleOptionTab::SelectedPosition sp = tabOpt->selectedPosition; if (tabOpt->direction == Qt::RightToLeft && !verticalTabs) { @@ -4212,15 +4172,13 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter QStyleOptionTab myTab = *tab; ThemeTabDirection ttd = getTabDirection(myTab.shape); bool verticalTabs = ttd == kThemeTabWest || ttd == kThemeTabEast; - bool selected = (myTab.state & QStyle::State_Selected); // Check to see if we use have the same as the system font // (QComboMenuItem is internal and should never be seen by the // outside world, unless they read the source, in which case, it's // their own fault). bool nonDefaultFont = p->font() != qt_app_fonts_hash()->value("QComboMenuItem"); - bool isSelectedAndNeedsShadow = selected && !usingYosemiteOrLater; - if (isSelectedAndNeedsShadow || verticalTabs || nonDefaultFont || !tab->icon.isNull() + if (verticalTabs || nonDefaultFont || !tab->icon.isNull() || !myTab.leftButtonSize.isEmpty() || !myTab.rightButtonSize.isEmpty()) { int heightOffset = 0; if (verticalTabs) { @@ -4231,7 +4189,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter } myTab.rect.setHeight(myTab.rect.height() + heightOffset); - if (myTab.documentMode || isSelectedAndNeedsShadow) { + if (myTab.documentMode) { p->save(); rotateTabPainter(p, myTab.shape, myTab.rect); @@ -4427,61 +4385,27 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter p->setPen(mi->palette.buttonText().color()); if (mi->checked) { - // Use the HIThemeTextInfo foo to draw the check mark correctly, if we do it, - // we somehow need to use a special encoding as it doesn't look right with our - // drawText(). - p->save(); - CGContextSetShouldAntialias(cg, true); - CGContextSetShouldSmoothFonts(cg, true); - QColor textColor = p->pen().color(); - CGFloat colorComp[] = { static_cast<CGFloat>(textColor.redF()), static_cast<CGFloat>(textColor.greenF()), - static_cast<CGFloat>(textColor.blueF()), static_cast<CGFloat>(textColor.alphaF()) }; - CGContextSetFillColorSpace(cg, qt_mac_genericColorSpace()); - CGContextSetFillColor(cg, colorComp); - HIThemeTextInfo tti; - tti.version = qt_mac_hitheme_version; - tti.state = tds; - if (active && enabled) - tti.state = kThemeStatePressed; - switch (widgetSize) { - case QAquaSizeUnknown: - case QAquaSizeLarge: - tti.fontID = kThemeMenuItemMarkFont; - break; - case QAquaSizeSmall: - tti.fontID = kThemeSmallSystemFont; - break; - case QAquaSizeMini: - tti.fontID = kThemeMiniSystemFont; - break; - } - tti.horizontalFlushness = kHIThemeTextHorizontalFlushLeft; - tti.verticalFlushness = kHIThemeTextVerticalFlushCenter; - tti.options = kHIThemeTextBoxOptionNone; - tti.truncationPosition = kHIThemeTextTruncationNone; - tti.truncationMaxLines = 1; - QCFString checkmark; -#if 0 - if (mi->checkType == QStyleOptionMenuItem::Exclusive) - checkmark = QString(QChar(kDiamondUnicode)); - else -#endif - checkmark = QString(QChar(kCheckUnicode)); - int mw = checkcol + macItemFrame; - int mh = contentRect.height() - 2 * macItemFrame; - int xp = contentRect.x(); - xp += macItemFrame; - CGFloat outWidth, outHeight, outBaseline; - HIThemeGetTextDimensions(checkmark, 0, &tti, &outWidth, &outHeight, - &outBaseline); + QStyleOption checkmarkOpt; + checkmarkOpt.initFrom(w); + + const int mw = checkcol + macItemFrame; + const int mh = contentRect.height() + macItemFrame; + const int xp = contentRect.x() + macItemFrame; + checkmarkOpt.rect = QRect(xp, contentRect.y() - checkmarkOpt.fontMetrics.descent(), mw, mh); + + checkmarkOpt.state |= State_On; // Always on. Never rendered when off. + checkmarkOpt.state.setFlag(State_Selected, active); + checkmarkOpt.state.setFlag(State_Enabled, enabled); if (widgetSize == QAquaSizeMini) - outBaseline += 1; - QRect r(xp, contentRect.y(), mw, mh); - r.translate(0, p->fontMetrics().ascent() - int(outBaseline) + 1); - HIRect bounds = qt_hirectForQRect(r); - HIThemeDrawTextBox(checkmark, &bounds, &tti, - cg, kHIThemeOrientationNormal); - p->restore(); + checkmarkOpt.state |= State_Mini; + else if (widgetSize == QAquaSizeSmall) + checkmarkOpt.state |= State_Small; + + // We let drawPrimitive(PE_IndicatorMenuCheckMark) pick the right color + checkmarkOpt.palette.setColor(QPalette::HighlightedText, p->pen().color()); + checkmarkOpt.palette.setColor(QPalette::Text, p->pen().color()); + + proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &checkmarkOpt, p, w); } if (!mi->icon.isNull()) { QIcon::Mode mode = (mi->state & State_Enabled) ? QIcon::Normal @@ -4654,7 +4578,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter tdi.value = pb->progress; tdi.attributes = vertical ? 0 : kThemeTrackHorizontal; - if (isIndeterminate || (tdi.value < tdi.max && !usingYosemiteOrLater)) { + if (isIndeterminate) { if (QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject))) tdi.trackInfo.progress.phase = animation->animationStep(); else if (opt->styleObject) @@ -4736,8 +4660,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter HIThemeSplitterDrawInfo sdi; sdi.version = qt_mac_hitheme_version; sdi.state = tds; - sdi.adornment = qt_mac_is_metal(w) || usingYosemiteOrLater ? - kHIThemeSplitterAdornmentMetal : kHIThemeSplitterAdornmentNone; + sdi.adornment = kHIThemeSplitterAdornmentMetal; HIRect hirect = qt_hirectForQRect(opt->rect); HIThemeDrawPaneSplitter(&hirect, &sdi, cg, kHIThemeOrientationNormal); } else { @@ -5287,7 +5210,6 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex QWindow *window = widget && widget->window() ? widget->window()->windowHandle() : QStyleHelper::styleObjectWindow(opt->styleObject); const_cast<QMacStylePrivate *>(d)->resolveCurrentNSView(window); - const bool usingYosemiteOrLater = QSysInfo::MacintoshVersion >= QSysInfo::MV_10_10; switch (cc) { case CC_Slider: case CC_ScrollBar: @@ -5380,7 +5302,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex int oldMin = styleObject->property("_q_stylemin").toInt(); int oldMax = styleObject->property("_q_stylemax").toInt(); QRect oldRect = styleObject->property("_q_stylerect").toRect(); - int oldState = styleObject->property("_q_stylestate").toInt(); + QStyle::State oldState = static_cast<QStyle::State>(styleObject->property("_q_stylestate").value<QStyle::State::Int>()); uint oldActiveControls = styleObject->property("_q_stylecontrols").toUInt(); // a scrollbar is transient when the scrollbar itself and @@ -5403,7 +5325,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex styleObject->setProperty("_q_stylemin", slider->minimum); styleObject->setProperty("_q_stylemax", slider->maximum); styleObject->setProperty("_q_stylerect", slider->rect); - styleObject->setProperty("_q_stylestate", static_cast<int>(slider->state)); + styleObject->setProperty("_q_stylestate", static_cast<QStyle::State::Int>(slider->state)); styleObject->setProperty("_q_stylecontrols", static_cast<uint>(slider->activeSubControls)); QScrollbarStyleAnimation *anim = qobject_cast<QScrollbarStyleAnimation *>(d->animation(styleObject)); @@ -5532,7 +5454,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex } else { d->stopAnimation(opt->styleObject); - if (usingYosemiteOrLater && cc == CC_Slider) { + if (cc == CC_Slider) { // Fix min and max positions. (See also getSliderInfo() // for the slider values adjustments.) // HITheme seems to have forgotten how to render @@ -5595,22 +5517,20 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex if (cc == CC_Slider && slider->subControls & SC_SliderTickmarks) { HIRect bounds; - if (usingYosemiteOrLater) { - // As part of fixing the min and max positions, - // we need to adjust the tickmarks as well - bounds = tdi.bounds; - if (slider->orientation == Qt::Horizontal) { - tdi.bounds.size.width += 2; - tdi.bounds.origin.x -= 1; - if (tdi.trackInfo.slider.thumbDir == kThemeThumbUpward) - tdi.bounds.origin.y -= 2; - } else { - tdi.bounds.size.height += 3; - tdi.bounds.origin.y -= 3; - tdi.bounds.origin.y += 1; - if (tdi.trackInfo.slider.thumbDir == kThemeThumbUpward) // pointing left - tdi.bounds.origin.x -= 2; - } + // As part of fixing the min and max positions, + // we need to adjust the tickmarks as well + bounds = tdi.bounds; + if (slider->orientation == Qt::Horizontal) { + tdi.bounds.size.width += 2; + tdi.bounds.origin.x -= 1; + if (tdi.trackInfo.slider.thumbDir == kThemeThumbUpward) + tdi.bounds.origin.y -= 2; + } else { + tdi.bounds.size.height += 3; + tdi.bounds.origin.y -= 3; + tdi.bounds.origin.y += 1; + if (tdi.trackInfo.slider.thumbDir == kThemeThumbUpward) // pointing left + tdi.bounds.origin.x -= 2; } if (qt_mac_is_metal(widget)) { @@ -5634,10 +5554,9 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex cg, kHIThemeOrientationNormal); tdi.trackInfo.slider.thumbDir = kThemeThumbUpward; - if (usingYosemiteOrLater) { - if (slider->orientation == Qt::Vertical) - tdi.bounds.origin.x -= 2; - } + // 10.10 and above need a slight shift + if (slider->orientation == Qt::Vertical) + tdi.bounds.origin.x -= 2; HIThemeDrawTrackTickMarks(&tdi, numMarks, cg, kHIThemeOrientationNormal); @@ -5649,11 +5568,10 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex kHIThemeOrientationNormal); } - if (usingYosemiteOrLater) - tdi.bounds = bounds; + tdi.bounds = bounds; } - if (usingYosemiteOrLater && cc == CC_Slider) { + if (cc == CC_Slider) { // Still as part of fixing the min and max positions, // we also adjust the knob position. We can do this // because it's rendered separately from the track. @@ -5745,11 +5663,11 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex HIThemeButtonDrawInfo bdi; d->initComboboxBdi(combo, &bdi, widget, tds); HIRect rect = qt_hirectForQRect(combo->rect); - if (combo->editable && usingYosemiteOrLater) + if (combo->editable) rect.origin.y += tds == kThemeStateInactive ? 1 : 2; if (tds != kThemeStateInactive) QMacStylePrivate::drawCombobox(rect, bdi, p); - else if (!widget && combo->editable && usingYosemiteOrLater) { + else if (!widget && combo->editable) { QCocoaWidget cw = cocoaWidgetFromHIThemeButtonKind(bdi.kind); NSView *cb = d->cocoaControl(cw); QRect r = combo->rect.adjusted(3, 0, 0, 0); @@ -5931,31 +5849,23 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex drawToolbarButtonArrow(tb->rect, tds, cg); } if (tb->state & State_On) { - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_10) { - 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 { - static QPixmap pm(QLatin1String(":/qt-project.org/mac/style/images/leopard-unified-toolbar-on.png")); - p->save(); - p->setRenderHint(QPainter::SmoothPixmapTransform); - QStyleHelper::drawBorderPixmap(pm, p, tb->rect, 2, 2, 2, 2); - p->restore(); - } + 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); } proxy()->drawControl(CE_ToolButtonLabel, opt, p, widget); } else { @@ -6295,8 +6205,8 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op switch (sc) { case SC_ComboBoxEditField:{ ret = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi); - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_10) - ret.setHeight(ret.height() - 1); + // 10.10 and above need a slight shift + ret.setHeight(ret.height() - 1); break; } case SC_ComboBoxArrow:{ ret = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi); @@ -6754,7 +6664,7 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, case CT_ComboBox: { sz.rwidth() += 50; const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt); - if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_10 || (cb && !cb->editable)) + if (cb && !cb->editable) sz.rheight() += 2; break; } diff --git a/src/widgets/styles/qmacstyle_mac_p.h b/src/widgets/styles/qmacstyle_mac_p.h index 3642424a14..98a9063bf0 100644 --- a/src/widgets/styles/qmacstyle_mac_p.h +++ b/src/widgets/styles/qmacstyle_mac_p.h @@ -100,10 +100,6 @@ public: virtual int styleHint(StyleHint sh, const QStyleOption *opt = 0, const QWidget *w = 0, QStyleHintReturn *shret = 0) const; - enum FocusRectPolicy { FocusEnabled, FocusDisabled, FocusDefault }; - static void setFocusRectPolicy(QWidget *w, FocusRectPolicy policy); - static FocusRectPolicy focusRectPolicy(const QWidget *w); - enum WidgetSizePolicy { SizeSmall, SizeLarge, SizeMini, SizeDefault }; diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp index 7f52d3d2f3..972deef150 100644 --- a/src/widgets/styles/qwindowsvistastyle.cpp +++ b/src/widgets/styles/qwindowsvistastyle.cpp @@ -39,6 +39,7 @@ #include "qwindowsvistastyle_p.h" #include "qwindowsvistastyle_p_p.h" +#include <qoperatingsystemversion.h> #include <qscreen.h> #include <qwindow.h> #include <private/qstyleanimation_p.h> @@ -1752,7 +1753,7 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle theme.stateId = stateId; d->drawBackground(theme); - if (QSysInfo::WindowsVersion < QSysInfo::WV_WINDOWS8) { + if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows8) { const QRect gripperBounds = QWindowsXPStylePrivate::scrollBarGripperBounds(flags, widget, &theme); // Draw gripper if there is enough space if (!gripperBounds.isEmpty() && flags & State_Enabled) { |