Changeset 561 for trunk/src/gui/styles/qmacstyle_mac.mm
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/styles/qmacstyle_mac.mm
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** 40 40 ****************************************************************************/ 41 41 42 43 44 45 46 42 47 #include "qmacstyle_mac.h" 43 48 … … 46 51 //#define DEBUG_SIZE_CONSTRAINT 47 52 53 48 54 #include <private/qcombobox_p.h> 49 55 #include <private/qmacstylepixmaps_mac_p.h> … … 51 57 #include <private/qpainter_p.h> 52 58 #include <private/qprintengine_mac_p.h> 59 53 60 #include <qapplication.h> 54 61 #include <qbitmap.h> … … 98 105 99 106 extern QRegion qt_mac_convert_mac_region(RgnHandle); //qregion_mac.cpp 100 extern QHash<QByteArray, QFont> *qt_app_fonts_hash(); // qapplication.cpp101 107 102 108 // The following constants are used for adjusting the size … … 126 132 static const QColor mainWindowGradientEnd(200, 200, 200); 127 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 128 148 129 149 // Resolve these at run-time, since the functions was moved in Leopard. … … 323 343 } 324 344 p->setPen(borderHighlightTop); 325 p->drawLine( 0, 0, width, 0);345 p->drawLine(, 0, width, 0); 326 346 p->setPen(borderTop); 327 p->drawLine( 0, 1, width, 1);347 p->drawLine(, 1, width, 1); 328 348 329 349 // center block 330 QRect centralRect( 0, 2, width, height - 2);350 QRect centralRect(, 2, width, height - 2); 331 351 if (active) { 332 352 QColor mainColor = QColor(120, 120, 120); … … 351 371 } 352 372 p->setPen(borderHighlightBottom); 353 p->drawLine( 0, height - 2, width, height - 2);373 p->drawLine(, height - 2, width, height - 2); 354 374 p->setPen(borderBottom); 355 p->drawLine( 0, height - 1, width, height - 1);375 p->drawLine(, height - 1, width, height - 1); 356 376 } 357 377 … … 487 507 QPainter *p, const QStyleOption *opt) const; 488 508 489 void drawPantherTab(const QStyleOptionTab *tab, QPainter *p, const QWidget *w = 0) const;490 491 509 QSize pushButtonSizeFromContents(const QStyleOptionButton *btn) const; 492 510 … … 541 559 *****************************************************************************/ 542 560 extern CGContextRef qt_mac_cg_context(const QPaintDevice *); //qpaintdevice_mac.cpp 543 extern QPixmap qt_mac_convert_iconref(const IconRef, int, int); //qpixmap_mac.cpp544 561 extern QRegion qt_mac_convert_mac_region(HIShapeRef); //qregion_mac.cpp 545 562 void qt_mac_dispose_rgn(RgnHandle r); //qregion_mac.cpp … … 550 567 *****************************************************************************/ 551 568 const int qt_mac_hitheme_version = 0; //the HITheme version we speak 552 const int macSpinBoxSep = 5; // distance between spinwidget and the lineedit553 569 const int macItemFrame = 2; // menu item frame width 554 570 const int macItemHMargin = 3; // menu item hor text margin … … 563 579 static inline int qt_mac_hitheme_tab_version() 564 580 { 565 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) 566 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) 567 return 1; 568 #endif 569 return 0; 581 return 1; 570 582 } 571 583 … … 833 845 break; 834 846 case QStyle::CT_HeaderSection: 835 if ( sz == QAquaSizeLarge &&isTreeView(widg))847 if (isTreeView(widg)) 836 848 ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricListHeaderHeight)); 837 849 break; … … 1033 1045 csz.setWidth(iconSize.width() + textRect.width() 1034 1046 + ((btn->features & QStyleOptionButton::HasMenu) 1035 ? q->p ixelMetric(QStyle::PM_MenuButtonIndicator, btn, 0) : 0));1047 ? q->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, 0) : 0)); 1036 1048 csz.setHeight(qMax(iconSize.height(), textRect.height())); 1037 1049 return csz; … … 1453 1465 1454 1466 // Tiger broke reverse scroll bars so put them back and "fake it" 1455 if (isScrollbar && (tdi->attributes & kThemeTrackRightToLeft) 1456 && QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { 1467 if (isScrollbar && (tdi->attributes & kThemeTrackRightToLeft)) { 1457 1468 tdi->attributes &= ~kThemeTrackRightToLeft; 1458 1469 tdi->value = tdi->max - slider->sliderPosition; … … 1535 1546 if ((defaultButton || !progressBars.isEmpty()) && timerID <= -1) 1536 1547 timerID = startTimer(animateSpeed(AquaListViewItemOpen)); 1537 }1538 1539 enum { TabNormalLeft, TabNormalMid, TabNormalRight, TabSelectedActiveLeft,1540 TabSelectedActiveMid, TabSelectedActiveRight, TabSelectedInactiveLeft,1541 TabSelectedInactiveMid, TabSelectedInactiveRight, TabSelectedActiveGraphiteLeft,1542 TabSelectedActiveGraphiteMid, TabSelectedActiveGraphiteRight,1543 TabPressedLeft, TabPressedMid, TabPressedRight };1544 1545 static const char * const * const PantherTabXpms[] = {1546 qt_mac_tabnrm_left,1547 qt_mac_tabnrm_mid,1548 qt_mac_tabnrm_right,1549 qt_mac_tabselected_active_left,1550 qt_mac_tabselected_active_mid,1551 qt_mac_tabselected_active_right,1552 qt_mac_tabselected_inactive_left,1553 qt_mac_tabselected_inactive_mid,1554 qt_mac_tabselected_inactive_right,1555 qt_mac_tab_selected_active_graph_left,1556 qt_mac_tab_selected_active_graph_mid,1557 qt_mac_tab_selected_active_graph_right,1558 qt_mac_tab_press_left,1559 qt_mac_tab_press_mid,1560 qt_mac_tab_press_right};1561 1562 void QMacStylePrivate::drawPantherTab(const QStyleOptionTab *tabOpt, QPainter *p,1563 const QWidget *) const1564 {1565 QString tabKey = QLatin1String("$qt_mac_style_tab_");1566 int pantherTabStart;1567 int pantherTabMid;1568 int pantherTabEnd;1569 1570 ThemeTabDirection ttd = getTabDirection(tabOpt->shape);1571 1572 if (tabOpt->state & QStyle::State_Selected) {1573 if (!(tabOpt->state & QStyle::State_Active)) {1574 pantherTabStart = TabSelectedInactiveLeft;1575 } else {1576 // Draw into a pixmap to determine which version we use, Aqua or Graphite.1577 QPixmap tabPix(20, 20);1578 QPainter pixPainter(&tabPix);1579 HIThemeTabDrawInfo tdi;1580 tdi.version = 0;1581 tdi.style = kThemeTabFront;1582 tdi.direction = kThemeTabNorth;1583 tdi.size = kHIThemeTabSizeNormal;1584 tdi.adornment = kHIThemeTabAdornmentNone;1585 HIRect inRect = CGRectMake(0.0f, 0.0f, 20.0f, 20.0f);1586 HIThemeDrawTab(&inRect, &tdi, QMacCGContext(&pixPainter), kHIThemeOrientationNormal, 0);1587 pixPainter.end();1588 const QRgb GraphiteColor = 0xffa7b0ba;1589 QRgb pmColor = tabPix.toImage().pixel(10, 10);1590 if (qAbs(qRed(pmColor) - qRed(GraphiteColor)) < 3 &&1591 qAbs(qGreen(pmColor) - qGreen(GraphiteColor)) < 31592 && qAbs(qBlue(pmColor) - qBlue(GraphiteColor)) < 3)1593 pantherTabStart = TabSelectedActiveGraphiteLeft;1594 else1595 pantherTabStart = TabSelectedActiveLeft;1596 }1597 } else if (tabOpt->state & QStyle::State_Sunken) {1598 pantherTabStart = TabPressedLeft;1599 } else {1600 pantherTabStart = TabNormalLeft;1601 }1602 1603 1604 bool doLine;1605 bool verticalTabs = ttd == kThemeTabWest || ttd == kThemeTabEast;1606 1607 QStyleOptionTab::TabPosition tp = tabOpt->position;1608 if (ttd == kThemeTabWest1609 || ((ttd == kThemeTabNorth || ttd == kThemeTabSouth)1610 && tabOpt->direction == Qt::RightToLeft)) {1611 if (tp == QStyleOptionTab::Beginning)1612 tp = QStyleOptionTab::End;1613 else if (tp == QStyleOptionTab::End)1614 tp = QStyleOptionTab::Beginning;1615 }1616 1617 switch (tp) {1618 default: // Stupid GCC, being overly pedantic1619 case QStyleOptionTab::Beginning:1620 doLine = false;1621 pantherTabMid = pantherTabEnd = pantherTabStart + 1;1622 break;1623 case QStyleOptionTab::Middle:1624 doLine = true;1625 pantherTabMid = pantherTabEnd = ++pantherTabStart;1626 break;1627 case QStyleOptionTab::End:1628 doLine = true;1629 pantherTabMid = ++pantherTabStart;1630 pantherTabEnd = pantherTabMid + 1;1631 break;1632 case QStyleOptionTab::OnlyOneTab:1633 doLine = false;1634 pantherTabMid = pantherTabStart + 1;1635 pantherTabEnd = pantherTabMid + 1;1636 break;1637 }1638 1639 QPixmap pmStart;1640 if (!QPixmapCache::find(tabKey + QString::number(pantherTabStart), pmStart)) {1641 pmStart = QPixmap(PantherTabXpms[pantherTabStart]);1642 QPixmapCache::insert(tabKey + QString::number(pantherTabStart), pmStart);1643 }1644 1645 QPixmap pmMid;1646 if (!QPixmapCache::find(tabKey + QString::number(pantherTabMid), pmMid)) {1647 pmMid = QPixmap(PantherTabXpms[pantherTabMid]);1648 QPixmapCache::insert(tabKey + QString::number(pantherTabMid), pmMid);1649 }1650 1651 QPixmap pmEnd;1652 if (!QPixmapCache::find(tabKey + QString::number(pantherTabEnd), pmEnd)) {1653 pmEnd = QPixmap(PantherTabXpms[pantherTabEnd]);1654 QPixmapCache::insert(tabKey + QString::number(pantherTabEnd), pmEnd);1655 }1656 QRect tr = tabOpt->rect;1657 if (verticalTabs) {1658 p->save();1659 int newX, newY, newRot;1660 if (tabOpt->shape == QTabBar::RoundedEast || tabOpt->shape == QTabBar::TriangularEast) {1661 newX = tr.width();1662 newY = tr.y();1663 newRot = 90;1664 } else {1665 newX = 0;1666 newY = tr.y() + tr.height();1667 newRot = -90;1668 }1669 tr.setRect(0, 0, tr.height(), tr.width());1670 QMatrix m;1671 if (ttd == kThemeTabEast) {1672 // It's lame but Apple inverts these on the East side.1673 m.scale(-1, 1);1674 m.translate(-tabOpt->rect.width(), 0);1675 }1676 m.translate(newX, newY);1677 m.rotate(newRot);1678 p->setMatrix(m, true);1679 }1680 1681 int x = tr.x();1682 int y = tr.y();1683 int endX = x + tr.width() - pmEnd.width();1684 1685 p->drawPixmap(x, y, pmStart.width(), tr.height(), pmStart);1686 if (doLine) {1687 QPen oldPen = p->pen();1688 p->setPen(QColor(0, 0, 0, 0x35));1689 p->drawLine(x, y + (verticalTabs ? 0 : 1), x, tr.height() - 2);1690 }1691 1692 for (x = x + pmStart.width(); x < endX; x += pmMid.width())1693 p->drawPixmap(x, y, pmMid.width(), tr.height(), pmMid);1694 p->drawPixmap(endX, y, pmEnd.width(), tr.height(), pmEnd);1695 if (verticalTabs)1696 p->restore();1697 1548 } 1698 1549 … … 1990 1841 } 1991 1842 1992 /*!1993 \class QMacStyle1994 \brief The QMacStyle class provides a Mac OS X style using the Apple Appearance Manager.1995 1996 \ingroup appearance1997 1998 This class is implemented as a wrapper to the HITheme1999 APIs, allowing applications to be styled according to the current2000 theme in use on Mac OS X. This is done by having primitives2001 in QStyle implemented in terms of what Mac OS X would normally theme.2002 2003 \warning This style is only available on Mac OS X because it relies on the2004 HITheme APIs.2005 2006 There are additional issues that should be taken2007 into consideration to make an application compatible with the2008 \link http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/index.html2009 Apple Human Interface Guidelines \endlink. Some of these issues are outlined2010 below.2011 2012 \list2013 2014 \i Layout - The restrictions on window layout are such that some2015 aspects of layout that are style-dependent cannot be achieved2016 using QLayout. Changes are being considered (and feedback would be2017 appreciated) to make layouts QStyle-able. Some of the restrictions2018 involve horizontal and vertical widget alignment and widget size2019 (covered below).2020 2021 \i Widget size - Mac OS X allows widgets to have specific fixed sizes. Qt2022 does not fully implement this behavior so as to maintain cross-platform2023 compatibility. As a result some widgets sizes may be inappropriate (and2024 subsequently not rendered correctly by the HITheme APIs).The2025 QWidget::sizeHint() will return the appropriate size for many2026 managed widgets (widgets enumerated in \l QStyle::ContentsType).2027 2028 \i Effects - QMacStyle uses HITheme for performing most of the drawing, but2029 also uses emulation in a few cases where HITheme does not provide the2030 required functionality (for example, tab bars on Panther, the toolbar2031 separator, etc). We tried to make the emulation as close to the original as2032 possible. Please report any issues you see in effects or non-standard2033 widgets.2034 2035 \endlist2036 2037 There are other issues that need to be considered in the feel of2038 your application (including the general color scheme to match the2039 Aqua colors). The Guidelines mentioned above will remain current2040 with new advances and design suggestions for Mac OS X.2041 2042 Note that the functions provided by QMacStyle are2043 reimplementations of QStyle functions; see QStyle for their2044 documentation.2045 2046 \img qmacstyle.png2047 \sa QWindowsXPStyle, QWindowsStyle, QPlastiqueStyle, QCDEStyle, QMotifStyle2048 */2049 2050 2051 /*!2052 \enum QMacStyle::WidgetSizePolicy2053 2054 \value SizeSmall2055 \value SizeLarge2056 \value SizeMini2057 \value SizeDefault2058 \omitvalue SizeNone2059 */2060 2061 /*!2062 Constructs a QMacStyle object.2063 */2064 1843 QMacStyle::QMacStyle() 2065 1844 : QWindowsStyle() … … 2068 1847 } 2069 1848 2070 /*!2071 Destructs a QMacStyle object.2072 */2073 1849 QMacStyle::~QMacStyle() 2074 1850 { … … 2084 1860 { 2085 1861 QPixmap px(4, 4); 2086 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) 2087 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { 2088 QMacCGContext cg(&px); 2089 HIThemeSetFill(kThemeBrushDialogBackgroundActive, 0, cg, kHIThemeOrientationNormal); 2090 const CGRect cgRect = CGRectMake(0, 0, px.width(), px.height()); 2091 CGContextFillRect(cg, cgRect); 2092 } else 2093 #endif 2094 { 2095 #ifndef QT_MAC_NO_QUICKDRAW 2096 QMacSavedPortInfo port(&px); 2097 SetThemeBackground(kThemeBrushDialogBackgroundActive, px.depth(), true); 2098 const Rect qdRect = { 0, 0, px.width(), px.height() }; 2099 EraseRect(&qdRect); 2100 #endif 2101 } 1862 QMacCGContext cg(&px); 1863 HIThemeSetFill(kThemeBrushDialogBackgroundActive, 0, cg, kHIThemeOrientationNormal); 1864 const CGRect cgRect = CGRectMake(0, 0, px.width(), px.height()); 1865 CGContextFillRect(cg, cgRect); 2102 1866 return px; 2103 1867 } … … 2107 1871 HIThemeSetFill us used directly if we are filling with the standard background. 2108 1872 */ 2109 void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QPoint &offset, const QBrush &brush) 2110 { 2111 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) 1873 void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush) 1874 { 2112 1875 QPoint dummy; 2113 1876 const QPaintDevice *target = painter->device(); 2114 1877 const QPaintDevice *redirected = QPainter::redirected(target, &dummy); 2115 1878 const bool usePainter = redirected && redirected != target; 2116 const QRegion translated = rgn.translated(offset); 2117 2118 if (!usePainter && QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4 && qt_mac_backgroundPattern 1879 1880 if (!usePainter && qt_mac_backgroundPattern 2119 1881 && qt_mac_backgroundPattern->cacheKey() == brush.texture().cacheKey()) { 2120 1882 2121 painter->setClipRegion( translated);1883 painter->setClipRegion(); 2122 1884 2123 1885 CGContextRef cg = qt_mac_cg_context(target); … … 2125 1887 HIThemeSetFill(kThemeBrushDialogBackgroundActive, 0, cg, kHIThemeOrientationInverted); 2126 1888 2127 const QVector<QRect> &rects = translated.rects();1889 const QVector<QRect> &rects = .rects(); 2128 1890 for (int i = 0; i < rects.size(); ++i) { 2129 1891 const QRect rect(rects.at(i)); … … 2135 1897 2136 1898 CGContextRestoreGState(cg); 2137 } else 2138 #endif 2139 { 2140 const QRect rect(translated.boundingRect()); 2141 painter->setClipRegion(translated); 1899 } else { 1900 const QRect rect(rgn.boundingRect()); 1901 painter->setClipRegion(rgn); 2142 1902 painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft()); 2143 1903 } 2144 1904 } 2145 1905 2146 /*! \reimp */2147 1906 void QMacStyle::polish(QPalette &pal) 2148 1907 { 2149 if (qt_mac_backgroundPattern == 0) 1908 if (!qt_mac_backgroundPattern) { 1909 if (!qApp) 1910 return; 2150 1911 qt_mac_backgroundPattern = new QPixmap(d->generateBackgroundPattern()); 1912 2151 1913 2152 1914 QColor pc(Qt::black); … … 2165 1927 } 2166 1928 2167 /*! \reimp */2168 1929 void QMacStyle::polish(QApplication *) 2169 1930 { 2170 1931 } 2171 1932 2172 /*! \reimp */2173 1933 void QMacStyle::unpolish(QApplication *) 2174 1934 { 2175 1935 } 2176 1936 2177 /*! \reimp */2178 1937 void QMacStyle::polish(QWidget* w) 2179 1938 { … … 2193 1952 if (!w->testAttribute(Qt::WA_SetPalette)) { 2194 1953 QPixmap px(64, 64); 1954 2195 1955 HIThemeMenuDrawInfo mtinfo; 2196 1956 mtinfo.version = qt_mac_hitheme_version; … … 2208 1968 } 2209 1969 2210 // Adjust the lineedit of the editable combo box2211 if (QSysInfo::MacintoshVersion == QSysInfo::MV_10_3) {2212 if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(w)) {2213 if (qobject_cast<QComboBox *>(lineEdit->parentWidget())2214 && !lineEdit->testAttribute(Qt::WA_SetFont)) {2215 QFont font = lineEdit->font();2216 font.setPointSize(font.pointSize() - 1);2217 lineEdit->setFont(font);2218 }2219 }2220 }2221 2222 1970 if (QTabBar *tb = qobject_cast<QTabBar*>(w)) { 2223 1971 if (tb->documentMode()) { … … 2239 1987 } 2240 1988 2241 /*! \reimp */2242 1989 void QMacStyle::unpolish(QWidget* w) 2243 1990 { … … 2270 2017 } 2271 2018 2272 /*! \reimp */2273 2019 int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QWidget *widget) const 2274 2020 { … … 2282 2028 break; 2283 2029 case PM_ToolBarIconSize: 2284 ret = p ixelMetric(PM_LargeIconSize);2030 ret = pixelMetric(PM_LargeIconSize); 2285 2031 break; 2286 2032 case PM_FocusFrameVMargin: … … 2374 2120 case PM_SpinBoxFrameWidth: 2375 2121 GetThemeMetric(kThemeMetricEditTextFrameOutset, &ret); 2376 ret += 2; 2122 switch (d->aquaSizeConstrain(opt, widget)) { 2123 default: 2124 ret += 2; 2125 break; 2126 case QAquaSizeMini: 2127 ret += 1; 2128 break; 2129 } 2377 2130 break; 2378 2131 case PM_ButtonShiftHorizontal: … … 2403 2156 QCFType<HIShapeRef> region; 2404 2157 HIRect hirect = qt_hirectForQRect(tb->rect); 2405 if (hirect.size.width == -1)2158 if (hirect.size.width ) 2406 2159 hirect.size.width = 100; 2407 if (hirect.size.height == -1)2160 if (hirect.size.height ) 2408 2161 hirect.size.height = 30; 2409 2162 … … 2449 2202 break; 2450 2203 case QAquaSizeMini: 2451 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3) && 02452 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_3) {2453 GetThemeMetric(kThemeMetricMiniScrollBarWidth, &ret);2454 break;2455 }2456 #endif2457 2204 case QAquaSizeSmall: 2458 2205 GetThemeMetric(kThemeMetricSmallScrollBarWidth, &ret); … … 2556 2303 case PM_ToolBarItemSpacing: 2557 2304 ret = 4; 2558 break;2559 case PM_MessageBoxIconSize:2560 ret = 64;2561 2305 break; 2562 2306 case PM_SplitterWidth: … … 2635 2379 ret = 0; 2636 2380 break; 2381 2382 2383 2637 2384 default: 2638 2385 ret = QWindowsStyle::pixelMetric(metric, opt, widget); … … 2642 2389 } 2643 2390 2644 /*! \reimp */2645 2391 QPalette QMacStyle::standardPalette() const 2646 2392 { … … 2652 2398 } 2653 2399 2654 /*! \reimp */2655 2400 int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w, 2656 2401 QStyleHintReturn *hret) const … … 2798 2543 pix.fill(QColor(fillR, fillG, fillB)); 2799 2544 QPainter pix_paint(&pix); 2800 drawControl(CE_FocusFrame, opt, &pix_paint, w);2545 drawControl(CE_FocusFrame, opt, &pix_paint, w); 2801 2546 pix_paint.end(); 2802 2547 img = pix.toImage(); … … 2947 2692 } 2948 2693 2949 /*! \reimp */2950 2694 QPixmap QMacStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, 2951 2695 const QStyleOption *opt) const … … 2973 2717 2974 2718 2975 /*! \reimp */2976 2719 QPixmap QMacStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, 2977 2720 const QWidget *widget) const … … 3004 2747 return icon.pixmap(size, size); 3005 2748 } 3006 /*! 3007 \enum QMacStyle::FocusRectPolicy 3008 3009 This type is used to signify a widget's focus rectangle policy. 3010 3011 \value FocusEnabled show a focus rectangle when the widget has focus. 3012 \value FocusDisabled never show a focus rectangle for the widget. 3013 \value FocusDefault show a focus rectangle when the widget has 3014 focus and the widget is a QSpinWidget, QDateTimeEdit, QLineEdit, 3015 QListBox, QListView, editable QTextEdit, or one of their 3016 subclasses. 3017 */ 3018 3019 /*! 3020 \obsolete 3021 Sets the focus rectangle policy of \a w. The \a policy can be one of 3022 \l{QMacStyle::FocusRectPolicy}. 3023 3024 This is now simply an interface to the Qt::WA_MacShowFocusRect attribute and the 3025 FocusDefault value does nothing anymore. If you want to set a widget back 3026 to its default value, you must save the old value of the attribute before 3027 you change it. 3028 3029 \sa focusRectPolicy() QWidget::setAttribute() 3030 */ 2749 3031 2750 void QMacStyle::setFocusRectPolicy(QWidget *w, FocusRectPolicy policy) 3032 2751 { … … 3041 2760 } 3042 2761 3043 /*!3044 \obsolete3045 Returns the focus rectangle policy for the widget \a w.3046 3047 The focus rectangle policy can be one of \l{QMacStyle::FocusRectPolicy}.3048 3049 In 4.3 and up this function will simply test for the3050 Qt::WA_MacShowFocusRect attribute and will never return3051 QMacStyle::FocusDefault.3052 3053 \sa setFocusRectPolicy(), QWidget::testAttribute()3054 */3055 2762 QMacStyle::FocusRectPolicy QMacStyle::focusRectPolicy(const QWidget *w) 3056 2763 { … … 3058 2765 } 3059 2766 3060 /*!3061 \obsolete3062 3063 Call QWidget::setAttribute() with Qt::WA_MacMiniSize, Qt::WA_MacSmallSize,3064 or Qt::WA_MacNormalSize instead.3065 */3066 2767 void QMacStyle::setWidgetSizePolicy(const QWidget *widget, WidgetSizePolicy policy) 3067 2768 { … … 3072 2773 } 3073 2774 3074 /*!3075 \obsolete3076 3077 Call QWidget::testAttribute() with Qt::WA_MacMiniSize, Qt::WA_MacSmallSize,3078 or Qt::WA_MacNormalSize instead.3079 */3080 2775 QMacStyle::WidgetSizePolicy QMacStyle::widgetSizePolicy(const QWidget *widget) 3081 2776 { … … 3093 2788 } 3094 2789 3095 /*! \reimp */3096 2790 void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, 3097 2791 const QWidget *w) const … … 3164 2858 break; 3165 2859 } 3166 drawPrimitive(PE_FrameTabWidget, &twf, p, w);2860 drawPrimitive(PE_FrameTabWidget, &twf, p, w); 3167 2861 p->restore(); 3168 2862 } … … 3262 2956 // In HITheme, up is down, down is up and hamburgers eat people. 3263 2957 if (header->sortIndicator != QStyleOptionHeader::None) 3264 drawPrimitive(2958 drawPrimitive( 3265 2959 (header->sortIndicator == QStyleOptionHeader::SortDown) ? 3266 2960 PE_IndicatorArrowUp : PE_IndicatorArrowDown, header, p, w); … … 3396 3090 int lw = frame->lineWidth; 3397 3091 if (lw <= 0) 3398 lw = p ixelMetric(PM_DefaultFrameWidth, frame, w);3092 lw = pixelMetric(PM_DefaultFrameWidth, frame, w); 3399 3093 { //clear to base color 3400 3094 p->save(); … … 3421 3115 = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) { 3422 3116 HIRect hirect = qt_hirectForQRect(twf->rect); 3423 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) 3424 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { 3425 HIThemeTabPaneDrawInfo tpdi; 3426 tpdi.version = qt_mac_hitheme_tab_version(); 3427 tpdi.state = tds; 3428 tpdi.direction = getTabDirection(twf->shape); 3429 tpdi.size = kHIThemeTabSizeNormal; 3430 if (tpdi.version == 1) { 3431 tpdi.kind = kHIThemeTabKindNormal; 3432 tpdi.adornment = kHIThemeTabPaneAdornmentNormal; 3433 } 3434 HIThemeDrawTabPane(&hirect, &tpdi, cg, kHIThemeOrientationNormal); 3435 } else 3436 #endif 3437 { 3438 HIThemeGroupBoxDrawInfo gdi; 3439 gdi.version = qt_mac_hitheme_version; 3440 gdi.state = tds; 3441 gdi.kind = kHIThemeGroupBoxKindSecondary; 3442 HIThemeDrawGroupBox(&hirect, &gdi, cg, kHIThemeOrientationNormal); 3443 } 3117 HIThemeTabPaneDrawInfo tpdi; 3118 tpdi.version = qt_mac_hitheme_tab_version(); 3119 tpdi.state = tds; 3120 tpdi.direction = getTabDirection(twf->shape); 3121 tpdi.size = kHIThemeTabSizeNormal; 3122 tpdi.kind = kHIThemeTabKindNormal; 3123 tpdi.adornment = kHIThemeTabPaneAdornmentNormal; 3124 HIThemeDrawTabPane(&hirect, &tpdi, cg, kHIThemeOrientationNormal); 3444 3125 } 3445 3126 break; … … 3465 3146 break; 3466 3147 } 3467 3468 3148 // Use the Leopard style only if the status bar is the status bar for a 3469 3149 // QMainWindow with a unifed toolbar. … … 3526 3206 3527 3207 3528 /*! \reimp */3529 3208 void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter *p, 3530 3209 const QWidget *w) const … … 3610 3289 if (opt->state & State_Enabled) 3611 3290 mode = QIcon::Normal; 3612 QPixmap pixmap = header->icon.pixmap(p ixelMetric(PM_SmallIconSize), mode);3291 QPixmap pixmap = header->icon.pixmap(pixelMetric(PM_SmallIconSize), mode); 3613 3292 3614 3293 QRect pixr = header->rect; 3615 3294 pixr.setY(header->rect.center().y() - (pixmap.height() - 1) / 2); 3616 drawItemPixmap(p, pixr, Qt::AlignVCenter, pixmap);3295 drawItemPixmap(p, pixr, Qt::AlignVCenter, pixmap); 3617 3296 textr.translate(pixmap.width() + 2, 0); 3618 3297 } 3619 3298 3620 drawItemText(p, textr, header->textAlignment | Qt::AlignVCenter, header->palette,3621 header->state & State_Enabled, header->text, QPalette::ButtonText);3299 drawItemText(p, textr, header->textAlignment | Qt::AlignVCenter, header->palette, 3300 header->state & State_Enabled, header->text, QPalette::ButtonText); 3622 3301 } 3623 3302 break; … … 3630 3309 int shiftX = 0; 3631 3310 int shiftY = 0; 3632 if (tb->state & (State_Sunken | State_On)) { 3633 shiftX = pixelMetric(PM_ButtonShiftHorizontal, tb, w); 3634 shiftY = pixelMetric(PM_ButtonShiftVertical, tb, w); 3311 bool needText = false; 3312 int alignment = 0; 3313 bool down = tb->state & (State_Sunken | State_On); 3314 if (down) { 3315 shiftX = proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, w); 3316 shiftY = proxy()->pixelMetric(PM_ButtonShiftVertical, tb, w); 3635 3317 } 3636 3318 // The down state is special for QToolButtons in a toolbar on the Mac … … 3638 3320 // This doesn't really fit into any particular case in QIcon, so we 3639 3321 // do the majority of the work ourselves. 3640 if (tb->state & State_Sunken 3641 && !(tb->features & QStyleOptionToolButton::Arrow)) { 3322 if (!(tb->features & QStyleOptionToolButton::Arrow)) { 3642 3323 Qt::ToolButtonStyle tbstyle = tb->toolButtonStyle; 3643 3324 if (tb->icon.isNull() && !tb->text.isEmpty()) … … 3645 3326 3646 3327 switch (tbstyle) { 3647 case Qt::ToolButtonTextOnly: 3648 drawItemText(p, cr, Qt::AlignCenter, tb->palette,3649 tb->state & State_Enabled, tb->text);3650 break; 3328 case Qt::ToolButtonTextOnly: 3329 3330 ; 3331 break; 3651 3332 case Qt::ToolButtonIconOnly: 3652 3333 case Qt::ToolButtonTextBesideIcon: … … 3654 3335 QRect pr = cr; 3655 3336 QIcon::Mode iconMode = (tb->state & State_Enabled) ? QIcon::Normal 3656 3337 : QIcon::Disabled; 3657 3338 QIcon::State iconState = (tb->state & State_On) ? QIcon::On 3658 3339 : QIcon::Off; 3659 3340 QPixmap pixmap = tb->icon.pixmap(tb->rect.size().boundedTo(tb->iconSize), iconMode, iconState); 3660 3341 3661 3342 // Draw the text if it's needed. 3662 3343 if (tb->toolButtonStyle != Qt::ToolButtonIconOnly) { 3663 int alignment = 0;3344 ; 3664 3345 if (tb->toolButtonStyle == Qt::ToolButtonTextUnderIcon) { 3665 pr.setHeight(pixmap.size().height() + 6);3666 cr.adjust(0, pr.bottom() , 0, -3);3346 pr.setHeight(pixmap.size().height()); 3347 cr.adjust(0, pr.bottom()); 3667 3348 alignment |= Qt::AlignCenter; 3668 3349 } else { … … 3671 3352 alignment |= Qt::AlignLeft | Qt::AlignVCenter; 3672 3353 } 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3673 3370 cr.translate(shiftX, shiftY); 3674 drawItemText(p, cr, alignment, tb->palette, 3675 tb->state & State_Enabled, tb->text); 3676 cr.adjust(0, 3, 0, -3); // the drop shadow 3677 drawItemText(p, cr, alignment, tb->palette, 3678 tb->state & State_Enabled, tb->text); 3371 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5 3372 && (tbstyle == Qt::ToolButtonTextOnly 3373 || (tbstyle != Qt::ToolButtonTextOnly && !down))) { 3374 QPen pen = p->pen(); 3375 QColor light = down ? Qt::black : Qt::white; 3376 light.setAlphaF(0.375f); 3377 p->setPen(light); 3378 p->drawText(cr.adjusted(0, 1, 0, 1), alignment, tb->text); 3379 p->setPen(pen); 3380 if (down && tbstyle == Qt::ToolButtonTextOnly) { 3381 pal = QApplication::palette("QMenu"); 3382 pal.setCurrentColorGroup(tb->palette.currentColorGroup()); 3383 role = QPalette::HighlightedText; 3384 } 3679 3385 } 3680 pr.translate(shiftX, shiftY); 3681 pixmap = darkenPixmap(pixmap); 3682 drawItemPixmap(p, pr, Qt::AlignCenter, pixmap); 3683 break; } 3386 drawItemText(p, cr, alignment, pal, 3387 tb->state & State_Enabled, tb->text, role); 3388 if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_5 && 3389 (tb->state & State_Sunken)) { 3390 // Draw a "drop shadow" in earlier versions. 3391 drawItemText(p, cr.adjusted(0, 1, 0, 1), alignment, 3392 tb->palette, tb->state & State_Enabled, tb->text); 3393 } 3684 3394 } 3685 3395 } else { … … 3731 3441 3732 3442 if (btn->features & QStyleOptionButton::HasMenu) { 3733 int mbi = p ixelMetric(QStyle::PM_MenuButtonIndicator, btn, w);3443 int mbi = pixelMetric(QStyle::PM_MenuButtonIndicator, btn, w); 3734 3444 QRect ir = btn->rect; 3735 3445 HIRect arrowRect = CGRectMake(ir.right() - mbi - PushButtonRightOffset, … … 3818 3528 int contentW = textRect.width(); 3819 3529 if (hasMenu) 3820 contentW += p ixelMetric(PM_MenuButtonIndicator) + 4;3530 contentW += pixelMetric(PM_MenuButtonIndicator) + 4; 3821 3531 QIcon::Mode mode = btn->state & State_Enabled ? QIcon::Normal : QIcon::Disabled; 3822 3532 if (mode == QIcon::Normal && btn->state & State_HasFocus) … … 3832 3542 QRect iconDestRect(iconLeftOffset, iconTopOffset, pixmap.width(), pixmap.height()); 3833 3543 QRect visualIconDestRect = visualRect(btn->direction, freeContentRect, iconDestRect); 3834 drawItemPixmap(p, visualIconDestRect, Qt::AlignLeft | Qt::AlignVCenter, pixmap);3544 drawItemPixmap(p, visualIconDestRect, Qt::AlignLeft | Qt::AlignVCenter, pixmap); 3835 3545 int newOffset = iconDestRect.x() + iconDestRect.width() 3836 3546 + PushButtonContentPadding - textRect.x(); … … 3840 3550 if (hasText) { 3841 3551 textRect = visualRect(btn->direction, freeContentRect, textRect); 3842 drawItemText(p, textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, btn->palette,3843 (btn->state & State_Enabled), btn->text, QPalette::ButtonText);3552 drawItemText(p, textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, btn->palette, 3553 (btn->state & State_Enabled), btn->text, QPalette::ButtonText); 3844 3554 } 3845 3555 } … … 3866 3576 } 3867 3577 } 3868 3869 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) 3870 if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_3) { 3871 HIThemeTabDrawInfo tdi; 3872 tdi.version = 1; 3873 tdi.style = kThemeTabNonFront; 3874 tdi.direction = getTabDirection(tabOpt->shape); 3875 switch (d->aquaSizeConstrain(opt, w)) { 3578 HIThemeTabDrawInfo tdi; 3579 tdi.version = 1; 3580 tdi.style = kThemeTabNonFront; 3581 tdi.direction = getTabDirection(tabOpt->shape); 3582 switch (d->aquaSizeConstrain(opt, w)) { 3583 default: 3584 case QAquaSizeUnknown: 3585 case QAquaSizeLarge: 3586 tdi.size = kHIThemeTabSizeNormal; 3587 break; 3588 case QAquaSizeSmall: 3589 tdi.size = kHIThemeTabSizeSmall; 3590 break; 3591 case QAquaSizeMini: 3592 tdi.size = kHIThemeTabSizeMini; 3593 break; 3594 } 3595 bool verticalTabs = tdi.direction == kThemeTabWest || tdi.direction == kThemeTabEast; 3596 QRect tabRect = tabOpt->rect; 3597 3598 bool selected = tabOpt->state & State_Selected; 3599 if (selected) { 3600 if (!(tabOpt->state & State_Active)) 3601 tdi.style = kThemeTabFrontUnavailable; 3602 else if (!(tabOpt->state & State_Enabled)) 3603 tdi.style = kThemeTabFrontInactive; 3604 else 3605 tdi.style = kThemeTabFront; 3606 } else if (!(tabOpt->state & State_Active)) { 3607 tdi.style = kThemeTabNonFrontUnavailable; 3608 } else if (!(tabOpt->state & State_Enabled)) { 3609 tdi.style = kThemeTabNonFrontInactive; 3610 } else if (tabOpt->state & State_Sunken) { 3611 tdi.style = kThemeTabFrontInactive; // (should be kThemeTabNonFrontPressed) 3612 } 3613 if (tabOpt->state & State_HasFocus) 3614 tdi.adornment = kHIThemeTabAdornmentFocus; 3615 else 3616 tdi.adornment = kHIThemeTabAdornmentNone; 3617 tdi.kind = kHIThemeTabKindNormal; 3618 if (!verticalTabs) 3619 tabRect.setY(tabRect.y() - 1); 3620 else 3621 tabRect.setX(tabRect.x() - 1); 3622 QStyleOptionTab::TabPosition tp = tabOpt->position; 3623 QStyleOptionTab::SelectedPosition sp = tabOpt->selectedPosition; 3624 if (tabOpt->direction == Qt::RightToLeft && !verticalTabs) { 3625 if (sp == QStyleOptionTab::NextIsSelected) 3626 sp = QStyleOptionTab::PreviousIsSelected; 3627 else if (sp == QStyleOptionTab::PreviousIsSelected) 3628 sp = QStyleOptionTab::NextIsSelected; 3629 switch (tp) { 3630 case QStyleOptionTab::Beginning: 3631 tp = QStyleOptionTab::End; 3632 break; 3633 case QStyleOptionTab::End: 3634 tp = QStyleOptionTab::Beginning; 3635 break; 3876 3636 default: 3877 case QAquaSizeUnknown:3878 case QAquaSizeLarge:3879 tdi.size = kHIThemeTabSizeNormal;3880 3637 break; 3881 case QAquaSizeSmall: 3882 tdi.size = kHIThemeTabSizeSmall; 3883 break; 3884 case QAquaSizeMini: 3885 tdi.size = kHIThemeTabSizeMini; 3886 break; 3887 } 3888 bool verticalTabs = tdi.direction == kThemeTabWest || tdi.direction == kThemeTabEast; 3889 QRect tabRect = tabOpt->rect; 3890 3891 if ((!verticalTabs && tabRect.height() > 21 || verticalTabs && tabRect.width() > 21)) { 3892 d->drawPantherTab(tabOpt, p, w); 3893 break; 3894 } 3895 3896 bool selected = tabOpt->state & State_Selected; 3897 if (selected) { 3898 if (!(tabOpt->state & State_Active)) 3899 tdi.style = kThemeTabFrontUnavailable; 3900 else if (!(tabOpt->state & State_Enabled)) 3901 tdi.style = kThemeTabFrontInactive; 3902 else 3903 tdi.style = kThemeTabFront; 3904 } else if (!(tabOpt->state & State_Active)) { 3905 tdi.style = kThemeTabNonFrontUnavailable; 3906 } else if (!(tabOpt->state & State_Enabled)) { 3907 tdi.style = kThemeTabNonFrontInactive; 3908 } else if (tabOpt->state & State_Sunken) { 3909 tdi.style = kThemeTabFrontInactive; // (should be kThemeTabNonFrontPressed) 3910 } 3911 if (tabOpt->state & State_HasFocus) 3912 tdi.adornment = kHIThemeTabAdornmentFocus; 3913 else 3914 tdi.adornment = kHIThemeTabAdornmentNone; 3915 tdi.kind = kHIThemeTabKindNormal; 3916 if (!verticalTabs) 3917 tabRect.setY(tabRect.y() - 1); 3918 else 3919 tabRect.setX(tabRect.x() - 1); 3920 QStyleOptionTab::TabPosition tp = tabOpt->position; 3921 QStyleOptionTab::SelectedPosition sp = tabOpt->selectedPosition; 3922 if (tabOpt->direction == Qt::RightToLeft && !verticalTabs) { 3923 if (sp == QStyleOptionTab::NextIsSelected) 3924 sp = QStyleOptionTab::PreviousIsSelected; 3925 else if (sp == QStyleOptionTab::PreviousIsSelected) 3926 sp = QStyleOptionTab::NextIsSelected; 3927 switch (tp) { 3928 case QStyleOptionTab::Beginning: 3929 tp = QStyleOptionTab::End; 3930 break; 3931 case QStyleOptionTab::End: 3932 tp = QStyleOptionTab::Beginning; 3933 break; 3934 default: 3935 break; 3936 } 3937 } 3938 switch (tp) { 3939 case QStyleOptionTab::Beginning: 3940 tdi.position = kHIThemeTabPositionFirst; 3941 if (sp != QStyleOptionTab::NextIsSelected) 3942 tdi.adornment |= kHIThemeTabAdornmentTrailingSeparator; 3943 break; 3944 case QStyleOptionTab::Middle: 3945 tdi.position = kHIThemeTabPositionMiddle; 3946 if (selected) 3947 tdi.adornment |= kHIThemeTabAdornmentLeadingSeparator; 3948 if (sp != QStyleOptionTab::NextIsSelected) // Also when we're selected. 3949 tdi.adornment |= kHIThemeTabAdornmentTrailingSeparator; 3950 break; 3951 case QStyleOptionTab::End: 3952 tdi.position = kHIThemeTabPositionLast; 3953 if (selected) 3954 tdi.adornment |= kHIThemeTabAdornmentLeadingSeparator; 3955 break; 3956 case QStyleOptionTab::OnlyOneTab: 3957 tdi.position = kHIThemeTabPositionOnly; 3958 break; 3959 } 3638 } 3639 } 3640 bool stretchTabs = (!verticalTabs && tabRect.height() > 22 || verticalTabs && tabRect.width() > 22); 3641 3642 switch (tp) { 3643 case QStyleOptionTab::Beginning: 3644 tdi.position = kHIThemeTabPositionFirst; 3645 if (sp != QStyleOptionTab::NextIsSelected || stretchTabs) 3646 tdi.adornment |= kHIThemeTabAdornmentTrailingSeparator; 3647 break; 3648 case QStyleOptionTab::Middle: 3649 tdi.position = kHIThemeTabPositionMiddle; 3650 if (selected) 3651 tdi.adornment |= kHIThemeTabAdornmentLeadingSeparator; 3652 if (sp != QStyleOptionTab::NextIsSelected || stretchTabs) // Also when we're selected. 3653 tdi.adornment |= kHIThemeTabAdornmentTrailingSeparator; 3654 break; 3655 case QStyleOptionTab::End: 3656 tdi.position = kHIThemeTabPositionLast; 3657 if (selected) 3658 tdi.adornment |= kHIThemeTabAdornmentLeadingSeparator; 3659 break; 3660 case QStyleOptionTab::OnlyOneTab: 3661 tdi.position = kHIThemeTabPositionOnly; 3662 break; 3663 } 3664 // HITheme doesn't stretch its tabs. Therefore we have to cheat and do the job ourselves. 3665 if (stretchTabs) { 3666 HIRect hirect = CGRectMake(0, 0, 23, 23); 3667 QPixmap pm(23, 23); 3668 pm.fill(Qt::transparent); 3669 { 3670 QMacCGContext pmcg(&pm); 3671 HIThemeDrawTab(&hirect, &tdi, pmcg, kHIThemeOrientationNormal, 0); 3672 } 3673 QStyleHelper::drawBorderPixmap(pm, p, tabRect, 7, 7, 7, 7); 3674 } else { 3960 3675 HIRect hirect = qt_hirectForQRect(tabRect); 3961 3676 HIThemeDrawTab(&hirect, &tdi, cg, kHIThemeOrientationNormal, 0); 3962 } else3963 #endif3964 {3965 d->drawPantherTab(tabOpt, p, w);3966 3677 } 3967 3678 } … … 3998 3709 nr.moveTop(+1); 3999 3710 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextHideMnemonic; 4000 drawItemText(p, nr, alignment, np, tab->state & State_Enabled, tab->text, QPalette::WindowText); 3711 proxy()->drawItemText(p, nr, alignment, np, tab->state & State_Enabled, 3712 tab->text, QPalette::WindowText); 4001 3713 p->restore(); 4002 3714 } … … 4121 3833 break; 4122 3834 case CE_FocusFrame: { 4123 int xOff = p ixelMetric(PM_FocusFrameHMargin, opt, w) + 1;4124 int yOff = p ixelMetric(PM_FocusFrameVMargin, opt, w) + 1;3835 int xOff = pixelMetric(PM_FocusFrameHMargin, opt, w) + 1; 3836 int yOff = pixelMetric(PM_FocusFrameVMargin, opt, w) + 1; 4125 3837 HIRect hirect = CGRectMake(xOff+opt->rect.x(), yOff+opt->rect.y(), opt->rect.width() - 2 * xOff, 4126 3838 opt->rect.height() - 2 * yOff); … … 4245 3957 : QIcon::Disabled; 4246 3958 // Always be normal or disabled to follow the Mac style. 4247 int smallIconSize = p ixelMetric(PM_SmallIconSize);3959 int smallIconSize = pixelMetric(PM_SmallIconSize); 4248 3960 QSize iconSize(smallIconSize, smallIconSize); 4249 3961 if (const QComboBox *comboBox = qobject_cast<const QComboBox *>(w)) { … … 4280 3992 const int xm = macItemFrame + maxpmw + macItemHMargin; 4281 3993 QFont myFont = mi->font; 4282 if (mi->state & QStyle::State_Mini) 4283 myFont.setPointSize(mi->font.pointSize()); 3994 // myFont may not have any "hard" flags set. We override 3995 // the point size so that when it is resolved against the device, this font will win. 3996 // This is mainly to handle cases where someone sets the font on the window 3997 // and then the combo inherits it and passes it onward. At that point the resolve mask 3998 // is very, very weak. This makes it stonger. 3999 myFont.setPointSizeF(QFontInfo(mi->font).pointSizeF()); 4284 4000 p->setFont(myFont); 4285 4001 p->drawText(xpos, yPos, contentRect.width() - xm - tabwidth + 1, … … 4355 4071 Qt::AlignCenter | Qt::TextHideMnemonic | Qt::TextDontClip 4356 4072 | Qt::TextSingleLine, 4357 mi->icon.pixmap(p ixelMetric(PM_SmallIconSize),4073 mi->icon.pixmap(pixelMetric(PM_SmallIconSize), 4358 4074 (mi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled)); 4359 4075 } else { … … 4415 4131 else 4416 4132 tdi.enableState = kThemeTrackActive; 4417 HIThemeDrawTrack(&tdi, 0, cg, kHIThemeOrientationNormal); 4133 HIThemeOrientation drawOrientation = kHIThemeOrientationNormal; 4134 if (reverse) { 4135 if (vertical) { 4136 drawOrientation = kHIThemeOrientationInverted; 4137 } else { 4138 CGContextSaveGState(cg); 4139 CGContextTranslateCTM(cg, pb->rect.width(), 0); 4140 CGContextScaleCTM(cg, -1, 1); 4141 } 4142 } 4143 HIThemeDrawTrack(&tdi, 0, cg, drawOrientation); 4144 if (reverse && !vertical) 4145 CGContextRestoreGState(cg); 4418 4146 } 4419 4147 break; … … 4503 4231 // For unified tool bars, draw nothing. 4504 4232 if (w) { 4505 if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(w->window())) 4233 if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(w->window())) 4506 4234 if (mainWindow->unifiedTitleAndToolBarOnMac()) 4507 4235 break; 4236 4508 4237 } 4509 4238 … … 4550 4279 } 4551 4280 } 4552 /*! \reimp */ 4281 4553 4282 QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt, 4554 4283 const QWidget *widget) const … … 4844 4573 } 4845 4574 4846 /*! \reimp */4847 4575 void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, 4848 4576 const QWidget *widget) const … … 4875 4603 // because on Tiger I only "fake" the reverse stuff. 4876 4604 bool reverseHorizontal = (slider->direction == Qt::RightToLeft 4877 && slider->orientation == Qt::Horizontal 4878 && (!slider->upsideDown 4879 || (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4 4880 && slider->upsideDown))); 4605 && slider->orientation == Qt::Horizontal); 4881 4606 if ((reverseHorizontal 4882 4607 && slider->activeSubControls == SC_ScrollBarAddLine) … … 4913 4638 // there is not enough space for them. 4914 4639 if (cc == CC_ScrollBar) { 4915 const int scrollBarLeng ht= (slider->orientation == Qt::Horizontal)4640 const int scrollBarLeng = (slider->orientation == Qt::Horizontal) 4916 4641 ? slider->rect.width() : slider->rect.height(); 4917 4642 const QMacStyle::WidgetSizePolicy sizePolicy = widgetSizePolicy(widget); 4918 if (scrollBarLeng ht< scrollButtonsCutoffSize(thumbIndicatorCutoff, sizePolicy))4643 if (scrollBarLeng < scrollButtonsCutoffSize(thumbIndicatorCutoff, sizePolicy)) 4919 4644 tdi.attributes &= ~kThemeTrackShowThumb; 4920 if (scrollBarLeng ht< scrollButtonsCutoffSize(scrollButtonsCutoff, sizePolicy))4645 if (scrollBarLeng < scrollButtonsCutoffSize(scrollButtonsCutoff, sizePolicy)) 4921 4646 tdi.enableState = kThemeTrackNothingToScroll; 4922 4647 } … … 4980 4705 if (item.state & State_Open) 4981 4706 treeOpt.state |= State_Open; 4982 drawPrimitive(PE_IndicatorBranch, &treeOpt, p, widget);4707 drawPrimitive(PE_IndicatorBranch, &treeOpt, p, widget); 4983 4708 } 4984 4709 y += item.totalHeight; … … 4994 4719 GetThemeMetric(kThemeMetricEditTextFrameOutset, &frame_size); 4995 4720 4996 QRect lineeditRect = subControlRect(CC_SpinBox, sb, SC_SpinBoxEditField, widget);4721 QRect lineeditRect = subControlRect(CC_SpinBox, sb, SC_SpinBoxEditField, widget); 4997 4722 lineeditRect.adjust(-frame_size, -frame_size, +frame_size, +frame_size); 4998 4723 … … 5015 4740 break; 5016 4741 case QAquaSizeMini: 4742 4743 5017 4744 case QAquaSizeSmall: 5018 if (aquaSize == QAquaSizeMini) 5019 bdi.kind = kThemeIncDecButtonMini; 5020 else 5021 bdi.kind = kThemeIncDecButtonSmall; 4745 bdi.kind = kThemeIncDecButtonSmall; 5022 4746 break; 5023 4747 } … … 5039 4763 bdi.adornment = kThemeAdornmentNone; 5040 4764 5041 QRect updown = subControlRect(CC_SpinBox, sb, SC_SpinBoxUp,5042 widget); 5043 updown |= subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);4765 QRect updown = 4766 4767 updown |= subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget); 5044 4768 HIRect newRect = qt_hirectForQRect(updown); 5045 4769 QRect off_rct; … … 5050 4774 int(outRect.size.width - newRect.size.width), 5051 4775 int(outRect.size.height - newRect.size.height)); 5052 5053 // HIThemeGetButtonBackgroundBounds offsets non-focused normal sized5054 // buttons by one in de y direction, account for that here.5055 if (bdi.adornment == kThemeAdornmentNone && bdi.kind == kThemeIncDecButton)5056 off_rct.adjust(0, 1, 0, 0);5057 5058 // Adjust the rect for small buttos also.5059 if (bdi.adornment == kThemeAdornmentFocus && bdi.kind == kThemeIncDecButtonSmall)5060 off_rct.adjust(0, 0, 0, -1);5061 4776 5062 4777 newRect = qt_hirectForQRect(updown, off_rct); … … 5129 4844 ThemeTitleBarWidget tbw = kThemeWidgetCollapseBox; 5130 4845 bool active = titlebar->state & State_Active; 5131 int border = 2; 5132 titleBarRect.origin.x += border; 5133 titleBarRect.origin.y -= border; 4846 if (qMacVersion() < QSysInfo::MV_10_6) { 4847 int border = 2; 4848 titleBarRect.origin.x += border; 4849 titleBarRect.origin.y -= border; 4850 } 5134 4851 5135 4852 while (sc <= SC_TitleBarCloseButton) { … … 5163 4880 ptrHIShapeGetBounds(titleRegion2, &tmpRect); 5164 4881 if (tmpRect.size.width != 1) { 5165 int iconExtent = p ixelMetric(PM_SmallIconSize);4882 int iconExtent = pixelMetric(PM_SmallIconSize); 5166 4883 iw = titlebar->icon.actualSize(QSize(iconExtent, iconExtent)).width(); 5167 4884 } … … 5181 4898 x += br.width() / 2 - p->fontMetrics().width(titlebar->text) / 2; 5182 4899 if (iw) 5183 p->drawPixmap(x - iw, y, titlebar->icon.pixmap(pixelMetric(PM_SmallIconSize), QIcon::Normal)); 4900 p->drawPixmap(x - iw, y, 4901 titlebar->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize), QIcon::Normal)); 5184 4902 drawItemText(p, br, Qt::AlignCenter, opt->palette, tds == kThemeStateActive, 5185 4903 titlebar->text, QPalette::Text); … … 5218 4936 tti.truncationMaxLines = 1 + groupBox->text.count(QLatin1Char('\n')); 5219 4937 QCFString groupText = qt_mac_removeMnemonics(groupBox->text); 5220 QRect r = subControlRect(CC_GroupBox, groupBox, SC_GroupBoxLabel, widget);4938 QRect r = subControlRect(CC_GroupBox, groupBox, SC_GroupBoxLabel, widget); 5221 4939 HIRect bounds = qt_hirectForQRect(r); 5222 4940 HIThemeDrawTextBox(groupText, &bounds, &tti, cg, kHIThemeOrientationNormal); … … 5231 4949 if (tb->subControls & SC_ToolButtonMenu) { 5232 4950 QStyleOption arrowOpt(0); 5233 arrowOpt.rect = subControlRect(cc, tb, SC_ToolButtonMenu, widget);4951 arrowOpt.rect = subControlRect(cc, tb, SC_ToolButtonMenu, widget); 5234 4952 arrowOpt.rect.setY(arrowOpt.rect.y() + arrowOpt.rect.height() / 2); 5235 4953 arrowOpt.rect.setHeight(arrowOpt.rect.height() / 2); 5236 4954 arrowOpt.state = tb->state; 5237 4955 arrowOpt.palette = tb->palette; 5238 drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget); 5239 } else if (tb->features & QStyleOptionToolButton::HasMenu) { 4956 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget); 4957 } else if ((tb->features & QStyleOptionToolButton::HasMenu) 4958 && (tb->toolButtonStyle != Qt::ToolButtonTextOnly && !tb->icon.isNull())) { 5240 4959 drawToolbarButtonArrow(tb->rect, tds, cg); 5241 4960 } 5242 4961 if (tb->state & State_On) { 5243 QPen oldPen = p->pen(); 5244 p->setPen(QColor(0, 0, 0, 0x3a)); 5245 p->fillRect(tb->rect.adjusted(1, 1, -1, -1), QColor(0, 0, 0, 0x12)); 5246 p->drawLine(tb->rect.left() + 1, tb->rect.top(), 5247 tb->rect.right() - 1, tb->rect.top()); 5248 p->drawLine(tb->rect.left() + 1, tb->rect.bottom(), 5249 tb->rect.right() - 1, tb->rect.bottom()); 5250 p->drawLine(tb->rect.topLeft(), tb->rect.bottomLeft()); 5251 p->drawLine(tb->rect.topRight(), tb->rect.bottomRight()); 5252 p->setPen(oldPen); 5253 } 5254 drawControl(CE_ToolButtonLabel, opt, p, widget); 4962 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { 4963 static QPixmap pm(QLatin1String(":/trolltech/mac/style/images/leopard-unified-toolbar-on.png")); 4964 p->setRenderHint(QPainter::SmoothPixmapTransform); 4965 QStyleHelper::drawBorderPixmap(pm, p, tb->rect, 2, 2, 2, 2); 4966 } else { 4967 QPen oldPen = p->pen(); 4968 p->setPen(QColor(0, 0, 0, 0x3a)); 4969 p->fillRect(tb->rect.adjusted(1, 1, -1, -1), QColor(0, 0, 0, 0x12)); 4970 p->drawLine(tb->rect.left() + 1, tb->rect.top(), 4971 tb->rect.right() - 1, tb->rect.top()); 4972 p->drawLine(tb->rect.left() + 1, tb->rect.bottom(), 4973 tb->rect.right() - 1, tb->rect.bottom()); 4974 p->drawLine(tb->rect.topLeft(), tb->rect.bottomLeft()); 4975 p->drawLine(tb->rect.topRight(), tb->rect.bottomRight()); 4976 p->setPen(oldPen); 4977 } 4978 } 4979 proxy()->drawControl(CE_ToolButtonLabel, opt, p, widget); 5255 4980 } else { 5256 4981 ThemeButtonKind bkind = kThemeBevelButton; … … 5261 4986 break; 5262 4987 case QAquaSizeMini: 5263 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3) && 05264 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_3) {5265 bkind = kThemeMiniBevelButton;5266 break;5267 }5268 #endif5269 4988 case QAquaSizeSmall: 5270 4989 bkind = kThemeSmallBevelButton; … … 5273 4992 5274 4993 QRect button, menuarea; 5275 button = subControlRect(cc, tb, SC_ToolButton, widget);5276 menuarea = subControlRect(cc, tb, SC_ToolButtonMenu, widget);4994 button = subControlRect(cc, tb, SC_ToolButton, widget); 4995 menuarea = subControlRect(cc, tb, SC_ToolButtonMenu, widget); 5277 4996 State bflags = tb->state, 5278 4997 mflags = tb->state; … … 5337 5056 drawToolbarButtonArrow(tb->rect, tds, cg); 5338 5057 } 5339 QRect buttonRect = subControlRect(CC_ToolButton, tb, SC_ToolButton, widget);5340 int fw = p ixelMetric(PM_DefaultFrameWidth, opt, widget);5058 QRect buttonRect = subControlRect(CC_ToolButton, tb, SC_ToolButton, widget); 5059 int fw = pixelMetric(PM_DefaultFrameWidth, opt, widget); 5341 5060 QStyleOptionToolButton label = *tb; 5342 5061 label.rect = buttonRect.adjusted(fw, fw, -fw, -fw); 5343 drawControl(CE_ToolButtonLabel, &label, p, widget); 5344 } 5345 } 5062 proxy()->drawControl(CE_ToolButtonLabel, &label, p, widget); 5063 } 5064 } 5065 break; 5066 case CC_Dial: 5067 if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(opt)) 5068 QStyleHelper::drawDial(dial, p); 5346 5069 break; 5347 5070 default: … … 5351 5074 } 5352 5075 5353 /*! \reimp */5354 5076 QStyle::SubControl QMacStyle::hitTestComplexControl(ComplexControl cc, 5355 5077 const QStyleOptionComplex *opt, … … 5392 5114 // The arrow buttons are not drawn if the scroll bar is to short, 5393 5115 // exclude them from the hit test. 5394 const int scrollBarLeng ht= (sb->orientation == Qt::Horizontal)5116 const int scrollBarLeng = (sb->orientation == Qt::Horizontal) 5395 5117 ? sb->rect.width() : sb->rect.height(); 5396 if (scrollBarLeng ht< scrollButtonsCutoffSize(scrollButtonsCutoff, widgetSizePolicy(widget)))5118 if (scrollBarLeng < scrollButtonsCutoffSize(scrollButtonsCutoff, widgetSizePolicy(widget))) 5397 5119 sbi.enableState = kThemeTrackNothingToScroll; 5398 5120 … … 5482 5204 } 5483 5205 5484 /*! \reimp */5485 5206 QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, 5486 5207 const QWidget *widget) const … … 5513 5234 : kControlDownButtonPart; 5514 5235 if (slider->direction == Qt::RightToLeft 5515 && slider->orientation == Qt::Horizontal 5516 && (!slider->upsideDown 5517 || (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4 5518 && slider->upsideDown)) 5519 ) { 5236 && slider->orientation == Qt::Horizontal) { 5520 5237 if (cpc == kControlDownButtonPart) 5521 5238 cpc = kControlUpButtonPart; … … 5570 5287 wrc = kWindowTitleTextRgn; 5571 5288 else if (sc == SC_TitleBarSysMenu) 5572 ret.setRect(-1024, -1024, 10, p ixelMetric(PM_TitleBarHeight,5289 ret.setRect(-1024, -1024, 10, pixelMetric(PM_TitleBarHeight, 5573 5290 titlebar, widget)); 5574 5291 if (wrc != kWindowGlobalPortRgn) { … … 5606 5323 ret = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi); 5607 5324 ret.setX(ret.x() + ret.width()); 5608 ret.setWidth(combo->rect. width() - ret.width() - ret.x());5325 ret.setWidth(combo->rect.()); 5609 5326 break; } 5610 5327 case SC_ComboBoxListBoxPopup:{ … … 5612 5329 HIRect inner = QMacStylePrivate::comboboxInnerBounds(qt_hirectForQRect(combo->rect), bdi.kind); 5613 5330 QRect editRect = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi); 5614 ret.adjust(qRound(inner.origin.x), 0, qRound(inner.origin.x + inner.size.width), editRect.y() + editRect.height() + 2); 5331 const int comboTop = combo->rect.top(); 5332 ret = QRect(qRound(inner.origin.x), 5333 comboTop, 5334 qRound(inner.origin.x - combo->rect.left() + inner.size.width), 5335 editRect.bottom() - comboTop + 2); 5615 5336 } else { 5616 5337 QRect editRect = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi); 5617 ret.adjust(4 - 11, 1, editRect.width() + 10 + 11, 1); 5338 ret = QRect(combo->rect.x() + 4 - 11, 5339 combo->rect.y() + 1, 5340 editRect.width() + 10 + 11, 5341 1); 5618 5342 } 5619 5343 break; } … … 5667 5391 QRect labelRect = alignedRect(groupBox->direction, groupBox->textAlignment, 5668 5392 QSize(tw, h), ret); 5669 int indicatorWidth = p ixelMetric(PM_IndicatorWidth, opt, widget);5393 int indicatorWidth = pixelMetric(PM_IndicatorWidth, opt, widget); 5670 5394 bool rtl = groupBox->direction == Qt::RightToLeft; 5671 5395 if (sc == SC_GroupBoxLabel) { … … 5689 5413 int left = rtl ? labelRect.right() - indicatorWidth : labelRect.left(); 5690 5414 ret.setRect(left, ret.top(), 5691 indicatorWidth, p ixelMetric(PM_IndicatorHeight, opt, widget));5415 indicatorWidth, pixelMetric(PM_IndicatorHeight, opt, widget)); 5692 5416 } 5693 5417 break; … … 5724 5448 case CC_SpinBox: 5725 5449 if (const QStyleOptionSpinBox *spin = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) { 5726 const int spinner_w = 14, 5727 fw = pixelMetric(PM_SpinBoxFrameWidth, spin, widget); 5450 QAquaWidgetSize aquaSize = d->aquaSizeConstrain(spin, widget); 5451 int spinner_w; 5452 int spinBoxSep; 5453 int fw = proxy()->pixelMetric(PM_SpinBoxFrameWidth, spin, widget); 5454 switch (aquaSize) { 5455 default: 5456 case QAquaSizeUnknown: 5457 case QAquaSizeLarge: 5458 spinner_w = 14; 5459 spinBoxSep = 2; 5460 break; 5461 case QAquaSizeSmall: 5462 spinner_w = 12; 5463 spinBoxSep = 2; 5464 break; 5465 case QAquaSizeMini: 5466 spinner_w = 10; 5467 spinBoxSep = 1; 5468 break; 5469 } 5470 5728 5471 switch (sc) { 5729 5472 case SC_SpinBoxUp: … … 5731 5474 if (spin->buttonSymbols == QAbstractSpinBox::NoButtons) 5732 5475 break; 5733 const int frameWidth = pixelMetric(PM_SpinBoxFrameWidth, spin, widget); 5734 const int spinner_w = 18; 5735 const int y = frameWidth; 5736 const int x = spin->rect.width() - spinner_w + frameWidth; 5476 5477 const int y = fw; 5478 const int x = spin->rect.width() - spinner_w; 5737 5479 ret.setRect(x + spin->rect.x(), y + spin->rect.y(), spinner_w, spin->rect.height() - y * 2); 5738 5480 HIThemeButtonDrawInfo bdi; 5739 5481 bdi.version = qt_mac_hitheme_version; 5740 5482 bdi.kind = kThemeIncDecButton; 5741 QAquaWidgetSize aquaSize = d->aquaSizeConstrain(opt, widget);5483 ; 5742 5484 switch (aquaSize) { 5743 case QAquaSizeUnknown: 5744 case QAquaSizeLarge: 5745 bdi.kind = kThemeIncDecButton; 5746 break; 5747 case QAquaSizeMini: 5748 case QAquaSizeSmall: 5749 if (aquaSize == QAquaSizeMini) 5750 bdi.kind = kThemeIncDecButtonMini; 5751 else 5752 bdi.kind = kThemeIncDecButtonSmall; 5753 break; 5485 default: 5486 case QAquaSizeUnknown: 5487 case QAquaSizeLarge: 5488 bdi.kind = kThemeIncDecButton; 5489 hackTranslateX = 0; 5490 break; 5491 case QAquaSizeSmall: 5492 bdi.kind = kThemeIncDecButtonSmall; 5493 hackTranslateX = -2; 5494 break; 5495 case QAquaSizeMini: 5496 bdi.kind = kThemeIncDecButtonMini; 5497 hackTranslateX = -1; 5498 break; 5754 5499 } 5755 5500 bdi.state = kThemeStateActive; … … 5757 5502 bdi.adornment = kThemeAdornmentNone; 5758 5503 HIRect hirect = qt_hirectForQRect(ret); 5504 5759 5505 HIRect outRect; 5760 5506 HIThemeGetButtonBackgroundBounds(&hirect, &bdi, &outRect); … … 5771 5517 break; 5772 5518 } 5773 ret.translate( -1, -2); // hack: position the buttons correctly (weird that we need this)5519 ret.translate(); // hack: position the buttons correctly (weird that we need this) 5774 5520 ret = visualRect(spin->direction, spin->rect, ret); 5775 5521 break; 5776 5522 } 5777 5523 case SC_SpinBoxEditField: 5778 ret.setRect(fw, fw, 5779 spin->rect.width() - spinner_w - fw * 2 - macSpinBoxSep + 1, 5780 spin->rect.height() - fw * 2); 5524 if (spin->buttonSymbols == QAbstractSpinBox::NoButtons) { 5525 ret.setRect(fw, fw, 5526 spin->rect.width() - fw * 2, 5527 spin->rect.height() - fw * 2); 5528 } else { 5529 ret.setRect(fw, fw, 5530 spin->rect.width() - fw * 2 - spinBoxSep - spinner_w, 5531 spin->rect.height() - fw * 2); 5532 } 5781 5533 ret = visualRect(spin->direction, spin->rect, ret); 5782 5534 break; … … 5800 5552 } 5801 5553 5802 /*! \reimp */5803 5554 QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, 5804 5555 const QSize &csz, const QWidget *widget) const … … 5809 5560 switch (ct) { 5810 5561 case QStyle::CT_SpinBox: 5811 sz.setWidth(sz.width() + macSpinBoxSep);5812 sz.setHeight(sz.height() - 3); // hack to work around horrible sizeHint() code in QAbstractSpinBox5562 5563 sz.setHeight(sz.height() - 3); 5813 5564 break; 5814 5565 case QStyle::CT_TabBarTab: 5815 5566 if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(opt)) { 5816 bool newStyleTabs =5817 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)5818 QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4 ? true :5819 #endif5820 false;5821 5567 const QAquaWidgetSize AquaSize = d->aquaSizeConstrain(opt, widget); 5822 5568 const bool differentFont = (widget && widget->testAttribute(Qt::WA_SetFont)) … … 5826 5572 if (vertTabs) 5827 5573 sz.transpose(); 5828 if (newStyleTabs) { 5829 int defaultTabHeight; 5830 int defaultExtraSpace = pixelMetric(PM_TabBarTabHSpace, tab, widget); // Remove spurious gcc warning (AFAIK) 5831 QFontMetrics fm = opt->fontMetrics; 5832 switch (AquaSize) { 5833 case QAquaSizeUnknown: 5834 case QAquaSizeLarge: 5835 if (tab->documentMode) 5836 defaultTabHeight = 23; 5837 else 5838 defaultTabHeight = 21; 5839 break; 5840 case QAquaSizeSmall: 5841 defaultTabHeight = 18; 5842 break; 5843 case QAquaSizeMini: 5844 defaultTabHeight = 16; 5845 break; 5846 } 5847 5848 bool setWidth = false; 5849 if (differentFont || !tab->icon.isNull()) { 5850 sz.rheight() = qMax(defaultTabHeight, sz.height()); 5851 } else { 5852 QSize textSize = fm.size(Qt::TextShowMnemonic, tab->text); 5853 sz.rheight() = qMax(defaultTabHeight, textSize.height()); 5854 sz.rwidth() = textSize.width() + defaultExtraSpace; 5855 setWidth = true; 5856 } 5857 5858 if (vertTabs) 5859 sz.transpose(); 5860 5861 int maxWidgetHeight = qMax(tab->leftButtonSize.height(), tab->rightButtonSize.height()); 5862 int maxWidgetWidth = qMax(tab->leftButtonSize.width(), tab->rightButtonSize.width()); 5863 5864 int widgetWidth = 0; 5865 int widgetHeight = 0; 5866 int padding = 0; 5867 if (tab->leftButtonSize.isValid()) { 5868 padding += 8; 5869 widgetWidth += tab->leftButtonSize.width(); 5870 widgetHeight += tab->leftButtonSize.height(); 5871 } 5872 if (tab->rightButtonSize.isValid()) { 5873 padding += 8; 5874 widgetWidth += tab->rightButtonSize.width(); 5875 widgetHeight += tab->rightButtonSize.height(); 5876 } 5877 5878 if (vertTabs) { 5879 sz.setHeight(sz.height() + widgetHeight + padding); 5880 sz.setWidth(qMax(sz.width(), maxWidgetWidth)); 5881 } else { 5882 if (setWidth) 5883 sz.setWidth(sz.width() + widgetWidth + padding); 5884 sz.setHeight(qMax(sz.height(), maxWidgetHeight)); 5885 } 5574 int defaultTabHeight; 5575 int defaultExtraSpace = proxy()->pixelMetric(PM_TabBarTabHSpace, tab, widget); // Remove spurious gcc warning (AFAIK) 5576 QFontMetrics fm = opt->fontMetrics; 5577 switch (AquaSize) { 5578 case QAquaSizeUnknown: 5579 case QAquaSizeLarge: 5580 if (tab->documentMode) 5581 defaultTabHeight = 23; 5582 else 5583 defaultTabHeight = 21; 5584 break; 5585 case QAquaSizeSmall: 5586 defaultTabHeight = 18; 5587 break; 5588 case QAquaSizeMini: 5589 defaultTabHeight = 16; 5590 break; 5591 } 5592 bool setWidth = false; 5593 if (differentFont || !tab->icon.isNull()) { 5594 sz.rheight() = qMax(defaultTabHeight, sz.height()); 5886 5595 } else { 5887 SInt32 tabh = sz.height(); 5888 SInt32 overlap = 0; 5889 switch (AquaSize) { 5890 default: 5891 case QAquaSizeUnknown: 5892 case QAquaSizeLarge: 5893 GetThemeMetric(kThemeLargeTabHeight, &tabh); 5894 GetThemeMetric(kThemeMetricTabFrameOverlap, &overlap); 5895 break; 5896 case QAquaSizeMini: 5897 GetThemeMetric(kThemeMetricMiniTabHeight, &tabh); 5898 GetThemeMetric(kThemeMetricMiniTabFrameOverlap, &overlap); 5899 break; 5900 case QAquaSizeSmall: 5901 GetThemeMetric(kThemeSmallTabHeight, &tabh); 5902 GetThemeMetric(kThemeMetricSmallTabFrameOverlap, &overlap); 5903 break; 5904 } 5905 tabh += overlap; 5906 if (sz.height() < tabh) 5907 sz.rheight() = tabh; 5596 QSize textSize = fm.size(Qt::TextShowMnemonic, tab->text); 5597 sz.rheight() = qMax(defaultTabHeight, textSize.height()); 5598 sz.rwidth() = textSize.width() + defaultExtraSpace; 5599 setWidth = true; 5600 } 5601 5602 if (vertTabs) 5603 sz.transpose(); 5604 5605 int maxWidgetHeight = qMax(tab->leftButtonSize.height(), tab->rightButtonSize.height()); 5606 int maxWidgetWidth = qMax(tab->leftButtonSize.width(), tab->rightButtonSize.width()); 5607 5608 int widgetWidth = 0; 5609 int widgetHeight = 0; 5610 int padding = 0; 5611 if (tab->leftButtonSize.isValid()) { 5612 padding += 8; 5613 widgetWidth += tab->leftButtonSize.width(); 5614 widgetHeight += tab->leftButtonSize.height(); 5615 } 5616 if (tab->rightButtonSize.isValid()) { 5617 padding += 8; 5618 widgetWidth += tab->rightButtonSize.width(); 5619 widgetHeight += tab->rightButtonSize.height(); 5620 } 5621 5622 if (vertTabs) { 5623 sz.setHeight(sz.height() + widgetHeight + padding); 5624 sz.setWidth(qMax(sz.width(), maxWidgetWidth)); 5625 } else { 5626 if (setWidth) 5627 sz.setWidth(sz.width() + widgetWidth + padding); 5628 sz.setHeight(qMax(sz.height(), maxWidgetHeight)); 5908 5629 } 5909 5630 } … … 5935 5656 maxpmw = qMax(maxpmw, iconSize.width()); 5936 5657 } else { 5937 int iconExtent = p ixelMetric(PM_SmallIconSize);5658 int iconExtent = pixelMetric(PM_SmallIconSize); 5938 5659 h = qMax(h, mi->icon.actualSize(QSize(iconExtent, iconExtent)).height() + 4); 5939 5660 } … … 5964 5685 break; 5965 5686 case CT_ToolButton: 5687 5688 5689 5690 5691 5692 5693 5694 5966 5695 sz.rwidth() += 10; 5967 5696 sz.rheight() += 10; … … 5974 5703 QStyleOption myOption = *opt; 5975 5704 myOption.rect.setSize(sz); 5976 if ( styleHint(SH_Menu_Mask, &myOption, widget, &menuMask)) {5705 if (styleHint(SH_Menu_Mask, &myOption, widget, &menuMask)) { 5977 5706 sz = menuMask.region.boundingRect().size(); 5978 5707 } … … 6087 5816 } 6088 5817 6089 /*!6090 \reimp6091 */6092 5818 void QMacStyle::drawItemText(QPainter *p, const QRect &r, int flags, const QPalette &pal, 6093 5819 bool enabled, const QString &text, QPalette::ColorRole textRole) const … … 6098 5824 } 6099 5825 6100 /*!6101 \reimp6102 */6103 5826 bool QMacStyle::event(QEvent *e) 6104 5827 { … … 6149 5872 } 6150 5873 6151 void qt_mac_constructQIconFromIconRef(const IconRef icon, const IconRef overlayIcon, QIcon *retIcon, QStyle::StandardPixmap standardIcon = QStyle::SP_CustomBase)6152 {6153 int size = 16;6154 while (size <= 128) {6155 6156 const QString cacheKey = QLatin1String("qt_mac_constructQIconFromIconRef") + QString::number(standardIcon) + QString::number(size);6157 QPixmap mainIcon;6158 if (standardIcon >= QStyle::SP_CustomBase) {6159 mainIcon = qt_mac_convert_iconref(icon, size, size);6160 } else if (QPixmapCache::find(cacheKey, mainIcon) == false) {6161 mainIcon = qt_mac_convert_iconref(icon, size, size);6162 QPixmapCache::insert(cacheKey, mainIcon);6163 }6164 6165 if (overlayIcon) {6166 int littleSize = size / 2;6167 QPixmap overlayPix = qt_mac_convert_iconref(overlayIcon, littleSize, littleSize);6168 QPainter painter(&mainIcon);6169 painter.drawPixmap(size - littleSize, size - littleSize, overlayPix);6170 }6171 6172 retIcon->addPixmap(mainIcon);6173 size += size; // 16 -> 32 -> 64 -> 1286174 }6175 }6176 6177 /*!6178 \internal6179 */6180 5874 QIcon QMacStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *opt, 6181 5875 const QWidget *widget) const 6182 5876 { 6183 OSType iconType = 0;6184 5877 switch (standardIcon) { 6185 case QStyle::SP_MessageBoxQuestion: 6186 case QStyle::SP_MessageBoxInformation: 6187 case QStyle::SP_MessageBoxWarning: 6188 case QStyle::SP_MessageBoxCritical: 6189 iconType = kGenericApplicationIcon; 6190 break; 6191 case SP_DesktopIcon: 6192 iconType = kDesktopIcon; 6193 break; 6194 case SP_TrashIcon: 6195 iconType = kTrashIcon; 6196 break; 6197 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) 6198 case SP_ComputerIcon: 6199 iconType = kComputerIcon; 6200 break; 6201 #endif 6202 case SP_DriveFDIcon: 6203 iconType = kGenericFloppyIcon; 6204 break; 6205 case SP_DriveHDIcon: 6206 iconType = kGenericHardDiskIcon; 6207 break; 6208 case SP_DriveCDIcon: 6209 case SP_DriveDVDIcon: 6210 iconType = kGenericCDROMIcon; 6211 break; 6212 case SP_DriveNetIcon: 6213 iconType = kGenericNetworkIcon; 6214 break; 6215 case SP_DirOpenIcon: 6216 iconType = kOpenFolderIcon; 6217 break; 6218 case SP_DirClosedIcon: 6219 case SP_DirLinkIcon: 6220 iconType = kGenericFolderIcon; 6221 break; 6222 case SP_FileLinkIcon: 6223 case SP_FileIcon: 6224 iconType = kGenericDocumentIcon; 6225 break; 5878 default: 5879 return QWindowsStyle::standardIconImplementation(standardIcon, opt, widget); 6226 5880 case SP_ToolBarHorizontalExtensionButton: 6227 5881 case SP_ToolBarVerticalExtensionButton: { … … 6237 5891 } 6238 5892 return pixmap; 6239 } 6240 break; 6241 case SP_DirIcon: { 6242 // A rather special case 6243 QIcon closeIcon = QStyle::standardIcon(SP_DirClosedIcon, opt, widget); 6244 QIcon openIcon = QStyle::standardIcon(SP_DirOpenIcon, opt, widget); 6245 closeIcon.addPixmap(openIcon.pixmap(16, 16), QIcon::Normal, QIcon::On); 6246 closeIcon.addPixmap(openIcon.pixmap(32, 32), QIcon::Normal, QIcon::On); 6247 closeIcon.addPixmap(openIcon.pixmap(64, 64), QIcon::Normal, QIcon::On); 6248 closeIcon.addPixmap(openIcon.pixmap(128, 128), QIcon::Normal, QIcon::On); 6249 return closeIcon; 6250 } 6251 case SP_TitleBarNormalButton: 6252 case SP_TitleBarCloseButton: { 6253 QIcon titleBarIcon; 6254 if (standardIcon == SP_TitleBarCloseButton) { 6255 titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/closedock-16.png")); 6256 titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/closedock-down-16.png"), QSize(16, 16), QIcon::Normal, QIcon::On); 6257 } else { 6258 titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/dockdock-16.png")); 6259 titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/dockdock-down-16.png"), QSize(16, 16), QIcon::Normal, QIcon::On); 6260 } 6261 return titleBarIcon; 6262 } 6263 default: 6264 break; 6265 } 6266 if (iconType != 0) { 6267 QIcon retIcon; 6268 IconRef icon; 6269 IconRef overlayIcon = 0; 6270 if (iconType != kGenericApplicationIcon) { 6271 GetIconRef(kOnSystemDisk, kSystemIconsCreator, iconType, &icon); 6272 } else { 6273 FSRef fsRef; 6274 ProcessSerialNumber psn = { 0, kCurrentProcess }; 6275 GetProcessBundleLocation(&psn, &fsRef); 6276 GetIconRefFromFileInfo(&fsRef, 0, 0, 0, 0, kIconServicesNormalUsageFlag, &icon, 0); 6277 if (standardIcon == SP_MessageBoxCritical) { 6278 overlayIcon = icon; 6279 GetIconRef(kOnSystemDisk, kSystemIconsCreator, kAlertCautionIcon, &icon); 6280 } 6281 } 6282 if (icon) { 6283 qt_mac_constructQIconFromIconRef(icon, overlayIcon, &retIcon, standardIcon); 6284 ReleaseIconRef(icon); 6285 } 6286 if (overlayIcon) 6287 ReleaseIconRef(overlayIcon); 6288 return retIcon; 6289 } 6290 return QWindowsStyle::standardIconImplementation(standardIcon, opt, widget); 6291 } 6292 6293 /*! 6294 \internal 6295 */ 5893 } 5894 } 5895 } 5896 6296 5897 int QMacStyle::layoutSpacingImplementation(QSizePolicy::ControlType control1, 6297 5898 QSizePolicy::ControlType control2,
Note:
See TracChangeset
for help on using the changeset viewer.