diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-08-19 13:50:45 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-10-07 08:58:49 (GMT) |
commit | ee383b89f16a9a75a934076255bddbef5a075fa3 (patch) | |
tree | 22118d8368e89aae2ebf09e41b79f3d69d811cae /src | |
parent | c14455b78904f25e724cd928652c49f9583c6aa0 (diff) | |
download | Qt-ee383b89f16a9a75a934076255bddbef5a075fa3.zip Qt-ee383b89f16a9a75a934076255bddbef5a075fa3.tar.gz Qt-ee383b89f16a9a75a934076255bddbef5a075fa3.tar.bz2 |
Integrate the GuiPlatformPlugin interface
This is an internal interface for plugins that can be provided by
the platform to give platform-specific features by platforms built on
top of Qt.
We can easlily integrate Qt on Windows, Mac, Gnome, ... without any
plugin because we can link to their respective library (dynamically
if we don't want to depend on it). On Gnome, we can dynamically
resolve Gtk+ symbols.
This is however not possible for KDE or other platform built on top
of Qt: we can't link against their library because they depend on us
and we can't dynamically resolve the symbols because they are
mangled (C++)
So this plugin provides hooks inside Qt to be able to do things
like native File or Color dialog, native icons, accurate reading of
the config file, and so on.
This is currently private API.
Task-number: QT-406
Reviewed-by: Jens Bache-Wiig
Reviewed-by: Oswald Buddenhagen
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/dialogs/qcolordialog.cpp | 21 | ||||
-rw-r--r-- | src/gui/dialogs/qcolordialog_p.h | 1 | ||||
-rw-r--r-- | src/gui/dialogs/qfiledialog_p.h | 24 | ||||
-rw-r--r-- | src/gui/image/qicon.cpp | 11 | ||||
-rw-r--r-- | src/gui/kernel/kernel.pri | 6 | ||||
-rw-r--r-- | src/gui/kernel/qapplication.cpp | 38 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_p.h | 1 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_x11.cpp | 42 | ||||
-rw-r--r-- | src/gui/kernel/qguiplatformplugin.cpp | 231 | ||||
-rw-r--r-- | src/gui/kernel/qguiplatformplugin_p.h | 122 | ||||
-rw-r--r-- | src/gui/kernel/qkde.cpp | 33 | ||||
-rw-r--r-- | src/gui/kernel/qkde_p.h | 9 | ||||
-rw-r--r-- | src/gui/styles/qcommonstyle.cpp | 54 | ||||
-rw-r--r-- | src/gui/styles/qcommonstyle_p.h | 1 |
14 files changed, 441 insertions, 153 deletions
diff --git a/src/gui/dialogs/qcolordialog.cpp b/src/gui/dialogs/qcolordialog.cpp index a7df999..44a82ef 100644 --- a/src/gui/dialogs/qcolordialog.cpp +++ b/src/gui/dialogs/qcolordialog.cpp @@ -62,6 +62,7 @@ #include "qmime.h" #include "qspinbox.h" #include "qdialogbuttonbox.h" +#include "private/qguiplatformplugin_p.h" #ifdef Q_WS_S60 #include "private/qt_s60_p.h" @@ -1454,6 +1455,8 @@ void QColorDialogPrivate::init(const QColor &initial) q->setSizeGripEnabled(false); q->setWindowTitle(QColorDialog::tr("Select Color")); + nativeDialogInUse = false; + nextCust = 0; QVBoxLayout *mainLay = new QVBoxLayout(q); // there's nothing in this dialog that benefits from sizing up @@ -1719,6 +1722,8 @@ void QColorDialog::setCurrentColor(const QColor &color) d->setCurrentQColor(color); d->setCocoaPanelColor(color); #endif + if (d->nativeDialogInUse) + qt_guiPlatformPlugin()->colorDialogSetCurrentColor(this, color); } QColor QColorDialog::currentColor() const @@ -1871,6 +1876,17 @@ void QColorDialog::setVisible(bool visible) setAttribute(Qt::WA_DontShowOnScreen, false); } } +#else + + if (!(d->opts & DontUseNativeDialog) && qt_guiPlatformPlugin()->colorDialogSetVisible(this, visible)) { + d->nativeDialogInUse = true; + // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below + // updates the state correctly, but skips showing the non-native version: + setAttribute(Qt::WA_DontShowOnScreen); + } else { + d->nativeDialogInUse = false; + setAttribute(Qt::WA_DontShowOnScreen, false); + } #endif QDialog::setVisible(visible); @@ -1970,8 +1986,8 @@ QRgb QColorDialog::getRgba(QRgb initial, bool *ok, QWidget *parent) QColorDialog::~QColorDialog() { -#if defined(Q_WS_MAC) Q_D(QColorDialog); +#if defined(Q_WS_MAC) if (d->delegate) { d->releaseCocoaColorPanelDelegate(); QColorDialogPrivate::sharedColorPanelAvailable = true; @@ -1985,6 +2001,9 @@ QColorDialog::~QColorDialog() settings.setValue(QLatin1String("Qt/customColors/") + QString::number(i), cusrgb[i]); } #endif + if (d->nativeDialogInUse) + qt_guiPlatformPlugin()->colorDialogDelete(this); + } diff --git a/src/gui/dialogs/qcolordialog_p.h b/src/gui/dialogs/qcolordialog_p.h index c7cabfb..81df503 100644 --- a/src/gui/dialogs/qcolordialog_p.h +++ b/src/gui/dialogs/qcolordialog_p.h @@ -114,6 +114,7 @@ public: QColorDialog::ColorDialogOptions opts; QPointer<QObject> receiverToDisconnectOnClose; QByteArray memberToDisconnectOnClose; + bool nativeDialogInUse; #ifdef Q_WS_MAC void openCocoaColorPanel(const QColor &initial, diff --git a/src/gui/dialogs/qfiledialog_p.h b/src/gui/dialogs/qfiledialog_p.h index 54fc0e0..44289d9 100644 --- a/src/gui/dialogs/qfiledialog_p.h +++ b/src/gui/dialogs/qfiledialog_p.h @@ -76,6 +76,8 @@ #include <qdebug.h> #include "qsidebar_p.h" #include "qfscompleter_p.h" +#include "../kernel/qguiplatformplugin_p.h" + #if defined (Q_OS_UNIX) #include <unistd.h> @@ -405,17 +407,17 @@ inline QString QFileDialogPrivate::rootPath() const { #ifndef Q_WS_MAC // Dummies for platforms that don't use native dialogs: - inline void QFileDialogPrivate::deleteNativeDialog_sys() {} - inline bool QFileDialogPrivate::setVisible_sys(bool) { return false; } - inline QDialog::DialogCode QFileDialogPrivate::dialogResultCode_sys(){ return QDialog::Rejected; } - inline void QFileDialogPrivate::setDirectory_sys(const QString &) {} - inline QString QFileDialogPrivate::directory_sys() const { return QString(); } - inline void QFileDialogPrivate::selectFile_sys(const QString &) {} - inline QStringList QFileDialogPrivate::selectedFiles_sys() const { return QStringList(); } - inline void QFileDialogPrivate::setFilter_sys() {} - inline void QFileDialogPrivate::setNameFilters_sys(const QStringList &) {} - inline void QFileDialogPrivate::selectNameFilter_sys(const QString &) {} - inline QString QFileDialogPrivate::selectedNameFilter_sys() const { return QString(); } + inline void QFileDialogPrivate::deleteNativeDialog_sys() { qt_guiPlatformPlugin()->fileDialogDelete(q_func()); } + inline bool QFileDialogPrivate::setVisible_sys(bool visible) { return qt_guiPlatformPlugin()->fileDialogSetVisible(q_func(), visible); } + inline QDialog::DialogCode QFileDialogPrivate::dialogResultCode_sys(){ return qt_guiPlatformPlugin()->fileDialogResultCode(q_func()); } + inline void QFileDialogPrivate::setDirectory_sys(const QString &directory) { qt_guiPlatformPlugin()->fileDialogSetDirectory(q_func(), directory); } + inline QString QFileDialogPrivate::directory_sys() const { return qt_guiPlatformPlugin()->fileDialogDirectory(q_func()); } + inline void QFileDialogPrivate::selectFile_sys(const QString &filename) { qt_guiPlatformPlugin()->fileDialogSelectFile(q_func(), filename); } + inline QStringList QFileDialogPrivate::selectedFiles_sys() const { return qt_guiPlatformPlugin()->fileDialogSelectedFiles(q_func()); } + inline void QFileDialogPrivate::setFilter_sys() { qt_guiPlatformPlugin()->fileDialogSetFilter(q_func()); } + inline void QFileDialogPrivate::setNameFilters_sys(const QStringList &filters) { qt_guiPlatformPlugin()->fileDialogSetNameFilters(q_func(), filters); } + inline void QFileDialogPrivate::selectNameFilter_sys(const QString &filter) { qt_guiPlatformPlugin()->fileDialogSelectNameFilter(q_func(), filter); } + inline QString QFileDialogPrivate::selectedNameFilter_sys() const { return qt_guiPlatformPlugin()->fileDialogSelectedNameFilter(q_func()); } #endif QT_END_NAMESPACE diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index fce4508..3448459 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -54,6 +54,7 @@ #include "qvariant.h" #include "qcache.h" #include "qdebug.h" +#include "private/qguiplatformplugin_p.h" #ifdef Q_WS_MAC #include <private/qt_mac_p.h> @@ -966,13 +967,9 @@ QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback) QIcon icon; -#ifdef Q_WS_X11 - if (X11->desktopEnvironment == DE_KDE) { - icon = QKde::kdeIcon(name); - if (!icon.isNull()) - return icon; - } -#endif + icon = qt_guiPlatformPlugin()->loadIcon(name); + if (!icon.isNull()) + return icon; if (iconCache.contains(name)) { icon = *iconCache.object(name); diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index 7cde384..760d73c 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -47,7 +47,8 @@ HEADERS += \ kernel/qgesture_p.h \ kernel/qstandardgestures.h \ kernel/qstandardgestures_p.h \ - kernel/qsoftkeymanager_p.h + kernel/qsoftkeymanager_p.h \ + kernel/qguiplatformplugin_p.h SOURCES += \ kernel/qaction.cpp \ @@ -79,7 +80,8 @@ SOURCES += \ kernel/qkeymapper.cpp \ kernel/qgesture.cpp \ kernel/qstandardgestures.cpp \ - kernel/qsoftkeymanager.cpp + kernel/qsoftkeymanager.cpp \ + kernel/qguiplatformplugin.cpp win32 { DEFINES += QT_NO_DIRECTDRAW diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 044fedd..43addb6 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -84,6 +84,8 @@ #include "qinputcontextfactory.h" #endif +#include "qguiplatformplugin_p.h" + #include <qthread.h> #include <private/qthread_p.h> @@ -788,6 +790,9 @@ void QApplicationPrivate::construct( qCritical("Library qttestability load failed!"); } } + + //make sure the plugin is loaded + qt_guiPlatformPlugin(); #endif } @@ -1955,38 +1960,7 @@ void QApplicationPrivate::setSystemFont(const QFont &font) */ QString QApplicationPrivate::desktopStyleKey() { -QString desktopstyle; -#if defined(Q_WS_WIN) && defined(Q_WS_WINCE) - if (qt_wince_is_smartphone() || qt_wince_is_pocket_pc()) - desktopstyle = QLatin1String("WindowsMobile"); - else - desktopstyle = QLatin1String("WindowsCE"); - -#elif defined(Q_WS_WIN) - if ((QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA - && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based)) - desktopstyle = QLatin1String("WindowsVista"); - else if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP - && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based)) - desktopstyle = QLatin1String("WindowsXP"); - else - desktopstyle = QLatin1String("Windows"); // default styles for Windows -#elif defined(Q_WS_X11) && defined(Q_OS_SOLARIS) - desktopstyle = QLatin1String("CDE"); // default style for X11 on Solaris -#elif defined(Q_WS_S60) - desktopstyle = QLatin1String("S60"); // default style for Symbian with S60 -#elif defined(Q_OS_SYMBIAN) - desktopstyle = QLatin1String("Windows"); // default style for Symbian without S60 -#elif defined(Q_WS_X11) && defined(Q_OS_IRIX) - desktopstyle = QLatin1String("SGI"); // default style for X11 on IRIX -#elif defined(Q_WS_QWS) - desktopstyle = QLatin1String("Plastique"); // default style for X11 and small devices -#elif defined(Q_WS_X11) - desktopstyle = QApplicationPrivate::x11_desktop_style(); // default runtime dependant style for X11 -#elif defined(Q_WS_MAC) - desktopstyle = QLatin1String("Macintosh"); // default style for all Mac's -#endif - return desktopstyle; + return qt_guiPlatformPlugin()->styleName(); } /*! diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h index 6036196..95b6d28 100644 --- a/src/gui/kernel/qapplication_p.h +++ b/src/gui/kernel/qapplication_p.h @@ -305,7 +305,6 @@ public: #if defined(Q_WS_X11) #ifndef QT_NO_SETTINGS - static QString x11_desktop_style(); static bool x11_apply_settings(); #endif static void reset_instance_pointer(); diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp index e46a370..bf95684 100644 --- a/src/gui/kernel/qapplication_x11.cpp +++ b/src/gui/kernel/qapplication_x11.cpp @@ -85,6 +85,7 @@ #include "qtimer.h" #include "qlibrary.h" #include <private/qgraphicssystemfactory_p.h> +#include "qguiplatformplugin_p.h" #include "qkde_p.h" #if !defined (QT_NO_TABLET) @@ -919,7 +920,7 @@ bool QApplicationPrivate::x11_apply_settings() QString stylename = settings.value(QLatin1String("style")).toString(); if (stylename.isEmpty() && QApplicationPrivate::styleOverride.isNull() && X11->use_xrender) { - stylename = x11_desktop_style(); + stylename = qt_guiPlatformPlugin()->styleName(); } static QString currentStyleName = stylename; @@ -1313,8 +1314,7 @@ static void qt_set_x11_resources(const char* font = 0, const char* fg = 0, pal.setColor(QPalette::Disabled, QPalette::Highlight, Qt::darkBlue); } - if (kdeColors) - pal = QKde::kdePalette().resolve(pal); + pal = qt_guiPlatformPlugin()->palette().resolve(pal); QApplicationPrivate::setSystemPalette(pal); QColor::setAllowX11ColorNames(allowX11ColorNames); } @@ -2560,42 +2560,6 @@ void qt_init(QApplicationPrivate *priv, int, #endif } - - // run-time search for default style -/*! - \internal -*/ -QString QApplicationPrivate::x11_desktop_style() -{ - QString stylename; - switch(X11->desktopEnvironment) { - case DE_KDE: - stylename = QKde::kdeStyle(); - break; - case DE_GNOME: { - QStringList availableStyles = QStyleFactory::keys(); - // Set QGtkStyle for GNOME if available - QString gtkStyleKey = QString::fromLatin1("GTK+"); - if (availableStyles.contains(gtkStyleKey)) { - stylename = gtkStyleKey; - break; - } - if (X11->use_xrender) - stylename = QLatin1String("cleanlooks"); - else - stylename = QLatin1String("windows"); - break; - } - case DE_CDE: - stylename = QLatin1String("cde"); - break; - default: - // Don't do anything - break; - } - return stylename; -} - void QApplicationPrivate::initializeWidgetPaletteHash() { } diff --git a/src/gui/kernel/qguiplatformplugin.cpp b/src/gui/kernel/qguiplatformplugin.cpp new file mode 100644 index 0000000..cf15aa2 --- /dev/null +++ b/src/gui/kernel/qguiplatformplugin.cpp @@ -0,0 +1,231 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qguiplatformplugin_p.h" +#include <qdebug.h> +#include "private/qfactoryloader_p.h" +#include "qstylefactory.h" +#include "qapplication.h" +#include "qplatformdefs.h" + +#ifdef Q_WS_WINCE +#include "qguifunctions_wince.h" +extern bool qt_wince_is_smartphone(); //qguifunctions_wince.cpp +extern bool qt_wince_is_mobile(); //qguifunctions_wince.cpp +extern bool qt_wince_is_pocket_pc(); //qguifunctions_wince.cpp +#endif + + +#if defined(Q_WS_X11) +#include "qkde_p.h" +#include "qt_x11_p.h" +#endif + + +QT_BEGIN_NAMESPACE + + +/*! \internal + Return (an construct if necesseray) the Gui Platform plugin. + + The plugin key to be loaded is inside the QT_PLATFORM_PLUGIN environment variable. + If it is not set, it will be the DESKTOP_SESSION on X11. + + If no plugin can be loaded, the default one is returned. + */ +QGuiPlatformPlugin *qt_guiPlatformPlugin() +{ + static QGuiPlatformPlugin *plugin; + if (!plugin) + { +#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) + + QString key = QString::fromLocal8Bit(qgetenv("QT_PLATFORM_PLUGIN")); +#ifdef Q_WS_X11 + if (key.isEmpty()) { + switch(X11->desktopEnvironment) { + case DE_KDE: + key = QString::fromLatin1("kde"); + break; + default: + key = QString::fromLocal8Bit(qgetenv("DESKTOP_SESSION")); + break; + } + } +#endif + + if (!key.isEmpty() && QApplication::desktopSettingsAware()) { + QFactoryLoader loader(QGuiPlatformPluginInterface_iid, QLatin1String("/gui_platform")); + plugin = qobject_cast<QGuiPlatformPlugin *>(loader.instance(key)); + } +#endif // QT_NO_LIBRARY + + if(!plugin) { + static QGuiPlatformPlugin def; + plugin = &def; + } + } + return plugin; +} + + +/* \class QPlatformPlugin + QGuiPlatformPlugin can be used to integrate Qt applications in a platform built on top of Qt. + The application developer should not know or use the plugin, it is only used by Qt internaly. + + But full platform that are built on top of Qt may provide a plugin so 3rd party Qt application + running in the platform are integrated. + */ + +/* + The constructor can be used to install hooks in Qt + */ +QGuiPlatformPlugin::QGuiPlatformPlugin(QObject *parent) : QObject(parent) {} +QGuiPlatformPlugin::~QGuiPlatformPlugin() {} + + +/* return the string key to be used by default the application */ +QString QGuiPlatformPlugin::styleName() +{ +#if defined(Q_WS_WIN) && defined(Q_WS_WINCE) + if (qt_wince_is_smartphone() || qt_wince_is_pocket_pc()) + return QLatin1String("WindowsMobile"); + else + return QLatin1String("WindowsCE"); +#elif defined(Q_WS_WIN) + if ((QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA + && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based)) + return QLatin1String("WindowsVista"); + else if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP + && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based)) + return QLatin1String("WindowsXP"); + else + return QLatin1String("Windows"); // default styles for Windows +#elif defined(Q_WS_X11) && defined(Q_OS_SOLARIS) + return QLatin1String("CDE"); // default style for X11 on Solaris +#elif defined(Q_WS_S60) + return QLatin1String("S60"); // default style for Symbian with S60 +#elif defined(Q_OS_SYMBIAN) + return QLatin1String("Windows"); // default style for Symbian without S60 +#elif defined(Q_WS_X11) && defined(Q_OS_IRIX) + return QLatin1String("SGI"); // default style for X11 on IRIX +#elif defined(Q_WS_QWS) + return QLatin1String("Plastique"); // default style for X11 and small devices +#elif defined(Q_WS_MAC) + return QLatin1String("Macintosh"); // default style for all Mac's +#elif defined(Q_WS_X11) + QString stylename; + switch(X11->desktopEnvironment) { + case DE_KDE: + stylename = QKde::kdeStyle(); + break; + case DE_GNOME: { + QStringList availableStyles = QStyleFactory::keys(); + // Set QGtkStyle for GNOME if available + QString gtkStyleKey = QString::fromLatin1("GTK+"); + if (availableStyles.contains(gtkStyleKey)) { + stylename = gtkStyleKey; + break; + } + if (X11->use_xrender) + stylename = QLatin1String("cleanlooks"); + else + stylename = QLatin1String("windows"); + break; + } + case DE_CDE: + stylename = QLatin1String("cde"); + break; + default: + // Don't do anything + break; + } + return stylename; +#endif +} + +/* return an aditional default palette (only work on X11) */ +QPalette QGuiPlatformPlugin::palette() +{ +#ifdef Q_WS_X11 + if (QApplication::desktopSettingsAware() && X11->desktopEnvironment == DE_KDE) + return QKde::kdePalette(); +#endif + + return QPalette(); +} + +/* backend for QIcon::fromTheme. A null icon means it uses the default backend */ +QIcon QGuiPlatformPlugin::loadIcon(const QString &name) +{ + return QIcon(); +} + +/* Like QStyle::styleHint */ +int QGuiPlatformPlugin::platformHint(PlatformHint hint) +{ + int ret = 0; + switch(hint) + { + case PH_ToolButtonStyle: + ret = Qt::ToolButtonIconOnly; +#ifdef Q_WS_X11 + if (X11->desktopEnvironment == DE_KDE && X11->desktopVersion >= 4 + && QApplication::desktopSettingsAware()) { + ret = QKde::kdeToolButtonStyle(); + } +#endif + break; + case PH_ToolBarIconSize: +#ifdef Q_WS_X11 + if (X11->desktopEnvironment == DE_KDE && X11->desktopVersion >= 4 + && QApplication::desktopSettingsAware()) { + ret = QKde::kdeToolBarIconSize(); + } +#endif + //by default keep ret = 0 so QCommonStyle will use the style default + break; + } + return ret; +} + + +QT_END_NAMESPACE diff --git a/src/gui/kernel/qguiplatformplugin_p.h b/src/gui/kernel/qguiplatformplugin_p.h new file mode 100644 index 0000000..57ea8af --- /dev/null +++ b/src/gui/kernel/qguiplatformplugin_p.h @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGUIPLATFORM_P_H +#define QGUIPLATFORM_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qplugin.h> +#include <QtCore/qfactoryinterface.h> +#include <QtGui/qdialog.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +class QStyle; +class QPalette; +class QIcon; +class QFileDialog; +class QColorDialog; + +struct Q_GUI_EXPORT QGuiPlatformPluginInterface : public QFactoryInterface +{ +}; + +#define QGuiPlatformPluginInterface_iid "com.nokia.qt.QGuiPlatformPluginInterface" + +Q_DECLARE_INTERFACE(QGuiPlatformPluginInterface, QGuiPlatformPluginInterface_iid) + +class Q_GUI_EXPORT QGuiPlatformPlugin : public QObject, public QGuiPlatformPluginInterface +{ + Q_OBJECT + Q_INTERFACES(QGuiPlatformPluginInterface:QFactoryInterface) + public: + explicit QGuiPlatformPlugin(QObject *parent = 0); + ~QGuiPlatformPlugin(); + + virtual QStringList keys() const { return QStringList() << QLatin1String("default"); }; + + virtual QString styleName(); + virtual QPalette palette(); + virtual QIcon loadIcon(const QString &name); + enum PlatformHint { PH_ToolButtonStyle, PH_ToolBarIconSize }; + virtual int platformHint(PlatformHint hint); + + + virtual void fileDialogDelete(QFileDialog *) {} + virtual bool fileDialogSetVisible(QFileDialog *, bool) { return false; } + virtual QDialog::DialogCode fileDialogResultCode(QFileDialog *) { return QDialog::Rejected; } + virtual void fileDialogSetDirectory(QFileDialog *, const QString &) {} + virtual QString fileDialogDirectory(const QFileDialog *) const { return QString(); } + virtual void fileDialogSelectFile(QFileDialog *, const QString &) {} + virtual QStringList fileDialogSelectedFiles(const QFileDialog *) const { return QStringList(); } + virtual void fileDialogSetFilter(QFileDialog *) {} + virtual void fileDialogSetNameFilters(QFileDialog *, const QStringList &) {} + virtual void fileDialogSelectNameFilter(QFileDialog *, const QString &) {} + virtual QString fileDialogSelectedNameFilter(const QFileDialog *) const { return QString(); } + + virtual void colorDialogDelete(QColorDialog *) {} + virtual bool colorDialogSetVisible(QColorDialog *, bool) { return false; } + virtual void colorDialogSetCurrentColor(QColorDialog *, const QColor &) {} +}; + +//internal +QGuiPlatformPlugin *qt_guiPlatformPlugin(); + +QT_END_NAMESPACE + +QT_END_HEADER + + +#endif // QGUIPLATFORMPLUGIN_H diff --git a/src/gui/kernel/qkde.cpp b/src/gui/kernel/qkde.cpp index 6c8909f..edc53ac 100644 --- a/src/gui/kernel/qkde.cpp +++ b/src/gui/kernel/qkde.cpp @@ -141,14 +141,33 @@ QString QKde::kdeStyle() return QLatin1String("windows"); } -/*!\internal - placeholder to load icon from kde. - to be implemented - */ -QIcon QKde::kdeIcon(const QString &name) + +int QKde::kdeToolButtonStyle() +{ + QSettings settings(QKde::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")) + return Qt::ToolButtonTextBesideIcon; + else if (toolbarStyle == QLatin1String("TextOnly")) + return Qt::ToolButtonTextOnly; + else if (toolbarStyle == QLatin1String("TextUnderIcon")) + return Qt::ToolButtonTextUnderIcon; + + return Qt::ToolButtonTextBesideIcon; +} + +int QKde::kdeToolBarIconSize() { - //###todo - return QIcon(); + static int iconSize = -1; + if (iconSize == -1) { + QSettings settings(QKde::kdeHome() + QLatin1String("/share/config/kdeglobals"), + QSettings::IniFormat); + settings.beginGroup(QLatin1String("ToolbarIcons")); + iconSize = settings.value(QLatin1String("Size")).toInt(); + } + return iconSize; } QT_END_NAMESPACE diff --git a/src/gui/kernel/qkde_p.h b/src/gui/kernel/qkde_p.h index 4063f0e..c22a145 100644 --- a/src/gui/kernel/qkde_p.h +++ b/src/gui/kernel/qkde_p.h @@ -61,12 +61,17 @@ QT_BEGIN_NAMESPACE -// This namespace contains helper function to help KDE integration +/*!\internal + This namespace contains helper function to help KDE integration + They are only used if we detect the use of KDE and the KDE platform plugin is not found (old KDE version) + Or if the detected KDE version is KDE3 +*/ namespace QKde { QString kdeHome(); QString kdeStyle(); QPalette kdePalette(); - QIcon kdeIcon(const QString &name); + int kdeToolButtonStyle(); + int kdeToolBarIconSize(); } diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp index df4f866..612258a 100644 --- a/src/gui/styles/qcommonstyle.cpp +++ b/src/gui/styles/qcommonstyle.cpp @@ -63,7 +63,6 @@ #include <qtoolbar.h> #include <qtoolbutton.h> #include <qrubberband.h> -#include <../kernel/qkde_p.h> #include <private/qcommonstylepixmaps_p.h> #include <private/qmath_p.h> #include <private/qstylehelper_p.h> @@ -75,6 +74,7 @@ #include <qdir.h> #include <qsettings.h> #include <qpixmapcache.h> +#include <private/qguiplatformplugin_p.h> #include <limits.h> @@ -837,35 +837,6 @@ static void drawArrow(const QStyle *style, const QStyleOptionToolButton *toolbut } #endif // QT_NO_TOOLBUTTON - -#ifdef Q_WS_X11 // These functions are used to parse the X11 freedesktop icon spec - -/*!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 (X11->desktopEnvironment == DE_KDE && X11->desktopVersion >= 4) { - QSettings settings(QKde::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 - #ifndef QT_NO_ITEMVIEWS QSize QCommonStylePrivate::viewItemSize(const QStyleOptionViewItemV4 *option, int role) const @@ -4688,19 +4659,8 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid break; case PM_ToolBarIconSize: -#ifdef Q_WS_X11 - if (X11->desktopVersion >= 4) { - static int iconSize = 0; - if (!iconSize) { - QSettings settings(QKde::kdeHome() + - QLatin1String("/share/config/kdeglobals"), - QSettings::IniFormat); - settings.beginGroup(QLatin1String("ToolbarIcons")); - iconSize = settings.value(QLatin1String("Size"), QLatin1String("22")).toInt(); - } - ret = iconSize; - } else -#endif + ret = qt_guiPlatformPlugin()->platformHint(QGuiPlatformPlugin::PH_ToolBarIconSize); + if (!ret) ret = proxy()->pixelMetric(PM_SmallIconSize, opt, widget); break; @@ -5192,13 +5152,7 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget ret = true; break; case SH_ToolButtonStyle: - ret = Qt::ToolButtonIconOnly; -#ifdef Q_WS_X11 - { - static int buttonStyle = d_func()->lookupToolButtonStyle(); - return buttonStyle; - } -#endif + ret = qt_guiPlatformPlugin()->platformHint(QGuiPlatformPlugin::PH_ToolButtonStyle); break; case SH_RequestSoftwareInputPanel: ret = RSIP_OnMouseClickAndAlreadyFocused; diff --git a/src/gui/styles/qcommonstyle_p.h b/src/gui/styles/qcommonstyle_p.h index 7162392..a905601 100644 --- a/src/gui/styles/qcommonstyle_p.h +++ b/src/gui/styles/qcommonstyle_p.h @@ -122,7 +122,6 @@ public: } #endif mutable QIcon tabBarcloseButtonIcon; - int lookupToolButtonStyle() const; #ifndef QT_NO_TABBAR void tabLayout(const QStyleOptionTabV3 *opt, const QWidget *widget, QRect *textRect, QRect *pixmapRect) const; #endif |