Cleanup & simplify color theme handling

parent 08e8497d
......@@ -198,7 +198,7 @@ void AssetPanel::updatePalette()
// static
const QString AssetPanel::getStyleSheet()
{
KColorScheme scheme(QApplication::palette().currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
KColorScheme scheme(QApplication::palette().currentColorGroup(), KColorScheme::View);
QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
QColor hgh = KColorUtils::mix(QApplication::palette().window().color(), selected_bg, 0.2);
QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
......
......@@ -44,7 +44,7 @@ KeyframeView::KeyframeView(std::shared_ptr<KeyframeModelList> model, QWidget *pa
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum));
setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
QPalette p = palette();
KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window);
m_colSelected = palette().highlight().color();
m_colKeyframe = scheme.foreground(KColorScheme::NormalText).color();
m_size = QFontInfo(font()).pixelSize() * 1.8;
......
......@@ -240,7 +240,7 @@ SmallJobLabel::SmallJobLabel(QWidget *parent)
const QString SmallJobLabel::getStyleSheet(const QPalette &p)
{
KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window);
QColor bg = scheme.background(KColorScheme::LinkBackground).color();
QColor fg = scheme.foreground(KColorScheme::LinkText).color();
QString style =
......
......@@ -233,7 +233,7 @@ RenderWidget::RenderWidget(const QString &projectfolder, bool enableProxy, QWidg
m_view.checkTwoPass->setEnabled(false);
m_view.proxy_render->setHidden(!enableProxy);
connect(m_view.proxy_render, &QCheckBox::toggled, this, &RenderWidget::slotProxyWarn);
KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window);
QColor bg = scheme.background(KColorScheme::NegativeBackground).color();
m_view.errorBox->setStyleSheet(
QStringLiteral("QGroupBox { background-color: rgb(%1, %2, %3); border-radius: 5px;}; ").arg(bg.red()).arg(bg.green()).arg(bg.blue()));
......
......@@ -254,7 +254,7 @@ DvdWizardMenu::DvdWizardMenu(DVDFORMAT format, QWidget *parent)
connect(m_scene, &DvdScene::sceneChanged, this, &QWizardPage::completeChanged);
// red background for error message
KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window);
QPalette p = m_view.error_message->palette();
p.setColor(QPalette::Background, scheme.background(KColorScheme::NegativeBackground).color());
m_view.error_message->setAutoFillBackground(true);
......
......@@ -55,7 +55,7 @@ AnimKeyframeRuler::AnimKeyframeRuler(int min, int max, QWidget *parent)
m_lineHeight = m_size / 2;
setMinimumHeight(m_size);
setMaximumHeight(m_size);
KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window);
m_selected = palette().highlight().color();
m_keyframe = scheme.foreground(KColorScheme::LinkText).color();
}
......
......@@ -1245,7 +1245,7 @@ void EffectStackView2::setKeyframes(const QString &tag, const QString &keyframes
// static
const QString EffectStackView2::getStyleSheet()
{
KColorScheme scheme(QApplication::palette().currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
KColorScheme scheme(QApplication::palette().currentColorGroup(), KColorScheme::View);
QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
QColor hgh = KColorUtils::mix(QApplication::palette().window().color(), selected_bg, 0.2);
QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
......
......@@ -52,7 +52,7 @@ KeyframeHelper::KeyframeHelper(QWidget *parent)
m_lineHeight = m_size / 2;
setMinimumHeight(m_size);
setMaximumHeight(m_size);
KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window);
m_selected = scheme.decoration(KColorScheme::HoverColor).color();
m_keyframe = scheme.foreground(KColorScheme::LinkText).color();
}
......
......@@ -793,11 +793,6 @@
<default></default>
</entry>
<entry name="colortheme" type="String">
<label>Name of the chosen color theme.</label>
<default></default>
</entry>
<entry name="widgetstyle" type="String">
<label>Name of the chosen widget style.</label>
<default></default>
......
......@@ -84,6 +84,9 @@ int main(int argc, char *argv[])
qCDebug(KDENLIVE_LOG) << "Non KDE Desktop detected, forcing Breeze icon theme";
}
}
// Set breeze dark as default on first opening
KConfigGroup cg(config, "UiSettings");
cg.writeEntry("ColorScheme", "Breeze Dark");
}
// Init DBus services
......
......@@ -165,16 +165,14 @@ MainWindow::MainWindow(QWidget *parent)
void MainWindow::init()
{
QString desktopStyle = QApplication::style()->objectName();
// Init color theme
KActionMenu *themeAction = new KActionMenu(i18n("Theme"), this);
ThemeManager::instance()->setThemeMenuAction(themeAction);
ThemeManager::instance()->setCurrentTheme(KdenliveSettings::colortheme());
connect(ThemeManager::instance(), &ThemeManager::signalThemeChanged, this, &MainWindow::slotThemeChanged, Qt::DirectConnection);
// Load themes
auto themeManager = new ThemeManager(actionCollection());
actionCollection()->addAction(QStringLiteral("themes_menu"), themeManager);
connect(themeManager, &ThemeManager::themeChanged, this, &MainWindow::slotThemeChanged);
if (!KdenliveSettings::widgetstyle().isEmpty() && QString::compare(desktopStyle, KdenliveSettings::widgetstyle(), Qt::CaseInsensitive) != 0) {
// User wants a custom widget style, init
doChangeStyle();
} else {
ThemeManager::instance()->slotChangePalette();
}
// Widget themes for non KDE users
......@@ -303,7 +301,6 @@ void MainWindow::init()
// Audio spectrum scope
m_audioSpectrum = new AudioGraphSpectrum(pCore->monitorManager());
QDockWidget *spectrumDock = addDock(i18n("Audio Spectrum"), QStringLiteral("audiospectrum"), m_audioSpectrum);
connect(this, &MainWindow::reloadTheme, m_audioSpectrum, &AudioGraphSpectrum::refreshPixmap);
// Close library and audiospectrum on first run
libraryDock->close();
spectrumDock->close();
......@@ -363,7 +360,6 @@ void MainWindow::init()
m_undoViewDock = addDock(i18n("Undo History"), QStringLiteral("undo_history"), m_undoView);
// Color and icon theme stuff
addAction(QStringLiteral("themes_menu"), themeAction);
connect(m_commandStack, &QUndoGroup::cleanChanged, m_saveAction, &QAction::setDisabled);
addAction(QStringLiteral("styles_menu"), stylesAction);
......@@ -620,7 +616,6 @@ void MainWindow::init()
KdenliveSettings::setCurrenttmpfolder(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
QTimer::singleShot(0, this, &MainWindow::GUISetupDone);
connect(this, &MainWindow::reloadTheme, this, &MainWindow::slotReloadTheme, Qt::UniqueConnection);
#ifdef USE_JOGSHUTTLE
new JogManager(this);
......@@ -629,30 +624,16 @@ void MainWindow::init()
// m_messageLabel->setMessage(QStringLiteral("This is a beta version. Always backup your data"), MltError);
}
void MainWindow::slotThemeChanged(const QString &theme)
void MainWindow::slotThemeChanged(const QString &name)
{
disconnect(this, &MainWindow::reloadTheme, this, &MainWindow::slotReloadTheme);
KSharedConfigPtr config = KSharedConfig::openConfig(theme);
KSharedConfigPtr config = KSharedConfig::openConfig(name);
QPalette plt = KColorScheme::createApplicationPalette(config);
setPalette(plt);
qApp->setPalette(palette());
//qApp->setPalette(plt);
// Required for qml palette change
QGuiApplication::setPalette(plt);
KdenliveSettings::setColortheme(theme);
QColor background = plt.window().color();
bool useDarkIcons = background.value() < 100;
KSharedConfigPtr kconfig = KSharedConfig::openConfig();
KConfigGroup initialGroup(kconfig, "version");
if (initialGroup.exists() && KdenliveSettings::force_breeze() && useDarkIcons != KdenliveSettings::use_dark_breeze()) {
// We need to reload icon theme
KdenliveSettings::setUse_dark_breeze(useDarkIcons);
if (KMessageBox::warningContinueCancel(this, i18n("Kdenlive needs to be restarted to apply color theme change. Restart now ?")) ==
KMessageBox::Continue) {
slotRestart();
}
}
if (m_assetPanel) {
m_assetPanel->updatePalette();
......@@ -671,8 +652,21 @@ void MainWindow::slotThemeChanged(const QString &theme)
}
if (m_timelineTabs) {
m_timelineTabs->setPalette(plt);
getMainTimeline()->controller()->getModel()->_resetView();
}
if (m_audioSpectrum) {
m_audioSpectrum->refreshPixmap();
}
KSharedConfigPtr kconfig = KSharedConfig::openConfig();
KConfigGroup initialGroup(kconfig, "version");
if (initialGroup.exists() && KdenliveSettings::force_breeze() && useDarkIcons != KdenliveSettings::use_dark_breeze()) {
// We need to reload icon theme
QIcon::setThemeName(useDarkIcons ? QStringLiteral("breeze-dark") : QStringLiteral("breeze"));
KdenliveSettings::setUse_dark_breeze(useDarkIcons);
}
#if KXMLGUI_VERSION_MINOR < 23 && KXMLGUI_VERSION_MAJOR == 5
// Not required anymore with auto colored icons since KF5 5.23
QColor background = plt.window().color();
......@@ -710,20 +704,6 @@ void MainWindow::slotThemeChanged(const QString &theme)
m_themeInitialized = true;
m_isDarkTheme = useDarkIcons;
#endif
connect(this, &MainWindow::reloadTheme, this, &MainWindow::slotReloadTheme, Qt::UniqueConnection);
}
bool MainWindow::event(QEvent *e)
{
switch (e->type()) {
case QEvent::ApplicationPaletteChange:
emit reloadTheme();
e->accept();
break;
default:
break;
}
return KXmlGuiWindow::event(e);
}
void MainWindow::updateActionsToolTip()
......@@ -754,11 +734,6 @@ void MainWindow::updateAction()
action->setToolTip(i18nc("@info:tooltip Tooltip of toolbar button", "%1 (%2)", strippedTooltip, action->shortcut().toString()));
}
void MainWindow::slotReloadTheme()
{
ThemeManager::instance()->slotSettingsChanged();
}
MainWindow::~MainWindow()
{
pCore->prepareShutdown();
......@@ -1668,8 +1643,6 @@ bool MainWindow::readOptions()
if (!initialGroup.exists() || KdenliveSettings::sdlAudioBackend().isEmpty()) {
// First run, check if user is on a KDE Desktop
firstRun = true;
// Check color theme
ThemeManager::instance()->initDarkTheme();
// this is our first run, show Wizard
QPointer<Wizard> w = new Wizard(true, false);
if (w->exec() == QDialog::Accepted && w->isOk()) {
......@@ -3837,8 +3810,6 @@ void MainWindow::doChangeStyle()
newStyle = defaultStyle("Breeze");
}
QApplication::setStyle(QStyleFactory::create(newStyle));
// Changing widget style resets color theme, so update color theme again
ThemeManager::instance()->slotChangePalette();
}
bool MainWindow::isTabbedWith(QDockWidget *widget, const QString &otherWidget)
......
......@@ -226,7 +226,6 @@ private:
/** @brief initialize startup values, return true if first run. */
bool readOptions();
void saveOptions();
bool event(QEvent *e) override;
void loadGenerators();
/** @brief Instantiates a "Get Hot New Stuff" dialog.
......@@ -433,8 +432,7 @@ private slots:
/** @brief Move playhead to mouse curser position if defined key is pressed */
void slotAlignPlayheadToMousePos();
void slotThemeChanged(const QString &);
void slotReloadTheme();
void slotThemeChanged(const QString &name);
/** @brief Close Kdenlive and try to restart it */
void slotRestart();
void triggerKey(QKeyEvent *ev);
......@@ -476,7 +474,6 @@ signals:
Q_SCRIPTABLE void abortRenderJob(const QString &url);
void configurationChanged();
void GUISetupDone();
void reloadTheme();
void setPreviewProgress(int);
void setRenderProgress(int);
void displayMessage(const QString &, MessageType, int);
......
......@@ -39,7 +39,7 @@ SimpleTimelineWidget::SimpleTimelineWidget(QWidget *parent)
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum));
setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
QPalette p = palette();
KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window);
m_colSelected = palette().highlight().color();
m_colKeyframe = scheme.foreground(KColorScheme::NormalText).color();
m_size = QFontInfo(font()).pixelSize() * 1.8;
......
......@@ -200,7 +200,7 @@ bool StatusBarMessageLabel::slotMessageTimeout()
}
QColor bgColor =
KStatefulBrush(KColorScheme::Window, KColorScheme::NegativeBackground, KSharedConfig::openConfig(KdenliveSettings::colortheme())).brush(this).color();
KStatefulBrush(KColorScheme::Window, KColorScheme::NegativeBackground).brush(this).color();
const char *iconName = nullptr;
setColor(parentWidget()->palette().window().color());
switch (m_currentMessage.type) {
......
This diff is collapsed.
/* ============================================================
*
* This file is a part of digiKam project
* http://www.digikam.org
*
* Date : 2004-08-02
* Description : theme manager
*
* Copyright (C) 2006-2013 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2, or (at your option)
* any later version.
*
* This program 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 General Public License for more details.
*
* ============================================================ */
/*************************************************************************************
* This file is part of KDevPlatform *
* Copyright 2016 Zhigalin Alexander <alexander@zhigalin.tk> *
* *
* This 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) version 3, or any *
* later version accepted by the membership of KDE e.V. (or its *
* successor approved by the membership of KDE e.V.), which shall *
* act as a proxy defined in Section 6 of version 3 of the license. *
* *
* 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, see <http://www.gnu.org/licenses/>. *
*************************************************************************************/
#ifndef THEMEMANAGER_H
#define THEMEMANAGER_H
......@@ -27,61 +25,33 @@
// Qt includes
#include <QObject>
#include <QPixmap>
#include <QAction>
#include <QApplication>
#include <QString>
// KDE includes
#include <KSharedConfig>
// Local includes
#include <KColorSchemeManager>
class KActionMenu;
class Theme;
class ThemeManager : public QObject
class ThemeManager : public QAction
{
Q_OBJECT
public:
~ThemeManager();
static ThemeManager *instance();
QString currentThemeName() const;
void setCurrentTheme(const QString &name);
QString defaultThemeName() const;
void setThemeMenuAction(KActionMenu *const action);
/** @brief set dark theme by default if available */
void initDarkTheme();
Q_SIGNALS:
void signalThemeChanged(const QString &);
public Q_SLOTS:
void slotSettingsChanged();
void slotChangePalette();
ThemeManager(QObject* parent);
QString currentSchemeName() const;
private Q_SLOTS:
void slotConfigColors();
void slotSchemeChanged(QAction* triggeredAction, const QString &path);
private:
ThemeManager();
void populateThemeMenu();
QPixmap createSchemePreviewIcon(const KSharedConfigPtr &config) const;
QString currentKDEdefaultTheme() const;
void updateCurrentKDEdefaultThemePreview();
QString loadCurrentScheme() const;
void saveCurrentScheme(const QString &name);
QString currentDesktopDefaultScheme() const;
private:
friend class ThemeManagerCreator;
class Private;
Private *const d;
signals:
void themeChanged(const QString &name);
};
#endif /* THEMEMANAGER_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment