src/gui/styles/qmacstyle_mac.mm
branchRCL_3
changeset 5 d3bac044e0f0
parent 4 3b1da2848fc7
child 7 3f74d0d4af4c
equal deleted inserted replaced
4:3b1da2848fc7 5:d3bac044e0f0
   665             return ret;
   665             return ret;
   666     }
   666     }
   667 
   667 
   668     switch (ct) {
   668     switch (ct) {
   669     case QStyle::CT_PushButton: {
   669     case QStyle::CT_PushButton: {
   670         const QPushButton *psh = static_cast<const QPushButton *>(widg);
   670         const QPushButton *psh = qobject_cast<const QPushButton *>(widg);
   671         QString buttonText = qt_mac_removeMnemonics(psh->text());
   671         // If this comparison is false, then the widget was not a push button.
   672         if (buttonText.contains(QLatin1Char('\n')))
   672         // This is bad and there's very little we can do since we were requested to find a
   673             ret = QSize(-1, -1);
   673         // sensible size for a widget that pretends to be a QPushButton but is not.
   674         else if (sz == QAquaSizeLarge)
   674         if(psh) {
   675             ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricPushButtonHeight));
   675             QString buttonText = qt_mac_removeMnemonics(psh->text());
   676         else if (sz == QAquaSizeSmall)
   676             if (buttonText.contains(QLatin1Char('\n')))
   677             ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricSmallPushButtonHeight));
   677                 ret = QSize(-1, -1);
   678         else if (sz == QAquaSizeMini)
   678             else if (sz == QAquaSizeLarge)
   679             ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricMiniPushButtonHeight));
   679                 ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricPushButtonHeight));
   680 
   680             else if (sz == QAquaSizeSmall)
   681         if (!psh->icon().isNull()){
   681                 ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricSmallPushButtonHeight));
   682             // If the button got an icon, and the icon is larger than the
   682             else if (sz == QAquaSizeMini)
   683             // button, we can't decide on a default size
   683                 ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricMiniPushButtonHeight));
   684             ret.setWidth(-1);
   684 
   685             if (ret.height() < psh->iconSize().height())
   685             if (!psh->icon().isNull()){
   686                 ret.setHeight(-1);
   686                 // If the button got an icon, and the icon is larger than the
   687         }
   687                 // button, we can't decide on a default size
   688         else if (buttonText == QLatin1String("OK") || buttonText == QLatin1String("Cancel")){
   688                 ret.setWidth(-1);
   689             // Aqua Style guidelines restrict the size of OK and Cancel buttons to 68 pixels.
   689                 if (ret.height() < psh->iconSize().height())
   690             // However, this doesn't work for German, therefore only do it for English,
   690                     ret.setHeight(-1);
   691             // I suppose it would be better to do some sort of lookups for languages
   691             }
   692             // that like to have really long words.
   692             else if (buttonText == QLatin1String("OK") || buttonText == QLatin1String("Cancel")){
   693             ret.setWidth(77 - 8);
   693                 // Aqua Style guidelines restrict the size of OK and Cancel buttons to 68 pixels.
   694         }
   694                 // However, this doesn't work for German, therefore only do it for English,
   695 
   695                 // I suppose it would be better to do some sort of lookups for languages
       
   696                 // that like to have really long words.
       
   697                 ret.setWidth(77 - 8);
       
   698             }
       
   699         } else {
       
   700             // The only sensible thing to do is to return whatever the style suggests...
       
   701             if (sz == QAquaSizeLarge)
       
   702                 ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricPushButtonHeight));
       
   703             else if (sz == QAquaSizeSmall)
       
   704                 ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricSmallPushButtonHeight));
       
   705             else if (sz == QAquaSizeMini)
       
   706                 ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricMiniPushButtonHeight));
       
   707             else
       
   708                 // Since there's no default size we return the large size...
       
   709                 ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricPushButtonHeight));
       
   710          }
   696 #if 0 //Not sure we are applying the rules correctly for RadioButtons/CheckBoxes --Sam
   711 #if 0 //Not sure we are applying the rules correctly for RadioButtons/CheckBoxes --Sam
   697     } else if (ct == QStyle::CT_RadioButton) {
   712     } else if (ct == QStyle::CT_RadioButton) {
   698         QRadioButton *rdo = static_cast<QRadioButton *>(widg);
   713         QRadioButton *rdo = static_cast<QRadioButton *>(widg);
   699         // Exception for case where multiline radio button text requires no size constrainment
   714         // Exception for case where multiline radio button text requires no size constrainment
   700         if (rdo->text().find('\n') != -1)
   715         if (rdo->text().find('\n') != -1)
   747         break;
   762         break;
   748     case QStyle::CT_ToolButton:
   763     case QStyle::CT_ToolButton:
   749         if (sz == QAquaSizeSmall) {
   764         if (sz == QAquaSizeSmall) {
   750             int width = 0, height = 0;
   765             int width = 0, height = 0;
   751             if (szHint == QSize(-1, -1)) { //just 'guess'..
   766             if (szHint == QSize(-1, -1)) { //just 'guess'..
   752                 const QToolButton *bt = static_cast<const QToolButton *>(widg);
   767                 const QToolButton *bt = qobject_cast<const QToolButton *>(widg);
   753                 if (!bt->icon().isNull()) {
   768                 // If this conversion fails then the widget was not what it claimed to be.
   754                     QSize iconSize = bt->iconSize();
   769                 if(bt) {
   755                     QSize pmSize = bt->icon().actualSize(QSize(32, 32), QIcon::Normal);
   770                     if (!bt->icon().isNull()) {
   756                     width = qMax(width, qMax(iconSize.width(), pmSize.width()));
   771                         QSize iconSize = bt->iconSize();
   757                     height = qMax(height, qMax(iconSize.height(), pmSize.height()));
   772                         QSize pmSize = bt->icon().actualSize(QSize(32, 32), QIcon::Normal);
   758                 }
   773                         width = qMax(width, qMax(iconSize.width(), pmSize.width()));
   759                 if (!bt->text().isNull() && bt->toolButtonStyle() != Qt::ToolButtonIconOnly) {
   774                         height = qMax(height, qMax(iconSize.height(), pmSize.height()));
   760                     int text_width = bt->fontMetrics().width(bt->text()),
       
   761                        text_height = bt->fontMetrics().height();
       
   762                     if (bt->toolButtonStyle() == Qt::ToolButtonTextUnderIcon) {
       
   763                         width = qMax(width, text_width);
       
   764                         height += text_height;
       
   765                     } else {
       
   766                         width += text_width;
       
   767                         width = qMax(height, text_height);
       
   768                     }
   775                     }
       
   776                     if (!bt->text().isNull() && bt->toolButtonStyle() != Qt::ToolButtonIconOnly) {
       
   777                         int text_width = bt->fontMetrics().width(bt->text()),
       
   778                            text_height = bt->fontMetrics().height();
       
   779                         if (bt->toolButtonStyle() == Qt::ToolButtonTextUnderIcon) {
       
   780                             width = qMax(width, text_width);
       
   781                             height += text_height;
       
   782                         } else {
       
   783                             width += text_width;
       
   784                             width = qMax(height, text_height);
       
   785                         }
       
   786                     }
       
   787                 } else {
       
   788                     // Let's return the size hint...
       
   789                     width = szHint.width();
       
   790                     height = szHint.height();
   769                 }
   791                 }
   770             } else {
   792             } else {
   771                 width = szHint.width();
   793                 width = szHint.width();
   772                 height = szHint.height();
   794                 height = szHint.height();
   773             }
   795             }
   776             ret = QSize(width, height);
   798             ret = QSize(width, height);
   777         }
   799         }
   778         break;
   800         break;
   779     case QStyle::CT_Slider: {
   801     case QStyle::CT_Slider: {
   780         int w = -1;
   802         int w = -1;
   781         const QSlider *sld = static_cast<const QSlider *>(widg);
   803         const QSlider *sld = qobject_cast<const QSlider *>(widg);
   782         if (sz == QAquaSizeLarge) {
   804         // If this conversion fails then the widget was not what it claimed to be.
   783             if (sld->orientation() == Qt::Horizontal) {
   805         if(sld) {
   784                 w = qt_mac_aqua_get_metric(kThemeMetricHSliderHeight);
   806             if (sz == QAquaSizeLarge) {
   785                 if (sld->tickPosition() != QSlider::NoTicks)
   807                 if (sld->orientation() == Qt::Horizontal) {
   786                     w += qt_mac_aqua_get_metric(kThemeMetricHSliderTickHeight);
   808                     w = qt_mac_aqua_get_metric(kThemeMetricHSliderHeight);
   787             } else {
   809                     if (sld->tickPosition() != QSlider::NoTicks)
   788                 w = qt_mac_aqua_get_metric(kThemeMetricVSliderWidth);
   810                         w += qt_mac_aqua_get_metric(kThemeMetricHSliderTickHeight);
   789                 if (sld->tickPosition() != QSlider::NoTicks)
   811                 } else {
   790                     w += qt_mac_aqua_get_metric(kThemeMetricVSliderTickWidth);
   812                     w = qt_mac_aqua_get_metric(kThemeMetricVSliderWidth);
   791             }
   813                     if (sld->tickPosition() != QSlider::NoTicks)
   792         } else if (sz == QAquaSizeSmall) {
   814                         w += qt_mac_aqua_get_metric(kThemeMetricVSliderTickWidth);
   793             if (sld->orientation() == Qt::Horizontal) {
   815                 }
   794                 w = qt_mac_aqua_get_metric(kThemeMetricSmallHSliderHeight);
   816             } else if (sz == QAquaSizeSmall) {
   795                 if (sld->tickPosition() != QSlider::NoTicks)
   817                 if (sld->orientation() == Qt::Horizontal) {
   796                     w += qt_mac_aqua_get_metric(kThemeMetricSmallHSliderTickHeight);
   818                     w = qt_mac_aqua_get_metric(kThemeMetricSmallHSliderHeight);
   797             } else {
   819                     if (sld->tickPosition() != QSlider::NoTicks)
   798                 w = qt_mac_aqua_get_metric(kThemeMetricSmallVSliderWidth);
   820                         w += qt_mac_aqua_get_metric(kThemeMetricSmallHSliderTickHeight);
   799                 if (sld->tickPosition() != QSlider::NoTicks)
   821                 } else {
   800                     w += qt_mac_aqua_get_metric(kThemeMetricSmallVSliderTickWidth);
   822                     w = qt_mac_aqua_get_metric(kThemeMetricSmallVSliderWidth);
   801             }
   823                     if (sld->tickPosition() != QSlider::NoTicks)
   802         } else if (sz == QAquaSizeMini) {
   824                         w += qt_mac_aqua_get_metric(kThemeMetricSmallVSliderTickWidth);
   803             if (sld->orientation() == Qt::Horizontal) {
   825                 }
   804                 w = qt_mac_aqua_get_metric(kThemeMetricMiniHSliderHeight);
   826             } else if (sz == QAquaSizeMini) {
   805                 if (sld->tickPosition() != QSlider::NoTicks)
   827                 if (sld->orientation() == Qt::Horizontal) {
   806                     w += qt_mac_aqua_get_metric(kThemeMetricMiniHSliderTickHeight);
   828                     w = qt_mac_aqua_get_metric(kThemeMetricMiniHSliderHeight);
   807             } else {
   829                     if (sld->tickPosition() != QSlider::NoTicks)
   808                 w = qt_mac_aqua_get_metric(kThemeMetricMiniVSliderWidth);
   830                         w += qt_mac_aqua_get_metric(kThemeMetricMiniHSliderTickHeight);
   809                 if (sld->tickPosition() != QSlider::NoTicks)
   831                 } else {
   810                     w += qt_mac_aqua_get_metric(kThemeMetricMiniVSliderTickWidth);
   832                     w = qt_mac_aqua_get_metric(kThemeMetricMiniVSliderWidth);
   811             }
   833                     if (sld->tickPosition() != QSlider::NoTicks)
       
   834                         w += qt_mac_aqua_get_metric(kThemeMetricMiniVSliderTickWidth);
       
   835                 }
       
   836             }
       
   837         } else {
       
   838             // This is tricky, we were requested to find a size for a slider which is not
       
   839             // a slider. We don't know if this is vertical or horizontal or if we need to
       
   840             // have tick marks or not.
       
   841             // For this case we will return an horizontal slider without tick marks.
       
   842             w = qt_mac_aqua_get_metric(kThemeMetricHSliderHeight);
       
   843             w += qt_mac_aqua_get_metric(kThemeMetricHSliderTickHeight);
   812         }
   844         }
   813         if (sld->orientation() == Qt::Horizontal)
   845         if (sld->orientation() == Qt::Horizontal)
   814             ret.setHeight(w);
   846             ret.setHeight(w);
   815         else
   847         else
   816             ret.setWidth(w);
   848             ret.setWidth(w);
  2377         break;
  2409         break;
  2378     case PM_MenuHMargin:
  2410     case PM_MenuHMargin:
  2379         ret = 0;
  2411         ret = 0;
  2380         break;
  2412         break;
  2381     case PM_ToolBarFrameWidth:
  2413     case PM_ToolBarFrameWidth:
  2382         ret = 0;
  2414         ret = 1;
       
  2415         if (widget) {
       
  2416             if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(widget->parent()))
       
  2417                 if (mainWindow->unifiedTitleAndToolBarOnMac())
       
  2418                     ret = 0;
       
  2419         }
  2383         break;
  2420         break;
  2384     default:
  2421     default:
  2385         ret = QWindowsStyle::pixelMetric(metric, opt, widget);
  2422         ret = QWindowsStyle::pixelMetric(metric, opt, widget);
  2386         break;
  2423         break;
  2387     }
  2424     }
  4307                 // We need to allow the text a bit more space when the header is as
  4344                 // We need to allow the text a bit more space when the header is as
  4308                 // small as kThemeMetricListHeaderHeight, otherwise it gets clipped:
  4345                 // small as kThemeMetricListHeaderHeight, otherwise it gets clipped:
  4309                 rect.setY(0);
  4346                 rect.setY(0);
  4310                 rect.setHeight(widget->height());
  4347                 rect.setHeight(widget->height());
  4311             }
  4348             }
  4312             if (opt->direction == Qt::RightToLeft)
       
  4313                 rect.adjust(15, 0, -20, 0);
       
  4314         }
  4349         }
  4315         break;
  4350         break;
  4316     case SE_ProgressBarGroove:
  4351     case SE_ProgressBarGroove:
  4317     case SE_ProgressBarLabel:
  4352     case SE_ProgressBarLabel:
  4318         break;
  4353         break;
  5683             sz = QSize(w, h);
  5718             sz = QSize(w, h);
  5684         }
  5719         }
  5685         break;
  5720         break;
  5686     case CT_ToolButton:
  5721     case CT_ToolButton:
  5687         if (widget && qobject_cast<const QToolBar *>(widget->parentWidget())) {
  5722         if (widget && qobject_cast<const QToolBar *>(widget->parentWidget())) {
  5688             sz.rwidth() += 4;
  5723             if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(widget->parent())) {
  5689             if (sz.height() <= 32) {
  5724                 if (mainWindow->unifiedTitleAndToolBarOnMac()) {
  5690                 // Workaround strange HIToolBar bug when getting constraints.
  5725                     sz.rwidth() += 4;
  5691                 sz.rheight() += 1;
  5726                     if (sz.height() <= 32) {
  5692             }
  5727                         // Workaround strange HIToolBar bug when getting constraints.
  5693             return sz;
  5728                         sz.rheight() += 1;
       
  5729                     }
       
  5730                     return sz;
       
  5731                 }
       
  5732             }
  5694         }
  5733         }
  5695         sz.rwidth() += 10;
  5734         sz.rwidth() += 10;
  5696         sz.rheight() += 10;
  5735         sz.rheight() += 10;
  5697         return sz;
  5736         return sz;
  5698     case CT_ComboBox:
  5737     case CT_ComboBox: