Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
keycapturelineedit.cpp
1 /*
2 
3 Pencil - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2017 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 
19 #include <QKeyEvent>
20 #include <QDebug>
21 #include "keycapturelineedit.h"
22 
23 KeyCaptureLineEdit::KeyCaptureLineEdit(QWidget *parent) :
24  QLineEdit(parent)
25 {
26 }
27 
28 void KeyCaptureLineEdit::keyPressEvent(QKeyEvent* event)
29 {
30  if (event->key() == Qt::Key_Control ||
31  event->key() == Qt::Key_Shift ||
32  event->key() == Qt::Key_Alt ||
33  event->key() == Qt::Key_Meta )
34  {
35  // only modifier key is not allowed.
36  qDebug() << "only!";
37  event->accept();
38  return;
39  }
40 
41  int keyInt = event->key();
42 
43  if (event->modifiers() & Qt::CTRL)
44  {
45  keyInt += Qt::CTRL;
46  }
47  if (event->modifiers() & Qt::SHIFT)
48  {
49  keyInt += Qt::SHIFT;
50  }
51  if (event->modifiers() & Qt::ALT)
52  {
53  keyInt += Qt::ALT;
54  }
55  if (event->modifiers() & Qt::META)
56  {
57  keyInt += Qt::META;
58  }
59 
60  QKeySequence keySeq(keyInt);
61  QString strKeySeq = keySeq.toString(QKeySequence::NativeText);
62 
63  this->setText(strKeySeq);
64  emit keyCaptured(keySeq);
65 }