summaryrefslogtreecommitdiffstats
path: root/src/gui/styles/qcommonstyle.cpp
diff options
context:
space:
mode:
authorJens Bache-Wiig <jbache@trolltech.com>2009-07-16 19:00:45 (GMT)
committerJens Bache-Wiig <jbache@trolltech.com>2009-07-16 19:12:29 (GMT)
commite1c019fd7ecaa59eee39f23434dd63d5656f4ee0 (patch)
tree52e299e2d6ecc0d32247f2ee2dafbba99350c3a3 /src/gui/styles/qcommonstyle.cpp
parentca2122e9eb2b0d68d4203b05128f6fc5a838f3d6 (diff)
downloadQt-e1c019fd7ecaa59eee39f23434dd63d5656f4ee0.zip
Qt-e1c019fd7ecaa59eee39f23434dd63d5656f4ee0.tar.gz
Qt-e1c019fd7ecaa59eee39f23434dd63d5656f4ee0.tar.bz2
Allow picking up tool button style from the system
KDE and GNOME has the concept of a default tool button style that can be set system-wide. Qt currently allways default to IconOnly. I have added an optional Qt::ToolButtonSystemDefault value so you can opt-in to respect the system setting. We did not change the default because a lot of apps will look odd when for instance text is beside icons and the descriptive text is too long. Task-number: 237864 Reviewed-by: ogoffart
Diffstat (limited to 'src/gui/styles/qcommonstyle.cpp')
-rw-r--r--src/gui/styles/qcommonstyle.cpp41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp
index 7b8b75e..29176c3 100644
--- a/src/gui/styles/qcommonstyle.cpp
+++ b/src/gui/styles/qcommonstyle.cpp
@@ -840,6 +840,11 @@ static void drawArrow(const QStyle *style, const QStyleOptionToolButton *toolbut
#ifdef Q_WS_X11 // These functions are used to parse the X11 freedesktop icon spec
+static int kdeVersion()
+{
+ static int kdeVersion = qgetenv("KDE_SESSION_VERSION").toInt();
+ return kdeVersion;
+}
void QCommonStylePrivate::lookupIconTheme() const
{
@@ -858,8 +863,7 @@ void QCommonStylePrivate::lookupIconTheme() const
QFileInfo fileInfo(QLatin1String("/usr/share/icons/default.kde"));
QDir dir(fileInfo.canonicalFilePath());
- int kdeVersion = qgetenv("KDE_SESSION_VERSION").toInt();
- QString kdeDefault = kdeVersion >= 4 ? QString::fromLatin1("oxygen") : QString::fromLatin1("crystalsvg");
+ QString kdeDefault = kdeVersion() >= 4 ? QString::fromLatin1("oxygen") : QString::fromLatin1("crystalsvg");
QString defaultTheme = fileInfo.exists() ? dir.dirName() : kdeDefault;
QSettings settings(QApplicationPrivate::kdeHome() +
QLatin1String("/share/config/kdeglobals"), QSettings::IniFormat);
@@ -997,6 +1001,29 @@ QIcon QCommonStylePrivate::createIcon(const QString &name) const
icon.addPixmap(findIcon(32, name));
return icon;
}
+/*!internal
+
+Checks if you are running KDE and looks up the toolbar
+from the KDE configuration file
+
+*/
+int QCommonStylePrivate::lookupToolButtonStyle() const
+{
+ int result = Qt::ToolButtonIconOnly;
+ if (kdeVersion() >= 4) {
+ QSettings settings(QApplicationPrivate::kdeHome() +
+ QLatin1String("/share/config/kdeglobals"), QSettings::IniFormat);
+ settings.beginGroup(QLatin1String("Toolbar style"));
+ QString toolbarStyle = settings.value(QLatin1String("ToolButtonStyle"), QLatin1String("TextBesideIcon")).toString();
+ if (toolbarStyle == QLatin1String("TextBesideIcon"))
+ result = Qt::ToolButtonTextBesideIcon;
+ else if (toolbarStyle == QLatin1String("TextOnly"))
+ result = Qt::ToolButtonTextOnly;
+ else if (toolbarStyle == QLatin1String("TextUnderIcon"))
+ result = Qt::ToolButtonTextUnderIcon;
+ }
+ return result;
+}
#endif //Q_WS_X11
@@ -5290,6 +5317,16 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget
case SH_DockWidget_ButtonsHaveFrame:
ret = true;
break;
+ case SH_ToolButtonStyle:
+ ret = Qt::ToolButtonIconOnly;
+#ifdef Q_WS_X11
+ {
+ Q_D(const QCommonStyle);
+ static int buttonStyle = d->lookupToolButtonStyle();
+ return buttonStyle;
+ }
+#endif
+ break;
default:
ret = 0;
break;