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

List:       kde-kimageshop
Subject:    Re: Sub-pixel positioning
From:       Adrian Page <adrian () pagenet ! plus ! com>
Date:       2004-03-19 22:57:45
Message-ID: 200403192257.45934.adrian () pagenet ! plus ! com
[Download RAW message or body]

On Friday 19 March 2004 10:21 pm, Boudewijn Rempt wrote:
> > After looking into the event code, I've found that it's also easy to stop
> > mouse move events being thrown away when drawing can't keep up with the
> > movement - something you talked about in a message in the list. I've
> > quickly hacked that in and it does make a big difference.
>
> Now I'm really curious -- I tried to do that, but couldn't make it... How
> did you do that in a quick hack?

Override x11Event() for KisCanvas and handle the move events before the 
default behaviour gets a chance. Attached patch works but is still in 'hack' 
mode. :-)

Adrian

["mouseMove.diff" (text/x-diff)]

Index: ui/kis_canvas.cc
===================================================================
RCS file: /home/kde/koffice/krita/ui/kis_canvas.cc,v
retrieving revision 1.9
diff -u -3 -p -u -r1.9 kis_canvas.cc
--- ui/kis_canvas.cc	16 Oct 2003 21:41:55 -0000	1.9
+++ ui/kis_canvas.cc	19 Mar 2004 22:47:26 -0000
@@ -14,10 +14,56 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
+ *
+
+ The X11-specific event handling code is based upon code from 
+ src/kernel/qapplication_x11.cpp from the Qt GUI Toolkit and is subject
+ to the following license and copyright:
+
+ ****************************************************************************
+** 
+**
+** Implementation of X11 startup routines and event handling
+**
+** Created : 931029
+**
+** Copyright (C) 1992-2003 Trolltech AS.  All rights reserved.
+**
+** This file is part of the kernel module of the Qt GUI Toolkit.
+**
+** This file may be distributed under the terms of the Q Public License
+** as defined by Trolltech AS of Norway and appearing in the file
+** LICENSE.QPL included in the packaging of this file.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
+** licenses for Unix/X11 may use this file in accordance with the Qt Commercial
+** License Agreement provided with the Software.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
+**   information about Qt Commercial License Agreements.
+** See http://www.trolltech.com/qpl/ for QPL licensing information.
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
 #include "kis_canvas.h"
 #include "kis_cursor.h"
 
+#ifdef Q_WS_X11
+#include <X11/Xlib.h>
+#endif
+
 KisCanvas::KisCanvas(QWidget *parent, const char *name) : super(parent, name)
 {
 	setBackgroundMode(QWidget::NoBackground);
@@ -87,5 +133,66 @@ void KisCanvas::keyReleaseEvent(QKeyEven
 	emit gotKeyReleaseEvent(e);
 }
 
+#ifdef Q_WS_X11
+
+static int translateButtonState(int s)
+{
+	int bst = 0;
+	if (s & Button1Mask)
+		bst |= Qt::LeftButton;
+	if (s & Button2Mask)
+		bst |= Qt::MidButton;
+	if (s & Button3Mask)
+		bst |= Qt::RightButton;
+	if (s & ShiftMask)
+		bst |= Qt::ShiftButton;
+	if (s & ControlMask)
+		bst |= Qt::ControlButton;
+	/*if (s & qt_alt_mask)
+		bst |= Qt::AltButton;
+	if (s & qt_meta_mask)
+		bst |= Qt::MetaButton;*/
+	return bst;
+}
+
+bool KisCanvas::x11Event(XEvent *event)
+{
+	static int x_root_save = -1, y_root_save = -1;
+
+	if (event->type == MotionNotify) {
+		// Mouse move
+		XMotionEvent motion = event->xmotion;
+
+		QPoint pos;
+		QPoint globalPos;
+
+		pos.rx() = motion.x;
+		pos.ry() = motion.y;
+		globalPos.rx() = motion.x_root;
+		globalPos.ry() = motion.y_root;
+		
+		int state = translateButtonState(motion.state);
+		
+		bool throw_away = FALSE;
+		if (x_root_save == globalPos.x() &&
+		    y_root_save == globalPos.y())
+			throw_away = TRUE;
+		x_root_save = globalPos.x();
+		y_root_save = globalPos.y();
+		if (!throw_away)
+		{
+			QMouseEvent ev(QEvent::MouseMove, pos, globalPos, state, state);
+			mouseMoveEvent(&ev);
+		}
+
+		return true;
+	}
+	else {
+		return false;
+	}
+}
+
+#endif // Q_WS_X11
+
 #include "kis_canvas.moc"
 
Index: ui/kis_canvas.h
===================================================================
RCS file: /home/kde/koffice/krita/ui/kis_canvas.h,v
retrieving revision 1.8
diff -u -3 -p -u -r1.8 kis_canvas.h
--- ui/kis_canvas.h	16 Oct 2003 21:41:55 -0000	1.8
+++ ui/kis_canvas.h	19 Mar 2004 22:47:26 -0000
@@ -53,6 +53,10 @@ protected:
 	virtual void wheelEvent(QWheelEvent *event);
 	virtual void keyPressEvent(QKeyEvent *event);
 	virtual void keyReleaseEvent(QKeyEvent *event);
+
+#ifdef Q_WS_X11
+	bool x11Event(XEvent *event);
+#endif
 };
 
 #endif // KIS_CANVAS_H_



_______________________________________________
kimageshop mailing list
kimageshop@kde.org
https://mail.kde.org/mailman/listinfo/kimageshop


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

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