[EMAIL PROTECTED] (Lars Gullik Bjønnes) writes:

| | this is kindo a proof-of-concept.
>
| This is a revised version of the patch. This time is also prunes key
| events that is caused by auto-repeat. (Gives imho very nice behavior.)

And I cleaned it up a bit.

If people feels that this make behaviour better I think we should
commit this for 1.4.

| Comments bitte please por favor.

ditto again.

Index: src/frontends/qt2/QContentPane.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QContentPane.C,v
retrieving revision 1.32
diff -u -p -B -b -w -r1.32 QContentPane.C
--- src/frontends/qt2/QContentPane.C	1 Aug 2004 21:24:03 -0000	1.32
+++ src/frontends/qt2/QContentPane.C	13 May 2005 00:01:18 -0000
@@ -19,7 +19,6 @@
 
 #include <qapplication.h>
 #include <qpainter.h>
-#include <qtimer.h>
 
 #include <boost/bind.hpp>
 
@@ -90,6 +89,8 @@ QContentPane::QContentPane(QWorkArea * p
 		boost::bind(&QContentPane::generateSyntheticMouseEvent,
 			    this));
 
+	connect(&step_timer_, SIGNAL(timeout()), SLOT(keyeventTimeout()));
+
 	setFocusPolicy(QWidget::WheelFocus);
 	setFocus();
 	setCursor(ibeamCursor);
@@ -97,6 +98,9 @@ QContentPane::QContentPane(QWorkArea * p
 	// stupid moc strikes again
 	connect(wa_->scrollbar_, SIGNAL(valueChanged(int)),
 		this, SLOT(scrollBarChanged(int)));
+
+	// Start the timer, one-shot.
+	step_timer_.start(25, true);
 }
 
 
@@ -216,9 +220,35 @@ void QContentPane::wheelEvent(QWheelEven
 
 void QContentPane::keyPressEvent(QKeyEvent * e)
 {
+	keyeventQueue_.push(boost::shared_ptr<QKeyEvent>(new QKeyEvent(*e)));
+}
+
+
+void QContentPane::keyeventTimeout()
+{
+	bool handle_autos = true;
+
+	while (!keyeventQueue_.empty()) {
+		boost::shared_ptr<QKeyEvent> ev = keyeventQueue_.front();
+
+		// We never handle more than one auto repeated
+		// char in a list of queued up events.
+		if (!handle_autos && ev->isAutoRepeat()) {
+			keyeventQueue_.pop();
+			continue;
+		}
+
 	boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym);
-	sym->set(e);
-	wa_->workAreaKeyPress(sym, q_key_state(e->state()));
+		sym->set(ev.get());
+
+		wa_->workAreaKeyPress(sym, q_key_state(ev->state()));
+		keyeventQueue_.pop();
+
+		handle_autos = false;
+	}
+
+	// Restart the timer.
+	step_timer_.start(25, true);
 }
 
 
Index: src/frontends/qt2/QContentPane.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QContentPane.h,v
retrieving revision 1.14
diff -u -p -B -b -w -r1.14 QContentPane.h
--- src/frontends/qt2/QContentPane.h	19 Jan 2005 15:03:30 -0000	1.14
+++ src/frontends/qt2/QContentPane.h	13 May 2005 00:01:18 -0000
@@ -21,9 +21,12 @@
 
 #include <qwidget.h>
 #include <qpixmap.h>
+#include <qtimer.h>
 
 #include <boost/scoped_ptr.hpp>
 
+#include <queue>
+
 class QWorkArea;
 
 /// for emulating triple click
@@ -105,6 +108,8 @@ public slots:
 	void doubleClickTimeout();
 
 	void scrollBarChanged(int);
+        void keyeventTimeout();
+        
 private:
 	/// The slot connected to SyntheticMouseEvent::timeout.
 	void generateSyntheticMouseEvent();
@@ -114,6 +119,9 @@ private:
 	bool track_scrollbar_;
 	/// owning widget
 	QWorkArea * wa_;
+
+	QTimer step_timer_;
+	std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
 
 	/// the double buffered pixmap
 	boost::scoped_ptr<QPixmap> pixmap_;
Index: src/frontends/qt2/lyx_gui.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/lyx_gui.C,v
retrieving revision 1.82
diff -u -p -B -b -w -r1.82 lyx_gui.C
--- src/frontends/qt2/lyx_gui.C	11 May 2005 20:09:20 -0000	1.82
+++ src/frontends/qt2/lyx_gui.C	13 May 2005 00:01:18 -0000
@@ -260,7 +260,7 @@ void sync_events()
 	// prevent keyboard events being handed to the LyX core, where
 	// they could cause re-entrant calls to screen update.
 #if QT_VERSION >= 0x030100
-	qApp->eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
+	qApp->eventLoop()->processEvents(QEventLoop::AllEvents, 5);
 #endif
 }
 
-- 
        Lgb

Reply via email to