From 53d25d9558186f014fc4bdfbdbf30aafe5fb2ef7 Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Tue, 15 Sep 2015 17:43:24 +0200 Subject: [PATCH] implemented SH_KCustomElement from KStyle, to have them working in KDE4. --- kstyle/breezestyle.cpp | 4 ++-- kstyle/kstylekde4compat.cpp | 41 ++++++++++++++++++++++++++++++++++++- kstyle/kstylekde4compat.h | 24 ++++++++++++++++++---- 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index 269a2261..2b9112fc 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -173,7 +173,7 @@ namespace Breeze , _splitterFactory( new SplitterFactory( this ) ) , _widgetExplorer( new WidgetExplorer( this ) ) , _tabBarData( new BreezePrivate::TabBarData( this ) ) - #if BREEZE_HAVE_KSTYLE + #if BREEZE_HAVE_KSTYLE||BREEZE_USE_KDE4 , SH_ArgbDndWindow( newStyleHint( QStringLiteral( "SH_ArgbDndWindow" ) ) ) , CE_CapacityBar( newControlElement( QStringLiteral( "CE_CapacityBar" ) ) ) #endif @@ -822,7 +822,7 @@ namespace Breeze StyleControl fcn( nullptr ); - #if BREEZE_HAVE_KSTYLE + #if BREEZE_HAVE_KSTYLE||BREEZE_USE_KDE4 if( element == CE_CapacityBar ) { fcn = &Style::drawProgressBarControl; diff --git a/kstyle/kstylekde4compat.cpp b/kstyle/kstylekde4compat.cpp index b47374a7..6906cecf 100644 --- a/kstyle/kstylekde4compat.cpp +++ b/kstyle/kstylekde4compat.cpp @@ -23,16 +23,55 @@ #include #include + +static const QStyle::StyleHint SH_KCustomStyleElement = (QStyle::StyleHint)0xff000001; +static const int X_KdeBase = 0xff000000; + +//_____________________________________________________________________ KStyleKDE4Compat::KStyleKDE4Compat() { + controlCounter = subElementCounter = X_KdeBase; + hintCounter = X_KdeBase + 1; //sic! X_KdeBase is covered by SH_KCustomStyleElement } +//_____________________________________________________________________ KStyleKDE4Compat::~KStyleKDE4Compat() +{} + +//_____________________________________________________________________ +static inline int newStyleElement(const QString &element, const char *check, int &counter, QHash *elements) { + if (!element.contains(check)) { + return 0; + } + int id = elements->value(element, 0); + if (!id) { + ++counter; + id = counter; + elements->insert(element, id); + } + return id; } +//_____________________________________________________________________ +QStyle::StyleHint KStyleKDE4Compat::newStyleHint(const QString &element) +{ return (StyleHint)newStyleElement(element, "SH_", hintCounter, &styleElements); } + +//_____________________________________________________________________ +QStyle::ControlElement KStyleKDE4Compat::newControlElement(const QString &element) +{ return (ControlElement)newStyleElement(element, "CE_", controlCounter, &styleElements); } + +//_____________________________________________________________________ +QStyle::SubElement KStyleKDE4Compat::newSubElement(const QString &element) +{ return (SubElement)newStyleElement(element, "SE_", subElementCounter, &styleElements); } + +//_____________________________________________________________________ int KStyleKDE4Compat::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const { + + if( hint == SH_KCustomStyleElement && widget ) + { return styleElements.value(widget->objectName(), 0); } + switch (hint) { case SH_ItemView_ActivateItemOnSingleClick: { KConfigGroup g(KSharedConfig::openConfig(), "KDE"); @@ -81,4 +120,4 @@ int KStyleKDE4Compat::styleHint(StyleHint hint, const QStyleOption *option, cons }; return QCommonStyle::styleHint(hint, option, widget, returnData); -} \ No newline at end of file +} diff --git a/kstyle/kstylekde4compat.h b/kstyle/kstylekde4compat.h index f3bd828d..ad713c02 100644 --- a/kstyle/kstylekde4compat.h +++ b/kstyle/kstylekde4compat.h @@ -28,15 +28,31 @@ #define KSTYLE_KDE4_COMPAT_H #include +#include class KStyleKDE4Compat : public QCommonStyle { Q_OBJECT -public: + + public: + KStyleKDE4Compat(); ~KStyleKDE4Compat(); - virtual int styleHint(StyleHint hint, const QStyleOption *opt, - const QWidget *w, QStyleHintReturn *returnData) const; + virtual int styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *w, QStyleHintReturn *returnData) const; + + protected: + + StyleHint newStyleHint(const QString &element); + ControlElement newControlElement(const QString &element); + SubElement newSubElement(const QString &element); + + private: + + QHash styleElements; + int hintCounter; + int controlCounter; + int subElementCounter; + }; -#endif \ No newline at end of file +#endif