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
18 #include "QWorkArea.h"
22 #include "BufferView.h"
23 #include "insets/insettext.h"
26 #include <qapplication.h>
34 /// copy some horizontal regions about inside a pixmap
35 void copyInPixmap(QPixmap * p, int dest_y, int src_y, int src_w, int src_h)
37 // bitBlt(dest, dest_x, dest_y, source, src_x, src_y, src_w, src_h)
38 bitBlt(p, 0, dest_y, p, 0, src_y, src_w, src_h);
44 QScreen::QScreen(QWorkArea & o)
45 : LyXScreen(), owner_(o)
55 void QScreen::repaint()
57 QWidget * content(owner_.getContent());
58 content->repaint(0, 0, content->width(), content->height());
62 void QScreen::expose(int x, int y, int w, int h)
64 lyxerr[Debug::GUI] << "expose " << w << 'x' << h
65 << '+' << x << '+' << y << endl;
67 owner_.getContent()->update(x, y, w, h);
71 void QScreen::draw(LyXText * text, BufferView * bv, unsigned int y)
73 QPixmap * p(owner_.getPixmap());
75 owner_.getPainter().start();
77 int const old_first = text->top_y();
80 // If you want to fix the warning below, fix it so it
81 // actually scrolls properly. Hint: a cast won't do.
83 // is any optimization possible?
84 if (y - old_first < owner_.workHeight()
85 && old_first - y < owner_.workHeight()) {
86 if (text->top_y() < old_first) {
87 int const dest_y = old_first - text->top_y();
88 drawFromTo(text, bv, 0, dest_y, 0, 0);
89 copyInPixmap(p, dest_y, 0, owner_.workWidth(), owner_.height() - dest_y);
90 expose(0, 0, owner_.workWidth(), dest_y);
92 int const src_y = text->top_y() - old_first;
93 drawFromTo(text, bv, owner_.height() - src_y, owner_.height(), 0, 0);
94 copyInPixmap(p, 0, 0, owner_.workWidth(), owner_.height() - src_y);
95 expose(0, owner_.height() - src_y, owner_.workWidth(), src_y);
98 lyxerr[Debug::GUI] << "dumb full redraw" << endl;
99 drawFromTo(text, bv, 0, owner_.height(), 0, 0);
103 owner_.getPainter().end();
107 void QScreen::showCursor(int x, int y, int h, Cursor_Shape shape)
118 cursor_w_ = cursor_h_ / 3;
120 case REVERSED_L_SHAPE:
121 cursor_w_ = cursor_h_ / 3;
122 cursor_x_ = x - cursor_w_ + 1;
126 if (!nocursor_pixmap_.get()
127 || cursor_w_ != nocursor_pixmap_->width()
128 || cursor_h_ != nocursor_pixmap_->height()) {
129 nocursor_pixmap_.reset(new QPixmap(cursor_w_, cursor_h_));
132 if (!qApp->focusWidget())
136 bitBlt(nocursor_pixmap_.get(), 0, 0, owner_.getPixmap(),
137 cursor_x_, cursor_y_, cursor_w_, cursor_h_);
139 Painter & pain(owner_.getPainter());
141 pain.line(x, y, x, y + h - 1, LColor::cursor);
146 case REVERSED_L_SHAPE:
148 pain.line(cursor_x_, y + h - 1, cursor_x_ + cursor_w_ - 1,
149 y + h - 1, LColor::cursor);
155 owner_.getContent()->repaint(
156 cursor_x_, cursor_y_,
157 cursor_w_, cursor_h_);
161 void QScreen::removeCursor()
163 // before first showCursor
164 if (!nocursor_pixmap_.get())
167 bitBlt(owner_.getPixmap(), cursor_x_, cursor_y_,
168 nocursor_pixmap_.get(), 0, 0, cursor_w_, cursor_h_);
170 owner_.getContent()->repaint(
171 cursor_x_, cursor_y_,
172 cursor_w_, cursor_h_);