[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Ctrl-A -> Select All
From:       Waldo Bastian <bastian () suse ! de>
Date:       1999-12-23 21:01:24
[Download RAW message or body]

Hiya,

Based on Reggie's suggestion, I've hacked a "Ctrl-A" does select-all 
together. See the attached diff for KApplication. It works great but I 
think it is a horrible hack. 

Typically we want all shortcuts that operate directly on widgets to be 
configurable. (Home, End, Delete Till End Of Line, Delete Char, 
Backspace, Delete From Start of Line, Delete Line, Select All, Left, 
Right, Up Down, Scroll Up, Scroll Down, Scroll Page Up, Scroll Page 
Down, Start of Document, End of Document, etc.. etc..) For short 
"ControlEvents"

The following change to Qt could make that possible:
KeyEvents are being send to application as they are now. Widgets don't 
check KeyEvents for things other than insertable text.
When a keyevent comes back to Qt unhandled, it looks whether the 
keyevent describes a "ControlEvent", if so it translates the keyEvent 
into a ControlEvent and sends this to the application. Such an event 
could have as value "Right". When e.g. a QLineEdit gets such an event 
it moves the cursor to the right.

Example: 
When the user presses Ctrl-A this is first send to the application as a 
normal "Ctrl-A" key-event. QWidgets don't handle this key-event. When 
nobody else handles it, Qt translates it into a "Home" ControlEvent and 
sends it again to the application. Now the appropriate QWidget will 
handle it and take the correct action.

With this design it is for KDE quite easy to set up a different 
"key-events to control-events" translation.

Reggie, Matthias: What does it take to get this into Qt?

PS: I couldn't attach the "ctrl-a does select-all" diff since the 
filedialog didn't work :-] 

Index: kapp.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kapp.cpp,v
retrieving revision 1.250
diff -u -r1.250 kapp.cpp
--- kapp.cpp	1999/12/21 17:39:06	1.250
+++ kapp.cpp	1999/12/23 20:28:47
@@ -36,7 +36,6 @@
 #include <qsessionmanager.h>
 #include <qlist.h>
 #include <qtranslator.h>
-
 #include <kapp.h>
 #include <kglobal.h>
 #include <kstddirs.h>
@@ -46,6 +45,8 @@
 #include <kiconloader.h>
 #include <kconfig.h>
 #include <ksimpleconfig.h>
+#include <qlineedit.h>
+#include <qmultilineedit.h>
 
 #include <kstyle.h>
 #include <qplatinumstyle.h>
@@ -86,6 +87,10 @@
 #ifdef KeyPress
 #undef KeyPress
 #endif
+#ifdef KeyRelease
+#undef KeyRelease
+#endif
+#include <qevent.h>  // Defines KeyPress!
 
 KApplication* KApplication::KApp = 0L;
 //extern bool bAreaCalculated;
@@ -144,6 +149,56 @@
     }
 }
 
+bool KApplication::notify( QObject *receiver, QEvent *event)
+{
+   QEvent::Type t = event->type();
+   if ((t == QEvent::KeyPress) || (t == QEvent::KeyRelease))
+   {
+      printf("Event Type = %d\n", (int) t);
+   
+      QKeyEvent *k = dynamic_cast<QKeyEvent *>(event);
+      ASSERT(k);
+
+      int key = k->key();
+      if ( k->state() & ShiftButton )
+         key |= SHIFT;
+      if ( k->state() & ControlButton )
+         key |= CTRL;
+      if ( k->state() & AltButton )
+         key |= ALT;
+
+      if (key == CTRL + Key_A)
+      {
+         int asc=k->ascii();
+         printf("Object = '%s' Key code = %d ascii = %d '%c'\n", +     
    QLineEdit *le = dynamic_cast<QLineEdit *>(receiver);
+         if (le)
+         {
+            if (t == QEvent::KeyPress)
+            {
+               printf("Select All.\n");
+               le->selectAll();
+            }
+            return true;
+         }
+         QMultiLineEdit *mle = dynamic_cast<QMultiLineEdit 
*>(receiver);
+         if (mle)
+         {
+            if (t == QEvent::KeyPress)
+            {
+               printf("Select All.\n");
+               mle->selectAll();
+            }
+            return true;
+         }
+      }
+   }
+   else if (t == QEvent::Accel)
+   {
+      printf("Event Type = Accel\n");
+   }
+   return QApplication::notify( receiver, event);
+}
 
 
 // the help class for session management communication
Index: kapp.h
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kapp.h,v
retrieving revision 1.127
diff -u -r1.127 kapp.h
--- kapp.h	1999/12/21 17:39:06	1.127
+++ kapp.h	1999/12/23 20:28:49
@@ -99,6 +99,9 @@
   /** Destructor */
   virtual ~KApplication();
 
+  bool notify( QObject *receiver, QEvent *event);
+  
+
   /** Returns the number of command line arguments, i. e. the length
    *  of the array KApplication::argv(). In this array, the arguments
    *  handled by KApplication itself (i. e. '-icon') are already 
removed
receiver->className(), key, asc, (asc >= 32) && (asc < 127) ? asc : 
'.');

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic