summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2014-01-16 18:27:26 +0100
committerJ-P Nurmi <jpnurmi@digia.com>2014-01-16 18:40:34 +0100
commit9357575806f51fa95c6b6d44f2fe0f2c0c252ebc (patch)
tree9dfc4a88af043633dde40e83f0cda2570b6bf4e6
parent7bd6205398b2d89b3ac083b2f6f00b197f40057a (diff)
WIP: QGtk3ThemePlugin
-rw-r--r--src/plugins/platformthemes/gtk3/gtk3.json3
-rw-r--r--src/plugins/platformthemes/gtk3/gtk3.pro23
-rw-r--r--src/plugins/platformthemes/gtk3/main.cpp67
-rw-r--r--src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp606
-rw-r--r--src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.h143
-rw-r--r--src/plugins/platformthemes/gtk3/qgtk3theme.cpp105
-rw-r--r--src/plugins/platformthemes/gtk3/qgtk3theme.h64
-rw-r--r--src/plugins/platformthemes/platformthemes.pro2
-rw-r--r--src/plugins/plugins.pro2
9 files changed, 1014 insertions, 1 deletions
diff --git a/src/plugins/platformthemes/gtk3/gtk3.json b/src/plugins/platformthemes/gtk3/gtk3.json
new file mode 100644
index 0000000..3887248
--- /dev/null
+++ b/src/plugins/platformthemes/gtk3/gtk3.json
@@ -0,0 +1,3 @@
+{
+ "Keys": [ "gtk3" ]
+}
diff --git a/src/plugins/platformthemes/gtk3/gtk3.pro b/src/plugins/platformthemes/gtk3/gtk3.pro
new file mode 100644
index 0000000..1cc5e34
--- /dev/null
+++ b/src/plugins/platformthemes/gtk3/gtk3.pro
@@ -0,0 +1,23 @@
+TARGET = qgtk3
+
+PLUGIN_TYPE = platformthemes
+PLUGIN_CLASS_NAME = QGtk3ThemePlugin
+load(qt_plugin)
+
+QT += core-private gui-private platformsupport-private
+
+CONFIG += X11
+# TODO:
+# QMAKE_CXXFLAGS += $$QT_CFLAGS_QGTK3
+# LIBS += $$QT_LIBS_QGTK3
+CONFIG += link_pkgconfig
+PKGCONFIG += gtk+-3.0
+
+HEADERS += \
+ qgtk3dialoghelpers.h \
+ qgtk3theme.h
+
+SOURCES += \
+ main.cpp \
+ qgtk3dialoghelpers.cpp \
+ qgtk3theme.cpp
diff --git a/src/plugins/platformthemes/gtk3/main.cpp b/src/plugins/platformthemes/gtk3/main.cpp
new file mode 100644
index 0000000..3e8438f
--- /dev/null
+++ b/src/plugins/platformthemes/gtk3/main.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** 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, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qpa/qplatformthemeplugin.h>
+#include "qgtk3theme.h"
+
+QT_BEGIN_NAMESPACE
+
+class QGtk3ThemePlugin : public QPlatformThemePlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPA.QPlatformThemeFactoryInterface.5.1" FILE "gtk3.json")
+
+public:
+ QPlatformTheme *create(const QString &key, const QStringList &params);
+};
+
+QPlatformTheme *QGtk3ThemePlugin::create(const QString &key, const QStringList &params)
+{
+ Q_UNUSED(params);
+ if (!key.compare(QGtk3Theme::name, Qt::CaseInsensitive))
+ return new QGtk3Theme;
+
+ return 0;
+}
+
+QT_END_NAMESPACE
+
+#include "main.moc"
diff --git a/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp
new file mode 100644
index 0000000..f2b40df
--- /dev/null
+++ b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp
@@ -0,0 +1,606 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** 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, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qgtk3dialoghelpers.h"
+
+#include <qeventloop.h>
+#include <qwindow.h>
+#include <qcolor.h>
+#include <qdebug.h>
+#include <qfont.h>
+
+#include <private/qguiapplication_p.h>
+
+#undef signals
+#include <gtk/gtk.h>
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+#include <pango/pango.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGtk3Dialog : public QWindow
+{
+ Q_OBJECT
+
+public:
+ QGtk3Dialog(GtkWidget *gtkWidget);
+ ~QGtk3Dialog();
+
+ GtkDialog* gtkDialog() const;
+
+ void exec();
+ bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent);
+ void hide();
+
+Q_SIGNALS:
+ void accept();
+ void reject();
+
+protected:
+ static void onResponse(QGtk3Dialog *dialog, int response);
+
+private:
+ GtkWidget *gtkWidget;
+};
+
+QGtk3Dialog::QGtk3Dialog(GtkWidget *gtkWidget) : gtkWidget(gtkWidget)
+{
+ g_signal_connect_swapped(G_OBJECT(gtkWidget), "response", G_CALLBACK(onResponse), this);
+ g_signal_connect(G_OBJECT(gtkWidget), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
+}
+
+QGtk3Dialog::~QGtk3Dialog()
+{
+ gtk_widget_destroy(gtkWidget);
+}
+
+GtkDialog* QGtk3Dialog::gtkDialog() const
+{
+ return GTK_DIALOG(gtkWidget);
+}
+
+void QGtk3Dialog::exec()
+{
+ if (modality() == Qt::ApplicationModal) {
+ // block input to the whole app, including other GTK dialogs
+ gtk_dialog_run(gtkDialog());
+ } else {
+ // block input to the window, allow input to other GTK dialogs
+ QEventLoop loop;
+ connect(this, SIGNAL(accept()), &loop, SLOT(quit()));
+ connect(this, SIGNAL(reject()), &loop, SLOT(quit()));
+ loop.exec();
+ }
+}
+
+bool QGtk3Dialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
+{
+ setParent(parent);
+ setFlags(flags);
+ setModality(modality);
+
+ gtk_widget_realize(gtkWidget); // creates X window
+
+ GdkWindow *gdkWindow = gtk_widget_get_window(gtkWidget);
+ if (parent) {
+ GdkDisplay *gdkDisplay = gdk_window_get_display(gdkWindow);
+ XSetTransientForHint(gdk_x11_display_get_xdisplay(gdkDisplay),
+ gdk_x11_window_get_xid(gdkWindow),
+ parent->winId());
+ }
+
+ if (modality != Qt::NonModal) {
+ gdk_window_set_modal_hint(gdkWindow, true);
+ QGuiApplicationPrivate::showModalWindow(this);
+ }
+
+ gtk_widget_show(gtkWidget);
+ return true;
+}
+
+void QGtk3Dialog::hide()
+{
+ QGuiApplicationPrivate::hideModalWindow(this);
+ gtk_widget_hide(gtkWidget);
+}
+
+void QGtk3Dialog::onResponse(QGtk3Dialog *dialog, int response)
+{
+ if (response == GTK_RESPONSE_OK)
+ emit dialog->accept();
+ else
+ emit dialog->reject();
+}
+
+QGtk3ColorDialogHelper::QGtk3ColorDialogHelper()
+{
+ d.reset(new QGtk3Dialog(gtk_color_chooser_dialog_new("", 0)));
+ connect(d.data(), SIGNAL(accept()), this, SLOT(onAccepted()));
+ connect(d.data(), SIGNAL(reject()), this, SIGNAL(reject()));
+
+ g_signal_connect_swapped(d->gtkDialog(), "color-activated", G_CALLBACK(onColorChanged), this);
+}
+
+QGtk3ColorDialogHelper::~QGtk3ColorDialogHelper()
+{
+}
+
+bool QGtk3ColorDialogHelper::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
+{
+ applyOptions();
+ return d->show(flags, modality, parent);
+}
+
+void QGtk3ColorDialogHelper::exec()
+{
+ d->exec();
+}
+
+void QGtk3ColorDialogHelper::hide()
+{
+ d->hide();
+}
+
+void QGtk3ColorDialogHelper::setCurrentColor(const QColor &color)
+{
+ GtkDialog *gtkDialog = d->gtkDialog();
+ if (color.alpha() < 255)
+ gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(gtkDialog), true);
+ GdkRGBA gdkColor;
+ gdkColor.red = color.redF();
+ gdkColor.green = color.greenF();
+ gdkColor.blue = color.blueF();
+ gdkColor.alpha = color.alphaF();
+ gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(gtkDialog), &gdkColor);
+}
+
+QColor QGtk3ColorDialogHelper::currentColor() const
+{
+ GtkDialog *gtkDialog = d->gtkDialog();
+ GdkRGBA gdkColor;
+ gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(gtkDialog), &gdkColor);
+ return QColor::fromRgbF(gdkColor.red, gdkColor.green, gdkColor.blue, gdkColor.alpha);
+}
+
+void QGtk3ColorDialogHelper::onAccepted()
+{
+ emit accept();
+ emit colorSelected(currentColor());
+}
+
+void QGtk3ColorDialogHelper::onColorChanged(QGtk3ColorDialogHelper *dialog)
+{
+ emit dialog->currentColorChanged(dialog->currentColor());
+}
+
+void QGtk3ColorDialogHelper::applyOptions()
+{
+ GtkDialog *gtkDialog = d->gtkDialog();
+ gtk_window_set_title(GTK_WINDOW(gtkDialog), options()->windowTitle().toUtf8());
+
+ gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(gtkDialog), options()->testOption(QColorDialogOptions::ShowAlphaChannel));
+
+ // TODO:
+// GtkWidget *okButton = 0;
+// GtkWidget *cancelButton = 0;
+// GtkWidget *helpButton = 0;
+// g_object_get(G_OBJECT(gtkDialog), "ok-button", &okButton, "cancel-button", &cancelButton, "help-button", &helpButton, NULL);
+// if (okButton)
+// g_object_set(G_OBJECT(okButton), "visible", !options()->testOption(QColorDialogOptions::NoButtons), NULL);
+// if (cancelButton)
+// g_object_set(G_OBJECT(cancelButton), "visible", !options()->testOption(QColorDialogOptions::NoButtons), NULL);
+// if (helpButton)
+// gtk_widget_hide(helpButton);
+}
+
+QGtk3FileDialogHelper::QGtk3FileDialogHelper()
+{
+ d.reset(new QGtk3Dialog(gtk_file_chooser_dialog_new("", 0,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OK, GTK_RESPONSE_OK, NULL)));
+ connect(d.data(), SIGNAL(accept()), this, SLOT(onAccepted()));
+ connect(d.data(), SIGNAL(reject()), this, SIGNAL(reject()));
+
+ g_signal_connect(GTK_FILE_CHOOSER(d->gtkDialog()), "selection-changed", G_CALLBACK(onSelectionChanged), this);
+ g_signal_connect_swapped(GTK_FILE_CHOOSER(d->gtkDialog()), "current-folder-changed", G_CALLBACK(onCurrentFolderChanged), this);
+}
+
+QGtk3FileDialogHelper::~QGtk3FileDialogHelper()
+{
+}
+
+bool QGtk3FileDialogHelper::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
+{
+ _dir.clear();
+ _selection.clear();
+
+ applyOptions();
+ return d->show(flags, modality, parent);
+}
+
+void QGtk3FileDialogHelper::exec()
+{
+ d->exec();
+}
+
+void QGtk3FileDialogHelper::hide()
+{
+ // After GtkFileChooserDialog has been hidden, gtk_file_chooser_get_current_folder()
+ // & gtk_file_chooser_get_filenames() will return bogus values -> cache the actual
+ // values before hiding the dialog
+ _dir = directory();
+ _selection = selectedFiles();
+
+ d->hide();
+}
+
+bool QGtk3FileDialogHelper::defaultNameFilterDisables() const
+{
+ return false;
+}
+
+void QGtk3FileDialogHelper::setDirectory(const QUrl &directory)
+{
+ GtkDialog *gtkDialog = d->gtkDialog();
+ gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(gtkDialog), directory.toLocalFile().toUtf8());
+}
+
+QUrl QGtk3FileDialogHelper::directory() const
+{
+ // While GtkFileChooserDialog is hidden, gtk_file_chooser_get_current_folder()
+ // returns a bogus value -> return the cached value before hiding
+ if (!_dir.isEmpty())
+ return _dir;
+
+ QString ret;
+ GtkDialog *gtkDialog = d->gtkDialog();
+ gchar *folder = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(gtkDialog));
+ if (folder) {
+ ret = QString::fromUtf8(folder);
+ g_free(folder);
+ }
+ return QUrl::fromLocalFile(ret);
+}
+
+void QGtk3FileDialogHelper::selectFile(const QUrl &filename)
+{
+ GtkDialog *gtkDialog = d->gtkDialog();
+ gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(gtkDialog), filename.toLocalFile().toUtf8());
+}
+
+QList<QUrl> QGtk3FileDialogHelper::selectedFiles() const
+{
+ // While GtkFileChooserDialog is hidden, gtk_file_chooser_get_filenames()
+ // returns a bogus value -> return the cached value before hiding
+ if (!_selection.isEmpty())
+ return _selection;
+
+ QList<QUrl> selection;
+ GtkDialog *gtkDialog = d->gtkDialog();
+ GSList *filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(gtkDialog));
+ for (GSList *it = filenames; it; it = it->next)
+ selection += QUrl::fromLocalFile(QString::fromUtf8((const char*)it->data));
+ g_slist_free(filenames);
+ return selection;
+}
+
+void QGtk3FileDialogHelper::setFilter()
+{
+ applyOptions();
+}
+
+void QGtk3FileDialogHelper::selectNameFilter(const QString &filter)
+{
+ GtkFileFilter *gtkFilter = _filters.value(filter);
+ if (gtkFilter) {
+ GtkDialog *gtkDialog = d->gtkDialog();
+ gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(gtkDialog), gtkFilter);
+ }
+}
+
+QString QGtk3FileDialogHelper::selectedNameFilter() const
+{
+ GtkDialog *gtkDialog = d->gtkDialog();
+ GtkFileFilter *gtkFilter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(gtkDialog));
+ return _filterNames.value(gtkFilter);
+}
+
+void QGtk3FileDialogHelper::onAccepted()
+{
+ emit accept();
+
+ QString filter = selectedNameFilter();
+ if (filter.isEmpty())
+ emit filterSelected(filter);
+
+ QList<QUrl> files = selectedFiles();
+ emit filesSelected(files);
+ if (files.count() == 1)
+ emit fileSelected(files.first());
+}
+
+void QGtk3FileDialogHelper::onSelectionChanged(GtkDialog *gtkDialog, QGtk3FileDialogHelper *helper)
+{
+ QString selection;
+ gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(gtkDialog));
+ if (filename) {
+ selection = QString::fromUtf8(filename);
+ g_free(filename);
+ }
+ emit helper->currentChanged(QUrl::fromLocalFile(selection));
+}
+
+void QGtk3FileDialogHelper::onCurrentFolderChanged(QGtk3FileDialogHelper *dialog)
+{
+ emit dialog->directoryEntered(dialog->directory());
+}
+
+static GtkFileChooserAction gtkFileChooserAction(const QSharedPointer<QFileDialogOptions> &options)
+{
+ switch (options->fileMode()) {
+ case QFileDialogOptions::AnyFile:
+ case QFileDialogOptions::ExistingFile:
+ case QFileDialogOptions::ExistingFiles:
+ if (options->acceptMode() == QFileDialogOptions::AcceptOpen)
+ return GTK_FILE_CHOOSER_ACTION_OPEN;
+ else
+ return GTK_FILE_CHOOSER_ACTION_SAVE;
+ case QFileDialogOptions::Directory:
+ case QFileDialogOptions::DirectoryOnly:
+ default:
+ if (options->acceptMode() == QFileDialogOptions::AcceptOpen)
+ return GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
+ else
+ return GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER;
+ }
+}
+
+void QGtk3FileDialogHelper::applyOptions()
+{
+ GtkDialog *gtkDialog = d->gtkDialog();
+ const QSharedPointer<QFileDialogOptions> &opts = options();
+
+ gtk_window_set_title(GTK_WINDOW(gtkDialog), opts->windowTitle().toUtf8());
+ gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(gtkDialog), true);
+
+ const GtkFileChooserAction action = gtkFileChooserAction(opts);
+ gtk_file_chooser_set_action(GTK_FILE_CHOOSER(gtkDialog), action);
+
+ const bool selectMultiple = opts->fileMode() == QFileDialogOptions::ExistingFiles;
+ gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(gtkDialog), selectMultiple);
+
+ const bool confirmOverwrite = !opts->testOption(QFileDialogOptions::DontConfirmOverwrite);
+ gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(gtkDialog), confirmOverwrite);
+
+ const QStringList nameFilters = opts->nameFilters();
+ if (!nameFilters.isEmpty())
+ setNameFilters(nameFilters);
+
+ if (opts->initialDirectory().isLocalFile())
+ setDirectory(opts->initialDirectory());
+
+ foreach (const QUrl &filename, opts->initiallySelectedFiles())
+ selectFile(filename);
+
+ const QString initialNameFilter = opts->initiallySelectedNameFilter();
+ if (!initialNameFilter.isEmpty())
+ selectNameFilter(initialNameFilter);
+
+ GtkWidget *acceptButton = gtk_dialog_get_widget_for_response(gtkDialog, GTK_RESPONSE_OK);
+ if (acceptButton) {
+ if (opts->isLabelExplicitlySet(QFileDialogOptions::Accept))
+ gtk_button_set_label(GTK_BUTTON(acceptButton), opts->labelText(QFileDialogOptions::Accept).toUtf8());
+ else if (opts->acceptMode() == QFileDialogOptions::AcceptOpen)
+ gtk_button_set_label(GTK_BUTTON(acceptButton), GTK_STOCK_OPEN);
+ else
+ gtk_button_set_label(GTK_BUTTON(acceptButton), GTK_STOCK_SAVE);
+ }
+
+ GtkWidget *rejectButton = gtk_dialog_get_widget_for_response(gtkDialog, GTK_RESPONSE_CANCEL);
+ if (rejectButton) {
+ if (opts->isLabelExplicitlySet(QFileDialogOptions::Reject))
+ gtk_button_set_label(GTK_BUTTON(rejectButton), opts->labelText(QFileDialogOptions::Reject).toUtf8());
+ else
+ gtk_button_set_label(GTK_BUTTON(rejectButton), GTK_STOCK_CANCEL);
+ }
+}
+
+void QGtk3FileDialogHelper::setNameFilters(const QStringList &filters)
+{
+ GtkDialog *gtkDialog = d->gtkDialog();
+ foreach (GtkFileFilter *filter, _filters)
+ gtk_file_chooser_remove_filter(GTK_FILE_CHOOSER(gtkDialog), filter);
+
+ _filters.clear();
+ _filterNames.clear();
+
+ foreach (const QString &filter, filters) {
+ GtkFileFilter *gtkFilter = gtk_file_filter_new();
+ const QString name = filter.left(filter.indexOf(QLatin1Char('(')));
+ const QStringList extensions = cleanFilterList(filter);
+
+ gtk_file_filter_set_name(gtkFilter, name.isEmpty() ? extensions.join(QStringLiteral(", ")).toUtf8() : name.toUtf8());
+ foreach (const QString &ext, extensions)
+ gtk_file_filter_add_pattern(gtkFilter, ext.toUtf8());
+
+ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(gtkDialog), gtkFilter);
+
+ _filters.insert(filter, gtkFilter);
+ _filterNames.insert(gtkFilter, filter);
+ }
+}
+
+QGtk3FontDialogHelper::QGtk3FontDialogHelper()
+{
+ d.reset(new QGtk3Dialog(gtk_font_chooser_dialog_new("", 0)));
+ connect(d.data(), SIGNAL(accept()), this, SLOT(onAccepted()));
+ connect(d.data(), SIGNAL(reject()), this, SIGNAL(reject()));
+}
+
+QGtk3FontDialogHelper::~QGtk3FontDialogHelper()
+{
+}
+
+bool QGtk3FontDialogHelper::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
+{
+ applyOptions();
+ return d->show(flags, modality, parent);
+}
+
+void QGtk3FontDialogHelper::exec()
+{
+ d->exec();
+}
+
+void QGtk3FontDialogHelper::hide()
+{
+ d->hide();
+}
+
+static QString qt_fontToString(const QFont &font)
+{
+ PangoFontDescription *desc = pango_font_description_new();
+ pango_font_description_set_size(desc, font.pointSizeF() * PANGO_SCALE);
+ pango_font_description_set_family(desc, font.family().toUtf8());
+
+ int weight = font.weight();
+ if (weight >= QFont::Black)
+ pango_font_description_set_weight(desc, PANGO_WEIGHT_HEAVY);
+ else if (weight >= QFont::Bold)
+ pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
+ else if (weight >= QFont::DemiBold)
+ pango_font_description_set_weight(desc, PANGO_WEIGHT_SEMIBOLD);
+ else if (weight >= QFont::Normal)
+ pango_font_description_set_weight(desc, PANGO_WEIGHT_NORMAL);
+ else
+ pango_font_description_set_weight(desc, PANGO_WEIGHT_LIGHT);
+
+ int style = font.style();
+ if (style == QFont::StyleItalic)
+ pango_font_description_set_style(desc, PANGO_STYLE_ITALIC);
+ else if (style == QFont::StyleOblique)
+ pango_font_description_set_style(desc, PANGO_STYLE_OBLIQUE);
+ else
+ pango_font_description_set_style(desc, PANGO_STYLE_NORMAL);
+
+ char *str = pango_font_description_to_string(desc);
+ QString name = QString::fromUtf8(str);
+ pango_font_description_free(desc);
+ g_free(str);
+ return name;
+}
+
+static QFont qt_fontFromString(const QString &name)
+{
+ QFont font;
+ PangoFontDescription *desc = pango_font_description_from_string(name.toUtf8());
+ font.setPointSizeF(static_cast<float>(pango_font_description_get_size(desc)) / PANGO_SCALE);
+
+ QString family = QString::fromUtf8(pango_font_description_get_family(desc));
+ if (!family.isEmpty())
+ font.setFamily(family);
+
+ int weight = pango_font_description_get_weight(desc);
+ if (weight >= PANGO_WEIGHT_HEAVY)
+ font.setWeight(QFont::Black);
+ else if (weight >= PANGO_WEIGHT_BOLD)
+ font.setWeight(QFont::Bold);
+ else if (weight >= PANGO_WEIGHT_SEMIBOLD)
+ font.setWeight(QFont::DemiBold);
+ else if (weight >= PANGO_WEIGHT_NORMAL)
+ font.setWeight(QFont::Normal);
+ else
+ font.setWeight(QFont::Light);
+
+ PangoStyle style = pango_font_description_get_style(desc);
+ if (style == PANGO_STYLE_ITALIC)
+ font.setStyle(QFont::StyleItalic);
+ else if (style == PANGO_STYLE_OBLIQUE)
+ font.setStyle(QFont::StyleOblique);
+ else
+ font.setStyle(QFont::StyleNormal);
+
+ pango_font_description_free(desc);
+ return font;
+}
+
+void QGtk3FontDialogHelper::setCurrentFont(const QFont &font)
+{
+ GtkFontChooser *gtkDialog = GTK_FONT_CHOOSER(d->gtkDialog());
+ gtk_font_chooser_set_font(gtkDialog, qt_fontToString(font).toUtf8());
+}
+
+QFont QGtk3FontDialogHelper::currentFont() const
+{
+ GtkFontChooser *gtkDialog = GTK_FONT_CHOOSER(d->gtkDialog());
+ gchar *name = gtk_font_chooser_get_font(gtkDialog);
+ QFont font = qt_fontFromString(QString::fromUtf8(name));
+ g_free(name);
+ return font;
+}
+
+void QGtk3FontDialogHelper::onAccepted()
+{
+ emit accept();
+ emit fontSelected(currentFont());
+}
+
+void QGtk3FontDialogHelper::applyOptions()
+{
+ GtkDialog *gtkDialog = d->gtkDialog();
+ const QSharedPointer<QFontDialogOptions> &opts = options();
+
+ gtk_window_set_title(GTK_WINDOW(gtkDialog), opts->windowTitle().toUtf8());
+
+ // TODO:
+// GtkWidget *okButton = gtk_font_selection_dialog_get_ok_button(GTK_FONT_SELECTION_DIALOG(gtkDialog));
+// GtkWidget *cancelButton = gtk_font_selection_dialog_get_cancel_button(GTK_FONT_SELECTION_DIALOG(gtkDialog));
+// if (okButton)
+// gtk_widget_set_visible(okButton, !options()->testOption(QFontDialogOptions::NoButtons));
+// if (cancelButton)
+// gtk_widget_set_visible(cancelButton, !options()->testOption(QFontDialogOptions::NoButtons));
+}
+
+QT_END_NAMESPACE
+
+#include "qgtk3dialoghelpers.moc"
diff --git a/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.h b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.h
new file mode 100644
index 0000000..819c041
--- /dev/null
+++ b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.h
@@ -0,0 +1,143 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** 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, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGTK3DIALOGHELPERS_H
+#define QGTK3DIALOGHELPERS_H
+
+#include <QtCore/qscopedpointer.h>
+#include <qpa/qplatformdialoghelper.h>
+
+typedef struct _GtkDialog GtkDialog;
+typedef struct _GtkFileFilter GtkFileFilter;
+
+QT_BEGIN_NAMESPACE
+
+class QGtk3Dialog;
+
+class QGtk3ColorDialogHelper : public QPlatformColorDialogHelper
+{
+ Q_OBJECT
+
+public:
+ QGtk3ColorDialogHelper();
+ ~QGtk3ColorDialogHelper();
+
+ bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent);
+ void exec();
+ void hide();
+
+ void setCurrentColor(const QColor &color);
+ QColor currentColor() const;
+
+private Q_SLOTS:
+ void onAccepted();
+
+private:
+ static void onColorChanged(QGtk3ColorDialogHelper *helper);
+ void applyOptions();
+
+ QScopedPointer<QGtk3Dialog> d;
+};
+
+class QGtk3FileDialogHelper : public QPlatformFileDialogHelper
+{
+ Q_OBJECT
+
+public:
+ QGtk3FileDialogHelper();
+ ~QGtk3FileDialogHelper();
+
+ bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent);
+ void exec();
+ void hide();
+
+ bool defaultNameFilterDisables() const;
+ void setDirectory(const QUrl &directory) Q_DECL_OVERRIDE;
+ QUrl directory() const Q_DECL_OVERRIDE;
+ void selectFile(const QUrl &filename) Q_DECL_OVERRIDE;
+ QList<QUrl> selectedFiles() const Q_DECL_OVERRIDE;
+ void setFilter();
+ void selectNameFilter(const QString &filter);
+ QString selectedNameFilter() const;
+
+private Q_SLOTS:
+ void onAccepted();
+
+private:
+ static void onSelectionChanged(GtkDialog *dialog, QGtk3FileDialogHelper *helper);
+ static void onCurrentFolderChanged(QGtk3FileDialogHelper *helper);
+ void applyOptions();
+ void setNameFilters(const QStringList &filters);
+
+ QUrl _dir;
+ QList<QUrl> _selection;
+ QHash<QString, GtkFileFilter*> _filters;
+ QHash<GtkFileFilter*, QString> _filterNames;
+ QScopedPointer<QGtk3Dialog> d;
+};
+
+class QGtk3FontDialogHelper : public QPlatformFontDialogHelper
+{
+ Q_OBJECT
+
+public:
+ QGtk3FontDialogHelper();
+ ~QGtk3FontDialogHelper();
+
+ bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent);
+ void exec();
+ void hide();
+
+ void setCurrentFont(const QFont &font);
+ QFont currentFont() const;
+
+private Q_SLOTS:
+ void onAccepted();
+
+private:
+ void applyOptions();
+
+ QScopedPointer<QGtk3Dialog> d;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGTK3DIALOGHELPERS_H
diff --git a/src/plugins/platformthemes/gtk3/qgtk3theme.cpp b/src/plugins/platformthemes/gtk3/qgtk3theme.cpp
new file mode 100644
index 0000000..b02b106
--- /dev/null
+++ b/src/plugins/platformthemes/gtk3/qgtk3theme.cpp
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** 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, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qgtk3theme.h"
+#include "qgtk3dialoghelpers.h"
+#include <QVariant>
+
+#undef signals
+#include <gtk/gtk.h>
+
+QT_BEGIN_NAMESPACE
+
+const char *QGtk3Theme::name = "gtk3";
+
+static QString gtkSetting(const gchar *propertyName)
+{
+ GtkSettings *settings = gtk_settings_get_default();
+ gchararray value;
+ g_object_get(settings, propertyName, &value, NULL);
+ QString str = QString::fromUtf8(value);
+ g_free(value);
+ return str;
+}
+
+QGtk3Theme::QGtk3Theme()
+{
+ gtk_init(0, 0);
+}
+
+QVariant QGtk3Theme::themeHint(QPlatformTheme::ThemeHint hint) const
+{
+ switch (hint) {
+ case QPlatformTheme::StyleNames: {
+ QStringList styleNames;
+ styleNames << QStringLiteral("gtk3") << QStringLiteral("fusion");
+ return QVariant(styleNames);
+ }
+ case QPlatformTheme::SystemIconThemeName:
+ return QVariant(gtkSetting("gtk-icon-theme-name"));
+ case QPlatformTheme::SystemIconFallbackThemeName:
+ return QVariant(gtkSetting("gtk-fallback-icon-theme"));
+ default:
+ return QGnomeTheme::themeHint(hint);
+ }
+}
+
+bool QGtk3Theme::usePlatformNativeDialog(DialogType type) const
+{
+ Q_UNUSED(type);
+ return true;
+}
+
+QPlatformDialogHelper *QGtk3Theme::createPlatformDialogHelper(DialogType type) const
+{
+ switch (type) {
+ case ColorDialog:
+ return new QGtk3ColorDialogHelper;
+ case FileDialog:
+ return new QGtk3FileDialogHelper;
+ case FontDialog:
+ return new QGtk3FontDialogHelper;
+ default:
+ return 0;
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/platformthemes/gtk3/qgtk3theme.h b/src/plugins/platformthemes/gtk3/qgtk3theme.h
new file mode 100644
index 0000000..1da0401
--- /dev/null
+++ b/src/plugins/platformthemes/gtk3/qgtk3theme.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** 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, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGTK3THEME_H
+#define QGTK3THEME_H
+
+#include <private/qgenericunixthemes_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGtk3Theme : public QGnomeTheme
+{
+public:
+ QGtk3Theme();
+
+ virtual QVariant themeHint(ThemeHint hint) const;
+
+ virtual bool usePlatformNativeDialog(DialogType type) const;
+ virtual QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const;
+
+ static const char *name;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGTK3THEME_H
diff --git a/src/plugins/platformthemes/platformthemes.pro b/src/plugins/platformthemes/platformthemes.pro
new file mode 100644
index 0000000..ee57b84
--- /dev/null
+++ b/src/plugins/platformthemes/platformthemes.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+packagesExist(gtk+-3.0): SUBDIRS += gtk3
diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro
index 38e0c33..8afe610 100644
--- a/src/plugins/plugins.pro
+++ b/src/plugins/plugins.pro
@@ -1,2 +1,2 @@
TEMPLATE = subdirs
-SUBDIRS = styles
+SUBDIRS = platformthemes styles