src/gui/kernel/qkde.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    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 
       
    53 QT_BEGIN_NAMESPACE
       
    54 
       
    55 /*! \internal
       
    56 Gets the current KDE home path
       
    57 like "/home/troll/.kde"
       
    58 */
       
    59 QString QKde::kdeHome()
       
    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 
       
    75 /*!\internal
       
    76   Reads the color from the config, and store it in the palette with the given color role if found
       
    77   */
       
    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 
       
    97 /*!\internal
       
    98     Returns the KDE palette
       
    99 */
       
   100 QPalette QKde::kdePalette()
       
   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 
       
   123 /*!\internal
       
   124     Returns the name of the QStyle to use.
       
   125     (read from the kde config if needed)
       
   126 */
       
   127 QString QKde::kdeStyle()
       
   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 
       
   145 int QKde::kdeToolButtonStyle()
       
   146 {
       
   147     QSettings settings(QKde::kdeHome() + QLatin1String("/share/config/kdeglobals"),
       
   148                         QSettings::IniFormat);
       
   149     settings.beginGroup(QLatin1String("Toolbar style"));
       
   150     QString toolbarStyle = settings.value(QLatin1String("ToolButtonStyle"), QLatin1String("TextBesideIcon")).toString();
       
   151     if (toolbarStyle == QLatin1String("TextBesideIcon"))
       
   152         return Qt::ToolButtonTextBesideIcon;
       
   153     else if (toolbarStyle == QLatin1String("TextOnly"))
       
   154         return Qt::ToolButtonTextOnly;
       
   155     else if (toolbarStyle == QLatin1String("TextUnderIcon"))
       
   156         return Qt::ToolButtonTextUnderIcon;
       
   157 
       
   158     return Qt::ToolButtonTextBesideIcon;
       
   159 }
       
   160 
       
   161 int QKde::kdeToolBarIconSize()
       
   162 {
       
   163     static int iconSize = -1;
       
   164     if (iconSize == -1) {
       
   165         QSettings settings(QKde::kdeHome() + QLatin1String("/share/config/kdeglobals"),
       
   166                             QSettings::IniFormat);
       
   167                             settings.beginGroup(QLatin1String("ToolbarIcons"));
       
   168         iconSize = settings.value(QLatin1String("Size")).toInt();
       
   169     }
       
   170     return iconSize;
       
   171 }
       
   172 
       
   173 QT_END_NAMESPACE
       
   174 
       
   175 #endif //Q_WS_X11
       
   176