Add support for modifying GTK themes.

ubuntu/cosmic
Simon Quigley 6 years ago
parent 14204f0dcd
commit ae2282e219

1
debian/changelog vendored

@ -2,6 +2,7 @@ lxqt-config (0.13.0-0ubuntu2) UNRELEASED; urgency=medium
* Bump Standards-version to 4.1.5, no changes needed. * Bump Standards-version to 4.1.5, no changes needed.
* Change Uploaders to Ubuntu uploaders. * Change Uploaders to Ubuntu uploaders.
* Add support for modifying GTK themes.
-- Simon Quigley <tsimonq2@ubuntu.com> Mon, 30 Jul 2018 16:21:58 -0500 -- Simon Quigley <tsimonq2@ubuntu.com> Mon, 30 Jul 2018 16:21:58 -0500

@ -0,0 +1,853 @@
Description: Add the ability to set GTK themes
Author: P.L. Lucas <selairi@gmail.com>
Origin: upstream
Applied-Upstream: https://github.com/lxqt/lxqt-config/pull/244
Last-Update: 2018-07-30
--- a/lxqt-config-appearance/CMakeLists.txt
+++ b/lxqt-config-appearance/CMakeLists.txt
@@ -15,6 +15,7 @@ set(MOC_FILES
fontsconfig.h
styleconfig.h
fontconfigfile.h
+ configothertoolkits.h
)
set(CPP_FILES
@@ -25,6 +26,7 @@ set(CPP_FILES
fontsconfig.cpp
styleconfig.cpp
fontconfigfile.cpp
+ configothertoolkits.cpp
)
set(UI_FILES
--- /dev/null
+++ b/lxqt-config-appearance/configothertoolkits.cpp
@@ -0,0 +1,329 @@
+/* BEGIN_COMMON_COPYRIGHT_HEADER
+ * (c)LGPL2+
+ *
+ * LXQt - a lightweight, Qt based, desktop toolset
+ * https://lxqt.org/
+ *
+ * Copyright: 2018 LXQt team
+ *
+ * This program or library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * END_COMMON_COPYRIGHT_HEADER */
+
+#include "configothertoolkits.h"
+#include <QFile>
+#include <QTextStream>
+#include <QStandardPaths>
+#include <QMetaEnum>
+#include <QToolBar>
+#include <QDir>
+#include <QFileInfo>
+#include <QFont>
+#include <QDateTime>
+#include <QMessageBox>
+
+#include <sys/types.h>
+#include <signal.h>
+
+static const char *GTK2_CONFIG = R"GTK2_CONFIG(
+# Created by lxqt-config-appearance (DO NOT EDIT!)
+gtk-theme-name = "%1"
+gtk-icon-theme-name = "%2"
+gtk-font-name = "%3"
+gtk-button-images = %4
+gtk-menu-images = %4
+gtk-toolbar-style = %5
+)GTK2_CONFIG";
+
+static const char *GTK3_CONFIG = R"GTK3_CONFIG(
+# Created by lxqt-config-appearance (DO NOT EDIT!)
+[Settings]
+gtk-theme-name = %1
+gtk-icon-theme-name = %2
+# GTK3 ignores bold or italic attributes.
+gtk-font-name = %3
+gtk-menu-images = %4
+gtk-button-images = %4
+gtk-toolbar-style = %5
+)GTK3_CONFIG";
+
+static const char *XSETTINGS_CONFIG = R"XSETTINGS_CONFIG(
+# Created by lxqt-config-appearance (DO NOT EDIT!)
+Net/IconThemeName "%2"
+Net/ThemeName "%1"
+Gtk/FontName "%3"
+Gtk/MenuImages %4
+Gtk/ButtonImages %4
+Gtk/ToolbarStyle "%5"
+)XSETTINGS_CONFIG";
+
+ConfigOtherToolKits::ConfigOtherToolKits(LXQt::Settings *settings, LXQt::Settings *configAppearanceSettings, QObject *parent) : QObject(parent)
+{
+ mSettings = settings;
+ mConfigAppearanceSettings = configAppearanceSettings;
+ if(tempFile.open()) {
+ mXsettingsdProc.setProcessChannelMode(QProcess::ForwardedChannels);
+ mXsettingsdProc.start("xsettingsd", QStringList() << "-c" << tempFile.fileName());
+ if(!mXsettingsdProc.waitForStarted())
+ return;
+ tempFile.close();
+ }
+}
+
+ConfigOtherToolKits::~ConfigOtherToolKits()
+{
+ mXsettingsdProc.close();
+}
+
+static QString get_environment_var(const char *envvar, const char *defaultValue)
+{
+ QString homeDir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
+ QString mDirPath = QString::fromLocal8Bit(qgetenv(envvar));
+ if(mDirPath.isEmpty())
+ mDirPath = homeDir + defaultValue;
+ else {
+ for(QString path : mDirPath.split(":") ) {
+ mDirPath = path;
+ break;
+ }
+ }
+ return mDirPath;
+}
+
+static QString _get_config_path(QString path)
+{
+ QString homeDir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
+ path.replace("$XDG_CONFIG_HOME", get_environment_var("XDG_CONFIG_HOME", "/.config"));
+ path.replace("$GTK2_RC_FILES", get_environment_var("GTK2_RC_FILES", "/.gtkrc-2.0")); // If $GTK2_RC_FILES is undefined, "~/.gtkrc-2.0" will be used.
+ path.replace("~", homeDir);
+ return path;
+}
+
+QString ConfigOtherToolKits::getGTKConfigPath(QString version)
+{
+ if(version == "2.0")
+ return _get_config_path("$GTK2_RC_FILES");
+ return _get_config_path(QString("$XDG_CONFIG_HOME/gtk-%1/settings.ini").arg(version));
+}
+
+static bool grep(QFile &file, QByteArray text)
+{
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ return false;
+ while (!file.atEnd()) {
+ QByteArray line = file.readLine().trimmed();
+ if(line.startsWith(text)) {
+ return true;
+ }
+ }
+ file.close();
+ return false;
+}
+
+bool ConfigOtherToolKits::backupGTKSettings(QString version)
+{
+ QString gtkrcPath = getGTKConfigPath(version);
+ QFile file(gtkrcPath);
+ if(file.exists() && !grep(file, "# Created by lxqt-config-appearance (DO NOT EDIT!)")) {
+ QString backupPath = gtkrcPath + "-" + QString::number(QDateTime::currentSecsSinceEpoch()) + "~";
+ file.copy(backupPath);
+ QMessageBox::warning(nullptr, tr("GTK themes"),
+ tr("<p>'%1' has been overwritten.</p><p>You can find a copy of your old settings in '%2'</p>")
+ .arg(getGTKConfigPath(version))
+ .arg(backupPath)
+ , QMessageBox::Ok);
+ return true;
+ }
+ return false;
+}
+
+void ConfigOtherToolKits::setConfig()
+{
+ if(!mConfigAppearanceSettings->contains("ControlGTKThemeEnabled"))
+ mConfigAppearanceSettings->setValue("ControlGTKThemeEnabled", false);
+ bool controlGTKThemeEnabled = mConfigAppearanceSettings->value("ControlGTKThemeEnabled").toBool();
+ if(! controlGTKThemeEnabled)
+ return;
+ updateConfigFromSettings();
+ mConfig.styleTheme = getGTKThemeFromRCFile("3.0");
+ setGTKConfig("3.0");
+ mConfig.styleTheme = getGTKThemeFromRCFile("2.0");
+ setGTKConfig("2.0");
+ setXSettingsConfig();
+}
+
+void ConfigOtherToolKits::setXSettingsConfig()
+{
+ // setGTKConfig is called before calling setXSettingsConfig,
+ // then updateConfigFromSettings is not required.
+ //updateConfigFromSettings();
+ //mConfig.styleTheme = getGTKThemeFromRCFile(version);
+
+ // Reload settings. xsettingsd must be installed.
+ // xsettingsd settings are written to stdin.
+ if(QProcess::Running == mXsettingsdProc.state()) {
+ QFile file(tempFile.fileName());
+ if(file.open(QIODevice::WriteOnly)) {
+ file.write( getConfig(XSETTINGS_CONFIG).toLocal8Bit() );
+ file.flush();
+ file.close();
+ }
+ int pid = mXsettingsdProc.processId();
+ kill(pid, SIGHUP);
+ }
+}
+
+void ConfigOtherToolKits::setGTKConfig(QString version, QString theme)
+{
+ updateConfigFromSettings();
+ if(!theme.isEmpty())
+ mConfig.styleTheme = theme;
+ backupGTKSettings(version);
+ QString gtkrcPath = getGTKConfigPath(version);
+ if(version == "2.0")
+ writeConfig(gtkrcPath, GTK2_CONFIG);
+ else
+ writeConfig(gtkrcPath, GTK3_CONFIG);
+}
+
+QString ConfigOtherToolKits::getConfig(const char *configString)
+{
+ return QString(configString).arg(mConfig.styleTheme, mConfig.iconTheme,
+ mConfig.fontName, mConfig.buttonStyle==0 ? "0":"1",
+ mConfig.toolButtonStyle
+ );
+}
+
+void ConfigOtherToolKits::writeConfig(QString path, const char *configString)
+{
+ path = _get_config_path(path);
+
+ QFile file(path);
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ return;
+ }
+ QTextStream out(&file);
+ out << getConfig(configString);
+ out.flush();
+ file.close();
+}
+
+QStringList ConfigOtherToolKits::getGTKThemes(QString version)
+{
+ QStringList themeList;
+ QString configFile = version=="2.0" ? "gtk-2.0/gtkrc" : QString("gtk-%1/gtk.css").arg(version);
+
+ QStringList dataPaths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
+ for(QString dataPath : dataPaths) {
+ QDir themesPath(dataPath + "/themes");
+ QStringList themes = themesPath.entryList(QDir::Dirs);
+ for(QString theme : themes) {
+ QFileInfo themePath(QString("%1/themes/%2/%3").arg(dataPath, theme, configFile));
+ if(themePath.exists())
+ themeList.append(theme);
+ }
+ }
+ return themeList;
+}
+
+QString ConfigOtherToolKits::getGTKThemeFromRCFile(QString version)
+{
+ if(version == "2.0") {
+ QString gtkrcPath = _get_config_path("$GTK2_RC_FILES");
+ QFile file(gtkrcPath);
+ if(file.exists()) {
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ return QString();
+ while (!file.atEnd()) {
+ QByteArray line = file.readLine().trimmed();
+ if(line.startsWith("gtk-theme-name")) {
+ QList<QByteArray> parts = line.split('=');
+ if(parts.size()>=2) {
+ file.close();
+ return parts[1].replace('"', "").trimmed();
+ }
+ }
+ }
+ file.close();
+ }
+ } else {
+ QString gtkrcPath = _get_config_path(QString("$XDG_CONFIG_HOME/gtk-%1/settings.ini").arg(version));
+ QFile file(gtkrcPath);
+ if(file.exists()) {
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ return QString();
+ bool settingsFound = false;
+ while (!file.atEnd()) {
+ QByteArray line = file.readLine().trimmed();
+ if(line.startsWith("[Settings]"))
+ settingsFound = true;
+ else if(line.startsWith("[") && line.endsWith("]"))
+ settingsFound = false;
+ else if(settingsFound && line.startsWith("gtk-theme-name")) {
+ QList<QByteArray> parts = line.split('=');
+ if(parts.size()>=2) {
+ file.close();
+ return parts[1].trimmed();
+ }
+ }
+ }
+ file.close();
+ }
+ }
+ return QString();
+}
+
+void ConfigOtherToolKits::updateConfigFromSettings()
+{
+ mSettings->beginGroup(QLatin1String("Qt"));
+ QFont font;
+ font.fromString(mSettings->value("font").toString());
+ // Font name from: https://developer.gnome.org/pango/stable/pango-Fonts.html#pango-font-description-from-string
+ // FAMILY-LIST [SIZE]", where FAMILY-LIST is a comma separated list of families optionally terminated by a comma,
+ // STYLE_OPTIONS is a whitespace separated list of words where each word describes one of style, variant, weight, stretch, or gravity, and
+ // SIZE is a decimal number (size in points) or optionally followed by the unit modifier "px" for absolute size.
+ mConfig.fontName = QString("%1%2%3 %4")
+ .arg(font.family()) //%1
+ .arg(font.style()==QFont::StyleNormal?"":" Italic") //%2
+ .arg(font.weight()==QFont::Normal?"":" Bold") //%3
+ .arg(font.pointSize()); //%4
+ mSettings->endGroup();
+
+ mConfig.iconTheme = mSettings->value("icon_theme").toString();
+ {
+ // Tool button style
+ QByteArray tb_style = mSettings->value("tool_button_style").toByteArray();
+ // convert toolbar style name to value
+ QMetaEnum me = QToolBar::staticMetaObject.property(QToolBar::staticMetaObject.indexOfProperty("toolButtonStyle")).enumerator();
+ int val = me.keyToValue(tb_style.constData());
+ mConfig.buttonStyle = 1;
+ switch(val) {
+ case Qt::ToolButtonIconOnly:
+ mConfig.toolButtonStyle = "GTK_TOOLBAR_ICONS";
+ break;
+ case Qt::ToolButtonTextOnly:
+ mConfig.toolButtonStyle = "GTK_TOOLBAR_TEXT";
+ mConfig.buttonStyle = 0;
+ break;
+ case Qt::ToolButtonTextUnderIcon:
+ mConfig.toolButtonStyle = "GTK_TOOLBAR_BOTH";
+ break;
+ default:
+ mConfig.toolButtonStyle = "GTK_TOOLBAR_BOTH_HORIZ";
+ }
+ }
+}
+
--- /dev/null
+++ b/lxqt-config-appearance/configothertoolkits.h
@@ -0,0 +1,70 @@
+/* BEGIN_COMMON_COPYRIGHT_HEADER
+ * (c)LGPL2+
+ *
+ * LXQt - a lightweight, Qt based, desktop toolset
+ * https://lxqt.org
+ *
+ * Copyright: 2018 LXQt team
+ *
+ * This program or library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * END_COMMON_COPYRIGHT_HEADER */
+
+#ifndef CONFIGOTHERTOOLKITS_H
+#define CONFIGOTHERTOOLKITS_H
+
+#include <QWidget>
+#include <QProcess>
+#include <QTemporaryFile>
+#include <LXQt/Settings>
+
+class ConfigOtherToolKits : public QObject
+{
+ Q_OBJECT
+
+public:
+ ConfigOtherToolKits(LXQt::Settings *settings, LXQt::Settings *configAppearanceSettings, QObject *parent = 0);
+ ~ConfigOtherToolKits();
+ QStringList getGTKThemes(QString version);
+ QString getGTKThemeFromRCFile(QString version);
+ QString getGTKConfigPath(QString version);
+ bool backupGTKSettings(QString version);
+
+public slots:
+ void setConfig();
+ void setXSettingsConfig();
+ void setGTKConfig(QString version, QString theme = QString());
+
+private:
+ struct Config {
+ QString iconTheme;
+ QString styleTheme;
+ QString fontName;
+ QString toolButtonStyle;
+ int buttonStyle;
+ } mConfig;
+ void writeConfig(QString path, const char *configString);
+ QString getConfig(const char *configString);
+ void updateConfigFromSettings();
+
+ LXQt::Settings *mSettings;
+ LXQt::Settings *mConfigAppearanceSettings;
+
+ QProcess mXsettingsdProc;
+ QTemporaryFile tempFile;
+};
+
+#endif // CONFIGOTHERTOOLKITS_H
--- a/lxqt-config-appearance/fontconfigfile.h
+++ b/lxqt-config-appearance/fontconfigfile.h
@@ -64,6 +64,7 @@ public:
}
void setAutohint(bool value);
+
private Q_SLOTS:
void save();
--- a/lxqt-config-appearance/fontsconfig.cpp
+++ b/lxqt-config-appearance/fontsconfig.cpp
@@ -188,6 +188,8 @@ void FontsConfig::updateQtFont()
mQtSettings->endGroup();
mQtSettings->sync();
+ emit updateSettings();
+
#ifdef Q_WS_X11
qt_x11_apply_settings_in_all_apps();
#endif
--- a/lxqt-config-appearance/fontsconfig.h
+++ b/lxqt-config-appearance/fontsconfig.h
@@ -51,6 +51,9 @@ public:
public Q_SLOTS:
void initControls();
+signals:
+ void updateSettings();
+
private Q_SLOTS:
void updateQtFont();
void antialiasToggled(bool toggled);
--- a/lxqt-config-appearance/iconthemeconfig.cpp
+++ b/lxqt-config-appearance/iconthemeconfig.cpp
@@ -151,5 +151,7 @@ void IconThemeConfig::iconThemeSelected(
m_settings->setValue("icon_theme", theme);
m_settings->sync();
+
+ emit updateSettings();
}
}
--- a/lxqt-config-appearance/iconthemeconfig.h
+++ b/lxqt-config-appearance/iconthemeconfig.h
@@ -51,6 +51,9 @@ private:
public slots:
void initControls();
+signals:
+ void updateSettings();
+
private slots:
void iconThemeSelected(QTreeWidgetItem *item, int column);
};
--- a/lxqt-config-appearance/main.cpp
+++ b/lxqt-config-appearance/main.cpp
@@ -34,6 +34,7 @@
#include "lxqtthemeconfig.h"
#include "styleconfig.h"
#include "fontsconfig.h"
+#include "configothertoolkits.h"
#include "../liblxqt-config-cursor/selectwnd.h"
@@ -58,14 +59,19 @@ int main (int argc, char **argv)
app.setActivationWindow(dialog);
+ LXQt::Settings mConfigAppearanceSettings("lxqt-config-appearance");
+ ConfigOtherToolKits *configOtherToolKits = new ConfigOtherToolKits(settings, &mConfigAppearanceSettings, dialog);
+
QSettings& qtSettings = *settings; // use lxqt config file for Qt settings in Qt5.
- StyleConfig* stylePage = new StyleConfig(settings, &qtSettings, dialog);
+ StyleConfig* stylePage = new StyleConfig(settings, &qtSettings, &mConfigAppearanceSettings, configOtherToolKits, dialog);
dialog->addPage(stylePage, QObject::tr("Widget Style"), QStringList() << "preferences-desktop-theme" << "preferences-desktop");
QObject::connect(dialog, SIGNAL(reset()), stylePage, SLOT(initControls()));
+ QObject::connect(stylePage, SIGNAL(updateSettings()), configOtherToolKits, SLOT(setConfig()));
IconThemeConfig* iconPage = new IconThemeConfig(settings, dialog);
dialog->addPage(iconPage, QObject::tr("Icons Theme"), QStringList() << "preferences-desktop-icons" << "preferences-desktop");
QObject::connect(dialog, SIGNAL(reset()), iconPage, SLOT(initControls()));
+ QObject::connect(iconPage, SIGNAL(updateSettings()), configOtherToolKits, SLOT(setConfig()));
LXQtThemeConfig* themePage = new LXQtThemeConfig(settings, dialog);
dialog->addPage(themePage, QObject::tr("LXQt Theme"), QStringList() << "preferences-desktop-color" << "preferences-desktop");
@@ -74,6 +80,7 @@ int main (int argc, char **argv)
FontsConfig* fontsPage = new FontsConfig(settings, &qtSettings, dialog);
dialog->addPage(fontsPage, QObject::tr("Font"), QStringList() << "preferences-desktop-font" << "preferences-desktop");
QObject::connect(dialog, SIGNAL(reset()), fontsPage, SLOT(initControls()));
+ QObject::connect(fontsPage, SIGNAL(updateSettings()), configOtherToolKits, SLOT(setConfig()));
SelectWnd* cursorPage = new SelectWnd(sessionSettings, dialog);
cursorPage->setCurrent();
--- a/lxqt-config-appearance/styleconfig.cpp
+++ b/lxqt-config-appearance/styleconfig.cpp
@@ -41,25 +41,23 @@
extern void qt_x11_apply_settings_in_all_apps();
#endif
-StyleConfig::StyleConfig(LXQt::Settings* settings, QSettings* qtSettings, QWidget* parent) :
+StyleConfig::StyleConfig(LXQt::Settings* settings, QSettings* qtSettings, LXQt::Settings *configAppearanceSettings, ConfigOtherToolKits *configOtherToolKits, QWidget* parent) :
QWidget(parent),
ui(new Ui::StyleConfig),
mQtSettings(qtSettings),
mSettings(settings)
{
+ mConfigAppearanceSettings = configAppearanceSettings;
+ mConfigOtherToolKits = configOtherToolKits;
ui->setupUi(this);
- connect(ui->styleList, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
- this, SLOT(styleSelected(QTreeWidgetItem*,int)));
+ initControls();
- const auto keys = QStyleFactory::keys();
- for(const QString& name : keys)
- {
- QTreeWidgetItem *item = new QTreeWidgetItem(QStringList(name));
- ui->styleList->addTopLevelItem(item);
- }
+ connect(ui->gtk2ComboBox, SIGNAL(activated(const QString &)), this, SLOT(gtk2StyleSelected(const QString &)));
+ connect(ui->gtk3ComboBox, SIGNAL(activated(const QString &)), this, SLOT(gtk3StyleSelected(const QString &)));
+ connect(ui->qtComboBox, SIGNAL(activated(const QString &)), this, SLOT(qtStyleSelected(const QString &)));
- initControls();
+ connect(ui->advancedOptionsGroupBox, SIGNAL(toggled(bool)), this, SLOT(showAdvancedOptions(bool)));
connect(ui->toolButtonStyle, SIGNAL(currentIndexChanged(int)), SLOT(toolButtonStyleSelected(int)));
connect(ui->singleClickActivate, SIGNAL(toggled(bool)), SLOT(singleClickActivateToggled(bool)));
@@ -74,22 +72,20 @@ StyleConfig::~StyleConfig()
void StyleConfig::initControls()
{
- // read Qt style settings from Qt Trolltech.conf config
- mQtSettings->beginGroup(QLatin1String("Qt"));
- QString currentTheme = mQtSettings->value("style").toString();
- mQtSettings->endGroup();
- QTreeWidgetItemIterator it(ui->styleList);
- while (*it) {
- if ((*it)->data(0, Qt::DisplayRole).toString() == currentTheme)
- {
- ui->styleList->setCurrentItem((*it));
- break;
- }
- ++it;
- }
+ // Fill global themes
+ QStringList qtThemes = QStyleFactory::keys();
+ QStringList gtk2Themes = mConfigOtherToolKits->getGTKThemes("2.0");
+ QStringList gtk3Themes = mConfigOtherToolKits->getGTKThemes("3.0");
+
+ if(!mConfigAppearanceSettings->contains("ControlGTKThemeEnabled"))
+ mConfigAppearanceSettings->setValue("ControlGTKThemeEnabled", false);
+ bool controlGTKThemeEnabled = mConfigAppearanceSettings->value("ControlGTKThemeEnabled").toBool();
+
+ showAdvancedOptions(controlGTKThemeEnabled);
+ ui->advancedOptionsGroupBox->setChecked(controlGTKThemeEnabled);
- // read other widget related settings form LXQt settings.
+ // read other widget related settings from LXQt settings.
QByteArray tb_style = mSettings->value("tool_button_style").toByteArray();
// convert toolbar style name to value
QMetaEnum me = QToolBar::staticMetaObject.property(QToolBar::staticMetaObject.indexOfProperty("toolButtonStyle")).enumerator();
@@ -101,24 +97,21 @@ void StyleConfig::initControls()
// activate item views with single click
ui->singleClickActivate->setChecked( mSettings->value("single_click_activate", false).toBool());
- update();
-}
+ // Fill Qt themes
+ ui->qtComboBox->addItems(qtThemes);
-void StyleConfig::styleSelected(QTreeWidgetItem* item, int column)
-{
- Q_UNUSED(column);
- if (!item)
- return;
- QVariant themeName = item->data(0, Qt::DisplayRole);
- mQtSettings->beginGroup(QLatin1String("Qt"));
- mQtSettings->setValue("style", themeName);
- mQtSettings->endGroup();
- mQtSettings->sync();
+ // Fill GTK themes
+ ui->gtk2ComboBox->addItems(gtk2Themes);
+ ui->gtk3ComboBox->addItems(gtk3Themes);
+
+ ui->gtk2ComboBox->setCurrentText(mConfigOtherToolKits->getGTKThemeFromRCFile("2.0"));
+ ui->gtk3ComboBox->setCurrentText(mConfigOtherToolKits->getGTKThemeFromRCFile("3.0"));
+ mSettings->beginGroup(QLatin1String("Qt"));
+ ui->qtComboBox->setCurrentText(mSettings->value("style").toString());
+ mSettings->endGroup();
-#ifdef Q_WS_X11
- qt_x11_apply_settings_in_all_apps();
-#endif
+ update();
}
void StyleConfig::toolButtonStyleSelected(int index)
@@ -131,7 +124,8 @@ void StyleConfig::toolButtonStyleSelecte
if(str)
{
mSettings->setValue("tool_button_style", str);
- mSettings->sync();
+ mSettings->sync();
+ emit updateSettings();
}
}
@@ -141,3 +135,28 @@ void StyleConfig::singleClickActivateTog
mSettings->sync();
}
+void StyleConfig::qtStyleSelected(const QString &themeName)
+{
+ mQtSettings->beginGroup(QLatin1String("Qt"));
+ mQtSettings->setValue("style", themeName);
+ mQtSettings->endGroup();
+ mQtSettings->sync();
+}
+
+void StyleConfig::gtk3StyleSelected(const QString &themeName)
+{
+ mConfigOtherToolKits->setGTKConfig("3.0", themeName);
+ mConfigOtherToolKits->setXSettingsConfig();
+}
+
+void StyleConfig::gtk2StyleSelected(const QString &themeName)
+{
+ mConfigOtherToolKits->setGTKConfig("2.0", themeName);
+ mConfigOtherToolKits->setXSettingsConfig();
+}
+
+void StyleConfig::showAdvancedOptions(bool on)
+{
+ ui->uniformThemeLabel->setVisible(on);
+ mConfigAppearanceSettings->setValue("ControlGTKThemeEnabled", on);
+}
--- a/lxqt-config-appearance/styleconfig.h
+++ b/lxqt-config-appearance/styleconfig.h
@@ -30,6 +30,7 @@
#include <QWidget>
#include <LXQt/Settings>
+#include "configothertoolkits.h"
class QTreeWidgetItem;
class QSettings;
@@ -43,14 +44,24 @@ class StyleConfig : public QWidget
Q_OBJECT
public:
- explicit StyleConfig(LXQt::Settings *settings, QSettings *qtSettings, QWidget *parent = 0);
+ explicit StyleConfig(LXQt::Settings *settings,
+ QSettings *qtSettings, LXQt::Settings *configAppearanceSettings,
+ ConfigOtherToolKits *configOtherToolKits, QWidget *parent = 0);
~StyleConfig();
public slots:
void initControls();
+signals:
+ void updateSettings();
+
private slots:
- void styleSelected(QTreeWidgetItem* item, int column);
+ void gtk2StyleSelected(const QString &themeName);
+ void gtk3StyleSelected(const QString &themeName);
+ void qtStyleSelected(const QString &themeName);
+
+ void showAdvancedOptions(bool on);
+
void toolButtonStyleSelected(int index);
void singleClickActivateToggled(bool toggled);
@@ -58,6 +69,8 @@ private:
Ui::StyleConfig *ui;
QSettings *mQtSettings;
LXQt::Settings *mSettings;
+ LXQt::Settings *mConfigAppearanceSettings;
+ ConfigOtherToolKits *mConfigOtherToolKits;
};
#endif // STYLECONFIG_H
--- a/lxqt-config-appearance/styleconfig.ui
+++ b/lxqt-config-appearance/styleconfig.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>490</width>
- <height>363</height>
+ <width>609</width>
+ <height>344</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
@@ -24,38 +24,83 @@
</property>
</widget>
</item>
- <item row="1" column="0" colspan="2">
- <widget class="QTreeWidget" name="styleList">
+ <item row="4" column="0" colspan="2">
+ <widget class="QGroupBox" name="advancedOptionsGroupBox">
<property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
- <verstretch>1</verstretch>
+ <verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="alternatingRowColors">
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="title">
+ <string>Set GTK themes (GTK configuration files will be overwritten!)</string>
+ </property>
+ <property name="checkable">
<bool>true</bool>
</property>
- <property name="rootIsDecorated">
+ <property name="checked">
<bool>false</bool>
</property>
- <attribute name="headerVisible">
- <bool>false</bool>
- </attribute>
- <column>
- <property name="text">
- <string notr="true">1</string>
- </property>
- </column>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QFormLayout" name="formLayout_2">
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>GTK 3 Theme</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QComboBox" name="gtk3ComboBox"/>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>GTK 2 Theme</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="gtk2ComboBox"/>
+ </item>
+ <item row="3" column="1">
+ <widget class="QLabel" name="uniformThemeLabel">
+ <property name="text">
+ <string>To attempt uniform theming, either select similar style/theme
+(if available) across all lists, or select 'gtk2' Qt style (if available)
+ to mimic GTK themes.
+
+Make sure 'xsettingsd' is installed to help GTK applications apply
+themes on the fly.</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
</widget>
</item>
- <item row="2" column="0">
+ <item row="5" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Toolbar button style:</string>
</property>
</widget>
</item>
- <item row="2" column="1">
+ <item row="5" column="1">
<widget class="QComboBox" name="toolButtonStyle">
<item>
<property name="text">
@@ -84,13 +129,23 @@
</item>
</widget>
</item>
- <item row="3" column="0" colspan="2">
+ <item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="singleClickActivate">
<property name="text">
<string>Activate item on single click</string>
</property>
</widget>
</item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="qtComboBox"/>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>Qt Style</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<resources/>

@ -0,0 +1 @@
gtk-appearance-settings.patch
Loading…
Cancel
Save