98 #include <qdatetimeedit.h> |
98 #include <qdatetimeedit.h> |
99 #include <qmath.h> |
99 #include <qmath.h> |
100 #include <QtGui/qgraphicsproxywidget.h> |
100 #include <QtGui/qgraphicsproxywidget.h> |
101 #include <QtGui/qgraphicsview.h> |
101 #include <QtGui/qgraphicsview.h> |
102 #include <private/qt_cocoa_helpers_mac_p.h> |
102 #include <private/qt_cocoa_helpers_mac_p.h> |
|
103 #include "qmacstyle_mac_p.h" |
103 #include <private/qstylehelper_p.h> |
104 #include <private/qstylehelper_p.h> |
104 |
105 |
105 QT_BEGIN_NAMESPACE |
106 QT_BEGIN_NAMESPACE |
106 |
|
107 extern QRegion qt_mac_convert_mac_region(RgnHandle); //qregion_mac.cpp |
|
108 |
107 |
109 // The following constants are used for adjusting the size |
108 // The following constants are used for adjusting the size |
110 // of push buttons so that they are drawn inside their bounds. |
109 // of push buttons so that they are drawn inside their bounds. |
111 static const int PushButtonLeftOffset = 6; |
110 const int QMacStylePrivate::PushButtonLeftOffset = 6; |
112 static const int PushButtonTopOffset = 4; |
111 const int QMacStylePrivate::PushButtonTopOffset = 4; |
113 static const int PushButtonRightOffset = 12; |
112 const int QMacStylePrivate::PushButtonRightOffset = 12; |
114 static const int PushButtonBottomOffset = 12; |
113 const int QMacStylePrivate::PushButtonBottomOffset = 12; |
115 static const int MiniButtonH = 26; |
114 const int QMacStylePrivate::MiniButtonH = 26; |
116 static const int SmallButtonH = 30; |
115 const int QMacStylePrivate::SmallButtonH = 30; |
117 static const int BevelButtonW = 50; |
116 const int QMacStylePrivate::BevelButtonW = 50; |
118 static const int BevelButtonH = 22; |
117 const int QMacStylePrivate::BevelButtonH = 22; |
119 static const int PushButtonContentPadding = 6; |
118 const int QMacStylePrivate::PushButtonContentPadding = 6; |
120 |
119 |
121 // These colors specify the titlebar gradient colors on |
120 // These colors specify the titlebar gradient colors on |
122 // Leopard. Ideally we should get them from the system. |
121 // Leopard. Ideally we should get them from the system. |
123 static const QColor titlebarGradientActiveBegin(220, 220, 220); |
122 static const QColor titlebarGradientActiveBegin(220, 220, 220); |
124 static const QColor titlebarGradientActiveEnd(151, 151, 151); |
123 static const QColor titlebarGradientActiveEnd(151, 151, 151); |
130 // Gradient colors used for the dock widget title bar and |
129 // Gradient colors used for the dock widget title bar and |
131 // non-unifed tool bar bacground. |
130 // non-unifed tool bar bacground. |
132 static const QColor mainWindowGradientBegin(240, 240, 240); |
131 static const QColor mainWindowGradientBegin(240, 240, 240); |
133 static const QColor mainWindowGradientEnd(200, 200, 200); |
132 static const QColor mainWindowGradientEnd(200, 200, 200); |
134 |
133 |
135 #if (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5) |
134 static const int DisclosureOffset = 4; |
136 enum { |
|
137 kThemePushButtonTextured = 31, |
|
138 kThemePushButtonTexturedSmall = 32, |
|
139 kThemePushButtonTexturedMini = 33 |
|
140 }; |
|
141 |
|
142 /* Search fields */ |
|
143 enum { |
|
144 kHIThemeFrameTextFieldRound = 1000, |
|
145 kHIThemeFrameTextFieldRoundSmall = 1001, |
|
146 kHIThemeFrameTextFieldRoundMini = 1002 |
|
147 }; |
|
148 #endif |
|
149 |
135 |
150 // Resolve these at run-time, since the functions was moved in Leopard. |
136 // Resolve these at run-time, since the functions was moved in Leopard. |
151 typedef HIRect * (*PtrHIShapeGetBounds)(HIShapeRef, HIRect *); |
137 typedef HIRect * (*PtrHIShapeGetBounds)(HIShapeRef, HIRect *); |
152 static PtrHIShapeGetBounds ptrHIShapeGetBounds = 0; |
138 static PtrHIShapeGetBounds ptrHIShapeGetBounds = 0; |
|
139 |
|
140 static int closeButtonSize = 12; |
|
141 |
|
142 extern QRegion qt_mac_convert_mac_region(RgnHandle); //qregion_mac.cpp |
153 |
143 |
154 static bool isVerticalTabs(const QTabBar::Shape shape) { |
144 static bool isVerticalTabs(const QTabBar::Shape shape) { |
155 return (shape == QTabBar::RoundedEast |
145 return (shape == QTabBar::RoundedEast |
156 || shape == QTabBar::TriangularEast |
146 || shape == QTabBar::TriangularEast |
157 || shape == QTabBar::RoundedWest |
147 || shape == QTabBar::RoundedWest |
158 || shape == QTabBar::TriangularWest); |
148 || shape == QTabBar::TriangularWest); |
159 } |
149 } |
160 |
|
161 static int closeButtonSize = 12; |
|
162 |
150 |
163 void drawTabCloseButton(QPainter *p, bool hover, bool active, bool selected) |
151 void drawTabCloseButton(QPainter *p, bool hover, bool active, bool selected) |
164 { |
152 { |
165 // draw background circle |
153 // draw background circle |
166 p->setRenderHints(QPainter::Antialiasing); |
154 p->setRenderHints(QPainter::Antialiasing); |
376 p->drawLine(tabRect.x(), height - 2, width, height - 2); |
364 p->drawLine(tabRect.x(), height - 2, width, height - 2); |
377 p->setPen(borderBottom); |
365 p->setPen(borderBottom); |
378 p->drawLine(tabRect.x(), height - 1, width, height - 1); |
366 p->drawLine(tabRect.x(), height - 1, width, height - 1); |
379 } |
367 } |
380 |
368 |
381 /* |
|
382 AHIG: |
|
383 Apple Human Interface Guidelines |
|
384 http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/ |
|
385 |
|
386 Builder: |
|
387 Apple Interface Builder v. 3.1.1 |
|
388 */ |
|
389 |
|
390 // this works as long as we have at most 16 different control types |
|
391 #define CT1(c) CT2(c, c) |
|
392 #define CT2(c1, c2) ((uint(c1) << 16) | uint(c2)) |
|
393 |
|
394 enum QAquaWidgetSize { QAquaSizeLarge = 0, QAquaSizeSmall = 1, QAquaSizeMini = 2, |
|
395 QAquaSizeUnknown = -1 }; |
|
396 |
|
397 #define SIZE(large, small, mini) \ |
|
398 (controlSize == QAquaSizeLarge ? (large) : controlSize == QAquaSizeSmall ? (small) : (mini)) |
|
399 |
|
400 // same as return SIZE(...) but optimized |
|
401 #define return_SIZE(large, small, mini) \ |
|
402 do { \ |
|
403 static const int sizes[] = { (large), (small), (mini) }; \ |
|
404 return sizes[controlSize]; \ |
|
405 } while (0) |
|
406 |
|
407 static int getControlSize(const QStyleOption *option, const QWidget *widget) |
369 static int getControlSize(const QStyleOption *option, const QWidget *widget) |
408 { |
370 { |
409 if (option) { |
371 if (option) { |
410 if (option->state & (QStyle::State_Small | QStyle::State_Mini)) |
372 if (option->state & (QStyle::State_Small | QStyle::State_Mini)) |
411 return (option->state & QStyle::State_Mini) ? QAquaSizeMini : QAquaSizeSmall; |
373 return (option->state & QStyle::State_Mini) ? QAquaSizeMini : QAquaSizeSmall; |
479 break; |
441 break; |
480 } |
442 } |
481 return ttd; |
443 return ttd; |
482 } |
444 } |
483 |
445 |
484 class QMacStylePrivate : public QObject |
|
485 { |
|
486 Q_OBJECT |
|
487 |
|
488 public: |
|
489 QMacStylePrivate(QMacStyle *style); |
|
490 |
|
491 // Stuff from QAquaAnimate: |
|
492 bool addWidget(QWidget *); |
|
493 void removeWidget(QWidget *); |
|
494 |
|
495 enum Animates { AquaPushButton, AquaProgressBar, AquaListViewItemOpen }; |
|
496 bool animatable(Animates, const QWidget *) const; |
|
497 void stopAnimate(Animates, QWidget *); |
|
498 void startAnimate(Animates, QWidget *); |
|
499 static ThemeDrawState getDrawState(QStyle::State flags); |
|
500 QAquaWidgetSize aquaSizeConstrain(const QStyleOption *option, const QWidget *widg, |
|
501 QStyle::ContentsType ct = QStyle::CT_CustomBase, |
|
502 QSize szHint=QSize(-1, -1), QSize *insz = 0) const; |
|
503 void getSliderInfo(QStyle::ComplexControl cc, const QStyleOptionSlider *slider, |
|
504 HIThemeTrackDrawInfo *tdi, const QWidget *needToRemoveMe); |
|
505 bool doAnimate(Animates); |
|
506 inline int animateSpeed(Animates) const { return 33; } |
|
507 |
|
508 // Utility functions |
|
509 void drawColorlessButton(const HIRect &macRect, HIThemeButtonDrawInfo *bdi, |
|
510 QPainter *p, const QStyleOption *opt) const; |
|
511 |
|
512 QSize pushButtonSizeFromContents(const QStyleOptionButton *btn) const; |
|
513 |
|
514 HIRect pushButtonContentBounds(const QStyleOptionButton *btn, |
|
515 const HIThemeButtonDrawInfo *bdi) const; |
|
516 |
|
517 void initComboboxBdi(const QStyleOptionComboBox *combo, HIThemeButtonDrawInfo *bdi, |
|
518 const QWidget *widget, const ThemeDrawState &tds); |
|
519 |
|
520 static HIRect comboboxInnerBounds(const HIRect &outerBounds, int buttonKind); |
|
521 |
|
522 static QRect comboboxEditBounds(const QRect &outerBounds, const HIThemeButtonDrawInfo &bdi); |
|
523 |
|
524 static void drawCombobox(const HIRect &outerBounds, const HIThemeButtonDrawInfo &bdi, QPainter *p); |
|
525 static void drawTableHeader(const HIRect &outerBounds, bool drawTopBorder, bool drawLeftBorder, |
|
526 const HIThemeButtonDrawInfo &bdi, QPainter *p); |
|
527 bool contentFitsInPushButton(const QStyleOptionButton *btn, HIThemeButtonDrawInfo *bdi, |
|
528 ThemeButtonKind buttonKindToCheck) const; |
|
529 void initHIThemePushButton(const QStyleOptionButton *btn, const QWidget *widget, |
|
530 const ThemeDrawState tds, |
|
531 HIThemeButtonDrawInfo *bdi) const; |
|
532 QPixmap generateBackgroundPattern() const; |
|
533 protected: |
|
534 bool eventFilter(QObject *, QEvent *); |
|
535 void timerEvent(QTimerEvent *); |
|
536 |
|
537 private slots: |
|
538 void startAnimationTimer(); |
|
539 |
|
540 public: |
|
541 QPointer<QPushButton> defaultButton; //default push buttons |
|
542 int timerID; |
|
543 QList<QPointer<QWidget> > progressBars; //existing progress bars that need animation |
|
544 |
|
545 struct ButtonState { |
|
546 int frame; |
|
547 enum { ButtonDark, ButtonLight } dir; |
|
548 } buttonState; |
|
549 UInt8 progressFrame; |
|
550 QPointer<QFocusFrame> focusWidget; |
|
551 CFAbsoluteTime defaultButtonStart; |
|
552 QMacStyle *q; |
|
553 bool mouseDown; |
|
554 }; |
|
555 |
|
556 QT_BEGIN_INCLUDE_NAMESPACE |
446 QT_BEGIN_INCLUDE_NAMESPACE |
557 #include "qmacstyle_mac.moc" |
447 #include "moc_qmacstyle_mac.cpp" |
|
448 #include "moc_qmacstyle_mac_p.cpp" |
558 QT_END_INCLUDE_NAMESPACE |
449 QT_END_INCLUDE_NAMESPACE |
559 |
450 |
560 /***************************************************************************** |
451 /***************************************************************************** |
561 External functions |
452 External functions |
562 *****************************************************************************/ |
453 *****************************************************************************/ |
1053 { |
944 { |
1054 HIRect outerBounds = qt_hirectForQRect(btn->rect); |
945 HIRect outerBounds = qt_hirectForQRect(btn->rect); |
1055 // Adjust the bounds to correct for |
946 // Adjust the bounds to correct for |
1056 // carbon not calculating the content bounds fully correct |
947 // carbon not calculating the content bounds fully correct |
1057 if (bdi->kind == kThemePushButton || bdi->kind == kThemePushButtonSmall){ |
948 if (bdi->kind == kThemePushButton || bdi->kind == kThemePushButtonSmall){ |
1058 outerBounds.origin.y += PushButtonTopOffset; |
949 outerBounds.origin.y += QMacStylePrivate::PushButtonTopOffset; |
1059 outerBounds.size.height -= PushButtonBottomOffset; |
950 outerBounds.size.height -= QMacStylePrivate::PushButtonBottomOffset; |
1060 } else if (bdi->kind == kThemePushButtonMini) { |
951 } else if (bdi->kind == kThemePushButtonMini) { |
1061 outerBounds.origin.y += PushButtonTopOffset; |
952 outerBounds.origin.y += QMacStylePrivate::PushButtonTopOffset; |
1062 } |
953 } |
1063 |
954 |
1064 HIRect contentBounds; |
955 HIRect contentBounds; |
1065 HIThemeGetButtonContentBounds(&outerBounds, bdi, &contentBounds); |
956 HIThemeGetButtonContentBounds(&outerBounds, bdi, &contentBounds); |
1066 return contentBounds; |
957 return contentBounds; |
1072 */ |
963 */ |
1073 QSize QMacStylePrivate::pushButtonSizeFromContents(const QStyleOptionButton *btn) const |
964 QSize QMacStylePrivate::pushButtonSizeFromContents(const QStyleOptionButton *btn) const |
1074 { |
965 { |
1075 QSize csz(0, 0); |
966 QSize csz(0, 0); |
1076 QSize iconSize = btn->icon.isNull() ? QSize(0, 0) |
967 QSize iconSize = btn->icon.isNull() ? QSize(0, 0) |
1077 : (btn->iconSize + QSize(PushButtonContentPadding, 0)); |
968 : (btn->iconSize + QSize(QMacStylePrivate::PushButtonContentPadding, 0)); |
1078 QRect textRect = btn->text.isEmpty() ? QRect(0, 0, 1, 1) |
969 QRect textRect = btn->text.isEmpty() ? QRect(0, 0, 1, 1) |
1079 : btn->fontMetrics.boundingRect(QRect(), Qt::AlignCenter, btn->text); |
970 : btn->fontMetrics.boundingRect(QRect(), Qt::AlignCenter, btn->text); |
1080 csz.setWidth(iconSize.width() + textRect.width() |
971 csz.setWidth(iconSize.width() + textRect.width() |
1081 + ((btn->features & QStyleOptionButton::HasMenu) |
972 + ((btn->features & QStyleOptionButton::HasMenu) |
1082 ? q->proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, 0) : 0)); |
973 ? q->proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, 0) : 0)); |
1147 // to get the dynamic choosing of button kind. |
1038 // to get the dynamic choosing of button kind. |
1148 case QAquaSizeUnknown: |
1039 case QAquaSizeUnknown: |
1149 // Choose the button kind that closest match the button rect, but at the |
1040 // Choose the button kind that closest match the button rect, but at the |
1150 // same time displays the button contents without clipping. |
1041 // same time displays the button contents without clipping. |
1151 bdi->kind = kThemeBevelButton; |
1042 bdi->kind = kThemeBevelButton; |
1152 if (btn->rect.width() >= BevelButtonW && btn->rect.height() >= BevelButtonH){ |
1043 if (btn->rect.width() >= QMacStylePrivate::BevelButtonW && btn->rect.height() >= QMacStylePrivate::BevelButtonH){ |
1153 if (widget && widget->testAttribute(Qt::WA_MacVariableSize)) { |
1044 if (widget && widget->testAttribute(Qt::WA_MacVariableSize)) { |
1154 if (btn->rect.height() <= MiniButtonH){ |
1045 if (btn->rect.height() <= QMacStylePrivate::MiniButtonH){ |
1155 if (contentFitsInPushButton(btn, bdi, kThemePushButtonMini)) |
1046 if (contentFitsInPushButton(btn, bdi, kThemePushButtonMini)) |
1156 bdi->kind = kThemePushButtonMini; |
1047 bdi->kind = kThemePushButtonMini; |
1157 } else if (btn->rect.height() <= SmallButtonH){ |
1048 } else if (btn->rect.height() <= QMacStylePrivate::SmallButtonH){ |
1158 if (contentFitsInPushButton(btn, bdi, kThemePushButtonSmall)) |
1049 if (contentFitsInPushButton(btn, bdi, kThemePushButtonSmall)) |
1159 bdi->kind = kThemePushButtonSmall; |
1050 bdi->kind = kThemePushButtonSmall; |
1160 } else if (contentFitsInPushButton(btn, bdi, kThemePushButton)) { |
1051 } else if (contentFitsInPushButton(btn, bdi, kThemePushButton)) { |
1161 bdi->kind = kThemePushButton; |
1052 bdi->kind = kThemePushButton; |
1162 } |
1053 } |
1915 if (!usePainter && qt_mac_backgroundPattern |
1806 if (!usePainter && qt_mac_backgroundPattern |
1916 && qt_mac_backgroundPattern->cacheKey() == brush.texture().cacheKey()) { |
1807 && qt_mac_backgroundPattern->cacheKey() == brush.texture().cacheKey()) { |
1917 |
1808 |
1918 painter->setClipRegion(rgn); |
1809 painter->setClipRegion(rgn); |
1919 |
1810 |
1920 CGContextRef cg = qt_mac_cg_context(target); |
1811 QCFType<CGContextRef> cg = qt_mac_cg_context(target); |
1921 CGContextSaveGState(cg); |
1812 CGContextSaveGState(cg); |
1922 HIThemeSetFill(kThemeBrushDialogBackgroundActive, 0, cg, kHIThemeOrientationInverted); |
1813 HIThemeSetFill(kThemeBrushDialogBackgroundActive, 0, cg, kHIThemeOrientationInverted); |
1923 |
1814 |
1924 const QVector<QRect> &rects = rgn.rects(); |
1815 const QVector<QRect> &rects = rgn.rects(); |
1925 for (int i = 0; i < rects.size(); ++i) { |
1816 for (int i = 0; i < rects.size(); ++i) { |
3098 if (opt->state & State_Open) |
2989 if (opt->state & State_Open) |
3099 bi.value = kThemeDisclosureDown; |
2990 bi.value = kThemeDisclosureDown; |
3100 else |
2991 else |
3101 bi.value = opt->direction == Qt::LeftToRight ? kThemeDisclosureRight : kThemeDisclosureLeft; |
2992 bi.value = opt->direction == Qt::LeftToRight ? kThemeDisclosureRight : kThemeDisclosureLeft; |
3102 bi.adornment = kThemeAdornmentNone; |
2993 bi.adornment = kThemeAdornmentNone; |
3103 HIRect hirect = qt_hirectForQRect(opt->rect); |
2994 HIRect hirect = qt_hirectForQRect(opt->rect.adjusted(DisclosureOffset,0,-DisclosureOffset,0)); |
3104 HIThemeDrawButton(&hirect, &bi, cg, kHIThemeOrientationNormal, 0); |
2995 HIThemeDrawButton(&hirect, &bi, cg, kHIThemeOrientationNormal, 0); |
3105 break; } |
2996 break; } |
3106 |
2997 |
3107 case PE_Frame: { |
2998 case PE_Frame: { |
3108 QPen oldPen = p->pen(); |
2999 QPen oldPen = p->pen(); |
3492 // Unlike Carbon, we want the button to always be drawn inside its bounds. |
3383 // Unlike Carbon, we want the button to always be drawn inside its bounds. |
3493 // Therefore, make the button a bit smaller, so that even if it got focus, |
3384 // Therefore, make the button a bit smaller, so that even if it got focus, |
3494 // the focus 'shadow' will be inside. |
3385 // the focus 'shadow' will be inside. |
3495 HIRect newRect = qt_hirectForQRect(btn->rect); |
3386 HIRect newRect = qt_hirectForQRect(btn->rect); |
3496 if (bdi.kind == kThemePushButton || bdi.kind == kThemePushButtonSmall) { |
3387 if (bdi.kind == kThemePushButton || bdi.kind == kThemePushButtonSmall) { |
3497 newRect.origin.x += PushButtonLeftOffset; |
3388 newRect.origin.x += QMacStylePrivate::PushButtonLeftOffset; |
3498 newRect.origin.y += PushButtonTopOffset; |
3389 newRect.origin.y += QMacStylePrivate::PushButtonTopOffset; |
3499 newRect.size.width -= PushButtonRightOffset; |
3390 newRect.size.width -= QMacStylePrivate::PushButtonRightOffset; |
3500 newRect.size.height -= PushButtonBottomOffset; |
3391 newRect.size.height -= QMacStylePrivate::PushButtonBottomOffset; |
3501 } else if (bdi.kind == kThemePushButtonMini) { |
3392 } else if (bdi.kind == kThemePushButtonMini) { |
3502 newRect.origin.x += PushButtonLeftOffset - 2; |
3393 newRect.origin.x += QMacStylePrivate::PushButtonLeftOffset - 2; |
3503 newRect.origin.y += PushButtonTopOffset; |
3394 newRect.origin.y += QMacStylePrivate::PushButtonTopOffset; |
3504 newRect.size.width -= PushButtonRightOffset - 4; |
3395 newRect.size.width -= QMacStylePrivate::PushButtonRightOffset - 4; |
3505 } |
3396 } |
3506 HIThemeDrawButton(&newRect, &bdi, cg, kHIThemeOrientationNormal, 0); |
3397 HIThemeDrawButton(&newRect, &bdi, cg, kHIThemeOrientationNormal, 0); |
3507 |
3398 |
3508 if (btn->features & QStyleOptionButton::HasMenu) { |
3399 if (btn->features & QStyleOptionButton::HasMenu) { |
3509 int mbi = proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, w); |
3400 int mbi = proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, w); |
3510 QRect ir = btn->rect; |
3401 QRect ir = btn->rect; |
3511 HIRect arrowRect = CGRectMake(ir.right() - mbi - PushButtonRightOffset, |
3402 HIRect arrowRect = CGRectMake(ir.right() - mbi - QMacStylePrivate::PushButtonRightOffset, |
3512 ir.height() / 2 - 4, mbi, ir.height() / 2); |
3403 ir.height() / 2 - 4, mbi, ir.height() / 2); |
3513 bool drawColorless = btn->palette.currentColorGroup() == QPalette::Active; |
3404 bool drawColorless = btn->palette.currentColorGroup() == QPalette::Active; |
3514 if (drawColorless && tds == kThemeStateInactive) |
3405 if (drawColorless && tds == kThemeStateInactive) |
3515 tds = kThemeStateActive; |
3406 tds = kThemeStateActive; |
3516 |
3407 |
3600 // Decide if the icon is should be on or off: |
3491 // Decide if the icon is should be on or off: |
3601 QIcon::State state = QIcon::Off; |
3492 QIcon::State state = QIcon::Off; |
3602 if (btn->state & State_On) |
3493 if (btn->state & State_On) |
3603 state = QIcon::On; |
3494 state = QIcon::On; |
3604 QPixmap pixmap = btn->icon.pixmap(btn->iconSize, mode, state); |
3495 QPixmap pixmap = btn->icon.pixmap(btn->iconSize, mode, state); |
3605 contentW += pixmap.width() + PushButtonContentPadding; |
3496 contentW += pixmap.width() + QMacStylePrivate::PushButtonContentPadding; |
3606 int iconLeftOffset = freeContentRect.x() + (freeContentRect.width() - contentW) / 2; |
3497 int iconLeftOffset = freeContentRect.x() + (freeContentRect.width() - contentW) / 2; |
3607 int iconTopOffset = freeContentRect.y() + (freeContentRect.height() - pixmap.height()) / 2; |
3498 int iconTopOffset = freeContentRect.y() + (freeContentRect.height() - pixmap.height()) / 2; |
3608 QRect iconDestRect(iconLeftOffset, iconTopOffset, pixmap.width(), pixmap.height()); |
3499 QRect iconDestRect(iconLeftOffset, iconTopOffset, pixmap.width(), pixmap.height()); |
3609 QRect visualIconDestRect = visualRect(btn->direction, freeContentRect, iconDestRect); |
3500 QRect visualIconDestRect = visualRect(btn->direction, freeContentRect, iconDestRect); |
3610 proxy()->drawItemPixmap(p, visualIconDestRect, Qt::AlignLeft | Qt::AlignVCenter, pixmap); |
3501 proxy()->drawItemPixmap(p, visualIconDestRect, Qt::AlignLeft | Qt::AlignVCenter, pixmap); |
3611 int newOffset = iconDestRect.x() + iconDestRect.width() |
3502 int newOffset = iconDestRect.x() + iconDestRect.width() |
3612 + PushButtonContentPadding - textRect.x(); |
3503 + QMacStylePrivate::PushButtonContentPadding - textRect.x(); |
3613 textRect.adjust(newOffset, 0, newOffset, 0); |
3504 textRect.adjust(newOffset, 0, newOffset, 0); |
3614 } |
3505 } |
3615 // Draw the text: |
3506 // Draw the text: |
3616 if (hasText) { |
3507 if (hasText) { |
3617 textRect = visualRect(btn->direction, freeContentRect, textRect); |
3508 textRect = visualRect(btn->direction, freeContentRect, textRect); |
4350 { |
4241 { |
4351 QRect rect; |
4242 QRect rect; |
4352 int controlSize = getControlSize(opt, widget); |
4243 int controlSize = getControlSize(opt, widget); |
4353 |
4244 |
4354 switch (sr) { |
4245 switch (sr) { |
|
4246 case SE_ItemViewItemText: |
|
4247 if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) { |
|
4248 int fw = proxy()->pixelMetric(PM_FocusFrameHMargin, opt, widget); |
|
4249 // We add the focusframeargin between icon and text in commonstyle |
|
4250 rect = QCommonStyle::subElementRect(sr, opt, widget); |
|
4251 if (vopt->features & QStyleOptionViewItemV2::HasDecoration) |
|
4252 rect.adjust(-fw, 0, 0, 0); |
|
4253 } |
|
4254 break; |
4355 case SE_ToolBoxTabContents: |
4255 case SE_ToolBoxTabContents: |
4356 rect = QCommonStyle::subElementRect(sr, opt, widget); |
4256 rect = QCommonStyle::subElementRect(sr, opt, widget); |
4357 break; |
4257 break; |
4358 case SE_PushButtonContents: |
4258 case SE_PushButtonContents: |
4359 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
4259 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
4367 } |
4267 } |
4368 break; |
4268 break; |
4369 case SE_HeaderLabel: |
4269 case SE_HeaderLabel: |
4370 if (qstyleoption_cast<const QStyleOptionHeader *>(opt)) { |
4270 if (qstyleoption_cast<const QStyleOptionHeader *>(opt)) { |
4371 rect = QWindowsStyle::subElementRect(sr, opt, widget); |
4271 rect = QWindowsStyle::subElementRect(sr, opt, widget); |
4372 if (widget && widget->height() <= qt_mac_aqua_get_metric(kThemeMetricListHeaderHeight)){ |
4272 if (widget && widget->height() <= 22){ |
4373 // We need to allow the text a bit more space when the header is as |
4273 // We need to allow the text a bit more space when the header is |
4374 // small as kThemeMetricListHeaderHeight, otherwise it gets clipped: |
4274 // small, otherwise it gets clipped: |
4375 rect.setY(0); |
4275 rect.setY(0); |
4376 rect.setHeight(widget->height()); |
4276 rect.setHeight(widget->height()); |
4377 } |
4277 } |
4378 } |
4278 } |
4379 break; |
4279 break; |
4396 HIThemeGetButtonContentBounds(&inRect, &bdi, &contentRect); |
4296 HIThemeGetButtonContentBounds(&inRect, &bdi, &contentRect); |
4397 QCFType<HIShapeRef> shape; |
4297 QCFType<HIShapeRef> shape; |
4398 HIRect outRect; |
4298 HIRect outRect; |
4399 HIThemeGetButtonShape(&inRect, &bdi, &shape); |
4299 HIThemeGetButtonShape(&inRect, &bdi, &shape); |
4400 ptrHIShapeGetBounds(shape, &outRect); |
4300 ptrHIShapeGetBounds(shape, &outRect); |
4401 rect = QRect(int(outRect.origin.x), int(outRect.origin.y), |
4301 rect = QRect(int(outRect.origin.x + DisclosureOffset), int(outRect.origin.y), |
4402 int(contentRect.origin.x - outRect.origin.x), int(outRect.size.height)); |
4302 int(contentRect.origin.x - outRect.origin.x + DisclosureOffset), |
|
4303 int(outRect.size.height)); |
4403 break; |
4304 break; |
4404 } |
4305 } |
4405 case SE_TabWidgetLeftCorner: |
4306 case SE_TabWidgetLeftCorner: |
4406 if (const QStyleOptionTabWidgetFrame *twf |
4307 if (const QStyleOptionTabWidgetFrame *twf |
4407 = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) { |
4308 = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) { |
5693 break; |
5594 break; |
5694 case QStyle::CT_PushButton: |
5595 case QStyle::CT_PushButton: |
5695 // By default, we fit the contents inside a normal rounded push button. |
5596 // By default, we fit the contents inside a normal rounded push button. |
5696 // Do this by add enough space around the contents so that rounded |
5597 // Do this by add enough space around the contents so that rounded |
5697 // borders (including highlighting when active) will show. |
5598 // borders (including highlighting when active) will show. |
5698 sz.rwidth() += PushButtonLeftOffset + PushButtonRightOffset + 12; |
5599 sz.rwidth() += QMacStylePrivate::PushButtonLeftOffset + QMacStylePrivate::PushButtonRightOffset + 12; |
5699 sz.rheight() += PushButtonTopOffset + PushButtonBottomOffset; |
5600 sz.rheight() += QMacStylePrivate::PushButtonTopOffset + QMacStylePrivate::PushButtonBottomOffset; |
5700 break; |
5601 break; |
5701 case QStyle::CT_MenuItem: |
5602 case QStyle::CT_MenuItem: |
5702 if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { |
5603 if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { |
5703 int maxpmw = mi->maxIconWidth; |
5604 int maxpmw = mi->maxIconWidth; |
5704 const QComboBox *comboBox = qobject_cast<const QComboBox *>(widget); |
5605 const QComboBox *comboBox = qobject_cast<const QComboBox *>(widget); |
5786 sz = sz.expandedTo(QSize(minimumSize, sz.height())); |
5687 sz = sz.expandedTo(QSize(minimumSize, sz.height())); |
5787 else |
5688 else |
5788 sz = sz.expandedTo(QSize(sz.width(), minimumSize)); |
5689 sz = sz.expandedTo(QSize(sz.width(), minimumSize)); |
5789 } |
5690 } |
5790 break; |
5691 break; |
|
5692 case CT_ItemViewItem: |
|
5693 if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) { |
|
5694 sz = QCommonStyle::sizeFromContents(ct, vopt, csz, widget); |
|
5695 sz.setHeight(sz.height() + 2); |
|
5696 } |
|
5697 break; |
|
5698 |
5791 default: |
5699 default: |
5792 sz = QWindowsStyle::sizeFromContents(ct, opt, csz, widget); |
5700 sz = QWindowsStyle::sizeFromContents(ct, opt, csz, widget); |
5793 } |
5701 } |
5794 |
5702 |
5795 if (useAquaGuideline){ |
5703 if (useAquaGuideline){ |