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, SIGNAL(visibleChanged()), this, SLOT(updateItem())); | 107 | connect(this, SIGNAL(visibleChanged()), this, SLOT(updateItem())); | ||
86 | connect(this, SIGNAL(widthChanged()), this, SLOT(updateItem())); | 108 | connect(this, SIGNAL(widthChanged()), this, SLOT(updateItem())); | ||
87 | connect(this, SIGNAL(heightChanged()), this, SLOT(updateItem())); | 109 | connect(this, SIGNAL(heightChanged()), this, SLOT(updateItem())); | ||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | 202 | case Button: { | |||
185 | opt->text = text(); | 207 | opt->text = text(); | ||
186 | 208 | | |||
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 | int e = qApp->style()->pixelMetric(QStyle::PM_ButtonIconSize, m_styleoption, nullptr); | 215 | int e = KQuickStyleItem::style()->pixelMetric(QStyle::PM_ButtonIconSize, m_styleoption, nullptr); | ||
194 | opt->iconSize = QSize(e, e); | 216 | opt->iconSize = QSize(e, e); | ||
195 | opt->features = activeControl() == QLatin1String("default") ? | 217 | opt->features = activeControl() == QLatin1String("default") ? | ||
196 | QStyleOptionButton::DefaultButton : | 218 | QStyleOptionButton::DefaultButton : | ||
197 | QStyleOptionButton::None; | 219 | QStyleOptionButton::None; | ||
198 | const QFont font = qApp->font("QPushButton"); | 220 | const QFont font = qApp->font("QPushButton"); | ||
199 | opt->fontMetrics = QFontMetrics(font); | 221 | opt->fontMetrics = QFontMetrics(font); | ||
200 | QObject * menu = m_properties[QStringLiteral("menu")].value<QObject *>(); | 222 | QObject * menu = m_properties[QStringLiteral("menu")].value<QObject *>(); | ||
201 | if (menu) { | 223 | if (menu) { | ||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | 304 | case ToolButton: { | |||
299 | if (m_properties.value(QStringLiteral("menu")).toBool()) { | 321 | if (m_properties.value(QStringLiteral("menu")).toBool()) { | ||
300 | opt->subControls |= QStyle::SC_ToolButtonMenu; | 322 | opt->subControls |= QStyle::SC_ToolButtonMenu; | ||
301 | opt->features = QStyleOptionToolButton::HasMenu; | 323 | opt->features = QStyleOptionToolButton::HasMenu; | ||
302 | } | 324 | } | ||
303 | 325 | | |||
304 | // For now both text and icon | 326 | // For now both text and icon | ||
305 | opt->toolButtonStyle = Qt::ToolButtonTextBesideIcon; | 327 | opt->toolButtonStyle = Qt::ToolButtonTextBesideIcon; | ||
306 | 328 | | |||
307 | int e = qApp->style()->pixelMetric(QStyle::PM_ToolBarIconSize, m_styleoption, nullptr); | 329 | int e = KQuickStyleItem::style()->pixelMetric(QStyle::PM_ToolBarIconSize, m_styleoption, nullptr); | ||
308 | opt->iconSize = QSize(e, e); | 330 | opt->iconSize = QSize(e, e); | ||
309 | 331 | | |||
310 | const QFont font = qApp->font("QToolButton"); | 332 | const QFont font = qApp->font("QToolButton"); | ||
311 | opt->font = font; | 333 | opt->font = font; | ||
312 | opt->fontMetrics = QFontMetrics(font); | 334 | opt->fontMetrics = QFontMetrics(font); | ||
313 | } | 335 | } | ||
314 | break; | 336 | break; | ||
315 | case ToolBar: { | 337 | case ToolBar: { | ||
▲ Show 20 Lines • Show All 282 Lines • ▼ Show 20 Line(s) | 618 | ? QStyle::SC_ScrollBarSubLine : (activeControl() == QLatin1String("down")) ? | |||
598 | (activeControl() == QLatin1String("handle")) ? | 620 | (activeControl() == QLatin1String("handle")) ? | ||
599 | QStyle::SC_ScrollBarSlider : hover() ? QStyle::SC_ScrollBarGroove : QStyle::SC_None; | 621 | QStyle::SC_ScrollBarSlider : hover() ? QStyle::SC_ScrollBarGroove : QStyle::SC_None; | ||
600 | if (raised()) | 622 | if (raised()) | ||
601 | opt->state |= QStyle::State_On; | 623 | opt->state |= QStyle::State_On; | ||
602 | 624 | | |||
603 | opt->sliderValue = value(); | 625 | opt->sliderValue = value(); | ||
604 | opt->subControls = QStyle::SC_All; | 626 | opt->subControls = QStyle::SC_All; | ||
605 | 627 | | |||
606 | setTransient(qApp->style()->styleHint(QStyle::SH_ScrollBar_Transient, m_styleoption)); | 628 | setTransient(KQuickStyleItem::style()->styleHint(QStyle::SH_ScrollBar_Transient, m_styleoption)); | ||
607 | break; | 629 | break; | ||
608 | } | 630 | } | ||
609 | default: | 631 | default: | ||
610 | break; | 632 | break; | ||
611 | } | 633 | } | ||
612 | 634 | | |||
613 | if (!m_styleoption) | 635 | if (!m_styleoption) | ||
614 | m_styleoption = new QStyleOption(); | 636 | m_styleoption = new QStyleOption(); | ||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Line(s) | |||||
729 | * | 751 | * | ||
730 | * Returns a simplified style name. | 752 | * Returns a simplified style name. | ||
731 | * | 753 | * | ||
732 | * QMacStyle = "mac" | 754 | * QMacStyle = "mac" | ||
733 | * QWindowsXPStyle = "windowsxp" | 755 | * QWindowsXPStyle = "windowsxp" | ||
734 | * QFusionStyle = "fusion" | 756 | * QFusionStyle = "fusion" | ||
735 | */ | 757 | */ | ||
736 | 758 | | |||
737 | QString KQuickStyleItem::style() const | 759 | QString KQuickStyleItem::styleName() const | ||
738 | { | 760 | { | ||
739 | QString style = qApp->style()->metaObject()->className(); | 761 | QString style = KQuickStyleItem::style()->metaObject()->className(); | ||
740 | style = style.toLower(); | 762 | style = style.toLower(); | ||
741 | if (style.startsWith(QLatin1Char('q'))) | 763 | if (style.startsWith(QLatin1Char('q'))) | ||
742 | style = style.right(style.length() - 1); | 764 | style = style.right(style.length() - 1); | ||
743 | if (style.endsWith(QLatin1String("style"))) | 765 | if (style.endsWith(QLatin1String("style"))) | ||
744 | style = style.left(style.length() - 5); | 766 | style = style.left(style.length() - 5); | ||
745 | return style; | 767 | return style; | ||
746 | } | 768 | } | ||
747 | 769 | | |||
748 | QString KQuickStyleItem::hitTest(int px, int py) | 770 | QString KQuickStyleItem::hitTest(int px, int py) | ||
749 | { | 771 | { | ||
750 | QStyle::SubControl subcontrol = QStyle::SC_All; | 772 | QStyle::SubControl subcontrol = QStyle::SC_All; | ||
751 | switch (m_itemType) { | 773 | switch (m_itemType) { | ||
752 | case SpinBox :{ | 774 | case SpinBox :{ | ||
753 | subcontrol = qApp->style()->hitTestComplexControl(QStyle::CC_SpinBox, | 775 | subcontrol = KQuickStyleItem::style()->hitTestComplexControl(QStyle::CC_SpinBox, | ||
754 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 776 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
755 | QPoint(px,py), nullptr); | 777 | QPoint(px,py), nullptr); | ||
756 | if (subcontrol == QStyle::SC_SpinBoxUp) | 778 | if (subcontrol == QStyle::SC_SpinBoxUp) | ||
757 | return QStringLiteral("up"); | 779 | return QStringLiteral("up"); | ||
758 | else if (subcontrol == QStyle::SC_SpinBoxDown) | 780 | else if (subcontrol == QStyle::SC_SpinBoxDown) | ||
759 | return QStringLiteral("down"); | 781 | return QStringLiteral("down"); | ||
760 | } | 782 | } | ||
761 | break; | 783 | break; | ||
762 | 784 | | |||
763 | case Slider: { | 785 | case Slider: { | ||
764 | subcontrol = qApp->style()->hitTestComplexControl(QStyle::CC_Slider, | 786 | subcontrol = KQuickStyleItem::style()->hitTestComplexControl(QStyle::CC_Slider, | ||
765 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 787 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
766 | QPoint(px,py), nullptr); | 788 | QPoint(px,py), nullptr); | ||
767 | if (subcontrol == QStyle::SC_SliderHandle) | 789 | if (subcontrol == QStyle::SC_SliderHandle) | ||
768 | return QStringLiteral("handle"); | 790 | return QStringLiteral("handle"); | ||
769 | } | 791 | } | ||
770 | break; | 792 | break; | ||
771 | 793 | | |||
772 | case ScrollBar: { | 794 | case ScrollBar: { | ||
773 | subcontrol = qApp->style()->hitTestComplexControl(QStyle::CC_ScrollBar, | 795 | subcontrol = KQuickStyleItem::style()->hitTestComplexControl(QStyle::CC_ScrollBar, | ||
774 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 796 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
775 | QPoint(px,py), nullptr); | 797 | QPoint(px,py), nullptr); | ||
776 | switch (subcontrol) { | 798 | switch (subcontrol) { | ||
777 | case QStyle::SC_ScrollBarSlider: | 799 | case QStyle::SC_ScrollBarSlider: | ||
778 | return QStringLiteral("handle"); | 800 | return QStringLiteral("handle"); | ||
779 | 801 | | |||
780 | case QStyle::SC_ScrollBarSubLine: | 802 | case QStyle::SC_ScrollBarSubLine: | ||
781 | return QStringLiteral("up"); | 803 | return QStringLiteral("up"); | ||
Show All 21 Lines | |||||
803 | 825 | | |||
804 | QSize KQuickStyleItem::sizeFromContents(int width, int height) | 826 | QSize KQuickStyleItem::sizeFromContents(int width, int height) | ||
805 | { | 827 | { | ||
806 | initStyleOption(); | 828 | initStyleOption(); | ||
807 | 829 | | |||
808 | QSize size; | 830 | QSize size; | ||
809 | switch (m_itemType) { | 831 | switch (m_itemType) { | ||
810 | case RadioButton: | 832 | case RadioButton: | ||
811 | size = qApp->style()->sizeFromContents(QStyle::CT_RadioButton, m_styleoption, QSize(width,height)); | 833 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_RadioButton, m_styleoption, QSize(width,height)); | ||
812 | break; | 834 | break; | ||
813 | case CheckBox: | 835 | case CheckBox: | ||
814 | size = qApp->style()->sizeFromContents(QStyle::CT_CheckBox, m_styleoption, QSize(width,height)); | 836 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_CheckBox, m_styleoption, QSize(width,height)); | ||
815 | break; | 837 | break; | ||
816 | case ToolBar: | 838 | case ToolBar: | ||
817 | size = QSize(200, style().contains(QLatin1String("windows")) ? 30 : 42); | 839 | size = QSize(200, styleName().contains(QLatin1String("windows")) ? 30 : 42); | ||
818 | break; | 840 | break; | ||
819 | case ToolButton: { | 841 | case ToolButton: { | ||
820 | QStyleOptionToolButton *btn = qstyleoption_cast<QStyleOptionToolButton*>(m_styleoption); | 842 | QStyleOptionToolButton *btn = qstyleoption_cast<QStyleOptionToolButton*>(m_styleoption); | ||
821 | int w = 0; | 843 | int w = 0; | ||
822 | int h = 0; | 844 | int h = 0; | ||
823 | if (btn->toolButtonStyle != Qt::ToolButtonTextOnly) { | 845 | if (btn->toolButtonStyle != Qt::ToolButtonTextOnly) { | ||
824 | QSize icon = btn->iconSize; | 846 | QSize icon = btn->iconSize; | ||
825 | w = icon.width(); | 847 | w = icon.width(); | ||
Show All 11 Lines | 857 | } else if (btn->toolButtonStyle == Qt::ToolButtonTextBesideIcon) { | |||
837 | if (textSize.height() > h) | 859 | if (textSize.height() > h) | ||
838 | h = textSize.height(); | 860 | h = textSize.height(); | ||
839 | } else { // TextOnly | 861 | } else { // TextOnly | ||
840 | w = textSize.width(); | 862 | w = textSize.width(); | ||
841 | h = textSize.height(); | 863 | h = textSize.height(); | ||
842 | } | 864 | } | ||
843 | } | 865 | } | ||
844 | btn->rect.setSize(QSize(w, h)); | 866 | btn->rect.setSize(QSize(w, h)); | ||
845 | size = qApp->style()->sizeFromContents(QStyle::CT_ToolButton, m_styleoption, QSize(w, h)); } | 867 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_ToolButton, m_styleoption, QSize(w, h)); } | ||
846 | break; | 868 | break; | ||
847 | case Button: { | 869 | case Button: { | ||
848 | QStyleOptionButton *btn = qstyleoption_cast<QStyleOptionButton*>(m_styleoption); | 870 | QStyleOptionButton *btn = qstyleoption_cast<QStyleOptionButton*>(m_styleoption); | ||
849 | 871 | | |||
850 | int contentWidth = btn->fontMetrics.width(btn->text); | 872 | int contentWidth = btn->fontMetrics.width(btn->text); | ||
851 | int contentHeight = btn->fontMetrics.height(); | 873 | int contentHeight = btn->fontMetrics.height(); | ||
852 | if (!btn->icon.isNull()) { | 874 | if (!btn->icon.isNull()) { | ||
853 | //+4 matches a hardcoded value in QStyle and acts as a margin between the icon and the text. | 875 | //+4 matches a hardcoded value in QStyle and acts as a margin between the icon and the text. | ||
854 | contentWidth += btn->iconSize.width() + 4; | 876 | contentWidth += btn->iconSize.width() + 4; | ||
855 | contentHeight = qMax(btn->fontMetrics.height(), btn->iconSize.height()); | 877 | contentHeight = qMax(btn->fontMetrics.height(), btn->iconSize.height()); | ||
856 | } | 878 | } | ||
857 | int newWidth = qMax(width, contentWidth); | 879 | int newWidth = qMax(width, contentWidth); | ||
858 | int newHeight = qMax(height, contentHeight); | 880 | int newHeight = qMax(height, contentHeight); | ||
859 | size = qApp->style()->sizeFromContents(QStyle::CT_PushButton, m_styleoption, QSize(newWidth, newHeight)); } | 881 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_PushButton, m_styleoption, QSize(newWidth, newHeight)); } | ||
860 | break; | 882 | break; | ||
861 | case ComboBox: { | 883 | case ComboBox: { | ||
862 | QStyleOptionComboBox *btn = qstyleoption_cast<QStyleOptionComboBox*>(m_styleoption); | 884 | QStyleOptionComboBox *btn = qstyleoption_cast<QStyleOptionComboBox*>(m_styleoption); | ||
863 | int newWidth = qMax(width, btn->fontMetrics.width(btn->currentText)); | 885 | int newWidth = qMax(width, btn->fontMetrics.width(btn->currentText)); | ||
864 | int newHeight = qMax(height, btn->fontMetrics.height()); | 886 | int newHeight = qMax(height, btn->fontMetrics.height()); | ||
865 | size = qApp->style()->sizeFromContents(QStyle::CT_ComboBox, m_styleoption, QSize(newWidth, newHeight)); } | 887 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_ComboBox, m_styleoption, QSize(newWidth, newHeight)); } | ||
866 | break; | 888 | break; | ||
867 | case Tab: | 889 | case Tab: | ||
868 | size = qApp->style()->sizeFromContents(QStyle::CT_TabBarTab, m_styleoption, QSize(width,height)); | 890 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_TabBarTab, m_styleoption, QSize(width,height)); | ||
869 | break; | 891 | break; | ||
870 | case Slider: | 892 | case Slider: | ||
871 | size = qApp->style()->sizeFromContents(QStyle::CT_Slider, m_styleoption, QSize(width,height)); | 893 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_Slider, m_styleoption, QSize(width,height)); | ||
872 | break; | 894 | break; | ||
873 | case ProgressBar: | 895 | case ProgressBar: | ||
874 | size = qApp->style()->sizeFromContents(QStyle::CT_ProgressBar, m_styleoption, QSize(width,height)); | 896 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_ProgressBar, m_styleoption, QSize(width,height)); | ||
875 | break; | 897 | break; | ||
876 | case SpinBox: | 898 | case SpinBox: | ||
877 | case Edit: | 899 | case Edit: | ||
878 | { | 900 | { | ||
879 | // We have to create a new style option since we might be calling with a QStyleOptionSpinBox | 901 | // We have to create a new style option since we might be calling with a QStyleOptionSpinBox | ||
880 | QStyleOptionFrame frame; | 902 | QStyleOptionFrame frame; | ||
881 | frame.state = m_styleoption->state; | 903 | frame.state = m_styleoption->state; | ||
882 | frame.lineWidth = qApp->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, m_styleoption, nullptr); | 904 | frame.lineWidth = KQuickStyleItem::style()->pixelMetric(QStyle::PM_DefaultFrameWidth, m_styleoption, nullptr); | ||
883 | frame.rect = m_styleoption->rect; | 905 | frame.rect = m_styleoption->rect; | ||
884 | frame.styleObject = this; | 906 | frame.styleObject = this; | ||
885 | size = qApp->style()->sizeFromContents(QStyle::CT_LineEdit, &frame, QSize(width, height)); | 907 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_LineEdit, &frame, QSize(width, height)); | ||
886 | if (m_itemType == SpinBox) | 908 | if (m_itemType == SpinBox) | ||
887 | size.setWidth(qApp->style()->sizeFromContents(QStyle::CT_SpinBox, | 909 | size.setWidth(KQuickStyleItem::style()->sizeFromContents(QStyle::CT_SpinBox, | ||
888 | m_styleoption, QSize(width + 2, height)).width()); | 910 | m_styleoption, QSize(width + 2, height)).width()); | ||
889 | } | 911 | } | ||
890 | break; | 912 | break; | ||
891 | case GroupBox: { | 913 | case GroupBox: { | ||
892 | QStyleOptionGroupBox *box = qstyleoption_cast<QStyleOptionGroupBox*>(m_styleoption); | 914 | QStyleOptionGroupBox *box = qstyleoption_cast<QStyleOptionGroupBox*>(m_styleoption); | ||
893 | QFontMetrics metrics(box->fontMetrics); | 915 | QFontMetrics metrics(box->fontMetrics); | ||
894 | int baseWidth = metrics.width(box->text) + metrics.width(QLatin1Char(' ')); | 916 | int baseWidth = metrics.width(box->text) + metrics.width(QLatin1Char(' ')); | ||
895 | int baseHeight = metrics.height() + m_contentHeight; | 917 | int baseHeight = metrics.height() + m_contentHeight; | ||
896 | if (box->subControls & QStyle::SC_GroupBoxCheckBox) { | 918 | if (box->subControls & QStyle::SC_GroupBoxCheckBox) { | ||
897 | baseWidth += qApp->style()->pixelMetric(QStyle::PM_IndicatorWidth); | 919 | baseWidth += KQuickStyleItem::style()->pixelMetric(QStyle::PM_IndicatorWidth); | ||
898 | baseWidth += qApp->style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing); | 920 | baseWidth += KQuickStyleItem::style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing); | ||
899 | baseHeight = qMax(baseHeight, qApp->style()->pixelMetric(QStyle::PM_IndicatorHeight)); | 921 | baseHeight = qMax(baseHeight, KQuickStyleItem::style()->pixelMetric(QStyle::PM_IndicatorHeight)); | ||
900 | } | 922 | } | ||
901 | size = qApp->style()->sizeFromContents(QStyle::CT_GroupBox, m_styleoption, QSize(qMax(baseWidth, m_contentWidth), baseHeight)); | 923 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_GroupBox, m_styleoption, QSize(qMax(baseWidth, m_contentWidth), baseHeight)); | ||
902 | } | 924 | } | ||
903 | break; | 925 | break; | ||
904 | case Header: | 926 | case Header: | ||
905 | size = qApp->style()->sizeFromContents(QStyle::CT_HeaderSection, m_styleoption, QSize(width,height)); | 927 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_HeaderSection, m_styleoption, QSize(width,height)); | ||
906 | break; | 928 | break; | ||
907 | case ItemRow: | 929 | case ItemRow: | ||
908 | case Item: //fall through | 930 | case Item: //fall through | ||
909 | size = qApp->style()->sizeFromContents(QStyle::CT_ItemViewItem, m_styleoption, QSize(width,height)); | 931 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_ItemViewItem, m_styleoption, QSize(width,height)); | ||
910 | break; | 932 | break; | ||
911 | case MenuBarItem: | 933 | case MenuBarItem: | ||
912 | size = qApp->style()->sizeFromContents(QStyle::CT_MenuBarItem, m_styleoption, QSize(width,height)); | 934 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_MenuBarItem, m_styleoption, QSize(width,height)); | ||
913 | break; | 935 | break; | ||
914 | case MenuBar: | 936 | case MenuBar: | ||
915 | size = qApp->style()->sizeFromContents(QStyle::CT_MenuBar, m_styleoption, QSize(width,height)); | 937 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_MenuBar, m_styleoption, QSize(width,height)); | ||
916 | break; | 938 | break; | ||
917 | case Menu: | 939 | case Menu: | ||
918 | size = qApp->style()->sizeFromContents(QStyle::CT_Menu, m_styleoption, QSize(width,height)); | 940 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_Menu, m_styleoption, QSize(width,height)); | ||
919 | break; | 941 | break; | ||
920 | case MenuItem: | 942 | case MenuItem: | ||
921 | case ComboBoxItem: | 943 | case ComboBoxItem: | ||
922 | if (static_cast<QStyleOptionMenuItem *>(m_styleoption)->menuItemType == QStyleOptionMenuItem::Scroller) { | 944 | if (static_cast<QStyleOptionMenuItem *>(m_styleoption)->menuItemType == QStyleOptionMenuItem::Scroller) { | ||
923 | size.setHeight(qMax(QApplication::globalStrut().height(), | 945 | size.setHeight(qMax(QApplication::globalStrut().height(), | ||
924 | qApp->style()->pixelMetric(QStyle::PM_MenuScrollerHeight, nullptr, nullptr))); | 946 | KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuScrollerHeight, nullptr, nullptr))); | ||
925 | } else { | 947 | } else { | ||
926 | size = qApp->style()->sizeFromContents(QStyle::CT_MenuItem, m_styleoption, QSize(width,height)); | 948 | size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_MenuItem, m_styleoption, QSize(width,height)); | ||
927 | } | 949 | } | ||
928 | break; | 950 | break; | ||
929 | default: | 951 | default: | ||
930 | break; | 952 | break; | ||
931 | } | 953 | } | ||
932 | return size.expandedTo(QSize(m_contentWidth, m_contentHeight)); | 954 | return size.expandedTo(QSize(m_contentWidth, m_contentHeight)); | ||
933 | } | 955 | } | ||
934 | 956 | | |||
935 | qreal KQuickStyleItem::baselineOffset() | 957 | qreal KQuickStyleItem::baselineOffset() | ||
936 | { | 958 | { | ||
937 | QRect r; | 959 | QRect r; | ||
938 | bool ceilResult = true; // By default baseline offset rounding is done upwards | 960 | bool ceilResult = true; // By default baseline offset rounding is done upwards | ||
939 | switch (m_itemType) { | 961 | switch (m_itemType) { | ||
940 | case RadioButton: | 962 | case RadioButton: | ||
941 | r = qApp->style()->subElementRect(QStyle::SE_RadioButtonContents, m_styleoption); | 963 | r = KQuickStyleItem::style()->subElementRect(QStyle::SE_RadioButtonContents, m_styleoption); | ||
942 | break; | 964 | break; | ||
943 | case Button: | 965 | case Button: | ||
944 | r = qApp->style()->subElementRect(QStyle::SE_PushButtonContents, m_styleoption); | 966 | r = KQuickStyleItem::style()->subElementRect(QStyle::SE_PushButtonContents, m_styleoption); | ||
945 | break; | 967 | break; | ||
946 | case CheckBox: | 968 | case CheckBox: | ||
947 | r = qApp->style()->subElementRect(QStyle::SE_CheckBoxContents, m_styleoption); | 969 | r = KQuickStyleItem::style()->subElementRect(QStyle::SE_CheckBoxContents, m_styleoption); | ||
948 | break; | 970 | break; | ||
949 | case Edit: | 971 | case Edit: | ||
950 | r = qApp->style()->subElementRect(QStyle::SE_LineEditContents, m_styleoption); | 972 | r = KQuickStyleItem::style()->subElementRect(QStyle::SE_LineEditContents, m_styleoption); | ||
951 | break; | 973 | break; | ||
952 | case ComboBox: | 974 | case ComboBox: | ||
953 | if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(m_styleoption)) { | 975 | if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(m_styleoption)) { | ||
954 | r = qApp->style()->subControlRect(QStyle::CC_ComboBox, combo, QStyle::SC_ComboBoxEditField); | 976 | r = KQuickStyleItem::style()->subControlRect(QStyle::CC_ComboBox, combo, QStyle::SC_ComboBoxEditField); | ||
955 | if (style() != QLatin1String("mac")) | 977 | if (styleName() != QLatin1String("mac")) | ||
956 | r.adjust(0,0,0,1); | 978 | r.adjust(0,0,0,1); | ||
957 | } | 979 | } | ||
958 | break; | 980 | break; | ||
959 | case SpinBox: | 981 | case SpinBox: | ||
960 | if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(m_styleoption)) { | 982 | if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(m_styleoption)) { | ||
961 | r = qApp->style()->subControlRect(QStyle::CC_SpinBox, spinbox, QStyle::SC_SpinBoxEditField); | 983 | r = KQuickStyleItem::style()->subControlRect(QStyle::CC_SpinBox, spinbox, QStyle::SC_SpinBoxEditField); | ||
962 | ceilResult = false; | 984 | ceilResult = false; | ||
963 | } | 985 | } | ||
964 | break; | 986 | break; | ||
965 | default: | 987 | default: | ||
966 | break; | 988 | break; | ||
967 | } | 989 | } | ||
968 | if (r.height() > 0) { | 990 | if (r.height() > 0) { | ||
969 | const QFontMetrics &fm = m_styleoption->fontMetrics; | 991 | const QFontMetrics &fm = m_styleoption->fontMetrics; | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 1032 | { | |||
1011 | initStyleOption(); | 1033 | initStyleOption(); | ||
1012 | m_styleoption->rect.setWidth(width()); | 1034 | m_styleoption->rect.setWidth(width()); | ||
1013 | m_styleoption->rect.setHeight(height()); | 1035 | m_styleoption->rect.setHeight(height()); | ||
1014 | } | 1036 | } | ||
1015 | 1037 | | |||
1016 | int KQuickStyleItem::pixelMetric(const QString &metric) | 1038 | int KQuickStyleItem::pixelMetric(const QString &metric) | ||
1017 | { | 1039 | { | ||
1018 | if (metric == QLatin1String("scrollbarExtent")) | 1040 | if (metric == QLatin1String("scrollbarExtent")) | ||
1019 | return qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent, nullptr); | 1041 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_ScrollBarExtent, nullptr); | ||
1020 | else if (metric == QLatin1String("defaultframewidth")) | 1042 | else if (metric == QLatin1String("defaultframewidth")) | ||
1021 | return qApp->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, m_styleoption); | 1043 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_DefaultFrameWidth, m_styleoption); | ||
1022 | else if (metric == QLatin1String("taboverlap")) | 1044 | else if (metric == QLatin1String("taboverlap")) | ||
1023 | return qApp->style()->pixelMetric(QStyle::PM_TabBarTabOverlap, nullptr); | 1045 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TabBarTabOverlap, nullptr); | ||
1024 | else if (metric == QLatin1String("tabbaseoverlap")) | 1046 | else if (metric == QLatin1String("tabbaseoverlap")) | ||
1025 | return qApp->style()->pixelMetric(QStyle::PM_TabBarBaseOverlap, m_styleoption); | 1047 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TabBarBaseOverlap, m_styleoption); | ||
1026 | else if (metric == QLatin1String("tabhspace")) | 1048 | else if (metric == QLatin1String("tabhspace")) | ||
1027 | return qApp->style()->pixelMetric(QStyle::PM_TabBarTabHSpace, nullptr); | 1049 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TabBarTabHSpace, nullptr); | ||
1028 | else if (metric == QLatin1String("indicatorwidth")) | 1050 | else if (metric == QLatin1String("indicatorwidth")) | ||
1029 | return qApp->style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, nullptr); | 1051 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, nullptr); | ||
1030 | else if (metric == QLatin1String("tabvspace")) | 1052 | else if (metric == QLatin1String("tabvspace")) | ||
1031 | return qApp->style()->pixelMetric(QStyle::PM_TabBarTabVSpace, nullptr); | 1053 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TabBarTabVSpace, nullptr); | ||
1032 | else if (metric == QLatin1String("tabbaseheight")) | 1054 | else if (metric == QLatin1String("tabbaseheight")) | ||
1033 | return qApp->style()->pixelMetric(QStyle::PM_TabBarBaseHeight, nullptr); | 1055 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TabBarBaseHeight, nullptr); | ||
1034 | else if (metric == QLatin1String("tabvshift")) | 1056 | else if (metric == QLatin1String("tabvshift")) | ||
1035 | return qApp->style()->pixelMetric(QStyle::PM_TabBarTabShiftVertical, nullptr); | 1057 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TabBarTabShiftVertical, nullptr); | ||
1036 | else if (metric == QLatin1String("menubarhmargin")) | 1058 | else if (metric == QLatin1String("menubarhmargin")) | ||
1037 | return qApp->style()->pixelMetric(QStyle::PM_MenuBarHMargin, nullptr); | 1059 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuBarHMargin, nullptr); | ||
1038 | else if (metric == QLatin1String("menubarvmargin")) | 1060 | else if (metric == QLatin1String("menubarvmargin")) | ||
1039 | return qApp->style()->pixelMetric(QStyle::PM_MenuBarVMargin, nullptr); | 1061 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuBarVMargin, nullptr); | ||
1040 | else if (metric == QLatin1String("menubarpanelwidth")) | 1062 | else if (metric == QLatin1String("menubarpanelwidth")) | ||
1041 | return qApp->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, nullptr); | 1063 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, nullptr); | ||
1042 | else if (metric == QLatin1String("menubaritemspacing")) | 1064 | else if (metric == QLatin1String("menubaritemspacing")) | ||
1043 | return qApp->style()->pixelMetric(QStyle::PM_MenuBarItemSpacing, nullptr); | 1065 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuBarItemSpacing, nullptr); | ||
1044 | else if (metric == QLatin1String("spacebelowmenubar")) | 1066 | else if (metric == QLatin1String("spacebelowmenubar")) | ||
1045 | return qApp->style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, m_styleoption); | 1067 | return KQuickStyleItem::style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, m_styleoption); | ||
1046 | else if (metric == QLatin1String("menuhmargin")) | 1068 | else if (metric == QLatin1String("menuhmargin")) | ||
1047 | return qApp->style()->pixelMetric(QStyle::PM_MenuHMargin, nullptr); | 1069 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuHMargin, nullptr); | ||
1048 | else if (metric == QLatin1String("menuvmargin")) | 1070 | else if (metric == QLatin1String("menuvmargin")) | ||
1049 | return qApp->style()->pixelMetric(QStyle::PM_MenuVMargin, nullptr); | 1071 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuVMargin, nullptr); | ||
1050 | else if (metric == QLatin1String("menupanelwidth")) | 1072 | else if (metric == QLatin1String("menupanelwidth")) | ||
1051 | return qApp->style()->pixelMetric(QStyle::PM_MenuPanelWidth, nullptr); | 1073 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuPanelWidth, nullptr); | ||
1052 | else if (metric == QLatin1String("submenuoverlap")) | 1074 | else if (metric == QLatin1String("submenuoverlap")) | ||
1053 | return qApp->style()->pixelMetric(QStyle::PM_SubMenuOverlap, nullptr); | 1075 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_SubMenuOverlap, nullptr); | ||
1054 | else if (metric == QLatin1String("splitterwidth")) | 1076 | else if (metric == QLatin1String("splitterwidth")) | ||
1055 | return qApp->style()->pixelMetric(QStyle::PM_SplitterWidth, nullptr); | 1077 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_SplitterWidth, nullptr); | ||
1056 | else if (metric == QLatin1String("scrollbarspacing")) | 1078 | else if (metric == QLatin1String("scrollbarspacing")) | ||
1057 | return abs(qApp->style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarSpacing, nullptr)); | 1079 | return abs(KQuickStyleItem::style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarSpacing, nullptr)); | ||
1058 | else if (metric == QLatin1String("treeviewindentation")) | 1080 | else if (metric == QLatin1String("treeviewindentation")) | ||
1059 | return qApp->style()->pixelMetric(QStyle::PM_TreeViewIndentation, nullptr); | 1081 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_TreeViewIndentation, nullptr); | ||
1060 | else if (metric == QLatin1String("layouthorizontalspacing")) | 1082 | else if (metric == QLatin1String("layouthorizontalspacing")) | ||
1061 | return qApp->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing, nullptr); | 1083 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing, nullptr); | ||
1062 | else if (metric == QLatin1String("layoutverticalspacing")) | 1084 | else if (metric == QLatin1String("layoutverticalspacing")) | ||
1063 | return qApp->style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing, nullptr); | 1085 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing, nullptr); | ||
1064 | else if (metric == QLatin1String("layoutleftmargin")) | 1086 | else if (metric == QLatin1String("layoutleftmargin")) | ||
1065 | return qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin, nullptr); | 1087 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_LayoutLeftMargin, nullptr); | ||
1066 | else if (metric == QLatin1String("layouttopmargin")) | 1088 | else if (metric == QLatin1String("layouttopmargin")) | ||
1067 | return qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin, nullptr); | 1089 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_LayoutTopMargin, nullptr); | ||
1068 | else if (metric == QLatin1String("layoutrightmargin")) | 1090 | else if (metric == QLatin1String("layoutrightmargin")) | ||
1069 | return qApp->style()->pixelMetric(QStyle::PM_LayoutRightMargin, nullptr); | 1091 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_LayoutRightMargin, nullptr); | ||
1070 | else if (metric == QLatin1String("layoutbottommargin")) | 1092 | else if (metric == QLatin1String("layoutbottommargin")) | ||
1071 | return qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin, nullptr); | 1093 | return KQuickStyleItem::style()->pixelMetric(QStyle::PM_LayoutBottomMargin, nullptr); | ||
1072 | return 0; | 1094 | return 0; | ||
1073 | } | 1095 | } | ||
1074 | 1096 | | |||
1075 | QVariant KQuickStyleItem::styleHint(const QString &metric) | 1097 | QVariant KQuickStyleItem::styleHint(const QString &metric) | ||
1076 | { | 1098 | { | ||
1077 | initStyleOption(); | 1099 | initStyleOption(); | ||
1078 | if (metric == QLatin1String("comboboxpopup")) { | 1100 | if (metric == QLatin1String("comboboxpopup")) { | ||
1079 | return qApp->style()->styleHint(QStyle::SH_ComboBox_Popup, m_styleoption); | 1101 | return KQuickStyleItem::style()->styleHint(QStyle::SH_ComboBox_Popup, m_styleoption); | ||
1080 | } else if (metric == QLatin1String("highlightedTextColor")) { | 1102 | } else if (metric == QLatin1String("highlightedTextColor")) { | ||
1081 | return m_styleoption->palette.highlightedText().color().name(); | 1103 | return m_styleoption->palette.highlightedText().color().name(); | ||
1082 | } else if (metric == QLatin1String("textColor")) { | 1104 | } else if (metric == QLatin1String("textColor")) { | ||
1083 | QPalette pal = m_styleoption->palette; | 1105 | QPalette pal = m_styleoption->palette; | ||
1084 | pal.setCurrentColorGroup(active()? QPalette::Active : QPalette::Inactive); | 1106 | pal.setCurrentColorGroup(active()? QPalette::Active : QPalette::Inactive); | ||
1085 | return pal.text().color().name(); | 1107 | return pal.text().color().name(); | ||
1086 | } else if (metric == QLatin1String("focuswidget")) { | 1108 | } else if (metric == QLatin1String("focuswidget")) { | ||
1087 | return qApp->style()->styleHint(QStyle::SH_FocusFrame_AboveWidget); | 1109 | return KQuickStyleItem::style()->styleHint(QStyle::SH_FocusFrame_AboveWidget); | ||
1088 | } else if (metric == QLatin1String("tabbaralignment")) { | 1110 | } else if (metric == QLatin1String("tabbaralignment")) { | ||
1089 | int result = qApp->style()->styleHint(QStyle::SH_TabBar_Alignment); | 1111 | int result = KQuickStyleItem::style()->styleHint(QStyle::SH_TabBar_Alignment); | ||
1090 | if (result == Qt::AlignCenter) | 1112 | if (result == Qt::AlignCenter) | ||
1091 | return QStringLiteral("center"); | 1113 | return QStringLiteral("center"); | ||
1092 | return QStringLiteral("left"); | 1114 | return QStringLiteral("left"); | ||
1093 | } else if (metric == QLatin1String("externalScrollBars")) { | 1115 | } else if (metric == QLatin1String("externalScrollBars")) { | ||
1094 | return qApp->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents); | 1116 | return KQuickStyleItem::style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents); | ||
1095 | } else if (metric == QLatin1String("scrollToClickPosition")) | 1117 | } else if (metric == QLatin1String("scrollToClickPosition")) | ||
1096 | return qApp->style()->styleHint(QStyle::SH_ScrollBar_LeftClickAbsolutePosition); | 1118 | return KQuickStyleItem::style()->styleHint(QStyle::SH_ScrollBar_LeftClickAbsolutePosition); | ||
1097 | else if (metric == QLatin1String("activateItemOnSingleClick")) | 1119 | else if (metric == QLatin1String("activateItemOnSingleClick")) | ||
1098 | return qApp->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick); | 1120 | return KQuickStyleItem::style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick); | ||
1099 | else if (metric == QLatin1String("submenupopupdelay")) | 1121 | else if (metric == QLatin1String("submenupopupdelay")) | ||
1100 | return qApp->style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, m_styleoption); | 1122 | return KQuickStyleItem::style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, m_styleoption); | ||
1101 | else if (metric == QLatin1String("wheelScrollLines")) | 1123 | else if (metric == QLatin1String("wheelScrollLines")) | ||
1102 | return qApp->wheelScrollLines(); | 1124 | return qApp->wheelScrollLines(); | ||
1103 | return 0; | 1125 | return 0; | ||
1104 | 1126 | | |||
1105 | // Add SH_Menu_SpaceActivatesItem | 1127 | // Add SH_Menu_SpaceActivatesItem | ||
1106 | } | 1128 | } | ||
1107 | 1129 | | |||
1108 | void KQuickStyleItem::setHints(const QVariantMap &str) | 1130 | void KQuickStyleItem::setHints(const QVariantMap &str) | ||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Line(s) | 1247 | { | |||
1226 | QStyle::ComplexControl control = QStyle::CC_SpinBox; | 1248 | QStyle::ComplexControl control = QStyle::CC_SpinBox; | ||
1227 | if (subcontrolString == QLatin1String("down")) | 1249 | if (subcontrolString == QLatin1String("down")) | ||
1228 | subcontrol = QStyle::SC_SpinBoxDown; | 1250 | subcontrol = QStyle::SC_SpinBoxDown; | ||
1229 | else if (subcontrolString == QLatin1String("up")) | 1251 | else if (subcontrolString == QLatin1String("up")) | ||
1230 | subcontrol = QStyle::SC_SpinBoxUp; | 1252 | subcontrol = QStyle::SC_SpinBoxUp; | ||
1231 | else if (subcontrolString == QLatin1String("edit")){ | 1253 | else if (subcontrolString == QLatin1String("edit")){ | ||
1232 | subcontrol = QStyle::SC_SpinBoxEditField; | 1254 | subcontrol = QStyle::SC_SpinBoxEditField; | ||
1233 | } | 1255 | } | ||
1234 | return qApp->style()->subControlRect(control, | 1256 | return KQuickStyleItem::style()->subControlRect(control, | ||
1235 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 1257 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
1236 | subcontrol); | 1258 | subcontrol); | ||
1237 | 1259 | | |||
1238 | } | 1260 | } | ||
1239 | break; | 1261 | break; | ||
1240 | case Slider: | 1262 | case Slider: | ||
1241 | { | 1263 | { | ||
1242 | QStyle::ComplexControl control = QStyle::CC_Slider; | 1264 | QStyle::ComplexControl control = QStyle::CC_Slider; | ||
1243 | if (subcontrolString == QLatin1String("handle")) | 1265 | if (subcontrolString == QLatin1String("handle")) | ||
1244 | subcontrol = QStyle::SC_SliderHandle; | 1266 | subcontrol = QStyle::SC_SliderHandle; | ||
1245 | else if (subcontrolString == QLatin1String("groove")) | 1267 | else if (subcontrolString == QLatin1String("groove")) | ||
1246 | subcontrol = QStyle::SC_SliderGroove; | 1268 | subcontrol = QStyle::SC_SliderGroove; | ||
1247 | return qApp->style()->subControlRect(control, | 1269 | return KQuickStyleItem::style()->subControlRect(control, | ||
1248 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 1270 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
1249 | subcontrol); | 1271 | subcontrol); | ||
1250 | 1272 | | |||
1251 | } | 1273 | } | ||
1252 | break; | 1274 | break; | ||
1253 | case ScrollBar: | 1275 | case ScrollBar: | ||
1254 | { | 1276 | { | ||
1255 | QStyle::ComplexControl control = QStyle::CC_ScrollBar; | 1277 | QStyle::ComplexControl control = QStyle::CC_ScrollBar; | ||
1256 | if (subcontrolString == QLatin1String("slider")) | 1278 | if (subcontrolString == QLatin1String("slider")) | ||
1257 | subcontrol = QStyle::SC_ScrollBarSlider; | 1279 | subcontrol = QStyle::SC_ScrollBarSlider; | ||
1258 | if (subcontrolString == QLatin1String("groove")) | 1280 | if (subcontrolString == QLatin1String("groove")) | ||
1259 | subcontrol = QStyle::SC_ScrollBarGroove; | 1281 | subcontrol = QStyle::SC_ScrollBarGroove; | ||
1260 | else if (subcontrolString == QLatin1String("handle")) | 1282 | else if (subcontrolString == QLatin1String("handle")) | ||
1261 | subcontrol = QStyle::SC_ScrollBarSlider; | 1283 | subcontrol = QStyle::SC_ScrollBarSlider; | ||
1262 | else if (subcontrolString == QLatin1String("add")) | 1284 | else if (subcontrolString == QLatin1String("add")) | ||
1263 | subcontrol = QStyle::SC_ScrollBarAddPage; | 1285 | subcontrol = QStyle::SC_ScrollBarAddPage; | ||
1264 | else if (subcontrolString == QLatin1String("sub")) | 1286 | else if (subcontrolString == QLatin1String("sub")) | ||
1265 | subcontrol = QStyle::SC_ScrollBarSubPage; | 1287 | subcontrol = QStyle::SC_ScrollBarSubPage; | ||
1266 | return qApp->style()->subControlRect(control, | 1288 | return KQuickStyleItem::style()->subControlRect(control, | ||
1267 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 1289 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
1268 | subcontrol); | 1290 | subcontrol); | ||
1269 | } | 1291 | } | ||
1270 | break; | 1292 | break; | ||
1271 | case ItemBranchIndicator: { | 1293 | case ItemBranchIndicator: { | ||
1272 | QStyleOption opt; | 1294 | QStyleOption opt; | ||
1273 | opt.rect = QRect(0, 0, implicitWidth(), implicitHeight()); | 1295 | opt.rect = QRect(0, 0, implicitWidth(), implicitHeight()); | ||
1274 | return qApp->style()->subElementRect(QStyle::SE_TreeViewDisclosureItem, &opt, nullptr); | 1296 | return KQuickStyleItem::style()->subElementRect(QStyle::SE_TreeViewDisclosureItem, &opt, nullptr); | ||
1275 | } | 1297 | } | ||
1276 | default: | 1298 | default: | ||
1277 | break; | 1299 | break; | ||
1278 | } | 1300 | } | ||
1279 | return QRectF(); | 1301 | return QRectF(); | ||
1280 | } | 1302 | } | ||
1281 | 1303 | | |||
1282 | namespace { | 1304 | namespace { | ||
Show All 35 Lines | 1327 | { | |||
1318 | 1340 | | |||
1319 | // Set AA_UseHighDpiPixmaps when calling style code to make QIcon return | 1341 | // Set AA_UseHighDpiPixmaps when calling style code to make QIcon return | ||
1320 | // "retina" pixmaps. The flag is controlled by the application so we can't | 1342 | // "retina" pixmaps. The flag is controlled by the application so we can't | ||
1321 | // set it unconditinally. | 1343 | // set it unconditinally. | ||
1322 | QHighDpiPixmapsEnabler1 enabler; | 1344 | QHighDpiPixmapsEnabler1 enabler; | ||
1323 | 1345 | | |||
1324 | switch (m_itemType) { | 1346 | switch (m_itemType) { | ||
1325 | case Button: | 1347 | case Button: | ||
1326 | qApp->style()->drawControl(QStyle::CE_PushButton, m_styleoption, painter); | 1348 | KQuickStyleItem::style()->drawControl(QStyle::CE_PushButton, m_styleoption, painter); | ||
1327 | break; | 1349 | break; | ||
1328 | case ItemRow :{ | 1350 | case ItemRow :{ | ||
1329 | QPixmap pixmap; | 1351 | QPixmap pixmap; | ||
1330 | // Only draw through style once | 1352 | // Only draw through style once | ||
1331 | const QString pmKey = QLatin1Literal("itemrow") % QString::number(m_styleoption->state,16) % activeControl(); | 1353 | const QString pmKey = QLatin1Literal("itemrow") % QString::number(m_styleoption->state,16) % activeControl(); | ||
1332 | if (!QPixmapCache::find(pmKey, pixmap) || pixmap.width() < width() || height() != pixmap.height()) { | 1354 | if (!QPixmapCache::find(pmKey, pixmap) || pixmap.width() < width() || height() != pixmap.height()) { | ||
1333 | int newSize = width(); | 1355 | int newSize = width(); | ||
1334 | pixmap = QPixmap(newSize, height()); | 1356 | pixmap = QPixmap(newSize, height()); | ||
1335 | pixmap.fill(Qt::transparent); | 1357 | pixmap.fill(Qt::transparent); | ||
1336 | QPainter pixpainter(&pixmap); | 1358 | QPainter pixpainter(&pixmap); | ||
1337 | qApp->style()->drawPrimitive(QStyle::PE_PanelItemViewRow, m_styleoption, &pixpainter); | 1359 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_PanelItemViewRow, m_styleoption, &pixpainter); | ||
1338 | if ((style() == QLatin1String("mac") || !qApp->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected)) && selected()) { | 1360 | if ((styleName() == QLatin1String("mac") || !KQuickStyleItem::style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected)) && selected()) { | ||
1339 | QPalette pal = QApplication::palette("QAbstractItemView"); | 1361 | QPalette pal = QApplication::palette("QAbstractItemView"); | ||
1340 | pal.setCurrentColorGroup(m_styleoption->palette.currentColorGroup()); | 1362 | pal.setCurrentColorGroup(m_styleoption->palette.currentColorGroup()); | ||
1341 | pixpainter.fillRect(m_styleoption->rect, pal.highlight()); | 1363 | pixpainter.fillRect(m_styleoption->rect, pal.highlight()); | ||
1342 | } | 1364 | } | ||
1343 | QPixmapCache::insert(pmKey, pixmap); | 1365 | QPixmapCache::insert(pmKey, pixmap); | ||
1344 | } | 1366 | } | ||
1345 | painter->drawPixmap(0, 0, pixmap); | 1367 | painter->drawPixmap(0, 0, pixmap); | ||
1346 | } | 1368 | } | ||
1347 | break; | 1369 | break; | ||
1348 | case Item: | 1370 | case Item: | ||
1349 | qApp->style()->drawControl(QStyle::CE_ItemViewItem, m_styleoption, painter); | 1371 | KQuickStyleItem::style()->drawControl(QStyle::CE_ItemViewItem, m_styleoption, painter); | ||
1350 | break; | 1372 | break; | ||
1351 | case ItemBranchIndicator: | 1373 | case ItemBranchIndicator: | ||
1352 | qApp->style()->drawPrimitive(QStyle::PE_IndicatorBranch, m_styleoption, painter); | 1374 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_IndicatorBranch, m_styleoption, painter); | ||
1353 | break; | 1375 | break; | ||
1354 | case Header: | 1376 | case Header: | ||
1355 | qApp->style()->drawControl(QStyle::CE_Header, m_styleoption, painter); | 1377 | KQuickStyleItem::style()->drawControl(QStyle::CE_Header, m_styleoption, painter); | ||
1356 | break; | 1378 | break; | ||
1357 | case ToolButton: | 1379 | case ToolButton: | ||
1358 | qApp->style()->drawComplexControl(QStyle::CC_ToolButton, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); | 1380 | KQuickStyleItem::style()->drawComplexControl(QStyle::CC_ToolButton, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); | ||
1359 | break; | 1381 | break; | ||
1360 | case Tab: | 1382 | case Tab: | ||
1361 | { | 1383 | { | ||
1362 | if (m_lastFocusReason != Qt::TabFocusReason && m_lastFocusReason != Qt::BacktabFocusReason) { | 1384 | if (m_lastFocusReason != Qt::TabFocusReason && m_lastFocusReason != Qt::BacktabFocusReason) { | ||
1363 | m_styleoption->state &= ~QStyle::State_HasFocus; | 1385 | m_styleoption->state &= ~QStyle::State_HasFocus; | ||
1364 | } | 1386 | } | ||
1365 | qApp->style()->drawControl(QStyle::CE_TabBarTab, m_styleoption, painter); | 1387 | KQuickStyleItem::style()->drawControl(QStyle::CE_TabBarTab, m_styleoption, painter); | ||
1366 | } | 1388 | } | ||
1367 | break; | 1389 | break; | ||
1368 | case Frame: | 1390 | case Frame: | ||
1369 | qApp->style()->drawControl(QStyle::CE_ShapedFrame, m_styleoption, painter); | 1391 | KQuickStyleItem::style()->drawControl(QStyle::CE_ShapedFrame, m_styleoption, painter); | ||
1370 | break; | 1392 | break; | ||
1371 | case FocusFrame: | 1393 | case FocusFrame: | ||
1372 | qApp->style()->drawControl(QStyle::CE_FocusFrame, m_styleoption, painter); | 1394 | KQuickStyleItem::style()->drawControl(QStyle::CE_FocusFrame, m_styleoption, painter); | ||
1373 | break; | 1395 | break; | ||
1374 | case FocusRect: | 1396 | case FocusRect: | ||
1375 | qApp->style()->drawPrimitive(QStyle::PE_FrameFocusRect, m_styleoption, painter); | 1397 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_FrameFocusRect, m_styleoption, painter); | ||
1376 | break; | 1398 | break; | ||
1377 | case TabFrame: | 1399 | case TabFrame: | ||
1378 | qApp->style()->drawPrimitive(QStyle::PE_FrameTabWidget, m_styleoption, painter); | 1400 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_FrameTabWidget, m_styleoption, painter); | ||
1379 | break; | 1401 | break; | ||
1380 | case MenuBar: | 1402 | case MenuBar: | ||
1381 | qApp->style()->drawControl(QStyle::CE_MenuBarEmptyArea, m_styleoption, painter); | 1403 | KQuickStyleItem::style()->drawControl(QStyle::CE_MenuBarEmptyArea, m_styleoption, painter); | ||
1382 | break; | 1404 | break; | ||
1383 | case MenuBarItem: | 1405 | case MenuBarItem: | ||
1384 | qApp->style()->drawControl(QStyle::CE_MenuBarItem, m_styleoption, painter); | 1406 | KQuickStyleItem::style()->drawControl(QStyle::CE_MenuBarItem, m_styleoption, painter); | ||
1385 | break; | 1407 | break; | ||
1386 | case MenuItem: | 1408 | case MenuItem: | ||
1387 | case ComboBoxItem: { // fall through | 1409 | case ComboBoxItem: { // fall through | ||
1388 | QStyle::ControlElement menuElement = | 1410 | QStyle::ControlElement menuElement = | ||
1389 | static_cast<QStyleOptionMenuItem *>(m_styleoption)->menuItemType == QStyleOptionMenuItem::Scroller ? | 1411 | static_cast<QStyleOptionMenuItem *>(m_styleoption)->menuItemType == QStyleOptionMenuItem::Scroller ? | ||
1390 | QStyle::CE_MenuScroller : QStyle::CE_MenuItem; | 1412 | QStyle::CE_MenuScroller : QStyle::CE_MenuItem; | ||
1391 | qApp->style()->drawControl(menuElement, m_styleoption, painter); | 1413 | KQuickStyleItem::style()->drawControl(menuElement, m_styleoption, painter); | ||
1392 | } | 1414 | } | ||
1393 | break; | 1415 | break; | ||
1394 | case CheckBox: | 1416 | case CheckBox: | ||
1395 | qApp->style()->drawControl(QStyle::CE_CheckBox, m_styleoption, painter); | 1417 | KQuickStyleItem::style()->drawControl(QStyle::CE_CheckBox, m_styleoption, painter); | ||
1396 | break; | 1418 | break; | ||
1397 | case RadioButton: | 1419 | case RadioButton: | ||
1398 | qApp->style()->drawControl(QStyle::CE_RadioButton, m_styleoption, painter); | 1420 | KQuickStyleItem::style()->drawControl(QStyle::CE_RadioButton, m_styleoption, painter); | ||
1399 | break; | 1421 | break; | ||
1400 | case Edit: { | 1422 | case Edit: { | ||
1401 | qApp->style()->drawPrimitive(QStyle::PE_PanelLineEdit, m_styleoption, painter); | 1423 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_PanelLineEdit, m_styleoption, painter); | ||
1402 | } | 1424 | } | ||
1403 | break; | 1425 | break; | ||
1404 | case MacHelpButton: | 1426 | case MacHelpButton: | ||
1405 | //Not managed as mac is not supported | 1427 | //Not managed as mac is not supported | ||
1406 | break; | 1428 | break; | ||
1407 | case Widget: | 1429 | case Widget: | ||
1408 | qApp->style()->drawPrimitive(QStyle::PE_Widget, m_styleoption, painter); | 1430 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_Widget, m_styleoption, painter); | ||
1409 | break; | 1431 | break; | ||
1410 | case ScrollAreaCorner: | 1432 | case ScrollAreaCorner: | ||
1411 | qApp->style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, m_styleoption, painter); | 1433 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, m_styleoption, painter); | ||
1412 | break; | 1434 | break; | ||
1413 | case Splitter: | 1435 | case Splitter: | ||
1414 | if (m_styleoption->rect.width() == 1) | 1436 | if (m_styleoption->rect.width() == 1) | ||
1415 | painter->fillRect(0, 0, width(), height(), m_styleoption->palette.dark().color()); | 1437 | painter->fillRect(0, 0, width(), height(), m_styleoption->palette.dark().color()); | ||
1416 | else | 1438 | else | ||
1417 | qApp->style()->drawControl(QStyle::CE_Splitter, m_styleoption, painter); | 1439 | KQuickStyleItem::style()->drawControl(QStyle::CE_Splitter, m_styleoption, painter); | ||
1418 | break; | 1440 | break; | ||
1419 | case ComboBox: | 1441 | case ComboBox: | ||
1420 | { | 1442 | { | ||
1421 | qApp->style()->drawComplexControl(QStyle::CC_ComboBox, | 1443 | KQuickStyleItem::style()->drawComplexControl(QStyle::CC_ComboBox, | ||
1422 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 1444 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
1423 | painter); | 1445 | painter); | ||
1424 | // This is needed on mac as it will use the painter color and ignore the palette | 1446 | // This is needed on mac as it will use the painter color and ignore the palette | ||
1425 | QPen pen = painter->pen(); | 1447 | QPen pen = painter->pen(); | ||
1426 | painter->setPen(m_styleoption->palette.text().color()); | 1448 | painter->setPen(m_styleoption->palette.text().color()); | ||
1427 | qApp->style()->drawControl(QStyle::CE_ComboBoxLabel, m_styleoption, painter); | 1449 | KQuickStyleItem::style()->drawControl(QStyle::CE_ComboBoxLabel, m_styleoption, painter); | ||
1428 | painter->setPen(pen); | 1450 | painter->setPen(pen); | ||
1429 | } break; | 1451 | } break; | ||
1430 | case SpinBox: | 1452 | case SpinBox: | ||
1431 | #ifdef Q_OS_MAC | 1453 | #ifdef Q_OS_MAC | ||
1432 | // macstyle depends on the embedded qlineedit to fill the editfield background | 1454 | // macstyle depends on the embedded qlineedit to fill the editfield background | ||
1433 | if (style() == QLatin1String("mac")) { | 1455 | if (styleName() == QLatin1String("mac")) { | ||
1434 | QRect editRect = qApp->style()->subControlRect(QStyle::CC_SpinBox, | 1456 | QRect editRect = KQuickStyleItem::style()->subControlRect(QStyle::CC_SpinBox, | ||
1435 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 1457 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
1436 | QStyle::SC_SpinBoxEditField); | 1458 | QStyle::SC_SpinBoxEditField); | ||
1437 | painter->fillRect(editRect.adjusted(-1, -1, 1, 1), m_styleoption->palette.base()); | 1459 | painter->fillRect(editRect.adjusted(-1, -1, 1, 1), m_styleoption->palette.base()); | ||
1438 | } | 1460 | } | ||
1439 | #endif | 1461 | #endif | ||
1440 | qApp->style()->drawComplexControl(QStyle::CC_SpinBox, | 1462 | KQuickStyleItem::style()->drawComplexControl(QStyle::CC_SpinBox, | ||
1441 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 1463 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
1442 | painter); | 1464 | painter); | ||
1443 | break; | 1465 | break; | ||
1444 | case Slider: | 1466 | case Slider: | ||
1445 | qApp->style()->drawComplexControl(QStyle::CC_Slider, | 1467 | KQuickStyleItem::style()->drawComplexControl(QStyle::CC_Slider, | ||
1446 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 1468 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
1447 | painter); | 1469 | painter); | ||
1448 | break; | 1470 | break; | ||
1449 | case Dial: | 1471 | case Dial: | ||
1450 | qApp->style()->drawComplexControl(QStyle::CC_Dial, | 1472 | KQuickStyleItem::style()->drawComplexControl(QStyle::CC_Dial, | ||
1451 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | 1473 | qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), | ||
1452 | painter); | 1474 | painter); | ||
1453 | break; | 1475 | break; | ||
1454 | case ProgressBar: | 1476 | case ProgressBar: | ||
1455 | qApp->style()->drawControl(QStyle::CE_ProgressBar, m_styleoption, painter); | 1477 | KQuickStyleItem::style()->drawControl(QStyle::CE_ProgressBar, m_styleoption, painter); | ||
1456 | break; | 1478 | break; | ||
1457 | case ToolBar: | 1479 | case ToolBar: | ||
1458 | painter->fillRect(m_styleoption->rect, m_styleoption->palette.window().color()); | 1480 | painter->fillRect(m_styleoption->rect, m_styleoption->palette.window().color()); | ||
1459 | qApp->style()->drawControl(QStyle::CE_ToolBar, m_styleoption, painter); | 1481 | KQuickStyleItem::style()->drawControl(QStyle::CE_ToolBar, m_styleoption, painter); | ||
1460 | painter->save(); | 1482 | painter->save(); | ||
1461 | painter->setPen(style() != QLatin1String("fusion") ? m_styleoption->palette.dark().color().darker(120) : | 1483 | painter->setPen(styleName() != QLatin1String("fusion") ? m_styleoption->palette.dark().color().darker(120) : | ||
1462 | m_styleoption->palette.window().color().lighter(107)); | 1484 | m_styleoption->palette.window().color().lighter(107)); | ||
1463 | painter->drawLine(m_styleoption->rect.bottomLeft(), m_styleoption->rect.bottomRight()); | 1485 | painter->drawLine(m_styleoption->rect.bottomLeft(), m_styleoption->rect.bottomRight()); | ||
1464 | painter->restore(); | 1486 | painter->restore(); | ||
1465 | break; | 1487 | break; | ||
1466 | case StatusBar: | 1488 | case StatusBar: | ||
1467 | { | 1489 | { | ||
1468 | painter->fillRect(m_styleoption->rect, m_styleoption->palette.window().color()); | 1490 | painter->fillRect(m_styleoption->rect, m_styleoption->palette.window().color()); | ||
1469 | painter->setPen(m_styleoption->palette.dark().color().darker(120)); | 1491 | painter->setPen(m_styleoption->palette.dark().color().darker(120)); | ||
1470 | painter->drawLine(m_styleoption->rect.topLeft(), m_styleoption->rect.topRight()); | 1492 | painter->drawLine(m_styleoption->rect.topLeft(), m_styleoption->rect.topRight()); | ||
1471 | qApp->style()->drawPrimitive(QStyle::PE_PanelStatusBar, m_styleoption, painter); | 1493 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_PanelStatusBar, m_styleoption, painter); | ||
1472 | } | 1494 | } | ||
1473 | break; | 1495 | break; | ||
1474 | case GroupBox: | 1496 | case GroupBox: | ||
1475 | qApp->style()->drawComplexControl(QStyle::CC_GroupBox, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); | 1497 | KQuickStyleItem::style()->drawComplexControl(QStyle::CC_GroupBox, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); | ||
1476 | break; | 1498 | break; | ||
1477 | case ScrollBar: | 1499 | case ScrollBar: | ||
1478 | qApp->style()->drawComplexControl(QStyle::CC_ScrollBar, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); | 1500 | KQuickStyleItem::style()->drawComplexControl(QStyle::CC_ScrollBar, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); | ||
1479 | break; | 1501 | break; | ||
1480 | case Menu: { | 1502 | case Menu: { | ||
1481 | QStyleHintReturnMask val; | 1503 | QStyleHintReturnMask val; | ||
1482 | qApp->style()->styleHint(QStyle::SH_Menu_Mask, m_styleoption, nullptr, &val); | 1504 | KQuickStyleItem::style()->styleHint(QStyle::SH_Menu_Mask, m_styleoption, nullptr, &val); | ||
1483 | painter->save(); | 1505 | painter->save(); | ||
1484 | painter->setClipRegion(val.region); | 1506 | painter->setClipRegion(val.region); | ||
1485 | painter->fillRect(m_styleoption->rect, m_styleoption->palette.window()); | 1507 | painter->fillRect(m_styleoption->rect, m_styleoption->palette.window()); | ||
1486 | painter->restore(); | 1508 | painter->restore(); | ||
1487 | qApp->style()->drawPrimitive(QStyle::PE_PanelMenu, m_styleoption, painter); | 1509 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_PanelMenu, m_styleoption, painter); | ||
1488 | 1510 | | |||
1489 | if (int fw = qApp->style()->pixelMetric(QStyle::PM_MenuPanelWidth)) { | 1511 | if (int fw = KQuickStyleItem::style()->pixelMetric(QStyle::PM_MenuPanelWidth)) { | ||
1490 | QStyleOptionFrame frame; | 1512 | QStyleOptionFrame frame; | ||
1491 | frame.state = QStyle::State_None; | 1513 | frame.state = QStyle::State_None; | ||
1492 | frame.lineWidth = fw; | 1514 | frame.lineWidth = fw; | ||
1493 | frame.midLineWidth = 0; | 1515 | frame.midLineWidth = 0; | ||
1494 | frame.rect = m_styleoption->rect; | 1516 | frame.rect = m_styleoption->rect; | ||
1495 | frame.styleObject = this; | 1517 | frame.styleObject = this; | ||
1496 | frame.palette = m_styleoption->palette; | 1518 | frame.palette = m_styleoption->palette; | ||
1497 | qApp->style()->drawPrimitive(QStyle::PE_FrameMenu, &frame, painter); | 1519 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_FrameMenu, &frame, painter); | ||
1498 | } | 1520 | } | ||
1499 | } | 1521 | } | ||
1500 | break; | 1522 | break; | ||
1501 | default: | 1523 | default: | ||
1502 | break; | 1524 | break; | ||
1503 | } | 1525 | } | ||
1504 | } | 1526 | } | ||
1505 | 1527 | | |||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Line(s) | 1692 | { | |||
1674 | if (size) | 1696 | if (size) | ||
1675 | *size = QSize(width, height); | 1697 | *size = QSize(width, height); | ||
1676 | 1698 | | |||
1677 | QPixmap pixmap(width, height); | 1699 | QPixmap pixmap(width, height); | ||
1678 | 1700 | | |||
1679 | QStyleOptionViewItem opt; | 1701 | QStyleOptionViewItem opt; | ||
1680 | opt.state |= QStyle::State_Enabled; | 1702 | opt.state |= QStyle::State_Enabled; | ||
1681 | opt.rect = QRect(0, 0, width, height); | 1703 | opt.rect = QRect(0, 0, width, height); | ||
1682 | QString style = qApp->style()->metaObject()->className(); | 1704 | QString style = KQuickStyleItem::style()->metaObject()->className(); | ||
1683 | opt.features = 0; | 1705 | opt.features = 0; | ||
1684 | 1706 | | |||
1685 | if (id.contains(QLatin1String("selected"))) | 1707 | if (id.contains(QLatin1String("selected"))) | ||
1686 | opt.state |= QStyle::State_Selected; | 1708 | opt.state |= QStyle::State_Selected; | ||
1687 | 1709 | | |||
1688 | if (id.contains(QLatin1String("active"))) { | 1710 | if (id.contains(QLatin1String("active"))) { | ||
1689 | opt.state |= QStyle::State_Active; | 1711 | opt.state |= QStyle::State_Active; | ||
1690 | opt.palette.setCurrentColorGroup(QPalette::Active); | 1712 | opt.palette.setCurrentColorGroup(QPalette::Active); | ||
1691 | } else | 1713 | } else | ||
1692 | opt.palette.setCurrentColorGroup(QPalette::Inactive); | 1714 | opt.palette.setCurrentColorGroup(QPalette::Inactive); | ||
1693 | 1715 | | |||
1694 | if (id.contains(QLatin1String("alternate"))) | 1716 | if (id.contains(QLatin1String("alternate"))) | ||
1695 | opt.features |= QStyleOptionViewItem::Alternate; | 1717 | opt.features |= QStyleOptionViewItem::Alternate; | ||
1696 | 1718 | | |||
1697 | QPalette pal = QApplication::palette("QAbstractItemView"); | 1719 | QPalette pal = QApplication::palette("QAbstractItemView"); | ||
1698 | if (opt.state & QStyle::State_Selected && (style.contains(QLatin1String("Mac")) || | 1720 | if (opt.state & QStyle::State_Selected && (style.contains(QLatin1String("Mac")) || | ||
1699 | !qApp->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected))) { | 1721 | !KQuickStyleItem::style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected))) { | ||
1700 | pal.setCurrentColorGroup(opt.palette.currentColorGroup()); | 1722 | pal.setCurrentColorGroup(opt.palette.currentColorGroup()); | ||
1701 | pixmap.fill(pal.highlight().color()); | 1723 | pixmap.fill(pal.highlight().color()); | ||
1702 | } else { | 1724 | } else { | ||
1703 | pixmap.fill(pal.base().color()); | 1725 | pixmap.fill(pal.base().color()); | ||
1704 | QPainter pixpainter(&pixmap); | 1726 | QPainter pixpainter(&pixmap); | ||
1705 | qApp->style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, &pixpainter); | 1727 | KQuickStyleItem::style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, &pixpainter); | ||
1706 | } | 1728 | } | ||
1707 | return pixmap; | 1729 | return pixmap; | ||
1708 | } | 1730 | } | ||
1709 | 1731 | | |||
1710 | #include "moc_kquickstyleitem_p.cpp" | 1732 | #include "moc_kquickstyleitem_p.cpp" | ||
1711 | #include "moc_kquickpadding_p.cpp" | 1733 | #include "moc_kquickpadding_p.cpp" |