Changeset View
Changeset View
Standalone View
Standalone View
plugin/kquickstyleitem.cpp
Show First 20 Lines • Show All 894 Lines • ▼ Show 20 Line(s) | 892 | case ToolButton: { | |||
---|---|---|---|---|---|
895 | int h = 0; | 895 | int h = 0; | ||
896 | if (btn->toolButtonStyle != Qt::ToolButtonTextOnly) { | 896 | if (btn->toolButtonStyle != Qt::ToolButtonTextOnly) { | ||
897 | QSize icon = btn->iconSize; | 897 | QSize icon = btn->iconSize; | ||
898 | w = icon.width(); | 898 | w = icon.width(); | ||
899 | h = icon.height(); | 899 | h = icon.height(); | ||
900 | } | 900 | } | ||
901 | if (btn->toolButtonStyle != Qt::ToolButtonIconOnly) { | 901 | if (btn->toolButtonStyle != Qt::ToolButtonIconOnly) { | ||
902 | QSize textSize = btn->fontMetrics.size(Qt::TextShowMnemonic, btn->text); | 902 | QSize textSize = btn->fontMetrics.size(Qt::TextShowMnemonic, btn->text); | ||
903 | textSize.setWidth(textSize.width() + btn->fontMetrics.width(QLatin1Char(' '))*2); | 903 | textSize.setWidth(textSize.width() + btn->fontMetrics.horizontalAdvance(QLatin1Char(' '))*2); | ||
904 | if (btn->toolButtonStyle == Qt::ToolButtonTextUnderIcon) { | 904 | if (btn->toolButtonStyle == Qt::ToolButtonTextUnderIcon) { | ||
905 | h += 4 + textSize.height(); | 905 | h += 4 + textSize.height(); | ||
906 | if (textSize.width() > w) | 906 | if (textSize.width() > w) | ||
907 | w = textSize.width(); | 907 | w = textSize.width(); | ||
908 | } else if (btn->toolButtonStyle == Qt::ToolButtonTextBesideIcon) { | 908 | } else if (btn->toolButtonStyle == Qt::ToolButtonTextBesideIcon) { | ||
909 | w += 4 + textSize.width(); | 909 | w += 4 + textSize.width(); | ||
910 | if (textSize.height() > h) | 910 | if (textSize.height() > h) | ||
911 | h = textSize.height(); | 911 | h = textSize.height(); | ||
912 | } else { // TextOnly | 912 | } else { // TextOnly | ||
913 | w = textSize.width(); | 913 | w = textSize.width(); | ||
914 | h = textSize.height(); | 914 | h = textSize.height(); | ||
915 | } | 915 | } | ||
916 | } | 916 | } | ||
917 | btn->rect.setSize(QSize(w, h)); | 917 | btn->rect.setSize(QSize(w, h)); | ||
918 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_ToolButton, m_styleoption, QSize(w, h)); } | 918 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_ToolButton, m_styleoption, QSize(w, h)); } | ||
919 | break; | 919 | break; | ||
920 | case Button: { | 920 | case Button: { | ||
921 | QStyleOptionButton *btn = qstyleoption_cast<QStyleOptionButton*>(m_styleoption); | 921 | QStyleOptionButton *btn = qstyleoption_cast<QStyleOptionButton*>(m_styleoption); | ||
922 | 922 | | |||
923 | int contentWidth = btn->fontMetrics.width(btn->text); | 923 | int contentWidth = btn->fontMetrics.boundingRect(btn->text).width(); | ||
924 | int contentHeight = btn->fontMetrics.height(); | 924 | int contentHeight = btn->fontMetrics.height(); | ||
925 | 925 | | |||
926 | if (!btn->icon.isNull()) { | 926 | if (!btn->icon.isNull()) { | ||
927 | //+4 matches a hardcoded value in QStyle and acts as a margin between the icon and the text. | 927 | //+4 matches a hardcoded value in QStyle and acts as a margin between the icon and the text. | ||
928 | contentWidth += btn->iconSize.width() + 4; | 928 | contentWidth += btn->iconSize.width() + 4; | ||
929 | contentHeight = qMax(btn->fontMetrics.height(), btn->iconSize.height()); | 929 | contentHeight = qMax(btn->fontMetrics.height(), btn->iconSize.height()); | ||
930 | } | 930 | } | ||
931 | 931 | | |||
932 | int newWidth = qMax(width, contentWidth); | 932 | int newWidth = qMax(width, contentWidth); | ||
933 | int newHeight = qMax(height, contentHeight); | 933 | int newHeight = qMax(height, contentHeight); | ||
934 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_PushButton, m_styleoption, QSize(newWidth, newHeight)); } | 934 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_PushButton, m_styleoption, QSize(newWidth, newHeight)); } | ||
935 | break; | 935 | break; | ||
936 | case ComboBox: { | 936 | case ComboBox: { | ||
937 | QStyleOptionComboBox *btn = qstyleoption_cast<QStyleOptionComboBox*>(m_styleoption); | 937 | QStyleOptionComboBox *btn = qstyleoption_cast<QStyleOptionComboBox*>(m_styleoption); | ||
938 | int newWidth = qMax(width, btn->fontMetrics.width(btn->currentText)); | 938 | int newWidth = qMax(width, btn->fontMetrics.boundingRect(btn->currentText).width()); | ||
939 | int newHeight = qMax(height, btn->fontMetrics.height()); | 939 | int newHeight = qMax(height, btn->fontMetrics.height()); | ||
940 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_ComboBox, m_styleoption, QSize(newWidth, newHeight)); } | 940 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_ComboBox, m_styleoption, QSize(newWidth, newHeight)); } | ||
941 | break; | 941 | break; | ||
942 | case Tab: { | 942 | case Tab: { | ||
943 | QStyleOptionTab *tab = qstyleoption_cast<QStyleOptionTab*>(m_styleoption); | 943 | QStyleOptionTab *tab = qstyleoption_cast<QStyleOptionTab*>(m_styleoption); | ||
944 | 944 | | |||
945 | int contentWidth = tab->fontMetrics.width(tab->text); | 945 | int contentWidth = tab->fontMetrics.boundingRect(tab->text).width(); | ||
946 | int contentHeight = tab->fontMetrics.height(); | 946 | int contentHeight = tab->fontMetrics.height(); | ||
947 | 947 | | |||
948 | if (!tab->icon.isNull()) { | 948 | if (!tab->icon.isNull()) { | ||
949 | //+4 matches a hardcoded value in QStyle and acts as a margin between the icon and the text. | 949 | //+4 matches a hardcoded value in QStyle and acts as a margin between the icon and the text. | ||
950 | contentWidth += tab->iconSize.width() + 4; | 950 | contentWidth += tab->iconSize.width() + 4; | ||
951 | contentHeight = qMax(contentHeight, tab->iconSize.height()); | 951 | contentHeight = qMax(contentHeight, tab->iconSize.height()); | ||
952 | } | 952 | } | ||
953 | 953 | | |||
Show All 31 Lines | 984 | if (m_itemType == SpinBox) { | |||
985 | size.setWidth(KQuickStyleItem::style()->sizeFromContents(QStyle::CT_SpinBox, | 985 | size.setWidth(KQuickStyleItem::style()->sizeFromContents(QStyle::CT_SpinBox, | ||
986 | m_styleoption, QSize(width + 2, height)).width()); | 986 | m_styleoption, QSize(width + 2, height)).width()); | ||
987 | } | 987 | } | ||
988 | } | 988 | } | ||
989 | break; | 989 | break; | ||
990 | case GroupBox: { | 990 | case GroupBox: { | ||
991 | QStyleOptionGroupBox *box = qstyleoption_cast<QStyleOptionGroupBox*>(m_styleoption); | 991 | QStyleOptionGroupBox *box = qstyleoption_cast<QStyleOptionGroupBox*>(m_styleoption); | ||
992 | QFontMetrics metrics(box->fontMetrics); | 992 | QFontMetrics metrics(box->fontMetrics); | ||
993 | int baseWidth = metrics.width(box->text) + metrics.width(QLatin1Char(' ')); | 993 | int baseWidth = metrics.boundingRect(box->text + QLatin1Char(' ')).width(); | ||
994 | int baseHeight = metrics.height() + m_contentHeight; | 994 | int baseHeight = metrics.height() + m_contentHeight; | ||
995 | if (box->subControls & QStyle::SC_GroupBoxCheckBox) { | 995 | if (box->subControls & QStyle::SC_GroupBoxCheckBox) { | ||
996 | baseWidth += KQuickStyleItem::style()->pixelMetric(QStyle::PM_IndicatorWidth); | 996 | baseWidth += KQuickStyleItem::style()->pixelMetric(QStyle::PM_IndicatorWidth); | ||
997 | baseWidth += KQuickStyleItem::style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing); | 997 | baseWidth += KQuickStyleItem::style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing); | ||
998 | baseHeight = qMax(baseHeight, KQuickStyleItem::style()->pixelMetric(QStyle::PM_IndicatorHeight)); | 998 | baseHeight = qMax(baseHeight, KQuickStyleItem::style()->pixelMetric(QStyle::PM_IndicatorHeight)); | ||
999 | } | 999 | } | ||
1000 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_GroupBox, m_styleoption, QSize(qMax(baseWidth, m_contentWidth), baseHeight)); | 1000 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_GroupBox, m_styleoption, QSize(qMax(baseWidth, m_contentWidth), baseHeight)); | ||
1001 | } | 1001 | } | ||
▲ Show 20 Lines • Show All 421 Lines • ▼ Show 20 Line(s) | 1404 | { | |||
1423 | switch (m_itemType) { | 1423 | switch (m_itemType) { | ||
1424 | case Button: | 1424 | case Button: | ||
1425 | KQuickStyleItem::style()->drawControl(QStyle::CE_PushButton, m_styleoption, painter); | 1425 | KQuickStyleItem::style()->drawControl(QStyle::CE_PushButton, m_styleoption, painter); | ||
1426 | break; | 1426 | break; | ||
1427 | case ItemRow :{ | 1427 | case ItemRow :{ | ||
1428 | QPixmap pixmap; | 1428 | QPixmap pixmap; | ||
1429 | // Only draw through style once | 1429 | // Only draw through style once | ||
1430 | const QString pmKey = QLatin1String("itemrow") % QString::number(m_styleoption->state,16) % activeControl(); | 1430 | const QString pmKey = QLatin1String("itemrow") % QString::number(m_styleoption->state,16) % activeControl(); | ||
1431 | if (!QPixmapCache::find(pmKey, pixmap) || pixmap.width() < width() || height() != pixmap.height()) { | 1431 | if (!QPixmapCache::find(pmKey, &pixmap) || pixmap.width() < width() || height() != pixmap.height()) { | ||
1432 | int newSize = width(); | 1432 | int newSize = width(); | ||
1433 | pixmap = QPixmap(newSize, height()); | 1433 | pixmap = QPixmap(newSize, height()); | ||
1434 | pixmap.fill(Qt::transparent); | 1434 | pixmap.fill(Qt::transparent); | ||
1435 | QPainter pixpainter(&pixmap); | 1435 | QPainter pixpainter(&pixmap); | ||
1436 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_PanelItemViewRow, m_styleoption, &pixpainter); | 1436 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_PanelItemViewRow, m_styleoption, &pixpainter); | ||
1437 | if ((styleName() == QLatin1String("mac") || !KQuickStyleItem::style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected)) && selected()) { | 1437 | if ((styleName() == QLatin1String("mac") || !KQuickStyleItem::style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected)) && selected()) { | ||
1438 | QPalette pal = QApplication::palette("QAbstractItemView"); | 1438 | QPalette pal = QApplication::palette("QAbstractItemView"); | ||
1439 | pal.setCurrentColorGroup(m_styleoption->palette.currentColorGroup()); | 1439 | pal.setCurrentColorGroup(m_styleoption->palette.currentColorGroup()); | ||
▲ Show 20 Lines • Show All 370 Lines • Show Last 20 Lines |