From 0e24f4ead4e7626f2fee21713922b4091462b573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 9 Sep 2013 09:41:37 +0200 Subject: [PATCH] Introduce an initShortcut method for kwinbindings Method replaces the logic of the macros. The macros are still there to not need to change all the code. Major difference is that the new method uses the compile time checked connect syntax. --- kwinbindings.cpp | 133 ++++++++++++++++++++++------------------------- useractions.cpp | 14 +++++ workspace.h | 3 ++ 3 files changed, 79 insertions(+), 71 deletions(-) diff --git a/kwinbindings.cpp b/kwinbindings.cpp index af662ea89..dcc6aad5c 100644 --- a/kwinbindings.cpp +++ b/kwinbindings.cpp @@ -28,22 +28,13 @@ along with this program. If not, see . // new DEF3 allows to pass data to the action, replacing the %1 argument in the name #define DEF2( name, descr, key, fnSlot ) \ - a = actionCollection->addAction( QStringLiteral(name) ); \ - a->setText( i18n(descr) ); \ - KGlobalAccel::self()->setDefaultShortcut(a, QList() << key); \ - KGlobalAccel::self()->setShortcut(a, QList() << key); \ - connect(a, SIGNAL(triggered(bool)), SLOT(fnSlot)); + initShortcut(QStringLiteral(name), i18n(descr), key, &Workspace::fnSlot); #define DEF( name, key, fnSlot ) \ - DEF2(name, name, key, fnSlot) + initShortcut(QStringLiteral(name), i18n(name), key, &Workspace::fnSlot); #define DEF3( name, key, fnSlot, value ) \ - a = actionCollection->addAction( QStringLiteral(name).arg(value) ); \ - a->setText( i18n(name, value) ); \ - KGlobalAccel::self()->setDefaultShortcut(a, QList() << key); \ - KGlobalAccel::self()->setShortcut(a, QList() << key); \ - a->setData(value); \ - connect(a, SIGNAL(triggered(bool)), SLOT(fnSlot)); + initShortcut(QStringLiteral(name).arg(value), i18n(name, value), key, &Workspace::fnSlot, value); a = actionCollection->addAction(QStringLiteral("Program:kwin")); @@ -51,123 +42,123 @@ a->setText(i18n("System")); a = actionCollection->addAction(QStringLiteral("Group:Navigation")); a->setText(i18n("Navigation")); -DEF(I18N_NOOP("Walk Through Window Tabs"), 0, slotActivateNextTab()); -DEF(I18N_NOOP("Walk Through Window Tabs (Reverse)"), 0, slotActivatePrevTab()); -DEF(I18N_NOOP("Remove Window From Group"), 0, slotUntab()); +DEF(I18N_NOOP("Walk Through Window Tabs"), 0, slotActivateNextTab); +DEF(I18N_NOOP("Walk Through Window Tabs (Reverse)"), 0, slotActivatePrevTab); +DEF(I18N_NOOP("Remove Window From Group"), 0, slotUntab); a = actionCollection->addAction(QStringLiteral("Group:Windows")); a->setText(i18n("Windows")); DEF(I18N_NOOP("Window Operations Menu"), - Qt::ALT + Qt::Key_F3, slotWindowOperations()); + Qt::ALT + Qt::Key_F3, slotWindowOperations); DEF2("Window Close", I18N_NOOP("Close Window"), - Qt::ALT + Qt::Key_F4, slotWindowClose()); + Qt::ALT + Qt::Key_F4, slotWindowClose); DEF2("Window Maximize", I18N_NOOP("Maximize Window"), - 0, slotWindowMaximize()); + 0, slotWindowMaximize); DEF2("Window Maximize Vertical", I18N_NOOP("Maximize Window Vertically"), - 0, slotWindowMaximizeVertical()); + 0, slotWindowMaximizeVertical); DEF2("Window Maximize Horizontal", I18N_NOOP("Maximize Window Horizontally"), - 0, slotWindowMaximizeHorizontal()); + 0, slotWindowMaximizeHorizontal); DEF2("Window Minimize", I18N_NOOP("Minimize Window"), - 0, slotWindowMinimize()); + 0, slotWindowMinimize); DEF2("Window Shade", I18N_NOOP("Shade Window"), - 0, slotWindowShade()); + 0, slotWindowShade); DEF2("Window Move", I18N_NOOP("Move Window"), - 0, slotWindowMove()); + 0, slotWindowMove); DEF2("Window Resize", I18N_NOOP("Resize Window"), - 0, slotWindowResize()); + 0, slotWindowResize); DEF2("Window Raise", I18N_NOOP("Raise Window"), - 0, slotWindowRaise()); + 0, slotWindowRaise); DEF2("Window Lower", I18N_NOOP("Lower Window"), - 0, slotWindowLower()); + 0, slotWindowLower); DEF(I18N_NOOP("Toggle Window Raise/Lower"), - 0, slotWindowRaiseOrLower()); + 0, slotWindowRaiseOrLower); DEF2("Window Fullscreen", I18N_NOOP("Make Window Fullscreen"), - 0, slotWindowFullScreen()); + 0, slotWindowFullScreen); DEF2("Window No Border", I18N_NOOP("Hide Window Border"), - 0, slotWindowNoBorder()); + 0, slotWindowNoBorder); DEF2("Window Above Other Windows", I18N_NOOP("Keep Window Above Others"), - 0, slotWindowAbove()); + 0, slotWindowAbove); DEF2("Window Below Other Windows", I18N_NOOP("Keep Window Below Others"), - 0, slotWindowBelow()); + 0, slotWindowBelow); DEF(I18N_NOOP("Activate Window Demanding Attention"), - Qt::CTRL + Qt::ALT + Qt::Key_A, slotActivateAttentionWindow()); + Qt::CTRL + Qt::ALT + Qt::Key_A, slotActivateAttentionWindow); DEF(I18N_NOOP("Setup Window Shortcut"), - 0, slotSetupWindowShortcut()); + 0, slotSetupWindowShortcut); DEF2("Window Pack Right", I18N_NOOP("Pack Window to the Right"), - 0, slotWindowPackRight()); + 0, slotWindowPackRight); DEF2("Window Pack Left", I18N_NOOP("Pack Window to the Left"), - 0, slotWindowPackLeft()); + 0, slotWindowPackLeft); DEF2("Window Pack Up", I18N_NOOP("Pack Window Up"), - 0, slotWindowPackUp()); + 0, slotWindowPackUp); DEF2("Window Pack Down", I18N_NOOP("Pack Window Down"), - 0, slotWindowPackDown()); + 0, slotWindowPackDown); DEF2("Window Grow Horizontal", I18N_NOOP("Pack Grow Window Horizontally"), - 0, slotWindowGrowHorizontal()); + 0, slotWindowGrowHorizontal); DEF2("Window Grow Vertical", I18N_NOOP("Pack Grow Window Vertically"), - 0, slotWindowGrowVertical()); + 0, slotWindowGrowVertical); DEF2("Window Shrink Horizontal", I18N_NOOP("Pack Shrink Window Horizontally"), - 0, slotWindowShrinkHorizontal()); + 0, slotWindowShrinkHorizontal); DEF2("Window Shrink Vertical", I18N_NOOP("Pack Shrink Window Vertically"), - 0, slotWindowShrinkVertical()); + 0, slotWindowShrinkVertical); DEF2("Window Quick Tile Left", I18N_NOOP("Quick Tile Window to the Left"), - 0, slotWindowQuickTileLeft()); + 0, slotWindowQuickTileLeft); DEF2("Window Quick Tile Right", I18N_NOOP("Quick Tile Window to the Right"), - 0, slotWindowQuickTileRight()); + 0, slotWindowQuickTileRight); DEF2("Window Quick Tile Top Left", I18N_NOOP("Quick Tile Window to the Top Left"), - 0, slotWindowQuickTileTopLeft()); + 0, slotWindowQuickTileTopLeft); DEF2("Window Quick Tile Bottom Left", I18N_NOOP("Quick Tile Window to the Bottom Left"), - 0, slotWindowQuickTileBottomLeft()); + 0, slotWindowQuickTileBottomLeft); DEF2("Window Quick Tile Top Right", I18N_NOOP("Quick Tile Window to the Top Right"), - 0, slotWindowQuickTileTopRight()); + 0, slotWindowQuickTileTopRight); DEF2("Window Quick Tile Bottom Right", I18N_NOOP("Quick Tile Window to the Bottom Right"), - 0, slotWindowQuickTileBottomRight()); + 0, slotWindowQuickTileBottomRight); DEF2("Switch Window Up", I18N_NOOP("Switch to Window Above"), - Qt::META + Qt::ALT + Qt::Key_Up, slotSwitchWindowUp()); + Qt::META + Qt::ALT + Qt::Key_Up, slotSwitchWindowUp); DEF2("Switch Window Down", I18N_NOOP("Switch to Window Below"), - Qt::META + Qt::ALT + Qt::Key_Down, slotSwitchWindowDown()); + Qt::META + Qt::ALT + Qt::Key_Down, slotSwitchWindowDown); DEF2("Switch Window Right", I18N_NOOP("Switch to Window to the Right"), - Qt::META + Qt::ALT + Qt::Key_Right, slotSwitchWindowRight()); + Qt::META + Qt::ALT + Qt::Key_Right, slotSwitchWindowRight); DEF2("Switch Window Left", I18N_NOOP("Switch to Window to the Left"), - Qt::META + Qt::ALT + Qt::Key_Left, slotSwitchWindowLeft()); + Qt::META + Qt::ALT + Qt::Key_Left, slotSwitchWindowLeft); DEF2("Increase Opacity", I18N_NOOP("Increase Opacity of Active Window by 5 %"), - 0, slotIncreaseWindowOpacity()); + 0, slotIncreaseWindowOpacity); DEF2("Decrease Opacity", I18N_NOOP("Decrease Opacity of Active Window by 5 %"), - 0, slotLowerWindowOpacity()); + 0, slotLowerWindowOpacity); a = actionCollection->addAction(QStringLiteral("Group:Window Desktop")); a->setText(i18n("Window & Desktop")); DEF2("Window On All Desktops", I18N_NOOP("Keep Window on All Desktops"), - 0, slotWindowOnAllDesktops()); + 0, slotWindowOnAllDesktops); for (int i = 1; i < 21; ++i) { - DEF3(I18N_NOOP("Window to Desktop %1"), 0, slotWindowToDesktop(), i); + DEF3(I18N_NOOP("Window to Desktop %1"), 0, slotWindowToDesktop, i); } -DEF(I18N_NOOP("Window to Next Desktop"), 0, slotWindowToNextDesktop()); -DEF(I18N_NOOP("Window to Previous Desktop"), 0, slotWindowToPreviousDesktop()); -DEF(I18N_NOOP("Window One Desktop to the Right"), 0, slotWindowToDesktopRight()); -DEF(I18N_NOOP("Window One Desktop to the Left"), 0, slotWindowToDesktopLeft()); -DEF(I18N_NOOP("Window One Desktop Up"), 0, slotWindowToDesktopUp()); -DEF(I18N_NOOP("Window One Desktop Down"), 0, slotWindowToDesktopDown()); +DEF(I18N_NOOP("Window to Next Desktop"), 0, slotWindowToNextDesktop); +DEF(I18N_NOOP("Window to Previous Desktop"), 0, slotWindowToPreviousDesktop); +DEF(I18N_NOOP("Window One Desktop to the Right"), 0, slotWindowToDesktopRight); +DEF(I18N_NOOP("Window One Desktop to the Left"), 0, slotWindowToDesktopLeft); +DEF(I18N_NOOP("Window One Desktop Up"), 0, slotWindowToDesktopUp); +DEF(I18N_NOOP("Window One Desktop Down"), 0, slotWindowToDesktopDown); for (int i = 0; i < 8; ++i) { - DEF3(I18N_NOOP("Window to Screen %1"), 0, slotWindowToScreen(), i); + DEF3(I18N_NOOP("Window to Screen %1"), 0, slotWindowToScreen, i); } -DEF(I18N_NOOP("Window to Next Screen"), 0, slotWindowToNextScreen()); -DEF(I18N_NOOP("Window to Previous Screen"), 0, slotWindowToPrevScreen()); -DEF(I18N_NOOP("Show Desktop"), 0, slotToggleShowDesktop()); +DEF(I18N_NOOP("Window to Next Screen"), 0, slotWindowToNextScreen); +DEF(I18N_NOOP("Window to Previous Screen"), 0, slotWindowToPrevScreen); +DEF(I18N_NOOP("Show Desktop"), 0, slotToggleShowDesktop); for (int i = 0; i < 8; ++i) { - DEF3(I18N_NOOP("Switch to Screen %1"), 0, slotSwitchToScreen(), i); + DEF3(I18N_NOOP("Switch to Screen %1"), 0, slotSwitchToScreen, i); } -DEF(I18N_NOOP("Switch to Next Screen"), 0, slotSwitchToNextScreen()); -DEF(I18N_NOOP("Switch to Previous Screen"), 0, slotSwitchToPrevScreen()); +DEF(I18N_NOOP("Switch to Next Screen"), 0, slotSwitchToNextScreen); +DEF(I18N_NOOP("Switch to Previous Screen"), 0, slotSwitchToPrevScreen); a = actionCollection->addAction(QStringLiteral("Group:Miscellaneous")); a->setText(i18n("Miscellaneous")); -DEF(I18N_NOOP("Kill Window"), Qt::CTRL + Qt::ALT + Qt::Key_Escape, slotKillWindow()); -DEF(I18N_NOOP("Suspend Compositing"), Qt::SHIFT + Qt::ALT + Qt::Key_F12, slotToggleCompositing()); -DEF(I18N_NOOP("Invert Screen Colors"), 0, slotInvertScreen()); +DEF(I18N_NOOP("Kill Window"), Qt::CTRL + Qt::ALT + Qt::Key_Escape, slotKillWindow); +DEF(I18N_NOOP("Suspend Compositing"), Qt::SHIFT + Qt::ALT + Qt::Key_F12, slotToggleCompositing); +DEF(I18N_NOOP("Invert Screen Colors"), 0, slotInvertScreen); #undef DEF #undef DEF2 diff --git a/useractions.cpp b/useractions.cpp index 5b3417f31..d83cf9470 100755 --- a/useractions.cpp +++ b/useractions.cpp @@ -927,6 +927,20 @@ void Workspace::closeActivePopup() m_userActionsMenu->close(); } + +template +void Workspace::initShortcut(const QString &actionName, const QString &description, const QKeySequence &shortcut, Slot slot, const QVariant &data) +{ + QAction *a = keys->addAction(actionName); + a->setText(description); + if (data.isValid()) { + a->setData(data); + } + KGlobalAccel::self()->setDefaultShortcut(a, QList() << shortcut); + KGlobalAccel::self()->setShortcut(a, QList() << shortcut); + connect(a, &QAction::triggered, this, slot); +} + /*! Create the global accel object \c keys. */ diff --git a/workspace.h b/workspace.h index 2d693fb8b..7fc6d66ea 100644 --- a/workspace.h +++ b/workspace.h @@ -419,6 +419,9 @@ Q_SIGNALS: private: void init(); void initShortcuts(); + template + void initShortcut(const QString &actionName, const QString &description, const QKeySequence &shortcut, + Slot slot, const QVariant &data = QVariant()); void setupWindowShortcut(Client* c); enum Direction { DirectionNorth,