2024-04-24 20:48:23 +03:00
|
|
|
/*
|
|
|
|
This file is part of the KDE libraries
|
|
|
|
Copyright (C) 2024 Ivailo Monev <xakepa10@gmail.com>
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
2024-04-24 20:48:23 +03:00
|
|
|
License version 2, as published by the Free Software Foundation.
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public License
|
|
|
|
along with this library; see the file COPYING.LIB. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KSHORTCUTSEDITOR_H
|
|
|
|
#define KSHORTCUTSEDITOR_H
|
|
|
|
|
2022-09-21 04:41:08 +03:00
|
|
|
#include <kdeui_export.h>
|
2024-04-26 04:19:37 +03:00
|
|
|
#include <kconfiggroup.h>
|
|
|
|
#include <kactioncollection.h>
|
2022-09-21 04:41:08 +03:00
|
|
|
|
2024-04-24 13:41:29 +03:00
|
|
|
#include <QWidget>
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
class KShortcutsEditorPrivate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @short Widget for configuration of KAccel and KGlobalAccel.
|
|
|
|
*
|
2024-04-24 20:48:23 +03:00
|
|
|
* The class takes care of all aspects of configuration shortcuts, including handling key conflicts
|
|
|
|
* internally..
|
2014-11-13 01:04:59 +02:00
|
|
|
*
|
|
|
|
* @see KShortcutsDialog
|
2024-04-24 20:48:23 +03:00
|
|
|
* @author Ivailo Monev <xakepa10@gmail.com>
|
2014-11-13 01:04:59 +02:00
|
|
|
*/
|
|
|
|
class KDEUI_EXPORT KShortcutsEditor : public QWidget
|
|
|
|
{
|
2023-08-27 07:08:35 +03:00
|
|
|
Q_OBJECT
|
2014-11-13 01:04:59 +02:00
|
|
|
public:
|
2023-08-27 07:08:35 +03:00
|
|
|
enum ActionType {
|
2024-04-24 11:12:13 +03:00
|
|
|
/// Actions which are triggered by any keypress in a widget
|
2024-04-24 13:41:29 +03:00
|
|
|
LocalAction = 1,
|
2023-08-27 07:08:35 +03:00
|
|
|
/// Actions which are triggered by any keypress in the windowing system
|
2024-04-24 13:41:29 +03:00
|
|
|
GlobalAction = 2,
|
2023-08-27 07:08:35 +03:00
|
|
|
/// All actions
|
2024-04-24 11:12:13 +03:00
|
|
|
AllActions = (LocalAction | GlobalAction)
|
2023-08-27 07:08:35 +03:00
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(ActionTypes, ActionType)
|
|
|
|
|
|
|
|
enum LetterShortcuts {
|
|
|
|
/// Shortcuts without a modifier are not allowed,
|
|
|
|
/// so 'A' would not be valid, whereas 'Ctrl+A' would be.
|
|
|
|
/// This only applies to printable characters, however.
|
|
|
|
/// 'F1', 'Insert' etc. could still be used.
|
|
|
|
LetterShortcutsDisallowed = 0,
|
|
|
|
/// Letter shortcuts are allowed
|
|
|
|
LetterShortcutsAllowed
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param collection the KActionCollection to configure
|
|
|
|
* @param parent parent widget
|
|
|
|
* @param actionTypes types of actions to display in this widget.
|
2024-04-24 22:12:15 +03:00
|
|
|
* @param letterShortcuts set to LetterShortcutsDisallowed if unmodified alphanumeric
|
2023-08-27 07:08:35 +03:00
|
|
|
* keys ('A', '1', etc.) are not permissible shortcuts.
|
|
|
|
*/
|
|
|
|
KShortcutsEditor(KActionCollection *collection, QWidget *parent,
|
|
|
|
ActionTypes actionTypes = AllActions,
|
2024-04-24 22:12:15 +03:00
|
|
|
LetterShortcuts letterShortcuts = LetterShortcutsAllowed);
|
2023-08-27 07:08:35 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \overload
|
|
|
|
*
|
|
|
|
* Creates a key chooser without a starting action collection.
|
|
|
|
*
|
|
|
|
* @param parent parent widget
|
|
|
|
* @param actionTypes types of actions to display in this widget.
|
2024-04-24 22:12:15 +03:00
|
|
|
* @param letterShortcuts set to LetterShortcutsDisallowed if unmodified alphanumeric
|
2023-08-27 07:08:35 +03:00
|
|
|
* keys ('A', '1', etc.) are not permissible shortcuts.
|
|
|
|
*/
|
2024-04-24 13:41:29 +03:00
|
|
|
explicit KShortcutsEditor(QWidget *parent, ActionTypes actionTypes = AllActions,
|
2024-04-24 22:12:15 +03:00
|
|
|
LetterShortcuts letterShortcuts = LetterShortcutsAllowed);
|
2023-08-27 07:08:35 +03:00
|
|
|
|
|
|
|
/// Destructor
|
|
|
|
virtual ~KShortcutsEditor();
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Are the unsaved changes?
|
|
|
|
*/
|
|
|
|
bool isModified() const;
|
|
|
|
|
2023-08-27 07:08:35 +03:00
|
|
|
/**
|
|
|
|
* Removes all action collections from the editor
|
|
|
|
*/
|
|
|
|
void clearCollections();
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-08-27 07:08:35 +03:00
|
|
|
/**
|
|
|
|
* Insert an action collection, i.e. add all its actions to the ones
|
|
|
|
* already associated with the KShortcutsEditor object.
|
|
|
|
* @param title subtree title of this collection of shortcut.
|
|
|
|
*/
|
|
|
|
void addCollection(KActionCollection *, const QString &title = QString());
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Export the current setting to configuration @p config.
|
|
|
|
*
|
|
|
|
* This initializes the configuration object. This will export the global
|
|
|
|
* configuration too.
|
|
|
|
*
|
|
|
|
* @param config Config object
|
|
|
|
*/
|
2024-04-25 23:10:57 +03:00
|
|
|
void exportConfiguration(KConfigGroup *config = nullptr) const;
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Import the settings from configuration @p config.
|
|
|
|
*
|
|
|
|
* This will remove all current setting before importing. All shortcuts
|
2024-04-24 09:24:13 +03:00
|
|
|
* are set to QKeySequence() prior to importing from @p config!
|
2014-11-13 01:04:59 +02:00
|
|
|
*
|
|
|
|
* @param config Config object
|
|
|
|
*/
|
2024-04-25 23:10:57 +03:00
|
|
|
void importConfiguration(KConfigGroup *config = nullptr);
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
2023-08-27 07:08:35 +03:00
|
|
|
/**
|
|
|
|
* Emitted when an action's shortcut has been changed.
|
|
|
|
**/
|
|
|
|
void keyChange();
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
2023-08-27 07:08:35 +03:00
|
|
|
/**
|
|
|
|
* Set all shortcuts to their default values (bindings).
|
|
|
|
**/
|
|
|
|
void allDefault();
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
private:
|
2024-04-24 22:12:15 +03:00
|
|
|
Q_PRIVATE_SLOT(d, void _k_slotKeySequenceChanged())
|
2024-04-26 04:19:37 +03:00
|
|
|
Q_PRIVATE_SLOT(d, void _k_slotStealShortcut())
|
2024-04-24 22:12:15 +03:00
|
|
|
|
2023-08-27 07:08:35 +03:00
|
|
|
friend class KShortcutsDialog;
|
|
|
|
friend class KShortcutsEditorPrivate;
|
|
|
|
Q_DISABLE_COPY(KShortcutsEditor)
|
2024-04-24 22:12:15 +03:00
|
|
|
KShortcutsEditorPrivate *const d;
|
2014-11-13 01:04:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(KShortcutsEditor::ActionTypes)
|
|
|
|
|
|
|
|
#endif // KSHORTCUTSEDITOR_H
|