]> git.lyx.org Git - features.git/blob - src/frontends/qt3/qscreen.C
* Rename src/frontends/qt2 to src/frontends/qt3,
[features.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
34 QScreen::QScreen(QWorkArea & o)
35         : LyXScreen(), owner_(o)
36 {
37 }
38
39
40 QScreen::~QScreen()
41 {
42 }
43
44
45 WorkArea & QScreen::workarea() const
46 {
47         return owner_;
48 }
49
50
51 void QScreen::repaint()
52 {
53         QWidget * content = owner_.getContent();
54         content->repaint(0, 0, content->width(), content->height());
55 }
56
57
58 void QScreen::expose(int x, int y, int w, int h)
59 {
60         lyxerr[Debug::GUI] << "expose " << w << 'x' << h
61                 << '+' << x << '+' << y << std::endl;
62
63         owner_.getContent()->update(x, y, w, h);
64 }
65
66
67 void QScreen::showCursor(int x, int y, int h, Cursor_Shape shape)
68 {
69         if (!qApp->focusWidget())
70                 return;
71
72         // Cache the dimensions of the cursor.
73         cursor_x_ = x;
74         cursor_y_ = y;
75         cursor_h_ = h;
76
77         switch (shape) {
78         case BAR_SHAPE:
79                 cursor_w_ = 1;
80                 break;
81         case L_SHAPE:
82                 cursor_w_ = cursor_h_ / 3;
83                 break;
84         case REVERSED_L_SHAPE:
85                 cursor_w_ = cursor_h_ / 3;
86                 cursor_x_ = x - cursor_w_ + 1;
87                 break;
88         }
89
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).
94
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_);
99         }
100
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;
105
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_);
110         }
111
112         switch (shape) {
113         case BAR_SHAPE:
114                 break;
115         case REVERSED_L_SHAPE:
116         case 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_);
122                 }
123                 break;
124         }
125
126         // Save the old area (no cursor).
127         bitBlt(&nocursor_pixmap_, 0, 0, owner_.getPixmap(),
128                cursor_x_, cursor_y_, cursor_w_, cursor_h_);
129
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());
134
135         // Draw the new (horizontal) cursor if necessary.
136         switch (shape) {
137         case BAR_SHAPE:
138                 break;
139         case REVERSED_L_SHAPE:
140         case L_SHAPE:
141                 bitBlt(owner_.getPixmap(), cursor_x_, y + h - 1,
142                        &hcursor_pixmap_, 0, 0,
143                        hcursor_pixmap_.width(), hcursor_pixmap_.height());
144                 break;
145         }
146
147         owner_.getContent()->update(
148                 cursor_x_, cursor_y_,
149                 cursor_w_, cursor_h_);
150 }
151
152
153 void QScreen::removeCursor()
154 {
155         // before first showCursor
156         if (nocursor_pixmap_.isNull())
157                 return;
158
159         bitBlt(owner_.getPixmap(), cursor_x_, cursor_y_,
160                &nocursor_pixmap_, 0, 0, cursor_w_, cursor_h_);
161
162         owner_.getContent()
163                 ->update(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
164 }