]> git.lyx.org Git - lyx.git/blob - src/frontends/qt3/qscreen.C
GUI API Cleanup step 2: merge of the "younes" branch.
[lyx.git] / src / frontends / qt3 / 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 "QWorkArea.h"
14 #include "qscreen.h"
15
16 #include "debug.h"
17 #include "lcolorcache.h"
18
19 #include <qapplication.h>
20
21
22 namespace {
23
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)
26 {
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);
29 }
30
31 } // namespace anon
32
33 namespace lyx {
34 namespace frontend {
35
36 QScreen::QScreen(QWorkArea & o)
37         : owner_(o)
38 {
39 }
40
41
42 QScreen::~QScreen()
43 {
44 }
45
46
47 void QScreen::repaint()
48 {
49         QWidget * content = owner_.getContent();
50         content->repaint(0, 0, content->width(), content->height());
51 }
52
53
54 void QScreen::expose(int x, int y, int w, int h)
55 {
56         lyxerr[Debug::GUI] << "expose " << w << 'x' << h
57                 << '+' << x << '+' << y << std::endl;
58
59         owner_.getContent()->update(x, y, w, h);
60 }
61
62
63 void QScreen::showCursor(int x, int y, int h, CursorShape shape)
64 {
65         if (!qApp->focusWidget())
66                 return;
67
68         // Cache the dimensions of the cursor.
69         cursor_x_ = x;
70         cursor_y_ = y;
71         cursor_h_ = h;
72
73         switch (shape) {
74         case BAR_SHAPE:
75                 cursor_w_ = 1;
76                 break;
77         case L_SHAPE:
78                 cursor_w_ = cursor_h_ / 3;
79                 break;
80         case REVERSED_L_SHAPE:
81                 cursor_w_ = cursor_h_ / 3;
82                 cursor_x_ = x - cursor_w_ + 1;
83                 break;
84         }
85
86         // We cache three pixmaps:
87         // 1 the rectangle of the original screen.
88         // 2 the vertical line of the cursor.
89         // 3 the horizontal line of the L-shaped cursor (if necessary).
90
91         // Initialise storage for these pixmaps as necessary.
92         if (cursor_w_ != nocursor_pixmap_.width() ||
93             cursor_h_ != nocursor_pixmap_.height()) {
94                 nocursor_pixmap_.resize(cursor_w_, cursor_h_);
95         }
96
97         QColor const & required_color = lcolorcache.get(LColor::cursor);
98         bool const cursor_color_changed = required_color != cursor_color_;
99         if (cursor_color_changed)
100                 cursor_color_ = required_color;
101
102         if (cursor_h_ != vcursor_pixmap_.height() || cursor_color_changed) {
103                 if (cursor_h_ != vcursor_pixmap_.height())
104                         vcursor_pixmap_.resize(1, cursor_h_);
105                 vcursor_pixmap_.fill(cursor_color_);
106         }
107
108         switch (shape) {
109         case BAR_SHAPE:
110                 break;
111         case REVERSED_L_SHAPE:
112         case L_SHAPE:
113                 if (cursor_w_ != hcursor_pixmap_.width() ||
114                     cursor_color_changed) {
115                         if (cursor_w_ != hcursor_pixmap_.width())
116                                 hcursor_pixmap_.resize(cursor_w_, 1);
117                         hcursor_pixmap_.fill(cursor_color_);
118                 }
119                 break;
120         }
121
122         // Save the old area (no cursor).
123         bitBlt(&nocursor_pixmap_, 0, 0, owner_.getPixmap(),
124                cursor_x_, cursor_y_, cursor_w_, cursor_h_);
125
126         // Draw the new (vertical) cursor using the cached store.
127         bitBlt(owner_.getPixmap(), x, y,
128                &vcursor_pixmap_, 0, 0,
129                vcursor_pixmap_.width(), vcursor_pixmap_.height());
130
131         // Draw the new (horizontal) cursor if necessary.
132         switch (shape) {
133         case BAR_SHAPE:
134                 break;
135         case REVERSED_L_SHAPE:
136         case L_SHAPE:
137                 bitBlt(owner_.getPixmap(), cursor_x_, y + h - 1,
138                        &hcursor_pixmap_, 0, 0,
139                        hcursor_pixmap_.width(), hcursor_pixmap_.height());
140                 break;
141         }
142
143         owner_.getContent()->update(
144                 cursor_x_, cursor_y_,
145                 cursor_w_, cursor_h_);
146 }
147
148
149 void QScreen::removeCursor()
150 {
151         // before first showCursor
152         if (nocursor_pixmap_.isNull())
153                 return;
154
155         bitBlt(owner_.getPixmap(), cursor_x_, cursor_y_,
156                &nocursor_pixmap_, 0, 0, cursor_w_, cursor_h_);
157
158         owner_.getContent()
159                 ->update(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
160 }
161
162
163 } // namespace frontend
164 } // namespace lyx