Lars Gullik Bj�nnes wrote:
> | (See attached.) I can't remember if any concensus was reached. The code
> | is certainly conceptually cleaner than what we have now, even if it
> | transpires that it doesn't actually reduce traffic that much.
>>
> | If nodody says "commit it, Angus", I'll just leave it to rot in my
> | pending directory.
>
> I like it.
I committed it. For reference here's the patch again created with
$ cvs -q diff -Bbw src/frontends/qt2 > zero_traffic.diff
--
Angus
Index: src/frontends/qt2/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/ChangeLog,v
retrieving revision 1.780
diff -u -p -B -b -w -r1.780 ChangeLog
--- src/frontends/qt2/ChangeLog 16 May 2005 09:14:17 -0000 1.780
+++ src/frontends/qt2/ChangeLog 19 May 2005 16:28:36 -0000
@@ -1,3 +1,7 @@
+2005-05-19 Angus Leeming <[EMAIL PROTECTED]>
+
+ * qscreen.[Ch]: cache and reuse pixmaps to show the flashing cursor.
+
2005-05-13 Angus Leeming <[EMAIL PROTECTED]>
* QBibtex.C (build_dialog):
Index: src/frontends/qt2/qscreen.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/qscreen.C,v
retrieving revision 1.28
diff -u -p -B -b -w -r1.28 qscreen.C
--- src/frontends/qt2/qscreen.C 20 May 2004 09:36:28 -0000 1.28
+++ src/frontends/qt2/qscreen.C 19 May 2005 16:28:36 -0000
@@ -14,12 +14,10 @@
#include "qscreen.h"
#include "debug.h"
-#include "LColor.h"
+#include "lcolorcache.h"
#include <qapplication.h>
-using std::endl;
-
namespace {
@@ -60,7 +58,7 @@ void QScreen::repaint()
void QScreen::expose(int x, int y, int w, int h)
{
lyxerr[Debug::GUI] << "expose " << w << 'x' << h
- << '+' << x << '+' << y << endl;
+ << '+' << x << '+' << y << std::endl;
owner_.getContent()->update(x, y, w, h);
}
@@ -68,6 +66,10 @@ void QScreen::expose(int x, int y, int w
void QScreen::showCursor(int x, int y, int h, Cursor_Shape shape)
{
+ if (!qApp->focusWidget())
+ return;
+
+ // Cache the dimensions of the cursor.
cursor_x_ = x;
cursor_y_ = y;
cursor_h_ = h;
@@ -85,35 +87,63 @@ void QScreen::showCursor(int x, int y, i
break;
}
- if (!nocursor_pixmap_.get()
- || cursor_w_ != nocursor_pixmap_->width()
- || cursor_h_ != nocursor_pixmap_->height()) {
- nocursor_pixmap_.reset(new QPixmap(cursor_w_, cursor_h_));
+ // We cache three pixmaps:
+ // 1 the rectangle of the original screen.
+ // 2 the vertical line of the cursor.
+ // 3 the horizontal line of the L-shaped cursor (if necessary).
+
+ // Initialise storage for these pixmaps as necessary.
+ if (cursor_w_ != nocursor_pixmap_.width() ||
+ cursor_h_ != nocursor_pixmap_.height()) {
+ nocursor_pixmap_.resize(cursor_w_, cursor_h_);
+ }
+
+ QColor const & required_color = lcolorcache.get(LColor::cursor);
+ bool const cursor_color_changed = required_color != cursor_color_;
+ if (cursor_color_changed)
+ cursor_color_ = required_color;
+
+ if (cursor_h_ != vcursor_pixmap_.height() || cursor_color_changed) {
+ if (cursor_h_ != vcursor_pixmap_.height())
+ vcursor_pixmap_.resize(1, cursor_h_);
+ vcursor_pixmap_.fill(cursor_color_);
}
- if (!qApp->focusWidget())
- return;
+ switch (shape) {
+ case BAR_SHAPE:
+ break;
+ case REVERSED_L_SHAPE:
+ case L_SHAPE:
+ if (cursor_w_ != hcursor_pixmap_.width() ||
+ cursor_color_changed) {
+ if (cursor_w_ != hcursor_pixmap_.width())
+ hcursor_pixmap_.resize(cursor_w_, 1);
+ hcursor_pixmap_.fill(cursor_color_);
+ }
+ break;
+ }
- // save old area
- bitBlt(nocursor_pixmap_.get(), 0, 0, owner_.getPixmap(),
+ // Save the old area (no cursor).
+ bitBlt(&nocursor_pixmap_, 0, 0, owner_.getPixmap(),
cursor_x_, cursor_y_, cursor_w_, cursor_h_);
- Painter & pain(owner_.getPainter());
- pain.start();
- pain.line(x, y, x, y + h - 1, LColor::cursor);
+ // Draw the new (vertical) cursor using the cached store.
+ bitBlt(owner_.getPixmap(), x, y,
+ &vcursor_pixmap_, 0, 0,
+ vcursor_pixmap_.width(), vcursor_pixmap_.height());
+ // Draw the new (horizontal) cursor if necessary.
switch (shape) {
case BAR_SHAPE:
break;
case REVERSED_L_SHAPE:
case L_SHAPE:
- pain.line(cursor_x_, y + h - 1, cursor_x_ + cursor_w_ - 1,
- y + h - 1, LColor::cursor);
+ bitBlt(owner_.getPixmap(), cursor_x_, y + h - 1,
+ &hcursor_pixmap_, 0, 0,
+ hcursor_pixmap_.width(), hcursor_pixmap_.height());
break;
}
- pain.end();
-
owner_.getContent()->repaint(
cursor_x_, cursor_y_,
cursor_w_, cursor_h_);
@@ -123,13 +153,12 @@ void QScreen::showCursor(int x, int y, i
void QScreen::removeCursor()
{
// before first showCursor
- if (!nocursor_pixmap_.get())
+ if (nocursor_pixmap_.isNull())
return;
bitBlt(owner_.getPixmap(), cursor_x_, cursor_y_,
- nocursor_pixmap_.get(), 0, 0, cursor_w_, cursor_h_);
+ &nocursor_pixmap_, 0, 0, cursor_w_, cursor_h_);
- owner_.getContent()->repaint(
- cursor_x_, cursor_y_,
- cursor_w_, cursor_h_);
+ owner_.getContent()
+ ->repaint(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
}
Index: src/frontends/qt2/qscreen.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/qscreen.h,v
retrieving revision 1.11
diff -u -p -B -b -w -r1.11 qscreen.h
--- src/frontends/qt2/qscreen.h 5 Sep 2003 15:06:13 -0000 1.11
+++ src/frontends/qt2/qscreen.h 19 May 2005 16:28:36 -0000
@@ -12,10 +12,9 @@
#ifndef QSCREEN_H
#define QSCREEN_H
-
#include "screen.h"
-#include <qrect.h>
-#include <boost/scoped_ptr.hpp>
+#include <qcolor.h>
+#include <qpixmap.h>
class QWorkArea;
class WorkArea;
@@ -50,7 +49,9 @@ private:
/// our owning widget
QWorkArea & owner_;
- boost::scoped_ptr<QPixmap> nocursor_pixmap_;
+ QPixmap nocursor_pixmap_;
+ QPixmap hcursor_pixmap_;
+ QPixmap vcursor_pixmap_;
//@{ the cursor pixmap position/size
int cursor_x_;
@@ -58,6 +59,8 @@ private:
int cursor_w_;
int cursor_h_;
//@}
+
+ QColor cursor_color_;
};
#endif // QSCREEN_H