diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ Config GuiAddons WidgetsAddons + ConfigWidgets IconThemes I18n ItemModels diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt --- a/shell/CMakeLists.txt +++ b/shell/CMakeLists.txt @@ -18,6 +18,7 @@ shellextension.cpp core.cpp uicontroller.cpp + colorschemechooser.cpp projectcontroller.cpp project.cpp partcontroller.cpp @@ -118,6 +119,7 @@ Qt5::QuickWidgets KF5::GuiAddons + KF5::ConfigWidgets KF5::IconThemes KF5::KIOFileWidgets KF5::KIOWidgets diff --git a/shell/colorschemechooser.h b/shell/colorschemechooser.h new file mode 100644 --- /dev/null +++ b/shell/colorschemechooser.h @@ -0,0 +1,72 @@ +/************************************************************************************* + * This file is part of KDevPlatform * + * Copyright 2016 Zhigalin Alexander * + * * + * 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 . * + *************************************************************************************/ + +#ifndef COLORSCHEMECHOOSER_H +#define COLORSCHEMECHOOSER_H + +#include +#include +#include + +#include +#include + +#include "mainwindow.h" + +class KActionCollection; + +namespace KDevelop +{ + +/** + * Provides an action that will offer to change the color scheme of the current application + * + * Furthermore, it will save the selection in the user configuration so that it's remember + * for subsequent runs of the same program. + */ +class ColorSchemeChooser : public QObject +{ + Q_OBJECT + public: + /** + * Restores the settings and constructs the action + */ + ColorSchemeChooser(QObject* parent); + + /** + * Returns the action to place in the menus or a KActionCollection + */ + KActionMenu* menuAction(); + + private Q_SLOTS: + void slotSettingsChanged(QAction* triggeredAction); + + private: + KActionMenu* m_menuAction = nullptr; + + + QString currentColorSchemeName() const; + void setCurrentColorSchemeName(const QString &name); +}; + +} // namespace KDevelop + +#endif // COLORSCHEMECHOOSER_H diff --git a/shell/colorschemechooser.cpp b/shell/colorschemechooser.cpp new file mode 100644 --- /dev/null +++ b/shell/colorschemechooser.cpp @@ -0,0 +1,92 @@ +/************************************************************************************* + * This file is part of KDevPlatform * + * Copyright 2016 Zhigalin Alexander * + * * + * 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 . * + *************************************************************************************/ + +#include "colorschemechooser.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include "mainwindow.h" +#include "core.h" +#include "debug.h" + +namespace KDevelop +{ + +ColorSchemeChooser::ColorSchemeChooser(QObject* parent) + : QObject(parent) +{ + auto manager = new KColorSchemeManager(this); + const auto theme = currentColorSchemeName(); + qCDebug(SHELL) << "Initial color scheme:" << theme; + + m_menuAction = manager->createSchemeSelectionMenu(QIcon::fromTheme(QStringLiteral("preferences-desktop-color")), i18n("&Color Theme"), theme, this); + + connect(m_menuAction->menu(), &QMenu::triggered, this, &ColorSchemeChooser::slotSettingsChanged); + + if (!theme.isEmpty()) { + auto themeIdx = manager->indexForScheme(theme); + manager->activateScheme(themeIdx); + } +} + +KActionMenu* ColorSchemeChooser::menuAction() +{ + return m_menuAction; +} + +QString ColorSchemeChooser::currentColorSchemeName() const +{ + KSharedConfigPtr config = KSharedConfig::openConfig(); + KConfigGroup cg(config, "General"); + return cg.readEntry("ColorScheme", QStringLiteral("Breeze")); +} + +void ColorSchemeChooser::setCurrentColorSchemeName(const QString &name) +{ + qDebug() << "setting color scheme" << name; + + KSharedConfigPtr config = KSharedConfig::openConfig(); + KConfigGroup cg(config, "General"); + cg.writeEntry("ColorScheme", name); +} + +void ColorSchemeChooser::slotSettingsChanged(QAction *triggeredAction) +{ + setCurrentColorSchemeName(KLocalizedString::removeAcceleratorMarker(triggeredAction->text())); +} + +} // namespace KDevelop diff --git a/shell/mainwindow.h b/shell/mainwindow.h --- a/shell/mainwindow.h +++ b/shell/mainwindow.h @@ -89,6 +89,7 @@ void dropEvent( QDropEvent* ) override; void applyMainWindowSettings(const KConfigGroup& config) override; void createGUI(KParts::Part* part); + void populateThemes(); protected Q_SLOTS: void tabContextMenuRequested(Sublime::View* , QMenu* ) override; diff --git a/shell/mainwindow.cpp b/shell/mainwindow.cpp --- a/shell/mainwindow.cpp +++ b/shell/mainwindow.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include #include diff --git a/shell/mainwindow_p.cpp b/shell/mainwindow_p.cpp --- a/shell/mainwindow_p.cpp +++ b/shell/mainwindow_p.cpp @@ -53,6 +53,7 @@ #include "sessioncontroller.h" #include "debug.h" #include "ktexteditorpluginintegration.h" +#include "colorschemechooser.h" #include #include @@ -318,6 +319,11 @@ connect( action, &QAction::triggered, this, &MainWindowPrivate::viewAddNewToolView ); action->setToolTip( i18nc( "@info:tooltip", "Add tool view" ) ); action->setWhatsThis( i18nc( "@info:whatsthis", "Adds a new tool view to this window." ) ); + + // Load Themes + auto tm = new ColorSchemeChooser(actionCollection()); + actionCollection()->addAction(QStringLiteral("colorscheme_menu"), tm->menuAction()); + } void MainWindowPrivate::toggleArea(bool b)