Changeset View
Changeset View
Standalone View
Standalone View
plugin/kquickstyleitem.cpp
Show All 39 Lines | |||||
40 | ****************************************************************************/ | 40 | ****************************************************************************/ | ||
41 | 41 | | |||
42 | #include "kquickstyleitem_p.h" | 42 | #include "kquickstyleitem_p.h" | ||
43 | 43 | | |||
44 | #include <qstringbuilder.h> | 44 | #include <qstringbuilder.h> | ||
45 | #include <qpainter.h> | 45 | #include <qpainter.h> | ||
46 | #include <qpixmapcache.h> | 46 | #include <qpixmapcache.h> | ||
47 | #include <qstyle.h> | 47 | #include <qstyle.h> | ||
48 | #include <qstylefactory.h> | ||||
48 | #include <qstyleoption.h> | 49 | #include <qstyleoption.h> | ||
49 | #include <qapplication.h> | 50 | #include <qapplication.h> | ||
50 | #include <qquickwindow.h> | 51 | #include <qquickwindow.h> | ||
51 | #include <QtQuick/qsgninepatchnode.h> | 52 | #include <QtQuick/qsgninepatchnode.h> | ||
52 | 53 | | |||
54 | #include <ksharedconfig.h> | ||||
55 | #include <kconfiggroup.h> | ||||
56 | | ||||
53 | #include <Kirigami2/PlatformTheme> | 57 | #include <Kirigami2/PlatformTheme> | ||
54 | 58 | | |||
59 | QStyle *KQuickStyleItem::s_style = nullptr; | ||||
60 | | ||||
61 | QStyle *KQuickStyleItem::style() | ||||
62 | { | ||||
63 | auto style = qApp->style(); | ||||
64 | return style ? style : s_style; | ||||
65 | } | ||||
66 | | ||||
55 | KQuickStyleItem::KQuickStyleItem(QQuickItem *parent) | 67 | KQuickStyleItem::KQuickStyleItem(QQuickItem *parent) | ||
56 | : QQuickItem(parent), | 68 | : QQuickItem(parent), | ||
57 | m_styleoption(nullptr), | 69 | m_styleoption(nullptr), | ||
58 | m_itemType(Undefined), | 70 | m_itemType(Undefined), | ||
59 | m_sunken(false), | 71 | m_sunken(false), | ||
60 | m_raised(false), | 72 | m_raised(false), | ||
61 | m_active(true), | 73 | m_active(true), | ||
62 | m_selected(false), | 74 | m_selected(false), | ||
Show All 9 Lines | |||||
72 | m_step(0), | 84 | m_step(0), | ||
73 | m_paintMargins(0), | 85 | m_paintMargins(0), | ||
74 | m_contentWidth(0), | 86 | m_contentWidth(0), | ||
75 | m_contentHeight(0), | 87 | m_contentHeight(0), | ||
76 | m_textureWidth(0), | 88 | m_textureWidth(0), | ||
77 | m_textureHeight(0), | 89 | m_textureHeight(0), | ||
78 | m_lastFocusReason(Qt::NoFocusReason) | 90 | m_lastFocusReason(Qt::NoFocusReason) | ||
79 | { | 91 | { | ||
92 | if (!qApp->style()) { | ||||
93 | KSharedConfig::Ptr kdeglobals = KSharedConfig::openConfig(); | ||||
94 | KConfigGroup cg(kdeglobals, "KDE"); | ||||
95 | auto style = s_style; | ||||
96 | s_style = QStyleFactory::create(cg.readEntry("widgetStyle", QStringLiteral("Fusion"))); | ||||
97 | if (style) { | ||||
98 | delete style; | ||||
99 | } | ||||
100 | } | ||||
101 | | ||||
80 | m_font = qApp->font(); | 102 | m_font = qApp->font(); | ||
81 | setFlag(QQuickItem::ItemHasContents, true); | 103 | setFlag(QQuickItem::ItemHasContents, true); | ||
82 | setSmooth(false); | 104 | setSmooth(false); | ||
83 | qmlRegisterType<KQuickPadding>(); | 105 | qmlRegisterType<KQuickPadding>(); | ||
84 | 106 | | |||
85 | connect(this, &KQuickStyleItem::visibleChanged, this, &KQuickStyleItem::updateItem); | 107 | connect(this, &KQuickStyleItem::visibleChanged, this, &KQuickStyleItem::updateItem); | ||
86 | connect(this, &KQuickStyleItem::widthChanged, this, &KQuickStyleItem::updateItem); | 108 | connect(this, &KQuickStyleItem::widthChanged, this, &KQuickStyleItem::updateItem); | ||
87 | connect(this, &KQuickStyleItem::heightChanged, this, &KQuickStyleItem::updateItem); | 109 | connect(this, &KQuickStyleItem::heightChanged, this, &KQuickStyleItem::updateItem); | ||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 202 | case Button: { | |||
187 | const QVariant icon = m_properties[QStringLiteral("icon")]; | 209 | const QVariant icon = m_properties[QStringLiteral("icon")]; | ||
188 | if (icon.canConvert<QIcon>()) { | 210 | if (icon.canConvert<QIcon>()) { | ||
189 | opt->icon = icon.value<QIcon>(); | 211 | opt->icon = icon.value<QIcon>(); | ||
190 | } else if (icon.canConvert<QString>()) { | 212 | } else if (icon.canConvert<QString>()) { | ||
191 | opt->icon = m_theme->iconFromTheme(icon.value<QString>(), m_properties[QStringLiteral("iconColor")].value<QColor>()); | 213 | opt->icon = m_theme->iconFromTheme(icon.value<QString>(), m_properties[QStringLiteral("iconColor")].value<QColor>()); | ||
192 | } | 214 | } | ||
193 | auto iconSize = QSize(m_properties[QStringLiteral("iconWidth")].toInt(), m_properties[QStringLiteral("iconHeight")].toInt()); | 215 | auto iconSize = QSize(m_properties[QStringLiteral("iconWidth")].toInt(), m_properties[QStringLiteral("iconHeight")].toInt()); | ||
194 | if (iconSize.isEmpty()) { | 216 | if (iconSize.isEmpty()) { | ||
195 | int e = qApp->style()->pixelMetric(QStyle::PM_ButtonIconSize, m_styleoption, nullptr); | 217 | int e = KQuickStyleItem::style()->pixelMetric(QStyle::PM_ButtonIconSize, m_styleoption, nullptr); | ||
196 | if (iconSize.width() <= 0) { | 218 | if (iconSize.width() <= 0) { | ||
197 | iconSize.setWidth(e); | 219 | iconSize.setWidth(e); | ||
198 | } | 220 | } | ||
199 | if (iconSize.height() <= 0) { | 221 | if (iconSize.height() <= 0) { | ||
200 | iconSize.setHeight(e); | 222 | iconSize.setHeight(e); | ||
201 | } | 223 | } | ||
202 | } | 224 | } | ||
203 | opt->iconSize = iconSize; | 225 | opt->iconSize = iconSize; | ||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Line(s) | 316 | case ToolButton: { | |||
311 | if (m_properties.value(QStringLiteral("menu")).toBool()) { | 333 | if (m_properties.value(QStringLiteral("menu")).toBool()) { | ||
312 | opt->subControls |= QStyle::SC_ToolButtonMenu; | 334 | opt->subControls |= QStyle::SC_ToolButtonMenu; | ||
313 | opt->features = QStyleOptionToolButton::HasMenu; | 335 | opt->features = QStyleOptionToolButton::HasMenu; | ||
314 | } | 336 | } | ||
315 | 337 | | |||
316 | // For now both text and icon | 338 | // For now both text and icon | ||
317 | opt->toolButtonStyle = Qt::ToolButtonTextBesideIcon; | 339 | opt->toolButtonStyle = Qt::ToolButtonTextBesideIcon; | ||
318 | 340 | | |||
319 | int e = qApp->style()->pixelMetric(QStyle::PM_ToolBarIconSize, m_styleoption, nullptr); | 341 | int e = KQuickStyleItem::style()->pixelMetric(QStyle::PM_ToolBarIconSize, m_styleoption, nullptr); | ||
320 | opt->iconSize = QSize(e, e); | 342 | opt->iconSize = QSize(e, e); | ||
321 | 343 | | |||
322 | const QFont font = qApp->font("QToolButton"); | 344 | const QFont font = qApp->font("QToolButton"); | ||
323 | opt->font = font; | 345 | opt->font = font; | ||
324 | opt->fontMetrics = QFontMetrics(font); | 346 | opt->fontMetrics = QFontMetrics(font); | ||
325 | } | 347 | } | ||
326 | break; | 348 | break; | ||
327 | case ToolBar: { | 349 | case ToolBar: { | ||
▲ Show 20 Lines • Show All 282 Lines • ▼ Show 20 Line(s) | 630 | ? QStyle::SC_ScrollBarSubLine : (activeControl() == QLatin1String("down")) ? | |||
610 | (activeControl() == QLatin1String("handle")) ? | 632 | (activeControl() == QLatin1String("handle")) ? | ||
611 | QStyle::SC_ScrollBarSlider : hover() ? QStyle::SC_ScrollBarGroove : QStyle::SC_None; | 633 | QStyle::SC_ScrollBarSlider : hover() ? QStyle::SC_ScrollBarGroove : QStyle::SC_None; | ||
612 | if (raised()) | 634 | if (raised()) | ||
613 | opt->state |= QStyle::State_On; | 635 | opt->state |= QStyle::State_On; | ||
614 | 636 | | |||
615 | opt->sliderValue = value(); | 637 | opt->sliderValue = value(); | ||
616 | opt->subControls = QStyle::SC_All; | 638 | opt->subControls = QStyle::SC_All; | ||
617 | 639 | | |||
618 | setTransient(qApp->style()->styleHint(QStyle::SH_ScrollBar_Transient, m_styleoption)); | 640 | setTransient(KQuickStyleItem::style()->styleHint(QStyle::SH_ScrollBar_Transient, m_styleoption)); | ||
619 | break; | 641 | break; | ||
620 | } | 642 | } | ||
621 | default: | 643 | default: | ||
622 | break; | 644 | break; | ||
623 | } | 645 | } | ||
624 | 646 | | |||
625 | if (!m_styleoption) | 647 | if (!m_styleoption) | ||
626 | m_styleoption = new QStyleOption(); | 648 | m_styleoption = new QStyleOption(); | ||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Line(s) | |||||
741 | * | 763 | * | ||
742 | * Returns a simplified style name. | 764 | * Returns a simplified style name. | ||
743 | * | 765 | * | ||
744 | * QMacStyle = "mac" | 766 | * QMacStyle = "mac" | ||
745 | * QWindowsXPStyle = "windowsxp" | 767 | * QWindowsXPStyle = "windowsxp" | ||
746 | * QFusionStyle = "fusion" | 768 | * QFusionStyle = "fusion" | ||
747 | */ | 769 | */ | ||
748 | 770 | | |||
749 | QString KQuickStyleItem::style() const | 771 | QString KQuickStyleItem::styleName() const | ||
750 | { | 772 | { | ||
751 | QString style = QString::fromLatin1(qApp->style()->metaObject()->className()); | 773 | QString style = QString::fromLatin1(KQuickStyleItem::style()->metaObject()->className()); | ||
752 | style = style.toLower(); | 774 | style = style.toLower(); | ||
753 | if (style.startsWith(QLatin1Char('q'))) | 775 | if (style.startsWith(QLatin1Char('q'))) | ||
754 | style = style.right(style.length() - 1); | 776 | style = style.right(style.length() - 1); | ||
755 | if (style.endsWith(QLatin1String("style"))) | 777 | if (style.endsWith(QLatin1String("style"))) | ||
756 | style = style.left(style.length() - 5); | 778 | style = style.left(style.length() - 5); | ||
757 | return style; | 779 | return style; | ||
758 | } | 780 | } | ||
759 | 781 | | |||
760 | QString KQuickStyleItem::hitTest(int px, int py) | 782 | QString KQuickStyleItem::hitTest(int px, int py) | ||
761 | { | 783 | { | ||
762 | QStyle::SubControl subcontrol = QStyle::SC_All; | 784 | QStyle::SubControl subcontrol = QStyle::SC_All; | ||
763 | switch (m_itemType) { | 785 | switch (m_itemType) { | ||
764 | case SpinBox :{ | 786 | case SpinBox :{ | ||
765 | subcontrol = qApp->style()->hitTestComplexControl(QStyle::CC_SpinBox, | 787 | subcontrol = KQuickStyleItem::style()->hitTestComplexControl(QStyle::CC_SpinBox, | ||
766 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 788 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
767 | QPoint(px,py), nullptr); | 789 | QPoint(px,py), nullptr); | ||
768 | if (subcontrol == QStyle::SC_SpinBoxUp) | 790 | if (subcontrol == QStyle::SC_SpinBoxUp) | ||
769 | return QStringLiteral("up"); | 791 | return QStringLiteral("up"); | ||
770 | else if (subcontrol == QStyle::SC_SpinBoxDown) | 792 | else if (subcontrol == QStyle::SC_SpinBoxDown) | ||
771 | return QStringLiteral("down"); | 793 | return QStringLiteral("down"); | ||
772 | } | 794 | } | ||
773 | break; | 795 | break; | ||
774 | 796 | | |||
775 | case Slider: { | 797 | case Slider: { | ||
776 | subcontrol = qApp->style()->hitTestComplexControl(QStyle::CC_Slider, | 798 | subcontrol = KQuickStyleItem::style()->hitTestComplexControl(QStyle::CC_Slider, | ||
777 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 799 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
778 | QPoint(px,py), nullptr); | 800 | QPoint(px,py), nullptr); | ||
779 | if (subcontrol == QStyle::SC_SliderHandle) | 801 | if (subcontrol == QStyle::SC_SliderHandle) | ||
780 | return QStringLiteral("handle"); | 802 | return QStringLiteral("handle"); | ||
781 | } | 803 | } | ||
782 | break; | 804 | break; | ||
783 | 805 | | |||
784 | case ScrollBar: { | 806 | case ScrollBar: { | ||
785 | subcontrol = qApp->style()->hitTestComplexControl(QStyle::CC_ScrollBar, | 807 | subcontrol = KQuickStyleItem::style()->hitTestComplexControl(QStyle::CC_ScrollBar, | ||
786 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 808 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
787 | QPoint(px,py), nullptr); | 809 | QPoint(px,py), nullptr); | ||
788 | switch (subcontrol) { | 810 | switch (subcontrol) { | ||
789 | case QStyle::SC_ScrollBarSlider: | 811 | case QStyle::SC_ScrollBarSlider: | ||
790 | return QStringLiteral("handle"); | 812 | return QStringLiteral("handle"); | ||
791 | 813 | | |||
792 | case QStyle::SC_ScrollBarSubLine: | 814 | case QStyle::SC_ScrollBarSubLine: | ||
793 | return QStringLiteral("up"); | 815 | return QStringLiteral("up"); | ||
Show All 21 Lines | |||||
815 | 837 | | |||
816 | QSize KQuickStyleItem::sizeFromContents(int width, int height) | 838 | QSize KQuickStyleItem::sizeFromContents(int width, int height) | ||
817 | { | 839 | { | ||
818 | initStyleOption(); | 840 | initStyleOption(); | ||
819 | 841 | | |||
820 | QSize size; | 842 | QSize size; | ||
821 | switch (m_itemType) { | 843 | switch (m_itemType) { | ||
822 | case RadioButton: | 844 | case RadioButton: | ||
823 | size = qApp->style()->sizeFromContents(QStyle::CT_RadioButton, m_styleoption, QSize(width,height)); | 845 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_RadioButton, m_styleoption, QSize(width,height)); | ||
824 | break; | 846 | break; | ||
825 | case CheckBox: | 847 | case CheckBox: | ||
826 | size = qApp->style()->sizeFromContents(QStyle::CT_CheckBox, m_styleoption, QSize(width,height)); | 848 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_CheckBox, m_styleoption, QSize(width,height)); | ||
827 | break; | 849 | break; | ||
828 | case ToolBar: | 850 | case ToolBar: | ||
829 | size = QSize(200, style().contains(QLatin1String("windows")) ? 30 : 42); | 851 | size = QSize(200, styleName().contains(QLatin1String("windows")) ? 30 : 42); | ||
830 | break; | 852 | break; | ||
831 | case ToolButton: { | 853 | case ToolButton: { | ||
832 | QStyleOptionToolButton *btn = qstyleoption_cast<QStyleOptionToolButton*>(m_styleoption); | 854 | QStyleOptionToolButton *btn = qstyleoption_cast<QStyleOptionToolButton*>(m_styleoption); | ||
833 | int w = 0; | 855 | int w = 0; | ||
834 | int h = 0; | 856 | int h = 0; | ||
835 | if (btn->toolButtonStyle != Qt::ToolButtonTextOnly) { | 857 | if (btn->toolButtonStyle != Qt::ToolButtonTextOnly) { | ||
836 | QSize icon = btn->iconSize; | 858 | QSize icon = btn->iconSize; | ||
837 | w = icon.width(); | 859 | w = icon.width(); | ||
Show All 11 Lines | 869 | } else if (btn->toolButtonStyle == Qt::ToolButtonTextBesideIcon) { | |||
849 | if (textSize.height() > h) | 871 | if (textSize.height() > h) | ||
850 | h = textSize.height(); | 872 | h = textSize.height(); | ||
851 | } else { // TextOnly | 873 | } else { // TextOnly | ||
852 | w = textSize.width(); | 874 | w = textSize.width(); | ||
853 | h = textSize.height(); | 875 | h = textSize.height(); | ||
854 | } | 876 | } | ||
855 | } | 877 | } | ||
856 | btn->rect.setSize(QSize(w, h)); | 878 | btn->rect.setSize(QSize(w, h)); | ||
857 | size = qApp->style()->sizeFromContents(QStyle::CT_ToolButton, m_styleoption, QSize(w, h)); } | 879 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_ToolButton, m_styleoption, QSize(w, h)); } | ||
858 | break; | 880 | break; | ||
859 | case Button: { | 881 | case Button: { | ||
860 | QStyleOptionButton *btn = qstyleoption_cast<QStyleOptionButton*>(m_styleoption); | 882 | QStyleOptionButton *btn = qstyleoption_cast<QStyleOptionButton*>(m_styleoption); | ||
861 | 883 | | |||
862 | int contentWidth = btn->fontMetrics.width(btn->text); | 884 | int contentWidth = btn->fontMetrics.width(btn->text); | ||
863 | int contentHeight = btn->fontMetrics.height(); | 885 | int contentHeight = btn->fontMetrics.height(); | ||
864 | if (!btn->icon.isNull()) { | 886 | if (!btn->icon.isNull()) { | ||
865 | //+4 matches a hardcoded value in QStyle and acts as a margin between the icon and the text. | 887 | //+4 matches a hardcoded value in QStyle and acts as a margin between the icon and the text. | ||
866 | contentWidth += btn->iconSize.width() + 4; | 888 | contentWidth += btn->iconSize.width() + 4; | ||
867 | contentHeight = qMax(btn->fontMetrics.height(), btn->iconSize.height()); | 889 | contentHeight = qMax(btn->fontMetrics.height(), btn->iconSize.height()); | ||
868 | } | 890 | } | ||
869 | int newWidth = qMax(width, contentWidth); | 891 | int newWidth = qMax(width, contentWidth); | ||
870 | int newHeight = qMax(height, contentHeight); | 892 | int newHeight = qMax(height, contentHeight); | ||
871 | size = qApp->style()->sizeFromContents(QStyle::CT_PushButton, m_styleoption, QSize(newWidth, newHeight)); } | 893 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_PushButton, m_styleoption, QSize(newWidth, newHeight)); } | ||
872 | break; | 894 | break; | ||
873 | case ComboBox: { | 895 | case ComboBox: { | ||
874 | QStyleOptionComboBox *btn = qstyleoption_cast<QStyleOptionComboBox*>(m_styleoption); | 896 | QStyleOptionComboBox *btn = qstyleoption_cast<QStyleOptionComboBox*>(m_styleoption); | ||
875 | int newWidth = qMax(width, btn->fontMetrics.width(btn->currentText)); | 897 | int newWidth = qMax(width, btn->fontMetrics.width(btn->currentText)); | ||
876 | int newHeight = qMax(height, btn->fontMetrics.height()); | 898 | int newHeight = qMax(height, btn->fontMetrics.height()); | ||
877 | size = qApp->style()->sizeFromContents(QStyle::CT_ComboBox, m_styleoption, QSize(newWidth, newHeight)); } | 899 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_ComboBox, m_styleoption, QSize(newWidth, newHeight)); } | ||
878 | break; | 900 | break; | ||
879 | case Tab: | 901 | case Tab: | ||
880 | size = qApp->style()->sizeFromContents(QStyle::CT_TabBarTab, m_styleoption, QSize(width,height)); | 902 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_TabBarTab, m_styleoption, QSize(width,height)); | ||
881 | break; | 903 | break; | ||
882 | case Slider: | 904 | case Slider: | ||
883 | size = qApp->style()->sizeFromContents(QStyle::CT_Slider, m_styleoption, QSize(width,height)); | 905 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_Slider, m_styleoption, QSize(width,height)); | ||
884 | break; | 906 | break; | ||
885 | case ProgressBar: | 907 | case ProgressBar: | ||
886 | size = qApp->style()->sizeFromContents(QStyle::CT_ProgressBar, m_styleoption, QSize(width,height)); | 908 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_ProgressBar, m_styleoption, QSize(width,height)); | ||
887 | break; | 909 | break; | ||
888 | case SpinBox: | 910 | case SpinBox: | ||
889 | case Edit: | 911 | case Edit: | ||
890 | { | 912 | { | ||
891 | // We have to create a new style option since we might be calling with a QStyleOptionSpinBox | 913 | // We have to create a new style option since we might be calling with a QStyleOptionSpinBox | ||
892 | QStyleOptionFrame frame; | 914 | QStyleOptionFrame frame; | ||
893 | frame.state = m_styleoption->state; | 915 | frame.state = m_styleoption->state; | ||
894 | frame.lineWidth = qApp->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, m_styleoption, nullptr); | 916 | frame.lineWidth = KQuickStyleItem::style()->pixelMetric(QStyle::PM_DefaultFrameWidth, m_styleoption, nullptr); | ||
895 | frame.rect = m_styleoption->rect; | 917 | frame.rect = m_styleoption->rect; | ||
896 | frame.styleObject = this; | 918 | frame.styleObject = this; | ||
897 | size = qApp->style()->sizeFromContents(QStyle::CT_LineEdit, &frame, QSize(width, height)); | 919 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_LineEdit, &frame, QSize(width, height)); | ||
898 | if (m_itemType == SpinBox) | 920 | if (m_itemType == SpinBox) | ||
899 | size.setWidth(qApp->style()->sizeFromContents(QStyle::CT_SpinBox, | 921 | size.setWidth(KQuickStyleItem::style()->sizeFromContents(QStyle::CT_SpinBox, | ||
900 | m_styleoption, QSize(width + 2, height)).width()); | 922 | m_styleoption, QSize(width + 2, height)).width()); | ||
901 | } | 923 | } | ||
902 | break; | 924 | break; | ||
903 | case GroupBox: { | 925 | case GroupBox: { | ||
904 | QStyleOptionGroupBox *box = qstyleoption_cast<QStyleOptionGroupBox*>(m_styleoption); | 926 | QStyleOptionGroupBox *box = qstyleoption_cast<QStyleOptionGroupBox*>(m_styleoption); | ||
905 | QFontMetrics metrics(box->fontMetrics); | 927 | QFontMetrics metrics(box->fontMetrics); | ||
906 | int baseWidth = metrics.width(box->text) + metrics.width(QLatin1Char(' ')); | 928 | int baseWidth = metrics.width(box->text) + metrics.width(QLatin1Char(' ')); | ||
907 | int baseHeight = metrics.height() + m_contentHeight; | 929 | int baseHeight = metrics.height() + m_contentHeight; | ||
908 | if (box->subControls & QStyle::SC_GroupBoxCheckBox) { | 930 | if (box->subControls & QStyle::SC_GroupBoxCheckBox) { | ||
909 | baseWidth += qApp->style()->pixelMetric(QStyle::PM_IndicatorWidth); | 931 | baseWidth += KQuickStyleItem::style()->pixelMetric(QStyle::PM_IndicatorWidth); | ||
910 | baseWidth += qApp->style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing); | 932 | baseWidth += KQuickStyleItem::style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing); | ||
911 | baseHeight = qMax(baseHeight, qApp->style()->pixelMetric(QStyle::PM_IndicatorHeight)); | 933 | baseHeight = qMax(baseHeight, KQuickStyleItem::style()->pixelMetric(QStyle::PM_IndicatorHeight)); | ||
912 | } | 934 | } | ||
913 | size = qApp->style()->sizeFromContents(QStyle::CT_GroupBox, m_styleoption, QSize(qMax(baseWidth, m_contentWidth), baseHeight)); | 935 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_GroupBox, m_styleoption, QSize(qMax(baseWidth, m_contentWidth), baseHeight)); | ||
914 | } | 936 | } | ||
915 | break; | 937 | break; | ||
916 | case Header: | 938 | case Header: | ||
917 | size = qApp->style()->sizeFromContents(QStyle::CT_HeaderSection, m_styleoption, QSize(width,height)); | 939 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_HeaderSection, m_styleoption, QSize(width,height)); | ||
918 | break; | 940 | break; | ||
919 | case ItemRow: | 941 | case ItemRow: | ||
920 | case Item: //fall through | 942 | case Item: //fall through | ||
921 | size = qApp->style()->sizeFromContents(QStyle::CT_ItemViewItem, m_styleoption, QSize(width,height)); | 943 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_ItemViewItem, m_styleoption, QSize(width,height)); | ||
922 | break; | 944 | break; | ||
923 | case MenuBarItem: | 945 | case MenuBarItem: | ||
924 | size = qApp->style()->sizeFromContents(QStyle::CT_MenuBarItem, m_styleoption, QSize(width,height)); | 946 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_MenuBarItem, m_styleoption, QSize(width,height)); | ||
925 | break; | 947 | break; | ||
926 | case MenuBar: | 948 | case MenuBar: | ||
927 | size = qApp->style()->sizeFromContents(QStyle::CT_MenuBar, m_styleoption, QSize(width,height)); | 949 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_MenuBar, m_styleoption, QSize(width,height)); | ||
928 | break; | 950 | break; | ||
929 | case Menu: | 951 | case Menu: | ||
930 | size = qApp->style()->sizeFromContents(QStyle::CT_Menu, m_styleoption, QSize(width,height)); | 952 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_Menu, m_styleoption, QSize(width,height)); | ||
931 | break; | 953 | break; | ||
932 | case MenuItem: | 954 | case MenuItem: | ||
933 | case ComboBoxItem: | 955 | case ComboBoxItem: | ||
934 | if (static_cast<QStyleOptionMenuItem *>(m_styleoption)->menuItemType == QStyleOptionMenuItem::Scroller) { | 956 | if (static_cast<QStyleOptionMenuItem *>(m_styleoption)->menuItemType == QStyleOptionMenuItem::Scroller) { | ||
935 | size.setHeight(qMax(QApplication::globalStrut().height(), | 957 | size.setHeight(qMax(QApplication::globalStrut().height(), | ||
936 | qApp->style()->pixelMetric(QStyle::PM_MenuScrollerHeight, nullptr, nullptr))); | 958 | KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuScrollerHeight, nullptr, nullptr))); | ||
937 | } else { | 959 | } else { | ||
938 | size = qApp->style()->sizeFromContents(QStyle::CT_MenuItem, m_styleoption, QSize(width,height)); | 960 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_MenuItem, m_styleoption, QSize(width,height)); | ||
939 | } | 961 | } | ||
940 | break; | 962 | break; | ||
941 | default: | 963 | default: | ||
942 | break; | 964 | break; | ||
943 | } | 965 | } | ||
944 | return size.expandedTo(QSize(m_contentWidth, m_contentHeight)); | 966 | return size.expandedTo(QSize(m_contentWidth, m_contentHeight)); | ||
945 | } | 967 | } | ||
946 | 968 | | |||
947 | qreal KQuickStyleItem::baselineOffset() | 969 | qreal KQuickStyleItem::baselineOffset() | ||
948 | { | 970 | { | ||
949 | QRect r; | 971 | QRect r; | ||
950 | bool ceilResult = true; // By default baseline offset rounding is done upwards | 972 | bool ceilResult = true; // By default baseline offset rounding is done upwards | ||
951 | switch (m_itemType) { | 973 | switch (m_itemType) { | ||
952 | case RadioButton: | 974 | case RadioButton: | ||
953 | r = qApp->style()->subElementRect(QStyle::SE_RadioButtonContents, m_styleoption); | 975 | r = KQuickStyleItem::style()->subElementRect(QStyle::SE_RadioButtonContents, m_styleoption); | ||
954 | break; | 976 | break; | ||
955 | case Button: | 977 | case Button: | ||
956 | r = qApp->style()->subElementRect(QStyle::SE_PushButtonContents, m_styleoption); | 978 | r = KQuickStyleItem::style()->subElementRect(QStyle::SE_PushButtonContents, m_styleoption); | ||
957 | break; | 979 | break; | ||
958 | case CheckBox: | 980 | case CheckBox: | ||
959 | r = qApp->style()->subElementRect(QStyle::SE_CheckBoxContents, m_styleoption); | 981 | r = KQuickStyleItem::style()->subElementRect(QStyle::SE_CheckBoxContents, m_styleoption); | ||
960 | break; | 982 | break; | ||
961 | case Edit: | 983 | case Edit: | ||
962 | r = qApp->style()->subElementRect(QStyle::SE_LineEditContents, m_styleoption); | 984 | r = KQuickStyleItem::style()->subElementRect(QStyle::SE_LineEditContents, m_styleoption); | ||
963 | break; | 985 | break; | ||
964 | case ComboBox: | 986 | case ComboBox: | ||
965 | if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(m_styleoption)) { | 987 | if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(m_styleoption)) { | ||
966 | r = qApp->style()->subControlRect(QStyle::CC_ComboBox, combo, QStyle::SC_ComboBoxEditField); | 988 | r = KQuickStyleItem::style()->subControlRect(QStyle::CC_ComboBox, combo, QStyle::SC_ComboBoxEditField); | ||
967 | if (style() != QLatin1String("mac")) | 989 | if (styleName() != QLatin1String("mac")) | ||
968 | r.adjust(0,0,0,1); | 990 | r.adjust(0,0,0,1); | ||
969 | } | 991 | } | ||
970 | break; | 992 | break; | ||
971 | case SpinBox: | 993 | case SpinBox: | ||
972 | if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(m_styleoption)) { | 994 | if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(m_styleoption)) { | ||
973 | r = qApp->style()->subControlRect(QStyle::CC_SpinBox, spinbox, QStyle::SC_SpinBoxEditField); | 995 | r = KQuickStyleItem::style()->subControlRect(QStyle::CC_SpinBox, spinbox, QStyle::SC_SpinBoxEditField); | ||
974 | ceilResult = false; | 996 | ceilResult = false; | ||
975 | } | 997 | } | ||
976 | break; | 998 | break; | ||
977 | default: | 999 | default: | ||
978 | break; | 1000 | break; | ||
979 | } | 1001 | } | ||
980 | if (r.height() > 0) { | 1002 | if (r.height() > 0) { | ||
981 | const QFontMetrics &fm = m_styleoption->fontMetrics; | 1003 | const QFontMetrics &fm = m_styleoption->fontMetrics; | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 1044 | { | |||
1023 | initStyleOption(); | 1045 | initStyleOption(); | ||
1024 | m_styleoption->rect.setWidth(width()); | 1046 | m_styleoption->rect.setWidth(width()); | ||
1025 | m_styleoption->rect.setHeight(height()); | 1047 | m_styleoption->rect.setHeight(height()); | ||
1026 | } | 1048 | } | ||
1027 | 1049 | | |||
1028 | int KQuickStyleItem::pixelMetric(const QString &metric) | 1050 | int KQuickStyleItem::pixelMetric(const QString &metric) | ||
1029 | { | 1051 | { | ||
1030 | if (metric == QLatin1String("scrollbarExtent")) | 1052 | if (metric == QLatin1String("scrollbarExtent")) | ||
1031 | return qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent, nullptr); | 1053 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_ScrollBarExtent, nullptr); | ||
1032 | else if (metric == QLatin1String("defaultframewidth")) | 1054 | else if (metric == QLatin1String("defaultframewidth")) | ||
1033 | return qApp->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, m_styleoption); | 1055 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_DefaultFrameWidth, m_styleoption); | ||
1034 | else if (metric == QLatin1String("taboverlap")) | 1056 | else if (metric == QLatin1String("taboverlap")) | ||
1035 | return qApp->style()->pixelMetric(QStyle::PM_TabBarTabOverlap, nullptr); | 1057 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TabBarTabOverlap, nullptr); | ||
1036 | else if (metric == QLatin1String("tabbaseoverlap")) | 1058 | else if (metric == QLatin1String("tabbaseoverlap")) | ||
1037 | return qApp->style()->pixelMetric(QStyle::PM_TabBarBaseOverlap, m_styleoption); | 1059 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TabBarBaseOverlap, m_styleoption); | ||
1038 | else if (metric == QLatin1String("tabhspace")) | 1060 | else if (metric == QLatin1String("tabhspace")) | ||
1039 | return qApp->style()->pixelMetric(QStyle::PM_TabBarTabHSpace, nullptr); | 1061 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TabBarTabHSpace, nullptr); | ||
1040 | else if (metric == QLatin1String("indicatorwidth")) | 1062 | else if (metric == QLatin1String("indicatorwidth")) | ||
1041 | return qApp->style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, nullptr); | 1063 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, nullptr); | ||
1042 | else if (metric == QLatin1String("tabvspace")) | 1064 | else if (metric == QLatin1String("tabvspace")) | ||
1043 | return qApp->style()->pixelMetric(QStyle::PM_TabBarTabVSpace, nullptr); | 1065 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TabBarTabVSpace, nullptr); | ||
1044 | else if (metric == QLatin1String("tabbaseheight")) | 1066 | else if (metric == QLatin1String("tabbaseheight")) | ||
1045 | return qApp->style()->pixelMetric(QStyle::PM_TabBarBaseHeight, nullptr); | 1067 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TabBarBaseHeight, nullptr); | ||
1046 | else if (metric == QLatin1String("tabvshift")) | 1068 | else if (metric == QLatin1String("tabvshift")) | ||
1047 | return qApp->style()->pixelMetric(QStyle::PM_TabBarTabShiftVertical, nullptr); | 1069 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TabBarTabShiftVertical, nullptr); | ||
1048 | else if (metric == QLatin1String("menubarhmargin")) | 1070 | else if (metric == QLatin1String("menubarhmargin")) | ||
1049 | return qApp->style()->pixelMetric(QStyle::PM_MenuBarHMargin, nullptr); | 1071 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuBarHMargin, nullptr); | ||
1050 | else if (metric == QLatin1String("menubarvmargin")) | 1072 | else if (metric == QLatin1String("menubarvmargin")) | ||
1051 | return qApp->style()->pixelMetric(QStyle::PM_MenuBarVMargin, nullptr); | 1073 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuBarVMargin, nullptr); | ||
1052 | else if (metric == QLatin1String("menubarpanelwidth")) | 1074 | else if (metric == QLatin1String("menubarpanelwidth")) | ||
1053 | return qApp->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, nullptr); | 1075 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, nullptr); | ||
1054 | else if (metric == QLatin1String("menubaritemspacing")) | 1076 | else if (metric == QLatin1String("menubaritemspacing")) | ||
1055 | return qApp->style()->pixelMetric(QStyle::PM_MenuBarItemSpacing, nullptr); | 1077 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuBarItemSpacing, nullptr); | ||
1056 | else if (metric == QLatin1String("spacebelowmenubar")) | 1078 | else if (metric == QLatin1String("spacebelowmenubar")) | ||
1057 | return qApp->style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, m_styleoption); | 1079 | return KQuickStyleItem::style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, m_styleoption); | ||
1058 | else if (metric == QLatin1String("menuhmargin")) | 1080 | else if (metric == QLatin1String("menuhmargin")) | ||
1059 | return qApp->style()->pixelMetric(QStyle::PM_MenuHMargin, nullptr); | 1081 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuHMargin, nullptr); | ||
1060 | else if (metric == QLatin1String("menuvmargin")) | 1082 | else if (metric == QLatin1String("menuvmargin")) | ||
1061 | return qApp->style()->pixelMetric(QStyle::PM_MenuVMargin, nullptr); | 1083 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuVMargin, nullptr); | ||
1062 | else if (metric == QLatin1String("menupanelwidth")) | 1084 | else if (metric == QLatin1String("menupanelwidth")) | ||
1063 | return qApp->style()->pixelMetric(QStyle::PM_MenuPanelWidth, nullptr); | 1085 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuPanelWidth, nullptr); | ||
1064 | else if (metric == QLatin1String("submenuoverlap")) | 1086 | else if (metric == QLatin1String("submenuoverlap")) | ||
1065 | return qApp->style()->pixelMetric(QStyle::PM_SubMenuOverlap, nullptr); | 1087 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_SubMenuOverlap, nullptr); | ||
1066 | else if (metric == QLatin1String("splitterwidth")) | 1088 | else if (metric == QLatin1String("splitterwidth")) | ||
1067 | return qApp->style()->pixelMetric(QStyle::PM_SplitterWidth, nullptr); | 1089 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_SplitterWidth, nullptr); | ||
1068 | else if (metric == QLatin1String("scrollbarspacing")) | 1090 | else if (metric == QLatin1String("scrollbarspacing")) | ||
1069 | return abs(qApp->style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarSpacing, nullptr)); | 1091 | return abs(KQuickStyleItem::style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarSpacing, nullptr)); | ||
1070 | else if (metric == QLatin1String("treeviewindentation")) | 1092 | else if (metric == QLatin1String("treeviewindentation")) | ||
1071 | return qApp->style()->pixelMetric(QStyle::PM_TreeViewIndentation, nullptr); | 1093 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TreeViewIndentation, nullptr); | ||
1072 | else if (metric == QLatin1String("layouthorizontalspacing")) | 1094 | else if (metric == QLatin1String("layouthorizontalspacing")) | ||
1073 | return qApp->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing, nullptr); | 1095 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing, nullptr); | ||
1074 | else if (metric == QLatin1String("layoutverticalspacing")) | 1096 | else if (metric == QLatin1String("layoutverticalspacing")) | ||
1075 | return qApp->style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing, nullptr); | 1097 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing, nullptr); | ||
1076 | else if (metric == QLatin1String("layoutleftmargin")) | 1098 | else if (metric == QLatin1String("layoutleftmargin")) | ||
1077 | return qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin, nullptr); | 1099 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_LayoutLeftMargin, nullptr); | ||
1078 | else if (metric == QLatin1String("layouttopmargin")) | 1100 | else if (metric == QLatin1String("layouttopmargin")) | ||
1079 | return qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin, nullptr); | 1101 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_LayoutTopMargin, nullptr); | ||
1080 | else if (metric == QLatin1String("layoutrightmargin")) | 1102 | else if (metric == QLatin1String("layoutrightmargin")) | ||
1081 | return qApp->style()->pixelMetric(QStyle::PM_LayoutRightMargin, nullptr); | 1103 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_LayoutRightMargin, nullptr); | ||
1082 | else if (metric == QLatin1String("layoutbottommargin")) | 1104 | else if (metric == QLatin1String("layoutbottommargin")) | ||
1083 | return qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin, nullptr); | 1105 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_LayoutBottomMargin, nullptr); | ||
1084 | return 0; | 1106 | return 0; | ||
1085 | } | 1107 | } | ||
1086 | 1108 | | |||
1087 | QVariant KQuickStyleItem::styleHint(const QString &metric) | 1109 | QVariant KQuickStyleItem::styleHint(const QString &metric) | ||
1088 | { | 1110 | { | ||
1089 | initStyleOption(); | 1111 | initStyleOption(); | ||
1090 | if (metric == QLatin1String("comboboxpopup")) { | 1112 | if (metric == QLatin1String("comboboxpopup")) { | ||
1091 | return qApp->style()->styleHint(QStyle::SH_ComboBox_Popup, m_styleoption); | 1113 | return KQuickStyleItem::style()->styleHint(QStyle::SH_ComboBox_Popup, m_styleoption); | ||
1092 | } else if (metric == QLatin1String("highlightedTextColor")) { | 1114 | } else if (metric == QLatin1String("highlightedTextColor")) { | ||
1093 | return m_styleoption->palette.highlightedText().color().name(); | 1115 | return m_styleoption->palette.highlightedText().color().name(); | ||
1094 | } else if (metric == QLatin1String("textColor")) { | 1116 | } else if (metric == QLatin1String("textColor")) { | ||
1095 | QPalette pal = m_styleoption->palette; | 1117 | QPalette pal = m_styleoption->palette; | ||
1096 | pal.setCurrentColorGroup(active()? QPalette::Active : QPalette::Inactive); | 1118 | pal.setCurrentColorGroup(active()? QPalette::Active : QPalette::Inactive); | ||
1097 | return pal.text().color().name(); | 1119 | return pal.text().color().name(); | ||
1098 | } else if (metric == QLatin1String("focuswidget")) { | 1120 | } else if (metric == QLatin1String("focuswidget")) { | ||
1099 | return qApp->style()->styleHint(QStyle::SH_FocusFrame_AboveWidget); | 1121 | return KQuickStyleItem::style()->styleHint(QStyle::SH_FocusFrame_AboveWidget); | ||
1100 | } else if (metric == QLatin1String("tabbaralignment")) { | 1122 | } else if (metric == QLatin1String("tabbaralignment")) { | ||
1101 | int result = qApp->style()->styleHint(QStyle::SH_TabBar_Alignment); | 1123 | int result = KQuickStyleItem::style()->styleHint(QStyle::SH_TabBar_Alignment); | ||
1102 | if (result == Qt::AlignCenter) | 1124 | if (result == Qt::AlignCenter) | ||
1103 | return QStringLiteral("center"); | 1125 | return QStringLiteral("center"); | ||
1104 | return QStringLiteral("left"); | 1126 | return QStringLiteral("left"); | ||
1105 | } else if (metric == QLatin1String("externalScrollBars")) { | 1127 | } else if (metric == QLatin1String("externalScrollBars")) { | ||
1106 | return qApp->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents); | 1128 | return KQuickStyleItem::style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents); | ||
1107 | } else if (metric == QLatin1String("scrollToClickPosition")) | 1129 | } else if (metric == QLatin1String("scrollToClickPosition")) | ||
1108 | return qApp->style()->styleHint(QStyle::SH_ScrollBar_LeftClickAbsolutePosition); | 1130 | return KQuickStyleItem::style()->styleHint(QStyle::SH_ScrollBar_LeftClickAbsolutePosition); | ||
1109 | else if (metric == QLatin1String("activateItemOnSingleClick")) | 1131 | else if (metric == QLatin1String("activateItemOnSingleClick")) | ||
1110 | return qApp->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick); | 1132 | return KQuickStyleItem::style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick); | ||
1111 | else if (metric == QLatin1String("submenupopupdelay")) | 1133 | else if (metric == QLatin1String("submenupopupdelay")) | ||
1112 | return qApp->style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, m_styleoption); | 1134 | return KQuickStyleItem::style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, m_styleoption); | ||
1113 | else if (metric == QLatin1String("wheelScrollLines")) | 1135 | else if (metric == QLatin1String("wheelScrollLines")) | ||
1114 | return qApp->wheelScrollLines(); | 1136 | return qApp->wheelScrollLines(); | ||
1115 | return 0; | 1137 | return 0; | ||
1116 | 1138 | | |||
1117 | // Add SH_Menu_SpaceActivatesItem | 1139 | // Add SH_Menu_SpaceActivatesItem | ||
1118 | } | 1140 | } | ||
1119 | 1141 | | |||
1120 | void KQuickStyleItem::setHints(const QVariantMap &str) | 1142 | void KQuickStyleItem::setHints(const QVariantMap &str) | ||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Line(s) | 1259 | { | |||
1238 | QStyle::ComplexControl control = QStyle::CC_SpinBox; | 1260 | QStyle::ComplexControl control = QStyle::CC_SpinBox; | ||
1239 | if (subcontrolString == QLatin1String("down")) | 1261 | if (subcontrolString == QLatin1String("down")) | ||
1240 | subcontrol = QStyle::SC_SpinBoxDown; | 1262 | subcontrol = QStyle::SC_SpinBoxDown; | ||
1241 | else if (subcontrolString == QLatin1String("up")) | 1263 | else if (subcontrolString == QLatin1String("up")) | ||
1242 | subcontrol = QStyle::SC_SpinBoxUp; | 1264 | subcontrol = QStyle::SC_SpinBoxUp; | ||
1243 | else if (subcontrolString == QLatin1String("edit")){ | 1265 | else if (subcontrolString == QLatin1String("edit")){ | ||
1244 | subcontrol = QStyle::SC_SpinBoxEditField; | 1266 | subcontrol = QStyle::SC_SpinBoxEditField; | ||
1245 | } | 1267 | } | ||
1246 | return qApp->style()->subControlRect(control, | 1268 | return KQuickStyleItem::style()->subControlRect(control, | ||
1247 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 1269 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
1248 | subcontrol); | 1270 | subcontrol); | ||
1249 | 1271 | | |||
1250 | } | 1272 | } | ||
1251 | break; | 1273 | break; | ||
1252 | case Slider: | 1274 | case Slider: | ||
1253 | { | 1275 | { | ||
1254 | QStyle::ComplexControl control = QStyle::CC_Slider; | 1276 | QStyle::ComplexControl control = QStyle::CC_Slider; | ||
1255 | if (subcontrolString == QLatin1String("handle")) | 1277 | if (subcontrolString == QLatin1String("handle")) | ||
1256 | subcontrol = QStyle::SC_SliderHandle; | 1278 | subcontrol = QStyle::SC_SliderHandle; | ||
1257 | else if (subcontrolString == QLatin1String("groove")) | 1279 | else if (subcontrolString == QLatin1String("groove")) | ||
1258 | subcontrol = QStyle::SC_SliderGroove; | 1280 | subcontrol = QStyle::SC_SliderGroove; | ||
1259 | return qApp->style()->subControlRect(control, | 1281 | return KQuickStyleItem::style()->subControlRect(control, | ||
1260 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 1282 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
1261 | subcontrol); | 1283 | subcontrol); | ||
1262 | 1284 | | |||
1263 | } | 1285 | } | ||
1264 | break; | 1286 | break; | ||
1265 | case ScrollBar: | 1287 | case ScrollBar: | ||
1266 | { | 1288 | { | ||
1267 | QStyle::ComplexControl control = QStyle::CC_ScrollBar; | 1289 | QStyle::ComplexControl control = QStyle::CC_ScrollBar; | ||
1268 | if (subcontrolString == QLatin1String("slider")) | 1290 | if (subcontrolString == QLatin1String("slider")) | ||
1269 | subcontrol = QStyle::SC_ScrollBarSlider; | 1291 | subcontrol = QStyle::SC_ScrollBarSlider; | ||
1270 | if (subcontrolString == QLatin1String("groove")) | 1292 | if (subcontrolString == QLatin1String("groove")) | ||
1271 | subcontrol = QStyle::SC_ScrollBarGroove; | 1293 | subcontrol = QStyle::SC_ScrollBarGroove; | ||
1272 | else if (subcontrolString == QLatin1String("handle")) | 1294 | else if (subcontrolString == QLatin1String("handle")) | ||
1273 | subcontrol = QStyle::SC_ScrollBarSlider; | 1295 | subcontrol = QStyle::SC_ScrollBarSlider; | ||
1274 | else if (subcontrolString == QLatin1String("add")) | 1296 | else if (subcontrolString == QLatin1String("add")) | ||
1275 | subcontrol = QStyle::SC_ScrollBarAddPage; | 1297 | subcontrol = QStyle::SC_ScrollBarAddPage; | ||
1276 | else if (subcontrolString == QLatin1String("sub")) | 1298 | else if (subcontrolString == QLatin1String("sub")) | ||
1277 | subcontrol = QStyle::SC_ScrollBarSubPage; | 1299 | subcontrol = QStyle::SC_ScrollBarSubPage; | ||
1278 | return qApp->style()->subControlRect(control, | 1300 | return KQuickStyleItem::style()->subControlRect(control, | ||
1279 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 1301 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
1280 | subcontrol); | 1302 | subcontrol); | ||
1281 | } | 1303 | } | ||
1282 | break; | 1304 | break; | ||
1283 | case ItemBranchIndicator: { | 1305 | case ItemBranchIndicator: { | ||
1284 | QStyleOption opt; | 1306 | QStyleOption opt; | ||
1285 | opt.rect = QRect(0, 0, implicitWidth(), implicitHeight()); | 1307 | opt.rect = QRect(0, 0, implicitWidth(), implicitHeight()); | ||
1286 | return qApp->style()->subElementRect(QStyle::SE_TreeViewDisclosureItem, &opt, nullptr); | 1308 | return KQuickStyleItem::style()->subElementRect(QStyle::SE_TreeViewDisclosureItem, &opt, nullptr); | ||
1287 | } | 1309 | } | ||
1288 | default: | 1310 | default: | ||
1289 | break; | 1311 | break; | ||
1290 | } | 1312 | } | ||
1291 | return QRectF(); | 1313 | return QRectF(); | ||
1292 | } | 1314 | } | ||
1293 | 1315 | | |||
1294 | namespace { | 1316 | namespace { | ||
Show All 35 Lines | 1339 | { | |||
1330 | 1352 | | |||
1331 | // Set AA_UseHighDpiPixmaps when calling style code to make QIcon return | 1353 | // Set AA_UseHighDpiPixmaps when calling style code to make QIcon return | ||
1332 | // "retina" pixmaps. The flag is controlled by the application so we can't | 1354 | // "retina" pixmaps. The flag is controlled by the application so we can't | ||
1333 | // set it unconditinally. | 1355 | // set it unconditinally. | ||
1334 | QHighDpiPixmapsEnabler1 enabler; | 1356 | QHighDpiPixmapsEnabler1 enabler; | ||
1335 | 1357 | | |||
1336 | switch (m_itemType) { | 1358 | switch (m_itemType) { | ||
1337 | case Button: | 1359 | case Button: | ||
1338 | qApp->style()->drawControl(QStyle::CE_PushButton, m_styleoption, painter); | 1360 | KQuickStyleItem::style()->drawControl(QStyle::CE_PushButton, m_styleoption, painter); | ||
1339 | break; | 1361 | break; | ||
1340 | case ItemRow :{ | 1362 | case ItemRow :{ | ||
1341 | QPixmap pixmap; | 1363 | QPixmap pixmap; | ||
1342 | // Only draw through style once | 1364 | // Only draw through style once | ||
1343 | const QString pmKey = QLatin1Literal("itemrow") % QString::number(m_styleoption->state,16) % activeControl(); | 1365 | const QString pmKey = QLatin1Literal("itemrow") % QString::number(m_styleoption->state,16) % activeControl(); | ||
1344 | if (!QPixmapCache::find(pmKey, pixmap) || pixmap.width() < width() || height() != pixmap.height()) { | 1366 | if (!QPixmapCache::find(pmKey, pixmap) || pixmap.width() < width() || height() != pixmap.height()) { | ||
1345 | int newSize = width(); | 1367 | int newSize = width(); | ||
1346 | pixmap = QPixmap(newSize, height()); | 1368 | pixmap = QPixmap(newSize, height()); | ||
1347 | pixmap.fill(Qt::transparent); | 1369 | pixmap.fill(Qt::transparent); | ||
1348 | QPainter pixpainter(&pixmap); | 1370 | QPainter pixpainter(&pixmap); | ||
1349 | qApp->style()->drawPrimitive(QStyle::PE_PanelItemViewRow, m_styleoption, &pixpainter); | 1371 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_PanelItemViewRow, m_styleoption, &pixpainter); | ||
1350 | if ((style() == QLatin1String("mac") || !qApp->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected)) && selected()) { | 1372 | if ((styleName() == QLatin1String("mac") || !KQuickStyleItem::style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected)) && selected()) { | ||
1351 | QPalette pal = QApplication::palette("QAbstractItemView"); | 1373 | QPalette pal = QApplication::palette("QAbstractItemView"); | ||
1352 | pal.setCurrentColorGroup(m_styleoption->palette.currentColorGroup()); | 1374 | pal.setCurrentColorGroup(m_styleoption->palette.currentColorGroup()); | ||
1353 | pixpainter.fillRect(m_styleoption->rect, pal.highlight()); | 1375 | pixpainter.fillRect(m_styleoption->rect, pal.highlight()); | ||
1354 | } | 1376 | } | ||
1355 | QPixmapCache::insert(pmKey, pixmap); | 1377 | QPixmapCache::insert(pmKey, pixmap); | ||
1356 | } | 1378 | } | ||
1357 | painter->drawPixmap(0, 0, pixmap); | 1379 | painter->drawPixmap(0, 0, pixmap); | ||
1358 | } | 1380 | } | ||
1359 | break; | 1381 | break; | ||
1360 | case Item: | 1382 | case Item: | ||
1361 | qApp->style()->drawControl(QStyle::CE_ItemViewItem, m_styleoption, painter); | 1383 | KQuickStyleItem::style()->drawControl(QStyle::CE_ItemViewItem, m_styleoption, painter); | ||
1362 | break; | 1384 | break; | ||
1363 | case ItemBranchIndicator: | 1385 | case ItemBranchIndicator: | ||
1364 | qApp->style()->drawPrimitive(QStyle::PE_IndicatorBranch, m_styleoption, painter); | 1386 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_IndicatorBranch, m_styleoption, painter); | ||
1365 | break; | 1387 | break; | ||
1366 | case Header: | 1388 | case Header: | ||
1367 | qApp->style()->drawControl(QStyle::CE_Header, m_styleoption, painter); | 1389 | KQuickStyleItem::style()->drawControl(QStyle::CE_Header, m_styleoption, painter); | ||
1368 | break; | 1390 | break; | ||
1369 | case ToolButton: | 1391 | case ToolButton: | ||
1370 | qApp->style()->drawComplexControl(QStyle::CC_ToolButton, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); | 1392 | KQuickStyleItem::style()->drawComplexControl(QStyle::CC_ToolButton, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); | ||
1371 | break; | 1393 | break; | ||
1372 | case Tab: | 1394 | case Tab: | ||
1373 | { | 1395 | { | ||
1374 | if (m_lastFocusReason != Qt::TabFocusReason && m_lastFocusReason != Qt::BacktabFocusReason) { | 1396 | if (m_lastFocusReason != Qt::TabFocusReason && m_lastFocusReason != Qt::BacktabFocusReason) { | ||
1375 | m_styleoption->state &= ~QStyle::State_HasFocus; | 1397 | m_styleoption->state &= ~QStyle::State_HasFocus; | ||
1376 | } | 1398 | } | ||
1377 | qApp->style()->drawControl(QStyle::CE_TabBarTab, m_styleoption, painter); | 1399 | KQuickStyleItem::style()->drawControl(QStyle::CE_TabBarTab, m_styleoption, painter); | ||
1378 | } | 1400 | } | ||
1379 | break; | 1401 | break; | ||
1380 | case Frame: | 1402 | case Frame: | ||
1381 | qApp->style()->drawControl(QStyle::CE_ShapedFrame, m_styleoption, painter); | 1403 | KQuickStyleItem::style()->drawControl(QStyle::CE_ShapedFrame, m_styleoption, painter); | ||
1382 | break; | 1404 | break; | ||
1383 | case FocusFrame: | 1405 | case FocusFrame: | ||
1384 | qApp->style()->drawControl(QStyle::CE_FocusFrame, m_styleoption, painter); | 1406 | KQuickStyleItem::style()->drawControl(QStyle::CE_FocusFrame, m_styleoption, painter); | ||
1385 | break; | 1407 | break; | ||
1386 | case FocusRect: | 1408 | case FocusRect: | ||
1387 | qApp->style()->drawPrimitive(QStyle::PE_FrameFocusRect, m_styleoption, painter); | 1409 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_FrameFocusRect, m_styleoption, painter); | ||
1388 | break; | 1410 | break; | ||
1389 | case TabFrame: | 1411 | case TabFrame: | ||
1390 | qApp->style()->drawPrimitive(QStyle::PE_FrameTabWidget, m_styleoption, painter); | 1412 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_FrameTabWidget, m_styleoption, painter); | ||
1391 | break; | 1413 | break; | ||
1392 | case MenuBar: | 1414 | case MenuBar: | ||
1393 | qApp->style()->drawControl(QStyle::CE_MenuBarEmptyArea, m_styleoption, painter); | 1415 | KQuickStyleItem::style()->drawControl(QStyle::CE_MenuBarEmptyArea, m_styleoption, painter); | ||
1394 | break; | 1416 | break; | ||
1395 | case MenuBarItem: | 1417 | case MenuBarItem: | ||
1396 | qApp->style()->drawControl(QStyle::CE_MenuBarItem, m_styleoption, painter); | 1418 | KQuickStyleItem::style()->drawControl(QStyle::CE_MenuBarItem, m_styleoption, painter); | ||
1397 | break; | 1419 | break; | ||
1398 | case MenuItem: | 1420 | case MenuItem: | ||
1399 | case ComboBoxItem: { // fall through | 1421 | case ComboBoxItem: { // fall through | ||
1400 | QStyle::ControlElement menuElement = | 1422 | QStyle::ControlElement menuElement = | ||
1401 | static_cast<QStyleOptionMenuItem *>(m_styleoption)->menuItemType == QStyleOptionMenuItem::Scroller ? | 1423 | static_cast<QStyleOptionMenuItem *>(m_styleoption)->menuItemType == QStyleOptionMenuItem::Scroller ? | ||
1402 | QStyle::CE_MenuScroller : QStyle::CE_MenuItem; | 1424 | QStyle::CE_MenuScroller : QStyle::CE_MenuItem; | ||
1403 | qApp->style()->drawControl(menuElement, m_styleoption, painter); | 1425 | KQuickStyleItem::style()->drawControl(menuElement, m_styleoption, painter); | ||
1404 | } | 1426 | } | ||
1405 | break; | 1427 | break; | ||
1406 | case CheckBox: | 1428 | case CheckBox: | ||
1407 | qApp->style()->drawControl(QStyle::CE_CheckBox, m_styleoption, painter); | 1429 | KQuickStyleItem::style()->drawControl(QStyle::CE_CheckBox, m_styleoption, painter); | ||
1408 | break; | 1430 | break; | ||
1409 | case RadioButton: | 1431 | case RadioButton: | ||
1410 | qApp->style()->drawControl(QStyle::CE_RadioButton, m_styleoption, painter); | 1432 | KQuickStyleItem::style()->drawControl(QStyle::CE_RadioButton, m_styleoption, painter); | ||
1411 | break; | 1433 | break; | ||
1412 | case Edit: { | 1434 | case Edit: { | ||
1413 | qApp->style()->drawPrimitive(QStyle::PE_PanelLineEdit, m_styleoption, painter); | 1435 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_PanelLineEdit, m_styleoption, painter); | ||
1414 | } | 1436 | } | ||
1415 | break; | 1437 | break; | ||
1416 | case MacHelpButton: | 1438 | case MacHelpButton: | ||
1417 | //Not managed as mac is not supported | 1439 | //Not managed as mac is not supported | ||
1418 | break; | 1440 | break; | ||
1419 | case Widget: | 1441 | case Widget: | ||
1420 | qApp->style()->drawPrimitive(QStyle::PE_Widget, m_styleoption, painter); | 1442 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_Widget, m_styleoption, painter); | ||
1421 | break; | 1443 | break; | ||
1422 | case ScrollAreaCorner: | 1444 | case ScrollAreaCorner: | ||
1423 | qApp->style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, m_styleoption, painter); | 1445 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, m_styleoption, painter); | ||
1424 | break; | 1446 | break; | ||
1425 | case Splitter: | 1447 | case Splitter: | ||
1426 | if (m_styleoption->rect.width() == 1) | 1448 | if (m_styleoption->rect.width() == 1) | ||
1427 | painter->fillRect(0, 0, width(), height(), m_styleoption->palette.dark().color()); | 1449 | painter->fillRect(0, 0, width(), height(), m_styleoption->palette.dark().color()); | ||
1428 | else | 1450 | else | ||
1429 | qApp->style()->drawControl(QStyle::CE_Splitter, m_styleoption, painter); | 1451 | KQuickStyleItem::style()->drawControl(QStyle::CE_Splitter, m_styleoption, painter); | ||
1430 | break; | 1452 | break; | ||
1431 | case ComboBox: | 1453 | case ComboBox: | ||
1432 | { | 1454 | { | ||
1433 | qApp->style()->drawComplexControl(QStyle::CC_ComboBox, | 1455 | KQuickStyleItem::style()->drawComplexControl(QStyle::CC_ComboBox, | ||
1434 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 1456 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
1435 | painter); | 1457 | painter); | ||
1436 | // This is needed on mac as it will use the painter color and ignore the palette | 1458 | // This is needed on mac as it will use the painter color and ignore the palette | ||
1437 | QPen pen = painter->pen(); | 1459 | QPen pen = painter->pen(); | ||
1438 | painter->setPen(m_styleoption->palette.text().color()); | 1460 | painter->setPen(m_styleoption->palette.text().color()); | ||
1439 | qApp->style()->drawControl(QStyle::CE_ComboBoxLabel, m_styleoption, painter); | 1461 | KQuickStyleItem::style()->drawControl(QStyle::CE_ComboBoxLabel, m_styleoption, painter); | ||
1440 | painter->setPen(pen); | 1462 | painter->setPen(pen); | ||
1441 | } break; | 1463 | } break; | ||
1442 | case SpinBox: | 1464 | case SpinBox: | ||
1443 | #ifdef Q_OS_MAC | 1465 | #ifdef Q_OS_MAC | ||
1444 | // macstyle depends on the embedded qlineedit to fill the editfield background | 1466 | // macstyle depends on the embedded qlineedit to fill the editfield background | ||
1445 | if (style() == QLatin1String("mac")) { | 1467 | if (styleName() == QLatin1String("mac")) { | ||
1446 | QRect editRect = qApp->style()->subControlRect(QStyle::CC_SpinBox, | 1468 | QRect editRect = KQuickStyleItem::style()->subControlRect(QStyle::CC_SpinBox, | ||
1447 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 1469 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
1448 | QStyle::SC_SpinBoxEditField); | 1470 | QStyle::SC_SpinBoxEditField); | ||
1449 | painter->fillRect(editRect.adjusted(-1, -1, 1, 1), m_styleoption->palette.base()); | 1471 | painter->fillRect(editRect.adjusted(-1, -1, 1, 1), m_styleoption->palette.base()); | ||
1450 | } | 1472 | } | ||
1451 | #endif | 1473 | #endif | ||
1452 | qApp->style()->drawComplexControl(QStyle::CC_SpinBox, | 1474 | KQuickStyleItem::style()->drawComplexControl(QStyle::CC_SpinBox, | ||
1453 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 1475 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
1454 | painter); | 1476 | painter); | ||
1455 | break; | 1477 | break; | ||
1456 | case Slider: | 1478 | case Slider: | ||
1457 | qApp->style()->drawComplexControl(QStyle::CC_Slider, | 1479 | KQuickStyleItem::style()->drawComplexControl(QStyle::CC_Slider, | ||
1458 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 1480 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
1459 | painter); | 1481 | painter); | ||
1460 | break; | 1482 | break; | ||
1461 | case Dial: | 1483 | case Dial: | ||
1462 | qApp->style()->drawComplexControl(QStyle::CC_Dial, | 1484 | KQuickStyleItem::style()->drawComplexControl(QStyle::CC_Dial, | ||
1463 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 1485 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
1464 | painter); | 1486 | painter); | ||
1465 | break; | 1487 | break; | ||
1466 | case ProgressBar: | 1488 | case ProgressBar: | ||
1467 | qApp->style()->drawControl(QStyle::CE_ProgressBar, m_styleoption, painter); | 1489 | KQuickStyleItem::style()->drawControl(QStyle::CE_ProgressBar, m_styleoption, painter); | ||
1468 | break; | 1490 | break; | ||
1469 | case ToolBar: | 1491 | case ToolBar: | ||
1470 | painter->fillRect(m_styleoption->rect, m_styleoption->palette.window().color()); | 1492 | painter->fillRect(m_styleoption->rect, m_styleoption->palette.window().color()); | ||
1471 | qApp->style()->drawControl(QStyle::CE_ToolBar, m_styleoption, painter); | 1493 | KQuickStyleItem::style()->drawControl(QStyle::CE_ToolBar, m_styleoption, painter); | ||
1472 | painter->save(); | 1494 | painter->save(); | ||
1473 | painter->setPen(style() != QLatin1String("fusion") ? m_styleoption->palette.dark().color().darker(120) : | 1495 | painter->setPen(styleName() != QLatin1String("fusion") ? m_styleoption->palette.dark().color().darker(120) : | ||
1474 | m_styleoption->palette.window().color().lighter(107)); | 1496 | m_styleoption->palette.window().color().lighter(107)); | ||
1475 | painter->drawLine(m_styleoption->rect.bottomLeft(), m_styleoption->rect.bottomRight()); | 1497 | painter->drawLine(m_styleoption->rect.bottomLeft(), m_styleoption->rect.bottomRight()); | ||
1476 | painter->restore(); | 1498 | painter->restore(); | ||
1477 | break; | 1499 | break; | ||
1478 | case StatusBar: | 1500 | case StatusBar: | ||
1479 | { | 1501 | { | ||
1480 | painter->fillRect(m_styleoption->rect, m_styleoption->palette.window().color()); | 1502 | painter->fillRect(m_styleoption->rect, m_styleoption->palette.window().color()); | ||
1481 | painter->setPen(m_styleoption->palette.dark().color().darker(120)); | 1503 | painter->setPen(m_styleoption->palette.dark().color().darker(120)); | ||
1482 | painter->drawLine(m_styleoption->rect.topLeft(), m_styleoption->rect.topRight()); | 1504 | painter->drawLine(m_styleoption->rect.topLeft(), m_styleoption->rect.topRight()); | ||
1483 | qApp->style()->drawPrimitive(QStyle::PE_PanelStatusBar, m_styleoption, painter); | 1505 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_PanelStatusBar, m_styleoption, painter); | ||
1484 | } | 1506 | } | ||
1485 | break; | 1507 | break; | ||
1486 | case GroupBox: | 1508 | case GroupBox: | ||
1487 | qApp->style()->drawComplexControl(QStyle::CC_GroupBox, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); | 1509 | KQuickStyleItem::style()->drawComplexControl(QStyle::CC_GroupBox, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); | ||
1488 | break; | 1510 | break; | ||
1489 | case ScrollBar: | 1511 | case ScrollBar: | ||
1490 | qApp->style()->drawComplexControl(QStyle::CC_ScrollBar, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); | 1512 | KQuickStyleItem::style()->drawComplexControl(QStyle::CC_ScrollBar, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); | ||
1491 | break; | 1513 | break; | ||
1492 | case Menu: { | 1514 | case Menu: { | ||
1493 | QStyleHintReturnMask val; | 1515 | QStyleHintReturnMask val; | ||
1494 | qApp->style()->styleHint(QStyle::SH_Menu_Mask, m_styleoption, nullptr, &val); | 1516 | KQuickStyleItem::style()->styleHint(QStyle::SH_Menu_Mask, m_styleoption, nullptr, &val); | ||
1495 | painter->save(); | 1517 | painter->save(); | ||
1496 | painter->setClipRegion(val.region); | 1518 | painter->setClipRegion(val.region); | ||
1497 | painter->fillRect(m_styleoption->rect, m_styleoption->palette.window()); | 1519 | painter->fillRect(m_styleoption->rect, m_styleoption->palette.window()); | ||
1498 | painter->restore(); | 1520 | painter->restore(); | ||
1499 | qApp->style()->drawPrimitive(QStyle::PE_PanelMenu, m_styleoption, painter); | 1521 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_PanelMenu, m_styleoption, painter); | ||
1500 | 1522 | | |||
1501 | if (int fw = qApp->style()->pixelMetric(QStyle::PM_MenuPanelWidth)) { | 1523 | if (int fw = KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuPanelWidth)) { | ||
1502 | QStyleOptionFrame frame; | 1524 | QStyleOptionFrame frame; | ||
1503 | frame.state = QStyle::State_None; | 1525 | frame.state = QStyle::State_None; | ||
1504 | frame.lineWidth = fw; | 1526 | frame.lineWidth = fw; | ||
1505 | frame.midLineWidth = 0; | 1527 | frame.midLineWidth = 0; | ||
1506 | frame.rect = m_styleoption->rect; | 1528 | frame.rect = m_styleoption->rect; | ||
1507 | frame.styleObject = this; | 1529 | frame.styleObject = this; | ||
1508 | frame.palette = m_styleoption->palette; | 1530 | frame.palette = m_styleoption->palette; | ||
1509 | qApp->style()->drawPrimitive(QStyle::PE_FrameMenu, &frame, painter); | 1531 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_FrameMenu, &frame, painter); | ||
1510 | } | 1532 | } | ||
1511 | } | 1533 | } | ||
1512 | break; | 1534 | break; | ||
1513 | default: | 1535 | default: | ||
1514 | break; | 1536 | break; | ||
1515 | } | 1537 | } | ||
1516 | } | 1538 | } | ||
1517 | 1539 | | |||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Line(s) | 1704 | { | |||
1686 | if (size) | 1708 | if (size) | ||
1687 | *size = QSize(width, height); | 1709 | *size = QSize(width, height); | ||
1688 | 1710 | | |||
1689 | QPixmap pixmap(width, height); | 1711 | QPixmap pixmap(width, height); | ||
1690 | 1712 | | |||
1691 | QStyleOptionViewItem opt; | 1713 | QStyleOptionViewItem opt; | ||
1692 | opt.state |= QStyle::State_Enabled; | 1714 | opt.state |= QStyle::State_Enabled; | ||
1693 | opt.rect = QRect(0, 0, width, height); | 1715 | opt.rect = QRect(0, 0, width, height); | ||
1694 | QString style = QString::fromLatin1(qApp->style()->metaObject()->className()); | 1716 | QString style = QString::fromLatin1(KQuickStyleItem::style()->metaObject()->className()); | ||
1695 | opt.features = 0; | 1717 | opt.features = 0; | ||
1696 | 1718 | | |||
1697 | if (id.contains(QLatin1String("selected"))) | 1719 | if (id.contains(QLatin1String("selected"))) | ||
1698 | opt.state |= QStyle::State_Selected; | 1720 | opt.state |= QStyle::State_Selected; | ||
1699 | 1721 | | |||
1700 | if (id.contains(QLatin1String("active"))) { | 1722 | if (id.contains(QLatin1String("active"))) { | ||
1701 | opt.state |= QStyle::State_Active; | 1723 | opt.state |= QStyle::State_Active; | ||
1702 | opt.palette.setCurrentColorGroup(QPalette::Active); | 1724 | opt.palette.setCurrentColorGroup(QPalette::Active); | ||
1703 | } else | 1725 | } else | ||
1704 | opt.palette.setCurrentColorGroup(QPalette::Inactive); | 1726 | opt.palette.setCurrentColorGroup(QPalette::Inactive); | ||
1705 | 1727 | | |||
1706 | if (id.contains(QLatin1String("alternate"))) | 1728 | if (id.contains(QLatin1String("alternate"))) | ||
1707 | opt.features |= QStyleOptionViewItem::Alternate; | 1729 | opt.features |= QStyleOptionViewItem::Alternate; | ||
1708 | 1730 | | |||
1709 | QPalette pal = QApplication::palette("QAbstractItemView"); | 1731 | QPalette pal = QApplication::palette("QAbstractItemView"); | ||
1710 | if (opt.state & QStyle::State_Selected && (style.contains(QLatin1String("Mac")) || | 1732 | if (opt.state & QStyle::State_Selected && (style.contains(QLatin1String("Mac")) || | ||
1711 | !qApp->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected))) { | 1733 | !KQuickStyleItem::style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected))) { | ||
1712 | pal.setCurrentColorGroup(opt.palette.currentColorGroup()); | 1734 | pal.setCurrentColorGroup(opt.palette.currentColorGroup()); | ||
1713 | pixmap.fill(pal.highlight().color()); | 1735 | pixmap.fill(pal.highlight().color()); | ||
1714 | } else { | 1736 | } else { | ||
1715 | pixmap.fill(pal.base().color()); | 1737 | pixmap.fill(pal.base().color()); | ||
1716 | QPainter pixpainter(&pixmap); | 1738 | QPainter pixpainter(&pixmap); | ||
1717 | qApp->style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, &pixpainter); | 1739 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, &pixpainter); | ||
1718 | } | 1740 | } | ||
1719 | return pixmap; | 1741 | return pixmap; | ||
1720 | } | 1742 | } | ||
1721 | 1743 | | |||
1722 | #include "moc_kquickstyleitem_p.cpp" | 1744 | #include "moc_kquickstyleitem_p.cpp" | ||
1723 | #include "moc_kquickpadding_p.cpp" | 1745 | #include "moc_kquickpadding_p.cpp" |