added basic support for Emacs style key bindings
authorRĂ¼diger Sonderfeld <ruediger@c-plusplus.de>
Tue, 9 Mar 2010 15:12:16 +0000 (16:12 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 1 May 2010 16:36:46 +0000 (18:36 +0200)
src/qtui/inputwidget.cpp
src/qtui/inputwidget.h
src/qtui/settingspages/inputwidgetsettingspage.ui
src/uisupport/multilineedit.cpp
src/uisupport/multilineedit.h

index 814f4f4..f490a67 100644 (file)
@@ -106,6 +106,9 @@ InputWidget::InputWidget(QWidget *parent)
   setEnableSpellCheck(s.value("EnableSpellCheck", false));
 #endif
 
   setEnableSpellCheck(s.value("EnableSpellCheck", false));
 #endif
 
+  s.notify("EnableEmacsMode", this, SLOT(setEnableEmacsMode(QVariant)));
+  setEnableEmacsMode(s.value("EnableEmacsMode", false));
+
   s.notify("ShowNickSelector", this, SLOT(setShowNickSelector(QVariant)));
   setShowNickSelector(s.value("ShowNickSelector", true));
 
   s.notify("ShowNickSelector", this, SLOT(setShowNickSelector(QVariant)));
   setShowNickSelector(s.value("ShowNickSelector", true));
 
@@ -161,6 +164,10 @@ void InputWidget::setEnableSpellCheck(const QVariant &v) {
   ui.inputEdit->setSpellCheckEnabled(v.toBool());
 }
 
   ui.inputEdit->setSpellCheckEnabled(v.toBool());
 }
 
+void InputWidget::setEnableEmacsMode(const QVariant &v) {
+  ui.inputEdit->setEmacsMode(v.toBool());
+}
+
 void InputWidget::setShowNickSelector(const QVariant &v) {
   ui.ownNick->setVisible(v.toBool());
 }
 void InputWidget::setShowNickSelector(const QVariant &v) {
   ui.ownNick->setVisible(v.toBool());
 }
index 033378d..b577035 100644 (file)
@@ -55,6 +55,7 @@ private slots:
   void setCustomFont(const QVariant &font);
   void setUseCustomFont(const QVariant &);
   void setEnableSpellCheck(const QVariant &);
   void setCustomFont(const QVariant &font);
   void setUseCustomFont(const QVariant &);
   void setEnableSpellCheck(const QVariant &);
+  void setEnableEmacsMode(const QVariant &);
   void setShowNickSelector(const QVariant &);
   void setShowStyleButtons(const QVariant &);
   void setEnablePerChatHistory(const QVariant &);
   void setShowNickSelector(const QVariant &);
   void setShowStyleButtons(const QVariant &);
   void setEnablePerChatHistory(const QVariant &);
index c4197d4..078745f 100644 (file)
      </property>
     </widget>
    </item>
      </property>
     </widget>
    </item>
+   <item>
+    <widget class="QCheckBox" name="enableEmacsMode">
+     <property name="toolTip">
+      <string>Enables (limited) Emacs key bindings in the input field.</string>
+     </property>
+     <property name="text">
+      <string>Emacs key bindings</string>
+     </property>
+     <property name="settingsKey" stdset="0">
+      <string notr="true">EnableEmacsMode</string>
+     </property>
+     <property name="defaultValue" stdset="0">
+      <bool>false</bool>
+     </property>
+    </widget>
+   </item>
    <item>
     <widget class="QGroupBox" name="groupBox">
      <property name="title">
    <item>
     <widget class="QGroupBox" name="groupBox">
      <property name="title">
index a0e0e8c..871f47a 100644 (file)
@@ -168,6 +168,10 @@ QSize MultiLineEdit::minimumSizeHint() const {
   return sizeHint();
 }
 
   return sizeHint();
 }
 
+void MultiLineEdit::setEmacsMode(bool enable) {
+  _emacsMode = enable;
+}
+
 void MultiLineEdit::setSpellCheckEnabled(bool enable) {
 #ifdef HAVE_KDE
   setCheckSpellingEnabled(enable);
 void MultiLineEdit::setSpellCheckEnabled(bool enable) {
 #ifdef HAVE_KDE
   setCheckSpellingEnabled(enable);
@@ -318,6 +322,62 @@ void MultiLineEdit::keyPressEvent(QKeyEvent *event) {
     ;
   }
 
     ;
   }
 
+  if(_emacsMode) {
+    if(event->modifiers() & Qt::ControlModifier) {
+      switch(event->key()) {
+        // move
+      case Qt::Key_A:
+        moveCursor(QTextCursor::StartOfLine);
+        return;
+      case Qt::Key_E:
+        moveCursor(QTextCursor::EndOfLine);
+        return;
+      case Qt::Key_F:
+        moveCursor(QTextCursor::Right);
+        return;
+      case Qt::Key_B:
+        moveCursor(QTextCursor::Left);
+        return;
+      case Qt::Key_Right:
+        moveCursor(QTextCursor::WordRight);
+        return;
+      case Qt::Key_Left:
+        moveCursor(QTextCursor::WordLeft);
+        return;
+
+        // modify
+      case Qt::Key_Y:
+        paste();
+        return;
+      case Qt::Key_K:
+        moveCursor(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
+        cut();
+        return;
+      }
+    }
+    else if(event->modifiers() & Qt::MetaModifier) {
+      switch(event->key()) {
+      case Qt::Key_Right:
+        moveCursor(QTextCursor::WordRight);
+        return;
+      case Qt::Key_Left:
+        moveCursor(QTextCursor::WordLeft);
+        return;
+      case Qt::Key_F:
+        moveCursor(QTextCursor::WordRight);
+        return;
+      case Qt::Key_B:
+        moveCursor(QTextCursor::WordLeft);
+        return;
+      case Qt::Key_Less:
+        moveCursor(QTextCursor::Start);
+        return;
+      case Qt::Key_Greater:
+        moveCursor(QTextCursor::End);
+        return;
+      }
+    }
+  }
 
 #ifdef HAVE_KDE
   KTextEdit::keyPressEvent(event);
 
 #ifdef HAVE_KDE
   KTextEdit::keyPressEvent(event);
index b3a9d59..a1a0ffd 100644 (file)
@@ -70,11 +70,13 @@ public:
   inline QStringList history() const { return _history; }
   inline QHash<int, QString> tempHistory() const { return _tempHistory; }
   inline qint32 idx() const { return _idx; }
   inline QStringList history() const { return _history; }
   inline QHash<int, QString> tempHistory() const { return _tempHistory; }
   inline qint32 idx() const { return _idx; }
+  inline bool emacsMode() const { return _emacsMode; }
 
 public slots:
   void setMode(Mode mode);
   void setMinHeight(int numLines);
   void setMaxHeight(int numLines);
 
 public slots:
   void setMode(Mode mode);
   void setMinHeight(int numLines);
   void setMaxHeight(int numLines);
+  void setEmacsMode(bool enable = true);
   void setScrollBarsEnabled(bool enable = true);
   void setSpellCheckEnabled(bool enable = true);
   void setPasteProtectionEnabled(bool enable = true, QWidget *msgBoxParent = 0);
   void setScrollBarsEnabled(bool enable = true);
   void setSpellCheckEnabled(bool enable = true);
   void setPasteProtectionEnabled(bool enable = true, QWidget *msgBoxParent = 0);
@@ -119,6 +121,7 @@ private:
   int _maxHeight;
   bool _scrollBarsEnabled;
   bool _pasteProtectionEnabled;
   int _maxHeight;
   bool _scrollBarsEnabled;
   bool _pasteProtectionEnabled;
+  bool _emacsMode;
 
   QSize _sizeHint;
   qreal _lastDocumentHeight;
 
   QSize _sizeHint;
   qreal _lastDocumentHeight;