]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/qscreen.C
Minipage is no more (long live the box inset)
[lyx.git] / src / frontends / qt2 / qscreen.C
1 /**
2  * \file qscreen.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "debug.h"
14 #include "QWorkArea.h"
15 #include "qscreen.h"
16 #include "LColor.h"
17
18 #include <qapplication.h>
19
20 using std::endl;
21
22
23 namespace {
24
25 /// copy some horizontal regions about inside a pixmap
26 void copyInPixmap(QPixmap * p, int dest_y, int src_y, int src_w, int src_h)
27 {
28         // bitBlt(dest, dest_x, dest_y, source, src_x, src_y, src_w, src_h)
29         bitBlt(p, 0, dest_y, p, 0, src_y, src_w, src_h);
30 }
31
32 } // namespace anon
33
34
35 QScreen::QScreen(QWorkArea & o)
36         : LyXScreen(), owner_(o)
37 {
38 }
39
40
41 QScreen::~QScreen()
42 {
43 }
44
45
46 WorkArea & QScreen::workarea() const
47 {
48         return owner_;
49 }
50
51
52 void QScreen::repaint()
53 {
54         QWidget * content = owner_.getContent();
55         content->repaint(0, 0, content->width(), content->height());
56 }
57
58
59 void QScreen::expose(int x, int y, int w, int h)
60 {
61         lyxerr[Debug::GUI] << "expose " << w << 'x' << h
62                 << '+' << x << '+' << y << endl;
63
64         owner_.getContent()->update(x, y, w, h);
65 }
66
67
68 void QScreen::showCursor(int x, int y, int h, Cursor_Shape shape)
69 {
70         cursor_x_ = x;
71         cursor_y_ = y;
72         cursor_h_ = h;
73
74         switch (shape) {
75                 case BAR_SHAPE:
76                         cursor_w_ = 1;
77                         break;
78                 case L_SHAPE:
79                         cursor_w_ = cursor_h_ / 3;
80                         break;
81                 case REVERSED_L_SHAPE:
82                         cursor_w_ = cursor_h_ / 3;
83                         cursor_x_ = x - cursor_w_ + 1;
84                         break;
85         }
86
87         if (!nocursor_pixmap_.get()
88                 || cursor_w_ != nocursor_pixmap_->width()
89                 || cursor_h_ != nocursor_pixmap_->height()) {
90                 nocursor_pixmap_.reset(new QPixmap(cursor_w_, cursor_h_));
91         }
92
93         if (!qApp->focusWidget())
94                 return;
95
96         // save old area
97         bitBlt(nocursor_pixmap_.get(), 0, 0, owner_.getPixmap(),
98                 cursor_x_, cursor_y_, cursor_w_, cursor_h_);
99
100         Painter & pain(owner_.getPainter());
101         pain.start();
102         pain.line(x, y, x, y + h - 1, LColor::cursor);
103
104         switch (shape) {
105                 case BAR_SHAPE:
106                         break;
107                 case REVERSED_L_SHAPE:
108                 case L_SHAPE:
109                         pain.line(cursor_x_, y + h - 1, cursor_x_ + cursor_w_ - 1,
110                                 y + h - 1, LColor::cursor);
111                         break;
112         }
113
114         pain.end();
115
116         owner_.getContent()->repaint(
117                 cursor_x_, cursor_y_,
118                 cursor_w_, cursor_h_);
119 }
120
121
122 void QScreen::removeCursor()
123 {
124         // before first showCursor
125         if (!nocursor_pixmap_.get())
126                 return;
127
128         bitBlt(owner_.getPixmap(), cursor_x_, cursor_y_,
129                 nocursor_pixmap_.get(), 0, 0, cursor_w_, cursor_h_);
130
131         owner_.getContent()->repaint(
132                 cursor_x_, cursor_y_,
133                 cursor_w_, cursor_h_);
134 }