1 /***************************************************************************
2 * Copyright (C) 2010 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 {
46 KeySequenceWidget(QWidget *parent = 0);
48 void setModel(ShortcutsModel *model);
51 void setKeySequence(const QKeySequence &seq);
55 * This signal is emitted when the current key sequence has changed by user input
56 * \param seq The key sequence the user has chosen
57 * \param conflicting The index of an action that needs to have its shortcut removed. The user has already been
58 * asked to agree (if he declines, this signal won't be emitted at all).
60 void keySequenceChanged(const QKeySequence &seq, const QModelIndex &conflicting = QModelIndex());
65 void updateShortcutDisplay();
66 void startRecording();
67 void cancelRecording();
71 inline bool isRecording() const { return _isRecording; }
74 bool isOkWhenModifierless(int keyQt) const;
75 bool isShiftAsModifierAllowed(int keyQt) const;
76 bool isKeySequenceAvailable(const QKeySequence &seq);
78 ShortcutsModel *_shortcutsModel;
80 QKeySequence _keySequence, _oldKeySequence;
82 QModelIndex _conflictingIndex;
84 KeySequenceButton *_keyButton;
85 QToolButton *_clearButton;
87 friend class KeySequenceButton;
91 /*****************************************************************************/
93 class KeySequenceButton : public QPushButton {
96 explicit KeySequenceButton(KeySequenceWidget *d, QWidget *parent = 0);
99 virtual bool event(QEvent *event);
100 virtual void keyPressEvent(QKeyEvent *event);
101 virtual void keyReleaseEvent(QKeyEvent *event);
104 KeySequenceWidget *d;
107 #endif // KEYSEQUENCEWIDGET_H