Krita Source Code Documentation
Loading...
Searching...
No Matches
KisKShortcutSchemesEditor Class Reference

#include <kshortcutschemeseditor.h>

+ Inheritance diagram for KisKShortcutSchemesEditor:

Signals

void shortcutsSchemeChanged (const QString &)
 

Public Member Functions

QString currentScheme ()
 
 KisKShortcutSchemesEditor (KisShortcutsDialog *parent)
 

Protected Member Functions

void updateDeleteButton ()
 

Private Slots

void deleteScheme ()
 
void exportShortcutsScheme ()
 
void importShortcutsScheme ()
 
void loadCustomShortcuts ()
 
void newScheme ()
 
void saveCustomShortcuts ()
 

Private Attributes

QPushButton * m_deleteScheme {nullptr}
 
KisShortcutsDialogm_dialog {nullptr}
 
QPushButton * m_exportScheme {nullptr}
 
QPushButton * m_newScheme {nullptr}
 
QHash< QString, QString > m_schemeFileLocations
 
QComboBox * m_schemesList {nullptr}
 

Detailed Description

Definition at line 15 of file kshortcutschemeseditor.h.

Constructor & Destructor Documentation

◆ KisKShortcutSchemesEditor()

KisKShortcutSchemesEditor::KisKShortcutSchemesEditor ( KisShortcutsDialog * parent)

Definition at line 33 of file kshortcutschemeseditor.cpp.

34 : m_dialog(parent)
35{
36 KConfigGroup group(KSharedConfig::openConfig(), "Shortcut Schemes");
37
38 QStringList schemes;
39 schemes << QStringLiteral("Default");
40
41 auto schemeFileLocations = KisKShortcutSchemesHelper::schemeFileLocations();
42 schemes << schemeFileLocations.keys();
43
44 QString currentScheme = group.readEntry("Current Scheme", "Default");
45 QString schemeFileName = KisKShortcutSchemesHelper::schemeFileLocations().value(currentScheme);
46 if (!QFileInfo(schemeFileName).exists()) {
47 currentScheme = "Default";
48 }
49 setContentsMargins(0, 0, 0, 0);
50
51 QLabel *schemesLabel = new QLabel(i18n("Shortcut Schemes:"), m_dialog);
52 addWidget(schemesLabel);
53
54 m_schemesList = new QComboBox(m_dialog);
55 m_schemesList->setEditable(false);
56 m_schemesList->addItems(schemes);
57 m_schemesList->setCurrentIndex(m_schemesList->findText(currentScheme));
58 schemesLabel->setBuddy(m_schemesList);
59 addWidget(m_schemesList);
60
61 m_newScheme = new QPushButton(i18nc("New shortcut scheme", "New..."));
62 addWidget(m_newScheme);
63
64 m_deleteScheme = new QPushButton(i18n("Delete"));
65 addWidget(m_deleteScheme);
66
67 QPushButton *moreActions = new QPushButton(i18n("Save/Load"));
68 addWidget(moreActions);
69
70 QMenu *moreActionsMenu = new QMenu(m_dialog);
71 // moreActionsMenu->addAction(i18n("Save as Scheme Defaults"),
72 // this, SLOT(saveAsDefaultsForScheme()));
73
74 moreActionsMenu->addAction(i18n("Save Custom Shortcuts"),
75 this, SLOT(saveCustomShortcuts()));
76 moreActionsMenu->addAction(i18n("Load Custom Shortcuts"),
77 this, SLOT(loadCustomShortcuts()));
78 moreActionsMenu->addAction(i18n("Export Scheme..."),
79 this, SLOT(exportShortcutsScheme()));
80 moreActionsMenu->addAction(i18n("Import Scheme..."),
81 this, SLOT(importShortcutsScheme()));
82 moreActions->setMenu(moreActionsMenu);
83
84 addStretch(1);
85
86 connect(m_schemesList, SIGNAL(textActivated(QString)),
87 this, SIGNAL(shortcutsSchemeChanged(QString)));
88 connect(m_newScheme, SIGNAL(clicked()), this, SLOT(newScheme()));
89 connect(m_deleteScheme, SIGNAL(clicked()), this, SLOT(deleteScheme()));
91}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void shortcutsSchemeChanged(const QString &)
static QHash< QString, QString > schemeFileLocations()

References connect(), currentScheme(), deleteScheme(), exportShortcutsScheme(), importShortcutsScheme(), loadCustomShortcuts(), m_deleteScheme, m_dialog, m_newScheme, m_schemesList, newScheme(), saveCustomShortcuts(), KisKShortcutSchemesHelper::schemeFileLocations(), shortcutsSchemeChanged(), and updateDeleteButton().

Member Function Documentation

◆ currentScheme()

QString KisKShortcutSchemesEditor::currentScheme ( )
Returns
the currently selected scheme in the editor (may differ from current app's scheme.

Definition at line 145 of file kshortcutschemeseditor.cpp.

146{
147 return m_schemesList->currentText();
148}

References m_schemesList.

◆ deleteScheme

void KisKShortcutSchemesEditor::deleteScheme ( )
privateslot

Definition at line 124 of file kshortcutschemeseditor.cpp.

125{
126 if (KMessageBox::questionTwoActions(m_dialog,
127 i18n("Do you really want to delete the scheme %1?\n\
128 Note that this will not remove any system wide shortcut schemes.",
129 currentScheme()),
130 QString(),
131 KStandardGuiItem::del(),
132 KStandardGuiItem::cancel())
133 == KMessageBox::SecondaryAction) {
134 return;
135 }
136
137 //delete the scheme for the app itself
139
140 m_schemesList->removeItem(m_schemesList->findText(currentScheme()));
143}
static QString shortcutSchemeFileName(const QString &schemeName)

References currentScheme(), m_dialog, m_schemesList, KisKShortcutSchemesHelper::shortcutSchemeFileName(), shortcutsSchemeChanged(), and updateDeleteButton().

◆ exportShortcutsScheme

void KisKShortcutSchemesEditor::exportShortcutsScheme ( )
privateslot

Definition at line 150 of file kshortcutschemeseditor.cpp.

151{
152 KConfigGroup group = KSharedConfig::openConfig()->group("File Dialogs");
153 QString proposedPath = group.readEntry("ExportShortcuts", KoResourcePaths::saveLocation("kis_shortcuts"));
154
156 dialog.setCaption(i18n("Export Shortcuts"));
157 dialog.setDefaultDir(proposedPath);
158 dialog.setMimeTypeFilters(QStringList() << "application/x-krita-shortcuts", "application/x-krita-shortcuts");
159 QString path = dialog.filename();
160
161 if (!path.isEmpty()) {
163 }
164}
QList< QString > QStringList
void exportConfiguration(const QString &path) const
static QString saveLocation(const QString &type, const QString &suffix=QString(), bool create=true)

References KisShortcutsDialog::exportConfiguration(), m_dialog, KoFileDialog::SaveFile, and KoResourcePaths::saveLocation().

◆ importShortcutsScheme

void KisKShortcutSchemesEditor::importShortcutsScheme ( )
privateslot

Definition at line 205 of file kshortcutschemeseditor.cpp.

206{
207 KConfigGroup group = KSharedConfig::openConfig()->group("File Dialogs");
208 QString proposedPath = group.readEntry("ImportShortcuts", QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
209
211 dialog.setCaption(i18n("Import Shortcuts"));
212 dialog.setDefaultDir(proposedPath);
213 dialog.setMimeTypeFilters(QStringList() << "application/x-krita-shortcuts", "application/x-krita-shortcuts");
214 QString path = dialog.filename();
215
216 if (path.isEmpty()) {
217 return;
218 }
219
221}
void importConfiguration(const QString &path)

References KisShortcutsDialog::importConfiguration(), KoFileDialog::ImportFile, and m_dialog.

◆ loadCustomShortcuts

void KisKShortcutSchemesEditor::loadCustomShortcuts ( )
privateslot

Definition at line 184 of file kshortcutschemeseditor.cpp.

185{
186 KConfigGroup group = KSharedConfig::openConfig()->group("File Dialogs");
187 QString proposedPath = group.readEntry("ImportShortcuts", QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
188
190 dialog.setCaption(i18n("Import Shortcuts"));
191 dialog.setDefaultDir(proposedPath);
192 dialog.setMimeTypeFilters(QStringList() << "application/x-krita-shortcuts", "application/x-krita-shortcuts");
193 QString path = dialog.filename();
194
195 if (path.isEmpty()) {
196 return;
197 }
198
199 // auto ar = KisActionRegistry::instance();
200 // ar->loadCustomShortcuts(path);
202
203}
void loadCustomShortcuts(const QString &path)

References KoFileDialog::ImportFile, KisShortcutsDialog::loadCustomShortcuts(), and m_dialog.

◆ newScheme

void KisKShortcutSchemesEditor::newScheme ( )
privateslot

Definition at line 93 of file kshortcutschemeseditor.cpp.

94{
95 bool ok;
96 const QString newName = QInputDialog::getText(m_dialog, i18n("Name for New Scheme"),
97 i18n("Name for new scheme:"), QLineEdit::Normal, i18n("New Scheme"), &ok);
98 if (!ok) {
99 return;
100 }
101
102 if (m_schemesList->findText(newName) != -1) {
103 KMessageBox::error(m_dialog, i18n("A scheme with this name already exists."));
104 return;
105 }
106
107 const QString newSchemeFileName = KisKShortcutSchemesHelper::shortcutSchemeFileName(newName) + ".shortcuts";
108
109 QFile schemeFile(newSchemeFileName);
110 if (!schemeFile.open(QFile::WriteOnly | QFile::Truncate)) {
111 qDebug() << "Could not open scheme file.";
112 return;
113 }
114 schemeFile.close();
115
116 m_dialog->exportConfiguration(newSchemeFileName);
117 m_schemesList->addItem(newName);
118 m_schemesList->setCurrentIndex(m_schemesList->findText(newName));
119 m_schemeFileLocations.insert(newName, newSchemeFileName);
121 Q_EMIT shortcutsSchemeChanged(newName);
122}
QHash< QString, QString > m_schemeFileLocations

References KisShortcutsDialog::exportConfiguration(), m_dialog, m_schemeFileLocations, m_schemesList, KisKShortcutSchemesHelper::shortcutSchemeFileName(), shortcutsSchemeChanged(), and updateDeleteButton().

◆ saveCustomShortcuts

void KisKShortcutSchemesEditor::saveCustomShortcuts ( )
privateslot

Definition at line 166 of file kshortcutschemeseditor.cpp.

167{
168 KConfigGroup group = KSharedConfig::openConfig()->group("File Dialogs");
169 QString proposedPath = group.readEntry("SaveCustomShortcuts", QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
170
171 KoFileDialog dialog(m_dialog, KoFileDialog::SaveFile, "SaveCustomShortcuts");
172 dialog.setCaption(i18n("Save Shortcuts"));
173 dialog.setDefaultDir(proposedPath);
174 dialog.setMimeTypeFilters(QStringList() << "application/x-krita-shortcuts", "application/x-krita-shortcuts");
175 QString path = dialog.filename();
176
177 if (!path.isEmpty()) {
179 }
180}
void saveCustomShortcuts(const QString &path) const

References m_dialog, KisShortcutsDialog::saveCustomShortcuts(), and KoFileDialog::SaveFile.

◆ shortcutsSchemeChanged

void KisKShortcutSchemesEditor::shortcutsSchemeChanged ( const QString & )
signal

◆ updateDeleteButton()

void KisKShortcutSchemesEditor::updateDeleteButton ( )
protected

Definition at line 233 of file kshortcutschemeseditor.cpp.

234{
235 m_deleteScheme->setEnabled(m_schemesList->count() >= 1);
236}

References m_deleteScheme, and m_schemesList.

Member Data Documentation

◆ m_deleteScheme

QPushButton* KisKShortcutSchemesEditor::m_deleteScheme {nullptr}
private

Definition at line 41 of file kshortcutschemeseditor.h.

41{nullptr};

◆ m_dialog

KisShortcutsDialog* KisKShortcutSchemesEditor::m_dialog {nullptr}
private

Definition at line 45 of file kshortcutschemeseditor.h.

45{nullptr};

◆ m_exportScheme

QPushButton* KisKShortcutSchemesEditor::m_exportScheme {nullptr}
private

Definition at line 42 of file kshortcutschemeseditor.h.

42{nullptr};

◆ m_newScheme

QPushButton* KisKShortcutSchemesEditor::m_newScheme {nullptr}
private

Definition at line 40 of file kshortcutschemeseditor.h.

40{nullptr};

◆ m_schemeFileLocations

QHash<QString, QString> KisKShortcutSchemesEditor::m_schemeFileLocations
private

Definition at line 46 of file kshortcutschemeseditor.h.

◆ m_schemesList

QComboBox* KisKShortcutSchemesEditor::m_schemesList {nullptr}
private

Definition at line 43 of file kshortcutschemeseditor.h.

43{nullptr};

The documentation for this class was generated from the following files: