Archive for May, 2009

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();

Google translate KDE plasma runner

I like google translate plasmoid translatoid, it would be great to have something like that with KDE krunner.

So i just coded a simple ‘google translate’ plasma runner, here’s the code

The default languages goes in configuration
snapshot56

The word or sentence must be between parenthesis.


Syntaxt:

* to find a word : gt=[word or sentence]
* manually specify languages : gt=en,es[word or sentence]

snapshot55
snapshot57