]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/qscreen.C
rename LFUN enum values according to their command (as used in th minibuffer/bind...
[lyx.git] / src / frontends / qt4 / 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  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "QWorkArea.h"
15 #include "qscreen.h"
16
17 #include <QColor>
18 #include <QPainter>
19 #include <QApplication>
20
21 #include "debug.h"
22 #include "lcolorcache.h"
23
24
25 namespace {
26
27 } // namespace anon
28
29
30 QScreen::QScreen(QWorkArea & o)
31         : LyXScreen(), owner_(o), nocursor_(0,0)
32 {
33 }
34
35
36 QScreen::~QScreen()
37 {
38 }
39
40
41 WorkArea & QScreen::workarea() const
42 {
43         return owner_;
44 }
45
46 void QScreen::expose(int x, int y, int w, int h)
47 {
48         lyxerr[Debug::GUI] << "expose " << w << 'x' << h
49                 << '+' << x << '+' << y << std::endl;
50
51         owner_.update(x, y, w, h);
52 }
53
54 void QScreen::showCursor(int x, int y, int h, Cursor_Shape shape)
55 {
56         if (!qApp->focusWidget())
57                 return;
58
59         if (x==cursor_x_ && y==cursor_y_ && h==cursor_h_) {
60                 // Draw the new (vertical) cursor using the cached store.
61                 owner_.drawScreen(cursor_x_, cursor_y_, vcursor_);
62                 return;
63         }
64
65         // Cache the dimensions of the cursor.
66         cursor_x_ = x;
67         cursor_y_ = y;
68         cursor_h_ = h;
69
70         switch (shape) {
71         case BAR_SHAPE:
72                 cursor_w_ = 2;
73                 break;
74         case L_SHAPE:
75                 cursor_w_ = cursor_h_ / 3;
76                 break;
77         case REVERSED_L_SHAPE:
78                 cursor_w_ = cursor_h_ / 3;
79                 cursor_x_ = x - cursor_w_ + 1;
80                 break;
81         }
82
83
84         // We cache three pixmaps:
85         // 1 the rectangle of the original screen.
86         // 2 the vertical line of the cursor.
87         // 3 the horizontal line of the L-shaped cursor (if necessary).
88
89         QColor const & required_color = lcolorcache.get(LColor::cursor);
90         bool const cursor_color_changed = required_color != cursor_color_;
91         if (cursor_color_changed)
92                 cursor_color_ = required_color;
93
94         vcursor_ = QPixmap(cursor_w_, cursor_h_);
95         vcursor_ .fill(cursor_color_);
96
97         switch (shape) {
98         case BAR_SHAPE:
99                 break;
100         case REVERSED_L_SHAPE:
101         case L_SHAPE:
102                 if (cursor_w_ != hcursor_.width() ||
103                     cursor_color_changed) {
104                         if (cursor_w_ != hcursor_.width())
105                                 hcursor_ = QPixmap(cursor_w_, 1);
106                         hcursor_.fill(cursor_color_);
107                 }
108                 break;
109         }
110
111         // Save the old area (no cursor).
112         nocursor_ = owner_.copyScreen(cursor_x_, cursor_y_, cursor_w_, cursor_h_);
113
114         // Draw the new (vertical) cursor using the cached store.
115         owner_.drawScreen(cursor_x_, cursor_y_, vcursor_);
116
117         // Draw the new (horizontal) cursor if necessary.
118         switch (shape) {
119         case BAR_SHAPE:
120                 break;
121         case REVERSED_L_SHAPE:
122         case L_SHAPE:
123                 owner_.drawScreen(cursor_x_, y + h - 1, hcursor_);
124                 break;
125         }
126 }
127
128
129 void QScreen::removeCursor()
130 {
131         // before first showCursor
132         if (nocursor_.isNull())
133                 return;
134
135         owner_.drawScreen(cursor_x_, cursor_y_, nocursor_);
136 }