src/gui/styles/qmacstyle_mac.mm
changeset 30 5dc02b23752f
parent 18 2f34d5167611
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
    54 #include <private/qcombobox_p.h>
    54 #include <private/qcombobox_p.h>
    55 #include <private/qmacstylepixmaps_mac_p.h>
    55 #include <private/qmacstylepixmaps_mac_p.h>
    56 #include <private/qpaintengine_mac_p.h>
    56 #include <private/qpaintengine_mac_p.h>
    57 #include <private/qpainter_p.h>
    57 #include <private/qpainter_p.h>
    58 #include <private/qprintengine_mac_p.h>
    58 #include <private/qprintengine_mac_p.h>
    59 #include <private/qstylehelper_p.h>
       
    60 #include <qapplication.h>
    59 #include <qapplication.h>
    61 #include <qbitmap.h>
    60 #include <qbitmap.h>
    62 #include <qcheckbox.h>
    61 #include <qcheckbox.h>
    63 #include <qcombobox.h>
    62 #include <qcombobox.h>
    64 #include <qdialogbuttonbox.h>
    63 #include <qdialogbuttonbox.h>
    95 #include <qtableview.h>
    94 #include <qtableview.h>
    96 #include <qwizard.h>
    95 #include <qwizard.h>
    97 #include <qdebug.h>
    96 #include <qdebug.h>
    98 #include <qlibrary.h>
    97 #include <qlibrary.h>
    99 #include <qdatetimeedit.h>
    98 #include <qdatetimeedit.h>
       
    99 #include <qmath.h>
   100 #include <QtGui/qgraphicsproxywidget.h>
   100 #include <QtGui/qgraphicsproxywidget.h>
   101 #include <QtGui/qgraphicsview.h>
   101 #include <QtGui/qgraphicsview.h>
   102 #include <private/qt_cocoa_helpers_mac_p.h>
   102 #include <private/qt_cocoa_helpers_mac_p.h>
       
   103 #include <private/qstylehelper_p.h>
   103 
   104 
   104 QT_BEGIN_NAMESPACE
   105 QT_BEGIN_NAMESPACE
   105 
   106 
   106 extern QRegion qt_mac_convert_mac_region(RgnHandle); //qregion_mac.cpp
   107 extern QRegion qt_mac_convert_mac_region(RgnHandle); //qregion_mac.cpp
   107 
   108 
   235     if (selected) {
   236     if (selected) {
   236         QRect rect(1, 0, width - 2, height);
   237         QRect rect(1, 0, width - 2, height);
   237 
   238 
   238         // fill body
   239         // fill body
   239         if (active) {
   240         if (active) {
   240             p->fillRect(rect, QColor(151, 151, 151));
   241             int d = (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) ? 16 : 0;
       
   242             p->fillRect(rect, QColor(151 + d, 151 + d, 151 + d));
   241         } else {
   243         } else {
       
   244             int d = (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) ? 9 : 0;
   242             QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
   245             QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
   243             gradient.setColorAt(0, QColor(207, 207, 207));
   246             gradient.setColorAt(0, QColor(207 + d, 207 + d, 207 + d));
   244             gradient.setColorAt(0.5, QColor(206, 206, 206));
   247             gradient.setColorAt(0.5, QColor(206 + d, 206 + d, 206 + d));
   245             gradient.setColorAt(1, QColor(201, 201, 201));
   248             gradient.setColorAt(1, QColor(201 + d, 201 + d, 201 + d));
   246             p->fillRect(rect, gradient);
   249             p->fillRect(rect, gradient);
   247         }
   250         }
   248 
   251 
   249         // draw border
   252         // draw border
   250         QColor borderSides;
   253         QColor borderSides;
   430              ));
   433              ));
   431 }
   434 }
   432 
   435 
   433 QString qt_mac_removeMnemonics(const QString &original)
   436 QString qt_mac_removeMnemonics(const QString &original)
   434 {
   437 {
   435     // copied from qt_format_text (to be bug-for-bug compatible).
       
   436     QString returnText(original.size(), 0);
   438     QString returnText(original.size(), 0);
   437     int finalDest = 0;
   439     int finalDest = 0;
   438     int currPos = 0;
   440     int currPos = 0;
   439     int l = original.length();
   441     int l = original.length();
   440     while (l) {
   442     while (l) {
   441         if (original.at(currPos) == QLatin1Char('&')) {
   443         if (original.at(currPos) == QLatin1Char('&')
       
   444             && (l == 1 || original.at(currPos + 1) != QLatin1Char('&'))) {
   442             ++currPos;
   445             ++currPos;
   443             --l;
   446             --l;
   444             if (l == 0)
   447             if (l == 0)
   445                 break;
   448                 break;
   446         }
   449         }
  2138         else
  2141         else
  2139 #endif
  2142 #endif
  2140         // The combo box popup has no frame.
  2143         // The combo box popup has no frame.
  2141         if (qstyleoption_cast<const QStyleOptionComboBox *>(opt) != 0)
  2144         if (qstyleoption_cast<const QStyleOptionComboBox *>(opt) != 0)
  2142             ret = 0;
  2145             ret = 0;
       
  2146         // Frame of mac style line edits is two pixels on top and one on the bottom
       
  2147         else if (qobject_cast<const QLineEdit *>(widget) != 0)
       
  2148             ret = 2;
  2143         else
  2149         else
  2144             ret = QWindowsStyle::pixelMetric(metric, opt, widget);
  2150             ret = 1;
  2145         break;
  2151         break;
  2146     case PM_MaximumDragDistance:
  2152     case PM_MaximumDragDistance:
  2147         ret = -1;
  2153         ret = -1;
  2148         break;
  2154         break;
  2149     case PM_ScrollBarSliderMin:
  2155     case PM_ScrollBarSliderMin:
  3095             bi.value = opt->direction == Qt::LeftToRight ? kThemeDisclosureRight : kThemeDisclosureLeft;
  3101             bi.value = opt->direction == Qt::LeftToRight ? kThemeDisclosureRight : kThemeDisclosureLeft;
  3096         bi.adornment = kThemeAdornmentNone;
  3102         bi.adornment = kThemeAdornmentNone;
  3097         HIRect hirect = qt_hirectForQRect(opt->rect);
  3103         HIRect hirect = qt_hirectForQRect(opt->rect);
  3098         HIThemeDrawButton(&hirect, &bi, cg, kHIThemeOrientationNormal, 0);
  3104         HIThemeDrawButton(&hirect, &bi, cg, kHIThemeOrientationNormal, 0);
  3099         break; }
  3105         break; }
       
  3106 
  3100     case PE_Frame: {
  3107     case PE_Frame: {
  3101         QPen oldPen = p->pen();
  3108         QPen oldPen = p->pen();
  3102         QPen newPen;
  3109         p->setPen(opt->palette.base().color().darker(140));
  3103         newPen.setBrush(opt->palette.dark());
       
  3104         p->setPen(newPen);
       
  3105         p->drawRect(opt->rect.adjusted(0, 0, -1, -1));
  3110         p->drawRect(opt->rect.adjusted(0, 0, -1, -1));
       
  3111         p->setPen(opt->palette.base().color().darker(180));
       
  3112         p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
  3106         p->setPen(oldPen);
  3113         p->setPen(oldPen);
  3107         break; }
  3114         break; }
       
  3115 
  3108     case PE_FrameLineEdit:
  3116     case PE_FrameLineEdit:
  3109         if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
  3117         if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
  3110             if (frame->state & State_Sunken) {
  3118             if (frame->state & State_Sunken) {
  3111                 QColor baseColor(frame->palette.background().color());
  3119                 QColor baseColor(frame->palette.background().color());
  3112                 HIThemeFrameDrawInfo fdi;
  3120                 HIThemeFrameDrawInfo fdi;
  3144             }
  3152             }
  3145         }
  3153         }
  3146         break;
  3154         break;
  3147     case PE_PanelLineEdit:
  3155     case PE_PanelLineEdit:
  3148         QWindowsStyle::drawPrimitive(pe, opt, p, w);
  3156         QWindowsStyle::drawPrimitive(pe, opt, p, w);
       
  3157         // Draw the focus frame for widgets other than QLineEdit (e.g. for line edits in Webkit).
       
  3158         // Focus frame is drawn outside the rectangle passed in the option-rect.
       
  3159         if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
       
  3160             if ((opt->state & State_HasFocus) && !qobject_cast<const QLineEdit*>(w)) {
       
  3161                 int vmargin = pixelMetric(QStyle::PM_FocusFrameVMargin);
       
  3162                 int hmargin = pixelMetric(QStyle::PM_FocusFrameHMargin);
       
  3163                 QStyleOptionFrame focusFrame = *panel;
       
  3164                 focusFrame.rect = panel->rect.adjusted(-hmargin, -vmargin, hmargin, vmargin);
       
  3165                 drawControl(CE_FocusFrame, &focusFrame, p, w);
       
  3166             }
       
  3167         }
       
  3168 
  3149         break;
  3169         break;
  3150     case PE_FrameTabWidget:
  3170     case PE_FrameTabWidget:
  3151         if (const QStyleOptionTabWidgetFrame *twf
  3171         if (const QStyleOptionTabWidgetFrame *twf
  3152                 = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
  3172                 = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
  3153             HIRect hirect = qt_hirectForQRect(twf->rect);
  3173             HIRect hirect = qt_hirectForQRect(twf->rect);
  3167         p->setPen(QPen(QColor(217, 217, 217)));
  3187         p->setPen(QPen(QColor(217, 217, 217)));
  3168         p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
  3188         p->drawLine(opt->rect.topLeft(), opt->rect.topRight());
  3169         p->drawLine(opt->rect.topLeft(), opt->rect.bottomLeft());
  3189         p->drawLine(opt->rect.topLeft(), opt->rect.bottomLeft());
  3170         } break;
  3190         } break;
  3171     case PE_FrameStatusBarItem:
  3191     case PE_FrameStatusBarItem:
  3172         QCommonStyle::drawPrimitive(pe, opt, p, w);
       
  3173         break;
  3192         break;
  3174     case PE_IndicatorTabClose: {
  3193     case PE_IndicatorTabClose: {
  3175         bool hover = (opt->state & State_MouseOver);
  3194         bool hover = (opt->state & State_MouseOver);
  3176         bool selected = (opt->state & State_Selected);
  3195         bool selected = (opt->state & State_Selected);
  3177         bool active = (opt->state & State_Active);
  3196         bool active = (opt->state & State_Active);
  3264                 bdi.value = kThemeButtonOff;
  3283                 bdi.value = kThemeButtonOff;
  3265 
  3284 
  3266             if (header->orientation == Qt::Horizontal){
  3285             if (header->orientation == Qt::Horizontal){
  3267                 switch (header->position) {
  3286                 switch (header->position) {
  3268                 case QStyleOptionHeader::Beginning:
  3287                 case QStyleOptionHeader::Beginning:
       
  3288                     ir.adjust(-1, -1, 0, 0);
  3269                     break;
  3289                     break;
  3270                 case QStyleOptionHeader::Middle:
  3290                 case QStyleOptionHeader::Middle:
       
  3291                     ir.adjust(-1, -1, 0, 0);
       
  3292                     break;
       
  3293                 case QStyleOptionHeader::OnlyOneSection:
  3271                 case QStyleOptionHeader::End:
  3294                 case QStyleOptionHeader::End:
  3272                     ir.adjust(-1, 0, 0, 0);
  3295                     ir.adjust(-1, -1, 1, 0);
  3273                     break;
  3296                     break;
  3274                 default:
  3297                 default:
  3275                     break;
  3298                     break;
  3276                 }
  3299                 }
  3277 
  3300 
  5416                     tti.truncationMaxLines = 1 + groupBox->text.count(QLatin1Char('\n'));
  5439                     tti.truncationMaxLines = 1 + groupBox->text.count(QLatin1Char('\n'));
  5417                     CGFloat width;
  5440                     CGFloat width;
  5418                     CGFloat height;
  5441                     CGFloat height;
  5419                     QCFString groupText = qt_mac_removeMnemonics(groupBox->text);
  5442                     QCFString groupText = qt_mac_removeMnemonics(groupBox->text);
  5420                     HIThemeGetTextDimensions(groupText, 0, &tti, &width, &height, 0);
  5443                     HIThemeGetTextDimensions(groupText, 0, &tti, &width, &height, 0);
  5421                     tw = int(width);
  5444                     tw = qRound(width);
  5422                     h = int(height);
  5445                     h = qCeil(height);
  5423                 } else {
  5446                 } else {
  5424                     QFontMetrics fm = groupBox->fontMetrics;
  5447                     QFontMetricsF fm = QFontMetricsF(groupBox->fontMetrics);
  5425                     if (!checkable && !fontIsSet)
  5448                     h = qCeil(fm.height());
  5426                         fm = QFontMetrics(qt_app_fonts_hash()->value("QSmallFont", QFont()));
  5449                     tw = qCeil(fm.size(Qt::TextShowMnemonic, groupBox->text).width());
  5427                     h = fm.height();
       
  5428                     tw = fm.size(Qt::TextShowMnemonic, groupBox->text).width();
       
  5429                 }
  5450                 }
  5430                 ret.setHeight(h);
  5451                 ret.setHeight(h);
  5431 
  5452 
  5432                 QRect labelRect = alignedRect(groupBox->direction, groupBox->textAlignment,
  5453                 QRect labelRect = alignedRect(groupBox->direction, groupBox->textAlignment,
  5433                                               QSize(tw, h), ret);
  5454                                               QSize(tw, h), ret);
  5470                     if (widget && !widget->testAttribute(Qt::WA_SetFont)
  5491                     if (widget && !widget->testAttribute(Qt::WA_SetFont)
  5471                             && QApplication::desktopSettingsAware())
  5492                             && QApplication::desktopSettingsAware())
  5472                         fm = QFontMetrics(qt_app_fonts_hash()->value("QSmallFont", QFont()));
  5493                         fm = QFontMetrics(qt_app_fonts_hash()->value("QSmallFont", QFont()));
  5473                     yOffset = 5;
  5494                     yOffset = 5;
  5474                     if (hasNoText)
  5495                     if (hasNoText)
  5475                         yOffset = -fm.height();
  5496                         yOffset = -qCeil(QFontMetricsF(fm).height());
  5476                 }
  5497                 }
  5477 
  5498 
  5478                 ret = opt->rect.adjusted(0, fm.height() + yOffset, 0, 0);
  5499                 ret = opt->rect.adjusted(0, qCeil(QFontMetricsF(fm).height()) + yOffset, 0, 0);
  5479                 if (sc == SC_GroupBoxContents)
  5500                 if (sc == SC_GroupBoxContents)
  5480                     ret.adjust(3, 3, -3, -4);    // guess
  5501                     ret.adjust(3, 3, -3, -4);    // guess
  5481             }
  5502             }
  5482                 break;
  5503                 break;
  5483             default:
  5504             default: