From ac3fa9168954faabc3acd37dde82479340b78283 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Sat, 8 Jul 2017 09:59:59 -0400 Subject: Clean up the LShortcutEvents class so it uses Qt::Key values now instead of raw keycodes. --- .../src-events/LShortcutEvents.cpp | 46 +++++++++++++++++----- .../src-events/LShortcutEvents.h | 7 ++-- 2 files changed, 41 insertions(+), 12 deletions(-) (limited to 'src-qt5/core/lumina-desktop-unified/src-events') diff --git a/src-qt5/core/lumina-desktop-unified/src-events/LShortcutEvents.cpp b/src-qt5/core/lumina-desktop-unified/src-events/LShortcutEvents.cpp index f8bb20d3..1b78da21 100644 --- a/src-qt5/core/lumina-desktop-unified/src-events/LShortcutEvents.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-events/LShortcutEvents.cpp @@ -106,15 +106,34 @@ void LShortcutEvents::CheckMouseSequence(WId win, NativeWindowSystem::MouseButto } QString LShortcutEvents::keylistToString(){ + if(keylist.isEmpty()){ return ""; } QString shortcut; + QList keys; int ckey = 0; for(int i=0; i0){ shortcut.append("+"); } - shortcut.append( QString::number(keylist[i]) ); + if(i == keylist.length()-1){ ckey+=keylist[i]; } //always treat the last key as a non-modifier + else if(keylist[i] == Qt::Key_Control){ ckey+=Qt::CTRL; } //use the modifier form of the key + else if(keylist[i] == Qt::Key_Alt){ ckey += Qt::ALT; } + else if(keylist[i] == Qt::Key_Shift){ ckey += Qt::SHIFT; } + else if(keylist[i] == Qt::Key_Meta){ ckey += Qt::META; } + else{ ckey+= keylist[i]; keys << ckey; ckey = 0; } //non-modifier - need to finish current mod+key combo and start a new one + } + if(ckey!=0){ keys << ckey; } //add in the last one as well + if(keys.length() < 1){ return ""; } + QKeySequence seq; + switch(keys.length()){ + case 1: + seq = QKeySequence(keys[0]); break; + case 2: + seq = QKeySequence(keys[0], keys[1]); break; + case 3: + seq = QKeySequence(keys[0], keys[1], keys[2]); break; + default: + seq = QKeySequence(keys[0],keys[1], keys[2], keys[3]); break; } /*qDebug() << "KeyList to String:"; - qDebug() << " keys:" << keylist; - qDebug() << " string:" << shortcut;*/ - return shortcut; + qDebug() << " keys:" << seq; + qDebug() << " string:" << seq.toString();*/ + return seq.toString(); } void LShortcutEvents::evaluateShortcutAction(QString action){ @@ -123,6 +142,8 @@ void LShortcutEvents::evaluateShortcutAction(QString action){ if(action.startsWith("Exec=")){ emit LaunchApplication(action.section("=",1,-1)); return; + }else if(action.startsWith("Launch=")){ + emit LaunchStandardApplication(action.section("=",1,-1)); } //Specific Internal actions action = action.toLower(); @@ -135,9 +156,9 @@ void LShortcutEvents::evaluateShortcutAction(QString action){ } // === PUBLIC SLOTS === -void LShortcutEvents::KeyPress(WId window, int key){ +void LShortcutEvents::KeyPress(WId window, Qt::Key key){ if(window!=WIN){ keylist.clear(); WIN = window; } - if(!keylist.contains(key)){ + /*if(!keylist.contains(key)){ //Put it in the list in ascending order bool found = false; for(int i=0; istart(); //will "restart" if already running } -void LShortcutEvents::KeyRelease(WId window, int key){ +void LShortcutEvents::KeyRelease(WId window, Qt::Key key){ if(window!=WIN){ keylist.clear(); return; } if(!evaluated){ CheckKeySequence(WIN); } //run this "before" removing the key from the list - keylist.removeAll(key); + for(int i=keylist.length()-1; i>=0; i--){ + if(keylist[i] == key){ keylist.removeAt(i); break; } + } clearTimer->start(); //will "restart" if already running } diff --git a/src-qt5/core/lumina-desktop-unified/src-events/LShortcutEvents.h b/src-qt5/core/lumina-desktop-unified/src-events/LShortcutEvents.h index a8ab4b38..4560cb1f 100644 --- a/src-qt5/core/lumina-desktop-unified/src-events/LShortcutEvents.h +++ b/src-qt5/core/lumina-desktop-unified/src-events/LShortcutEvents.h @@ -22,7 +22,7 @@ public: void stop(); private: - QList keylist; //keys currently held down (NOTE: QKeySequence has a max of 4 keys for combinations) + QList< Qt::Key > keylist; //keys currently held down WId WIN; //current window being acted on by the keys QTimer *clearTimer; //used to clear the internal keylist every once in a while if no events come in. bool evaluated; @@ -34,8 +34,8 @@ private: void evaluateShortcutAction(QString action); public slots: - void KeyPress(WId window, int key); - void KeyRelease(WId window, int key); + void KeyPress(WId window, Qt::Key key); + void KeyRelease(WId window, Qt::Key key); void MousePress(WId window, NativeWindowSystem::MouseButton); void MouseRelease(WId window, NativeWindowSystem::MouseButton); void clearKeys(); @@ -66,6 +66,7 @@ signals: //General Utility Launch void LaunchApplication(QString exec); + void LaunchStandardApplication(QString app); //standard app like "terminal", "browser", "email", "settings", etc.. }; -- cgit