Changeset 651 for trunk/src/gui/styles/qmacstyle_mac.mm
- Timestamp:
- Mar 8, 2010, 12:52:58 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.6.2 (added) merged: 650 /branches/vendor/nokia/qt/current merged: 649 /branches/vendor/nokia/qt/4.6.1 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/styles/qmacstyle_mac.mm
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 668 668 switch (ct) { 669 669 case QStyle::CT_PushButton: { 670 const QPushButton *psh = static_cast<const QPushButton *>(widg); 671 QString buttonText = qt_mac_removeMnemonics(psh->text()); 672 if (buttonText.contains(QLatin1Char('\n'))) 673 ret = QSize(-1, -1); 674 else if (sz == QAquaSizeLarge) 675 ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricPushButtonHeight)); 676 else if (sz == QAquaSizeSmall) 677 ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricSmallPushButtonHeight)); 678 else if (sz == QAquaSizeMini) 679 ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricMiniPushButtonHeight)); 680 681 if (!psh->icon().isNull()){ 682 // If the button got an icon, and the icon is larger than the 683 // button, we can't decide on a default size 684 ret.setWidth(-1); 685 if (ret.height() < psh->iconSize().height()) 686 ret.setHeight(-1); 687 } 688 else if (buttonText == QLatin1String("OK") || buttonText == QLatin1String("Cancel")){ 689 // Aqua Style guidelines restrict the size of OK and Cancel buttons to 68 pixels. 690 // However, this doesn't work for German, therefore only do it for English, 691 // I suppose it would be better to do some sort of lookups for languages 692 // that like to have really long words. 693 ret.setWidth(77 - 8); 694 } 695 670 const QPushButton *psh = qobject_cast<const QPushButton *>(widg); 671 // If this comparison is false, then the widget was not a push button. 672 // This is bad and there's very little we can do since we were requested to find a 673 // sensible size for a widget that pretends to be a QPushButton but is not. 674 if(psh) { 675 QString buttonText = qt_mac_removeMnemonics(psh->text()); 676 if (buttonText.contains(QLatin1Char('\n'))) 677 ret = QSize(-1, -1); 678 else if (sz == QAquaSizeLarge) 679 ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricPushButtonHeight)); 680 else if (sz == QAquaSizeSmall) 681 ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricSmallPushButtonHeight)); 682 else if (sz == QAquaSizeMini) 683 ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricMiniPushButtonHeight)); 684 685 if (!psh->icon().isNull()){ 686 // If the button got an icon, and the icon is larger than the 687 // button, we can't decide on a default size 688 ret.setWidth(-1); 689 if (ret.height() < psh->iconSize().height()) 690 ret.setHeight(-1); 691 } 692 else if (buttonText == QLatin1String("OK") || buttonText == QLatin1String("Cancel")){ 693 // Aqua Style guidelines restrict the size of OK and Cancel buttons to 68 pixels. 694 // However, this doesn't work for German, therefore only do it for English, 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 711 #if 0 //Not sure we are applying the rules correctly for RadioButtons/CheckBoxes --Sam 697 712 } else if (ct == QStyle::CT_RadioButton) { … … 750 765 int width = 0, height = 0; 751 766 if (szHint == QSize(-1, -1)) { //just 'guess'.. 752 const QToolButton *bt = static_cast<const QToolButton *>(widg); 753 if (!bt->icon().isNull()) { 754 QSize iconSize = bt->iconSize(); 755 QSize pmSize = bt->icon().actualSize(QSize(32, 32), QIcon::Normal); 756 width = qMax(width, qMax(iconSize.width(), pmSize.width())); 757 height = qMax(height, qMax(iconSize.height(), pmSize.height())); 758 } 759 if (!bt->text().isNull() && bt->toolButtonStyle() != Qt::ToolButtonIconOnly) { 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); 767 const QToolButton *bt = qobject_cast<const QToolButton *>(widg); 768 // If this conversion fails then the widget was not what it claimed to be. 769 if(bt) { 770 if (!bt->icon().isNull()) { 771 QSize iconSize = bt->iconSize(); 772 QSize pmSize = bt->icon().actualSize(QSize(32, 32), QIcon::Normal); 773 width = qMax(width, qMax(iconSize.width(), pmSize.width())); 774 height = qMax(height, qMax(iconSize.height(), pmSize.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 792 } else { … … 779 801 case QStyle::CT_Slider: { 780 802 int w = -1; 781 const QSlider *sld = static_cast<const QSlider *>(widg); 782 if (sz == QAquaSizeLarge) { 783 if (sld->orientation() == Qt::Horizontal) { 784 w = qt_mac_aqua_get_metric(kThemeMetricHSliderHeight); 785 if (sld->tickPosition() != QSlider::NoTicks) 786 w += qt_mac_aqua_get_metric(kThemeMetricHSliderTickHeight); 787 } else { 788 w = qt_mac_aqua_get_metric(kThemeMetricVSliderWidth); 789 if (sld->tickPosition() != QSlider::NoTicks) 790 w += qt_mac_aqua_get_metric(kThemeMetricVSliderTickWidth); 791 } 792 } else if (sz == QAquaSizeSmall) { 793 if (sld->orientation() == Qt::Horizontal) { 794 w = qt_mac_aqua_get_metric(kThemeMetricSmallHSliderHeight); 795 if (sld->tickPosition() != QSlider::NoTicks) 796 w += qt_mac_aqua_get_metric(kThemeMetricSmallHSliderTickHeight); 797 } else { 798 w = qt_mac_aqua_get_metric(kThemeMetricSmallVSliderWidth); 799 if (sld->tickPosition() != QSlider::NoTicks) 800 w += qt_mac_aqua_get_metric(kThemeMetricSmallVSliderTickWidth); 801 } 802 } else if (sz == QAquaSizeMini) { 803 if (sld->orientation() == Qt::Horizontal) { 804 w = qt_mac_aqua_get_metric(kThemeMetricMiniHSliderHeight); 805 if (sld->tickPosition() != QSlider::NoTicks) 806 w += qt_mac_aqua_get_metric(kThemeMetricMiniHSliderTickHeight); 807 } else { 808 w = qt_mac_aqua_get_metric(kThemeMetricMiniVSliderWidth); 809 if (sld->tickPosition() != QSlider::NoTicks) 810 w += qt_mac_aqua_get_metric(kThemeMetricMiniVSliderTickWidth); 811 } 803 const QSlider *sld = qobject_cast<const QSlider *>(widg); 804 // If this conversion fails then the widget was not what it claimed to be. 805 if(sld) { 806 if (sz == QAquaSizeLarge) { 807 if (sld->orientation() == Qt::Horizontal) { 808 w = qt_mac_aqua_get_metric(kThemeMetricHSliderHeight); 809 if (sld->tickPosition() != QSlider::NoTicks) 810 w += qt_mac_aqua_get_metric(kThemeMetricHSliderTickHeight); 811 } else { 812 w = qt_mac_aqua_get_metric(kThemeMetricVSliderWidth); 813 if (sld->tickPosition() != QSlider::NoTicks) 814 w += qt_mac_aqua_get_metric(kThemeMetricVSliderTickWidth); 815 } 816 } else if (sz == QAquaSizeSmall) { 817 if (sld->orientation() == Qt::Horizontal) { 818 w = qt_mac_aqua_get_metric(kThemeMetricSmallHSliderHeight); 819 if (sld->tickPosition() != QSlider::NoTicks) 820 w += qt_mac_aqua_get_metric(kThemeMetricSmallHSliderTickHeight); 821 } else { 822 w = qt_mac_aqua_get_metric(kThemeMetricSmallVSliderWidth); 823 if (sld->tickPosition() != QSlider::NoTicks) 824 w += qt_mac_aqua_get_metric(kThemeMetricSmallVSliderTickWidth); 825 } 826 } else if (sz == QAquaSizeMini) { 827 if (sld->orientation() == Qt::Horizontal) { 828 w = qt_mac_aqua_get_metric(kThemeMetricMiniHSliderHeight); 829 if (sld->tickPosition() != QSlider::NoTicks) 830 w += qt_mac_aqua_get_metric(kThemeMetricMiniHSliderTickHeight); 831 } else { 832 w = qt_mac_aqua_get_metric(kThemeMetricMiniVSliderWidth); 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 845 if (sld->orientation() == Qt::Horizontal) … … 2380 2412 break; 2381 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 2420 break; 2384 2421 default: … … 4310 4347 rect.setHeight(widget->height()); 4311 4348 } 4312 if (opt->direction == Qt::RightToLeft)4313 rect.adjust(15, 0, -20, 0);4314 4349 } 4315 4350 break; … … 5686 5721 case CT_ToolButton: 5687 5722 if (widget && qobject_cast<const QToolBar *>(widget->parentWidget())) { 5688 sz.rwidth() += 4; 5689 if (sz.height() <= 32) { 5690 // Workaround strange HIToolBar bug when getting constraints. 5691 sz.rheight() += 1; 5692 } 5693 return sz; 5723 if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(widget->parent())) { 5724 if (mainWindow->unifiedTitleAndToolBarOnMac()) { 5725 sz.rwidth() += 4; 5726 if (sz.height() <= 32) { 5727 // Workaround strange HIToolBar bug when getting constraints. 5728 sz.rheight() += 1; 5729 } 5730 return sz; 5731 } 5732 } 5694 5733 } 5695 5734 sz.rwidth() += 10;
Note:
See TracChangeset
for help on using the changeset viewer.