Move krunner with keyboard

Just a simple patch to allow move krunner interface with META + [Left, Right, Down, Up] keys.

snapshot62

http://pastebin.com/f28723323


Index: workspace/krunner/interfaces/default/interface.cpp
===================================================================
--- workspace/krunner/interfaces/default/interface.cpp	(revision 974496)
+++ workspace/krunner/interfaces/default/interface.cpp	(working copy)
@@ -130,6 +130,28 @@
     QAction *focusEdit = new QAction(this);
     focusEdit->setShortcut(Qt::Key_F6);
 
+    QActionGroup *moveActions = new QActionGroup(this);
+
+    QAction *upAction = new QAction(this);
+    upAction->setShortcut(Qt::META | Qt::Key_Up);
+    
+    QAction *downAction = new QAction(this);
+    downAction->setShortcut(Qt::META | Qt::Key_Down);
+
+    QAction *leftAction = new QAction(this);
+    leftAction->setShortcut(Qt::META | Qt::Key_Left);
+    
+    QAction *rightAction = new QAction(this);
+    rightAction->setShortcut(Qt::META | Qt::Key_Right);
+
+    moveActions->addAction(upAction);
+    moveActions->addAction(downAction);
+    moveActions->addAction(leftAction);
+    moveActions->addAction(rightAction);
+    addActions(moveActions->actions());
+
+    connect(moveActions, SIGNAL(triggered(QAction *)), SLOT(slotMove(QAction *)));
+    
     // in therory, the widget should detect the direction from the content
     // but this is not available in Qt4.4/KDE 4.2, so the best default for this widget
     // is LTR: as it's more or less a "command line interface"
@@ -396,6 +418,31 @@
     }
 }
 
+void Interface::slotMove(QAction *action)
+{
+    int movement = 30;
+
+    int x = QWidget::pos().x();
+    int y = QWidget::pos().y();
+
+    switch (action->shortcut()) {
+        case Qt::META | Qt::Key_Up:
+            if (y > 0) y -= movement;
+            break;
+        case Qt::META | Qt::Key_Down:
+            if (y screenGeometry().height() - height()) y += movement;
+            break;
+        case Qt::META | Qt::Key_Right:
+            if (x screenGeometry().width() - width()) x += movement;
+            break;
+        case Qt::META | Qt::Key_Left:
+            if (x > 0) x -= movement;
+            break;
+    }
+
+    move(x, y);
+}
+
 void Interface::setStaticQueryMode(bool staticQuery)
 {
     if (staticQuery) {
@@ -427,7 +474,7 @@
     }
     e->accept();
 }
-
+    
 void Interface::run(ResultItem *item)
 {
     if (!item || item->group() < Plasma::QueryMatch::PossibleMatch) {
Index: workspace/krunner/interfaces/default/interface.h
===================================================================
--- workspace/krunner/interfaces/default/interface.h	(revision 974496)
+++ workspace/krunner/interfaces/default/interface.h	(working copy)
@@ -72,6 +72,7 @@
         void resetInterface();
         void showHelp();
         void itemSelected();
+        void slotMove(QAction *);
 
     private:
         void centerOnScreen();

Advertisements
    • jpr
    • May 13th, 2010

    Thanks for this patch. I’ve patched my kde 4.4.3 krunner with it and it’s almost working. The only issue is that I have a dual screens (1440×900 on the left + 1280×1024 on the right) and I can’t move the krunner window to the right passed 1024 pixels from the ‘left’ screen…

    My guess is that the trouble is coming from the “screenGeometry().width()” call, but I no Qt expert to see how to fix it…

    Any clue?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: