Qt 4.8
qkde.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 
43 #include "qkde_p.h"
44 #include <QtCore/QLibrary>
45 #include <QtCore/QDir>
46 #include <QtCore/qdebug.h>
47 #include <QtCore/QSettings>
48 #include "QtGui/qstylefactory.h"
49 #include "qt_x11_p.h"
50 
51 #if defined(Q_WS_X11)
52 
54 
60 {
61  static QString kdeHomePath;
62  if (kdeHomePath.isEmpty()) {
63  kdeHomePath = QString::fromLocal8Bit(qgetenv("KDEHOME"));
64  if (kdeHomePath.isEmpty()) {
65  QDir homeDir(QDir::homePath());
66  QString kdeConfDir(QLatin1String("/.kde"));
67  if (4 == X11->desktopVersion && homeDir.exists(QLatin1String(".kde4")))
68  kdeConfDir = QLatin1String("/.kde4");
69  kdeHomePath = QDir::homePath() + kdeConfDir;
70  }
71  }
72  return kdeHomePath;
73 }
74 
78 static bool kdeColor(QPalette *pal, QPalette::ColorRole role, const QSettings &kdeSettings, const QString &kde4Key, const QString &kde3Key = QString())
79 {
80  QVariant variant = kdeSettings.value(kde4Key);
81  if (!variant.isValid())
82  QVariant variant = kdeSettings.value(kde3Key);
83  if (variant.isValid()) {
84  QStringList values = variant.toStringList();
85  if (values.size() == 3) {
86  int r = values[0].toInt();
87  int g = values[1].toInt();
88  int b = values[2].toInt();
89  pal->setBrush(role, QColor(r, g, b));
90  return true;
91  }
92  }
93  return false;
94 }
95 
96 
101 {
102  const QSettings theKdeSettings(QKde::kdeHome() +
103  QLatin1String("/share/config/kdeglobals"), QSettings::IniFormat);
104  QPalette pal;
105 
106  // Setup KDE palette
107  kdeColor(&pal, QPalette::Button, theKdeSettings, QLatin1String("Colors:Button/BackgroundNormal"), QLatin1String("buttonBackground"));
108  kdeColor(&pal, QPalette::Window, theKdeSettings, QLatin1String("Colors:Window/BackgroundNormal"), QLatin1String("background"));
109  kdeColor(&pal, QPalette::Text, theKdeSettings, QLatin1String("Colors:View/ForegroundNormal"), QLatin1String("foreground"));
110  kdeColor(&pal, QPalette::WindowText, theKdeSettings, QLatin1String("Colors:Window/ForegroundNormal"), QLatin1String("windowForeground"));
111  kdeColor(&pal, QPalette::Base, theKdeSettings, QLatin1String("Colors:View/BackgroundNormal"), QLatin1String("windowBackground"));
112  kdeColor(&pal, QPalette::Highlight, theKdeSettings, QLatin1String("Colors:Selection/BackgroundNormal"), QLatin1String("selectBackground"));
113  kdeColor(&pal, QPalette::HighlightedText, theKdeSettings, QLatin1String("Colors:Selection/ForegroundNormal"), QLatin1String("selectForeground"));
114  kdeColor(&pal, QPalette::AlternateBase, theKdeSettings, QLatin1String("Colors:View/BackgroundAlternate"), QLatin1String("alternateBackground"));
115  kdeColor(&pal, QPalette::ButtonText, theKdeSettings, QLatin1String("Colors:Button/ForegroundNormal"), QLatin1String("buttonForeground"));
116  kdeColor(&pal, QPalette::Link, theKdeSettings, QLatin1String("Colors:View/ForegroundLink"), QLatin1String("linkColor"));
117  kdeColor(&pal, QPalette::LinkVisited, theKdeSettings, QLatin1String("Colors:View/ForegroundVisited"), QLatin1String("visitedLinkColor"));
118  //## TODO tooltip color
119 
120  return pal;
121 }
122 
128 {
129  if (X11->desktopVersion >= 4) {
130  QSettings kdeSettings(QKde::kdeHome() + QLatin1String("/share/config/kdeglobals"), QSettings::IniFormat);
131  QString style = kdeSettings.value(QLatin1String("widgetStyle"), QLatin1String("Oxygen")).toString();
132 
133  QStringList availableStyles = QStyleFactory::keys();
134  if(availableStyles.contains(style, Qt::CaseInsensitive))
135  return style;
136  }
137 
138  if (X11->use_xrender)
139  return QLatin1String("plastique");
140  else
141  return QLatin1String("windows");
142 }
143 
144 
146 {
147  QSettings settings(QKde::kdeHome() + QLatin1String("/share/config/kdeglobals"),
149  settings.beginGroup(QLatin1String("Toolbar style"));
150  QString toolbarStyle = settings.value(QLatin1String("ToolButtonStyle"), QLatin1String("TextBesideIcon")).toString();
151  if (toolbarStyle == QLatin1String("TextBesideIcon"))
153  else if (toolbarStyle == QLatin1String("TextOnly"))
154  return Qt::ToolButtonTextOnly;
155  else if (toolbarStyle == QLatin1String("TextUnderIcon"))
157 
159 }
160 
162 {
163  static int iconSize = -1;
164  if (iconSize == -1) {
165  QSettings settings(QKde::kdeHome() + QLatin1String("/share/config/kdeglobals"),
167  settings.beginGroup(QLatin1String("ToolbarIcons"));
168  iconSize = settings.value(QLatin1String("Size")).toInt();
169  }
170  return iconSize;
171 }
172 
174 
175 #endif //Q_WS_X11
176 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
static bool kdeColor(QPalette *pal, QPalette::ColorRole role, const QSettings &kdeSettings, const QString &kde4Key, const QString &kde3Key=QString())
Definition: qkde.cpp:78
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for setting key.
Definition: qsettings.cpp:3460
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
ColorRole
The ColorRole enum defines the different symbolic color roles used in current GUIs.
Definition: qpalette.h:93
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
void beginGroup(const QString &prefix)
Appends prefix to the current group.
Definition: qsettings.cpp:3073
QString kdeStyle()
Definition: qkde.cpp:127
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define X11
Definition: qt_x11_p.h:724
bool exists() const
Returns true if the directory exists; otherwise returns false.
Definition: qdir.cpp:1560
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
QStringList toStringList() const
Returns the variant as a QStringList if the variant has type() StringList, String ...
Definition: qvariant.cpp:2259
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette...
Definition: qpalette.h:206
static QStringList keys()
Returns the list of valid keys, i.e.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
QPalette kdePalette()
Definition: qkde.cpp:100
quint16 values[128]
int kdeToolButtonStyle()
Definition: qkde.cpp:145
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QString kdeHome()
Definition: qkde.cpp:59
int kdeToolBarIconSize()
Definition: qkde.cpp:161
const char * variant
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
static QString homePath()
Returns the absolute path of the user&#39;s home directory.
Definition: qdir.cpp:1942
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61