File indexing completed on 2024-04-21 05:51:23
0001 /* 0002 SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KEYBINDINGEDITOR_H 0008 #define KEYBINDINGEDITOR_H 0009 0010 // Qt 0011 #include <QDialog> 0012 0013 // Konsole 0014 // TODO: Move away Profile::Property from the profile header. 0015 #include "profile/Profile.h" 0016 0017 class QTableWidgetItem; 0018 0019 namespace Ui 0020 { 0021 class KeyBindingEditor; 0022 } 0023 0024 namespace Konsole 0025 { 0026 class KeyboardTranslator; 0027 0028 /** 0029 * A dialog which allows the user to edit a key bindings scheme 0030 * which maps between key combinations input by the user and 0031 * the character sequence sent to the terminal when those 0032 * combinations are pressed. 0033 * 0034 * The dialog can be initialized with the settings of an 0035 * existing key bindings scheme using the setup() method. 0036 * 0037 * The dialog creates a copy of the supplied keyboard translator 0038 * to which any changes are applied. The modified translator 0039 * can be retrieved using the translator() method. 0040 */ 0041 class KeyBindingEditor : public QDialog 0042 { 0043 Q_OBJECT 0044 0045 public: 0046 /** Constructs a new key bindings editor with the specified parent. */ 0047 explicit KeyBindingEditor(QWidget *parent = nullptr); 0048 ~KeyBindingEditor() override; 0049 0050 /** 0051 * Initializes the dialog with the bindings and other settings 0052 * from the specified @p translator. 0053 * @p currentProfileTranslator the name of the translator set in the 0054 * current profile 0055 * @p isNewTranslator specifies whether the translator being edited 0056 * is an already existing one or a newly created 0057 * one, defaults to false. 0058 */ 0059 void setup(const KeyboardTranslator *translator, const QString ¤tProfileTranslator, bool isNewTranslator = false); 0060 0061 /** 0062 * Returns the modified translator describing the changes to the bindings 0063 * and other settings which the user made. 0064 */ 0065 KeyboardTranslator *translator() const; 0066 0067 /** 0068 * Sets the text of the editor's description field. 0069 */ 0070 void setDescription(const QString &description); 0071 0072 /** 0073 * Returns the text of the editor's description field. 0074 */ 0075 QString description() const; 0076 0077 // reimplemented to handle test area input 0078 bool eventFilter(QObject *watched, QEvent *event) override; 0079 0080 Q_SIGNALS: 0081 /** 0082 * Emitted when the user clicks the OK button to save the changes. This 0083 * signal is connected to EditProfileDialog::updateKeyBindingsList() 0084 * to update the key bindings list on the Keyboard tab in the Edit 0085 * Profile dialog. 0086 * @p translatorName is the translator that has just been edited 0087 */ 0088 void updateKeyBindingsListRequest(const QString &translatorName); 0089 0090 /** 0091 * Emitted when the user clicks the OK button to save the changes to 0092 * the translator that's set in the current profile; this signal is 0093 * connected to EditProfileDialog::updateTempProfileProperty() to 0094 * request applying the changes to the _tempProfile. 0095 * @p newTranslatorName is the name of the translator, that has just 0096 * been edited/saved, and which is also the translator 0097 * set in the current Profile 0098 */ 0099 void updateTempProfileKeyBindingsRequest(Profile::Property, const QString &newTranslatorName); 0100 0101 private Q_SLOTS: 0102 // reimplemented 0103 void accept() override; 0104 0105 void setTranslatorDescription(const QString &description); 0106 void bindingTableItemChanged(QTableWidgetItem *item); 0107 void removeSelectedEntry(); 0108 void addNewEntry(); 0109 0110 private: 0111 Q_DISABLE_COPY(KeyBindingEditor) 0112 0113 void setupKeyBindingTable(const KeyboardTranslator *translator); 0114 0115 Ui::KeyBindingEditor *_ui; 0116 0117 // translator to which modifications are made as the user makes 0118 // changes in the UI. 0119 // this is initialized as a copy of the translator specified 0120 // when setup() is called 0121 KeyboardTranslator *_translator; 0122 0123 // Show only the rows that match the text entered by the user in the 0124 // filter search box 0125 void filterRows(const QString &text); 0126 0127 bool _isNewTranslator; 0128 0129 // The translator set in the current profile 0130 QString _currentProfileTranslator; 0131 0132 // Sets the size hint of the dialog to be slightly smaller than the 0133 // size of EditProfileDialog 0134 QSize sizeHint() const override; 0135 }; 0136 } 0137 0138 #endif // KEYBINDINGEDITOR_H