1 /***************************************************************************
2 * Copyright (C) 2005-2014 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This class has been inspired by KDE's KKeySequenceWidget and uses *
6 * some code snippets of its implementation, part of kdelibs. *
7 * The original file is *
8 * Copyright (C) 1998 Mark Donohoe <donohoe@kde.org> *
9 * Copyright (C) 2001 Ellis Whitehead <ellis@kde.org> *
10 * Copyright (C) 2007 Andreas Hartmetz <ahartmetz@gmail.com> *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
17 * This program is distributed in the hope that it will be useful, *
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20 * GNU General Public License for more details. *
22 * You should have received a copy of the GNU General Public License *
23 * along with this program; if not, write to the *
24 * Free Software Foundation, Inc., *
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
26 ***************************************************************************/
28 #ifndef KEYSEQUENCEWIDGET_H
29 #define KEYSEQUENCEWIDGET_H
31 #include <QKeySequence>
32 #include <QPushButton>
36 #include "shortcutsmodel.h"
39 class ActionCollection;
40 class KeySequenceButton;
43 class KeySequenceWidget : public QWidget
47 KeySequenceWidget(QWidget *parent = 0);
49 void setModel(ShortcutsModel *model);
52 void setKeySequence(const QKeySequence &seq);
56 * This signal is emitted when the current key sequence has changed by user input
57 * \param seq The key sequence the user has chosen
58 * \param conflicting The index of an action that needs to have its shortcut removed. The user has already been
59 * asked to agree (if he declines, this signal won't be emitted at all).
61 void keySequenceChanged(const QKeySequence &seq, const QModelIndex &conflicting = QModelIndex());
66 void updateShortcutDisplay();
67 void startRecording();
68 void cancelRecording();
72 inline bool isRecording() const { return _isRecording; }
75 bool isOkWhenModifierless(int keyQt) const;
76 bool isShiftAsModifierAllowed(int keyQt) const;
77 bool isKeySequenceAvailable(const QKeySequence &seq);
79 ShortcutsModel *_shortcutsModel;
81 QKeySequence _keySequence, _oldKeySequence;
83 QModelIndex _conflictingIndex;
85 KeySequenceButton *_keyButton;
86 QToolButton *_clearButton;
88 friend class KeySequenceButton;
92 /*****************************************************************************/
94 class KeySequenceButton : public QPushButton
98 explicit KeySequenceButton(KeySequenceWidget *d, QWidget *parent = 0);
101 virtual bool event(QEvent *event);
102 virtual void keyPressEvent(QKeyEvent *event);
103 virtual void keyReleaseEvent(QKeyEvent *event);
106 KeySequenceWidget *d;
110 #endif // KEYSEQUENCEWIDGET_H