diff --git a/development/scons/SConscript b/development/scons/SConscript index d9f990e680..e82ab85a6c 100644 --- a/development/scons/SConscript +++ b/development/scons/SConscript @@ -973,7 +973,6 @@ if build_qt4: qfontexample.C qfont_loader.C qfont_metrics.C - qscreen.C qt_helpers.C ''')] diff --git a/src/frontends/gtk/GScreen.C b/src/frontends/gtk/GScreen.C index 653250ad80..ee711bba9c 100644 --- a/src/frontends/gtk/GScreen.C +++ b/src/frontends/gtk/GScreen.C @@ -58,7 +58,7 @@ GScreen::~GScreen() } -WorkArea & GScreen::workarea() const +WorkArea & GScreen::workarea() { return owner_; } diff --git a/src/frontends/gtk/GScreen.h b/src/frontends/gtk/GScreen.h index d6551385c2..baaea7e3f5 100644 --- a/src/frontends/gtk/GScreen.h +++ b/src/frontends/gtk/GScreen.h @@ -42,7 +42,7 @@ public: 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); diff --git a/src/frontends/qt3/qscreen.C b/src/frontends/qt3/qscreen.C index 53ae53d284..5b5ab545dc 100644 --- a/src/frontends/qt3/qscreen.C +++ b/src/frontends/qt3/qscreen.C @@ -42,7 +42,7 @@ QScreen::~QScreen() } -WorkArea & QScreen::workarea() const +WorkArea & QScreen::workarea() { return owner_; } diff --git a/src/frontends/qt3/qscreen.h b/src/frontends/qt3/qscreen.h index 2f2dfe555a..7d595f5e45 100644 --- a/src/frontends/qt3/qscreen.h +++ b/src/frontends/qt3/qscreen.h @@ -31,7 +31,7 @@ public: protected: /// get the work area - virtual WorkArea & workarea() const; + virtual WorkArea & workarea(); /// repaint the whole content immediately void repaint(); diff --git a/src/frontends/qt4/LyXScreenFactory.C b/src/frontends/qt4/LyXScreenFactory.C index 85edbce2d9..e1a4c3d44c 100644 --- a/src/frontends/qt4/LyXScreenFactory.C +++ b/src/frontends/qt4/LyXScreenFactory.C @@ -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(owner)); + return &(static_cast(owner)); } } // namespace LyXScreenFactory diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 3454150eea..2c53b31f15 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -92,6 +92,5 @@ libqt4_la_SOURCES = \ qfont_loader.h qfont_loader.C \ qfont_metrics.C \ qlkey.h \ - qscreen.h qscreen.C \ qt_helpers.h qt_helpers.C \ $(MOCFILES) diff --git a/src/frontends/qt4/QWorkArea.C b/src/frontends/qt4/QWorkArea.C index 86261069ed..35f5891c64 100644 --- a/src/frontends/qt4/QWorkArea.C +++ b/src/frontends/qt4/QWorkArea.C @@ -216,6 +216,7 @@ void QWorkArea::setScrollbarParams(int h, int scroll_pos, int scroll_line_step) void QWorkArea::adjustViewWithScrollBar(int action) { + /* lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION << " verticalScrollBar val=" << verticalScrollBar()->value() << " verticalScrollBar pos=" << verticalScrollBar()->sliderPosition() @@ -224,7 +225,7 @@ void QWorkArea::adjustViewWithScrollBar(int action) << " pagestep=" << verticalScrollBar()->pageStep() << " linestep=" << verticalScrollBar()->lineStep() << endl; - + */ view_.view()->scrollDocView(verticalScrollBar()->sliderPosition()); } @@ -538,6 +539,12 @@ void QWorkArea::paintEvent(QPaintEvent * e) */ 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,6 +560,92 @@ void QWorkArea::drawScreen(int x, int y, QPixmap pixmap) viewport()->update(x, y, pixmap.width(), pixmap.height()); } +/////////////////////////////////////////////////////////////// +// LyXSreen overloaded methods: + +WorkArea & QWorkArea::workarea() +{ +// return static_cast (*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_); +} /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// diff --git a/src/frontends/qt4/QWorkArea.h b/src/frontends/qt4/QWorkArea.h index 6ca7a88e12..1f5147ee21 100644 --- a/src/frontends/qt4/QWorkArea.h +++ b/src/frontends/qt4/QWorkArea.h @@ -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 @@ public: * 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 @@ public: QPixmap is implicitely shared so no need to pass by reference. */ void drawScreen(int x, int y, QPixmap pixmap); + + 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(); - LyXView & view() - { - return view_; - } protected: /// repaint part of the widget @@ -221,6 +234,29 @@ private: std::queue > 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 diff --git a/src/frontends/qt4/qscreen.C b/src/frontends/qt4/qscreen.C deleted file mode 100644 index ef24f99ce2..0000000000 --- a/src/frontends/qt4/qscreen.C +++ /dev/null @@ -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 - -#include "QWorkArea.h" -#include "qscreen.h" - -#include -#include -#include - -#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_); -} diff --git a/src/frontends/qt4/qscreen.h b/src/frontends/qt4/qscreen.h deleted file mode 100644 index ae920f1ab0..0000000000 --- a/src/frontends/qt4/qscreen.h +++ /dev/null @@ -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 - -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 diff --git a/src/frontends/screen.h b/src/frontends/screen.h index c10c65d0e8..1c2825fc1b 100644 --- a/src/frontends/screen.h +++ b/src/frontends/screen.h @@ -63,7 +63,7 @@ protected: 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 { diff --git a/src/frontends/xforms/xscreen.C b/src/frontends/xforms/xscreen.C index b0a0a77043..1c903ba878 100644 --- a/src/frontends/xforms/xscreen.C +++ b/src/frontends/xforms/xscreen.C @@ -59,7 +59,7 @@ XScreen::~XScreen() } -WorkArea & XScreen::workarea() const +WorkArea & XScreen::workarea() { return owner_; } diff --git a/src/frontends/xforms/xscreen.h b/src/frontends/xforms/xscreen.h index 00bfc2538e..829ac96230 100644 --- a/src/frontends/xforms/xscreen.h +++ b/src/frontends/xforms/xscreen.h @@ -41,7 +41,7 @@ public: 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);