Make tabcompletion key configurable via shortcuts. fixes 1018
authorBas Pape <baspape@gmail.com>
Sun, 7 Aug 2011 14:55:40 +0000 (16:55 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Fri, 20 Jan 2012 18:22:08 +0000 (19:22 +0100)
src/uisupport/CMakeLists.txt
src/uisupport/tabcompleter.cpp
src/uisupport/tabcompleter.h

index 5afab31..3d135d9 100644 (file)
@@ -86,7 +86,9 @@ endif(HAVE_KDE)
 qt4_wrap_cpp(MOC ${MOC_HDRS})
 
 include_directories(${CMAKE_SOURCE_DIR}/src/common
 qt4_wrap_cpp(MOC ${MOC_HDRS})
 
 include_directories(${CMAKE_SOURCE_DIR}/src/common
-                    ${CMAKE_SOURCE_DIR}/src/client)
+                    ${CMAKE_SOURCE_DIR}/src/client
+                    ${CMAKE_SOURCE_DIR}/src/qtui
+                    ${CMAKE_SOURCE_DIR}/src/uisupport)
 
 add_library(mod_uisupport STATIC ${SOURCES} ${MOC} ${HEADERS})
 add_dependencies(mod_uisupport mod_common mod_client)
 
 add_library(mod_uisupport STATIC ${SOURCES} ${MOC} ${HEADERS})
 add_dependencies(mod_uisupport mod_common mod_client)
index 5f7b083..527eb79 100644 (file)
@@ -28,6 +28,9 @@
 #include "network.h"
 #include "networkmodel.h"
 #include "uisettings.h"
 #include "network.h"
 #include "networkmodel.h"
 #include "uisettings.h"
+#include "action.h"
+#include "actioncollection.h"
+#include "qtui.h"
 
 #include <QRegExp>
 
 
 #include <QRegExp>
 
@@ -42,7 +45,16 @@ TabCompleter::TabCompleter(MultiLineEdit *_lineEdit)
     _enabled(false),
     _nickSuffix(": ")
 {
     _enabled(false),
     _nickSuffix(": ")
 {
+  // use both an Action and generic eventFilter, to make the shortcut configurable
+  // yet still be able to reset() when required
   _lineEdit->installEventFilter(this);
   _lineEdit->installEventFilter(this);
+  ActionCollection *coll = QtUi::actionCollection("General");
+  coll->addAction("TabCompletionKey", new Action(tr("Tab completion"), coll,
+                                              this, SLOT(onTabCompletionKey()), QKeySequence(Qt::Key_Tab)));
+}
+
+void TabCompleter::onTabCompletionKey() {
+  complete();
 }
 
 void TabCompleter::buildCompletionList() {
 }
 
 void TabCompleter::buildCompletionList() {
@@ -153,13 +165,10 @@ bool TabCompleter::eventFilter(QObject *obj, QEvent *event) {
 
   QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
 
 
   QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
 
-  if(keyEvent->key() == Qt::Key_Tab) {
-    complete();
-    return true;
-  } else {
+  if(keyEvent->key() != QtUi::actionCollection("General")->action("TabCompletionKey")->shortcut()) {
     reset();
     reset();
-    return false;
   }
   }
+  return false;
 }
 
 // this determines the sort order
 }
 
 // this determines the sort order
index b8461ee..47aebb0 100644 (file)
@@ -47,6 +47,9 @@ public:
 
   virtual bool eventFilter(QObject *obj, QEvent *event);
 
 
   virtual bool eventFilter(QObject *obj, QEvent *event);
 
+public slots:
+  void onTabCompletionKey();
+
 private:
 
   struct CompletionKey {
 private:
 
   struct CompletionKey {