1 /***************************************************************************
2 * Copyright (C) 2005-2008 by Felix Geyer *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; version 2 of the License. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
20 #include "ShortcutWidget.h"
22 #if defined(GLOBAL_AUTOTYPE) && defined(Q_WS_X11)
27 #include "HelperX11.h"
28 #include "AutoTypeGlobalX11.h"
30 ShortcutWidget::ShortcutWidget(QWidget* parent) : QLineEdit(parent), lock(false), failed(false){
33 Shortcut ShortcutWidget::shortcut(){
40 void ShortcutWidget::setShortcut(const Shortcut& s){
42 displayShortcut(s.key, false, s.ctrl, s.shift, s.alt, s.altgr, s.win);
45 void ShortcutWidget::keyPressEvent(QKeyEvent* event){
46 keyEvent(event, false);
50 void ShortcutWidget::keyReleaseEvent(QKeyEvent* event){
51 keyEvent(event, true);
55 void ShortcutWidget::keyEvent(QKeyEvent* event, bool release){
59 AutoTypeGlobalX11* autoTypeGlobal = static_cast<AutoTypeGlobalX11*>(autoType);
61 unsigned int mods = HelperX11::keyboardModifiers(QX11Info::display());
62 displayShortcut(event->nativeVirtualKey(), release, mods & ControlMask,
63 mods & ShiftMask, mods & autoTypeGlobal->maskAlt(),
64 mods & autoTypeGlobal->maskAltGr(), mods & autoTypeGlobal->maskMeta());
67 void ShortcutWidget::displayShortcut(quint32 key, bool release, bool ctrl, bool shift, bool alt, bool altgr, bool win){
71 text.append(tr("Ctrl")).append(" + ");
73 text.append(tr("Shift")).append(" + ");
75 text.append(tr("Alt")).append(" + ");
77 text.append(tr("AltGr")).append(" + ");
79 text.append(tr("Win")).append(" + ");
81 if ( !release && (key<XK_Shift_L || key>XK_Hyper_R) && (key<XK_ISO_Lock || key>XK_ISO_Last_Group_Lock) ){
82 // converts key into orignal key on the keyboard
83 KeySym keysym = XKeycodeToKeysym(QX11Info::display(), XKeysymToKeycode(QX11Info::display(),key), 0);
84 if (keysym>=0xfd00 && keysym<=0xffff){
85 text.append(XKeysymToString(keysym));
88 text.append(static_cast<quint32>(keysym));
91 lock = ctrl || shift || alt || altgr || win;
93 pShortcut.key = keysym;
94 pShortcut.ctrl = ctrl;
95 pShortcut.shift = shift;
97 pShortcut.altgr = altgr;
99 failed = autoType->registerGlobalShortcut(pShortcut);
101 setBackgroundColor(QColor(255, 150, 150));
103 setBackgroundColor(Qt::white);
109 setBackgroundColor(Qt::white);
115 void ShortcutWidget::setBackgroundColor(const QColor& c){
116 QPalette p( palette() );
117 p.setColor(backgroundRole(), c);
123 ShortcutWidget::ShortcutWidget(QWidget* parent) : QLineEdit(parent){