aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/themetuner.cpp
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2015-05-12 16:19:40 -0400
committerLibravatarUnit 193 <unit193@ubuntu.com>2015-05-12 16:19:40 -0400
commit9618f0ebbf4b88045247c01ce8c8f58203508ebf (patch)
tree20c9894691353ee8bab4eec668e9b0b6c6426e0f /SQLiteStudio3/guiSQLiteStudio/themetuner.cpp
parenta308f430f694423064ebc86fd0506c8c6fdb3d93 (diff)
Imported Upstream version 3.0.6upstream/3.0.6
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/themetuner.cpp')
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/themetuner.cpp125
1 files changed, 125 insertions, 0 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/themetuner.cpp b/SQLiteStudio3/guiSQLiteStudio/themetuner.cpp
new file mode 100644
index 0000000..e48865f
--- /dev/null
+++ b/SQLiteStudio3/guiSQLiteStudio/themetuner.cpp
@@ -0,0 +1,125 @@
+#include "themetuner.h"
+#include "uiconfig.h"
+#include "mainwindow.h"
+#include "uiconfig.h"
+#include <QApplication>
+#include <QFile>
+#include <QStyle>
+#include <QDebug>
+
+ThemeTuner* ThemeTuner::instance = nullptr;
+
+ThemeTuner::ThemeTuner(QObject* parent) :
+ QObject(parent)
+{
+ init();
+}
+
+void ThemeTuner::tuneTheme(const QString& themeName)
+{
+ tuneCss(themeName);
+}
+
+void ThemeTuner::tuneCurrentTheme()
+{
+ tuneTheme(QApplication::style()->objectName());
+}
+
+void ThemeTuner::manageCompactLayout(QWidget* w)
+{
+ manageCompactLayout(QList<QWidget*>({w}));
+}
+
+void ThemeTuner::manageCompactLayout(QList<QWidget*> wList)
+{
+ widgetsForCompactLayout += wList;
+ for (QWidget* w : wList)
+ connect(w, SIGNAL(destroyed()), this, SLOT(handleWidgetDestroyed()));
+
+ handleCompactLayoutChange(CFG_UI.General.CompactLayout.get());
+}
+
+QString ThemeTuner::getDefaultCss(const QString& themeName) const
+{
+ QString css = defaultGeneralCss;
+ QString lowerTheme = themeName.toLower();
+ if (!themeName.isNull() && defaultPerStyleCss.contains(lowerTheme))
+ css += "\n" + defaultPerStyleCss[lowerTheme];
+
+ return css;
+}
+
+ThemeTuner* ThemeTuner::getInstance()
+{
+ if (!instance)
+ instance = new ThemeTuner();
+
+ return instance;
+}
+
+void ThemeTuner::cleanUp()
+{
+ if (instance)
+ safe_delete(instance);
+}
+
+void ThemeTuner::init()
+{
+ QFile f(":/css/general.css");
+ if (!f.open(QIODevice::ReadOnly))
+ {
+ qCritical() << "Could not open general.css";
+ return;
+ }
+
+ defaultGeneralCss = QString::fromLatin1(f.readAll());
+ f.close();
+
+ connect(CFG_UI.General.CompactLayout, SIGNAL(changed(QVariant)), this, SLOT(handleCompactLayoutChange(QVariant)));
+}
+
+void ThemeTuner::tuneCss(const QString& themeName)
+{
+ if (!CFG_UI.General.CustomCss.get().isNull())
+ {
+ applyCss(CFG_UI.General.CustomCss.get());
+ return;
+ }
+
+ applyCss(getDefaultCss(themeName));
+}
+
+void ThemeTuner::applyCss(const QString& css)
+{
+ MAINWINDOW->setStyleSheet(css);
+}
+
+void ThemeTuner::handleWidgetDestroyed()
+{
+ QWidget* w = dynamic_cast<QWidget*>(sender());
+ if (!w)
+ return;
+
+ widgetsForCompactLayout.removeOne(w);
+}
+
+void ThemeTuner::handleCompactLayoutChange(const QVariant& newValue)
+{
+ if (newValue.toBool())
+ {
+ for (QWidget* w : widgetsForCompactLayout)
+ {
+ w->layout()->setContentsMargins(0, 0, 0, 0);
+ w->layout()->setSpacing(0);
+ }
+ }
+ else
+ {
+ for (QWidget* w : widgetsForCompactLayout)
+ {
+ w->layout()->setContentsMargins(-1, -1, -1, -1);
+ w->layout()->setSpacing(-1);
+ }
+ }
+}
+