-rw-r--r-- | core/apps/embeddedkonsole/TEWidget.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/core/apps/embeddedkonsole/TEWidget.cpp b/core/apps/embeddedkonsole/TEWidget.cpp index 2e3e0f5..de5e585 100644 --- a/core/apps/embeddedkonsole/TEWidget.cpp +++ b/core/apps/embeddedkonsole/TEWidget.cpp | |||
@@ -1,1433 +1,1433 @@ | |||
1 | /* ------------------------------------------------------------------------ */ | 1 | /* ------------------------------------------------------------------------ */ |
2 | /* */ | 2 | /* */ |
3 | /* [TEWidget.C] Terminal Emulation Widget */ | 3 | /* [TEWidget.C] Terminal Emulation Widget */ |
4 | /* */ | 4 | /* */ |
5 | /* ------------------------------------------------------------------------ */ | 5 | /* ------------------------------------------------------------------------ */ |
6 | /* */ | 6 | /* */ |
7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ | 7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ |
8 | /* */ | 8 | /* */ |
9 | /* This file is part of Konsole - an X terminal for KDE */ | 9 | /* This file is part of Konsole - an X terminal for KDE */ |
10 | /* */ | 10 | /* */ |
11 | /* ------------------------------------------------------------------------ */ | 11 | /* ------------------------------------------------------------------------ */ |
12 | /* */ | 12 | /* */ |
13 | /* Ported Konsole to Qt/Embedded */ | 13 | /* Ported Konsole to Qt/Embedded */ |
14 | /* */ | 14 | /* */ |
15 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ | 15 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ |
16 | /* */ | 16 | /* */ |
17 | /* -------------------------------------------------------------------------- */ | 17 | /* -------------------------------------------------------------------------- */ |
18 | /*! \class TEWidget | 18 | /*! \class TEWidget |
19 | 19 | ||
20 | \brief Visible screen contents | 20 | \brief Visible screen contents |
21 | 21 | ||
22 | This class is responsible to map the `image' of a terminal emulation to the | 22 | This class is responsible to map the `image' of a terminal emulation to the |
23 | display. All the dependency of the emulation to a specific GUI or toolkit is | 23 | display. All the dependency of the emulation to a specific GUI or toolkit is |
24 | localized here. Further, this widget has no knowledge about being part of an | 24 | localized here. Further, this widget has no knowledge about being part of an |
25 | emulation, it simply work within the terminal emulation framework by exposing | 25 | emulation, it simply work within the terminal emulation framework by exposing |
26 | size and key events and by being ordered to show a new image. | 26 | size and key events and by being ordered to show a new image. |
27 | 27 | ||
28 | <ul> | 28 | <ul> |
29 | <li> The internal image has the size of the widget (evtl. rounded up) | 29 | <li> The internal image has the size of the widget (evtl. rounded up) |
30 | <li> The external image used in setImage can have any size. | 30 | <li> The external image used in setImage can have any size. |
31 | <li> (internally) the external image is simply copied to the internal | 31 | <li> (internally) the external image is simply copied to the internal |
32 | when a setImage happens. During a resizeEvent no painting is done | 32 | when a setImage happens. During a resizeEvent no painting is done |
33 | a paintEvent is expected to follow anyway. | 33 | a paintEvent is expected to follow anyway. |
34 | </ul> | 34 | </ul> |
35 | 35 | ||
36 | \sa TEScreen \sa Emulation | 36 | \sa TEScreen \sa Emulation |
37 | */ | 37 | */ |
38 | 38 | ||
39 | /* FIXME: | 39 | /* FIXME: |
40 | - 'image' may also be used uninitialized (it isn't in fact) in resizeEvent | 40 | - 'image' may also be used uninitialized (it isn't in fact) in resizeEvent |
41 | - 'font_a' not used in mouse events | 41 | - 'font_a' not used in mouse events |
42 | - add destructor | 42 | - add destructor |
43 | */ | 43 | */ |
44 | 44 | ||
45 | /* TODO | 45 | /* TODO |
46 | - evtl. be sensitive to `paletteChange' while using default colors. | 46 | - evtl. be sensitive to `paletteChange' while using default colors. |
47 | - set different 'rounding' styles? I.e. have a mode to show clipped chars? | 47 | - set different 'rounding' styles? I.e. have a mode to show clipped chars? |
48 | */ | 48 | */ |
49 | 49 | ||
50 | // #include "config.h" | 50 | // #include "config.h" |
51 | #include "TEWidget.h" | 51 | #include "TEWidget.h" |
52 | #include "session.h" | 52 | #include "session.h" |
53 | #include <qpe/config.h> | 53 | #include <qpe/config.h> |
54 | 54 | ||
55 | #include <qpe/resource.h> | 55 | #include <qpe/resource.h> |
56 | #include <qpe/sound.h> | 56 | #include <qpe/sound.h> |
57 | 57 | ||
58 | #if !(QT_NO_COP) | 58 | #if !(QT_NO_COP) |
59 | #include <qpe/qcopenvelope_qws.h> | 59 | #include <qpe/qcopenvelope_qws.h> |
60 | #endif | 60 | #endif |
61 | 61 | ||
62 | #include <qcursor.h> | 62 | #include <qcursor.h> |
63 | #include <qregexp.h> | 63 | #include <qregexp.h> |
64 | #include <qpainter.h> | 64 | #include <qpainter.h> |
65 | #include <qclipboard.h> | 65 | #include <qclipboard.h> |
66 | #include <qstyle.h> | 66 | #include <qstyle.h> |
67 | #include <qfile.h> | 67 | #include <qfile.h> |
68 | #include <qdragobject.h> | 68 | #include <qdragobject.h> |
69 | #include <qnamespace.h> | 69 | #include <qnamespace.h> |
70 | 70 | ||
71 | #include <stdio.h> | 71 | #include <stdio.h> |
72 | #include <stdlib.h> | 72 | #include <stdlib.h> |
73 | #include <unistd.h> | 73 | #include <unistd.h> |
74 | #include <ctype.h> | 74 | #include <ctype.h> |
75 | #include <sys/stat.h> | 75 | #include <sys/stat.h> |
76 | #include <sys/types.h> | 76 | #include <sys/types.h> |
77 | #include <signal.h> | 77 | #include <signal.h> |
78 | 78 | ||
79 | #include <assert.h> | 79 | #include <assert.h> |
80 | 80 | ||
81 | // #include "TEWidget.moc" | 81 | // #include "TEWidget.moc" |
82 | //#include <kapp.h> | 82 | //#include <kapp.h> |
83 | //#include <kcursor.h> | 83 | //#include <kcursor.h> |
84 | //#include <kurl.h> | 84 | //#include <kurl.h> |
85 | //#include <kdebug.h> | 85 | //#include <kdebug.h> |
86 | //#include <klocale.h> | 86 | //#include <klocale.h> |
87 | 87 | ||
88 | #define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__) | 88 | #define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__) |
89 | #define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); } | 89 | #define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); } |
90 | 90 | ||
91 | #define loc(X,Y) ((Y)*columns+(X)) | 91 | #define loc(X,Y) ((Y)*columns+(X)) |
92 | 92 | ||
93 | //FIXME: the rim should normally be 1, 0 only when running in full screen mode. | 93 | //FIXME: the rim should normally be 1, 0 only when running in full screen mode. |
94 | #define rimX 0 // left/right rim width | 94 | #define rimX 0 // left/right rim width |
95 | #define rimY 0 // top/bottom rim high | 95 | #define rimY 0 // top/bottom rim high |
96 | 96 | ||
97 | #define SCRWIDTH 16 // width of the scrollbar | 97 | #define SCRWIDTH 16 // width of the scrollbar |
98 | 98 | ||
99 | #define yMouseScroll 1 | 99 | #define yMouseScroll 1 |
100 | // scroll increment used when dragging selection at top/bottom of window. | 100 | // scroll increment used when dragging selection at top/bottom of window. |
101 | 101 | ||
102 | /* ------------------------------------------------------------------------- */ | 102 | /* ------------------------------------------------------------------------- */ |
103 | /* */ | 103 | /* */ |
104 | /* Colors */ | 104 | /* Colors */ |
105 | /* */ | 105 | /* */ |
106 | /* ------------------------------------------------------------------------- */ | 106 | /* ------------------------------------------------------------------------- */ |
107 | 107 | ||
108 | //FIXME: the default color table is in session.C now. | 108 | //FIXME: the default color table is in session.C now. |
109 | // We need a way to get rid of this one, here. | 109 | // We need a way to get rid of this one, here. |
110 | static const ColorEntry base_color_table[TABLE_COLORS] = | 110 | static const ColorEntry base_color_table[TABLE_COLORS] = |
111 | // The following are almost IBM standard color codes, with some slight | 111 | // The following are almost IBM standard color codes, with some slight |
112 | // gamma correction for the dim colors to compensate for bright X screens. | 112 | // gamma correction for the dim colors to compensate for bright X screens. |
113 | // It contains the 8 ansiterm/xterm colors in 2 intensities. | 113 | // It contains the 8 ansiterm/xterm colors in 2 intensities. |
114 | { | 114 | { |
115 | // Fixme: could add faint colors here, also. | 115 | // Fixme: could add faint colors here, also. |
116 | // normal | 116 | // normal |
117 | ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback | 117 | ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback |
118 | ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red | 118 | ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red |
119 | ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow | 119 | ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow |
120 | ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta | 120 | ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta |
121 | ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White | 121 | ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White |
122 | // intensiv | 122 | // intensiv |
123 | ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ), | 123 | ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ), |
124 | ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ), | 124 | ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ), |
125 | ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ), | 125 | ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ), |
126 | ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), | 126 | ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), |
127 | ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 ) | 127 | ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 ) |
128 | }; | 128 | }; |
129 | 129 | ||
130 | /* Note that we use ANSI color order (bgr), while IBMPC color order is (rgb) | 130 | /* Note that we use ANSI color order (bgr), while IBMPC color order is (rgb) |
131 | 131 | ||
132 | Code 0 1 2 3 4 5 6 7 | 132 | Code 0 1 2 3 4 5 6 7 |
133 | ----------- ------- ------- ------- ------- ------- ------- ------- ------- | 133 | ----------- ------- ------- ------- ------- ------- ------- ------- ------- |
134 | ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White | 134 | ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White |
135 | IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White | 135 | IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White |
136 | */ | 136 | */ |
137 | 137 | ||
138 | QColor TEWidget::getDefaultBackColor() | 138 | QColor TEWidget::getDefaultBackColor() |
139 | { | 139 | { |
140 | return color_table[DEFAULT_BACK_COLOR].color; | 140 | return color_table[DEFAULT_BACK_COLOR].color; |
141 | } | 141 | } |
142 | 142 | ||
143 | const ColorEntry* TEWidget::getColorTable() const | 143 | const ColorEntry* TEWidget::getColorTable() const |
144 | { | 144 | { |
145 | return color_table; | 145 | return color_table; |
146 | } | 146 | } |
147 | 147 | ||
148 | const ColorEntry* TEWidget::getdefaultColorTable() const | 148 | const ColorEntry* TEWidget::getdefaultColorTable() const |
149 | { | 149 | { |
150 | return base_color_table; | 150 | return base_color_table; |
151 | } | 151 | } |
152 | 152 | ||
153 | 153 | ||
154 | const QPixmap *TEWidget::backgroundPixmap() | 154 | const QPixmap *TEWidget::backgroundPixmap() |
155 | { | 155 | { |
156 | static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm"); | 156 | static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm"); |
157 | const QPixmap *pm = bg; | 157 | const QPixmap *pm = bg; |
158 | return pm; | 158 | return pm; |
159 | } | 159 | } |
160 | 160 | ||
161 | void TEWidget::setColorTable(const ColorEntry table[]) | 161 | void TEWidget::setColorTable(const ColorEntry table[]) |
162 | { | 162 | { |
163 | for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i]; | 163 | for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i]; |
164 | 164 | ||
165 | const QPixmap* pm = backgroundPixmap(); | 165 | const QPixmap* pm = backgroundPixmap(); |
166 | if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color); | 166 | if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color); |
167 | update(); | 167 | update(); |
168 | } | 168 | } |
169 | 169 | ||
170 | //FIXME: add backgroundPixmapChanged. | 170 | //FIXME: add backgroundPixmapChanged. |
171 | 171 | ||
172 | /* ------------------------------------------------------------------------- */ | 172 | /* ------------------------------------------------------------------------- */ |
173 | /* */ | 173 | /* */ |
174 | /* Font */ | 174 | /* Font */ |
175 | /* */ | 175 | /* */ |
176 | /* ------------------------------------------------------------------------- */ | 176 | /* ------------------------------------------------------------------------- */ |
177 | 177 | ||
178 | /* | 178 | /* |
179 | The VT100 has 32 special graphical characters. The usual vt100 extended | 179 | The VT100 has 32 special graphical characters. The usual vt100 extended |
180 | xterm fonts have these at 0x00..0x1f. | 180 | xterm fonts have these at 0x00..0x1f. |
181 | 181 | ||
182 | QT's iso mapping leaves 0x00..0x7f without any changes. But the graphicals | 182 | QT's iso mapping leaves 0x00..0x7f without any changes. But the graphicals |
183 | come in here as proper unicode characters. | 183 | come in here as proper unicode characters. |
184 | 184 | ||
185 | We treat non-iso10646 fonts as VT100 extended and do the requiered mapping | 185 | We treat non-iso10646 fonts as VT100 extended and do the requiered mapping |
186 | from unicode to 0x00..0x1f. The remaining translation is then left to the | 186 | from unicode to 0x00..0x1f. The remaining translation is then left to the |
187 | QCodec. | 187 | QCodec. |
188 | */ | 188 | */ |
189 | 189 | ||
190 | // assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i. | 190 | // assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i. |
191 | 191 | ||
192 | unsigned short vt100_graphics[32] = | 192 | unsigned short vt100_graphics[32] = |
193 | { // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15 | 193 | { // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15 |
194 | 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, | 194 | 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, |
195 | 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, | 195 | 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, |
196 | 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534, | 196 | 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534, |
197 | 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7 | 197 | 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7 |
198 | }; | 198 | }; |
199 | 199 | ||
200 | static QChar vt100extended(QChar c) | 200 | static QChar vt100extended(QChar c) |
201 | { | 201 | { |
202 | switch (c.unicode()) | 202 | switch (c.unicode()) |
203 | { | 203 | { |
204 | case 0x25c6 : return 1; | 204 | case 0x25c6 : return 1; |
205 | case 0x2592 : return 2; | 205 | case 0x2592 : return 2; |
206 | case 0x2409 : return 3; | 206 | case 0x2409 : return 3; |
207 | case 0x240c : return 4; | 207 | case 0x240c : return 4; |
208 | case 0x240d : return 5; | 208 | case 0x240d : return 5; |
209 | case 0x240a : return 6; | 209 | case 0x240a : return 6; |
210 | case 0x00b0 : return 7; | 210 | case 0x00b0 : return 7; |
211 | case 0x00b1 : return 8; | 211 | case 0x00b1 : return 8; |
212 | case 0x2424 : return 9; | 212 | case 0x2424 : return 9; |
213 | case 0x240b : return 10; | 213 | case 0x240b : return 10; |
214 | case 0x2518 : return 11; | 214 | case 0x2518 : return 11; |
215 | case 0x2510 : return 12; | 215 | case 0x2510 : return 12; |
216 | case 0x250c : return 13; | 216 | case 0x250c : return 13; |
217 | case 0x2514 : return 14; | 217 | case 0x2514 : return 14; |
218 | case 0x253c : return 15; | 218 | case 0x253c : return 15; |
219 | case 0xf800 : return 16; | 219 | case 0xf800 : return 16; |
220 | case 0xf801 : return 17; | 220 | case 0xf801 : return 17; |
221 | case 0x2500 : return 18; | 221 | case 0x2500 : return 18; |
222 | case 0xf803 : return 19; | 222 | case 0xf803 : return 19; |
223 | case 0xf804 : return 20; | 223 | case 0xf804 : return 20; |
224 | case 0x251c : return 21; | 224 | case 0x251c : return 21; |
225 | case 0x2524 : return 22; | 225 | case 0x2524 : return 22; |
226 | case 0x2534 : return 23; | 226 | case 0x2534 : return 23; |
227 | case 0x252c : return 24; | 227 | case 0x252c : return 24; |
228 | case 0x2502 : return 25; | 228 | case 0x2502 : return 25; |
229 | case 0x2264 : return 26; | 229 | case 0x2264 : return 26; |
230 | case 0x2265 : return 27; | 230 | case 0x2265 : return 27; |
231 | case 0x03c0 : return 28; | 231 | case 0x03c0 : return 28; |
232 | case 0x2260 : return 29; | 232 | case 0x2260 : return 29; |
233 | case 0x00a3 : return 30; | 233 | case 0x00a3 : return 30; |
234 | case 0x00b7 : return 31; | 234 | case 0x00b7 : return 31; |
235 | } | 235 | } |
236 | return c; | 236 | return c; |
237 | } | 237 | } |
238 | 238 | ||
239 | static QChar identicalMap(QChar c) | 239 | static QChar identicalMap(QChar c) |
240 | { | 240 | { |
241 | return c; | 241 | return c; |
242 | } | 242 | } |
243 | 243 | ||
244 | void TEWidget::fontChange(const QFont &) | 244 | void TEWidget::fontChange(const QFont &) |
245 | { | 245 | { |
246 | QFontMetrics fm(font()); | 246 | QFontMetrics fm(font()); |
247 | font_h = fm.height(); | 247 | font_h = fm.height(); |
248 | // font_w = fm.maxWidth(); | 248 | // font_w = fm.maxWidth(); |
249 | font_w = fm.width("m"); | 249 | font_w = fm.width("m"); |
250 | font_a = fm.ascent(); | 250 | font_a = fm.ascent(); |
251 | printf("font h=%d max_width=%d width_m=%d assent=%d\n", font_h, | 251 | printf("font h=%d max_width=%d width_m=%d assent=%d\n", font_h, |
252 | fm.maxWidth(), font_w, font_a); | 252 | fm.maxWidth(), font_w, font_a); |
253 | 253 | ||
254 | //printf("font_h: %d\n",font_h); | 254 | //printf("font_h: %d\n",font_h); |
255 | //printf("font_w: %d\n",font_w); | 255 | //printf("font_w: %d\n",font_w); |
256 | //printf("font_a: %d\n",font_a); | 256 | //printf("font_a: %d\n",font_a); |
257 | //printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii()); | 257 | //printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii()); |
258 | //printf("rawname: %s\n",font().rawName().ascii()); | 258 | //printf("rawname: %s\n",font().rawName().ascii()); |
259 | fontMap = | 259 | fontMap = |
260 | #if QT_VERSION < 300 | 260 | #if QT_VERSION < 300 |
261 | strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646") | 261 | strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646") |
262 | ? vt100extended | 262 | ? vt100extended |
263 | : | 263 | : |
264 | #endif | 264 | #endif |
265 | identicalMap; | 265 | identicalMap; |
266 | propagateSize(); | 266 | propagateSize(); |
267 | update(); | 267 | update(); |
268 | } | 268 | } |
269 | 269 | ||
270 | void TEWidget::setVTFont(const QFont& f) | 270 | void TEWidget::setVTFont(const QFont& f) |
271 | { | 271 | { |
272 | QFrame::setFont(f); | 272 | QFrame::setFont(f); |
273 | } | 273 | } |
274 | 274 | ||
275 | QFont TEWidget::getVTFont() { | 275 | QFont TEWidget::getVTFont() { |
276 | return font(); | 276 | return font(); |
277 | } | 277 | } |
278 | 278 | ||
279 | void TEWidget::setFont(const QFont &) | 279 | void TEWidget::setFont(const QFont &) |
280 | { | 280 | { |
281 | // ignore font change request if not coming from konsole itself | 281 | // ignore font change request if not coming from konsole itself |
282 | } | 282 | } |
283 | 283 | ||
284 | /* ------------------------------------------------------------------------- */ | 284 | /* ------------------------------------------------------------------------- */ |
285 | /* */ | 285 | /* */ |
286 | /* Constructor / Destructor */ | 286 | /* Constructor / Destructor */ |
287 | /* */ | 287 | /* */ |
288 | /* ------------------------------------------------------------------------- */ | 288 | /* ------------------------------------------------------------------------- */ |
289 | 289 | ||
290 | TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name) | 290 | TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name) |
291 | { | 291 | { |
292 | #ifndef QT_NO_CLIPBOARD | 292 | #ifndef QT_NO_CLIPBOARD |
293 | cb = QApplication::clipboard(); | 293 | cb = QApplication::clipboard(); |
294 | QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), | 294 | QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), |
295 | this, SLOT(onClearSelection()) ); | 295 | this, SLOT(onClearSelection()) ); |
296 | #endif | 296 | #endif |
297 | 297 | ||
298 | scrollbar = new QScrollBar(this); | 298 | scrollbar = new QScrollBar(this); |
299 | scrollbar->setCursor( arrowCursor ); | 299 | scrollbar->setCursor( arrowCursor ); |
300 | connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); | 300 | connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); |
301 | 301 | ||
302 | hScrollbar = new QScrollBar(this); | 302 | hScrollbar = new QScrollBar(this); |
303 | hScrollbar->setCursor( arrowCursor ); | 303 | hScrollbar->setCursor( arrowCursor ); |
304 | hScrollbar->setOrientation(QScrollBar::Horizontal); | 304 | hScrollbar->setOrientation(QScrollBar::Horizontal); |
305 | // hScrollbar->setMaximumHeight(16); | 305 | // hScrollbar->setMaximumHeight(16); |
306 | 306 | ||
307 | connect( hScrollbar, SIGNAL(valueChanged(int)), this, SLOT( hScrollChanged(int))); | 307 | connect( hScrollbar, SIGNAL(valueChanged(int)), this, SLOT( hScrollChanged(int))); |
308 | 308 | ||
309 | Config cfg( "Konsole" ); | 309 | Config cfg( "Konsole" ); |
310 | cfg.setGroup("ScrollBar"); | 310 | cfg.setGroup("ScrollBar"); |
311 | switch( cfg.readNumEntry("Position",2)){ | 311 | switch( cfg.readNumEntry("Position",2)){ |
312 | case 0: | 312 | case 0: |
313 | scrollLoc = SCRNONE; | 313 | scrollLoc = SCRNONE; |
314 | break; | 314 | break; |
315 | case 1: | 315 | case 1: |
316 | scrollLoc = SCRLEFT; | 316 | scrollLoc = SCRLEFT; |
317 | break; | 317 | break; |
318 | case 2: | 318 | case 2: |
319 | scrollLoc = SCRRIGHT; | 319 | scrollLoc = SCRRIGHT; |
320 | break; | 320 | break; |
321 | }; | 321 | }; |
322 | 322 | ||
323 | useHorzScroll=cfg.readBoolEntry("HorzScroll",0); | 323 | useHorzScroll=cfg.readBoolEntry("HorzScroll",0); |
324 | 324 | ||
325 | blinkT = new QTimer(this); | 325 | blinkT = new QTimer(this); |
326 | connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent())); | 326 | connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent())); |
327 | // blinking = FALSE; | 327 | // blinking = FALSE; |
328 | blinking = TRUE; | 328 | blinking = TRUE; |
329 | 329 | ||
330 | resizing = FALSE; | 330 | resizing = FALSE; |
331 | actSel = 0; | 331 | actSel = 0; |
332 | image = 0; | 332 | image = 0; |
333 | lines = 1; | 333 | lines = 1; |
334 | columns = 1; | 334 | columns = 1; |
335 | font_w = 1; | 335 | font_w = 1; |
336 | font_h = 1; | 336 | font_h = 1; |
337 | font_a = 1; | 337 | font_a = 1; |
338 | word_selection_mode = FALSE; | 338 | word_selection_mode = FALSE; |
339 | hposition = 0; | 339 | hposition = 0; |
340 | vcolumns = 0; | 340 | vcolumns = 0; |
341 | useBeep = true; | 341 | useBeep = true; |
342 | 342 | ||
343 | setMouseMarks(TRUE); | 343 | setMouseMarks(TRUE); |
344 | setVTFont( QFont("fixed") ); | 344 | setVTFont( QFont("fixed") ); |
345 | setColorTable(base_color_table); // init color table | 345 | setColorTable(base_color_table); // init color table |
346 | 346 | ||
347 | qApp->installEventFilter( this ); //FIXME: see below | 347 | qApp->installEventFilter( this ); //FIXME: see below |
348 | // KCursor::setAutoHideCursor( this, true ); | 348 | // KCursor::setAutoHideCursor( this, true ); |
349 | 349 | ||
350 | // Init DnD //////////////////////////////////////////////////////////////// | 350 | // Init DnD //////////////////////////////////////////////////////////////// |
351 | currentSession = NULL; | 351 | currentSession = NULL; |
352 | // setAcceptDrops(true); // attempt | 352 | // setAcceptDrops(true); // attempt |
353 | // m_drop = new QPopupMenu(this); | 353 | // m_drop = new QPopupMenu(this); |
354 | // m_drop->insertItem( QString("Paste"), 0); | 354 | // m_drop->insertItem( QString("Paste"), 0); |
355 | // m_drop->insertItem( QString("cd"), 1); | 355 | // m_drop->insertItem( QString("cd"), 1); |
356 | // connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int))); | 356 | // connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int))); |
357 | 357 | ||
358 | // we need focus so that the auto-hide cursor feature works | 358 | // we need focus so that the auto-hide cursor feature works |
359 | setFocus(); | 359 | setFocus(); |
360 | setFocusPolicy( WheelFocus ); | 360 | setFocusPolicy( WheelFocus ); |
361 | } | 361 | } |
362 | 362 | ||
363 | //FIXME: make proper destructor | 363 | //FIXME: make proper destructor |
364 | // Here's a start (David) | 364 | // Here's a start (David) |
365 | TEWidget::~TEWidget() | 365 | TEWidget::~TEWidget() |
366 | { | 366 | { |
367 | qApp->removeEventFilter( this ); | 367 | qApp->removeEventFilter( this ); |
368 | if (image) free(image); | 368 | if (image) free(image); |
369 | } | 369 | } |
370 | 370 | ||
371 | /* ------------------------------------------------------------------------- */ | 371 | /* ------------------------------------------------------------------------- */ |
372 | /* */ | 372 | /* */ |
373 | /* Display Operations */ | 373 | /* Display Operations */ |
374 | /* */ | 374 | /* */ |
375 | /* ------------------------------------------------------------------------- */ | 375 | /* ------------------------------------------------------------------------- */ |
376 | 376 | ||
377 | /*! | 377 | /*! |
378 | attributed string draw primitive | 378 | attributed string draw primitive |
379 | */ | 379 | */ |
380 | 380 | ||
381 | void TEWidget::drawAttrStr(QPainter &paint, QRect rect, | 381 | void TEWidget::drawAttrStr(QPainter &paint, QRect rect, |
382 | QString& str, ca attr, BOOL pm, BOOL clear) | 382 | QString& str, ca attr, BOOL pm, BOOL clear) |
383 | { | 383 | { |
384 | if (pm && color_table[attr.b].transparent) | 384 | if (pm && color_table[attr.b].transparent) |
385 | { | 385 | { |
386 | paint.setBackgroundMode( TransparentMode ); | 386 | paint.setBackgroundMode( TransparentMode ); |
387 | if (clear) erase(rect); | 387 | if (clear) erase(rect); |
388 | } | 388 | } |
389 | else | 389 | else |
390 | { | 390 | { |
391 | if (blinking) | 391 | if (blinking) |
392 | paint.fillRect(rect, color_table[attr.b].color); | 392 | paint.fillRect(rect, color_table[attr.b].color); |
393 | else | 393 | else |
394 | { | 394 | { |
395 | paint.setBackgroundMode( OpaqueMode ); | 395 | paint.setBackgroundMode( OpaqueMode ); |
396 | paint.setBackgroundColor( color_table[attr.b].color ); | 396 | paint.setBackgroundColor( color_table[attr.b].color ); |
397 | } | 397 | } |
398 | } | 398 | } |
399 | 399 | ||
400 | if (color_table[attr.f].bold) | 400 | if (color_table[attr.f].bold) |
401 | paint.setPen(QColor( 0x8F, 0x00, 0x00 )); | 401 | paint.setPen(QColor( 0x8F, 0x00, 0x00 )); |
402 | else | 402 | else |
403 | paint.setPen(color_table[attr.f].color); | 403 | paint.setPen(color_table[attr.f].color); |
404 | 404 | ||
405 | paint.drawText(rect.x(),rect.y()+font_a, str); | 405 | paint.drawText(rect.x(),rect.y()+font_a, str); |
406 | 406 | ||
407 | if (attr.r & RE_UNDERLINE) | 407 | if (attr.r & RE_UNDERLINE) |
408 | paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 ); | 408 | paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 ); |
409 | } | 409 | } |
410 | 410 | ||
411 | /*! | 411 | /*! |
412 | The image can only be set completely. | 412 | The image can only be set completely. |
413 | 413 | ||
414 | The size of the new image may or may not match the size of the widget. | 414 | The size of the new image may or may not match the size of the widget. |
415 | */ | 415 | */ |
416 | 416 | ||
417 | void TEWidget::setImage(const ca* const newimg, int lines, int columns) | 417 | void TEWidget::setImage(const ca* const newimg, int lines, int columns) |
418 | { int y,x,len; | 418 | { int y,x,len; |
419 | const QPixmap* pm = backgroundPixmap(); | 419 | const QPixmap* pm = backgroundPixmap(); |
420 | QPainter paint; | 420 | QPainter paint; |
421 | setUpdatesEnabled(FALSE); | 421 | setUpdatesEnabled(FALSE); |
422 | paint.begin( this ); | 422 | paint.begin( this ); |
423 | HCNT("setImage"); | 423 | HCNT("setImage"); |
424 | 424 | ||
425 | QPoint tL = contentsRect().topLeft(); | 425 | QPoint tL = contentsRect().topLeft(); |
426 | int tLx = tL.x(); | 426 | int tLx = tL.x(); |
427 | int tLy = tL.y(); | 427 | int tLy = tL.y(); |
428 | hasBlinker = FALSE; | 428 | hasBlinker = FALSE; |
429 | 429 | ||
430 | int cf = -1; // undefined | 430 | int cf = -1; // undefined |
431 | int cb = -1; // undefined | 431 | int cb = -1; // undefined |
432 | int cr = -1; // undefined | 432 | int cr = -1; // undefined |
433 | 433 | ||
434 | int lins = QMIN(this->lines, QMAX(0,lines )); | 434 | int lins = QMIN(this->lines, QMAX(0,lines )); |
435 | int cols = QMIN(this->columns,QMAX(0,columns)); | 435 | int cols = QMIN(this->columns,QMAX(0,columns)); |
436 | QChar *disstrU = new QChar[cols]; | 436 | QChar *disstrU = new QChar[cols]; |
437 | for (y = 0; y < lins; y++) { | 437 | for (y = 0; y < lins; y++) { |
438 | const ca* lcl = &image[y*this->columns]; | 438 | const ca* lcl = &image[y*this->columns]; |
439 | const ca* const ext = &newimg[y*columns]; | 439 | const ca* const ext = &newimg[y*columns]; |
440 | if (!resizing) // not while resizing, we're expecting a paintEvent | 440 | if (!resizing) // not while resizing, we're expecting a paintEvent |
441 | for (x = 0; x < cols; x++) | 441 | for (x = 0; x < cols; x++) |
442 | { | 442 | { |
443 | hasBlinker |= (ext[x].r & RE_BLINK); | 443 | hasBlinker |= (ext[x].r & RE_BLINK); |
444 | if (ext[x] != lcl[x]) | 444 | if (ext[x] != lcl[x]) |
445 | { | 445 | { |
446 | cr = ext[x].r; | 446 | cr = ext[x].r; |
447 | cb = ext[x].b; | 447 | cb = ext[x].b; |
448 | if (ext[x].f != cf) cf = ext[x].f; | 448 | if (ext[x].f != cf) cf = ext[x].f; |
449 | int lln = cols - x; | 449 | int lln = cols - x; |
450 | disstrU[0] = fontMap(ext[x+0].c); | 450 | disstrU[0] = fontMap(ext[x+0].c); |
451 | for (len = 1; len < lln; len++) | 451 | for (len = 1; len < lln; len++) |
452 | { | 452 | { |
453 | if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr || | 453 | if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr || |
454 | ext[x+len] == lcl[x+len] ) | 454 | ext[x+len] == lcl[x+len] ) |
455 | break; | 455 | break; |
456 | disstrU[len] = fontMap(ext[x+len].c); | 456 | disstrU[len] = fontMap(ext[x+len].c); |
457 | } | 457 | } |
458 | QString unistr(disstrU,len); | 458 | QString unistr(disstrU,len); |
459 | drawAttrStr(paint, | 459 | drawAttrStr(paint, |
460 | QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), | 460 | QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), |
461 | unistr, ext[x], pm != NULL, true); | 461 | unistr, ext[x], pm != NULL, true); |
462 | x += len - 1; | 462 | x += len - 1; |
463 | } | 463 | } |
464 | } | 464 | } |
465 | // finally, make `image' become `newimg'. | 465 | // finally, make `image' become `newimg'. |
466 | memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca)); | 466 | memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca)); |
467 | } | 467 | } |
468 | drawFrame( &paint ); | 468 | drawFrame( &paint ); |
469 | paint.end(); | 469 | paint.end(); |
470 | setUpdatesEnabled(TRUE); | 470 | setUpdatesEnabled(TRUE); |
471 | if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms | 471 | if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms |
472 | if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; } | 472 | if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; } |
473 | delete [] disstrU; | 473 | delete [] disstrU; |
474 | } | 474 | } |
475 | 475 | ||
476 | // paint Event //////////////////////////////////////////////////// | 476 | // paint Event //////////////////////////////////////////////////// |
477 | 477 | ||
478 | /*! | 478 | /*! |
479 | The difference of this routine vs. the `setImage' is, | 479 | The difference of this routine vs. the `setImage' is, |
480 | that the drawing does not include a difference analysis | 480 | that the drawing does not include a difference analysis |
481 | between the old and the new image. Instead, the internal | 481 | between the old and the new image. Instead, the internal |
482 | image is used and the painting bound by the PaintEvent box. | 482 | image is used and the painting bound by the PaintEvent box. |
483 | */ | 483 | */ |
484 | 484 | ||
485 | void TEWidget::paintEvent( QPaintEvent* pe ) | 485 | void TEWidget::paintEvent( QPaintEvent* pe ) |
486 | { | 486 | { |
487 | 487 | ||
488 | //{ static int cnt = 0; printf("paint %d\n",cnt++); } | 488 | //{ static int cnt = 0; printf("paint %d\n",cnt++); } |
489 | const QPixmap* pm = backgroundPixmap(); | 489 | const QPixmap* pm = backgroundPixmap(); |
490 | QPainter paint; | 490 | QPainter paint; |
491 | setUpdatesEnabled(FALSE); | 491 | setUpdatesEnabled(FALSE); |
492 | paint.begin( this ); | 492 | paint.begin( this ); |
493 | paint.setBackgroundMode( TransparentMode ); | 493 | paint.setBackgroundMode( TransparentMode ); |
494 | HCNT("paintEvent"); | 494 | HCNT("paintEvent"); |
495 | 495 | ||
496 | // Note that the actual widget size can be slightly larger | 496 | // Note that the actual widget size can be slightly larger |
497 | // that the image (the size is truncated towards the smaller | 497 | // that the image (the size is truncated towards the smaller |
498 | // number of characters in `resizeEvent'. The paint rectangle | 498 | // number of characters in `resizeEvent'. The paint rectangle |
499 | // can thus be larger than the image, but less then the size | 499 | // can thus be larger than the image, but less then the size |
500 | // of one character. | 500 | // of one character. |
501 | 501 | ||
502 | QRect rect = pe->rect().intersect(contentsRect()); | 502 | QRect rect = pe->rect().intersect(contentsRect()); |
503 | 503 | ||
504 | QPoint tL = contentsRect().topLeft(); | 504 | QPoint tL = contentsRect().topLeft(); |
505 | int tLx = tL.x(); | 505 | int tLx = tL.x(); |
506 | int tLy = tL.y(); | 506 | int tLy = tL.y(); |
507 | 507 | ||
508 | int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w)); | 508 | int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w)); |
509 | int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h)); | 509 | int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h)); |
510 | int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w)); | 510 | int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w)); |
511 | int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h)); | 511 | int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h)); |
512 | 512 | ||
513 | /* | 513 | /* |
514 | printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly, | 514 | printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly, |
515 | rect.left(), rect.right(), rect.top(), rect.bottom()); | 515 | rect.left(), rect.right(), rect.top(), rect.bottom()); |
516 | */ | 516 | */ |
517 | 517 | ||
518 | // if (pm != NULL && color_table[image->b].transparent) | 518 | // if (pm != NULL && color_table[image->b].transparent) |
519 | // erase(rect); | 519 | // erase(rect); |
520 | // BL: I have no idea why we need this, and it breaks the refresh. | 520 | // BL: I have no idea why we need this, and it breaks the refresh. |
521 | 521 | ||
522 | QChar *disstrU = new QChar[columns]; | 522 | QChar *disstrU = new QChar[columns]; |
523 | for (int y = luy; y <= rly; y++) | 523 | for (int y = luy; y <= rly; y++) |
524 | for (int x = lux; x <= rlx; x++) | 524 | for (int x = lux; x <= rlx; x++) |
525 | { | 525 | { |
526 | int len = 1; | 526 | int len = 1; |
527 | disstrU[0] = fontMap(image[loc(x,y)].c); | 527 | disstrU[0] = fontMap(image[loc(x,y)].c); |
528 | int cf = image[loc(x,y)].f; | 528 | int cf = image[loc(x,y)].f; |
529 | int cb = image[loc(x,y)].b; | 529 | int cb = image[loc(x,y)].b; |
530 | int cr = image[loc(x,y)].r; | 530 | int cr = image[loc(x,y)].r; |
531 | while (x+len <= rlx && | 531 | while (x+len <= rlx && |
532 | image[loc(x+len,y)].f == cf && | 532 | image[loc(x+len,y)].f == cf && |
533 | image[loc(x+len,y)].b == cb && | 533 | image[loc(x+len,y)].b == cb && |
534 | image[loc(x+len,y)].r == cr ) | 534 | image[loc(x+len,y)].r == cr ) |
535 | { | 535 | { |
536 | disstrU[len] = fontMap(image[loc(x+len,y)].c); | 536 | disstrU[len] = fontMap(image[loc(x+len,y)].c); |
537 | len += 1; | 537 | len += 1; |
538 | } | 538 | } |
539 | QString unistr(disstrU,len); | 539 | QString unistr(disstrU,len); |
540 | drawAttrStr(paint, | 540 | drawAttrStr(paint, |
541 | QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), | 541 | QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), |
542 | unistr, image[loc(x,y)], pm != NULL, false); | 542 | unistr, image[loc(x,y)], pm != NULL, false); |
543 | x += len - 1; | 543 | x += len - 1; |
544 | } | 544 | } |
545 | delete [] disstrU; | 545 | delete [] disstrU; |
546 | drawFrame( &paint ); | 546 | drawFrame( &paint ); |
547 | paint.end(); | 547 | paint.end(); |
548 | setUpdatesEnabled(TRUE); | 548 | setUpdatesEnabled(TRUE); |
549 | } | 549 | } |
550 | 550 | ||
551 | void TEWidget::blinkEvent() | 551 | void TEWidget::blinkEvent() |
552 | { | 552 | { |
553 | blinking = !blinking; | 553 | blinking = !blinking; |
554 | repaint(FALSE); | 554 | repaint(FALSE); |
555 | } | 555 | } |
556 | 556 | ||
557 | /* ------------------------------------------------------------------------- */ | 557 | /* ------------------------------------------------------------------------- */ |
558 | /* */ | 558 | /* */ |
559 | /* Resizing */ | 559 | /* Resizing */ |
560 | /* */ | 560 | /* */ |
561 | /* ------------------------------------------------------------------------- */ | 561 | /* ------------------------------------------------------------------------- */ |
562 | 562 | ||
563 | void TEWidget::resizeEvent(QResizeEvent* ev) | 563 | void TEWidget::resizeEvent(QResizeEvent* ev) |
564 | { | 564 | { |
565 | // printf("resize: %d,%d\n",ev->size().width(),ev->size().height()); | 565 | // printf("resize: %d,%d\n",ev->size().width(),ev->size().height()); |
566 | //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h); | 566 | //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h); |
567 | //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h); | 567 | //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h); |
568 | //printf("curren: %d,%d\n",width(),height()); | 568 | //printf("curren: %d,%d\n",width(),height()); |
569 | HCNT("resizeEvent"); | 569 | HCNT("resizeEvent"); |
570 | 570 | ||
571 | // see comment in `paintEvent' concerning the rounding. | 571 | // see comment in `paintEvent' concerning the rounding. |
572 | //FIXME: could make a routine here; check width(),height() | 572 | //FIXME: could make a routine here; check width(),height() |
573 | assert(ev->size().width() == width()); | 573 | assert(ev->size().width() == width()); |
574 | assert(ev->size().height() == height()); | 574 | assert(ev->size().height() == height()); |
575 | 575 | ||
576 | propagateSize(); | 576 | propagateSize(); |
577 | } | 577 | } |
578 | 578 | ||
579 | void TEWidget::propagateSize() | 579 | void TEWidget::propagateSize() |
580 | { | 580 | { |
581 | ca* oldimg = image; | 581 | ca* oldimg = image; |
582 | int oldlin = lines; | 582 | int oldlin = lines; |
583 | int oldcol = columns; | 583 | int oldcol = columns; |
584 | makeImage(); | 584 | makeImage(); |
585 | // we copy the old image to reduce flicker | 585 | // we copy the old image to reduce flicker |
586 | int lins = QMIN(oldlin,lines); | 586 | int lins = QMIN(oldlin,lines); |
587 | int cols = QMIN(oldcol,columns); | 587 | int cols = QMIN(oldcol,columns); |
588 | if (oldimg) | 588 | if (oldimg) |
589 | { | 589 | { |
590 | for (int lin = 0; lin < lins; lin++) | 590 | for (int lin = 0; lin < lins; lin++) |
591 | memcpy((void*)&image[columns*lin], | 591 | memcpy((void*)&image[columns*lin], |
592 | (void*)&oldimg[oldcol*lin],cols*sizeof(ca)); | 592 | (void*)&oldimg[oldcol*lin],cols*sizeof(ca)); |
593 | free(oldimg); //FIXME: try new,delete | 593 | free(oldimg); //FIXME: try new,delete |
594 | } | 594 | } |
595 | else | 595 | else |
596 | clearImage(); | 596 | clearImage(); |
597 | 597 | ||
598 | //NOTE: control flows from the back through the chest right into the eye. | 598 | //NOTE: control flows from the back through the chest right into the eye. |
599 | // `emu' will call back via `setImage'. | 599 | // `emu' will call back via `setImage'. |
600 | 600 | ||
601 | resizing = TRUE; | 601 | resizing = TRUE; |
602 | emit changedImageSizeSignal(lines, columns); // expose resizeEvent | 602 | emit changedImageSizeSignal(lines, columns); // expose resizeEvent |
603 | resizing = FALSE; | 603 | resizing = FALSE; |
604 | } | 604 | } |
605 | 605 | ||
606 | /* ------------------------------------------------------------------------- */ | 606 | /* ------------------------------------------------------------------------- */ |
607 | /* */ | 607 | /* */ |
608 | /* Scrollbar */ | 608 | /* Scrollbar */ |
609 | /* */ | 609 | /* */ |
610 | /* ------------------------------------------------------------------------- */ | 610 | /* ------------------------------------------------------------------------- */ |
611 | 611 | ||
612 | void TEWidget::scrollChanged(int) { | 612 | void TEWidget::scrollChanged(int) { |
613 | emit changedHistoryCursor(scrollbar->value()); //expose | 613 | emit changedHistoryCursor(scrollbar->value()); //expose |
614 | } | 614 | } |
615 | 615 | ||
616 | void TEWidget::hScrollChanged(int loc) { | 616 | void TEWidget::hScrollChanged(int loc) { |
617 | hposition = loc; | 617 | hposition = loc; |
618 | propagateSize(); | 618 | propagateSize(); |
619 | update(); | 619 | update(); |
620 | 620 | ||
621 | // emit changedHorzCursor( hScrollbar->value()); //expose | 621 | // emit changedHorzCursor( hScrollbar->value()); //expose |
622 | } | 622 | } |
623 | 623 | ||
624 | void TEWidget::setScroll(int cursor, int slines) | 624 | void TEWidget::setScroll(int cursor, int slines) |
625 | { | 625 | { |
626 | disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); | 626 | disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); |
627 | scrollbar->setRange(0,slines); | 627 | scrollbar->setRange(0,slines); |
628 | scrollbar->setSteps(1,lines); | 628 | scrollbar->setSteps(1,lines); |
629 | scrollbar->setValue(cursor); | 629 | scrollbar->setValue(cursor); |
630 | connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); | 630 | connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); |
631 | } | 631 | } |
632 | 632 | ||
633 | void TEWidget::setScrollbarLocation(int loc) | 633 | void TEWidget::setScrollbarLocation(int loc) |
634 | { | 634 | { |
635 | if (scrollLoc == loc) return; // quickly | 635 | if (scrollLoc == loc) return; // quickly |
636 | scrollLoc = loc; | 636 | scrollLoc = loc; |
637 | propagateSize(); | 637 | propagateSize(); |
638 | update(); | 638 | update(); |
639 | } | 639 | } |
640 | 640 | ||
641 | /* ------------------------------------------------------------------------- */ | 641 | /* ------------------------------------------------------------------------- */ |
642 | /* */ | 642 | /* */ |
643 | /* Mouse */ | 643 | /* Mouse */ |
644 | /* */ | 644 | /* */ |
645 | /* ------------------------------------------------------------------------- */ | 645 | /* ------------------------------------------------------------------------- */ |
646 | 646 | ||
647 | /*! | 647 | /*! |
648 | Three different operations can be performed using the mouse, and the | 648 | Three different operations can be performed using the mouse, and the |
649 | routines in this section serve all of them: | 649 | routines in this section serve all of them: |
650 | 650 | ||
651 | 1) The press/release events are exposed to the application | 651 | 1) The press/release events are exposed to the application |
652 | 2) Marking (press and move left button) and Pasting (press middle button) | 652 | 2) Marking (press and move left button) and Pasting (press middle button) |
653 | 3) The right mouse button is used from the configuration menu | 653 | 3) The right mouse button is used from the configuration menu |
654 | 654 | ||
655 | NOTE: During the marking process we attempt to keep the cursor within | 655 | NOTE: During the marking process we attempt to keep the cursor within |
656 | the bounds of the text as being displayed by setting the mouse position | 656 | the bounds of the text as being displayed by setting the mouse position |
657 | whenever the mouse has left the text area. | 657 | whenever the mouse has left the text area. |
658 | 658 | ||
659 | Two reasons to do so: | 659 | Two reasons to do so: |
660 | 1) QT does not allow the `grabMouse' to confine-to the TEWidget. | 660 | 1) QT does not allow the `grabMouse' to confine-to the TEWidget. |
661 | Thus a `XGrapPointer' would have to be used instead. | 661 | Thus a `XGrapPointer' would have to be used instead. |
662 | 2) Even if so, this would not help too much, since the text area | 662 | 2) Even if so, this would not help too much, since the text area |
663 | of the TEWidget is normally not identical with it's bounds. | 663 | of the TEWidget is normally not identical with it's bounds. |
664 | 664 | ||
665 | The disadvantage of the current handling is, that the mouse can visibly | 665 | The disadvantage of the current handling is, that the mouse can visibly |
666 | leave the bounds of the widget and is then moved back. Because of the | 666 | leave the bounds of the widget and is then moved back. Because of the |
667 | current construction, and the reasons mentioned above, we cannot do better | 667 | current construction, and the reasons mentioned above, we cannot do better |
668 | without changing the overall construction. | 668 | without changing the overall construction. |
669 | */ | 669 | */ |
670 | 670 | ||
671 | /*! | 671 | /*! |
672 | */ | 672 | */ |
673 | 673 | ||
674 | void TEWidget::mousePressEvent(QMouseEvent* ev) | 674 | void TEWidget::mousePressEvent(QMouseEvent* ev) |
675 | { | 675 | { |
676 | //printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); | 676 | //printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); |
677 | if ( !contentsRect().contains(ev->pos()) ) return; | 677 | if ( !contentsRect().contains(ev->pos()) ) return; |
678 | QPoint tL = contentsRect().topLeft(); | 678 | QPoint tL = contentsRect().topLeft(); |
679 | int tLx = tL.x(); | 679 | int tLx = tL.x(); |
680 | int tLy = tL.y(); | 680 | int tLy = tL.y(); |
681 | 681 | ||
682 | mouse_down_x = ev->x(); | 682 | mouse_down_x = ev->x(); |
683 | mouse_down_y = ev->y(); | 683 | mouse_down_y = ev->y(); |
684 | 684 | ||
685 | //printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY); | 685 | //printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY); |
686 | if ( ev->button() == LeftButton) | 686 | if ( ev->button() == LeftButton) |
687 | { | 687 | { |
688 | QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); | 688 | QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); |
689 | 689 | ||
690 | word_selection_mode = (ev->state() & ShiftButton); | 690 | word_selection_mode = (ev->state() & ShiftButton); |
691 | 691 | ||
692 | if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; | 692 | if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; |
693 | 693 | ||
694 | if (mouse_marks || (ev->state() & ShiftButton)) | 694 | if (mouse_marks || (ev->state() & ShiftButton)) |
695 | { | 695 | { |
696 | emit clearSelectionSignal(); | 696 | emit clearSelectionSignal(); |
697 | iPntSel = pntSel = pos; | 697 | iPntSel = pntSel = pos; |
698 | actSel = 1; // left mouse button pressed but nothing selected yet. | 698 | actSel = 1; // left mouse button pressed but nothing selected yet. |
699 | grabMouse( /*crossCursor*/ ); // handle with care! | 699 | grabMouse( /*crossCursor*/ ); // handle with care! |
700 | } | 700 | } |
701 | else | 701 | else |
702 | { | 702 | { |
703 | emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button | 703 | emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button |
704 | } | 704 | } |
705 | } | 705 | } |
706 | if ( ev->button() == MidButton ) | 706 | if ( ev->button() == MidButton ) |
707 | { | 707 | { |
708 | emitSelection(); | 708 | emitSelection(); |
709 | } | 709 | } |
710 | if ( ev->button() == RightButton ) // Configure | 710 | if ( ev->button() == RightButton ) // Configure |
711 | { | 711 | { |
712 | emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() ); | 712 | emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() ); |
713 | } | 713 | } |
714 | } | 714 | } |
715 | 715 | ||
716 | void TEWidget::mouseMoveEvent(QMouseEvent* ev) | 716 | void TEWidget::mouseMoveEvent(QMouseEvent* ev) |
717 | { | 717 | { |
718 | // for auto-hiding the cursor, we need mouseTracking | 718 | // for auto-hiding the cursor, we need mouseTracking |
719 | if (ev->state() == NoButton ) return; | 719 | if (ev->state() == NoButton ) return; |
720 | 720 | ||
721 | if (actSel == 0) return; | 721 | if (actSel == 0) return; |
722 | 722 | ||
723 | // don't extend selection while pasting | 723 | // don't extend selection while pasting |
724 | if (ev->state() & MidButton) return; | 724 | if (ev->state() & MidButton) return; |
725 | 725 | ||
726 | //if ( !contentsRect().contains(ev->pos()) ) return; | 726 | //if ( !contentsRect().contains(ev->pos()) ) return; |
727 | QPoint tL = contentsRect().topLeft(); | 727 | QPoint tL = contentsRect().topLeft(); |
728 | int tLx = tL.x(); | 728 | int tLx = tL.x(); |
729 | int tLy = tL.y(); | 729 | int tLy = tL.y(); |
730 | int scroll = scrollbar->value(); | 730 | int scroll = scrollbar->value(); |
731 | // int hScroll = hScrollbar->value(); | 731 | // int hScroll = hScrollbar->value(); |
732 | 732 | ||
733 | // we're in the process of moving the mouse with the left button pressed | 733 | // we're in the process of moving the mouse with the left button pressed |
734 | // the mouse cursor will kept catched within the bounds of the text in | 734 | // the mouse cursor will kept catched within the bounds of the text in |
735 | // this widget. | 735 | // this widget. |
736 | 736 | ||
737 | // Adjust position within text area bounds. See FIXME above. | 737 | // Adjust position within text area bounds. See FIXME above. |
738 | QPoint pos = ev->pos(); | 738 | QPoint pos = ev->pos(); |
739 | if ( pos.x() < tLx+blX ) pos.setX( tLx+blX ); | 739 | if ( pos.x() < tLx+blX ) pos.setX( tLx+blX ); |
740 | if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w ); | 740 | if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w ); |
741 | if ( pos.y() < tLy+bY ) pos.setY( tLy+bY ); | 741 | if ( pos.y() < tLy+bY ) pos.setY( tLy+bY ); |
742 | if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 ); | 742 | if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 ); |
743 | // check if we produce a mouse move event by this | 743 | // check if we produce a mouse move event by this |
744 | if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos)); | 744 | if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos)); |
745 | 745 | ||
746 | if ( pos.y() == tLy+bY+lines*font_h-1 ) | 746 | if ( pos.y() == tLy+bY+lines*font_h-1 ) |
747 | { | 747 | { |
748 | scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward | 748 | scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward |
749 | } | 749 | } |
750 | if ( pos.y() == tLy+bY ) | 750 | if ( pos.y() == tLy+bY ) |
751 | { | 751 | { |
752 | scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback | 752 | scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback |
753 | } | 753 | } |
754 | 754 | ||
755 | QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h); | 755 | QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h); |
756 | QPoint ohere; | 756 | QPoint ohere; |
757 | bool swapping = FALSE; | 757 | bool swapping = FALSE; |
758 | 758 | ||
759 | if ( word_selection_mode ) | 759 | if ( word_selection_mode ) |
760 | { | 760 | { |
761 | // Extend to word boundaries | 761 | // Extend to word boundaries |
762 | int i; | 762 | int i; |
763 | int selClass; | 763 | int selClass; |
764 | 764 | ||
765 | bool left_not_right = ( here.y() < iPntSel.y() || | 765 | bool left_not_right = ( here.y() < iPntSel.y() || |
766 | here.y() == iPntSel.y() && here.x() < iPntSel.x() ); | 766 | here.y() == iPntSel.y() && here.x() < iPntSel.x() ); |
767 | bool old_left_not_right = ( pntSel.y() < iPntSel.y() || | 767 | bool old_left_not_right = ( pntSel.y() < iPntSel.y() || |
768 | pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); | 768 | pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); |
769 | swapping = left_not_right != old_left_not_right; | 769 | swapping = left_not_right != old_left_not_right; |
770 | 770 | ||
771 | // Find left (left_not_right ? from here : from start) | 771 | // Find left (left_not_right ? from here : from start) |
772 | QPoint left = left_not_right ? here : iPntSel; | 772 | QPoint left = left_not_right ? here : iPntSel; |
773 | i = loc(left.x(),left.y()); | 773 | i = loc(left.x(),left.y()); |
774 | selClass = charClass(image[i].c); | 774 | selClass = charClass(image[i].c); |
775 | while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) | 775 | while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) |
776 | { i--; left.rx()--; } | 776 | { i--; left.rx()--; } |
777 | 777 | ||
778 | // Find left (left_not_right ? from start : from here) | 778 | // Find left (left_not_right ? from start : from here) |
779 | QPoint right = left_not_right ? iPntSel : here; | 779 | QPoint right = left_not_right ? iPntSel : here; |
780 | i = loc(right.x(),right.y()); | 780 | i = loc(right.x(),right.y()); |
781 | selClass = charClass(image[i].c); | 781 | selClass = charClass(image[i].c); |
782 | while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass ) | 782 | while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass ) |
783 | { i++; right.rx()++; } | 783 | { i++; right.rx()++; } |
784 | 784 | ||
785 | // Pick which is start (ohere) and which is extension (here) | 785 | // Pick which is start (ohere) and which is extension (here) |
786 | if ( left_not_right ) | 786 | if ( left_not_right ) |
787 | { | 787 | { |
788 | here = left; ohere = right; | 788 | here = left; ohere = right; |
789 | } | 789 | } |
790 | else | 790 | else |
791 | { | 791 | { |
792 | here = right; ohere = left; | 792 | here = right; ohere = left; |
793 | } | 793 | } |
794 | } | 794 | } |
795 | 795 | ||
796 | if (here == pntSel && scroll == scrollbar->value()) return; // not moved | 796 | if (here == pntSel && scroll == scrollbar->value()) return; // not moved |
797 | 797 | ||
798 | if ( word_selection_mode ) { | 798 | if ( word_selection_mode ) { |
799 | if ( actSel < 2 || swapping ) { | 799 | if ( actSel < 2 || swapping ) { |
800 | emit beginSelectionSignal( ohere.x(), ohere.y() ); | 800 | emit beginSelectionSignal( ohere.x(), ohere.y() ); |
801 | } | 801 | } |
802 | } else if ( actSel < 2 ) { | 802 | } else if ( actSel < 2 ) { |
803 | emit beginSelectionSignal( pntSel.x(), pntSel.y() ); | 803 | emit beginSelectionSignal( pntSel.x(), pntSel.y() ); |
804 | } | 804 | } |
805 | 805 | ||
806 | actSel = 2; // within selection | 806 | actSel = 2; // within selection |
807 | pntSel = here; | 807 | pntSel = here; |
808 | emit extendSelectionSignal( here.x(), here.y() ); | 808 | emit extendSelectionSignal( here.x(), here.y() ); |
809 | } | 809 | } |
810 | 810 | ||
811 | void TEWidget::mouseReleaseEvent(QMouseEvent* ev) | 811 | void TEWidget::mouseReleaseEvent(QMouseEvent* ev) |
812 | { | 812 | { |
813 | //printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); | 813 | //printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); |
814 | if ( ev->button() == LeftButton) | 814 | if ( ev->button() == LeftButton) |
815 | { | 815 | { |
816 | if (QABS(ev->x() - mouse_down_x) < 3 | 816 | if (QABS(ev->x() - mouse_down_x) < 3 |
817 | && QABS(ev->y() - mouse_down_y) < 3 | 817 | && QABS(ev->y() - mouse_down_y) < 3 |
818 | && ev->y() < qApp->desktop()->height()/8) { | 818 | && ev->y() < qApp->desktop()->height()/8) { |
819 | emit setFullScreen(false); | 819 | emit setFullScreen(false); |
820 | } | 820 | } |
821 | 821 | ||
822 | if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); | 822 | if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); |
823 | preserve_line_breaks = TRUE; | 823 | preserve_line_breaks = TRUE; |
824 | actSel = 0; | 824 | actSel = 0; |
825 | 825 | ||
826 | //FIXME: emits a release event even if the mouse is | 826 | //FIXME: emits a release event even if the mouse is |
827 | // outside the range. The procedure used in `mouseMoveEvent' | 827 | // outside the range. The procedure used in `mouseMoveEvent' |
828 | // applies here, too. | 828 | // applies here, too. |
829 | 829 | ||
830 | QPoint tL = contentsRect().topLeft(); | 830 | QPoint tL = contentsRect().topLeft(); |
831 | int tLx = tL.x(); | 831 | int tLx = tL.x(); |
832 | int tLy = tL.y(); | 832 | int tLy = tL.y(); |
833 | 833 | ||
834 | if (!mouse_marks && !(ev->state() & ShiftButton)) | 834 | if (!mouse_marks && !(ev->state() & ShiftButton)) |
835 | emit mouseSignal( 3, // release | 835 | emit mouseSignal( 3, // release |
836 | (ev->x()-tLx-blX)/font_w + 1, | 836 | (ev->x()-tLx-blX)/font_w + 1, |
837 | (ev->y()-tLy-bY)/font_h + 1 ); | 837 | (ev->y()-tLy-bY)/font_h + 1 ); |
838 | releaseMouse(); | 838 | releaseMouse(); |
839 | } | 839 | } |
840 | } | 840 | } |
841 | 841 | ||
842 | void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev) | 842 | void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev) |
843 | { | 843 | { |
844 | if ( ev->button() != LeftButton) return; | 844 | if ( ev->button() != LeftButton) return; |
845 | 845 | ||
846 | QPoint tL = contentsRect().topLeft(); | 846 | QPoint tL = contentsRect().topLeft(); |
847 | int tLx = tL.x(); | 847 | int tLx = tL.x(); |
848 | int tLy = tL.y(); | 848 | int tLy = tL.y(); |
849 | QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); | 849 | QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); |
850 | 850 | ||
851 | // pass on double click as two clicks. | 851 | // pass on double click as two clicks. |
852 | if (!mouse_marks && !(ev->state() & ShiftButton)) | 852 | if (!mouse_marks && !(ev->state() & ShiftButton)) |
853 | { | 853 | { |
854 | emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button | 854 | emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button |
855 | emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release | 855 | emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release |
856 | emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button | 856 | emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button |
857 | return; | 857 | return; |
858 | } | 858 | } |
859 | 859 | ||
860 | 860 | ||
861 | emit clearSelectionSignal(); | 861 | emit clearSelectionSignal(); |
862 | QPoint bgnSel = pos; | 862 | QPoint bgnSel = pos; |
863 | QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); | 863 | QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); |
864 | int i = loc(bgnSel.x(),bgnSel.y()); | 864 | int i = loc(bgnSel.x(),bgnSel.y()); |
865 | iPntSel = bgnSel; | 865 | iPntSel = bgnSel; |
866 | 866 | ||
867 | word_selection_mode = TRUE; | 867 | word_selection_mode = TRUE; |
868 | 868 | ||
869 | // find word boundaries... | 869 | // find word boundaries... |
870 | int selClass = charClass(image[i].c); | 870 | int selClass = charClass(image[i].c); |
871 | { | 871 | { |
872 | // set the start... | 872 | // set the start... |
873 | int x = bgnSel.x(); | 873 | int x = bgnSel.x(); |
874 | while ( x > 0 && charClass(image[i-1].c) == selClass ) | 874 | while ( x > 0 && charClass(image[i-1].c) == selClass ) |
875 | { i--; x--; } | 875 | { i--; x--; } |
876 | bgnSel.setX(x); | 876 | bgnSel.setX(x); |
877 | emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); | 877 | emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); |
878 | 878 | ||
879 | // set the end... | 879 | // set the end... |
880 | i = loc( endSel.x(), endSel.y() ); | 880 | i = loc( endSel.x(), endSel.y() ); |
881 | x = endSel.x(); | 881 | x = endSel.x(); |
882 | while( x < columns-1 && charClass(image[i+1].c) == selClass ) | 882 | while( x < columns-1 && charClass(image[i+1].c) == selClass ) |
883 | { i++; x++ ; } | 883 | { i++; x++ ; } |
884 | endSel.setX(x); | 884 | endSel.setX(x); |
885 | actSel = 2; // within selection | 885 | actSel = 2; // within selection |
886 | emit extendSelectionSignal( endSel.x(), endSel.y() ); | 886 | emit extendSelectionSignal( endSel.x(), endSel.y() ); |
887 | emit endSelectionSignal(preserve_line_breaks); | 887 | emit endSelectionSignal(preserve_line_breaks); |
888 | preserve_line_breaks = TRUE; | 888 | preserve_line_breaks = TRUE; |
889 | } | 889 | } |
890 | } | 890 | } |
891 | 891 | ||
892 | void TEWidget::focusInEvent( QFocusEvent * ) | 892 | void TEWidget::focusInEvent( QFocusEvent * ) |
893 | { | 893 | { |
894 | 894 | ||
895 | // do nothing, to prevent repainting | 895 | // do nothing, to prevent repainting |
896 | } | 896 | } |
897 | 897 | ||
898 | 898 | ||
899 | void TEWidget::focusOutEvent( QFocusEvent * ) | 899 | void TEWidget::focusOutEvent( QFocusEvent * ) |
900 | { | 900 | { |
901 | // do nothing, to prevent repainting | 901 | // do nothing, to prevent repainting |
902 | } | 902 | } |
903 | 903 | ||
904 | bool TEWidget::focusNextPrevChild( bool next ) | 904 | bool TEWidget::focusNextPrevChild( bool next ) |
905 | { | 905 | { |
906 | if (next) | 906 | if (next) |
907 | return false; // This disables changing the active part in konqueror | 907 | return false; // This disables changing the active part in konqueror |
908 | // when pressing Tab | 908 | // when pressing Tab |
909 | return QFrame::focusNextPrevChild( next ); | 909 | return QFrame::focusNextPrevChild( next ); |
910 | } | 910 | } |
911 | 911 | ||
912 | 912 | ||
913 | int TEWidget::charClass(char ch) const | 913 | int TEWidget::charClass(char ch) const |
914 | { | 914 | { |
915 | // This might seem like overkill, but imagine if ch was a Unicode | 915 | // This might seem like overkill, but imagine if ch was a Unicode |
916 | // character (Qt 2.0 QChar) - it might then be sensible to separate | 916 | // character (Qt 2.0 QChar) - it might then be sensible to separate |
917 | // the different language ranges, etc. | 917 | // the different language ranges, etc. |
918 | 918 | ||
919 | if ( isspace(ch) ) return ' '; | 919 | if ( isspace(ch) ) return ' '; |
920 | 920 | ||
921 | static const char *word_characters = ":@-./_~"; | 921 | static const char *word_characters = ":@-./_~"; |
922 | if ( isalnum(ch) || strchr(word_characters, ch) ) | 922 | if ( isalnum(ch) || strchr(word_characters, ch) ) |
923 | return 'a'; | 923 | return 'a'; |
924 | 924 | ||
925 | // Everything else is weird | 925 | // Everything else is weird |
926 | return 1; | 926 | return 1; |
927 | } | 927 | } |
928 | 928 | ||
929 | void TEWidget::setMouseMarks(bool on) | 929 | void TEWidget::setMouseMarks(bool on) |
930 | { | 930 | { |
931 | mouse_marks = on; | 931 | mouse_marks = on; |
932 | setCursor( mouse_marks ? ibeamCursor : arrowCursor ); | 932 | setCursor( mouse_marks ? ibeamCursor : arrowCursor ); |
933 | } | 933 | } |
934 | 934 | ||
935 | /* ------------------------------------------------------------------------- */ | 935 | /* ------------------------------------------------------------------------- */ |
936 | /* */ | 936 | /* */ |
937 | /* Clipboard */ | 937 | /* Clipboard */ |
938 | /* */ | 938 | /* */ |
939 | /* ------------------------------------------------------------------------- */ | 939 | /* ------------------------------------------------------------------------- */ |
940 | 940 | ||
941 | #undef KeyPress | 941 | #undef KeyPress |
942 | 942 | ||
943 | void TEWidget::emitSelection() | 943 | void TEWidget::emitSelection() |
944 | // Paste Clipboard by simulating keypress events | 944 | // Paste Clipboard by simulating keypress events |
945 | { | 945 | { |
946 | #ifndef QT_NO_CLIPBOARD | 946 | #ifndef QT_NO_CLIPBOARD |
947 | QString text = QApplication::clipboard()->text(); | 947 | QString text = QApplication::clipboard()->text(); |
948 | //qDebug(text); | 948 | //qDebug(text); |
949 | if ( ! text.isNull()) | 949 | if ( ! text.isNull()) |
950 | { | 950 | { |
951 | text.replace(QRegExp("\n"), "\r"); | 951 | text.replace(QRegExp("\n"), "\r"); |
952 | QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); | 952 | QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); |
953 | emit keyPressedSignal(&e); // expose as a big fat keypress event | 953 | emit keyPressedSignal(&e); // expose as a big fat keypress event |
954 | emit clearSelectionSignal(); | 954 | emit clearSelectionSignal(); |
955 | } | 955 | } |
956 | #endif | 956 | #endif |
957 | } | 957 | } |
958 | 958 | ||
959 | void TEWidget::emitText(QString text) | 959 | void TEWidget::emitText(QString text) |
960 | { | 960 | { |
961 | QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); | 961 | QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); |
962 | emit keyPressedSignal(&e); // expose as a big fat keypress event | 962 | emit keyPressedSignal(&e); // expose as a big fat keypress event |
963 | } | 963 | } |
964 | 964 | ||
965 | void TEWidget::pasteClipboard( ) | 965 | void TEWidget::pasteClipboard( ) |
966 | { | 966 | { |
967 | emitSelection(); | 967 | emitSelection(); |
968 | } | 968 | } |
969 | 969 | ||
970 | void TEWidget::setSelection(const QString& t) | 970 | void TEWidget::setSelection(const QString& t) |
971 | { | 971 | { |
972 | #ifndef QT_NO_CLIPBOARD | 972 | #ifndef QT_NO_CLIPBOARD |
973 | // Disconnect signal while WE set the clipboard | 973 | // Disconnect signal while WE set the clipboard |
974 | QObject *cb = QApplication::clipboard(); | 974 | QObject *cb = QApplication::clipboard(); |
975 | QObject::disconnect( cb, SIGNAL(dataChanged()), | 975 | QObject::disconnect( cb, SIGNAL(dataChanged()), |
976 | this, SLOT(onClearSelection()) ); | 976 | this, SLOT(onClearSelection()) ); |
977 | 977 | ||
978 | QApplication::clipboard()->setText(t); | 978 | QApplication::clipboard()->setText(t); |
979 | 979 | ||
980 | QObject::connect( cb, SIGNAL(dataChanged()), | 980 | QObject::connect( cb, SIGNAL(dataChanged()), |
981 | this, SLOT(onClearSelection()) ); | 981 | this, SLOT(onClearSelection()) ); |
982 | #endif | 982 | #endif |
983 | } | 983 | } |
984 | 984 | ||
985 | void TEWidget::onClearSelection() | 985 | void TEWidget::onClearSelection() |
986 | { | 986 | { |
987 | emit clearSelectionSignal(); | 987 | emit clearSelectionSignal(); |
988 | } | 988 | } |
989 | 989 | ||
990 | /* ------------------------------------------------------------------------- */ | 990 | /* ------------------------------------------------------------------------- */ |
991 | /* */ | 991 | /* */ |
992 | /* Keyboard */ | 992 | /* Keyboard */ |
993 | /* */ | 993 | /* */ |
994 | /* ------------------------------------------------------------------------- */ | 994 | /* ------------------------------------------------------------------------- */ |
995 | 995 | ||
996 | //FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' | 996 | //FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' |
997 | // due to a bug in `QT' or the ignorance of the author to prevent | 997 | // due to a bug in `QT' or the ignorance of the author to prevent |
998 | // repaint events being emitted to the screen whenever one leaves | 998 | // repaint events being emitted to the screen whenever one leaves |
999 | // or reenters the screen to/from another application. | 999 | // or reenters the screen to/from another application. |
1000 | // | 1000 | // |
1001 | // Troll says one needs to change focusInEvent() and focusOutEvent(), | 1001 | // Troll says one needs to change focusInEvent() and focusOutEvent(), |
1002 | // which would also let you have an in-focus cursor and an out-focus | 1002 | // which would also let you have an in-focus cursor and an out-focus |
1003 | // cursor like xterm does. | 1003 | // cursor like xterm does. |
1004 | 1004 | ||
1005 | // for the auto-hide cursor feature, I added empty focusInEvent() and | 1005 | // for the auto-hide cursor feature, I added empty focusInEvent() and |
1006 | // focusOutEvent() so that update() isn't called. | 1006 | // focusOutEvent() so that update() isn't called. |
1007 | // For auto-hide, we need to get keypress-events, but we only get them when | 1007 | // For auto-hide, we need to get keypress-events, but we only get them when |
1008 | // we have focus. | 1008 | // we have focus. |
1009 | 1009 | ||
1010 | void TEWidget::doScroll(int lines) | 1010 | void TEWidget::doScroll(int lines) |
1011 | { | 1011 | { |
1012 | scrollbar->setValue(scrollbar->value()+lines); | 1012 | scrollbar->setValue(scrollbar->value()+lines); |
1013 | } | 1013 | } |
1014 | 1014 | ||
1015 | void TEWidget::doHScroll(int lines) { | 1015 | void TEWidget::doHScroll(int lines) { |
1016 | hScrollbar->setValue( hScrollbar->value()+lines); | 1016 | hScrollbar->setValue( hScrollbar->value()+lines); |
1017 | } | 1017 | } |
1018 | 1018 | ||
1019 | bool TEWidget::eventFilter( QObject *obj, QEvent *e ) | 1019 | bool TEWidget::eventFilter( QObject *obj, QEvent *e ) |
1020 | { | 1020 | { |
1021 | if ( (e->type() == QEvent::Accel || | 1021 | if ( (e->type() == QEvent::Accel || |
1022 | e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { | 1022 | e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { |
1023 | static_cast<QKeyEvent *>( e )->ignore(); | 1023 | static_cast<QKeyEvent *>( e )->ignore(); |
1024 | return true; | 1024 | return true; |
1025 | } | 1025 | } |
1026 | if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) | 1026 | if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) |
1027 | return FALSE; // not us | 1027 | return FALSE; // not us |
1028 | if ( e->type() == QEvent::Wheel) { | 1028 | if ( e->type() == QEvent::Wheel) { |
1029 | QApplication::sendEvent(scrollbar, e); | 1029 | QApplication::sendEvent(scrollbar, e); |
1030 | } | 1030 | } |
1031 | 1031 | ||
1032 | #ifdef FAKE_CTRL_AND_ALT | 1032 | #ifdef FAKE_CTRL_AND_ALT |
1033 | static bool control = FALSE; | 1033 | static bool control = FALSE; |
1034 | static bool alt = FALSE; | 1034 | static bool alt = FALSE; |
1035 | // qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:"); | 1035 | // qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:"); |
1036 | bool dele=FALSE; | 1036 | bool dele=FALSE; |
1037 | if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { | 1037 | if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { |
1038 | QKeyEvent* ke = (QKeyEvent*)e; | 1038 | QKeyEvent* ke = (QKeyEvent*)e; |
1039 | bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); | 1039 | bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); |
1040 | switch (ke->key()) { | 1040 | switch (ke->key()) { |
1041 | case Key_F9: // let this be "Control" | 1041 | case Key_F9: // let this be "Control" |
1042 | control = keydown; | 1042 | control = keydown; |
1043 | e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); | 1043 | e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); |
1044 | dele=TRUE; | 1044 | dele=TRUE; |
1045 | break; | 1045 | break; |
1046 | case Key_F13: // let this be "Alt" | 1046 | case Key_F13: // let this be "Alt" |
1047 | alt = keydown; | 1047 | alt = keydown; |
1048 | e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); | 1048 | e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); |
1049 | dele=TRUE; | 1049 | dele=TRUE; |
1050 | break; | 1050 | break; |
1051 | default: | 1051 | default: |
1052 | if ( control ) { | 1052 | if ( control ) { |
1053 | int a = toupper(ke->ascii())-64; | 1053 | int a = toupper(ke->ascii())-64; |
1054 | if ( a >= 0 && a < ' ' ) { | 1054 | if ( a >= 0 && a < ' ' ) { |
1055 | e = new QKeyEvent(e->type(), ke->key(), | 1055 | e = new QKeyEvent(e->type(), ke->key(), |
1056 | a, ke->state()|ControlButton, QChar(a,0)); | 1056 | a, ke->state()|ControlButton, QChar(a,0)); |
1057 | dele=TRUE; | 1057 | dele=TRUE; |
1058 | } | 1058 | } |
1059 | } | 1059 | } |
1060 | if ( alt ) { | 1060 | if ( alt ) { |
1061 | e = new QKeyEvent(e->type(), ke->key(), | 1061 | e = new QKeyEvent(e->type(), ke->key(), |
1062 | ke->ascii(), ke->state()|AltButton, ke->text()); | 1062 | ke->ascii(), ke->state()|AltButton, ke->text()); |
1063 | dele=TRUE; | 1063 | dele=TRUE; |
1064 | } | 1064 | } |
1065 | } | 1065 | } |
1066 | } | 1066 | } |
1067 | #endif | 1067 | #endif |
1068 | 1068 | ||
1069 | if ( e->type() == QEvent::KeyPress ) { | 1069 | if ( e->type() == QEvent::KeyPress ) { |
1070 | QKeyEvent* ke = (QKeyEvent*)e; | 1070 | QKeyEvent* ke = (QKeyEvent*)e; |
1071 | actSel=0; // Key stroke implies a screen update, so TEWidget won't | 1071 | actSel=0; // Key stroke implies a screen update, so TEWidget won't |
1072 | // know where the current selection is. | 1072 | // know where the current selection is. |
1073 | 1073 | ||
1074 | // qDebug("key pressed is 0x%x, ascii is 0x%x, state %d", ke->key(), ke->ascii(), ke->state()); | 1074 | // qDebug("key pressed is 0x%x, ascii is 0x%x, state %d", ke->key(), ke->ascii(), ke->state()); |
1075 | 1075 | ||
1076 | bool special_function = true; | 1076 | bool special_function = true; |
1077 | switch(ke->key()) { | 1077 | switch(ke->key()) { |
1078 | //case 0x201b: // fn-5 | 1078 | //case 0x201b: // fn-5 |
1079 | //case Key_F1: | 1079 | //case Key_F1: |
1080 | // switch sessions (?) | 1080 | // switch sessions (?) |
1081 | // emitText("\\"); // expose (??) | 1081 | // emitText("\\"); // expose (??) |
1082 | // break; | 1082 | // break; |
1083 | 1083 | ||
1084 | case 0x2016: // fn-p | 1084 | case 0x2016: // fn-p |
1085 | case Key_F2: | 1085 | case Key_F2: |
1086 | pasteClipboard(); | 1086 | pasteClipboard(); |
1087 | break; | 1087 | break; |
1088 | 1088 | ||
1089 | case 0x2018: // fn-S | 1089 | case 0x2018: // fn-S |
1090 | case Key_F3: | 1090 | case Key_F3: |
1091 | emit changeSession(1); | 1091 | emit changeSession(1); |
1092 | break; | 1092 | break; |
1093 | 1093 | ||
1094 | case 0x2019: // fn-n | 1094 | case 0x2019: // fn-n |
1095 | emit newSession(); | 1095 | emit newSession(); |
1096 | break; | 1096 | break; |
1097 | 1097 | ||
1098 | case Qt::Key_Tab: | 1098 | case Qt::Key_Tab: |
1099 | if (ke->state() == ControlButton) { | 1099 | if (ke->state() == ControlButton) { |
1100 | emit changeSession(1); | 1100 | emit changeSession(1); |
1101 | } else { | 1101 | } else { |
1102 | special_function = false; | 1102 | special_function = false; |
1103 | } | 1103 | } |
1104 | break; | 1104 | break; |
1105 | 1105 | ||
1106 | #if 0 | 1106 | #if 0 |
1107 | case Qt::Key_Left: | 1107 | case Qt::Key_Left: |
1108 | if (vcolumns == 0) { | 1108 | if (vcolumns == 0) { |
1109 | emit changeSession(-1); | 1109 | emit changeSession(-1); |
1110 | } else { | 1110 | } else { |
1111 | special_function = false; | 1111 | special_function = false; |
1112 | } | 1112 | } |
1113 | break; | 1113 | break; |
1114 | 1114 | ||
1115 | case Qt::Key_Right: | 1115 | case Qt::Key_Right: |
1116 | if (vcolumns == 0) { | 1116 | if (vcolumns == 0) { |
1117 | emit changeSession(1); | 1117 | emit changeSession(1); |
1118 | } else { | 1118 | } else { |
1119 | special_function = false; | 1119 | special_function = false; |
1120 | } | 1120 | } |
1121 | break; | 1121 | break; |
1122 | #endif | 1122 | #endif |
1123 | 1123 | ||
1124 | case 0x201b: // fn-5 | 1124 | case 0x201b: // fn-5 |
1125 | case Key_F4: | 1125 | case Key_F4: |
1126 | emit toggleFullScreen(); | 1126 | emit toggleFullScreen(); |
1127 | break; | 1127 | break; |
1128 | 1128 | ||
1129 | case 0x200f: // fn-1 magnify minus | 1129 | case 0x200f: // fn-1 magnify minus |
1130 | case Key_F5: | 1130 | case Key_F5: |
1131 | emit changeFontSize(-1); | 1131 | emit changeFontSize(-1); |
1132 | break; | 1132 | break; |
1133 | 1133 | ||
1134 | case 0x2010: // fn-2 magnify plus | 1134 | case 0x2010: // fn-2 magnify plus |
1135 | case Key_F6: | 1135 | case Key_F6: |
1136 | emit changeFontSize(1); | 1136 | emit changeFontSize(1); |
1137 | break; | 1137 | break; |
1138 | 1138 | ||
1139 | default: | 1139 | default: |
1140 | special_function = false; | 1140 | special_function = false; |
1141 | } | 1141 | } |
1142 | if (special_function) { | 1142 | if (special_function) { |
1143 | return true; | 1143 | return true; |
1144 | } | 1144 | } |
1145 | // else if( ke->state() == ControlButton && ke->key() == Key_V) { | 1145 | // else if( ke->state() == ControlButton && ke->key() == Key_V) { |
1146 | // pasteClipboard(); | 1146 | // pasteClipboard(); |
1147 | // } | 1147 | // } |
1148 | // else if( ke->state() == ControlButton && ke->key() == Key_C) { | 1148 | // else if( ke->state() == ControlButton && ke->key() == Key_C) { |
1149 | // pasteClipboard(); | 1149 | // pasteClipboard(); |
1150 | // } | 1150 | // } |
1151 | emit keyPressedSignal(ke); // expose | 1151 | emit keyPressedSignal(ke); // expose |
1152 | ke->accept(); | 1152 | ke->accept(); |
1153 | #ifdef FAKE_CTRL_AND_ALT | 1153 | #ifdef FAKE_CTRL_AND_ALT |
1154 | if ( dele ) delete e; | 1154 | if ( dele ) delete e; |
1155 | #endif | 1155 | #endif |
1156 | return true; // stop the event | 1156 | return true; // stop the event |
1157 | } | 1157 | } |
1158 | if ( e->type() == QEvent::Enter ) { | 1158 | if ( e->type() == QEvent::Enter ) { |
1159 | QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), | 1159 | QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), |
1160 | this, SLOT(onClearSelection()) ); | 1160 | this, SLOT(onClearSelection()) ); |
1161 | } | 1161 | } |
1162 | if ( e->type() == QEvent::Leave ) { | 1162 | if ( e->type() == QEvent::Leave ) { |
1163 | QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), | 1163 | QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), |
1164 | this, SLOT(onClearSelection()) ); | 1164 | this, SLOT(onClearSelection()) ); |
1165 | } | 1165 | } |
1166 | return QFrame::eventFilter( obj, e ); | 1166 | return QFrame::eventFilter( obj, e ); |
1167 | } | 1167 | } |
1168 | 1168 | ||
1169 | /* ------------------------------------------------------------------------- */ | 1169 | /* ------------------------------------------------------------------------- */ |
1170 | /* */ | 1170 | /* */ |
1171 | /* Frame */ | 1171 | /* Frame */ |
1172 | /* */ | 1172 | /* */ |
1173 | /* ------------------------------------------------------------------------- */ | 1173 | /* ------------------------------------------------------------------------- */ |
1174 | 1174 | ||
1175 | void TEWidget::frameChanged() | 1175 | void TEWidget::frameChanged() |
1176 | { | 1176 | { |
1177 | propagateSize(); | 1177 | propagateSize(); |
1178 | update(); | 1178 | update(); |
1179 | } | 1179 | } |
1180 | /* ------------------------------------------------------------------------- */ | 1180 | /* ------------------------------------------------------------------------- */ |
1181 | /* */ | 1181 | /* */ |
1182 | /* Sound */ | 1182 | /* Sound */ |
1183 | /* */ | 1183 | /* */ |
1184 | /* ------------------------------------------------------------------------- */ | 1184 | /* ------------------------------------------------------------------------- */ |
1185 | 1185 | ||
1186 | void TEWidget::Bell() | 1186 | void TEWidget::Bell() |
1187 | { | 1187 | { |
1188 | //#ifdef QT_QWS_SL5XXX | 1188 | //#ifdef QT_QWS_SL5XXX |
1189 | //# ifndef QT_NO_COP | 1189 | //# ifndef QT_NO_COP |
1190 | if(useBeep) | 1190 | if(useBeep) |
1191 | QCopEnvelope( "QPE/TaskBar", "soundAlarm()" ); | 1191 | QCopEnvelope( "QPE/TaskBar", "soundAlarm()" ); |
1192 | 1192 | ||
1193 | //# endif | 1193 | //# endif |
1194 | //#else | 1194 | //#else |
1195 | //# ifndef QT_NO_SOUND | 1195 | //# ifndef QT_NO_SOUND |
1196 | // QSound::play(Resource::findSound("alarm")); | 1196 | // QSound::play(Resource::findSound("alarm")); |
1197 | //# endif | 1197 | //# endif |
1198 | //#endif | 1198 | //#endif |
1199 | 1199 | ||
1200 | // QApplication::beep(); | 1200 | // QApplication::beep(); |
1201 | } | 1201 | } |
1202 | 1202 | ||
1203 | /* ------------------------------------------------------------------------- */ | 1203 | /* ------------------------------------------------------------------------- */ |
1204 | /* */ | 1204 | /* */ |
1205 | /* Auxiluary */ | 1205 | /* Auxiluary */ |
1206 | /* */ | 1206 | /* */ |
1207 | /* ------------------------------------------------------------------------- */ | 1207 | /* ------------------------------------------------------------------------- */ |
1208 | 1208 | ||
1209 | void TEWidget::clearImage() | 1209 | void TEWidget::clearImage() |
1210 | // initialize the image | 1210 | // initialize the image |
1211 | // for internal use only | 1211 | // for internal use only |
1212 | { | 1212 | { |
1213 | for (int y = 0; y < lines; y++) | 1213 | for (int y = 0; y < lines; y++) |
1214 | for (int x = 0; x < columns; x++) | 1214 | for (int x = 0; x < columns; x++) |
1215 | { | 1215 | { |
1216 | image[loc(x,y)].c = 0xff; //' '; | 1216 | image[loc(x,y)].c = 0xff; //' '; |
1217 | image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; | 1217 | image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; |
1218 | image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; | 1218 | image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; |
1219 | image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; | 1219 | image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; |
1220 | } | 1220 | } |
1221 | } | 1221 | } |
1222 | 1222 | ||
1223 | // Create Image /////////////////////////////////////////////////////// | 1223 | // Create Image /////////////////////////////////////////////////////// |
1224 | 1224 | ||
1225 | void TEWidget::calcGeometry() | 1225 | void TEWidget::calcGeometry() |
1226 | { | 1226 | { |
1227 | int showhscrollbar = 1; | 1227 | int showhscrollbar = 1; |
1228 | int hwidth = 0; | 1228 | int hwidth = 0; |
1229 | int dcolumns; | 1229 | int dcolumns = 0; |
1230 | Config cfg( "Konsole" ); | 1230 | Config cfg( "Konsole" ); |
1231 | cfg.setGroup("ScrollBar"); | 1231 | cfg.setGroup("ScrollBar"); |
1232 | useHorzScroll=cfg.readBoolEntry("HorzScroll",0); | 1232 | useHorzScroll=cfg.readBoolEntry("HorzScroll",0); |
1233 | 1233 | ||
1234 | if(vcolumns == 0) showhscrollbar = 0; | 1234 | if(vcolumns == 0) showhscrollbar = 0; |
1235 | if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width(); | 1235 | if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width(); |
1236 | 1236 | ||
1237 | scrollbar->resize(QApplication::style().scrollBarExtent().width(), | 1237 | scrollbar->resize(QApplication::style().scrollBarExtent().width(), |
1238 | contentsRect().height() - hwidth); | 1238 | contentsRect().height() - hwidth); |
1239 | 1239 | ||
1240 | switch(scrollLoc) { | 1240 | switch(scrollLoc) { |
1241 | case SCRNONE : | 1241 | case SCRNONE : |
1242 | columns = ( contentsRect().width() - 2 * rimX ) / font_w; | 1242 | columns = ( contentsRect().width() - 2 * rimX ) / font_w; |
1243 | dcolumns = columns; | 1243 | dcolumns = columns; |
1244 | if(vcolumns) columns = vcolumns; | 1244 | if(vcolumns) columns = vcolumns; |
1245 | blX = (contentsRect().width() - (columns*font_w) ) / 2; | 1245 | blX = (contentsRect().width() - (columns*font_w) ) / 2; |
1246 | if(showhscrollbar) | 1246 | if(showhscrollbar) |
1247 | blX = -hposition * font_w; | 1247 | blX = -hposition * font_w; |
1248 | brX = blX; | 1248 | brX = blX; |
1249 | scrollbar->hide(); | 1249 | scrollbar->hide(); |
1250 | break; | 1250 | break; |
1251 | case SCRLEFT : | 1251 | case SCRLEFT : |
1252 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; | 1252 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; |
1253 | dcolumns = columns; | 1253 | dcolumns = columns; |
1254 | if(vcolumns) columns = vcolumns; | 1254 | if(vcolumns) columns = vcolumns; |
1255 | brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; | 1255 | brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; |
1256 | if(showhscrollbar) | 1256 | if(showhscrollbar) |
1257 | brX = -hposition * font_w; | 1257 | brX = -hposition * font_w; |
1258 | blX = brX + scrollbar->width(); | 1258 | blX = brX + scrollbar->width(); |
1259 | scrollbar->move(contentsRect().topLeft()); | 1259 | scrollbar->move(contentsRect().topLeft()); |
1260 | scrollbar->show(); | 1260 | scrollbar->show(); |
1261 | break; | 1261 | break; |
1262 | case SCRRIGHT: | 1262 | case SCRRIGHT: |
1263 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; | 1263 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; |
1264 | dcolumns = columns; | 1264 | dcolumns = columns; |
1265 | if(vcolumns) columns = vcolumns; | 1265 | if(vcolumns) columns = vcolumns; |
1266 | blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; | 1266 | blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; |
1267 | if(showhscrollbar) | 1267 | if(showhscrollbar) |
1268 | blX = -hposition * font_w; | 1268 | blX = -hposition * font_w; |
1269 | brX = blX; | 1269 | brX = blX; |
1270 | scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); | 1270 | scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); |
1271 | scrollbar->show(); | 1271 | scrollbar->show(); |
1272 | break; | 1272 | break; |
1273 | } | 1273 | } |
1274 | //FIXME: support 'rounding' styles | 1274 | //FIXME: support 'rounding' styles |
1275 | lines = ( contentsRect().height() - 2 * rimY ) / font_h; | 1275 | lines = ( contentsRect().height() - 2 * rimY ) / font_h; |
1276 | bY = (contentsRect().height() - (lines *font_h)) / 2; | 1276 | bY = (contentsRect().height() - (lines *font_h)) / 2; |
1277 | 1277 | ||
1278 | if(showhscrollbar == 1) { | 1278 | if(showhscrollbar == 1) { |
1279 | hScrollbar->resize(contentsRect().width() - hwidth, hwidth); | 1279 | hScrollbar->resize(contentsRect().width() - hwidth, hwidth); |
1280 | hScrollbar->setRange(0, vcolumns - dcolumns); | 1280 | hScrollbar->setRange(0, vcolumns - dcolumns); |
1281 | 1281 | ||
1282 | QPoint p = contentsRect().bottomLeft(); | 1282 | QPoint p = contentsRect().bottomLeft(); |
1283 | if(scrollLoc == SCRLEFT) | 1283 | if(scrollLoc == SCRLEFT) |
1284 | hScrollbar->move(QPoint(p.x()+hwidth, p.y() - hwidth)); | 1284 | hScrollbar->move(QPoint(p.x()+hwidth, p.y() - hwidth)); |
1285 | else | 1285 | else |
1286 | hScrollbar->move(QPoint(p.x(), p.y() - hwidth)); | 1286 | hScrollbar->move(QPoint(p.x(), p.y() - hwidth)); |
1287 | 1287 | ||
1288 | hScrollbar->show(); | 1288 | hScrollbar->show(); |
1289 | } | 1289 | } |
1290 | else hScrollbar->hide(); | 1290 | else hScrollbar->hide(); |
1291 | 1291 | ||
1292 | if(showhscrollbar == 1) { | 1292 | if(showhscrollbar == 1) { |
1293 | lines = lines - (hwidth / font_h) - 1; | 1293 | lines = lines - (hwidth / font_h) - 1; |
1294 | if(lines < 1) lines = 1; | 1294 | if(lines < 1) lines = 1; |
1295 | } | 1295 | } |
1296 | //FIXME: support 'rounding' styles | 1296 | //FIXME: support 'rounding' styles |
1297 | } | 1297 | } |
1298 | 1298 | ||
1299 | void TEWidget::makeImage() | 1299 | void TEWidget::makeImage() |
1300 | //FIXME: rename 'calcGeometry? | 1300 | //FIXME: rename 'calcGeometry? |
1301 | { | 1301 | { |
1302 | calcGeometry(); | 1302 | calcGeometry(); |
1303 | image = (ca*) malloc(lines*columns*sizeof(ca)); | 1303 | image = (ca*) malloc(lines*columns*sizeof(ca)); |
1304 | clearImage(); | 1304 | clearImage(); |
1305 | } | 1305 | } |
1306 | 1306 | ||
1307 | // calculate the needed size | 1307 | // calculate the needed size |
1308 | QSize TEWidget::calcSize(int cols, int lins) const | 1308 | QSize TEWidget::calcSize(int cols, int lins) const |
1309 | { | 1309 | { |
1310 | int frw = width() - contentsRect().width(); | 1310 | int frw = width() - contentsRect().width(); |
1311 | int frh = height() - contentsRect().height(); | 1311 | int frh = height() - contentsRect().height(); |
1312 | int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); | 1312 | int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); |
1313 | return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh ); | 1313 | return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh ); |
1314 | } | 1314 | } |
1315 | 1315 | ||
1316 | QSize TEWidget::sizeHint() const | 1316 | QSize TEWidget::sizeHint() const |
1317 | { | 1317 | { |
1318 | return size(); | 1318 | return size(); |
1319 | } | 1319 | } |
1320 | 1320 | ||
1321 | void TEWidget::styleChange(QStyle &) | 1321 | void TEWidget::styleChange(QStyle &) |
1322 | { | 1322 | { |
1323 | propagateSize(); | 1323 | propagateSize(); |
1324 | } | 1324 | } |
1325 | 1325 | ||
1326 | #ifndef QT_NO_DRAGANDDROP | 1326 | #ifndef QT_NO_DRAGANDDROP |
1327 | 1327 | ||
1328 | /* --------------------------------------------------------------------- */ | 1328 | /* --------------------------------------------------------------------- */ |
1329 | /* */ | 1329 | /* */ |
1330 | /* Drag & Drop */ | 1330 | /* Drag & Drop */ |
1331 | /* */ | 1331 | /* */ |
1332 | /* --------------------------------------------------------------------- */ | 1332 | /* --------------------------------------------------------------------- */ |
1333 | 1333 | ||
1334 | 1334 | ||
1335 | void TEWidget::dragEnterEvent(QDragEnterEvent* e) | 1335 | void TEWidget::dragEnterEvent(QDragEnterEvent* e) |
1336 | { | 1336 | { |
1337 | e->accept(QTextDrag::canDecode(e) || | 1337 | e->accept(QTextDrag::canDecode(e) || |
1338 | QUriDrag::canDecode(e)); | 1338 | QUriDrag::canDecode(e)); |
1339 | } | 1339 | } |
1340 | 1340 | ||
1341 | void TEWidget::dropEvent(QDropEvent* event) | 1341 | void TEWidget::dropEvent(QDropEvent* event) |
1342 | { | 1342 | { |
1343 | // The current behaviour when url(s) are dropped is | 1343 | // The current behaviour when url(s) are dropped is |
1344 | // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd | 1344 | // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd |
1345 | // * in all other cases, just paste | 1345 | // * in all other cases, just paste |
1346 | // (for non-local ones, or for a list of URLs, 'cd' is nonsense) | 1346 | // (for non-local ones, or for a list of URLs, 'cd' is nonsense) |
1347 | QStrList strlist; | 1347 | QStrList strlist; |
1348 | int file_count = 0; | 1348 | int file_count = 0; |
1349 | dropText = ""; | 1349 | dropText = ""; |
1350 | bool bPopup = true; | 1350 | bool bPopup = true; |
1351 | 1351 | ||
1352 | if(QUriDrag::decode(event, strlist)) { | 1352 | if(QUriDrag::decode(event, strlist)) { |
1353 | if (strlist.count()) { | 1353 | if (strlist.count()) { |
1354 | for(const char* p = strlist.first(); p; p = strlist.next()) { | 1354 | for(const char* p = strlist.first(); p; p = strlist.next()) { |
1355 | if(file_count++ > 0) { | 1355 | if(file_count++ > 0) { |
1356 | dropText += " "; | 1356 | dropText += " "; |
1357 | bPopup = false; // more than one file, don't popup | 1357 | bPopup = false; // more than one file, don't popup |
1358 | } | 1358 | } |
1359 | 1359 | ||
1360 | /* | 1360 | /* |
1361 | KURL url(p); | 1361 | KURL url(p); |
1362 | if (url.isLocalFile()) { | 1362 | if (url.isLocalFile()) { |
1363 | dropText += url.path(); // local URL : remove protocol | 1363 | dropText += url.path(); // local URL : remove protocol |
1364 | } | 1364 | } |
1365 | else { | 1365 | else { |
1366 | dropText += url.prettyURL(); | 1366 | dropText += url.prettyURL(); |
1367 | bPopup = false; // a non-local file, don't popup | 1367 | bPopup = false; // a non-local file, don't popup |
1368 | } | 1368 | } |
1369 | */ | 1369 | */ |
1370 | 1370 | ||
1371 | } | 1371 | } |
1372 | 1372 | ||
1373 | if (bPopup) | 1373 | if (bPopup) |
1374 | // m_drop->popup(pos() + event->pos()); | 1374 | // m_drop->popup(pos() + event->pos()); |
1375 | m_drop->popup(mapToGlobal(event->pos())); | 1375 | m_drop->popup(mapToGlobal(event->pos())); |
1376 | else | 1376 | else |
1377 | { | 1377 | { |
1378 | if (currentSession) { | 1378 | if (currentSession) { |
1379 | currentSession->getEmulation()->sendString(dropText.local8Bit()); | 1379 | currentSession->getEmulation()->sendString(dropText.local8Bit()); |
1380 | } | 1380 | } |
1381 | // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; | 1381 | // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; |
1382 | } | 1382 | } |
1383 | } | 1383 | } |
1384 | } | 1384 | } |
1385 | else if(QTextDrag::decode(event, dropText)) { | 1385 | else if(QTextDrag::decode(event, dropText)) { |
1386 | // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; | 1386 | // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; |
1387 | if (currentSession) { | 1387 | if (currentSession) { |
1388 | currentSession->getEmulation()->sendString(dropText.local8Bit()); | 1388 | currentSession->getEmulation()->sendString(dropText.local8Bit()); |
1389 | } | 1389 | } |
1390 | // Paste it | 1390 | // Paste it |
1391 | } | 1391 | } |
1392 | } | 1392 | } |
1393 | #endif | 1393 | #endif |
1394 | 1394 | ||
1395 | 1395 | ||
1396 | void TEWidget::drop_menu_activated(int item) | 1396 | void TEWidget::drop_menu_activated(int item) |
1397 | { | 1397 | { |
1398 | #ifndef QT_NO_DRAGANDDROP | 1398 | #ifndef QT_NO_DRAGANDDROP |
1399 | switch (item) | 1399 | switch (item) |
1400 | { | 1400 | { |
1401 | case 0: // paste | 1401 | case 0: // paste |
1402 | currentSession->getEmulation()->sendString(dropText.local8Bit()); | 1402 | currentSession->getEmulation()->sendString(dropText.local8Bit()); |
1403 | // KWM::activate((Window)this->winId()); | 1403 | // KWM::activate((Window)this->winId()); |
1404 | break; | 1404 | break; |
1405 | case 1: // cd ... | 1405 | case 1: // cd ... |
1406 | currentSession->getEmulation()->sendString("cd "); | 1406 | currentSession->getEmulation()->sendString("cd "); |
1407 | struct stat statbuf; | 1407 | struct stat statbuf; |
1408 | if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) | 1408 | if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) |
1409 | { | 1409 | { |
1410 | if ( !S_ISDIR(statbuf.st_mode) ) | 1410 | if ( !S_ISDIR(statbuf.st_mode) ) |
1411 | { | 1411 | { |
1412 | /* | 1412 | /* |
1413 | KURL url; | 1413 | KURL url; |
1414 | url.setPath( dropText ); | 1414 | url.setPath( dropText ); |
1415 | dropText = url.directory( true, false ); // remove filename | 1415 | dropText = url.directory( true, false ); // remove filename |
1416 | */ | 1416 | */ |
1417 | } | 1417 | } |
1418 | } | 1418 | } |
1419 | dropText.replace(QRegExp(" "), "\\ "); // escape spaces | 1419 | dropText.replace(QRegExp(" "), "\\ "); // escape spaces |
1420 | currentSession->getEmulation()->sendString(dropText.local8Bit()); | 1420 | currentSession->getEmulation()->sendString(dropText.local8Bit()); |
1421 | currentSession->getEmulation()->sendString("\n"); | 1421 | currentSession->getEmulation()->sendString("\n"); |
1422 | // KWM::activate((Window)this->winId()); | 1422 | // KWM::activate((Window)this->winId()); |
1423 | break; | 1423 | break; |
1424 | } | 1424 | } |
1425 | #endif | 1425 | #endif |
1426 | } | 1426 | } |
1427 | 1427 | ||
1428 | void TEWidget::setWrapAt(int columns) | 1428 | void TEWidget::setWrapAt(int columns) |
1429 | { | 1429 | { |
1430 | vcolumns = columns; | 1430 | vcolumns = columns; |
1431 | propagateSize(); | 1431 | propagateSize(); |
1432 | update(); | 1432 | update(); |
1433 | } | 1433 | } |