[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: Make KStyle honour KDE wide single-click behaviour
From:       Craig Drummond <craig () kde ! org>
Date:       2008-06-12 20:17:41
Message-ID: 200806122117.42180.craig () kde ! org
[Download RAW message or body]

On Thursday 12 Jun 2008, David Faure wrote:
> On Wednesday 11 June 2008, Andreas Pakulat wrote:
> > The style hint is asked each time you release the mouse on an itemview,
> > by the Qt implementation (and also double-click release).
> >
> > The creation of the kcomponent data is just allocating 1 dpointer with
> > some text data (kaboutdata) and in worst case registering the component
> > as main component if this is called from a non-kde-app. However that
> > part can easily be cached.
>
> I see no reason why the kcomponentdata couldn't be a member of the style,
> just like it is in any other "component".

What about the attached patch? I've used a similar thing in the QtCurve Qt4 
style, and it seems to work fine for me. This patch also controls the icons 
on button settings, as well as mapping some KDE icons.

Craig.

["kstyle.diff" (text/x-diff)]

Index: kstyle.cpp
===================================================================
--- kstyle.cpp	(revision 819479)
+++ kstyle.cpp	(working copy)
@@ -45,6 +45,10 @@
 
 #include "kstyle.h"
 #include "kstyle.moc"
+#include "kglobalsettings.h"
+#include "kiconloader.h"
+#include "kicon.h"
+#include "kcomponentdata.h"
 
 #include <QtCore/qalgorithms.h>
 #include <QtCore/QCache>
@@ -59,6 +63,7 @@
 #include <QtGui/QPainter>
 #include <QtGui/QScrollBar>
 #include <QtGui/QStyleOption>
+#include <QtGui/QFileDialog>
 
 //### FIXME: Who to credit these to?
 static const qint32 u_arrow[]={-1,-3, 0,-3, -2,-2, 1,-2, -3,-1, 2,-1, -4,0, 3,0, \
-4,1, 3,1}; @@ -68,6 +73,25 @@
 #define QCOORDARRLEN(x) sizeof(x)/(sizeof(qint32)*2)
 
 
+static KComponentData *kstyleKComponentData=0;
+static int            kstyleInstanceCount=0;
+
+static void checkKComponentData()
+{
+    if(!kstyleKComponentData && !KGlobal::hasMainComponent())
+    {
+        QString name(QApplication::applicationName());
+
+        if(name.isEmpty())
+            name=qAppName();
+
+        if(name.isEmpty())
+            name="KStyle";
+
+        kstyleKComponentData=new KComponentData(name.toLatin1(), name.toLatin1());
+    }
+}
+
 /**
  TODO: lots of missing widgets, SH_ settings, etc.
 
@@ -107,6 +131,8 @@
 
 KStyle::KStyle() : clickedLabel(0), d(new KStylePrivate)
 {
+    kstyleInstanceCount++;
+
     //Set up some default metrics...
     setWidgetLayoutProp(WT_Generic, Generic::DefaultFrameWidth, 2);
 
@@ -245,6 +271,12 @@
 #warning "mem leak: need to delete bOpt"
 #endif
     delete d;
+
+    if(0==--kstyleInstanceCount && kstyleKComponentData)
+    {
+        delete kstyleKComponentData;
+        kstyleKComponentData=0L;
+    }
 }
 
 QString KStyle::defaultStyle()
@@ -314,8 +346,195 @@
 QPixmap KStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption \
*opt,  const QWidget *widget) const
 {
+    checkKComponentData();
+
+    bool isFileDialog(widget && qobject_cast<const QFileDialog *>(widget));
+
+    switch(standardPixmap)
+    {
+        case SP_MessageBoxInformation:
+            return KIconLoader::global()->loadIcon("dialog-information", \
KIconLoader::Dialog, 32); +        case SP_MessageBoxWarning:
+            return KIconLoader::global()->loadIcon("dialog-warning", \
KIconLoader::Dialog, 32); +        case SP_MessageBoxCritical:
+            return KIconLoader::global()->loadIcon("dialog-error", \
KIconLoader::Dialog, 32); +        case SP_MessageBoxQuestion:
+            return KIconLoader::global()->loadIcon("dialog-information", \
KIconLoader::Dialog, 32); +        case SP_FileDialogStart:
+            return KIconLoader::global()->loadIcon(Qt::RightToLeft==QApplication::layoutDirection()
 +                                                    ? "go-edn" : "go-first", \
KIconLoader::Small, 16); +        case SP_FileDialogEnd:
+            return KIconLoader::global()->loadIcon(Qt::RightToLeft==QApplication::layoutDirection()
 +                                                    ? "go-first" : "go-end", \
KIconLoader::Small, 16); +        case SP_FileDialogToParent:
+            return KIconLoader::global()->loadIcon("go-up", KIconLoader::Small, 16);
+        case SP_FileDialogNewFolder:
+            return KIconLoader::global()->loadIcon("folder-new", KIconLoader::Small, \
16); +        case SP_FileDialogDetailedView:
+            return KIconLoader::global()->loadIcon("view-list-details", \
KIconLoader::Small, 16); +        case SP_FileDialogListView:
+            return KIconLoader::global()->loadIcon("view-list-icons", \
KIconLoader::Small, 16); +        case SP_FileDialogBack:
+            return KIconLoader::global()->loadIcon(Qt::RightToLeft==QApplication::layoutDirection()
 +                                                    ? "go-next" : "go-previous", \
KIconLoader::Small, 16); +        case SP_DialogOkButton:
+            return KIconLoader::global()->loadIcon("dialog-ok", KIconLoader::Small, \
16); +        case SP_DialogCancelButton:
+            return KIconLoader::global()->loadIcon("dialog-cancel", \
KIconLoader::Small, 16); +        case SP_DialogHelpButton:
+            return KIconLoader::global()->loadIcon("help-contents", \
KIconLoader::Small, 16); +        case SP_DialogOpenButton:
+            return KIconLoader::global()->loadIcon("document-open", \
KIconLoader::Small, 16); +        case SP_DialogSaveButton:
+            return KIconLoader::global()->loadIcon("document-save", \
KIconLoader::Small, 16); +        case SP_DialogCloseButton:
+            return KIconLoader::global()->loadIcon("dialog-close", \
KIconLoader::Small, 16); +        case SP_DialogApplyButton:
+            return KIconLoader::global()->loadIcon("dialog-ok-apply", \
KIconLoader::Small, 16); +        case SP_DialogResetButton:
+            return KIconLoader::global()->loadIcon("document-revert", \
KIconLoader::Small, 16); +        case SP_DialogYesButton:
+            return KIconLoader::global()->loadIcon("dialog-ok", KIconLoader::Small, \
16); +        case SP_DialogNoButton:
+            return KIconLoader::global()->loadIcon("dialog-cancel", \
KIconLoader::Small, 16); +        case SP_ArrowUp:
+            return KIconLoader::global()->loadIcon("arrow-up", KIconLoader::Dialog, \
32); +        case SP_ArrowDown:
+            return KIconLoader::global()->loadIcon("arrow-down", \
KIconLoader::Dialog, 32); +        case SP_ArrowLeft:
+            return KIconLoader::global()->loadIcon("arrow-left", \
KIconLoader::Dialog, 32); +        case SP_ArrowRight:
+            return KIconLoader::global()->loadIcon("arrow-right", \
KIconLoader::Dialog, 32); +        case SP_ArrowBack:
+            return KIconLoader::global()->loadIcon(Qt::RightToLeft==QApplication::layoutDirection()
 +                                                     ? (isFileDialog ? "go-next" : \
"arrow-right") +                                                     : (isFileDialog \
? "go-previous" : "arrow-left"), KIconLoader::Dialog, 32); +        case \
SP_ArrowForward: +            return \
KIconLoader::global()->loadIcon(Qt::RightToLeft==QApplication::layoutDirection() +    \
? (isFileDialog ? "go-previous" : "arrow-left") +                                     \
: (isFileDialog ? "go-next" : "arrow-right"), KIconLoader::Dialog, 32); +        case \
SP_BrowserReload: +            return KIconLoader::global()->loadIcon("view-refresh", \
KIconLoader::Small, 16); +        case SP_BrowserStop:
+            return KIconLoader::global()->loadIcon("process-stop", \
KIconLoader::Small, 16); +        case SP_MediaPlay:
+            return KIconLoader::global()->loadIcon("media-playback-start", \
KIconLoader::Small, 16); +        case SP_MediaStop:
+            return KIconLoader::global()->loadIcon("media-playback-stop", \
KIconLoader::Small, 16); +        case SP_MediaPause:
+            return KIconLoader::global()->loadIcon("media-playback-pause", \
KIconLoader::Small, 16); +        case SP_MediaSkipForward:
+            return KIconLoader::global()->loadIcon("media-skip-forward", \
KIconLoader::Small, 16); +        case SP_MediaSkipBackward:
+            return KIconLoader::global()->loadIcon("media-skip-backward", \
KIconLoader::Small, 16); +        case SP_MediaSeekForward:
+            return KIconLoader::global()->loadIcon("media-seek-forward", \
KIconLoader::Small, 16); +        case SP_MediaSeekBackward:
+            return KIconLoader::global()->loadIcon("media-seek-backward", \
KIconLoader::Small, 16); +        case SP_MediaVolume:
+            return KIconLoader::global()->loadIcon("player-volume", \
KIconLoader::Small, 16); +        case SP_MediaVolumeMuted:
+            return KIconLoader::global()->loadIcon("player-volume-muted", \
KIconLoader::Small, 16); +        default:
+            break;
+    }
     return QCommonStyle::standardPixmap(standardPixmap, opt, widget);
 }
+
+QIcon KStyle::standardIconImplementation(StandardPixmap standardPixmap, const \
QStyleOption *opt, const QWidget *widget) const +{
+    checkKComponentData();
+
+    switch(standardPixmap)
+    {
+        case SP_MessageBoxInformation:
+            return KIcon("dialog-information");
+        case SP_MessageBoxWarning:
+            return KIcon("dialog-warning");
+        case SP_MessageBoxCritical:
+            return KIcon("dialog-error");
+        case SP_MessageBoxQuestion:
+            return KIcon("dialog-information");
+        case SP_FileDialogStart:
+            return KIcon(Qt::RightToLeft==QApplication::layoutDirection()
+                                                    ? "go-edn" : "go-first");
+        case SP_FileDialogEnd:
+            return KIcon(Qt::RightToLeft==QApplication::layoutDirection()
+                                                    ? "go-first" : "go-end");
+        case SP_FileDialogToParent:
+            return KIcon("go-up");
+        case SP_FileDialogNewFolder:
+            return KIcon("folder-new");
+        case SP_FileDialogDetailedView:
+            return KIcon("view-list-details");
+        case SP_FileDialogListView:
+            return KIcon("view-list-icons");
+        case SP_FileDialogBack:
+            return KIcon(Qt::RightToLeft==QApplication::layoutDirection()
+                                                    ? "go-next" : "go-previous");
+        case SP_DialogOkButton:
+            return KIcon("dialog-ok");
+        case SP_DialogCancelButton:
+            return KIcon("dialog-cancel");
+        case SP_DialogHelpButton:
+            return KIcon("help-contents");
+        case SP_DialogOpenButton:
+            return KIcon("document-open");
+        case SP_DialogSaveButton:
+            return KIcon("document-save");
+        case SP_DialogCloseButton:
+            return KIcon("dialog-close");
+        case SP_DialogApplyButton:
+            return KIcon("dialog-ok-apply");
+        case SP_DialogResetButton:
+            return KIcon("document-revert");
+        case SP_DialogYesButton:
+            return KIcon("dialog-ok");
+        case SP_DialogNoButton:
+            return KIcon("dialog-cancel");
+        case SP_ArrowUp:
+            return KIcon("arrow-up");
+        case SP_ArrowDown:
+            return KIcon("arrow-down");
+        case SP_ArrowLeft:
+            return KIcon("arrow-left");
+        case SP_ArrowRight:
+            return KIcon("arrow-right");
+        case SP_ArrowBack:
+            return KIcon(Qt::RightToLeft==QApplication::layoutDirection()
+                                                     ? "go-next" : "go-previous");
+        case SP_ArrowForward:
+            return KIcon(Qt::RightToLeft==QApplication::layoutDirection()
+                                                     ? "go-previous"
+                                                     : "go-next");
+        case SP_BrowserReload:
+            return KIcon("view-refresh");
+        case SP_BrowserStop:
+            return KIcon("process-stop");
+        case SP_MediaPlay:
+            return KIcon("media-playback-start");
+        case SP_MediaStop:
+            return KIcon("media-playback-stop");
+        case SP_MediaPause:
+            return KIcon("media-playback-pause");
+        case SP_MediaSkipForward:
+            return KIcon("media-skip-forward");
+        case SP_MediaSkipBackward:
+            return KIcon("media-skip-backward");
+        case SP_MediaSeekForward:
+            return KIcon("media-seek-forward");
+        case SP_MediaSeekBackward:
+            return KIcon("media-seek-backward");
+        case SP_MediaVolume:
+            return KIcon("player-volume");
+        case SP_MediaVolumeMuted:
+            return KIcon("player-volume-muted");
+        default:
+            break;
+    }
+    return QCommonStyle::standardIconImplementation(standardPixmap, opt, widget);
+}
+
 QPixmap KStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap,
                                     const QStyleOption *opt) const
 {
@@ -2201,6 +2420,14 @@
         case SH_ItemView_ShowDecorationSelected:
             return false;
 
+        case SH_DialogButtonBox_ButtonsHaveIcons:
+            checkKComponentData();
+            return KGlobalSettings::showIconsOnPushButtons();
+
+        case SH_ItemView_ActivateItemOnSingleClick:
+            checkKComponentData();
+            return KGlobalSettings::singleClick();
+
         default:
             break;
     };
Index: kstyle.h
===================================================================
--- kstyle.h	(revision 817521)
+++ kstyle.h	(working copy)
@@ -1555,6 +1555,7 @@
     QPalette standardPalette() const;
     QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
                                    const QWidget *widget = 0) const;
+    QIcon standardIconImplementation(StandardPixmap standardPixmap, const \
                QStyleOption *opt, const QWidget *widget) const;
     QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap,
                                    const QStyleOption *opt) const;
     bool eventFilter(QObject *, QEvent *);



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic