Debian Codegraph @

qt5/widgetsaddons/fcitxqtkeysequencewidget.h

raw
1 /***************************************************************************
2 * Copyright (C) 2013~2013 by CSSlayer *
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 *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
19
20 /* this is forked from kdelibs/kdeui/kkeysequencewidget.h */
21
22 /*
23 Original Copyright header
24 This file is part of the KDE libraries
25 Copyright (C) 2001, 2002 Ellis Whitehead <[email protected]>
26 Copyright (C) 2007 Andreas Hartmetz <[email protected]>
27
28 This library is free software; you can redistribute it and/or
29 modify it under the terms of the GNU Library General Public
30 License as published by the Free Software Foundation; either
31 version 2 of the License, or (at your option) any later version.
32
33 This library is distributed in the hope that it will be useful,
34 but WITHOUT ANY WARRANTY; without even the implied warranty of
35 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36 Library General Public License for more details.
37
38 You should have received a copy of the GNU Library General Public License
39 along with this library; see the file COPYING.LIB. If not, write to
40 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
41 Boston, MA 02110-1301, USA.
42 */
43
44 #ifndef KKEYSEQUENCEWIDGET_H
45 #define KKEYSEQUENCEWIDGET_H
46
47 #include <QtCore/QList>
48 #include <QtWidgets/QPushButton>
49
50 #include "fcitxqtwidgetsaddons_export.h"
51
52 enum FcitxQtModifierSide { MS_Unknown = 0, MS_Left = 1, MS_Right = 2 };
53
54 class FcitxQtKeySequenceWidgetPrivate;
55
56 class FCITXQTWIDGETSADDONS_EXPORT FcitxQtKeySequenceWidget : public QWidget {
57 Q_OBJECT
58
59 Q_PROPERTY(bool multiKeyShortcutsAllowed READ multiKeyShortcutsAllowed WRITE
60 setMultiKeyShortcutsAllowed)
61
62 Q_PROPERTY(bool modifierlessAllowed READ isModifierlessAllowed WRITE
63 setModifierlessAllowed)
64
65 Q_PROPERTY(bool modifierOnlyAllowed READ isModifierOnlyAllowed WRITE
66 setModifierOnlyAllowed)
67
68 public:
69 enum Validation { Validate = 0, NoValidate = 1 };
70
71 /**
72 * Constructor.
73 */
74 explicit FcitxQtKeySequenceWidget(QWidget *parent = 0);
75
76 /**
77 * Destructs the widget.
78 */
79 virtual ~FcitxQtKeySequenceWidget();
80
81 void setMultiKeyShortcutsAllowed(bool);
82 bool multiKeyShortcutsAllowed() const;
83
84 void setModifierlessAllowed(bool allow);
85 bool isModifierlessAllowed();
86
87 void setModifierOnlyAllowed(bool allow);
88 bool isModifierOnlyAllowed();
89
90 /*
91 * only useful when modifierOnlyAllowed is true
92 * and the key is modifierOnly.
93 */
94 FcitxQtModifierSide modifierSide();
95
96 void setClearButtonShown(bool show);
97
98 QKeySequence keySequence() const;
99
100 static void keyQtToFcitx(int keyQt, FcitxQtModifierSide side, int &outsym,
101 uint &outstate);
102 static int keyFcitxToQt(int sym, uint state);
103
104 Q_SIGNALS:
105 void keySequenceChanged(const QKeySequence &seq, FcitxQtModifierSide side);
106
107 public Q_SLOTS:
108 void captureKeySequence();
109 void setKeySequence(const QKeySequence &seq,
110 FcitxQtModifierSide side = MS_Unknown,
111 Validation val = NoValidate);
112 void clearKeySequence();
113
114 private:
115 friend class FcitxQtKeySequenceWidgetPrivate;
116 FcitxQtKeySequenceWidgetPrivate *const d;
117
118 Q_DISABLE_COPY(FcitxQtKeySequenceWidget)
119 };
120
121 #endif // KKEYSEQUENCEWIDGET_H