Hello,
I would like to put this in but I touched a tiny bit the other
frontends. Any objection?
Abdel.
____________________________
Log:
This patch removes qscreen.[Ch] and simplify the cursor drawing on
screen. Basically, we paint now only if needed. So there's no need
anymore to handle the "no cursor" pixmap saving.
SConscript: removed qscreen.C
frontends/qt4/Makefile.am: removed qscreen.C
frontends/screen.h: remove workarea() constness
frontends/qt3/qscreen.[Ch]: ditto
frontends/gtk/GScreen.[Ch]: ditto
frontends/xforms/xscreen.[Ch]: ditto
frontends/qt4/LyXScreenFactory.C: now return the QWorkarea directly
frontends/qt4/QWorkArea.[Ch]: inherits LyXScreen, handle the cursor painting
frontends/qt4/qscreen.[Ch]: removed
Index: development/scons/SConscript
===================================================================
--- development/scons/SConscript (revision 13976)
+++ development/scons/SConscript (working copy)
@@ -973,7 +973,6 @@
qfontexample.C
qfont_loader.C
qfont_metrics.C
- qscreen.C
qt_helpers.C
''')]
Index: src/frontends/gtk/GScreen.C
===================================================================
--- src/frontends/gtk/GScreen.C (revision 13976)
+++ src/frontends/gtk/GScreen.C (working copy)
@@ -58,7 +58,7 @@
}
-WorkArea & GScreen::workarea() const
+WorkArea & GScreen::workarea()
{
return owner_;
}
Index: src/frontends/gtk/GScreen.h
===================================================================
--- src/frontends/gtk/GScreen.h (revision 13976)
+++ src/frontends/gtk/GScreen.h (working copy)
@@ -42,7 +42,7 @@
virtual void showCursor(int x, int y, int h, Cursor_Shape shape);
protected:
/// get the work area
- virtual WorkArea & workarea() const;
+ virtual WorkArea & workarea();
/// Copies specified area of pixmap to screen
virtual void expose(int x, int y, int w, int h);
Index: src/frontends/qt3/qscreen.C
===================================================================
--- src/frontends/qt3/qscreen.C (revision 13976)
+++ src/frontends/qt3/qscreen.C (working copy)
@@ -42,7 +42,7 @@
}
-WorkArea & QScreen::workarea() const
+WorkArea & QScreen::workarea()
{
return owner_;
}
Index: src/frontends/qt3/qscreen.h
===================================================================
--- src/frontends/qt3/qscreen.h (revision 13976)
+++ src/frontends/qt3/qscreen.h (working copy)
@@ -31,7 +31,7 @@
protected:
/// get the work area
- virtual WorkArea & workarea() const;
+ virtual WorkArea & workarea();
/// repaint the whole content immediately
void repaint();
Index: src/frontends/qt4/LyXScreenFactory.C
===================================================================
--- src/frontends/qt4/LyXScreenFactory.C (revision 13976)
+++ src/frontends/qt4/LyXScreenFactory.C (working copy)
@@ -13,13 +13,12 @@
#include "frontends/LyXScreenFactory.h"
#include "QWorkArea.h"
-#include "qscreen.h"
namespace LyXScreenFactory {
LyXScreen * create(WorkArea & owner)
{
- return new QScreen(static_cast<QWorkArea &>(owner));
+ return &(static_cast<QWorkArea &>(owner));
}
} // namespace LyXScreenFactory
Index: src/frontends/qt4/Makefile.am
===================================================================
--- src/frontends/qt4/Makefile.am (revision 13976)
+++ src/frontends/qt4/Makefile.am (working copy)
@@ -92,6 +92,5 @@
qfont_loader.h qfont_loader.C \
qfont_metrics.C \
qlkey.h \
- qscreen.h qscreen.C \
qt_helpers.h qt_helpers.C \
$(MOCFILES)
Index: src/frontends/qt4/qscreen.C
===================================================================
--- src/frontends/qt4/qscreen.C (revision 13976)
+++ src/frontends/qt4/qscreen.C (working copy)
@@ -1,136 +0,0 @@
-/**
- * \file qscreen.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "QWorkArea.h"
-#include "qscreen.h"
-
-#include <QColor>
-#include <QPainter>
-#include <QApplication>
-
-#include "debug.h"
-#include "lcolorcache.h"
-
-
-namespace {
-
-} // namespace anon
-
-
-QScreen::QScreen(QWorkArea & o)
- : LyXScreen(), owner_(o), nocursor_(0,0)
-{
-}
-
-
-QScreen::~QScreen()
-{
-}
-
-
-WorkArea & QScreen::workarea() const
-{
- return owner_;
-}
-
-void QScreen::expose(int x, int y, int w, int h)
-{
- lyxerr[Debug::GUI] << "expose " << w << 'x' << h
- << '+' << x << '+' << y << std::endl;
-
- owner_.update(x, y, w, h);
-}
-
-void QScreen::showCursor(int x, int y, int h, Cursor_Shape shape)
-{
- if (!qApp->focusWidget())
- return;
-
- if (x==cursor_x_ && y==cursor_y_ && h==cursor_h_) {
- // Draw the new (vertical) cursor using the cached store.
- owner_.drawScreen(cursor_x_, cursor_y_, vcursor_);
- return;
- }
-
- // Cache the dimensions of the cursor.
- cursor_x_ = x;
- cursor_y_ = y;
- cursor_h_ = h;
-
- switch (shape) {
- case BAR_SHAPE:
- cursor_w_ = 2;
- break;
- case L_SHAPE:
- cursor_w_ = cursor_h_ / 3;
- break;
- case REVERSED_L_SHAPE:
- cursor_w_ = cursor_h_ / 3;
- cursor_x_ = x - cursor_w_ + 1;
- break;
- }
-
-
- // 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).
-
- 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;
-
- vcursor_ = QPixmap(cursor_w_, cursor_h_);
- vcursor_ .fill(cursor_color_);
-
- switch (shape) {
- case BAR_SHAPE:
- break;
- case REVERSED_L_SHAPE:
- case L_SHAPE:
- if (cursor_w_ != hcursor_.width() ||
- cursor_color_changed) {
- if (cursor_w_ != hcursor_.width())
- hcursor_ = QPixmap(cursor_w_, 1);
- hcursor_.fill(cursor_color_);
- }
- break;
- }
-
- // Save the old area (no cursor).
- nocursor_ = owner_.copyScreen(cursor_x_, cursor_y_, cursor_w_,
cursor_h_);
-
- // Draw the new (vertical) cursor using the cached store.
- owner_.drawScreen(cursor_x_, cursor_y_, vcursor_);
-
- // Draw the new (horizontal) cursor if necessary.
- switch (shape) {
- case BAR_SHAPE:
- break;
- case REVERSED_L_SHAPE:
- case L_SHAPE:
- owner_.drawScreen(cursor_x_, y + h - 1, hcursor_);
- break;
- }
-}
-
-
-void QScreen::removeCursor()
-{
- // before first showCursor
- if (nocursor_.isNull())
- return;
-
- owner_.drawScreen(cursor_x_, cursor_y_, nocursor_);
-}
Index: src/frontends/qt4/qscreen.h
===================================================================
--- src/frontends/qt4/qscreen.h (revision 13976)
+++ src/frontends/qt4/qscreen.h (working copy)
@@ -1,66 +0,0 @@
-// -*- C++ -*-
-/**
- * \file qscreen.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef QSCREEN_H
-#define QSCREEN_H
-
-
-#include "screen.h"
-
-#include <QPixmap>
-
-class QColor;
-
-class QWorkArea;
-class WorkArea;
-
-
-/**
- * Qt implementation of toolkit-specific parts of LyXScreen.
- */
-class QScreen : public LyXScreen {
-public:
- QScreen(QWorkArea &);
-
- virtual ~QScreen();
-
-protected:
- /// get the work area
- virtual WorkArea & workarea() const;
-
- /// copies specified area of pixmap to screen
- virtual void expose(int x, int y, int exp_width, int exp_height);
-
- /// paint the cursor and store the background
- virtual void showCursor(int x, int y, int h, Cursor_Shape shape);
-
- /// hide the cursor
- virtual void removeCursor();
-
-private:
- /// our owning widget
- QWorkArea & owner_;
-
- QPixmap nocursor_;
- QPixmap hcursor_;
- QPixmap vcursor_;
-
- //@{ the cursor pixmap position/size
- int cursor_x_;
- int cursor_y_;
- int cursor_w_;
- int cursor_h_;
- //@}
-
- QColor cursor_color_;
-};
-
-#endif // QSCREEN_H
Index: src/frontends/qt4/QWorkArea.C
===================================================================
--- src/frontends/qt4/QWorkArea.C (revision 13976)
+++ src/frontends/qt4/QWorkArea.C (working copy)
@@ -538,6 +538,12 @@
*/
QPainter q(viewport());
q.drawPixmap(e->rect(), paint_device_, e->rect());
+
+ if (show_vcursor_)
+ q.drawPixmap(cursor_x_, cursor_y_, vcursor_);
+
+ if (show_hcursor_)
+ q.drawPixmap(cursor_x_, cursor_y_ + cursor_h_ - 1, hcursor_);
}
@@ -553,7 +559,93 @@
viewport()->update(x, y, pixmap.width(), pixmap.height());
}
+///////////////////////////////////////////////////////////////
+// LyXSreen overloaded methods:
+WorkArea & QWorkArea::workarea()
+{
+// return static_cast<QWorkArea &> (*this);
+ return *this;
+}
+
+
+void QWorkArea::expose(int x, int y, int w, int h)
+{
+// lyxerr[Debug::GUI] << "expose " << w << 'x' << h
+// << '+' << x << '+' << y << std::endl;
+
+ update(x, y, w, h);
+}
+
+
+void QWorkArea::showCursor(int x, int y, int h, Cursor_Shape shape)
+{
+ if (!qApp->focusWidget())
+ return;
+
+ show_vcursor_ = true;
+
+ QColor const & required_color = lcolorcache.get(LColor::cursor);
+
+ if (x==cursor_x_ && y==cursor_y_ && h==cursor_h_
+ && cursor_color_ == required_color
+ && cursor_shape_ == shape) {
+ show_hcursor_ = lshape_cursor_;
+ viewport()->update(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
+ return;
+ }
+
+ // Cache the dimensions of the cursor.
+ cursor_x_ = x;
+ cursor_y_ = y;
+ cursor_h_ = h;
+ cursor_color_ = required_color;
+ cursor_shape_ = shape;
+
+ switch (cursor_shape_) {
+ case BAR_SHAPE:
+ // FIXME the cursor width shouldn't be hard-coded!
+ cursor_w_ = 2;
+ lshape_cursor_ = false;
+ break;
+ case L_SHAPE:
+ cursor_w_ = cursor_h_ / 3;
+ lshape_cursor_ = true;
+ break;
+ case REVERSED_L_SHAPE:
+ cursor_w_ = cursor_h_ / 3;
+ cursor_x_ -= cursor_w_ - 1;
+ lshape_cursor_ = true;
+ break;
+ }
+
+ // We cache two pixmaps:
+ // 1 the vertical line of the cursor.
+ // 2 the horizontal line of the L-shaped cursor (if necessary).
+
+ // Draw the new (vertical) cursor.
+ vcursor_ = QPixmap(cursor_w_, cursor_h_);
+ vcursor_.fill(cursor_color_);
+
+ // Draw the new (horizontal) cursor if necessary.
+ if (lshape_cursor_) {
+ hcursor_ = QPixmap(cursor_w_, 1);
+ hcursor_.fill(cursor_color_);
+ show_hcursor_ = true;
+ }
+
+ viewport()->update(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
+}
+
+
+void QWorkArea::removeCursor()
+{
+ show_vcursor_ = false;
+ show_hcursor_ = false;
+
+ viewport()->update(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
+}
+
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// Specific stuff
Index: src/frontends/qt4/QWorkArea.h
===================================================================
--- src/frontends/qt4/QWorkArea.h (revision 13976)
+++ src/frontends/qt4/QWorkArea.h (working copy)
@@ -25,6 +25,7 @@
#include "WorkArea.h"
#include "QLPainter.h"
#include "LyXView.h"
+#include "screen.h"
#include "funcrequest.h"
#include "frontends/Timeout.h"
@@ -95,7 +96,7 @@
* Qt-specific implementation of the work area
* (buffer view GUI)
*/
-class QWorkArea : public QAbstractScrollArea, public WorkArea {
+class QWorkArea : public QAbstractScrollArea, public WorkArea, public
LyXScreen {
Q_OBJECT
@@ -144,11 +145,23 @@
QPixmap is implicitely shared so no need to pass by reference.
*/
void drawScreen(int x, int y, QPixmap pixmap);
+
+ LyXView & view() { return view_; }
- LyXView & view()
- {
- return view_;
- }
+ // LyXScreen overloaded methods:
+
+ /// get the work area
+ virtual WorkArea & workarea();
+
+ /// copies specified area of pixmap to screen
+ virtual void expose(int x, int y, int exp_width, int exp_height);
+
+ /// paint the cursor and store the background
+ virtual void showCursor(int x, int y, int h, Cursor_Shape shape);
+
+ /// hide the cursor
+ virtual void removeCursor();
+
protected:
/// repaint part of the widget
@@ -221,6 +234,29 @@
std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
double_click dc_event_;
+
+ ///
+ int cursor_x_;
+ ///
+ int cursor_y_;
+ ///
+ int cursor_w_;
+ ///
+ int cursor_h_;
+ ///
+ QPixmap hcursor_;
+ ///
+ QPixmap vcursor_;
+ ///
+ bool show_hcursor_;
+ ///
+ bool show_vcursor_;
+ ///
+ bool lshape_cursor_;
+ ///
+ QColor cursor_color_;
+ ///
+ Cursor_Shape cursor_shape_;
};
#endif // QWORKAREA_H
Index: src/frontends/screen.h
===================================================================
--- src/frontends/screen.h (revision 13976)
+++ src/frontends/screen.h (working copy)
@@ -63,7 +63,7 @@
virtual void expose(int x, int y, int w, int h) = 0;
/// get the work area
- virtual WorkArea & workarea() const = 0;
+ virtual WorkArea & workarea() = 0;
/// types of cursor in work area
enum Cursor_Shape {
Index: src/frontends/xforms/xscreen.C
===================================================================
--- src/frontends/xforms/xscreen.C (revision 13976)
+++ src/frontends/xforms/xscreen.C (working copy)
@@ -59,7 +59,7 @@
}
-WorkArea & XScreen::workarea() const
+WorkArea & XScreen::workarea()
{
return owner_;
}
Index: src/frontends/xforms/xscreen.h
===================================================================
--- src/frontends/xforms/xscreen.h (revision 13976)
+++ src/frontends/xforms/xscreen.h (working copy)
@@ -41,7 +41,7 @@
protected:
/// get the work area
- virtual WorkArea & workarea() const;
+ virtual WorkArea & workarea();
/// Copies specified area of pixmap to screen
virtual void expose(int x, int y, int w, int h);