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