diff options
Diffstat (limited to 'src/gui/styles/qmacstyle_mac.mm')
-rw-r--r-- | src/gui/styles/qmacstyle_mac.mm | 1077 |
1 files changed, 381 insertions, 696 deletions
diff --git a/src/gui/styles/qmacstyle_mac.mm b/src/gui/styles/qmacstyle_mac.mm index ee106eb..63ba641 100644 --- a/src/gui/styles/qmacstyle_mac.mm +++ b/src/gui/styles/qmacstyle_mac.mm @@ -50,11 +50,13 @@ #define QMAC_QAQUASTYLE_SIZE_CONSTRAIN //#define DEBUG_SIZE_CONSTRAINT +#include <private/qapplication_p.h> #include <private/qcombobox_p.h> #include <private/qmacstylepixmaps_mac_p.h> #include <private/qpaintengine_mac_p.h> #include <private/qpainter_p.h> #include <private/qprintengine_mac_p.h> +#include <private/qstylehelper_p.h> #include <qapplication.h> #include <qbitmap.h> #include <qcheckbox.h> @@ -102,7 +104,6 @@ QT_BEGIN_NAMESPACE extern QRegion qt_mac_convert_mac_region(RgnHandle); //qregion_mac.cpp -extern QHash<QByteArray, QFont> *qt_app_fonts_hash(); // qapplication.cpp // The following constants are used for adjusting the size // of push buttons so that they are drawn inside their bounds. @@ -130,6 +131,20 @@ static const QColor titlebarSeparatorLineInactive(131, 131, 131); static const QColor mainWindowGradientBegin(240, 240, 240); static const QColor mainWindowGradientEnd(200, 200, 200); +#if (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5) +enum { + kThemePushButtonTextured = 31, + kThemePushButtonTexturedSmall = 32, + kThemePushButtonTexturedMini = 33 +}; + +/* Search fields */ +enum { + kHIThemeFrameTextFieldRound = 1000, + kHIThemeFrameTextFieldRoundSmall = 1001, + kHIThemeFrameTextFieldRoundMini = 1002 +}; +#endif // Resolve these at run-time, since the functions was moved in Leopard. typedef HIRect * (*PtrHIShapeGetBounds)(HIShapeRef, HIRect *); @@ -488,11 +503,9 @@ public: inline int animateSpeed(Animates) const { return 33; } // Utility functions - void drawColorlessButton(const QRect &macRect, HIThemeButtonDrawInfo *bdi, + void drawColorlessButton(const HIRect &macRect, HIThemeButtonDrawInfo *bdi, QPainter *p, const QStyleOption *opt) const; - void drawPantherTab(const QStyleOptionTab *tab, QPainter *p, const QWidget *w = 0) const; - QSize pushButtonSizeFromContents(const QStyleOptionButton *btn) const; HIRect pushButtonContentBounds(const QStyleOptionButton *btn, @@ -505,7 +518,7 @@ public: static QRect comboboxEditBounds(const QRect &outerBounds, const HIThemeButtonDrawInfo &bdi); - static void drawCombobox(const QRect &outerBounds, const HIThemeButtonDrawInfo &bdi, QPainter *p); + static void drawCombobox(const HIRect &outerBounds, const HIThemeButtonDrawInfo &bdi, QPainter *p); static void drawTableHeader(const HIRect &outerBounds, bool drawTopBorder, bool drawLeftBorder, const HIThemeButtonDrawInfo &bdi, QPainter *p); bool contentFitsInPushButton(const QStyleOptionButton *btn, HIThemeButtonDrawInfo *bdi, @@ -545,7 +558,6 @@ QT_END_INCLUDE_NAMESPACE External functions *****************************************************************************/ extern CGContextRef qt_mac_cg_context(const QPaintDevice *); //qpaintdevice_mac.cpp -extern QPixmap qt_mac_convert_iconref(const IconRef, int, int); //qpixmap_mac.cpp extern QRegion qt_mac_convert_mac_region(HIShapeRef); //qregion_mac.cpp void qt_mac_dispose_rgn(RgnHandle r); //qregion_mac.cpp extern QPaintDevice *qt_mac_safe_pdev; //qapplication_mac.cpp @@ -566,11 +578,7 @@ QPixmap *qt_mac_backgroundPattern = 0; // stores the standard widget background. *****************************************************************************/ static inline int qt_mac_hitheme_tab_version() { -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) - return 1; -#endif - return 0; + return 1; } static inline HIRect qt_hirectForQRect(const QRect &convertRect, const QRect &rect = QRect()) @@ -836,7 +844,7 @@ static QSize qt_aqua_get_known_size(QStyle::ContentsType ct, const QWidget *widg } break; case QStyle::CT_HeaderSection: - if (sz == QAquaSizeLarge && isTreeView(widg)) + if (isTreeView(widg)) ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricListHeaderHeight)); break; case QStyle::CT_MenuBar: @@ -1020,13 +1028,6 @@ HIRect QMacStylePrivate::pushButtonContentBounds(const QStyleOptionButton *btn, HIRect contentBounds; HIThemeGetButtonContentBounds(&outerBounds, bdi, &contentBounds); - - // Return the button rect if the rect returned by HIThemeGetButtonContentBounds - // is invalid. This avoids passing around bad rects to code that does not expect it. - if (contentBounds.size.height == 0 && contentBounds.size.width == 0) { - return qt_hirectForQRect(btn->rect); - } - return contentBounds; } @@ -1043,7 +1044,7 @@ QSize QMacStylePrivate::pushButtonSizeFromContents(const QStyleOptionButton *btn : btn->fontMetrics.boundingRect(QRect(), Qt::AlignCenter, btn->text); csz.setWidth(iconSize.width() + textRect.width() + ((btn->features & QStyleOptionButton::HasMenu) - ? q->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, 0) : 0)); + ? q->proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, 0) : 0)); csz.setHeight(qMax(iconSize.height(), textRect.height())); return csz; } @@ -1287,12 +1288,11 @@ QRect QMacStylePrivate::comboboxEditBounds(const QRect &outerBounds, const HIThe create it manually by drawing a small Carbon combo onto a pixmap (use pixmap cache), chop it up, and copy it back onto the widget. Othervise, draw the combobox supplied by Carbon directly. */ -void QMacStylePrivate::drawCombobox(const QRect &outerBounds, const HIThemeButtonDrawInfo &bdi, QPainter *p) +void QMacStylePrivate::drawCombobox(const HIRect &outerBounds, const HIThemeButtonDrawInfo &bdi, QPainter *p) { - if (!(bdi.kind == kThemeComboBox && outerBounds.height() > 28)){ + if (!(bdi.kind == kThemeComboBox && outerBounds.size.height > 28)){ // We have an unscaled combobox, or popup-button; use Carbon directly. - const HIRect hiOuterBounds = qt_hirectForQRect(outerBounds); - HIRect innerBounds = QMacStylePrivate::comboboxInnerBounds(hiOuterBounds, bdi.kind); + HIRect innerBounds = QMacStylePrivate::comboboxInnerBounds(outerBounds, bdi.kind); HIThemeDrawButton(&innerBounds, &bdi, QMacCGContext(p), kHIThemeOrientationNormal, 0); } else { QPixmap buffer; @@ -1307,50 +1307,31 @@ void QMacStylePrivate::drawCombobox(const QRect &outerBounds, const HIThemeButto QPixmapCache::insert(key, buffer); } - const int widgetX = outerBounds.x(); - const int widgetY = outerBounds.y(); - const int widgetWidth = outerBounds.width(); - const int widgetHeight = outerBounds.height(); - - const int buttonWidth = 20; - const int frameWidth = 10; - const int frameHeight = 10; // frame height - const int bstart = widgetWidth - buttonWidth; - const int flower = widgetHeight - frameHeight; + const int bwidth = 20; + const int fwidth = 10; + const int fheight = 10; + int w = qRound(outerBounds.size.width); + int h = qRound(outerBounds.size.height); + int bstart = w - bwidth; + int blower = fheight + 1; + int flower = h - fheight; + int sheight = flower - fheight; + int center = qRound(outerBounds.size.height + outerBounds.origin.y) / 2; // Draw upper and lower gap - p->drawPixmap(widgetX + frameWidth, widgetY, bstart - frameWidth, frameHeight, - buffer, frameWidth, 0, 1, frameHeight); // upper - p->drawPixmap(widgetX + frameWidth, widgetY + flower, bstart - frameWidth, frameHeight, - buffer, frameWidth, buffer.height() - frameHeight, 1, frameHeight); // lower - - const int center = widgetY + widgetHeight / 2; - const int sheight = flower - frameHeight; - + p->drawPixmap(fwidth, 0, bstart - fwidth, fheight, buffer, fwidth, 0, 1, fheight); + p->drawPixmap(fwidth, flower, bstart - fwidth, fheight, buffer, fwidth, buffer.height() - fheight, 1, fheight); // Draw left and right gap. Right gap is drawn top and bottom separatly - p->drawPixmap(widgetX, widgetY + frameHeight, frameWidth, sheight, - buffer, 0, frameHeight, frameWidth, 1); // right - p->drawPixmap(widgetX + bstart, widgetY + frameHeight, buttonWidth, widgetHeight / 2 - frameHeight, - buffer, buffer.width() - buttonWidth, frameHeight - 1, buttonWidth, 1); // top left - p->drawPixmap(widgetX + bstart, center, buttonWidth, sheight / 2, - buffer, buffer.width() - buttonWidth, frameHeight + 6, buttonWidth, 1); // bottom left - + p->drawPixmap(0, fheight, fwidth, sheight, buffer, 0, fheight, fwidth, 1); + p->drawPixmap(bstart, fheight, bwidth, center - fheight, buffer, buffer.width() - bwidth, fheight - 1, bwidth, 1); + p->drawPixmap(bstart, center, bwidth, sheight / 2, buffer, buffer.width() - bwidth, fheight + 6, bwidth, 1); // Draw arrow - p->drawPixmap(widgetX + bstart, center - 4, buttonWidth - 3, 6, - buffer, buffer.width() - buttonWidth, frameHeight, buttonWidth - 3, 6); - + p->drawPixmap(bstart, center - 4, bwidth - 3, 6, buffer, buffer.width() - bwidth, fheight, bwidth - 3, 6); // Draw corners - p->drawPixmap(widgetX, widgetY, frameWidth, frameHeight, - buffer, 0, 0, frameWidth, frameHeight); // top left - p->drawPixmap(widgetX + bstart, widgetY, buttonWidth, frameHeight, - buffer, buffer.width() - buttonWidth, 0, buttonWidth, frameHeight); // top right - p->drawPixmap(widgetX, widgetY + flower, frameWidth, frameHeight, - buffer, 0, buffer.height() - frameHeight, frameWidth, frameHeight); // bottom left - - const int blower = frameHeight + 1; - p->drawPixmap(widgetX + bstart, widgetY + widgetHeight - blower, buttonWidth, blower, - buffer, - buffer.width() - buttonWidth, buffer.height() - blower, buttonWidth, blower); // bottom right + p->drawPixmap(0, 0, fwidth, fheight, buffer, 0, 0, fwidth, fheight); + p->drawPixmap(bstart, 0, bwidth, fheight, buffer, buffer.width() - bwidth, 0, bwidth, fheight); + p->drawPixmap(0, flower, fwidth, fheight, buffer, 0, buffer.height() - fheight, fwidth, fheight); + p->drawPixmap(bstart, h - blower, bwidth, blower, buffer, buffer.width() - bwidth, buffer.height() - blower, bwidth, blower); } } @@ -1483,8 +1464,7 @@ void QMacStylePrivate::getSliderInfo(QStyle::ComplexControl cc, const QStyleOpti } // Tiger broke reverse scroll bars so put them back and "fake it" - if (isScrollbar && (tdi->attributes & kThemeTrackRightToLeft) - && QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { + if (isScrollbar && (tdi->attributes & kThemeTrackRightToLeft)) { tdi->attributes &= ~kThemeTrackRightToLeft; tdi->value = tdi->max - slider->sliderPosition; } @@ -1567,166 +1547,6 @@ void QMacStylePrivate::startAnimationTimer() timerID = startTimer(animateSpeed(AquaListViewItemOpen)); } -enum { TabNormalLeft, TabNormalMid, TabNormalRight, TabSelectedActiveLeft, - TabSelectedActiveMid, TabSelectedActiveRight, TabSelectedInactiveLeft, - TabSelectedInactiveMid, TabSelectedInactiveRight, TabSelectedActiveGraphiteLeft, - TabSelectedActiveGraphiteMid, TabSelectedActiveGraphiteRight, - TabPressedLeft, TabPressedMid, TabPressedRight }; - -static const char * const * const PantherTabXpms[] = { - qt_mac_tabnrm_left, - qt_mac_tabnrm_mid, - qt_mac_tabnrm_right, - qt_mac_tabselected_active_left, - qt_mac_tabselected_active_mid, - qt_mac_tabselected_active_right, - qt_mac_tabselected_inactive_left, - qt_mac_tabselected_inactive_mid, - qt_mac_tabselected_inactive_right, - qt_mac_tab_selected_active_graph_left, - qt_mac_tab_selected_active_graph_mid, - qt_mac_tab_selected_active_graph_right, - qt_mac_tab_press_left, - qt_mac_tab_press_mid, - qt_mac_tab_press_right}; - -void QMacStylePrivate::drawPantherTab(const QStyleOptionTab *tabOpt, QPainter *p, - const QWidget *) const -{ - QString tabKey = QLatin1String("$qt_mac_style_tab_"); - int pantherTabStart; - int pantherTabMid; - int pantherTabEnd; - - ThemeTabDirection ttd = getTabDirection(tabOpt->shape); - - if (tabOpt->state & QStyle::State_Selected) { - if (!(tabOpt->state & QStyle::State_Active)) { - pantherTabStart = TabSelectedInactiveLeft; - } else { - // Draw into a pixmap to determine which version we use, Aqua or Graphite. - QPixmap tabPix(20, 20); - QPainter pixPainter(&tabPix); - HIThemeTabDrawInfo tdi; - tdi.version = 0; - tdi.style = kThemeTabFront; - tdi.direction = kThemeTabNorth; - tdi.size = kHIThemeTabSizeNormal; - tdi.adornment = kHIThemeTabAdornmentNone; - HIRect inRect = CGRectMake(0.0f, 0.0f, 20.0f, 20.0f); - HIThemeDrawTab(&inRect, &tdi, QMacCGContext(&pixPainter), kHIThemeOrientationNormal, 0); - pixPainter.end(); - const QRgb GraphiteColor = 0xffa7b0ba; - QRgb pmColor = tabPix.toImage().pixel(10, 10); - if (qAbs(qRed(pmColor) - qRed(GraphiteColor)) < 3 && - qAbs(qGreen(pmColor) - qGreen(GraphiteColor)) < 3 - && qAbs(qBlue(pmColor) - qBlue(GraphiteColor)) < 3) - pantherTabStart = TabSelectedActiveGraphiteLeft; - else - pantherTabStart = TabSelectedActiveLeft; - } - } else if (tabOpt->state & QStyle::State_Sunken) { - pantherTabStart = TabPressedLeft; - } else { - pantherTabStart = TabNormalLeft; - } - - - bool doLine; - bool verticalTabs = ttd == kThemeTabWest || ttd == kThemeTabEast; - - QStyleOptionTab::TabPosition tp = tabOpt->position; - if (ttd == kThemeTabWest - || ((ttd == kThemeTabNorth || ttd == kThemeTabSouth) - && tabOpt->direction == Qt::RightToLeft)) { - if (tp == QStyleOptionTab::Beginning) - tp = QStyleOptionTab::End; - else if (tp == QStyleOptionTab::End) - tp = QStyleOptionTab::Beginning; - } - - switch (tp) { - default: // Stupid GCC, being overly pedantic - case QStyleOptionTab::Beginning: - doLine = false; - pantherTabMid = pantherTabEnd = pantherTabStart + 1; - break; - case QStyleOptionTab::Middle: - doLine = true; - pantherTabMid = pantherTabEnd = ++pantherTabStart; - break; - case QStyleOptionTab::End: - doLine = true; - pantherTabMid = ++pantherTabStart; - pantherTabEnd = pantherTabMid + 1; - break; - case QStyleOptionTab::OnlyOneTab: - doLine = false; - pantherTabMid = pantherTabStart + 1; - pantherTabEnd = pantherTabMid + 1; - break; - } - - QPixmap pmStart; - if (!QPixmapCache::find(tabKey + QString::number(pantherTabStart), pmStart)) { - pmStart = QPixmap(PantherTabXpms[pantherTabStart]); - QPixmapCache::insert(tabKey + QString::number(pantherTabStart), pmStart); - } - - QPixmap pmMid; - if (!QPixmapCache::find(tabKey + QString::number(pantherTabMid), pmMid)) { - pmMid = QPixmap(PantherTabXpms[pantherTabMid]); - QPixmapCache::insert(tabKey + QString::number(pantherTabMid), pmMid); - } - - QPixmap pmEnd; - if (!QPixmapCache::find(tabKey + QString::number(pantherTabEnd), pmEnd)) { - pmEnd = QPixmap(PantherTabXpms[pantherTabEnd]); - QPixmapCache::insert(tabKey + QString::number(pantherTabEnd), pmEnd); - } - QRect tr = tabOpt->rect; - if (verticalTabs) { - p->save(); - int newX, newY, newRot; - if (tabOpt->shape == QTabBar::RoundedEast || tabOpt->shape == QTabBar::TriangularEast) { - newX = tr.width(); - newY = tr.y(); - newRot = 90; - } else { - newX = 0; - newY = tr.y() + tr.height(); - newRot = -90; - } - tr.setRect(0, 0, tr.height(), tr.width()); - QMatrix m; - if (ttd == kThemeTabEast) { - // It's lame but Apple inverts these on the East side. - m.scale(-1, 1); - m.translate(-tabOpt->rect.width(), 0); - } - m.translate(newX, newY); - m.rotate(newRot); - p->setMatrix(m, true); - } - - int x = tr.x(); - int y = tr.y(); - int endX = x + tr.width() - pmEnd.width(); - - p->drawPixmap(x, y, pmStart.width(), tr.height(), pmStart); - if (doLine) { - QPen oldPen = p->pen(); - p->setPen(QColor(0, 0, 0, 0x35)); - p->drawLine(x, y + (verticalTabs ? 0 : 1), x, tr.height() - 2); - } - - for (x = x + pmStart.width(); x < endX; x += pmMid.width()) - p->drawPixmap(x, y, pmMid.width(), tr.height(), pmMid); - p->drawPixmap(endX, y, pmEnd.width(), tr.height(), pmEnd); - if (verticalTabs) - p->restore(); -} - bool QMacStylePrivate::addWidget(QWidget *w) { //already knew of it @@ -1915,7 +1735,7 @@ bool QMacStylePrivate::doAnimate(QMacStylePrivate::Animates as) return true; } -void QMacStylePrivate::drawColorlessButton(const QRect &outerBounds, HIThemeButtonDrawInfo *bdi, +void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonDrawInfo *bdi, QPainter *p, const QStyleOption *opt) const { int xoff = 0, @@ -1925,8 +1745,8 @@ void QMacStylePrivate::drawColorlessButton(const QRect &outerBounds, HIThemeButt finalyoff = 0; const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt); - const int width = outerBounds.width() + extraWidth; - const int height = outerBounds.height() + extraHeight; + int width = int(macRect.size.width) + extraWidth; + int height = int(macRect.size.height) + extraHeight; if (width <= 0 || height <= 0) return; // nothing to draw @@ -1943,11 +1763,11 @@ void QMacStylePrivate::drawColorlessButton(const QRect &outerBounds, HIThemeButt // Carbon combos don't scale. Therefore we draw it // ourselves, if a scaled version is needed. QPainter tmpPainter(&activePixmap); - QMacStylePrivate::drawCombobox(outerBounds, *bdi, &tmpPainter); + QMacStylePrivate::drawCombobox(macRect, *bdi, &tmpPainter); } else { QMacCGContext cg(&activePixmap); - HIRect newRect = CGRectMake(xoff, yoff, outerBounds.width(), outerBounds.height()); + HIRect newRect = CGRectMake(xoff, yoff, macRect.size.width, macRect.size.height); HIThemeDrawButton(&newRect, bdi, cg, kHIThemeOrientationNormal, 0); } } @@ -1987,7 +1807,7 @@ void QMacStylePrivate::drawColorlessButton(const QRect &outerBounds, HIThemeButt colorlessPixmap.fill(Qt::transparent); QMacCGContext cg(&colorlessPixmap); - HIRect newRect = CGRectMake(xoff, yoff, outerBounds.width(), outerBounds.height()); + HIRect newRect = CGRectMake(xoff, yoff, macRect.size.width, macRect.size.height); int oldValue = bdi->value; bdi->value = kThemeButtonOff; HIThemeDrawButton(&newRect, bdi, cg, kHIThemeOrientationNormal, 0); @@ -2017,7 +1837,7 @@ void QMacStylePrivate::drawColorlessButton(const QRect &outerBounds, HIThemeButt } QPixmapCache::insert(key, pm); } - p->drawPixmap(outerBounds.x(), outerBounds.y() + finalyoff, width, height, pm); + p->drawPixmap(int(macRect.origin.x), int(macRect.origin.y) + finalyoff, width, height, pm); } QMacStyle::QMacStyle() @@ -2039,22 +1859,10 @@ QMacStyle::~QMacStyle() QPixmap QMacStylePrivate::generateBackgroundPattern() const { QPixmap px(4, 4); -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { - QMacCGContext cg(&px); - HIThemeSetFill(kThemeBrushDialogBackgroundActive, 0, cg, kHIThemeOrientationNormal); - const CGRect cgRect = CGRectMake(0, 0, px.width(), px.height()); - CGContextFillRect(cg, cgRect); - } else -#endif - { -#ifndef QT_MAC_NO_QUICKDRAW - QMacSavedPortInfo port(&px); - SetThemeBackground(kThemeBrushDialogBackgroundActive, px.depth(), true); - const Rect qdRect = { 0, 0, px.width(), px.height() }; - EraseRect(&qdRect); -#endif - } + QMacCGContext cg(&px); + HIThemeSetFill(kThemeBrushDialogBackgroundActive, 0, cg, kHIThemeOrientationNormal); + const CGRect cgRect = CGRectMake(0, 0, px.width(), px.height()); + CGContextFillRect(cg, cgRect); return px; } @@ -2062,25 +1870,23 @@ QPixmap QMacStylePrivate::generateBackgroundPattern() const Fills the given \a rect with the pattern stored in \a brush. As an optimization, HIThemeSetFill us used directly if we are filling with the standard background. */ -void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QPoint &offset, const QBrush &brush) +void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush) { -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) QPoint dummy; const QPaintDevice *target = painter->device(); const QPaintDevice *redirected = QPainter::redirected(target, &dummy); const bool usePainter = redirected && redirected != target; - const QRegion translated = rgn.translated(offset); - if (!usePainter && QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4 && qt_mac_backgroundPattern + if (!usePainter && qt_mac_backgroundPattern && qt_mac_backgroundPattern->cacheKey() == brush.texture().cacheKey()) { - painter->setClipRegion(translated); + painter->setClipRegion(rgn); CGContextRef cg = qt_mac_cg_context(target); CGContextSaveGState(cg); HIThemeSetFill(kThemeBrushDialogBackgroundActive, 0, cg, kHIThemeOrientationInverted); - const QVector<QRect> &rects = translated.rects(); + const QVector<QRect> &rects = rgn.rects(); for (int i = 0; i < rects.size(); ++i) { const QRect rect(rects.at(i)); // Anchor the pattern to the top so it stays put when the window is resized. @@ -2090,11 +1896,9 @@ void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QPoint } CGContextRestoreGState(cg); - } else -#endif - { - const QRect rect(translated.boundingRect()); - painter->setClipRegion(translated); + } else { + const QRect rect(rgn.boundingRect()); + painter->setClipRegion(rgn); painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft()); } } @@ -2163,18 +1967,6 @@ void QMacStyle::polish(QWidget* w) } } - // Adjust the lineedit of the editable combo box - if (QSysInfo::MacintoshVersion == QSysInfo::MV_10_3) { - if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(w)) { - if (qobject_cast<QComboBox *>(lineEdit->parentWidget()) - && !lineEdit->testAttribute(Qt::WA_SetFont)) { - QFont font = lineEdit->font(); - font.setPointSize(font.pointSize() - 1); - lineEdit->setFont(font); - } - } - } - if (QTabBar *tb = qobject_cast<QTabBar*>(w)) { if (tb->documentMode()) { w->setAttribute(Qt::WA_Hover); @@ -2235,7 +2027,7 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW ret = closeButtonSize; break; case PM_ToolBarIconSize: - ret = pixelMetric(PM_LargeIconSize); + ret = proxy()->pixelMetric(PM_LargeIconSize); break; case PM_FocusFrameVMargin: case PM_FocusFrameHMargin: @@ -2409,12 +2201,6 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW GetThemeMetric(kThemeMetricScrollBarWidth, &ret); break; case QAquaSizeMini: -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3) && 0 - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_3) { - GetThemeMetric(kThemeMetricMiniScrollBarWidth, &ret); - break; - } -#endif case QAquaSizeSmall: GetThemeMetric(kThemeMetricSmallScrollBarWidth, &ret); break; @@ -2517,9 +2303,6 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW case PM_ToolBarItemSpacing: ret = 4; break; - case PM_MessageBoxIconSize: - ret = 64; - break; case PM_SplitterWidth: ret = qMax(7, QApplication::globalStrut().width()); break; @@ -2595,6 +2378,9 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW case PM_MenuHMargin: ret = 0; break; + case PM_ToolBarFrameWidth: + ret = 0; + break; default: ret = QWindowsStyle::pixelMetric(metric, opt, widget); break; @@ -2756,7 +2542,7 @@ int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w QPixmap pix(pixmapSize); pix.fill(QColor(fillR, fillG, fillB)); QPainter pix_paint(&pix); - drawControl(CE_FocusFrame, opt, &pix_paint, w); + proxy()->drawControl(CE_FocusFrame, opt, &pix_paint, w); pix_paint.end(); img = pix.toImage(); } @@ -3071,7 +2857,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai twf.rect = twf.rect.adjusted(0, -10, 0, 0); break; } - drawPrimitive(PE_FrameTabWidget, &twf, p, w); + proxy()->drawPrimitive(PE_FrameTabWidget, &twf, p, w); p->restore(); } break; @@ -3169,7 +2955,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) { // In HITheme, up is down, down is up and hamburgers eat people. if (header->sortIndicator != QStyleOptionHeader::None) - drawPrimitive( + proxy()->drawPrimitive( (header->sortIndicator == QStyleOptionHeader::SortDown) ? PE_IndicatorArrowUp : PE_IndicatorArrowDown, header, p, w); } @@ -3242,13 +3028,15 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai bdi.value = kThemeButtonOn; else bdi.value = kThemeButtonOff; - - if (!drawColorless) { - const HIRect macRect = qt_hirectForQRect(opt->rect); + HIRect macRect; + if (pe == PE_Q3CheckListExclusiveIndicator || pe == PE_Q3CheckListIndicator) + macRect = qt_hirectForQRect(opt->rect); + else + macRect = qt_hirectForQRect(opt->rect); + if (!drawColorless) HIThemeDrawButton(&macRect, &bdi, cg, kHIThemeOrientationNormal, 0); - } else { - d->drawColorlessButton(opt->rect, &bdi, p, opt); - } + else + d->drawColorlessButton(macRect, &bdi, p, opt); break; } case PE_FrameFocusRect: // Use the our own focus widget stuff. @@ -3301,7 +3089,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai fdi.isFocused = (frame->state & State_HasFocus); int lw = frame->lineWidth; if (lw <= 0) - lw = pixelMetric(PM_DefaultFrameWidth, frame, w); + lw = proxy()->pixelMetric(PM_DefaultFrameWidth, frame, w); { //clear to base color p->save(); p->setPen(QPen(baseColor, lw)); @@ -3326,27 +3114,14 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) { HIRect hirect = qt_hirectForQRect(twf->rect); -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { - HIThemeTabPaneDrawInfo tpdi; - tpdi.version = qt_mac_hitheme_tab_version(); - tpdi.state = tds; - tpdi.direction = getTabDirection(twf->shape); - tpdi.size = kHIThemeTabSizeNormal; - if (tpdi.version == 1) { - tpdi.kind = kHIThemeTabKindNormal; - tpdi.adornment = kHIThemeTabPaneAdornmentNormal; - } - HIThemeDrawTabPane(&hirect, &tpdi, cg, kHIThemeOrientationNormal); - } else -#endif - { - HIThemeGroupBoxDrawInfo gdi; - gdi.version = qt_mac_hitheme_version; - gdi.state = tds; - gdi.kind = kHIThemeGroupBoxKindSecondary; - HIThemeDrawGroupBox(&hirect, &gdi, cg, kHIThemeOrientationNormal); - } + HIThemeTabPaneDrawInfo tpdi; + tpdi.version = qt_mac_hitheme_tab_version(); + tpdi.state = tds; + tpdi.direction = getTabDirection(twf->shape); + tpdi.size = kHIThemeTabSizeNormal; + tpdi.kind = kHIThemeTabKindNormal; + tpdi.adornment = kHIThemeTabPaneAdornmentNormal; + HIThemeDrawTabPane(&hirect, &tpdi, cg, kHIThemeOrientationNormal); } break; case PE_PanelScrollAreaCorner: { @@ -3370,7 +3145,6 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai QWindowsStyle::drawPrimitive(pe, opt, p, w); break; } - // Use the Leopard style only if the status bar is the status bar for a // QMainWindow with a unifed toolbar. if (w == 0 || w->parent() == 0 || qobject_cast<QMainWindow *>(w->parent()) == 0 || @@ -3514,16 +3288,16 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter QIcon::Mode mode = QIcon::Disabled; if (opt->state & State_Enabled) mode = QIcon::Normal; - QPixmap pixmap = header->icon.pixmap(pixelMetric(PM_SmallIconSize), mode); + QPixmap pixmap = header->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize), mode); QRect pixr = header->rect; pixr.setY(header->rect.center().y() - (pixmap.height() - 1) / 2); - drawItemPixmap(p, pixr, Qt::AlignVCenter, pixmap); + proxy()->drawItemPixmap(p, pixr, Qt::AlignVCenter, pixmap); textr.translate(pixmap.width() + 2, 0); } - drawItemText(p, textr, header->textAlignment | Qt::AlignVCenter, header->palette, - header->state & State_Enabled, header->text, QPalette::ButtonText); + proxy()->drawItemText(p, textr, header->textAlignment | Qt::AlignVCenter, header->palette, + header->state & State_Enabled, header->text, QPalette::ButtonText); } break; case CE_ToolButtonLabel: @@ -3534,58 +3308,89 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter QRect cr = tb->rect; int shiftX = 0; int shiftY = 0; - if (tb->state & (State_Sunken | State_On)) { - shiftX = pixelMetric(PM_ButtonShiftHorizontal, tb, w); - shiftY = pixelMetric(PM_ButtonShiftVertical, tb, w); + bool needText = false; + int alignment = 0; + bool down = tb->state & (State_Sunken | State_On); + if (down) { + shiftX = proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, w); + shiftY = proxy()->pixelMetric(PM_ButtonShiftVertical, tb, w); } // The down state is special for QToolButtons in a toolbar on the Mac // The text is a bit bolder and gets a drop shadow and the icons are also darkened. // This doesn't really fit into any particular case in QIcon, so we // do the majority of the work ourselves. - if (tb->state & State_Sunken - && !(tb->features & QStyleOptionToolButton::Arrow)) { + if (!(tb->features & QStyleOptionToolButton::Arrow)) { Qt::ToolButtonStyle tbstyle = tb->toolButtonStyle; if (tb->icon.isNull() && !tb->text.isEmpty()) tbstyle = Qt::ToolButtonTextOnly; switch (tbstyle) { - case Qt::ToolButtonTextOnly: - drawItemText(p, cr, Qt::AlignCenter, tb->palette, - tb->state & State_Enabled, tb->text); - break; + case Qt::ToolButtonTextOnly: { + needText = true; + alignment = Qt::AlignCenter; + break; } case Qt::ToolButtonIconOnly: case Qt::ToolButtonTextBesideIcon: case Qt::ToolButtonTextUnderIcon: { QRect pr = cr; QIcon::Mode iconMode = (tb->state & State_Enabled) ? QIcon::Normal - : QIcon::Disabled; + : QIcon::Disabled; QIcon::State iconState = (tb->state & State_On) ? QIcon::On - : QIcon::Off; + : QIcon::Off; QPixmap pixmap = tb->icon.pixmap(tb->rect.size().boundedTo(tb->iconSize), iconMode, iconState); // Draw the text if it's needed. if (tb->toolButtonStyle != Qt::ToolButtonIconOnly) { - int alignment = 0; + needText = true; if (tb->toolButtonStyle == Qt::ToolButtonTextUnderIcon) { - pr.setHeight(pixmap.size().height() + 6); - cr.adjust(0, pr.bottom(), 0, -3); + pr.setHeight(pixmap.size().height()); + cr.adjust(0, pr.bottom() + 1, 0, 1); alignment |= Qt::AlignCenter; } else { pr.setWidth(pixmap.width() + 8); cr.adjust(pr.right(), 0, 0, 0); alignment |= Qt::AlignLeft | Qt::AlignVCenter; } - cr.translate(shiftX, shiftY); - drawItemText(p, cr, alignment, tb->palette, - tb->state & State_Enabled, tb->text); - cr.adjust(0, 3, 0, -3); // the drop shadow - drawItemText(p, cr, alignment, tb->palette, - tb->state & State_Enabled, tb->text); } - pr.translate(shiftX, shiftY); - pixmap = darkenPixmap(pixmap); - drawItemPixmap(p, pr, Qt::AlignCenter, pixmap); + if (opt->state & State_Sunken) { + pr.translate(shiftX, shiftY); + pixmap = darkenPixmap(pixmap); + } + proxy()->drawItemPixmap(p, pr, Qt::AlignCenter, pixmap); break; } + default: + Q_ASSERT(false); + break; + } + + if (needText) { + QPalette pal = tb->palette; + QPalette::ColorRole role = QPalette::NoRole; + if (down) + cr.translate(shiftX, shiftY); + if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5 + && (tbstyle == Qt::ToolButtonTextOnly + || (tbstyle != Qt::ToolButtonTextOnly && !down))) { + QPen pen = p->pen(); + QColor light = down ? Qt::black : Qt::white; + light.setAlphaF(0.375f); + p->setPen(light); + p->drawText(cr.adjusted(0, 1, 0, 1), alignment, tb->text); + p->setPen(pen); + if (down && tbstyle == Qt::ToolButtonTextOnly) { + pal = QApplication::palette("QMenu"); + pal.setCurrentColorGroup(tb->palette.currentColorGroup()); + role = QPalette::HighlightedText; + } + } + drawItemText(p, cr, alignment, pal, + tb->state & State_Enabled, tb->text, role); + if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_5 && + (tb->state & State_Sunken)) { + // Draw a "drop shadow" in earlier versions. + drawItemText(p, cr.adjusted(0, 1, 0, 1), alignment, + tb->palette, tb->state & State_Enabled, tb->text); + } } } else { QWindowsStyle::drawControl(ce, &myTb, p, w); @@ -3635,7 +3440,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter HIThemeDrawButton(&newRect, &bdi, cg, kHIThemeOrientationNormal, 0); if (btn->features & QStyleOptionButton::HasMenu) { - int mbi = pixelMetric(QStyle::PM_MenuButtonIndicator, btn, w); + int mbi = proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, w); QRect ir = btn->rect; HIRect arrowRect = CGRectMake(ir.right() - mbi - PushButtonRightOffset, ir.height() / 2 - 4, mbi, ir.height() / 2); @@ -3722,7 +3527,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter if (hasIcon) { int contentW = textRect.width(); if (hasMenu) - contentW += pixelMetric(PM_MenuButtonIndicator) + 4; + contentW += proxy()->pixelMetric(PM_MenuButtonIndicator) + 4; QIcon::Mode mode = btn->state & State_Enabled ? QIcon::Normal : QIcon::Disabled; if (mode == QIcon::Normal && btn->state & State_HasFocus) mode = QIcon::Active; @@ -3736,7 +3541,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter int iconTopOffset = freeContentRect.y() + (freeContentRect.height() - pixmap.height()) / 2; QRect iconDestRect(iconLeftOffset, iconTopOffset, pixmap.width(), pixmap.height()); QRect visualIconDestRect = visualRect(btn->direction, freeContentRect, iconDestRect); - drawItemPixmap(p, visualIconDestRect, Qt::AlignLeft | Qt::AlignVCenter, pixmap); + proxy()->drawItemPixmap(p, visualIconDestRect, Qt::AlignLeft | Qt::AlignVCenter, pixmap); int newOffset = iconDestRect.x() + iconDestRect.width() + PushButtonContentPadding - textRect.x(); textRect.adjust(newOffset, 0, newOffset, 0); @@ -3744,8 +3549,8 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter // Draw the text: if (hasText) { textRect = visualRect(btn->direction, freeContentRect, textRect); - drawItemText(p, textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, btn->palette, - (btn->state & State_Enabled), btn->text, QPalette::ButtonText); + proxy()->drawItemText(p, textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, btn->palette, + (btn->state & State_Enabled), btn->text, QPalette::ButtonText); } } } @@ -3770,104 +3575,104 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter return; } } - -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) - if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_3) { - HIThemeTabDrawInfo tdi; - tdi.version = 1; - tdi.style = kThemeTabNonFront; - tdi.direction = getTabDirection(tabOpt->shape); - switch (d->aquaSizeConstrain(opt, w)) { - default: - case QAquaSizeUnknown: - case QAquaSizeLarge: - tdi.size = kHIThemeTabSizeNormal; - break; - case QAquaSizeSmall: - tdi.size = kHIThemeTabSizeSmall; + HIThemeTabDrawInfo tdi; + tdi.version = 1; + tdi.style = kThemeTabNonFront; + tdi.direction = getTabDirection(tabOpt->shape); + switch (d->aquaSizeConstrain(opt, w)) { + default: + case QAquaSizeUnknown: + case QAquaSizeLarge: + tdi.size = kHIThemeTabSizeNormal; + break; + case QAquaSizeSmall: + tdi.size = kHIThemeTabSizeSmall; + break; + case QAquaSizeMini: + tdi.size = kHIThemeTabSizeMini; + break; + } + bool verticalTabs = tdi.direction == kThemeTabWest || tdi.direction == kThemeTabEast; + QRect tabRect = tabOpt->rect; + + bool selected = tabOpt->state & State_Selected; + if (selected) { + if (!(tabOpt->state & State_Active)) + tdi.style = kThemeTabFrontUnavailable; + else if (!(tabOpt->state & State_Enabled)) + tdi.style = kThemeTabFrontInactive; + else + tdi.style = kThemeTabFront; + } else if (!(tabOpt->state & State_Active)) { + tdi.style = kThemeTabNonFrontUnavailable; + } else if (!(tabOpt->state & State_Enabled)) { + tdi.style = kThemeTabNonFrontInactive; + } else if (tabOpt->state & State_Sunken) { + tdi.style = kThemeTabFrontInactive; // (should be kThemeTabNonFrontPressed) + } + if (tabOpt->state & State_HasFocus) + tdi.adornment = kHIThemeTabAdornmentFocus; + else + tdi.adornment = kHIThemeTabAdornmentNone; + tdi.kind = kHIThemeTabKindNormal; + 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) { + if (sp == QStyleOptionTab::NextIsSelected) + sp = QStyleOptionTab::PreviousIsSelected; + else if (sp == QStyleOptionTab::PreviousIsSelected) + sp = QStyleOptionTab::NextIsSelected; + switch (tp) { + case QStyleOptionTab::Beginning: + tp = QStyleOptionTab::End; break; - case QAquaSizeMini: - tdi.size = kHIThemeTabSizeMini; + case QStyleOptionTab::End: + tp = QStyleOptionTab::Beginning; break; - } - bool verticalTabs = tdi.direction == kThemeTabWest || tdi.direction == kThemeTabEast; - QRect tabRect = tabOpt->rect; - - if ((!verticalTabs && tabRect.height() > 21 || verticalTabs && tabRect.width() > 21)) { - d->drawPantherTab(tabOpt, p, w); + default: break; } + } + switch (tp) { + case QStyleOptionTab::Beginning: + tdi.position = kHIThemeTabPositionFirst; + if (sp != QStyleOptionTab::NextIsSelected) + tdi.adornment |= kHIThemeTabAdornmentTrailingSeparator; + break; + case QStyleOptionTab::Middle: + tdi.position = kHIThemeTabPositionMiddle; + if (selected) + tdi.adornment |= kHIThemeTabAdornmentLeadingSeparator; + if (sp != QStyleOptionTab::NextIsSelected) // Also when we're selected. + tdi.adornment |= kHIThemeTabAdornmentTrailingSeparator; + break; + case QStyleOptionTab::End: + tdi.position = kHIThemeTabPositionLast; + if (selected) + tdi.adornment |= kHIThemeTabAdornmentLeadingSeparator; + break; + case QStyleOptionTab::OnlyOneTab: + tdi.position = kHIThemeTabPositionOnly; + break; + } - bool selected = tabOpt->state & State_Selected; - if (selected) { - if (!(tabOpt->state & State_Active)) - tdi.style = kThemeTabFrontUnavailable; - else if (!(tabOpt->state & State_Enabled)) - tdi.style = kThemeTabFrontInactive; - else - tdi.style = kThemeTabFront; - } else if (!(tabOpt->state & State_Active)) { - tdi.style = kThemeTabNonFrontUnavailable; - } else if (!(tabOpt->state & State_Enabled)) { - tdi.style = kThemeTabNonFrontInactive; - } else if (tabOpt->state & State_Sunken) { - tdi.style = kThemeTabFrontInactive; // (should be kThemeTabNonFrontPressed) - } - if (tabOpt->state & State_HasFocus) - tdi.adornment = kHIThemeTabAdornmentFocus; - else - tdi.adornment = kHIThemeTabAdornmentNone; - tdi.kind = kHIThemeTabKindNormal; - 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) { - if (sp == QStyleOptionTab::NextIsSelected) - sp = QStyleOptionTab::PreviousIsSelected; - else if (sp == QStyleOptionTab::PreviousIsSelected) - sp = QStyleOptionTab::NextIsSelected; - switch (tp) { - case QStyleOptionTab::Beginning: - tp = QStyleOptionTab::End; - break; - case QStyleOptionTab::End: - tp = QStyleOptionTab::Beginning; - break; - default: - break; - } - } - switch (tp) { - case QStyleOptionTab::Beginning: - tdi.position = kHIThemeTabPositionFirst; - if (sp != QStyleOptionTab::NextIsSelected) - tdi.adornment |= kHIThemeTabAdornmentTrailingSeparator; - break; - case QStyleOptionTab::Middle: - tdi.position = kHIThemeTabPositionMiddle; - if (selected) - tdi.adornment |= kHIThemeTabAdornmentLeadingSeparator; - if (sp != QStyleOptionTab::NextIsSelected) // Also when we're selected. - tdi.adornment |= kHIThemeTabAdornmentTrailingSeparator; - break; - case QStyleOptionTab::End: - tdi.position = kHIThemeTabPositionLast; - if (selected) - tdi.adornment |= kHIThemeTabAdornmentLeadingSeparator; - break; - case QStyleOptionTab::OnlyOneTab: - tdi.position = kHIThemeTabPositionOnly; - break; + // HITheme doesn't stretch its tabs. Therefore we have to cheat and do the job ourselves. + if ((!verticalTabs && tabRect.height() > 21 || verticalTabs && tabRect.width() > 21)) { + HIRect hirect = CGRectMake(0, 0, 23, 23); + QPixmap pm(23, 23); + pm.fill(Qt::transparent); + { + QMacCGContext pmcg(&pm); + HIThemeDrawTab(&hirect, &tdi, pmcg, kHIThemeOrientationNormal, 0); } + QStyleHelper::drawBorderPixmap(pm, p, tabRect, 7, 7, 7, 7); + } else { HIRect hirect = qt_hirectForQRect(tabRect); HIThemeDrawTab(&hirect, &tdi, cg, kHIThemeOrientationNormal, 0); - } else -#endif - { - d->drawPantherTab(tabOpt, p, w); } } break; @@ -3902,7 +3707,8 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter QRect nr = subElementRect(SE_TabBarTabText, opt, w); nr.moveTop(+1); int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextHideMnemonic; - drawItemText(p, nr, alignment, np, tab->state & State_Enabled, tab->text, QPalette::WindowText); + proxy()->drawItemText(p, nr, alignment, np, tab->state & State_Enabled, + tab->text, QPalette::WindowText); p->restore(); } @@ -4025,8 +3831,8 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter } break; case CE_FocusFrame: { - int xOff = pixelMetric(PM_FocusFrameHMargin, opt, w) + 1; - int yOff = pixelMetric(PM_FocusFrameVMargin, opt, w) + 1; + int xOff = proxy()->pixelMetric(PM_FocusFrameHMargin, opt, w) + 1; + int yOff = proxy()->pixelMetric(PM_FocusFrameVMargin, opt, w) + 1; HIRect hirect = CGRectMake(xOff+opt->rect.x(), yOff+opt->rect.y(), opt->rect.width() - 2 * xOff, opt->rect.height() - 2 * yOff); HIThemeDrawFocusRect(&hirect, true, QMacCGContext(p), kHIThemeOrientationNormal); @@ -4149,7 +3955,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter QIcon::Mode mode = (mi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled; // Always be normal or disabled to follow the Mac style. - int smallIconSize = pixelMetric(PM_SmallIconSize); + int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize); QSize iconSize(smallIconSize, smallIconSize); if (const QComboBox *comboBox = qobject_cast<const QComboBox *>(w)) { iconSize = comboBox->iconSize(); @@ -4184,8 +3990,12 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter const int xm = macItemFrame + maxpmw + macItemHMargin; QFont myFont = mi->font; - if (mi->state & QStyle::State_Mini) - myFont.setPointSize(mi->font.pointSize()); + // myFont may not have any "hard" flags set. We override + // the point size so that when it is resolved against the device, this font will win. + // This is mainly to handle cases where someone sets the font on the window + // and then the combo inherits it and passes it onward. At that point the resolve mask + // is very, very weak. This makes it stonger. + myFont.setPointSizeF(mi->font.pointSizeF()); p->setFont(myFont); p->drawText(xpos, yPos, contentRect.width() - xm - tabwidth + 1, contentRect.height(), text_flags ^ Qt::AlignRight, s); @@ -4259,7 +4069,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter drawItemPixmap(p, mi->rect, Qt::AlignCenter | Qt::TextHideMnemonic | Qt::TextDontClip | Qt::TextSingleLine, - mi->icon.pixmap(pixelMetric(PM_SmallIconSize), + mi->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize), (mi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled)); } else { drawItemText(p, mi->rect, @@ -4319,7 +4129,19 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter tdi.enableState = kThemeTrackDisabled; else tdi.enableState = kThemeTrackActive; - HIThemeDrawTrack(&tdi, 0, cg, kHIThemeOrientationNormal); + HIThemeOrientation drawOrientation = kHIThemeOrientationNormal; + if (reverse) { + if (vertical) { + drawOrientation = kHIThemeOrientationInverted; + } else { + CGContextSaveGState(cg); + CGContextTranslateCTM(cg, pb->rect.width(), 0); + CGContextScaleCTM(cg, -1, 1); + } + } + HIThemeDrawTrack(&tdi, 0, cg, drawOrientation); + if (reverse && !vertical) + CGContextRestoreGState(cg); } break; case CE_ProgressBarLabel: @@ -4407,9 +4229,10 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter case CE_ToolBar: { // For unified tool bars, draw nothing. if (w) { - if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(w->window())) + if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(w->window())) { if (mainWindow->unifiedTitleAndToolBarOnMac()) break; + } } // draw background gradient @@ -4778,10 +4601,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex // similar when I have an upside down scroll bar // because on Tiger I only "fake" the reverse stuff. bool reverseHorizontal = (slider->direction == Qt::RightToLeft - && slider->orientation == Qt::Horizontal - && (!slider->upsideDown - || (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4 - && slider->upsideDown))); + && slider->orientation == Qt::Horizontal); if ((reverseHorizontal && slider->activeSubControls == SC_ScrollBarAddLine) || (!reverseHorizontal @@ -4816,12 +4636,12 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex // no longer possible to move it, second the up/down buttons are removed when // there is not enough space for them. if (cc == CC_ScrollBar) { - const int scrollBarLenght = (slider->orientation == Qt::Horizontal) + const int scrollBarLength = (slider->orientation == Qt::Horizontal) ? slider->rect.width() : slider->rect.height(); const QMacStyle::WidgetSizePolicy sizePolicy = widgetSizePolicy(widget); - if (scrollBarLenght < scrollButtonsCutoffSize(thumbIndicatorCutoff, sizePolicy)) + if (scrollBarLength < scrollButtonsCutoffSize(thumbIndicatorCutoff, sizePolicy)) tdi.attributes &= ~kThemeTrackShowThumb; - if (scrollBarLenght < scrollButtonsCutoffSize(scrollButtonsCutoff, sizePolicy)) + if (scrollBarLength < scrollButtonsCutoffSize(scrollButtonsCutoff, sizePolicy)) tdi.enableState = kThemeTrackNothingToScroll; } @@ -4883,7 +4703,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex treeOpt.state |= State_Children; if (item.state & State_Open) treeOpt.state |= State_Open; - drawPrimitive(PE_IndicatorBranch, &treeOpt, p, widget); + proxy()->drawPrimitive(PE_IndicatorBranch, &treeOpt, p, widget); } y += item.totalHeight; } @@ -4897,7 +4717,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex SInt32 frame_size; GetThemeMetric(kThemeMetricEditTextFrameOutset, &frame_size); - QRect lineeditRect = subControlRect(CC_SpinBox, sb, SC_SpinBoxEditField, widget); + QRect lineeditRect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxEditField, widget); lineeditRect.adjust(-frame_size, -frame_size, +frame_size, +frame_size); HIThemeFrameDrawInfo fdi; @@ -4941,9 +4761,9 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex bdi.value = kThemeButtonOff; bdi.adornment = kThemeAdornmentNone; - QRect updown = subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget); + QRect updown = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget); - updown |= subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget); + updown |= proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget); HIRect newRect = qt_hirectForQRect(updown); QRect off_rct; HIRect outRect; @@ -4964,9 +4784,9 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex d->initComboboxBdi(combo, &bdi, widget, d->getDrawState(opt->state)); bool drawColorless = combo->palette.currentColorGroup() == QPalette::Active && tds == kThemeStateInactive; if (!drawColorless) - QMacStylePrivate::drawCombobox(combo->rect, bdi, p); + QMacStylePrivate::drawCombobox(qt_hirectForQRect(combo->rect), bdi, p); else - d->drawColorlessButton(combo->rect, &bdi, p, opt); + d->drawColorlessButton(qt_hirectForQRect(combo->rect), &bdi, p, opt); } break; case CC_TitleBar: @@ -5056,7 +4876,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex &titleRegion2); ptrHIShapeGetBounds(titleRegion2, &tmpRect); if (tmpRect.size.width != 1) { - int iconExtent = pixelMetric(PM_SmallIconSize); + int iconExtent = proxy()->pixelMetric(PM_SmallIconSize); iw = titlebar->icon.actualSize(QSize(iconExtent, iconExtent)).width(); } } @@ -5074,7 +4894,8 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex else x += br.width() / 2 - p->fontMetrics().width(titlebar->text) / 2; if (iw) - p->drawPixmap(x - iw, y, titlebar->icon.pixmap(pixelMetric(PM_SmallIconSize), QIcon::Normal)); + p->drawPixmap(x - iw, y, + titlebar->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize), QIcon::Normal)); drawItemText(p, br, Qt::AlignCenter, opt->palette, tds == kThemeStateActive, titlebar->text, QPalette::Text); p->restore(); @@ -5111,7 +4932,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex tti.truncationPosition = kHIThemeTextTruncationNone; tti.truncationMaxLines = 1 + groupBox->text.count(QLatin1Char('\n')); QCFString groupText = qt_mac_removeMnemonics(groupBox->text); - QRect r = subControlRect(CC_GroupBox, groupBox, SC_GroupBoxLabel, widget); + QRect r = proxy()->subControlRect(CC_GroupBox, groupBox, SC_GroupBoxLabel, widget); HIRect bounds = qt_hirectForQRect(r); HIThemeDrawTextBox(groupText, &bounds, &tti, cg, kHIThemeOrientationNormal); p->restore(); @@ -5124,29 +4945,35 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) { if (tb->subControls & SC_ToolButtonMenu) { QStyleOption arrowOpt(0); - arrowOpt.rect = subControlRect(cc, tb, SC_ToolButtonMenu, widget); + arrowOpt.rect = proxy()->subControlRect(cc, tb, SC_ToolButtonMenu, widget); arrowOpt.rect.setY(arrowOpt.rect.y() + arrowOpt.rect.height() / 2); arrowOpt.rect.setHeight(arrowOpt.rect.height() / 2); arrowOpt.state = tb->state; arrowOpt.palette = tb->palette; - drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget); + proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget); } else if ((tb->features & QStyleOptionToolButton::HasMenu) && (tb->toolButtonStyle != Qt::ToolButtonTextOnly && !tb->icon.isNull())) { drawToolbarButtonArrow(tb->rect, tds, cg); } if (tb->state & State_On) { - QPen oldPen = p->pen(); - p->setPen(QColor(0, 0, 0, 0x3a)); - p->fillRect(tb->rect.adjusted(1, 1, -1, -1), QColor(0, 0, 0, 0x12)); - p->drawLine(tb->rect.left() + 1, tb->rect.top(), - tb->rect.right() - 1, tb->rect.top()); - p->drawLine(tb->rect.left() + 1, tb->rect.bottom(), - tb->rect.right() - 1, tb->rect.bottom()); - p->drawLine(tb->rect.topLeft(), tb->rect.bottomLeft()); - p->drawLine(tb->rect.topRight(), tb->rect.bottomRight()); - p->setPen(oldPen); + if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { + static QPixmap pm(QLatin1String(":/trolltech/mac/style/images/leopard-unified-toolbar-on.png")); + p->setRenderHint(QPainter::SmoothPixmapTransform); + QStyleHelper::drawBorderPixmap(pm, p, tb->rect, 2, 2, 2, 2); + } else { + QPen oldPen = p->pen(); + p->setPen(QColor(0, 0, 0, 0x3a)); + p->fillRect(tb->rect.adjusted(1, 1, -1, -1), QColor(0, 0, 0, 0x12)); + p->drawLine(tb->rect.left() + 1, tb->rect.top(), + tb->rect.right() - 1, tb->rect.top()); + p->drawLine(tb->rect.left() + 1, tb->rect.bottom(), + tb->rect.right() - 1, tb->rect.bottom()); + p->drawLine(tb->rect.topLeft(), tb->rect.bottomLeft()); + p->drawLine(tb->rect.topRight(), tb->rect.bottomRight()); + p->setPen(oldPen); + } } - drawControl(CE_ToolButtonLabel, opt, p, widget); + proxy()->drawControl(CE_ToolButtonLabel, opt, p, widget); } else { ThemeButtonKind bkind = kThemeBevelButton; switch (d->aquaSizeConstrain(opt, widget)) { @@ -5155,20 +4982,14 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex bkind = kThemeBevelButton; break; case QAquaSizeMini: -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3) && 0 - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_3) { - bkind = kThemeMiniBevelButton; - break; - } -#endif case QAquaSizeSmall: bkind = kThemeSmallBevelButton; break; } QRect button, menuarea; - button = subControlRect(cc, tb, SC_ToolButton, widget); - menuarea = subControlRect(cc, tb, SC_ToolButtonMenu, widget); + button = proxy()->subControlRect(cc, tb, SC_ToolButton, widget); + menuarea = proxy()->subControlRect(cc, tb, SC_ToolButtonMenu, widget); State bflags = tb->state, mflags = tb->state; if (tb->subControls & SC_ToolButton) @@ -5231,14 +5052,18 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex } else if (tb->features & QStyleOptionToolButton::HasMenu) { drawToolbarButtonArrow(tb->rect, tds, cg); } - QRect buttonRect = subControlRect(CC_ToolButton, tb, SC_ToolButton, widget); - int fw = pixelMetric(PM_DefaultFrameWidth, opt, widget); + QRect buttonRect = proxy()->subControlRect(CC_ToolButton, tb, SC_ToolButton, widget); + int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget); QStyleOptionToolButton label = *tb; label.rect = buttonRect.adjusted(fw, fw, -fw, -fw); - drawControl(CE_ToolButtonLabel, &label, p, widget); + proxy()->drawControl(CE_ToolButtonLabel, &label, p, widget); } } break; + case CC_Dial: + if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(opt)) + QStyleHelper::drawDial(dial, p); + break; default: QWindowsStyle::drawComplexControl(cc, opt, p, widget); break; @@ -5254,6 +5079,8 @@ QStyle::SubControl QMacStyle::hitTestComplexControl(ComplexControl cc, case CC_ComboBox: if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { sc = QWindowsStyle::hitTestComplexControl(cc, cmb, pt, widget); + if (!cmb->editable && sc != QStyle::SC_None) + sc = SC_ComboBoxArrow; // A bit of a lie, but what we want } break; case CC_Slider: @@ -5283,9 +5110,9 @@ QStyle::SubControl QMacStyle::hitTestComplexControl(ComplexControl cc, // The arrow buttons are not drawn if the scroll bar is to short, // exclude them from the hit test. - const int scrollBarLenght = (sb->orientation == Qt::Horizontal) + const int scrollBarLength = (sb->orientation == Qt::Horizontal) ? sb->rect.width() : sb->rect.height(); - if (scrollBarLenght < scrollButtonsCutoffSize(scrollButtonsCutoff, widgetSizePolicy(widget))) + if (scrollBarLength < scrollButtonsCutoffSize(scrollButtonsCutoff, widgetSizePolicy(widget))) sbi.enableState = kThemeTrackNothingToScroll; sbi.viewsize = sb->pageStep; @@ -5403,11 +5230,7 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op cpc = sc == SC_ScrollBarSubLine ? kControlUpButtonPart : kControlDownButtonPart; if (slider->direction == Qt::RightToLeft - && slider->orientation == Qt::Horizontal - && (!slider->upsideDown - || (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4 - && slider->upsideDown)) - ) { + && slider->orientation == Qt::Horizontal) { if (cpc == kControlDownButtonPart) cpc = kControlUpButtonPart; else if (cpc == kControlUpButtonPart) @@ -5460,7 +5283,7 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op else if (sc == SC_TitleBarLabel) wrc = kWindowTitleTextRgn; else if (sc == SC_TitleBarSysMenu) - ret.setRect(-1024, -1024, 10, pixelMetric(PM_TitleBarHeight, + ret.setRect(-1024, -1024, 10, proxy()->pixelMetric(PM_TitleBarHeight, titlebar, widget)); if (wrc != kWindowGlobalPortRgn) { QCFType<HIShapeRef> region; @@ -5564,7 +5387,7 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op QRect labelRect = alignedRect(groupBox->direction, groupBox->textAlignment, QSize(tw, h), ret); - int indicatorWidth = pixelMetric(PM_IndicatorWidth, opt, widget); + int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, opt, widget); bool rtl = groupBox->direction == Qt::RightToLeft; if (sc == SC_GroupBoxLabel) { if (checkable) { @@ -5586,7 +5409,7 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op if (sc == SC_GroupBoxCheckBox) { int left = rtl ? labelRect.right() - indicatorWidth : labelRect.left(); ret.setRect(left, ret.top(), - indicatorWidth, pixelMetric(PM_IndicatorHeight, opt, widget)); + indicatorWidth, proxy()->pixelMetric(PM_IndicatorHeight, opt, widget)); } break; } @@ -5624,7 +5447,7 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op QAquaWidgetSize aquaSize = d->aquaSizeConstrain(spin, widget); int spinner_w; int spinBoxSep; - int fw = pixelMetric(PM_SpinBoxFrameWidth, spin, widget); + int fw = proxy()->pixelMetric(PM_SpinBoxFrameWidth, spin, widget); switch (aquaSize) { default: case QAquaSizeUnknown: @@ -5701,7 +5524,7 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op spin->rect.height() - fw * 2); } else { ret.setRect(fw, fw, - spin->rect.width() - spinner_w - fw * 2 - spinBoxSep, + spin->rect.width() - fw * 2 - spinBoxSep - spinner_w, spin->rect.height() - fw * 2); } ret = visualRect(spin->direction, spin->rect, ret); @@ -5738,11 +5561,6 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, break; case QStyle::CT_TabBarTab: if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(opt)) { - bool newStyleTabs = -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) - QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4 ? true : -#endif - false; const QAquaWidgetSize AquaSize = d->aquaSizeConstrain(opt, widget); const bool differentFont = (widget && widget->testAttribute(Qt::WA_SetFont)) || !QApplication::desktopSettingsAware(); @@ -5750,86 +5568,61 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, bool vertTabs = ttd == kThemeTabWest || ttd == kThemeTabEast; if (vertTabs) sz.transpose(); - if (newStyleTabs) { - int defaultTabHeight; - int defaultExtraSpace = pixelMetric(PM_TabBarTabHSpace, tab, widget); // Remove spurious gcc warning (AFAIK) - QFontMetrics fm = opt->fontMetrics; - switch (AquaSize) { - case QAquaSizeUnknown: - case QAquaSizeLarge: - if (tab->documentMode) - defaultTabHeight = 23; - else - defaultTabHeight = 21; - break; - case QAquaSizeSmall: - defaultTabHeight = 18; - break; - case QAquaSizeMini: - defaultTabHeight = 16; - break; - } - - bool setWidth = false; - if (differentFont || !tab->icon.isNull()) { - sz.rheight() = qMax(defaultTabHeight, sz.height()); - } else { - QSize textSize = fm.size(Qt::TextShowMnemonic, tab->text); - sz.rheight() = qMax(defaultTabHeight, textSize.height()); - sz.rwidth() = textSize.width() + defaultExtraSpace; - setWidth = true; - } + int defaultTabHeight; + int defaultExtraSpace = proxy()->pixelMetric(PM_TabBarTabHSpace, tab, widget); // Remove spurious gcc warning (AFAIK) + QFontMetrics fm = opt->fontMetrics; + switch (AquaSize) { + case QAquaSizeUnknown: + case QAquaSizeLarge: + if (tab->documentMode) + defaultTabHeight = 23; + else + defaultTabHeight = 21; + break; + case QAquaSizeSmall: + defaultTabHeight = 18; + break; + case QAquaSizeMini: + defaultTabHeight = 16; + break; + } + bool setWidth = false; + if (differentFont || !tab->icon.isNull()) { + sz.rheight() = qMax(defaultTabHeight, sz.height()); + } else { + QSize textSize = fm.size(Qt::TextShowMnemonic, tab->text); + sz.rheight() = qMax(defaultTabHeight, textSize.height()); + sz.rwidth() = textSize.width() + defaultExtraSpace; + setWidth = true; + } - if (vertTabs) - sz.transpose(); + if (vertTabs) + sz.transpose(); - int maxWidgetHeight = qMax(tab->leftButtonSize.height(), tab->rightButtonSize.height()); - int maxWidgetWidth = qMax(tab->leftButtonSize.width(), tab->rightButtonSize.width()); + int maxWidgetHeight = qMax(tab->leftButtonSize.height(), tab->rightButtonSize.height()); + int maxWidgetWidth = qMax(tab->leftButtonSize.width(), tab->rightButtonSize.width()); - int widgetWidth = 0; - int widgetHeight = 0; - int padding = 0; - if (tab->leftButtonSize.isValid()) { - padding += 8; - widgetWidth += tab->leftButtonSize.width(); - widgetHeight += tab->leftButtonSize.height(); - } - if (tab->rightButtonSize.isValid()) { - padding += 8; - widgetWidth += tab->rightButtonSize.width(); - widgetHeight += tab->rightButtonSize.height(); - } + int widgetWidth = 0; + int widgetHeight = 0; + int padding = 0; + if (tab->leftButtonSize.isValid()) { + padding += 8; + widgetWidth += tab->leftButtonSize.width(); + widgetHeight += tab->leftButtonSize.height(); + } + if (tab->rightButtonSize.isValid()) { + padding += 8; + widgetWidth += tab->rightButtonSize.width(); + widgetHeight += tab->rightButtonSize.height(); + } - if (vertTabs) { - sz.setHeight(sz.height() + widgetHeight + padding); - sz.setWidth(qMax(sz.width(), maxWidgetWidth)); - } else { - if (setWidth) - sz.setWidth(sz.width() + widgetWidth + padding); - sz.setHeight(qMax(sz.height(), maxWidgetHeight)); - } + if (vertTabs) { + sz.setHeight(sz.height() + widgetHeight + padding); + sz.setWidth(qMax(sz.width(), maxWidgetWidth)); } else { - SInt32 tabh = sz.height(); - SInt32 overlap = 0; - switch (AquaSize) { - default: - case QAquaSizeUnknown: - case QAquaSizeLarge: - GetThemeMetric(kThemeLargeTabHeight, &tabh); - GetThemeMetric(kThemeMetricTabFrameOverlap, &overlap); - break; - case QAquaSizeMini: - GetThemeMetric(kThemeMetricMiniTabHeight, &tabh); - GetThemeMetric(kThemeMetricMiniTabFrameOverlap, &overlap); - break; - case QAquaSizeSmall: - GetThemeMetric(kThemeSmallTabHeight, &tabh); - GetThemeMetric(kThemeMetricSmallTabFrameOverlap, &overlap); - break; - } - tabh += overlap; - if (sz.height() < tabh) - sz.rheight() = tabh; + if (setWidth) + sz.setWidth(sz.width() + widgetWidth + padding); + sz.setHeight(qMax(sz.height(), maxWidgetHeight)); } } break; @@ -5859,7 +5652,7 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, h = qMax(h, iconSize.height() + 4); maxpmw = qMax(maxpmw, iconSize.width()); } else { - int iconExtent = pixelMetric(PM_SmallIconSize); + int iconExtent = proxy()->pixelMetric(PM_SmallIconSize); h = qMax(h, mi->icon.actualSize(QSize(iconExtent, iconExtent)).height() + 4); } } @@ -5888,6 +5681,14 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, } break; case CT_ToolButton: + if (widget && qobject_cast<const QToolBar *>(widget->parentWidget())) { + sz.rwidth() += 4; + if (sz.height() <= 32) { + // Workaround strange HIToolBar bug when getting constraints. + sz.rheight() += 1; + } + return sz; + } sz.rwidth() += 10; sz.rheight() += 10; return sz; @@ -5898,7 +5699,7 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, QStyleHintReturnMask menuMask; QStyleOption myOption = *opt; myOption.rect.setSize(sz); - if (styleHint(SH_Menu_Mask, &myOption, widget, &menuMask)) { + if (proxy()->styleHint(SH_Menu_Mask, &myOption, widget, &menuMask)) { sz = menuMask.region.boundingRect().size(); } break; } @@ -6067,78 +5868,12 @@ bool QMacStyle::event(QEvent *e) return false; } -void qt_mac_constructQIconFromIconRef(const IconRef icon, const IconRef overlayIcon, QIcon *retIcon, QStyle::StandardPixmap standardIcon = QStyle::SP_CustomBase) -{ - int size = 16; - while (size <= 128) { - - const QString cacheKey = QLatin1String("qt_mac_constructQIconFromIconRef") + QString::number(standardIcon) + QString::number(size); - QPixmap mainIcon; - if (standardIcon >= QStyle::SP_CustomBase) { - mainIcon = qt_mac_convert_iconref(icon, size, size); - } else if (QPixmapCache::find(cacheKey, mainIcon) == false) { - mainIcon = qt_mac_convert_iconref(icon, size, size); - QPixmapCache::insert(cacheKey, mainIcon); - } - - if (overlayIcon) { - int littleSize = size / 2; - QPixmap overlayPix = qt_mac_convert_iconref(overlayIcon, littleSize, littleSize); - QPainter painter(&mainIcon); - painter.drawPixmap(size - littleSize, size - littleSize, overlayPix); - } - - retIcon->addPixmap(mainIcon); - size += size; // 16 -> 32 -> 64 -> 128 - } -} - QIcon QMacStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *opt, const QWidget *widget) const { - OSType iconType = 0; switch (standardIcon) { - case QStyle::SP_MessageBoxQuestion: - case QStyle::SP_MessageBoxInformation: - case QStyle::SP_MessageBoxWarning: - case QStyle::SP_MessageBoxCritical: - iconType = kGenericApplicationIcon; - break; - case SP_DesktopIcon: - iconType = kDesktopIcon; - break; - case SP_TrashIcon: - iconType = kTrashIcon; - break; -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) - case SP_ComputerIcon: - iconType = kComputerIcon; - break; -#endif - case SP_DriveFDIcon: - iconType = kGenericFloppyIcon; - break; - case SP_DriveHDIcon: - iconType = kGenericHardDiskIcon; - break; - case SP_DriveCDIcon: - case SP_DriveDVDIcon: - iconType = kGenericCDROMIcon; - break; - case SP_DriveNetIcon: - iconType = kGenericNetworkIcon; - break; - case SP_DirOpenIcon: - iconType = kOpenFolderIcon; - break; - case SP_DirClosedIcon: - case SP_DirLinkIcon: - iconType = kGenericFolderIcon; - break; - case SP_FileLinkIcon: - case SP_FileIcon: - iconType = kGenericDocumentIcon; - break; + default: + return QWindowsStyle::standardIconImplementation(standardIcon, opt, widget); case SP_ToolBarHorizontalExtensionButton: case SP_ToolBarVerticalExtensionButton: { QPixmap pixmap(qt_mac_toolbar_ext); @@ -6152,58 +5887,8 @@ QIcon QMacStyle::standardIconImplementation(StandardPixmap standardIcon, const Q return pix2; } return pixmap; - } - break; - case SP_DirIcon: { - // A rather special case - QIcon closeIcon = QStyle::standardIcon(SP_DirClosedIcon, opt, widget); - QIcon openIcon = QStyle::standardIcon(SP_DirOpenIcon, opt, widget); - closeIcon.addPixmap(openIcon.pixmap(16, 16), QIcon::Normal, QIcon::On); - closeIcon.addPixmap(openIcon.pixmap(32, 32), QIcon::Normal, QIcon::On); - closeIcon.addPixmap(openIcon.pixmap(64, 64), QIcon::Normal, QIcon::On); - closeIcon.addPixmap(openIcon.pixmap(128, 128), QIcon::Normal, QIcon::On); - return closeIcon; - } - case SP_TitleBarNormalButton: - case SP_TitleBarCloseButton: { - QIcon titleBarIcon; - if (standardIcon == SP_TitleBarCloseButton) { - titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/closedock-16.png")); - titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/closedock-down-16.png"), QSize(16, 16), QIcon::Normal, QIcon::On); - } else { - titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/dockdock-16.png")); - titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/dockdock-down-16.png"), QSize(16, 16), QIcon::Normal, QIcon::On); - } - return titleBarIcon; } - default: - break; - } - if (iconType != 0) { - QIcon retIcon; - IconRef icon; - IconRef overlayIcon = 0; - if (iconType != kGenericApplicationIcon) { - GetIconRef(kOnSystemDisk, kSystemIconsCreator, iconType, &icon); - } else { - FSRef fsRef; - ProcessSerialNumber psn = { 0, kCurrentProcess }; - GetProcessBundleLocation(&psn, &fsRef); - GetIconRefFromFileInfo(&fsRef, 0, 0, 0, 0, kIconServicesNormalUsageFlag, &icon, 0); - if (standardIcon == SP_MessageBoxCritical) { - overlayIcon = icon; - GetIconRef(kOnSystemDisk, kSystemIconsCreator, kAlertCautionIcon, &icon); - } - } - if (icon) { - qt_mac_constructQIconFromIconRef(icon, overlayIcon, &retIcon, standardIcon); - ReleaseIconRef(icon); - } - if (overlayIcon) - ReleaseIconRef(overlayIcon); - return retIcon; } - return QWindowsStyle::standardIconImplementation(standardIcon, opt, widget); } int QMacStyle::layoutSpacingImplementation(QSizePolicy::ControlType control1, |