Changeset View
Changeset View
Standalone View
Standalone View
kate/katecolorschemechooser.cpp
- This file was added.
1 | /************************************************************************************* | ||||
---|---|---|---|---|---|
2 | * This file is part of KDevPlatform * | ||||
3 | * Copyright 2016 Zhigalin Alexander <alexander@zhigalin.tk> * | ||||
4 | * * | ||||
5 | * This library is free software; you can redistribute it and/or * | ||||
6 | * modify it under the terms of the GNU Lesser General Public * | ||||
7 | * License as published by the Free Software Foundation; either * | ||||
8 | * version 2.1 of the License, or (at your option) version 3, or any * | ||||
9 | * later version accepted by the membership of KDE e.V. (or its * | ||||
10 | * successor approved by the membership of KDE e.V.), which shall * | ||||
11 | * act as a proxy defined in Section 6 of version 3 of the license. * | ||||
12 | * * | ||||
13 | * This library is distributed in the hope that it will be useful, * | ||||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * | ||||
16 | * Lesser General Public License for more details. * | ||||
17 | * * | ||||
18 | * You should have received a copy of the GNU Lesser General Public * | ||||
19 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. * | ||||
20 | *************************************************************************************/ | ||||
21 | | ||||
22 | #include "katecolorschemechooser.h" | ||||
23 | | ||||
24 | #include <QStringList> | ||||
25 | #include <QFileInfo> | ||||
26 | #include <QActionGroup> | ||||
27 | #include <QApplication> | ||||
28 | #include <QAction> | ||||
29 | #include <QStandardPaths> | ||||
30 | #include <QDirIterator> | ||||
31 | #include <QMenu> | ||||
32 | #include <QModelIndex> | ||||
33 | | ||||
34 | #include <KActionMenu> | ||||
35 | #include <KColorSchemeManager> | ||||
36 | #include <KLocalizedString> | ||||
37 | #include <KActionCollection> | ||||
38 | #include <KSharedConfig> | ||||
39 | #include <KConfigGroup> | ||||
40 | | ||||
41 | #include "katemainwindow.h" | ||||
42 | #include "katedebug.h" | ||||
43 | | ||||
44 | | ||||
45 | KateColorSchemeChooser::KateColorSchemeChooser(QObject* parent) | ||||
46 | : QAction(parent) | ||||
47 | { | ||||
48 | auto manager = new KColorSchemeManager(parent); | ||||
49 | | ||||
50 | const auto scheme(currentSchemeName()); | ||||
51 | qCDebug(LOG_KATE) << "Color scheme : " << scheme; | ||||
52 | | ||||
53 | auto selectionMenu = manager->createSchemeSelectionMenu(scheme, this); | ||||
54 | | ||||
55 | connect(selectionMenu->menu(), &QMenu::triggered, | ||||
56 | this, &KateColorSchemeChooser::slotSchemeChanged); | ||||
57 | | ||||
58 | manager->activateScheme(manager->indexForScheme(scheme)); | ||||
59 | | ||||
60 | setMenu(selectionMenu->menu()); | ||||
61 | menu()->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-color"))); | ||||
62 | menu()->setTitle(i18n("&Color Theme")); | ||||
63 | } | ||||
64 | | ||||
65 | QString KateColorSchemeChooser::loadCurrentScheme() const | ||||
66 | { | ||||
67 | KSharedConfigPtr config = KSharedConfig::openConfig(); | ||||
68 | KConfigGroup cg(config, "UiSettings"); | ||||
69 | return cg.readEntry("ColorScheme", currentDesktopDefaultScheme()); | ||||
70 | } | ||||
71 | | ||||
72 | void KateColorSchemeChooser::saveCurrentScheme(const QString &name) | ||||
73 | { | ||||
74 | KSharedConfigPtr config = KSharedConfig::openConfig(); | ||||
75 | KConfigGroup cg(config, "UiSettings"); | ||||
76 | cg.writeEntry("ColorScheme", name); | ||||
77 | cg.sync(); | ||||
78 | } | ||||
79 | | ||||
80 | QString KateColorSchemeChooser::currentDesktopDefaultScheme() const | ||||
81 | { | ||||
82 | KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("kdeglobals")); | ||||
83 | KConfigGroup group(config, "General"); | ||||
84 | return group.readEntry("ColorScheme", QStringLiteral("Breeze")); | ||||
85 | } | ||||
86 | | ||||
87 | QString KateColorSchemeChooser::currentSchemeName() const | ||||
88 | { | ||||
89 | if(!menu()) return loadCurrentScheme(); | ||||
90 | | ||||
91 | QAction* const action = menu()->activeAction(); | ||||
92 | | ||||
93 | if(action) return KLocalizedString::removeAcceleratorMarker(action->text()); | ||||
94 | return currentDesktopDefaultScheme(); | ||||
95 | } | ||||
96 | | ||||
97 | void KateColorSchemeChooser::slotSchemeChanged(QAction* triggeredAction) | ||||
98 | { | ||||
99 | saveCurrentScheme(KLocalizedString::removeAcceleratorMarker(triggeredAction->text())); | ||||
100 | } |