File indexing completed on 2024-10-06 06:38:46
0001 /* 0002 KStyle for KDE5 (KDE Integration) 0003 SPDX-FileCopyrightText: 2013 Alejandro Fiestas Olivares <afiestas@kde.org> 0004 0005 KStyle for KDE4 0006 SPDX-FileCopyrightText: 2004-2005 Maksim Orlovich <maksim@kde.org> 0007 SPDX-FileCopyrightText: 2005, 2006 Sandro Giessl <giessl@kde.org> 0008 0009 Based in part on the following software: 0010 0011 KStyle for KDE3 0012 SPDX-FileCopyrightText: 2001-2002 Karol Szwed <gallium@kde.org> 0013 Portions 0014 SPDX-FileCopyrightText: 1998-2000 TrollTech AS 0015 0016 Keramik for KDE3, 0017 SPDX-FileCopyrightText: 2002 Malte Starostik <malte@kde.org> 0018 SPDX-FileCopyrightText: 2002-2003 Maksim Orlovich <maksim@kde.org> 0019 Portions 0020 SPDX-FileCopyrightText: 2001-2002 Karol Szwed <gallium@kde.org> 0021 SPDX-FileCopyrightText: 2001-2002 Fredrik Höglund <fredrik@kde.org> 0022 SPDX-FileCopyrightText: 2000 Daniel M. Duley <mosfet@kde.org> 0023 SPDX-FileCopyrightText: 2000 Dirk Mueller <mueller@kde.org> 0024 SPDX-FileCopyrightText: 2001 Martijn Klingens <klingens@kde.org> 0025 SPDX-FileCopyrightText: 2003 Sandro Giessl <sandro@giessl.com> 0026 0027 SPDX-License-Identifier: LGPL-2.0-or-later 0028 */ 0029 0030 #ifndef KDE_KSTYLE_H 0031 #define KDE_KSTYLE_H 0032 0033 #include <kstyle_export.h> 0034 0035 #include <QCommonStyle> 0036 #include <QPalette> 0037 0038 class KStylePrivate; 0039 /** 0040 * Provides integration with KDE Plasma Workspace settings for Qt styles. 0041 * 0042 * Derive your Qt style from KStyle to automatically inherit 0043 * various settings from the KDE Plasma Workspace, providing a 0044 * consistent user experience. For example, this will ensure a 0045 * consistent single-click or double-click activation setting, 0046 * and the use of standard themed icons. 0047 * 0048 * @author Maksim Orlovich (maksim\@kde.org) 0049 * @author Sandro Giessl (giessl\@kde.org) 0050 * @author Àlex Fiestas (afiestas\@kde.org) 0051 */ 0052 0053 class KSTYLE_EXPORT KStyle : public QCommonStyle 0054 { 0055 Q_OBJECT 0056 0057 public: 0058 KStyle(); 0059 ~KStyle() override; 0060 0061 /** 0062 * Runtime element extension 0063 * This is just convenience and does /not/ require the using widgets style to inherit KStyle 0064 * (i.e. calling this while using cleanlooks won't segfault or so but just return 0) 0065 * Returns a unique id for an element string (e.g. "CE_CapacityBar") 0066 * 0067 * For simplicity, only StyleHints, ControlElements and their SubElements are supported 0068 * If you don't need extended SubElement functionality, just drop it 0069 * 0070 * @param element The style element, represented as string. 0071 * Naming convention: "appname.(2-char-element-type)_element" 0072 * where the 2-char-element-type is of {SH, CE, SE} 0073 * (widgets in kdelibs don't have to pass the appname) 0074 * examples: "CE_CapacityBar", "amarok.CE_Analyzer" 0075 * @param widget Your widget ("this") passing this is mandatory, passing NULL will just return 0 0076 * @returns a unique id for the @p element string or 0, if the element is not supported by the 0077 * widgets current style 0078 * 0079 * Important notes: 0080 * 1) If your string lacks the matching "SH_", "CE_" or "SE_" token the element 0081 * request will be ignored (return is 0) 0082 * 2) Try to avoid custom elements and use default ones (if possible) to get better style support 0083 * and keep UI coherency 0084 * 3) If you cache this value (good idea, this requires a map lookup) don't (!) forget to catch 0085 * style changes in QWidget::changeEvent() 0086 */ 0087 static StyleHint customStyleHint(const QString &element, const QWidget *widget); 0088 static ControlElement customControlElement(const QString &element, const QWidget *widget); 0089 static SubElement customSubElement(const QString &element, const QWidget *widget); 0090 0091 protected: 0092 /** 0093 * Runtime element extension, allows inheriting styles to add support custom elements 0094 * merges supporting inherit chains 0095 * Supposed to be called e.g. in your constructor. 0096 * 0097 * NOTICE: in order to have this work, your style must provide 0098 * an "X-KDE-CustomElements" classinfo, i.e. 0099 * class MyStyle : public KStyle 0100 * { 0101 * Q_OBJECT 0102 * Q_CLASSINFO ("X-KDE-CustomElements", "true") 0103 * 0104 * public: 0105 * ..... 0106 * } 0107 * 0108 * @param element The style element, represented as string. 0109 * Suggested naming convention: appname.(2-char-element-type)_element 0110 * where the 2-char-element-type is of {SH, CE, SE} 0111 * widgets in kdelibs don't have to pass the appname 0112 * examples: "CE_CapacityBar", "amarok.CE_Analyzer" 0113 * 0114 * Important notes: 0115 * 1) If your string lacks the matching "SH_", "CE_" or "SE_" token the element 0116 * request will be ignored (return is 0) 0117 * 2) To keep UI coherency, don't support any nonsense in your style, but convince app developers 0118 * to use standard elements - if available 0119 */ 0120 StyleHint newStyleHint(const QString &element); 0121 ControlElement newControlElement(const QString &element); 0122 SubElement newSubElement(const QString &element); 0123 0124 public: 0125 //@{ 0126 int pixelMetric(PixelMetric m, const QStyleOption *opt = nullptr, const QWidget *widget = nullptr) const override; 0127 virtual int styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *w, QStyleHintReturn *returnData) const override; 0128 0129 void polish(QWidget *) override; 0130 using QCommonStyle::polish; //! needed to avoid warnings at compilation time 0131 0132 QPalette standardPalette() const override; 0133 0134 virtual QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option = nullptr, const QWidget *widget = nullptr) const override; 0135 //@} 0136 private: 0137 KStylePrivate *const d; 0138 }; 0139 0140 #endif // KDE_KSTYLE_H