qkeysequenceedit.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qkeysequenceedit.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7static_assert(bool(QKeySequencePrivate::MaxKeyCount == 4), "QKeySequencePrivate::MaxKeyCount == 4");-
8-
9void QKeySequenceEditPrivate::init()-
10{-
11 QKeySequenceEdit * const q = q_func();-
12-
13 lineEdit = new QLineEdit(q);-
14 lineEdit->setObjectName(([]() -> QString { enum { Size = sizeof(u"" "qt_keysequenceedit_lineedit")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "qt_keysequenceedit_lineedit" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return
never executed: return qstring_literal_temp;
qstring_literal_temp;
never executed: return qstring_literal_temp;
}()));
0
15 keyNum = 0;-
16 prevKey = -1;-
17 releaseTimer = 0;-
18-
19 QVBoxLayout *layout = new QVBoxLayout(q);-
20 layout->setContentsMargins(0, 0, 0, 0);-
21 layout->addWidget(lineEdit);-
22-
23 key[0] = key[1] = key[2] = key[3] = 0;-
24-
25 lineEdit->setFocusProxy(q);-
26 lineEdit->installEventFilter(q);-
27 resetState();-
28-
29 q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);-
30 q->setFocusPolicy(Qt::StrongFocus);-
31 q->setAttribute(Qt::WA_MacShowFocusRect, true);-
32 q->setAttribute(Qt::WA_InputMethodEnabled, false);-
33-
34-
35}
never executed: end of block
0
36-
37int QKeySequenceEditPrivate::translateModifiers(Qt::KeyboardModifiers state, const QString &text)-
38{-
39 int result = 0;-
40-
41-
42 if ((
(state & Qt::ShiftModifier)Description
TRUEnever evaluated
FALSEnever evaluated
state & Qt::ShiftModifier)
(state & Qt::ShiftModifier)Description
TRUEnever evaluated
FALSEnever evaluated
&& (text.isEmpty()
text.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
||
0
43 !text.at(0).isPrint()
!text.at(0).isPrint()Description
TRUEnever evaluated
FALSEnever evaluated
||
0
44 text.at(0).isLetterOrNumber()
text.at(0).isLetterOrNumber()Description
TRUEnever evaluated
FALSEnever evaluated
||
0
45 text.at(0).isSpace()
text.at(0).isSpace()Description
TRUEnever evaluated
FALSEnever evaluated
))
0
46 result |= Qt::SHIFT;
never executed: result |= Qt::SHIFT;
0
47-
48 if (state & Qt::ControlModifier
state & Qt::ControlModifierDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
49 result |= Qt::CTRL;
never executed: result |= Qt::CTRL;
0
50 if (state & Qt::MetaModifier
state & Qt::MetaModifierDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
51 result |= Qt::META;
never executed: result |= Qt::META;
0
52 if (state & Qt::AltModifier
state & Qt::AltModifierDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
53 result |= Qt::ALT;
never executed: result |= Qt::ALT;
0
54 return
never executed: return result;
result;
never executed: return result;
0
55}-
56-
57void QKeySequenceEditPrivate::resetState()-
58{-
59 QKeySequenceEdit * const q = q_func();-
60-
61 if (releaseTimer
releaseTimerDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
62 q->killTimer(releaseTimer);-
63 releaseTimer = 0;-
64 }
never executed: end of block
0
65 prevKey = -1;-
66 lineEdit->setText(keySequence.toString(QKeySequence::NativeText));-
67 lineEdit->setPlaceholderText(QKeySequenceEdit::tr("Press shortcut"));-
68}
never executed: end of block
0
69-
70void QKeySequenceEditPrivate::finishEditing()-
71{-
72 QKeySequenceEdit * const q = q_func();-
73-
74 resetState();-
75 q->keySequenceChanged(keySequence);-
76 q->editingFinished();-
77}
never executed: end of block
0
78QKeySequenceEdit::QKeySequenceEdit(QWidget *parent) :-
79 QWidget(*new QKeySequenceEditPrivate, parent, 0)-
80{-
81 QKeySequenceEditPrivate * const d = d_func();-
82 d->init();-
83}
never executed: end of block
0
84-
85-
86-
87-
88QKeySequenceEdit::QKeySequenceEdit(const QKeySequence &keySequence, QWidget *parent) :-
89 QWidget(*new QKeySequenceEditPrivate, parent, 0)-
90{-
91 QKeySequenceEditPrivate * const d = d_func();-
92 d->init();-
93 setKeySequence(keySequence);-
94}
never executed: end of block
0
95-
96-
97-
98-
99QKeySequenceEdit::QKeySequenceEdit(QKeySequenceEditPrivate &dd, QWidget *parent, Qt::WindowFlags f) :-
100 QWidget(dd, parent, f)-
101{-
102 QKeySequenceEditPrivate * const d = d_func();-
103 d->init();-
104}
never executed: end of block
0
105-
106-
107-
108-
109QKeySequenceEdit::~QKeySequenceEdit()-
110{-
111}-
112QKeySequence QKeySequenceEdit::keySequence() const-
113{-
114 const QKeySequenceEditPrivate * const d = d_func();-
115-
116 return
never executed: return d->keySequence;
d->keySequence;
never executed: return d->keySequence;
0
117}-
118-
119void QKeySequenceEdit::setKeySequence(const QKeySequence &keySequence)-
120{-
121 QKeySequenceEditPrivate * const d = d_func();-
122-
123 d->resetState();-
124-
125 if (d->keySequence == keySequence
d->keySequence == keySequenceDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
126 return;
never executed: return;
0
127-
128 d->keySequence = keySequence;-
129-
130 d->key[0] = d->key[1] = d->key[2] = d->key[3] = 0;-
131 d->keyNum = keySequence.count();-
132 for (int i = 0; i < d->keyNum
i < d->keyNumDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
133 d->key[i] = keySequence[i];
never executed: d->key[i] = keySequence[i];
0
134-
135 d->lineEdit->setText(keySequence.toString(QKeySequence::NativeText));-
136-
137 keySequenceChanged(keySequence);-
138}
never executed: end of block
0
139void QKeySequenceEdit::clear()-
140{-
141 setKeySequence(QKeySequence());-
142}
never executed: end of block
0
143-
144-
145-
146-
147bool QKeySequenceEdit::event(QEvent *e)-
148{-
149 switch (e->type()) {-
150 case
never executed: case QEvent::Shortcut:
QEvent::Shortcut:
never executed: case QEvent::Shortcut:
0
151 return
never executed: return true;
true;
never executed: return true;
0
152 case
never executed: case QEvent::ShortcutOverride:
QEvent::ShortcutOverride:
never executed: case QEvent::ShortcutOverride:
0
153 e->accept();-
154 return
never executed: return true;
true;
never executed: return true;
0
155 default
never executed: default :
:
never executed: default :
0
156 break;
never executed: break;
0
157 }-
158-
159 return
never executed: return QWidget::event(e);
QWidget::event(e);
never executed: return QWidget::event(e);
0
160}-
161-
162-
163-
164-
165void QKeySequenceEdit::keyPressEvent(QKeyEvent *e)-
166{-
167 QKeySequenceEditPrivate * const d = d_func();-
168-
169 int nextKey = e->key();-
170-
171 if (d->prevKey == -1
d->prevKey == -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
172 clear();-
173 d->prevKey = nextKey;-
174 }
never executed: end of block
0
175-
176 d->lineEdit->setPlaceholderText(QString());-
177 if (nextKey == Qt::Key_Control
nextKey == Qt::Key_ControlDescription
TRUEnever evaluated
FALSEnever evaluated
0
178 || nextKey == Qt::Key_Shift
nextKey == Qt::Key_ShiftDescription
TRUEnever evaluated
FALSEnever evaluated
0
179 || nextKey == Qt::Key_Meta
nextKey == Qt::Key_MetaDescription
TRUEnever evaluated
FALSEnever evaluated
0
180 || nextKey == Qt::Key_Alt
nextKey == Qt::Key_AltDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
181 return;
never executed: return;
0
182 }-
183-
184 QString selectedText = d->lineEdit->selectedText();-
185 if (!selectedText.isEmpty()
!selectedText.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
&& selectedText == d->lineEdit->text()
selectedText =...neEdit->text()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
186 clear();-
187 if (nextKey == Qt::Key_Backspace
nextKey == Qt::Key_BackspaceDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
188 return;
never executed: return;
0
189 }
never executed: end of block
0
190-
191 if (d->keyNum >= QKeySequencePrivate::MaxKeyCount
d->keyNum >= Q...e::MaxKeyCountDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
192 return;
never executed: return;
0
193-
194 nextKey |= d->translateModifiers(e->modifiers(), e->text());-
195-
196 d->key[d->keyNum] = nextKey;-
197 d->keyNum++;-
198-
199 QKeySequence key(d->key[0], d->key[1], d->key[2], d->key[3]);-
200 d->keySequence = key;-
201 QString text = key.toString(QKeySequence::NativeText);-
202 if (d->keyNum < QKeySequencePrivate::MaxKeyCount
d->keyNum < QK...e::MaxKeyCountDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
203-
204 text = tr("%1, ...").arg(text);-
205 }
never executed: end of block
0
206 d->lineEdit->setText(text);-
207 e->accept();-
208}
never executed: end of block
0
209-
210-
211-
212-
213void QKeySequenceEdit::keyReleaseEvent(QKeyEvent *e)-
214{-
215 QKeySequenceEditPrivate * const d = d_func();-
216-
217 if (d->prevKey == e->key()
d->prevKey == e->key()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
218 if (d->keyNum < QKeySequencePrivate::MaxKeyCount
d->keyNum < QK...e::MaxKeyCountDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
219 d->releaseTimer = startTimer(1000);
never executed: d->releaseTimer = startTimer(1000);
0
220 else-
221 d->finishEditing();
never executed: d->finishEditing();
0
222 }-
223 e->accept();-
224}
never executed: end of block
0
225-
226-
227-
228-
229void QKeySequenceEdit::timerEvent(QTimerEvent *e)-
230{-
231 QKeySequenceEditPrivate * const d = d_func();-
232 if (e->timerId() == d->releaseTimer
e->timerId() =...->releaseTimerDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
233 d->finishEditing();-
234 return;
never executed: return;
0
235 }-
236-
237 QWidget::timerEvent(e);-
238}
never executed: end of block
0
239-
240-
241-
242-
243-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9