LiveShortcutLineEdit.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package MemoryX::gui-plugins::SceneEditor
19  * @date 2015
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 #include "LiveShortcutLineEdit.h"
25 
26 #include <QKeyEvent>
27 
29  ClearableLineEdit(parent)
30 {
31 }
32 
34 {
35  if (event->type() == QEvent::KeyPress)
36  {
37  QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
38 
39  int keyInt = keyEvent->key();
40  Qt::Key key = static_cast<Qt::Key>(keyInt);
41 
42  if (key == Qt::Key_unknown)
43  {
44  return;
45  }
46 
47  // the user have clicked just and only the special keys Ctrl, Shift, Alt, Meta.
48  if (key == Qt::Key_Control ||
49  key == Qt::Key_Shift ||
50  key == Qt::Key_Alt ||
51  key == Qt::Key_Meta)
52  {
53  return;
54  }
55 
56  // check for a combination of user clicks
57  Qt::KeyboardModifiers modifiers = keyEvent->modifiers();
58  QString keyText = keyEvent->text();
59  // if the keyText is empty than it's a special key like F1, F5, ...
60 
61  QList<Qt::Key> modifiersList;
62 
63  if (modifiers & Qt::ShiftModifier)
64  {
65  keyInt += Qt::SHIFT;
66  }
67 
68  if (modifiers & Qt::ControlModifier)
69  {
70  keyInt += Qt::CTRL;
71  }
72 
73  if (modifiers & Qt::AltModifier)
74  {
75  keyInt += Qt::ALT;
76  }
77 
78  if (modifiers & Qt::MetaModifier)
79  {
80  keyInt += Qt::META;
81  }
82 
83  this->setText(QKeySequence(keyInt).toString(QKeySequence::NativeText));
84  }
85 }
86 
88 {
89  keyPressEvent(event);
90 }
gui::dialog::LiveShortcutLineEdit::LiveShortcutLineEdit
LiveShortcutLineEdit(QWidget *parent=0)
Constructor.
Definition: LiveShortcutLineEdit.cpp:28
LiveShortcutLineEdit.h
gui::ClearableLineEdit
This class is a custom QLineEdit which provides a button to clear the text of the line edit.
Definition: ClearableLineEdit.h:41
gui::dialog::LiveShortcutLineEdit::keyPressEvent
void keyPressEvent(QKeyEvent *event) override
Event triggered when a key is pressed.
Definition: LiveShortcutLineEdit.cpp:33
armarx::viz::toString
const char * toString(InteractionFeedbackType type)
Definition: Interaction.h:27
gui::dialog::LiveShortcutLineEdit::publicKeyPressEvent
void publicKeyPressEvent(QKeyEvent *event)
Redirects given event to protected method keyPressEvent.
Definition: LiveShortcutLineEdit.cpp:87