| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qkeysequenceedit.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | - | |||||||||||||||||||
| 7 | static_assert(bool(QKeySequencePrivate::MaxKeyCount == 4), "QKeySequencePrivate::MaxKeyCount == 4"); | - | ||||||||||||||||||
| 8 | - | |||||||||||||||||||
| 9 | void 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: qstring_literal_temp;return 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 | - | |||||||||||||||||||
| 37 | int QKeySequenceEditPrivate::translateModifiers(Qt::KeyboardModifiers state, const QString &text) | - | ||||||||||||||||||
| 38 | { | - | ||||||||||||||||||
| 39 | int result = 0; | - | ||||||||||||||||||
| 40 | - | |||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | if ((
| 0 | ||||||||||||||||||
| 43 | !text.at(0).isPrint()
| 0 | ||||||||||||||||||
| 44 | text.at(0).isLetterOrNumber()
| 0 | ||||||||||||||||||
| 45 | text.at(0).isSpace()
| 0 | ||||||||||||||||||
| 46 | result |= Qt::SHIFT; never executed: result |= Qt::SHIFT; | 0 | ||||||||||||||||||
| 47 | - | |||||||||||||||||||
| 48 | if (state & Qt::ControlModifier
| 0 | ||||||||||||||||||
| 49 | result |= Qt::CTRL; never executed: result |= Qt::CTRL; | 0 | ||||||||||||||||||
| 50 | if (state & Qt::MetaModifier
| 0 | ||||||||||||||||||
| 51 | result |= Qt::META; never executed: result |= Qt::META; | 0 | ||||||||||||||||||
| 52 | if (state & Qt::AltModifier
| 0 | ||||||||||||||||||
| 53 | result |= Qt::ALT; never executed: result |= Qt::ALT; | 0 | ||||||||||||||||||
| 54 | return never executed: result;return result;never executed: return result; | 0 | ||||||||||||||||||
| 55 | } | - | ||||||||||||||||||
| 56 | - | |||||||||||||||||||
| 57 | void QKeySequenceEditPrivate::resetState() | - | ||||||||||||||||||
| 58 | { | - | ||||||||||||||||||
| 59 | QKeySequenceEdit * const q = q_func(); | - | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | if (releaseTimer
| 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 | - | |||||||||||||||||||
| 70 | void 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 | ||||||||||||||||||
| 78 | QKeySequenceEdit::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 | - | |||||||||||||||||||
| 88 | QKeySequenceEdit::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 | - | |||||||||||||||||||
| 99 | QKeySequenceEdit::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 | - | |||||||||||||||||||
| 109 | QKeySequenceEdit::~QKeySequenceEdit() | - | ||||||||||||||||||
| 110 | { | - | ||||||||||||||||||
| 111 | } | - | ||||||||||||||||||
| 112 | QKeySequence QKeySequenceEdit::keySequence() const | - | ||||||||||||||||||
| 113 | { | - | ||||||||||||||||||
| 114 | const QKeySequenceEditPrivate * const d = d_func(); | - | ||||||||||||||||||
| 115 | - | |||||||||||||||||||
| 116 | return never executed: d->keySequence;return d->keySequence;never executed: return d->keySequence; | 0 | ||||||||||||||||||
| 117 | } | - | ||||||||||||||||||
| 118 | - | |||||||||||||||||||
| 119 | void QKeySequenceEdit::setKeySequence(const QKeySequence &keySequence) | - | ||||||||||||||||||
| 120 | { | - | ||||||||||||||||||
| 121 | QKeySequenceEditPrivate * const d = d_func(); | - | ||||||||||||||||||
| 122 | - | |||||||||||||||||||
| 123 | d->resetState(); | - | ||||||||||||||||||
| 124 | - | |||||||||||||||||||
| 125 | if (d->keySequence == keySequence
| 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
| 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 | ||||||||||||||||||
| 139 | void QKeySequenceEdit::clear() | - | ||||||||||||||||||
| 140 | { | - | ||||||||||||||||||
| 141 | setKeySequence(QKeySequence()); | - | ||||||||||||||||||
| 142 | } never executed: end of block | 0 | ||||||||||||||||||
| 143 | - | |||||||||||||||||||
| 144 | - | |||||||||||||||||||
| 145 | - | |||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | bool QKeySequenceEdit::event(QEvent *e) | - | ||||||||||||||||||
| 148 | { | - | ||||||||||||||||||
| 149 | switch (e->type()) { | - | ||||||||||||||||||
| 150 | case never executed: QEvent::Shortcut:case QEvent::Shortcut:never executed: case QEvent::Shortcut: | 0 | ||||||||||||||||||
| 151 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 152 | case never executed: QEvent::ShortcutOverride:case QEvent::ShortcutOverride:never executed: case QEvent::ShortcutOverride: | 0 | ||||||||||||||||||
| 153 | e->accept(); | - | ||||||||||||||||||
| 154 | return never executed: true;return 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: QWidget::event(e);return QWidget::event(e);never executed: return QWidget::event(e); | 0 | ||||||||||||||||||
| 160 | } | - | ||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | - | |||||||||||||||||||
| 163 | - | |||||||||||||||||||
| 164 | - | |||||||||||||||||||
| 165 | void QKeySequenceEdit::keyPressEvent(QKeyEvent *e) | - | ||||||||||||||||||
| 166 | { | - | ||||||||||||||||||
| 167 | QKeySequenceEditPrivate * const d = d_func(); | - | ||||||||||||||||||
| 168 | - | |||||||||||||||||||
| 169 | int nextKey = e->key(); | - | ||||||||||||||||||
| 170 | - | |||||||||||||||||||
| 171 | if (d->prevKey == -1
| 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
| 0 | ||||||||||||||||||
| 178 | || nextKey == Qt::Key_Shift
| 0 | ||||||||||||||||||
| 179 | || nextKey == Qt::Key_Meta
| 0 | ||||||||||||||||||
| 180 | || nextKey == Qt::Key_Alt
| 0 | ||||||||||||||||||
| 181 | return; never executed: return; | 0 | ||||||||||||||||||
| 182 | } | - | ||||||||||||||||||
| 183 | - | |||||||||||||||||||
| 184 | QString selectedText = d->lineEdit->selectedText(); | - | ||||||||||||||||||
| 185 | if (!selectedText.isEmpty()
| 0 | ||||||||||||||||||
| 186 | clear(); | - | ||||||||||||||||||
| 187 | if (nextKey == Qt::Key_Backspace
| 0 | ||||||||||||||||||
| 188 | return; never executed: return; | 0 | ||||||||||||||||||
| 189 | } never executed: end of block | 0 | ||||||||||||||||||
| 190 | - | |||||||||||||||||||
| 191 | if (d->keyNum >= QKeySequencePrivate::MaxKeyCount
| 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
| 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 | - | |||||||||||||||||||
| 213 | void QKeySequenceEdit::keyReleaseEvent(QKeyEvent *e) | - | ||||||||||||||||||
| 214 | { | - | ||||||||||||||||||
| 215 | QKeySequenceEditPrivate * const d = d_func(); | - | ||||||||||||||||||
| 216 | - | |||||||||||||||||||
| 217 | if (d->prevKey == e->key()
| 0 | ||||||||||||||||||
| 218 | if (d->keyNum < QKeySequencePrivate::MaxKeyCount
| 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 | - | |||||||||||||||||||
| 229 | void QKeySequenceEdit::timerEvent(QTimerEvent *e) | - | ||||||||||||||||||
| 230 | { | - | ||||||||||||||||||
| 231 | QKeySequenceEditPrivate * const d = d_func(); | - | ||||||||||||||||||
| 232 | if (e->timerId() == d->releaseTimer
| 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 code | Preprocessed file |