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
25
26#include <QKeyEvent>
27
31
32void
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 || key == Qt::Key_Shift || key == Qt::Key_Alt ||
49 key == Qt::Key_Meta)
50 {
51 return;
52 }
53
54 // check for a combination of user clicks
55 Qt::KeyboardModifiers modifiers = keyEvent->modifiers();
56 QString keyText = keyEvent->text();
57 // if the keyText is empty than it's a special key like F1, F5, ...
58
59 QList<Qt::Key> modifiersList;
60
61 if (modifiers & Qt::ShiftModifier)
62 {
63 keyInt += Qt::SHIFT;
64 }
65
66 if (modifiers & Qt::ControlModifier)
67 {
68 keyInt += Qt::CTRL;
69 }
70
71 if (modifiers & Qt::AltModifier)
72 {
73 keyInt += Qt::ALT;
74 }
75
76 if (modifiers & Qt::MetaModifier)
77 {
78 keyInt += Qt::META;
79 }
80
81 this->setText(QKeySequence(keyInt).toString(QKeySequence::NativeText));
82 }
83}
84
85void
ClearableLineEdit(QWidget *parent=0)
Constructor.
LiveShortcutLineEdit(QWidget *parent=0)
Constructor.
void keyPressEvent(QKeyEvent *event) override
Event triggered when a key is pressed.
void publicKeyPressEvent(QKeyEvent *event)
Redirects given event to protected method keyPressEvent.