3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "QWorkArea.h"
17 #include "lcolorcache.h"
19 #include <qapplication.h>
24 /// copy some horizontal regions about inside a pixmap
25 void copyInPixmap(QPixmap * p, int dest_y, int src_y, int src_w, int src_h)
27 // bitBlt(dest, dest_x, dest_y, source, src_x, src_y, src_w, src_h)
28 bitBlt(p, 0, dest_y, p, 0, src_y, src_w, src_h);
34 QScreen::QScreen(QWorkArea & o)
35 : LyXScreen(), owner_(o)
45 WorkArea & QScreen::workarea() const
51 void QScreen::repaint()
53 QWidget * content = owner_.getContent();
54 content->repaint(0, 0, content->width(), content->height());
58 void QScreen::expose(int x, int y, int w, int h)
60 lyxerr[Debug::GUI] << "expose " << w << 'x' << h
61 << '+' << x << '+' << y << std::endl;
63 owner_.getContent()->update(x, y, w, h);
67 void QScreen::showCursor(int x, int y, int h, Cursor_Shape shape)
69 if (!qApp->focusWidget())
72 // Cache the dimensions of the cursor.
82 cursor_w_ = cursor_h_ / 3;
84 case REVERSED_L_SHAPE:
85 cursor_w_ = cursor_h_ / 3;
86 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(1, 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 bitBlt(&nocursor_pixmap_, 0, 0, owner_.getPixmap(),
128 cursor_x_, cursor_y_, cursor_w_, cursor_h_);
130 // Draw the new (vertical) cursor using the cached store.
131 bitBlt(owner_.getPixmap(), x, y,
132 &vcursor_pixmap_, 0, 0,
133 vcursor_pixmap_.width(), vcursor_pixmap_.height());
135 // Draw the new (horizontal) cursor if necessary.
139 case REVERSED_L_SHAPE:
141 bitBlt(owner_.getPixmap(), cursor_x_, y + h - 1,
142 &hcursor_pixmap_, 0, 0,
143 hcursor_pixmap_.width(), hcursor_pixmap_.height());
147 owner_.getContent()->update(
148 cursor_x_, cursor_y_,
149 cursor_w_, cursor_h_);
153 void QScreen::removeCursor()
155 // before first showCursor
156 if (nocursor_pixmap_.isNull())
159 bitBlt(owner_.getPixmap(), cursor_x_, cursor_y_,
160 &nocursor_pixmap_, 0, 0, cursor_w_, cursor_h_);
163 ->update(cursor_x_, cursor_y_, cursor_w_, cursor_h_);