Commit e3219f02 authored by Michael Abrahams's avatar Michael Abrahams

Move shortcut settings into "Configure Krita" menu

Summary:
This is desirable because it lessens the confusion of having "Canvas Input Settings" and "Shortcut Settings." Users can see at a glance that both pages are available. I think it looks nicer, too.

Class renaming and documentation updates can be done in a separate patch.

Reviewers: #krita:_next, dkazakov

Reviewed By: #krita:_next, dkazakov

Subscribers: dkazakov

Differential Revision: https://phabricator.kde.org/D1121
parent 3547cd8a
......@@ -45,6 +45,7 @@
#include <kis_config.h>
#include <KisDocument.h>
#include <KisViewManager.h>
#include <kis_action_registry.h>
class DesktopViewProxy::Private
{
......@@ -100,7 +101,9 @@ DesktopViewProxy::DesktopViewProxy(MainWindow* mainWindow, KisMainWindow* parent
connect(d->desktopWindow, SIGNAL(documentSaved()), this, SIGNAL(documentSaved()));
connect(d->desktopWindow, SIGNAL(keyBindingsChanged()), this, SLOT(updateKeyBindings()));
// XXX: Shortcut editor is untested in Gemini since refactoring.
connect(KisActionRegistry::instance(), SIGNAL(shortcutsUpdated()), this, SLOT(updateShortcuts()));
}
DesktopViewProxy::~DesktopViewProxy()
......
......@@ -288,7 +288,8 @@ xsi:schemaLocation="http://www.kde.org/standards/kxmlgui/1.0 http://www.kde.org
<Separator/>
<Action name="theme_menu"/>
<Separator/>
<Action name="options_configure_keybinding"/>
<!-- `Configure Shortcuts` was moved into main configuration menu -->
<!-- <Action name="options_configure_keybinding"/> -->
<Action name="options_configure"/>
<Separator/>
<Action name="manage_bundles"/>
......
......@@ -1624,12 +1624,6 @@ void KisMainWindow::exportAnimation()
#endif
}
void KisMainWindow::slotConfigureKeys()
{
KisPart::instance()->configureShortcuts();
emit keyBindingsChanged();
}
void KisMainWindow::slotConfigureToolbars()
{
KConfigGroup group = KSharedConfig::openConfig()->group("krita");
......@@ -2217,7 +2211,6 @@ void KisMainWindow::createActions()
actionManager->createStandardAction(KStandardAction::New, this, SLOT(slotFileNew()));
actionManager->createStandardAction(KStandardAction::Open, this, SLOT(slotFileOpen()));
actionManager->createStandardAction(KStandardAction::Quit, this, SLOT(slotFileQuit()));
actionManager->createStandardAction(KStandardAction::KeyBindings, this, SLOT(slotConfigureKeys()));
actionManager->createStandardAction(KStandardAction::ConfigureToolbars, this, SLOT(slotConfigureToolbars()));
actionManager->createStandardAction(KStandardAction::FullScreen, this, SLOT(viewFullscreen(bool)));
......
......@@ -286,11 +286,6 @@ private Q_SLOTS:
*/
void slotFileQuit();
/**
* Configure key bindings.
*/
void slotConfigureKeys();
/**
* Configure toolbars.
*/
......
......@@ -123,13 +123,13 @@ public:
// Basically, we are going to insert the current UI/MainWindow ActionCollection
// into the KisActionRegistry.
void KisPart::Private::loadActions()
void KisPart::loadActions()
{
actionCollection = part->currentMainwindow()->viewManager()->actionCollection();
d->actionCollection = currentMainwindow()->viewManager()->actionCollection();
KisActionRegistry * actionRegistry = KisActionRegistry::instance();
Q_FOREACH (auto action, actionCollection->actions()) {
Q_FOREACH (auto action, d->actionCollection->actions()) {
auto name = action->objectName();
actionRegistry->addAction(action->objectName(), action);
}
......@@ -424,14 +424,6 @@ void KisPart::openExistingFile(const QUrl &url)
qApp->restoreOverrideCursor();
}
void KisPart::configureShortcuts()
{
d->loadActions();
auto actionRegistry = KisActionRegistry::instance();
actionRegistry->configureShortcuts();
}
void KisPart::updateShortcuts()
{
// Update any non-UI actionCollections. That includes:
......
......@@ -136,6 +136,10 @@ public:
*/
KisMainWindow *currentMainwindow() const;
/**
* Load actions for currently active main window into KisActionRegistry.
*/
void loadActions();
/**
* @return the application-wide KisIdleWatcher.
......@@ -156,15 +160,6 @@ public Q_SLOTS:
*/
void openExistingFile(const QUrl &url);
/**
* @brief configureShortcuts opens the shortcut configuration dialog.
* @param parent the parent widget for the dialog
*
* After the user closes the dialog, all actioncollections will be updated
* with the new shortcuts.
*/
void configureShortcuts();
protected Q_SLOTS:
/**
......
......@@ -57,6 +57,7 @@
#include <klocalizedstring.h>
#include <kundo2stack.h>
#include <KoResourcePaths.h>
#include "kis_action_registry.h"
#include "widgets/squeezedcombobox.h"
#include "kis_clipboard.h"
......@@ -246,6 +247,35 @@ void GeneralTab::clearBackgroundImage()
m_backgroundimage->setText("");
}
ShortcutSettingsTab::ShortcutSettingsTab(QWidget *parent, const char *name)
: QWidget(parent)
{
setObjectName(name);
QGridLayout * l = new QGridLayout(this);
l->setMargin(0);
m_page = new WdgShortcutSettings(this);
l->addWidget(m_page, 0, 0);
KisPart::instance()->loadActions();
KisActionRegistry::instance()->setupDialog(m_page);
}
void ShortcutSettingsTab::setDefault()
{
m_page->allDefault();
}
void ShortcutSettingsTab::saveChanges()
{
KisActionRegistry::instance()->settingsPageSaved();
}
void ShortcutSettingsTab::revertChanges()
{
m_page->allDefault();
}
ColorSettingsTab::ColorSettingsTab(QWidget *parent, const char *name)
: QWidget(parent)
{
......@@ -803,6 +833,24 @@ KisDlgPreferences::KisDlgPreferences(QWidget* parent, const char* name)
addPage(page);
m_general = new GeneralTab(vbox);
// Shortcuts
vbox = new KoVBox();
page = new KPageWidgetItem(vbox, i18n("Keyboard Shortcuts"));
page->setObjectName("shortcuts");
page->setHeader(i18n("Shortcuts"));
page->setIcon(KisIconUtils::loadIcon("configure-shortcuts"));
addPage(page);
m_shortcutSettings = new ShortcutSettingsTab(vbox);
connect(this, SIGNAL(accepted()), m_shortcutSettings, SLOT(saveChanges()));
connect(this, SIGNAL(rejected()), m_shortcutSettings, SLOT(revertChanges()));
// Canvas input settings
m_inputConfiguration = new KisInputConfigurationPage();
page = addPage(m_inputConfiguration, i18n("Canvas Input Settings"));
page->setHeader(i18n("Canvas Input"));
page->setObjectName("canvasinput");
page->setIcon(KisIconUtils::loadIcon("applications-system"));
// Display
vbox = new KoVBox();
page = new KPageWidgetItem(vbox, i18n("Display"));
......@@ -856,13 +904,6 @@ KisDlgPreferences::KisDlgPreferences(QWidget* parent, const char* name)
page->setIcon(KisIconUtils::loadIcon("im-user"));
// input settings
m_inputConfiguration = new KisInputConfigurationPage();
page = addPage(m_inputConfiguration, i18n("Canvas Input Settings"));
page->setHeader(i18n("Canvas Input"));
page->setObjectName("canvasinput");
page->setIcon(KisIconUtils::loadIcon("applications-system"));
QPushButton *restoreDefaultsButton = button(QDialogButtonBox::RestoreDefaults);
connect(this, SIGNAL(accepted()), m_inputConfiguration, SLOT(saveChanges()));
......@@ -898,6 +939,9 @@ void KisDlgPreferences::slotDefault()
if (currentPage()->objectName() == "default") {
m_general->setDefault();
}
else if (currentPage()->objectName() == "shortcuts") {
m_shortcutSettings->setDefault();
}
else if (currentPage()->objectName() == "display") {
m_displaySettings->setDefault();
}
......
......@@ -34,6 +34,7 @@
#include "ui_wdgtabletsettings.h"
#include "ui_wdgperformancesettings.h"
#include "ui_wdgfullscreensettings.h"
#include "KisShortcutsDialog.h"
class KoID;
class KisInputConfigurationPage;
......@@ -84,7 +85,47 @@ private Q_SLOTS:
};
//=======================
/**
* "Shortcuts" tab for preferences dialog
*/
class WdgShortcutSettings : public KisShortcutsDialog
{
Q_OBJECT
public:
WdgShortcutSettings(QWidget *parent)
: KisShortcutsDialog(KisShortcutsEditor::AllActions,
KisShortcutsEditor::LetterShortcutsAllowed,
parent)
{ }
};
class ShortcutSettingsTab : public QWidget
{
Q_OBJECT
public:
ShortcutSettingsTab(QWidget *parent = 0, const char *name = 0);
public:
void setDefault();
WdgShortcutSettings *m_page;
public Q_SLOTS:
void saveChanges();
void revertChanges();
};
/**
* "Color" tab for preferences dialog
*/
class WdgColorSettings : public QWidget, public Ui::WdgColorSettings
{
......@@ -268,6 +309,7 @@ protected:
protected:
GeneralTab *m_general;
ShortcutSettingsTab *m_shortcutSettings;
ColorSettingsTab *m_colorSettings;
PerformanceTab *m_performanceSettings;
DisplaySettingsTab *m_displaySettings;
......
......@@ -219,25 +219,19 @@ QAction * KisActionRegistry::makeQAction(const QString &name, QObject *parent)
};
void KisActionRegistry::configureShortcuts()
void KisActionRegistry::setupDialog(KisShortcutsDialog *dlg)
{
KisShortcutsDialog dlg;
for (auto i = d->actionCollections.constBegin(); i != d->actionCollections.constEnd(); i++ ) {
dlg.addCollection(i.value(), i.key());
dlg->addCollection(i.value(), i.key());
}
}
/* Testing */
// QStringList mainWindowActions;
// foreach (auto a, ac->actions()) {
// mainWindowActions << a->objectName();
// }
// dlg.addCollection(ac, "TESTING: XMLGUI-MAINWINDOW");
dlg.configure(); // Show the dialog.
void KisActionRegistry::settingsPageSaved()
{
// For now, custom shortcuts are dealt with by writing to file and reloading.
loadCustomShortcuts();
// Announce UI should reload current shortcuts.
emit shortcutsUpdated();
}
......
......@@ -28,6 +28,7 @@
class KActionCollection;
class QDomElement;
class KConfigBase;
class KisShortcutsDialog;
/**
* KisActionRegistry is intended to manage the global action configuration data
......@@ -114,9 +115,15 @@ public:
QStringList allActions();
/**
* Display the shortcut configuration dialog.
* Setup the shortcut configuration widget.
*/
void configureShortcuts();
void setupDialog(KisShortcutsDialog *dlg);
/**
* Called when "OK" button is pressed in settings dialog.
*/
void settingsPageSaved();
/**
......
......@@ -49,7 +49,7 @@
KisShortcutsDialog::KisShortcutsDialog(KisShortcutsEditor::ActionTypes types,
KisShortcutsEditor::LetterShortcuts allowLetterShortcuts,
QWidget *parent)
: QDialog(parent)
: QWidget(parent)
, d(new KisShortcutsDialogPrivate(this))
{
......@@ -58,9 +58,6 @@ KisShortcutsDialog::KisShortcutsDialog(KisShortcutsEditor::ActionTypes types,
/* Construct & Connect UI */
setWindowTitle(i18n("Configure Shortcuts"));
setModal(true);
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
mainLayout->addWidget(d->m_shortcutsEditor);
......@@ -77,21 +74,12 @@ KisShortcutsDialog::KisShortcutsDialog(KisShortcutsEditor::ActionTypes types,
QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
buttonBox->addButton(printButton, QDialogButtonBox::ActionRole);
buttonBox->setStandardButtons(QDialogButtonBox::Ok |
QDialogButtonBox::Cancel);
KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok),
KStandardGuiItem::ok());
KGuiItem::assign(buttonBox->button(QDialogButtonBox::Cancel),
KStandardGuiItem::cancel());
bottomLayout->addWidget(buttonBox);
mainLayout->addLayout(bottomLayout);
connect(printButton, SIGNAL(clicked()), d->m_shortcutsEditor, SLOT(printShortcuts()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(undo()));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
KConfigGroup group(KSharedConfig::openConfig(), "KisShortcutsDialog Settings");
resize(group.readEntry("Dialog Size", sizeHint()));
......@@ -110,29 +98,15 @@ void KisShortcutsDialog::addCollection(KActionCollection *collection, const QStr
d->m_collections.insert(title, collection);
}
QList<KActionCollection *> KisShortcutsDialog::actionCollections() const
{
return d->m_collections.values();
}
bool KisShortcutsDialog::configure(bool saveSettings)
void KisShortcutsDialog::save()
{
d->m_saveSettings = saveSettings;
if (isModal()) {
int retcode = exec();
return retcode;
} else {
show();
return false;
}
d->save();
}
void KisShortcutsDialog::accept()
QList<KActionCollection *> KisShortcutsDialog::actionCollections() const
{
if (d->m_saveSettings) {
d->save();
}
QDialog::accept();
return d->m_collections.values();
}
QSize KisShortcutsDialog::sizeHint() const
......@@ -140,15 +114,6 @@ QSize KisShortcutsDialog::sizeHint() const
return QSize(600, 480);
}
int KisShortcutsDialog::configure(KActionCollection *collection,
KisShortcutsEditor::LetterShortcuts allowLetterShortcuts,
QWidget *parent, bool saveSettings)
{
KisShortcutsDialog dlg(KisShortcutsEditor::AllActions, allowLetterShortcuts, parent);
dlg.d->m_shortcutsEditor->addCollection(collection);
return dlg.configure(saveSettings);
}
void KisShortcutsDialog::allDefault()
{
d->m_shortcutsEditor->allDefault();
......
......@@ -97,7 +97,7 @@ const auto defaultActionTypes = KisShortcutsEditor::WidgetAction \
| KisShortcutsEditor::WindowAction \
| KisShortcutsEditor::ApplicationAction;
class KRITAWIDGETUTILS_EXPORT KisShortcutsDialog : public QDialog
class KRITAWIDGETUTILS_EXPORT KisShortcutsDialog : public QWidget
{
Q_OBJECT
......@@ -105,9 +105,10 @@ public:
/**
* Constructs a KisShortcutsDialog. Mostly UI boilerplate.
*
* @p parent is parent widget. Set @p allowLetterShortcuts to false if
* unmodified alphanumeric keys ('A', '1', etc.) are not permissible
* shortcuts.
* @param allowLetterShortcuts set to KisShortcutsEditor::LetterShortcutsDisallowed if unmodified alphanumeric
* keys ('A', '1', etc.) are not permissible shortcuts.
*
* @param parent the parent widget to attach to
*
* There is some legacy support for global (i.e. desktop-wide) shortucts
* that should probably be removed.
......@@ -132,19 +133,14 @@ public:
*/
QList<KActionCollection *> actionCollections() const;
/**
* Run the dialog. If @p saveSettings is true, save any modifications to the
* actioncollections with a call to writeSettings().
*
*
* FIXME should there be a setSaveSettings method? When is this f'n called?
*/
bool configure(bool saveSettings = true);
/** @see QWidget::sizeHint() */
QSize sizeHint() const Q_DECL_OVERRIDE;
/**
* Called when the "OK" button in the main configuration page is pressed.
*/
void save();
/**
* Import shortcut scheme file from @p path
......@@ -166,35 +162,10 @@ public:
*/
void saveCustomShortcuts(const QString &path) const;
/**
* Pops up a modal (blocking) dialog for configuring key settings. The new
* shortcut settings will become active if the user presses OK.
*
* @param collection the KActionCollection to configure
* @param allowLetterShortcuts set to KisShortcutsEditor::LetterShortcutsDisallowed if unmodified alphanumeric
* keys ('A', '1', etc.) are not permissible shortcuts.
* @param parent the parent widget to attach to
* @param bSaveSettings if true, the settings will also be saved back
* by calling writeSettings() on the action collections that were added.
*
* @return Accept if the dialog was closed with OK, Reject otherwise.
*/
static int configure(KActionCollection *collection,
KisShortcutsEditor::LetterShortcuts allowLetterShortcuts \
= KisShortcutsEditor::LetterShortcutsAllowed,
QWidget *parent = 0,
bool bSaveSettings = true);
public Q_SLOTS:
///@reimp
void accept() Q_DECL_OVERRIDE;
void allDefault();
Q_SIGNALS:
///emitted after OK is clicked and settings are saved
void saved();
private:
Q_PRIVATE_SLOT(d, void changeShortcutScheme(const QString &))
Q_PRIVATE_SLOT(d, void undo())
......
......@@ -88,7 +88,6 @@ void KisShortcutsDialog::KisShortcutsDialogPrivate::undo()
void KisShortcutsDialog::KisShortcutsDialogPrivate::save()
{
m_shortcutsEditor->save();
emit q->saved();
};
#include "moc_KisShortcutsDialog_p.cpp"
......@@ -94,7 +94,6 @@ public:
QHash<QString, KActionCollection *> m_collections;
KisShortcutsDialog *q;
KisShortcutsEditor *m_shortcutsEditor;
bool m_saveSettings{false};
KShortcutSchemesEditor *m_schemeEditor{0};
};
......
......@@ -76,7 +76,7 @@ KShortcutSchemesEditor::KShortcutSchemesEditor(KisShortcutsDialog *parent)
m_deleteScheme = new QPushButton(i18n("Delete"));
addWidget(m_deleteScheme);
QPushButton *moreActions = new QPushButton(i18n("More Actions"));
QPushButton *moreActions = new QPushButton(i18n("Save/Load"));
addWidget(moreActions);
QMenu *moreActionsMenu = new QMenu(m_dialog);
......@@ -91,8 +91,6 @@ KShortcutSchemesEditor::KShortcutSchemesEditor(KisShortcutsDialog *parent)
this, SLOT(exportShortcutsScheme()));
moreActionsMenu->addAction(i18n("Import Scheme..."),
this, SLOT(importShortcutsScheme()));
moreActionsMenu->addAction(i18n("Restore Defaults"),
m_dialog, SLOT(allDefault()));
moreActions->setMenu(moreActionsMenu);
addStretch(1);
......
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