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