3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
14 #include "QWorkArea.h"
21 #include "lcolorcache.h"
23 #include <QApplication>
31 QScreen::QScreen(QWorkArea & o)
32 : LyXScreen(), owner_(o), nocursor_pixmap_(0,0)
42 WorkArea & QScreen::workarea() const
47 void QScreen::expose(int x, int y, int w, int h)
49 lyxerr[Debug::GUI] << "expose " << w << 'x' << h << '+' << x << '+' << y << std::endl;
51 owner_.viewport()->update(x, y, w, h);
56 void QScreen::showCursor(int x, int y, int h, Cursor_Shape shape)
58 if (!qApp->focusWidget())
61 if (x==cursor_x_ && y==cursor_y_ && h==cursor_h_) {
62 // Draw the new (vertical) cursor using the cached store.
63 QLPainter * lp = (QLPainter *) &(owner_.getPainter());
64 lp->pixmap(cursor_x_, cursor_y_, vcursor_pixmap_);
65 owner_.viewport()->update(
67 cursor_w_, cursor_h_);
71 // Cache the dimensions of the cursor.
81 cursor_w_ = cursor_h_ / 3;
83 case REVERSED_L_SHAPE:
84 cursor_w_ = cursor_h_ / 3;
85 cursor_x_ = x - cursor_w_ + 1;
90 // We cache three pixmaps:
91 // 1 the rectangle of the original screen.
92 // 2 the vertical line of the cursor.
93 // 3 the horizontal line of the L-shaped cursor (if necessary).
95 // Initialise storage for these pixmaps as necessary.
96 if (cursor_w_ != nocursor_pixmap_.width() ||
97 cursor_h_ != nocursor_pixmap_.height()) {
98 nocursor_pixmap_.resize(cursor_w_, cursor_h_);
101 QColor const & required_color = lcolorcache.get(LColor::cursor);
102 bool const cursor_color_changed = required_color != cursor_color_;
103 if (cursor_color_changed)
104 cursor_color_ = required_color;
106 // if (cursor_h_ != vcursor_pixmap_.height() || cursor_color_changed) {
107 // if (cursor_h_ != vcursor_pixmap_.height())
108 vcursor_pixmap_.resize(cursor_w_, cursor_h_);
109 vcursor_pixmap_.fill(cursor_color_);
115 case REVERSED_L_SHAPE:
117 if (cursor_w_ != hcursor_pixmap_.width() ||
118 cursor_color_changed) {
119 if (cursor_w_ != hcursor_pixmap_.width())
120 hcursor_pixmap_.resize(cursor_w_, 1);
121 hcursor_pixmap_.fill(cursor_color_);
126 // Save the old area (no cursor).
127 QPainter qp(&nocursor_pixmap_);
128 qp.drawPixmap(0, 0, *owner_.pixmap(),
129 cursor_x_, cursor_y_, cursor_w_, cursor_h_);
131 // Draw the new (vertical) cursor using the cached store.
132 QLPainter * lp = (QLPainter *) &(owner_.getPainter());
133 lp->pixmap(cursor_x_, cursor_y_, vcursor_pixmap_);
135 // Draw the new (horizontal) cursor if necessary.
139 case REVERSED_L_SHAPE:
141 lp->pixmap(cursor_x_, y + h - 1, hcursor_pixmap_);
145 owner_.viewport()->update(
146 cursor_x_, cursor_y_,
147 cursor_w_, cursor_h_);
151 void QScreen::removeCursor()
153 // before first showCursor
154 if (nocursor_pixmap_.isNull())
157 QLPainter * lp = (QLPainter *) &(owner_.getPainter());
158 lp->pixmap(cursor_x_, cursor_y_, nocursor_pixmap_);
160 owner_.viewport()->update(
161 cursor_x_, cursor_y_,
162 cursor_w_, cursor_h_);