KDE/kdebase/apps/konsole/src

Robert Knight robertknight at gmail.com
Mon Apr 21 23:06:13 BST 2008


SVN commit 799577 by knight:

Allow the terminal display's host to decide whether shortcut keypresses

which are also valid terminal key sequences should be overridden and sent
to the terminal instead.

Default behaviour in the standalone Konsole is never to override shortcuts.  Default
behaviour in the terminal part is to always override shortcuts.

Shortcuts which are not valid terminal key sequences (eg. because they have more than
two modifiers) are never overridden.

Add an overrideShortcut() signal to the Part to expose this functionality to clients.

CCMAIL: kde-core-devel at kde.org


 M  +12 -0     Part.cpp  
 M  +21 -0     Part.h  
 M  +29 -2     TerminalDisplay.cpp  
 M  +11 -0     TerminalDisplay.h  


--- trunk/KDE/kdebase/apps/konsole/src/Part.cpp #799576:799577
@@ -238,8 +238,20 @@
 			SLOT(activeViewTitleChanged(ViewProperties*)));
 	activeViewTitleChanged(controller);
 
+	const char* displaySignal = SIGNAL(overrideShortcutCheck(QKeyEvent*,bool&));
+	const char* partSlot = SLOT(overrideTerminalShortcut(QKeyEvent*,bool&));
+
+	disconnect(controller->view(),displaySignal,this,partSlot);
+	connect(controller->view(),displaySignal,this,partSlot);
+
     _pluggedController = controller;
 }
+void Part::overrideTerminalShortcut(QKeyEvent* event, bool& override)
+{
+	// override all shortcuts in the embedded terminal by default
+	override = true;
+	emit overrideShortcut(event,override);
+}	
 void Part::activeViewTitleChanged(ViewProperties* properties)
 {
 	emit setWindowCaption(properties->title());
--- trunk/KDE/kdebase/apps/konsole/src/Part.h #799576:799577
@@ -30,6 +30,7 @@
 
 class QAction;
 class QStringList;
+class QKeyEvent;
 
 namespace Konsole
 {
@@ -111,6 +112,25 @@
 	 */
 	void openTeletype(int fd);
 
+signals:
+	/** 
+	 * When the key sequence for a shortcut, which is also a valid terminal key sequence
+	 * is pressed while the terminal has focus, this signal is emitted to check whether 
+	 * the terminal display should override the shortcut and send the key sequence to the
+	 * terminal application instead.
+	 *
+	 * In the embedded terminal, shortcuts are overridden and sent to the terminal by default.
+	 * Set @p override to false to prevent this happening and allow the shortcut to be triggered
+	 * normally.
+	 *
+	 * overrideShortcut() is not called for shortcuts which are not valid terminal key sequences,
+	 * eg. shortcuts with two or more modifiers.
+	 *
+	 * @param event Describes the keys that were pressed.
+	 * @param override Set this to false to prevent the terminal display from overriding the shortcut
+	 */
+	void overrideShortcut(QKeyEvent* event, bool& override);
+
 protected:
     /** Reimplemented from KParts::PartBase. */
     virtual bool openFile();
@@ -124,6 +144,7 @@
 	void showManageProfilesDialog();
     void terminalExited();
     void newTab();
+	void overrideTerminalShortcut(QKeyEvent*,bool& override);
 
 private:
     Session* activeSession() const;
--- trunk/KDE/kdebase/apps/konsole/src/TerminalDisplay.cpp #799576:799577
@@ -2462,6 +2462,7 @@
   if ( e->type() == QEvent::ShortcutOverride )
   {
     QKeyEvent* keyEvent = static_cast<QKeyEvent *>( e );
+	int modifiers = keyEvent->modifiers();
 
     // a check to see if keyEvent->text() is empty is used
     // to avoid intercepting the press of the modifier key on its own.
@@ -2469,16 +2470,42 @@
     // this is important as it allows a press and release of the Alt key
     // on its own to focus the menu bar, making it possible to
     // work with the menu without using the mouse
-    if ( (keyEvent->modifiers() == Qt::AltModifier) && 
+    if ( (modifiers == Qt::AltModifier) && 
          !keyEvent->text().isEmpty() )
     {
     	keyEvent->accept();
       	return true;
     }
 
+	//  When a possible shortcut combination is pressed, 
+	//  emit the overrideShortcutCheck() signal to allow the host
+	//  to decide whether the terminal should override it or not.
+	if (modifiers != Qt::NoModifier) 
+	{
+		int modifierCount = 0;
+		unsigned int currentModifier = Qt::ShiftModifier;
+
+		while (currentModifier <= Qt::KeypadModifier)
+		{
+			if (modifiers & currentModifier)
+				modifierCount++;
+			currentModifier <<= 1;
+		}
+		if (modifierCount < 2) 
+		{
+			bool override = false;
+			emit overrideShortcutCheck(keyEvent,override);
+			if (override)
+			{
+				keyEvent->accept();
+				return true;
+			}
+		}
+	}
+
     // Override any of the following shortcuts because
     // they are needed by the terminal
-    int keyCode = keyEvent->key() | keyEvent->modifiers();
+    int keyCode = keyEvent->key() | modifiers;
     switch ( keyCode )
     {
       // list is taken from the QLineEdit::event() code
--- trunk/KDE/kdebase/apps/konsole/src/TerminalDisplay.h #799576:799577
@@ -509,6 +509,17 @@
      */
     void configureRequest( TerminalDisplay*, int state, const QPoint& position );
 
+	/**
+	 * When a shortcut which is also a valid terminal key sequence is pressed while 
+	 * the terminal widget  has focus, this signal is emitted to allow the host to decide 
+	 * whether the shortcut should be overridden.  
+	 * When the shortcut is overridden, the key sequence will be sent to the terminal emulation instead
+	 * and the action associated with the shortcut will not be triggered.
+	 *
+	 * @p override is set to false by default and the shortcut will be triggered as normal.
+	 */
+	void overrideShortcutCheck(QKeyEvent* keyEvent,bool& override);
+
    void isBusySelecting(bool);
    void sendStringToEmu(const char*);
 




More information about the kde-core-devel mailing list