1 /* 2 * Copyright (C) 2019 Damir Porobic <damir.porobic@gmx.com> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef KSNIP_KEYSEQUENCELINEEDIT_H 21 #define KSNIP_KEYSEQUENCELINEEDIT_H 22 23 #include <QLineEdit> 24 #include <QKeySequence> 25 #include <QKeyEvent> 26 #include <QApplication> 27 28 #include "src/gui/globalHotKeys/KeyHandlerFactory.h" 29 #include "src/gui/globalHotKeys/NativeKeyEventFilter.h" 30 31 class KeySequenceLineEdit : public QLineEdit 32 { 33 Q_OBJECT 34 public: 35 explicit KeySequenceLineEdit(QWidget *widget, const QList<Qt::Key> &allowedKeys); 36 ~KeySequenceLineEdit() override; 37 QKeySequence value() const; 38 void setValue(const QKeySequence &keySequence); 39 void clear(); 40 41 protected: 42 void keyPressEvent(QKeyEvent *event) override; 43 void keyReleaseEvent(QKeyEvent *event) override; 44 void focusInEvent(QFocusEvent *event) override; 45 void focusOutEvent(QFocusEvent *event) override; 46 47 private: 48 QKeySequence mKeySequence; 49 Qt::KeyboardModifiers mModifiers; 50 Qt::Key mKey; 51 QList<Qt::Key> mAllowedKeys; 52 QList<QSharedPointer<NativeKeyEventFilter>> mSpecialKeyFilters; 53 54 void updateText(); 55 void keyPressed(Qt::Key key); 56 void setupSpecialKeyHandling(); 57 void updateKeySequence(); 58 void addSpecialKeyHandler(const QKeySequence &keySequence, Qt::Key key); 59 Qt::Key getAllowedKey(const QKeyEvent *event) const; 60 void removeSpecialKeyHandler(); 61 }; 62 63 64 #endif //KSNIP_KEYSEQUENCELINEEDIT_H 65