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