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

List:       kde-core-devel
Subject:    Re: accel problems: might be qt-copt, might be kdelibs
From:       Ellis Whitehead <ellis () kde ! org>
Date:       2002-10-14 20:45:29
[Download RAW message or body]

On Monday 14 October 2002 11:41, Alexander Neundorf wrote:
> On Sunday 13 October 2002 16:59, Ellis Whitehead wrote:
> ...
>
> > Hi.  No need for the keyPressEvent() stuff.  The problem was due to an
> > oversight in the kaccel code: the keyPress event wasn't being stopped
> > after being handled by KAccel.  The attached patch seems to fix it.  It's
> > an ugly hack, but it seems to be working fine, and I'll increase the
> > aesthetic value later. *grin*  It adds a new class, KAccelEventFilter,
> > which adds itself to the kapp x11 event filter list.  KAccelEventFilter
> > then kills the keyPress event if it's handled by KAccel.
> >
> > Seem ok to commit?
>
> It doesn't compile with --enable-final, due to KeyPress, which is already
> undefined in kapplication.cpp

New patch attached.  I'm not using --enable-final, so I didn't test it in that 
respect, but the #undef is placed before any k*.h includes.

> The problem in konqy still exists.
> Pressing alt+left goes back and activates the menubar, which then can't be
> deactivated using Escape.

I can't reproduce this, but I'm not using the most recent qt-copy either.  Are 
you aware of other people having this problem too?  When you press and 
release the Alt key, does it activate the menu?  I'll keep looking to see if 
I can find where the problem is.  Not the easiest task when you can't 
reproduce it yourself, though...

Cheers,
Ellis
["kaccel.cpp.diff" (text/x-diff)]

Index: kaccel.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kaccel.cpp,v
retrieving revision 1.135
diff -u -3 -d -p -b -B -r1.135 kaccel.cpp
--- kaccel.cpp	2002/10/07 21:42:45	1.135
+++ kaccel.cpp	2002/10/14 20:37:31
@@ -17,13 +17,22 @@
     Boston, MA 02111-1307, USA.
 */
 
-#include "kaccel.h"
-
 #include <qaccel.h>
 #include <qpopupmenu.h>
 #include <qstring.h>
 #include <qtimer.h>
 
+#ifdef Q_WS_X11
+#	include <X11/Xlib.h>
+#	include <X11/keysymdef.h>
+
+	// defined by X11 headers
+	const int XKeyPress = KeyPress;
+#	undef KeyPress
+#endif
+
+#include "kaccel.h"
+
 #include <kaccelbase.h>
 #include <kapplication.h>
 #include <kdebug.h>
@@ -32,7 +41,78 @@
 
 #include "kaccelprivate.h"
 
+// TODO: Put in kaccelbase.cpp
+//---------------------------------------------------------------------
+// KAccelEventHandler
 //---------------------------------------------------------------------
+
+class KAccelEventHandler : public QWidget
+{
+ public:
+	static KAccelEventHandler* self()
+	{
+		if( !g_pSelf )
+			g_pSelf = new KAccelEventHandler;
+		return g_pSelf;
+	}
+	
+	static bool active() { return g_bActive; }
+	static void accelActivated( bool b ) { g_bAccelActivated = b; }
+	
+ private:
+	KAccelEventHandler();
+
+#	ifdef Q_WS_X11
+	bool x11Event( XEvent* pEvent );
+#	endif
+
+	static KAccelEventHandler* g_pSelf;
+	static bool g_bActive;
+	static bool g_bAccelActivated;
+};
+
+KAccelEventHandler* KAccelEventHandler::g_pSelf = 0;
+bool KAccelEventHandler::g_bActive = false;
+bool KAccelEventHandler::g_bAccelActivated = false;
+
+KAccelEventHandler::KAccelEventHandler()
+{
+#	ifdef Q_WS_X11
+		kapp->installX11EventFilter( this );
+#	endif
+}
+
+#ifdef Q_WS_X11
+bool KAccelEventHandler::x11Event( XEvent* pEvent )
+{
+	if( QWidget::keyboardGrabber() || !kapp->focusWidget() )
+		return false;
+	
+	if( pEvent->type == XKeyPress ) {
+		KKeyNative keyNative( pEvent );
+		KKey key( keyNative );
+		key.simplify();
+		int keyCodeQt = key.keyCodeQt();
+		int state = 0;
+		if( key.modFlags() & KKey::SHIFT ) state |= Qt::ShiftButton;
+		if( key.modFlags() & KKey::CTRL )  state |= Qt::ControlButton;
+		if( key.modFlags() & KKey::ALT )   state |= Qt::AltButton;
+		
+		QKeyEvent ke( QEvent::AccelOverride, keyCodeQt, 0,  state );
+		ke.ignore();
+		g_bActive = true;
+		kapp->sendEvent( kapp->focusWidget(), &ke );
+		g_bActive = false;
+		bool bHandled = g_bAccelActivated;
+		g_bAccelActivated = false;
+		return bHandled;
+	}
+	
+	return false;
+}
+#endif // Q_WS_X11
+
+//---------------------------------------------------------------------
 // KAccelPrivate
 //---------------------------------------------------------------------
 
@@ -46,6 +126,7 @@ KAccelPrivate::KAccelPrivate( KAccel* pP
 	connect( (QAccel*)m_pAccel, SIGNAL(activated(int)), this, SLOT(slotKeyPressed(int)) \
);  
 	m_pWatch->installEventFilter( this );
+	KAccelEventHandler::self();
 }
 
 void KAccelPrivate::setEnabled( bool bEnabled )
@@ -208,16 +289,16 @@ void KAccelPrivate::slotMenuActivated( i
 
 bool KAccelPrivate::eventFilter( QObject* /*pWatched*/, QEvent* pEvent )
 {
-	if( pEvent->type() == QEvent::AccelOverride ) {
+	if( KAccelEventHandler::active() && pEvent->type() == QEvent::AccelOverride ) {
 		QKeyEvent* pKeyEvent = (QKeyEvent*) pEvent;
 		KKey key( pKeyEvent );
-		//kdDebug(125) << "KAccelPrivate::eventFilter( AccelOverride ): this = " << this \
<< ", key = " << key.toStringInternal() << endl; +		kdDebug(125) << \
"KAccelPrivate::eventFilter( AccelOverride ): this = " << this << ", key = " << \
key.toStringInternal() << endl;  int keyCodeQt = key.keyCodeQt();
 		QMap<int, int>::iterator it = m_mapIDToKey.begin();
 		for( ; it != m_mapIDToKey.end(); ++it ) {
 			if( (*it) == keyCodeQt ) {
 				int nID = it.key();
-				//kdDebug(125) << "shortcut found!" << endl;
+				kdDebug(125) << "shortcut found!" << endl;
 				if( m_mapIDToAction.contains( nID ) ) {
 					// TODO: reduce duplication between here and slotMenuActivated
 					KAccelAction* pAction = m_mapIDToAction[nID];
@@ -226,7 +307,9 @@ bool KAccelPrivate::eventFilter( QObject
 					disconnect( this, SIGNAL(menuItemActivated()), pAction->objSlotPtr(), \
pAction->methodSlotPtr() );  } else
 					slotKeyPressed( nID );
+				
 				pKeyEvent->accept();
+				KAccelEventHandler::accelActivated( true );
 				return true;
 			}
 		}



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

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