summaryrefslogtreecommitdiff
authorar <ar>2005-01-21 19:56:15 (UTC)
committer ar <ar>2005-01-21 19:56:15 (UTC)
commitcd51d382be50bc021739395309e23760f1619759 (patch) (unidiff)
treee76155f772df7faea5fcf38667c6da8c916208db
parentfdc37fbd908472e28735a8f0b01e3e66a43535e0 (diff)
downloadopie-cd51d382be50bc021739395309e23760f1619759.zip
opie-cd51d382be50bc021739395309e23760f1619759.tar.gz
opie-cd51d382be50bc021739395309e23760f1619759.tar.bz2
- make opie compilable against qte 2.3.10 snapshot
check QT_VERSION against 0x030000 instead of 300
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/TEWidget.cpp2
-rw-r--r--core/apps/textedit/textedit.cpp2
-rw-r--r--core/opie-login/loginwindowimpl.cpp4
-rw-r--r--freetype/fontfactoryttf_qws.h2
-rw-r--r--libopie2/opieui/oseparator.cpp2
-rw-r--r--libopie2/qt3/opieui/oeditlistbox.h2
-rw-r--r--libopie2/qt3/opieui/ojanuswidget.cpp2
-rw-r--r--library/lightstyle.cpp10
-rw-r--r--library/lightstyle.h2
-rw-r--r--library/qpeapplication.cpp4
-rw-r--r--library/qpestyle.cpp4
-rw-r--r--library/qpestyle.h2
-rw-r--r--noncore/apps/opie-console/TEWidget.cpp2
-rw-r--r--noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp4
-rw-r--r--noncore/apps/tinykate/libkate/qt3back/qregexp3.h4
-rw-r--r--noncore/apps/zsafe/shadedlistitem.cpp2
-rw-r--r--noncore/net/wellenreiter/gui/configwindow.cpp6
-rw-r--r--noncore/settings/appearance2/appearance.cpp4
-rw-r--r--noncore/settings/doctab/doctab.cpp2
-rw-r--r--noncore/settings/language/language.cpp2
-rw-r--r--noncore/settings/networksettings/interfaces/module.h2
-rw-r--r--noncore/settings/networksettings/mainwindow/addconnectionimp.cpp2
-rw-r--r--noncore/settings/networksettings/mainwindow/mainwindowimp.cpp2
-rw-r--r--noncore/unsupported/qpdf/QOutputDev.cpp2
-rw-r--r--scripts/kconfig/qconf.cc16
-rw-r--r--scripts/kconfig/qconf.h2
26 files changed, 45 insertions, 45 deletions
diff --git a/core/apps/embeddedkonsole/TEWidget.cpp b/core/apps/embeddedkonsole/TEWidget.cpp
index 5171bf1..bee58e7 100644
--- a/core/apps/embeddedkonsole/TEWidget.cpp
+++ b/core/apps/embeddedkonsole/TEWidget.cpp
@@ -1,1431 +1,1431 @@
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 62#ifndef QT_NO_DRAGANDDROP
63#include <qdragobject.h> 63#include <qdragobject.h>
64#include <qfile.h> 64#include <qfile.h>
65#endif 65#endif
66 66
67#include <stdio.h> 67#include <stdio.h>
68#include <stdlib.h> 68#include <stdlib.h>
69#include <unistd.h> 69#include <unistd.h>
70#include <ctype.h> 70#include <ctype.h>
71#include <sys/stat.h> 71#include <sys/stat.h>
72#include <sys/types.h> 72#include <sys/types.h>
73#include <signal.h> 73#include <signal.h>
74 74
75#include <assert.h> 75#include <assert.h>
76 76
77// #include "TEWidget.moc" 77// #include "TEWidget.moc"
78//#include <kapp.h> 78//#include <kapp.h>
79//#include <kcursor.h> 79//#include <kcursor.h>
80//#include <kurl.h> 80//#include <kurl.h>
81//#include <kdebug.h> 81//#include <kdebug.h>
82//#include <klocale.h> 82//#include <klocale.h>
83 83
84#define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__) 84#define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__)
85#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++); }
86 86
87#define loc(X,Y) ((Y)*columns+(X)) 87#define loc(X,Y) ((Y)*columns+(X))
88 88
89//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.
90#define rimX 0 // left/right rim width 90#define rimX 0 // left/right rim width
91#define rimY 0 // top/bottom rim high 91#define rimY 0 // top/bottom rim high
92 92
93#define SCRWIDTH 16 // width of the scrollbar 93#define SCRWIDTH 16 // width of the scrollbar
94 94
95#define yMouseScroll 1 95#define yMouseScroll 1
96// scroll increment used when dragging selection at top/bottom of window. 96// scroll increment used when dragging selection at top/bottom of window.
97 97
98/* ------------------------------------------------------------------------- */ 98/* ------------------------------------------------------------------------- */
99/* */ 99/* */
100/* Colors */ 100/* Colors */
101/* */ 101/* */
102/* ------------------------------------------------------------------------- */ 102/* ------------------------------------------------------------------------- */
103 103
104//FIXME: the default color table is in session.C now. 104//FIXME: the default color table is in session.C now.
105// We need a way to get rid of this one, here. 105// We need a way to get rid of this one, here.
106static const ColorEntry base_color_table[TABLE_COLORS] = 106static const ColorEntry base_color_table[TABLE_COLORS] =
107// The following are almost IBM standard color codes, with some slight 107// The following are almost IBM standard color codes, with some slight
108// 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.
109// It contains the 8 ansiterm/xterm colors in 2 intensities. 109// It contains the 8 ansiterm/xterm colors in 2 intensities.
110{ 110{
111 // Fixme: could add faint colors here, also. 111 // Fixme: could add faint colors here, also.
112 // normal 112 // normal
113 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
114 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
115 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
116 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
117 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
118 // intensiv 118 // intensiv
119 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 ),
120 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 ),
121 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 ),
122 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 ),
123 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 )
124}; 124};
125 125
126/* 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)
127 127
128 Code 0 1 2 3 4 5 6 7 128 Code 0 1 2 3 4 5 6 7
129 ----------- ------- ------- ------- ------- ------- ------- ------- ------- 129 ----------- ------- ------- ------- ------- ------- ------- ------- -------
130 ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White 130 ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White
131 IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White 131 IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White
132*/ 132*/
133 133
134QColor TEWidget::getDefaultBackColor() 134QColor TEWidget::getDefaultBackColor()
135{ 135{
136 return color_table[DEFAULT_BACK_COLOR].color; 136 return color_table[DEFAULT_BACK_COLOR].color;
137} 137}
138 138
139const ColorEntry* TEWidget::getColorTable() const 139const ColorEntry* TEWidget::getColorTable() const
140{ 140{
141 return color_table; 141 return color_table;
142} 142}
143 143
144const ColorEntry* TEWidget::getdefaultColorTable() const 144const ColorEntry* TEWidget::getdefaultColorTable() const
145{ 145{
146 return base_color_table; 146 return base_color_table;
147} 147}
148 148
149 149
150const QPixmap *TEWidget::backgroundPixmap() 150const QPixmap *TEWidget::backgroundPixmap()
151{ 151{
152 static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm"); 152 static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm");
153 const QPixmap *pm = bg; 153 const QPixmap *pm = bg;
154 return pm; 154 return pm;
155} 155}
156 156
157void TEWidget::setColorTable(const ColorEntry table[]) 157void TEWidget::setColorTable(const ColorEntry table[])
158{ 158{
159 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];
160 160
161 const QPixmap* pm = backgroundPixmap(); 161 const QPixmap* pm = backgroundPixmap();
162 if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color); 162 if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color);
163 update(); 163 update();
164} 164}
165 165
166//FIXME: add backgroundPixmapChanged. 166//FIXME: add backgroundPixmapChanged.
167 167
168/* ------------------------------------------------------------------------- */ 168/* ------------------------------------------------------------------------- */
169/* */ 169/* */
170/* Font */ 170/* Font */
171/* */ 171/* */
172/* ------------------------------------------------------------------------- */ 172/* ------------------------------------------------------------------------- */
173 173
174/* 174/*
175 The VT100 has 32 special graphical characters. The usual vt100 extended 175 The VT100 has 32 special graphical characters. The usual vt100 extended
176 xterm fonts have these at 0x00..0x1f. 176 xterm fonts have these at 0x00..0x1f.
177 177
178 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
179 come in here as proper unicode characters. 179 come in here as proper unicode characters.
180 180
181 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
182 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
183 QCodec. 183 QCodec.
184*/ 184*/
185 185
186// assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i. 186// assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i.
187 187
188unsigned short vt100_graphics[32] = 188unsigned short vt100_graphics[32] =
189{ // 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
190 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 190 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0,
191 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 191 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c,
192 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534, 192 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534,
193 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7 193 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7
194}; 194};
195 195
196static QChar vt100extended(QChar c) 196static QChar vt100extended(QChar c)
197{ 197{
198 switch (c.unicode()) 198 switch (c.unicode())
199 { 199 {
200 case 0x25c6 : return 1; 200 case 0x25c6 : return 1;
201 case 0x2592 : return 2; 201 case 0x2592 : return 2;
202 case 0x2409 : return 3; 202 case 0x2409 : return 3;
203 case 0x240c : return 4; 203 case 0x240c : return 4;
204 case 0x240d : return 5; 204 case 0x240d : return 5;
205 case 0x240a : return 6; 205 case 0x240a : return 6;
206 case 0x00b0 : return 7; 206 case 0x00b0 : return 7;
207 case 0x00b1 : return 8; 207 case 0x00b1 : return 8;
208 case 0x2424 : return 9; 208 case 0x2424 : return 9;
209 case 0x240b : return 10; 209 case 0x240b : return 10;
210 case 0x2518 : return 11; 210 case 0x2518 : return 11;
211 case 0x2510 : return 12; 211 case 0x2510 : return 12;
212 case 0x250c : return 13; 212 case 0x250c : return 13;
213 case 0x2514 : return 14; 213 case 0x2514 : return 14;
214 case 0x253c : return 15; 214 case 0x253c : return 15;
215 case 0xf800 : return 16; 215 case 0xf800 : return 16;
216 case 0xf801 : return 17; 216 case 0xf801 : return 17;
217 case 0x2500 : return 18; 217 case 0x2500 : return 18;
218 case 0xf803 : return 19; 218 case 0xf803 : return 19;
219 case 0xf804 : return 20; 219 case 0xf804 : return 20;
220 case 0x251c : return 21; 220 case 0x251c : return 21;
221 case 0x2524 : return 22; 221 case 0x2524 : return 22;
222 case 0x2534 : return 23; 222 case 0x2534 : return 23;
223 case 0x252c : return 24; 223 case 0x252c : return 24;
224 case 0x2502 : return 25; 224 case 0x2502 : return 25;
225 case 0x2264 : return 26; 225 case 0x2264 : return 26;
226 case 0x2265 : return 27; 226 case 0x2265 : return 27;
227 case 0x03c0 : return 28; 227 case 0x03c0 : return 28;
228 case 0x2260 : return 29; 228 case 0x2260 : return 29;
229 case 0x00a3 : return 30; 229 case 0x00a3 : return 30;
230 case 0x00b7 : return 31; 230 case 0x00b7 : return 31;
231 } 231 }
232 return c; 232 return c;
233} 233}
234 234
235static QChar identicalMap(QChar c) 235static QChar identicalMap(QChar c)
236{ 236{
237 return c; 237 return c;
238} 238}
239 239
240void TEWidget::fontChange(const QFont &) 240void TEWidget::fontChange(const QFont &)
241{ 241{
242 QFontMetrics fm(font()); 242 QFontMetrics fm(font());
243 font_h = fm.height(); 243 font_h = fm.height();
244 // font_w = fm.maxWidth(); 244 // font_w = fm.maxWidth();
245 font_w = fm.width("m"); 245 font_w = fm.width("m");
246 font_a = fm.ascent(); 246 font_a = fm.ascent();
247 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,
248 fm.maxWidth(), font_w, font_a); 248 fm.maxWidth(), font_w, font_a);
249 249
250 //printf("font_h: %d\n",font_h); 250 //printf("font_h: %d\n",font_h);
251 //printf("font_w: %d\n",font_w); 251 //printf("font_w: %d\n",font_w);
252 //printf("font_a: %d\n",font_a); 252 //printf("font_a: %d\n",font_a);
253 //printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii()); 253 //printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii());
254 //printf("rawname: %s\n",font().rawName().ascii()); 254 //printf("rawname: %s\n",font().rawName().ascii());
255 fontMap = 255 fontMap =
256#if QT_VERSION < 300 256#if QT_VERSION < 0x030000
257 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646") 257 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646")
258 ? vt100extended 258 ? vt100extended
259 : 259 :
260#endif 260#endif
261 identicalMap; 261 identicalMap;
262 propagateSize(); 262 propagateSize();
263 update(); 263 update();
264} 264}
265 265
266void TEWidget::setVTFont(const QFont& f) 266void TEWidget::setVTFont(const QFont& f)
267{ 267{
268 QFrame::setFont(f); 268 QFrame::setFont(f);
269} 269}
270 270
271QFont TEWidget::getVTFont() { 271QFont TEWidget::getVTFont() {
272 return font(); 272 return font();
273} 273}
274 274
275void TEWidget::setFont(const QFont &) 275void TEWidget::setFont(const QFont &)
276{ 276{
277 // ignore font change request if not coming from konsole itself 277 // ignore font change request if not coming from konsole itself
278} 278}
279 279
280/* ------------------------------------------------------------------------- */ 280/* ------------------------------------------------------------------------- */
281/* */ 281/* */
282/* Constructor / Destructor */ 282/* Constructor / Destructor */
283/* */ 283/* */
284/* ------------------------------------------------------------------------- */ 284/* ------------------------------------------------------------------------- */
285 285
286TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name) 286TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name)
287{ 287{
288#ifndef QT_NO_CLIPBOARD 288#ifndef QT_NO_CLIPBOARD
289 cb = QApplication::clipboard(); 289 cb = QApplication::clipboard();
290 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 290 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
291 this, SLOT(onClearSelection()) ); 291 this, SLOT(onClearSelection()) );
292#endif 292#endif
293 293
294 scrollbar = new QScrollBar(this); 294 scrollbar = new QScrollBar(this);
295 scrollbar->setCursor( arrowCursor ); 295 scrollbar->setCursor( arrowCursor );
296 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 296 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
297 297
298 hScrollbar = new QScrollBar(this); 298 hScrollbar = new QScrollBar(this);
299 hScrollbar->setCursor( arrowCursor ); 299 hScrollbar->setCursor( arrowCursor );
300 hScrollbar->setOrientation(QScrollBar::Horizontal); 300 hScrollbar->setOrientation(QScrollBar::Horizontal);
301 // hScrollbar->setMaximumHeight(16); 301 // hScrollbar->setMaximumHeight(16);
302 302
303 connect( hScrollbar, SIGNAL(valueChanged(int)), this, SLOT( hScrollChanged(int))); 303 connect( hScrollbar, SIGNAL(valueChanged(int)), this, SLOT( hScrollChanged(int)));
304 304
305 Config cfg( "Konsole" ); 305 Config cfg( "Konsole" );
306 cfg.setGroup("ScrollBar"); 306 cfg.setGroup("ScrollBar");
307 switch( cfg.readNumEntry("Position",2)){ 307 switch( cfg.readNumEntry("Position",2)){
308 case 0: 308 case 0:
309 scrollLoc = SCRNONE; 309 scrollLoc = SCRNONE;
310 break; 310 break;
311 case 1: 311 case 1:
312 scrollLoc = SCRLEFT; 312 scrollLoc = SCRLEFT;
313 break; 313 break;
314 case 2: 314 case 2:
315 scrollLoc = SCRRIGHT; 315 scrollLoc = SCRRIGHT;
316 break; 316 break;
317 }; 317 };
318 318
319 useHorzScroll=cfg.readBoolEntry("HorzScroll",0); 319 useHorzScroll=cfg.readBoolEntry("HorzScroll",0);
320 320
321 blinkT = new QTimer(this); 321 blinkT = new QTimer(this);
322 connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent())); 322 connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent()));
323 // blinking = FALSE; 323 // blinking = FALSE;
324 blinking = TRUE; 324 blinking = TRUE;
325 325
326 resizing = FALSE; 326 resizing = FALSE;
327 actSel = 0; 327 actSel = 0;
328 image = 0; 328 image = 0;
329 lines = 1; 329 lines = 1;
330 columns = 1; 330 columns = 1;
331 font_w = 1; 331 font_w = 1;
332 font_h = 1; 332 font_h = 1;
333 font_a = 1; 333 font_a = 1;
334 word_selection_mode = FALSE; 334 word_selection_mode = FALSE;
335 hposition = 0; 335 hposition = 0;
336 vcolumns = 0; 336 vcolumns = 0;
337 useBeep = true; 337 useBeep = true;
338 338
339 setMouseMarks(TRUE); 339 setMouseMarks(TRUE);
340 setVTFont( QFont("fixed") ); 340 setVTFont( QFont("fixed") );
341 setColorTable(base_color_table); // init color table 341 setColorTable(base_color_table); // init color table
342 342
343 qApp->installEventFilter( this ); //FIXME: see below 343 qApp->installEventFilter( this ); //FIXME: see below
344// KCursor::setAutoHideCursor( this, true ); 344// KCursor::setAutoHideCursor( this, true );
345 345
346 // Init DnD //////////////////////////////////////////////////////////////// 346 // Init DnD ////////////////////////////////////////////////////////////////
347 currentSession = NULL; 347 currentSession = NULL;
348// setAcceptDrops(true); // attempt 348// setAcceptDrops(true); // attempt
349// m_drop = new QPopupMenu(this); 349// m_drop = new QPopupMenu(this);
350// m_drop->insertItem( QString("Paste"), 0); 350// m_drop->insertItem( QString("Paste"), 0);
351// m_drop->insertItem( QString("cd"), 1); 351// m_drop->insertItem( QString("cd"), 1);
352// connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int))); 352// connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int)));
353 353
354 // we need focus so that the auto-hide cursor feature works 354 // we need focus so that the auto-hide cursor feature works
355 setFocus(); 355 setFocus();
356 setFocusPolicy( WheelFocus ); 356 setFocusPolicy( WheelFocus );
357} 357}
358 358
359//FIXME: make proper destructor 359//FIXME: make proper destructor
360// Here's a start (David) 360// Here's a start (David)
361TEWidget::~TEWidget() 361TEWidget::~TEWidget()
362{ 362{
363 qApp->removeEventFilter( this ); 363 qApp->removeEventFilter( this );
364 if (image) free(image); 364 if (image) free(image);
365} 365}
366 366
367/* ------------------------------------------------------------------------- */ 367/* ------------------------------------------------------------------------- */
368/* */ 368/* */
369/* Display Operations */ 369/* Display Operations */
370/* */ 370/* */
371/* ------------------------------------------------------------------------- */ 371/* ------------------------------------------------------------------------- */
372 372
373/*! 373/*!
374 attributed string draw primitive 374 attributed string draw primitive
375*/ 375*/
376 376
377void TEWidget::drawAttrStr(QPainter &paint, QRect rect, 377void TEWidget::drawAttrStr(QPainter &paint, QRect rect,
378 QString& str, ca attr, BOOL pm, BOOL clear) 378 QString& str, ca attr, BOOL pm, BOOL clear)
379{ 379{
380 if (pm && color_table[attr.b].transparent) 380 if (pm && color_table[attr.b].transparent)
381 { 381 {
382 paint.setBackgroundMode( TransparentMode ); 382 paint.setBackgroundMode( TransparentMode );
383 if (clear) erase(rect); 383 if (clear) erase(rect);
384 } 384 }
385 else 385 else
386 { 386 {
387 if (blinking) 387 if (blinking)
388 paint.fillRect(rect, color_table[attr.b].color); 388 paint.fillRect(rect, color_table[attr.b].color);
389 else 389 else
390 { 390 {
391 paint.setBackgroundMode( OpaqueMode ); 391 paint.setBackgroundMode( OpaqueMode );
392 paint.setBackgroundColor( color_table[attr.b].color ); 392 paint.setBackgroundColor( color_table[attr.b].color );
393 } 393 }
394 } 394 }
395 395
396 if (color_table[attr.f].bold) 396 if (color_table[attr.f].bold)
397 paint.setPen(QColor( 0x8F, 0x00, 0x00 )); 397 paint.setPen(QColor( 0x8F, 0x00, 0x00 ));
398 else 398 else
399 paint.setPen(color_table[attr.f].color); 399 paint.setPen(color_table[attr.f].color);
400 400
401 paint.drawText(rect.x(),rect.y()+font_a, str); 401 paint.drawText(rect.x(),rect.y()+font_a, str);
402 402
403 if (attr.r & RE_UNDERLINE) 403 if (attr.r & RE_UNDERLINE)
404 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 );
405} 405}
406 406
407/*! 407/*!
408 The image can only be set completely. 408 The image can only be set completely.
409 409
410 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.
411*/ 411*/
412 412
413void TEWidget::setImage(const ca* const newimg, int lines, int columns) 413void TEWidget::setImage(const ca* const newimg, int lines, int columns)
414{ int y,x,len; 414{ int y,x,len;
415 const QPixmap* pm = backgroundPixmap(); 415 const QPixmap* pm = backgroundPixmap();
416 QPainter paint; 416 QPainter paint;
417 setUpdatesEnabled(FALSE); 417 setUpdatesEnabled(FALSE);
418 paint.begin( this ); 418 paint.begin( this );
419HCNT("setImage"); 419HCNT("setImage");
420 420
421 QPoint tL = contentsRect().topLeft(); 421 QPoint tL = contentsRect().topLeft();
422 int tLx = tL.x(); 422 int tLx = tL.x();
423 int tLy = tL.y(); 423 int tLy = tL.y();
424 hasBlinker = FALSE; 424 hasBlinker = FALSE;
425 425
426 int cf = -1; // undefined 426 int cf = -1; // undefined
427 int cb = -1; // undefined 427 int cb = -1; // undefined
428 int cr = -1; // undefined 428 int cr = -1; // undefined
429 429
430 int lins = QMIN(this->lines, QMAX(0,lines )); 430 int lins = QMIN(this->lines, QMAX(0,lines ));
431 int cols = QMIN(this->columns,QMAX(0,columns)); 431 int cols = QMIN(this->columns,QMAX(0,columns));
432 QChar *disstrU = new QChar[cols]; 432 QChar *disstrU = new QChar[cols];
433 for (y = 0; y < lins; y++) { 433 for (y = 0; y < lins; y++) {
434 const ca* lcl = &image[y*this->columns]; 434 const ca* lcl = &image[y*this->columns];
435 const ca* const ext = &newimg[y*columns]; 435 const ca* const ext = &newimg[y*columns];
436 if (!resizing) // not while resizing, we're expecting a paintEvent 436 if (!resizing) // not while resizing, we're expecting a paintEvent
437 for (x = 0; x < cols; x++) 437 for (x = 0; x < cols; x++)
438 { 438 {
439 hasBlinker |= (ext[x].r & RE_BLINK); 439 hasBlinker |= (ext[x].r & RE_BLINK);
440 if (ext[x] != lcl[x]) 440 if (ext[x] != lcl[x])
441 { 441 {
442 cr = ext[x].r; 442 cr = ext[x].r;
443 cb = ext[x].b; 443 cb = ext[x].b;
444 if (ext[x].f != cf) cf = ext[x].f; 444 if (ext[x].f != cf) cf = ext[x].f;
445 int lln = cols - x; 445 int lln = cols - x;
446 disstrU[0] = fontMap(ext[x+0].c); 446 disstrU[0] = fontMap(ext[x+0].c);
447 for (len = 1; len < lln; len++) 447 for (len = 1; len < lln; len++)
448 { 448 {
449 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 ||
450 ext[x+len] == lcl[x+len] ) 450 ext[x+len] == lcl[x+len] )
451 break; 451 break;
452 disstrU[len] = fontMap(ext[x+len].c); 452 disstrU[len] = fontMap(ext[x+len].c);
453 } 453 }
454 QString unistr(disstrU,len); 454 QString unistr(disstrU,len);
455 drawAttrStr(paint, 455 drawAttrStr(paint,
456 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),
457 unistr, ext[x], pm != NULL, true); 457 unistr, ext[x], pm != NULL, true);
458 x += len - 1; 458 x += len - 1;
459 } 459 }
460 } 460 }
461 // finally, make `image' become `newimg'. 461 // finally, make `image' become `newimg'.
462 memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca)); 462 memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca));
463 } 463 }
464 drawFrame( &paint ); 464 drawFrame( &paint );
465 paint.end(); 465 paint.end();
466 setUpdatesEnabled(TRUE); 466 setUpdatesEnabled(TRUE);
467 if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms 467 if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms
468 if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; } 468 if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; }
469 delete [] disstrU; 469 delete [] disstrU;
470} 470}
471 471
472// paint Event //////////////////////////////////////////////////// 472// paint Event ////////////////////////////////////////////////////
473 473
474/*! 474/*!
475 The difference of this routine vs. the `setImage' is, 475 The difference of this routine vs. the `setImage' is,
476 that the drawing does not include a difference analysis 476 that the drawing does not include a difference analysis
477 between the old and the new image. Instead, the internal 477 between the old and the new image. Instead, the internal
478 image is used and the painting bound by the PaintEvent box. 478 image is used and the painting bound by the PaintEvent box.
479*/ 479*/
480 480
481void TEWidget::paintEvent( QPaintEvent* pe ) 481void TEWidget::paintEvent( QPaintEvent* pe )
482{ 482{
483 483
484//{ static int cnt = 0; printf("paint %d\n",cnt++); } 484//{ static int cnt = 0; printf("paint %d\n",cnt++); }
485 const QPixmap* pm = backgroundPixmap(); 485 const QPixmap* pm = backgroundPixmap();
486 QPainter paint; 486 QPainter paint;
487 setUpdatesEnabled(FALSE); 487 setUpdatesEnabled(FALSE);
488 paint.begin( this ); 488 paint.begin( this );
489 paint.setBackgroundMode( TransparentMode ); 489 paint.setBackgroundMode( TransparentMode );
490HCNT("paintEvent"); 490HCNT("paintEvent");
491 491
492 // Note that the actual widget size can be slightly larger 492 // Note that the actual widget size can be slightly larger
493 // that the image (the size is truncated towards the smaller 493 // that the image (the size is truncated towards the smaller
494 // number of characters in `resizeEvent'. The paint rectangle 494 // number of characters in `resizeEvent'. The paint rectangle
495 // 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
496 // of one character. 496 // of one character.
497 497
498 QRect rect = pe->rect().intersect(contentsRect()); 498 QRect rect = pe->rect().intersect(contentsRect());
499 499
500 QPoint tL = contentsRect().topLeft(); 500 QPoint tL = contentsRect().topLeft();
501 int tLx = tL.x(); 501 int tLx = tL.x();
502 int tLy = tL.y(); 502 int tLy = tL.y();
503 503
504 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));
505 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));
506 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));
507 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));
508 508
509 /* 509 /*
510 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,
511 rect.left(), rect.right(), rect.top(), rect.bottom()); 511 rect.left(), rect.right(), rect.top(), rect.bottom());
512 */ 512 */
513 513
514 // if (pm != NULL && color_table[image->b].transparent) 514 // if (pm != NULL && color_table[image->b].transparent)
515 // erase(rect); 515 // erase(rect);
516 // 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.
517 517
518 QChar *disstrU = new QChar[columns]; 518 QChar *disstrU = new QChar[columns];
519 for (int y = luy; y <= rly; y++) 519 for (int y = luy; y <= rly; y++)
520 for (int x = lux; x <= rlx; x++) 520 for (int x = lux; x <= rlx; x++)
521 { 521 {
522 int len = 1; 522 int len = 1;
523 disstrU[0] = fontMap(image[loc(x,y)].c); 523 disstrU[0] = fontMap(image[loc(x,y)].c);
524 int cf = image[loc(x,y)].f; 524 int cf = image[loc(x,y)].f;
525 int cb = image[loc(x,y)].b; 525 int cb = image[loc(x,y)].b;
526 int cr = image[loc(x,y)].r; 526 int cr = image[loc(x,y)].r;
527 while (x+len <= rlx && 527 while (x+len <= rlx &&
528 image[loc(x+len,y)].f == cf && 528 image[loc(x+len,y)].f == cf &&
529 image[loc(x+len,y)].b == cb && 529 image[loc(x+len,y)].b == cb &&
530 image[loc(x+len,y)].r == cr ) 530 image[loc(x+len,y)].r == cr )
531 { 531 {
532 disstrU[len] = fontMap(image[loc(x+len,y)].c); 532 disstrU[len] = fontMap(image[loc(x+len,y)].c);
533 len += 1; 533 len += 1;
534 } 534 }
535 QString unistr(disstrU,len); 535 QString unistr(disstrU,len);
536 drawAttrStr(paint, 536 drawAttrStr(paint,
537 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),
538 unistr, image[loc(x,y)], pm != NULL, false); 538 unistr, image[loc(x,y)], pm != NULL, false);
539 x += len - 1; 539 x += len - 1;
540 } 540 }
541 delete [] disstrU; 541 delete [] disstrU;
542 drawFrame( &paint ); 542 drawFrame( &paint );
543 paint.end(); 543 paint.end();
544 setUpdatesEnabled(TRUE); 544 setUpdatesEnabled(TRUE);
545} 545}
546 546
547void TEWidget::blinkEvent() 547void TEWidget::blinkEvent()
548{ 548{
549 blinking = !blinking; 549 blinking = !blinking;
550 repaint(FALSE); 550 repaint(FALSE);
551} 551}
552 552
553/* ------------------------------------------------------------------------- */ 553/* ------------------------------------------------------------------------- */
554/* */ 554/* */
555/* Resizing */ 555/* Resizing */
556/* */ 556/* */
557/* ------------------------------------------------------------------------- */ 557/* ------------------------------------------------------------------------- */
558 558
559void TEWidget::resizeEvent(QResizeEvent* ev) 559void TEWidget::resizeEvent(QResizeEvent* ev)
560{ 560{
561// printf("resize: %d,%d\n",ev->size().width(),ev->size().height()); 561// printf("resize: %d,%d\n",ev->size().width(),ev->size().height());
562 //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);
563 //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);
564 //printf("curren: %d,%d\n",width(),height()); 564 //printf("curren: %d,%d\n",width(),height());
565HCNT("resizeEvent"); 565HCNT("resizeEvent");
566 566
567 // see comment in `paintEvent' concerning the rounding. 567 // see comment in `paintEvent' concerning the rounding.
568 //FIXME: could make a routine here; check width(),height() 568 //FIXME: could make a routine here; check width(),height()
569 assert(ev->size().width() == width()); 569 assert(ev->size().width() == width());
570 assert(ev->size().height() == height()); 570 assert(ev->size().height() == height());
571 571
572 propagateSize(); 572 propagateSize();
573} 573}
574 574
575void TEWidget::propagateSize() 575void TEWidget::propagateSize()
576{ 576{
577 ca* oldimg = image; 577 ca* oldimg = image;
578 int oldlin = lines; 578 int oldlin = lines;
579 int oldcol = columns; 579 int oldcol = columns;
580 makeImage(); 580 makeImage();
581 // we copy the old image to reduce flicker 581 // we copy the old image to reduce flicker
582 int lins = QMIN(oldlin,lines); 582 int lins = QMIN(oldlin,lines);
583 int cols = QMIN(oldcol,columns); 583 int cols = QMIN(oldcol,columns);
584 if (oldimg) 584 if (oldimg)
585 { 585 {
586 for (int lin = 0; lin < lins; lin++) 586 for (int lin = 0; lin < lins; lin++)
587 memcpy((void*)&image[columns*lin], 587 memcpy((void*)&image[columns*lin],
588 (void*)&oldimg[oldcol*lin],cols*sizeof(ca)); 588 (void*)&oldimg[oldcol*lin],cols*sizeof(ca));
589 free(oldimg); //FIXME: try new,delete 589 free(oldimg); //FIXME: try new,delete
590 } 590 }
591 else 591 else
592 clearImage(); 592 clearImage();
593 593
594 //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.
595 // `emu' will call back via `setImage'. 595 // `emu' will call back via `setImage'.
596 596
597 resizing = TRUE; 597 resizing = TRUE;
598 emit changedImageSizeSignal(lines, columns); // expose resizeEvent 598 emit changedImageSizeSignal(lines, columns); // expose resizeEvent
599 resizing = FALSE; 599 resizing = FALSE;
600} 600}
601 601
602/* ------------------------------------------------------------------------- */ 602/* ------------------------------------------------------------------------- */
603/* */ 603/* */
604/* Scrollbar */ 604/* Scrollbar */
605/* */ 605/* */
606/* ------------------------------------------------------------------------- */ 606/* ------------------------------------------------------------------------- */
607 607
608void TEWidget::scrollChanged(int) { 608void TEWidget::scrollChanged(int) {
609 emit changedHistoryCursor(scrollbar->value()); //expose 609 emit changedHistoryCursor(scrollbar->value()); //expose
610} 610}
611 611
612void TEWidget::hScrollChanged(int loc) { 612void TEWidget::hScrollChanged(int loc) {
613 hposition = loc; 613 hposition = loc;
614 propagateSize(); 614 propagateSize();
615 update(); 615 update();
616 616
617// emit changedHorzCursor( hScrollbar->value()); //expose 617// emit changedHorzCursor( hScrollbar->value()); //expose
618} 618}
619 619
620void TEWidget::setScroll(int cursor, int slines) 620void TEWidget::setScroll(int cursor, int slines)
621{ 621{
622 disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 622 disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
623 scrollbar->setRange(0,slines); 623 scrollbar->setRange(0,slines);
624 scrollbar->setSteps(1,lines); 624 scrollbar->setSteps(1,lines);
625 scrollbar->setValue(cursor); 625 scrollbar->setValue(cursor);
626 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 626 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
627} 627}
628 628
629void TEWidget::setScrollbarLocation(int loc) 629void TEWidget::setScrollbarLocation(int loc)
630{ 630{
631 if (scrollLoc == loc) return; // quickly 631 if (scrollLoc == loc) return; // quickly
632 scrollLoc = loc; 632 scrollLoc = loc;
633 propagateSize(); 633 propagateSize();
634 update(); 634 update();
635} 635}
636 636
637/* ------------------------------------------------------------------------- */ 637/* ------------------------------------------------------------------------- */
638/* */ 638/* */
639/* Mouse */ 639/* Mouse */
640/* */ 640/* */
641/* ------------------------------------------------------------------------- */ 641/* ------------------------------------------------------------------------- */
642 642
643/*! 643/*!
644 Three different operations can be performed using the mouse, and the 644 Three different operations can be performed using the mouse, and the
645 routines in this section serve all of them: 645 routines in this section serve all of them:
646 646
647 1) The press/release events are exposed to the application 647 1) The press/release events are exposed to the application
648 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)
649 3) The right mouse button is used from the configuration menu 649 3) The right mouse button is used from the configuration menu
650 650
651 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
652 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
653 whenever the mouse has left the text area. 653 whenever the mouse has left the text area.
654 654
655 Two reasons to do so: 655 Two reasons to do so:
656 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.
657 Thus a `XGrapPointer' would have to be used instead. 657 Thus a `XGrapPointer' would have to be used instead.
658 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
659 of the TEWidget is normally not identical with it's bounds. 659 of the TEWidget is normally not identical with it's bounds.
660 660
661 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
662 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
663 current construction, and the reasons mentioned above, we cannot do better 663 current construction, and the reasons mentioned above, we cannot do better
664 without changing the overall construction. 664 without changing the overall construction.
665*/ 665*/
666 666
667/*! 667/*!
668*/ 668*/
669 669
670void TEWidget::mousePressEvent(QMouseEvent* ev) 670void TEWidget::mousePressEvent(QMouseEvent* ev)
671{ 671{
672//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());
673 if ( !contentsRect().contains(ev->pos()) ) return; 673 if ( !contentsRect().contains(ev->pos()) ) return;
674 QPoint tL = contentsRect().topLeft(); 674 QPoint tL = contentsRect().topLeft();
675 int tLx = tL.x(); 675 int tLx = tL.x();
676 int tLy = tL.y(); 676 int tLy = tL.y();
677 677
678 mouse_down_x = ev->x(); 678 mouse_down_x = ev->x();
679 mouse_down_y = ev->y(); 679 mouse_down_y = ev->y();
680 680
681//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);
682 if ( ev->button() == LeftButton) 682 if ( ev->button() == LeftButton)
683 { 683 {
684 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);
685 685
686 word_selection_mode = (ev->state() & ShiftButton); 686 word_selection_mode = (ev->state() & ShiftButton);
687 687
688 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; 688 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ;
689 689
690 if (mouse_marks || (ev->state() & ShiftButton)) 690 if (mouse_marks || (ev->state() & ShiftButton))
691 { 691 {
692 emit clearSelectionSignal(); 692 emit clearSelectionSignal();
693 iPntSel = pntSel = pos; 693 iPntSel = pntSel = pos;
694 actSel = 1; // left mouse button pressed but nothing selected yet. 694 actSel = 1; // left mouse button pressed but nothing selected yet.
695 grabMouse( /*crossCursor*/ ); // handle with care! 695 grabMouse( /*crossCursor*/ ); // handle with care!
696 } 696 }
697 else 697 else
698 { 698 {
699 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button 699 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button
700 } 700 }
701 } 701 }
702 if ( ev->button() == MidButton ) 702 if ( ev->button() == MidButton )
703 { 703 {
704 emitSelection(); 704 emitSelection();
705 } 705 }
706 if ( ev->button() == RightButton ) // Configure 706 if ( ev->button() == RightButton ) // Configure
707 { 707 {
708 emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() ); 708 emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() );
709 } 709 }
710} 710}
711 711
712void TEWidget::mouseMoveEvent(QMouseEvent* ev) 712void TEWidget::mouseMoveEvent(QMouseEvent* ev)
713{ 713{
714 // for auto-hiding the cursor, we need mouseTracking 714 // for auto-hiding the cursor, we need mouseTracking
715 if (ev->state() == NoButton ) return; 715 if (ev->state() == NoButton ) return;
716 716
717 if (actSel == 0) return; 717 if (actSel == 0) return;
718 718
719 // don't extend selection while pasting 719 // don't extend selection while pasting
720 if (ev->state() & MidButton) return; 720 if (ev->state() & MidButton) return;
721 721
722 //if ( !contentsRect().contains(ev->pos()) ) return; 722 //if ( !contentsRect().contains(ev->pos()) ) return;
723 QPoint tL = contentsRect().topLeft(); 723 QPoint tL = contentsRect().topLeft();
724 int tLx = tL.x(); 724 int tLx = tL.x();
725 int tLy = tL.y(); 725 int tLy = tL.y();
726 int scroll = scrollbar->value(); 726 int scroll = scrollbar->value();
727// int hScroll = hScrollbar->value(); 727// int hScroll = hScrollbar->value();
728 728
729 // 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
730 // 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
731 // this widget. 731 // this widget.
732 732
733 // Adjust position within text area bounds. See FIXME above. 733 // Adjust position within text area bounds. See FIXME above.
734 QPoint pos = ev->pos(); 734 QPoint pos = ev->pos();
735 if ( pos.x() < tLx+blX ) pos.setX( tLx+blX ); 735 if ( pos.x() < tLx+blX ) pos.setX( tLx+blX );
736 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 );
737 if ( pos.y() < tLy+bY ) pos.setY( tLy+bY ); 737 if ( pos.y() < tLy+bY ) pos.setY( tLy+bY );
738 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 );
739 // check if we produce a mouse move event by this 739 // check if we produce a mouse move event by this
740 if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos)); 740 if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos));
741 741
742 if ( pos.y() == tLy+bY+lines*font_h-1 ) 742 if ( pos.y() == tLy+bY+lines*font_h-1 )
743 { 743 {
744 scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward 744 scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward
745 } 745 }
746 if ( pos.y() == tLy+bY ) 746 if ( pos.y() == tLy+bY )
747 { 747 {
748 scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback 748 scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback
749 } 749 }
750 750
751 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);
752 QPoint ohere; 752 QPoint ohere;
753 bool swapping = FALSE; 753 bool swapping = FALSE;
754 754
755 if ( word_selection_mode ) 755 if ( word_selection_mode )
756 { 756 {
757 // Extend to word boundaries 757 // Extend to word boundaries
758 int i; 758 int i;
759 int selClass; 759 int selClass;
760 760
761 bool left_not_right = ( here.y() < iPntSel.y() || 761 bool left_not_right = ( here.y() < iPntSel.y() ||
762 here.y() == iPntSel.y() && here.x() < iPntSel.x() ); 762 here.y() == iPntSel.y() && here.x() < iPntSel.x() );
763 bool old_left_not_right = ( pntSel.y() < iPntSel.y() || 763 bool old_left_not_right = ( pntSel.y() < iPntSel.y() ||
764 pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); 764 pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() );
765 swapping = left_not_right != old_left_not_right; 765 swapping = left_not_right != old_left_not_right;
766 766
767 // Find left (left_not_right ? from here : from start) 767 // Find left (left_not_right ? from here : from start)
768 QPoint left = left_not_right ? here : iPntSel; 768 QPoint left = left_not_right ? here : iPntSel;
769 i = loc(left.x(),left.y()); 769 i = loc(left.x(),left.y());
770 selClass = charClass(image[i].c); 770 selClass = charClass(image[i].c);
771 while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) 771 while ( left.x() > 0 && charClass(image[i-1].c) == selClass )
772 { i--; left.rx()--; } 772 { i--; left.rx()--; }
773 773
774 // Find left (left_not_right ? from start : from here) 774 // Find left (left_not_right ? from start : from here)
775 QPoint right = left_not_right ? iPntSel : here; 775 QPoint right = left_not_right ? iPntSel : here;
776 i = loc(right.x(),right.y()); 776 i = loc(right.x(),right.y());
777 selClass = charClass(image[i].c); 777 selClass = charClass(image[i].c);
778 while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass ) 778 while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass )
779 { i++; right.rx()++; } 779 { i++; right.rx()++; }
780 780
781 // Pick which is start (ohere) and which is extension (here) 781 // Pick which is start (ohere) and which is extension (here)
782 if ( left_not_right ) 782 if ( left_not_right )
783 { 783 {
784 here = left; ohere = right; 784 here = left; ohere = right;
785 } 785 }
786 else 786 else
787 { 787 {
788 here = right; ohere = left; 788 here = right; ohere = left;
789 } 789 }
790 } 790 }
791 791
792 if (here == pntSel && scroll == scrollbar->value()) return; // not moved 792 if (here == pntSel && scroll == scrollbar->value()) return; // not moved
793 793
794 if ( word_selection_mode ) { 794 if ( word_selection_mode ) {
795 if ( actSel < 2 || swapping ) { 795 if ( actSel < 2 || swapping ) {
796 emit beginSelectionSignal( ohere.x(), ohere.y() ); 796 emit beginSelectionSignal( ohere.x(), ohere.y() );
797 } 797 }
798 } else if ( actSel < 2 ) { 798 } else if ( actSel < 2 ) {
799 emit beginSelectionSignal( pntSel.x(), pntSel.y() ); 799 emit beginSelectionSignal( pntSel.x(), pntSel.y() );
800 } 800 }
801 801
802 actSel = 2; // within selection 802 actSel = 2; // within selection
803 pntSel = here; 803 pntSel = here;
804 emit extendSelectionSignal( here.x(), here.y() ); 804 emit extendSelectionSignal( here.x(), here.y() );
805} 805}
806 806
807void TEWidget::mouseReleaseEvent(QMouseEvent* ev) 807void TEWidget::mouseReleaseEvent(QMouseEvent* ev)
808{ 808{
809//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());
810 if ( ev->button() == LeftButton) 810 if ( ev->button() == LeftButton)
811 { 811 {
812 if (QABS(ev->x() - mouse_down_x) < 3 812 if (QABS(ev->x() - mouse_down_x) < 3
813 && QABS(ev->y() - mouse_down_y) < 3 813 && QABS(ev->y() - mouse_down_y) < 3
814 && ev->y() < qApp->desktop()->height()/8) { 814 && ev->y() < qApp->desktop()->height()/8) {
815 emit setFullScreen(false); 815 emit setFullScreen(false);
816 } 816 }
817 817
818 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); 818 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks);
819 preserve_line_breaks = TRUE; 819 preserve_line_breaks = TRUE;
820 actSel = 0; 820 actSel = 0;
821 821
822 //FIXME: emits a release event even if the mouse is 822 //FIXME: emits a release event even if the mouse is
823 // outside the range. The procedure used in `mouseMoveEvent' 823 // outside the range. The procedure used in `mouseMoveEvent'
824 // applies here, too. 824 // applies here, too.
825 825
826 QPoint tL = contentsRect().topLeft(); 826 QPoint tL = contentsRect().topLeft();
827 int tLx = tL.x(); 827 int tLx = tL.x();
828 int tLy = tL.y(); 828 int tLy = tL.y();
829 829
830 if (!mouse_marks && !(ev->state() & ShiftButton)) 830 if (!mouse_marks && !(ev->state() & ShiftButton))
831 emit mouseSignal( 3, // release 831 emit mouseSignal( 3, // release
832 (ev->x()-tLx-blX)/font_w + 1, 832 (ev->x()-tLx-blX)/font_w + 1,
833 (ev->y()-tLy-bY)/font_h + 1 ); 833 (ev->y()-tLy-bY)/font_h + 1 );
834 releaseMouse(); 834 releaseMouse();
835 } 835 }
836} 836}
837 837
838void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev) 838void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev)
839{ 839{
840 if ( ev->button() != LeftButton) return; 840 if ( ev->button() != LeftButton) return;
841 841
842 QPoint tL = contentsRect().topLeft(); 842 QPoint tL = contentsRect().topLeft();
843 int tLx = tL.x(); 843 int tLx = tL.x();
844 int tLy = tL.y(); 844 int tLy = tL.y();
845 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);
846 846
847 // pass on double click as two clicks. 847 // pass on double click as two clicks.
848 if (!mouse_marks && !(ev->state() & ShiftButton)) 848 if (!mouse_marks && !(ev->state() & ShiftButton))
849 { 849 {
850 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 850 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
851 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release 851 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release
852 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 852 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
853 return; 853 return;
854 } 854 }
855 855
856 856
857 emit clearSelectionSignal(); 857 emit clearSelectionSignal();
858 QPoint bgnSel = pos; 858 QPoint bgnSel = pos;
859 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);
860 int i = loc(bgnSel.x(),bgnSel.y()); 860 int i = loc(bgnSel.x(),bgnSel.y());
861 iPntSel = bgnSel; 861 iPntSel = bgnSel;
862 862
863 word_selection_mode = TRUE; 863 word_selection_mode = TRUE;
864 864
865 // find word boundaries... 865 // find word boundaries...
866 int selClass = charClass(image[i].c); 866 int selClass = charClass(image[i].c);
867 { 867 {
868 // set the start... 868 // set the start...
869 int x = bgnSel.x(); 869 int x = bgnSel.x();
870 while ( x > 0 && charClass(image[i-1].c) == selClass ) 870 while ( x > 0 && charClass(image[i-1].c) == selClass )
871 { i--; x--; } 871 { i--; x--; }
872 bgnSel.setX(x); 872 bgnSel.setX(x);
873 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); 873 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() );
874 874
875 // set the end... 875 // set the end...
876 i = loc( endSel.x(), endSel.y() ); 876 i = loc( endSel.x(), endSel.y() );
877 x = endSel.x(); 877 x = endSel.x();
878 while( x < columns-1 && charClass(image[i+1].c) == selClass ) 878 while( x < columns-1 && charClass(image[i+1].c) == selClass )
879 { i++; x++ ; } 879 { i++; x++ ; }
880 endSel.setX(x); 880 endSel.setX(x);
881 actSel = 2; // within selection 881 actSel = 2; // within selection
882 emit extendSelectionSignal( endSel.x(), endSel.y() ); 882 emit extendSelectionSignal( endSel.x(), endSel.y() );
883 emit endSelectionSignal(preserve_line_breaks); 883 emit endSelectionSignal(preserve_line_breaks);
884 preserve_line_breaks = TRUE; 884 preserve_line_breaks = TRUE;
885 } 885 }
886} 886}
887 887
888void TEWidget::focusInEvent( QFocusEvent * ) 888void TEWidget::focusInEvent( QFocusEvent * )
889{ 889{
890 890
891 // do nothing, to prevent repainting 891 // do nothing, to prevent repainting
892} 892}
893 893
894 894
895void TEWidget::focusOutEvent( QFocusEvent * ) 895void TEWidget::focusOutEvent( QFocusEvent * )
896{ 896{
897 // do nothing, to prevent repainting 897 // do nothing, to prevent repainting
898} 898}
899 899
900bool TEWidget::focusNextPrevChild( bool next ) 900bool TEWidget::focusNextPrevChild( bool next )
901{ 901{
902 if (next) 902 if (next)
903 return false; // This disables changing the active part in konqueror 903 return false; // This disables changing the active part in konqueror
904 // when pressing Tab 904 // when pressing Tab
905 return QFrame::focusNextPrevChild( next ); 905 return QFrame::focusNextPrevChild( next );
906} 906}
907 907
908 908
909int TEWidget::charClass(char ch) const 909int TEWidget::charClass(char ch) const
910{ 910{
911 // 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
912 // 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
913 // the different language ranges, etc. 913 // the different language ranges, etc.
914 914
915 if ( isspace(ch) ) return ' '; 915 if ( isspace(ch) ) return ' ';
916 916
917 static const char *word_characters = ":@-./_~"; 917 static const char *word_characters = ":@-./_~";
918 if ( isalnum(ch) || strchr(word_characters, ch) ) 918 if ( isalnum(ch) || strchr(word_characters, ch) )
919 return 'a'; 919 return 'a';
920 920
921 // Everything else is weird 921 // Everything else is weird
922 return 1; 922 return 1;
923} 923}
924 924
925void TEWidget::setMouseMarks(bool on) 925void TEWidget::setMouseMarks(bool on)
926{ 926{
927 mouse_marks = on; 927 mouse_marks = on;
928 setCursor( mouse_marks ? ibeamCursor : arrowCursor ); 928 setCursor( mouse_marks ? ibeamCursor : arrowCursor );
929} 929}
930 930
931/* ------------------------------------------------------------------------- */ 931/* ------------------------------------------------------------------------- */
932/* */ 932/* */
933/* Clipboard */ 933/* Clipboard */
934/* */ 934/* */
935/* ------------------------------------------------------------------------- */ 935/* ------------------------------------------------------------------------- */
936 936
937#undef KeyPress 937#undef KeyPress
938 938
939void TEWidget::emitSelection() 939void TEWidget::emitSelection()
940// Paste Clipboard by simulating keypress events 940// Paste Clipboard by simulating keypress events
941{ 941{
942#ifndef QT_NO_CLIPBOARD 942#ifndef QT_NO_CLIPBOARD
943 QString text = QApplication::clipboard()->text(); 943 QString text = QApplication::clipboard()->text();
944 //odebug << text << oendl; 944 //odebug << text << oendl;
945 if ( ! text.isNull()) 945 if ( ! text.isNull())
946 { 946 {
947 text.replace(QRegExp("\n"), "\r"); 947 text.replace(QRegExp("\n"), "\r");
948 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 948 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
949 emit keyPressedSignal(&e); // expose as a big fat keypress event 949 emit keyPressedSignal(&e); // expose as a big fat keypress event
950 emit clearSelectionSignal(); 950 emit clearSelectionSignal();
951 } 951 }
952#endif 952#endif
953} 953}
954 954
955void TEWidget::emitText(QString text) 955void TEWidget::emitText(QString text)
956{ 956{
957 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 957 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
958 emit keyPressedSignal(&e); // expose as a big fat keypress event 958 emit keyPressedSignal(&e); // expose as a big fat keypress event
959} 959}
960 960
961void TEWidget::pasteClipboard( ) 961void TEWidget::pasteClipboard( )
962{ 962{
963 emitSelection(); 963 emitSelection();
964} 964}
965 965
966void TEWidget::setSelection(const QString& t) 966void TEWidget::setSelection(const QString& t)
967{ 967{
968#ifndef QT_NO_CLIPBOARD 968#ifndef QT_NO_CLIPBOARD
969 // Disconnect signal while WE set the clipboard 969 // Disconnect signal while WE set the clipboard
970 QObject *cb = QApplication::clipboard(); 970 QObject *cb = QApplication::clipboard();
971 QObject::disconnect( cb, SIGNAL(dataChanged()), 971 QObject::disconnect( cb, SIGNAL(dataChanged()),
972 this, SLOT(onClearSelection()) ); 972 this, SLOT(onClearSelection()) );
973 973
974 QApplication::clipboard()->setText(t); 974 QApplication::clipboard()->setText(t);
975 975
976 QObject::connect( cb, SIGNAL(dataChanged()), 976 QObject::connect( cb, SIGNAL(dataChanged()),
977 this, SLOT(onClearSelection()) ); 977 this, SLOT(onClearSelection()) );
978#endif 978#endif
979} 979}
980 980
981void TEWidget::onClearSelection() 981void TEWidget::onClearSelection()
982{ 982{
983 emit clearSelectionSignal(); 983 emit clearSelectionSignal();
984} 984}
985 985
986/* ------------------------------------------------------------------------- */ 986/* ------------------------------------------------------------------------- */
987/* */ 987/* */
988/* Keyboard */ 988/* Keyboard */
989/* */ 989/* */
990/* ------------------------------------------------------------------------- */ 990/* ------------------------------------------------------------------------- */
991 991
992//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' 992//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent'
993// 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
994// repaint events being emitted to the screen whenever one leaves 994// repaint events being emitted to the screen whenever one leaves
995// or reenters the screen to/from another application. 995// or reenters the screen to/from another application.
996// 996//
997// Troll says one needs to change focusInEvent() and focusOutEvent(), 997// Troll says one needs to change focusInEvent() and focusOutEvent(),
998// 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
999// cursor like xterm does. 999// cursor like xterm does.
1000 1000
1001// for the auto-hide cursor feature, I added empty focusInEvent() and 1001// for the auto-hide cursor feature, I added empty focusInEvent() and
1002// focusOutEvent() so that update() isn't called. 1002// focusOutEvent() so that update() isn't called.
1003// 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
1004// we have focus. 1004// we have focus.
1005 1005
1006void TEWidget::doScroll(int lines) 1006void TEWidget::doScroll(int lines)
1007{ 1007{
1008 scrollbar->setValue(scrollbar->value()+lines); 1008 scrollbar->setValue(scrollbar->value()+lines);
1009} 1009}
1010 1010
1011void TEWidget::doHScroll(int lines) { 1011void TEWidget::doHScroll(int lines) {
1012 hScrollbar->setValue( hScrollbar->value()+lines); 1012 hScrollbar->setValue( hScrollbar->value()+lines);
1013} 1013}
1014 1014
1015bool TEWidget::eventFilter( QObject *obj, QEvent *e ) 1015bool TEWidget::eventFilter( QObject *obj, QEvent *e )
1016{ 1016{
1017 if ( (e->type() == QEvent::Accel || 1017 if ( (e->type() == QEvent::Accel ||
1018 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { 1018 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) {
1019 static_cast<QKeyEvent *>( e )->ignore(); 1019 static_cast<QKeyEvent *>( e )->ignore();
1020 return true; 1020 return true;
1021 } 1021 }
1022 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) 1022 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ )
1023 return FALSE; // not us 1023 return FALSE; // not us
1024 if ( e->type() == QEvent::Wheel) { 1024 if ( e->type() == QEvent::Wheel) {
1025 QApplication::sendEvent(scrollbar, e); 1025 QApplication::sendEvent(scrollbar, e);
1026 } 1026 }
1027 1027
1028#ifdef FAKE_CTRL_AND_ALT 1028#ifdef FAKE_CTRL_AND_ALT
1029 static bool control = FALSE; 1029 static bool control = FALSE;
1030 static bool alt = FALSE; 1030 static bool alt = FALSE;
1031// odebug << " Has a keyboard with no CTRL and ALT keys, but we fake it:" << oendl; 1031// odebug << " Has a keyboard with no CTRL and ALT keys, but we fake it:" << oendl;
1032 bool dele=FALSE; 1032 bool dele=FALSE;
1033 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 1033 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
1034 QKeyEvent* ke = (QKeyEvent*)e; 1034 QKeyEvent* ke = (QKeyEvent*)e;
1035 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); 1035 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat();
1036 switch (ke->key()) { 1036 switch (ke->key()) {
1037 case Key_F9: // let this be "Control" 1037 case Key_F9: // let this be "Control"
1038 control = keydown; 1038 control = keydown;
1039 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); 1039 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state());
1040 dele=TRUE; 1040 dele=TRUE;
1041 break; 1041 break;
1042 case Key_F13: // let this be "Alt" 1042 case Key_F13: // let this be "Alt"
1043 alt = keydown; 1043 alt = keydown;
1044 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); 1044 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state());
1045 dele=TRUE; 1045 dele=TRUE;
1046 break; 1046 break;
1047 default: 1047 default:
1048 if ( control ) { 1048 if ( control ) {
1049 int a = toupper(ke->ascii())-64; 1049 int a = toupper(ke->ascii())-64;
1050 if ( a >= 0 && a < ' ' ) { 1050 if ( a >= 0 && a < ' ' ) {
1051 e = new QKeyEvent(e->type(), ke->key(), 1051 e = new QKeyEvent(e->type(), ke->key(),
1052 a, ke->state()|ControlButton, QChar(a,0)); 1052 a, ke->state()|ControlButton, QChar(a,0));
1053 dele=TRUE; 1053 dele=TRUE;
1054 } 1054 }
1055 } 1055 }
1056 if ( alt ) { 1056 if ( alt ) {
1057 e = new QKeyEvent(e->type(), ke->key(), 1057 e = new QKeyEvent(e->type(), ke->key(),
1058 ke->ascii(), ke->state()|AltButton, ke->text()); 1058 ke->ascii(), ke->state()|AltButton, ke->text());
1059 dele=TRUE; 1059 dele=TRUE;
1060 } 1060 }
1061 } 1061 }
1062 } 1062 }
1063#endif 1063#endif
1064 1064
1065 if ( e->type() == QEvent::KeyPress ) { 1065 if ( e->type() == QEvent::KeyPress ) {
1066 QKeyEvent* ke = (QKeyEvent*)e; 1066 QKeyEvent* ke = (QKeyEvent*)e;
1067 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
1068 // know where the current selection is. 1068 // know where the current selection is.
1069 1069
1070// odebug << "key pressed is 0x" << ke->key() << ", ascii is 0x" << ke->ascii() << ", state " << ke->state() << "" << oendl; 1070// odebug << "key pressed is 0x" << ke->key() << ", ascii is 0x" << ke->ascii() << ", state " << ke->state() << "" << oendl;
1071 1071
1072 bool special_function = true; 1072 bool special_function = true;
1073 switch(ke->key()) { 1073 switch(ke->key()) {
1074 //case 0x201b: // fn-5 1074 //case 0x201b: // fn-5
1075 //case Key_F1: 1075 //case Key_F1:
1076 // switch sessions (?) 1076 // switch sessions (?)
1077 // emitText("\\"); // expose (??) 1077 // emitText("\\"); // expose (??)
1078 // break; 1078 // break;
1079 1079
1080 case 0x2016: // fn-p 1080 case 0x2016: // fn-p
1081 case Key_F2: 1081 case Key_F2:
1082 pasteClipboard(); 1082 pasteClipboard();
1083 break; 1083 break;
1084 1084
1085 case 0x2018: // fn-S 1085 case 0x2018: // fn-S
1086 case Key_F3: 1086 case Key_F3:
1087 emit changeSession(1); 1087 emit changeSession(1);
1088 break; 1088 break;
1089 1089
1090 case 0x2019: // fn-n 1090 case 0x2019: // fn-n
1091 emit newSession(); 1091 emit newSession();
1092 break; 1092 break;
1093 1093
1094 case Qt::Key_Tab: 1094 case Qt::Key_Tab:
1095 if (ke->state() == ControlButton) { 1095 if (ke->state() == ControlButton) {
1096 emit changeSession(1); 1096 emit changeSession(1);
1097 } else { 1097 } else {
1098 special_function = false; 1098 special_function = false;
1099 } 1099 }
1100 break; 1100 break;
1101 1101
1102#if 0 1102#if 0
1103 case Qt::Key_Left: 1103 case Qt::Key_Left:
1104 if (vcolumns == 0) { 1104 if (vcolumns == 0) {
1105 emit changeSession(-1); 1105 emit changeSession(-1);
1106 } else { 1106 } else {
1107 special_function = false; 1107 special_function = false;
1108 } 1108 }
1109 break; 1109 break;
1110 1110
1111 case Qt::Key_Right: 1111 case Qt::Key_Right:
1112 if (vcolumns == 0) { 1112 if (vcolumns == 0) {
1113 emit changeSession(1); 1113 emit changeSession(1);
1114 } else { 1114 } else {
1115 special_function = false; 1115 special_function = false;
1116 } 1116 }
1117 break; 1117 break;
1118#endif 1118#endif
1119 1119
1120 case 0x201b: // fn-5 1120 case 0x201b: // fn-5
1121 case Key_F4: 1121 case Key_F4:
1122 emit toggleFullScreen(); 1122 emit toggleFullScreen();
1123 break; 1123 break;
1124 1124
1125 case 0x200f: // fn-1 magnify minus 1125 case 0x200f: // fn-1 magnify minus
1126 case Key_F5: 1126 case Key_F5:
1127 emit changeFontSize(-1); 1127 emit changeFontSize(-1);
1128 break; 1128 break;
1129 1129
1130 case 0x2010: // fn-2 magnify plus 1130 case 0x2010: // fn-2 magnify plus
1131 case Key_F6: 1131 case Key_F6:
1132 emit changeFontSize(1); 1132 emit changeFontSize(1);
1133 break; 1133 break;
1134 1134
1135 default: 1135 default:
1136 special_function = false; 1136 special_function = false;
1137 } 1137 }
1138 if (special_function) { 1138 if (special_function) {
1139 return true; 1139 return true;
1140 } 1140 }
1141 // else if( ke->state() == ControlButton && ke->key() == Key_V) { 1141 // else if( ke->state() == ControlButton && ke->key() == Key_V) {
1142 // pasteClipboard(); 1142 // pasteClipboard();
1143 // } 1143 // }
1144 // else if( ke->state() == ControlButton && ke->key() == Key_C) { 1144 // else if( ke->state() == ControlButton && ke->key() == Key_C) {
1145 // pasteClipboard(); 1145 // pasteClipboard();
1146 // } 1146 // }
1147 emit keyPressedSignal(ke); // expose 1147 emit keyPressedSignal(ke); // expose
1148 ke->accept(); 1148 ke->accept();
1149#ifdef FAKE_CTRL_AND_ALT 1149#ifdef FAKE_CTRL_AND_ALT
1150 if ( dele ) delete e; 1150 if ( dele ) delete e;
1151#endif 1151#endif
1152 return true; // stop the event 1152 return true; // stop the event
1153 } 1153 }
1154 if ( e->type() == QEvent::Enter ) { 1154 if ( e->type() == QEvent::Enter ) {
1155 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), 1155 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()),
1156 this, SLOT(onClearSelection()) ); 1156 this, SLOT(onClearSelection()) );
1157 } 1157 }
1158 if ( e->type() == QEvent::Leave ) { 1158 if ( e->type() == QEvent::Leave ) {
1159 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 1159 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
1160 this, SLOT(onClearSelection()) ); 1160 this, SLOT(onClearSelection()) );
1161 } 1161 }
1162 return QFrame::eventFilter( obj, e ); 1162 return QFrame::eventFilter( obj, e );
1163} 1163}
1164 1164
1165/* ------------------------------------------------------------------------- */ 1165/* ------------------------------------------------------------------------- */
1166/* */ 1166/* */
1167/* Frame */ 1167/* Frame */
1168/* */ 1168/* */
1169/* ------------------------------------------------------------------------- */ 1169/* ------------------------------------------------------------------------- */
1170 1170
1171void TEWidget::frameChanged() 1171void TEWidget::frameChanged()
1172{ 1172{
1173 propagateSize(); 1173 propagateSize();
1174 update(); 1174 update();
1175} 1175}
1176/* ------------------------------------------------------------------------- */ 1176/* ------------------------------------------------------------------------- */
1177/* */ 1177/* */
1178/* Sound */ 1178/* Sound */
1179/* */ 1179/* */
1180/* ------------------------------------------------------------------------- */ 1180/* ------------------------------------------------------------------------- */
1181 1181
1182void TEWidget::Bell() 1182void TEWidget::Bell()
1183{ 1183{
1184//#ifdef QT_QWS_SL5XXX 1184//#ifdef QT_QWS_SL5XXX
1185//# ifndef QT_NO_COP 1185//# ifndef QT_NO_COP
1186 if(useBeep) 1186 if(useBeep)
1187 QCopEnvelope( "QPE/TaskBar", "soundAlarm()" ); 1187 QCopEnvelope( "QPE/TaskBar", "soundAlarm()" );
1188 1188
1189//# endif 1189//# endif
1190//#else 1190//#else
1191//# ifndef QT_NO_SOUND 1191//# ifndef QT_NO_SOUND
1192// QSound::play(Resource::findSound("alarm")); 1192// QSound::play(Resource::findSound("alarm"));
1193//# endif 1193//# endif
1194//#endif 1194//#endif
1195 1195
1196// QApplication::beep(); 1196// QApplication::beep();
1197} 1197}
1198 1198
1199/* ------------------------------------------------------------------------- */ 1199/* ------------------------------------------------------------------------- */
1200/* */ 1200/* */
1201/* Auxiluary */ 1201/* Auxiluary */
1202/* */ 1202/* */
1203/* ------------------------------------------------------------------------- */ 1203/* ------------------------------------------------------------------------- */
1204 1204
1205void TEWidget::clearImage() 1205void TEWidget::clearImage()
1206// initialize the image 1206// initialize the image
1207// for internal use only 1207// for internal use only
1208{ 1208{
1209 for (int y = 0; y < lines; y++) 1209 for (int y = 0; y < lines; y++)
1210 for (int x = 0; x < columns; x++) 1210 for (int x = 0; x < columns; x++)
1211 { 1211 {
1212 image[loc(x,y)].c = 0xff; //' '; 1212 image[loc(x,y)].c = 0xff; //' ';
1213 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; 1213 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR;
1214 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; 1214 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR;
1215 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; 1215 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION;
1216 } 1216 }
1217} 1217}
1218 1218
1219// Create Image /////////////////////////////////////////////////////// 1219// Create Image ///////////////////////////////////////////////////////
1220 1220
1221void TEWidget::calcGeometry() 1221void TEWidget::calcGeometry()
1222{ 1222{
1223 int showhscrollbar = 1; 1223 int showhscrollbar = 1;
1224 int hwidth = 0; 1224 int hwidth = 0;
1225 int dcolumns = 0; 1225 int dcolumns = 0;
1226 Config cfg( "Konsole" ); 1226 Config cfg( "Konsole" );
1227 cfg.setGroup("ScrollBar"); 1227 cfg.setGroup("ScrollBar");
1228 useHorzScroll=cfg.readBoolEntry("HorzScroll",0); 1228 useHorzScroll=cfg.readBoolEntry("HorzScroll",0);
1229 1229
1230 if(vcolumns == 0) showhscrollbar = 0; 1230 if(vcolumns == 0) showhscrollbar = 0;
1231 if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width(); 1231 if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width();
1232 1232
1233 scrollbar->resize(QApplication::style().scrollBarExtent().width(), 1233 scrollbar->resize(QApplication::style().scrollBarExtent().width(),
1234 contentsRect().height() - hwidth); 1234 contentsRect().height() - hwidth);
1235 1235
1236 switch(scrollLoc) { 1236 switch(scrollLoc) {
1237 case SCRNONE : 1237 case SCRNONE :
1238 columns = ( contentsRect().width() - 2 * rimX ) / font_w; 1238 columns = ( contentsRect().width() - 2 * rimX ) / font_w;
1239 dcolumns = columns; 1239 dcolumns = columns;
1240 if(vcolumns) columns = vcolumns; 1240 if(vcolumns) columns = vcolumns;
1241 blX = (contentsRect().width() - (columns*font_w) ) / 2; 1241 blX = (contentsRect().width() - (columns*font_w) ) / 2;
1242 if(showhscrollbar) 1242 if(showhscrollbar)
1243 blX = -hposition * font_w; 1243 blX = -hposition * font_w;
1244 brX = blX; 1244 brX = blX;
1245 scrollbar->hide(); 1245 scrollbar->hide();
1246 break; 1246 break;
1247 case SCRLEFT : 1247 case SCRLEFT :
1248 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1248 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1249 dcolumns = columns; 1249 dcolumns = columns;
1250 if(vcolumns) columns = vcolumns; 1250 if(vcolumns) columns = vcolumns;
1251 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1251 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1252 if(showhscrollbar) 1252 if(showhscrollbar)
1253 brX = -hposition * font_w; 1253 brX = -hposition * font_w;
1254 blX = brX + scrollbar->width(); 1254 blX = brX + scrollbar->width();
1255 scrollbar->move(contentsRect().topLeft()); 1255 scrollbar->move(contentsRect().topLeft());
1256 scrollbar->show(); 1256 scrollbar->show();
1257 break; 1257 break;
1258 case SCRRIGHT: 1258 case SCRRIGHT:
1259 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1259 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1260 dcolumns = columns; 1260 dcolumns = columns;
1261 if(vcolumns) columns = vcolumns; 1261 if(vcolumns) columns = vcolumns;
1262 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1262 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1263 if(showhscrollbar) 1263 if(showhscrollbar)
1264 blX = -hposition * font_w; 1264 blX = -hposition * font_w;
1265 brX = blX; 1265 brX = blX;
1266 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); 1266 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0));
1267 scrollbar->show(); 1267 scrollbar->show();
1268 break; 1268 break;
1269 } 1269 }
1270 //FIXME: support 'rounding' styles 1270 //FIXME: support 'rounding' styles
1271 lines = ( contentsRect().height() - 2 * rimY ) / font_h; 1271 lines = ( contentsRect().height() - 2 * rimY ) / font_h;
1272 bY = (contentsRect().height() - (lines *font_h)) / 2; 1272 bY = (contentsRect().height() - (lines *font_h)) / 2;
1273 1273
1274 if(showhscrollbar == 1) { 1274 if(showhscrollbar == 1) {
1275 hScrollbar->resize(contentsRect().width() - hwidth, hwidth); 1275 hScrollbar->resize(contentsRect().width() - hwidth, hwidth);
1276 hScrollbar->setRange(0, vcolumns - dcolumns); 1276 hScrollbar->setRange(0, vcolumns - dcolumns);
1277 1277
1278 QPoint p = contentsRect().bottomLeft(); 1278 QPoint p = contentsRect().bottomLeft();
1279 if(scrollLoc == SCRLEFT) 1279 if(scrollLoc == SCRLEFT)
1280 hScrollbar->move(QPoint(p.x()+hwidth, p.y() - hwidth)); 1280 hScrollbar->move(QPoint(p.x()+hwidth, p.y() - hwidth));
1281 else 1281 else
1282 hScrollbar->move(QPoint(p.x(), p.y() - hwidth)); 1282 hScrollbar->move(QPoint(p.x(), p.y() - hwidth));
1283 1283
1284 hScrollbar->show(); 1284 hScrollbar->show();
1285 } 1285 }
1286 else hScrollbar->hide(); 1286 else hScrollbar->hide();
1287 1287
1288 if(showhscrollbar == 1) { 1288 if(showhscrollbar == 1) {
1289 lines = lines - (hwidth / font_h) - 1; 1289 lines = lines - (hwidth / font_h) - 1;
1290 if(lines < 1) lines = 1; 1290 if(lines < 1) lines = 1;
1291 } 1291 }
1292 //FIXME: support 'rounding' styles 1292 //FIXME: support 'rounding' styles
1293} 1293}
1294 1294
1295void TEWidget::makeImage() 1295void TEWidget::makeImage()
1296//FIXME: rename 'calcGeometry? 1296//FIXME: rename 'calcGeometry?
1297{ 1297{
1298 calcGeometry(); 1298 calcGeometry();
1299 image = (ca*) malloc(lines*columns*sizeof(ca)); 1299 image = (ca*) malloc(lines*columns*sizeof(ca));
1300 clearImage(); 1300 clearImage();
1301} 1301}
1302 1302
1303// calculate the needed size 1303// calculate the needed size
1304QSize TEWidget::calcSize(int cols, int lins) const 1304QSize TEWidget::calcSize(int cols, int lins) const
1305{ 1305{
1306 int frw = width() - contentsRect().width(); 1306 int frw = width() - contentsRect().width();
1307 int frh = height() - contentsRect().height(); 1307 int frh = height() - contentsRect().height();
1308 int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); 1308 int scw = (scrollLoc==SCRNONE?0:scrollbar->width());
1309 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 );
1310} 1310}
1311 1311
1312QSize TEWidget::sizeHint() const 1312QSize TEWidget::sizeHint() const
1313{ 1313{
1314 return size(); 1314 return size();
1315} 1315}
1316 1316
1317void TEWidget::styleChange(QStyle &) 1317void TEWidget::styleChange(QStyle &)
1318{ 1318{
1319 propagateSize(); 1319 propagateSize();
1320} 1320}
1321 1321
1322#ifndef QT_NO_DRAGANDDROP 1322#ifndef QT_NO_DRAGANDDROP
1323 1323
1324/* --------------------------------------------------------------------- */ 1324/* --------------------------------------------------------------------- */
1325/* */ 1325/* */
1326/* Drag & Drop */ 1326/* Drag & Drop */
1327/* */ 1327/* */
1328/* --------------------------------------------------------------------- */ 1328/* --------------------------------------------------------------------- */
1329 1329
1330 1330
1331void TEWidget::dragEnterEvent(QDragEnterEvent* e) 1331void TEWidget::dragEnterEvent(QDragEnterEvent* e)
1332{ 1332{
1333 e->accept(QTextDrag::canDecode(e) || 1333 e->accept(QTextDrag::canDecode(e) ||
1334 QUriDrag::canDecode(e)); 1334 QUriDrag::canDecode(e));
1335} 1335}
1336 1336
1337void TEWidget::dropEvent(QDropEvent* event) 1337void TEWidget::dropEvent(QDropEvent* event)
1338{ 1338{
1339 // The current behaviour when url(s) are dropped is 1339 // The current behaviour when url(s) are dropped is
1340 // * 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
1341 // * in all other cases, just paste 1341 // * in all other cases, just paste
1342 // (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)
1343 QStrList strlist; 1343 QStrList strlist;
1344 int file_count = 0; 1344 int file_count = 0;
1345 dropText = ""; 1345 dropText = "";
1346 bool bPopup = true; 1346 bool bPopup = true;
1347 1347
1348 if(QUriDrag::decode(event, strlist)) { 1348 if(QUriDrag::decode(event, strlist)) {
1349 if (strlist.count()) { 1349 if (strlist.count()) {
1350 for(const char* p = strlist.first(); p; p = strlist.next()) { 1350 for(const char* p = strlist.first(); p; p = strlist.next()) {
1351 if(file_count++ > 0) { 1351 if(file_count++ > 0) {
1352 dropText += " "; 1352 dropText += " ";
1353 bPopup = false; // more than one file, don't popup 1353 bPopup = false; // more than one file, don't popup
1354 } 1354 }
1355 1355
1356/* 1356/*
1357 KURL url(p); 1357 KURL url(p);
1358 if (url.isLocalFile()) { 1358 if (url.isLocalFile()) {
1359 dropText += url.path(); // local URL : remove protocol 1359 dropText += url.path(); // local URL : remove protocol
1360 } 1360 }
1361 else { 1361 else {
1362 dropText += url.prettyURL(); 1362 dropText += url.prettyURL();
1363 bPopup = false; // a non-local file, don't popup 1363 bPopup = false; // a non-local file, don't popup
1364 } 1364 }
1365*/ 1365*/
1366 1366
1367 } 1367 }
1368 1368
1369 if (bPopup) 1369 if (bPopup)
1370 // m_drop->popup(pos() + event->pos()); 1370 // m_drop->popup(pos() + event->pos());
1371 m_drop->popup(mapToGlobal(event->pos())); 1371 m_drop->popup(mapToGlobal(event->pos()));
1372 else 1372 else
1373 { 1373 {
1374 if (currentSession) { 1374 if (currentSession) {
1375 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1375 currentSession->getEmulation()->sendString(dropText.local8Bit());
1376 } 1376 }
1377// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1377// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1378 } 1378 }
1379 } 1379 }
1380 } 1380 }
1381 else if(QTextDrag::decode(event, dropText)) { 1381 else if(QTextDrag::decode(event, dropText)) {
1382// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1382// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1383 if (currentSession) { 1383 if (currentSession) {
1384 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1384 currentSession->getEmulation()->sendString(dropText.local8Bit());
1385 } 1385 }
1386 // Paste it 1386 // Paste it
1387 } 1387 }
1388} 1388}
1389#endif 1389#endif
1390 1390
1391 1391
1392void TEWidget::drop_menu_activated(int item) 1392void TEWidget::drop_menu_activated(int item)
1393{ 1393{
1394#ifndef QT_NO_DRAGANDDROP 1394#ifndef QT_NO_DRAGANDDROP
1395 switch (item) 1395 switch (item)
1396 { 1396 {
1397 case 0: // paste 1397 case 0: // paste
1398 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1398 currentSession->getEmulation()->sendString(dropText.local8Bit());
1399// KWM::activate((Window)this->winId()); 1399// KWM::activate((Window)this->winId());
1400 break; 1400 break;
1401 case 1: // cd ... 1401 case 1: // cd ...
1402 currentSession->getEmulation()->sendString("cd "); 1402 currentSession->getEmulation()->sendString("cd ");
1403 struct stat statbuf; 1403 struct stat statbuf;
1404 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) 1404 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 )
1405 { 1405 {
1406 if ( !S_ISDIR(statbuf.st_mode) ) 1406 if ( !S_ISDIR(statbuf.st_mode) )
1407 { 1407 {
1408/* 1408/*
1409 KURL url; 1409 KURL url;
1410 url.setPath( dropText ); 1410 url.setPath( dropText );
1411 dropText = url.directory( true, false ); // remove filename 1411 dropText = url.directory( true, false ); // remove filename
1412*/ 1412*/
1413 } 1413 }
1414 } 1414 }
1415 dropText.replace(QRegExp(" "), "\\ "); // escape spaces 1415 dropText.replace(QRegExp(" "), "\\ "); // escape spaces
1416 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1416 currentSession->getEmulation()->sendString(dropText.local8Bit());
1417 currentSession->getEmulation()->sendString("\n"); 1417 currentSession->getEmulation()->sendString("\n");
1418// KWM::activate((Window)this->winId()); 1418// KWM::activate((Window)this->winId());
1419 break; 1419 break;
1420 } 1420 }
1421#else 1421#else
1422 Q_UNUSED(item); 1422 Q_UNUSED(item);
1423#endif 1423#endif
1424} 1424}
1425 1425
1426void TEWidget::setWrapAt(int columns) 1426void TEWidget::setWrapAt(int columns)
1427{ 1427{
1428 vcolumns = columns; 1428 vcolumns = columns;
1429 propagateSize(); 1429 propagateSize();
1430 update(); 1430 update();
1431} 1431}
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index cabeb20..c7273c5 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -1,1208 +1,1208 @@
1/********************************************************************** 1/**********************************************************************
2// textedit.cpp 2// textedit.cpp
3** Copyright (C) 2000 Trolltech AS. All rights reserved. 3** Copyright (C) 2000 Trolltech AS. All rights reserved.
4** 4**
5** This file is part of Opie Environment. 5** This file is part of Opie Environment.
6** 6**
7** This file may be distributed and/or modified under the terms of the 7** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software 8** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file. 10** packaging of this file.
11** 11**
12**********************************************************************/ 12**********************************************************************/
13// changes added by L. J. Potter Sun 02-17-2002 21:31:31 13// changes added by L. J. Potter Sun 02-17-2002 21:31:31
14 14
15#include "textedit.h" 15#include "textedit.h"
16#include "filePermissions.h" 16#include "filePermissions.h"
17 17
18/* OPIE */ 18/* OPIE */
19#include <opie2/odebug.h> 19#include <opie2/odebug.h>
20#include <opie2/ofileselector.h> 20#include <opie2/ofileselector.h>
21#include <opie2/ofiledialog.h> 21#include <opie2/ofiledialog.h>
22#include <opie2/ofontselector.h> 22#include <opie2/ofontselector.h>
23#include <qpe/resource.h> 23#include <qpe/resource.h>
24#include <qpe/config.h> 24#include <qpe/config.h>
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26 26
27 27
28/* QT */ 28/* QT */
29#include <qmenubar.h> 29#include <qmenubar.h>
30#include <qtoolbar.h> 30#include <qtoolbar.h>
31#include <qtextstream.h> 31#include <qtextstream.h>
32#include <qclipboard.h> 32#include <qclipboard.h>
33#include <qaction.h> 33#include <qaction.h>
34#include <qlineedit.h> 34#include <qlineedit.h>
35#include <qmessagebox.h> 35#include <qmessagebox.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qtimer.h> 37#include <qtimer.h>
38#include <qdir.h> 38#include <qdir.h>
39 39
40/* STD */ 40/* STD */
41#include <unistd.h> 41#include <unistd.h>
42#include <sys/stat.h> 42#include <sys/stat.h>
43#include <stdlib.h> //getenv 43#include <stdlib.h> //getenv
44 44
45using namespace Opie::Core; 45using namespace Opie::Core;
46using namespace Opie::Ui; 46using namespace Opie::Ui;
47 47
48#if QT_VERSION < 300 48#if QT_VERSION < 0x030000
49class QpeEditor : public QMultiLineEdit 49class QpeEditor : public QMultiLineEdit
50{ 50{
51 51
52public: 52public:
53 QpeEditor( QWidget *parent, const char * name = 0 ) 53 QpeEditor( QWidget *parent, const char * name = 0 )
54 : QMultiLineEdit( parent, name ) { 54 : QMultiLineEdit( parent, name ) {
55 clearTableFlags(); 55 clearTableFlags();
56 setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); 56 setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar );
57} 57}
58 58
59 void find( const QString &txt, bool caseSensitive, 59 void find( const QString &txt, bool caseSensitive,
60 bool backwards ); 60 bool backwards );
61protected: 61protected:
62 bool markIt; 62 bool markIt;
63 int line1, line2, col1, col2; 63 int line1, line2, col1, col2;
64 void mousePressEvent( QMouseEvent * ); 64 void mousePressEvent( QMouseEvent * );
65 void mouseReleaseEvent( QMouseEvent * ); 65 void mouseReleaseEvent( QMouseEvent * );
66 66
67//public slots: 67//public slots:
68 /* 68 /*
69signals: 69signals:
70 void notFound(); 70 void notFound();
71 void searchWrapped(); 71 void searchWrapped();
72 */ 72 */
73 73
74private: 74private:
75 75
76}; 76};
77 77
78void QpeEditor::mousePressEvent( QMouseEvent *e ) { 78void QpeEditor::mousePressEvent( QMouseEvent *e ) {
79 switch(e->button()) { 79 switch(e->button()) {
80 case RightButton: 80 case RightButton:
81 { //rediculous workaround for qt popup menu 81 { //rediculous workaround for qt popup menu
82 //and the hold right click mechanism 82 //and the hold right click mechanism
83 this->setSelection( line1, col1, line2, col2); 83 this->setSelection( line1, col1, line2, col2);
84 QMultiLineEdit::mousePressEvent( e ); 84 QMultiLineEdit::mousePressEvent( e );
85 markIt = false; 85 markIt = false;
86 } 86 }
87 break; 87 break;
88 default: 88 default:
89 { 89 {
90 if(!markIt) { 90 if(!markIt) {
91 int line, col; 91 int line, col;
92 this->getCursorPosition(&line, &col); 92 this->getCursorPosition(&line, &col);
93 line1=line2=line; 93 line1=line2=line;
94 col1=col2=col; 94 col1=col2=col;
95 } 95 }
96 QMultiLineEdit::mousePressEvent( e ); 96 QMultiLineEdit::mousePressEvent( e );
97 } 97 }
98 break; 98 break;
99 }; 99 };
100} 100}
101 101
102void QpeEditor::mouseReleaseEvent( QMouseEvent * ) { 102void QpeEditor::mouseReleaseEvent( QMouseEvent * ) {
103 if(this->hasMarkedText()) { 103 if(this->hasMarkedText()) {
104 markIt = true; 104 markIt = true;
105 this->getMarkedRegion( &line1, &col1, &line2, & col2 ); 105 this->getMarkedRegion( &line1, &col1, &line2, & col2 );
106 } else { 106 } else {
107 markIt = false; 107 markIt = false;
108 } 108 }
109} 109}
110 110
111void QpeEditor::find ( const QString &txt, bool caseSensitive, 111void QpeEditor::find ( const QString &txt, bool caseSensitive,
112 bool backwards ) 112 bool backwards )
113{ 113{
114 static bool wrap = false; 114 static bool wrap = false;
115 int line, col; 115 int line, col;
116 if ( wrap ) { 116 if ( wrap ) {
117 if ( !backwards ) 117 if ( !backwards )
118 line = col = 0; 118 line = col = 0;
119 wrap = false; 119 wrap = false;
120 // emit searchWrapped(); 120 // emit searchWrapped();
121 } else { 121 } else {
122 getCursorPosition( &line, &col ); 122 getCursorPosition( &line, &col );
123 } 123 }
124 //ignore backwards for now.... 124 //ignore backwards for now....
125 if ( !backwards ) { 125 if ( !backwards ) {
126 for ( ; ; ) { 126 for ( ; ; ) {
127 if ( line >= numLines() ) { 127 if ( line >= numLines() ) {
128 wrap = true; 128 wrap = true;
129 //emit notFound(); 129 //emit notFound();
130 break; 130 break;
131 } 131 }
132 int findCol = getString( line )->find( txt, col, caseSensitive ); 132 int findCol = getString( line )->find( txt, col, caseSensitive );
133 if ( findCol >= 0 ) { 133 if ( findCol >= 0 ) {
134 setCursorPosition( line, findCol, false ); 134 setCursorPosition( line, findCol, false );
135 col = findCol + txt.length(); 135 col = findCol + txt.length();
136 setCursorPosition( line, col, true ); 136 setCursorPosition( line, col, true );
137 137
138 //found = true; 138 //found = true;
139 break; 139 break;
140 } 140 }
141 line++; 141 line++;
142 col = 0; 142 col = 0;
143 } 143 }
144 } 144 }
145} 145}
146 146
147 147
148#else 148#else
149 149
150#error "Must make a QpeEditor that inherits QTextEdit" 150#error "Must make a QpeEditor that inherits QTextEdit"
151 151
152#endif 152#endif
153 153
154 154
155static const int nfontsizes = 6; 155static const int nfontsizes = 6;
156static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; 156static const int fontsize[nfontsizes] = {8,10,12,14,18,24};
157 157
158TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) 158TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
159 : QMainWindow( parent, name, f ), bFromDocView( false ) 159 : QMainWindow( parent, name, f ), bFromDocView( false )
160{ 160{
161 doc = 0; 161 doc = 0;
162 edited=false; 162 edited=false;
163 fromSetDocument=false; 163 fromSetDocument=false;
164 164
165 setToolBarsMovable( false ); 165 setToolBarsMovable( false );
166 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); 166 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
167 167
168 channel = new QCopChannel( "QPE/Application/textedit", this ); 168 channel = new QCopChannel( "QPE/Application/textedit", this );
169 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), 169 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
170 this, SLOT(receive(const QCString&,const QByteArray&)) ); 170 this, SLOT(receive(const QCString&,const QByteArray&)) );
171 171
172 setIcon( Resource::loadPixmap( "TextEditor" ) ); 172 setIcon( Resource::loadPixmap( "TextEditor" ) );
173 173
174 QToolBar *bar = new QToolBar( this ); 174 QToolBar *bar = new QToolBar( this );
175 bar->setHorizontalStretchable( true ); 175 bar->setHorizontalStretchable( true );
176 menu = bar; 176 menu = bar;
177 177
178 QMenuBar *mb = new QMenuBar( bar ); 178 QMenuBar *mb = new QMenuBar( bar );
179 QPopupMenu *file = new QPopupMenu( this ); 179 QPopupMenu *file = new QPopupMenu( this );
180 QPopupMenu *edit = new QPopupMenu( this ); 180 QPopupMenu *edit = new QPopupMenu( this );
181 QPopupMenu *advancedMenu = new QPopupMenu(this); 181 QPopupMenu *advancedMenu = new QPopupMenu(this);
182 182
183 font = new QPopupMenu( this ); 183 font = new QPopupMenu( this );
184 184
185 bar = new QToolBar( this ); 185 bar = new QToolBar( this );
186 editBar = bar; 186 editBar = bar;
187 187
188 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), 188 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ),
189 QString::null, 0, this, 0 ); 189 QString::null, 0, this, 0 );
190 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 190 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
191// a->addTo( bar ); 191// a->addTo( bar );
192 a->addTo( file ); 192 a->addTo( file );
193 193
194 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), 194 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ),
195 QString::null, 0, this, 0 ); 195 QString::null, 0, this, 0 );
196 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); 196 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
197 a->addTo( bar ); 197 a->addTo( bar );
198 a->addTo( file ); 198 a->addTo( file );
199 199
200 a = new QAction( tr( "Save" ), Resource::loadPixmap("save") , 200 a = new QAction( tr( "Save" ), Resource::loadPixmap("save") ,
201 QString::null, 0, this, 0 ); 201 QString::null, 0, this, 0 );
202 connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); 202 connect( a, SIGNAL( activated() ), this, SLOT( save() ) );
203 file->insertSeparator(); 203 file->insertSeparator();
204 a->addTo( bar ); 204 a->addTo( bar );
205 a->addTo( file ); 205 a->addTo( file );
206 206
207 a = new QAction( tr( "Save As" ), Resource::loadPixmap("save") , 207 a = new QAction( tr( "Save As" ), Resource::loadPixmap("save") ,
208 QString::null, 0, this, 0 ); 208 QString::null, 0, this, 0 );
209 connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); 209 connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) );
210 a->addTo( file ); 210 a->addTo( file );
211 211
212 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), 212 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ),
213 QString::null, 0, this, 0 ); 213 QString::null, 0, this, 0 );
214 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); 214 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
215 a->addTo( editBar ); 215 a->addTo( editBar );
216 a->addTo( edit ); 216 a->addTo( edit );
217 217
218 a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), 218 a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ),
219 QString::null, 0, this, 0 ); 219 QString::null, 0, this, 0 );
220 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); 220 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
221 a->addTo( editBar ); 221 a->addTo( editBar );
222 a->addTo( edit ); 222 a->addTo( edit );
223 223
224 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), 224 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ),
225 QString::null, 0, this, 0 ); 225 QString::null, 0, this, 0 );
226 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); 226 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
227 a->addTo( editBar ); 227 a->addTo( editBar );
228 a->addTo( edit ); 228 a->addTo( edit );
229 229
230 230
231#ifndef QT_NO_CLIPBOARD 231#ifndef QT_NO_CLIPBOARD
232 a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), 232 a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ),
233 QString::null, 0, this, 0 ); 233 QString::null, 0, this, 0 );
234 connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); 234 connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) );
235 a->addTo( edit ); 235 a->addTo( edit );
236#endif 236#endif
237 237
238 a = new QAction( tr( "Goto Line..." ), Resource::loadPixmap( "find" ), 238 a = new QAction( tr( "Goto Line..." ), Resource::loadPixmap( "find" ),
239 QString::null, 0, this, 0 ); 239 QString::null, 0, this, 0 );
240 connect( a, SIGNAL( activated() ), this, SLOT( gotoLine() ) ); 240 connect( a, SIGNAL( activated() ), this, SLOT( gotoLine() ) );
241 edit->insertSeparator(); 241 edit->insertSeparator();
242 a->addTo( edit ); 242 a->addTo( edit );
243 243
244 a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), 244 a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ),
245 QString::null, 0, this, 0 ); 245 QString::null, 0, this, 0 );
246 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); 246 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) );
247 a->addTo( bar ); 247 a->addTo( bar );
248 a->addTo( edit ); 248 a->addTo( edit );
249 249
250 zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); 250 zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 );
251 connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); 251 connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) );
252 zin->addTo( font ); 252 zin->addTo( font );
253 253
254 zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); 254 zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 );
255 connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); 255 connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) );
256 zout->addTo( font ); 256 zout->addTo( font );
257 257
258 font->insertSeparator(); 258 font->insertSeparator();
259 259
260 font->insertItem(tr("Font"), this, SLOT(changeFont()) ); 260 font->insertItem(tr("Font"), this, SLOT(changeFont()) );
261 261
262 font->insertSeparator(); 262 font->insertSeparator();
263 font->insertItem(tr("Advanced Features"), advancedMenu); 263 font->insertItem(tr("Advanced Features"), advancedMenu);
264 264
265 QAction *wa = new QAction( tr("Wrap lines"), 265 QAction *wa = new QAction( tr("Wrap lines"),
266 QString::null, 0, this, 0 ); 266 QString::null, 0, this, 0 );
267 connect( wa, SIGNAL( toggled(bool) ), 267 connect( wa, SIGNAL( toggled(bool) ),
268 this, SLOT( setWordWrap(bool) ) ); 268 this, SLOT( setWordWrap(bool) ) );
269 wa->setToggleAction(true); 269 wa->setToggleAction(true);
270 wa->addTo( advancedMenu); 270 wa->addTo( advancedMenu);
271 271
272 nStart = new QAction( tr("Start with new file"), 272 nStart = new QAction( tr("Start with new file"),
273 QString::null, 0, this, 0 ); 273 QString::null, 0, this, 0 );
274 connect( nStart, SIGNAL( toggled(bool) ), 274 connect( nStart, SIGNAL( toggled(bool) ),
275 this, SLOT( changeStartConfig(bool) ) ); 275 this, SLOT( changeStartConfig(bool) ) );
276 nStart->setToggleAction(true); 276 nStart->setToggleAction(true);
277 nStart->addTo( advancedMenu ); 277 nStart->addTo( advancedMenu );
278 nStart->setEnabled(false); 278 nStart->setEnabled(false);
279 279
280 nAdvanced = new QAction( tr("Prompt on Exit"), 280 nAdvanced = new QAction( tr("Prompt on Exit"),
281 QString::null, 0, this, 0 ); 281 QString::null, 0, this, 0 );
282 connect( nAdvanced, SIGNAL( toggled(bool) ), 282 connect( nAdvanced, SIGNAL( toggled(bool) ),
283 this, SLOT( doPrompt(bool) ) ); 283 this, SLOT( doPrompt(bool) ) );
284 nAdvanced->setToggleAction(true); 284 nAdvanced->setToggleAction(true);
285 nAdvanced->addTo( advancedMenu ); 285 nAdvanced->addTo( advancedMenu );
286 286
287 desktopAction = new QAction( tr("Always open linked file"), 287 desktopAction = new QAction( tr("Always open linked file"),
288 QString::null, 0, this, 0 ); 288 QString::null, 0, this, 0 );
289 connect( desktopAction, SIGNAL( toggled(bool) ), 289 connect( desktopAction, SIGNAL( toggled(bool) ),
290 this, SLOT( doDesktop(bool) ) ); 290 this, SLOT( doDesktop(bool) ) );
291 desktopAction->setToggleAction(true); 291 desktopAction->setToggleAction(true);
292 desktopAction->addTo( advancedMenu); 292 desktopAction->addTo( advancedMenu);
293 293
294 filePermAction = new QAction( tr("File Permissions"), 294 filePermAction = new QAction( tr("File Permissions"),
295 QString::null, 0, this, 0 ); 295 QString::null, 0, this, 0 );
296 connect( filePermAction, SIGNAL( toggled(bool) ), 296 connect( filePermAction, SIGNAL( toggled(bool) ),
297 this, SLOT( doFilePerms(bool) ) ); 297 this, SLOT( doFilePerms(bool) ) );
298 filePermAction->setToggleAction(true); 298 filePermAction->setToggleAction(true);
299 filePermAction->addTo( advancedMenu); 299 filePermAction->addTo( advancedMenu);
300 300
301 searchBarAction = new QAction( tr("Search Bar Open"), 301 searchBarAction = new QAction( tr("Search Bar Open"),
302 QString::null, 0, this, 0 ); 302 QString::null, 0, this, 0 );
303 connect( searchBarAction, SIGNAL( toggled(bool) ), 303 connect( searchBarAction, SIGNAL( toggled(bool) ),
304 this, SLOT( setSearchBar(bool) ) ); 304 this, SLOT( setSearchBar(bool) ) );
305 searchBarAction->setToggleAction(true); 305 searchBarAction->setToggleAction(true);
306 searchBarAction->addTo( advancedMenu); 306 searchBarAction->addTo( advancedMenu);
307 307
308 nAutoSave = new QAction( tr("Auto Save 5 min."), 308 nAutoSave = new QAction( tr("Auto Save 5 min."),
309 QString::null, 0, this, 0 ); 309 QString::null, 0, this, 0 );
310 connect( nAutoSave, SIGNAL( toggled(bool) ), 310 connect( nAutoSave, SIGNAL( toggled(bool) ),
311 this, SLOT( doTimer(bool) ) ); 311 this, SLOT( doTimer(bool) ) );
312 nAutoSave->setToggleAction(true); 312 nAutoSave->setToggleAction(true);
313 nAutoSave->addTo( advancedMenu); 313 nAutoSave->addTo( advancedMenu);
314 314
315 315
316 //font->insertSeparator(); 316 //font->insertSeparator();
317 317
318 //font->insertItem(tr("About"), this, SLOT( doAbout()) ); 318 //font->insertItem(tr("About"), this, SLOT( doAbout()) );
319 319
320 mb->insertItem( tr( "File" ), file ); 320 mb->insertItem( tr( "File" ), file );
321 mb->insertItem( tr( "Edit" ), edit ); 321 mb->insertItem( tr( "Edit" ), edit );
322 mb->insertItem( tr( "View" ), font ); 322 mb->insertItem( tr( "View" ), font );
323 323
324 searchBar = new QToolBar(this); 324 searchBar = new QToolBar(this);
325 addToolBar( searchBar, "Search", QMainWindow::Top, true ); 325 addToolBar( searchBar, "Search", QMainWindow::Top, true );
326 326
327 searchBar->setHorizontalStretchable( true ); 327 searchBar->setHorizontalStretchable( true );
328 328
329 searchEdit = new QLineEdit( searchBar, "searchEdit" ); 329 searchEdit = new QLineEdit( searchBar, "searchEdit" );
330 searchBar->setStretchableWidget( searchEdit ); 330 searchBar->setStretchableWidget( searchEdit );
331 connect( searchEdit, SIGNAL( textChanged(const QString&) ), 331 connect( searchEdit, SIGNAL( textChanged(const QString&) ),
332 this, SLOT( search() ) ); 332 this, SLOT( search() ) );
333 333
334 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), 334 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ),
335 QString::null, 0, this, 0 ); 335 QString::null, 0, this, 0 );
336 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); 336 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
337 a->addTo( searchBar ); 337 a->addTo( searchBar );
338 a->addTo( edit ); 338 a->addTo( edit );
339 339
340 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), 340 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ),
341 QString::null, 0, this, 0 ); 341 QString::null, 0, this, 0 );
342 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); 342 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
343 a->addTo( searchBar ); 343 a->addTo( searchBar );
344 344
345 edit->insertSeparator(); 345 edit->insertSeparator();
346 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), 346 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ),
347 QString::null, 0, this, 0 ); 347 QString::null, 0, this, 0 );
348 connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); 348 connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) );
349 a->addTo( edit ); 349 a->addTo( edit );
350 350
351 searchBar->hide(); 351 searchBar->hide();
352 352
353 editor = new QpeEditor( this ); 353 editor = new QpeEditor( this );
354 setCentralWidget( editor ); 354 setCentralWidget( editor );
355 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 355 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken );
356 connect( editor, SIGNAL( textChanged() ), 356 connect( editor, SIGNAL( textChanged() ),
357 this, SLOT( editorChanged() ) ); 357 this, SLOT( editorChanged() ) );
358 358
359 QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); 359 QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold);
360 360
361 Config cfg("TextEdit"); 361 Config cfg("TextEdit");
362 cfg. setGroup ( "Font" ); 362 cfg. setGroup ( "Font" );
363 363
364 QFont defaultFont = editor-> font ( ); 364 QFont defaultFont = editor-> font ( );
365 365
366 QString family = cfg. readEntry ( "Family", defaultFont. family ( )); 366 QString family = cfg. readEntry ( "Family", defaultFont. family ( ));
367 int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); 367 int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( ));
368 int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); 368 int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( ));
369 bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); 369 bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( ));
370 370
371 defaultFont = QFont ( family, size, weight, italic ); 371 defaultFont = QFont ( family, size, weight, italic );
372 editor-> setFont ( defaultFont ); 372 editor-> setFont ( defaultFont );
373// updateCaption(); 373// updateCaption();
374 374
375 cfg.setGroup ( "View" ); 375 cfg.setGroup ( "View" );
376 376
377 promptExit = cfg.readBoolEntry ( "PromptExit", false ); 377 promptExit = cfg.readBoolEntry ( "PromptExit", false );
378 openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); 378 openDesktop = cfg.readBoolEntry ( "OpenDesktop", true );
379 filePerms = cfg.readBoolEntry ( "FilePermissions", false ); 379 filePerms = cfg.readBoolEntry ( "FilePermissions", false );
380 useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); 380 useSearchBar = cfg.readBoolEntry ( "SearchBar", false );
381 startWithNew = cfg.readBoolEntry ( "startNew", true); 381 startWithNew = cfg.readBoolEntry ( "startNew", true);
382 featureAutoSave = cfg.readBoolEntry( "autosave", false); 382 featureAutoSave = cfg.readBoolEntry( "autosave", false);
383 383
384 if(useSearchBar) searchBarAction->setOn(true); 384 if(useSearchBar) searchBarAction->setOn(true);
385 if(promptExit) nAdvanced->setOn( true ); 385 if(promptExit) nAdvanced->setOn( true );
386 if(openDesktop) desktopAction->setOn( true ); 386 if(openDesktop) desktopAction->setOn( true );
387 if(filePerms) filePermAction->setOn( true ); 387 if(filePerms) filePermAction->setOn( true );
388 if(startWithNew) nStart->setOn( true ); 388 if(startWithNew) nStart->setOn( true );
389 if(featureAutoSave) nAutoSave->setOn(true); 389 if(featureAutoSave) nAutoSave->setOn(true);
390 390
391// { 391// {
392// doTimer(true); 392// doTimer(true);
393// } 393// }
394 394
395 bool wrap = cfg. readBoolEntry ( "Wrap", true ); 395 bool wrap = cfg. readBoolEntry ( "Wrap", true );
396 wa-> setOn ( wrap ); 396 wa-> setOn ( wrap );
397 setWordWrap ( wrap ); 397 setWordWrap ( wrap );
398 398
399///////////////// 399/////////////////
400 if( qApp->argc() > 1) { 400 if( qApp->argc() > 1) {
401 currentFileName=qApp->argv()[1]; 401 currentFileName=qApp->argv()[1];
402 402
403 QFileInfo fi(currentFileName); 403 QFileInfo fi(currentFileName);
404 404
405 if(fi.baseName().left(1) == "") { 405 if(fi.baseName().left(1) == "") {
406 openDotFile(currentFileName); 406 openDotFile(currentFileName);
407 } else { 407 } else {
408 openFile(currentFileName); 408 openFile(currentFileName);
409 } 409 }
410 } else { 410 } else {
411 edited1=false; 411 edited1=false;
412 openDotFile(""); 412 openDotFile("");
413 } 413 }
414 414
415 viewSelection = cfg.readNumEntry( "FileView", 0 ); 415 viewSelection = cfg.readNumEntry( "FileView", 0 );
416} 416}
417 417
418TextEdit::~TextEdit() { 418TextEdit::~TextEdit() {
419 owarn << "textedit d'tor" << oendl; 419 owarn << "textedit d'tor" << oendl;
420 delete editor; 420 delete editor;
421} 421}
422 422
423void TextEdit::closeEvent(QCloseEvent *) { 423void TextEdit::closeEvent(QCloseEvent *) {
424 if( edited1 && promptExit) 424 if( edited1 && promptExit)
425 { 425 {
426 switch( savePrompt() ) 426 switch( savePrompt() )
427 { 427 {
428 case 1: 428 case 1:
429 { 429 {
430 saveAs(); 430 saveAs();
431 qApp->quit(); 431 qApp->quit();
432 } 432 }
433 break; 433 break;
434 434
435 case 2: 435 case 2:
436 { 436 {
437 qApp->quit(); 437 qApp->quit();
438 } 438 }
439 break; 439 break;
440 440
441 case -1: 441 case -1:
442 break; 442 break;
443 }; 443 };
444 } 444 }
445 else 445 else
446 qApp->quit(); 446 qApp->quit();
447 447
448} 448}
449 449
450void TextEdit::cleanUp() { 450void TextEdit::cleanUp() {
451 451
452 Config cfg ( "TextEdit" ); 452 Config cfg ( "TextEdit" );
453 cfg. setGroup ( "Font" ); 453 cfg. setGroup ( "Font" );
454 QFont f = editor->font(); 454 QFont f = editor->font();
455 cfg.writeEntry ( "Family", f. family ( )); 455 cfg.writeEntry ( "Family", f. family ( ));
456 cfg.writeEntry ( "Size", f. pointSize ( )); 456 cfg.writeEntry ( "Size", f. pointSize ( ));
457 cfg.writeEntry ( "Weight", f. weight ( )); 457 cfg.writeEntry ( "Weight", f. weight ( ));
458 cfg.writeEntry ( "Italic", f. italic ( )); 458 cfg.writeEntry ( "Italic", f. italic ( ));
459 459
460 cfg.setGroup ( "View" ); 460 cfg.setGroup ( "View" );
461 cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); 461 cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth );
462 cfg.writeEntry ( "FileView", viewSelection ); 462 cfg.writeEntry ( "FileView", viewSelection );
463 463
464 cfg.writeEntry ( "PromptExit", promptExit ); 464 cfg.writeEntry ( "PromptExit", promptExit );
465 cfg.writeEntry ( "OpenDesktop", openDesktop ); 465 cfg.writeEntry ( "OpenDesktop", openDesktop );
466 cfg.writeEntry ( "FilePermissions", filePerms ); 466 cfg.writeEntry ( "FilePermissions", filePerms );
467 cfg.writeEntry ( "SearchBar", useSearchBar ); 467 cfg.writeEntry ( "SearchBar", useSearchBar );
468 cfg.writeEntry ( "startNew", startWithNew ); 468 cfg.writeEntry ( "startNew", startWithNew );
469 469
470} 470}
471 471
472 472
473void TextEdit::accept() { 473void TextEdit::accept() {
474 if( edited1) 474 if( edited1)
475 saveAs(); 475 saveAs();
476 qApp->quit(); 476 qApp->quit();
477} 477}
478 478
479void TextEdit::zoomIn() { 479void TextEdit::zoomIn() {
480 setFontSize(editor->font().pointSize()+1,false); 480 setFontSize(editor->font().pointSize()+1,false);
481} 481}
482 482
483void TextEdit::zoomOut() { 483void TextEdit::zoomOut() {
484 setFontSize(editor->font().pointSize()-1,true); 484 setFontSize(editor->font().pointSize()-1,true);
485} 485}
486 486
487 487
488void TextEdit::setFontSize(int sz, bool round_down_not_up) { 488void TextEdit::setFontSize(int sz, bool round_down_not_up) {
489 int s=10; 489 int s=10;
490 for (int i=0; i<nfontsizes; i++) { 490 for (int i=0; i<nfontsizes; i++) {
491 if ( fontsize[i] == sz ) { 491 if ( fontsize[i] == sz ) {
492 s = sz; 492 s = sz;
493 break; 493 break;
494 } else if ( round_down_not_up ) { 494 } else if ( round_down_not_up ) {
495 if ( fontsize[i] < sz ) 495 if ( fontsize[i] < sz )
496 s = fontsize[i]; 496 s = fontsize[i];
497 } else { 497 } else {
498 if ( fontsize[i] > sz ) { 498 if ( fontsize[i] > sz ) {
499 s = fontsize[i]; 499 s = fontsize[i];
500 break; 500 break;
501 } 501 }
502 } 502 }
503 } 503 }
504 504
505 QFont f = editor->font(); 505 QFont f = editor->font();
506 f.setPointSize(s); 506 f.setPointSize(s);
507 editor->setFont(f); 507 editor->setFont(f);
508 508
509 zin->setEnabled(s != fontsize[nfontsizes-1]); 509 zin->setEnabled(s != fontsize[nfontsizes-1]);
510 zout->setEnabled(s != fontsize[0]); 510 zout->setEnabled(s != fontsize[0]);
511} 511}
512 512
513void TextEdit::setBold(bool y) { 513void TextEdit::setBold(bool y) {
514 QFont f = editor->font(); 514 QFont f = editor->font();
515 f.setBold(y); 515 f.setBold(y);
516 editor->setFont(f); 516 editor->setFont(f);
517} 517}
518 518
519void TextEdit::setItalic(bool y) { 519void TextEdit::setItalic(bool y) {
520 QFont f = editor->font(); 520 QFont f = editor->font();
521 f.setItalic(y); 521 f.setItalic(y);
522 editor->setFont(f); 522 editor->setFont(f);
523} 523}
524 524
525void TextEdit::setWordWrap(bool y) { 525void TextEdit::setWordWrap(bool y) {
526 bool state = editor->edited(); 526 bool state = editor->edited();
527 QString captionStr = caption(); 527 QString captionStr = caption();
528 bool b1 = edited1; 528 bool b1 = edited1;
529 bool b2 = edited; 529 bool b2 = edited;
530 530
531 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); 531 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
532 editor->setEdited( state ); 532 editor->setEdited( state );
533 edited1=b1; 533 edited1=b1;
534 edited=b2; 534 edited=b2;
535 setCaption(captionStr); 535 setCaption(captionStr);
536} 536}
537 537
538void TextEdit::setSearchBar(bool b) { 538void TextEdit::setSearchBar(bool b) {
539 useSearchBar=b; 539 useSearchBar=b;
540 Config cfg("TextEdit"); 540 Config cfg("TextEdit");
541 cfg.setGroup("View"); 541 cfg.setGroup("View");
542 cfg.writeEntry ( "SearchBar", b ); 542 cfg.writeEntry ( "SearchBar", b );
543 searchBarAction->setOn(b); 543 searchBarAction->setOn(b);
544 if(b) 544 if(b)
545 searchBar->show(); 545 searchBar->show();
546 else 546 else
547 searchBar->hide(); 547 searchBar->hide();
548 editor->setFocus(); 548 editor->setFocus();
549} 549}
550 550
551void TextEdit::fileNew() { 551void TextEdit::fileNew() {
552// if( !bFromDocView ) { 552// if( !bFromDocView ) {
553// saveAs(); 553// saveAs();
554// } 554// }
555 newFile(DocLnk()); 555 newFile(DocLnk());
556} 556}
557 557
558void TextEdit::fileOpen() { 558void TextEdit::fileOpen() {
559 Config cfg("TextEdit"); 559 Config cfg("TextEdit");
560 cfg. setGroup ( "View" ); 560 cfg. setGroup ( "View" );
561 QMap<QString, QStringList> map; 561 QMap<QString, QStringList> map;
562 map.insert(tr("All"), QStringList() ); 562 map.insert(tr("All"), QStringList() );
563 QStringList text; 563 QStringList text;
564 text << "text/*"; 564 text << "text/*";
565 map.insert(tr("Text"), text ); 565 map.insert(tr("Text"), text );
566 text << "*"; 566 text << "*";
567 map.insert(tr("All"), text ); 567 map.insert(tr("All"), text );
568 QString str = OFileDialog::getOpenFileName( 2, 568 QString str = OFileDialog::getOpenFileName( 2,
569 QString::null , 569 QString::null ,
570 QString::null, map); 570 QString::null, map);
571 if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) 571 if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() )
572 { 572 {
573 openFile( str ); 573 openFile( str );
574 } 574 }
575 else 575 else
576 updateCaption(); 576 updateCaption();
577} 577}
578 578
579void TextEdit::doSearchBar() { 579void TextEdit::doSearchBar() {
580 if(!useSearchBar) 580 if(!useSearchBar)
581 searchBar->hide(); 581 searchBar->hide();
582 else 582 else
583 searchBar->show(); 583 searchBar->show();
584} 584}
585 585
586#if 0 586#if 0
587void TextEdit::slotFind() { 587void TextEdit::slotFind() {
588 FindDialog frmFind( tr("Text Editor"), this ); 588 FindDialog frmFind( tr("Text Editor"), this );
589 connect( &frmFind, SIGNAL(signalFindClicked(const QString&,bool,bool,int)), 589 connect( &frmFind, SIGNAL(signalFindClicked(const QString&,bool,bool,int)),
590 editor, SLOT(slotDoFind(const QString&,bool,bool))); 590 editor, SLOT(slotDoFind(const QString&,bool,bool)));
591 591
592 //case sensitive, backwards, [category] 592 //case sensitive, backwards, [category]
593 593
594 connect( editor, SIGNAL(notFound()), 594 connect( editor, SIGNAL(notFound()),
595 &frmFind, SLOT(slotNotFound()) ); 595 &frmFind, SLOT(slotNotFound()) );
596 connect( editor, SIGNAL(searchWrapped()), 596 connect( editor, SIGNAL(searchWrapped()),
597 &frmFind, SLOT(slotWrapAround()) ); 597 &frmFind, SLOT(slotWrapAround()) );
598 598
599 frmFind.exec(); 599 frmFind.exec();
600 600
601 601
602} 602}
603#endif 603#endif
604 604
605void TextEdit::fileRevert() { 605void TextEdit::fileRevert() {
606 clear(); 606 clear();
607 fileOpen(); 607 fileOpen();
608} 608}
609 609
610void TextEdit::editCut() { 610void TextEdit::editCut() {
611#ifndef QT_NO_CLIPBOARD 611#ifndef QT_NO_CLIPBOARD
612 editor->cut(); 612 editor->cut();
613#endif 613#endif
614} 614}
615 615
616void TextEdit::editCopy() { 616void TextEdit::editCopy() {
617#ifndef QT_NO_CLIPBOARD 617#ifndef QT_NO_CLIPBOARD
618 editor->copy(); 618 editor->copy();
619#endif 619#endif
620} 620}
621 621
622void TextEdit::editPaste() { 622void TextEdit::editPaste() {
623#ifndef QT_NO_CLIPBOARD 623#ifndef QT_NO_CLIPBOARD
624 editor->paste(); 624 editor->paste();
625#endif 625#endif
626} 626}
627 627
628void TextEdit::editFind() { 628void TextEdit::editFind() {
629 searchBar->show(); 629 searchBar->show();
630 searchEdit->setFocus(); 630 searchEdit->setFocus();
631} 631}
632 632
633void TextEdit::findNext() { 633void TextEdit::findNext() {
634 editor->find( searchEdit->text(), false, false ); 634 editor->find( searchEdit->text(), false, false );
635 635
636} 636}
637 637
638void TextEdit::findClose() { 638void TextEdit::findClose() {
639 searchBar->hide(); 639 searchBar->hide();
640} 640}
641 641
642void TextEdit::search() { 642void TextEdit::search() {
643 editor->find( searchEdit->text(), false, false ); 643 editor->find( searchEdit->text(), false, false );
644} 644}
645 645
646void TextEdit::newFile( const DocLnk &f ) { 646void TextEdit::newFile( const DocLnk &f ) {
647 DocLnk nf = f; 647 DocLnk nf = f;
648 nf.setType("text/plain"); 648 nf.setType("text/plain");
649 clear(); 649 clear();
650 setWState (WState_Reserved1 ); 650 setWState (WState_Reserved1 );
651 editor->setFocus(); 651 editor->setFocus();
652 doc = new DocLnk(nf); 652 doc = new DocLnk(nf);
653 currentFileName = "Unnamed"; 653 currentFileName = "Unnamed";
654 odebug << "newFile "+currentFileName << oendl; 654 odebug << "newFile "+currentFileName << oendl;
655 updateCaption( currentFileName); 655 updateCaption( currentFileName);
656// editor->setEdited( false); 656// editor->setEdited( false);
657} 657}
658 658
659void TextEdit::openDotFile( const QString &f ) { 659void TextEdit::openDotFile( const QString &f ) {
660 if(!currentFileName.isEmpty()) { 660 if(!currentFileName.isEmpty()) {
661 currentFileName=f; 661 currentFileName=f;
662 662
663 odebug << "openFile dotfile " + currentFileName << oendl; 663 odebug << "openFile dotfile " + currentFileName << oendl;
664 QString txt; 664 QString txt;
665 QFile file(f); 665 QFile file(f);
666 file.open(IO_ReadWrite); 666 file.open(IO_ReadWrite);
667 QTextStream t(&file); 667 QTextStream t(&file);
668 while ( !t.atEnd()) { 668 while ( !t.atEnd()) {
669 txt+=t.readLine()+"\n"; 669 txt+=t.readLine()+"\n";
670 } 670 }
671 editor->setText(txt); 671 editor->setText(txt);
672 editor->setEdited( false); 672 editor->setEdited( false);
673 edited1=false; 673 edited1=false;
674 edited=false; 674 edited=false;
675 675
676 676
677 } 677 }
678 updateCaption( currentFileName); 678 updateCaption( currentFileName);
679} 679}
680 680
681void TextEdit::openFile( const QString &f ) { 681void TextEdit::openFile( const QString &f ) {
682 odebug << "filename is "+ f << oendl; 682 odebug << "filename is "+ f << oendl;
683 QString filer; 683 QString filer;
684 QFileInfo fi( f); 684 QFileInfo fi( f);
685// bFromDocView = true; 685// bFromDocView = true;
686 if(f.find(".desktop",0,true) != -1 && !openDesktop ) 686 if(f.find(".desktop",0,true) != -1 && !openDesktop )
687 { 687 {
688 switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) ) 688 switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) )
689 { 689 {
690 case 0: //desktop 690 case 0: //desktop
691 filer = f; 691 filer = f;
692 break; 692 break;
693 case 1: //linked 693 case 1: //linked
694 DocLnk sf(f); 694 DocLnk sf(f);
695 filer = sf.file(); 695 filer = sf.file();
696 break; 696 break;
697 }; 697 };
698 } 698 }
699 else if(fi.baseName().left(1) == "") 699 else if(fi.baseName().left(1) == "")
700 { 700 {
701 odebug << "opening dotfile" << oendl; 701 odebug << "opening dotfile" << oendl;
702 currentFileName=f; 702 currentFileName=f;
703 openDotFile(currentFileName); 703 openDotFile(currentFileName);
704 return; 704 return;
705 } 705 }
706 /* 706 /*
707 * The problem is a file where Config(f).isValid() and it does not 707 * The problem is a file where Config(f).isValid() and it does not
708 * end with .desktop will be treated as desktop file 708 * end with .desktop will be treated as desktop file
709 */ 709 */
710 else if (f.find(".desktop",0,true) != -1 ) 710 else if (f.find(".desktop",0,true) != -1 )
711 { 711 {
712 DocLnk sf(f); 712 DocLnk sf(f);
713 filer = sf.file(); 713 filer = sf.file();
714 if(filer.right(1) == "/") 714 if(filer.right(1) == "/")
715 filer = f; 715 filer = f;
716 716
717 } 717 }
718 else 718 else
719 filer = f; 719 filer = f;
720 720
721 DocLnk nf; 721 DocLnk nf;
722 nf.setType("text/plain"); 722 nf.setType("text/plain");
723 nf.setFile(filer); 723 nf.setFile(filer);
724 currentFileName=filer; 724 currentFileName=filer;
725 725
726 nf.setName(fi.baseName()); 726 nf.setName(fi.baseName());
727 openFile(nf); 727 openFile(nf);
728 728
729 odebug << "openFile string "+currentFileName << oendl; 729 odebug << "openFile string "+currentFileName << oendl;
730 730
731 showEditTools(); 731 showEditTools();
732 // Show filename in caption 732 // Show filename in caption
733 QString name = filer; 733 QString name = filer;
734 int sep = name.findRev( '/' ); 734 int sep = name.findRev( '/' );
735 if ( sep > 0 ) 735 if ( sep > 0 )
736 name = name.mid( sep+1 ); 736 name = name.mid( sep+1 );
737 updateCaption( name ); 737 updateCaption( name );
738} 738}
739 739
740void TextEdit::openFile( const DocLnk &f ) { 740void TextEdit::openFile( const DocLnk &f ) {
741// clear(); 741// clear();
742// bFromDocView = true; 742// bFromDocView = true;
743 FileManager fm; 743 FileManager fm;
744 QString txt; 744 QString txt;
745 currentFileName=f.file(); 745 currentFileName=f.file();
746 odebug << "openFile doclnk " + currentFileName << oendl; 746 odebug << "openFile doclnk " + currentFileName << oendl;
747 if ( !fm.loadFile( f, txt ) ) { 747 if ( !fm.loadFile( f, txt ) ) {
748 // ####### could be a new file 748 // ####### could be a new file
749 odebug << "Cannot open file" << oendl; 749 odebug << "Cannot open file" << oendl;
750 } 750 }
751// fileNew(); 751// fileNew();
752 if ( doc ) 752 if ( doc )
753 delete doc; 753 delete doc;
754 doc = new DocLnk(f); 754 doc = new DocLnk(f);
755 editor->setText(txt); 755 editor->setText(txt);
756 editor->setEdited( false); 756 editor->setEdited( false);
757 edited1=false; 757 edited1=false;
758 edited=false; 758 edited=false;
759 759
760 doc->setName(currentFileName); 760 doc->setName(currentFileName);
761 updateCaption(); 761 updateCaption();
762 setTimer(); 762 setTimer();
763} 763}
764 764
765void TextEdit::showEditTools() { 765void TextEdit::showEditTools() {
766 menu->show(); 766 menu->show();
767 editBar->show(); 767 editBar->show();
768 if(!useSearchBar) 768 if(!useSearchBar)
769 searchBar->hide(); 769 searchBar->hide();
770 else 770 else
771 searchBar->show(); 771 searchBar->show();
772 setWState (WState_Reserved1 ); 772 setWState (WState_Reserved1 );
773} 773}
774 774
775/*! 775/*!
776 unprompted save */ 776 unprompted save */
777bool TextEdit::save() { 777bool TextEdit::save() {
778 QString name, file; 778 QString name, file;
779 odebug << "saveAsFile " + currentFileName << oendl; 779 odebug << "saveAsFile " + currentFileName << oendl;
780 if(currentFileName.isEmpty()) { 780 if(currentFileName.isEmpty()) {
781 saveAs(); 781 saveAs();
782 return false; 782 return false;
783 } 783 }
784 name = currentFileName; 784 name = currentFileName;
785 if(doc) { 785 if(doc) {
786 file = doc->file(); 786 file = doc->file();
787 odebug << "saver file "+file << oendl; 787 odebug << "saver file "+file << oendl;
788 name = doc->name(); 788 name = doc->name();
789 odebug << "File named "+name << oendl; 789 odebug << "File named "+name << oendl;
790 } else { 790 } else {
791 file = currentFileName; 791 file = currentFileName;
792 name = QFileInfo(currentFileName).baseName(); 792 name = QFileInfo(currentFileName).baseName();
793 } 793 }
794 794
795 QString rt = editor->text(); 795 QString rt = editor->text();
796 if( !rt.isEmpty() ) { 796 if( !rt.isEmpty() ) {
797 if(name.isEmpty()) { 797 if(name.isEmpty()) {
798 saveAs(); 798 saveAs();
799 } else { 799 } else {
800 currentFileName = name; 800 currentFileName = name;
801 odebug << "saveFile "+currentFileName << oendl; 801 odebug << "saveFile "+currentFileName << oendl;
802 802
803 struct stat buf; 803 struct stat buf;
804 mode_t mode; 804 mode_t mode;
805 stat(file.latin1(), &buf); 805 stat(file.latin1(), &buf);
806 mode = buf.st_mode; 806 mode = buf.st_mode;
807 807
808 if(!fileIs) { 808 if(!fileIs) {
809 doc->setName( name); 809 doc->setName( name);
810 FileManager fm; 810 FileManager fm;
811 if ( !fm.saveFile( *doc, rt ) ) { 811 if ( !fm.saveFile( *doc, rt ) ) {
812 QMessageBox::message(tr("Text Edit"),tr("Save Failed")); 812 QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
813 return false; 813 return false;
814 } 814 }
815 } else { 815 } else {
816 odebug << "regular save file" << oendl; 816 odebug << "regular save file" << oendl;
817 QFile f(file); 817 QFile f(file);
818 if( f.open(IO_WriteOnly)) { 818 if( f.open(IO_WriteOnly)) {
819 QCString crt = rt.utf8(); 819 QCString crt = rt.utf8();
820 f.writeBlock(crt,crt.length()); 820 f.writeBlock(crt,crt.length());
821 } else { 821 } else {
822 QMessageBox::message(tr("Text Edit"),tr("Write Failed")); 822 QMessageBox::message(tr("Text Edit"),tr("Write Failed"));
823 return false; 823 return false;
824 } 824 }
825 825
826 } 826 }
827 editor->setEdited( false); 827 editor->setEdited( false);
828 edited1=false; 828 edited1=false;
829 edited=false; 829 edited=false;
830 if(caption().left(1)=="*") 830 if(caption().left(1)=="*")
831 setCaption(caption().right(caption().length()-1)); 831 setCaption(caption().right(caption().length()-1));
832 832
833 833
834 chmod( file.latin1(), mode); 834 chmod( file.latin1(), mode);
835 } 835 }
836 return true; 836 return true;
837 } 837 }
838 return false; 838 return false;
839} 839}
840 840
841/*! 841/*!
842 prompted save */ 842 prompted save */
843bool TextEdit::saveAs() { 843bool TextEdit::saveAs() {
844 844
845 if(caption() == tr("Text Editor")) 845 if(caption() == tr("Text Editor"))
846 return false; 846 return false;
847 odebug << "saveAsFile " + currentFileName << oendl; 847 odebug << "saveAsFile " + currentFileName << oendl;
848 // case of nothing to save... 848 // case of nothing to save...
849// if ( !doc && !currentFileName.isEmpty()) { 849// if ( !doc && !currentFileName.isEmpty()) {
850// //|| !bFromDocView) 850// //|| !bFromDocView)
851// odebug << "no doc" << oendl; 851// odebug << "no doc" << oendl;
852// return true; 852// return true;
853// } 853// }
854// if ( !editor->edited() ) { 854// if ( !editor->edited() ) {
855// delete doc; 855// delete doc;
856// doc = 0; 856// doc = 0;
857// return true; 857// return true;
858// } 858// }
859 859
860 QString rt = editor->text(); 860 QString rt = editor->text();
861 odebug << currentFileName << oendl; 861 odebug << currentFileName << oendl;
862 862
863 if( currentFileName.isEmpty() 863 if( currentFileName.isEmpty()
864 || currentFileName == tr("Unnamed") 864 || currentFileName == tr("Unnamed")
865 || currentFileName == tr("Text Editor")) { 865 || currentFileName == tr("Text Editor")) {
866 odebug << "do silly TT filename thing" << oendl; 866 odebug << "do silly TT filename thing" << oendl;
867// if ( doc && doc->name().isEmpty() ) { 867// if ( doc && doc->name().isEmpty() ) {
868 QString pt = rt.simplifyWhiteSpace(); 868 QString pt = rt.simplifyWhiteSpace();
869 int i = pt.find( ' ' ); 869 int i = pt.find( ' ' );
870 QString docname = pt; 870 QString docname = pt;
871 if ( i > 0 ) 871 if ( i > 0 )
872 docname = pt.left( i ); 872 docname = pt.left( i );
873 // remove "." at the beginning 873 // remove "." at the beginning
874 while( docname.startsWith( "." ) ) 874 while( docname.startsWith( "." ) )
875 docname = docname.mid( 1 ); 875 docname = docname.mid( 1 );
876 docname.replace( QRegExp("/"), "_" ); 876 docname.replace( QRegExp("/"), "_" );
877 // cut the length. filenames longer than that 877 // cut the length. filenames longer than that
878 //don't make sense and something goes wrong when they get too long. 878 //don't make sense and something goes wrong when they get too long.
879 if ( docname.length() > 40 ) 879 if ( docname.length() > 40 )
880 docname = docname.left(40); 880 docname = docname.left(40);
881 if ( docname.isEmpty() ) 881 if ( docname.isEmpty() )
882 docname = tr("Unnamed"); 882 docname = tr("Unnamed");
883 if(doc) doc->setName(docname); 883 if(doc) doc->setName(docname);
884 currentFileName=docname; 884 currentFileName=docname;
885// } 885// }
886// else 886// else
887// odebug << "hmmmmmm" << oendl; 887// odebug << "hmmmmmm" << oendl;
888 } 888 }
889 889
890 890
891 QMap<QString, QStringList> map; 891 QMap<QString, QStringList> map;
892 map.insert(tr("All"), QStringList() ); 892 map.insert(tr("All"), QStringList() );
893 QStringList text; 893 QStringList text;
894 text << "text/*"; 894 text << "text/*";
895 map.insert(tr("Text"), text ); 895 map.insert(tr("Text"), text );
896 text << "*"; 896 text << "*";
897 map.insert(tr("All"), text ); 897 map.insert(tr("All"), text );
898 898
899 QFileInfo cuFi( currentFileName); 899 QFileInfo cuFi( currentFileName);
900 QString filee = cuFi.fileName(); 900 QString filee = cuFi.fileName();
901 QString dire = cuFi.dirPath(); 901 QString dire = cuFi.dirPath();
902 if(dire==".") 902 if(dire==".")
903 dire = QPEApplication::documentDir(); 903 dire = QPEApplication::documentDir();
904 QString str; 904 QString str;
905 if( !featureAutoSave) { 905 if( !featureAutoSave) {
906 str = OFileDialog::getSaveFileName( 2, 906 str = OFileDialog::getSaveFileName( 2,
907 dire, 907 dire,
908 filee, map); 908 filee, map);
909 } else 909 } else
910 str=currentFileName; 910 str=currentFileName;
911 911
912 if(!str.isEmpty()) { 912 if(!str.isEmpty()) {
913 QString fileNm=str; 913 QString fileNm=str;
914 914
915 odebug << "saving filename "+fileNm << oendl; 915 odebug << "saving filename "+fileNm << oendl;
916 QFileInfo fi(fileNm); 916 QFileInfo fi(fileNm);
917 currentFileName=fi.fileName(); 917 currentFileName=fi.fileName();
918 if(doc) 918 if(doc)
919// QString file = doc->file(); 919// QString file = doc->file();
920// doc->removeFiles(); 920// doc->removeFiles();
921 delete doc; 921 delete doc;
922 DocLnk nf; 922 DocLnk nf;
923 nf.setType("text/plain"); 923 nf.setType("text/plain");
924 nf.setFile( fileNm); 924 nf.setFile( fileNm);
925 doc = new DocLnk(nf); 925 doc = new DocLnk(nf);
926// editor->setText(rt); 926// editor->setText(rt);
927 odebug << "Saving file as "+currentFileName << oendl; 927 odebug << "Saving file as "+currentFileName << oendl;
928 doc->setName( fi.baseName() /*currentFileName*/); 928 doc->setName( fi.baseName() /*currentFileName*/);
929 updateCaption( currentFileName); 929 updateCaption( currentFileName);
930 930
931 FileManager fm; 931 FileManager fm;
932 if ( !fm.saveFile( *doc, rt ) ) { 932 if ( !fm.saveFile( *doc, rt ) ) {
933 QMessageBox::message(tr("Text Edit"),tr("Save Failed")); 933 QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
934 return false; 934 return false;
935 } 935 }
936 936
937 if( filePerms ) { 937 if( filePerms ) {
938 filePermissions *filePerm; 938 filePermissions *filePerm;
939 filePerm = new filePermissions(this, 939 filePerm = new filePermissions(this,
940 tr("Permissions"),true, 940 tr("Permissions"),true,
941 0,(const QString &)fileNm); 941 0,(const QString &)fileNm);
942 QPEApplication::execDialog( filePerm ); 942 QPEApplication::execDialog( filePerm );
943 943
944 if( filePerm) 944 if( filePerm)
945 delete filePerm; 945 delete filePerm;
946 } 946 }
947// } 947// }
948 editor->setEdited( false); 948 editor->setEdited( false);
949 edited1 = false; 949 edited1 = false;
950 edited = false; 950 edited = false;
951 if(caption().left(1)=="*") 951 if(caption().left(1)=="*")
952 setCaption(caption().right(caption().length()-1)); 952 setCaption(caption().right(caption().length()-1));
953 953
954 return true; 954 return true;
955 } 955 }
956 odebug << "returning false" << oendl; 956 odebug << "returning false" << oendl;
957 currentFileName = ""; 957 currentFileName = "";
958 return false; 958 return false;
959} //end saveAs 959} //end saveAs
960 960
961void TextEdit::clear() { 961void TextEdit::clear() {
962 delete doc; 962 delete doc;
963 doc = 0; 963 doc = 0;
964 editor->clear(); 964 editor->clear();
965} 965}
966 966
967void TextEdit::updateCaption( const QString &name ) { 967void TextEdit::updateCaption( const QString &name ) {
968 968
969 if ( name.isEmpty() ) 969 if ( name.isEmpty() )
970 setCaption( tr("Text Editor") ); 970 setCaption( tr("Text Editor") );
971 else { 971 else {
972 QString s = name; 972 QString s = name;
973 if ( s.isNull() ) 973 if ( s.isNull() )
974 s = doc->name(); 974 s = doc->name();
975 if ( s.isEmpty() ) { 975 if ( s.isEmpty() ) {
976 s = tr( "Unnamed" ); 976 s = tr( "Unnamed" );
977 currentFileName=s; 977 currentFileName=s;
978 } 978 }
979// if(s.left(1) == "/") 979// if(s.left(1) == "/")
980// s = s.right(s.length()-1); 980// s = s.right(s.length()-1);
981 setCaption( tr("%1 - Text Editor").arg( s ) ); 981 setCaption( tr("%1 - Text Editor").arg( s ) );
982 } 982 }
983} 983}
984 984
985void TextEdit::setDocument(const QString& fileref) { 985void TextEdit::setDocument(const QString& fileref) {
986 if(fileref != "Unnamed") { 986 if(fileref != "Unnamed") {
987 currentFileName=fileref; 987 currentFileName=fileref;
988 odebug << "setDocument" << oendl; 988 odebug << "setDocument" << oendl;
989 QFileInfo fi(currentFileName); 989 QFileInfo fi(currentFileName);
990 odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl; 990 odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl;
991 if( (fi.baseName().left(1)).isEmpty() ) { 991 if( (fi.baseName().left(1)).isEmpty() ) {
992 openDotFile(currentFileName); 992 openDotFile(currentFileName);
993 993
994 } else { 994 } else {
995 odebug << "setDoc open" << oendl; 995 odebug << "setDoc open" << oendl;
996 bFromDocView = true; 996 bFromDocView = true;
997 openFile(fileref); 997 openFile(fileref);
998 editor->setEdited(true); 998 editor->setEdited(true);
999 edited1=false; 999 edited1=false;
1000 edited=true; 1000 edited=true;
1001 // fromSetDocument=false; 1001 // fromSetDocument=false;
1002 // doSearchBar(); 1002 // doSearchBar();
1003 } 1003 }
1004 } 1004 }
1005 updateCaption( currentFileName); 1005 updateCaption( currentFileName);
1006} 1006}
1007 1007
1008void TextEdit::changeFont() { 1008void TextEdit::changeFont() {
1009 QDialog *d = new QDialog ( this, "FontDialog", true ); 1009 QDialog *d = new QDialog ( this, "FontDialog", true );
1010 d-> setCaption ( tr( "Choose font" )); 1010 d-> setCaption ( tr( "Choose font" ));
1011 QBoxLayout *lay = new QVBoxLayout ( d ); 1011 QBoxLayout *lay = new QVBoxLayout ( d );
1012 OFontSelector *ofs = new OFontSelector ( true, d ); 1012 OFontSelector *ofs = new OFontSelector ( true, d );
1013 lay-> addWidget ( ofs ); 1013 lay-> addWidget ( ofs );
1014 ofs-> setSelectedFont ( editor-> font ( )); 1014 ofs-> setSelectedFont ( editor-> font ( ));
1015 1015
1016 if ( QPEApplication::execDialog( d ) == QDialog::Accepted ) 1016 if ( QPEApplication::execDialog( d ) == QDialog::Accepted )
1017 editor-> setFont ( ofs-> selectedFont ( )); 1017 editor-> setFont ( ofs-> selectedFont ( ));
1018 delete d; 1018 delete d;
1019 1019
1020} 1020}
1021 1021
1022void TextEdit::editDelete() { 1022void TextEdit::editDelete() {
1023 switch ( QMessageBox::warning(this,tr("Text Editor"), 1023 switch ( QMessageBox::warning(this,tr("Text Editor"),
1024 tr("Do you really want<BR>to <B>delete</B> " 1024 tr("Do you really want<BR>to <B>delete</B> "
1025 "the current file\nfrom the disk?<BR>This is " 1025 "the current file\nfrom the disk?<BR>This is "
1026 "<B>irreversable!</B>"), 1026 "<B>irreversable!</B>"),
1027 tr("Yes"),tr("No"),0,0,1) ) { 1027 tr("Yes"),tr("No"),0,0,1) ) {
1028 case 0: 1028 case 0:
1029 if(doc) { 1029 if(doc) {
1030 doc->removeFiles(); 1030 doc->removeFiles();
1031 clear(); 1031 clear();
1032 setCaption( tr("Text Editor") ); 1032 setCaption( tr("Text Editor") );
1033 } 1033 }
1034 break; 1034 break;
1035 case 1: 1035 case 1:
1036 // exit 1036 // exit
1037 break; 1037 break;
1038 }; 1038 };
1039} 1039}
1040 1040
1041void TextEdit::changeStartConfig( bool b ) { 1041void TextEdit::changeStartConfig( bool b ) {
1042 startWithNew=b; 1042 startWithNew=b;
1043 Config cfg("TextEdit"); 1043 Config cfg("TextEdit");
1044 cfg.setGroup("View"); 1044 cfg.setGroup("View");
1045 cfg.writeEntry("startNew",b); 1045 cfg.writeEntry("startNew",b);
1046 update(); 1046 update();
1047} 1047}
1048 1048
1049void TextEdit::editorChanged() { 1049void TextEdit::editorChanged() {
1050// odebug << "editor changed" << oendl; 1050// odebug << "editor changed" << oendl;
1051 if( /*editor->edited() &&*/ /*edited && */!edited1) { 1051 if( /*editor->edited() &&*/ /*edited && */!edited1) {
1052 setCaption( "*"+caption()); 1052 setCaption( "*"+caption());
1053 edited1=true; 1053 edited1=true;
1054 } 1054 }
1055 edited=true; 1055 edited=true;
1056} 1056}
1057 1057
1058void TextEdit::receive(const QCString&msg, const QByteArray &) { 1058void TextEdit::receive(const QCString&msg, const QByteArray &) {
1059 odebug << "QCop "+msg << oendl; 1059 odebug << "QCop "+msg << oendl;
1060 if ( msg == "setDocument(QString)" ) { 1060 if ( msg == "setDocument(QString)" ) {
1061 odebug << "bugger all" << oendl; 1061 odebug << "bugger all" << oendl;
1062 1062
1063 } 1063 }
1064 1064
1065} 1065}
1066 1066
1067void TextEdit::doAbout() { 1067void TextEdit::doAbout() {
1068 QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" 1068 QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>"
1069 "2000 Trolltech AS, and<BR>" 1069 "2000 Trolltech AS, and<BR>"
1070 "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" 1070 "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>"
1071 "and is licensed under the GPL")); 1071 "and is licensed under the GPL"));
1072} 1072}
1073 1073
1074void TextEdit::doPrompt(bool b) { 1074void TextEdit::doPrompt(bool b) {
1075 promptExit=b; 1075 promptExit=b;
1076 Config cfg("TextEdit"); 1076 Config cfg("TextEdit");
1077 cfg.setGroup ( "View" ); 1077 cfg.setGroup ( "View" );
1078 cfg.writeEntry ( "PromptExit", b); 1078 cfg.writeEntry ( "PromptExit", b);
1079} 1079}
1080 1080
1081void TextEdit::doDesktop(bool b) { 1081void TextEdit::doDesktop(bool b) {
1082 openDesktop=b; 1082 openDesktop=b;
1083 Config cfg("TextEdit"); 1083 Config cfg("TextEdit");
1084 cfg.setGroup ( "View" ); 1084 cfg.setGroup ( "View" );
1085 cfg.writeEntry ( "OpenDesktop", b); 1085 cfg.writeEntry ( "OpenDesktop", b);
1086} 1086}
1087 1087
1088void TextEdit::doFilePerms(bool b) { 1088void TextEdit::doFilePerms(bool b) {
1089 filePerms=b; 1089 filePerms=b;
1090 Config cfg("TextEdit"); 1090 Config cfg("TextEdit");
1091 cfg.setGroup ( "View" ); 1091 cfg.setGroup ( "View" );
1092 cfg.writeEntry ( "FilePermissions", b); 1092 cfg.writeEntry ( "FilePermissions", b);
1093} 1093}
1094 1094
1095void TextEdit::editPasteTimeDate() { 1095void TextEdit::editPasteTimeDate() {
1096#ifndef QT_NO_CLIPBOARD 1096#ifndef QT_NO_CLIPBOARD
1097 QClipboard *cb = QApplication::clipboard(); 1097 QClipboard *cb = QApplication::clipboard();
1098 QDateTime dt = QDateTime::currentDateTime(); 1098 QDateTime dt = QDateTime::currentDateTime();
1099 cb->setText( dt.toString()); 1099 cb->setText( dt.toString());
1100 editor->paste(); 1100 editor->paste();
1101#endif 1101#endif
1102} 1102}
1103 1103
1104int TextEdit::savePrompt() 1104int TextEdit::savePrompt()
1105{ 1105{
1106 switch( QMessageBox::information( 0, (tr("Textedit")), 1106 switch( QMessageBox::information( 0, (tr("Textedit")),
1107 (tr("Textedit detected\n" 1107 (tr("Textedit detected\n"
1108 "you have unsaved changes\n" 1108 "you have unsaved changes\n"
1109 "Go ahead and save?\n")), 1109 "Go ahead and save?\n")),
1110 (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) 1110 (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) )
1111 { 1111 {
1112 case 0: 1112 case 0:
1113 { 1113 {
1114 return 1; 1114 return 1;
1115 } 1115 }
1116 break; 1116 break;
1117 1117
1118 case 1: 1118 case 1:
1119 { 1119 {
1120 return 2; 1120 return 2;
1121 } 1121 }
1122 break; 1122 break;
1123 1123
1124 case 2: 1124 case 2:
1125 { 1125 {
1126 return -1; 1126 return -1;
1127 } 1127 }
1128 break; 1128 break;
1129 }; 1129 };
1130 1130
1131 return 0; 1131 return 0;
1132} 1132}
1133 1133
1134void TextEdit::timerCrank() 1134void TextEdit::timerCrank()
1135{ 1135{
1136 if(featureAutoSave && edited1) 1136 if(featureAutoSave && edited1)
1137 { 1137 {
1138 if(currentFileName.isEmpty()) 1138 if(currentFileName.isEmpty())
1139 { 1139 {
1140 currentFileName = QDir::homeDirPath()+"/textedit.tmp"; 1140 currentFileName = QDir::homeDirPath()+"/textedit.tmp";
1141 saveAs(); 1141 saveAs();
1142 } 1142 }
1143 else 1143 else
1144 { 1144 {
1145// odebug << "autosave" << oendl; 1145// odebug << "autosave" << oendl;
1146 save(); 1146 save();
1147 } 1147 }
1148 setTimer(); 1148 setTimer();
1149 } 1149 }
1150} 1150}
1151 1151
1152void TextEdit::doTimer(bool b) 1152void TextEdit::doTimer(bool b)
1153{ 1153{
1154 Config cfg("TextEdit"); 1154 Config cfg("TextEdit");
1155 cfg.setGroup ( "View" ); 1155 cfg.setGroup ( "View" );
1156 cfg.writeEntry ( "autosave", b); 1156 cfg.writeEntry ( "autosave", b);
1157 featureAutoSave = b; 1157 featureAutoSave = b;
1158 nAutoSave->setOn(b); 1158 nAutoSave->setOn(b);
1159 if(b) 1159 if(b)
1160 { 1160 {
1161// odebug << "doTimer true" << oendl; 1161// odebug << "doTimer true" << oendl;
1162 setTimer(); 1162 setTimer();
1163 } 1163 }
1164// else 1164// else
1165// odebug << "doTimer false" << oendl; 1165// odebug << "doTimer false" << oendl;
1166} 1166}
1167 1167
1168void TextEdit::setTimer() 1168void TextEdit::setTimer()
1169{ 1169{
1170if(featureAutoSave) 1170if(featureAutoSave)
1171 { 1171 {
1172// odebug << "setting autosave" << oendl; 1172// odebug << "setting autosave" << oendl;
1173 QTimer *timer = new QTimer(this ); 1173 QTimer *timer = new QTimer(this );
1174 connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); 1174 connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) );
1175 timer->start( 300000, true); //5 minutes 1175 timer->start( 300000, true); //5 minutes
1176 } 1176 }
1177} 1177}
1178 1178
1179void TextEdit::gotoLine() { 1179void TextEdit::gotoLine() {
1180 if( editor->length() < 1) 1180 if( editor->length() < 1)
1181 return; 1181 return;
1182 QWidget *d = QApplication::desktop(); 1182 QWidget *d = QApplication::desktop();
1183 gotoEdit = new QLineEdit( 0, "Goto line"); 1183 gotoEdit = new QLineEdit( 0, "Goto line");
1184 1184
1185 gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2)); 1185 gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2));
1186 gotoEdit->setFrame(true); 1186 gotoEdit->setFrame(true);
1187 gotoEdit->show(); 1187 gotoEdit->show();
1188 connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto())); 1188 connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto()));
1189} 1189}
1190 1190
1191void TextEdit::doGoto() { 1191void TextEdit::doGoto() {
1192 QString number = gotoEdit->text(); 1192 QString number = gotoEdit->text();
1193 gotoEdit->hide(); 1193 gotoEdit->hide();
1194 1194
1195 if(gotoEdit) { 1195 if(gotoEdit) {
1196 delete gotoEdit; 1196 delete gotoEdit;
1197 gotoEdit = 0; 1197 gotoEdit = 0;
1198 } 1198 }
1199 1199
1200 bool ok; 1200 bool ok;
1201 int lineNumber = number.toInt(&ok, 10); 1201 int lineNumber = number.toInt(&ok, 10);
1202 if( editor->numLines() < lineNumber) 1202 if( editor->numLines() < lineNumber)
1203 QMessageBox::message(tr("Text Edit"),tr("Not enough lines")); 1203 QMessageBox::message(tr("Text Edit"),tr("Not enough lines"));
1204 else 1204 else
1205 { 1205 {
1206 editor->setCursorPosition(lineNumber, 0, false); 1206 editor->setCursorPosition(lineNumber, 0, false);
1207 } 1207 }
1208} 1208}
diff --git a/core/opie-login/loginwindowimpl.cpp b/core/opie-login/loginwindowimpl.cpp
index 73c2cbe..ac24894 100644
--- a/core/opie-login/loginwindowimpl.cpp
+++ b/core/opie-login/loginwindowimpl.cpp
@@ -1,262 +1,262 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> 3             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This file is free software; you can 5 _;:,     .>    :=|. This file is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU General Public 7:`=1 )Y*s>-.--   : the terms of the GNU General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This file is distributed in the hope that 12    .i_,=:_.      -<s. This file is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
17..}^=.=       =       ; Public License for more details. 17..}^=.=       =       ; Public License for more details.
18++=   -.     .`     .: 18++=   -.     .`     .:
19 :     =  ...= . :.=- You should have received a copy of the GNU 19 :     =  ...= . :.=- You should have received a copy of the GNU
20 -.   .:....=;==+<; General Public License along with this file; 20 -.   .:....=;==+<; General Public License along with this file;
21  -_. . .   )=.  = see the file COPYING. If not, write to the 21  -_. . .   )=.  = see the file COPYING. If not, write to the
22    --        :-=` Free Software Foundation, Inc., 22    --        :-=` Free Software Foundation, Inc.,
23 59 Temple Place - Suite 330, 23 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. 24 Boston, MA 02111-1307, USA.
25 25
26*/ 26*/
27#include <qpe/version.h> 27#include <qpe/version.h>
28#include <qpushbutton.h> 28#include <qpushbutton.h>
29#include <qlayout.h> 29#include <qlayout.h>
30#include <qlineedit.h> 30#include <qlineedit.h>
31#include <qtimer.h> 31#include <qtimer.h>
32#include <qcombobox.h> 32#include <qcombobox.h>
33#include <qlabel.h> 33#include <qlabel.h>
34#include <qpopupmenu.h> 34#include <qpopupmenu.h>
35#include <qmessagebox.h> 35#include <qmessagebox.h>
36#if QT_VERSION < 300 36#if QT_VERSION < 0x030000
37#include <qgfx_qws.h> 37#include <qgfx_qws.h>
38#endif 38#endif
39#include <qwindowsystem_qws.h> 39#include <qwindowsystem_qws.h>
40 40
41#include <qpe/resource.h> 41#include <qpe/resource.h>
42#include <qpe/qcopenvelope_qws.h> 42#include <qpe/qcopenvelope_qws.h>
43#include <qpe/config.h> 43#include <qpe/config.h>
44 44
45#include <opie2/odevice.h> 45#include <opie2/odevice.h>
46 46
47#include <stdio.h> 47#include <stdio.h>
48#include <stdlib.h> 48#include <stdlib.h>
49 49
50#include "passworddialogimpl.h" 50#include "passworddialogimpl.h"
51#include "loginwindowimpl.h" 51#include "loginwindowimpl.h"
52#include "loginapplication.h" 52#include "loginapplication.h"
53#include "inputmethods.h" 53#include "inputmethods.h"
54 54
55using namespace Opie::Core; 55using namespace Opie::Core;
56 56
57 57
58LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose ) 58LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose )
59{ 59{
60 QPopupMenu *pop = new QPopupMenu ( this ); 60 QPopupMenu *pop = new QPopupMenu ( this );
61 pop-> insertItem ( tr( "Restart" ), this, SLOT( restart())); 61 pop-> insertItem ( tr( "Restart" ), this, SLOT( restart()));
62 pop-> insertItem ( tr( "Quit" ), this, SLOT( quit())); 62 pop-> insertItem ( tr( "Quit" ), this, SLOT( quit()));
63 m_menu-> setPopup ( pop ); 63 m_menu-> setPopup ( pop );
64 64
65 QCopChannel *channel = new QCopChannel ( "QPE/TaskBar", this ); 65 QCopChannel *channel = new QCopChannel ( "QPE/TaskBar", this );
66 connect ( channel, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( receive(const QCString&,const QByteArray&))); 66 connect ( channel, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( receive(const QCString&,const QByteArray&)));
67 67
68 QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 ); 68 QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 );
69 m_input = new InputMethods ( m_taskbar ); 69 m_input = new InputMethods ( m_taskbar );
70 connect ( m_input, SIGNAL( inputToggled(bool)), this, SLOT( calcMaxWindowRect())); 70 connect ( m_input, SIGNAL( inputToggled(bool)), this, SLOT( calcMaxWindowRect()));
71 lay-> addWidget ( m_input ); 71 lay-> addWidget ( m_input );
72 lay-> addStretch ( 10 ); 72 lay-> addStretch ( 10 );
73 73
74 setActiveWindow ( ); 74 setActiveWindow ( );
75 m_password-> setFocus ( ); 75 m_password-> setFocus ( );
76 76
77 m_user-> insertStringList ( lApp-> allUsers ( )); 77 m_user-> insertStringList ( lApp-> allUsers ( ));
78 78
79 //there is no point in displaying the IM for a zaurus 79 //there is no point in displaying the IM for a zaurus
80 if (ODevice::inst ( )-> series ( ) != Model_Zaurus){ 80 if (ODevice::inst ( )-> series ( ) != Model_Zaurus){
81 QTimer::singleShot ( 0, this, SLOT( showIM())); 81 QTimer::singleShot ( 0, this, SLOT( showIM()));
82 } 82 }
83 83
84 QString opiedir = ::getenv ( "OPIEDIR" ); 84 QString opiedir = ::getenv ( "OPIEDIR" );
85 QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" ); 85 QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" );
86 86
87 if ( !bgpix. isNull ( )) { 87 if ( !bgpix. isNull ( )) {
88 setBackgroundPixmap ( bgpix ); 88 setBackgroundPixmap ( bgpix );
89 m_caption-> setBackgroundPixmap ( bgpix); 89 m_caption-> setBackgroundPixmap ( bgpix);
90 TextLabel1-> setBackgroundPixmap ( bgpix); 90 TextLabel1-> setBackgroundPixmap ( bgpix);
91 TextLabel2-> setBackgroundPixmap ( bgpix); 91 TextLabel2-> setBackgroundPixmap ( bgpix);
92 } 92 }
93 93
94 //m_caption-> setText ( tr("<center>Welcome to OPIE %1</center><center>& %2 %3</center>"). arg(QPE_VERSION). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( ))); 94 //m_caption-> setText ( tr("<center>Welcome to OPIE %1</center><center>& %2 %3</center>"). arg(QPE_VERSION). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( )));
95 95
96 Config cfg ( "opie-login" ); 96 Config cfg ( "opie-login" );
97 cfg. setGroup ( "General" ); 97 cfg. setGroup ( "General" );
98 QString last = cfg. readEntry ( "LastLogin" ); 98 QString last = cfg. readEntry ( "LastLogin" );
99 99
100 if ( !last. isEmpty ( )) 100 if ( !last. isEmpty ( ))
101 m_user-> setEditText ( last ); 101 m_user-> setEditText ( last );
102 102
103 calcMaxWindowRect ( ); 103 calcMaxWindowRect ( );
104 104
105 if ( PasswordDialogImpl::needDialog() ) 105 if ( PasswordDialogImpl::needDialog() )
106 QTimer::singleShot(10, this, SLOT(showPasswordDialog()) ); 106 QTimer::singleShot(10, this, SLOT(showPasswordDialog()) );
107 107
108 108
109} 109}
110 110
111LoginWindowImpl::~LoginWindowImpl ( ) 111LoginWindowImpl::~LoginWindowImpl ( )
112{ 112{
113} 113}
114 114
115 115
116void LoginWindowImpl::receive ( const QCString &msg, const QByteArray &data ) 116void LoginWindowImpl::receive ( const QCString &msg, const QByteArray &data )
117{ 117{
118 QDataStream stream ( data, IO_ReadOnly ); 118 QDataStream stream ( data, IO_ReadOnly );
119 119
120 if ( msg == "hideInputMethod()" ) 120 if ( msg == "hideInputMethod()" )
121 m_input-> hideInputMethod ( ); 121 m_input-> hideInputMethod ( );
122 else if ( msg == "showInputMethod()" ) 122 else if ( msg == "showInputMethod()" )
123 m_input-> showInputMethod ( ); 123 m_input-> showInputMethod ( );
124 else if ( msg == "reloadInputMethods()" ) 124 else if ( msg == "reloadInputMethods()" )
125 m_input-> loadInputMethods ( ); 125 m_input-> loadInputMethods ( );
126} 126}
127 127
128void LoginWindowImpl::calcMaxWindowRect ( ) 128void LoginWindowImpl::calcMaxWindowRect ( )
129{ 129{
130#ifdef Q_WS_QWS 130#ifdef Q_WS_QWS
131 QRect wr; 131 QRect wr;
132 int displayWidth = qApp-> desktop ( )-> width ( ); 132 int displayWidth = qApp-> desktop ( )-> width ( );
133 QRect ir = m_input-> inputRect ( ); 133 QRect ir = m_input-> inputRect ( );
134 if ( ir.isValid() ) 134 if ( ir.isValid() )
135 wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 ); 135 wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 );
136 else 136 else
137 wr.setCoords( 0, 0, displayWidth-1, m_taskbar->y()-1 ); 137 wr.setCoords( 0, 0, displayWidth-1, m_taskbar->y()-1 );
138 138
139#if QT_VERSION < 300 139#if QT_VERSION < 0x030000
140 wr = qt_screen-> mapToDevice ( wr, QSize ( qt_screen-> width ( ), qt_screen-> height ( ))); 140 wr = qt_screen-> mapToDevice ( wr, QSize ( qt_screen-> width ( ), qt_screen-> height ( )));
141#endif 141#endif
142 142
143 QWSServer::setMaxWindowRect( wr ); 143 QWSServer::setMaxWindowRect( wr );
144#endif 144#endif
145} 145}
146 146
147 147
148void LoginWindowImpl::keyPressEvent ( QKeyEvent *e ) 148void LoginWindowImpl::keyPressEvent ( QKeyEvent *e )
149{ 149{
150 switch ( e-> key ( )) { 150 switch ( e-> key ( )) {
151 case HardKey_Suspend: suspend ( ); 151 case HardKey_Suspend: suspend ( );
152 break; 152 break;
153 case HardKey_Backlight: backlight ( ); 153 case HardKey_Backlight: backlight ( );
154 break; 154 break;
155 default: e-> ignore ( ); 155 default: e-> ignore ( );
156 break; 156 break;
157 } 157 }
158 LoginWindow::keyPressEvent ( e ); 158 LoginWindow::keyPressEvent ( e );
159} 159}
160 160
161 161
162void LoginWindowImpl::toggleEchoMode ( bool t ) 162void LoginWindowImpl::toggleEchoMode ( bool t )
163{ 163{
164 m_password-> setEchoMode ( t ? QLineEdit::Normal : QLineEdit::Password ); 164 m_password-> setEchoMode ( t ? QLineEdit::Normal : QLineEdit::Password );
165} 165}
166 166
167void LoginWindowImpl::showIM ( ) 167void LoginWindowImpl::showIM ( )
168{ 168{
169 m_input-> showInputMethod ( ); 169 m_input-> showInputMethod ( );
170} 170}
171 171
172void LoginWindowImpl::restart ( ) 172void LoginWindowImpl::restart ( )
173{ 173{
174 qApp-> quit ( ); 174 qApp-> quit ( );
175} 175}
176 176
177void LoginWindowImpl::quit ( ) 177void LoginWindowImpl::quit ( )
178{ 178{
179 lApp-> quitToConsole ( ); 179 lApp-> quitToConsole ( );
180} 180}
181 181
182void LoginWindowImpl::suspend ( ) 182void LoginWindowImpl::suspend ( )
183{ 183{
184 ODevice::inst ( )-> suspend ( ); 184 ODevice::inst ( )-> suspend ( );
185 185
186 QCopEnvelope e("QPE/System", "setBacklight(int)"); 186 QCopEnvelope e("QPE/System", "setBacklight(int)");
187 e << -3; // Force on 187 e << -3; // Force on
188} 188}
189 189
190void LoginWindowImpl::backlight ( ) 190void LoginWindowImpl::backlight ( )
191{ 191{
192 QCopEnvelope e("QPE/System", "setBacklight(int)"); 192 QCopEnvelope e("QPE/System", "setBacklight(int)");
193 e << -2; // toggle 193 e << -2; // toggle
194} 194}
195 195
196class WaitLogo : public QLabel { 196class WaitLogo : public QLabel {
197public: 197public:
198 WaitLogo ( ) : QLabel ( 0, "wait hack!", WStyle_Customize | WStyle_NoBorder | WStyle_Tool ) 198 WaitLogo ( ) : QLabel ( 0, "wait hack!", WStyle_Customize | WStyle_NoBorder | WStyle_Tool )
199 { 199 {
200 QImage img = Resource::loadImage ( "launcher/new_wait" ); 200 QImage img = Resource::loadImage ( "launcher/new_wait" );
201 QPixmap pix; 201 QPixmap pix;
202 pix. convertFromImage ( img ); 202 pix. convertFromImage ( img );
203 setPixmap ( pix ); 203 setPixmap ( pix );
204 setAlignment ( AlignCenter ); 204 setAlignment ( AlignCenter );
205 move ( 0, 0 ); 205 move ( 0, 0 );
206 resize ( qApp-> desktop ( )-> width ( ), qApp-> desktop ( )-> height ( )); 206 resize ( qApp-> desktop ( )-> width ( ), qApp-> desktop ( )-> height ( ));
207 207
208 m_visible = false; 208 m_visible = false;
209 show ( ); 209 show ( );
210 } 210 }
211 211
212 virtual void showEvent ( QShowEvent *e ) 212 virtual void showEvent ( QShowEvent *e )
213 { 213 {
214 QLabel::showEvent ( e ); 214 QLabel::showEvent ( e );
215 m_visible = true; 215 m_visible = true;
216 } 216 }
217 217
218 virtual void paintEvent ( QPaintEvent *e ) 218 virtual void paintEvent ( QPaintEvent *e )
219 { 219 {
220 QLabel::paintEvent ( e ); 220 QLabel::paintEvent ( e );
221 if ( m_visible ) 221 if ( m_visible )
222 qApp-> quit ( ); 222 qApp-> quit ( );
223 } 223 }
224 224
225private: 225private:
226 bool m_visible; 226 bool m_visible;
227}; 227};
228 228
229void LoginWindowImpl::login ( ) 229void LoginWindowImpl::login ( )
230{ 230{
231 const char *user = ::strdup ( m_user-> currentText ( ). local8Bit ( )); 231 const char *user = ::strdup ( m_user-> currentText ( ). local8Bit ( ));
232 const char *pass = ::strdup ( m_password-> text ( ). local8Bit ( )); 232 const char *pass = ::strdup ( m_password-> text ( ). local8Bit ( ));
233 233
234 if ( !user || !user [0] ) 234 if ( !user || !user [0] )
235 return; 235 return;
236 if ( !pass ) 236 if ( !pass )
237 pass = ""; 237 pass = "";
238 238
239 if ( lApp-> checkPassword ( user, pass )) { 239 if ( lApp-> checkPassword ( user, pass )) {
240 Config cfg ( "opie-login" ); 240 Config cfg ( "opie-login" );
241 cfg. setGroup ( "General" ); 241 cfg. setGroup ( "General" );
242 cfg. writeEntry ( "LastLogin", user ); 242 cfg. writeEntry ( "LastLogin", user );
243 cfg. write ( ); 243 cfg. write ( );
244 244
245 lApp-> setLoginAs ( user ); 245 lApp-> setLoginAs ( user );
246 246
247 // Draw a big wait icon, the image can be altered in later revisions 247 // Draw a big wait icon, the image can be altered in later revisions
248 m_input-> hideInputMethod ( ); 248 m_input-> hideInputMethod ( );
249 new WaitLogo ( ); 249 new WaitLogo ( );
250 // WaitLogo::showEvent() calls qApp-> quit() 250 // WaitLogo::showEvent() calls qApp-> quit()
251 } 251 }
252 else { 252 else {
253 QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." )); 253 QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." ));
254 m_password-> clear ( ); 254 m_password-> clear ( );
255 } 255 }
256} 256}
257 257
258void LoginWindowImpl::showPasswordDialog() { 258void LoginWindowImpl::showPasswordDialog() {
259 PasswordDialogImpl dia( this ); 259 PasswordDialogImpl dia( this );
260 dia.showMaximized(); 260 dia.showMaximized();
261 dia.exec(); 261 dia.exec();
262} 262}
diff --git a/freetype/fontfactoryttf_qws.h b/freetype/fontfactoryttf_qws.h
index 208ab61..ff0fcfc 100644
--- a/freetype/fontfactoryttf_qws.h
+++ b/freetype/fontfactoryttf_qws.h
@@ -1,63 +1,63 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21 21
22#ifndef FONTFACTORY_FT_H 22#ifndef FONTFACTORY_FT_H
23#define FONTFACTORY_FT_H 23#define FONTFACTORY_FT_H
24 24
25#include <qfontmanager_qws.h> 25#include <qfontmanager_qws.h>
26#if QT_VERSION >= 300 26#if QT_VERSION >= 0x030000
27# include <private/qfontdata_p.h> 27# include <private/qfontdata_p.h>
28#else 28#else
29# include "qfontdata_p.h" 29# include "qfontdata_p.h"
30#endif 30#endif
31 31
32 32
33#ifdef QT_NO_FREETYPE 33#ifdef QT_NO_FREETYPE
34 34
35extern "C" { 35extern "C" {
36#include <freetype/freetype.h> 36#include <freetype/freetype.h>
37} 37}
38 38
39// ascent, descent, width(ch), width(string), maxwidth? 39// ascent, descent, width(ch), width(string), maxwidth?
40// leftbearing, rightbearing, minleftbearing,minrightbearing 40// leftbearing, rightbearing, minleftbearing,minrightbearing
41// leading 41// leading
42 42
43class QFontFactoryFT : public QFontFactory { 43class QFontFactoryFT : public QFontFactory {
44 44
45public: 45public:
46 46
47 QFontFactoryFT(); 47 QFontFactoryFT();
48 virtual ~QFontFactoryFT(); 48 virtual ~QFontFactoryFT();
49 49
50 QRenderedFont * get(const QFontDef &,QDiskFont *); 50 QRenderedFont * get(const QFontDef &,QDiskFont *);
51 virtual void load(QDiskFont *) const; 51 virtual void load(QDiskFont *) const;
52 virtual QString name(); 52 virtual QString name();
53 53
54private: 54private:
55 55
56 friend class QRenderedFontFT; 56 friend class QRenderedFontFT;
57 FT_Library library; 57 FT_Library library;
58}; 58};
59 59
60#endif // QT_NO_FREETYPE 60#endif // QT_NO_FREETYPE
61 61
62#endif // QFONTFACTORY_FT_H 62#endif // QFONTFACTORY_FT_H
63 63
diff --git a/libopie2/opieui/oseparator.cpp b/libopie2/opieui/oseparator.cpp
index bbc4381..177368b 100644
--- a/libopie2/opieui/oseparator.cpp
+++ b/libopie2/opieui/oseparator.cpp
@@ -1,129 +1,129 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 3              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
4 Copyright (C) 1997 Michael Roth <mroth@wirlweb.de> 4 Copyright (C) 1997 Michael Roth <mroth@wirlweb.de>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32/* OPIE */ 32/* OPIE */
33 33
34#include <opie2/odebug.h> 34#include <opie2/odebug.h>
35#include <opie2/oseparator.h> 35#include <opie2/oseparator.h>
36 36
37/* QT */ 37/* QT */
38 38
39using namespace Opie::Core; 39using namespace Opie::Core;
40using namespace Opie::Ui; 40using namespace Opie::Ui;
41 41
42OSeparator::OSeparator(QWidget* parent, const char* name, WFlags f) 42OSeparator::OSeparator(QWidget* parent, const char* name, WFlags f)
43 : QFrame(parent, name, f) 43 : QFrame(parent, name, f)
44{ 44{
45 setLineWidth(1); 45 setLineWidth(1);
46 setMidLineWidth(0); 46 setMidLineWidth(0);
47 setOrientation( HLine ); 47 setOrientation( HLine );
48} 48}
49 49
50 50
51 51
52OSeparator::OSeparator(int orientation, QWidget* parent, const char* name, WFlags f) 52OSeparator::OSeparator(int orientation, QWidget* parent, const char* name, WFlags f)
53 : QFrame(parent, name, f) 53 : QFrame(parent, name, f)
54{ 54{
55 setLineWidth(1); 55 setLineWidth(1);
56 setMidLineWidth(0); 56 setMidLineWidth(0);
57 setOrientation( orientation ); 57 setOrientation( orientation );
58} 58}
59 59
60 60
61 61
62void OSeparator::setOrientation(int orientation) 62void OSeparator::setOrientation(int orientation)
63{ 63{
64 switch(orientation) 64 switch(orientation)
65 { 65 {
66 case Vertical: 66 case Vertical:
67 case VLine: 67 case VLine:
68 setFrameStyle( QFrame::VLine | QFrame::Sunken ); 68 setFrameStyle( QFrame::VLine | QFrame::Sunken );
69 setMinimumSize(2, 0); 69 setMinimumSize(2, 0);
70 break; 70 break;
71 71
72 default: 72 default:
73 owarn << "OSeparator::setOrientation(): invalid orientation, using default orientation HLine" << oendl; 73 owarn << "OSeparator::setOrientation(): invalid orientation, using default orientation HLine" << oendl;
74 74
75 case Horizontal: 75 case Horizontal:
76 case HLine: 76 case HLine:
77 setFrameStyle( QFrame::HLine | QFrame::Sunken ); 77 setFrameStyle( QFrame::HLine | QFrame::Sunken );
78 setMinimumSize(0, 2); 78 setMinimumSize(0, 2);
79 break; 79 break;
80 } 80 }
81} 81}
82 82
83 83
84 84
85int OSeparator::orientation() const 85int OSeparator::orientation() const
86{ 86{
87 if ( frameStyle() & VLine ) 87 if ( frameStyle() & VLine )
88 return VLine; 88 return VLine;
89 89
90 if ( frameStyle() & HLine ) 90 if ( frameStyle() & HLine )
91 return HLine; 91 return HLine;
92 92
93 return 0; 93 return 0;
94} 94}
95 95
96void OSeparator::drawFrame(QPainter *p) 96void OSeparator::drawFrame(QPainter *p)
97{ 97{
98 QPointp1, p2; 98 QPointp1, p2;
99 QRectr = frameRect(); 99 QRectr = frameRect();
100 const QColorGroup & g = colorGroup(); 100 const QColorGroup & g = colorGroup();
101 101
102 if ( frameStyle() & HLine ) { 102 if ( frameStyle() & HLine ) {
103 p1 = QPoint( r.x(), r.height()/2 ); 103 p1 = QPoint( r.x(), r.height()/2 );
104 p2 = QPoint( r.x()+r.width(), p1.y() ); 104 p2 = QPoint( r.x()+r.width(), p1.y() );
105 } 105 }
106 else { 106 else {
107 p1 = QPoint( r.x()+r.width()/2, 0 ); 107 p1 = QPoint( r.x()+r.width()/2, 0 );
108 p2 = QPoint( p1.x(), r.height() ); 108 p2 = QPoint( p1.x(), r.height() );
109 } 109 }
110 110
111#if QT_VERSION < 300 111#if QT_VERSION < 0x030000
112 style().drawSeparator( p, p1.x(), p1.y(), p2.x(), p2.y(), g, true, 1, midLineWidth() ); 112 style().drawSeparator( p, p1.x(), p1.y(), p2.x(), p2.y(), g, true, 1, midLineWidth() );
113#else 113#else
114 QStyleOption opt( lineWidth(), midLineWidth() ); 114 QStyleOption opt( lineWidth(), midLineWidth() );
115 style().drawPrimitive( QStyle::PE_Separator, p, QRect( p1, p2 ), g, QStyle::Style_Sunken, opt ); 115 style().drawPrimitive( QStyle::PE_Separator, p, QRect( p1, p2 ), g, QStyle::Style_Sunken, opt );
116#endif 116#endif
117} 117}
118 118
119 119
120QSize OSeparator::sizeHint() const 120QSize OSeparator::sizeHint() const
121{ 121{
122 if ( frameStyle() & VLine ) 122 if ( frameStyle() & VLine )
123 return QSize(2, 0); 123 return QSize(2, 0);
124 124
125 if ( frameStyle() & HLine ) 125 if ( frameStyle() & HLine )
126 return QSize(0, 2); 126 return QSize(0, 2);
127 127
128 return QSize(-1, -1); 128 return QSize(-1, -1);
129} 129}
diff --git a/libopie2/qt3/opieui/oeditlistbox.h b/libopie2/qt3/opieui/oeditlistbox.h
index 63fab11..c9c207d 100644
--- a/libopie2/qt3/opieui/oeditlistbox.h
+++ b/libopie2/qt3/opieui/oeditlistbox.h
@@ -1,250 +1,250 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 2000 David Faure <faure@kde.org>, Alexander Neundorf <neundorf@kde.org> 2 Copyright (C) 2000 David Faure <faure@kde.org>, Alexander Neundorf <neundorf@kde.org>
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either 6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version. 7 version 2 of the License, or (at your option) any later version.
8 8
9 This library is distributed in the hope that it will be useful, 9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details. 12 Library General Public License for more details.
13 13
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#ifndef OEDITLISTBOX_H 20#ifndef OEDITLISTBOX_H
21#define OEDITLISTBOX_H 21#define OEDITLISTBOX_H
22 22
23#include <qgroupbox.h> 23#include <qgroupbox.h>
24#include <qlistbox.h> 24#include <qlistbox.h>
25 25
26class OLineEdit; 26class OLineEdit;
27class OComboBox; 27class OComboBox;
28class QPushButton; 28class QPushButton;
29 29
30#if QT_VERSION < 300 30#if QT_VERSION < 0x030000
31 enum StringComparisonMode { 31 enum StringComparisonMode {
32 CaseSensitive = 0x00001, // 0 0001 32 CaseSensitive = 0x00001, // 0 0001
33 BeginsWith = 0x00002, // 0 0010 33 BeginsWith = 0x00002, // 0 0010
34 EndsWith = 0x00004, // 0 0100 34 EndsWith = 0x00004, // 0 0100
35 Contains = 0x00008, // 0 1000 35 Contains = 0x00008, // 0 1000
36 ExactMatch = 0x00010 // 1 0000 36 ExactMatch = 0x00010 // 1 0000
37 }; 37 };
38#endif 38#endif
39 39
40class OEditListBoxPrivate; 40class OEditListBoxPrivate;
41/** 41/**
42 * An editable listbox 42 * An editable listbox
43 * 43 *
44 * This class provides a editable listbox ;-), this means 44 * This class provides a editable listbox ;-), this means
45 * a listbox which is accompanied by a line edit to enter new 45 * a listbox which is accompanied by a line edit to enter new
46 * items into the listbox and pushbuttons to add and remove 46 * items into the listbox and pushbuttons to add and remove
47 * items from the listbox and two buttons to move items up and down. 47 * items from the listbox and two buttons to move items up and down.
48 */ 48 */
49class OEditListBox : public QGroupBox 49class OEditListBox : public QGroupBox
50{ 50{
51 Q_OBJECT 51 Q_OBJECT
52 52
53public: 53public:
54 /// @since 3.1 54 /// @since 3.1
55 class CustomEditor 55 class CustomEditor
56 { 56 {
57 public: 57 public:
58 CustomEditor() 58 CustomEditor()
59 : m_representationWidget( 0L ), 59 : m_representationWidget( 0L ),
60 m_lineEdit( 0L ) {} 60 m_lineEdit( 0L ) {}
61 CustomEditor( QWidget *repWidget, OLineEdit *edit ) 61 CustomEditor( QWidget *repWidget, OLineEdit *edit )
62 : m_representationWidget( repWidget ), 62 : m_representationWidget( repWidget ),
63 m_lineEdit( edit ) {} 63 m_lineEdit( edit ) {}
64 CustomEditor( OComboBox *combo ); 64 CustomEditor( OComboBox *combo );
65 65
66 void setRepresentationWidget( QWidget *repWidget ) { 66 void setRepresentationWidget( QWidget *repWidget ) {
67 m_representationWidget = repWidget; 67 m_representationWidget = repWidget;
68 } 68 }
69 void setLineEdit( OLineEdit *edit ) { 69 void setLineEdit( OLineEdit *edit ) {
70 m_lineEdit = edit; 70 m_lineEdit = edit;
71 } 71 }
72 72
73 virtual QWidget *representationWidget() const { 73 virtual QWidget *representationWidget() const {
74 return m_representationWidget; 74 return m_representationWidget;
75 } 75 }
76 virtual OLineEdit *lineEdit() const { 76 virtual OLineEdit *lineEdit() const {
77 return m_lineEdit; 77 return m_lineEdit;
78 } 78 }
79 79
80 protected: 80 protected:
81 QWidget *m_representationWidget; 81 QWidget *m_representationWidget;
82 OLineEdit *m_lineEdit; 82 OLineEdit *m_lineEdit;
83 }; 83 };
84 84
85 public: 85 public:
86 86
87 /** 87 /**
88 * Enumeration of the buttons, the listbox offers. Specify them in the 88 * Enumeration of the buttons, the listbox offers. Specify them in the
89 * constructor in the buttons parameter. 89 * constructor in the buttons parameter.
90 */ 90 */
91 enum Button { Add = 1, Remove = 2, UpDown = 4, All = Add|Remove|UpDown }; 91 enum Button { Add = 1, Remove = 2, UpDown = 4, All = Add|Remove|UpDown };
92 92
93 /** 93 /**
94 * Create an editable listbox. 94 * Create an editable listbox.
95 * 95 *
96 * If @p checkAtEntering is true, after every character you type 96 * If @p checkAtEntering is true, after every character you type
97 * in the line edit OEditListBox will enable or disable 97 * in the line edit OEditListBox will enable or disable
98 * the Add-button, depending whether the current content of the 98 * the Add-button, depending whether the current content of the
99 * line edit is already in the listbox. Maybe this can become a 99 * line edit is already in the listbox. Maybe this can become a
100 * performance hit with large lists on slow machines. 100 * performance hit with large lists on slow machines.
101 * If @p checkAtEntering is false, 101 * If @p checkAtEntering is false,
102 * it will be checked if you press the Add-button. It is not 102 * it will be checked if you press the Add-button. It is not
103 * possible to enter items twice into the listbox. 103 * possible to enter items twice into the listbox.
104 */ 104 */
105 OEditListBox(QWidget *parent = 0, const char *name = 0, 105 OEditListBox(QWidget *parent = 0, const char *name = 0,
106 bool checkAtEntering=false, int buttons = All ); 106 bool checkAtEntering=false, int buttons = All );
107 /** 107 /**
108 * Create an editable listbox. 108 * Create an editable listbox.
109 * 109 *
110 * The same as the other constructor, additionally it takes 110 * The same as the other constructor, additionally it takes
111 * @title, which will be the title of the frame around the listbox. 111 * @title, which will be the title of the frame around the listbox.
112 */ 112 */
113 OEditListBox(const QString& title, QWidget *parent = 0, 113 OEditListBox(const QString& title, QWidget *parent = 0,
114 const char *name = 0, bool checkAtEntering=false, 114 const char *name = 0, bool checkAtEntering=false,
115 int buttons = All ); 115 int buttons = All );
116 116
117 /** 117 /**
118 * Another constructor, which allows to use a custom editing widget 118 * Another constructor, which allows to use a custom editing widget
119 * instead of the standard OLineEdit widget. E.g. you can use a 119 * instead of the standard OLineEdit widget. E.g. you can use a
120 * @ref OURLRequester or a @ref OComboBox as input widget. The custom 120 * @ref OURLRequester or a @ref OComboBox as input widget. The custom
121 * editor must consist of a lineedit and optionally another widget that 121 * editor must consist of a lineedit and optionally another widget that
122 * is used as representation. A OComboBox or a OURLRequester have a 122 * is used as representation. A OComboBox or a OURLRequester have a
123 * OLineEdit as child-widget for example, so the OComboBox is used as 123 * OLineEdit as child-widget for example, so the OComboBox is used as
124 * the representation widget. 124 * the representation widget.
125 * 125 *
126 * @see OURLRequester::customEditor() 126 * @see OURLRequester::customEditor()
127 * @since 3.1 127 * @since 3.1
128 */ 128 */
129 OEditListBox( const QString& title, 129 OEditListBox( const QString& title,
130 const CustomEditor &customEditor, 130 const CustomEditor &customEditor,
131 QWidget *parent = 0, const char *name = 0, 131 QWidget *parent = 0, const char *name = 0,
132 bool checkAtEntering = false, int buttons = All ); 132 bool checkAtEntering = false, int buttons = All );
133 133
134 virtual ~OEditListBox(); 134 virtual ~OEditListBox();
135 135
136 /** 136 /**
137 * Return a pointer to the embedded QListBox. 137 * Return a pointer to the embedded QListBox.
138 */ 138 */
139 QListBox* listBox() const { return m_listBox; } 139 QListBox* listBox() const { return m_listBox; }
140 /** 140 /**
141 * Return a pointer to the embedded QLineEdit. 141 * Return a pointer to the embedded QLineEdit.
142 */ 142 */
143 OLineEdit* lineEdit() const { return m_lineEdit; } 143 OLineEdit* lineEdit() const { return m_lineEdit; }
144 /** 144 /**
145 * Return a pointer to the Add button 145 * Return a pointer to the Add button
146 */ 146 */
147 QPushButton* addButton() const { return servNewButton; } 147 QPushButton* addButton() const { return servNewButton; }
148 /** 148 /**
149 * Return a pointer to the Remove button 149 * Return a pointer to the Remove button
150 */ 150 */
151 QPushButton* removeButton() const { return servRemoveButton; } 151 QPushButton* removeButton() const { return servRemoveButton; }
152 /** 152 /**
153 * Return a pointer to the Up button 153 * Return a pointer to the Up button
154 */ 154 */
155 QPushButton* upButton() const { return servUpButton; } 155 QPushButton* upButton() const { return servUpButton; }
156 /** 156 /**
157 * Return a pointer to the Down button 157 * Return a pointer to the Down button
158 */ 158 */
159 QPushButton* downButton() const { return servDownButton; } 159 QPushButton* downButton() const { return servDownButton; }
160 160
161 /** 161 /**
162 * See @ref QListBox::count() 162 * See @ref QListBox::count()
163 */ 163 */
164 int count() const { return int(m_listBox->count()); } 164 int count() const { return int(m_listBox->count()); }
165 /** 165 /**
166 * See @ref QListBox::insertStringList() 166 * See @ref QListBox::insertStringList()
167 */ 167 */
168 void insertStringList(const QStringList& list, int index=-1); 168 void insertStringList(const QStringList& list, int index=-1);
169 /** 169 /**
170 * See @ref QListBox::insertStringList() 170 * See @ref QListBox::insertStringList()
171 */ 171 */
172 void insertStrList(const QStrList* list, int index=-1); 172 void insertStrList(const QStrList* list, int index=-1);
173 /** 173 /**
174 * See @ref QListBox::insertStrList() 174 * See @ref QListBox::insertStrList()
175 */ 175 */
176 void insertStrList(const QStrList& list, int index=-1); 176 void insertStrList(const QStrList& list, int index=-1);
177 /** 177 /**
178 * See @ref QListBox::insertStrList() 178 * See @ref QListBox::insertStrList()
179 */ 179 */
180 void insertStrList(const char ** list, int numStrings=-1, int index=-1); 180 void insertStrList(const char ** list, int numStrings=-1, int index=-1);
181 /** 181 /**
182 * See @ref QListBox::insertItem() 182 * See @ref QListBox::insertItem()
183 */ 183 */
184 void insertItem(const QString& text, int index=-1) {m_listBox->insertItem(text,index);} 184 void insertItem(const QString& text, int index=-1) {m_listBox->insertItem(text,index);}
185 /** 185 /**
186 * Clears both the listbox and the line edit. 186 * Clears both the listbox and the line edit.
187 */ 187 */
188 void clear(); 188 void clear();
189 /** 189 /**
190 * See @ref QListBox::text() 190 * See @ref QListBox::text()
191 */ 191 */
192 QString text(int index) const { return m_listBox->text(index); } 192 QString text(int index) const { return m_listBox->text(index); }
193 /** 193 /**
194 * See @ref QListBox::currentItem() 194 * See @ref QListBox::currentItem()
195 */ 195 */
196 int currentItem() const; 196 int currentItem() const;
197 /** 197 /**
198 * See @ref QListBox::currentText() 198 * See @ref QListBox::currentText()
199 */ 199 */
200 QString currentText() const { return m_listBox->currentText(); } 200 QString currentText() const { return m_listBox->currentText(); }
201 201
202 /** 202 /**
203 * @returns a stringlist of all items in the listbox 203 * @returns a stringlist of all items in the listbox
204 */ 204 */
205 QStringList items() const; 205 QStringList items() const;
206 206
207 signals: 207 signals:
208 void changed(); 208 void changed();
209 209
210 /** 210 /**
211 * This signal is emitted when the user adds a new string to the list, 211 * This signal is emitted when the user adds a new string to the list,
212 * the parameter is the added string. 212 * the parameter is the added string.
213 * @since 3.2 213 * @since 3.2
214 */ 214 */
215 void added( const QString & text ); 215 void added( const QString & text );
216 216
217 /** 217 /**
218 * This signal is emitted when the user removes a string from the list, 218 * This signal is emitted when the user removes a string from the list,
219 * the parameter is the removed string. 219 * the parameter is the removed string.
220 * @since 3.2 220 * @since 3.2
221 */ 221 */
222 void removed( const QString & text ); 222 void removed( const QString & text );
223 223
224 protected slots: 224 protected slots:
225 //the names should be self-explaining 225 //the names should be self-explaining
226 void moveItemUp(); 226 void moveItemUp();
227 void moveItemDown(); 227 void moveItemDown();
228 void addItem(); 228 void addItem();
229 void removeItem(); 229 void removeItem();
230 void enableMoveButtons(int index); 230 void enableMoveButtons(int index);
231 void typedSomething(const QString& text); 231 void typedSomething(const QString& text);
232 232
233 private: 233 private:
234 QListBox *m_listBox; 234 QListBox *m_listBox;
235 QPushButton *servUpButton, *servDownButton; 235 QPushButton *servUpButton, *servDownButton;
236 QPushButton *servNewButton, *servRemoveButton; 236 QPushButton *servNewButton, *servRemoveButton;
237 OLineEdit *m_lineEdit; 237 OLineEdit *m_lineEdit;
238 238
239 //this is called in both ctors, to avoid code duplication 239 //this is called in both ctors, to avoid code duplication
240 void init( bool checkAtEntering, int buttons, 240 void init( bool checkAtEntering, int buttons,
241 QWidget *representationWidget = 0L ); 241 QWidget *representationWidget = 0L );
242 242
243 protected: 243 protected:
244 virtual void virtual_hook( int id, void* data ); 244 virtual void virtual_hook( int id, void* data );
245 private: 245 private:
246 //our lovely private d-pointer 246 //our lovely private d-pointer
247 OEditListBoxPrivate *d; 247 OEditListBoxPrivate *d;
248}; 248};
249 249
250#endif // OEDITLISTBOX 250#endif // OEDITLISTBOX
diff --git a/libopie2/qt3/opieui/ojanuswidget.cpp b/libopie2/qt3/opieui/ojanuswidget.cpp
index 063e393..8bdbc03 100644
--- a/libopie2/qt3/opieui/ojanuswidget.cpp
+++ b/libopie2/qt3/opieui/ojanuswidget.cpp
@@ -1,1116 +1,1116 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4 Originally part of the KDE project 4 Originally part of the KDE project
5 (C) 1999-2000 Espen Sand (espensa@online.no) 5 (C) 1999-2000 Espen Sand (espensa@online.no)
6 =. 6 =.
7 .=l. 7 .=l.
8           .>+-= 8           .>+-=
9 _;:,     .>    :=|. This program is free software; you can 9 _;:,     .>    :=|. This program is free software; you can
10.> <`_,   >  .   <= redistribute it and/or modify it under 10.> <`_,   >  .   <= redistribute it and/or modify it under
11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
12.="- .-=="i,     .._ License as published by the Free Software 12.="- .-=="i,     .._ License as published by the Free Software
13 - .   .-<_>     .<> Foundation; either version 2 of the License, 13 - .   .-<_>     .<> Foundation; either version 2 of the License,
14     ._= =}       : or (at your option) any later version. 14     ._= =}       : or (at your option) any later version.
15    .%`+i>       _;_. 15    .%`+i>       _;_.
16    .i_,=:_.      -<s. This program is distributed in the hope that 16    .i_,=:_.      -<s. This program is distributed in the hope that
17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
18    : ..    .:,     . . . without even the implied warranty of 18    : ..    .:,     . . . without even the implied warranty of
19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
21..}^=.=       =       ; Library General Public License for more 21..}^=.=       =       ; Library General Public License for more
22++=   -.     .`     .: details. 22++=   -.     .`     .: details.
23 :     =  ...= . :.=- 23 :     =  ...= . :.=-
24 -.   .:....=;==+<; You should have received a copy of the GNU 24 -.   .:....=;==+<; You should have received a copy of the GNU
25  -_. . .   )=.  = Library General Public License along with 25  -_. . .   )=.  = Library General Public License along with
26    --        :-=` this library; see the file COPYING.LIB. 26    --        :-=` this library; see the file COPYING.LIB.
27 If not, write to the Free Software Foundation, 27 If not, write to the Free Software Foundation,
28 Inc., 59 Temple Place - Suite 330, 28 Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA. 29 Boston, MA 02111-1307, USA.
30 30
31*/ 31*/
32 32
33/* QT */ 33/* QT */
34 34
35#include <qbitmap.h> 35#include <qbitmap.h>
36#include <qgrid.h> 36#include <qgrid.h>
37#include <qhbox.h> 37#include <qhbox.h>
38#include <qheader.h> 38#include <qheader.h>
39#include <qlabel.h> 39#include <qlabel.h>
40#include <qlayout.h> 40#include <qlayout.h>
41#include <qobjectlist.h> 41#include <qobjectlist.h>
42#include <qpixmap.h> 42#include <qpixmap.h>
43#include <qlistview.h> 43#include <qlistview.h>
44#include <qsplitter.h> 44#include <qsplitter.h>
45#include <qtabwidget.h> 45#include <qtabwidget.h>
46#include <qvbox.h> 46#include <qvbox.h>
47#include <qwidgetstack.h> 47#include <qwidgetstack.h>
48#include <qpainter.h> 48#include <qpainter.h>
49#include <qtimer.h> 49#include <qtimer.h>
50#include <qstyle.h> 50#include <qstyle.h>
51 51
52/* OPIE */ 52/* OPIE */
53 53
54#include <opie2/odialog.h> 54#include <opie2/odialog.h>
55#include <opie2/oseparator.h> 55#include <opie2/oseparator.h>
56#include <opie2/ojanuswidget.h> 56#include <opie2/ojanuswidget.h>
57 57
58/*====================================================================================== 58/*======================================================================================
59 * IconListItem 59 * IconListItem
60 *======================================================================================*/ 60 *======================================================================================*/
61 61
62class OJanusWidget::IconListItem : public QListBoxItem 62class OJanusWidget::IconListItem : public QListBoxItem
63{ 63{
64 public: 64 public:
65 IconListItem( QListBox *listbox, const QPixmap &pixmap, 65 IconListItem( QListBox *listbox, const QPixmap &pixmap,
66 const QString &text ); 66 const QString &text );
67 virtual int height( const QListBox *lb ) const; 67 virtual int height( const QListBox *lb ) const;
68 virtual int width( const QListBox *lb ) const; 68 virtual int width( const QListBox *lb ) const;
69 int expandMinimumWidth( int width ); 69 int expandMinimumWidth( int width );
70 70
71 protected: 71 protected:
72 const QPixmap &defaultPixmap(); 72 const QPixmap &defaultPixmap();
73 void paint( QPainter *painter ); 73 void paint( QPainter *painter );
74 74
75 private: 75 private:
76 QPixmap mPixmap; 76 QPixmap mPixmap;
77 int mMinimumWidth; 77 int mMinimumWidth;
78}; 78};
79 79
80template class QPtrList<QListViewItem>; 80template class QPtrList<QListViewItem>;
81 81
82/*====================================================================================== 82/*======================================================================================
83 * OJanusWidget 83 * OJanusWidget
84 *======================================================================================*/ 84 *======================================================================================*/
85 85
86OJanusWidget::OJanusWidget( QWidget *parent, const char *name, int face ) 86OJanusWidget::OJanusWidget( QWidget *parent, const char *name, int face )
87 : QWidget( parent, name, 0 ), 87 : QWidget( parent, name, 0 ),
88 mValid(false), mPageList(0), 88 mValid(false), mPageList(0),
89 mTitleList(0), mFace(face), mTitleLabel(0), mActivePageWidget(0), 89 mTitleList(0), mFace(face), mTitleLabel(0), mActivePageWidget(0),
90 mShowIconsInTreeList(false), d(0) 90 mShowIconsInTreeList(false), d(0)
91{ 91{
92 QVBoxLayout *topLayout = new QVBoxLayout( this ); 92 QVBoxLayout *topLayout = new QVBoxLayout( this );
93 93
94 if( mFace == TreeList || mFace == IconList ) 94 if( mFace == TreeList || mFace == IconList )
95 { 95 {
96 mPageList = new QPtrList<QWidget>; 96 mPageList = new QPtrList<QWidget>;
97 mTitleList = new QStringList(); 97 mTitleList = new QStringList();
98 98
99 QFrame *page; 99 QFrame *page;
100 if( mFace == TreeList ) 100 if( mFace == TreeList )
101 { 101 {
102 QSplitter *splitter = new QSplitter( this ); 102 QSplitter *splitter = new QSplitter( this );
103 topLayout->addWidget( splitter, 10 ); 103 topLayout->addWidget( splitter, 10 );
104 mTreeListResizeMode = QSplitter::KeepSize; 104 mTreeListResizeMode = QSplitter::KeepSize;
105 105
106 mTreeList = new QListView( splitter ); 106 mTreeList = new QListView( splitter );
107 mTreeList->addColumn( QString::fromLatin1("") ); 107 mTreeList->addColumn( QString::fromLatin1("") );
108 mTreeList->header()->hide(); 108 mTreeList->header()->hide();
109 mTreeList->setRootIsDecorated(true); 109 mTreeList->setRootIsDecorated(true);
110 mTreeList->setSorting( -1 ); 110 mTreeList->setSorting( -1 );
111 connect( mTreeList, SIGNAL(selectionChanged()), SLOT(slotShowPage()) ); 111 connect( mTreeList, SIGNAL(selectionChanged()), SLOT(slotShowPage()) );
112 connect( mTreeList, SIGNAL(clicked(QListViewItem*)), SLOT(slotItemClicked(QListViewItem*))); 112 connect( mTreeList, SIGNAL(clicked(QListViewItem*)), SLOT(slotItemClicked(QListViewItem*)));
113 113
114 // 114 //
115 // Page area. Title at top with a separator below and a pagestack using 115 // Page area. Title at top with a separator below and a pagestack using
116 // all available space at bottom. 116 // all available space at bottom.
117 // 117 //
118 QFrame *p = new QFrame( splitter ); 118 QFrame *p = new QFrame( splitter );
119 119
120 QHBoxLayout *hbox = new QHBoxLayout( p, 0, 0 ); 120 QHBoxLayout *hbox = new QHBoxLayout( p, 0, 0 );
121 hbox->addSpacing( ODialog::spacingHint() ); 121 hbox->addSpacing( ODialog::spacingHint() );
122 122
123 page = new QFrame( p ); 123 page = new QFrame( p );
124 hbox->addWidget( page, 10 ); 124 hbox->addWidget( page, 10 );
125 } 125 }
126 else 126 else
127 { 127 {
128 QHBoxLayout *hbox = new QHBoxLayout( topLayout ); 128 QHBoxLayout *hbox = new QHBoxLayout( topLayout );
129 mIconList = new IconListBox( this ); 129 mIconList = new IconListBox( this );
130 130
131 QFont listFont( mIconList->font() ); 131 QFont listFont( mIconList->font() );
132 listFont.setBold( true ); 132 listFont.setBold( true );
133 mIconList->setFont( listFont ); 133 mIconList->setFont( listFont );
134 134
135 mIconList->verticalScrollBar()->installEventFilter( this ); 135 mIconList->verticalScrollBar()->installEventFilter( this );
136 hbox->addWidget( mIconList ); 136 hbox->addWidget( mIconList );
137 connect( mIconList, SIGNAL(selectionChanged()), SLOT(slotShowPage())); 137 connect( mIconList, SIGNAL(selectionChanged()), SLOT(slotShowPage()));
138 hbox->addSpacing( ODialog::spacingHint() ); 138 hbox->addSpacing( ODialog::spacingHint() );
139 page = new QFrame( this ); 139 page = new QFrame( this );
140 hbox->addWidget( page, 10 ); 140 hbox->addWidget( page, 10 );
141 } 141 }
142 142
143 // 143 //
144 // Rest of page area. Title at top with a separator below and a 144 // Rest of page area. Title at top with a separator below and a
145 // pagestack using all available space at bottom. 145 // pagestack using all available space at bottom.
146 // 146 //
147 147
148 QVBoxLayout *vbox = new QVBoxLayout( page, 0, ODialog::spacingHint() ); 148 QVBoxLayout *vbox = new QVBoxLayout( page, 0, ODialog::spacingHint() );
149 149
150 mTitleLabel = new QLabel( QString::fromLatin1("Empty page"), page, "OJanusWidgetTitleLabel" ); 150 mTitleLabel = new QLabel( QString::fromLatin1("Empty page"), page, "OJanusWidgetTitleLabel" );
151 vbox->addWidget( mTitleLabel ); 151 vbox->addWidget( mTitleLabel );
152 152
153 QFont titleFont( mTitleLabel->font() ); 153 QFont titleFont( mTitleLabel->font() );
154 titleFont.setBold( true ); 154 titleFont.setBold( true );
155 mTitleLabel->setFont( titleFont ); 155 mTitleLabel->setFont( titleFont );
156 156
157 mTitleSep = new OSeparator( page ); 157 mTitleSep = new OSeparator( page );
158 mTitleSep->setFrameStyle( QFrame::HLine|QFrame::Plain ); 158 mTitleSep->setFrameStyle( QFrame::HLine|QFrame::Plain );
159 vbox->addWidget( mTitleSep ); 159 vbox->addWidget( mTitleSep );
160 160
161 mPageStack = new QWidgetStack( page ); 161 mPageStack = new QWidgetStack( page );
162 connect(mPageStack, SIGNAL(aboutToShow(QWidget*)), 162 connect(mPageStack, SIGNAL(aboutToShow(QWidget*)),
163 this, SIGNAL(aboutToShowPage(QWidget*))); 163 this, SIGNAL(aboutToShowPage(QWidget*)));
164 vbox->addWidget( mPageStack, 10 ); 164 vbox->addWidget( mPageStack, 10 );
165 } 165 }
166 else if( mFace == Tabbed ) 166 else if( mFace == Tabbed )
167 { 167 {
168 mPageList = new QPtrList<QWidget>; 168 mPageList = new QPtrList<QWidget>;
169 169
170 mTabControl = new QTabWidget( this ); 170 mTabControl = new QTabWidget( this );
171 mTabControl->setMargin (ODialog::marginHint()); 171 mTabControl->setMargin (ODialog::marginHint());
172 topLayout->addWidget( mTabControl, 10 ); 172 topLayout->addWidget( mTabControl, 10 );
173 } 173 }
174 else if( mFace == Swallow ) 174 else if( mFace == Swallow )
175 { 175 {
176 mSwallowPage = new QWidget( this ); 176 mSwallowPage = new QWidget( this );
177 topLayout->addWidget( mSwallowPage, 10 ); 177 topLayout->addWidget( mSwallowPage, 10 );
178 } 178 }
179 else 179 else
180 { 180 {
181 mFace = Plain; 181 mFace = Plain;
182 mPlainPage = new QFrame( this ); 182 mPlainPage = new QFrame( this );
183 topLayout->addWidget( mPlainPage, 10 ); 183 topLayout->addWidget( mPlainPage, 10 );
184 } 184 }
185 185
186 /* FIXME: Revise for Opie 186 /* FIXME: Revise for Opie
187 if ( kapp ) 187 if ( kapp )
188 connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged())); 188 connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged()));
189 */ 189 */
190 190
191 mValid = true; 191 mValid = true;
192 192
193 setSwallowedWidget(0); // Set default size if 'mFace' is Swallow. 193 setSwallowedWidget(0); // Set default size if 'mFace' is Swallow.
194} 194}
195 195
196 196
197OJanusWidget::~OJanusWidget() 197OJanusWidget::~OJanusWidget()
198{ 198{
199 delete mPageList; 199 delete mPageList;
200 mPageList = 0; 200 mPageList = 0;
201 delete mTitleList; 201 delete mTitleList;
202 mTitleList = 0; 202 mTitleList = 0;
203} 203}
204 204
205 205
206bool OJanusWidget::isValid() const 206bool OJanusWidget::isValid() const
207{ 207{
208 return( mValid ); 208 return( mValid );
209} 209}
210 210
211 211
212QFrame *OJanusWidget::plainPage() 212QFrame *OJanusWidget::plainPage()
213{ 213{
214 return( mPlainPage ); 214 return( mPlainPage );
215} 215}
216 216
217 217
218int OJanusWidget::face() const 218int OJanusWidget::face() const
219{ 219{
220 return( mFace ); 220 return( mFace );
221} 221}
222 222
223QWidget *OJanusWidget::FindParent() 223QWidget *OJanusWidget::FindParent()
224{ 224{
225 if( mFace == Tabbed ) { 225 if( mFace == Tabbed ) {
226 return mTabControl; 226 return mTabControl;
227 } 227 }
228 else { 228 else {
229 return this; 229 return this;
230 } 230 }
231} 231}
232 232
233QFrame *OJanusWidget::addPage( const QStringList &items, const QString &header, 233QFrame *OJanusWidget::addPage( const QStringList &items, const QString &header,
234 const QPixmap &pixmap ) 234 const QPixmap &pixmap )
235{ 235{
236 if( mValid == false ) 236 if( mValid == false )
237 { 237 {
238 qDebug( "addPage: Invalid object" ); 238 qDebug( "addPage: Invalid object" );
239 return( 0 ); 239 return( 0 );
240 } 240 }
241 241
242 QFrame *page = new QFrame( FindParent(), "page" ); 242 QFrame *page = new QFrame( FindParent(), "page" );
243 addPageWidget( page, items, header, pixmap ); 243 addPageWidget( page, items, header, pixmap );
244 244
245 return page; 245 return page;
246} 246}
247 247
248void OJanusWidget::pageGone( QObject *obj ) 248void OJanusWidget::pageGone( QObject *obj )
249{ 249{
250 removePage( static_cast<QWidget*>( obj ) ); 250 removePage( static_cast<QWidget*>( obj ) );
251} 251}
252 252
253void OJanusWidget::slotReopen( QListViewItem * item ) 253void OJanusWidget::slotReopen( QListViewItem * item )
254{ 254{
255 if( item ) 255 if( item )
256 item->setOpen( true ); 256 item->setOpen( true );
257} 257}
258 258
259QFrame *OJanusWidget::addPage( const QString &itemName, const QString &header, 259QFrame *OJanusWidget::addPage( const QString &itemName, const QString &header,
260 const QPixmap &pixmap ) 260 const QPixmap &pixmap )
261{ 261{
262 QStringList items; 262 QStringList items;
263 items << itemName; 263 items << itemName;
264 return addPage(items, header, pixmap); 264 return addPage(items, header, pixmap);
265} 265}
266 266
267 267
268 268
269QVBox *OJanusWidget::addVBoxPage( const QStringList &items, 269QVBox *OJanusWidget::addVBoxPage( const QStringList &items,
270 const QString &header, 270 const QString &header,
271 const QPixmap &pixmap ) 271 const QPixmap &pixmap )
272{ 272{
273 if( mValid == false ) 273 if( mValid == false )
274 { 274 {
275 qDebug( "addPage: Invalid object" ); 275 qDebug( "addPage: Invalid object" );
276 return( 0 ); 276 return( 0 );
277 } 277 }
278 278
279 QVBox *page = new QVBox(FindParent() , "page" ); 279 QVBox *page = new QVBox(FindParent() , "page" );
280 page->setSpacing( ODialog::spacingHint() ); 280 page->setSpacing( ODialog::spacingHint() );
281 addPageWidget( page, items, header, pixmap ); 281 addPageWidget( page, items, header, pixmap );
282 282
283 return page; 283 return page;
284} 284}
285 285
286QVBox *OJanusWidget::addVBoxPage( const QString &itemName, 286QVBox *OJanusWidget::addVBoxPage( const QString &itemName,
287 const QString &header, 287 const QString &header,
288 const QPixmap &pixmap ) 288 const QPixmap &pixmap )
289{ 289{
290 QStringList items; 290 QStringList items;
291 items << itemName; 291 items << itemName;
292 return addVBoxPage(items, header, pixmap); 292 return addVBoxPage(items, header, pixmap);
293} 293}
294 294
295QHBox *OJanusWidget::addHBoxPage( const QStringList &items, 295QHBox *OJanusWidget::addHBoxPage( const QStringList &items,
296 const QString &header, 296 const QString &header,
297 const QPixmap &pixmap ) 297 const QPixmap &pixmap )
298{ 298{
299 if( mValid == false ) { 299 if( mValid == false ) {
300 qDebug( "addPage: Invalid object" ); 300 qDebug( "addPage: Invalid object" );
301 return( 0 ); 301 return( 0 );
302 } 302 }
303 303
304 QHBox *page = new QHBox(FindParent(), "page"); 304 QHBox *page = new QHBox(FindParent(), "page");
305 page->setSpacing( ODialog::spacingHint() ); 305 page->setSpacing( ODialog::spacingHint() );
306 addPageWidget( page, items, header, pixmap ); 306 addPageWidget( page, items, header, pixmap );
307 307
308 return page; 308 return page;
309} 309}
310 310
311QHBox *OJanusWidget::addHBoxPage( const QString &itemName, 311QHBox *OJanusWidget::addHBoxPage( const QString &itemName,
312 const QString &header, 312 const QString &header,
313 const QPixmap &pixmap ) 313 const QPixmap &pixmap )
314{ 314{
315 QStringList items; 315 QStringList items;
316 items << itemName; 316 items << itemName;
317 return addHBoxPage(items, header, pixmap); 317 return addHBoxPage(items, header, pixmap);
318} 318}
319 319
320QGrid *OJanusWidget::addGridPage( int n, Orientation dir, 320QGrid *OJanusWidget::addGridPage( int n, Orientation dir,
321 const QStringList &items, 321 const QStringList &items,
322 const QString &header, 322 const QString &header,
323 const QPixmap &pixmap ) 323 const QPixmap &pixmap )
324{ 324{
325 if( mValid == false ) 325 if( mValid == false )
326 { 326 {
327 qDebug( "addPage: Invalid object" ); 327 qDebug( "addPage: Invalid object" );
328 return( 0 ); 328 return( 0 );
329 } 329 }
330 330
331 QGrid *page = new QGrid( n, dir, FindParent(), "page" ); 331 QGrid *page = new QGrid( n, dir, FindParent(), "page" );
332 page->setSpacing( ODialog::spacingHint() ); 332 page->setSpacing( ODialog::spacingHint() );
333 addPageWidget( page, items, header, pixmap ); 333 addPageWidget( page, items, header, pixmap );
334 334
335 return page; 335 return page;
336} 336}
337 337
338 338
339QGrid *OJanusWidget::addGridPage( int n, Orientation dir, 339QGrid *OJanusWidget::addGridPage( int n, Orientation dir,
340 const QString &itemName, 340 const QString &itemName,
341 const QString &header, 341 const QString &header,
342 const QPixmap &pixmap ) 342 const QPixmap &pixmap )
343{ 343{
344 QStringList items; 344 QStringList items;
345 items << itemName; 345 items << itemName;
346 return addGridPage(n, dir, items, header, pixmap); 346 return addGridPage(n, dir, items, header, pixmap);
347} 347}
348 348
349void OJanusWidget::InsertTreeListItem(const QStringList &items, const QPixmap &pixmap, QFrame *page) 349void OJanusWidget::InsertTreeListItem(const QStringList &items, const QPixmap &pixmap, QFrame *page)
350{ 350{
351 bool isTop = true; 351 bool isTop = true;
352 QListViewItem *curTop = 0, *child, *last, *newChild; 352 QListViewItem *curTop = 0, *child, *last, *newChild;
353 unsigned int index = 1; 353 unsigned int index = 1;
354 QStringList curPath; 354 QStringList curPath;
355 355
356 for ( QStringList::ConstIterator it = items.begin(); it != items.end(); ++it, index++ ) { 356 for ( QStringList::ConstIterator it = items.begin(); it != items.end(); ++it, index++ ) {
357 QString name = (*it); 357 QString name = (*it);
358 bool isPath = ( index != items.count() ); 358 bool isPath = ( index != items.count() );
359 359
360 // Find the first child. 360 // Find the first child.
361 if (isTop) { 361 if (isTop) {
362 child = mTreeList->firstChild(); 362 child = mTreeList->firstChild();
363 } 363 }
364 else { 364 else {
365 child = curTop->firstChild(); 365 child = curTop->firstChild();
366 } 366 }
367 367
368 // Now search for a child with the current Name, and if it we doesn't 368 // Now search for a child with the current Name, and if it we doesn't
369 // find it, then remember the location of the last child. 369 // find it, then remember the location of the last child.
370 for (last = 0; child && child->text(0) != name ; last = child, child = child->nextSibling()); 370 for (last = 0; child && child->text(0) != name ; last = child, child = child->nextSibling());
371 371
372 if (last == 0 && child == 0) { 372 if (last == 0 && child == 0) {
373 // This node didn't have any children at all, lets just insert the 373 // This node didn't have any children at all, lets just insert the
374 // new child. 374 // new child.
375 if (isTop) 375 if (isTop)
376 newChild = new QListViewItem(mTreeList, name); 376 newChild = new QListViewItem(mTreeList, name);
377 else 377 else
378 newChild = new QListViewItem(curTop, name); 378 newChild = new QListViewItem(curTop, name);
379 379
380 } 380 }
381 else if (child != 0) { 381 else if (child != 0) {
382 // we found the given name in this child. 382 // we found the given name in this child.
383 if (!isPath) { 383 if (!isPath) {
384 qDebug( "The element inserted was already in the TreeList box!" ); 384 qDebug( "The element inserted was already in the TreeList box!" );
385 return; 385 return;
386 } 386 }
387 else { 387 else {
388 // Ok we found the folder 388 // Ok we found the folder
389 newChild = child; 389 newChild = child;
390 } 390 }
391 } 391 }
392 else { 392 else {
393 // the node had some children, but we didn't find the given name 393 // the node had some children, but we didn't find the given name
394 if (isTop) 394 if (isTop)
395 newChild = new QListViewItem(mTreeList, last, name); 395 newChild = new QListViewItem(mTreeList, last, name);
396 else 396 else
397 newChild = new QListViewItem(curTop, last, name); 397 newChild = new QListViewItem(curTop, last, name);
398 } 398 }
399 399
400 // Now make the element expandable if it is a path component, and make 400 // Now make the element expandable if it is a path component, and make
401 // ready for next loop 401 // ready for next loop
402 if (isPath) { 402 if (isPath) {
403 newChild->setExpandable(true); 403 newChild->setExpandable(true);
404 curTop = newChild; 404 curTop = newChild;
405 isTop = false; 405 isTop = false;
406 curPath << name; 406 curPath << name;
407 407
408 QString key = curPath.join("_/_"); 408 QString key = curPath.join("_/_");
409 if (mFolderIconMap.contains(key)) { 409 if (mFolderIconMap.contains(key)) {
410 QPixmap p = mFolderIconMap[key]; 410 QPixmap p = mFolderIconMap[key];
411 newChild->setPixmap(0,p); 411 newChild->setPixmap(0,p);
412 } 412 }
413 } 413 }
414 else { 414 else {
415 if (mShowIconsInTreeList) { 415 if (mShowIconsInTreeList) {
416 newChild->setPixmap(0, pixmap); 416 newChild->setPixmap(0, pixmap);
417 } 417 }
418 mTreeListToPageStack.insert(newChild, page); 418 mTreeListToPageStack.insert(newChild, page);
419 } 419 }
420 } 420 }
421} 421}
422 422
423void OJanusWidget::addPageWidget( QFrame *page, const QStringList &items, 423void OJanusWidget::addPageWidget( QFrame *page, const QStringList &items,
424 const QString &header,const QPixmap &pixmap ) 424 const QString &header,const QPixmap &pixmap )
425{ 425{
426 connect(page, SIGNAL(destroyed(QObject*)), SLOT(pageGone(QObject*))); 426 connect(page, SIGNAL(destroyed(QObject*)), SLOT(pageGone(QObject*)));
427 427
428 if( mFace == Tabbed ) 428 if( mFace == Tabbed )
429 { 429 {
430 mTabControl->addTab (page, items.last()); 430 mTabControl->addTab (page, items.last());
431 mPageList->append (page); 431 mPageList->append (page);
432 } 432 }
433 else if( mFace == TreeList || mFace == IconList ) 433 else if( mFace == TreeList || mFace == IconList )
434 { 434 {
435 mPageList->append( page ); 435 mPageList->append( page );
436 mPageStack->addWidget( page, 0 ); 436 mPageStack->addWidget( page, 0 );
437 437
438 if (items.count() == 0) { 438 if (items.count() == 0) {
439 qDebug( "Invalid QStringList, with zero items" ); 439 qDebug( "Invalid QStringList, with zero items" );
440 return; 440 return;
441 } 441 }
442 442
443 if( mFace == TreeList ) 443 if( mFace == TreeList )
444 { 444 {
445 InsertTreeListItem(items, pixmap, page); 445 InsertTreeListItem(items, pixmap, page);
446 } 446 }
447 else // mFace == IconList 447 else // mFace == IconList
448 { 448 {
449 QString itemName = items.last(); 449 QString itemName = items.last();
450 IconListItem *item = new IconListItem( mIconList, pixmap, itemName ); 450 IconListItem *item = new IconListItem( mIconList, pixmap, itemName );
451 // 451 //
452 // 2000-06-01 Espen Sand: If I do this with Qt 2.1.1 all sorts of 452 // 2000-06-01 Espen Sand: If I do this with Qt 2.1.1 all sorts of
453 // strange things happen. With Qt <= 2.1 it worked but now I must 453 // strange things happen. With Qt <= 2.1 it worked but now I must
454 // either specify the listbox in the constructor on the item 454 // either specify the listbox in the constructor on the item
455 // or as below, not both. 455 // or as below, not both.
456 // mIconList->insertItem( item ); 456 // mIconList->insertItem( item );
457 // 457 //
458 mIconListToPageStack.insert(item, page); 458 mIconListToPageStack.insert(item, page);
459 mIconList->invalidateHeight(); 459 mIconList->invalidateHeight();
460 mIconList->invalidateWidth(); 460 mIconList->invalidateWidth();
461 461
462 if (mIconList->isVisible()) 462 if (mIconList->isVisible())
463 mIconList->updateWidth(); 463 mIconList->updateWidth();
464 } 464 }
465 465
466 // 466 //
467 // Make sure the title label is sufficiently wide 467 // Make sure the title label is sufficiently wide
468 // 468 //
469 QString lastName = items.last(); 469 QString lastName = items.last();
470 const QString &title = (header != QString::null ? header : lastName); 470 const QString &title = (header != QString::null ? header : lastName);
471 QRect r = mTitleLabel->fontMetrics().boundingRect( title ); 471 QRect r = mTitleLabel->fontMetrics().boundingRect( title );
472 if( mTitleLabel->minimumWidth() < r.width() ) 472 if( mTitleLabel->minimumWidth() < r.width() )
473 { 473 {
474 mTitleLabel->setMinimumWidth( r.width() ); 474 mTitleLabel->setMinimumWidth( r.width() );
475 } 475 }
476 mTitleList->append( title ); 476 mTitleList->append( title );
477 477
478 if( mTitleList->count() == 1 ) 478 if( mTitleList->count() == 1 )
479 { 479 {
480 showPage(0); 480 showPage(0);
481 } 481 }
482 } 482 }
483 else 483 else
484 { 484 {
485 qDebug( "OJanusWidget::addPageWidget: can only add a page in Tabbed, TreeList or IconList modes" ); 485 qDebug( "OJanusWidget::addPageWidget: can only add a page in Tabbed, TreeList or IconList modes" );
486 } 486 }
487 487
488} 488}
489 489
490void OJanusWidget::setFolderIcon(const QStringList &path, const QPixmap &pixmap) 490void OJanusWidget::setFolderIcon(const QStringList &path, const QPixmap &pixmap)
491{ 491{
492 QString key = path.join("_/_"); 492 QString key = path.join("_/_");
493 mFolderIconMap.insert(key,pixmap); 493 mFolderIconMap.insert(key,pixmap);
494} 494}
495 495
496 496
497 497
498bool OJanusWidget::setSwallowedWidget( QWidget *widget ) 498bool OJanusWidget::setSwallowedWidget( QWidget *widget )
499{ 499{
500 if( mFace != Swallow || mValid == false ) 500 if( mFace != Swallow || mValid == false )
501 { 501 {
502 return( false ); 502 return( false );
503 } 503 }
504 504
505 // 505 //
506 // Remove current layout and make a new. 506 // Remove current layout and make a new.
507 // 507 //
508 if( mSwallowPage->layout() != 0 ) 508 if( mSwallowPage->layout() != 0 )
509 { 509 {
510 delete mSwallowPage->layout(); 510 delete mSwallowPage->layout();
511 } 511 }
512 QGridLayout *gbox = new QGridLayout( mSwallowPage, 1, 1, 0 ); 512 QGridLayout *gbox = new QGridLayout( mSwallowPage, 1, 1, 0 );
513 513
514 // 514 //
515 // Hide old children 515 // Hide old children
516 // 516 //
517 QObjectList *l = (QObjectList*)mSwallowPage->children(); // silence please 517 QObjectList *l = (QObjectList*)mSwallowPage->children(); // silence please
518 for( uint i=0; i < l->count(); i++ ) 518 for( uint i=0; i < l->count(); i++ )
519 { 519 {
520 QObject *o = l->at(i); 520 QObject *o = l->at(i);
521 if( o->isWidgetType() ) 521 if( o->isWidgetType() )
522 { 522 {
523 ((QWidget*)o)->hide(); 523 ((QWidget*)o)->hide();
524 } 524 }
525 } 525 }
526 526
527 // 527 //
528 // Add new child or make default size 528 // Add new child or make default size
529 // 529 //
530 if( widget == 0 ) 530 if( widget == 0 )
531 { 531 {
532 gbox->addRowSpacing(0,100); 532 gbox->addRowSpacing(0,100);
533 gbox->addColSpacing(0,100); 533 gbox->addColSpacing(0,100);
534 mSwallowPage->setMinimumSize(100,100); 534 mSwallowPage->setMinimumSize(100,100);
535 } 535 }
536 else 536 else
537 { 537 {
538 if( widget->parent() != mSwallowPage ) 538 if( widget->parent() != mSwallowPage )
539 { 539 {
540 widget->reparent( mSwallowPage, 0, QPoint(0,0) ); 540 widget->reparent( mSwallowPage, 0, QPoint(0,0) );
541 } 541 }
542 gbox->addWidget(widget, 0, 0 ); 542 gbox->addWidget(widget, 0, 0 );
543 gbox->activate(); 543 gbox->activate();
544 mSwallowPage->setMinimumSize( widget->minimumSize() ); 544 mSwallowPage->setMinimumSize( widget->minimumSize() );
545 } 545 }
546 546
547 return( true ); 547 return( true );
548} 548}
549 549
550bool OJanusWidget::slotShowPage() 550bool OJanusWidget::slotShowPage()
551{ 551{
552 if( mValid == false ) 552 if( mValid == false )
553 { 553 {
554 return( false ); 554 return( false );
555 } 555 }
556 556
557 if( mFace == TreeList ) 557 if( mFace == TreeList )
558 { 558 {
559 QListViewItem *node = mTreeList->selectedItem(); 559 QListViewItem *node = mTreeList->selectedItem();
560 if( node == 0 ) { return( false ); } 560 if( node == 0 ) { return( false ); }
561 561
562 QWidget *stackItem = mTreeListToPageStack[node]; 562 QWidget *stackItem = mTreeListToPageStack[node];
563 return showPage(stackItem); 563 return showPage(stackItem);
564 } 564 }
565 else if( mFace == IconList ) 565 else if( mFace == IconList )
566 { 566 {
567 QListBoxItem *node = mIconList->item( mIconList->currentItem() ); 567 QListBoxItem *node = mIconList->item( mIconList->currentItem() );
568 if( node == 0 ) { return( false ); } 568 if( node == 0 ) { return( false ); }
569 QWidget *stackItem = mIconListToPageStack[node]; 569 QWidget *stackItem = mIconListToPageStack[node];
570 return showPage(stackItem); 570 return showPage(stackItem);
571 } 571 }
572 572
573 return( false ); 573 return( false );
574} 574}
575 575
576 576
577bool OJanusWidget::showPage( int index ) 577bool OJanusWidget::showPage( int index )
578{ 578{
579 if( mPageList == 0 || mValid == false ) 579 if( mPageList == 0 || mValid == false )
580 { 580 {
581 return( false ); 581 return( false );
582 } 582 }
583 else 583 else
584 { 584 {
585 return showPage(mPageList->at(index)); 585 return showPage(mPageList->at(index));
586 } 586 }
587} 587}
588 588
589 589
590bool OJanusWidget::showPage( QWidget *w ) 590bool OJanusWidget::showPage( QWidget *w )
591{ 591{
592 if( w == 0 || mValid == false ) 592 if( w == 0 || mValid == false )
593 { 593 {
594 return( false ); 594 return( false );
595 } 595 }
596 596
597 if( mFace == TreeList || mFace == IconList ) 597 if( mFace == TreeList || mFace == IconList )
598 { 598 {
599 mPageStack->raiseWidget( w ); 599 mPageStack->raiseWidget( w );
600 mActivePageWidget = w; 600 mActivePageWidget = w;
601 601
602 int index = mPageList->findRef( w ); 602 int index = mPageList->findRef( w );
603 mTitleLabel->setText( *mTitleList->at(index) ); 603 mTitleLabel->setText( *mTitleList->at(index) );
604 if( mFace == TreeList ) 604 if( mFace == TreeList )
605 { 605 {
606 QMap<QListViewItem *, QWidget *>::Iterator it; 606 QMap<QListViewItem *, QWidget *>::Iterator it;
607 for (it = mTreeListToPageStack.begin(); it != mTreeListToPageStack.end(); ++it){ 607 for (it = mTreeListToPageStack.begin(); it != mTreeListToPageStack.end(); ++it){
608 QListViewItem *key = it.key(); 608 QListViewItem *key = it.key();
609 QWidget *val = it.data(); 609 QWidget *val = it.data();
610 if (val == w) { 610 if (val == w) {
611 mTreeList->setSelected(key, true ); 611 mTreeList->setSelected(key, true );
612 break; 612 break;
613 } 613 }
614 } 614 }
615 } 615 }
616 else 616 else
617 { 617 {
618 QMap<QListBoxItem *, QWidget *>::Iterator it; 618 QMap<QListBoxItem *, QWidget *>::Iterator it;
619 for (it = mIconListToPageStack.begin(); it != mIconListToPageStack.end(); ++it){ 619 for (it = mIconListToPageStack.begin(); it != mIconListToPageStack.end(); ++it){
620 QListBoxItem *key = it.key(); 620 QListBoxItem *key = it.key();
621 QWidget *val = it.data(); 621 QWidget *val = it.data();
622 if (val == w) { 622 if (val == w) {
623 mIconList->setSelected( key, true ); 623 mIconList->setSelected( key, true );
624 break; 624 break;
625 } 625 }
626 } 626 }
627 627
628 // 628 //
629 // 2000-02-13 Espen Sand 629 // 2000-02-13 Espen Sand
630 // Don't ask me why (because I don't know). If I select a page 630 // Don't ask me why (because I don't know). If I select a page
631 // with the mouse the page is not updated until it receives an 631 // with the mouse the page is not updated until it receives an
632 // event. It seems this event get lost if the mouse is not moved 632 // event. It seems this event get lost if the mouse is not moved
633 // when released. The timer ensures the update 633 // when released. The timer ensures the update
634 // 634 //
635 QTimer::singleShot( 0, mActivePageWidget, SLOT(update()) ); 635 QTimer::singleShot( 0, mActivePageWidget, SLOT(update()) );
636 } 636 }
637 } 637 }
638 else if( mFace == Tabbed ) 638 else if( mFace == Tabbed )
639 { 639 {
640 mTabControl->showPage(w); 640 mTabControl->showPage(w);
641 mActivePageWidget = w; 641 mActivePageWidget = w;
642 } 642 }
643 else 643 else
644 { 644 {
645 return( false ); 645 return( false );
646 } 646 }
647 647
648 return( true ); 648 return( true );
649} 649}
650 650
651 651
652int OJanusWidget::activePageIndex() const 652int OJanusWidget::activePageIndex() const
653{ 653{
654 if( mFace == TreeList) { 654 if( mFace == TreeList) {
655 QListViewItem *node = mTreeList->selectedItem(); 655 QListViewItem *node = mTreeList->selectedItem();
656 if( node == 0 ) { return -1; } 656 if( node == 0 ) { return -1; }
657 QWidget *stackItem = mTreeListToPageStack[node]; 657 QWidget *stackItem = mTreeListToPageStack[node];
658 return mPageList->findRef(stackItem); 658 return mPageList->findRef(stackItem);
659 } 659 }
660 else if (mFace == IconList) { 660 else if (mFace == IconList) {
661 QListBoxItem *node = mIconList->item( mIconList->currentItem() ); 661 QListBoxItem *node = mIconList->item( mIconList->currentItem() );
662 if( node == 0 ) { return( false ); } 662 if( node == 0 ) { return( false ); }
663 QWidget *stackItem = mIconListToPageStack[node]; 663 QWidget *stackItem = mIconListToPageStack[node];
664 return mPageList->findRef(stackItem); 664 return mPageList->findRef(stackItem);
665 } 665 }
666 else if( mFace == Tabbed ) { 666 else if( mFace == Tabbed ) {
667 QWidget *widget = mTabControl->currentPage(); 667 QWidget *widget = mTabControl->currentPage();
668 return( widget == 0 ? -1 : mPageList->findRef( widget ) ); 668 return( widget == 0 ? -1 : mPageList->findRef( widget ) );
669 } 669 }
670 else { 670 else {
671 return( -1 ); 671 return( -1 );
672 } 672 }
673} 673}
674 674
675 675
676int OJanusWidget::pageIndex( QWidget *widget ) const 676int OJanusWidget::pageIndex( QWidget *widget ) const
677{ 677{
678 if( widget == 0 ) 678 if( widget == 0 )
679 { 679 {
680 return( -1 ); 680 return( -1 );
681 } 681 }
682 else if( mFace == TreeList || mFace == IconList ) 682 else if( mFace == TreeList || mFace == IconList )
683 { 683 {
684 return( mPageList->findRef( widget ) ); 684 return( mPageList->findRef( widget ) );
685 } 685 }
686 else if( mFace == Tabbed ) 686 else if( mFace == Tabbed )
687 { 687 {
688 // 688 //
689 // The user gets the real page widget with addVBoxPage(), addHBoxPage() 689 // The user gets the real page widget with addVBoxPage(), addHBoxPage()
690 // and addGridPage() but not with addPage() which returns a child of 690 // and addGridPage() but not with addPage() which returns a child of
691 // the toplevel page. addPage() returns a QFrame so I check for that. 691 // the toplevel page. addPage() returns a QFrame so I check for that.
692 // 692 //
693 if( widget->isA("QFrame") ) 693 if( widget->isA("QFrame") )
694 { 694 {
695 return( mPageList->findRef( widget->parentWidget() ) ); 695 return( mPageList->findRef( widget->parentWidget() ) );
696 } 696 }
697 else 697 else
698 { 698 {
699 return( mPageList->findRef( widget ) ); 699 return( mPageList->findRef( widget ) );
700 } 700 }
701 } 701 }
702 else 702 else
703 { 703 {
704 return( -1 ); 704 return( -1 );
705 } 705 }
706} 706}
707 707
708void OJanusWidget::slotFontChanged() 708void OJanusWidget::slotFontChanged()
709{ 709{
710#ifdef FIXME 710#ifdef FIXME
711 711
712 if ( mTitleLabel != 0 ) 712 if ( mTitleLabel != 0 )
713 { 713 {
714 mTitleLabel->setFont( KGlobalSettings::generalFont() ); 714 mTitleLabel->setFont( KGlobalSettings::generalFont() );
715 QFont titleFont( mTitleLabel->font() ); 715 QFont titleFont( mTitleLabel->font() );
716 titleFont.setBold( true ); 716 titleFont.setBold( true );
717 mTitleLabel->setFont( titleFont ); 717 mTitleLabel->setFont( titleFont );
718 } 718 }
719#endif 719#endif
720 720
721 if( mFace == IconList ) 721 if( mFace == IconList )
722 { 722 {
723 QFont listFont( mIconList->font() ); 723 QFont listFont( mIconList->font() );
724 listFont.setBold( true ); 724 listFont.setBold( true );
725 mIconList->setFont( listFont ); 725 mIconList->setFont( listFont );
726 mIconList->invalidateHeight(); 726 mIconList->invalidateHeight();
727 mIconList->invalidateWidth(); 727 mIconList->invalidateWidth();
728 } 728 }
729} 729}
730 730
731// makes the treelist behave like the list of kcontrol 731// makes the treelist behave like the list of kcontrol
732void OJanusWidget::slotItemClicked(QListViewItem *it) 732void OJanusWidget::slotItemClicked(QListViewItem *it)
733{ 733{
734 if(it && (it->childCount()>0)) 734 if(it && (it->childCount()>0))
735 it->setOpen(!it->isOpen()); 735 it->setOpen(!it->isOpen());
736} 736}
737 737
738void OJanusWidget::setFocus() 738void OJanusWidget::setFocus()
739{ 739{
740 if( mValid == false ) { return; } 740 if( mValid == false ) { return; }
741 if( mFace == TreeList ) 741 if( mFace == TreeList )
742 { 742 {
743 mTreeList->setFocus(); 743 mTreeList->setFocus();
744 } 744 }
745 if( mFace == IconList ) 745 if( mFace == IconList )
746 { 746 {
747 mIconList->setFocus(); 747 mIconList->setFocus();
748 } 748 }
749 else if( mFace == Tabbed ) 749 else if( mFace == Tabbed )
750 { 750 {
751 mTabControl->setFocus(); 751 mTabControl->setFocus();
752 } 752 }
753 else if( mFace == Swallow ) 753 else if( mFace == Swallow )
754 { 754 {
755 mSwallowPage->setFocus(); 755 mSwallowPage->setFocus();
756 } 756 }
757 else if( mFace == Plain ) 757 else if( mFace == Plain )
758 { 758 {
759 mPlainPage->setFocus(); 759 mPlainPage->setFocus();
760 } 760 }
761} 761}
762 762
763 763
764QSize OJanusWidget::minimumSizeHint() const 764QSize OJanusWidget::minimumSizeHint() const
765{ 765{
766 if( mFace == TreeList || mFace == IconList ) 766 if( mFace == TreeList || mFace == IconList )
767 { 767 {
768 QSize s1( ODialog::spacingHint(), ODialog::spacingHint()*2 ); 768 QSize s1( ODialog::spacingHint(), ODialog::spacingHint()*2 );
769 QSize s2(0,0); 769 QSize s2(0,0);
770 QSize s3(0,0); 770 QSize s3(0,0);
771 QSize s4( mPageStack->sizeHint() ); 771 QSize s4( mPageStack->sizeHint() );
772 772
773 if( mFace == TreeList ) 773 if( mFace == TreeList )
774 { 774 {
775#if QT_VERSION < 300 775#if QT_VERSION < 0x030000
776 s1.rwidth() += style().splitterWidth(); 776 s1.rwidth() += style().splitterWidth();
777#else 777#else
778 s1.rwidth() += style().pixelMetric( QStyle::PM_SplitterWidth ); 778 s1.rwidth() += style().pixelMetric( QStyle::PM_SplitterWidth );
779#endif 779#endif
780 s2 = mTreeList->minimumSize(); 780 s2 = mTreeList->minimumSize();
781 } 781 }
782 else 782 else
783 { 783 {
784 mIconList->updateMinimumHeight(); 784 mIconList->updateMinimumHeight();
785 mIconList->updateWidth(); 785 mIconList->updateWidth();
786 s2 = mIconList->minimumSize(); 786 s2 = mIconList->minimumSize();
787 } 787 }
788 788
789 if( mTitleLabel->isVisible() == true ) 789 if( mTitleLabel->isVisible() == true )
790 { 790 {
791 s3 += mTitleLabel->sizeHint(); 791 s3 += mTitleLabel->sizeHint();
792 s3.rheight() += mTitleSep->minimumSize().height(); 792 s3.rheight() += mTitleSep->minimumSize().height();
793 } 793 }
794 794
795 // 795 //
796 // Select the tallest item. It has only effect in IconList mode 796 // Select the tallest item. It has only effect in IconList mode
797 // 797 //
798 int h1 = s1.rheight() + s3.rheight() + s4.height(); 798 int h1 = s1.rheight() + s3.rheight() + s4.height();
799 int h2 = QMAX( h1, s2.rheight() ); 799 int h2 = QMAX( h1, s2.rheight() );
800 800
801 return( QSize( s1.width()+s2.width()+QMAX(s3.width(),s4.width()), h2 ) ); 801 return( QSize( s1.width()+s2.width()+QMAX(s3.width(),s4.width()), h2 ) );
802 } 802 }
803 else if( mFace == Tabbed ) 803 else if( mFace == Tabbed )
804 { 804 {
805 return( mTabControl->sizeHint() ); 805 return( mTabControl->sizeHint() );
806 } 806 }
807 else if( mFace == Swallow ) 807 else if( mFace == Swallow )
808 { 808 {
809 return( mSwallowPage->minimumSize() ); 809 return( mSwallowPage->minimumSize() );
810 } 810 }
811 else if( mFace == Plain ) 811 else if( mFace == Plain )
812 { 812 {
813 return( mPlainPage->sizeHint() ); 813 return( mPlainPage->sizeHint() );
814 } 814 }
815 else 815 else
816 { 816 {
817 return( QSize( 100, 100 ) ); // Should never happen though. 817 return( QSize( 100, 100 ) ); // Should never happen though.
818 } 818 }
819 819
820} 820}
821 821
822 822
823QSize OJanusWidget::sizeHint() const 823QSize OJanusWidget::sizeHint() const
824{ 824{
825 return( minimumSizeHint() ); 825 return( minimumSizeHint() );
826} 826}
827 827
828 828
829void OJanusWidget::setTreeListAutoResize( bool state ) 829void OJanusWidget::setTreeListAutoResize( bool state )
830{ 830{
831 if( mFace == TreeList ) 831 if( mFace == TreeList )
832 { 832 {
833 mTreeListResizeMode = state == false ? 833 mTreeListResizeMode = state == false ?
834 QSplitter::KeepSize : QSplitter::Stretch; 834 QSplitter::KeepSize : QSplitter::Stretch;
835 QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget()); 835 QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget());
836 splitter->setResizeMode( mTreeList, mTreeListResizeMode ); 836 splitter->setResizeMode( mTreeList, mTreeListResizeMode );
837 } 837 }
838} 838}
839 839
840 840
841void OJanusWidget::setIconListAllVisible( bool state ) 841void OJanusWidget::setIconListAllVisible( bool state )
842{ 842{
843 if( mFace == IconList ) 843 if( mFace == IconList )
844 { 844 {
845 mIconList->setShowAll( state ); 845 mIconList->setShowAll( state );
846 } 846 }
847} 847}
848 848
849void OJanusWidget::setShowIconsInTreeList( bool state ) 849void OJanusWidget::setShowIconsInTreeList( bool state )
850{ 850{
851 mShowIconsInTreeList = state; 851 mShowIconsInTreeList = state;
852} 852}
853 853
854void OJanusWidget::setRootIsDecorated( bool state ) 854void OJanusWidget::setRootIsDecorated( bool state )
855{ 855{
856 if( mFace == TreeList ) { 856 if( mFace == TreeList ) {
857 mTreeList->setRootIsDecorated(state); 857 mTreeList->setRootIsDecorated(state);
858 } 858 }
859} 859}
860 860
861void OJanusWidget::unfoldTreeList( bool persist ) 861void OJanusWidget::unfoldTreeList( bool persist )
862{ 862{
863 if( mFace == TreeList ) 863 if( mFace == TreeList )
864 { 864 {
865 if( persist ) 865 if( persist )
866 connect( mTreeList, SIGNAL( collapsed(QListViewItem*) ), this, SLOT( slotReopen(QListViewItem*) ) ); 866 connect( mTreeList, SIGNAL( collapsed(QListViewItem*) ), this, SLOT( slotReopen(QListViewItem*) ) );
867 else 867 else
868 disconnect( mTreeList, SIGNAL( collapsed(QListViewItem*) ), this, SLOT( slotReopen(QListViewItem*) ) ); 868 disconnect( mTreeList, SIGNAL( collapsed(QListViewItem*) ), this, SLOT( slotReopen(QListViewItem*) ) );
869 869
870 for( QListViewItem * item = mTreeList->firstChild(); item; item = item->itemBelow() ) 870 for( QListViewItem * item = mTreeList->firstChild(); item; item = item->itemBelow() )
871 item->setOpen( true ); 871 item->setOpen( true );
872 } 872 }
873} 873}
874 874
875void OJanusWidget::showEvent( QShowEvent * ) 875void OJanusWidget::showEvent( QShowEvent * )
876{ 876{
877 if( mFace == TreeList ) 877 if( mFace == TreeList )
878 { 878 {
879 QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget()); 879 QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget());
880 splitter->setResizeMode( mTreeList, mTreeListResizeMode ); 880 splitter->setResizeMode( mTreeList, mTreeListResizeMode );
881 } 881 }
882} 882}
883 883
884 884
885// 885//
886// 2000-13-02 Espen Sand 886// 2000-13-02 Espen Sand
887// It should be obvious that this eventfilter must only be 887// It should be obvious that this eventfilter must only be
888// be installed on the vertical scrollbar of the mIconList. 888// be installed on the vertical scrollbar of the mIconList.
889// 889//
890bool OJanusWidget::eventFilter( QObject *o, QEvent *e ) 890bool OJanusWidget::eventFilter( QObject *o, QEvent *e )
891{ 891{
892 if( e->type() == QEvent::Show ) 892 if( e->type() == QEvent::Show )
893 { 893 {
894 IconListItem *item = (IconListItem*)mIconList->item(0); 894 IconListItem *item = (IconListItem*)mIconList->item(0);
895 if( item != 0 ) 895 if( item != 0 )
896 { 896 {
897 int lw = item->width( mIconList ); 897 int lw = item->width( mIconList );
898 int sw = mIconList->verticalScrollBar()->sizeHint().width(); 898 int sw = mIconList->verticalScrollBar()->sizeHint().width();
899 mIconList->setFixedWidth( lw+sw+mIconList->frameWidth()*2 ); 899 mIconList->setFixedWidth( lw+sw+mIconList->frameWidth()*2 );
900 } 900 }
901 } 901 }
902 else if( e->type() == QEvent::Hide ) 902 else if( e->type() == QEvent::Hide )
903 { 903 {
904 IconListItem *item = (IconListItem*)mIconList->item(0); 904 IconListItem *item = (IconListItem*)mIconList->item(0);
905 if( item != 0 ) 905 if( item != 0 )
906 { 906 {
907 int lw = item->width( mIconList ); 907 int lw = item->width( mIconList );
908 mIconList->setFixedWidth( lw+mIconList->frameWidth()*2 ); 908 mIconList->setFixedWidth( lw+mIconList->frameWidth()*2 );
909 } 909 }
910 } 910 }
911 return QWidget::eventFilter( o, e ); 911 return QWidget::eventFilter( o, e );
912} 912}
913 913
914 914
915 915
916// 916//
917// Code for the icon list box 917// Code for the icon list box
918// 918//
919 919
920 920
921OJanusWidget::IconListBox::IconListBox( QWidget *parent, const char *name, 921OJanusWidget::IconListBox::IconListBox( QWidget *parent, const char *name,
922 WFlags f ) 922 WFlags f )
923 :QListBox( parent, name, f ), mShowAll(false), mHeightValid(false), 923 :QListBox( parent, name, f ), mShowAll(false), mHeightValid(false),
924 mWidthValid(false) 924 mWidthValid(false)
925{ 925{
926} 926}
927 927
928 928
929void OJanusWidget::IconListBox::updateMinimumHeight() 929void OJanusWidget::IconListBox::updateMinimumHeight()
930{ 930{
931 if( mShowAll == true && mHeightValid == false ) 931 if( mShowAll == true && mHeightValid == false )
932 { 932 {
933 int h = frameWidth()*2; 933 int h = frameWidth()*2;
934 for( QListBoxItem *i = item(0); i != 0; i = i->next() ) 934 for( QListBoxItem *i = item(0); i != 0; i = i->next() )
935 { 935 {
936 h += i->height( this ); 936 h += i->height( this );
937 } 937 }
938 setMinimumHeight( h ); 938 setMinimumHeight( h );
939 mHeightValid = true; 939 mHeightValid = true;
940 } 940 }
941} 941}
942 942
943 943
944void OJanusWidget::IconListBox::updateWidth() 944void OJanusWidget::IconListBox::updateWidth()
945{ 945{
946 if( mWidthValid == false ) 946 if( mWidthValid == false )
947 { 947 {
948 int maxWidth = 10; 948 int maxWidth = 10;
949 for( QListBoxItem *i = item(0); i != 0; i = i->next() ) 949 for( QListBoxItem *i = item(0); i != 0; i = i->next() )
950 { 950 {
951 int w = ((IconListItem *)i)->width(this); 951 int w = ((IconListItem *)i)->width(this);
952 maxWidth = QMAX( w, maxWidth ); 952 maxWidth = QMAX( w, maxWidth );
953 } 953 }
954 954
955 for( QListBoxItem *i = item(0); i != 0; i = i->next() ) 955 for( QListBoxItem *i = item(0); i != 0; i = i->next() )
956 { 956 {
957 ((IconListItem *)i)->expandMinimumWidth( maxWidth ); 957 ((IconListItem *)i)->expandMinimumWidth( maxWidth );
958 } 958 }
959 959
960 if( verticalScrollBar()->isVisible() ) 960 if( verticalScrollBar()->isVisible() )
961 { 961 {
962 maxWidth += verticalScrollBar()->sizeHint().width(); 962 maxWidth += verticalScrollBar()->sizeHint().width();
963 } 963 }
964 964
965 setFixedWidth( maxWidth + frameWidth()*2 ); 965 setFixedWidth( maxWidth + frameWidth()*2 );
966 mWidthValid = true; 966 mWidthValid = true;
967 } 967 }
968} 968}
969 969
970 970
971void OJanusWidget::IconListBox::invalidateHeight() 971void OJanusWidget::IconListBox::invalidateHeight()
972{ 972{
973 mHeightValid = false; 973 mHeightValid = false;
974} 974}
975 975
976 976
977void OJanusWidget::IconListBox::invalidateWidth() 977void OJanusWidget::IconListBox::invalidateWidth()
978{ 978{
979 mWidthValid = false; 979 mWidthValid = false;
980} 980}
981 981
982 982
983void OJanusWidget::IconListBox::setShowAll( bool showAll ) 983void OJanusWidget::IconListBox::setShowAll( bool showAll )
984{ 984{
985 mShowAll = showAll; 985 mShowAll = showAll;
986 mHeightValid = false; 986 mHeightValid = false;
987} 987}
988 988
989 989
990 990
991OJanusWidget::IconListItem::IconListItem( QListBox *listbox, const QPixmap &pixmap, 991OJanusWidget::IconListItem::IconListItem( QListBox *listbox, const QPixmap &pixmap,
992 const QString &text ) 992 const QString &text )
993 : QListBoxItem( listbox ) 993 : QListBoxItem( listbox )
994{ 994{
995 mPixmap = pixmap; 995 mPixmap = pixmap;
996 if( mPixmap.isNull() == true ) 996 if( mPixmap.isNull() == true )
997 { 997 {
998 mPixmap = defaultPixmap(); 998 mPixmap = defaultPixmap();
999 } 999 }
1000 setText( text ); 1000 setText( text );
1001 mMinimumWidth = 0; 1001 mMinimumWidth = 0;
1002} 1002}
1003 1003
1004 1004
1005int OJanusWidget::IconListItem::expandMinimumWidth( int width ) 1005int OJanusWidget::IconListItem::expandMinimumWidth( int width )
1006{ 1006{
1007 mMinimumWidth = QMAX( mMinimumWidth, width ); 1007 mMinimumWidth = QMAX( mMinimumWidth, width );
1008 return( mMinimumWidth ); 1008 return( mMinimumWidth );
1009} 1009}
1010 1010
1011 1011
1012const QPixmap &OJanusWidget::IconListItem::defaultPixmap() 1012const QPixmap &OJanusWidget::IconListItem::defaultPixmap()
1013{ 1013{
1014 static QPixmap *pix=0; 1014 static QPixmap *pix=0;
1015 if( pix == 0 ) 1015 if( pix == 0 )
1016 { 1016 {
1017 pix = new QPixmap( 32, 32 ); 1017 pix = new QPixmap( 32, 32 );
1018 QPainter p( pix ); 1018 QPainter p( pix );
1019 p.eraseRect( 0, 0, pix->width(), pix->height() ); 1019 p.eraseRect( 0, 0, pix->width(), pix->height() );
1020 p.setPen( Qt::red ); 1020 p.setPen( Qt::red );
1021 p.drawRect ( 0, 0, pix->width(), pix->height() ); 1021 p.drawRect ( 0, 0, pix->width(), pix->height() );
1022 p.end(); 1022 p.end();
1023 1023
1024 QBitmap mask( pix->width(), pix->height(), true ); 1024 QBitmap mask( pix->width(), pix->height(), true );
1025 mask.fill( Qt::black ); 1025 mask.fill( Qt::black );
1026 p.begin( &mask ); 1026 p.begin( &mask );
1027 p.setPen( Qt::white ); 1027 p.setPen( Qt::white );
1028 p.drawRect ( 0, 0, pix->width(), pix->height() ); 1028 p.drawRect ( 0, 0, pix->width(), pix->height() );
1029 p.end(); 1029 p.end();
1030 1030
1031 pix->setMask( mask ); 1031 pix->setMask( mask );
1032 } 1032 }
1033 return( *pix ); 1033 return( *pix );
1034} 1034}
1035 1035
1036 1036
1037void OJanusWidget::IconListItem::paint( QPainter *painter ) 1037void OJanusWidget::IconListItem::paint( QPainter *painter )
1038{ 1038{
1039 QFontMetrics fm = painter->fontMetrics(); 1039 QFontMetrics fm = painter->fontMetrics();
1040 //int wt = fm.boundingRect(text()).width(); 1040 //int wt = fm.boundingRect(text()).width();
1041 int wp = mPixmap.width(); 1041 int wp = mPixmap.width();
1042 int ht = fm.lineSpacing(); 1042 int ht = fm.lineSpacing();
1043 int hp = mPixmap.height(); 1043 int hp = mPixmap.height();
1044 1044
1045 painter->drawPixmap( (mMinimumWidth-wp)/2, 5, mPixmap ); 1045 painter->drawPixmap( (mMinimumWidth-wp)/2, 5, mPixmap );
1046 if( text().isEmpty() == false ) 1046 if( text().isEmpty() == false )
1047 { 1047 {
1048 painter->drawText( 0, hp+7, mMinimumWidth, ht, Qt::AlignCenter, text() ); 1048 painter->drawText( 0, hp+7, mMinimumWidth, ht, Qt::AlignCenter, text() );
1049 } 1049 }
1050} 1050}
1051 1051
1052int OJanusWidget::IconListItem::height( const QListBox *lb ) const 1052int OJanusWidget::IconListItem::height( const QListBox *lb ) const
1053{ 1053{
1054 if( text().isEmpty() == true ) 1054 if( text().isEmpty() == true )
1055 { 1055 {
1056 return( mPixmap.height() ); 1056 return( mPixmap.height() );
1057 } 1057 }
1058 else 1058 else
1059 { 1059 {
1060 return( mPixmap.height() + lb->fontMetrics().lineSpacing()+10 ); 1060 return( mPixmap.height() + lb->fontMetrics().lineSpacing()+10 );
1061 } 1061 }
1062} 1062}
1063 1063
1064 1064
1065int OJanusWidget::IconListItem::width( const QListBox *lb ) const 1065int OJanusWidget::IconListItem::width( const QListBox *lb ) const
1066{ 1066{
1067 int wt = lb->fontMetrics().boundingRect(text()).width()+10; 1067 int wt = lb->fontMetrics().boundingRect(text()).width()+10;
1068 int wp = mPixmap.width() + 10; 1068 int wp = mPixmap.width() + 10;
1069 int w = QMAX( wt, wp ); 1069 int w = QMAX( wt, wp );
1070 return( QMAX( w, mMinimumWidth ) ); 1070 return( QMAX( w, mMinimumWidth ) );
1071} 1071}
1072 1072
1073// Just remove the page from our stack of widgets. Do not modify the given widget in 1073// Just remove the page from our stack of widgets. Do not modify the given widget in
1074// any way. No memory leak occurs as parent is not changed. 1074// any way. No memory leak occurs as parent is not changed.
1075// Make this virtual in KDE 4.0. 1075// Make this virtual in KDE 4.0.
1076// Ravikiran Rajagopal <ravi@ee.eng.ohio-state.edu> 1076// Ravikiran Rajagopal <ravi@ee.eng.ohio-state.edu>
1077void OJanusWidget::removePage( QWidget *page ) 1077void OJanusWidget::removePage( QWidget *page )
1078{ 1078{
1079 if (!mPageList || !mPageList->containsRef(page)) 1079 if (!mPageList || !mPageList->containsRef(page))
1080 return; 1080 return;
1081 1081
1082 int index = mPageList->findRef( page ); 1082 int index = mPageList->findRef( page );
1083 if ( mTitleList ) 1083 if ( mTitleList )
1084 mTitleList->remove(mTitleList->at(index)); 1084 mTitleList->remove(mTitleList->at(index));
1085 1085
1086 mPageList->removeRef(page); 1086 mPageList->removeRef(page);
1087 1087
1088 if ( mFace == TreeList ) 1088 if ( mFace == TreeList )
1089 { 1089 {
1090 QMap<QListViewItem*, QWidget *>::Iterator i; 1090 QMap<QListViewItem*, QWidget *>::Iterator i;
1091 for( i = mTreeListToPageStack.begin(); i != mTreeListToPageStack.end(); ++i ) 1091 for( i = mTreeListToPageStack.begin(); i != mTreeListToPageStack.end(); ++i )
1092 if (i.data()==page) 1092 if (i.data()==page)
1093 { 1093 {
1094 delete i.key(); 1094 delete i.key();
1095 mPageStack->removeWidget(page); 1095 mPageStack->removeWidget(page);
1096 mTreeListToPageStack.remove(i); 1096 mTreeListToPageStack.remove(i);
1097 break; 1097 break;
1098 } 1098 }
1099 } 1099 }
1100 else if ( mFace == IconList ) 1100 else if ( mFace == IconList )
1101 { 1101 {
1102 QMap<QListBoxItem*, QWidget *>::Iterator i; 1102 QMap<QListBoxItem*, QWidget *>::Iterator i;
1103 for( i = mIconListToPageStack.begin(); i != mIconListToPageStack.end(); ++i ) 1103 for( i = mIconListToPageStack.begin(); i != mIconListToPageStack.end(); ++i )
1104 if (i.data()==page) 1104 if (i.data()==page)
1105 { 1105 {
1106 delete i.key(); 1106 delete i.key();
1107 mPageStack->removeWidget(page); 1107 mPageStack->removeWidget(page);
1108 mIconListToPageStack.remove(i); 1108 mIconListToPageStack.remove(i);
1109 break; 1109 break;
1110 } 1110 }
1111 } 1111 }
1112 else // Tabbed 1112 else // Tabbed
1113 { 1113 {
1114 mTabControl->removePage(page); 1114 mTabControl->removePage(page);
1115 } 1115 }
1116} 1116}
diff --git a/library/lightstyle.cpp b/library/lightstyle.cpp
index f18bdca..3bd1623 100644
--- a/library/lightstyle.cpp
+++ b/library/lightstyle.cpp
@@ -1,1284 +1,1284 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "lightstyle.h" 20#include "lightstyle.h"
21 21
22#if QT_VERSION < 300 22#if QT_VERSION < 0x030000
23 23
24#define INCLUDE_MENUITEM_DEF 24#define INCLUDE_MENUITEM_DEF
25#include "qmenubar.h" 25#include "qmenubar.h"
26#include "qapplication.h" 26#include "qapplication.h"
27#include "qpainter.h" 27#include "qpainter.h"
28#include "qpalette.h" 28#include "qpalette.h"
29#include "qframe.h" 29#include "qframe.h"
30#include "qpushbutton.h" 30#include "qpushbutton.h"
31#include "qdrawutil.h" 31#include "qdrawutil.h"
32#include "qscrollbar.h" 32#include "qscrollbar.h"
33#include "qtabbar.h" 33#include "qtabbar.h"
34#include "qguardedptr.h" 34#include "qguardedptr.h"
35#include "qlayout.h" 35#include "qlayout.h"
36#include "qlineedit.h" 36#include "qlineedit.h"
37 37
38 38
39class LightStylePrivate 39class LightStylePrivate
40{ 40{
41public: 41public:
42 LightStylePrivate() 42 LightStylePrivate()
43 : hoverWidget(0), ref(1), savePalette(0) 43 : hoverWidget(0), ref(1), savePalette(0)
44 { 44 {
45 } 45 }
46 46
47 QGuardedPtr<QWidget> hoverWidget; 47 QGuardedPtr<QWidget> hoverWidget;
48 QPalette oldPalette, hoverPalette; 48 QPalette oldPalette, hoverPalette;
49 int ref; 49 int ref;
50 QPoint mousePos; 50 QPoint mousePos;
51 QPalette *savePalette; 51 QPalette *savePalette;
52}; 52};
53 53
54 54
55static LightStylePrivate *singleton = 0; 55static LightStylePrivate *singleton = 0;
56 56
57 57
58LightStyle::LightStyle() 58LightStyle::LightStyle()
59 : QWindowsStyle() 59 : QWindowsStyle()
60{ 60{
61 if (! singleton) { 61 if (! singleton) {
62 singleton = new LightStylePrivate; 62 singleton = new LightStylePrivate;
63 63
64 QPalette pal = QApplication::palette(); 64 QPalette pal = QApplication::palette();
65 singleton->oldPalette = pal; 65 singleton->oldPalette = pal;
66 66
67 QColor bg = pal.color(QPalette::Active, QColorGroup::Background); 67 QColor bg = pal.color(QPalette::Active, QColorGroup::Background);
68 QColor prelight; 68 QColor prelight;
69 69
70 if ( (bg.red() + bg.green() + bg.blue()) / 3 > 128) 70 if ( (bg.red() + bg.green() + bg.blue()) / 3 > 128)
71 prelight = pal.color(QPalette::Active, 71 prelight = pal.color(QPalette::Active,
72 QColorGroup::Background).light(110); 72 QColorGroup::Background).light(110);
73 else 73 else
74 prelight = pal.color(QPalette::Active, 74 prelight = pal.color(QPalette::Active,
75 QColorGroup::Background).light(120); 75 QColorGroup::Background).light(120);
76 76
77 QColorGroup active2(pal.color(QPalette::Active, 77 QColorGroup active2(pal.color(QPalette::Active,
78 QColorGroup::Foreground), // foreground 78 QColorGroup::Foreground), // foreground
79 prelight, // button 79 prelight, // button
80 prelight.light(), // light 80 prelight.light(), // light
81 prelight.dark(), // dark 81 prelight.dark(), // dark
82 prelight.dark(120), // mid 82 prelight.dark(120), // mid
83 pal.color(QPalette::Active, 83 pal.color(QPalette::Active,
84 QColorGroup::Text), // text 84 QColorGroup::Text), // text
85 pal.color(QPalette::Active, 85 pal.color(QPalette::Active,
86 QColorGroup::BrightText), // bright text 86 QColorGroup::BrightText), // bright text
87 pal.color(QPalette::Active, 87 pal.color(QPalette::Active,
88 QColorGroup::Base), // base 88 QColorGroup::Base), // base
89 bg); // background 89 bg); // background
90 active2.setColor(QColorGroup::Highlight, 90 active2.setColor(QColorGroup::Highlight,
91 pal.color(QPalette::Active, QColorGroup::Highlight)); 91 pal.color(QPalette::Active, QColorGroup::Highlight));
92 92
93 singleton->hoverPalette = pal; 93 singleton->hoverPalette = pal;
94 singleton->hoverPalette.setActive(active2); 94 singleton->hoverPalette.setActive(active2);
95 singleton->hoverPalette.setInactive(active2); 95 singleton->hoverPalette.setInactive(active2);
96 } else 96 } else
97 singleton->ref++; 97 singleton->ref++;
98} 98}
99 99
100 100
101LightStyle::~LightStyle() 101LightStyle::~LightStyle()
102{ 102{
103 if (singleton && singleton->ref-- <= 0) { 103 if (singleton && singleton->ref-- <= 0) {
104 delete singleton; 104 delete singleton;
105 singleton = 0; 105 singleton = 0;
106 } 106 }
107} 107}
108 108
109 109
110QSize LightStyle::scrollBarExtent() const 110QSize LightStyle::scrollBarExtent() const
111{ 111{
112 return QSize(12 + defaultFrameWidth(), 12 + defaultFrameWidth()); 112 return QSize(12 + defaultFrameWidth(), 12 + defaultFrameWidth());
113} 113}
114 114
115 115
116int LightStyle::buttonDefaultIndicatorWidth() const 116int LightStyle::buttonDefaultIndicatorWidth() const
117{ 117{
118 return 2; 118 return 2;
119} 119}
120 120
121 121
122int LightStyle::sliderThickness() const 122int LightStyle::sliderThickness() const
123{ 123{
124 return 16; 124 return 16;
125} 125}
126 126
127int LightStyle::sliderLength() const 127int LightStyle::sliderLength() const
128{ 128{
129 return 13; 129 return 13;
130} 130}
131 131
132 132
133int LightStyle::buttonMargin() const 133int LightStyle::buttonMargin() const
134{ 134{
135 return 4; 135 return 4;
136} 136}
137 137
138 138
139QSize LightStyle::exclusiveIndicatorSize() const 139QSize LightStyle::exclusiveIndicatorSize() const
140{ 140{
141 return QSize(13, 13); 141 return QSize(13, 13);
142} 142}
143 143
144 144
145int LightStyle::defaultFrameWidth() const 145int LightStyle::defaultFrameWidth() const
146{ 146{
147 return 2; 147 return 2;
148} 148}
149 149
150 150
151QSize LightStyle::indicatorSize() const 151QSize LightStyle::indicatorSize() const
152{ 152{
153 return QSize(13, 13); 153 return QSize(13, 13);
154} 154}
155 155
156 156
157void LightStyle::polish(QWidget *widget) 157void LightStyle::polish(QWidget *widget)
158{ 158{
159 if (widget->inherits("QPushButton")) 159 if (widget->inherits("QPushButton"))
160 widget->installEventFilter(this); 160 widget->installEventFilter(this);
161 161
162#if QT_VERSION >= 300 162#if QT_VERSION >= 0x030000
163 if (widget->inherits("QLineEdit")) { 163 if (widget->inherits("QLineEdit")) {
164 QLineEdit *lineedit = (QLineEdit *) widget; 164 QLineEdit *lineedit = (QLineEdit *) widget;
165 lineedit->setFrameShape(QFrame::StyledPanel); 165 lineedit->setFrameShape(QFrame::StyledPanel);
166 lineedit->setLineWidth(2); 166 lineedit->setLineWidth(2);
167 } 167 }
168#endif 168#endif
169 169
170 QWindowsStyle::polish(widget); 170 QWindowsStyle::polish(widget);
171} 171}
172 172
173 173
174void LightStyle::unPolish(QWidget *widget) 174void LightStyle::unPolish(QWidget *widget)
175{ 175{
176 if (widget->inherits("QPushButton")) 176 if (widget->inherits("QPushButton"))
177 widget->removeEventFilter(this); 177 widget->removeEventFilter(this);
178 178
179#if QT_VERSION >= 300 179#if QT_VERSION >= 0x030000
180 if (widget->inherits("QLineEdit")) { 180 if (widget->inherits("QLineEdit")) {
181 QLineEdit *lineedit = (QLineEdit *) widget; 181 QLineEdit *lineedit = (QLineEdit *) widget;
182 lineedit->setLineWidth(1); 182 lineedit->setLineWidth(1);
183 lineedit->setFrameShape(QFrame::WinPanel); 183 lineedit->setFrameShape(QFrame::WinPanel);
184 } 184 }
185#endif 185#endif
186 186
187 QWindowsStyle::unPolish(widget); 187 QWindowsStyle::unPolish(widget);
188} 188}
189 189
190 190
191void LightStyle::polish(QApplication *app) 191void LightStyle::polish(QApplication *app)
192{ 192{
193 QPalette pal = app->palette(); 193 QPalette pal = app->palette();
194 194
195 QColorGroup active(pal.color(QPalette::Active, 195 QColorGroup active(pal.color(QPalette::Active,
196 QColorGroup::Foreground), // foreground 196 QColorGroup::Foreground), // foreground
197 pal.color(QPalette::Active, 197 pal.color(QPalette::Active,
198 QColorGroup::Button), // button 198 QColorGroup::Button), // button
199 pal.color(QPalette::Active, 199 pal.color(QPalette::Active,
200 QColorGroup::Background).light(), // light 200 QColorGroup::Background).light(), // light
201 pal.color(QPalette::Active, 201 pal.color(QPalette::Active,
202 QColorGroup::Background).dark(175), // dark 202 QColorGroup::Background).dark(175), // dark
203 pal.color(QPalette::Active, 203 pal.color(QPalette::Active,
204 QColorGroup::Background).dark(110), // mid 204 QColorGroup::Background).dark(110), // mid
205 pal.color(QPalette::Active, 205 pal.color(QPalette::Active,
206 QColorGroup::Text), // text 206 QColorGroup::Text), // text
207 pal.color(QPalette::Active, 207 pal.color(QPalette::Active,
208 QColorGroup::BrightText), // bright text 208 QColorGroup::BrightText), // bright text
209 pal.color(QPalette::Active, 209 pal.color(QPalette::Active,
210 QColorGroup::Base), // base 210 QColorGroup::Base), // base
211 pal.color(QPalette::Active, 211 pal.color(QPalette::Active,
212 QColorGroup::Background)), // background 212 QColorGroup::Background)), // background
213 213
214 214
215 disabled(pal.color(QPalette::Disabled, 215 disabled(pal.color(QPalette::Disabled,
216 QColorGroup::Foreground), // foreground 216 QColorGroup::Foreground), // foreground
217 pal.color(QPalette::Disabled, 217 pal.color(QPalette::Disabled,
218 QColorGroup::Button), // button 218 QColorGroup::Button), // button
219 pal.color(QPalette::Disabled, 219 pal.color(QPalette::Disabled,
220 QColorGroup::Background).light(), // light 220 QColorGroup::Background).light(), // light
221 pal.color(QPalette::Disabled, 221 pal.color(QPalette::Disabled,
222 QColorGroup::Background).dark(), // dark 222 QColorGroup::Background).dark(), // dark
223 pal.color(QPalette::Disabled, 223 pal.color(QPalette::Disabled,
224 QColorGroup::Background).dark(110), // mid 224 QColorGroup::Background).dark(110), // mid
225 pal.color(QPalette::Disabled, 225 pal.color(QPalette::Disabled,
226 QColorGroup::Text), // text 226 QColorGroup::Text), // text
227 pal.color(QPalette::Disabled, 227 pal.color(QPalette::Disabled,
228 QColorGroup::BrightText), // bright text 228 QColorGroup::BrightText), // bright text
229 pal.color(QPalette::Disabled, 229 pal.color(QPalette::Disabled,
230 QColorGroup::Base), // base 230 QColorGroup::Base), // base
231 pal.color(QPalette::Disabled, 231 pal.color(QPalette::Disabled,
232 QColorGroup::Background)); // background 232 QColorGroup::Background)); // background
233 233
234 active.setColor(QColorGroup::Highlight, 234 active.setColor(QColorGroup::Highlight,
235 pal.color(QPalette::Active, QColorGroup::Highlight)); 235 pal.color(QPalette::Active, QColorGroup::Highlight));
236 disabled.setColor(QColorGroup::Highlight, 236 disabled.setColor(QColorGroup::Highlight,
237 pal.color(QPalette::Disabled, QColorGroup::Highlight)); 237 pal.color(QPalette::Disabled, QColorGroup::Highlight));
238 238
239 active.setColor(QColorGroup::HighlightedText, 239 active.setColor(QColorGroup::HighlightedText,
240 pal.color(QPalette::Active, QColorGroup::HighlightedText)); 240 pal.color(QPalette::Active, QColorGroup::HighlightedText));
241 disabled.setColor(QColorGroup::HighlightedText, 241 disabled.setColor(QColorGroup::HighlightedText,
242 pal.color(QPalette::Disabled, QColorGroup::HighlightedText)); 242 pal.color(QPalette::Disabled, QColorGroup::HighlightedText));
243 243
244 pal.setActive(active); 244 pal.setActive(active);
245 pal.setInactive(active); 245 pal.setInactive(active);
246 pal.setDisabled(disabled); 246 pal.setDisabled(disabled);
247 247
248 singleton->oldPalette = pal; 248 singleton->oldPalette = pal;
249 249
250 QColor bg = pal.color(QPalette::Active, QColorGroup::Background); 250 QColor bg = pal.color(QPalette::Active, QColorGroup::Background);
251 QColor prelight; 251 QColor prelight;
252 252
253 if ( (bg.red() + bg.green() + bg.blue()) / 3 > 128) 253 if ( (bg.red() + bg.green() + bg.blue()) / 3 > 128)
254 prelight = pal.color(QPalette::Active, 254 prelight = pal.color(QPalette::Active,
255 QColorGroup::Background).light(110); 255 QColorGroup::Background).light(110);
256 else 256 else
257 prelight = pal.color(QPalette::Active, 257 prelight = pal.color(QPalette::Active,
258 QColorGroup::Background).light(120); 258 QColorGroup::Background).light(120);
259 259
260 QColorGroup active2(pal.color(QPalette::Active, 260 QColorGroup active2(pal.color(QPalette::Active,
261 QColorGroup::Foreground), // foreground 261 QColorGroup::Foreground), // foreground
262 prelight, // button 262 prelight, // button
263 prelight.light(), // light 263 prelight.light(), // light
264 prelight.dark(), // dark 264 prelight.dark(), // dark
265 prelight.dark(120), // mid 265 prelight.dark(120), // mid
266 pal.color(QPalette::Active, 266 pal.color(QPalette::Active,
267 QColorGroup::Text), // text 267 QColorGroup::Text), // text
268 pal.color(QPalette::Active, 268 pal.color(QPalette::Active,
269 QColorGroup::BrightText), // bright text 269 QColorGroup::BrightText), // bright text
270 pal.color(QPalette::Active, 270 pal.color(QPalette::Active,
271 QColorGroup::Base), // base 271 QColorGroup::Base), // base
272 bg); // background 272 bg); // background
273 active2.setColor(QColorGroup::Highlight, 273 active2.setColor(QColorGroup::Highlight,
274 pal.color(QPalette::Active, QColorGroup::Highlight)); 274 pal.color(QPalette::Active, QColorGroup::Highlight));
275 275
276 singleton->hoverPalette = pal; 276 singleton->hoverPalette = pal;
277 singleton->hoverPalette.setActive(active2); 277 singleton->hoverPalette.setActive(active2);
278 singleton->hoverPalette.setInactive(active2); 278 singleton->hoverPalette.setInactive(active2);
279 279
280 app->setPalette(pal); 280 app->setPalette(pal);
281} 281}
282 282
283 283
284void LightStyle::unPolish(QApplication *app) 284void LightStyle::unPolish(QApplication *app)
285{ 285{
286 app->setPalette(singleton->oldPalette); 286 app->setPalette(singleton->oldPalette);
287} 287}
288 288
289 289
290void LightStyle::polishPopupMenu(QPopupMenu *menu) 290void LightStyle::polishPopupMenu(QPopupMenu *menu)
291{ 291{
292 menu->setMouseTracking(TRUE); 292 menu->setMouseTracking(TRUE);
293} 293}
294 294
295 295
296void LightStyle::drawPushButton(QPushButton *button, QPainter *p) 296void LightStyle::drawPushButton(QPushButton *button, QPainter *p)
297{ 297{
298 int x1, y1, x2, y2; 298 int x1, y1, x2, y2;
299 button->rect().coords(&x1, &y1, &x2, &y2); 299 button->rect().coords(&x1, &y1, &x2, &y2);
300 300
301 if (button->isDefault()) { 301 if (button->isDefault()) {
302 p->save(); 302 p->save();
303 p->setPen(button->palette().active().color(QColorGroup::Highlight)); 303 p->setPen(button->palette().active().color(QColorGroup::Highlight));
304 p->setBrush(button->palette().active().brush(QColorGroup::Highlight)); 304 p->setBrush(button->palette().active().brush(QColorGroup::Highlight));
305 p->drawRoundRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1, 15, 15); 305 p->drawRoundRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1, 15, 15);
306 p->restore(); 306 p->restore();
307 } 307 }
308 308
309 if (button->isDefault() || button->autoDefault()) { 309 if (button->isDefault() || button->autoDefault()) {
310 x1 += buttonDefaultIndicatorWidth(); 310 x1 += buttonDefaultIndicatorWidth();
311 y1 += buttonDefaultIndicatorWidth(); 311 y1 += buttonDefaultIndicatorWidth();
312 x2 -= buttonDefaultIndicatorWidth(); 312 x2 -= buttonDefaultIndicatorWidth();
313 y2 -= buttonDefaultIndicatorWidth(); 313 y2 -= buttonDefaultIndicatorWidth();
314 314
315 if (button->isDefault()) { 315 if (button->isDefault()) {
316 QPointArray pa(8); 316 QPointArray pa(8);
317 pa.setPoint(0, x1 + 2, y1 ); 317 pa.setPoint(0, x1 + 2, y1 );
318 pa.setPoint(1, x2 - 1, y1 ); 318 pa.setPoint(1, x2 - 1, y1 );
319 pa.setPoint(2, x2 + 1, y1 + 2); 319 pa.setPoint(2, x2 + 1, y1 + 2);
320 pa.setPoint(3, x2 + 1, y2 - 2); 320 pa.setPoint(3, x2 + 1, y2 - 2);
321 pa.setPoint(4, x2 - 2, y2 + 1); 321 pa.setPoint(4, x2 - 2, y2 + 1);
322 pa.setPoint(5, x1 + 2, y2 + 1); 322 pa.setPoint(5, x1 + 2, y2 + 1);
323 pa.setPoint(6, x1, y2 - 1); 323 pa.setPoint(6, x1, y2 - 1);
324 pa.setPoint(7, x1, y1 + 2); 324 pa.setPoint(7, x1, y1 + 2);
325 QRegion r(pa); 325 QRegion r(pa);
326 p->setClipRegion(r); 326 p->setClipRegion(r);
327 } 327 }
328 } 328 }
329 329
330 QBrush fill; 330 QBrush fill;
331 if (button->isDown() || button->isOn()) 331 if (button->isDown() || button->isOn())
332 fill = button->colorGroup().brush(QColorGroup::Mid); 332 fill = button->colorGroup().brush(QColorGroup::Mid);
333 else 333 else
334 fill = button->colorGroup().brush(QColorGroup::Button); 334 fill = button->colorGroup().brush(QColorGroup::Button);
335 335
336 if ( !button->isFlat() || button->isOn() || button->isDown() ) 336 if ( !button->isFlat() || button->isOn() || button->isDown() )
337 drawButton(p, x1, y1, x2 - x1 + 1, y2 - y1 + 1, 337 drawButton(p, x1, y1, x2 - x1 + 1, y2 - y1 + 1,
338 button->colorGroup(), button->isOn() || button->isDown(), &fill); 338 button->colorGroup(), button->isOn() || button->isDown(), &fill);
339} 339}
340 340
341 341
342void LightStyle::drawButton(QPainter *p, int x, int y, int w, int h, 342void LightStyle::drawButton(QPainter *p, int x, int y, int w, int h,
343 const QColorGroup &g, 343 const QColorGroup &g,
344 bool sunken, const QBrush *fill) 344 bool sunken, const QBrush *fill)
345{ 345{
346 p->save(); 346 p->save();
347 if ( fill ) 347 if ( fill )
348 p->fillRect(x + 2, y + 2, w - 4, h - 4, *fill); 348 p->fillRect(x + 2, y + 2, w - 4, h - 4, *fill);
349 else 349 else
350 p->fillRect(x + 2, y + 2, w - 4, h - 4, 350 p->fillRect(x + 2, y + 2, w - 4, h - 4,
351 QBrush(sunken ? g.mid() : g.button())); 351 QBrush(sunken ? g.mid() : g.button()));
352 352
353 // frame 353 // frame
354 p->setPen(g.dark()); 354 p->setPen(g.dark());
355 p->drawLine(x, y + 2, x, y + h - 3); // left 355 p->drawLine(x, y + 2, x, y + h - 3); // left
356 p->drawLine(x + 2, y, x + w - 3, y); // top 356 p->drawLine(x + 2, y, x + w - 3, y); // top
357 p->drawLine(x + w - 1, y + 2, x + w - 1, y + h - 3); // right 357 p->drawLine(x + w - 1, y + 2, x + w - 1, y + h - 3); // right
358 p->drawLine(x + 2, y + h - 1, x + w - 3, y + h - 1); // bottom 358 p->drawLine(x + 2, y + h - 1, x + w - 3, y + h - 1); // bottom
359 p->drawPoint(x + 1, y + 1); 359 p->drawPoint(x + 1, y + 1);
360 p->drawPoint(x + 1, y + h - 2); 360 p->drawPoint(x + 1, y + h - 2);
361 p->drawPoint(x + w - 2, y + 1); 361 p->drawPoint(x + w - 2, y + 1);
362 p->drawPoint(x + w - 2, y + h - 2); 362 p->drawPoint(x + w - 2, y + h - 2);
363 363
364 // bevel 364 // bevel
365 if (sunken) 365 if (sunken)
366 p->setPen(g.mid()); 366 p->setPen(g.mid());
367 else 367 else
368 p->setPen(g.light()); 368 p->setPen(g.light());
369 369
370 p->drawLine(x + 1, y + 2, x + 1, y + h - 3); // left 370 p->drawLine(x + 1, y + 2, x + 1, y + h - 3); // left
371 p->drawLine(x + 2, y + 1, x + w - 3, y + 1); // top 371 p->drawLine(x + 2, y + 1, x + w - 3, y + 1); // top
372 372
373 if (sunken) 373 if (sunken)
374 p->setPen(g.light()); 374 p->setPen(g.light());
375 else 375 else
376 p->setPen(g.mid()); 376 p->setPen(g.mid());
377 377
378 p->drawLine(x + w - 2, y + 2, x + w - 2, y + h - 3); // right + 1 378 p->drawLine(x + w - 2, y + 2, x + w - 2, y + h - 3); // right + 1
379 p->drawLine(x + 2, y + h - 2, x + w - 3, y + h - 2); // bottom + 1 379 p->drawLine(x + 2, y + h - 2, x + w - 3, y + h - 2); // bottom + 1
380 380
381 p->restore(); 381 p->restore();
382} 382}
383 383
384 384
385void LightStyle::drawBevelButton(QPainter *p, int x, int y, int w, int h, 385void LightStyle::drawBevelButton(QPainter *p, int x, int y, int w, int h,
386 const QColorGroup &g, 386 const QColorGroup &g,
387 bool sunken, const QBrush *fill) 387 bool sunken, const QBrush *fill)
388{ 388{
389 drawButton(p, x, y, w, h, g, sunken, fill); 389 drawButton(p, x, y, w, h, g, sunken, fill);
390} 390}
391 391
392 392
393void LightStyle::getButtonShift(int &x, int &y) const 393void LightStyle::getButtonShift(int &x, int &y) const
394{ 394{
395 x = y = 0; 395 x = y = 0;
396} 396}
397 397
398 398
399void LightStyle::drawComboButton(QPainter *p, int x, int y, int w, int h, 399void LightStyle::drawComboButton(QPainter *p, int x, int y, int w, int h,
400 const QColorGroup &g, bool, 400 const QColorGroup &g, bool,
401 bool editable, bool, 401 bool editable, bool,
402 const QBrush *fill) 402 const QBrush *fill)
403{ 403{
404 drawButton(p, x, y, w, h, g, FALSE, fill); 404 drawButton(p, x, y, w, h, g, FALSE, fill);
405 405
406 if (editable) { 406 if (editable) {
407 QRect r = comboButtonRect(x, y, w, h); 407 QRect r = comboButtonRect(x, y, w, h);
408 qDrawShadePanel(p, r.x() - 1, r.y() - 1, 408 qDrawShadePanel(p, r.x() - 1, r.y() - 1,
409 r.width() + defaultFrameWidth(), 409 r.width() + defaultFrameWidth(),
410 r.height() + defaultFrameWidth(), 410 r.height() + defaultFrameWidth(),
411 g, TRUE); 411 g, TRUE);
412 } 412 }
413 413
414 int indent = ((y + h) / 2) - 3; 414 int indent = ((y + h) / 2) - 3;
415 int xpos = x; 415 int xpos = x;
416 416
417#if QT_VERSION >= 300 417#if QT_VERSION >= 0x030000
418 if( QApplication::reverseLayout() ) 418 if( QApplication::reverseLayout() )
419 xpos += indent; 419 xpos += indent;
420 else 420 else
421#endif 421#endif
422 xpos += w - indent - 5; 422 xpos += w - indent - 5;
423 423
424 drawArrow(p, Qt::DownArrow, TRUE, xpos, indent, 5, 5, g, TRUE, fill); 424 drawArrow(p, Qt::DownArrow, TRUE, xpos, indent, 5, 5, g, TRUE, fill);
425} 425}
426 426
427 427
428QRect LightStyle::comboButtonRect( int x, int y, int w, int h ) const 428QRect LightStyle::comboButtonRect( int x, int y, int w, int h ) const
429{ 429{
430 QRect r(x + 3, y + 3, w - 6, h - 6); 430 QRect r(x + 3, y + 3, w - 6, h - 6);
431 int indent = ((y + h) / 2) - 3; 431 int indent = ((y + h) / 2) - 3;
432 r.setRight(r.right() - indent - 10); 432 r.setRight(r.right() - indent - 10);
433 433
434#if QT_VERSION >= 300 434#if QT_VERSION >= 0x030000
435 if( QApplication::reverseLayout() ) 435 if( QApplication::reverseLayout() )
436 r.moveBy( indent + 10, 0 ); 436 r.moveBy( indent + 10, 0 );
437#endif 437#endif
438 438
439 return r; 439 return r;
440} 440}
441 441
442 442
443QRect LightStyle::comboButtonFocusRect(int x, int y, int w, int h ) const 443QRect LightStyle::comboButtonFocusRect(int x, int y, int w, int h ) const
444{ 444{
445 return comboButtonRect(x, y, w, h); 445 return comboButtonRect(x, y, w, h);
446} 446}
447 447
448 448
449void LightStyle::drawPanel(QPainter *p, int x, int y, int w, int h, 449void LightStyle::drawPanel(QPainter *p, int x, int y, int w, int h,
450 const QColorGroup &g, bool sunken, 450 const QColorGroup &g, bool sunken,
451 int lw, const QBrush *fill) 451 int lw, const QBrush *fill)
452{ 452{
453 if (lw >= 2) { 453 if (lw >= 2) {
454 if ( fill ) 454 if ( fill )
455 p->fillRect(x + 2, y + 2, w - 4, h - 4, *fill); 455 p->fillRect(x + 2, y + 2, w - 4, h - 4, *fill);
456 456
457 QPen oldpen = p->pen(); 457 QPen oldpen = p->pen();
458 458
459 // frame 459 // frame
460 p->setPen(g.dark()); 460 p->setPen(g.dark());
461 p->drawLine(x, y + 2, x, y + h - 3); // left 461 p->drawLine(x, y + 2, x, y + h - 3); // left
462 p->drawLine(x + 2, y, x + w - 3, y); // top 462 p->drawLine(x + 2, y, x + w - 3, y); // top
463 p->drawLine(x + w - 1, y + 2, x + w - 1, y + h - 3); // right 463 p->drawLine(x + w - 1, y + 2, x + w - 1, y + h - 3); // right
464 p->drawLine(x + 2, y + h - 1, x + w - 3, y + h - 1); // bottom 464 p->drawLine(x + 2, y + h - 1, x + w - 3, y + h - 1); // bottom
465 p->drawPoint(x + 1, y + 1); 465 p->drawPoint(x + 1, y + 1);
466 p->drawPoint(x + 1, y + h - 2); 466 p->drawPoint(x + 1, y + h - 2);
467 p->drawPoint(x + w - 2, y + 1); 467 p->drawPoint(x + w - 2, y + 1);
468 p->drawPoint(x + w - 2, y + h - 2); 468 p->drawPoint(x + w - 2, y + h - 2);
469 469
470 // bevel 470 // bevel
471 if (sunken) 471 if (sunken)
472 p->setPen(g.mid()); 472 p->setPen(g.mid());
473 else 473 else
474 p->setPen(g.light()); 474 p->setPen(g.light());
475 475
476 p->drawLine(x + 1, y + 2, x + 1, y + h - 3); // left 476 p->drawLine(x + 1, y + 2, x + 1, y + h - 3); // left
477 p->drawLine(x + 2, y + 1, x + w - 3, y + 1); // top 477 p->drawLine(x + 2, y + 1, x + w - 3, y + 1); // top
478 478
479 if (sunken) 479 if (sunken)
480 p->setPen(g.light()); 480 p->setPen(g.light());
481 else 481 else
482 p->setPen(g.mid()); 482 p->setPen(g.mid());
483 483
484 p->drawLine(x + w - 2, y + 2, x + w - 2, y + h - 3); // right + 1 484 p->drawLine(x + w - 2, y + 2, x + w - 2, y + h - 3); // right + 1
485 p->drawLine(x + 2, y + h - 2, x + w - 3, y + h - 2); // bottom + 1 485 p->drawLine(x + 2, y + h - 2, x + w - 3, y + h - 2); // bottom + 1
486 486
487 // corners 487 // corners
488 p->setPen(g.background()); 488 p->setPen(g.background());
489 p->drawLine(x, y, x + 1, y); 489 p->drawLine(x, y, x + 1, y);
490 p->drawLine(x, y + h - 1, x + 1, y + h - 1); 490 p->drawLine(x, y + h - 1, x + 1, y + h - 1);
491 p->drawLine(x + w - 2, y, x + w - 1, y); 491 p->drawLine(x + w - 2, y, x + w - 1, y);
492 p->drawLine(x + w - 2, y + h - 1, x + w - 1, y + h - 1); 492 p->drawLine(x + w - 2, y + h - 1, x + w - 1, y + h - 1);
493 p->drawPoint(x, y + 1); 493 p->drawPoint(x, y + 1);
494 p->drawPoint(x, y + h - 2); 494 p->drawPoint(x, y + h - 2);
495 p->drawPoint(x + w - 1, y + 1); 495 p->drawPoint(x + w - 1, y + 1);
496 p->drawPoint(x + w - 1, y + h - 2); 496 p->drawPoint(x + w - 1, y + h - 2);
497 497
498 p->setPen(oldpen); 498 p->setPen(oldpen);
499 } else 499 } else
500 qDrawShadePanel(p, x, y, w, h, g, sunken, lw, fill); 500 qDrawShadePanel(p, x, y, w, h, g, sunken, lw, fill);
501} 501}
502 502
503 503
504void LightStyle::drawIndicator(QPainter *p, int x, int y ,int w, int h, 504void LightStyle::drawIndicator(QPainter *p, int x, int y ,int w, int h,
505 const QColorGroup &g, int state, 505 const QColorGroup &g, int state,
506 bool down, bool) 506 bool down, bool)
507{ 507{
508 drawButton(p, x, y, w, h, g, TRUE, 508 drawButton(p, x, y, w, h, g, TRUE,
509 &g.brush(down ? QColorGroup::Mid : QColorGroup::Base)); 509 &g.brush(down ? QColorGroup::Mid : QColorGroup::Base));
510 510
511 p->save(); 511 p->save();
512 512
513 p->setPen(g.foreground()); 513 p->setPen(g.foreground());
514 if (state == QButton::NoChange) { 514 if (state == QButton::NoChange) {
515 p->drawLine(x + 3, y + h / 2, x + w - 4, y + h / 2); 515 p->drawLine(x + 3, y + h / 2, x + w - 4, y + h / 2);
516 p->drawLine(x + 3, y + 1 + h / 2, x + w - 4, y + 1 + h / 2); 516 p->drawLine(x + 3, y + 1 + h / 2, x + w - 4, y + 1 + h / 2);
517 p->drawLine(x + 3, y - 1 + h / 2, x + w - 4, y - 1 + h / 2); 517 p->drawLine(x + 3, y - 1 + h / 2, x + w - 4, y - 1 + h / 2);
518 } else if (state == QButton::On) { 518 } else if (state == QButton::On) {
519 p->drawLine(x + 4, y + 3, x + w - 4, y + h - 5); 519 p->drawLine(x + 4, y + 3, x + w - 4, y + h - 5);
520 p->drawLine(x + 3, y + 3, x + w - 4, y + h - 4); 520 p->drawLine(x + 3, y + 3, x + w - 4, y + h - 4);
521 p->drawLine(x + 3, y + 4, x + w - 5, y + h - 4); 521 p->drawLine(x + 3, y + 4, x + w - 5, y + h - 4);
522 p->drawLine(x + 3, y + h - 5, x + w - 5, y + 3); 522 p->drawLine(x + 3, y + h - 5, x + w - 5, y + 3);
523 p->drawLine(x + 3, y + h - 4, x + w - 4, y + 3); 523 p->drawLine(x + 3, y + h - 4, x + w - 4, y + 3);
524 p->drawLine(x + 4, y + h - 4, x + w - 4, y + 4); 524 p->drawLine(x + 4, y + h - 4, x + w - 4, y + 4);
525 } 525 }
526 526
527 p->restore(); 527 p->restore();
528} 528}
529 529
530 530
531void LightStyle::drawExclusiveIndicator(QPainter *p, int x, int y, int w, int h, 531void LightStyle::drawExclusiveIndicator(QPainter *p, int x, int y, int w, int h,
532 const QColorGroup &g, bool on, 532 const QColorGroup &g, bool on,
533 bool down, bool) 533 bool down, bool)
534{ 534{
535 p->save(); 535 p->save();
536 536
537 p->fillRect(x, y, w, h, g.brush(QColorGroup::Background)); 537 p->fillRect(x, y, w, h, g.brush(QColorGroup::Background));
538 538
539 p->setPen(g.dark()); 539 p->setPen(g.dark());
540 p->drawArc(x, y, w, h, 0, 16*360); 540 p->drawArc(x, y, w, h, 0, 16*360);
541 p->setPen(g.mid()); 541 p->setPen(g.mid());
542 p->drawArc(x + 1, y + 1, w - 2, h - 2, 45*16, 180*16); 542 p->drawArc(x + 1, y + 1, w - 2, h - 2, 45*16, 180*16);
543 p->setPen(g.light()); 543 p->setPen(g.light());
544 p->drawArc(x + 1, y + 1, w - 2, h - 2, 235*16, 180*16); 544 p->drawArc(x + 1, y + 1, w - 2, h - 2, 235*16, 180*16);
545 545
546 p->setPen(down ? g.mid() : g.base()); 546 p->setPen(down ? g.mid() : g.base());
547 p->setBrush(down ? g.mid() : g.base()); 547 p->setBrush(down ? g.mid() : g.base());
548 p->drawEllipse(x + 2, y + 2, w - 4, h - 4); 548 p->drawEllipse(x + 2, y + 2, w - 4, h - 4);
549 549
550 if (on) { 550 if (on) {
551 p->setBrush(g.foreground()); 551 p->setBrush(g.foreground());
552 p->drawEllipse(x + 3, y + 3, w - x - 6, h - y - 6); 552 p->drawEllipse(x + 3, y + 3, w - x - 6, h - y - 6);
553 } 553 }
554 554
555 p->restore(); 555 p->restore();
556} 556}
557 557
558 558
559 559
560#if 1 560#if 1
561//copied from QPE style 561//copied from QPE style
562void LightStyle::drawTab( QPainter *p, const QTabBar *tb, QTab *t, bool selected ) 562void LightStyle::drawTab( QPainter *p, const QTabBar *tb, QTab *t, bool selected )
563{ 563{
564#if 0 564#if 0
565 //We can't do this, because QTabBar::focusInEvent redraws the 565 //We can't do this, because QTabBar::focusInEvent redraws the
566 // tab label with the default font. 566 // tab label with the default font.
567 QFont f = tb->font(); 567 QFont f = tb->font();
568 f.setBold( selected ); 568 f.setBold( selected );
569 p->setFont( f ); 569 p->setFont( f );
570#endif 570#endif
571 QRect r( t->rect() ); 571 QRect r( t->rect() );
572 if ( tb->shape() == QTabBar::RoundedAbove ) { 572 if ( tb->shape() == QTabBar::RoundedAbove ) {
573 p->setPen( tb->colorGroup().light() ); 573 p->setPen( tb->colorGroup().light() );
574 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() ); 574 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
575 if ( r.left() == 0 ) 575 if ( r.left() == 0 )
576 p->drawPoint( tb->rect().bottomLeft() ); 576 p->drawPoint( tb->rect().bottomLeft() );
577 else { 577 else {
578 p->setPen( tb->colorGroup().light() ); 578 p->setPen( tb->colorGroup().light() );
579 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() ); 579 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
580 } 580 }
581 581
582 if ( selected ) { 582 if ( selected ) {
583 p->setPen( tb->colorGroup().background() ); 583 p->setPen( tb->colorGroup().background() );
584 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 ); 584 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
585 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-2), 585 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-2),
586 tb->colorGroup().brush( QColorGroup::Background )); 586 tb->colorGroup().brush( QColorGroup::Background ));
587 587
588 } else { 588 } else {
589 r.setRect( r.left() + 2, r.top() + 2, 589 r.setRect( r.left() + 2, r.top() + 2,
590 r.width() - 4, r.height() - 2 ); 590 r.width() - 4, r.height() - 2 );
591 p->setPen( tb->colorGroup().button() ); 591 p->setPen( tb->colorGroup().button() );
592 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 ); 592 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
593 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-3), 593 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-3),
594 tb->colorGroup().brush( QColorGroup::Button )); 594 tb->colorGroup().brush( QColorGroup::Button ));
595 //do shading; will not work for pixmap brushes 595 //do shading; will not work for pixmap brushes
596 QColor bg = tb->colorGroup().button(); 596 QColor bg = tb->colorGroup().button();
597 // int h,s,v; 597 // int h,s,v;
598 // bg.hsv( &h, &s, &v ); 598 // bg.hsv( &h, &s, &v );
599 int n = r.height()/2; 599 int n = r.height()/2;
600 int dark = 100; 600 int dark = 100;
601 for ( int i = 1; i < n; i++ ) { 601 for ( int i = 1; i < n; i++ ) {
602 dark = (dark * (100+(i*15)/n) )/100; 602 dark = (dark * (100+(i*15)/n) )/100;
603 p->setPen( bg.dark( dark ) ); 603 p->setPen( bg.dark( dark ) );
604 int y = r.bottom()-n+i; 604 int y = r.bottom()-n+i;
605 int x1 = r.left()+1; 605 int x1 = r.left()+1;
606 int x2 = r.right()-1; 606 int x2 = r.right()-1;
607 p->drawLine( x1, y, x2, y ); 607 p->drawLine( x1, y, x2, y );
608 } 608 }
609 609
610 } 610 }
611 611
612 p->setPen( tb->colorGroup().light() ); 612 p->setPen( tb->colorGroup().light() );
613 p->drawLine( r.left(), r.bottom()-1, r.left(), r.top() + 2 ); 613 p->drawLine( r.left(), r.bottom()-1, r.left(), r.top() + 2 );
614 p->drawPoint( r.left()+1, r.top() + 1 ); 614 p->drawPoint( r.left()+1, r.top() + 1 );
615 p->drawLine( r.left()+2, r.top(), 615 p->drawLine( r.left()+2, r.top(),
616 r.right() - 2, r.top() ); 616 r.right() - 2, r.top() );
617 617
618 p->setPen( tb->colorGroup().dark() ); 618 p->setPen( tb->colorGroup().dark() );
619 p->drawPoint( r.right() - 1, r.top() + 1 ); 619 p->drawPoint( r.right() - 1, r.top() + 1 );
620 p->drawLine( r.right(), r.top() + 2, r.right(), r.bottom() - 1); 620 p->drawLine( r.right(), r.top() + 2, r.right(), r.bottom() - 1);
621 } else if ( tb->shape() == QTabBar::RoundedBelow ) { 621 } else if ( tb->shape() == QTabBar::RoundedBelow ) {
622 if ( selected ) { 622 if ( selected ) {
623 p->setPen( tb->colorGroup().background() ); 623 p->setPen( tb->colorGroup().background() );
624 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 ); 624 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
625 p->fillRect( QRect( r.left()+1, r.top(), r.width()-2, r.height()-2), 625 p->fillRect( QRect( r.left()+1, r.top(), r.width()-2, r.height()-2),
626 tb->palette().normal().brush( QColorGroup::Background )); 626 tb->palette().normal().brush( QColorGroup::Background ));
627 } else { 627 } else {
628 p->setPen( tb->colorGroup().dark() ); 628 p->setPen( tb->colorGroup().dark() );
629 p->drawLine( r.left(), r.top(), 629 p->drawLine( r.left(), r.top(),
630 r.right(), r.top() ); 630 r.right(), r.top() );
631 r.setRect( r.left() + 2, r.top(), 631 r.setRect( r.left() + 2, r.top(),
632 r.width() - 4, r.height() - 2 ); 632 r.width() - 4, r.height() - 2 );
633 p->setPen( tb->colorGroup().button() ); 633 p->setPen( tb->colorGroup().button() );
634 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 ); 634 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
635 p->fillRect( QRect( r.left()+1, r.top()+1, r.width()-2, r.height()-3), 635 p->fillRect( QRect( r.left()+1, r.top()+1, r.width()-2, r.height()-3),
636 tb->palette().normal().brush( QColorGroup::Button )); 636 tb->palette().normal().brush( QColorGroup::Button ));
637 } 637 }
638 638
639 p->setPen( tb->colorGroup().dark() ); 639 p->setPen( tb->colorGroup().dark() );
640 p->drawLine( r.right(), r.top(), 640 p->drawLine( r.right(), r.top(),
641 r.right(), r.bottom() - 2 ); 641 r.right(), r.bottom() - 2 );
642 p->drawPoint( r.right() - 1, r.bottom() - 1 ); 642 p->drawPoint( r.right() - 1, r.bottom() - 1 );
643 p->drawLine( r.right() - 2, r.bottom(), 643 p->drawLine( r.right() - 2, r.bottom(),
644 r.left() + 2, r.bottom() ); 644 r.left() + 2, r.bottom() );
645 645
646 p->setPen( tb->colorGroup().light() ); 646 p->setPen( tb->colorGroup().light() );
647 p->drawLine( r.left(), r.top()+1, 647 p->drawLine( r.left(), r.top()+1,
648 r.left(), r.bottom() - 2 ); 648 r.left(), r.bottom() - 2 );
649 p->drawPoint( r.left() + 1, r.bottom() - 1 ); 649 p->drawPoint( r.left() + 1, r.bottom() - 1 );
650 if ( r.left() == 0 ) 650 if ( r.left() == 0 )
651 p->drawPoint( tb->rect().topLeft() ); 651 p->drawPoint( tb->rect().topLeft() );
652 652
653 } else { 653 } else {
654 QCommonStyle::drawTab( p, tb, t, selected ); 654 QCommonStyle::drawTab( p, tb, t, selected );
655 } 655 }
656} 656}
657 657
658#else 658#else
659 659
660void LightStyle::drawTab(QPainter *p, const QTabBar *tabbar, QTab *tab, 660void LightStyle::drawTab(QPainter *p, const QTabBar *tabbar, QTab *tab,
661 bool selected) 661 bool selected)
662{ 662{
663 p->save(); 663 p->save();
664 664
665 QColorGroup g = tabbar->colorGroup(); 665 QColorGroup g = tabbar->colorGroup();
666 QRect fr(tab->r); 666 QRect fr(tab->r);
667 fr.setLeft(fr.left() + 2); 667 fr.setLeft(fr.left() + 2);
668 668
669 if (! selected) { 669 if (! selected) {
670 if (tabbar->shape() == QTabBar::RoundedAbove || 670 if (tabbar->shape() == QTabBar::RoundedAbove ||
671 tabbar->shape() == QTabBar::TriangularAbove) { 671 tabbar->shape() == QTabBar::TriangularAbove) {
672 672
673 fr.setTop(fr.top() + 2); 673 fr.setTop(fr.top() + 2);
674 } else { 674 } else {
675 fr.setBottom(fr.bottom() - 2); 675 fr.setBottom(fr.bottom() - 2);
676 } 676 }
677 } 677 }
678 678
679 QRegion tabr(tab->r); 679 QRegion tabr(tab->r);
680 680
681 QPointArray cliptri(4); 681 QPointArray cliptri(4);
682 cliptri.setPoint(0, fr.left(), fr.top()); 682 cliptri.setPoint(0, fr.left(), fr.top());
683 cliptri.setPoint(1, fr.left(), fr.top() + 5); 683 cliptri.setPoint(1, fr.left(), fr.top() + 5);
684 cliptri.setPoint(2, fr.left() + 5, fr.top()); 684 cliptri.setPoint(2, fr.left() + 5, fr.top());
685 cliptri.setPoint(3, fr.left(), fr.top()); 685 cliptri.setPoint(3, fr.left(), fr.top());
686 QRegion trir(cliptri); 686 QRegion trir(cliptri);
687 p->setClipRegion(tabr - trir); 687 p->setClipRegion(tabr - trir);
688 688
689 p->setPen( NoPen ); 689 p->setPen( NoPen );
690 p->setBrush(g.brush(selected ? QColorGroup::Background : QColorGroup::Mid)); 690 p->setBrush(g.brush(selected ? QColorGroup::Background : QColorGroup::Mid));
691 691
692 fr.setWidth(fr.width() - 1); 692 fr.setWidth(fr.width() - 1);
693 p->drawRect(fr.left() + 1, fr.top() + 1, fr.width() - 2, fr.height() - 2); 693 p->drawRect(fr.left() + 1, fr.top() + 1, fr.width() - 2, fr.height() - 2);
694 694
695 if (tabbar->shape() == QTabBar::RoundedAbove) { 695 if (tabbar->shape() == QTabBar::RoundedAbove) {
696 // "rounded" tabs on top 696 // "rounded" tabs on top
697 fr.setBottom(fr.bottom() - 1); 697 fr.setBottom(fr.bottom() - 1);
698 698
699 p->setPen(g.dark()); 699 p->setPen(g.dark());
700 p->drawLine(fr.left(), fr.top() + 5, fr.left(), fr.bottom() - 1); 700 p->drawLine(fr.left(), fr.top() + 5, fr.left(), fr.bottom() - 1);
701 p->drawLine(fr.left(), fr.top() + 5, fr.left() + 5, fr.top()); 701 p->drawLine(fr.left(), fr.top() + 5, fr.left() + 5, fr.top());
702 p->drawLine(fr.left() + 5, fr.top(), fr.right() - 1, fr.top()); 702 p->drawLine(fr.left() + 5, fr.top(), fr.right() - 1, fr.top());
703 p->drawLine(fr.right(), fr.top() + 1, fr.right(), fr.bottom() - 1); 703 p->drawLine(fr.right(), fr.top() + 1, fr.right(), fr.bottom() - 1);
704 704
705 if (selected) { 705 if (selected) {
706 p->drawLine(fr.right(), fr.bottom(), fr.right() + 2, fr.bottom()); 706 p->drawLine(fr.right(), fr.bottom(), fr.right() + 2, fr.bottom());
707 p->drawPoint(fr.left(), fr.bottom()); 707 p->drawPoint(fr.left(), fr.bottom());
708 } else 708 } else
709 p->drawLine(fr.left(), fr.bottom(), fr.right() + 2, fr.bottom()); 709 p->drawLine(fr.left(), fr.bottom(), fr.right() + 2, fr.bottom());
710 710
711 if (fr.left() == 2) { 711 if (fr.left() == 2) {
712 p->drawPoint(fr.left() - 1, fr.bottom() + 1); 712 p->drawPoint(fr.left() - 1, fr.bottom() + 1);
713 p->drawPoint(fr.left() - 2, fr.bottom() + 2); 713 p->drawPoint(fr.left() - 2, fr.bottom() + 2);
714 } 714 }
715 715
716 if (selected) { 716 if (selected) {
717 p->setPen(g.mid()); 717 p->setPen(g.mid());
718 p->drawLine(fr.right() - 1, fr.top() + 1, fr.right() - 1, fr.bottom() - 2); 718 p->drawLine(fr.right() - 1, fr.top() + 1, fr.right() - 1, fr.bottom() - 2);
719 } 719 }
720 720
721 p->setPen(g.light()); p->setPen(red); 721 p->setPen(g.light()); p->setPen(red);
722 p->drawLine(fr.left() + 1, fr.top() + 6, fr.left() + 1, 722 p->drawLine(fr.left() + 1, fr.top() + 6, fr.left() + 1,
723 fr.bottom() - (selected ? 0 : 1)); 723 fr.bottom() - (selected ? 0 : 1));
724 p->drawLine(fr.left() + 1, fr.top() + 5, fr.left() + 5, fr.top() + 1); 724 p->drawLine(fr.left() + 1, fr.top() + 5, fr.left() + 5, fr.top() + 1);
725 p->drawLine(fr.left() + 6, fr.top() + 1, fr.right() - 3, fr.top() + 1); 725 p->drawLine(fr.left() + 6, fr.top() + 1, fr.right() - 3, fr.top() + 1);
726 if (selected) { 726 if (selected) {
727 p->drawLine(fr.right() + 1, fr.bottom() + 1, 727 p->drawLine(fr.right() + 1, fr.bottom() + 1,
728 fr.right() + 2, fr.bottom() + 1); 728 fr.right() + 2, fr.bottom() + 1);
729 p->drawLine(fr.left(), fr.bottom() + 1, fr.left() + 1, fr.bottom() + 1); 729 p->drawLine(fr.left(), fr.bottom() + 1, fr.left() + 1, fr.bottom() + 1);
730 } else 730 } else
731 p->drawLine(fr.left(), fr.bottom() + 1, 731 p->drawLine(fr.left(), fr.bottom() + 1,
732 fr.right() + 2, fr.bottom() + 1); 732 fr.right() + 2, fr.bottom() + 1);
733 } else if (tabbar->shape() == QTabBar::RoundedBelow) { 733 } else if (tabbar->shape() == QTabBar::RoundedBelow) {
734 // "rounded" tabs on bottom 734 // "rounded" tabs on bottom
735 fr.setTop(fr.top() + 1); 735 fr.setTop(fr.top() + 1);
736 736
737 p->setPen(g.dark()); 737 p->setPen(g.dark());
738 p->drawLine(fr.left(), fr.top(), fr.left(), fr.bottom() - 1); 738 p->drawLine(fr.left(), fr.top(), fr.left(), fr.bottom() - 1);
739 p->drawLine(fr.left() + 1, fr.bottom(), fr.right() - 1, fr.bottom()); 739 p->drawLine(fr.left() + 1, fr.bottom(), fr.right() - 1, fr.bottom());
740 p->drawLine(fr.right(), fr.top(), fr.right(), fr.bottom() - 1); 740 p->drawLine(fr.right(), fr.top(), fr.right(), fr.bottom() - 1);
741 741
742 if (! selected) 742 if (! selected)
743 p->drawLine(fr.left(), fr.top(), fr.right() + 3, fr.top()); 743 p->drawLine(fr.left(), fr.top(), fr.right() + 3, fr.top());
744 else 744 else
745 p->drawLine(fr.right(), fr.top(), fr.right() + 3, fr.top()); 745 p->drawLine(fr.right(), fr.top(), fr.right() + 3, fr.top());
746 746
747 p->setPen(g.mid()); 747 p->setPen(g.mid());
748 if (selected) 748 if (selected)
749 p->drawLine(fr.right() - 1, fr.top() + 1, fr.right() - 1, fr.bottom() - 1); 749 p->drawLine(fr.right() - 1, fr.top() + 1, fr.right() - 1, fr.bottom() - 1);
750 else 750 else
751 p->drawLine(fr.left(), fr.top() - 1, fr.right() + 3, fr.top() - 1); 751 p->drawLine(fr.left(), fr.top() - 1, fr.right() + 3, fr.top() - 1);
752 752
753 p->setPen(g.light()); 753 p->setPen(g.light());
754 p->drawLine(fr.left() + 1, fr.top() + (selected ? -1 : 2), 754 p->drawLine(fr.left() + 1, fr.top() + (selected ? -1 : 2),
755 fr.left() + 1, fr.bottom() - 1); 755 fr.left() + 1, fr.bottom() - 1);
756 756
757 } else { 757 } else {
758 // triangular drawing code 758 // triangular drawing code
759 QCommonStyle::drawTab(p, tabbar, tab, selected); 759 QCommonStyle::drawTab(p, tabbar, tab, selected);
760 } 760 }
761 761
762 p->restore(); 762 p->restore();
763} 763}
764#endif 764#endif
765 765
766void LightStyle::drawSlider(QPainter *p, int x, int y, int w, int h, 766void LightStyle::drawSlider(QPainter *p, int x, int y, int w, int h,
767 const QColorGroup &g, Qt::Orientation orientation, 767 const QColorGroup &g, Qt::Orientation orientation,
768 bool above, bool below) 768 bool above, bool below)
769{ 769{
770 drawButton(p, x, y, w, h, g, FALSE, &g.brush(QColorGroup::Button)); 770 drawButton(p, x, y, w, h, g, FALSE, &g.brush(QColorGroup::Button));
771 771
772 if (orientation == Horizontal) { 772 if (orientation == Horizontal) {
773 if (above && below) { 773 if (above && below) {
774 drawArrow(p, Qt::UpArrow, FALSE, x + 1, y + 1, w, h / 2, g, TRUE); 774 drawArrow(p, Qt::UpArrow, FALSE, x + 1, y + 1, w, h / 2, g, TRUE);
775 drawArrow(p, Qt::DownArrow, FALSE, x + 1, y + (h / 2) - 1, 775 drawArrow(p, Qt::DownArrow, FALSE, x + 1, y + (h / 2) - 1,
776 w, h / 2, g, TRUE); 776 w, h / 2, g, TRUE);
777 } else 777 } else
778 drawArrow(p, (above) ? Qt::UpArrow : Qt::DownArrow, 778 drawArrow(p, (above) ? Qt::UpArrow : Qt::DownArrow,
779 FALSE, x + 1, y, w, h, g, TRUE); 779 FALSE, x + 1, y, w, h, g, TRUE);
780 } else { 780 } else {
781 if (above && below) { 781 if (above && below) {
782 drawArrow(p, Qt::LeftArrow, FALSE, x + 1, y, w / 2, h, g, TRUE); 782 drawArrow(p, Qt::LeftArrow, FALSE, x + 1, y, w / 2, h, g, TRUE);
783 drawArrow(p, Qt::RightArrow, FALSE, x + (w / 2) - 2, y, w / 2, h, g, TRUE); 783 drawArrow(p, Qt::RightArrow, FALSE, x + (w / 2) - 2, y, w / 2, h, g, TRUE);
784 } else 784 } else
785 drawArrow(p, (above) ? Qt::LeftArrow : Qt::RightArrow, 785 drawArrow(p, (above) ? Qt::LeftArrow : Qt::RightArrow,
786 FALSE, x, y, w, h, g, TRUE); 786 FALSE, x, y, w, h, g, TRUE);
787 } 787 }
788} 788}
789 789
790 790
791void LightStyle::drawSliderGroove(QPainter *p, int x, int y, int w, int h, 791void LightStyle::drawSliderGroove(QPainter *p, int x, int y, int w, int h,
792 const QColorGroup& g, QCOORD c, 792 const QColorGroup& g, QCOORD c,
793 Qt::Orientation orientation) 793 Qt::Orientation orientation)
794{ 794{
795 if (orientation == Horizontal) 795 if (orientation == Horizontal)
796 drawButton(p, x, y+c - 3, w, 6, g, TRUE, &g.brush(QColorGroup::Mid)); 796 drawButton(p, x, y+c - 3, w, 6, g, TRUE, &g.brush(QColorGroup::Mid));
797 else 797 else
798 drawButton(p, x+c - 3, y, 6, h, g, TRUE, &g.brush(QColorGroup::Mid)); 798 drawButton(p, x+c - 3, y, 6, h, g, TRUE, &g.brush(QColorGroup::Mid));
799} 799}
800 800
801 801
802void LightStyle::scrollBarMetrics(const QScrollBar *scrollbar, 802void LightStyle::scrollBarMetrics(const QScrollBar *scrollbar,
803 int &sliderMin, int &sliderMax, 803 int &sliderMin, int &sliderMax,
804 int &sliderLength, int &buttonDim) const 804 int &sliderLength, int &buttonDim) const
805{ 805{
806 int maxLength; 806 int maxLength;
807 int length = ((scrollbar->orientation() == Horizontal) ? 807 int length = ((scrollbar->orientation() == Horizontal) ?
808 scrollbar->width() : scrollbar->height()); 808 scrollbar->width() : scrollbar->height());
809 int extent = ((scrollbar->orientation() == Horizontal) ? 809 int extent = ((scrollbar->orientation() == Horizontal) ?
810 scrollbar->height() : scrollbar->width()); 810 scrollbar->height() : scrollbar->width());
811 extent--; 811 extent--;
812 812
813 if (length > (extent + defaultFrameWidth() - 1) * 2 + defaultFrameWidth()) 813 if (length > (extent + defaultFrameWidth() - 1) * 2 + defaultFrameWidth())
814 buttonDim = extent - defaultFrameWidth(); 814 buttonDim = extent - defaultFrameWidth();
815 else 815 else
816 buttonDim = (length - defaultFrameWidth()) / 2 - 1; 816 buttonDim = (length - defaultFrameWidth()) / 2 - 1;
817 817
818 sliderMin = buttonDim; 818 sliderMin = buttonDim;
819 maxLength = length - buttonDim * 3; 819 maxLength = length - buttonDim * 3;
820 820
821 if (scrollbar->maxValue() != scrollbar->minValue()) { 821 if (scrollbar->maxValue() != scrollbar->minValue()) {
822 uint range = scrollbar->maxValue() - scrollbar->minValue(); 822 uint range = scrollbar->maxValue() - scrollbar->minValue();
823 sliderLength = (scrollbar->pageStep() * maxLength) / 823 sliderLength = (scrollbar->pageStep() * maxLength) /
824 (range + scrollbar->pageStep()); 824 (range + scrollbar->pageStep());
825 825
826 if (sliderLength < buttonDim || range > INT_MAX / 2) 826 if (sliderLength < buttonDim || range > INT_MAX / 2)
827 sliderLength = buttonDim; 827 sliderLength = buttonDim;
828 if (sliderLength > maxLength) 828 if (sliderLength > maxLength)
829 sliderLength = maxLength; 829 sliderLength = maxLength;
830 } else 830 } else
831 sliderLength = maxLength; 831 sliderLength = maxLength;
832 832
833 sliderMax = sliderMin + maxLength - sliderLength; 833 sliderMax = sliderMin + maxLength - sliderLength;
834} 834}
835 835
836 836
837QStyle::ScrollControl LightStyle::scrollBarPointOver(const QScrollBar *scrollbar, 837QStyle::ScrollControl LightStyle::scrollBarPointOver(const QScrollBar *scrollbar,
838 int sliderStart, const QPoint &p) 838 int sliderStart, const QPoint &p)
839{ 839{
840 if (! scrollbar->rect().contains(p)) 840 if (! scrollbar->rect().contains(p))
841 return NoScroll; 841 return NoScroll;
842 842
843 int sliderMin, sliderMax, sliderLength, buttonDim, pos; 843 int sliderMin, sliderMax, sliderLength, buttonDim, pos;
844 scrollBarMetrics( scrollbar, sliderMin, sliderMax, sliderLength, buttonDim ); 844 scrollBarMetrics( scrollbar, sliderMin, sliderMax, sliderLength, buttonDim );
845 845
846 if (scrollbar->orientation() == Horizontal) 846 if (scrollbar->orientation() == Horizontal)
847 pos = p.x(); 847 pos = p.x();
848 else 848 else
849 pos = p.y(); 849 pos = p.y();
850 850
851 if (pos < buttonDim) 851 if (pos < buttonDim)
852 return SubLine; 852 return SubLine;
853 if (pos < sliderStart) 853 if (pos < sliderStart)
854 return SubPage; 854 return SubPage;
855 if (pos < sliderStart + sliderLength) 855 if (pos < sliderStart + sliderLength)
856 return Slider; 856 return Slider;
857 if (pos < sliderMax + sliderLength) 857 if (pos < sliderMax + sliderLength)
858 return AddPage; 858 return AddPage;
859 if (pos < sliderMax + sliderLength + buttonDim) 859 if (pos < sliderMax + sliderLength + buttonDim)
860 return SubLine; 860 return SubLine;
861 return AddLine; 861 return AddLine;
862} 862}
863 863
864 864
865 865
866void LightStyle::drawScrollBarControls( QPainter* p, const QScrollBar* scrollbar, 866void LightStyle::drawScrollBarControls( QPainter* p, const QScrollBar* scrollbar,
867 int sliderStart, uint controls, 867 int sliderStart, uint controls,
868 uint activeControl ) 868 uint activeControl )
869{ 869{
870 QColorGroup g = scrollbar->colorGroup(); 870 QColorGroup g = scrollbar->colorGroup();
871 871
872 int sliderMin, sliderMax, sliderLength, buttonDim; 872 int sliderMin, sliderMax, sliderLength, buttonDim;
873 scrollBarMetrics( scrollbar, sliderMin, sliderMax, sliderLength, buttonDim ); 873 scrollBarMetrics( scrollbar, sliderMin, sliderMax, sliderLength, buttonDim );
874 874
875 if (sliderStart > sliderMax) { // sanity check 875 if (sliderStart > sliderMax) { // sanity check
876 sliderStart = sliderMax; 876 sliderStart = sliderMax;
877 } 877 }
878 878
879 QRect addR, subR, subR2, addPageR, subPageR, sliderR; 879 QRect addR, subR, subR2, addPageR, subPageR, sliderR;
880 int length = ((scrollbar->orientation() == Horizontal) ? 880 int length = ((scrollbar->orientation() == Horizontal) ?
881 scrollbar->width() : scrollbar->height()); 881 scrollbar->width() : scrollbar->height());
882 int extent = ((scrollbar->orientation() == Horizontal) ? 882 int extent = ((scrollbar->orientation() == Horizontal) ?
883 scrollbar->height() : scrollbar->width()); 883 scrollbar->height() : scrollbar->width());
884 884
885 885
886 int fudge = 3; //####disgusting hack 886 int fudge = 3; //####disgusting hack
887 887
888 if (scrollbar->orientation() == Horizontal) { 888 if (scrollbar->orientation() == Horizontal) {
889 subR.setRect(0, defaultFrameWidth(), 889 subR.setRect(0, defaultFrameWidth(),
890 buttonDim + fudge, buttonDim); 890 buttonDim + fudge, buttonDim);
891 subR2.setRect(length - (buttonDim * 2), defaultFrameWidth() , 891 subR2.setRect(length - (buttonDim * 2), defaultFrameWidth() ,
892 buttonDim, buttonDim); 892 buttonDim, buttonDim);
893 addR.setRect(length - buttonDim, defaultFrameWidth(), 893 addR.setRect(length - buttonDim, defaultFrameWidth(),
894 buttonDim, buttonDim); 894 buttonDim, buttonDim);
895 } else { 895 } else {
896 subR.setRect(defaultFrameWidth() + 1, 0, 896 subR.setRect(defaultFrameWidth() + 1, 0,
897 buttonDim, buttonDim + fudge); 897 buttonDim, buttonDim + fudge);
898 subR2.setRect(defaultFrameWidth() + 1, length - (buttonDim * 2), 898 subR2.setRect(defaultFrameWidth() + 1, length - (buttonDim * 2),
899 buttonDim, buttonDim); 899 buttonDim, buttonDim);
900 addR.setRect(defaultFrameWidth() + 1, length - buttonDim, 900 addR.setRect(defaultFrameWidth() + 1, length - buttonDim,
901 buttonDim, buttonDim); 901 buttonDim, buttonDim);
902 } 902 }
903 903
904 int sliderEnd = sliderStart + sliderLength; 904 int sliderEnd = sliderStart + sliderLength;
905 int sliderW = extent - defaultFrameWidth() - 1; 905 int sliderW = extent - defaultFrameWidth() - 1;
906 if (scrollbar->orientation() == Horizontal) { 906 if (scrollbar->orientation() == Horizontal) {
907 subPageR.setRect( subR.right() + 1, defaultFrameWidth(), 907 subPageR.setRect( subR.right() + 1, defaultFrameWidth(),
908 sliderStart - subR.right() - 1 , sliderW ); 908 sliderStart - subR.right() - 1 , sliderW );
909 addPageR.setRect( sliderEnd, defaultFrameWidth(), 909 addPageR.setRect( sliderEnd, defaultFrameWidth(),
910 subR2.left() - sliderEnd, sliderW ); 910 subR2.left() - sliderEnd, sliderW );
911 sliderR.setRect( sliderStart, defaultFrameWidth(), sliderLength, sliderW ); 911 sliderR.setRect( sliderStart, defaultFrameWidth(), sliderLength, sliderW );
912 } else { 912 } else {
913 subPageR.setRect( defaultFrameWidth(), subR.bottom() + 1, 913 subPageR.setRect( defaultFrameWidth(), subR.bottom() + 1,
914 sliderW, sliderStart - subR.bottom() - 1 ); 914 sliderW, sliderStart - subR.bottom() - 1 );
915 addPageR.setRect( defaultFrameWidth(), sliderEnd, 915 addPageR.setRect( defaultFrameWidth(), sliderEnd,
916 sliderW, subR2.top() - sliderEnd ); 916 sliderW, subR2.top() - sliderEnd );
917 sliderR .setRect( defaultFrameWidth(), sliderStart, 917 sliderR .setRect( defaultFrameWidth(), sliderStart,
918 sliderW, sliderLength ); 918 sliderW, sliderLength );
919 } 919 }
920 920
921 if ( controls == ( AddLine | SubLine | AddPage | SubPage | 921 if ( controls == ( AddLine | SubLine | AddPage | SubPage |
922 Slider | First | Last ) ) { 922 Slider | First | Last ) ) {
923 if (scrollbar->orientation() == Horizontal) 923 if (scrollbar->orientation() == Horizontal)
924 qDrawShadePanel(p, 0, 0, length, 2, g, TRUE, 1, 924 qDrawShadePanel(p, 0, 0, length, 2, g, TRUE, 1,
925 &g.brush(QColorGroup::Background)); 925 &g.brush(QColorGroup::Background));
926 else 926 else
927 qDrawShadePanel(p, 0, 0, 2, length, g, TRUE, 1, 927 qDrawShadePanel(p, 0, 0, 2, length, g, TRUE, 1,
928 &g.brush(QColorGroup::Background)); 928 &g.brush(QColorGroup::Background));
929 } 929 }
930 930
931 if ( controls & AddLine ) 931 if ( controls & AddLine )
932 drawArrow( p, (scrollbar->orientation() == Vertical) ? DownArrow : RightArrow, 932 drawArrow( p, (scrollbar->orientation() == Vertical) ? DownArrow : RightArrow,
933 FALSE, addR.x(), addR.y(), 933 FALSE, addR.x(), addR.y(),
934 addR.width(), addR.height(), 934 addR.width(), addR.height(),
935 (( activeControl == AddLine ) ? 935 (( activeControl == AddLine ) ?
936 singleton->hoverPalette.active() : g), 936 singleton->hoverPalette.active() : g),
937 TRUE, &g.brush(QColorGroup::Background)); 937 TRUE, &g.brush(QColorGroup::Background));
938 if ( controls & SubLine ) { 938 if ( controls & SubLine ) {
939 drawArrow( p, (scrollbar->orientation() == Vertical) ? UpArrow : LeftArrow, 939 drawArrow( p, (scrollbar->orientation() == Vertical) ? UpArrow : LeftArrow,
940 FALSE, subR.x(), subR.y(), 940 FALSE, subR.x(), subR.y(),
941 subR.width(), subR.height(), 941 subR.width(), subR.height(),
942 (( activeControl == SubLine ) ? 942 (( activeControl == SubLine ) ?
943 singleton->hoverPalette.active() : g), 943 singleton->hoverPalette.active() : g),
944 TRUE, &g.brush(QColorGroup::Background)); 944 TRUE, &g.brush(QColorGroup::Background));
945 drawArrow( p, (scrollbar->orientation() == Vertical) ? UpArrow : LeftArrow, 945 drawArrow( p, (scrollbar->orientation() == Vertical) ? UpArrow : LeftArrow,
946 FALSE, subR2.x(), subR2.y(), 946 FALSE, subR2.x(), subR2.y(),
947 subR2.width(), subR2.height(), 947 subR2.width(), subR2.height(),
948 (( activeControl == SubLine ) ? 948 (( activeControl == SubLine ) ?
949 singleton->hoverPalette.active() : g), 949 singleton->hoverPalette.active() : g),
950 TRUE, &g.brush(QColorGroup::Background)); 950 TRUE, &g.brush(QColorGroup::Background));
951 } 951 }
952 952
953 if ( controls & SubPage ) 953 if ( controls & SubPage )
954 p->fillRect( subPageR, 954 p->fillRect( subPageR,
955 ((activeControl == SubPage) ? 955 ((activeControl == SubPage) ?
956 g.brush( QColorGroup::Dark ) : 956 g.brush( QColorGroup::Dark ) :
957 g.brush( QColorGroup::Mid ))); 957 g.brush( QColorGroup::Mid )));
958 if ( controls & AddPage ) 958 if ( controls & AddPage )
959 p->fillRect( addPageR, 959 p->fillRect( addPageR,
960 ((activeControl == AddPage) ? 960 ((activeControl == AddPage) ?
961 g.brush( QColorGroup::Dark ) : 961 g.brush( QColorGroup::Dark ) :
962 g.brush( QColorGroup::Mid ))); 962 g.brush( QColorGroup::Mid )));
963 963
964 if ( controls & Slider ) { 964 if ( controls & Slider ) {
965 965
966 QPoint bo = p->brushOrigin(); 966 QPoint bo = p->brushOrigin();
967 p->setBrushOrigin(sliderR.topLeft()); 967 p->setBrushOrigin(sliderR.topLeft());
968 if ( sliderR.isValid() ) { 968 if ( sliderR.isValid() ) {
969 p->fillRect( sliderR.x(), sliderR.y(), 2, 2, 969 p->fillRect( sliderR.x(), sliderR.y(), 2, 2,
970 g.brush( QColorGroup::Mid )); 970 g.brush( QColorGroup::Mid ));
971 p->fillRect( sliderR.x() + sliderR.width() - 2, 971 p->fillRect( sliderR.x() + sliderR.width() - 2,
972 sliderR.y(), 2, 2, 972 sliderR.y(), 2, 2,
973 g.brush( QColorGroup::Mid )); 973 g.brush( QColorGroup::Mid ));
974 p->fillRect( sliderR.x() + sliderR.width() - 2, 974 p->fillRect( sliderR.x() + sliderR.width() - 2,
975 sliderR.y() + sliderR.height() - 2, 2, 2, 975 sliderR.y() + sliderR.height() - 2, 2, 2,
976 g.brush( QColorGroup::Mid )); 976 g.brush( QColorGroup::Mid ));
977 p->fillRect( sliderR.x(), 977 p->fillRect( sliderR.x(),
978 sliderR.y() + sliderR.height() - 2, 2, 2, 978 sliderR.y() + sliderR.height() - 2, 2, 2,
979 g.brush( QColorGroup::Mid )); 979 g.brush( QColorGroup::Mid ));
980 980
981 QColorGroup cg( g ); 981 QColorGroup cg( g );
982 cg.setBrush( QColorGroup::Background, g.brush( QColorGroup::Mid ) ); 982 cg.setBrush( QColorGroup::Background, g.brush( QColorGroup::Mid ) );
983 drawBevelButton( p, sliderR.x(), sliderR.y(), 983 drawBevelButton( p, sliderR.x(), sliderR.y(),
984 sliderR.width(), sliderR.height(), 984 sliderR.width(), sliderR.height(),
985 cg, FALSE, &g.brush( QColorGroup::Button ) ); 985 cg, FALSE, &g.brush( QColorGroup::Button ) );
986 } 986 }
987 987
988 p->setBrushOrigin(bo); 988 p->setBrushOrigin(bo);
989 } 989 }
990} 990}
991 991
992 992
993void LightStyle::drawToolBarHandle(QPainter *p, const QRect &rect, 993void LightStyle::drawToolBarHandle(QPainter *p, const QRect &rect,
994 Qt::Orientation orientation, 994 Qt::Orientation orientation,
995 bool, const QColorGroup &g, bool) 995 bool, const QColorGroup &g, bool)
996{ 996{
997 p->save(); 997 p->save();
998 p->setPen(g.mid()); 998 p->setPen(g.mid());
999 p->setBrush(g.brush(QColorGroup::Mid)); 999 p->setBrush(g.brush(QColorGroup::Mid));
1000 1000
1001 if (orientation == Qt::Horizontal) { 1001 if (orientation == Qt::Horizontal) {
1002 QRect l, r; 1002 QRect l, r;
1003 l.setRect(rect.x() + 1, rect.y() + 1, rect.width() - 5, rect.height() - 2); 1003 l.setRect(rect.x() + 1, rect.y() + 1, rect.width() - 5, rect.height() - 2);
1004 r.setRect(l.right() + 1, l.y(), 3, l.height()); 1004 r.setRect(l.right() + 1, l.y(), 3, l.height());
1005 1005
1006 p->drawRect(l); 1006 p->drawRect(l);
1007 qDrawShadePanel(p, r, g, FALSE); 1007 qDrawShadePanel(p, r, g, FALSE);
1008 } else { 1008 } else {
1009 QRect t, b; 1009 QRect t, b;
1010 t.setRect(rect.x() + 1, rect.y() + 1, rect.width() - 2, rect.height() - 5); 1010 t.setRect(rect.x() + 1, rect.y() + 1, rect.width() - 2, rect.height() - 5);
1011 b.setRect(t.x(), t.bottom() + 1, t.width(), 3); 1011 b.setRect(t.x(), t.bottom() + 1, t.width(), 3);
1012 1012
1013 p->drawRect(t); 1013 p->drawRect(t);
1014 qDrawShadePanel(p, b, g, FALSE); 1014 qDrawShadePanel(p, b, g, FALSE);
1015 } 1015 }
1016 1016
1017 p->restore(); 1017 p->restore();
1018} 1018}
1019 1019
1020 1020
1021bool LightStyle::eventFilter(QObject *object, QEvent *event) 1021bool LightStyle::eventFilter(QObject *object, QEvent *event)
1022{ 1022{
1023 switch(event->type()) { 1023 switch(event->type()) {
1024 case QEvent::Enter: 1024 case QEvent::Enter:
1025 { 1025 {
1026 if (! object->isWidgetType() || 1026 if (! object->isWidgetType() ||
1027 ! object->inherits("QPushButton")) 1027 ! object->inherits("QPushButton"))
1028 break; 1028 break;
1029 1029
1030 singleton->hoverWidget = (QWidget *) object; 1030 singleton->hoverWidget = (QWidget *) object;
1031 if (! singleton->hoverWidget->isEnabled()) { 1031 if (! singleton->hoverWidget->isEnabled()) {
1032 singleton->hoverWidget = 0; 1032 singleton->hoverWidget = 0;
1033 break; 1033 break;
1034 } 1034 }
1035 1035
1036 QPalette pal = singleton->hoverWidget->palette(); 1036 QPalette pal = singleton->hoverWidget->palette();
1037 if (singleton->hoverWidget->ownPalette()) 1037 if (singleton->hoverWidget->ownPalette())
1038 singleton->savePalette = new QPalette(pal); 1038 singleton->savePalette = new QPalette(pal);
1039 1039
1040 singleton->hoverWidget->setPalette(singleton->hoverPalette); 1040 singleton->hoverWidget->setPalette(singleton->hoverPalette);
1041 1041
1042 break; 1042 break;
1043 } 1043 }
1044 1044
1045 case QEvent::Leave: 1045 case QEvent::Leave:
1046 { 1046 {
1047 if (object != singleton->hoverWidget) 1047 if (object != singleton->hoverWidget)
1048 break; 1048 break;
1049 1049
1050 if (singleton->savePalette) { 1050 if (singleton->savePalette) {
1051 singleton->hoverWidget->setPalette(*(singleton->savePalette)); 1051 singleton->hoverWidget->setPalette(*(singleton->savePalette));
1052 delete singleton->savePalette; 1052 delete singleton->savePalette;
1053 singleton->savePalette = 0; 1053 singleton->savePalette = 0;
1054 } else 1054 } else
1055 singleton->hoverWidget->unsetPalette(); 1055 singleton->hoverWidget->unsetPalette();
1056 1056
1057 singleton->hoverWidget = 0; 1057 singleton->hoverWidget = 0;
1058 1058
1059 break; 1059 break;
1060 } 1060 }
1061 1061
1062 default: 1062 default:
1063 { 1063 {
1064 ; 1064 ;
1065 } 1065 }
1066 } 1066 }
1067 1067
1068 return QWindowsStyle::eventFilter(object, event); 1068 return QWindowsStyle::eventFilter(object, event);
1069} 1069}
1070 1070
1071 1071
1072 static const int motifItemFrame = 1;// menu item frame width 1072 static const int motifItemFrame = 1;// menu item frame width
1073 static const int motifSepHeight = 2;// separator item height 1073 static const int motifSepHeight = 2;// separator item height
1074 static const int motifItemHMargin = 1;// menu item hor text margin 1074 static const int motifItemHMargin = 1;// menu item hor text margin
1075 static const int motifItemVMargin = 2;// menu item ver text margin 1075 static const int motifItemVMargin = 2;// menu item ver text margin
1076 static const int motifArrowHMargin = 0;// arrow horizontal margin 1076 static const int motifArrowHMargin = 0;// arrow horizontal margin
1077 static const int motifTabSpacing = 12;// space between text and tab 1077 static const int motifTabSpacing = 12;// space between text and tab
1078 static const int motifCheckMarkHMargin = 1;// horiz. margins of check mark 1078 static const int motifCheckMarkHMargin = 1;// horiz. margins of check mark
1079 static const int windowsRightBorder= 8; // right border on windows 1079 static const int windowsRightBorder= 8; // right border on windows
1080static const int windowsCheckMarkWidth = 2; // checkmarks width on windows 1080static const int windowsCheckMarkWidth = 2; // checkmarks width on windows
1081 1081
1082/*! \reimp 1082/*! \reimp
1083*/ 1083*/
1084int LightStyle::extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem* mi, const QFontMetrics& /*fm*/ ) 1084int LightStyle::extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem* mi, const QFontMetrics& /*fm*/ )
1085{ 1085{
1086#ifndef QT_NO_MENUDATA 1086#ifndef QT_NO_MENUDATA
1087 int w = 2*motifItemHMargin + 2*motifItemFrame; // a little bit of border can never harm 1087 int w = 2*motifItemHMargin + 2*motifItemFrame; // a little bit of border can never harm
1088 1088
1089 if ( mi->isSeparator() ) 1089 if ( mi->isSeparator() )
1090 return 10; // arbitrary 1090 return 10; // arbitrary
1091 else if ( mi->pixmap() ) 1091 else if ( mi->pixmap() )
1092 w += mi->pixmap()->width();// pixmap only 1092 w += mi->pixmap()->width();// pixmap only
1093 1093
1094 if ( !mi->text().isNull() ) { 1094 if ( !mi->text().isNull() ) {
1095 if ( mi->text().find('\t') >= 0 )// string contains tab 1095 if ( mi->text().find('\t') >= 0 )// string contains tab
1096 w += motifTabSpacing; 1096 w += motifTabSpacing;
1097 } 1097 }
1098 1098
1099 if ( maxpmw ) { // we have iconsets 1099 if ( maxpmw ) { // we have iconsets
1100 w += maxpmw; 1100 w += maxpmw;
1101 w += 6; // add a little extra border around the iconset 1101 w += 6; // add a little extra border around the iconset
1102 } 1102 }
1103 1103
1104 if ( checkable && maxpmw < windowsCheckMarkWidth ) { 1104 if ( checkable && maxpmw < windowsCheckMarkWidth ) {
1105 w += windowsCheckMarkWidth - maxpmw; // space for the checkmarks 1105 w += windowsCheckMarkWidth - maxpmw; // space for the checkmarks
1106 } 1106 }
1107 1107
1108 if ( maxpmw > 0 || checkable ) // we have a check-column ( iconsets or checkmarks) 1108 if ( maxpmw > 0 || checkable ) // we have a check-column ( iconsets or checkmarks)
1109 w += motifCheckMarkHMargin; // add space to separate the columns 1109 w += motifCheckMarkHMargin; // add space to separate the columns
1110 1110
1111 w += windowsRightBorder; // windows has a strange wide border on the right side 1111 w += windowsRightBorder; // windows has a strange wide border on the right side
1112 1112
1113 return w; 1113 return w;
1114#endif 1114#endif
1115} 1115}
1116 1116
1117/*! \reimp 1117/*! \reimp
1118*/ 1118*/
1119int LightStyle::popupMenuItemHeight( bool /*checkable*/, QMenuItem* mi, const QFontMetrics& fm ) 1119int LightStyle::popupMenuItemHeight( bool /*checkable*/, QMenuItem* mi, const QFontMetrics& fm )
1120{ 1120{
1121#ifndef QT_NO_MENUDATA 1121#ifndef QT_NO_MENUDATA
1122 int h = 0; 1122 int h = 0;
1123 if ( mi->isSeparator() ) // separator height 1123 if ( mi->isSeparator() ) // separator height
1124 h = motifSepHeight; 1124 h = motifSepHeight;
1125 else if ( mi->pixmap() ) // pixmap height 1125 else if ( mi->pixmap() ) // pixmap height
1126 h = mi->pixmap()->height() + 2*motifItemFrame; 1126 h = mi->pixmap()->height() + 2*motifItemFrame;
1127 else // text height 1127 else // text height
1128 h = fm.height() + 2*motifItemVMargin + 2*motifItemFrame; 1128 h = fm.height() + 2*motifItemVMargin + 2*motifItemFrame;
1129 1129
1130 if ( !mi->isSeparator() && mi->iconSet() != 0 ) { 1130 if ( !mi->isSeparator() && mi->iconSet() != 0 ) {
1131 h = QMAX( h, mi->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height() + 2*motifItemFrame ); 1131 h = QMAX( h, mi->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height() + 2*motifItemFrame );
1132 } 1132 }
1133 if ( mi->custom() ) 1133 if ( mi->custom() )
1134 h = QMAX( h, mi->custom()->sizeHint().height() + 2*motifItemVMargin + 2*motifItemFrame ) - 1; 1134 h = QMAX( h, mi->custom()->sizeHint().height() + 2*motifItemVMargin + 2*motifItemFrame ) - 1;
1135 return h; 1135 return h;
1136#endif 1136#endif
1137} 1137}
1138 1138
1139void LightStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi, 1139void LightStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi,
1140 const QPalette& pal, 1140 const QPalette& pal,
1141 bool act, bool enabled, int x, int y, int w, int h) 1141 bool act, bool enabled, int x, int y, int w, int h)
1142{ 1142{
1143#ifndef QT_NO_MENUDATA 1143#ifndef QT_NO_MENUDATA
1144 const QColorGroup & g = pal.active(); 1144 const QColorGroup & g = pal.active();
1145 bool dis = !enabled; 1145 bool dis = !enabled;
1146 QColorGroup itemg = dis ? pal.disabled() : pal.active(); 1146 QColorGroup itemg = dis ? pal.disabled() : pal.active();
1147 1147
1148 if ( checkable ) 1148 if ( checkable )
1149 maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks 1149 maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks
1150 1150
1151 int checkcol = maxpmw; 1151 int checkcol = maxpmw;
1152 1152
1153 if ( mi && mi->isSeparator() ) { // draw separator 1153 if ( mi && mi->isSeparator() ) { // draw separator
1154 p->setPen( g.dark() ); 1154 p->setPen( g.dark() );
1155 p->drawLine( x, y, x+w, y ); 1155 p->drawLine( x, y, x+w, y );
1156 p->setPen( g.light() ); 1156 p->setPen( g.light() );
1157 p->drawLine( x, y+1, x+w, y+1 ); 1157 p->drawLine( x, y+1, x+w, y+1 );
1158 return; 1158 return;
1159 } 1159 }
1160 1160
1161 QBrush fill = act? g.brush( QColorGroup::Highlight ) : 1161 QBrush fill = act? g.brush( QColorGroup::Highlight ) :
1162 g.brush( QColorGroup::Button ); 1162 g.brush( QColorGroup::Button );
1163 p->fillRect( x, y, w, h, fill); 1163 p->fillRect( x, y, w, h, fill);
1164 1164
1165 if ( !mi ) 1165 if ( !mi )
1166 return; 1166 return;
1167 1167
1168 if ( mi->isChecked() ) { 1168 if ( mi->isChecked() ) {
1169 if ( act && !dis ) { 1169 if ( act && !dis ) {
1170 qDrawShadePanel( p, x, y, checkcol, h, 1170 qDrawShadePanel( p, x, y, checkcol, h,
1171 g, TRUE, 1, &g.brush( QColorGroup::Button ) ); 1171 g, TRUE, 1, &g.brush( QColorGroup::Button ) );
1172 } else { 1172 } else {
1173 qDrawShadePanel( p, x, y, checkcol, h, 1173 qDrawShadePanel( p, x, y, checkcol, h,
1174 g, TRUE, 1, &g.brush( QColorGroup::Midlight ) ); 1174 g, TRUE, 1, &g.brush( QColorGroup::Midlight ) );
1175 } 1175 }
1176 } else if ( !act ) { 1176 } else if ( !act ) {
1177 p->fillRect(x, y, checkcol , h, 1177 p->fillRect(x, y, checkcol , h,
1178 g.brush( QColorGroup::Button )); 1178 g.brush( QColorGroup::Button ));
1179 } 1179 }
1180 1180
1181 if ( mi->iconSet() ) { // draw iconset 1181 if ( mi->iconSet() ) { // draw iconset
1182 QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal; 1182 QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal;
1183 if (act && !dis ) 1183 if (act && !dis )
1184 mode = QIconSet::Active; 1184 mode = QIconSet::Active;
1185 QPixmap pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode ); 1185 QPixmap pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
1186 int pixw = pixmap.width(); 1186 int pixw = pixmap.width();
1187 int pixh = pixmap.height(); 1187 int pixh = pixmap.height();
1188 if ( act && !dis ) { 1188 if ( act && !dis ) {
1189 if ( !mi->isChecked() ) 1189 if ( !mi->isChecked() )
1190 qDrawShadePanel( p, x, y, checkcol, h, g, FALSE, 1, &g.brush( QColorGroup::Button ) ); 1190 qDrawShadePanel( p, x, y, checkcol, h, g, FALSE, 1, &g.brush( QColorGroup::Button ) );
1191 } 1191 }
1192 QRect cr( x, y, checkcol, h ); 1192 QRect cr( x, y, checkcol, h );
1193 QRect pmr( 0, 0, pixw, pixh ); 1193 QRect pmr( 0, 0, pixw, pixh );
1194 pmr.moveCenter( cr.center() ); 1194 pmr.moveCenter( cr.center() );
1195 p->setPen( itemg.text() ); 1195 p->setPen( itemg.text() );
1196 p->drawPixmap( pmr.topLeft(), pixmap ); 1196 p->drawPixmap( pmr.topLeft(), pixmap );
1197 1197
1198 QBrush fill = act? g.brush( QColorGroup::Highlight ) : 1198 QBrush fill = act? g.brush( QColorGroup::Highlight ) :
1199 g.brush( QColorGroup::Button ); 1199 g.brush( QColorGroup::Button );
1200 p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill); 1200 p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill);
1201 } else if ( checkable ) {// just "checking"... 1201 } else if ( checkable ) {// just "checking"...
1202 int mw = checkcol + motifItemFrame; 1202 int mw = checkcol + motifItemFrame;
1203 int mh = h - 2*motifItemFrame; 1203 int mh = h - 2*motifItemFrame;
1204 if ( mi->isChecked() ) { 1204 if ( mi->isChecked() ) {
1205 drawCheckMark( p, x + motifItemFrame + 2, 1205 drawCheckMark( p, x + motifItemFrame + 2,
1206 y+motifItemFrame, mw, mh, itemg, act, dis ); 1206 y+motifItemFrame, mw, mh, itemg, act, dis );
1207 } 1207 }
1208 } 1208 }
1209 1209
1210 p->setPen( act ? g.highlightedText() : g.buttonText() ); 1210 p->setPen( act ? g.highlightedText() : g.buttonText() );
1211 1211
1212 QColor discol; 1212 QColor discol;
1213 if ( dis ) { 1213 if ( dis ) {
1214 discol = itemg.text(); 1214 discol = itemg.text();
1215 p->setPen( discol ); 1215 p->setPen( discol );
1216 } 1216 }
1217 1217
1218 int xm = motifItemFrame + checkcol + motifItemHMargin; 1218 int xm = motifItemFrame + checkcol + motifItemHMargin;
1219 1219
1220 if ( mi->custom() ) { 1220 if ( mi->custom() ) {
1221 int m = motifItemVMargin; 1221 int m = motifItemVMargin;
1222 p->save(); 1222 p->save();
1223 if ( dis && !act ) { 1223 if ( dis && !act ) {
1224 p->setPen( g.light() ); 1224 p->setPen( g.light() );
1225 mi->custom()->paint( p, itemg, act, enabled, 1225 mi->custom()->paint( p, itemg, act, enabled,
1226 x+xm+1, y+m+1, w-xm-tab+1, h-2*m ); 1226 x+xm+1, y+m+1, w-xm-tab+1, h-2*m );
1227 p->setPen( discol ); 1227 p->setPen( discol );
1228 } 1228 }
1229 mi->custom()->paint( p, itemg, act, enabled, 1229 mi->custom()->paint( p, itemg, act, enabled,
1230 x+xm, y+m, w-xm-tab+1, h-2*m ); 1230 x+xm, y+m, w-xm-tab+1, h-2*m );
1231 p->restore(); 1231 p->restore();
1232 } 1232 }
1233 QString s = mi->text(); 1233 QString s = mi->text();
1234 if ( !s.isNull() ) { // draw text 1234 if ( !s.isNull() ) { // draw text
1235 int t = s.find( '\t' ); 1235 int t = s.find( '\t' );
1236 int m = motifItemVMargin; 1236 int m = motifItemVMargin;
1237 const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine; 1237 const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
1238 if ( t >= 0 ) { // draw tab text 1238 if ( t >= 0 ) { // draw tab text
1239 if ( dis && !act ) { 1239 if ( dis && !act ) {
1240 p->setPen( g.light() ); 1240 p->setPen( g.light() );
1241 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1, 1241 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1,
1242 y+m+1, tab, h-2*m, text_flags, s.mid( t+1 )); 1242 y+m+1, tab, h-2*m, text_flags, s.mid( t+1 ));
1243 p->setPen( discol ); 1243 p->setPen( discol );
1244 } 1244 }
1245 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame, 1245 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame,
1246 y+m, tab, h-2*m, text_flags, s.mid( t+1 ) ); 1246 y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
1247 } 1247 }
1248 if ( dis && !act ) { 1248 if ( dis && !act ) {
1249 p->setPen( g.light() ); 1249 p->setPen( g.light() );
1250 p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t ); 1250 p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t );
1251 p->setPen( discol ); 1251 p->setPen( discol );
1252 } 1252 }
1253 p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t ); 1253 p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t );
1254 } else if ( mi->pixmap() ) { // draw pixmap 1254 } else if ( mi->pixmap() ) { // draw pixmap
1255 QPixmap *pixmap = mi->pixmap(); 1255 QPixmap *pixmap = mi->pixmap();
1256 if ( pixmap->depth() == 1 ) 1256 if ( pixmap->depth() == 1 )
1257 p->setBackgroundMode( OpaqueMode ); 1257 p->setBackgroundMode( OpaqueMode );
1258 p->drawPixmap( x+xm, y+motifItemFrame, *pixmap ); 1258 p->drawPixmap( x+xm, y+motifItemFrame, *pixmap );
1259 if ( pixmap->depth() == 1 ) 1259 if ( pixmap->depth() == 1 )
1260 p->setBackgroundMode( TransparentMode ); 1260 p->setBackgroundMode( TransparentMode );
1261 } 1261 }
1262 if ( mi->popup() ) { // draw sub menu arrow 1262 if ( mi->popup() ) { // draw sub menu arrow
1263 int dim = (h-2*motifItemFrame) / 2; 1263 int dim = (h-2*motifItemFrame) / 2;
1264 if ( act ) { 1264 if ( act ) {
1265 if ( !dis ) 1265 if ( !dis )
1266 discol = white; 1266 discol = white;
1267 QColorGroup g2( discol, g.highlight(), 1267 QColorGroup g2( discol, g.highlight(),
1268 white, white, 1268 white, white,
1269 dis ? discol : white, 1269 dis ? discol : white,
1270 discol, white ); 1270 discol, white );
1271 drawArrow( p, RightArrow, FALSE, 1271 drawArrow( p, RightArrow, FALSE,
1272 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2, 1272 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2,
1273 dim, dim, g2, TRUE ); 1273 dim, dim, g2, TRUE );
1274 } else { 1274 } else {
1275 drawArrow( p, RightArrow, 1275 drawArrow( p, RightArrow,
1276 FALSE, 1276 FALSE,
1277 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2, 1277 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2,
1278 dim, dim, g, mi->isEnabled() ); 1278 dim, dim, g, mi->isEnabled() );
1279 } 1279 }
1280 } 1280 }
1281#endif 1281#endif
1282} 1282}
1283 1283
1284#endif 1284#endif
diff --git a/library/lightstyle.h b/library/lightstyle.h
index c377cc2..0392957 100644
--- a/library/lightstyle.h
+++ b/library/lightstyle.h
@@ -1,120 +1,120 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef LIGHTSTYLE_H 20#ifndef LIGHTSTYLE_H
21#define LIGHTSTYLE_H 21#define LIGHTSTYLE_H
22 22
23 23
24#ifndef QT_H 24#ifndef QT_H
25#include <qstyle.h> 25#include <qstyle.h>
26#include <qwindowsstyle.h> 26#include <qwindowsstyle.h>
27#endif // QT_H 27#endif // QT_H
28 28
29#if QT_VERSION < 300 29#if QT_VERSION < 0x030000
30 30
31#ifdef QT_PLUGIN_STYLE_LIGHT 31#ifdef QT_PLUGIN_STYLE_LIGHT
32# define Q_EXPORT_STYLE_LIGHT 32# define Q_EXPORT_STYLE_LIGHT
33#else 33#else
34# define Q_EXPORT_STYLE_LIGHT Q_EXPORT 34# define Q_EXPORT_STYLE_LIGHT Q_EXPORT
35#endif // QT_PLUGIN_STYLE_LIGHT 35#endif // QT_PLUGIN_STYLE_LIGHT
36 36
37 37
38class Q_EXPORT_STYLE_LIGHT LightStyle : public QWindowsStyle 38class Q_EXPORT_STYLE_LIGHT LightStyle : public QWindowsStyle
39{ 39{
40public: 40public:
41 LightStyle(); 41 LightStyle();
42 virtual ~LightStyle(); 42 virtual ~LightStyle();
43 43
44 void polish(QWidget *widget); 44 void polish(QWidget *widget);
45 void unPolish(QWidget*widget); 45 void unPolish(QWidget*widget);
46 46
47 void polish(QApplication *app); 47 void polish(QApplication *app);
48 void unPolish(QApplication *app); 48 void unPolish(QApplication *app);
49 49
50 void polishPopupMenu(QPopupMenu *menu); 50 void polishPopupMenu(QPopupMenu *menu);
51 51
52 void drawPushButton(QPushButton *button, QPainter *p); 52 void drawPushButton(QPushButton *button, QPainter *p);
53 void drawButton(QPainter *p, int x, int y, int w, int h, 53 void drawButton(QPainter *p, int x, int y, int w, int h,
54 const QColorGroup &g, bool sunken = FALSE, 54 const QColorGroup &g, bool sunken = FALSE,
55 const QBrush *fill = 0); 55 const QBrush *fill = 0);
56 void drawBevelButton(QPainter *p, int x, int y, int w, int h, 56 void drawBevelButton(QPainter *p, int x, int y, int w, int h,
57 const QColorGroup &g, bool sunken = FALSE, 57 const QColorGroup &g, bool sunken = FALSE,
58 const QBrush *fill = 0); 58 const QBrush *fill = 0);
59 void getButtonShift(int &x, int &y) const; 59 void getButtonShift(int &x, int &y) const;
60 60
61 void drawComboButton(QPainter *p, int x, int y, int w, int h, 61 void drawComboButton(QPainter *p, int x, int y, int w, int h,
62 const QColorGroup &g, bool sunken = FALSE, 62 const QColorGroup &g, bool sunken = FALSE,
63 bool editable = FALSE, bool = TRUE, 63 bool editable = FALSE, bool = TRUE,
64 const QBrush *fill = 0); 64 const QBrush *fill = 0);
65 QRect comboButtonRect(int x, int y, int w, int h) const; 65 QRect comboButtonRect(int x, int y, int w, int h) const;
66 QRect comboButtonFocusRect(int x, int y, int w, int h) const; 66 QRect comboButtonFocusRect(int x, int y, int w, int h) const;
67 67
68 void drawIndicator(QPainter *p, int x, int y ,int w, int h, 68 void drawIndicator(QPainter *p, int x, int y ,int w, int h,
69 const QColorGroup &g, int state, 69 const QColorGroup &g, int state,
70 bool = FALSE, bool = TRUE); 70 bool = FALSE, bool = TRUE);
71 QSize indicatorSize() const; 71 QSize indicatorSize() const;
72 72
73 void drawExclusiveIndicator(QPainter *p, int x, int y ,int w, int h, 73 void drawExclusiveIndicator(QPainter *p, int x, int y ,int w, int h,
74 const QColorGroup &g, bool on, 74 const QColorGroup &g, bool on,
75 bool = FALSE, bool = TRUE); 75 bool = FALSE, bool = TRUE);
76 QSize exclusiveIndicatorSize() const; 76 QSize exclusiveIndicatorSize() const;
77 77
78 void drawPanel(QPainter * p, int x, int y, int w, int h, 78 void drawPanel(QPainter * p, int x, int y, int w, int h,
79 const QColorGroup &g, bool sunken = FALSE, 79 const QColorGroup &g, bool sunken = FALSE,
80 int = 1, const QBrush * = 0); 80 int = 1, const QBrush * = 0);
81 81
82 void scrollBarMetrics( const QScrollBar *, 82 void scrollBarMetrics( const QScrollBar *,
83 int &, int &, int &, int & ) const; 83 int &, int &, int &, int & ) const;
84 void drawScrollBarControls(QPainter* p, const QScrollBar* sb, 84 void drawScrollBarControls(QPainter* p, const QScrollBar* sb,
85 int sliderStart, uint controls, 85 int sliderStart, uint controls,
86 uint activeControl); 86 uint activeControl);
87 QStyle::ScrollControl scrollBarPointOver(const QScrollBar *, int, const QPoint& p); 87 QStyle::ScrollControl scrollBarPointOver(const QScrollBar *, int, const QPoint& p);
88 88
89 void drawTab(QPainter *p, const QTabBar *tabbar, QTab *tab, bool selected); 89 void drawTab(QPainter *p, const QTabBar *tabbar, QTab *tab, bool selected);
90 90
91 void drawSlider(QPainter *p, int x, int y, int w, int h, 91 void drawSlider(QPainter *p, int x, int y, int w, int h,
92 const QColorGroup &g, Qt::Orientation orientation, 92 const QColorGroup &g, Qt::Orientation orientation,
93 bool, bool); 93 bool, bool);
94 void drawSliderGroove(QPainter *p, int x, int y, int w, int h, 94 void drawSliderGroove(QPainter *p, int x, int y, int w, int h,
95 const QColorGroup& g, QCOORD, 95 const QColorGroup& g, QCOORD,
96 Qt::Orientation ); 96 Qt::Orientation );
97 97
98 void drawToolBarHandle(QPainter *, const QRect &, Qt::Orientation, 98 void drawToolBarHandle(QPainter *, const QRect &, Qt::Orientation,
99 bool, const QColorGroup &, bool = FALSE ); 99 bool, const QColorGroup &, bool = FALSE );
100 100
101 QSize scrollBarExtent() const; 101 QSize scrollBarExtent() const;
102 int buttonDefaultIndicatorWidth() const; 102 int buttonDefaultIndicatorWidth() const;
103 int buttonMargin() const; 103 int buttonMargin() const;
104 int sliderThickness() const; 104 int sliderThickness() const;
105 int sliderLength() const; 105 int sliderLength() const;
106 int defaultFrameWidth() const; 106 int defaultFrameWidth() const;
107 107
108 int extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem*, const QFontMetrics& ); 108 int extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem*, const QFontMetrics& );
109 int popupMenuItemHeight( bool checkable, QMenuItem*, const QFontMetrics& ); 109 int popupMenuItemHeight( bool checkable, QMenuItem*, const QFontMetrics& );
110 void drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi, 110 void drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi,
111 const QPalette& pal, 111 const QPalette& pal,
112 bool act, bool enabled, int x, int y, int w, int h); 112 bool act, bool enabled, int x, int y, int w, int h);
113 113
114protected: 114protected:
115 bool eventFilter(QObject *, QEvent *); 115 bool eventFilter(QObject *, QEvent *);
116}; 116};
117 117
118#endif 118#endif
119 119
120#endif // LIGHTSTYLE_H 120#endif // LIGHTSTYLE_H
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index af00f49..1c5ced3 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -1,2322 +1,2322 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19*/ 19*/
20#define QTOPIA_INTERNAL_LANGLIST 20#define QTOPIA_INTERNAL_LANGLIST
21#include <stdlib.h> 21#include <stdlib.h>
22#include <unistd.h> 22#include <unistd.h>
23#ifndef Q_OS_MACX 23#ifndef Q_OS_MACX
24#include <linux/limits.h> // needed for some toolchains (PATH_MAX) 24#include <linux/limits.h> // needed for some toolchains (PATH_MAX)
25#endif 25#endif
26#include <qfile.h> 26#include <qfile.h>
27#include <qqueue.h> 27#include <qqueue.h>
28#ifdef Q_WS_QWS 28#ifdef Q_WS_QWS
29#ifndef QT_NO_COP 29#ifndef QT_NO_COP
30#if QT_VERSION <= 231 30#if QT_VERSION <= 231
31#define private public 31#define private public
32#define sendLocally processEvent 32#define sendLocally processEvent
33#include "qcopenvelope_qws.h" 33#include "qcopenvelope_qws.h"
34#undef private 34#undef private
35#else 35#else
36#include "qcopenvelope_qws.h" 36#include "qcopenvelope_qws.h"
37#endif 37#endif
38#endif 38#endif
39#include <qwindowsystem_qws.h> 39#include <qwindowsystem_qws.h>
40#endif 40#endif
41#include <qtextstream.h> 41#include <qtextstream.h>
42#include <qpalette.h> 42#include <qpalette.h>
43#include <qbuffer.h> 43#include <qbuffer.h>
44#include <qptrdict.h> 44#include <qptrdict.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qdir.h> 46#include <qdir.h>
47#include <qlabel.h> 47#include <qlabel.h>
48#include <qdialog.h> 48#include <qdialog.h>
49#include <qdragobject.h> 49#include <qdragobject.h>
50#include <qtextcodec.h> 50#include <qtextcodec.h>
51#include <qevent.h> 51#include <qevent.h>
52#include <qtooltip.h> 52#include <qtooltip.h>
53#include <qsignal.h> 53#include <qsignal.h>
54#include <qmainwindow.h> 54#include <qmainwindow.h>
55#include <qwidgetlist.h> 55#include <qwidgetlist.h>
56#include <qpixmapcache.h> 56#include <qpixmapcache.h>
57 57
58#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 58#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
59#define QTOPIA_INTERNAL_INITAPP 59#define QTOPIA_INTERNAL_INITAPP
60#include "qpeapplication.h" 60#include "qpeapplication.h"
61#include "qpestyle.h" 61#include "qpestyle.h"
62#include "styleinterface.h" 62#include "styleinterface.h"
63#if QT_VERSION >= 300 63#if QT_VERSION >= 0x030000
64#include <qstylefactory.h> 64#include <qstylefactory.h>
65#else 65#else
66#include <qplatinumstyle.h> 66#include <qplatinumstyle.h>
67#include <qwindowsstyle.h> 67#include <qwindowsstyle.h>
68#include <qmotifstyle.h> 68#include <qmotifstyle.h>
69#include <qmotifplusstyle.h> 69#include <qmotifplusstyle.h>
70#include "lightstyle.h" 70#include "lightstyle.h"
71 71
72#include <qpe/qlibrary.h> 72#include <qpe/qlibrary.h>
73#endif 73#endif
74#include "global.h" 74#include "global.h"
75#include "resource.h" 75#include "resource.h"
76#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 76#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
77#include "qutfcodec.h" 77#include "qutfcodec.h"
78#endif 78#endif
79#include "config.h" 79#include "config.h"
80#include "network.h" 80#include "network.h"
81#ifdef QWS 81#ifdef QWS
82#include "fontmanager.h" 82#include "fontmanager.h"
83#include "fontdatabase.h" 83#include "fontdatabase.h"
84#endif 84#endif
85 85
86#include "alarmserver.h" 86#include "alarmserver.h"
87#include "applnk.h" 87#include "applnk.h"
88#include "qpemenubar.h" 88#include "qpemenubar.h"
89#include "textcodecinterface.h" 89#include "textcodecinterface.h"
90#include "imagecodecinterface.h" 90#include "imagecodecinterface.h"
91#include <qtopia/qpeglobal.h> 91#include <qtopia/qpeglobal.h>
92 92
93#include <unistd.h> 93#include <unistd.h>
94#include <sys/file.h> 94#include <sys/file.h>
95#include <sys/ioctl.h> 95#include <sys/ioctl.h>
96#ifndef QT_NO_SOUND 96#ifndef QT_NO_SOUND
97#include <sys/soundcard.h> 97#include <sys/soundcard.h>
98#endif 98#endif
99#include "qt_override_p.h" 99#include "qt_override_p.h"
100 100
101#include <backend/rohfeedback.h> 101#include <backend/rohfeedback.h>
102 102
103 103
104static bool useBigPixmaps = 0; 104static bool useBigPixmaps = 0;
105 105
106class HackWidget : public QWidget 106class HackWidget : public QWidget
107{ 107{
108public: 108public:
109 bool needsOk() 109 bool needsOk()
110 { return (getWState() & WState_Reserved1 ); } 110 { return (getWState() & WState_Reserved1 ); }
111 111
112 QRect normalGeometry() 112 QRect normalGeometry()
113 { return topData()->normalGeometry; }; 113 { return topData()->normalGeometry; };
114}; 114};
115 115
116class QPEApplicationData 116class QPEApplicationData
117{ 117{
118public: 118public:
119 QPEApplicationData ( ) : 119 QPEApplicationData ( ) :
120 presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), 120 presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ),
121 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), 121 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ),
122 keep_running( true ), qcopQok( false ), 122 keep_running( true ), qcopQok( false ),
123 fontFamily( "Vera" ), fontSize( 10 ), smallIconSize( 14 ), 123 fontFamily( "Vera" ), fontSize( 10 ), smallIconSize( 14 ),
124 bigIconSize( 32 ), qpe_main_widget( 0 ) 124 bigIconSize( 32 ), qpe_main_widget( 0 )
125 { 125 {
126 Config cfg( "qpe" ); 126 Config cfg( "qpe" );
127 cfg.setGroup( "Appearance" ); 127 cfg.setGroup( "Appearance" );
128 useBigPixmaps = cfg.readBoolEntry( "useBigPixmaps", false ); 128 useBigPixmaps = cfg.readBoolEntry( "useBigPixmaps", false );
129 fontFamily = cfg.readEntry( "FontFamily", "Vera" ); 129 fontFamily = cfg.readEntry( "FontFamily", "Vera" );
130 fontSize = cfg.readNumEntry( "FontSize", 10 ); 130 fontSize = cfg.readNumEntry( "FontSize", 10 );
131 smallIconSize = cfg.readNumEntry( "SmallIconSize", 14 ); 131 smallIconSize = cfg.readNumEntry( "SmallIconSize", 14 );
132 bigIconSize = cfg.readNumEntry( "BigIconSize", 32 ); 132 bigIconSize = cfg.readNumEntry( "BigIconSize", 32 );
133#ifdef OPIE_WITHROHFEEDBACK 133#ifdef OPIE_WITHROHFEEDBACK
134 RoH = 0; 134 RoH = 0;
135#endif 135#endif
136 } 136 }
137 137
138 int presstimer; 138 int presstimer;
139 QWidget* presswidget; 139 QWidget* presswidget;
140 QPoint presspos; 140 QPoint presspos;
141#ifdef OPIE_WITHROHFEEDBACK 141#ifdef OPIE_WITHROHFEEDBACK
142 Opie::Internal::RoHFeedback *RoH; 142 Opie::Internal::RoHFeedback *RoH;
143#endif 143#endif
144 144
145 bool rightpressed : 1; 145 bool rightpressed : 1;
146 bool kbgrabbed : 1; 146 bool kbgrabbed : 1;
147 bool notbusysent : 1; 147 bool notbusysent : 1;
148 bool preloaded : 1; 148 bool preloaded : 1;
149 bool forceshow : 1; 149 bool forceshow : 1;
150 bool nomaximize : 1; 150 bool nomaximize : 1;
151 bool keep_running : 1; 151 bool keep_running : 1;
152 bool qcopQok : 1; 152 bool qcopQok : 1;
153 153
154 QCString fontFamily; 154 QCString fontFamily;
155 int fontSize; 155 int fontSize;
156 int smallIconSize; 156 int smallIconSize;
157 int bigIconSize; 157 int bigIconSize;
158 158
159 QString appName; 159 QString appName;
160 struct QCopRec 160 struct QCopRec
161 { 161 {
162 QCopRec( const QCString &ch, const QCString &msg, 162 QCopRec( const QCString &ch, const QCString &msg,
163 const QByteArray &d ) : 163 const QByteArray &d ) :
164 channel( ch ), message( msg ), data( d ) 164 channel( ch ), message( msg ), data( d )
165 { } 165 { }
166 166
167 QCString channel; 167 QCString channel;
168 QCString message; 168 QCString message;
169 QByteArray data; 169 QByteArray data;
170 }; 170 };
171 QWidget* qpe_main_widget; 171 QWidget* qpe_main_widget;
172 QGuardedPtr<QWidget> lastraised; 172 QGuardedPtr<QWidget> lastraised;
173 QQueue<QCopRec> qcopq; 173 QQueue<QCopRec> qcopq;
174 QString styleName; 174 QString styleName;
175 QString decorationName; 175 QString decorationName;
176 176
177 void enqueueQCop( const QCString &ch, const QCString &msg, 177 void enqueueQCop( const QCString &ch, const QCString &msg,
178 const QByteArray &data ) 178 const QByteArray &data )
179 { 179 {
180 qcopq.enqueue( new QCopRec( ch, msg, data ) ); 180 qcopq.enqueue( new QCopRec( ch, msg, data ) );
181 } 181 }
182 void sendQCopQ() 182 void sendQCopQ()
183 { 183 {
184 if (!qcopQok ) 184 if (!qcopQok )
185 return; 185 return;
186 186
187 QCopRec * r; 187 QCopRec * r;
188 188
189 while((r=qcopq.dequeue())) { 189 while((r=qcopq.dequeue())) {
190 // remove from queue before sending... 190 // remove from queue before sending...
191 // event loop can come around again before getting 191 // event loop can come around again before getting
192 // back from sendLocally 192 // back from sendLocally
193#ifndef QT_NO_COP 193#ifndef QT_NO_COP
194 QCopChannel::sendLocally( r->channel, r->message, r->data ); 194 QCopChannel::sendLocally( r->channel, r->message, r->data );
195#endif 195#endif
196 196
197 delete r; 197 delete r;
198 } 198 }
199 } 199 }
200 200
201 static void show_mx(QWidget* mw, bool nomaximize, QString &strName) { 201 static void show_mx(QWidget* mw, bool nomaximize, QString &strName) {
202 if ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) 202 if ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") )
203 { 203 {
204 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( useBigPixmaps ); 204 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( useBigPixmaps );
205 } 205 }
206 QPoint p; 206 QPoint p;
207 QSize s; 207 QSize s;
208 bool max; 208 bool max;
209 209
210 if ( mw->isVisible() ) { 210 if ( mw->isVisible() ) {
211 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { 211 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
212 mw->resize(s); 212 mw->resize(s);
213 mw->move(p); 213 mw->move(p);
214 } 214 }
215 mw->raise(); 215 mw->raise();
216 } else { 216 } else {
217 217
218 if ( mw->layout() && mw->inherits("QDialog") ) { 218 if ( mw->layout() && mw->inherits("QDialog") ) {
219 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { 219 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
220 mw->resize(s); 220 mw->resize(s);
221 mw->move(p); 221 mw->move(p);
222 222
223 if ( max && !nomaximize ) { 223 if ( max && !nomaximize ) {
224 mw->showMaximized(); 224 mw->showMaximized();
225 } else { 225 } else {
226 mw->show(); 226 mw->show();
227 } 227 }
228 } else { 228 } else {
229 QPEApplication::showDialog((QDialog*)mw,nomaximize); 229 QPEApplication::showDialog((QDialog*)mw,nomaximize);
230 } 230 }
231 } else { 231 } else {
232 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { 232 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
233 mw->resize(s); 233 mw->resize(s);
234 mw->move(p); 234 mw->move(p);
235 } else { //no stored rectangle, make an estimation 235 } else { //no stored rectangle, make an estimation
236 int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2; 236 int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2;
237 int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2; 237 int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2;
238 mw->move( QMAX(x,0), QMAX(y,0) ); 238 mw->move( QMAX(x,0), QMAX(y,0) );
239#ifdef Q_WS_QWS 239#ifdef Q_WS_QWS
240 if ( !nomaximize ) 240 if ( !nomaximize )
241 mw->showMaximized(); 241 mw->showMaximized();
242#endif 242#endif
243 } 243 }
244 if ( max && !nomaximize ) 244 if ( max && !nomaximize )
245 mw->showMaximized(); 245 mw->showMaximized();
246 else 246 else
247 mw->show(); 247 mw->show();
248 } 248 }
249 } 249 }
250 } 250 }
251 251
252 static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s) 252 static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s)
253 { 253 {
254 maximized = TRUE; 254 maximized = TRUE;
255 // 350 is the trigger in qwsdefaultdecoration for providing a resize button 255 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
256 if ( qApp->desktop()->width() <= 350 ) 256 if ( qApp->desktop()->width() <= 350 )
257 return FALSE; 257 return FALSE;
258 258
259 Config cfg( "qpe" ); 259 Config cfg( "qpe" );
260 cfg.setGroup("ApplicationPositions"); 260 cfg.setGroup("ApplicationPositions");
261 QString str = cfg.readEntry( app, QString::null ); 261 QString str = cfg.readEntry( app, QString::null );
262 QStringList l = QStringList::split(",", str); 262 QStringList l = QStringList::split(",", str);
263 263
264 if ( l.count() == 5) { 264 if ( l.count() == 5) {
265 p.setX( l[0].toInt() ); 265 p.setX( l[0].toInt() );
266 p.setY( l[1].toInt() ); 266 p.setY( l[1].toInt() );
267 267
268 s.setWidth( l[2].toInt() ); 268 s.setWidth( l[2].toInt() );
269 s.setHeight( l[3].toInt() ); 269 s.setHeight( l[3].toInt() );
270 270
271 maximized = l[4].toInt(); 271 maximized = l[4].toInt();
272 272
273 return TRUE; 273 return TRUE;
274 } 274 }
275 275
276 return FALSE; 276 return FALSE;
277 } 277 }
278 278
279 279
280 static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) 280 static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s)
281 { 281 {
282#ifndef Q_WS_QWS 282#ifndef Q_WS_QWS
283 QRect qt_maxWindowRect = qApp->desktop()->geometry(); 283 QRect qt_maxWindowRect = qApp->desktop()->geometry();
284#endif 284#endif
285 int maxX = qt_maxWindowRect.width(); 285 int maxX = qt_maxWindowRect.width();
286 int maxY = qt_maxWindowRect.height(); 286 int maxY = qt_maxWindowRect.height();
287 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); 287 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() );
288 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); 288 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() );
289 289
290 // total window size is not allowed to be larger than desktop window size 290 // total window size is not allowed to be larger than desktop window size
291 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) 291 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) )
292 return FALSE; 292 return FALSE;
293 293
294 if ( wWidth > maxX ) { 294 if ( wWidth > maxX ) {
295 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); 295 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) );
296 wWidth = maxX; 296 wWidth = maxX;
297 } 297 }
298 298
299 if ( wHeight > maxY ) { 299 if ( wHeight > maxY ) {
300 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); 300 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) );
301 wHeight = maxY; 301 wHeight = maxY;
302 } 302 }
303 303
304 // any smaller than this and the maximize/close/help buttons will be overlapping 304 // any smaller than this and the maximize/close/help buttons will be overlapping
305 if ( wWidth < 80 || wHeight < 60 ) 305 if ( wWidth < 80 || wHeight < 60 )
306 return FALSE; 306 return FALSE;
307 307
308 if ( p.x() < 0 ) 308 if ( p.x() < 0 )
309 p.setX(0); 309 p.setX(0);
310 if ( p.y() < 0 ) 310 if ( p.y() < 0 )
311 p.setY(0); 311 p.setY(0);
312 312
313 if ( p.x() + wWidth > maxX ) 313 if ( p.x() + wWidth > maxX )
314 p.setX( maxX - wWidth ); 314 p.setX( maxX - wWidth );
315 if ( p.y() + wHeight > maxY ) 315 if ( p.y() + wHeight > maxY )
316 p.setY( maxY - wHeight ); 316 p.setY( maxY - wHeight );
317 317
318 return TRUE; 318 return TRUE;
319 } 319 }
320 320
321 static void store_widget_rect(QWidget *w, QString &app) 321 static void store_widget_rect(QWidget *w, QString &app)
322 { 322 {
323 // 350 is the trigger in qwsdefaultdecoration for providing a resize button 323 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
324 if ( qApp->desktop()->width() <= 350 ) 324 if ( qApp->desktop()->width() <= 350 )
325 return; 325 return;
326 // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to 326 // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to
327 // get the non-maximized version, so we have to do it the hard way ) 327 // get the non-maximized version, so we have to do it the hard way )
328 int offsetX = w->x() - w->geometry().left(); 328 int offsetX = w->x() - w->geometry().left();
329 int offsetY = w->y() - w->geometry().top(); 329 int offsetY = w->y() - w->geometry().top();
330 330
331 QRect r; 331 QRect r;
332 if ( w->isMaximized() ) 332 if ( w->isMaximized() )
333 r = ( (HackWidget *) w)->normalGeometry(); 333 r = ( (HackWidget *) w)->normalGeometry();
334 else 334 else
335 r = w->geometry(); 335 r = w->geometry();
336 336
337 // Stores the window placement as pos(), size() (due to the offset mapping) 337 // Stores the window placement as pos(), size() (due to the offset mapping)
338 Config cfg( "qpe" ); 338 Config cfg( "qpe" );
339 cfg.setGroup("ApplicationPositions"); 339 cfg.setGroup("ApplicationPositions");
340 QString s; 340 QString s;
341 s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); 341 s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() );
342 cfg.writeEntry( app, s ); 342 cfg.writeEntry( app, s );
343 } 343 }
344 344
345 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 345 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
346 { 346 {
347 /* 347 /*
348 // This works but disable it for now until it is safe to apply 348 // This works but disable it for now until it is safe to apply
349 // What is does is scan the .desktop files of all the apps for 349 // What is does is scan the .desktop files of all the apps for
350 // the applnk that has the corresponding argv[0] as this program 350 // the applnk that has the corresponding argv[0] as this program
351 // then it uses the name stored in the .desktop file as the caption 351 // then it uses the name stored in the .desktop file as the caption
352 // for the main widget. This saves duplicating translations for 352 // for the main widget. This saves duplicating translations for
353 // the app name in the program and in the .desktop files. 353 // the app name in the program and in the .desktop files.
354 354
355 AppLnkSet apps( appsPath ); 355 AppLnkSet apps( appsPath );
356 356
357 QList<AppLnk> appsList = apps.children(); 357 QList<AppLnk> appsList = apps.children();
358 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 358 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
359 if ( (*it)->exec() == appName ) { 359 if ( (*it)->exec() == appName ) {
360 mw->setCaption( (*it)->name() ); 360 mw->setCaption( (*it)->name() );
361 return TRUE; 361 return TRUE;
362 } 362 }
363 } 363 }
364 */ 364 */
365 return FALSE; 365 return FALSE;
366 } 366 }
367 367
368 368
369 void show(QWidget* mw, bool nomax) 369 void show(QWidget* mw, bool nomax)
370 { 370 {
371 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 371 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
372 nomaximize = nomax; 372 nomaximize = nomax;
373 qpe_main_widget = mw; 373 qpe_main_widget = mw;
374 qcopQok = TRUE; 374 qcopQok = TRUE;
375#ifndef QT_NO_COP 375#ifndef QT_NO_COP
376 376
377 sendQCopQ(); 377 sendQCopQ();
378#endif 378#endif
379 379
380 if ( preloaded ) { 380 if ( preloaded ) {
381 if (forceshow) 381 if (forceshow)
382 show_mx(mw, nomax, appName); 382 show_mx(mw, nomax, appName);
383 } 383 }
384 else if ( keep_running ) { 384 else if ( keep_running ) {
385 show_mx(mw, nomax, appName); 385 show_mx(mw, nomax, appName);
386 } 386 }
387 } 387 }
388 388
389 void loadTextCodecs() 389 void loadTextCodecs()
390 { 390 {
391 QString path = QPEApplication::qpeDir() + "plugins/textcodecs"; 391 QString path = QPEApplication::qpeDir() + "plugins/textcodecs";
392#ifdef Q_OS_MACX 392#ifdef Q_OS_MACX
393 QDir dir( path, "lib*.dylib" ); 393 QDir dir( path, "lib*.dylib" );
394#else 394#else
395 QDir dir( path, "lib*.so" ); 395 QDir dir( path, "lib*.so" );
396#endif 396#endif
397 QStringList list; 397 QStringList list;
398 if ( dir. exists ( )) 398 if ( dir. exists ( ))
399 list = dir.entryList(); 399 list = dir.entryList();
400 QStringList::Iterator it; 400 QStringList::Iterator it;
401 for ( it = list.begin(); it != list.end(); ++it ) { 401 for ( it = list.begin(); it != list.end(); ++it ) {
402 TextCodecInterface *iface = 0; 402 TextCodecInterface *iface = 0;
403 QLibrary *lib = new QLibrary( path + "/" + *it ); 403 QLibrary *lib = new QLibrary( path + "/" + *it );
404 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 404 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
405 QValueList<int> mibs = iface->mibEnums(); 405 QValueList<int> mibs = iface->mibEnums();
406 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { 406 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
407 (void)iface->createForMib(*i); 407 (void)iface->createForMib(*i);
408 // ### it exists now; need to remember if we can delete it 408 // ### it exists now; need to remember if we can delete it
409 } 409 }
410 } 410 }
411 else { 411 else {
412 lib->unload(); 412 lib->unload();
413 delete lib; 413 delete lib;
414 } 414 }
415 } 415 }
416 } 416 }
417 417
418 void loadImageCodecs() 418 void loadImageCodecs()
419 { 419 {
420 QString path = QPEApplication::qpeDir() + "plugins/imagecodecs"; 420 QString path = QPEApplication::qpeDir() + "plugins/imagecodecs";
421#ifdef Q_OS_MACX 421#ifdef Q_OS_MACX
422 QDir dir( path, "lib*.dylib" ); 422 QDir dir( path, "lib*.dylib" );
423#else 423#else
424 QDir dir( path, "lib*.so" ); 424 QDir dir( path, "lib*.so" );
425#endif 425#endif
426 QStringList list; 426 QStringList list;
427 if ( dir. exists ( )) 427 if ( dir. exists ( ))
428 list = dir.entryList(); 428 list = dir.entryList();
429 QStringList::Iterator it; 429 QStringList::Iterator it;
430 for ( it = list.begin(); it != list.end(); ++it ) { 430 for ( it = list.begin(); it != list.end(); ++it ) {
431 ImageCodecInterface *iface = 0; 431 ImageCodecInterface *iface = 0;
432 QLibrary *lib = new QLibrary( path + "/" + *it ); 432 QLibrary *lib = new QLibrary( path + "/" + *it );
433 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 433 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
434 QStringList formats = iface->keys(); 434 QStringList formats = iface->keys();
435 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { 435 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
436 (void)iface->installIOHandler(*i); 436 (void)iface->installIOHandler(*i);
437 // ### it exists now; need to remember if we can delete it 437 // ### it exists now; need to remember if we can delete it
438 } 438 }
439 } 439 }
440 else { 440 else {
441 lib->unload(); 441 lib->unload();
442 delete lib; 442 delete lib;
443 } 443 }
444 } 444 }
445 } 445 }
446 446
447}; 447};
448 448
449class ResourceMimeFactory : public QMimeSourceFactory 449class ResourceMimeFactory : public QMimeSourceFactory
450{ 450{
451public: 451public:
452 ResourceMimeFactory() : resImage( 0 ) 452 ResourceMimeFactory() : resImage( 0 )
453 { 453 {
454 setFilePath( Global::helpPath() ); 454 setFilePath( Global::helpPath() );
455 setExtensionType( "html", "text/html;charset=UTF-8" ); 455 setExtensionType( "html", "text/html;charset=UTF-8" );
456 } 456 }
457 ~ResourceMimeFactory() { 457 ~ResourceMimeFactory() {
458 delete resImage; 458 delete resImage;
459 } 459 }
460 460
461 const QMimeSource* data( const QString& abs_name ) const 461 const QMimeSource* data( const QString& abs_name ) const
462 { 462 {
463 const QMimeSource * r = QMimeSourceFactory::data( abs_name ); 463 const QMimeSource * r = QMimeSourceFactory::data( abs_name );
464 if ( !r ) { 464 if ( !r ) {
465 int sl = abs_name.length(); 465 int sl = abs_name.length();
466 do { 466 do {
467 sl = abs_name.findRev( '/', sl - 1 ); 467 sl = abs_name.findRev( '/', sl - 1 );
468 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; 468 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
469 int dot = name.findRev( '.' ); 469 int dot = name.findRev( '.' );
470 if ( dot >= 0 ) 470 if ( dot >= 0 )
471 name = name.left( dot ); 471 name = name.left( dot );
472 QImage img = Resource::loadImage( name ); 472 QImage img = Resource::loadImage( name );
473 if ( !img.isNull() ) { 473 if ( !img.isNull() ) {
474 delete resImage; 474 delete resImage;
475 resImage = new QImageDrag( img ); 475 resImage = new QImageDrag( img );
476 r = resImage; 476 r = resImage;
477 } 477 }
478 } 478 }
479 while ( !r && sl > 0 ); 479 while ( !r && sl > 0 );
480 } 480 }
481 return r; 481 return r;
482 } 482 }
483private: 483private:
484 mutable QImageDrag *resImage; 484 mutable QImageDrag *resImage;
485}; 485};
486 486
487static int& hack(int& i) 487static int& hack(int& i)
488{ 488{
489#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 489#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
490 // These should be created, but aren't in Qt 2.3.0 490 // These should be created, but aren't in Qt 2.3.0
491 (void)new QUtf8Codec; 491 (void)new QUtf8Codec;
492 (void)new QUtf16Codec; 492 (void)new QUtf16Codec;
493#endif 493#endif
494 return i; 494 return i;
495} 495}
496 496
497static int muted = 0; 497static int muted = 0;
498static int micMuted = 0; 498static int micMuted = 0;
499 499
500static void setVolume( int t = 0, int percent = -1 ) 500static void setVolume( int t = 0, int percent = -1 )
501{ 501{
502 switch ( t ) { 502 switch ( t ) {
503 case 0: { 503 case 0: {
504 Config cfg( "qpe" ); 504 Config cfg( "qpe" );
505 cfg.setGroup( "Volume" ); 505 cfg.setGroup( "Volume" );
506 if ( percent < 0 ) 506 if ( percent < 0 )
507 percent = cfg.readNumEntry( "VolumePercent", 50 ); 507 percent = cfg.readNumEntry( "VolumePercent", 50 );
508#ifndef QT_NO_SOUND 508#ifndef QT_NO_SOUND
509 int fd = 0; 509 int fd = 0;
510#ifdef QT_QWS_DEVFS 510#ifdef QT_QWS_DEVFS
511 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { 511 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) {
512#else 512#else
513 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 513 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
514#endif 514#endif
515 int vol = muted ? 0 : percent; 515 int vol = muted ? 0 : percent;
516 // set both channels to same volume 516 // set both channels to same volume
517 vol |= vol << 8; 517 vol |= vol << 8;
518 ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); 518 ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol );
519 ::close( fd ); 519 ::close( fd );
520 } 520 }
521#endif 521#endif
522 } 522 }
523 break; 523 break;
524 } 524 }
525} 525}
526 526
527static void setMic( int t = 0, int percent = -1 ) 527static void setMic( int t = 0, int percent = -1 )
528{ 528{
529 switch ( t ) { 529 switch ( t ) {
530 case 0: { 530 case 0: {
531 Config cfg( "qpe" ); 531 Config cfg( "qpe" );
532 cfg.setGroup( "Volume" ); 532 cfg.setGroup( "Volume" );
533 if ( percent < 0 ) 533 if ( percent < 0 )
534 percent = cfg.readNumEntry( "Mic", 50 ); 534 percent = cfg.readNumEntry( "Mic", 50 );
535 535
536#ifndef QT_NO_SOUND 536#ifndef QT_NO_SOUND
537 int fd = 0; 537 int fd = 0;
538 int mic = micMuted ? 0 : percent; 538 int mic = micMuted ? 0 : percent;
539#ifdef QT_QWS_DEVFS 539#ifdef QT_QWS_DEVFS
540 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { 540 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) {
541#else 541#else
542 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 542 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
543#endif 543#endif
544 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); 544 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic );
545 ::close( fd ); 545 ::close( fd );
546 } 546 }
547#endif 547#endif
548 } 548 }
549 break; 549 break;
550 } 550 }
551} 551}
552 552
553 553
554static void setBass( int t = 0, int percent = -1 ) 554static void setBass( int t = 0, int percent = -1 )
555{ 555{
556 switch ( t ) { 556 switch ( t ) {
557 case 0: { 557 case 0: {
558 Config cfg( "qpe" ); 558 Config cfg( "qpe" );
559 cfg.setGroup( "Volume" ); 559 cfg.setGroup( "Volume" );
560 if ( percent < 0 ) 560 if ( percent < 0 )
561 percent = cfg.readNumEntry( "BassPercent", 50 ); 561 percent = cfg.readNumEntry( "BassPercent", 50 );
562 562
563#ifndef QT_NO_SOUND 563#ifndef QT_NO_SOUND
564 int fd = 0; 564 int fd = 0;
565 int bass = percent; 565 int bass = percent;
566#ifdef QT_QWS_DEVFS 566#ifdef QT_QWS_DEVFS
567 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { 567 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) {
568#else 568#else
569 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 569 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
570#endif 570#endif
571 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); 571 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass );
572 ::close( fd ); 572 ::close( fd );
573 } 573 }
574#endif 574#endif
575 } 575 }
576 break; 576 break;
577 } 577 }
578} 578}
579 579
580 580
581static void setTreble( int t = 0, int percent = -1 ) 581static void setTreble( int t = 0, int percent = -1 )
582{ 582{
583 switch ( t ) { 583 switch ( t ) {
584 case 0: { 584 case 0: {
585 Config cfg( "qpe" ); 585 Config cfg( "qpe" );
586 cfg.setGroup( "Volume" ); 586 cfg.setGroup( "Volume" );
587 if ( percent < 0 ) 587 if ( percent < 0 )
588 percent = cfg.readNumEntry( "TreblePercent", 50 ); 588 percent = cfg.readNumEntry( "TreblePercent", 50 );
589 589
590#ifndef QT_NO_SOUND 590#ifndef QT_NO_SOUND
591 int fd = 0; 591 int fd = 0;
592 int treble = percent; 592 int treble = percent;
593#ifdef QT_QWS_DEVFS 593#ifdef QT_QWS_DEVFS
594 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { 594 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) {
595#else 595#else
596 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 596 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
597#endif 597#endif
598 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); 598 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble );
599 ::close( fd ); 599 ::close( fd );
600 } 600 }
601#endif 601#endif
602 } 602 }
603 break; 603 break;
604 } 604 }
605} 605}
606 606
607 607
608/** 608/**
609 \class QPEApplication 609 \class QPEApplication
610 \brief The QPEApplication class implements various system services 610 \brief The QPEApplication class implements various system services
611 that are available to all Qtopia applications. 611 that are available to all Qtopia applications.
612 612
613 Simply by using QPEApplication instead of QApplication, a standard Qt 613 Simply by using QPEApplication instead of QApplication, a standard Qt
614 application becomes a Qtopia application. It automatically follows 614 application becomes a Qtopia application. It automatically follows
615 style changes, quits and raises, and in the 615 style changes, quits and raises, and in the
616 case of \link docwidget.html document-oriented\endlink applications, 616 case of \link docwidget.html document-oriented\endlink applications,
617 changes the currently displayed document in response to the environment. 617 changes the currently displayed document in response to the environment.
618 618
619 To create a \link docwidget.html document-oriented\endlink 619 To create a \link docwidget.html document-oriented\endlink
620 application use showMainDocumentWidget(); to create a 620 application use showMainDocumentWidget(); to create a
621 non-document-oriented application use showMainWidget(). The 621 non-document-oriented application use showMainWidget(). The
622 keepRunning() function indicates whether the application will 622 keepRunning() function indicates whether the application will
623 continue running after it's processed the last \link qcop.html 623 continue running after it's processed the last \link qcop.html
624 QCop\endlink message. This can be changed using setKeepRunning(). 624 QCop\endlink message. This can be changed using setKeepRunning().
625 625
626 A variety of signals are emitted when certain events occur, for 626 A variety of signals are emitted when certain events occur, for
627 example, timeChanged(), clockChanged(), weekChanged(), 627 example, timeChanged(), clockChanged(), weekChanged(),
628 dateFormatChanged() and volumeChanged(). If the application receives 628 dateFormatChanged() and volumeChanged(). If the application receives
629 a \link qcop.html QCop\endlink message on the application's 629 a \link qcop.html QCop\endlink message on the application's
630 QPE/Application/\e{appname} channel, the appMessage() signal is 630 QPE/Application/\e{appname} channel, the appMessage() signal is
631 emitted. There are also flush() and reload() signals, which 631 emitted. There are also flush() and reload() signals, which
632 are emitted when synching begins and ends respectively - upon these 632 are emitted when synching begins and ends respectively - upon these
633 signals, the application should save and reload any data 633 signals, the application should save and reload any data
634 files that are involved in synching. Most of these signals will initially 634 files that are involved in synching. Most of these signals will initially
635 be received and unfiltered through the appMessage() signal. 635 be received and unfiltered through the appMessage() signal.
636 636
637 This class also provides a set of useful static functions. The 637 This class also provides a set of useful static functions. The
638 qpeDir() and documentDir() functions return the respective paths. 638 qpeDir() and documentDir() functions return the respective paths.
639 The grabKeyboard() and ungrabKeyboard() functions are used to 639 The grabKeyboard() and ungrabKeyboard() functions are used to
640 control whether the application takes control of the device's 640 control whether the application takes control of the device's
641 physical buttons (e.g. application launch keys). The stylus' mode of 641 physical buttons (e.g. application launch keys). The stylus' mode of
642 operation is set with setStylusOperation() and retrieved with 642 operation is set with setStylusOperation() and retrieved with
643 stylusOperation(). There are also setInputMethodHint() and 643 stylusOperation(). There are also setInputMethodHint() and
644 inputMethodHint() functions. 644 inputMethodHint() functions.
645 645
646 \ingroup qtopiaemb 646 \ingroup qtopiaemb
647*/ 647*/
648 648
649/*! 649/*!
650 \fn void QPEApplication::clientMoused() 650 \fn void QPEApplication::clientMoused()
651 651
652 \internal 652 \internal
653*/ 653*/
654 654
655/*! 655/*!
656 \fn void QPEApplication::timeChanged(); 656 \fn void QPEApplication::timeChanged();
657 This signal is emitted when the time changes outside the normal 657 This signal is emitted when the time changes outside the normal
658 passage of time, i.e. if the time is set backwards or forwards. 658 passage of time, i.e. if the time is set backwards or forwards.
659*/ 659*/
660 660
661/*! 661/*!
662 \fn void QPEApplication::clockChanged( bool ampm ); 662 \fn void QPEApplication::clockChanged( bool ampm );
663 663
664 This signal is emitted when the user changes the clock's style. If 664 This signal is emitted when the user changes the clock's style. If
665 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, 665 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise,
666 they want a 24-hour clock. 666 they want a 24-hour clock.
667*/ 667*/
668 668
669/*! 669/*!
670 \fn void QPEApplication::volumeChanged( bool muted ) 670 \fn void QPEApplication::volumeChanged( bool muted )
671 671
672 This signal is emitted whenever the mute state is changed. If \a 672 This signal is emitted whenever the mute state is changed. If \a
673 muted is TRUE, then sound output has been muted. 673 muted is TRUE, then sound output has been muted.
674*/ 674*/
675 675
676/*! 676/*!
677 \fn void QPEApplication::weekChanged( bool startOnMonday ) 677 \fn void QPEApplication::weekChanged( bool startOnMonday )
678 678
679 This signal is emitted if the week start day is changed. If \a 679 This signal is emitted if the week start day is changed. If \a
680 startOnMonday is TRUE then the first day of the week is Monday; if 680 startOnMonday is TRUE then the first day of the week is Monday; if
681 \a startOnMonday is FALSE then the first day of the week is 681 \a startOnMonday is FALSE then the first day of the week is
682 Sunday. 682 Sunday.
683*/ 683*/
684 684
685/*! 685/*!
686 \fn void QPEApplication::dateFormatChanged(DateFormat) 686 \fn void QPEApplication::dateFormatChanged(DateFormat)
687 687
688 This signal is emitted whenever the date format is changed. 688 This signal is emitted whenever the date format is changed.
689*/ 689*/
690 690
691/*! 691/*!
692 \fn void QPEApplication::flush() 692 \fn void QPEApplication::flush()
693 693
694 ### 694 ###
695*/ 695*/
696 696
697/*! 697/*!
698 \fn void QPEApplication::reload() 698 \fn void QPEApplication::reload()
699 699
700*/ 700*/
701 701
702 702
703 703
704void QPEApplication::processQCopFile() 704void QPEApplication::processQCopFile()
705{ 705{
706 QString qcopfn("/tmp/qcop-msg-"); 706 QString qcopfn("/tmp/qcop-msg-");
707 qcopfn += d->appName; // append command name 707 qcopfn += d->appName; // append command name
708 708
709 QFile f(qcopfn); 709 QFile f(qcopfn);
710 if ( f.open(IO_ReadWrite) ) { 710 if ( f.open(IO_ReadWrite) ) {
711#ifndef Q_OS_WIN32 711#ifndef Q_OS_WIN32
712 flock(f.handle(), LOCK_EX); 712 flock(f.handle(), LOCK_EX);
713#endif 713#endif
714 QDataStream ds(&f); 714 QDataStream ds(&f);
715 QCString channel, message; 715 QCString channel, message;
716 QByteArray data; 716 QByteArray data;
717 while(!ds.atEnd()) { 717 while(!ds.atEnd()) {
718 ds >> channel >> message >> data; 718 ds >> channel >> message >> data;
719 d->enqueueQCop(channel,message,data); 719 d->enqueueQCop(channel,message,data);
720 } 720 }
721 ::ftruncate(f.handle(), 0); 721 ::ftruncate(f.handle(), 0);
722#ifndef Q_OS_WIN32 722#ifndef Q_OS_WIN32
723 f.flush(); 723 f.flush();
724 flock(f.handle(), LOCK_UN); 724 flock(f.handle(), LOCK_UN);
725#endif 725#endif
726 } 726 }
727#endif 727#endif
728} 728}
729 729
730 730
731/*! 731/*!
732 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 732 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
733 733
734 This signal is emitted when a message is received on this 734 This signal is emitted when a message is received on this
735 application's QPE/Application/<i>appname</i> \link qcop.html 735 application's QPE/Application/<i>appname</i> \link qcop.html
736 QCop\endlink channel. 736 QCop\endlink channel.
737 737
738 The slot to which you connect this signal uses \a msg and \a data 738 The slot to which you connect this signal uses \a msg and \a data
739 in the following way: 739 in the following way:
740 740
741\code 741\code
742 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 742 void MyWidget::receive( const QCString& msg, const QByteArray& data )
743 { 743 {
744 QDataStream stream( data, IO_ReadOnly ); 744 QDataStream stream( data, IO_ReadOnly );
745 if ( msg == "someMessage(int,int,int)" ) { 745 if ( msg == "someMessage(int,int,int)" ) {
746 int a,b,c; 746 int a,b,c;
747 stream >> a >> b >> c; 747 stream >> a >> b >> c;
748 ... 748 ...
749 } else if ( msg == "otherMessage(QString)" ) { 749 } else if ( msg == "otherMessage(QString)" ) {
750 ... 750 ...
751 } 751 }
752 } 752 }
753\endcode 753\endcode
754 754
755 \sa qcop.html 755 \sa qcop.html
756 Note that messages received here may be processed by qpe application 756 Note that messages received here may be processed by qpe application
757 and emitted as signals, such as flush() and reload(). 757 and emitted as signals, such as flush() and reload().
758*/ 758*/
759 759
760#ifndef QT_NO_TRANSLATION 760#ifndef QT_NO_TRANSLATION
761static void qtopia_loadTranslations( const QStringList& qms ) 761static void qtopia_loadTranslations( const QStringList& qms )
762{ 762{
763 QStringList langs = Global::languageList(); 763 QStringList langs = Global::languageList();
764 764
765 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { 765 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
766 QString lang = *it; 766 QString lang = *it;
767 767
768 QTranslator * trans; 768 QTranslator * trans;
769 QString tfn; 769 QString tfn;
770 770
771 for (QStringList::ConstIterator qmit = qms.begin(); qmit!=qms.end(); ++qmit) { 771 for (QStringList::ConstIterator qmit = qms.begin(); qmit!=qms.end(); ++qmit) {
772 trans = new QTranslator(qApp); 772 trans = new QTranslator(qApp);
773 tfn = QPEApplication::qpeDir() + "i18n/" + lang + "/" + *qmit + ".qm"; 773 tfn = QPEApplication::qpeDir() + "i18n/" + lang + "/" + *qmit + ".qm";
774 if ( trans->load( tfn )) 774 if ( trans->load( tfn ))
775 qApp->installTranslator( trans ); 775 qApp->installTranslator( trans );
776 else 776 else
777 delete trans; 777 delete trans;
778 } 778 }
779 } 779 }
780} 780}
781#endif 781#endif
782 782
783/* 783/*
784 Turn off qDebug in release mode 784 Turn off qDebug in release mode
785 */ 785 */
786static void qtopiaMsgHandler(QtMsgType type, const char* msg) 786static void qtopiaMsgHandler(QtMsgType type, const char* msg)
787{ 787{
788 switch ( type ) { 788 switch ( type ) {
789 case QtDebugMsg: 789 case QtDebugMsg:
790#ifdef QT_DEBUG 790#ifdef QT_DEBUG
791 fprintf( stderr, "Debug: %s\n", msg ); 791 fprintf( stderr, "Debug: %s\n", msg );
792#endif 792#endif
793 break; 793 break;
794 case QtWarningMsg: 794 case QtWarningMsg:
795#ifdef QT_DEBUG 795#ifdef QT_DEBUG
796 fprintf( stderr, "Warning: %s\n", msg ); 796 fprintf( stderr, "Warning: %s\n", msg );
797#endif 797#endif
798 break; 798 break;
799 case QtFatalMsg: 799 case QtFatalMsg:
800 fprintf( stderr, "Fatal: %s\n", msg ); 800 fprintf( stderr, "Fatal: %s\n", msg );
801 abort(); 801 abort();
802 } 802 }
803} 803}
804 804
805/*! 805/*!
806 Constructs a QPEApplication just as you would construct 806 Constructs a QPEApplication just as you would construct
807 a QApplication, passing \a argc, \a argv, and \a t. 807 a QApplication, passing \a argc, \a argv, and \a t.
808 808
809 For applications, \a t should be the default, GuiClient. Only 809 For applications, \a t should be the default, GuiClient. Only
810 the Qtopia server passes GuiServer. 810 the Qtopia server passes GuiServer.
811*/ 811*/
812QPEApplication::QPEApplication( int & argc, char **argv, Type t ) 812QPEApplication::QPEApplication( int & argc, char **argv, Type t )
813 : QApplication( hack(argc), argv, t ), pidChannel( 0 ) 813 : QApplication( hack(argc), argv, t ), pidChannel( 0 )
814{ 814{
815 QPixmapCache::setCacheLimit(256); // sensible default for smaller devices. 815 QPixmapCache::setCacheLimit(256); // sensible default for smaller devices.
816 qInstallMsgHandler(qtopiaMsgHandler); 816 qInstallMsgHandler(qtopiaMsgHandler);
817 817
818 d = new QPEApplicationData; 818 d = new QPEApplicationData;
819 d->loadTextCodecs(); 819 d->loadTextCodecs();
820 d->loadImageCodecs(); 820 d->loadImageCodecs();
821 821
822 setFont( QFont( d->fontFamily, d->fontSize ) ); 822 setFont( QFont( d->fontFamily, d->fontSize ) );
823 AppLnk::setSmallIconSize( d->smallIconSize ); 823 AppLnk::setSmallIconSize( d->smallIconSize );
824 AppLnk::setBigIconSize( d->bigIconSize ); 824 AppLnk::setBigIconSize( d->bigIconSize );
825 825
826 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); 826 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
827 827
828 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); 828 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
829 829
830 830
831 sysChannel = new QCopChannel( "QPE/System", this ); 831 sysChannel = new QCopChannel( "QPE/System", this );
832 connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ), 832 connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
833 this, SLOT( systemMessage(const QCString&,const QByteArray&) ) ); 833 this, SLOT( systemMessage(const QCString&,const QByteArray&) ) );
834 834
835/* COde now in initapp */ 835/* COde now in initapp */
836#if 0 836#if 0
837#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 837#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
838 838
839 QString qcopfn( "/tmp/qcop-msg-" ); 839 QString qcopfn( "/tmp/qcop-msg-" );
840 qcopfn += QString( argv[ 0 ] ); // append command name 840 qcopfn += QString( argv[ 0 ] ); // append command name
841 841
842 QFile f( qcopfn ); 842 QFile f( qcopfn );
843 if ( f.open( IO_ReadOnly ) ) { 843 if ( f.open( IO_ReadOnly ) ) {
844 flock( f.handle(), LOCK_EX ); 844 flock( f.handle(), LOCK_EX );
845 } 845 }
846 846
847 847
848 848
849 QCString channel = QCString( argv[ 0 ] ); 849 QCString channel = QCString( argv[ 0 ] );
850 channel.replace( QRegExp( ".*/" ), "" ); 850 channel.replace( QRegExp( ".*/" ), "" );
851 d->appName = channel; 851 d->appName = channel;
852 channel = "QPE/Application/" + channel; 852 channel = "QPE/Application/" + channel;
853 pidChannel = new QCopChannel( channel, this ); 853 pidChannel = new QCopChannel( channel, this );
854 connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ), 854 connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
855 this, SLOT( pidMessage(const QCString&,const QByteArray&) ) ); 855 this, SLOT( pidMessage(const QCString&,const QByteArray&) ) );
856 856
857 if ( f.isOpen() ) { 857 if ( f.isOpen() ) {
858 d->keep_running = FALSE; 858 d->keep_running = FALSE;
859 QDataStream ds( &f ); 859 QDataStream ds( &f );
860 QCString channel, message; 860 QCString channel, message;
861 QByteArray data; 861 QByteArray data;
862 while ( !ds.atEnd() ) { 862 while ( !ds.atEnd() ) {
863 ds >> channel >> message >> data; 863 ds >> channel >> message >> data;
864 d->enqueueQCop( channel, message, data ); 864 d->enqueueQCop( channel, message, data );
865 } 865 }
866 866
867 flock( f.handle(), LOCK_UN ); 867 flock( f.handle(), LOCK_UN );
868 f.close(); 868 f.close();
869 f.remove(); 869 f.remove();
870 } 870 }
871 871
872 for ( int a = 0; a < argc; a++ ) { 872 for ( int a = 0; a < argc; a++ ) {
873 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { 873 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) {
874 argv[ a ] = argv[ a + 1 ]; 874 argv[ a ] = argv[ a + 1 ];
875 a++; 875 a++;
876 d->preloaded = TRUE; 876 d->preloaded = TRUE;
877 argc -= 1; 877 argc -= 1;
878 } 878 }
879 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { 879 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) {
880 argv[ a ] = argv[ a + 1 ]; 880 argv[ a ] = argv[ a + 1 ];
881 a++; 881 a++;
882 d->preloaded = TRUE; 882 d->preloaded = TRUE;
883 d->forceshow = TRUE; 883 d->forceshow = TRUE;
884 argc -= 1; 884 argc -= 1;
885 } 885 }
886 } 886 }
887 887
888 /* overide stored arguments */ 888 /* overide stored arguments */
889 setArgs( argc, argv ); 889 setArgs( argc, argv );
890 890
891#endif 891#endif
892#else 892#else
893 initApp( argc, argv ); 893 initApp( argc, argv );
894#endif 894#endif
895#ifdef Q_WS_QWS 895#ifdef Q_WS_QWS
896 /* load the font renderer factories */ 896 /* load the font renderer factories */
897 FontDatabase::loadRenderers(); 897 FontDatabase::loadRenderers();
898#endif 898#endif
899#ifndef QT_NO_TRANSLATION 899#ifndef QT_NO_TRANSLATION
900 QStringList qms; 900 QStringList qms;
901 qms << "libqpe"; 901 qms << "libqpe";
902 qms << "libopie"; 902 qms << "libopie";
903 qms << d->appName; 903 qms << d->appName;
904 904
905 qtopia_loadTranslations(qms); 905 qtopia_loadTranslations(qms);
906#endif 906#endif
907 907
908 applyStyle(); 908 applyStyle();
909 909
910 if ( type() == GuiServer ) { 910 if ( type() == GuiServer ) {
911 setVolume(); 911 setVolume();
912 } 912 }
913 913
914 installEventFilter( this ); 914 installEventFilter( this );
915 915
916 QPEMenuToolFocusManager::initialize(); 916 QPEMenuToolFocusManager::initialize();
917 917
918#ifdef QT_NO_QWS_CURSOR 918#ifdef QT_NO_QWS_CURSOR
919 // if we have no cursor, probably don't want tooltips 919 // if we have no cursor, probably don't want tooltips
920 QToolTip::setEnabled( FALSE ); 920 QToolTip::setEnabled( FALSE );
921#endif 921#endif
922} 922}
923 923
924 924
925#ifdef QTOPIA_INTERNAL_INITAPP 925#ifdef QTOPIA_INTERNAL_INITAPP
926void QPEApplication::initApp( int argc, char **argv ) 926void QPEApplication::initApp( int argc, char **argv )
927{ 927{
928 delete pidChannel; 928 delete pidChannel;
929 d->keep_running = TRUE; 929 d->keep_running = TRUE;
930 d->preloaded = FALSE; 930 d->preloaded = FALSE;
931 d->forceshow = FALSE; 931 d->forceshow = FALSE;
932 932
933 QCString channel = QCString(argv[0]); 933 QCString channel = QCString(argv[0]);
934 934
935 channel.replace(QRegExp(".*/"),""); 935 channel.replace(QRegExp(".*/"),"");
936 d->appName = channel; 936 d->appName = channel;
937 937
938#ifndef QT_NO_TRANSLATION 938#ifndef QT_NO_TRANSLATION
939 qtopia_loadTranslations( QStringList()<<channel ); 939 qtopia_loadTranslations( QStringList()<<channel );
940#endif 940#endif
941 941
942 #if QT_VERSION > 235 942 #if QT_VERSION > 235
943 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6 943 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6
944 #endif 944 #endif
945 945
946 channel = "QPE/Application/" + channel; 946 channel = "QPE/Application/" + channel;
947 pidChannel = new QCopChannel( channel, this); 947 pidChannel = new QCopChannel( channel, this);
948 connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)), 948 connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)),
949 this, SLOT(pidMessage(const QCString&,const QByteArray&))); 949 this, SLOT(pidMessage(const QCString&,const QByteArray&)));
950 950
951 951
952 952
953 processQCopFile(); 953 processQCopFile();
954 d->keep_running = d->qcopq.isEmpty(); 954 d->keep_running = d->qcopq.isEmpty();
955 955
956 for (int a=0; a<argc; a++) { 956 for (int a=0; a<argc; a++) {
957 if ( qstrcmp(argv[a],"-preload")==0 ) { 957 if ( qstrcmp(argv[a],"-preload")==0 ) {
958 argv[a] = argv[a+1]; 958 argv[a] = argv[a+1];
959 a++; 959 a++;
960 d->preloaded = TRUE; 960 d->preloaded = TRUE;
961 argc-=1; 961 argc-=1;
962 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { 962 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) {
963 argv[a] = argv[a+1]; 963 argv[a] = argv[a+1];
964 a++; 964 a++;
965 d->preloaded = TRUE; 965 d->preloaded = TRUE;
966 d->forceshow = TRUE; 966 d->forceshow = TRUE;
967 argc-=1; 967 argc-=1;
968 } 968 }
969 } 969 }
970 970
971 /* overide stored arguments */ 971 /* overide stored arguments */
972 setArgs(argc, argv); 972 setArgs(argc, argv);
973} 973}
974#endif 974#endif
975 975
976 976
977static QPtrDict<void>* inputMethodDict = 0; 977static QPtrDict<void>* inputMethodDict = 0;
978static void createInputMethodDict() 978static void createInputMethodDict()
979{ 979{
980 if ( !inputMethodDict ) 980 if ( !inputMethodDict )
981 inputMethodDict = new QPtrDict<void>; 981 inputMethodDict = new QPtrDict<void>;
982} 982}
983 983
984/*! 984/*!
985 Returns the currently set hint to the system as to whether 985 Returns the currently set hint to the system as to whether
986 widget \a w has any use for text input methods. 986 widget \a w has any use for text input methods.
987 987
988 988
989 \sa setInputMethodHint() InputMethodHint 989 \sa setInputMethodHint() InputMethodHint
990*/ 990*/
991QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) 991QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w )
992{ 992{
993 if ( inputMethodDict && w ) 993 if ( inputMethodDict && w )
994 return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); 994 return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
995 return Normal; 995 return Normal;
996} 996}
997 997
998/*! 998/*!
999 \enum QPEApplication::InputMethodHint 999 \enum QPEApplication::InputMethodHint
1000 1000
1001 \value Normal the application sometimes needs text input (the default). 1001 \value Normal the application sometimes needs text input (the default).
1002 \value AlwaysOff the application never needs text input. 1002 \value AlwaysOff the application never needs text input.
1003 \value AlwaysOn the application always needs text input. 1003 \value AlwaysOn the application always needs text input.
1004*/ 1004*/
1005 1005
1006/*! 1006/*!
1007 Hints to the system that widget \a w has use for text input methods 1007 Hints to the system that widget \a w has use for text input methods
1008 as specified by \a mode. 1008 as specified by \a mode.
1009 1009
1010 \sa inputMethodHint() InputMethodHint 1010 \sa inputMethodHint() InputMethodHint
1011*/ 1011*/
1012void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) 1012void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode )
1013{ 1013{
1014 createInputMethodDict(); 1014 createInputMethodDict();
1015 if ( mode == Normal ) { 1015 if ( mode == Normal ) {
1016 inputMethodDict->remove 1016 inputMethodDict->remove
1017 ( w ); 1017 ( w );
1018 } 1018 }
1019 else { 1019 else {
1020 inputMethodDict->insert( w, ( void* ) mode ); 1020 inputMethodDict->insert( w, ( void* ) mode );
1021 } 1021 }
1022} 1022}
1023 1023
1024class HackDialog : public QDialog 1024class HackDialog : public QDialog
1025{ 1025{
1026public: 1026public:
1027 void acceptIt() 1027 void acceptIt()
1028 { 1028 {
1029 accept(); 1029 accept();
1030 } 1030 }
1031 void rejectIt() 1031 void rejectIt()
1032 { 1032 {
1033 reject(); 1033 reject();
1034 } 1034 }
1035}; 1035};
1036 1036
1037 1037
1038void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) 1038void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key )
1039{ 1039{
1040 // specialised actions for certain widgets. May want to 1040 // specialised actions for certain widgets. May want to
1041 // add more stuff here. 1041 // add more stuff here.
1042 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) 1042 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" )
1043 && activePopupWidget() ->parentWidget() 1043 && activePopupWidget() ->parentWidget()
1044 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) 1044 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) )
1045 key = Qt::Key_Return; 1045 key = Qt::Key_Return;
1046 1046
1047 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) 1047 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) )
1048 key = Qt::Key_Return; 1048 key = Qt::Key_Return;
1049 1049
1050#ifdef QWS 1050#ifdef QWS
1051 1051
1052 ke->simpleData.keycode = key; 1052 ke->simpleData.keycode = key;
1053#endif 1053#endif
1054} 1054}
1055 1055
1056 1056
1057/*! 1057/*!
1058 \internal 1058 \internal
1059*/ 1059*/
1060 1060
1061#ifdef QWS 1061#ifdef QWS
1062bool QPEApplication::qwsEventFilter( QWSEvent * e ) 1062bool QPEApplication::qwsEventFilter( QWSEvent * e )
1063{ 1063{
1064 if ( !d->notbusysent && e->type == QWSEvent::Focus ) { 1064 if ( !d->notbusysent && e->type == QWSEvent::Focus ) {
1065 if ( qApp->type() != QApplication::GuiServer ) { 1065 if ( qApp->type() != QApplication::GuiServer ) {
1066 QCopEnvelope e( "QPE/System", "notBusy(QString)" ); 1066 QCopEnvelope e( "QPE/System", "notBusy(QString)" );
1067 e << d->appName; 1067 e << d->appName;
1068 } 1068 }
1069 d->notbusysent = TRUE; 1069 d->notbusysent = TRUE;
1070 } 1070 }
1071 if ( type() == GuiServer ) { 1071 if ( type() == GuiServer ) {
1072 switch ( e->type ) { 1072 switch ( e->type ) {
1073 case QWSEvent::Mouse: 1073 case QWSEvent::Mouse:
1074 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) 1074 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) )
1075 emit clientMoused(); 1075 emit clientMoused();
1076 break; 1076 break;
1077 default: 1077 default:
1078 break; 1078 break;
1079 } 1079 }
1080 } 1080 }
1081 if ( e->type == QWSEvent::Key ) { 1081 if ( e->type == QWSEvent::Key ) {
1082 QWSKeyEvent *ke = ( QWSKeyEvent * ) e; 1082 QWSKeyEvent *ke = ( QWSKeyEvent * ) e;
1083 if ( ke->simpleData.keycode == Qt::Key_F33 ) { 1083 if ( ke->simpleData.keycode == Qt::Key_F33 ) {
1084 // Use special "OK" key to press "OK" on top level widgets 1084 // Use special "OK" key to press "OK" on top level widgets
1085 QWidget * active = activeWindow(); 1085 QWidget * active = activeWindow();
1086 QWidget *popup = 0; 1086 QWidget *popup = 0;
1087 if ( active && active->isPopup() ) { 1087 if ( active && active->isPopup() ) {
1088 popup = active; 1088 popup = active;
1089 active = active->parentWidget(); 1089 active = active->parentWidget();
1090 } 1090 }
1091 if ( active && ( int ) active->winId() == ke->simpleData.window && 1091 if ( active && ( int ) active->winId() == ke->simpleData.window &&
1092 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { 1092 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) {
1093 if ( ke->simpleData.is_press ) { 1093 if ( ke->simpleData.is_press ) {
1094 if ( popup ) 1094 if ( popup )
1095 popup->close(); 1095 popup->close();
1096 if ( active->inherits( "QDialog" ) ) { 1096 if ( active->inherits( "QDialog" ) ) {
1097 HackDialog * d = ( HackDialog * ) active; 1097 HackDialog * d = ( HackDialog * ) active;
1098 d->acceptIt(); 1098 d->acceptIt();
1099 return TRUE; 1099 return TRUE;
1100 } 1100 }
1101 else if ( ( ( HackWidget * ) active ) ->needsOk() ) { 1101 else if ( ( ( HackWidget * ) active ) ->needsOk() ) {
1102 QSignal s; 1102 QSignal s;
1103 s.connect( active, SLOT( accept() ) ); 1103 s.connect( active, SLOT( accept() ) );
1104 s.activate(); 1104 s.activate();
1105 } 1105 }
1106 else { 1106 else {
1107 // do the same as with the select key: Map to the default action of the widget: 1107 // do the same as with the select key: Map to the default action of the widget:
1108 mapToDefaultAction( ke, Qt::Key_Return ); 1108 mapToDefaultAction( ke, Qt::Key_Return );
1109 } 1109 }
1110 } 1110 }
1111 } 1111 }
1112 } 1112 }
1113 else if ( ke->simpleData.keycode == Qt::Key_F30 ) { 1113 else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
1114 // Use special "select" key to do whatever default action a widget has 1114 // Use special "select" key to do whatever default action a widget has
1115 mapToDefaultAction( ke, Qt::Key_Space ); 1115 mapToDefaultAction( ke, Qt::Key_Space );
1116 } 1116 }
1117 else if ( ke->simpleData.keycode == Qt::Key_Escape && 1117 else if ( ke->simpleData.keycode == Qt::Key_Escape &&
1118 ke->simpleData.is_press ) { 1118 ke->simpleData.is_press ) {
1119 // Escape key closes app if focus on toplevel 1119 // Escape key closes app if focus on toplevel
1120 QWidget * active = activeWindow(); 1120 QWidget * active = activeWindow();
1121 if ( active && active->testWFlags( WType_TopLevel ) && 1121 if ( active && active->testWFlags( WType_TopLevel ) &&
1122 ( int ) active->winId() == ke->simpleData.window && 1122 ( int ) active->winId() == ke->simpleData.window &&
1123 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { 1123 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) {
1124 if ( active->inherits( "QDialog" ) ) { 1124 if ( active->inherits( "QDialog" ) ) {
1125 HackDialog * d = ( HackDialog * ) active; 1125 HackDialog * d = ( HackDialog * ) active;
1126 d->rejectIt(); 1126 d->rejectIt();
1127 return TRUE; 1127 return TRUE;
1128 } else /*if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 )*/ { 1128 } else /*if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 )*/ {
1129 active->close(); 1129 active->close();
1130 } 1130 }
1131 } 1131 }
1132 1132
1133 } 1133 }
1134 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) { 1134 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) {
1135 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... )) 1135 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... ))
1136 // but we cannot access libopie function within libqpe :( 1136 // but we cannot access libopie function within libqpe :(
1137 1137
1138 QWidget * active = activeWindow ( ); 1138 QWidget * active = activeWindow ( );
1139 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) { 1139 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) {
1140 if ( d-> kbgrabbed ) { // we grabbed the keyboard 1140 if ( d-> kbgrabbed ) { // we grabbed the keyboard
1141 QChar ch ( ke-> simpleData.unicode ); 1141 QChar ch ( ke-> simpleData.unicode );
1142 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease, 1142 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease,
1143 ke-> simpleData.keycode, 1143 ke-> simpleData.keycode,
1144 ch. latin1 ( ), 1144 ch. latin1 ( ),
1145 ke-> simpleData.modifiers, 1145 ke-> simpleData.modifiers,
1146 QString ( ch ), 1146 QString ( ch ),
1147 ke-> simpleData.is_auto_repeat, 1 ); 1147 ke-> simpleData.is_auto_repeat, 1 );
1148 1148
1149 QObject *which = QWidget::keyboardGrabber ( ); 1149 QObject *which = QWidget::keyboardGrabber ( );
1150 if ( !which ) 1150 if ( !which )
1151 which = QApplication::focusWidget ( ); 1151 which = QApplication::focusWidget ( );
1152 if ( !which ) 1152 if ( !which )
1153 which = QApplication::activeWindow ( ); 1153 which = QApplication::activeWindow ( );
1154 if ( !which ) 1154 if ( !which )
1155 which = qApp; 1155 which = qApp;
1156 1156
1157 QApplication::sendEvent ( which, &qke ); 1157 QApplication::sendEvent ( which, &qke );
1158 } 1158 }
1159 else { // we didn't grab the keyboard, so send the event to the launcher 1159 else { // we didn't grab the keyboard, so send the event to the launcher
1160 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" ); 1160 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" );
1161 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat ); 1161 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat );
1162 } 1162 }
1163 } 1163 }
1164 return true; 1164 return true;
1165 } 1165 }
1166 } 1166 }
1167 if ( e->type == QWSEvent::Focus ) { 1167 if ( e->type == QWSEvent::Focus ) {
1168 QWSFocusEvent * fe = ( QWSFocusEvent* ) e; 1168 QWSFocusEvent * fe = ( QWSFocusEvent* ) e;
1169 if ( !fe->simpleData.get_focus ) { 1169 if ( !fe->simpleData.get_focus ) {
1170 QWidget * active = activeWindow(); 1170 QWidget * active = activeWindow();
1171 while ( active && active->isPopup() ) { 1171 while ( active && active->isPopup() ) {
1172 active->close(); 1172 active->close();
1173 active = activeWindow(); 1173 active = activeWindow();
1174 } 1174 }
1175 } 1175 }
1176 else { 1176 else {
1177 // make sure our modal widget is ALWAYS on top 1177 // make sure our modal widget is ALWAYS on top
1178 QWidget *topm = activeModalWidget(); 1178 QWidget *topm = activeModalWidget();
1179 if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) { 1179 if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) {
1180 topm->raise(); 1180 topm->raise();
1181 } 1181 }
1182 } 1182 }
1183 if ( fe->simpleData.get_focus && inputMethodDict ) { 1183 if ( fe->simpleData.get_focus && inputMethodDict ) {
1184 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) ); 1184 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) );
1185 if ( m == AlwaysOff ) 1185 if ( m == AlwaysOff )
1186 Global::hideInputMethod(); 1186 Global::hideInputMethod();
1187 if ( m == AlwaysOn ) 1187 if ( m == AlwaysOn )
1188 Global::showInputMethod(); 1188 Global::showInputMethod();
1189 } 1189 }
1190 } 1190 }
1191 1191
1192 1192
1193 return QApplication::qwsEventFilter( e ); 1193 return QApplication::qwsEventFilter( e );
1194} 1194}
1195#endif 1195#endif
1196 1196
1197/*! 1197/*!
1198 Destroys the QPEApplication. 1198 Destroys the QPEApplication.
1199*/ 1199*/
1200QPEApplication::~QPEApplication() 1200QPEApplication::~QPEApplication()
1201{ 1201{
1202 ungrabKeyboard(); 1202 ungrabKeyboard();
1203#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 1203#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
1204 // Need to delete QCopChannels early, since the display will 1204 // Need to delete QCopChannels early, since the display will
1205 // be gone by the time we get to ~QObject(). 1205 // be gone by the time we get to ~QObject().
1206 delete sysChannel; 1206 delete sysChannel;
1207 delete pidChannel; 1207 delete pidChannel;
1208#endif 1208#endif
1209 1209
1210#ifdef OPIE_WITHROHFEEDBACK 1210#ifdef OPIE_WITHROHFEEDBACK
1211 if( d->RoH ) 1211 if( d->RoH )
1212 delete d->RoH; 1212 delete d->RoH;
1213#endif 1213#endif
1214 delete d; 1214 delete d;
1215} 1215}
1216 1216
1217/*! 1217/*!
1218 Returns <tt>$OPIEDIR/</tt>. 1218 Returns <tt>$OPIEDIR/</tt>.
1219*/ 1219*/
1220QString QPEApplication::qpeDir() 1220QString QPEApplication::qpeDir()
1221{ 1221{
1222 QString base, dir; 1222 QString base, dir;
1223 1223
1224 if (getenv( "OPIEDIR" )) 1224 if (getenv( "OPIEDIR" ))
1225 base = QString(getenv("OPIEDIR")).stripWhiteSpace(); 1225 base = QString(getenv("OPIEDIR")).stripWhiteSpace();
1226 if ( !base.isNull() && (base.length() > 0 )){ 1226 if ( !base.isNull() && (base.length() > 0 )){
1227#ifdef Q_OS_WIN32 1227#ifdef Q_OS_WIN32
1228 QString temp(base); 1228 QString temp(base);
1229 if (temp[(int)temp.length()-1] != QDir::separator()) 1229 if (temp[(int)temp.length()-1] != QDir::separator())
1230 temp.append(QDir::separator()); 1230 temp.append(QDir::separator());
1231 dir = temp; 1231 dir = temp;
1232#else 1232#else
1233 dir = QString( base ) + "/"; 1233 dir = QString( base ) + "/";
1234#endif 1234#endif
1235 }else{ 1235 }else{
1236 dir = QString( ".." ) + QDir::separator(); 1236 dir = QString( ".." ) + QDir::separator();
1237 } 1237 }
1238 1238
1239 return dir; 1239 return dir;
1240} 1240}
1241 1241
1242/*! 1242/*!
1243 Returns the user's current Document directory. There is a trailing "/". 1243 Returns the user's current Document directory. There is a trailing "/".
1244 .. well, it does now,, and there's no trailing '/' 1244 .. well, it does now,, and there's no trailing '/'
1245*/ 1245*/
1246QString QPEApplication::documentDir() 1246QString QPEApplication::documentDir()
1247{ 1247{
1248 const char* base = getenv( "HOME"); 1248 const char* base = getenv( "HOME");
1249 if ( base ) 1249 if ( base )
1250 return QString( base ) + "/Documents"; 1250 return QString( base ) + "/Documents";
1251 1251
1252 return QString( "../Documents" ); 1252 return QString( "../Documents" );
1253} 1253}
1254 1254
1255static int deforient = -1; 1255static int deforient = -1;
1256 1256
1257/*! 1257/*!
1258 \internal 1258 \internal
1259*/ 1259*/
1260int QPEApplication::defaultRotation() 1260int QPEApplication::defaultRotation()
1261{ 1261{
1262 if ( deforient < 0 ) { 1262 if ( deforient < 0 ) {
1263 QString d = getenv( "QWS_DISPLAY" ); 1263 QString d = getenv( "QWS_DISPLAY" );
1264 if ( d.contains( "Rot90" ) ) { 1264 if ( d.contains( "Rot90" ) ) {
1265 deforient = 90; 1265 deforient = 90;
1266 } 1266 }
1267 else if ( d.contains( "Rot180" ) ) { 1267 else if ( d.contains( "Rot180" ) ) {
1268 deforient = 180; 1268 deforient = 180;
1269 } 1269 }
1270 else if ( d.contains( "Rot270" ) ) { 1270 else if ( d.contains( "Rot270" ) ) {
1271 deforient = 270; 1271 deforient = 270;
1272 } 1272 }
1273 else { 1273 else {
1274 deforient = 0; 1274 deforient = 0;
1275 } 1275 }
1276 } 1276 }
1277 return deforient; 1277 return deforient;
1278} 1278}
1279 1279
1280/*! 1280/*!
1281 \internal 1281 \internal
1282*/ 1282*/
1283void QPEApplication::setDefaultRotation( int r ) 1283void QPEApplication::setDefaultRotation( int r )
1284{ 1284{
1285 if ( qApp->type() == GuiServer ) { 1285 if ( qApp->type() == GuiServer ) {
1286 deforient = r; 1286 deforient = r;
1287 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); 1287 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 );
1288 Config config("qpe"); 1288 Config config("qpe");
1289 config.setGroup( "Rotation" ); 1289 config.setGroup( "Rotation" );
1290 config.writeEntry( "Rot", r ); 1290 config.writeEntry( "Rot", r );
1291 } 1291 }
1292 else { 1292 else {
1293#ifndef QT_NO_COP 1293#ifndef QT_NO_COP
1294 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" ); 1294 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" );
1295 e << r; 1295 e << r;
1296 } 1296 }
1297#endif 1297#endif
1298 1298
1299 } 1299 }
1300} 1300}
1301 1301
1302#include <qgfx_qws.h> 1302#include <qgfx_qws.h>
1303#include <qwindowsystem_qws.h> 1303#include <qwindowsystem_qws.h>
1304 1304
1305#if QT_VERSION > 236 1305#if QT_VERSION > 236
1306extern void qws_clearLoadedFonts(); 1306extern void qws_clearLoadedFonts();
1307#endif 1307#endif
1308 1308
1309void QPEApplication::setCurrentMode( int x, int y, int depth ) 1309void QPEApplication::setCurrentMode( int x, int y, int depth )
1310{ 1310{
1311 // Reset the caches 1311 // Reset the caches
1312#if QT_VERSION > 236 1312#if QT_VERSION > 236
1313 qws_clearLoadedFonts(); 1313 qws_clearLoadedFonts();
1314#endif 1314#endif
1315 QPixmapCache::clear(); 1315 QPixmapCache::clear();
1316 1316
1317 // Change the screen mode 1317 // Change the screen mode
1318 qt_screen->setMode(x, y, depth); 1318 qt_screen->setMode(x, y, depth);
1319 1319
1320 if ( qApp->type() == GuiServer ) { 1320 if ( qApp->type() == GuiServer ) {
1321#if QT_VERSION > 236 1321#if QT_VERSION > 236
1322 // Reconfigure the GuiServer 1322 // Reconfigure the GuiServer
1323 qwsServer->beginDisplayReconfigure(); 1323 qwsServer->beginDisplayReconfigure();
1324 qwsServer->endDisplayReconfigure(); 1324 qwsServer->endDisplayReconfigure();
1325#endif 1325#endif
1326 // Get all the running apps to reset 1326 // Get all the running apps to reset
1327 QCopEnvelope env( "QPE/System", "reset()" ); 1327 QCopEnvelope env( "QPE/System", "reset()" );
1328 } 1328 }
1329} 1329}
1330 1330
1331void QPEApplication::reset() { 1331void QPEApplication::reset() {
1332 // Reconnect to the screen 1332 // Reconnect to the screen
1333 qt_screen->disconnect(); 1333 qt_screen->disconnect();
1334 qt_screen->connect( QString::null ); 1334 qt_screen->connect( QString::null );
1335 1335
1336 // Redraw everything 1336 // Redraw everything
1337 applyStyle(); 1337 applyStyle();
1338} 1338}
1339 1339
1340#if (QT_VERSION < 238) && defined Q_OS_MACX 1340#if (QT_VERSION < 238) && defined Q_OS_MACX
1341bool qt_left_hand_scrollbars = false; 1341bool qt_left_hand_scrollbars = false;
1342#else 1342#else
1343extern bool qt_left_hand_scrollbars QPE_WEAK_SYMBOL; 1343extern bool qt_left_hand_scrollbars QPE_WEAK_SYMBOL;
1344#endif 1344#endif
1345 1345
1346/*! 1346/*!
1347 \internal 1347 \internal
1348*/ 1348*/
1349void QPEApplication::applyStyle() 1349void QPEApplication::applyStyle()
1350{ 1350{
1351 Config config( "qpe" ); 1351 Config config( "qpe" );
1352 config.setGroup( "Appearance" ); 1352 config.setGroup( "Appearance" );
1353 1353
1354#if QT_VERSION > 233 1354#if QT_VERSION > 233
1355#if !defined(OPIE_NO_OVERRIDE_QT) 1355#if !defined(OPIE_NO_OVERRIDE_QT)
1356 // don't block ourselves ... 1356 // don't block ourselves ...
1357 Opie::force_appearance = 0; 1357 Opie::force_appearance = 0;
1358 1358
1359 static QString appname = Opie::binaryName ( ); 1359 static QString appname = Opie::binaryName ( );
1360 1360
1361 QStringList ex = config. readListEntry ( "NoStyle", ';' ); 1361 QStringList ex = config. readListEntry ( "NoStyle", ';' );
1362 int nostyle = 0; 1362 int nostyle = 0;
1363 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) { 1363 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) {
1364 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) { 1364 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) {
1365 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 ); 1365 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 );
1366 break; 1366 break;
1367 } 1367 }
1368 } 1368 }
1369#else 1369#else
1370 int nostyle = 0; 1370 int nostyle = 0;
1371#endif 1371#endif
1372 1372
1373 // Widget style 1373 // Widget style
1374 QString style = config.readEntry( "Style", "FlatStyle" ); 1374 QString style = config.readEntry( "Style", "FlatStyle" );
1375 1375
1376 // don't set a custom style 1376 // don't set a custom style
1377 if ( nostyle & Opie::Force_Style ) 1377 if ( nostyle & Opie::Force_Style )
1378 style = "FlatStyle"; 1378 style = "FlatStyle";
1379 1379
1380 internalSetStyle ( style ); 1380 internalSetStyle ( style );
1381 1381
1382 // Colors - from /etc/colors/Liquid.scheme 1382 // Colors - from /etc/colors/Liquid.scheme
1383 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) ); 1383 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) );
1384 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) ); 1384 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) );
1385 QPalette pal( btncolor, bgcolor ); 1385 QPalette pal( btncolor, bgcolor );
1386 QString color = config.readEntry( "Highlight", "#73adef" ); 1386 QString color = config.readEntry( "Highlight", "#73adef" );
1387 pal.setColor( QColorGroup::Highlight, QColor( color ) ); 1387 pal.setColor( QColorGroup::Highlight, QColor( color ) );
1388 color = config.readEntry( "HighlightedText", "#FFFFFF" ); 1388 color = config.readEntry( "HighlightedText", "#FFFFFF" );
1389 pal.setColor( QColorGroup::HighlightedText, QColor( color ) ); 1389 pal.setColor( QColorGroup::HighlightedText, QColor( color ) );
1390 color = config.readEntry( "Text", "#000000" ); 1390 color = config.readEntry( "Text", "#000000" );
1391 pal.setColor( QColorGroup::Text, QColor( color ) ); 1391 pal.setColor( QColorGroup::Text, QColor( color ) );
1392 color = config.readEntry( "ButtonText", "#000000" ); 1392 color = config.readEntry( "ButtonText", "#000000" );
1393 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) ); 1393 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) );
1394 color = config.readEntry( "Base", "#FFFFFF" ); 1394 color = config.readEntry( "Base", "#FFFFFF" );
1395 pal.setColor( QColorGroup::Base, QColor( color ) ); 1395 pal.setColor( QColorGroup::Base, QColor( color ) );
1396 1396
1397 pal.setColor( QPalette::Disabled, QColorGroup::Text, 1397 pal.setColor( QPalette::Disabled, QColorGroup::Text,
1398 pal.color( QPalette::Active, QColorGroup::Background ).dark() ); 1398 pal.color( QPalette::Active, QColorGroup::Background ).dark() );
1399 1399
1400 setPalette( pal, TRUE ); 1400 setPalette( pal, TRUE );
1401 1401
1402 1402
1403 // Set the ScrollBar on the 'right' side but only if the weak symbol is present 1403 // Set the ScrollBar on the 'right' side but only if the weak symbol is present
1404 if (&qt_left_hand_scrollbars ) 1404 if (&qt_left_hand_scrollbars )
1405 qt_left_hand_scrollbars = config.readBoolEntry( "LeftHand", false ); 1405 qt_left_hand_scrollbars = config.readBoolEntry( "LeftHand", false );
1406 1406
1407 // Window Decoration 1407 // Window Decoration
1408 QString dec = config.readEntry( "Decoration", "Flat" ); 1408 QString dec = config.readEntry( "Decoration", "Flat" );
1409 1409
1410 // don't set a custom deco 1410 // don't set a custom deco
1411 if ( nostyle & Opie::Force_Decoration ) 1411 if ( nostyle & Opie::Force_Decoration )
1412 dec = ""; 1412 dec = "";
1413 1413
1414 1414
1415 if ( dec != d->decorationName ) { 1415 if ( dec != d->decorationName ) {
1416 qwsSetDecoration( new QPEDecoration( dec ) ); 1416 qwsSetDecoration( new QPEDecoration( dec ) );
1417 d->decorationName = dec; 1417 d->decorationName = dec;
1418 } 1418 }
1419 1419
1420 // Font 1420 // Font
1421 QString ff = config.readEntry( "FontFamily", font().family() ); 1421 QString ff = config.readEntry( "FontFamily", font().family() );
1422 int fs = config.readNumEntry( "FontSize", font().pointSize() ); 1422 int fs = config.readNumEntry( "FontSize", font().pointSize() );
1423 1423
1424 // don't set a custom font 1424 // don't set a custom font
1425 if ( nostyle & Opie::Force_Font ) { 1425 if ( nostyle & Opie::Force_Font ) {
1426 ff = "Vera"; 1426 ff = "Vera";
1427 fs = 10; 1427 fs = 10;
1428 } 1428 }
1429 1429
1430 setFont ( QFont ( ff, fs ), true ); 1430 setFont ( QFont ( ff, fs ), true );
1431 1431
1432#if !defined(OPIE_NO_OVERRIDE_QT) 1432#if !defined(OPIE_NO_OVERRIDE_QT)
1433 // revert to global blocking policy ... 1433 // revert to global blocking policy ...
1434 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None; 1434 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None;
1435 Opie::force_appearance &= ~nostyle; 1435 Opie::force_appearance &= ~nostyle;
1436#endif 1436#endif
1437#endif 1437#endif
1438} 1438}
1439 1439
1440void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data ) 1440void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data )
1441{ 1441{
1442#ifdef Q_WS_QWS 1442#ifdef Q_WS_QWS
1443 QDataStream stream( data, IO_ReadOnly ); 1443 QDataStream stream( data, IO_ReadOnly );
1444 if ( msg == "applyStyle()" ) { 1444 if ( msg == "applyStyle()" ) {
1445 applyStyle(); 1445 applyStyle();
1446 } 1446 }
1447 else if ( msg == "toggleApplicationMenu()" ) { 1447 else if ( msg == "toggleApplicationMenu()" ) {
1448 QWidget *active = activeWindow ( ); 1448 QWidget *active = activeWindow ( );
1449 1449
1450 if ( active ) { 1450 if ( active ) {
1451 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( ); 1451 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( );
1452 bool oldactive = man-> isActive ( ); 1452 bool oldactive = man-> isActive ( );
1453 1453
1454 man-> setActive( !man-> isActive() ); 1454 man-> setActive( !man-> isActive() );
1455 1455
1456 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu 1456 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu
1457 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" ); 1457 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" );
1458 } 1458 }
1459 } 1459 }
1460 } 1460 }
1461 else if ( msg == "setDefaultRotation(int)" ) { 1461 else if ( msg == "setDefaultRotation(int)" ) {
1462 if ( type() == GuiServer ) { 1462 if ( type() == GuiServer ) {
1463 int r; 1463 int r;
1464 stream >> r; 1464 stream >> r;
1465 setDefaultRotation( r ); 1465 setDefaultRotation( r );
1466 } 1466 }
1467 } 1467 }
1468 else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net> 1468 else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net>
1469 if ( type() == GuiServer ) { 1469 if ( type() == GuiServer ) {
1470 int x, y, depth; 1470 int x, y, depth;
1471 stream >> x; 1471 stream >> x;
1472 stream >> y; 1472 stream >> y;
1473 stream >> depth; 1473 stream >> depth;
1474 setCurrentMode( x, y, depth ); 1474 setCurrentMode( x, y, depth );
1475 } 1475 }
1476 } 1476 }
1477 else if ( msg == "reset()" ) { 1477 else if ( msg == "reset()" ) {
1478 if ( type() != GuiServer ) 1478 if ( type() != GuiServer )
1479 reset(); 1479 reset();
1480 } 1480 }
1481 else if ( msg == "setCurrentRotation(int)" ) { 1481 else if ( msg == "setCurrentRotation(int)" ) {
1482 int r; 1482 int r;
1483 stream >> r; 1483 stream >> r;
1484 setCurrentRotation( r ); 1484 setCurrentRotation( r );
1485 } 1485 }
1486 else if ( msg == "shutdown()" ) { 1486 else if ( msg == "shutdown()" ) {
1487 if ( type() == GuiServer ) 1487 if ( type() == GuiServer )
1488 shutdown(); 1488 shutdown();
1489 } 1489 }
1490 else if ( msg == "quit()" ) { 1490 else if ( msg == "quit()" ) {
1491 if ( type() != GuiServer ) 1491 if ( type() != GuiServer )
1492 tryQuit(); 1492 tryQuit();
1493 } 1493 }
1494 else if ( msg == "forceQuit()" ) { 1494 else if ( msg == "forceQuit()" ) {
1495 if ( type() != GuiServer ) 1495 if ( type() != GuiServer )
1496 quit(); 1496 quit();
1497 } 1497 }
1498 else if ( msg == "restart()" ) { 1498 else if ( msg == "restart()" ) {
1499 if ( type() == GuiServer ) 1499 if ( type() == GuiServer )
1500 restart(); 1500 restart();
1501 } 1501 }
1502 else if ( msg == "language(QString)" ) { 1502 else if ( msg == "language(QString)" ) {
1503 if ( type() == GuiServer ) { 1503 if ( type() == GuiServer ) {
1504 QString l; 1504 QString l;
1505 stream >> l; 1505 stream >> l;
1506 QString cl = getenv( "LANG" ); 1506 QString cl = getenv( "LANG" );
1507 if ( cl != l ) { 1507 if ( cl != l ) {
1508 if ( l.isNull() ) 1508 if ( l.isNull() )
1509 unsetenv( "LANG" ); 1509 unsetenv( "LANG" );
1510 else 1510 else
1511 setenv( "LANG", l.latin1(), 1 ); 1511 setenv( "LANG", l.latin1(), 1 );
1512 restart(); 1512 restart();
1513 } 1513 }
1514 } 1514 }
1515 } 1515 }
1516 else if ( msg == "timeChange(QString)" ) { 1516 else if ( msg == "timeChange(QString)" ) {
1517 QString t; 1517 QString t;
1518 stream >> t; 1518 stream >> t;
1519 if ( t.isNull() ) 1519 if ( t.isNull() )
1520 unsetenv( "TZ" ); 1520 unsetenv( "TZ" );
1521 else 1521 else
1522 setenv( "TZ", t.latin1(), 1 ); 1522 setenv( "TZ", t.latin1(), 1 );
1523 // emit the signal so everyone else knows... 1523 // emit the signal so everyone else knows...
1524 emit timeChanged(); 1524 emit timeChanged();
1525 } 1525 }
1526 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { 1526 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) {
1527 if ( type() == GuiServer ) { 1527 if ( type() == GuiServer ) {
1528 QDateTime when; 1528 QDateTime when;
1529 QCString channel, message; 1529 QCString channel, message;
1530 int data; 1530 int data;
1531 stream >> when >> channel >> message >> data; 1531 stream >> when >> channel >> message >> data;
1532 AlarmServer::addAlarm( when, channel, message, data ); 1532 AlarmServer::addAlarm( when, channel, message, data );
1533 } 1533 }
1534 } 1534 }
1535 else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) { 1535 else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) {
1536 if ( type() == GuiServer ) { 1536 if ( type() == GuiServer ) {
1537 QDateTime when; 1537 QDateTime when;
1538 QCString channel, message; 1538 QCString channel, message;
1539 int data; 1539 int data;
1540 stream >> when >> channel >> message >> data; 1540 stream >> when >> channel >> message >> data;
1541 AlarmServer::deleteAlarm( when, channel, message, data ); 1541 AlarmServer::deleteAlarm( when, channel, message, data );
1542 } 1542 }
1543 } 1543 }
1544 else if ( msg == "clockChange(bool)" ) { 1544 else if ( msg == "clockChange(bool)" ) {
1545 int tmp; 1545 int tmp;
1546 stream >> tmp; 1546 stream >> tmp;
1547 emit clockChanged( tmp ); 1547 emit clockChanged( tmp );
1548 } 1548 }
1549 else if ( msg == "weekChange(bool)" ) { 1549 else if ( msg == "weekChange(bool)" ) {
1550 int tmp; 1550 int tmp;
1551 stream >> tmp; 1551 stream >> tmp;
1552 emit weekChanged( tmp ); 1552 emit weekChanged( tmp );
1553 } 1553 }
1554 else if ( msg == "setDateFormat(DateFormat)" ) { 1554 else if ( msg == "setDateFormat(DateFormat)" ) {
1555 DateFormat tmp; 1555 DateFormat tmp;
1556 stream >> tmp; 1556 stream >> tmp;
1557 emit dateFormatChanged( tmp ); 1557 emit dateFormatChanged( tmp );
1558 } 1558 }
1559 else if ( msg == "setVolume(int,int)" ) { 1559 else if ( msg == "setVolume(int,int)" ) {
1560 int t, v; 1560 int t, v;
1561 stream >> t >> v; 1561 stream >> t >> v;
1562 setVolume( t, v ); 1562 setVolume( t, v );
1563 emit volumeChanged( muted ); 1563 emit volumeChanged( muted );
1564 } 1564 }
1565 else if ( msg == "volumeChange(bool)" ) { 1565 else if ( msg == "volumeChange(bool)" ) {
1566 stream >> muted; 1566 stream >> muted;
1567 setVolume(); 1567 setVolume();
1568 emit volumeChanged( muted ); 1568 emit volumeChanged( muted );
1569 } 1569 }
1570 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1570 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1571 int t, v; 1571 int t, v;
1572 stream >> t >> v; 1572 stream >> t >> v;
1573 setMic( t, v ); 1573 setMic( t, v );
1574 emit micChanged( micMuted ); 1574 emit micChanged( micMuted );
1575 } 1575 }
1576 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1576 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1577 stream >> micMuted; 1577 stream >> micMuted;
1578 setMic(); 1578 setMic();
1579 emit micChanged( micMuted ); 1579 emit micChanged( micMuted );
1580 } 1580 }
1581 else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1581 else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1582 int t, v; 1582 int t, v;
1583 stream >> t >> v; 1583 stream >> t >> v;
1584 setBass( t, v ); 1584 setBass( t, v );
1585 } 1585 }
1586 else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1586 else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1587 setBass(); 1587 setBass();
1588 } 1588 }
1589 else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1589 else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1590 int t, v; 1590 int t, v;
1591 stream >> t >> v; 1591 stream >> t >> v;
1592 setTreble( t, v ); 1592 setTreble( t, v );
1593 } 1593 }
1594 else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1594 else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1595 setTreble(); 1595 setTreble();
1596 } else if ( msg == "getMarkedText()" ) { 1596 } else if ( msg == "getMarkedText()" ) {
1597 if ( type() == GuiServer ) { 1597 if ( type() == GuiServer ) {
1598 const ushort unicode = 'C'-'@'; 1598 const ushort unicode = 'C'-'@';
1599 const int scan = Key_C; 1599 const int scan = Key_C;
1600 qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE ); 1600 qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE );
1601 qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE ); 1601 qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE );
1602 } 1602 }
1603 } else if ( msg == "newChannel(QString)") { 1603 } else if ( msg == "newChannel(QString)") {
1604 QString myChannel = "QPE/Application/" + d->appName; 1604 QString myChannel = "QPE/Application/" + d->appName;
1605 QString channel; 1605 QString channel;
1606 stream >> channel; 1606 stream >> channel;
1607 if (channel == myChannel) { 1607 if (channel == myChannel) {
1608 processQCopFile(); 1608 processQCopFile();
1609 d->sendQCopQ(); 1609 d->sendQCopQ();
1610 } 1610 }
1611 } 1611 }
1612 1612
1613 1613
1614#endif 1614#endif
1615} 1615}
1616 1616
1617 1617
1618 1618
1619 1619
1620 1620
1621/*! 1621/*!
1622 \internal 1622 \internal
1623*/ 1623*/
1624bool QPEApplication::raiseAppropriateWindow() 1624bool QPEApplication::raiseAppropriateWindow()
1625{ 1625{
1626 bool r=FALSE; 1626 bool r=FALSE;
1627 1627
1628 // 1. Raise the main widget 1628 // 1. Raise the main widget
1629 QWidget *top = d->qpe_main_widget; 1629 QWidget *top = d->qpe_main_widget;
1630 if ( !top ) top = mainWidget(); 1630 if ( !top ) top = mainWidget();
1631 1631
1632 if ( top && d->keep_running ) { 1632 if ( top && d->keep_running ) {
1633 if ( top->isVisible() ) 1633 if ( top->isVisible() )
1634 r = TRUE; 1634 r = TRUE;
1635 else if (d->preloaded) { 1635 else if (d->preloaded) {
1636 // We are preloaded and not visible.. pretend we just started.. 1636 // We are preloaded and not visible.. pretend we just started..
1637#ifndef QT_NO_COP 1637#ifndef QT_NO_COP
1638 QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); 1638 QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
1639 e << d->appName; 1639 e << d->appName;
1640#endif 1640#endif
1641 } 1641 }
1642 1642
1643 d->show_mx(top,d->nomaximize, d->appName); 1643 d->show_mx(top,d->nomaximize, d->appName);
1644 top->raise(); 1644 top->raise();
1645 } 1645 }
1646 1646
1647 QWidget *topm = activeModalWidget(); 1647 QWidget *topm = activeModalWidget();
1648 1648
1649 // 2. Raise any parentless widgets (except top and topm, as they 1649 // 2. Raise any parentless widgets (except top and topm, as they
1650 // are raised before and after this loop). Order from most 1650 // are raised before and after this loop). Order from most
1651 // recently raised as deepest to least recently as top, so 1651 // recently raised as deepest to least recently as top, so
1652 // that repeated calls cycle through widgets. 1652 // that repeated calls cycle through widgets.
1653 QWidgetList *list = topLevelWidgets(); 1653 QWidgetList *list = topLevelWidgets();
1654 if ( list ) { 1654 if ( list ) {
1655 bool foundlast = FALSE; 1655 bool foundlast = FALSE;
1656 QWidget* topsub = 0; 1656 QWidget* topsub = 0;
1657 if ( d->lastraised ) { 1657 if ( d->lastraised ) {
1658 for (QWidget* w = list->first(); w; w = list->next()) { 1658 for (QWidget* w = list->first(); w; w = list->next()) {
1659 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) { 1659 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) {
1660 if ( w == d->lastraised ) 1660 if ( w == d->lastraised )
1661 foundlast = TRUE; 1661 foundlast = TRUE;
1662 if ( foundlast ) { 1662 if ( foundlast ) {
1663 w->raise(); 1663 w->raise();
1664 topsub = w; 1664 topsub = w;
1665 } 1665 }
1666 } 1666 }
1667 } 1667 }
1668 } 1668 }
1669 for (QWidget* w = list->first(); w; w = list->next()) { 1669 for (QWidget* w = list->first(); w; w = list->next()) {
1670 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) { 1670 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) {
1671 if ( w == d->lastraised ) 1671 if ( w == d->lastraised )
1672 break; 1672 break;
1673 w->raise(); 1673 w->raise();
1674 topsub = w; 1674 topsub = w;
1675 } 1675 }
1676 } 1676 }
1677 d->lastraised = topsub; 1677 d->lastraised = topsub;
1678 delete list; 1678 delete list;
1679 } 1679 }
1680 1680
1681 // 3. Raise the active modal widget. 1681 // 3. Raise the active modal widget.
1682 if ( topm ) { 1682 if ( topm ) {
1683 topm->show(); 1683 topm->show();
1684 topm->raise(); 1684 topm->raise();
1685 // If we haven't already handled the fastAppShowing message 1685 // If we haven't already handled the fastAppShowing message
1686 if (!top && d->preloaded) { 1686 if (!top && d->preloaded) {
1687#ifndef QT_NO_COP 1687#ifndef QT_NO_COP
1688 QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); 1688 QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
1689 e << d->appName; 1689 e << d->appName;
1690#endif 1690#endif
1691 } 1691 }
1692 r = FALSE; 1692 r = FALSE;
1693 } 1693 }
1694 1694
1695 return r; 1695 return r;
1696} 1696}
1697 1697
1698 1698
1699void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data) 1699void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data)
1700{ 1700{
1701#ifdef Q_WS_QWS 1701#ifdef Q_WS_QWS
1702 1702
1703 if ( msg == "quit()" ) { 1703 if ( msg == "quit()" ) {
1704 tryQuit(); 1704 tryQuit();
1705 } 1705 }
1706 else if ( msg == "quitIfInvisible()" ) { 1706 else if ( msg == "quitIfInvisible()" ) {
1707 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() ) 1707 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() )
1708 quit(); 1708 quit();
1709 } 1709 }
1710 else if ( msg == "close()" ) { 1710 else if ( msg == "close()" ) {
1711 hideOrQuit(); 1711 hideOrQuit();
1712 } 1712 }
1713 else if ( msg == "disablePreload()" ) { 1713 else if ( msg == "disablePreload()" ) {
1714 d->preloaded = FALSE; 1714 d->preloaded = FALSE;
1715 d->keep_running = TRUE; 1715 d->keep_running = TRUE;
1716 /* so that quit will quit */ 1716 /* so that quit will quit */
1717 } 1717 }
1718 else if ( msg == "enablePreload()" ) { 1718 else if ( msg == "enablePreload()" ) {
1719 if (d->qpe_main_widget) 1719 if (d->qpe_main_widget)
1720 d->preloaded = TRUE; 1720 d->preloaded = TRUE;
1721 d->keep_running = TRUE; 1721 d->keep_running = TRUE;
1722 /* so next quit won't quit */ 1722 /* so next quit won't quit */
1723 } 1723 }
1724 else if ( msg == "raise()" ) { 1724 else if ( msg == "raise()" ) {
1725 d->keep_running = TRUE; 1725 d->keep_running = TRUE;
1726 d->notbusysent = FALSE; 1726 d->notbusysent = FALSE;
1727 raiseAppropriateWindow(); 1727 raiseAppropriateWindow();
1728 // Tell the system we're still chugging along... 1728 // Tell the system we're still chugging along...
1729 QCopEnvelope e("QPE/System", "appRaised(QString)"); 1729 QCopEnvelope e("QPE/System", "appRaised(QString)");
1730 e << d->appName; 1730 e << d->appName;
1731 } 1731 }
1732 else if ( msg == "flush()" ) { 1732 else if ( msg == "flush()" ) {
1733 emit flush(); 1733 emit flush();
1734 // we need to tell the desktop 1734 // we need to tell the desktop
1735 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); 1735 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" );
1736 e << d->appName; 1736 e << d->appName;
1737 } 1737 }
1738 else if ( msg == "reload()" ) { 1738 else if ( msg == "reload()" ) {
1739 emit reload(); 1739 emit reload();
1740 } 1740 }
1741 else if ( msg == "setDocument(QString)" ) { 1741 else if ( msg == "setDocument(QString)" ) {
1742 d->keep_running = TRUE; 1742 d->keep_running = TRUE;
1743 QDataStream stream( data, IO_ReadOnly ); 1743 QDataStream stream( data, IO_ReadOnly );
1744 QString doc; 1744 QString doc;
1745 stream >> doc; 1745 stream >> doc;
1746 QWidget *mw = mainWidget(); 1746 QWidget *mw = mainWidget();
1747 if ( !mw ) 1747 if ( !mw )
1748 mw = d->qpe_main_widget; 1748 mw = d->qpe_main_widget;
1749 if ( mw ) 1749 if ( mw )
1750 Global::setDocument( mw, doc ); 1750 Global::setDocument( mw, doc );
1751 1751
1752 } else if ( msg == "QPEProcessQCop()" ) { 1752 } else if ( msg == "QPEProcessQCop()" ) {
1753 processQCopFile(); 1753 processQCopFile();
1754 d->sendQCopQ(); 1754 d->sendQCopQ();
1755 }else 1755 }else
1756 { 1756 {
1757 bool p = d->keep_running; 1757 bool p = d->keep_running;
1758 d->keep_running = FALSE; 1758 d->keep_running = FALSE;
1759 emit appMessage( msg, data); 1759 emit appMessage( msg, data);
1760 if ( d->keep_running ) { 1760 if ( d->keep_running ) {
1761 d->notbusysent = FALSE; 1761 d->notbusysent = FALSE;
1762 raiseAppropriateWindow(); 1762 raiseAppropriateWindow();
1763 if ( !p ) { 1763 if ( !p ) {
1764 // Tell the system we're still chugging along... 1764 // Tell the system we're still chugging along...
1765#ifndef QT_NO_COP 1765#ifndef QT_NO_COP
1766 QCopEnvelope e("QPE/System", "appRaised(QString)"); 1766 QCopEnvelope e("QPE/System", "appRaised(QString)");
1767 e << d->appName; 1767 e << d->appName;
1768#endif 1768#endif
1769 } 1769 }
1770 } 1770 }
1771 if ( p ) 1771 if ( p )
1772 d->keep_running = p; 1772 d->keep_running = p;
1773 } 1773 }
1774#endif 1774#endif
1775} 1775}
1776 1776
1777 1777
1778/*! 1778/*!
1779 Sets widget \a mw as the mainWidget() and shows it. For small windows, 1779 Sets widget \a mw as the mainWidget() and shows it. For small windows,
1780 consider passing TRUE for \a nomaximize rather than the default FALSE. 1780 consider passing TRUE for \a nomaximize rather than the default FALSE.
1781 1781
1782 \sa showMainDocumentWidget() 1782 \sa showMainDocumentWidget()
1783*/ 1783*/
1784void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) 1784void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize )
1785{ 1785{
1786// setMainWidget(mw); this breaks FastLoading because lastWindowClose() would quit 1786// setMainWidget(mw); this breaks FastLoading because lastWindowClose() would quit
1787 d->show(mw, nomaximize ); 1787 d->show(mw, nomaximize );
1788} 1788}
1789 1789
1790/*! 1790/*!
1791 Sets widget \a mw as the mainWidget() and shows it. For small windows, 1791 Sets widget \a mw as the mainWidget() and shows it. For small windows,
1792 consider passing TRUE for \a nomaximize rather than the default FALSE. 1792 consider passing TRUE for \a nomaximize rather than the default FALSE.
1793 1793
1794 This calls designates the application as 1794 This calls designates the application as
1795 a \link docwidget.html document-oriented\endlink application. 1795 a \link docwidget.html document-oriented\endlink application.
1796 1796
1797 The \a mw widget \e must have this slot: setDocument(const QString&). 1797 The \a mw widget \e must have this slot: setDocument(const QString&).
1798 1798
1799 \sa showMainWidget() 1799 \sa showMainWidget()
1800*/ 1800*/
1801void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ) 1801void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize )
1802{ 1802{
1803 if ( mw && argc() == 2 ) 1803 if ( mw && argc() == 2 )
1804 Global::setDocument( mw, QString::fromUtf8(argv()[1]) ); 1804 Global::setDocument( mw, QString::fromUtf8(argv()[1]) );
1805 1805
1806 1806
1807// setMainWidget(mw); see above 1807// setMainWidget(mw); see above
1808 d->show(mw, nomaximize ); 1808 d->show(mw, nomaximize );
1809} 1809}
1810 1810
1811 1811
1812/*! 1812/*!
1813 If an application is started via a \link qcop.html QCop\endlink 1813 If an application is started via a \link qcop.html QCop\endlink
1814 message, the application will process the \link qcop.html 1814 message, the application will process the \link qcop.html
1815 QCop\endlink message and then quit. If the application calls this 1815 QCop\endlink message and then quit. If the application calls this
1816 function while processing a \link qcop.html QCop\endlink message, 1816 function while processing a \link qcop.html QCop\endlink message,
1817 after processing its outstanding \link qcop.html QCop\endlink 1817 after processing its outstanding \link qcop.html QCop\endlink
1818 messages the application will start 'properly' and show itself. 1818 messages the application will start 'properly' and show itself.
1819 1819
1820 \sa keepRunning() 1820 \sa keepRunning()
1821*/ 1821*/
1822void QPEApplication::setKeepRunning() 1822void QPEApplication::setKeepRunning()
1823{ 1823{
1824 if ( qApp && qApp->inherits( "QPEApplication" ) ) { 1824 if ( qApp && qApp->inherits( "QPEApplication" ) ) {
1825 QPEApplication * qpeApp = ( QPEApplication* ) qApp; 1825 QPEApplication * qpeApp = ( QPEApplication* ) qApp;
1826 qpeApp->d->keep_running = TRUE; 1826 qpeApp->d->keep_running = TRUE;
1827 } 1827 }
1828} 1828}
1829 1829
1830/*! 1830/*!
1831 Returns TRUE if the application will quit after processing the 1831 Returns TRUE if the application will quit after processing the
1832 current list of qcop messages; otherwise returns FALSE. 1832 current list of qcop messages; otherwise returns FALSE.
1833 1833
1834 \sa setKeepRunning() 1834 \sa setKeepRunning()
1835*/ 1835*/
1836bool QPEApplication::keepRunning() const 1836bool QPEApplication::keepRunning() const
1837{ 1837{
1838 return d->keep_running; 1838 return d->keep_running;
1839} 1839}
1840 1840
1841/*! 1841/*!
1842 \internal 1842 \internal
1843*/ 1843*/
1844void QPEApplication::internalSetStyle( const QString &style ) 1844void QPEApplication::internalSetStyle( const QString &style )
1845{ 1845{
1846#if QT_VERSION >= 300 1846#if QT_VERSION >= 0x030000
1847 if ( style == "QPE" ) { 1847 if ( style == "QPE" ) {
1848 setStyle( new QPEStyle ); 1848 setStyle( new QPEStyle );
1849 } 1849 }
1850 else { 1850 else {
1851 QStyle *s = QStyleFactory::create( style ); 1851 QStyle *s = QStyleFactory::create( style );
1852 if ( s ) 1852 if ( s )
1853 setStyle( s ); 1853 setStyle( s );
1854 } 1854 }
1855#else 1855#else
1856 if ( style == "Windows" ) { 1856 if ( style == "Windows" ) {
1857 setStyle( new QWindowsStyle ); 1857 setStyle( new QWindowsStyle );
1858 } 1858 }
1859 else if ( style == "QPE" ) { 1859 else if ( style == "QPE" ) {
1860 setStyle( new QPEStyle ); 1860 setStyle( new QPEStyle );
1861 } 1861 }
1862 else if ( style == "Light" ) { 1862 else if ( style == "Light" ) {
1863 setStyle( new LightStyle ); 1863 setStyle( new LightStyle );
1864 } 1864 }
1865#ifndef QT_NO_STYLE_PLATINUM 1865#ifndef QT_NO_STYLE_PLATINUM
1866 else if ( style == "Platinum" ) { 1866 else if ( style == "Platinum" ) {
1867 setStyle( new QPlatinumStyle ); 1867 setStyle( new QPlatinumStyle );
1868 } 1868 }
1869#endif 1869#endif
1870#ifndef QT_NO_STYLE_MOTIF 1870#ifndef QT_NO_STYLE_MOTIF
1871 else if ( style == "Motif" ) { 1871 else if ( style == "Motif" ) {
1872 setStyle( new QMotifStyle ); 1872 setStyle( new QMotifStyle );
1873 } 1873 }
1874#endif 1874#endif
1875#ifndef QT_NO_STYLE_MOTIFPLUS 1875#ifndef QT_NO_STYLE_MOTIFPLUS
1876 else if ( style == "MotifPlus" ) { 1876 else if ( style == "MotifPlus" ) {
1877 setStyle( new QMotifPlusStyle ); 1877 setStyle( new QMotifPlusStyle );
1878 } 1878 }
1879#endif 1879#endif
1880 1880
1881 else { 1881 else {
1882 QStyle *sty = 0; 1882 QStyle *sty = 0;
1883 QString path = QPEApplication::qpeDir ( ) + "plugins/styles/"; 1883 QString path = QPEApplication::qpeDir ( ) + "plugins/styles/";
1884 1884
1885#ifdef Q_OS_MACX 1885#ifdef Q_OS_MACX
1886 if ( style. find ( ".dylib" ) > 0 ) 1886 if ( style. find ( ".dylib" ) > 0 )
1887 path += style; 1887 path += style;
1888 else 1888 else
1889 path = path + "lib" + style. lower ( ) + ".dylib"; // compatibility 1889 path = path + "lib" + style. lower ( ) + ".dylib"; // compatibility
1890#else 1890#else
1891 if ( style. find ( ".so" ) > 0 ) 1891 if ( style. find ( ".so" ) > 0 )
1892 path += style; 1892 path += style;
1893 else 1893 else
1894 path = path + "lib" + style. lower ( ) + ".so"; // compatibility 1894 path = path + "lib" + style. lower ( ) + ".so"; // compatibility
1895#endif 1895#endif
1896 static QLibrary *lastlib = 0; 1896 static QLibrary *lastlib = 0;
1897 static StyleInterface *lastiface = 0; 1897 static StyleInterface *lastiface = 0;
1898 1898
1899 QLibrary *lib = new QLibrary ( path ); 1899 QLibrary *lib = new QLibrary ( path );
1900 StyleInterface *iface = 0; 1900 StyleInterface *iface = 0;
1901 1901
1902 if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface ) 1902 if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface )
1903 sty = iface-> style ( ); 1903 sty = iface-> style ( );
1904 1904
1905 if ( sty ) { 1905 if ( sty ) {
1906 setStyle ( sty ); 1906 setStyle ( sty );
1907 1907
1908 if ( lastiface ) 1908 if ( lastiface )
1909 lastiface-> release ( ); 1909 lastiface-> release ( );
1910 lastiface = iface; 1910 lastiface = iface;
1911 1911
1912 if ( lastlib ) { 1912 if ( lastlib ) {
1913 lastlib-> unload ( ); 1913 lastlib-> unload ( );
1914 delete lastlib; 1914 delete lastlib;
1915 } 1915 }
1916 lastlib = lib; 1916 lastlib = lib;
1917 } 1917 }
1918 else { 1918 else {
1919 if ( iface ) 1919 if ( iface )
1920 iface-> release ( ); 1920 iface-> release ( );
1921 delete lib; 1921 delete lib;
1922 1922
1923 setStyle ( new LightStyle ( )); 1923 setStyle ( new LightStyle ( ));
1924 } 1924 }
1925 } 1925 }
1926#endif 1926#endif
1927} 1927}
1928 1928
1929/*! 1929/*!
1930 \internal 1930 \internal
1931*/ 1931*/
1932void QPEApplication::prepareForTermination( bool willrestart ) 1932void QPEApplication::prepareForTermination( bool willrestart )
1933{ 1933{
1934 if ( willrestart ) { 1934 if ( willrestart ) {
1935 QLabel *lblWait = new QLabel( tr( "Please wait..." ), 0, "wait hack", QWidget::WStyle_Customize | 1935 QLabel *lblWait = new QLabel( tr( "Please wait..." ), 0, "wait hack", QWidget::WStyle_Customize |
1936 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); 1936 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool );
1937 lblWait->setAlignment( QWidget::AlignCenter ); 1937 lblWait->setAlignment( QWidget::AlignCenter );
1938 lblWait->show(); 1938 lblWait->show();
1939 lblWait->showMaximized(); 1939 lblWait->showMaximized();
1940 } 1940 }
1941 { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); 1941 { QCopEnvelope envelope( "QPE/System", "forceQuit()" );
1942 } 1942 }
1943 processEvents(); // ensure the message goes out. 1943 processEvents(); // ensure the message goes out.
1944} 1944}
1945 1945
1946/*! 1946/*!
1947 \internal 1947 \internal
1948*/ 1948*/
1949void QPEApplication::shutdown() 1949void QPEApplication::shutdown()
1950{ 1950{
1951 // Implement in server's QPEApplication subclass 1951 // Implement in server's QPEApplication subclass
1952} 1952}
1953 1953
1954/*! 1954/*!
1955 \internal 1955 \internal
1956*/ 1956*/
1957void QPEApplication::restart() 1957void QPEApplication::restart()
1958{ 1958{
1959 // Implement in server's QPEApplication subclass 1959 // Implement in server's QPEApplication subclass
1960} 1960}
1961 1961
1962static QPtrDict<void>* stylusDict = 0; 1962static QPtrDict<void>* stylusDict = 0;
1963static void createDict() 1963static void createDict()
1964{ 1964{
1965 if ( !stylusDict ) 1965 if ( !stylusDict )
1966 stylusDict = new QPtrDict<void>; 1966 stylusDict = new QPtrDict<void>;
1967} 1967}
1968 1968
1969/*! 1969/*!
1970 Returns the current StylusMode for widget \a w. 1970 Returns the current StylusMode for widget \a w.
1971 1971
1972 \sa setStylusOperation() StylusMode 1972 \sa setStylusOperation() StylusMode
1973*/ 1973*/
1974QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w ) 1974QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w )
1975{ 1975{
1976 if ( stylusDict ) 1976 if ( stylusDict )
1977 return ( StylusMode ) ( int ) stylusDict->find( w ); 1977 return ( StylusMode ) ( int ) stylusDict->find( w );
1978 return LeftOnly; 1978 return LeftOnly;
1979} 1979}
1980 1980
1981/*! 1981/*!
1982 \enum QPEApplication::StylusMode 1982 \enum QPEApplication::StylusMode
1983 1983
1984 \value LeftOnly the stylus only generates LeftButton 1984 \value LeftOnly the stylus only generates LeftButton
1985 events (the default). 1985 events (the default).
1986 \value RightOnHold the stylus generates RightButton events 1986 \value RightOnHold the stylus generates RightButton events
1987 if the user uses the press-and-hold gesture. 1987 if the user uses the press-and-hold gesture.
1988 1988
1989 \sa setStylusOperation() stylusOperation() 1989 \sa setStylusOperation() stylusOperation()
1990*/ 1990*/
1991 1991
1992/*! 1992/*!
1993 Causes widget \a w to receive mouse events according to the stylus 1993 Causes widget \a w to receive mouse events according to the stylus
1994 \a mode. 1994 \a mode.
1995 1995
1996 \sa stylusOperation() StylusMode 1996 \sa stylusOperation() StylusMode
1997*/ 1997*/
1998void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode ) 1998void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode )
1999{ 1999{
2000 createDict(); 2000 createDict();
2001 if ( mode == LeftOnly ) { 2001 if ( mode == LeftOnly ) {
2002 stylusDict->remove 2002 stylusDict->remove
2003 ( w ); 2003 ( w );
2004 w->removeEventFilter( qApp ); 2004 w->removeEventFilter( qApp );
2005 } 2005 }
2006 else { 2006 else {
2007 stylusDict->insert( w, ( void* ) mode ); 2007 stylusDict->insert( w, ( void* ) mode );
2008 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) ); 2008 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) );
2009 w->installEventFilter( qApp ); 2009 w->installEventFilter( qApp );
2010 } 2010 }
2011} 2011}
2012 2012
2013 2013
2014/*! 2014/*!
2015 \reimp 2015 \reimp
2016*/ 2016*/
2017bool QPEApplication::eventFilter( QObject *o, QEvent *e ) 2017bool QPEApplication::eventFilter( QObject *o, QEvent *e )
2018{ 2018{
2019 if ( !o->isWidgetType() ) 2019 if ( !o->isWidgetType() )
2020 return FALSE; 2020 return FALSE;
2021 2021
2022 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { 2022 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) {
2023 QMouseEvent * me = ( QMouseEvent* ) e; 2023 QMouseEvent * me = ( QMouseEvent* ) e;
2024 StylusMode mode = (StylusMode)(int)stylusDict->find(o); 2024 StylusMode mode = (StylusMode)(int)stylusDict->find(o);
2025 switch (mode) { 2025 switch (mode) {
2026 case RightOnHold: 2026 case RightOnHold:
2027 switch ( me->type() ) { 2027 switch ( me->type() ) {
2028 case QEvent::MouseButtonPress: 2028 case QEvent::MouseButtonPress:
2029 if ( me->button() == LeftButton ) { 2029 if ( me->button() == LeftButton ) {
2030 static long Pref = 500; // #### pref. 2030 static long Pref = 500; // #### pref.
2031 d->presswidget = (QWidget*)o; 2031 d->presswidget = (QWidget*)o;
2032 d->presspos = me->pos(); 2032 d->presspos = me->pos();
2033 d->rightpressed = FALSE; 2033 d->rightpressed = FALSE;
2034#ifdef OPIE_WITHROHFEEDBACK 2034#ifdef OPIE_WITHROHFEEDBACK
2035 if( ! d->RoH ) 2035 if( ! d->RoH )
2036 d->RoH = new Opie::Internal::RoHFeedback; 2036 d->RoH = new Opie::Internal::RoHFeedback;
2037 2037
2038 d->RoH->init( me->globalPos(), d->presswidget ); 2038 d->RoH->init( me->globalPos(), d->presswidget );
2039 Pref = d->RoH->delay(); 2039 Pref = d->RoH->delay();
2040 2040
2041#endif 2041#endif
2042 if (!d->presstimer ) 2042 if (!d->presstimer )
2043 d->presstimer = startTimer( Pref ); // #### pref. 2043 d->presstimer = startTimer( Pref ); // #### pref.
2044 2044
2045 } 2045 }
2046 break; 2046 break;
2047 case QEvent::MouseMove: 2047 case QEvent::MouseMove:
2048 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { 2048 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) {
2049 killTimer(d->presstimer); 2049 killTimer(d->presstimer);
2050#ifdef OPIE_WITHROHFEEDBACK 2050#ifdef OPIE_WITHROHFEEDBACK
2051 d->RoH->stop(); 2051 d->RoH->stop();
2052#endif 2052#endif
2053 d->presstimer = 0; 2053 d->presstimer = 0;
2054 } 2054 }
2055 break; 2055 break;
2056 case QEvent::MouseButtonRelease: 2056 case QEvent::MouseButtonRelease:
2057 if ( me->button() == LeftButton ) { 2057 if ( me->button() == LeftButton ) {
2058 if ( d->presstimer ) { 2058 if ( d->presstimer ) {
2059 killTimer(d->presstimer); 2059 killTimer(d->presstimer);
2060#ifdef OPIE_WITHROHFEEDBACK 2060#ifdef OPIE_WITHROHFEEDBACK
2061 d->RoH->stop( ); 2061 d->RoH->stop( );
2062#endif 2062#endif
2063 d->presstimer = 0; 2063 d->presstimer = 0;
2064 } 2064 }
2065 if ( d->rightpressed && d->presswidget ) { 2065 if ( d->rightpressed && d->presswidget ) {
2066 printf( "Send ButtonRelease\n" ); 2066 printf( "Send ButtonRelease\n" );
2067 // Right released 2067 // Right released
2068 postEvent( d->presswidget, 2068 postEvent( d->presswidget,
2069 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), 2069 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(),
2070 RightButton, LeftButton + RightButton ) ); 2070 RightButton, LeftButton + RightButton ) );
2071 // Left released, off-widget 2071 // Left released, off-widget
2072 postEvent( d->presswidget, 2072 postEvent( d->presswidget,
2073 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1), 2073 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1),
2074 LeftButton, LeftButton ) ); 2074 LeftButton, LeftButton ) );
2075 postEvent( d->presswidget, 2075 postEvent( d->presswidget,
2076 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1), 2076 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1),
2077 LeftButton, LeftButton ) ); 2077 LeftButton, LeftButton ) );
2078 d->rightpressed = FALSE; 2078 d->rightpressed = FALSE;
2079 return TRUE; // don't send the real Left release 2079 return TRUE; // don't send the real Left release
2080 } 2080 }
2081 } 2081 }
2082 break; 2082 break;
2083 default: 2083 default:
2084 break; 2084 break;
2085 } 2085 }
2086 break; 2086 break;
2087 default: 2087 default:
2088 ; 2088 ;
2089 } 2089 }
2090 } 2090 }
2091 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 2091 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
2092 QKeyEvent *ke = (QKeyEvent *)e; 2092 QKeyEvent *ke = (QKeyEvent *)e;
2093 if ( ke->key() == Key_Enter ) { 2093 if ( ke->key() == Key_Enter ) {
2094 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { 2094 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) {
2095 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', 2095 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ',
2096 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); 2096 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) );
2097 return TRUE; 2097 return TRUE;
2098 } 2098 }
2099 } 2099 }
2100 } 2100 }
2101 return FALSE; 2101 return FALSE;
2102} 2102}
2103 2103
2104/*! 2104/*!
2105 \reimp 2105 \reimp
2106*/ 2106*/
2107void QPEApplication::timerEvent( QTimerEvent *e ) 2107void QPEApplication::timerEvent( QTimerEvent *e )
2108{ 2108{
2109 if ( e->timerId() == d->presstimer && d->presswidget ) { 2109 if ( e->timerId() == d->presstimer && d->presswidget ) {
2110 2110
2111 // Right pressed 2111 // Right pressed
2112 postEvent( d->presswidget, 2112 postEvent( d->presswidget,
2113 new QMouseEvent( QEvent::MouseButtonPress, d->presspos, 2113 new QMouseEvent( QEvent::MouseButtonPress, d->presspos,
2114 RightButton, LeftButton ) ); 2114 RightButton, LeftButton ) );
2115 killTimer( d->presstimer ); 2115 killTimer( d->presstimer );
2116 d->presstimer = 0; 2116 d->presstimer = 0;
2117 d->rightpressed = TRUE; 2117 d->rightpressed = TRUE;
2118#ifdef OPIE_WITHROHFEEDBACK 2118#ifdef OPIE_WITHROHFEEDBACK
2119 d->RoH->stop(); 2119 d->RoH->stop();
2120#endif 2120#endif
2121 } 2121 }
2122} 2122}
2123 2123
2124void QPEApplication::removeSenderFromStylusDict() 2124void QPEApplication::removeSenderFromStylusDict()
2125{ 2125{
2126 stylusDict->remove 2126 stylusDict->remove
2127 ( ( void* ) sender() ); 2127 ( ( void* ) sender() );
2128 if ( d->presswidget == sender() ) 2128 if ( d->presswidget == sender() )
2129 d->presswidget = 0; 2129 d->presswidget = 0;
2130} 2130}
2131 2131
2132/*! 2132/*!
2133 \internal 2133 \internal
2134*/ 2134*/
2135bool QPEApplication::keyboardGrabbed() const 2135bool QPEApplication::keyboardGrabbed() const
2136{ 2136{
2137 return d->kbgrabbed; 2137 return d->kbgrabbed;
2138} 2138}
2139 2139
2140 2140
2141/*! 2141/*!
2142 Reverses the effect of grabKeyboard(). This is called automatically 2142 Reverses the effect of grabKeyboard(). This is called automatically
2143 on program exit. 2143 on program exit.
2144*/ 2144*/
2145void QPEApplication::ungrabKeyboard() 2145void QPEApplication::ungrabKeyboard()
2146{ 2146{
2147 ((QPEApplication *) qApp )-> d-> kbgrabbed = false; 2147 ((QPEApplication *) qApp )-> d-> kbgrabbed = false;
2148} 2148}
2149 2149
2150/*! 2150/*!
2151 Grabs the physical keyboard keys, e.g. the application's launching 2151 Grabs the physical keyboard keys, e.g. the application's launching
2152 keys. Instead of launching applications when these keys are pressed 2152 keys. Instead of launching applications when these keys are pressed
2153 the signals emitted are sent to this application instead. Some games 2153 the signals emitted are sent to this application instead. Some games
2154 programs take over the launch keys in this way to make interaction 2154 programs take over the launch keys in this way to make interaction
2155 easier. 2155 easier.
2156 2156
2157 \sa ungrabKeyboard() 2157 \sa ungrabKeyboard()
2158*/ 2158*/
2159void QPEApplication::grabKeyboard() 2159void QPEApplication::grabKeyboard()
2160{ 2160{
2161 ((QPEApplication *) qApp )-> d-> kbgrabbed = true; 2161 ((QPEApplication *) qApp )-> d-> kbgrabbed = true;
2162} 2162}
2163 2163
2164/*! 2164/*!
2165 \reimp 2165 \reimp
2166*/ 2166*/
2167int QPEApplication::exec() 2167int QPEApplication::exec()
2168{ 2168{
2169 d->qcopQok = true; 2169 d->qcopQok = true;
2170#ifndef QT_NO_COP 2170#ifndef QT_NO_COP
2171 d->sendQCopQ(); 2171 d->sendQCopQ();
2172 if ( !d->keep_running ) 2172 if ( !d->keep_running )
2173 processEvents(); // we may have received QCop messages in the meantime. 2173 processEvents(); // we may have received QCop messages in the meantime.
2174#endif 2174#endif
2175 2175
2176 if ( d->keep_running ) 2176 if ( d->keep_running )
2177 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) 2177 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() )
2178 return QApplication::exec(); 2178 return QApplication::exec();
2179 2179
2180#ifndef QT_NO_COP 2180#ifndef QT_NO_COP
2181 2181
2182 { 2182 {
2183 QCopEnvelope e( "QPE/System", "closing(QString)" ); 2183 QCopEnvelope e( "QPE/System", "closing(QString)" );
2184 e << d->appName; 2184 e << d->appName;
2185 } 2185 }
2186#endif 2186#endif
2187 processEvents(); 2187 processEvents();
2188 return 0; 2188 return 0;
2189} 2189}
2190 2190
2191/*! 2191/*!
2192 \internal 2192 \internal
2193 External request for application to quit. Quits if possible without 2193 External request for application to quit. Quits if possible without
2194 loosing state. 2194 loosing state.
2195*/ 2195*/
2196void QPEApplication::tryQuit() 2196void QPEApplication::tryQuit()
2197{ 2197{
2198 if ( activeModalWidget() ) 2198 if ( activeModalWidget() )
2199 return ; // Inside modal loop or konsole. Too hard to save state. 2199 return ; // Inside modal loop or konsole. Too hard to save state.
2200#ifndef QT_NO_COP 2200#ifndef QT_NO_COP
2201 2201
2202 { 2202 {
2203 QCopEnvelope e( "QPE/System", "closing(QString)" ); 2203 QCopEnvelope e( "QPE/System", "closing(QString)" );
2204 e << d->appName; 2204 e << d->appName;
2205 } 2205 }
2206#endif 2206#endif
2207 if ( d->keep_running ) 2207 if ( d->keep_running )
2208 d->store_widget_rect(d->qpe_main_widget, d->appName); 2208 d->store_widget_rect(d->qpe_main_widget, d->appName);
2209 processEvents(); 2209 processEvents();
2210 2210
2211 quit(); 2211 quit();
2212} 2212}
2213 2213
2214 2214
2215/*! 2215/*!
2216 \internal 2216 \internal
2217 User initiated quit. Makes the window 'Go Away'. If preloaded this means 2217 User initiated quit. Makes the window 'Go Away'. If preloaded this means
2218 hiding the window. If not it means quitting the application. 2218 hiding the window. If not it means quitting the application.
2219 As this is user initiated we don't need to check state. 2219 As this is user initiated we don't need to check state.
2220*/ 2220*/
2221void QPEApplication::hideOrQuit() 2221void QPEApplication::hideOrQuit()
2222{ 2222{
2223 if ( d->keep_running ) 2223 if ( d->keep_running )
2224 d->store_widget_rect(d->qpe_main_widget, d->appName); 2224 d->store_widget_rect(d->qpe_main_widget, d->appName);
2225 processEvents(); 2225 processEvents();
2226 2226
2227 // If we are a preloaded application we don't actually quit, so emit 2227 // If we are a preloaded application we don't actually quit, so emit
2228 // a System message indicating we're quasi-closing. 2228 // a System message indicating we're quasi-closing.
2229 if ( d->preloaded && d->qpe_main_widget ) 2229 if ( d->preloaded && d->qpe_main_widget )
2230#ifndef QT_NO_COP 2230#ifndef QT_NO_COP
2231 2231
2232 { 2232 {
2233 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); 2233 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" );
2234 e << d->appName; 2234 e << d->appName;
2235 d->qpe_main_widget->hide(); 2235 d->qpe_main_widget->hide();
2236 } 2236 }
2237#endif 2237#endif
2238 else 2238 else
2239 quit(); 2239 quit();
2240} 2240}
2241 2241
2242#if (__GNUC__ > 2 ) 2242#if (__GNUC__ > 2 )
2243extern "C" void __cxa_pure_virtual(); 2243extern "C" void __cxa_pure_virtual();
2244 2244
2245void __cxa_pure_virtual() 2245void __cxa_pure_virtual()
2246{ 2246{
2247 fprintf( stderr, "Pure virtual called\n"); 2247 fprintf( stderr, "Pure virtual called\n");
2248 abort(); 2248 abort();
2249 2249
2250} 2250}
2251 2251
2252#endif 2252#endif
2253 2253
2254 2254
2255#if defined(OPIE_NEW_MALLOC) 2255#if defined(OPIE_NEW_MALLOC)
2256 2256
2257// The libraries with the skiff package (and possibly others) have 2257// The libraries with the skiff package (and possibly others) have
2258// completely useless implementations of builtin new and delete that 2258// completely useless implementations of builtin new and delete that
2259// use about 50% of your CPU. Here we revert to the simple libc 2259// use about 50% of your CPU. Here we revert to the simple libc
2260// functions. 2260// functions.
2261 2261
2262void* operator new[]( size_t size ) 2262void* operator new[]( size_t size )
2263{ 2263{
2264 return malloc( size ); 2264 return malloc( size );
2265} 2265}
2266 2266
2267void* operator new( size_t size ) 2267void* operator new( size_t size )
2268{ 2268{
2269 return malloc( size ); 2269 return malloc( size );
2270} 2270}
2271 2271
2272void operator delete[]( void* p ) 2272void operator delete[]( void* p )
2273{ 2273{
2274 if ( p ) 2274 if ( p )
2275 free( p ); 2275 free( p );
2276} 2276}
2277 2277
2278void operator delete[]( void* p, size_t /*size*/ ) 2278void operator delete[]( void* p, size_t /*size*/ )
2279{ 2279{
2280 if ( p ) 2280 if ( p )
2281 free( p ); 2281 free( p );
2282} 2282}
2283 2283
2284 2284
2285void operator delete( void* p ) 2285void operator delete( void* p )
2286{ 2286{
2287 if ( p ) 2287 if ( p )
2288 free( p ); 2288 free( p );
2289} 2289}
2290 2290
2291void operator delete( void* p, size_t /*size*/ ) 2291void operator delete( void* p, size_t /*size*/ )
2292{ 2292{
2293 if ( p ) 2293 if ( p )
2294 free( p ); 2294 free( p );
2295} 2295}
2296 2296
2297#endif 2297#endif
2298 2298
2299#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP) 2299#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP)
2300#include <qwidgetlist.h> 2300#include <qwidgetlist.h>
2301#ifdef QWS 2301#ifdef QWS
2302#include <qgfx_qws.h> 2302#include <qgfx_qws.h>
2303extern QRect qt_maxWindowRect; 2303extern QRect qt_maxWindowRect;
2304void qt_setMaxWindowRect(const QRect& r ) 2304void qt_setMaxWindowRect(const QRect& r )
2305{ 2305{
2306 qt_maxWindowRect = qt_screen->mapFromDevice( r, 2306 qt_maxWindowRect = qt_screen->mapFromDevice( r,
2307 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) ); 2307 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) );
2308 // Re-resize any maximized windows 2308 // Re-resize any maximized windows
2309 QWidgetList* l = QApplication::topLevelWidgets(); 2309 QWidgetList* l = QApplication::topLevelWidgets();
2310 if ( l ) { 2310 if ( l ) {
2311 QWidget * w = l->first(); 2311 QWidget * w = l->first();
2312 while ( w ) { 2312 while ( w ) {
2313 if ( w->isVisible() && w->isMaximized() ) { 2313 if ( w->isVisible() && w->isMaximized() ) {
2314 w->showMaximized(); 2314 w->showMaximized();
2315 } 2315 }
2316 w = l->next(); 2316 w = l->next();
2317 } 2317 }
2318 delete l; 2318 delete l;
2319 } 2319 }
2320} 2320}
2321#endif 2321#endif
2322#endif 2322#endif
diff --git a/library/qpestyle.cpp b/library/qpestyle.cpp
index b61ada4..0566f6b 100644
--- a/library/qpestyle.cpp
+++ b/library/qpestyle.cpp
@@ -1,1191 +1,1191 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "qpestyle.h" 21#include "qpestyle.h"
22 22
23 23
24#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2) 24#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
25 25
26#if QT_VERSION >= 300 26#if QT_VERSION >= 0x030000
27 27
28#include <qdrawutil.h> 28#include <qdrawutil.h>
29#include <qcombobox.h> 29#include <qcombobox.h>
30#include <qtabbar.h> 30#include <qtabbar.h>
31 31
32QPEStyle::QPEStyle() 32QPEStyle::QPEStyle()
33{ 33{
34} 34}
35 35
36QPEStyle::~QPEStyle() 36QPEStyle::~QPEStyle()
37{ 37{
38} 38}
39 39
40void QPEStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, const QRect &r, 40void QPEStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, const QRect &r,
41 const QColorGroup &cg, SFlags flags, const QStyleOption &data) const 41 const QColorGroup &cg, SFlags flags, const QStyleOption &data) const
42{ 42{
43 switch ( pe ) { 43 switch ( pe ) {
44 case PE_ButtonTool: 44 case PE_ButtonTool:
45 { 45 {
46 QColorGroup mycg = cg; 46 QColorGroup mycg = cg;
47 if ( flags & Style_On ) { 47 if ( flags & Style_On ) {
48 QBrush fill( cg.mid(), Dense4Pattern ); 48 QBrush fill( cg.mid(), Dense4Pattern );
49 mycg.setBrush( QColorGroup::Button, fill ); 49 mycg.setBrush( QColorGroup::Button, fill );
50 } 50 }
51 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data ); 51 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data );
52 break; 52 break;
53 } 53 }
54 case PE_ButtonCommand: 54 case PE_ButtonCommand:
55 case PE_ButtonDefault: 55 case PE_ButtonDefault:
56 case PE_ButtonBevel: 56 case PE_ButtonBevel:
57 case PE_HeaderSection: 57 case PE_HeaderSection:
58 { 58 {
59 QPen oldPen = p->pen(); 59 QPen oldPen = p->pen();
60 p->fillRect( r.x()+1, r.y()+1, r.width()-2, r.height()-2, cg.brush(QColorGroup::Button) ); 60 p->fillRect( r.x()+1, r.y()+1, r.width()-2, r.height()-2, cg.brush(QColorGroup::Button) );
61 61
62 int x2 = r.right(); 62 int x2 = r.right();
63 int y2 = r.bottom(); 63 int y2 = r.bottom();
64 64
65 if ( flags & (Style_Sunken | Style_Down | Style_On) ) 65 if ( flags & (Style_Sunken | Style_Down | Style_On) )
66 p->setPen( cg.dark() ); 66 p->setPen( cg.dark() );
67 else 67 else
68 p->setPen( cg.light() ); 68 p->setPen( cg.light() );
69 p->drawLine( r.x(), r.y()+1, r.x(), y2-1 ); 69 p->drawLine( r.x(), r.y()+1, r.x(), y2-1 );
70 p->drawLine( r.x()+1, r.y(), x2-1, r.y() ); 70 p->drawLine( r.x()+1, r.y(), x2-1, r.y() );
71 71
72 if ( flags & (Style_Sunken | Style_Down | Style_On) ) 72 if ( flags & (Style_Sunken | Style_Down | Style_On) )
73 p->setPen( cg.light() ); 73 p->setPen( cg.light() );
74 else 74 else
75 p->setPen( cg.dark() ); 75 p->setPen( cg.dark() );
76 p->drawLine( x2, r.y()+1, x2, y2-1 ); 76 p->drawLine( x2, r.y()+1, x2, y2-1 );
77 p->drawLine( r.x()+1, y2, x2-1, y2 ); 77 p->drawLine( r.x()+1, y2, x2-1, y2 );
78 p->setPen( oldPen ); 78 p->setPen( oldPen );
79 break; 79 break;
80 } 80 }
81 case PE_FocusRect: 81 case PE_FocusRect:
82 break; 82 break;
83 case PE_Indicator: 83 case PE_Indicator:
84 { 84 {
85 QColorGroup mycg( cg ); 85 QColorGroup mycg( cg );
86 QBrush fill; 86 QBrush fill;
87 if ( flags & Style_Down ) 87 if ( flags & Style_Down )
88 fill = cg.brush( QColorGroup::Button ); 88 fill = cg.brush( QColorGroup::Button );
89 else 89 else
90 fill = cg.brush( (flags&Style_Enabled) ? QColorGroup::Base : QColorGroup::Background ); 90 fill = cg.brush( (flags&Style_Enabled) ? QColorGroup::Base : QColorGroup::Background );
91 mycg.setBrush( QColorGroup::Button, fill ); 91 mycg.setBrush( QColorGroup::Button, fill );
92 if ( flags&Style_Enabled ) 92 if ( flags&Style_Enabled )
93 flags |= Style_Sunken; 93 flags |= Style_Sunken;
94 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags ); 94 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags );
95 if ( flags & Style_On ) { 95 if ( flags & Style_On ) {
96 QPointArray a( 7*2 ); 96 QPointArray a( 7*2 );
97 int i, xx, yy; 97 int i, xx, yy;
98 xx = r.x()+3; 98 xx = r.x()+3;
99 yy = r.y()+5; 99 yy = r.y()+5;
100 for ( i=0; i<3; i++ ) { 100 for ( i=0; i<3; i++ ) {
101 a.setPoint( 2*i, xx, yy ); 101 a.setPoint( 2*i, xx, yy );
102 a.setPoint( 2*i+1, xx, yy+2 ); 102 a.setPoint( 2*i+1, xx, yy+2 );
103 xx++; yy++; 103 xx++; yy++;
104 } 104 }
105 yy -= 2; 105 yy -= 2;
106 for ( i=3; i<7; i++ ) { 106 for ( i=3; i<7; i++ ) {
107 a.setPoint( 2*i, xx, yy ); 107 a.setPoint( 2*i, xx, yy );
108 a.setPoint( 2*i+1, xx, yy+2 ); 108 a.setPoint( 2*i+1, xx, yy+2 );
109 xx++; yy--; 109 xx++; yy--;
110 } 110 }
111 if ( flags & Style_NoChange ) { 111 if ( flags & Style_NoChange ) {
112 p->setPen( mycg.dark() ); 112 p->setPen( mycg.dark() );
113 } else { 113 } else {
114 p->setPen( mycg.text() ); 114 p->setPen( mycg.text() );
115 } 115 }
116 p->drawLineSegments( a ); 116 p->drawLineSegments( a );
117 } 117 }
118 break; 118 break;
119 } 119 }
120 case PE_ExclusiveIndicator: 120 case PE_ExclusiveIndicator:
121 { 121 {
122 static const QCOORD pts1[] = { // dark lines 122 static const QCOORD pts1[] = { // dark lines
123 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 }; 123 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
124 static const QCOORD pts4[] = { // white lines 124 static const QCOORD pts4[] = { // white lines
125 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7, 125 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
126 11,4, 10,3, 10,2 }; 126 11,4, 10,3, 10,2 };
127 static const QCOORD pts5[] = { // inner fill 127 static const QCOORD pts5[] = { // inner fill
128 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 }; 128 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
129 129
130 int x, y, w, h; 130 int x, y, w, h;
131 r.rect( &x, &y, &w, &h ); 131 r.rect( &x, &y, &w, &h );
132 p->eraseRect( x, y, w, h ); 132 p->eraseRect( x, y, w, h );
133 QPointArray a( QCOORDARRLEN(pts1), pts1 ); 133 QPointArray a( QCOORDARRLEN(pts1), pts1 );
134 a.translate( x, y ); 134 a.translate( x, y );
135 p->setPen( cg.dark() ); 135 p->setPen( cg.dark() );
136 p->drawPolyline( a ); 136 p->drawPolyline( a );
137 a.setPoints( QCOORDARRLEN(pts4), pts4 ); 137 a.setPoints( QCOORDARRLEN(pts4), pts4 );
138 a.translate( x, y ); 138 a.translate( x, y );
139 p->setPen( cg.light() ); 139 p->setPen( cg.light() );
140 p->drawPolyline( a ); 140 p->drawPolyline( a );
141 a.setPoints( QCOORDARRLEN(pts5), pts5 ); 141 a.setPoints( QCOORDARRLEN(pts5), pts5 );
142 a.translate( x, y ); 142 a.translate( x, y );
143 QColor fillColor = ( flags&Style_Down || !(flags&Style_Enabled) ) ? cg.button() : cg.base(); 143 QColor fillColor = ( flags&Style_Down || !(flags&Style_Enabled) ) ? cg.button() : cg.base();
144 p->setPen( fillColor ); 144 p->setPen( fillColor );
145 p->setBrush( fillColor ) ; 145 p->setBrush( fillColor ) ;
146 p->drawPolygon( a ); 146 p->drawPolygon( a );
147 if ( flags&Style_On ) { 147 if ( flags&Style_On ) {
148 p->setPen( NoPen ); 148 p->setPen( NoPen );
149 p->setBrush( cg.text() ); 149 p->setBrush( cg.text() );
150 p->drawRect( x+5, y+4, 2, 4 ); 150 p->drawRect( x+5, y+4, 2, 4 );
151 p->drawRect( x+4, y+5, 4, 2 ); 151 p->drawRect( x+4, y+5, 4, 2 );
152 } 152 }
153 break; 153 break;
154 } 154 }
155 default: 155 default:
156 QWindowsStyle::drawPrimitive( pe, p, r, cg, flags, data ); 156 QWindowsStyle::drawPrimitive( pe, p, r, cg, flags, data );
157 break; 157 break;
158 } 158 }
159} 159}
160 160
161void QPEStyle::drawControl( ControlElement ce, QPainter *p, 161void QPEStyle::drawControl( ControlElement ce, QPainter *p,
162 const QWidget *widget, const QRect &r, 162 const QWidget *widget, const QRect &r,
163 const QColorGroup &cg, SFlags how, const QStyleOption &data) const 163 const QColorGroup &cg, SFlags how, const QStyleOption &data) const
164{ 164{
165 switch ( ce ) { 165 switch ( ce ) {
166 case CE_PushButton: 166 case CE_PushButton:
167 { 167 {
168 const QPushButton *btn = (QPushButton*)widget; 168 const QPushButton *btn = (QPushButton*)widget;
169 SFlags flags; 169 SFlags flags;
170 flags = Style_Default; 170 flags = Style_Default;
171 if ( btn->isDown() ) 171 if ( btn->isDown() )
172 flags |= Style_Down; 172 flags |= Style_Down;
173 if ( btn->isOn() ) 173 if ( btn->isOn() )
174 flags |= Style_On; 174 flags |= Style_On;
175 if ( btn->isEnabled() ) 175 if ( btn->isEnabled() )
176 flags |= Style_Enabled; 176 flags |= Style_Enabled;
177 if ( btn->isDefault() ) 177 if ( btn->isDefault() )
178 flags |= Style_Default; 178 flags |= Style_Default;
179 if (! btn->isFlat() && !(flags & Style_Down)) 179 if (! btn->isFlat() && !(flags & Style_Down))
180 flags |= Style_Raised; 180 flags |= Style_Raised;
181 p->setPen( cg.foreground() ); 181 p->setPen( cg.foreground() );
182 p->setBrush( QBrush(cg.button(), NoBrush) ); 182 p->setBrush( QBrush(cg.button(), NoBrush) );
183 QColorGroup mycg( cg ); 183 QColorGroup mycg( cg );
184 if ( flags & Style_On ) { 184 if ( flags & Style_On ) {
185 QBrush fill = QBrush( cg.mid(), Dense4Pattern ); 185 QBrush fill = QBrush( cg.mid(), Dense4Pattern );
186 mycg.setBrush( QColorGroup::Button, fill ); 186 mycg.setBrush( QColorGroup::Button, fill );
187 } 187 }
188 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data ); 188 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data );
189 break; 189 break;
190 } 190 }
191 case CE_TabBarTab: 191 case CE_TabBarTab:
192 { 192 {
193 if ( !widget || !widget->parentWidget() ) 193 if ( !widget || !widget->parentWidget() )
194 break; 194 break;
195 195
196 const QTabBar *tb = (const QTabBar *) widget; 196 const QTabBar *tb = (const QTabBar *) widget;
197 bool selected = how & Style_Selected; 197 bool selected = how & Style_Selected;
198 198
199 QRect r2(r); 199 QRect r2(r);
200 if ( tb->shape() == QTabBar::RoundedAbove ) { 200 if ( tb->shape() == QTabBar::RoundedAbove ) {
201 p->setPen( cg.light() ); 201 p->setPen( cg.light() );
202 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() ); 202 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
203 if ( r2.left() == 0 ) 203 if ( r2.left() == 0 )
204 p->drawPoint( tb->rect().bottomLeft() ); 204 p->drawPoint( tb->rect().bottomLeft() );
205 else { 205 else {
206 p->setPen( cg.light() ); 206 p->setPen( cg.light() );
207 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() ); 207 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
208 } 208 }
209 209
210 if ( selected ) { 210 if ( selected ) {
211 p->setPen( cg.background() ); 211 p->setPen( cg.background() );
212 p->drawLine( r2.left()+2, r2.top()+1, r2.right()-2, r2.top()+1 ); 212 p->drawLine( r2.left()+2, r2.top()+1, r2.right()-2, r2.top()+1 );
213 p->fillRect( QRect( r2.left()+1, r2.top()+2, r2.width()-2, r2.height()-2), 213 p->fillRect( QRect( r2.left()+1, r2.top()+2, r2.width()-2, r2.height()-2),
214 cg.brush( QColorGroup::Background )); 214 cg.brush( QColorGroup::Background ));
215 } else { 215 } else {
216 r2.setRect( r2.left() + 2, r2.top() + 2, 216 r2.setRect( r2.left() + 2, r2.top() + 2,
217 r2.width() - 4, r2.height() - 2 ); 217 r2.width() - 4, r2.height() - 2 );
218 p->setPen( cg.button() ); 218 p->setPen( cg.button() );
219 p->drawLine( r2.left()+2, r2.top()+1, r2.right()-2, r2.top()+1 ); 219 p->drawLine( r2.left()+2, r2.top()+1, r2.right()-2, r2.top()+1 );
220 p->fillRect( QRect( r2.left()+1, r2.top()+2, r2.width()-2, r2.height()-3), 220 p->fillRect( QRect( r2.left()+1, r2.top()+2, r2.width()-2, r2.height()-3),
221 cg.brush( QColorGroup::Button )); 221 cg.brush( QColorGroup::Button ));
222 222
223 //do shading; will not work for pixmap brushes 223 //do shading; will not work for pixmap brushes
224 QColor bg = cg.button(); 224 QColor bg = cg.button();
225 // int h,s,v; 225 // int h,s,v;
226 // bg.hsv( &h, &s, &v ); 226 // bg.hsv( &h, &s, &v );
227 int n = r2.height()/2; 227 int n = r2.height()/2;
228 int dark = 100; 228 int dark = 100;
229 for ( int i = 1; i < n; i++ ) { 229 for ( int i = 1; i < n; i++ ) {
230 dark = (dark * (100+(i*15)/n) )/100; 230 dark = (dark * (100+(i*15)/n) )/100;
231 p->setPen( bg.dark( dark ) ); 231 p->setPen( bg.dark( dark ) );
232 int y = r2.bottom()-n+i; 232 int y = r2.bottom()-n+i;
233 int x1 = r2.left()+1; 233 int x1 = r2.left()+1;
234 int x2 = r2.right()-1; 234 int x2 = r2.right()-1;
235 p->drawLine( x1, y, x2, y ); 235 p->drawLine( x1, y, x2, y );
236 } 236 }
237 } 237 }
238 238
239 p->setPen( cg.light() ); 239 p->setPen( cg.light() );
240 p->drawLine( r2.left(), r2.bottom()-1, r2.left(), r2.top() + 2 ); 240 p->drawLine( r2.left(), r2.bottom()-1, r2.left(), r2.top() + 2 );
241 p->drawPoint( r2.left()+1, r2.top() + 1 ); 241 p->drawPoint( r2.left()+1, r2.top() + 1 );
242 p->drawLine( r2.left()+2, r2.top(), 242 p->drawLine( r2.left()+2, r2.top(),
243 r2.right() - 2, r2.top() ); 243 r2.right() - 2, r2.top() );
244 244
245 p->setPen( cg.dark() ); 245 p->setPen( cg.dark() );
246 p->drawPoint( r2.right() - 1, r2.top() + 1 ); 246 p->drawPoint( r2.right() - 1, r2.top() + 1 );
247 p->drawLine( r2.right(), r2.top() + 2, r2.right(), r2.bottom() - 1); 247 p->drawLine( r2.right(), r2.top() + 2, r2.right(), r2.bottom() - 1);
248 } else if ( tb->shape() == QTabBar::RoundedBelow ) { 248 } else if ( tb->shape() == QTabBar::RoundedBelow ) {
249 if ( selected ) { 249 if ( selected ) {
250 p->setPen( cg.background() ); 250 p->setPen( cg.background() );
251 p->drawLine( r2.left()+2, r2.bottom()-1, r2.right()-2, r2.bottom()-1 ); 251 p->drawLine( r2.left()+2, r2.bottom()-1, r2.right()-2, r2.bottom()-1 );
252 p->fillRect( QRect( r2.left()+1, r2.top(), r2.width()-2, r2.height()-2), 252 p->fillRect( QRect( r2.left()+1, r2.top(), r2.width()-2, r2.height()-2),
253 tb->palette().normal().brush( QColorGroup::Background )); 253 tb->palette().normal().brush( QColorGroup::Background ));
254 } else { 254 } else {
255 p->setPen( cg.dark() ); 255 p->setPen( cg.dark() );
256 p->drawLine( r2.left(), r2.top(), 256 p->drawLine( r2.left(), r2.top(),
257 r2.right(), r2.top() ); 257 r2.right(), r2.top() );
258 r2.setRect( r2.left() + 2, r2.top(), 258 r2.setRect( r2.left() + 2, r2.top(),
259 r2.width() - 4, r2.height() - 2 ); 259 r2.width() - 4, r2.height() - 2 );
260 p->setPen( cg.button() ); 260 p->setPen( cg.button() );
261 p->drawLine( r2.left()+2, r2.bottom()-1, r2.right()-2, r2.bottom()-1 ); 261 p->drawLine( r2.left()+2, r2.bottom()-1, r2.right()-2, r2.bottom()-1 );
262 p->fillRect( QRect( r2.left()+1, r2.top()+1, r2.width()-2, r2.height()-3), 262 p->fillRect( QRect( r2.left()+1, r2.top()+1, r2.width()-2, r2.height()-3),
263 tb->palette().normal().brush( QColorGroup::Button )); 263 tb->palette().normal().brush( QColorGroup::Button ));
264 } 264 }
265 265
266 p->setPen( cg.dark() ); 266 p->setPen( cg.dark() );
267 p->drawLine( r2.right(), r2.top(), 267 p->drawLine( r2.right(), r2.top(),
268 r2.right(), r2.bottom() - 2 ); 268 r2.right(), r2.bottom() - 2 );
269 p->drawPoint( r2.right() - 1, r2.bottom() - 1 ); 269 p->drawPoint( r2.right() - 1, r2.bottom() - 1 );
270 p->drawLine( r2.right() - 2, r2.bottom(), 270 p->drawLine( r2.right() - 2, r2.bottom(),
271 r2.left() + 2, r2.bottom() ); 271 r2.left() + 2, r2.bottom() );
272 272
273 p->setPen( cg.light() ); 273 p->setPen( cg.light() );
274 p->drawLine( r2.left(), r2.top()+1, 274 p->drawLine( r2.left(), r2.top()+1,
275 r2.left(), r2.bottom() - 2 ); 275 r2.left(), r2.bottom() - 2 );
276 p->drawPoint( r2.left() + 1, r2.bottom() - 1 ); 276 p->drawPoint( r2.left() + 1, r2.bottom() - 1 );
277 if ( r2.left() == 0 ) 277 if ( r2.left() == 0 )
278 p->drawPoint( tb->rect().topLeft() ); 278 p->drawPoint( tb->rect().topLeft() );
279 279
280 } else { 280 } else {
281 QCommonStyle::drawControl( ce, p, widget, r, cg, how, data ); 281 QCommonStyle::drawControl( ce, p, widget, r, cg, how, data );
282 } 282 }
283 break; 283 break;
284 } 284 }
285 default: 285 default:
286 QWindowsStyle::drawControl( ce, p, widget, r, cg, how, data ); 286 QWindowsStyle::drawControl( ce, p, widget, r, cg, how, data );
287 break; 287 break;
288 } 288 }
289} 289}
290 290
291void QPEStyle::drawComplexControl( ComplexControl control, QPainter *p, 291void QPEStyle::drawComplexControl( ComplexControl control, QPainter *p,
292 const QWidget *widget, const QRect &r, 292 const QWidget *widget, const QRect &r,
293 const QColorGroup &cg, SFlags how, 293 const QColorGroup &cg, SFlags how,
294 SCFlags sub, SCFlags subActive, const QStyleOption &data) const 294 SCFlags sub, SCFlags subActive, const QStyleOption &data) const
295{ 295{
296 switch ( control ) { 296 switch ( control ) {
297 case CC_ComboBox: 297 case CC_ComboBox:
298 if ( sub & SC_ComboBoxArrow ) { 298 if ( sub & SC_ComboBoxArrow ) {
299 SFlags flags = Style_Default; 299 SFlags flags = Style_Default;
300 300
301 drawPrimitive( PE_ButtonBevel, p, r, cg, flags, data ); 301 drawPrimitive( PE_ButtonBevel, p, r, cg, flags, data );
302 302
303 QRect ar = 303 QRect ar =
304 QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget, 304 QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget,
305 SC_ComboBoxArrow ), widget ); 305 SC_ComboBoxArrow ), widget );
306 306
307 if ( subActive == SC_ComboBoxArrow ) { 307 if ( subActive == SC_ComboBoxArrow ) {
308 p->setPen( cg.dark() ); 308 p->setPen( cg.dark() );
309 p->setBrush( cg.brush( QColorGroup::Button ) ); 309 p->setBrush( cg.brush( QColorGroup::Button ) );
310 p->drawRect( ar ); 310 p->drawRect( ar );
311 } 311 }
312 312
313 ar.addCoords( 2, 2, -2, -2 ); 313 ar.addCoords( 2, 2, -2, -2 );
314 if ( widget->isEnabled() ) 314 if ( widget->isEnabled() )
315 flags |= Style_Enabled; 315 flags |= Style_Enabled;
316 316
317 if ( subActive & Style_Sunken ) { 317 if ( subActive & Style_Sunken ) {
318 flags |= Style_Sunken; 318 flags |= Style_Sunken;
319 } 319 }
320 drawPrimitive( PE_ArrowDown, p, ar, cg, flags ); 320 drawPrimitive( PE_ArrowDown, p, ar, cg, flags );
321 } 321 }
322 322
323 if ( sub & SC_ComboBoxEditField ) { 323 if ( sub & SC_ComboBoxEditField ) {
324 const QComboBox * cb = (const QComboBox *) widget; 324 const QComboBox * cb = (const QComboBox *) widget;
325 QRect re = 325 QRect re =
326 QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget, 326 QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget,
327 SC_ComboBoxEditField ), widget ); 327 SC_ComboBoxEditField ), widget );
328 if ( cb->hasFocus() && !cb->editable() ) 328 if ( cb->hasFocus() && !cb->editable() )
329 p->fillRect( re.x(), re.y(), re.width(), re.height(), 329 p->fillRect( re.x(), re.y(), re.width(), re.height(),
330 cg.brush( QColorGroup::Highlight ) ); 330 cg.brush( QColorGroup::Highlight ) );
331 331
332 if ( cb->hasFocus() ) { 332 if ( cb->hasFocus() ) {
333 p->setPen( cg.highlightedText() ); 333 p->setPen( cg.highlightedText() );
334 p->setBackgroundColor( cg.highlight() ); 334 p->setBackgroundColor( cg.highlight() );
335 335
336 } else { 336 } else {
337 p->setPen( cg.text() ); 337 p->setPen( cg.text() );
338 p->setBackgroundColor( cg.background() ); 338 p->setBackgroundColor( cg.background() );
339 } 339 }
340 340
341 if ( cb->hasFocus() && !cb->editable() ) { 341 if ( cb->hasFocus() && !cb->editable() ) {
342 QRect re = 342 QRect re =
343 QStyle::visualRect( subRect( SR_ComboBoxFocusRect, cb ), widget ); 343 QStyle::visualRect( subRect( SR_ComboBoxFocusRect, cb ), widget );
344 drawPrimitive( PE_FocusRect, p, re, cg, Style_FocusAtBorder, QStyleOption(cg.highlight())); 344 drawPrimitive( PE_FocusRect, p, re, cg, Style_FocusAtBorder, QStyleOption(cg.highlight()));
345 } 345 }
346 } 346 }
347 break; 347 break;
348 default: 348 default:
349 QWindowsStyle::drawComplexControl( control, p, widget, r, cg, how, 349 QWindowsStyle::drawComplexControl( control, p, widget, r, cg, how,
350 sub, subActive, data ); 350 sub, subActive, data );
351 break; 351 break;
352 } 352 }
353} 353}
354 354
355int QPEStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const 355int QPEStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const
356{ 356{
357 int ret; 357 int ret;
358 switch( metric ) { 358 switch( metric ) {
359 case PM_ButtonMargin: 359 case PM_ButtonMargin:
360 ret = 2; 360 ret = 2;
361 break; 361 break;
362 case PM_DefaultFrameWidth: 362 case PM_DefaultFrameWidth:
363 ret = 1; 363 ret = 1;
364 break; 364 break;
365 case PM_ButtonDefaultIndicator: 365 case PM_ButtonDefaultIndicator:
366 ret = 2; 366 ret = 2;
367 break; 367 break;
368 case PM_ButtonShiftHorizontal: 368 case PM_ButtonShiftHorizontal:
369 case PM_ButtonShiftVertical: 369 case PM_ButtonShiftVertical:
370 ret = -1; 370 ret = -1;
371 break; 371 break;
372 case PM_IndicatorWidth: 372 case PM_IndicatorWidth:
373 ret = 15; 373 ret = 15;
374 break; 374 break;
375 case PM_IndicatorHeight: 375 case PM_IndicatorHeight:
376 ret = 13; 376 ret = 13;
377 break; 377 break;
378 case PM_ExclusiveIndicatorHeight: 378 case PM_ExclusiveIndicatorHeight:
379 case PM_ExclusiveIndicatorWidth: 379 case PM_ExclusiveIndicatorWidth:
380 ret = 15; 380 ret = 15;
381 break; 381 break;
382 case PM_ScrollBarExtent: 382 case PM_ScrollBarExtent:
383 ret = 13; 383 ret = 13;
384 break; 384 break;
385 case PM_SliderLength: 385 case PM_SliderLength:
386 ret = 12; 386 ret = 12;
387 break; 387 break;
388 default: 388 default:
389 ret = QWindowsStyle::pixelMetric( metric, widget ); 389 ret = QWindowsStyle::pixelMetric( metric, widget );
390 break; 390 break;
391 } 391 }
392 return ret; 392 return ret;
393} 393}
394 394
395QSize QPEStyle::sizeFromContents( ContentsType contents, const QWidget *widget, 395QSize QPEStyle::sizeFromContents( ContentsType contents, const QWidget *widget,
396 const QSize &contentsSize, const QStyleOption &data) const 396 const QSize &contentsSize, const QStyleOption &data) const
397{ 397{
398 QSize sz(contentsSize); 398 QSize sz(contentsSize);
399 399
400 switch ( contents ) { 400 switch ( contents ) {
401 case CT_PopupMenuItem: 401 case CT_PopupMenuItem:
402 { 402 {
403 if ( !widget || data.isDefault() ) 403 if ( !widget || data.isDefault() )
404 break; 404 break;
405 sz = QWindowsStyle::sizeFromContents( contents, widget, contentsSize, data ); 405 sz = QWindowsStyle::sizeFromContents( contents, widget, contentsSize, data );
406 sz = QSize( sz.width(), sz.height()-2 ); 406 sz = QSize( sz.width(), sz.height()-2 );
407 break; 407 break;
408 } 408 }
409 default: 409 default:
410 sz = QWindowsStyle::sizeFromContents( contents, widget, contentsSize, data ); 410 sz = QWindowsStyle::sizeFromContents( contents, widget, contentsSize, data );
411 break; 411 break;
412 } 412 }
413 413
414 return sz; 414 return sz;
415} 415}
416 416
417#else 417#else
418 418
419#include <qfontmetrics.h> 419#include <qfontmetrics.h>
420#include <qpalette.h> 420#include <qpalette.h>
421#include <qdrawutil.h> 421#include <qdrawutil.h>
422#include <qscrollbar.h> 422#include <qscrollbar.h>
423#include <qbutton.h> 423#include <qbutton.h>
424#include <qframe.h> 424#include <qframe.h>
425#include <qtabbar.h> 425#include <qtabbar.h>
426 426
427#define INCLUDE_MENUITEM_DEF 427#define INCLUDE_MENUITEM_DEF
428#include <qmenudata.h> 428#include <qmenudata.h>
429 429
430QPEStyle::QPEStyle() 430QPEStyle::QPEStyle()
431{ 431{
432#if QT_VERSION < 300 432#if QT_VERSION < 0x030000
433 setButtonMargin(buttonMargin()); 433 setButtonMargin(buttonMargin());
434 setScrollBarExtent(scrollBarExtent().width(),scrollBarExtent().height()); 434 setScrollBarExtent(scrollBarExtent().width(),scrollBarExtent().height());
435#endif 435#endif
436} 436}
437 437
438QPEStyle::~QPEStyle() 438QPEStyle::~QPEStyle()
439{ 439{
440} 440}
441 441
442int QPEStyle::buttonMargin() const 442int QPEStyle::buttonMargin() const
443{ 443{
444 return 2; 444 return 2;
445} 445}
446 446
447QSize QPEStyle::scrollBarExtent() const 447QSize QPEStyle::scrollBarExtent() const
448{ 448{
449 return QSize(13,13); 449 return QSize(13,13);
450} 450}
451 451
452void QPEStyle::polish ( QPalette & ) 452void QPEStyle::polish ( QPalette & )
453{ 453{
454} 454}
455 455
456void QPEStyle::polish( QWidget *w ) 456void QPEStyle::polish( QWidget *w )
457{ 457{
458 if ( w->inherits( "QListBox" ) || 458 if ( w->inherits( "QListBox" ) ||
459 w->inherits( "QListView" ) || 459 w->inherits( "QListView" ) ||
460 w->inherits( "QPopupMenu" ) || 460 w->inherits( "QPopupMenu" ) ||
461 w->inherits( "QSpinBox" ) ) { 461 w->inherits( "QSpinBox" ) ) {
462 QFrame *f = (QFrame *)w; 462 QFrame *f = (QFrame *)w;
463 f->setFrameShape( QFrame::StyledPanel ); 463 f->setFrameShape( QFrame::StyledPanel );
464 f->setLineWidth( 1 ); 464 f->setLineWidth( 1 );
465 } 465 }
466} 466}
467 467
468void QPEStyle::unPolish( QWidget *w ) 468void QPEStyle::unPolish( QWidget *w )
469{ 469{
470 if ( w->inherits( "QListBox" ) || 470 if ( w->inherits( "QListBox" ) ||
471 w->inherits( "QListView" ) || 471 w->inherits( "QListView" ) ||
472 w->inherits( "QPopupMenu" ) || 472 w->inherits( "QPopupMenu" ) ||
473 w->inherits( "QSpinBox" ) ) { 473 w->inherits( "QSpinBox" ) ) {
474 QFrame *f = (QFrame *)w; 474 QFrame *f = (QFrame *)w;
475 f->setFrameShape( QFrame::StyledPanel ); 475 f->setFrameShape( QFrame::StyledPanel );
476 f->setLineWidth( 2 ); 476 f->setLineWidth( 2 );
477 } 477 }
478} 478}
479 479
480int QPEStyle::defaultFrameWidth() const 480int QPEStyle::defaultFrameWidth() const
481{ 481{
482 return 1; 482 return 1;
483} 483}
484 484
485void QPEStyle::drawPanel ( QPainter * p, int x, int y, int w, int h, 485void QPEStyle::drawPanel ( QPainter * p, int x, int y, int w, int h,
486 const QColorGroup &g, bool sunken, int lineWidth, const QBrush * fill ) 486 const QColorGroup &g, bool sunken, int lineWidth, const QBrush * fill )
487{ 487{
488 qDrawShadePanel( p, QRect(x, y, w, h), g, sunken, lineWidth, fill ); 488 qDrawShadePanel( p, QRect(x, y, w, h), g, sunken, lineWidth, fill );
489} 489}
490 490
491void QPEStyle::drawButton( QPainter *p, int x, int y, int w, int h, 491void QPEStyle::drawButton( QPainter *p, int x, int y, int w, int h,
492 const QColorGroup &g, bool sunken, const QBrush* fill ) 492 const QColorGroup &g, bool sunken, const QBrush* fill )
493{ 493{
494 QPen oldPen = p->pen(); 494 QPen oldPen = p->pen();
495 if ( sunken ) 495 if ( sunken )
496 p->setPen( g.dark() ); 496 p->setPen( g.dark() );
497 else 497 else
498 p->setPen( g.light() ); 498 p->setPen( g.light() );
499 499
500 int x2 = x+w-1; 500 int x2 = x+w-1;
501 int y2 = y+h-1; 501 int y2 = y+h-1;
502 502
503 p->drawLine( x, y, x, y2 ); 503 p->drawLine( x, y, x, y2 );
504 p->drawLine( x, y, x2, y ); 504 p->drawLine( x, y, x2, y );
505 505
506 if ( sunken ) 506 if ( sunken )
507 p->setPen( g.light() ); 507 p->setPen( g.light() );
508 else 508 else
509 p->setPen( g.dark() ); 509 p->setPen( g.dark() );
510 510
511 p->drawLine( x2, y, x2, y2 ); 511 p->drawLine( x2, y, x2, y2 );
512 p->drawLine( x, y2, x2, y2 ); 512 p->drawLine( x, y2, x2, y2 );
513 p->setPen( oldPen ); 513 p->setPen( oldPen );
514 514
515 p->fillRect( x+1, y+1, w-2, h-2, fill?(*fill):g.brush(QColorGroup::Button) ); 515 p->fillRect( x+1, y+1, w-2, h-2, fill?(*fill):g.brush(QColorGroup::Button) );
516} 516}
517 517
518void QPEStyle::drawButtonMask ( QPainter * p, int x, int y, int w, int h ) 518void QPEStyle::drawButtonMask ( QPainter * p, int x, int y, int w, int h )
519{ 519{
520 p->fillRect( x, y, w, h, color1 ); 520 p->fillRect( x, y, w, h, color1 );
521} 521}
522 522
523void QPEStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h, 523void QPEStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h,
524 const QColorGroup &g, bool sunken, const QBrush* fill ) 524 const QColorGroup &g, bool sunken, const QBrush* fill )
525{ 525{
526 drawButton( p, x, y, w, h, g, sunken, fill ); 526 drawButton( p, x, y, w, h, g, sunken, fill );
527} 527}
528 528
529QRect QPEStyle::comboButtonRect( int x, int y, int w, int h) 529QRect QPEStyle::comboButtonRect( int x, int y, int w, int h)
530{ 530{
531 return QRect(x+1, y+1, w-2-14, h-2); 531 return QRect(x+1, y+1, w-2-14, h-2);
532} 532}
533 533
534 534
535QRect QPEStyle::comboButtonFocusRect( int x, int y, int w, int h) 535QRect QPEStyle::comboButtonFocusRect( int x, int y, int w, int h)
536{ 536{
537 return QRect(x+2, y+2, w-4-14, h-4); 537 return QRect(x+2, y+2, w-4-14, h-4);
538} 538}
539 539
540void QPEStyle::drawComboButton( QPainter *p, int x, int y, int w, int h, 540void QPEStyle::drawComboButton( QPainter *p, int x, int y, int w, int h,
541 const QColorGroup &g, bool sunken, 541 const QColorGroup &g, bool sunken,
542 bool /*editable*/, 542 bool /*editable*/,
543 bool enabled, 543 bool enabled,
544 const QBrush *fill ) 544 const QBrush *fill )
545{ 545{
546 drawBevelButton( p, x, y, w, h, g, FALSE, fill ); 546 drawBevelButton( p, x, y, w, h, g, FALSE, fill );
547 drawBevelButton( p, x+w-14, y, 14, h, g, sunken, fill ); 547 drawBevelButton( p, x+w-14, y, 14, h, g, sunken, fill );
548 drawArrow( p, QStyle::DownArrow, sunken, 548 drawArrow( p, QStyle::DownArrow, sunken,
549 x+w-14+ 2, y+ 2, 14- 4, h- 4, g, enabled, 549 x+w-14+ 2, y+ 2, 14- 4, h- 4, g, enabled,
550 &g.brush( QColorGroup::Button ) ); 550 &g.brush( QColorGroup::Button ) );
551 551
552} 552}
553 553
554 554
555void QPEStyle::drawExclusiveIndicator ( QPainter * p, int x, int y, int w, 555void QPEStyle::drawExclusiveIndicator ( QPainter * p, int x, int y, int w,
556 int h, const QColorGroup & g, bool on, bool down, bool enabled ) 556 int h, const QColorGroup & g, bool on, bool down, bool enabled )
557{ 557{
558 static const QCOORD pts1[] = { // dark lines 558 static const QCOORD pts1[] = { // dark lines
559 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 }; 559 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
560 static const QCOORD pts4[] = { // white lines 560 static const QCOORD pts4[] = { // white lines
561 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7, 561 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
562 11,4, 10,3, 10,2 }; 562 11,4, 10,3, 10,2 };
563 static const QCOORD pts5[] = { // inner fill 563 static const QCOORD pts5[] = { // inner fill
564 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 }; 564 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
565 565
566 p->eraseRect( x, y, w, h ); 566 p->eraseRect( x, y, w, h );
567 QPointArray a( QCOORDARRLEN(pts1), pts1 ); 567 QPointArray a( QCOORDARRLEN(pts1), pts1 );
568 a.translate( x, y ); 568 a.translate( x, y );
569 p->setPen( g.dark() ); 569 p->setPen( g.dark() );
570 p->drawPolyline( a ); 570 p->drawPolyline( a );
571 a.setPoints( QCOORDARRLEN(pts4), pts4 ); 571 a.setPoints( QCOORDARRLEN(pts4), pts4 );
572 a.translate( x, y ); 572 a.translate( x, y );
573 p->setPen( g.light() ); 573 p->setPen( g.light() );
574 p->drawPolyline( a ); 574 p->drawPolyline( a );
575 a.setPoints( QCOORDARRLEN(pts5), pts5 ); 575 a.setPoints( QCOORDARRLEN(pts5), pts5 );
576 a.translate( x, y ); 576 a.translate( x, y );
577 QColor fillColor = ( down || !enabled ) ? g.button() : g.base(); 577 QColor fillColor = ( down || !enabled ) ? g.button() : g.base();
578 p->setPen( fillColor ); 578 p->setPen( fillColor );
579 p->setBrush( fillColor ) ; 579 p->setBrush( fillColor ) ;
580 p->drawPolygon( a ); 580 p->drawPolygon( a );
581 if ( on ) { 581 if ( on ) {
582 p->setPen( NoPen ); 582 p->setPen( NoPen );
583 p->setBrush( g.text() ); 583 p->setBrush( g.text() );
584 p->drawRect( x+5, y+4, 2, 4 ); 584 p->drawRect( x+5, y+4, 2, 4 );
585 p->drawRect( x+4, y+5, 4, 2 ); 585 p->drawRect( x+4, y+5, 4, 2 );
586 } 586 }
587} 587}
588 588
589void QPEStyle::drawIndicator ( QPainter * p, int x, int y, int w, int h, 589void QPEStyle::drawIndicator ( QPainter * p, int x, int y, int w, int h,
590 const QColorGroup & g, int state, bool down, bool enabled ) 590 const QColorGroup & g, int state, bool down, bool enabled )
591{ 591{
592 592
593 QBrush fill; 593 QBrush fill;
594 if ( state == QButton::NoChange ) { 594 if ( state == QButton::NoChange ) {
595 QBrush b = p->brush(); 595 QBrush b = p->brush();
596 QColor c = p->backgroundColor(); 596 QColor c = p->backgroundColor();
597 p->setBackgroundMode( TransparentMode ); 597 p->setBackgroundMode( TransparentMode );
598 p->setBackgroundColor( green ); 598 p->setBackgroundColor( green );
599 fill = QBrush(g.base(), Dense4Pattern); 599 fill = QBrush(g.base(), Dense4Pattern);
600 p->setBackgroundColor( c ); 600 p->setBackgroundColor( c );
601 p->setBrush( b ); 601 p->setBrush( b );
602 } else if ( down ) 602 } else if ( down )
603 fill = g.brush( QColorGroup::Button ); 603 fill = g.brush( QColorGroup::Button );
604 else 604 else
605 fill = g.brush( enabled ? QColorGroup::Base : QColorGroup::Background ); 605 fill = g.brush( enabled ? QColorGroup::Base : QColorGroup::Background );
606 drawPanel( p, x, y, w, h, g, TRUE, 1, &fill ); 606 drawPanel( p, x, y, w, h, g, TRUE, 1, &fill );
607 if ( state != QButton::Off ) { 607 if ( state != QButton::Off ) {
608 QPointArray a( 7*2 ); 608 QPointArray a( 7*2 );
609 int i, xx, yy; 609 int i, xx, yy;
610 xx = x+3; 610 xx = x+3;
611 yy = y+5; 611 yy = y+5;
612 for ( i=0; i<3; i++ ) { 612 for ( i=0; i<3; i++ ) {
613 a.setPoint( 2*i, xx, yy ); 613 a.setPoint( 2*i, xx, yy );
614 a.setPoint( 2*i+1, xx, yy+2 ); 614 a.setPoint( 2*i+1, xx, yy+2 );
615 xx++; yy++; 615 xx++; yy++;
616 } 616 }
617 yy -= 2; 617 yy -= 2;
618 for ( i=3; i<7; i++ ) { 618 for ( i=3; i<7; i++ ) {
619 a.setPoint( 2*i, xx, yy ); 619 a.setPoint( 2*i, xx, yy );
620 a.setPoint( 2*i+1, xx, yy+2 ); 620 a.setPoint( 2*i+1, xx, yy+2 );
621 xx++; yy--; 621 xx++; yy--;
622 } 622 }
623 if ( state == QButton::NoChange ) { 623 if ( state == QButton::NoChange ) {
624 p->setPen( g.dark() ); 624 p->setPen( g.dark() );
625 } else { 625 } else {
626 p->setPen( g.text() ); 626 p->setPen( g.text() );
627 } 627 }
628 p->drawLineSegments( a ); 628 p->drawLineSegments( a );
629 } 629 }
630} 630}
631 631
632 #define HORIZONTAL(sb->orientation() == QScrollBar::Horizontal) 632 #define HORIZONTAL(sb->orientation() == QScrollBar::Horizontal)
633 #define VERTICAL!HORIZONTAL 633 #define VERTICAL!HORIZONTAL
634 #define MOTIF_BORDER2 634 #define MOTIF_BORDER2
635 #define SLIDER_MIN9 // ### motif says 6 but that's too small 635 #define SLIDER_MIN9 // ### motif says 6 but that's too small
636 636
637/*! \reimp */ 637/*! \reimp */
638 638
639void QPEStyle::scrollBarMetrics( const QScrollBar* sb, int &sliderMin, int &sliderMax, int &sliderLength, int& buttonDim ) 639void QPEStyle::scrollBarMetrics( const QScrollBar* sb, int &sliderMin, int &sliderMax, int &sliderLength, int& buttonDim )
640{ 640{
641 int maxLength; 641 int maxLength;
642 int length = HORIZONTAL ? sb->width() : sb->height(); 642 int length = HORIZONTAL ? sb->width() : sb->height();
643 int extent = HORIZONTAL ? sb->height() : sb->width(); 643 int extent = HORIZONTAL ? sb->height() : sb->width();
644 644
645 if ( length > (extent - 1)*2 ) 645 if ( length > (extent - 1)*2 )
646 buttonDim = extent; 646 buttonDim = extent;
647 else 647 else
648 buttonDim = length/2 - 1; 648 buttonDim = length/2 - 1;
649 649
650 sliderMin = 0; 650 sliderMin = 0;
651 maxLength = length - buttonDim*2; 651 maxLength = length - buttonDim*2;
652 652
653 if ( sb->maxValue() == sb->minValue() ) { 653 if ( sb->maxValue() == sb->minValue() ) {
654 sliderLength = maxLength; 654 sliderLength = maxLength;
655 } else { 655 } else {
656 sliderLength = (sb->pageStep()*maxLength)/ 656 sliderLength = (sb->pageStep()*maxLength)/
657 (sb->maxValue()-sb->minValue()+sb->pageStep()); 657 (sb->maxValue()-sb->minValue()+sb->pageStep());
658 uint range = sb->maxValue()-sb->minValue(); 658 uint range = sb->maxValue()-sb->minValue();
659 if ( sliderLength < SLIDER_MIN || range > INT_MAX/2 ) 659 if ( sliderLength < SLIDER_MIN || range > INT_MAX/2 )
660 sliderLength = SLIDER_MIN; 660 sliderLength = SLIDER_MIN;
661 if ( sliderLength > maxLength ) 661 if ( sliderLength > maxLength )
662 sliderLength = maxLength; 662 sliderLength = maxLength;
663 } 663 }
664 664
665 sliderMax = sliderMin + maxLength - sliderLength; 665 sliderMax = sliderMin + maxLength - sliderLength;
666} 666}
667 667
668/*!\reimp 668/*!\reimp
669 */ 669 */
670QStyle::ScrollControl QPEStyle::scrollBarPointOver( const QScrollBar* sb, int sliderStart, const QPoint& p ) 670QStyle::ScrollControl QPEStyle::scrollBarPointOver( const QScrollBar* sb, int sliderStart, const QPoint& p )
671{ 671{
672 if ( !sb->rect().contains( p ) ) 672 if ( !sb->rect().contains( p ) )
673 return NoScroll; 673 return NoScroll;
674 int sliderMin, sliderMax, sliderLength, buttonDim, pos; 674 int sliderMin, sliderMax, sliderLength, buttonDim, pos;
675 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim ); 675 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
676 676
677 if (sb->orientation() == QScrollBar::Horizontal) 677 if (sb->orientation() == QScrollBar::Horizontal)
678 pos = p.x(); 678 pos = p.x();
679 else 679 else
680 pos = p.y(); 680 pos = p.y();
681 681
682 if (pos < sliderStart) 682 if (pos < sliderStart)
683 return SubPage; 683 return SubPage;
684 if (pos < sliderStart + sliderLength) 684 if (pos < sliderStart + sliderLength)
685 return Slider; 685 return Slider;
686 if (pos < sliderMax + sliderLength) 686 if (pos < sliderMax + sliderLength)
687 return AddPage; 687 return AddPage;
688 if (pos < sliderMax + sliderLength + buttonDim) 688 if (pos < sliderMax + sliderLength + buttonDim)
689 return SubLine; 689 return SubLine;
690 return AddLine; 690 return AddLine;
691} 691}
692 692
693/*! \reimp */ 693/*! \reimp */
694 694
695void QPEStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb, int sliderStart, uint controls, uint activeControl ) 695void QPEStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb, int sliderStart, uint controls, uint activeControl )
696{ 696{
697#define ADD_LINE_ACTIVE ( activeControl == AddLine ) 697#define ADD_LINE_ACTIVE ( activeControl == AddLine )
698#define SUB_LINE_ACTIVE ( activeControl == SubLine ) 698#define SUB_LINE_ACTIVE ( activeControl == SubLine )
699 QColorGroup g = sb->colorGroup(); 699 QColorGroup g = sb->colorGroup();
700 700
701 int sliderMin, sliderMax, sliderLength, buttonDim; 701 int sliderMin, sliderMax, sliderLength, buttonDim;
702 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim ); 702 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
703 703
704 if ( controls == (AddLine | SubLine | AddPage | SubPage | Slider | First | Last ) ) 704 if ( controls == (AddLine | SubLine | AddPage | SubPage | Slider | First | Last ) )
705 p->fillRect( 0, 0, sb->width(), sb->height(), g.brush( QColorGroup::Mid )); 705 p->fillRect( 0, 0, sb->width(), sb->height(), g.brush( QColorGroup::Mid ));
706 706
707 if (sliderStart > sliderMax) { // sanity check 707 if (sliderStart > sliderMax) { // sanity check
708 sliderStart = sliderMax; 708 sliderStart = sliderMax;
709 } 709 }
710 710
711 int dimB = buttonDim; 711 int dimB = buttonDim;
712 QRect addB; 712 QRect addB;
713 QRect subB; 713 QRect subB;
714 QRect addPageR; 714 QRect addPageR;
715 QRect subPageR; 715 QRect subPageR;
716 QRect sliderR; 716 QRect sliderR;
717 int addX, addY, subX, subY; 717 int addX, addY, subX, subY;
718 int length = HORIZONTAL ? sb->width() : sb->height(); 718 int length = HORIZONTAL ? sb->width() : sb->height();
719 int extent = HORIZONTAL ? sb->height() : sb->width(); 719 int extent = HORIZONTAL ? sb->height() : sb->width();
720 720
721 if ( HORIZONTAL ) { 721 if ( HORIZONTAL ) {
722 subY = addY = ( extent - dimB ) / 2; 722 subY = addY = ( extent - dimB ) / 2;
723 subX = length - dimB - dimB; 723 subX = length - dimB - dimB;
724 addX = length - dimB; 724 addX = length - dimB;
725 } else { 725 } else {
726 subX = addX = ( extent - dimB ) / 2; 726 subX = addX = ( extent - dimB ) / 2;
727 subY = length - dimB - dimB; 727 subY = length - dimB - dimB;
728 addY = length - dimB; 728 addY = length - dimB;
729 } 729 }
730 730
731 int sliderEnd = sliderStart + sliderLength; 731 int sliderEnd = sliderStart + sliderLength;
732 int sliderW = extent; 732 int sliderW = extent;
733 if ( HORIZONTAL ) { 733 if ( HORIZONTAL ) {
734 subB.setRect( subX,subY+1,dimB,dimB-1 ); 734 subB.setRect( subX,subY+1,dimB,dimB-1 );
735 addB.setRect( addX,addY+1,dimB,dimB-1 ); 735 addB.setRect( addX,addY+1,dimB,dimB-1 );
736 736
737 subPageR.setRect( 0, 0, 737 subPageR.setRect( 0, 0,
738 sliderStart+1, sliderW ); 738 sliderStart+1, sliderW );
739 addPageR.setRect( sliderEnd-1, 0, subX - sliderEnd+1, sliderW ); 739 addPageR.setRect( sliderEnd-1, 0, subX - sliderEnd+1, sliderW );
740 sliderR .setRect( sliderStart, 1, sliderLength, sliderW-1 ); 740 sliderR .setRect( sliderStart, 1, sliderLength, sliderW-1 );
741 741
742 } else { 742 } else {
743 subB.setRect( subX+1,subY,dimB-1,dimB ); 743 subB.setRect( subX+1,subY,dimB-1,dimB );
744 addB.setRect( addX+1,addY,dimB-1,dimB ); 744 addB.setRect( addX+1,addY,dimB-1,dimB );
745 745
746 subPageR.setRect( 0, 0, sliderW, 746 subPageR.setRect( 0, 0, sliderW,
747 sliderStart+1 ); 747 sliderStart+1 );
748 addPageR.setRect( 0, sliderEnd-1, sliderW, subY - sliderEnd+1 ); 748 addPageR.setRect( 0, sliderEnd-1, sliderW, subY - sliderEnd+1 );
749 sliderR .setRect( 1, sliderStart, sliderW-1, sliderLength ); 749 sliderR .setRect( 1, sliderStart, sliderW-1, sliderLength );
750 } 750 }
751 751
752 bool maxedOut = (sb->maxValue() == sb->minValue()); 752 bool maxedOut = (sb->maxValue() == sb->minValue());
753 if ( controls & AddLine ) { 753 if ( controls & AddLine ) {
754 drawBevelButton( p, addB.x(), addB.y(), 754 drawBevelButton( p, addB.x(), addB.y(),
755 addB.width(), addB.height(), g, 755 addB.width(), addB.height(), g,
756 ADD_LINE_ACTIVE); 756 ADD_LINE_ACTIVE);
757 p->setPen(g.shadow()); 757 p->setPen(g.shadow());
758 drawArrow( p, VERTICAL ? DownArrow : RightArrow, 758 drawArrow( p, VERTICAL ? DownArrow : RightArrow,
759 FALSE, addB.x()+2, addB.y()+2, 759 FALSE, addB.x()+2, addB.y()+2,
760 addB.width()-4, addB.height()-4, g, !maxedOut, 760 addB.width()-4, addB.height()-4, g, !maxedOut,
761 &g.brush( QColorGroup::Button )); 761 &g.brush( QColorGroup::Button ));
762 } 762 }
763 if ( controls & SubLine ) { 763 if ( controls & SubLine ) {
764 drawBevelButton( p, subB.x(), subB.y(), 764 drawBevelButton( p, subB.x(), subB.y(),
765 subB.width(), subB.height(), g, 765 subB.width(), subB.height(), g,
766 SUB_LINE_ACTIVE ); 766 SUB_LINE_ACTIVE );
767 p->setPen(g.shadow()); 767 p->setPen(g.shadow());
768 drawArrow( p, VERTICAL ? UpArrow : LeftArrow, 768 drawArrow( p, VERTICAL ? UpArrow : LeftArrow,
769 FALSE, subB.x()+2, subB.y()+2, 769 FALSE, subB.x()+2, subB.y()+2,
770 subB.width()-4, subB.height()-4, g, !maxedOut, 770 subB.width()-4, subB.height()-4, g, !maxedOut,
771 &g.brush( QColorGroup::Button )); 771 &g.brush( QColorGroup::Button ));
772 } 772 }
773 773
774 774
775 if ( controls & SubPage ) 775 if ( controls & SubPage )
776 p->fillRect( subPageR.x(), subPageR.y(), subPageR.width(), 776 p->fillRect( subPageR.x(), subPageR.y(), subPageR.width(),
777 subPageR.height(), g.brush( QColorGroup::Mid )); 777 subPageR.height(), g.brush( QColorGroup::Mid ));
778 if ( controls & AddPage ) 778 if ( controls & AddPage )
779 p->fillRect( addPageR.x(), addPageR.y(), addPageR.width(), 779 p->fillRect( addPageR.x(), addPageR.y(), addPageR.width(),
780 addPageR.height(), g.brush( QColorGroup::Mid )); 780 addPageR.height(), g.brush( QColorGroup::Mid ));
781 if ( controls & Slider ) { 781 if ( controls & Slider ) {
782 QPoint bo = p->brushOrigin(); 782 QPoint bo = p->brushOrigin();
783 p->setBrushOrigin(sliderR.topLeft()); 783 p->setBrushOrigin(sliderR.topLeft());
784 drawBevelButton( p, sliderR.x(), sliderR.y(), 784 drawBevelButton( p, sliderR.x(), sliderR.y(),
785 sliderR.width(), sliderR.height(), g, 785 sliderR.width(), sliderR.height(), g,
786 FALSE, &g.brush( QColorGroup::Button ) ); 786 FALSE, &g.brush( QColorGroup::Button ) );
787 p->setBrushOrigin(bo); 787 p->setBrushOrigin(bo);
788 drawRiffles( p, sliderR.x(), sliderR.y(), 788 drawRiffles( p, sliderR.x(), sliderR.y(),
789 sliderR.width(), sliderR.height(), g, HORIZONTAL ); 789 sliderR.width(), sliderR.height(), g, HORIZONTAL );
790 } 790 }
791 791
792 // ### perhaps this should not be able to accept focus if maxedOut? 792 // ### perhaps this should not be able to accept focus if maxedOut?
793 if ( sb->hasFocus() && (controls & Slider) ) 793 if ( sb->hasFocus() && (controls & Slider) )
794 p->drawWinFocusRect( sliderR.x()+2, sliderR.y()+2, 794 p->drawWinFocusRect( sliderR.x()+2, sliderR.y()+2,
795 sliderR.width()-5, sliderR.height()-5, 795 sliderR.width()-5, sliderR.height()-5,
796 sb->backgroundColor() ); 796 sb->backgroundColor() );
797 797
798} 798}
799 799
800void QPEStyle::drawRiffles( QPainter* p, int x, int y, int w, int h, 800void QPEStyle::drawRiffles( QPainter* p, int x, int y, int w, int h,
801 const QColorGroup &g, bool horizontal ) 801 const QColorGroup &g, bool horizontal )
802{ 802{
803 if (!horizontal) { 803 if (!horizontal) {
804 if (h > 20) { 804 if (h > 20) {
805 y += (h-20)/2 ; 805 y += (h-20)/2 ;
806 h = 20; 806 h = 20;
807 } 807 }
808 if (h > 12) { 808 if (h > 12) {
809 int n = 3; 809 int n = 3;
810 int my = y+h/2-4; 810 int my = y+h/2-4;
811 int i ; 811 int i ;
812 p->setPen(g.light()); 812 p->setPen(g.light());
813 for (i=0; i<n; i++) { 813 for (i=0; i<n; i++) {
814 p->drawLine(x+2, my+3*i, x+w-4, my+3*i); 814 p->drawLine(x+2, my+3*i, x+w-4, my+3*i);
815 } 815 }
816 p->setPen(g.dark()); 816 p->setPen(g.dark());
817 my++; 817 my++;
818 for (i=0; i<n; i++) { 818 for (i=0; i<n; i++) {
819 p->drawLine(x+2, my+3*i, x+w-4, my+3*i); 819 p->drawLine(x+2, my+3*i, x+w-4, my+3*i);
820 } 820 }
821 } 821 }
822 } 822 }
823 else { 823 else {
824 if (w > 20) { 824 if (w > 20) {
825 x += (w-20)/2 ; 825 x += (w-20)/2 ;
826 w = 20; 826 w = 20;
827 } 827 }
828 if (w > 12) { 828 if (w > 12) {
829 int n = 3; 829 int n = 3;
830 int mx = x+w/2-4; 830 int mx = x+w/2-4;
831 int i ; 831 int i ;
832 p->setPen(g.light()); 832 p->setPen(g.light());
833 for (i=0; i<n; i++) { 833 for (i=0; i<n; i++) {
834 p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4); 834 p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4);
835 } 835 }
836 p->setPen(g.dark()); 836 p->setPen(g.dark());
837 mx++; 837 mx++;
838 for (i=0; i<n; i++) { 838 for (i=0; i<n; i++) {
839 p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4); 839 p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4);
840 } 840 }
841 } 841 }
842 } 842 }
843} 843}
844 844
845int QPEStyle::sliderLength() const 845int QPEStyle::sliderLength() const
846{ 846{
847 return 12; 847 return 12;
848} 848}
849 849
850void QPEStyle::drawSlider( QPainter *p, int x, int y, int w, int h, 850void QPEStyle::drawSlider( QPainter *p, int x, int y, int w, int h,
851 const QColorGroup &g, Orientation o, bool tickAbove, bool tickBelow ) 851 const QColorGroup &g, Orientation o, bool tickAbove, bool tickBelow )
852{ 852{
853 int a = tickAbove ? 3 : 0; 853 int a = tickAbove ? 3 : 0;
854 int b = tickBelow ? 3 : 0; 854 int b = tickBelow ? 3 : 0;
855 855
856 if ( o == Horizontal ) { 856 if ( o == Horizontal ) {
857 drawBevelButton( p, x, y+a, w, h-a-b, g, FALSE, &g.brush( QColorGroup::Button ) ); 857 drawBevelButton( p, x, y+a, w, h-a-b, g, FALSE, &g.brush( QColorGroup::Button ) );
858 int xp = x + w/2; 858 int xp = x + w/2;
859 qDrawShadeLine( p, xp, y+a+2, xp, y+h-b-3, g ); 859 qDrawShadeLine( p, xp, y+a+2, xp, y+h-b-3, g );
860 } else { 860 } else {
861 drawBevelButton( p, x+a, y, w-a-b, h, g, FALSE, &g.brush( QColorGroup::Button ) ); 861 drawBevelButton( p, x+a, y, w-a-b, h, g, FALSE, &g.brush( QColorGroup::Button ) );
862 int yp = y + h/2; 862 int yp = y + h/2;
863 qDrawShadeLine( p, x+a+2, yp, x+w-b-3, yp, g ); 863 qDrawShadeLine( p, x+a+2, yp, x+w-b-3, yp, g );
864 } 864 }
865} 865}
866 866
867void QPEStyle::drawSliderMask ( QPainter * p, int x, int y, int w, int h, 867void QPEStyle::drawSliderMask ( QPainter * p, int x, int y, int w, int h,
868 Orientation o, bool tickAbove, bool tickBelow ) 868 Orientation o, bool tickAbove, bool tickBelow )
869{ 869{
870 int a = tickAbove ? 3 : 0; 870 int a = tickAbove ? 3 : 0;
871 int b = tickBelow ? 3 : 0; 871 int b = tickBelow ? 3 : 0;
872 if ( o == Horizontal ) 872 if ( o == Horizontal )
873 p->fillRect( x, y+a, w, h-a-b, color1 ); 873 p->fillRect( x, y+a, w, h-a-b, color1 );
874 else 874 else
875 p->fillRect( x+a, y, w-a-b, h, color1 ); 875 p->fillRect( x+a, y, w-a-b, h, color1 );
876} 876}
877 877
878/*!\reimp 878/*!\reimp
879 */ 879 */
880void QPEStyle::drawSliderGrooveMask( QPainter *p, 880void QPEStyle::drawSliderGrooveMask( QPainter *p,
881 int x, int y, int w, int h, 881 int x, int y, int w, int h,
882 const QColorGroup& , QCOORD c, 882 const QColorGroup& , QCOORD c,
883 Orientation orient ) 883 Orientation orient )
884{ 884{
885 if ( orient == Horizontal ) 885 if ( orient == Horizontal )
886 p->fillRect( x, y + c - 2, w, 4, color1 ); 886 p->fillRect( x, y + c - 2, w, 4, color1 );
887 else 887 else
888 p->fillRect( x + c - 2, y, 4, h, color1 ); 888 p->fillRect( x + c - 2, y, 4, h, color1 );
889} 889}
890 890
891void QPEStyle::drawTab( QPainter *p, const QTabBar *tb, QTab *t, bool selected ) 891void QPEStyle::drawTab( QPainter *p, const QTabBar *tb, QTab *t, bool selected )
892{ 892{
893 QRect r( t->rect() ); 893 QRect r( t->rect() );
894 if ( tb->shape() == QTabBar::RoundedAbove ) { 894 if ( tb->shape() == QTabBar::RoundedAbove ) {
895 p->setPen( tb->colorGroup().light() ); 895 p->setPen( tb->colorGroup().light() );
896 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() ); 896 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
897 if ( r.left() == 0 ) 897 if ( r.left() == 0 )
898 p->drawPoint( tb->rect().bottomLeft() ); 898 p->drawPoint( tb->rect().bottomLeft() );
899 else { 899 else {
900 p->setPen( tb->colorGroup().light() ); 900 p->setPen( tb->colorGroup().light() );
901 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() ); 901 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
902 } 902 }
903 903
904 if ( selected ) { 904 if ( selected ) {
905 p->setPen( tb->colorGroup().background() ); 905 p->setPen( tb->colorGroup().background() );
906 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 ); 906 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
907 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-2), 907 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-2),
908 tb->colorGroup().brush( QColorGroup::Background )); 908 tb->colorGroup().brush( QColorGroup::Background ));
909 } else { 909 } else {
910 r.setRect( r.left() + 2, r.top() + 2, 910 r.setRect( r.left() + 2, r.top() + 2,
911 r.width() - 4, r.height() - 2 ); 911 r.width() - 4, r.height() - 2 );
912 p->setPen( tb->colorGroup().button() ); 912 p->setPen( tb->colorGroup().button() );
913 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 ); 913 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
914 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-3), 914 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-3),
915 tb->colorGroup().brush( QColorGroup::Button )); 915 tb->colorGroup().brush( QColorGroup::Button ));
916 916
917 //do shading; will not work for pixmap brushes 917 //do shading; will not work for pixmap brushes
918 QColor bg = tb->colorGroup().button(); 918 QColor bg = tb->colorGroup().button();
919 // int h,s,v; 919 // int h,s,v;
920 // bg.hsv( &h, &s, &v ); 920 // bg.hsv( &h, &s, &v );
921 int n = r.height()/2; 921 int n = r.height()/2;
922 int dark = 100; 922 int dark = 100;
923 for ( int i = 1; i < n; i++ ) { 923 for ( int i = 1; i < n; i++ ) {
924 dark = (dark * (100+(i*15)/n) )/100; 924 dark = (dark * (100+(i*15)/n) )/100;
925 p->setPen( bg.dark( dark ) ); 925 p->setPen( bg.dark( dark ) );
926 int y = r.bottom()-n+i; 926 int y = r.bottom()-n+i;
927 int x1 = r.left()+1; 927 int x1 = r.left()+1;
928 int x2 = r.right()-1; 928 int x2 = r.right()-1;
929 p->drawLine( x1, y, x2, y ); 929 p->drawLine( x1, y, x2, y );
930 } 930 }
931 } 931 }
932 932
933 p->setPen( tb->colorGroup().light() ); 933 p->setPen( tb->colorGroup().light() );
934 p->drawLine( r.left(), r.bottom()-1, r.left(), r.top() + 2 ); 934 p->drawLine( r.left(), r.bottom()-1, r.left(), r.top() + 2 );
935 p->drawPoint( r.left()+1, r.top() + 1 ); 935 p->drawPoint( r.left()+1, r.top() + 1 );
936 p->drawLine( r.left()+2, r.top(), 936 p->drawLine( r.left()+2, r.top(),
937 r.right() - 2, r.top() ); 937 r.right() - 2, r.top() );
938 938
939 p->setPen( tb->colorGroup().dark() ); 939 p->setPen( tb->colorGroup().dark() );
940 p->drawPoint( r.right() - 1, r.top() + 1 ); 940 p->drawPoint( r.right() - 1, r.top() + 1 );
941 p->drawLine( r.right(), r.top() + 2, r.right(), r.bottom() - 1); 941 p->drawLine( r.right(), r.top() + 2, r.right(), r.bottom() - 1);
942 } else if ( tb->shape() == QTabBar::RoundedBelow ) { 942 } else if ( tb->shape() == QTabBar::RoundedBelow ) {
943 if ( selected ) { 943 if ( selected ) {
944 p->setPen( tb->colorGroup().background() ); 944 p->setPen( tb->colorGroup().background() );
945 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 ); 945 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
946 p->fillRect( QRect( r.left()+1, r.top(), r.width()-2, r.height()-2), 946 p->fillRect( QRect( r.left()+1, r.top(), r.width()-2, r.height()-2),
947 tb->palette().normal().brush( QColorGroup::Background )); 947 tb->palette().normal().brush( QColorGroup::Background ));
948 } else { 948 } else {
949 p->setPen( tb->colorGroup().dark() ); 949 p->setPen( tb->colorGroup().dark() );
950 p->drawLine( r.left(), r.top(), 950 p->drawLine( r.left(), r.top(),
951 r.right(), r.top() ); 951 r.right(), r.top() );
952 r.setRect( r.left() + 2, r.top(), 952 r.setRect( r.left() + 2, r.top(),
953 r.width() - 4, r.height() - 2 ); 953 r.width() - 4, r.height() - 2 );
954 p->setPen( tb->colorGroup().button() ); 954 p->setPen( tb->colorGroup().button() );
955 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 ); 955 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
956 p->fillRect( QRect( r.left()+1, r.top()+1, r.width()-2, r.height()-3), 956 p->fillRect( QRect( r.left()+1, r.top()+1, r.width()-2, r.height()-3),
957 tb->palette().normal().brush( QColorGroup::Button )); 957 tb->palette().normal().brush( QColorGroup::Button ));
958 } 958 }
959 959
960 p->setPen( tb->colorGroup().dark() ); 960 p->setPen( tb->colorGroup().dark() );
961 p->drawLine( r.right(), r.top(), 961 p->drawLine( r.right(), r.top(),
962 r.right(), r.bottom() - 2 ); 962 r.right(), r.bottom() - 2 );
963 p->drawPoint( r.right() - 1, r.bottom() - 1 ); 963 p->drawPoint( r.right() - 1, r.bottom() - 1 );
964 p->drawLine( r.right() - 2, r.bottom(), 964 p->drawLine( r.right() - 2, r.bottom(),
965 r.left() + 2, r.bottom() ); 965 r.left() + 2, r.bottom() );
966 966
967 p->setPen( tb->colorGroup().light() ); 967 p->setPen( tb->colorGroup().light() );
968 p->drawLine( r.left(), r.top()+1, 968 p->drawLine( r.left(), r.top()+1,
969 r.left(), r.bottom() - 2 ); 969 r.left(), r.bottom() - 2 );
970 p->drawPoint( r.left() + 1, r.bottom() - 1 ); 970 p->drawPoint( r.left() + 1, r.bottom() - 1 );
971 if ( r.left() == 0 ) 971 if ( r.left() == 0 )
972 p->drawPoint( tb->rect().topLeft() ); 972 p->drawPoint( tb->rect().topLeft() );
973 973
974 } else { 974 } else {
975 QCommonStyle::drawTab( p, tb, t, selected ); 975 QCommonStyle::drawTab( p, tb, t, selected );
976 } 976 }
977} 977}
978 978
979 static const int motifItemFrame = 0;// menu item frame width 979 static const int motifItemFrame = 0;// menu item frame width
980 static const int motifSepHeight = 2;// separator item height 980 static const int motifSepHeight = 2;// separator item height
981 static const int motifItemHMargin = 1;// menu item hor text margin 981 static const int motifItemHMargin = 1;// menu item hor text margin
982 static const int motifItemVMargin = 2;// menu item ver text margin 982 static const int motifItemVMargin = 2;// menu item ver text margin
983 static const int motifArrowHMargin = 0;// arrow horizontal margin 983 static const int motifArrowHMargin = 0;// arrow horizontal margin
984 static const int motifTabSpacing = 12;// space between text and tab 984 static const int motifTabSpacing = 12;// space between text and tab
985 static const int motifCheckMarkHMargin = 1;// horiz. margins of check mark 985 static const int motifCheckMarkHMargin = 1;// horiz. margins of check mark
986 static const int windowsRightBorder= 8; // right border on windows 986 static const int windowsRightBorder= 8; // right border on windows
987static const int windowsCheckMarkWidth = 2; // checkmarks width on windows 987static const int windowsCheckMarkWidth = 2; // checkmarks width on windows
988 988
989/*! \reimp 989/*! \reimp
990*/ 990*/
991int QPEStyle::extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem* mi, const QFontMetrics& /*fm*/ ) 991int QPEStyle::extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem* mi, const QFontMetrics& /*fm*/ )
992{ 992{
993#ifndef QT_NO_MENUDATA 993#ifndef QT_NO_MENUDATA
994 int w = 2*motifItemHMargin + 2*motifItemFrame; // a little bit of border can never harm 994 int w = 2*motifItemHMargin + 2*motifItemFrame; // a little bit of border can never harm
995 995
996 if ( mi->isSeparator() ) 996 if ( mi->isSeparator() )
997 return 10; // arbitrary 997 return 10; // arbitrary
998 else if ( mi->pixmap() ) 998 else if ( mi->pixmap() )
999 w += mi->pixmap()->width();// pixmap only 999 w += mi->pixmap()->width();// pixmap only
1000 1000
1001 if ( !mi->text().isNull() ) { 1001 if ( !mi->text().isNull() ) {
1002 if ( mi->text().find('\t') >= 0 )// string contains tab 1002 if ( mi->text().find('\t') >= 0 )// string contains tab
1003 w += motifTabSpacing; 1003 w += motifTabSpacing;
1004 } 1004 }
1005 1005
1006 if ( maxpmw ) { // we have iconsets 1006 if ( maxpmw ) { // we have iconsets
1007 w += maxpmw; 1007 w += maxpmw;
1008 w += 6; // add a little extra border around the iconset 1008 w += 6; // add a little extra border around the iconset
1009 } 1009 }
1010 1010
1011 if ( checkable && maxpmw < windowsCheckMarkWidth ) { 1011 if ( checkable && maxpmw < windowsCheckMarkWidth ) {
1012 w += windowsCheckMarkWidth - maxpmw; // space for the checkmarks 1012 w += windowsCheckMarkWidth - maxpmw; // space for the checkmarks
1013 } 1013 }
1014 1014
1015 if ( maxpmw > 0 || checkable ) // we have a check-column ( iconsets or checkmarks) 1015 if ( maxpmw > 0 || checkable ) // we have a check-column ( iconsets or checkmarks)
1016 w += motifCheckMarkHMargin; // add space to separate the columns 1016 w += motifCheckMarkHMargin; // add space to separate the columns
1017 1017
1018 w += windowsRightBorder; // windows has a strange wide border on the right side 1018 w += windowsRightBorder; // windows has a strange wide border on the right side
1019 1019
1020 return w; 1020 return w;
1021#endif 1021#endif
1022} 1022}
1023 1023
1024/*! \reimp 1024/*! \reimp
1025*/ 1025*/
1026int QPEStyle::popupMenuItemHeight( bool /*checkable*/, QMenuItem* mi, const QFontMetrics& fm ) 1026int QPEStyle::popupMenuItemHeight( bool /*checkable*/, QMenuItem* mi, const QFontMetrics& fm )
1027{ 1027{
1028#ifndef QT_NO_MENUDATA 1028#ifndef QT_NO_MENUDATA
1029 int h = 0; 1029 int h = 0;
1030 if ( mi->isSeparator() ) // separator height 1030 if ( mi->isSeparator() ) // separator height
1031 h = motifSepHeight; 1031 h = motifSepHeight;
1032 else if ( mi->pixmap() ) // pixmap height 1032 else if ( mi->pixmap() ) // pixmap height
1033 h = mi->pixmap()->height() + 2*motifItemFrame; 1033 h = mi->pixmap()->height() + 2*motifItemFrame;
1034 else // text height 1034 else // text height
1035 h = fm.height() + 2*motifItemVMargin + 2*motifItemFrame - 1; 1035 h = fm.height() + 2*motifItemVMargin + 2*motifItemFrame - 1;
1036 1036
1037 if ( !mi->isSeparator() && mi->iconSet() != 0 ) { 1037 if ( !mi->isSeparator() && mi->iconSet() != 0 ) {
1038 h = QMAX( h, mi->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height() + 2*motifItemFrame ); 1038 h = QMAX( h, mi->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height() + 2*motifItemFrame );
1039 } 1039 }
1040 if ( mi->custom() ) 1040 if ( mi->custom() )
1041 h = QMAX( h, mi->custom()->sizeHint().height() + 2*motifItemVMargin + 2*motifItemFrame ) - 1; 1041 h = QMAX( h, mi->custom()->sizeHint().height() + 2*motifItemVMargin + 2*motifItemFrame ) - 1;
1042 return h; 1042 return h;
1043#endif 1043#endif
1044} 1044}
1045 1045
1046void QPEStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi, 1046void QPEStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi,
1047 const QPalette& pal, 1047 const QPalette& pal,
1048 bool act, bool enabled, int x, int y, int w, int h) 1048 bool act, bool enabled, int x, int y, int w, int h)
1049{ 1049{
1050#ifndef QT_NO_MENUDATA 1050#ifndef QT_NO_MENUDATA
1051 const QColorGroup & g = pal.active(); 1051 const QColorGroup & g = pal.active();
1052 bool dis = !enabled; 1052 bool dis = !enabled;
1053 QColorGroup itemg = dis ? pal.disabled() : pal.active(); 1053 QColorGroup itemg = dis ? pal.disabled() : pal.active();
1054 1054
1055 if ( checkable ) 1055 if ( checkable )
1056 maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks 1056 maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks
1057 1057
1058 int checkcol = maxpmw; 1058 int checkcol = maxpmw;
1059 1059
1060 if ( mi && mi->isSeparator() ) { // draw separator 1060 if ( mi && mi->isSeparator() ) { // draw separator
1061 p->setPen( g.dark() ); 1061 p->setPen( g.dark() );
1062 p->drawLine( x, y, x+w, y ); 1062 p->drawLine( x, y, x+w, y );
1063 p->setPen( g.light() ); 1063 p->setPen( g.light() );
1064 p->drawLine( x, y+1, x+w, y+1 ); 1064 p->drawLine( x, y+1, x+w, y+1 );
1065 return; 1065 return;
1066 } 1066 }
1067 1067
1068 QBrush fill = act? g.brush( QColorGroup::Highlight ) : 1068 QBrush fill = act? g.brush( QColorGroup::Highlight ) :
1069 g.brush( QColorGroup::Button ); 1069 g.brush( QColorGroup::Button );
1070 p->fillRect( x, y, w, h, fill); 1070 p->fillRect( x, y, w, h, fill);
1071 1071
1072 if ( !mi ) 1072 if ( !mi )
1073 return; 1073 return;
1074 1074
1075 if ( mi->isChecked() ) { 1075 if ( mi->isChecked() ) {
1076 if ( act && !dis ) { 1076 if ( act && !dis ) {
1077 qDrawShadePanel( p, x, y, checkcol, h, 1077 qDrawShadePanel( p, x, y, checkcol, h,
1078 g, TRUE, 1, &g.brush( QColorGroup::Button ) ); 1078 g, TRUE, 1, &g.brush( QColorGroup::Button ) );
1079 } else { 1079 } else {
1080 qDrawShadePanel( p, x, y, checkcol, h, 1080 qDrawShadePanel( p, x, y, checkcol, h,
1081 g, TRUE, 1, &g.brush( QColorGroup::Midlight ) ); 1081 g, TRUE, 1, &g.brush( QColorGroup::Midlight ) );
1082 } 1082 }
1083 } else if ( !act ) { 1083 } else if ( !act ) {
1084 p->fillRect(x, y, checkcol , h, 1084 p->fillRect(x, y, checkcol , h,
1085 g.brush( QColorGroup::Button )); 1085 g.brush( QColorGroup::Button ));
1086 } 1086 }
1087 1087
1088 if ( mi->iconSet() ) { // draw iconset 1088 if ( mi->iconSet() ) { // draw iconset
1089 QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal; 1089 QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal;
1090 if (act && !dis ) 1090 if (act && !dis )
1091 mode = QIconSet::Active; 1091 mode = QIconSet::Active;
1092 QPixmap pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode ); 1092 QPixmap pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
1093 int pixw = pixmap.width(); 1093 int pixw = pixmap.width();
1094 int pixh = pixmap.height(); 1094 int pixh = pixmap.height();
1095 if ( act && !dis ) { 1095 if ( act && !dis ) {
1096 if ( !mi->isChecked() ) 1096 if ( !mi->isChecked() )
1097 qDrawShadePanel( p, x, y, checkcol, h, g, FALSE, 1, &g.brush( QColorGroup::Button ) ); 1097 qDrawShadePanel( p, x, y, checkcol, h, g, FALSE, 1, &g.brush( QColorGroup::Button ) );
1098 } 1098 }
1099 QRect cr( x, y, checkcol, h ); 1099 QRect cr( x, y, checkcol, h );
1100 QRect pmr( 0, 0, pixw, pixh ); 1100 QRect pmr( 0, 0, pixw, pixh );
1101 pmr.moveCenter( cr.center() ); 1101 pmr.moveCenter( cr.center() );
1102 p->setPen( itemg.text() ); 1102 p->setPen( itemg.text() );
1103 p->drawPixmap( pmr.topLeft(), pixmap ); 1103 p->drawPixmap( pmr.topLeft(), pixmap );
1104 1104
1105 QBrush fill = act? g.brush( QColorGroup::Highlight ) : 1105 QBrush fill = act? g.brush( QColorGroup::Highlight ) :
1106 g.brush( QColorGroup::Button ); 1106 g.brush( QColorGroup::Button );
1107 p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill); 1107 p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill);
1108 } else if ( checkable ) {// just "checking"... 1108 } else if ( checkable ) {// just "checking"...
1109 int mw = checkcol + motifItemFrame; 1109 int mw = checkcol + motifItemFrame;
1110 int mh = h - 2*motifItemFrame; 1110 int mh = h - 2*motifItemFrame;
1111 if ( mi->isChecked() ) { 1111 if ( mi->isChecked() ) {
1112 drawCheckMark( p, x + motifItemFrame + 2, 1112 drawCheckMark( p, x + motifItemFrame + 2,
1113 y+motifItemFrame, mw, mh, itemg, act, dis ); 1113 y+motifItemFrame, mw, mh, itemg, act, dis );
1114 } 1114 }
1115 } 1115 }
1116 1116
1117 p->setPen( act ? g.highlightedText() : g.buttonText() ); 1117 p->setPen( act ? g.highlightedText() : g.buttonText() );
1118 1118
1119 QColor discol; 1119 QColor discol;
1120 if ( dis ) { 1120 if ( dis ) {
1121 discol = itemg.text(); 1121 discol = itemg.text();
1122 p->setPen( discol ); 1122 p->setPen( discol );
1123 } 1123 }
1124 1124
1125 int xm = motifItemFrame + checkcol + motifItemHMargin; 1125 int xm = motifItemFrame + checkcol + motifItemHMargin;
1126 1126
1127 if ( mi->custom() ) { 1127 if ( mi->custom() ) {
1128 int m = motifItemVMargin; 1128 int m = motifItemVMargin;
1129 p->save(); 1129 p->save();
1130 if ( dis && !act ) { 1130 if ( dis && !act ) {
1131 p->setPen( g.light() ); 1131 p->setPen( g.light() );
1132 mi->custom()->paint( p, itemg, act, enabled, 1132 mi->custom()->paint( p, itemg, act, enabled,
1133 x+xm+1, y+m+1, w-xm-tab+1, h-2*m ); 1133 x+xm+1, y+m+1, w-xm-tab+1, h-2*m );
1134 p->setPen( discol ); 1134 p->setPen( discol );
1135 } 1135 }
1136 mi->custom()->paint( p, itemg, act, enabled, 1136 mi->custom()->paint( p, itemg, act, enabled,
1137 x+xm, y+m, w-xm-tab+1, h-2*m ); 1137 x+xm, y+m, w-xm-tab+1, h-2*m );
1138 p->restore(); 1138 p->restore();
1139 } 1139 }
1140 QString s = mi->text(); 1140 QString s = mi->text();
1141 if ( !s.isNull() ) { // draw text 1141 if ( !s.isNull() ) { // draw text
1142 int t = s.find( '\t' ); 1142 int t = s.find( '\t' );
1143 int m = motifItemVMargin; 1143 int m = motifItemVMargin;
1144 const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine; 1144 const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
1145 if ( t >= 0 ) { // draw tab text 1145 if ( t >= 0 ) { // draw tab text
1146 if ( dis && !act ) { 1146 if ( dis && !act ) {
1147 p->setPen( g.light() ); 1147 p->setPen( g.light() );
1148 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1, 1148 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1,
1149 y+m+1, tab, h-2*m, text_flags, s.mid( t+1 )); 1149 y+m+1, tab, h-2*m, text_flags, s.mid( t+1 ));
1150 p->setPen( discol ); 1150 p->setPen( discol );
1151 } 1151 }
1152 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame, 1152 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame,
1153 y+m, tab, h-2*m, text_flags, s.mid( t+1 ) ); 1153 y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
1154 } 1154 }
1155 if ( dis && !act ) { 1155 if ( dis && !act ) {
1156 p->setPen( g.light() ); 1156 p->setPen( g.light() );
1157 p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t ); 1157 p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t );
1158 p->setPen( discol ); 1158 p->setPen( discol );
1159 } 1159 }
1160 p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t ); 1160 p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t );
1161 } else if ( mi->pixmap() ) { // draw pixmap 1161 } else if ( mi->pixmap() ) { // draw pixmap
1162 QPixmap *pixmap = mi->pixmap(); 1162 QPixmap *pixmap = mi->pixmap();
1163 if ( pixmap->depth() == 1 ) 1163 if ( pixmap->depth() == 1 )
1164 p->setBackgroundMode( OpaqueMode ); 1164 p->setBackgroundMode( OpaqueMode );
1165 p->drawPixmap( x+xm, y+motifItemFrame, *pixmap ); 1165 p->drawPixmap( x+xm, y+motifItemFrame, *pixmap );
1166 if ( pixmap->depth() == 1 ) 1166 if ( pixmap->depth() == 1 )
1167 p->setBackgroundMode( TransparentMode ); 1167 p->setBackgroundMode( TransparentMode );
1168 } 1168 }
1169 if ( mi->popup() ) { // draw sub menu arrow 1169 if ( mi->popup() ) { // draw sub menu arrow
1170 int dim = (h-2*motifItemFrame) / 2; 1170 int dim = (h-2*motifItemFrame) / 2;
1171 if ( act ) { 1171 if ( act ) {
1172 if ( !dis ) 1172 if ( !dis )
1173 discol = white; 1173 discol = white;
1174 QColorGroup g2( discol, g.highlight(), 1174 QColorGroup g2( discol, g.highlight(),
1175 white, white, 1175 white, white,
1176 dis ? discol : white, 1176 dis ? discol : white,
1177 discol, white ); 1177 discol, white );
1178 drawArrow( p, RightArrow, FALSE, 1178 drawArrow( p, RightArrow, FALSE,
1179 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2, 1179 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2,
1180 dim, dim, g2, TRUE ); 1180 dim, dim, g2, TRUE );
1181 } else { 1181 } else {
1182 drawArrow( p, RightArrow, 1182 drawArrow( p, RightArrow,
1183 FALSE, 1183 FALSE,
1184 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2, 1184 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2,
1185 dim, dim, g, mi->isEnabled() ); 1185 dim, dim, g, mi->isEnabled() );
1186 } 1186 }
1187 } 1187 }
1188#endif 1188#endif
1189} 1189}
1190 1190
1191#endif 1191#endif
diff --git a/library/qpestyle.h b/library/qpestyle.h
index 19ef346..1bde0ff 100644
--- a/library/qpestyle.h
+++ b/library/qpestyle.h
@@ -1,102 +1,102 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#ifndef QPESTYLE_H 21#ifndef QPESTYLE_H
22#define QPESTYLE_H 22#define QPESTYLE_H
23 23
24#ifndef QT_H 24#ifndef QT_H
25#include "qwindowsstyle.h" 25#include "qwindowsstyle.h"
26#endif // QT_H 26#endif // QT_H
27 27
28#if QT_VERSION >= 300 28#if QT_VERSION >= 0x030000
29 29
30class Q_EXPORT QPEStyle : public QWindowsStyle 30class Q_EXPORT QPEStyle : public QWindowsStyle
31{ 31{
32public: 32public:
33 QPEStyle(); 33 QPEStyle();
34 virtual ~QPEStyle(); 34 virtual ~QPEStyle();
35 35
36 virtual void drawPrimitive( PrimitiveElement pe, QPainter *p, const QRect &r, const QColorGroup &cg, SFlags flags=Style_Default, const QStyleOption & = QStyleOption::Default) const; 36 virtual void drawPrimitive( PrimitiveElement pe, QPainter *p, const QRect &r, const QColorGroup &cg, SFlags flags=Style_Default, const QStyleOption & = QStyleOption::Default) const;
37 virtual void drawControl( ControlElement ce, QPainter *p, const QWidget *widget, const QRect &r, const QColorGroup &cg, SFlags how=Style_Default, const QStyleOption & = QStyleOption::Default) const; 37 virtual void drawControl( ControlElement ce, QPainter *p, const QWidget *widget, const QRect &r, const QColorGroup &cg, SFlags how=Style_Default, const QStyleOption & = QStyleOption::Default) const;
38 virtual void drawComplexControl( ComplexControl control, QPainter *p, const QWidget *widget, const QRect &r, const QColorGroup &cg, SFlags how=Style_Default, SCFlags sub=SC_All, SCFlags subActive=SC_None, const QStyleOption & = QStyleOption::Default) const; 38 virtual void drawComplexControl( ComplexControl control, QPainter *p, const QWidget *widget, const QRect &r, const QColorGroup &cg, SFlags how=Style_Default, SCFlags sub=SC_All, SCFlags subActive=SC_None, const QStyleOption & = QStyleOption::Default) const;
39 virtual int pixelMetric( PixelMetric metric, const QWidget *widget=0 ) const; 39 virtual int pixelMetric( PixelMetric metric, const QWidget *widget=0 ) const;
40 virtual QSize sizeFromContents( ContentsType contents, const QWidget *widget, const QSize &contentsSize, const QStyleOption & = QStyleOption::Default) const; 40 virtual QSize sizeFromContents( ContentsType contents, const QWidget *widget, const QSize &contentsSize, const QStyleOption & = QStyleOption::Default) const;
41}; 41};
42 42
43#else 43#else
44 44
45class Q_EXPORT QPEStyle : public QWindowsStyle 45class Q_EXPORT QPEStyle : public QWindowsStyle
46{ 46{
47public: 47public:
48 QPEStyle(); 48 QPEStyle();
49 virtual ~QPEStyle(); 49 virtual ~QPEStyle();
50 virtual void polish( QPalette &p ); 50 virtual void polish( QPalette &p );
51 virtual void polish( QWidget *w ); 51 virtual void polish( QWidget *w );
52 virtual void unPolish( QWidget *w ); 52 virtual void unPolish( QWidget *w );
53 53
54 int defaultFrameWidth () const; 54 int defaultFrameWidth () const;
55 void drawPanel ( QPainter * p, int x, int y, int w, int h, 55 void drawPanel ( QPainter * p, int x, int y, int w, int h,
56 const QColorGroup &, bool sunken=FALSE, int lineWidth = 1, const QBrush * fill = 0 ); 56 const QColorGroup &, bool sunken=FALSE, int lineWidth = 1, const QBrush * fill = 0 );
57 void drawButton( QPainter *p, int x, int y, int w, int h, 57 void drawButton( QPainter *p, int x, int y, int w, int h,
58 const QColorGroup &g, bool sunken, const QBrush* fill ); 58 const QColorGroup &g, bool sunken, const QBrush* fill );
59 void drawButtonMask ( QPainter * p, int x, int y, int w, int h ); 59 void drawButtonMask ( QPainter * p, int x, int y, int w, int h );
60 void drawBevelButton( QPainter *p, int x, int y, int w, int h, 60 void drawBevelButton( QPainter *p, int x, int y, int w, int h,
61 const QColorGroup &g, bool sunken=FALSE, const QBrush* fill=0 ); 61 const QColorGroup &g, bool sunken=FALSE, const QBrush* fill=0 );
62 QRect comboButtonRect( int x, int y, int w, int h); 62 QRect comboButtonRect( int x, int y, int w, int h);
63 QRect comboButtonFocusRect( int x, int y, int w, int h); 63 QRect comboButtonFocusRect( int x, int y, int w, int h);
64 void drawComboButton( QPainter *p, int x, int y, int w, int h, 64 void drawComboButton( QPainter *p, int x, int y, int w, int h,
65 const QColorGroup &g, bool sunken, bool, bool enabled, 65 const QColorGroup &g, bool sunken, bool, bool enabled,
66 const QBrush *fill ); 66 const QBrush *fill );
67 void drawExclusiveIndicator ( QPainter * p, int x, int y, int w, int h, 67 void drawExclusiveIndicator ( QPainter * p, int x, int y, int w, int h,
68 const QColorGroup & g, bool on, bool down = FALSE, bool enabled = TRUE ); 68 const QColorGroup & g, bool on, bool down = FALSE, bool enabled = TRUE );
69 void drawIndicator ( QPainter * p, int x, int y, int w, int h, 69 void drawIndicator ( QPainter * p, int x, int y, int w, int h,
70 const QColorGroup & g, int state, bool down = FALSE, bool enabled = TRUE ); 70 const QColorGroup & g, int state, bool down = FALSE, bool enabled = TRUE );
71 void scrollBarMetrics( const QScrollBar*, int&, int&, int&, int&); 71 void scrollBarMetrics( const QScrollBar*, int&, int&, int&, int&);
72 void drawScrollBarControls( QPainter*, const QScrollBar*, int sliderStart, uint controls, uint activeControl ); 72 void drawScrollBarControls( QPainter*, const QScrollBar*, int sliderStart, uint controls, uint activeControl );
73 ScrollControl scrollBarPointOver( const QScrollBar* sb, int sliderStart, const QPoint& p ); 73 ScrollControl scrollBarPointOver( const QScrollBar* sb, int sliderStart, const QPoint& p );
74 void drawRiffles( QPainter* p, int x, int y, int w, int h, 74 void drawRiffles( QPainter* p, int x, int y, int w, int h,
75 const QColorGroup &g, bool horizontal ); 75 const QColorGroup &g, bool horizontal );
76 int sliderLength() const; 76 int sliderLength() const;
77 void drawSlider( QPainter *p, int x, int y, int w, int h, 77 void drawSlider( QPainter *p, int x, int y, int w, int h,
78 const QColorGroup &g, Orientation, bool tickAbove, bool tickBelow ); 78 const QColorGroup &g, Orientation, bool tickAbove, bool tickBelow );
79 void drawSliderMask( QPainter *p, int x, int y, int w, int h, 79 void drawSliderMask( QPainter *p, int x, int y, int w, int h,
80 Orientation, bool tickAbove, bool tickBelow ); 80 Orientation, bool tickAbove, bool tickBelow );
81 void drawSliderGrooveMask( QPainter *p, int x, int y, int w, int h, 81 void drawSliderGrooveMask( QPainter *p, int x, int y, int w, int h,
82 const QColorGroup& , QCOORD c, Orientation orient ); 82 const QColorGroup& , QCOORD c, Orientation orient );
83 void drawTab( QPainter *, const QTabBar *, QTab *, bool selected ); 83 void drawTab( QPainter *, const QTabBar *, QTab *, bool selected );
84 int extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem*, const QFontMetrics& ); 84 int extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem*, const QFontMetrics& );
85 int popupMenuItemHeight( bool checkable, QMenuItem*, const QFontMetrics& ); 85 int popupMenuItemHeight( bool checkable, QMenuItem*, const QFontMetrics& );
86 void drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi, 86 void drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi,
87 const QPalette& pal, 87 const QPalette& pal,
88 bool act, bool enabled, int x, int y, int w, int h); 88 bool act, bool enabled, int x, int y, int w, int h);
89 89
90 int buttonMargin() const; 90 int buttonMargin() const;
91 QSize scrollBarExtent() const; 91 QSize scrollBarExtent() const;
92 92
93 private:// Disabled copy constructor and operator= 93 private:// Disabled copy constructor and operator=
94#if defined(Q_DISABLE_COPY) 94#if defined(Q_DISABLE_COPY)
95 QPEStyle( const QPEStyle & ); 95 QPEStyle( const QPEStyle & );
96 QPEStyle& operator=( const QPEStyle & ); 96 QPEStyle& operator=( const QPEStyle & );
97#endif 97#endif
98}; 98};
99 99
100#endif 100#endif
101 101
102#endif // QPESTYLE_H 102#endif // QPESTYLE_H
diff --git a/noncore/apps/opie-console/TEWidget.cpp b/noncore/apps/opie-console/TEWidget.cpp
index 98c1793..1199e4f 100644
--- a/noncore/apps/opie-console/TEWidget.cpp
+++ b/noncore/apps/opie-console/TEWidget.cpp
@@ -1,1352 +1,1352 @@
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 <qpe/config.h> 52#include <qpe/config.h>
53 53
54#include <qapplication.h> 54#include <qapplication.h>
55#include <qclipboard.h> 55#include <qclipboard.h>
56 56
57#include <stdio.h> 57#include <stdio.h>
58#include <stdlib.h> 58#include <stdlib.h>
59#include <unistd.h> 59#include <unistd.h>
60#include <ctype.h> 60#include <ctype.h>
61#include <sys/stat.h> 61#include <sys/stat.h>
62#include <sys/types.h> 62#include <sys/types.h>
63#include <signal.h> 63#include <signal.h>
64 64
65#include <assert.h> 65#include <assert.h>
66 66
67 67
68 68
69// #include "TEWidget.moc" 69// #include "TEWidget.moc"
70//#include <kapp.h> 70//#include <kapp.h>
71//#include <kcursor.h> 71//#include <kcursor.h>
72//#include <kurl.h> 72//#include <kurl.h>
73//#include <kdebug.h> 73//#include <kdebug.h>
74//#include <klocale.h> 74//#include <klocale.h>
75 75
76#define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__) 76#define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__)
77#define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); } 77#define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); }
78 78
79#define loc(X,Y) ((Y)*columns+(X)) 79#define loc(X,Y) ((Y)*columns+(X))
80 80
81//FIXME: the rim should normally be 1, 0 only when running in full screen mode. 81//FIXME: the rim should normally be 1, 0 only when running in full screen mode.
82#define rimX 0 // left/right rim width 82#define rimX 0 // left/right rim width
83#define rimY 0 // top/bottom rim high 83#define rimY 0 // top/bottom rim high
84 84
85#define yMouseScroll 1 85#define yMouseScroll 1
86// scroll increment used when dragging selection at top/bottom of window. 86// scroll increment used when dragging selection at top/bottom of window.
87 87
88/* Button XPM */ 88/* Button XPM */
89namespace { 89namespace {
90static char * menu_xpm[] = { 90static char * menu_xpm[] = {
91"12 12 5 1", 91"12 12 5 1",
92 " c None", 92 " c None",
93 ".c #000000", 93 ".c #000000",
94 "+c #FFFDAD", 94 "+c #FFFDAD",
95 "@c #FFFF00", 95 "@c #FFFF00",
96 "#c #E5E100", 96 "#c #E5E100",
97" ", 97" ",
98" ", 98" ",
99" ......... ", 99" ......... ",
100" .+++++++. ", 100" .+++++++. ",
101" .+@@@@#. ", 101" .+@@@@#. ",
102" .+@@@#. ", 102" .+@@@#. ",
103" .+@@#. ", 103" .+@@#. ",
104" .+@#. ", 104" .+@#. ",
105" .+#. ", 105" .+#. ",
106" .+. ", 106" .+. ",
107" .. ", 107" .. ",
108" "}; 108" "};
109 109
110} 110}
111 111
112 112
113/* ------------------------------------------------------------------------- */ 113/* ------------------------------------------------------------------------- */
114/* */ 114/* */
115/* Colors */ 115/* Colors */
116/* */ 116/* */
117/* ------------------------------------------------------------------------- */ 117/* ------------------------------------------------------------------------- */
118 118
119//FIXME: the default color table is in session.C now. 119//FIXME: the default color table is in session.C now.
120// We need a way to get rid of this one, here. 120// We need a way to get rid of this one, here.
121static const ColorEntry base_color_table[TABLE_COLORS] = 121static const ColorEntry base_color_table[TABLE_COLORS] =
122// The following are almost IBM standard color codes, with some slight 122// The following are almost IBM standard color codes, with some slight
123// gamma correction for the dim colors to compensate for bright X screens. 123// gamma correction for the dim colors to compensate for bright X screens.
124// It contains the 8 ansiterm/xterm colors in 2 intensities. 124// It contains the 8 ansiterm/xterm colors in 2 intensities.
125{ 125{
126 // Fixme: could add faint colors here, also. 126 // Fixme: could add faint colors here, also.
127 // normal 127 // normal
128 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback 128 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback
129 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red 129 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red
130 ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow 130 ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow
131 ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta 131 ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta
132 ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White 132 ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White
133 // intensiv 133 // intensiv
134 ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ), 134 ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ),
135 ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ), 135 ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ),
136 ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ), 136 ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ),
137 ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), 137 ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ),
138 ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 ) 138 ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 )
139}; 139};
140 140
141/* Note that we use ANSI color order (bgr), while IBMPC color order is (rgb) 141/* Note that we use ANSI color order (bgr), while IBMPC color order is (rgb)
142 142
143 Code 0 1 2 3 4 5 6 7 143 Code 0 1 2 3 4 5 6 7
144 ----------- ------- ------- ------- ------- ------- ------- ------- ------- 144 ----------- ------- ------- ------- ------- ------- ------- ------- -------
145 ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White 145 ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White
146 IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White 146 IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White
147*/ 147*/
148 148
149QColor TEWidget::getDefaultBackColor() 149QColor TEWidget::getDefaultBackColor()
150{ 150{
151 return color_table[DEFAULT_BACK_COLOR].color; 151 return color_table[DEFAULT_BACK_COLOR].color;
152} 152}
153 153
154const ColorEntry* TEWidget::getColorTable() const 154const ColorEntry* TEWidget::getColorTable() const
155{ 155{
156 return color_table; 156 return color_table;
157} 157}
158 158
159const ColorEntry* TEWidget::getdefaultColorTable() const 159const ColorEntry* TEWidget::getdefaultColorTable() const
160{ 160{
161 return base_color_table; 161 return base_color_table;
162} 162}
163 163
164 164
165const QPixmap *TEWidget::backgroundPixmap() 165const QPixmap *TEWidget::backgroundPixmap()
166{ 166{
167 static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm"); 167 static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm");
168 const QPixmap *pm = bg; 168 const QPixmap *pm = bg;
169 return pm; 169 return pm;
170} 170}
171 171
172void TEWidget::setColorTable(const ColorEntry table[]) 172void TEWidget::setColorTable(const ColorEntry table[])
173{ 173{
174 for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i]; 174 for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i];
175 175
176 const QPixmap* pm = backgroundPixmap(); 176 const QPixmap* pm = backgroundPixmap();
177 if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color); 177 if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color);
178 update(); 178 update();
179} 179}
180 180
181//FIXME: add backgroundPixmapChanged. 181//FIXME: add backgroundPixmapChanged.
182 182
183/* ------------------------------------------------------------------------- */ 183/* ------------------------------------------------------------------------- */
184/* */ 184/* */
185/* Font */ 185/* Font */
186/* */ 186/* */
187/* ------------------------------------------------------------------------- */ 187/* ------------------------------------------------------------------------- */
188 188
189/* 189/*
190 The VT100 has 32 special graphical characters. The usual vt100 extended 190 The VT100 has 32 special graphical characters. The usual vt100 extended
191 xterm fonts have these at 0x00..0x1f. 191 xterm fonts have these at 0x00..0x1f.
192 192
193 QT's iso mapping leaves 0x00..0x7f without any changes. But the graphicals 193 QT's iso mapping leaves 0x00..0x7f without any changes. But the graphicals
194 come in here as proper unicode characters. 194 come in here as proper unicode characters.
195 195
196 We treat non-iso10646 fonts as VT100 extended and do the requiered mapping 196 We treat non-iso10646 fonts as VT100 extended and do the requiered mapping
197 from unicode to 0x00..0x1f. The remaining translation is then left to the 197 from unicode to 0x00..0x1f. The remaining translation is then left to the
198 QCodec. 198 QCodec.
199*/ 199*/
200 200
201// assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i. 201// assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i.
202 202
203unsigned short vt100_graphics[32] = 203unsigned short vt100_graphics[32] =
204{ // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15 204{ // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15
205 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 205 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0,
206 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 206 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c,
207 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534, 207 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534,
208 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7 208 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7
209}; 209};
210 210
211static QChar vt100extended(QChar c) 211static QChar vt100extended(QChar c)
212{ 212{
213 switch (c.unicode()) 213 switch (c.unicode())
214 { 214 {
215 case 0x25c6 : return 1; 215 case 0x25c6 : return 1;
216 case 0x2592 : return 2; 216 case 0x2592 : return 2;
217 case 0x2409 : return 3; 217 case 0x2409 : return 3;
218 case 0x240c : return 4; 218 case 0x240c : return 4;
219 case 0x240d : return 5; 219 case 0x240d : return 5;
220 case 0x240a : return 6; 220 case 0x240a : return 6;
221 case 0x00b0 : return 7; 221 case 0x00b0 : return 7;
222 case 0x00b1 : return 8; 222 case 0x00b1 : return 8;
223 case 0x2424 : return 9; 223 case 0x2424 : return 9;
224 case 0x240b : return 10; 224 case 0x240b : return 10;
225 case 0x2518 : return 11; 225 case 0x2518 : return 11;
226 case 0x2510 : return 12; 226 case 0x2510 : return 12;
227 case 0x250c : return 13; 227 case 0x250c : return 13;
228 case 0x2514 : return 14; 228 case 0x2514 : return 14;
229 case 0x253c : return 15; 229 case 0x253c : return 15;
230 case 0xf800 : return 16; 230 case 0xf800 : return 16;
231 case 0xf801 : return 17; 231 case 0xf801 : return 17;
232 case 0x2500 : return 18; 232 case 0x2500 : return 18;
233 case 0xf803 : return 19; 233 case 0xf803 : return 19;
234 case 0xf804 : return 20; 234 case 0xf804 : return 20;
235 case 0x251c : return 21; 235 case 0x251c : return 21;
236 case 0x2524 : return 22; 236 case 0x2524 : return 22;
237 case 0x2534 : return 23; 237 case 0x2534 : return 23;
238 case 0x252c : return 24; 238 case 0x252c : return 24;
239 case 0x2502 : return 25; 239 case 0x2502 : return 25;
240 case 0x2264 : return 26; 240 case 0x2264 : return 26;
241 case 0x2265 : return 27; 241 case 0x2265 : return 27;
242 case 0x03c0 : return 28; 242 case 0x03c0 : return 28;
243 case 0x2260 : return 29; 243 case 0x2260 : return 29;
244 case 0x00a3 : return 30; 244 case 0x00a3 : return 30;
245 case 0x00b7 : return 31; 245 case 0x00b7 : return 31;
246 } 246 }
247 return c; 247 return c;
248} 248}
249 249
250static QChar identicalMap(QChar c) 250static QChar identicalMap(QChar c)
251{ 251{
252 return c; 252 return c;
253} 253}
254 254
255void TEWidget::fontChange(const QFont &) 255void TEWidget::fontChange(const QFont &)
256{ 256{
257 QFontMetrics fm(font()); 257 QFontMetrics fm(font());
258 font_h = fm.height(); 258 font_h = fm.height();
259 font_w = fm.maxWidth(); 259 font_w = fm.maxWidth();
260 font_a = fm.ascent(); 260 font_a = fm.ascent();
261//printf("font_h: %d\n",font_h); 261//printf("font_h: %d\n",font_h);
262//printf("font_w: %d\n",font_w); 262//printf("font_w: %d\n",font_w);
263//printf("font_a: %d\n",font_a); 263//printf("font_a: %d\n",font_a);
264//printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii()); 264//printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii());
265//printf("rawname: %s\n",font().rawName().ascii()); 265//printf("rawname: %s\n",font().rawName().ascii());
266 fontMap = 266 fontMap =
267#if QT_VERSION < 300 267#if QT_VERSION < 0x030000
268 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646") 268 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646")
269 ? vt100extended 269 ? vt100extended
270 : 270 :
271#endif 271#endif
272 identicalMap; 272 identicalMap;
273 propagateSize(); 273 propagateSize();
274 update(); 274 update();
275} 275}
276 276
277void TEWidget::setVTFont(const QFont& f) 277void TEWidget::setVTFont(const QFont& f)
278{ 278{
279 QFrame::setFont(f); 279 QFrame::setFont(f);
280} 280}
281 281
282QFont TEWidget::getVTFont() { 282QFont TEWidget::getVTFont() {
283 return font(); 283 return font();
284} 284}
285 285
286void TEWidget::setFont(const QFont &) 286void TEWidget::setFont(const QFont &)
287{ 287{
288 // ignore font change request if not coming from konsole itself 288 // ignore font change request if not coming from konsole itself
289} 289}
290 290
291/* ------------------------------------------------------------------------- */ 291/* ------------------------------------------------------------------------- */
292/* */ 292/* */
293/* Constructor / Destructor */ 293/* Constructor / Destructor */
294/* */ 294/* */
295/* ----------------------------------------------------------------------- */ 295/* ----------------------------------------------------------------------- */
296 296
297 297
298 298
299TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name) 299TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name)
300{ 300{
301#ifndef QT_NO_CLIPBOARD 301#ifndef QT_NO_CLIPBOARD
302 cb = QApplication::clipboard(); 302 cb = QApplication::clipboard();
303 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 303 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
304 this, SLOT(onClearSelection()) ); 304 this, SLOT(onClearSelection()) );
305#endif 305#endif
306 306
307 307
308 scrollbar = new QScrollBar( this ); 308 scrollbar = new QScrollBar( this );
309 scrollbar->setCursor( arrowCursor ); 309 scrollbar->setCursor( arrowCursor );
310 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 310 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
311 311
312 hscrollbar = new QScrollBar( Qt::Horizontal, this ); 312 hscrollbar = new QScrollBar( Qt::Horizontal, this );
313 hscrollbar->setCursor( arrowCursor ); 313 hscrollbar->setCursor( arrowCursor );
314 connect(hscrollbar, SIGNAL(valueChanged(int)), this, SLOT(hscrollChanged(int))); 314 connect(hscrollbar, SIGNAL(valueChanged(int)), this, SLOT(hscrollChanged(int)));
315 315
316 m_cornerButton = new QPushButton( this ); 316 m_cornerButton = new QPushButton( this );
317 m_cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) ); 317 m_cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) );
318 m_cornerButton->setMaximumSize( 14, 14 ); 318 m_cornerButton->setMaximumSize( 14, 14 );
319 m_cornerButton->hide(); 319 m_cornerButton->hide();
320 320
321 Config cfg("Konsole"); 321 Config cfg("Konsole");
322 cfg.setGroup("ScrollBar"); 322 cfg.setGroup("ScrollBar");
323 switch( cfg.readNumEntry("Position",2)){ 323 switch( cfg.readNumEntry("Position",2)){
324 case 0: 324 case 0:
325 scrollLoc = SCRNONE; 325 scrollLoc = SCRNONE;
326 break; 326 break;
327 case 1: 327 case 1:
328 scrollLoc = SCRLEFT; 328 scrollLoc = SCRLEFT;
329 break; 329 break;
330 case 2: 330 case 2:
331 scrollLoc = SCRRIGHT; 331 scrollLoc = SCRRIGHT;
332 break; 332 break;
333 }; 333 };
334 334
335 blinkT = new QTimer(this); 335 blinkT = new QTimer(this);
336 connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent())); 336 connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent()));
337 // blinking = FALSE; 337 // blinking = FALSE;
338 blinking = TRUE; 338 blinking = TRUE;
339 339
340 resizing = FALSE; 340 resizing = FALSE;
341 actSel = 0; 341 actSel = 0;
342 image = 0; 342 image = 0;
343 lines = 1; 343 lines = 1;
344 columns = 1; 344 columns = 1;
345 font_w = 1; 345 font_w = 1;
346 font_h = 1; 346 font_h = 1;
347 font_a = 1; 347 font_a = 1;
348 word_selection_mode = FALSE; 348 word_selection_mode = FALSE;
349 vcolumns = 0; 349 vcolumns = 0;
350 hposition = 0; 350 hposition = 0;
351 351
352 setMouseMarks(TRUE); 352 setMouseMarks(TRUE);
353 setVTFont( QFont("fixed") ); 353 setVTFont( QFont("fixed") );
354 setColorTable(base_color_table); // init color table 354 setColorTable(base_color_table); // init color table
355 355
356 qApp->installEventFilter( this ); //FIXME: see below 356 qApp->installEventFilter( this ); //FIXME: see below
357// KCursor::setAutoHideCursor( this, true ); 357// KCursor::setAutoHideCursor( this, true );
358 358
359 // Init DnD //////////////////////////////////////////////////////////////// 359 // Init DnD ////////////////////////////////////////////////////////////////
360 currentSession = NULL; 360 currentSession = NULL;
361// setAcceptDrops(true); // attempt 361// setAcceptDrops(true); // attempt
362// m_drop = new QPopupMenu(this); 362// m_drop = new QPopupMenu(this);
363// m_drop->insertItem( QString("Paste"), 0); 363// m_drop->insertItem( QString("Paste"), 0);
364// m_drop->insertItem( QString("cd"), 1); 364// m_drop->insertItem( QString("cd"), 1);
365// connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int))); 365// connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int)));
366 366
367 // we need focus so that the auto-hide cursor feature works 367 // we need focus so that the auto-hide cursor feature works
368 setFocus(); 368 setFocus();
369 setFocusPolicy( WheelFocus ); 369 setFocusPolicy( WheelFocus );
370} 370}
371 371
372//FIXME: make proper destructor 372//FIXME: make proper destructor
373// Here's a start (David) 373// Here's a start (David)
374TEWidget::~TEWidget() 374TEWidget::~TEWidget()
375{ 375{
376 qApp->removeEventFilter( this ); 376 qApp->removeEventFilter( this );
377 if (image) free(image); 377 if (image) free(image);
378} 378}
379 379
380/* ------------------------------------------------------------------------- */ 380/* ------------------------------------------------------------------------- */
381/* */ 381/* */
382/* Display Operations */ 382/* Display Operations */
383/* */ 383/* */
384/* ------------------------------------------------------------------------- */ 384/* ------------------------------------------------------------------------- */
385 385
386/*! 386/*!
387 attributed string draw primitive 387 attributed string draw primitive
388*/ 388*/
389 389
390void TEWidget::drawAttrStr(QPainter &paint, QRect rect, 390void TEWidget::drawAttrStr(QPainter &paint, QRect rect,
391 QString& str, ca attr, BOOL pm, BOOL clear) 391 QString& str, ca attr, BOOL pm, BOOL clear)
392{ 392{
393 if (pm && color_table[attr.b].transparent) 393 if (pm && color_table[attr.b].transparent)
394 { 394 {
395 paint.setBackgroundMode( TransparentMode ); 395 paint.setBackgroundMode( TransparentMode );
396 if (clear) erase(rect); 396 if (clear) erase(rect);
397 } 397 }
398 else 398 else
399 { 399 {
400 if (blinking) 400 if (blinking)
401 paint.fillRect(rect, color_table[attr.b].color); 401 paint.fillRect(rect, color_table[attr.b].color);
402 else 402 else
403 { 403 {
404 paint.setBackgroundMode( OpaqueMode ); 404 paint.setBackgroundMode( OpaqueMode );
405 paint.setBackgroundColor( color_table[attr.b].color ); 405 paint.setBackgroundColor( color_table[attr.b].color );
406 } 406 }
407 } 407 }
408 408
409 if (color_table[attr.f].bold) 409 if (color_table[attr.f].bold)
410 paint.setPen(QColor( 0x8F, 0x00, 0x00 )); 410 paint.setPen(QColor( 0x8F, 0x00, 0x00 ));
411 else 411 else
412 paint.setPen(color_table[attr.f].color); 412 paint.setPen(color_table[attr.f].color);
413 413
414 paint.drawText(rect.x(),rect.y()+font_a, str); 414 paint.drawText(rect.x(),rect.y()+font_a, str);
415 415
416 if (attr.r & RE_UNDERLINE) 416 if (attr.r & RE_UNDERLINE)
417 paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 ); 417 paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 );
418} 418}
419 419
420/*! 420/*!
421 The image can only be set completely. 421 The image can only be set completely.
422 422
423 The size of the new image may or may not match the size of the widget. 423 The size of the new image may or may not match the size of the widget.
424*/ 424*/
425 425
426void TEWidget::setImage(const ca* const newimg, int lines, int columns) 426void TEWidget::setImage(const ca* const newimg, int lines, int columns)
427{ int y,x,len; 427{ int y,x,len;
428 const QPixmap* pm = backgroundPixmap(); 428 const QPixmap* pm = backgroundPixmap();
429 QPainter paint; 429 QPainter paint;
430 setUpdatesEnabled(FALSE); 430 setUpdatesEnabled(FALSE);
431 paint.begin( this ); 431 paint.begin( this );
432HCNT("setImage"); 432HCNT("setImage");
433 433
434 QPoint tL = contentsRect().topLeft(); 434 QPoint tL = contentsRect().topLeft();
435 int tLx = tL.x(); 435 int tLx = tL.x();
436 int tLy = tL.y(); 436 int tLy = tL.y();
437 hasBlinker = FALSE; 437 hasBlinker = FALSE;
438 438
439 int cf = -1; // undefined 439 int cf = -1; // undefined
440 int cb = -1; // undefined 440 int cb = -1; // undefined
441 int cr = -1; // undefined 441 int cr = -1; // undefined
442 442
443 int lins = QMIN(this->lines, QMAX(0,lines )); 443 int lins = QMIN(this->lines, QMAX(0,lines ));
444 int cols = QMIN(this->columns,QMAX(0,columns)); 444 int cols = QMIN(this->columns,QMAX(0,columns));
445 QChar *disstrU = new QChar[cols]; 445 QChar *disstrU = new QChar[cols];
446 446
447//{ static int cnt = 0; printf("setImage %d\n",cnt++); } 447//{ static int cnt = 0; printf("setImage %d\n",cnt++); }
448 for (y = 0; y < lins; y++) 448 for (y = 0; y < lins; y++)
449 { 449 {
450 const ca* lcl = &image[y*this->columns]; 450 const ca* lcl = &image[y*this->columns];
451 const ca* const ext = &newimg[y*columns]; 451 const ca* const ext = &newimg[y*columns];
452 if (!resizing) // not while resizing, we're expecting a paintEvent 452 if (!resizing) // not while resizing, we're expecting a paintEvent
453 for (x = 0; x < cols; x++) 453 for (x = 0; x < cols; x++)
454 { 454 {
455 hasBlinker |= (ext[x].r & RE_BLINK); 455 hasBlinker |= (ext[x].r & RE_BLINK);
456 if (ext[x] != lcl[x]) 456 if (ext[x] != lcl[x])
457 { 457 {
458 cr = ext[x].r; 458 cr = ext[x].r;
459 cb = ext[x].b; 459 cb = ext[x].b;
460 if (ext[x].f != cf) cf = ext[x].f; 460 if (ext[x].f != cf) cf = ext[x].f;
461 int lln = cols - x; 461 int lln = cols - x;
462 disstrU[0] = fontMap(ext[x+0].c); 462 disstrU[0] = fontMap(ext[x+0].c);
463 for (len = 1; len < lln; len++) 463 for (len = 1; len < lln; len++)
464 { 464 {
465 if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr || 465 if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr ||
466 ext[x+len] == lcl[x+len] ) 466 ext[x+len] == lcl[x+len] )
467 break; 467 break;
468 disstrU[len] = fontMap(ext[x+len].c); 468 disstrU[len] = fontMap(ext[x+len].c);
469 } 469 }
470 QString unistr(disstrU,len); 470 QString unistr(disstrU,len);
471 drawAttrStr(paint, 471 drawAttrStr(paint,
472 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), 472 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h),
473 unistr, ext[x], pm != NULL, true); 473 unistr, ext[x], pm != NULL, true);
474 x += len - 1; 474 x += len - 1;
475 } 475 }
476 } 476 }
477 // finally, make `image' become `newimg'. 477 // finally, make `image' become `newimg'.
478 memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca)); 478 memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca));
479 } 479 }
480 drawFrame( &paint ); 480 drawFrame( &paint );
481 paint.end(); 481 paint.end();
482 setUpdatesEnabled(TRUE); 482 setUpdatesEnabled(TRUE);
483 if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms 483 if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms
484 if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; } 484 if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; }
485 delete [] disstrU; 485 delete [] disstrU;
486} 486}
487 487
488// paint Event //////////////////////////////////////////////////// 488// paint Event ////////////////////////////////////////////////////
489 489
490/*! 490/*!
491 The difference of this routine vs. the `setImage' is, 491 The difference of this routine vs. the `setImage' is,
492 that the drawing does not include a difference analysis 492 that the drawing does not include a difference analysis
493 between the old and the new image. Instead, the internal 493 between the old and the new image. Instead, the internal
494 image is used and the painting bound by the PaintEvent box. 494 image is used and the painting bound by the PaintEvent box.
495*/ 495*/
496 496
497void TEWidget::paintEvent( QPaintEvent* pe ) 497void TEWidget::paintEvent( QPaintEvent* pe )
498{ 498{
499 499
500//{ static int cnt = 0; printf("paint %d\n",cnt++); } 500//{ static int cnt = 0; printf("paint %d\n",cnt++); }
501 const QPixmap* pm = backgroundPixmap(); 501 const QPixmap* pm = backgroundPixmap();
502 QPainter paint; 502 QPainter paint;
503 setUpdatesEnabled(FALSE); 503 setUpdatesEnabled(FALSE);
504 paint.begin( this ); 504 paint.begin( this );
505 paint.setBackgroundMode( TransparentMode ); 505 paint.setBackgroundMode( TransparentMode );
506HCNT("paintEvent"); 506HCNT("paintEvent");
507 507
508 // Note that the actual widget size can be slightly larger 508 // Note that the actual widget size can be slightly larger
509 // that the image (the size is truncated towards the smaller 509 // that the image (the size is truncated towards the smaller
510 // number of characters in `resizeEvent'. The paint rectangle 510 // number of characters in `resizeEvent'. The paint rectangle
511 // can thus be larger than the image, but less then the size 511 // can thus be larger than the image, but less then the size
512 // of one character. 512 // of one character.
513 513
514 QRect rect = pe->rect().intersect(contentsRect()); 514 QRect rect = pe->rect().intersect(contentsRect());
515 515
516 QPoint tL = contentsRect().topLeft(); 516 QPoint tL = contentsRect().topLeft();
517 int tLx = tL.x(); 517 int tLx = tL.x();
518 int tLy = tL.y(); 518 int tLy = tL.y();
519 519
520 int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w)); 520 int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w));
521 int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h)); 521 int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h));
522 int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w)); 522 int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w));
523 int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h)); 523 int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h));
524 524
525 /* 525 /*
526 printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly, 526 printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly,
527 rect.left(), rect.right(), rect.top(), rect.bottom()); 527 rect.left(), rect.right(), rect.top(), rect.bottom());
528 */ 528 */
529 529
530 // if (pm != NULL && color_table[image->b].transparent) 530 // if (pm != NULL && color_table[image->b].transparent)
531 // erase(rect); 531 // erase(rect);
532 // BL: I have no idea why we need this, and it breaks the refresh. 532 // BL: I have no idea why we need this, and it breaks the refresh.
533 533
534 QChar *disstrU = new QChar[columns]; 534 QChar *disstrU = new QChar[columns];
535 for (int y = luy; y <= rly; y++) 535 for (int y = luy; y <= rly; y++)
536 for (int x = lux; x <= rlx; x++) 536 for (int x = lux; x <= rlx; x++)
537 { 537 {
538 int len = 1; 538 int len = 1;
539 disstrU[0] = fontMap(image[loc(x,y)].c); 539 disstrU[0] = fontMap(image[loc(x,y)].c);
540 int cf = image[loc(x,y)].f; 540 int cf = image[loc(x,y)].f;
541 int cb = image[loc(x,y)].b; 541 int cb = image[loc(x,y)].b;
542 int cr = image[loc(x,y)].r; 542 int cr = image[loc(x,y)].r;
543 while (x+len <= rlx && 543 while (x+len <= rlx &&
544 image[loc(x+len,y)].f == cf && 544 image[loc(x+len,y)].f == cf &&
545 image[loc(x+len,y)].b == cb && 545 image[loc(x+len,y)].b == cb &&
546 image[loc(x+len,y)].r == cr ) 546 image[loc(x+len,y)].r == cr )
547 { 547 {
548 disstrU[len] = fontMap(image[loc(x+len,y)].c); 548 disstrU[len] = fontMap(image[loc(x+len,y)].c);
549 len += 1; 549 len += 1;
550 } 550 }
551 QString unistr(disstrU,len); 551 QString unistr(disstrU,len);
552 drawAttrStr(paint, 552 drawAttrStr(paint,
553 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), 553 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h),
554 unistr, image[loc(x,y)], pm != NULL, false); 554 unistr, image[loc(x,y)], pm != NULL, false);
555 x += len - 1; 555 x += len - 1;
556 } 556 }
557 delete [] disstrU; 557 delete [] disstrU;
558 drawFrame( &paint ); 558 drawFrame( &paint );
559 paint.end(); 559 paint.end();
560 setUpdatesEnabled(TRUE); 560 setUpdatesEnabled(TRUE);
561} 561}
562 562
563void TEWidget::blinkEvent() 563void TEWidget::blinkEvent()
564{ 564{
565 blinking = !blinking; 565 blinking = !blinking;
566 repaint(FALSE); 566 repaint(FALSE);
567} 567}
568 568
569/* ------------------------------------------------------------------------- */ 569/* ------------------------------------------------------------------------- */
570/* */ 570/* */
571/* Resizing */ 571/* Resizing */
572/* */ 572/* */
573/* ------------------------------------------------------------------------- */ 573/* ------------------------------------------------------------------------- */
574 574
575void TEWidget::resizeEvent(QResizeEvent* ev) 575void TEWidget::resizeEvent(QResizeEvent* ev)
576{ 576{
577// printf("resize: %d,%d\n",ev->size().width(),ev->size().height()); 577// printf("resize: %d,%d\n",ev->size().width(),ev->size().height());
578 //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h); 578 //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h);
579 //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h); 579 //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h);
580 //printf("curren: %d,%d\n",width(),height()); 580 //printf("curren: %d,%d\n",width(),height());
581HCNT("resizeEvent"); 581HCNT("resizeEvent");
582 582
583 // see comment in `paintEvent' concerning the rounding. 583 // see comment in `paintEvent' concerning the rounding.
584 //FIXME: could make a routine here; check width(),height() 584 //FIXME: could make a routine here; check width(),height()
585 assert(ev->size().width() == width()); 585 assert(ev->size().width() == width());
586 assert(ev->size().height() == height()); 586 assert(ev->size().height() == height());
587 587
588 propagateSize(); 588 propagateSize();
589} 589}
590 590
591void TEWidget::propagateSize() 591void TEWidget::propagateSize()
592{ 592{
593 ca* oldimg = image; 593 ca* oldimg = image;
594 int oldlin = lines; 594 int oldlin = lines;
595 int oldcol = columns; 595 int oldcol = columns;
596 makeImage(); 596 makeImage();
597 // we copy the old image to reduce flicker 597 // we copy the old image to reduce flicker
598 int lins = QMIN(oldlin,lines); 598 int lins = QMIN(oldlin,lines);
599 int cols = QMIN(oldcol,columns); 599 int cols = QMIN(oldcol,columns);
600 if (oldimg) 600 if (oldimg)
601 { 601 {
602 for (int lin = 0; lin < lins; lin++) 602 for (int lin = 0; lin < lins; lin++)
603 memcpy((void*)&image[columns*lin], 603 memcpy((void*)&image[columns*lin],
604 (void*)&oldimg[oldcol*lin],cols*sizeof(ca)); 604 (void*)&oldimg[oldcol*lin],cols*sizeof(ca));
605 free(oldimg); //FIXME: try new,delete 605 free(oldimg); //FIXME: try new,delete
606 } 606 }
607 else 607 else
608 clearImage(); 608 clearImage();
609 609
610 //NOTE: control flows from the back through the chest right into the eye. 610 //NOTE: control flows from the back through the chest right into the eye.
611 // `emu' will call back via `setImage'. 611 // `emu' will call back via `setImage'.
612 612
613 resizing = TRUE; 613 resizing = TRUE;
614 emit changedImageSizeSignal(lines, columns); // expose resizeEvent 614 emit changedImageSizeSignal(lines, columns); // expose resizeEvent
615 resizing = FALSE; 615 resizing = FALSE;
616} 616}
617 617
618/* ------------------------------------------------------------------------- */ 618/* ------------------------------------------------------------------------- */
619/* */ 619/* */
620/* Scrollbar */ 620/* Scrollbar */
621/* */ 621/* */
622/* ------------------------------------------------------------------------- */ 622/* ------------------------------------------------------------------------- */
623 623
624void TEWidget::scrollChanged(int) 624void TEWidget::scrollChanged(int)
625{ 625{
626 emit changedHistoryCursor(scrollbar->value()); //expose 626 emit changedHistoryCursor(scrollbar->value()); //expose
627} 627}
628 628
629void TEWidget::hscrollChanged(int loc) 629void TEWidget::hscrollChanged(int loc)
630{ 630{
631 hposition = loc; 631 hposition = loc;
632 propagateSize(); 632 propagateSize();
633 update(); 633 update();
634} 634}
635 635
636void TEWidget::setScroll(int cursor, int slines) 636void TEWidget::setScroll(int cursor, int slines)
637{ 637{
638 disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 638 disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
639 scrollbar->setRange(0,slines); 639 scrollbar->setRange(0,slines);
640 scrollbar->setSteps(1,lines); 640 scrollbar->setSteps(1,lines);
641 scrollbar->setValue(cursor); 641 scrollbar->setValue(cursor);
642 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 642 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
643} 643}
644 644
645void TEWidget::setScrollbarLocation(int loc) 645void TEWidget::setScrollbarLocation(int loc)
646{ 646{
647 if (scrollLoc == loc) return; // quickly 647 if (scrollLoc == loc) return; // quickly
648 scrollLoc = loc; 648 scrollLoc = loc;
649 propagateSize(); 649 propagateSize();
650 update(); 650 update();
651} 651}
652 652
653/* ------------------------------------------------------------------------- */ 653/* ------------------------------------------------------------------------- */
654/* */ 654/* */
655/* Mouse */ 655/* Mouse */
656/* */ 656/* */
657/* ------------------------------------------------------------------------- */ 657/* ------------------------------------------------------------------------- */
658 658
659/*! 659/*!
660 Three different operations can be performed using the mouse, and the 660 Three different operations can be performed using the mouse, and the
661 routines in this section serve all of them: 661 routines in this section serve all of them:
662 662
663 1) The press/release events are exposed to the application 663 1) The press/release events are exposed to the application
664 2) Marking (press and move left button) and Pasting (press middle button) 664 2) Marking (press and move left button) and Pasting (press middle button)
665 3) The right mouse button is used from the configuration menu 665 3) The right mouse button is used from the configuration menu
666 666
667 NOTE: During the marking process we attempt to keep the cursor within 667 NOTE: During the marking process we attempt to keep the cursor within
668 the bounds of the text as being displayed by setting the mouse position 668 the bounds of the text as being displayed by setting the mouse position
669 whenever the mouse has left the text area. 669 whenever the mouse has left the text area.
670 670
671 Two reasons to do so: 671 Two reasons to do so:
672 1) QT does not allow the `grabMouse' to confine-to the TEWidget. 672 1) QT does not allow the `grabMouse' to confine-to the TEWidget.
673 Thus a `XGrapPointer' would have to be used instead. 673 Thus a `XGrapPointer' would have to be used instead.
674 2) Even if so, this would not help too much, since the text area 674 2) Even if so, this would not help too much, since the text area
675 of the TEWidget is normally not identical with it's bounds. 675 of the TEWidget is normally not identical with it's bounds.
676 676
677 The disadvantage of the current handling is, that the mouse can visibly 677 The disadvantage of the current handling is, that the mouse can visibly
678 leave the bounds of the widget and is then moved back. Because of the 678 leave the bounds of the widget and is then moved back. Because of the
679 current construction, and the reasons mentioned above, we cannot do better 679 current construction, and the reasons mentioned above, we cannot do better
680 without changing the overall construction. 680 without changing the overall construction.
681*/ 681*/
682 682
683/*! 683/*!
684*/ 684*/
685 685
686void TEWidget::mousePressEvent(QMouseEvent* ev) 686void TEWidget::mousePressEvent(QMouseEvent* ev)
687{ 687{
688//printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); 688//printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
689 if ( !contentsRect().contains(ev->pos()) ) return; 689 if ( !contentsRect().contains(ev->pos()) ) return;
690 QPoint tL = contentsRect().topLeft(); 690 QPoint tL = contentsRect().topLeft();
691 int tLx = tL.x(); 691 int tLx = tL.x();
692 int tLy = tL.y(); 692 int tLy = tL.y();
693 693
694 word_selection_mode = FALSE; 694 word_selection_mode = FALSE;
695 695
696//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY); 696//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY);
697 if ( ev->button() == LeftButton) 697 if ( ev->button() == LeftButton)
698 { 698 {
699 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 699 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
700 700
701 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; 701 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ;
702 702
703 if (mouse_marks || (ev->state() & ShiftButton)) 703 if (mouse_marks || (ev->state() & ShiftButton))
704 { 704 {
705 emit clearSelectionSignal(); 705 emit clearSelectionSignal();
706 iPntSel = pntSel = pos; 706 iPntSel = pntSel = pos;
707 actSel = 1; // left mouse button pressed but nothing selected yet. 707 actSel = 1; // left mouse button pressed but nothing selected yet.
708 grabMouse( /*crossCursor*/ ); // handle with care! 708 grabMouse( /*crossCursor*/ ); // handle with care!
709 } 709 }
710 else 710 else
711 { 711 {
712 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button 712 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button
713 } 713 }
714 } 714 }
715 if ( ev->button() == MidButton ) 715 if ( ev->button() == MidButton )
716 { 716 {
717 emitSelection(); 717 emitSelection();
718 } 718 }
719 if ( ev->button() == RightButton ) // Configure 719 if ( ev->button() == RightButton ) // Configure
720 { 720 {
721 emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() ); 721 emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() );
722 } 722 }
723} 723}
724 724
725void TEWidget::mouseMoveEvent(QMouseEvent* ev) 725void TEWidget::mouseMoveEvent(QMouseEvent* ev)
726{ 726{
727 // for auto-hiding the cursor, we need mouseTracking 727 // for auto-hiding the cursor, we need mouseTracking
728 if (ev->state() == NoButton ) return; 728 if (ev->state() == NoButton ) return;
729 729
730 if (actSel == 0) return; 730 if (actSel == 0) return;
731 731
732 // don't extend selection while pasting 732 // don't extend selection while pasting
733 if (ev->state() & MidButton) return; 733 if (ev->state() & MidButton) return;
734 734
735 //if ( !contentsRect().contains(ev->pos()) ) return; 735 //if ( !contentsRect().contains(ev->pos()) ) return;
736 QPoint tL = contentsRect().topLeft(); 736 QPoint tL = contentsRect().topLeft();
737 int tLx = tL.x(); 737 int tLx = tL.x();
738 int tLy = tL.y(); 738 int tLy = tL.y();
739 int scroll = scrollbar->value(); 739 int scroll = scrollbar->value();
740 740
741 // we're in the process of moving the mouse with the left button pressed 741 // we're in the process of moving the mouse with the left button pressed
742 // the mouse cursor will kept catched within the bounds of the text in 742 // the mouse cursor will kept catched within the bounds of the text in
743 // this widget. 743 // this widget.
744 744
745 // Adjust position within text area bounds. See FIXME above. 745 // Adjust position within text area bounds. See FIXME above.
746 QPoint pos = ev->pos(); 746 QPoint pos = ev->pos();
747 if ( pos.x() < tLx+blX ) pos.setX( tLx+blX ); 747 if ( pos.x() < tLx+blX ) pos.setX( tLx+blX );
748 if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w ); 748 if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w );
749 if ( pos.y() < tLy+bY ) pos.setY( tLy+bY ); 749 if ( pos.y() < tLy+bY ) pos.setY( tLy+bY );
750 if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 ); 750 if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 );
751 // check if we produce a mouse move event by this 751 // check if we produce a mouse move event by this
752 if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos)); 752 if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos));
753 753
754 if ( pos.y() == tLy+bY+lines*font_h-1 ) 754 if ( pos.y() == tLy+bY+lines*font_h-1 )
755 { 755 {
756 scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward 756 scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward
757 } 757 }
758 if ( pos.y() == tLy+bY ) 758 if ( pos.y() == tLy+bY )
759 { 759 {
760 scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback 760 scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback
761 } 761 }
762 762
763 QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h); 763 QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h);
764 QPoint ohere; 764 QPoint ohere;
765 bool swapping = FALSE; 765 bool swapping = FALSE;
766 766
767 if ( word_selection_mode ) 767 if ( word_selection_mode )
768 { 768 {
769 // Extend to word boundaries 769 // Extend to word boundaries
770 int i; 770 int i;
771 int selClass; 771 int selClass;
772 772
773 bool left_not_right = ( here.y() < iPntSel.y() || 773 bool left_not_right = ( here.y() < iPntSel.y() ||
774 here.y() == iPntSel.y() && here.x() < iPntSel.x() ); 774 here.y() == iPntSel.y() && here.x() < iPntSel.x() );
775 bool old_left_not_right = ( pntSel.y() < iPntSel.y() || 775 bool old_left_not_right = ( pntSel.y() < iPntSel.y() ||
776 pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); 776 pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() );
777 swapping = left_not_right != old_left_not_right; 777 swapping = left_not_right != old_left_not_right;
778 778
779 // Find left (left_not_right ? from here : from start) 779 // Find left (left_not_right ? from here : from start)
780 QPoint left = left_not_right ? here : iPntSel; 780 QPoint left = left_not_right ? here : iPntSel;
781 i = loc(left.x(),left.y()); 781 i = loc(left.x(),left.y());
782 selClass = charClass(image[i].c); 782 selClass = charClass(image[i].c);
783 while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) 783 while ( left.x() > 0 && charClass(image[i-1].c) == selClass )
784 { i--; left.rx()--; } 784 { i--; left.rx()--; }
785 785
786 // Find left (left_not_right ? from start : from here) 786 // Find left (left_not_right ? from start : from here)
787 QPoint right = left_not_right ? iPntSel : here; 787 QPoint right = left_not_right ? iPntSel : here;
788 i = loc(right.x(),right.y()); 788 i = loc(right.x(),right.y());
789 selClass = charClass(image[i].c); 789 selClass = charClass(image[i].c);
790 while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass ) 790 while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass )
791 { i++; right.rx()++; } 791 { i++; right.rx()++; }
792 792
793 // Pick which is start (ohere) and which is extension (here) 793 // Pick which is start (ohere) and which is extension (here)
794 if ( left_not_right ) 794 if ( left_not_right )
795 { 795 {
796 here = left; ohere = right; 796 here = left; ohere = right;
797 } 797 }
798 else 798 else
799 { 799 {
800 here = right; ohere = left; 800 here = right; ohere = left;
801 } 801 }
802 } 802 }
803 803
804 if (here == pntSel && scroll == scrollbar->value()) return; // not moved 804 if (here == pntSel && scroll == scrollbar->value()) return; // not moved
805 805
806 if ( word_selection_mode ) { 806 if ( word_selection_mode ) {
807 if ( actSel < 2 || swapping ) { 807 if ( actSel < 2 || swapping ) {
808 emit beginSelectionSignal( ohere.x(), ohere.y() ); 808 emit beginSelectionSignal( ohere.x(), ohere.y() );
809 } 809 }
810 } else if ( actSel < 2 ) { 810 } else if ( actSel < 2 ) {
811 emit beginSelectionSignal( pntSel.x(), pntSel.y() ); 811 emit beginSelectionSignal( pntSel.x(), pntSel.y() );
812 } 812 }
813 813
814 actSel = 2; // within selection 814 actSel = 2; // within selection
815 pntSel = here; 815 pntSel = here;
816 emit extendSelectionSignal( here.x(), here.y() ); 816 emit extendSelectionSignal( here.x(), here.y() );
817} 817}
818 818
819void TEWidget::mouseReleaseEvent(QMouseEvent* ev) 819void TEWidget::mouseReleaseEvent(QMouseEvent* ev)
820{ 820{
821//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); 821//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
822 if ( ev->button() == LeftButton) 822 if ( ev->button() == LeftButton)
823 { 823 {
824 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); 824 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks);
825 preserve_line_breaks = TRUE; 825 preserve_line_breaks = TRUE;
826 actSel = 0; 826 actSel = 0;
827 827
828 //FIXME: emits a release event even if the mouse is 828 //FIXME: emits a release event even if the mouse is
829 // outside the range. The procedure used in `mouseMoveEvent' 829 // outside the range. The procedure used in `mouseMoveEvent'
830 // applies here, too. 830 // applies here, too.
831 831
832 QPoint tL = contentsRect().topLeft(); 832 QPoint tL = contentsRect().topLeft();
833 int tLx = tL.x(); 833 int tLx = tL.x();
834 int tLy = tL.y(); 834 int tLy = tL.y();
835 835
836 if (!mouse_marks && !(ev->state() & ShiftButton)) 836 if (!mouse_marks && !(ev->state() & ShiftButton))
837 emit mouseSignal( 3, // release 837 emit mouseSignal( 3, // release
838 (ev->x()-tLx-blX)/font_w + 1, 838 (ev->x()-tLx-blX)/font_w + 1,
839 (ev->y()-tLy-bY)/font_h + 1 ); 839 (ev->y()-tLy-bY)/font_h + 1 );
840 releaseMouse(); 840 releaseMouse();
841 } 841 }
842} 842}
843 843
844void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev) 844void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev)
845{ 845{
846 if ( ev->button() != LeftButton) return; 846 if ( ev->button() != LeftButton) return;
847 847
848 QPoint tL = contentsRect().topLeft(); 848 QPoint tL = contentsRect().topLeft();
849 int tLx = tL.x(); 849 int tLx = tL.x();
850 int tLy = tL.y(); 850 int tLy = tL.y();
851 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 851 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
852 852
853 // pass on double click as two clicks. 853 // pass on double click as two clicks.
854 if (!mouse_marks && !(ev->state() & ShiftButton)) 854 if (!mouse_marks && !(ev->state() & ShiftButton))
855 { 855 {
856 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 856 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
857 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release 857 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release
858 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 858 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
859 return; 859 return;
860 } 860 }
861 861
862 862
863 emit clearSelectionSignal(); 863 emit clearSelectionSignal();
864 QPoint bgnSel = pos; 864 QPoint bgnSel = pos;
865 QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 865 QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
866 int i = loc(bgnSel.x(),bgnSel.y()); 866 int i = loc(bgnSel.x(),bgnSel.y());
867 iPntSel = bgnSel; 867 iPntSel = bgnSel;
868 868
869 word_selection_mode = TRUE; 869 word_selection_mode = TRUE;
870 870
871 // find word boundaries... 871 // find word boundaries...
872 int selClass = charClass(image[i].c); 872 int selClass = charClass(image[i].c);
873 { 873 {
874 // set the start... 874 // set the start...
875 int x = bgnSel.x(); 875 int x = bgnSel.x();
876 while ( x > 0 && charClass(image[i-1].c) == selClass ) 876 while ( x > 0 && charClass(image[i-1].c) == selClass )
877 { i--; x--; } 877 { i--; x--; }
878 bgnSel.setX(x); 878 bgnSel.setX(x);
879 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); 879 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() );
880 880
881 // set the end... 881 // set the end...
882 i = loc( endSel.x(), endSel.y() ); 882 i = loc( endSel.x(), endSel.y() );
883 x = endSel.x(); 883 x = endSel.x();
884 while( x < columns-1 && charClass(image[i+1].c) == selClass ) 884 while( x < columns-1 && charClass(image[i+1].c) == selClass )
885 { i++; x++ ; } 885 { i++; x++ ; }
886 endSel.setX(x); 886 endSel.setX(x);
887 actSel = 2; // within selection 887 actSel = 2; // within selection
888 emit extendSelectionSignal( endSel.x(), endSel.y() ); 888 emit extendSelectionSignal( endSel.x(), endSel.y() );
889 emit endSelectionSignal(preserve_line_breaks); 889 emit endSelectionSignal(preserve_line_breaks);
890 preserve_line_breaks = TRUE; 890 preserve_line_breaks = TRUE;
891 } 891 }
892} 892}
893 893
894void TEWidget::focusInEvent( QFocusEvent * ) 894void TEWidget::focusInEvent( QFocusEvent * )
895{ 895{
896 896
897 // do nothing, to prevent repainting 897 // do nothing, to prevent repainting
898} 898}
899 899
900 900
901void TEWidget::focusOutEvent( QFocusEvent * ) 901void TEWidget::focusOutEvent( QFocusEvent * )
902{ 902{
903 // do nothing, to prevent repainting 903 // do nothing, to prevent repainting
904} 904}
905 905
906bool TEWidget::focusNextPrevChild( bool next ) 906bool TEWidget::focusNextPrevChild( bool next )
907{ 907{
908 if (next) 908 if (next)
909 return false; // This disables changing the active part in konqueror 909 return false; // This disables changing the active part in konqueror
910 // when pressing Tab 910 // when pressing Tab
911 return QFrame::focusNextPrevChild( next ); 911 return QFrame::focusNextPrevChild( next );
912} 912}
913 913
914 914
915int TEWidget::charClass(char ch) const 915int TEWidget::charClass(char ch) const
916{ 916{
917 // This might seem like overkill, but imagine if ch was a Unicode 917 // This might seem like overkill, but imagine if ch was a Unicode
918 // character (Qt 2.0 QChar) - it might then be sensible to separate 918 // character (Qt 2.0 QChar) - it might then be sensible to separate
919 // the different language ranges, etc. 919 // the different language ranges, etc.
920 920
921 if ( isspace(ch) ) return ' '; 921 if ( isspace(ch) ) return ' ';
922 922
923 static const char *word_characters = ":@-./_~"; 923 static const char *word_characters = ":@-./_~";
924 if ( isalnum(ch) || strchr(word_characters, ch) ) 924 if ( isalnum(ch) || strchr(word_characters, ch) )
925 return 'a'; 925 return 'a';
926 926
927 // Everything else is weird 927 // Everything else is weird
928 return 1; 928 return 1;
929} 929}
930 930
931void TEWidget::setMouseMarks(bool on) 931void TEWidget::setMouseMarks(bool on)
932{ 932{
933 mouse_marks = on; 933 mouse_marks = on;
934 setCursor( mouse_marks ? ibeamCursor : arrowCursor ); 934 setCursor( mouse_marks ? ibeamCursor : arrowCursor );
935} 935}
936 936
937/* ------------------------------------------------------------------------- */ 937/* ------------------------------------------------------------------------- */
938/* */ 938/* */
939/* Clipboard */ 939/* Clipboard */
940/* */ 940/* */
941/* ------------------------------------------------------------------------- */ 941/* ------------------------------------------------------------------------- */
942 942
943#undef KeyPress 943#undef KeyPress
944 944
945void TEWidget::emitSelection() 945void TEWidget::emitSelection()
946// Paste Clipboard by simulating keypress events 946// Paste Clipboard by simulating keypress events
947{ 947{
948#ifndef QT_NO_CLIPBOARD 948#ifndef QT_NO_CLIPBOARD
949 QString text = QApplication::clipboard()->text(); 949 QString text = QApplication::clipboard()->text();
950 if ( ! text.isNull() ) 950 if ( ! text.isNull() )
951 { 951 {
952 text.replace(QRegExp("\n"), "\r"); 952 text.replace(QRegExp("\n"), "\r");
953 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 953 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
954 emit keyPressedSignal(&e); // expose as a big fat keypress event 954 emit keyPressedSignal(&e); // expose as a big fat keypress event
955 emit clearSelectionSignal(); 955 emit clearSelectionSignal();
956 } 956 }
957#endif 957#endif
958} 958}
959 959
960void TEWidget::emitText(QString text) 960void TEWidget::emitText(QString text)
961{ 961{
962 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 962 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
963 emit keyPressedSignal(&e); // expose as a big fat keypress event 963 emit keyPressedSignal(&e); // expose as a big fat keypress event
964} 964}
965 965
966void TEWidget::pasteClipboard( ) 966void TEWidget::pasteClipboard( )
967{ 967{
968 emitSelection(); 968 emitSelection();
969} 969}
970 970
971void TEWidget::setSelection(const QString& t) 971void TEWidget::setSelection(const QString& t)
972{ 972{
973#ifndef QT_NO_CLIPBOARD 973#ifndef QT_NO_CLIPBOARD
974 // Disconnect signal while WE set the clipboard 974 // Disconnect signal while WE set the clipboard
975 QObject *cb = QApplication::clipboard(); 975 QObject *cb = QApplication::clipboard();
976 QObject::disconnect( cb, SIGNAL(dataChanged()), 976 QObject::disconnect( cb, SIGNAL(dataChanged()),
977 this, SLOT(onClearSelection()) ); 977 this, SLOT(onClearSelection()) );
978 978
979 QApplication::clipboard()->setText(t); 979 QApplication::clipboard()->setText(t);
980 980
981 QObject::connect( cb, SIGNAL(dataChanged()), 981 QObject::connect( cb, SIGNAL(dataChanged()),
982 this, SLOT(onClearSelection()) ); 982 this, SLOT(onClearSelection()) );
983#endif 983#endif
984} 984}
985 985
986void TEWidget::onClearSelection() 986void TEWidget::onClearSelection()
987{ 987{
988 emit clearSelectionSignal(); 988 emit clearSelectionSignal();
989} 989}
990 990
991/* ------------------------------------------------------------------------- */ 991/* ------------------------------------------------------------------------- */
992/* */ 992/* */
993/* Keyboard */ 993/* Keyboard */
994/* */ 994/* */
995/* ------------------------------------------------------------------------- */ 995/* ------------------------------------------------------------------------- */
996 996
997//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' 997//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent'
998// due to a bug in `QT' or the ignorance of the author to prevent 998// due to a bug in `QT' or the ignorance of the author to prevent
999// repaint events being emitted to the screen whenever one leaves 999// repaint events being emitted to the screen whenever one leaves
1000// or reenters the screen to/from another application. 1000// or reenters the screen to/from another application.
1001// 1001//
1002// Troll says one needs to change focusInEvent() and focusOutEvent(), 1002// Troll says one needs to change focusInEvent() and focusOutEvent(),
1003// which would also let you have an in-focus cursor and an out-focus 1003// which would also let you have an in-focus cursor and an out-focus
1004// cursor like xterm does. 1004// cursor like xterm does.
1005 1005
1006// for the auto-hide cursor feature, I added empty focusInEvent() and 1006// for the auto-hide cursor feature, I added empty focusInEvent() and
1007// focusOutEvent() so that update() isn't called. 1007// focusOutEvent() so that update() isn't called.
1008// For auto-hide, we need to get keypress-events, but we only get them when 1008// For auto-hide, we need to get keypress-events, but we only get them when
1009// we have focus. 1009// we have focus.
1010 1010
1011void TEWidget::doScroll(int lines) 1011void TEWidget::doScroll(int lines)
1012{ 1012{
1013 scrollbar->setValue(scrollbar->value()+lines); 1013 scrollbar->setValue(scrollbar->value()+lines);
1014} 1014}
1015 1015
1016bool TEWidget::eventFilter( QObject *obj, QEvent *e ) 1016bool TEWidget::eventFilter( QObject *obj, QEvent *e )
1017{ 1017{
1018 if ( (e->type() == QEvent::Accel || 1018 if ( (e->type() == QEvent::Accel ||
1019 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { 1019 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) {
1020 static_cast<QKeyEvent *>( e )->ignore(); 1020 static_cast<QKeyEvent *>( e )->ignore();
1021 return true; 1021 return true;
1022 } 1022 }
1023 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) 1023 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ )
1024 return FALSE; // not us 1024 return FALSE; // not us
1025 if ( e->type() == QEvent::Wheel) { 1025 if ( e->type() == QEvent::Wheel) {
1026 QApplication::sendEvent(scrollbar, e); 1026 QApplication::sendEvent(scrollbar, e);
1027 } 1027 }
1028 1028
1029#ifdef FAKE_CTRL_AND_ALT 1029#ifdef FAKE_CTRL_AND_ALT
1030 static bool control = FALSE; 1030 static bool control = FALSE;
1031 static bool alt = FALSE; 1031 static bool alt = FALSE;
1032 bool dele=FALSE; 1032 bool dele=FALSE;
1033 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 1033 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
1034 QKeyEvent* ke = (QKeyEvent*)e; 1034 QKeyEvent* ke = (QKeyEvent*)e;
1035 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); 1035 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat();
1036 switch (ke->key()) { 1036 switch (ke->key()) {
1037 case Key_F9: // let this be "Control" 1037 case Key_F9: // let this be "Control"
1038 control = keydown; 1038 control = keydown;
1039 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); 1039 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state());
1040 dele=TRUE; 1040 dele=TRUE;
1041 break; 1041 break;
1042 case Key_F13: // let this be "Alt" 1042 case Key_F13: // let this be "Alt"
1043 alt = keydown; 1043 alt = keydown;
1044 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); 1044 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state());
1045 dele=TRUE; 1045 dele=TRUE;
1046 break; 1046 break;
1047 default: 1047 default:
1048 if ( control ) { 1048 if ( control ) {
1049 int a = toupper(ke->ascii())-64; 1049 int a = toupper(ke->ascii())-64;
1050 if ( a >= 0 && a < ' ' ) { 1050 if ( a >= 0 && a < ' ' ) {
1051 e = new QKeyEvent(e->type(), ke->key(), 1051 e = new QKeyEvent(e->type(), ke->key(),
1052 a, ke->state()|ControlButton, QChar(a,0)); 1052 a, ke->state()|ControlButton, QChar(a,0));
1053 dele=TRUE; 1053 dele=TRUE;
1054 } 1054 }
1055 } 1055 }
1056 if ( alt ) { 1056 if ( alt ) {
1057 e = new QKeyEvent(e->type(), ke->key(), 1057 e = new QKeyEvent(e->type(), ke->key(),
1058 ke->ascii(), ke->state()|AltButton, ke->text()); 1058 ke->ascii(), ke->state()|AltButton, ke->text());
1059 dele=TRUE; 1059 dele=TRUE;
1060 } 1060 }
1061 } 1061 }
1062 } 1062 }
1063#endif 1063#endif
1064 1064
1065 if ( e->type() == QEvent::KeyPress ) { 1065 if ( e->type() == QEvent::KeyPress ) {
1066 QKeyEvent* ke = (QKeyEvent*)e; 1066 QKeyEvent* ke = (QKeyEvent*)e;
1067 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
1068 // know where the current selection is. 1068 // know where the current selection is.
1069 1069
1070 1070
1071 if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker 1071 if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker
1072 emitText("\\"); // expose 1072 emitText("\\"); // expose
1073 } else 1073 } else
1074 emit keyPressedSignal(ke); // expose 1074 emit keyPressedSignal(ke); // expose
1075 ke->accept(); 1075 ke->accept();
1076#ifdef FAKE_CTRL_AND_ALT 1076#ifdef FAKE_CTRL_AND_ALT
1077 if ( dele ) delete e; 1077 if ( dele ) delete e;
1078#endif 1078#endif
1079 return true; // stop the event 1079 return true; // stop the event
1080 } 1080 }
1081 if ( e->type() == QEvent::Enter ) { 1081 if ( e->type() == QEvent::Enter ) {
1082 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), 1082 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()),
1083 this, SLOT(onClearSelection()) ); 1083 this, SLOT(onClearSelection()) );
1084 } 1084 }
1085 if ( e->type() == QEvent::Leave ) { 1085 if ( e->type() == QEvent::Leave ) {
1086 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 1086 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
1087 this, SLOT(onClearSelection()) ); 1087 this, SLOT(onClearSelection()) );
1088 } 1088 }
1089 return QFrame::eventFilter( obj, e ); 1089 return QFrame::eventFilter( obj, e );
1090} 1090}
1091 1091
1092/* ------------------------------------------------------------------------- */ 1092/* ------------------------------------------------------------------------- */
1093/* */ 1093/* */
1094/* Frame */ 1094/* Frame */
1095/* */ 1095/* */
1096/* ------------------------------------------------------------------------- */ 1096/* ------------------------------------------------------------------------- */
1097 1097
1098void TEWidget::frameChanged() 1098void TEWidget::frameChanged()
1099{ 1099{
1100 propagateSize(); 1100 propagateSize();
1101 update(); 1101 update();
1102} 1102}
1103 1103
1104/* ------------------------------------------------------------------------- */ 1104/* ------------------------------------------------------------------------- */
1105/* */ 1105/* */
1106/* Sound */ 1106/* Sound */
1107/* */ 1107/* */
1108/* ------------------------------------------------------------------------- */ 1108/* ------------------------------------------------------------------------- */
1109 1109
1110void TEWidget::Bell() 1110void TEWidget::Bell()
1111{ 1111{
1112 QApplication::beep(); 1112 QApplication::beep();
1113} 1113}
1114 1114
1115/* ------------------------------------------------------------------------- */ 1115/* ------------------------------------------------------------------------- */
1116/* */ 1116/* */
1117/* Auxiluary */ 1117/* Auxiluary */
1118/* */ 1118/* */
1119/* ------------------------------------------------------------------------- */ 1119/* ------------------------------------------------------------------------- */
1120 1120
1121void TEWidget::clearImage() 1121void TEWidget::clearImage()
1122// initialize the image 1122// initialize the image
1123// for internal use only 1123// for internal use only
1124{ 1124{
1125 for (int y = 0; y < lines; y++) 1125 for (int y = 0; y < lines; y++)
1126 for (int x = 0; x < columns; x++) 1126 for (int x = 0; x < columns; x++)
1127 { 1127 {
1128 image[loc(x,y)].c = 0xff; //' '; 1128 image[loc(x,y)].c = 0xff; //' ';
1129 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; 1129 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR;
1130 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; 1130 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR;
1131 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; 1131 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION;
1132 } 1132 }
1133} 1133}
1134 1134
1135// Create Image /////////////////////////////////////////////////////// 1135// Create Image ///////////////////////////////////////////////////////
1136 1136
1137void TEWidget::calcGeometry() 1137void TEWidget::calcGeometry()
1138{ 1138{
1139 //FIXME: set rimX == rimY == 0 when running in full screen mode. 1139 //FIXME: set rimX == rimY == 0 when running in full screen mode.
1140 1140
1141 int showhscrollbar = 1; 1141 int showhscrollbar = 1;
1142 int hwidth = 0; 1142 int hwidth = 0;
1143 int dcolumns; 1143 int dcolumns;
1144 1144
1145 if(vcolumns == 0) showhscrollbar = 0; 1145 if(vcolumns == 0) showhscrollbar = 0;
1146 if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width(); 1146 if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width();
1147 1147
1148 scrollbar->resize(QApplication::style().scrollBarExtent().width(), 1148 scrollbar->resize(QApplication::style().scrollBarExtent().width(),
1149 contentsRect().height() - hwidth); 1149 contentsRect().height() - hwidth);
1150 1150
1151 if(!showhscrollbar) cornerButton()->move(0, 0); 1151 if(!showhscrollbar) cornerButton()->move(0, 0);
1152 else cornerButton()->move(contentsRect().width() - hwidth, contentsRect().height() - hwidth); 1152 else cornerButton()->move(contentsRect().width() - hwidth, contentsRect().height() - hwidth);
1153 1153
1154 1154
1155 switch(scrollLoc) 1155 switch(scrollLoc)
1156 { 1156 {
1157 case SCRNONE : 1157 case SCRNONE :
1158 columns = ( contentsRect().width() - 2 * rimX ) / font_w; 1158 columns = ( contentsRect().width() - 2 * rimX ) / font_w;
1159 dcolumns = columns; 1159 dcolumns = columns;
1160 if(vcolumns) columns = vcolumns; 1160 if(vcolumns) columns = vcolumns;
1161 blX = (contentsRect().width() - (columns*font_w) ) / 2; 1161 blX = (contentsRect().width() - (columns*font_w) ) / 2;
1162 if(showhscrollbar) 1162 if(showhscrollbar)
1163 blX = -hposition * font_w; 1163 blX = -hposition * font_w;
1164 brX = blX; 1164 brX = blX;
1165 scrollbar->hide(); 1165 scrollbar->hide();
1166 break; 1166 break;
1167 case SCRLEFT : 1167 case SCRLEFT :
1168 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1168 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1169 dcolumns = columns; 1169 dcolumns = columns;
1170 if(vcolumns) columns = vcolumns; 1170 if(vcolumns) columns = vcolumns;
1171 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1171 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1172 if(showhscrollbar) 1172 if(showhscrollbar)
1173 brX = -hposition * font_w; 1173 brX = -hposition * font_w;
1174 blX = brX + scrollbar->width(); 1174 blX = brX + scrollbar->width();
1175 scrollbar->move(contentsRect().topLeft()); 1175 scrollbar->move(contentsRect().topLeft());
1176 scrollbar->show(); 1176 scrollbar->show();
1177 break; 1177 break;
1178 case SCRRIGHT: 1178 case SCRRIGHT:
1179 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1179 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1180 dcolumns = columns; 1180 dcolumns = columns;
1181 if(vcolumns) columns = vcolumns; 1181 if(vcolumns) columns = vcolumns;
1182 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1182 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1183 if(showhscrollbar) 1183 if(showhscrollbar)
1184 blX = -hposition * font_w; 1184 blX = -hposition * font_w;
1185 brX = blX; 1185 brX = blX;
1186 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); 1186 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0));
1187 scrollbar->show(); 1187 scrollbar->show();
1188 break; 1188 break;
1189 } 1189 }
1190 //FIXME: support 'rounding' styles 1190 //FIXME: support 'rounding' styles
1191 lines = ( contentsRect().height() - 2 * rimY ) / font_h; 1191 lines = ( contentsRect().height() - 2 * rimY ) / font_h;
1192 bY = (contentsRect().height() - (lines *font_h)) / 2; 1192 bY = (contentsRect().height() - (lines *font_h)) / 2;
1193 1193
1194 if(showhscrollbar == 1) 1194 if(showhscrollbar == 1)
1195 { 1195 {
1196 hscrollbar->resize(contentsRect().width() - hwidth, hwidth); 1196 hscrollbar->resize(contentsRect().width() - hwidth, hwidth);
1197 hscrollbar->setRange(0, vcolumns - dcolumns); 1197 hscrollbar->setRange(0, vcolumns - dcolumns);
1198 1198
1199 QPoint p = contentsRect().bottomLeft(); 1199 QPoint p = contentsRect().bottomLeft();
1200 hscrollbar->move(QPoint(p.x(), p.y() - hwidth)); 1200 hscrollbar->move(QPoint(p.x(), p.y() - hwidth));
1201 hscrollbar->show(); 1201 hscrollbar->show();
1202 } 1202 }
1203 else hscrollbar->hide(); 1203 else hscrollbar->hide();
1204 1204
1205 if(showhscrollbar == 1) 1205 if(showhscrollbar == 1)
1206 { 1206 {
1207 lines = lines - (hwidth / font_h) - 1; 1207 lines = lines - (hwidth / font_h) - 1;
1208 if(lines < 1) lines = 1; 1208 if(lines < 1) lines = 1;
1209 } 1209 }
1210} 1210}
1211 1211
1212void TEWidget::makeImage() 1212void TEWidget::makeImage()
1213//FIXME: rename 'calcGeometry? 1213//FIXME: rename 'calcGeometry?
1214{ 1214{
1215 calcGeometry(); 1215 calcGeometry();
1216 image = (ca*) malloc(lines*columns*sizeof(ca)); 1216 image = (ca*) malloc(lines*columns*sizeof(ca));
1217 clearImage(); 1217 clearImage();
1218} 1218}
1219 1219
1220// calculate the needed size 1220// calculate the needed size
1221QSize TEWidget::calcSize(int cols, int lins) const 1221QSize TEWidget::calcSize(int cols, int lins) const
1222{ 1222{
1223 int frw = width() - contentsRect().width(); 1223 int frw = width() - contentsRect().width();
1224 int frh = height() - contentsRect().height(); 1224 int frh = height() - contentsRect().height();
1225 int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); 1225 int scw = (scrollLoc==SCRNONE?0:scrollbar->width());
1226 return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh ); 1226 return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh );
1227} 1227}
1228 1228
1229QSize TEWidget::sizeHint() const 1229QSize TEWidget::sizeHint() const
1230{ 1230{
1231 return size(); 1231 return size();
1232} 1232}
1233 1233
1234void TEWidget::styleChange(QStyle &) 1234void TEWidget::styleChange(QStyle &)
1235{ 1235{
1236 propagateSize(); 1236 propagateSize();
1237} 1237}
1238 1238
1239#ifdef QT_NO_DRAGANDDROP_FOO 1239#ifdef QT_NO_DRAGANDDROP_FOO
1240 1240
1241/* --------------------------------------------------------------------- */ 1241/* --------------------------------------------------------------------- */
1242/* */ 1242/* */
1243/* Drag & Drop */ 1243/* Drag & Drop */
1244/* */ 1244/* */
1245/* --------------------------------------------------------------------- */ 1245/* --------------------------------------------------------------------- */
1246 1246
1247 1247
1248void TEWidget::dragEnterEvent(QDragEnterEvent* e) 1248void TEWidget::dragEnterEvent(QDragEnterEvent* e)
1249{ 1249{
1250 e->accept(QTextDrag::canDecode(e) || 1250 e->accept(QTextDrag::canDecode(e) ||
1251 QUriDrag::canDecode(e)); 1251 QUriDrag::canDecode(e));
1252} 1252}
1253 1253
1254void TEWidget::dropEvent(QDropEvent* event) 1254void TEWidget::dropEvent(QDropEvent* event)
1255{ 1255{
1256 // The current behaviour when url(s) are dropped is 1256 // The current behaviour when url(s) are dropped is
1257 // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd 1257 // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd
1258 // * in all other cases, just paste 1258 // * in all other cases, just paste
1259 // (for non-local ones, or for a list of URLs, 'cd' is nonsense) 1259 // (for non-local ones, or for a list of URLs, 'cd' is nonsense)
1260 QStrList strlist; 1260 QStrList strlist;
1261 int file_count = 0; 1261 int file_count = 0;
1262 dropText = ""; 1262 dropText = "";
1263 bool bPopup = true; 1263 bool bPopup = true;
1264 1264
1265 if(QUriDrag::decode(event, strlist)) { 1265 if(QUriDrag::decode(event, strlist)) {
1266 if (strlist.count()) { 1266 if (strlist.count()) {
1267 for(const char* p = strlist.first(); p; p = strlist.next()) { 1267 for(const char* p = strlist.first(); p; p = strlist.next()) {
1268 if(file_count++ > 0) { 1268 if(file_count++ > 0) {
1269 dropText += " "; 1269 dropText += " ";
1270 bPopup = false; // more than one file, don't popup 1270 bPopup = false; // more than one file, don't popup
1271 } 1271 }
1272 1272
1273/* 1273/*
1274 KURL url(p); 1274 KURL url(p);
1275 if (url.isLocalFile()) { 1275 if (url.isLocalFile()) {
1276 dropText += url.path(); // local URL : remove protocol 1276 dropText += url.path(); // local URL : remove protocol
1277 } 1277 }
1278 else { 1278 else {
1279 dropText += url.prettyURL(); 1279 dropText += url.prettyURL();
1280 bPopup = false; // a non-local file, don't popup 1280 bPopup = false; // a non-local file, don't popup
1281 } 1281 }
1282*/ 1282*/
1283 1283
1284 } 1284 }
1285 1285
1286 if (bPopup) 1286 if (bPopup)
1287 // m_drop->popup(pos() + event->pos()); 1287 // m_drop->popup(pos() + event->pos());
1288 m_drop->popup(mapToGlobal(event->pos())); 1288 m_drop->popup(mapToGlobal(event->pos()));
1289 else 1289 else
1290 { 1290 {
1291 if (currentSession) { 1291 if (currentSession) {
1292 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1292 currentSession->getEmulation()->sendString(dropText.local8Bit());
1293 } 1293 }
1294// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1294// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1295 } 1295 }
1296 } 1296 }
1297 } 1297 }
1298 else if(QTextDrag::decode(event, dropText)) { 1298 else if(QTextDrag::decode(event, dropText)) {
1299// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1299// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1300 if (currentSession) { 1300 if (currentSession) {
1301 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1301 currentSession->getEmulation()->sendString(dropText.local8Bit());
1302 } 1302 }
1303 // Paste it 1303 // Paste it
1304 } 1304 }
1305} 1305}
1306#endif 1306#endif
1307 1307
1308 1308
1309void TEWidget::drop_menu_activated(int) 1309void TEWidget::drop_menu_activated(int)
1310{ 1310{
1311#ifdef QT_NO_DRAGANDDROP_FOO 1311#ifdef QT_NO_DRAGANDDROP_FOO
1312 switch (item) 1312 switch (item)
1313 { 1313 {
1314 case 0: // paste 1314 case 0: // paste
1315 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1315 currentSession->getEmulation()->sendString(dropText.local8Bit());
1316// KWM::activate((Window)this->winId()); 1316// KWM::activate((Window)this->winId());
1317 break; 1317 break;
1318 case 1: // cd ... 1318 case 1: // cd ...
1319 currentSession->getEmulation()->sendString("cd "); 1319 currentSession->getEmulation()->sendString("cd ");
1320 struct stat statbuf; 1320 struct stat statbuf;
1321 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) 1321 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 )
1322 { 1322 {
1323 if ( !S_ISDIR(statbuf.st_mode) ) 1323 if ( !S_ISDIR(statbuf.st_mode) )
1324 { 1324 {
1325/* 1325/*
1326 KURL url; 1326 KURL url;
1327 url.setPath( dropText ); 1327 url.setPath( dropText );
1328 dropText = url.directory( true, false ); // remove filename 1328 dropText = url.directory( true, false ); // remove filename
1329*/ 1329*/
1330 } 1330 }
1331 } 1331 }
1332 dropText.replace(QRegExp(" "), "\\ "); // escape spaces 1332 dropText.replace(QRegExp(" "), "\\ "); // escape spaces
1333 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1333 currentSession->getEmulation()->sendString(dropText.local8Bit());
1334 currentSession->getEmulation()->sendString("\n"); 1334 currentSession->getEmulation()->sendString("\n");
1335// KWM::activate((Window)this->winId()); 1335// KWM::activate((Window)this->winId());
1336 break; 1336 break;
1337 } 1337 }
1338#endif 1338#endif
1339} 1339}
1340 1340
1341QPushButton* TEWidget::cornerButton() { 1341QPushButton* TEWidget::cornerButton() {
1342 return m_cornerButton; 1342 return m_cornerButton;
1343} 1343}
1344 1344
1345void TEWidget::setWrapAt(int columns) 1345void TEWidget::setWrapAt(int columns)
1346{ 1346{
1347 vcolumns = columns; 1347 vcolumns = columns;
1348 propagateSize(); 1348 propagateSize();
1349 update(); 1349 update();
1350} 1350}
1351 1351
1352 1352
diff --git a/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp b/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp
index 78635b2..7b30b1a 100644
--- a/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp
+++ b/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp
@@ -1,3773 +1,3773 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Implementation of QRegExp class 4** Implementation of QRegExp class
5** 5**
6** Created : 950126 6** Created : 950126
7** 7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9** 9**
10** This file is part of the tools module of the Qt GUI Toolkit. 10** This file is part of the tools module of the Qt GUI Toolkit.
11** 11**
12** This file may be distributed under the terms of the Q Public License 12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file 13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file. 14** LICENSE.QPL included in the packaging of this file.
15** 15**
16** This file may be distributed and/or modified under the terms of the 16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software 17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the 18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file. 19** packaging of this file.
20** 20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License 22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software. 23** Agreement provided with the Software.
24** 24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27** 27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements. 29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information. 30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information. 31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32** 32**
33** Contact info@trolltech.com if any conditions of this licensing are 33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you. 34** not clear to you.
35** 35**
36**********************************************************************/ 36**********************************************************************/
37#if QT_VERSION >=300 37#if QT_VERSION >= 0x030000
38#error QRegExp3 is now in QT 3 use QRegExp instead 38#error QRegExp3 is now in QT 3 use QRegExp instead
39#endif 39#endif
40 40
41#if QT_VERSION < 300 41#if QT_VERSION < 0x030000
42#include "./qregexp3.h" 42#include "./qregexp3.h"
43#else 43#else
44#include "qregexp.h" 44#include "qregexp.h"
45#endif 45#endif
46 46
47/* OPIE */ 47/* OPIE */
48#include <opie2/odebug.h> 48#include <opie2/odebug.h>
49 49
50/* QT */ 50/* QT */
51#include <qarray.h> 51#include <qarray.h>
52#include <qbitarray.h> 52#include <qbitarray.h>
53#include <qcache.h> 53#include <qcache.h>
54#include <qintdict.h> 54#include <qintdict.h>
55#include <qmap.h> 55#include <qmap.h>
56#include <qstring.h> 56#include <qstring.h>
57#include <qtl.h> 57#include <qtl.h>
58#include <qvector.h> 58#include <qvector.h>
59 59
60/* STD */ 60/* STD */
61#include <limits.h> 61#include <limits.h>
62 62
63/* 63/*
64 WARNING! Be sure to read qregexp.tex before modifying this file. 64 WARNING! Be sure to read qregexp.tex before modifying this file.
65*/ 65*/
66 66
67/*! 67/*!
68 \class QRegExp3 qregexp.h 68 \class QRegExp3 qregexp.h
69 69
70 \brief The QRegExp class provides pattern matching using regular expressions. 70 \brief The QRegExp class provides pattern matching using regular expressions.
71 71
72 \ingroup tools 72 \ingroup tools
73 \ingroup misc 73 \ingroup misc
74 \ingroup shared 74 \ingroup shared
75 75
76 76
77 Regular expressions, "regexps", provide a way to find patterns 77 Regular expressions, "regexps", provide a way to find patterns
78 within text. This is useful in many contexts, for example: 78 within text. This is useful in many contexts, for example:
79 79
80 <ol> 80 <ol>
81 <li>\e Validation. A regexp can be used to check whether a piece of 81 <li>\e Validation. A regexp can be used to check whether a piece of
82 text meets some criteria, e.g. is an integer or contains no 82 text meets some criteria, e.g. is an integer or contains no
83 whitespace. 83 whitespace.
84 <li>\e Searching. Regexps provide a much more powerful means of 84 <li>\e Searching. Regexps provide a much more powerful means of
85 searching text than simple string matching does. For example we can 85 searching text than simple string matching does. For example we can
86 create a regexp which says "find one of the words 'mail', 'letter' 86 create a regexp which says "find one of the words 'mail', 'letter'
87 or 'correspondence' but not any of the words 'email', 'mailman' 87 or 'correspondence' but not any of the words 'email', 'mailman'
88 'mailer', 'letterbox' etc." 88 'mailer', 'letterbox' etc."
89 <li><em>Search and Replace.</em> A regexp can be used to replace a 89 <li><em>Search and Replace.</em> A regexp can be used to replace a
90 pattern with a piece of text, for example replace all occurrences of 90 pattern with a piece of text, for example replace all occurrences of
91 '&' with '\&amp;' except where the '&' is already followed by 91 '&' with '\&amp;' except where the '&' is already followed by
92 'amp;'. 92 'amp;'.
93 <li><em>String Splitting.</em> A regexp can be used to identify 93 <li><em>String Splitting.</em> A regexp can be used to identify
94 where a string should be split into its component fields, e.g. 94 where a string should be split into its component fields, e.g.
95 splitting tab delimited strings. 95 splitting tab delimited strings.
96 </ol> 96 </ol>
97 97
98 We present a very brief introduction to regexps, a description of 98 We present a very brief introduction to regexps, a description of
99 Qt's regexp language, some code examples, and finally the function 99 Qt's regexp language, some code examples, and finally the function
100 documentation. QRegExp is modelled on Perl's regexp engine and fully 100 documentation. QRegExp is modelled on Perl's regexp engine and fully
101 supports Unicode. QRegExp may also be used in the weaker 'wildcard' 101 supports Unicode. QRegExp may also be used in the weaker 'wildcard'
102 (globbing) mode which works in a similar way to command shells. A 102 (globbing) mode which works in a similar way to command shells. A
103 good text on regexps is <i>Mastering Regular Expressions: Powerful 103 good text on regexps is <i>Mastering Regular Expressions: Powerful
104 Techniques for Perl and Other Tools</i> by Jeffrey E. Friedl, ISBN 104 Techniques for Perl and Other Tools</i> by Jeffrey E. Friedl, ISBN
105 1565922573. 105 1565922573.
106 106
107 Experienced regexp users may prefer to skip the introduction and 107 Experienced regexp users may prefer to skip the introduction and
108 go directly to the relevant information: 108 go directly to the relevant information:
109 109
110 <ul> 110 <ul>
111 <li><a href="#characters-and-abbreviations-for-sets-of-characters"> 111 <li><a href="#characters-and-abbreviations-for-sets-of-characters">
112 Characters and Abbreviations for Sets of Characters</a> 112 Characters and Abbreviations for Sets of Characters</a>
113 <li><a href="#sets-of-characters">Sets of Characters</a> 113 <li><a href="#sets-of-characters">Sets of Characters</a>
114 <li><a href="#quantifiers">Quantifiers</a> 114 <li><a href="#quantifiers">Quantifiers</a>
115 <li><a href="#capturing-text">Capturing Text</a> 115 <li><a href="#capturing-text">Capturing Text</a>
116 <li><a href="#assertions">Assertions</a> 116 <li><a href="#assertions">Assertions</a>
117 <li><a href="#wildcard-matching">Wildcard Matching (globbing)</a> 117 <li><a href="#wildcard-matching">Wildcard Matching (globbing)</a>
118 <li><a href="#perl-users">Notes for Perl Users</a> 118 <li><a href="#perl-users">Notes for Perl Users</a>
119 <li><a href="#code-examples">Code Examples</a> 119 <li><a href="#code-examples">Code Examples</a>
120 <li><a href="#member-function-documentation">Member Function Documentation</a> 120 <li><a href="#member-function-documentation">Member Function Documentation</a>
121 </ul> 121 </ul>
122 122
123 <b>Introduction</b> 123 <b>Introduction</b>
124 124
125 Regexps are built up from expressions, quantifiers and assertions. 125 Regexps are built up from expressions, quantifiers and assertions.
126 The simplest form of expression is simply a character, e.g. <b>x</b> 126 The simplest form of expression is simply a character, e.g. <b>x</b>
127 or <b>5</b>. An expression can also be a set of characters. For 127 or <b>5</b>. An expression can also be a set of characters. For
128 example, <b>[ABCD]</b>, will match an <b>A</b> or a <b>B</b> or a 128 example, <b>[ABCD]</b>, will match an <b>A</b> or a <b>B</b> or a
129 <b>C</b> or a <b>D</b>. As a shorthand we could write this as 129 <b>C</b> or a <b>D</b>. As a shorthand we could write this as
130 <b>[A-D]</b>. If we want to match any of the captital letters in the 130 <b>[A-D]</b>. If we want to match any of the captital letters in the
131 English alphabet we can write <b>[A-Z]</b>. A quantifier tells the 131 English alphabet we can write <b>[A-Z]</b>. A quantifier tells the
132 regexp engine how many occurrences of the expression we want, e.g. 132 regexp engine how many occurrences of the expression we want, e.g.
133 <b>x{1,1}</b> means match an <b>x</b> which occurs at least once and 133 <b>x{1,1}</b> means match an <b>x</b> which occurs at least once and
134 at most once. We'll look at assertions and more complex expressions 134 at most once. We'll look at assertions and more complex expressions
135 later. Note that regexps cannot be used to check for balanced 135 later. Note that regexps cannot be used to check for balanced
136 brackets or tags (unless you know the maximum level of nesting). 136 brackets or tags (unless you know the maximum level of nesting).
137 137
138 138
139 We'll start by writing a regexp to match integers in the range 0 to 139 We'll start by writing a regexp to match integers in the range 0 to
140 99. We will require at least one digit so we will start with 140 99. We will require at least one digit so we will start with
141 <b>[0-9]{1,1}</b> which means match a digit exactly once. This 141 <b>[0-9]{1,1}</b> which means match a digit exactly once. This
142 regexp alone will match integers in the range 0 to 9. To match one 142 regexp alone will match integers in the range 0 to 9. To match one
143 or two digits we can increase the maximum number of occurrences so 143 or two digits we can increase the maximum number of occurrences so
144 the regexp becomes <b>[0-9]{1,2}</b> meaning match a digit at least 144 the regexp becomes <b>[0-9]{1,2}</b> meaning match a digit at least
145 once and at most twice. However, this regexp as it stands will not 145 once and at most twice. However, this regexp as it stands will not
146 match correctly. This regexp will match one or two digits \e within 146 match correctly. This regexp will match one or two digits \e within
147 a string. To ensure that we match against the whole string we must 147 a string. To ensure that we match against the whole string we must
148 use the anchor assertions. We need <b>^</b> (caret) which when it is 148 use the anchor assertions. We need <b>^</b> (caret) which when it is
149 the first character in the regexp means that the regexp must match 149 the first character in the regexp means that the regexp must match
150 from the beginning of the string. And we also need <b>$</b> (dollar) 150 from the beginning of the string. And we also need <b>$</b> (dollar)
151 which when it is the last character in the regexp means that the 151 which when it is the last character in the regexp means that the
152 regexp must match until the end of the string. So now our regexp is 152 regexp must match until the end of the string. So now our regexp is
153 <b>^[0-9]{1,2}$</b>. Note that assertions do not match any 153 <b>^[0-9]{1,2}$</b>. Note that assertions do not match any
154 characters. 154 characters.
155 155
156 If you've seen regexps elsewhere they may have looked different from 156 If you've seen regexps elsewhere they may have looked different from
157 the one above. This is because some sets of characters and some 157 the one above. This is because some sets of characters and some
158 quantifiers are so common that they have special symbols to 158 quantifiers are so common that they have special symbols to
159 represent them. <b>[0-9]</b> can be replaced with the symbol 159 represent them. <b>[0-9]</b> can be replaced with the symbol
160 <b>\d</b>. The quantifier to match exactly one occurrence, 160 <b>\d</b>. The quantifier to match exactly one occurrence,
161 <b>{1,1}</b>, can be replaced with the expression itself. This means 161 <b>{1,1}</b>, can be replaced with the expression itself. This means
162 that <b>x{1,1}</b> is exactly the same as <b>x</b> alone. So our 0 162 that <b>x{1,1}</b> is exactly the same as <b>x</b> alone. So our 0
163 to 99 matcher could be written: <b>^\d{1,2}$</b>, although most 163 to 99 matcher could be written: <b>^\d{1,2}$</b>, although most
164 people would write it <b>^\d\d?$</b>. The <b>?</b> is the same as 164 people would write it <b>^\d\d?$</b>. The <b>?</b> is the same as
165 the quantifier <b>{0,1}</b>, i.e. a minimum of no occurrences a 165 the quantifier <b>{0,1}</b>, i.e. a minimum of no occurrences a
166 maximum of one occurrence. This is used to make an expression 166 maximum of one occurrence. This is used to make an expression
167 optional. The regexp <b>^\d\d?$</b> means "from the beginning of the 167 optional. The regexp <b>^\d\d?$</b> means "from the beginning of the
168 string match one digit followed by zero or one digits and then the 168 string match one digit followed by zero or one digits and then the
169 end of the string". 169 end of the string".
170 170
171 Our second example is matching the words 'mail', 'letter' or 171 Our second example is matching the words 'mail', 'letter' or
172 'correspondence' but without matching 'email', 'mailman', 'mailer', 172 'correspondence' but without matching 'email', 'mailman', 'mailer',
173 'letterbox' etc. We'll start by just matching 'mail'. In full the 173 'letterbox' etc. We'll start by just matching 'mail'. In full the
174 regexp is, <b>m{1,1}a{1,1}i{1,1}l{1,1}</b>, but since an expression 174 regexp is, <b>m{1,1}a{1,1}i{1,1}l{1,1}</b>, but since an expression
175 itself is automatically quantified by <b>{1,1}</b> we can simply 175 itself is automatically quantified by <b>{1,1}</b> we can simply
176 write this as <b>mail</b>; an 'm' followed by an 'a' followed by an 176 write this as <b>mail</b>; an 'm' followed by an 'a' followed by an
177 'i' followed by an 'l'. The symbol '|' (bar) is used for \e 177 'i' followed by an 'l'. The symbol '|' (bar) is used for \e
178 alternation, so our regexp now becomes 178 alternation, so our regexp now becomes
179 <b>mail|letter|correspondence</b> which means match 'mail' \e or 179 <b>mail|letter|correspondence</b> which means match 'mail' \e or
180 'letter' \e or 'correspondence'. Whilst this regexp will find the 180 'letter' \e or 'correspondence'. Whilst this regexp will find the
181 words we want it will also find words we don't want such as 'email'. 181 words we want it will also find words we don't want such as 'email'.
182 We will start by putting our regexp in parenthesis 182 We will start by putting our regexp in parenthesis
183 <b>(mail|letter|correspondence)</b>. Parenthesis have two effects, 183 <b>(mail|letter|correspondence)</b>. Parenthesis have two effects,
184 firstly they group expressions together and secondly they identify 184 firstly they group expressions together and secondly they identify
185 parts of the regexp that we wish to <a href="#capturing-text">capture</a>. 185 parts of the regexp that we wish to <a href="#capturing-text">capture</a>.
186 Our regexp still matches any of the three words but now they are 186 Our regexp still matches any of the three words but now they are
187 grouped together as a unit. This is useful for building up more 187 grouped together as a unit. This is useful for building up more
188 complex regexps. It is also useful because it allows us to examine 188 complex regexps. It is also useful because it allows us to examine
189 which of the words actually matched. We need to use another 189 which of the words actually matched. We need to use another
190 assertion, this time <b>\b</b> "word boundary": 190 assertion, this time <b>\b</b> "word boundary":
191 <b>\b(mail|letter|correspondence)\b</b>. This regexp means "match a 191 <b>\b(mail|letter|correspondence)\b</b>. This regexp means "match a
192 word boundary followed by the expression in parenthesis followed by 192 word boundary followed by the expression in parenthesis followed by
193 another word boundary". The <b>\b</b> assertion matches at a \e 193 another word boundary". The <b>\b</b> assertion matches at a \e
194 position in the regexp not a \e character in the regexp. A word 194 position in the regexp not a \e character in the regexp. A word
195 boundary is any non-word character such as a space a newline or the 195 boundary is any non-word character such as a space a newline or the
196 beginning or end of the string. 196 beginning or end of the string.
197 197
198 For our third example we want to replace ampersands with the HTML 198 For our third example we want to replace ampersands with the HTML
199 entity '\&amp;'. The regexp to match is simple: <b>\&</b>, i.e. 199 entity '\&amp;'. The regexp to match is simple: <b>\&</b>, i.e.
200 match one ampersand. Unfortunately this will mess up our text if 200 match one ampersand. Unfortunately this will mess up our text if
201 some of the ampersands have already been turned into HTML entities. 201 some of the ampersands have already been turned into HTML entities.
202 So what we really want to say is replace an ampersand providing it 202 So what we really want to say is replace an ampersand providing it
203 is not followed by 'amp;'. For this we need the negative lookahead 203 is not followed by 'amp;'. For this we need the negative lookahead
204 assertion and our regexp becomes: <b>\&(?!amp;)</b>. The negative 204 assertion and our regexp becomes: <b>\&(?!amp;)</b>. The negative
205 lookahead assertion is introduced with '(?!' and finishes at the 205 lookahead assertion is introduced with '(?!' and finishes at the
206 ')'. It means that the text it contains, 'amp;' in our example, must 206 ')'. It means that the text it contains, 'amp;' in our example, must
207 \e not follow the expression that preceeds it. 207 \e not follow the expression that preceeds it.
208 208
209 Regexps provide a rich language that can be used in a variety of 209 Regexps provide a rich language that can be used in a variety of
210 ways. For example suppose we want to count all the occurrences of 210 ways. For example suppose we want to count all the occurrences of
211 'Eric' and 'Eirik' in a string. Two valid regexps to match these are 211 'Eric' and 'Eirik' in a string. Two valid regexps to match these are
212 <b>\\</b><b>b(Eric|Eirik)</b><b>\\</b><b>b</b> and 212 <b>\\</b><b>b(Eric|Eirik)</b><b>\\</b><b>b</b> and
213 <b>\\</b><b>bEi?ri[ck]</b><b>\\</b><b>b</b>. We need the word boundary 213 <b>\\</b><b>bEi?ri[ck]</b><b>\\</b><b>b</b>. We need the word boundary
214 '\b' so we don't get 'Ericsson' etc. The second regexp actually 214 '\b' so we don't get 'Ericsson' etc. The second regexp actually
215 matches more than we want, 'Eric', 'Erik', 'Eiric' and 'Eirik'. 215 matches more than we want, 'Eric', 'Erik', 'Eiric' and 'Eirik'.
216 216
217 We will implement some the examples above in the 217 We will implement some the examples above in the
218 <a href="#code-examples">code examples</a> section. 218 <a href="#code-examples">code examples</a> section.
219 219
220 <a name="characters-and-abbreviations-for-sets-of-characters"> 220 <a name="characters-and-abbreviations-for-sets-of-characters">
221 <b>Characters and Abbreviations for Sets of Characters</b></a> 221 <b>Characters and Abbreviations for Sets of Characters</b></a>
222 222
223 <ul> 223 <ul>
224 224
225 <li><b>c</b> Any character represents itself unless it has a special regexp 225 <li><b>c</b> Any character represents itself unless it has a special regexp
226 meaning. Thus <b>c</b> matches the character \e c. 226 meaning. Thus <b>c</b> matches the character \e c.
227 227
228 <li><b>\\</b><b>c</b> A character that follows a backslash matches the 228 <li><b>\\</b><b>c</b> A character that follows a backslash matches the
229 character itself except where mentioned below. For example if you 229 character itself except where mentioned below. For example if you
230 wished to match a literal caret at the beginning of a string you 230 wished to match a literal caret at the beginning of a string you
231 would write <b>\^</b>. 231 would write <b>\^</b>.
232 232
233 <li><b>\\</b><b>a</b> This matches the ASCII bell character (BEL, 0x07). 233 <li><b>\\</b><b>a</b> This matches the ASCII bell character (BEL, 0x07).
234 <li><b>\\</b><b>f</b> This matches the ASCII form feed character (FF, 0x0C). 234 <li><b>\\</b><b>f</b> This matches the ASCII form feed character (FF, 0x0C).
235 <li><b>\\</b><b>n</b> This matches the ASCII line feed character (LF, 0x0A), (Unix newline). 235 <li><b>\\</b><b>n</b> This matches the ASCII line feed character (LF, 0x0A), (Unix newline).
236 <li><b>\\</b><b>r</b> This matches the ASCII carriage return character (CR, 0x0D). 236 <li><b>\\</b><b>r</b> This matches the ASCII carriage return character (CR, 0x0D).
237 <li><b>\\</b><b>t</b> This matches the ASCII horizontal tab character (HT, 0x09). 237 <li><b>\\</b><b>t</b> This matches the ASCII horizontal tab character (HT, 0x09).
238 <li><b>\\</b><b>v</b> This matches the ASCII vertical tab character (VT, 0x0B). 238 <li><b>\\</b><b>v</b> This matches the ASCII vertical tab character (VT, 0x0B).
239 <li><b>\\</b><b>xhhhh</b> This matches the Unicode character corresponding 239 <li><b>\\</b><b>xhhhh</b> This matches the Unicode character corresponding
240 to the hexadecimal number hhhh (between 0x0000 and 0xFFFF). \0ooo 240 to the hexadecimal number hhhh (between 0x0000 and 0xFFFF). \0ooo
241 (i.e., \zero ooo) matches the ASCII/Latin-1 character corresponding 241 (i.e., \zero ooo) matches the ASCII/Latin-1 character corresponding
242 to the octal number ooo (between 0 and 0377). 242 to the octal number ooo (between 0 and 0377).
243 <li><b>. (dot)</b> This matches any character (including newline). 243 <li><b>. (dot)</b> This matches any character (including newline).
244 <li><b>\\</b><b>d</b> This matches a digit (see QChar::isDigit()). 244 <li><b>\\</b><b>d</b> This matches a digit (see QChar::isDigit()).
245 <li><b>\\</b><b>D</b> This matches a non-digit. 245 <li><b>\\</b><b>D</b> This matches a non-digit.
246 <li><b>\\</b><b>s</b> This matches a whitespace (see QChar::isSpace()). 246 <li><b>\\</b><b>s</b> This matches a whitespace (see QChar::isSpace()).
247 <li><b>\\</b><b>S</b> This matches a non-whitespace. 247 <li><b>\\</b><b>S</b> This matches a non-whitespace.
248 <li><b>\\</b><b>w</b> This matches a word character (see QChar::isLetterOrNumber()). 248 <li><b>\\</b><b>w</b> This matches a word character (see QChar::isLetterOrNumber()).
249 <li><b>\\</b><b>W</b> This matches a non-word character. 249 <li><b>\\</b><b>W</b> This matches a non-word character.
250 <li><b>\\</b><b>n</b> The n<sup>th</sup> 250 <li><b>\\</b><b>n</b> The n<sup>th</sup>
251 <a href="#capturing-text">backreference</a>, e.g. \1, \2, etc. 251 <a href="#capturing-text">backreference</a>, e.g. \1, \2, etc.
252 </ul> 252 </ul>
253 253
254 <em>Note that the C++ compiler transforms backslashes in strings so 254 <em>Note that the C++ compiler transforms backslashes in strings so
255 to include a <b>\\</b> in a regexp you will need to enter it twice, 255 to include a <b>\\</b> in a regexp you will need to enter it twice,
256 i.e. <b>\\</b><b>\\</b>.</em> 256 i.e. <b>\\</b><b>\\</b>.</em>
257 257
258 <a name="sets-of-characters"><b>Sets of Characters</b></a> 258 <a name="sets-of-characters"><b>Sets of Characters</b></a>
259 259
260 Square brackets are used to match any character in the set of 260 Square brackets are used to match any character in the set of
261 characters contained within the square brackets. All the character 261 characters contained within the square brackets. All the character
262 set abbreviations described above can be used within square 262 set abbreviations described above can be used within square
263 brackets. Apart from the character set abbreviations and the 263 brackets. Apart from the character set abbreviations and the
264 following two exceptions no characters have special meanings in 264 following two exceptions no characters have special meanings in
265 square brackets. 265 square brackets.
266 266
267 <ul> 267 <ul>
268 268
269 <li><b>^</b> The caret negates the character set if it occurs as the 269 <li><b>^</b> The caret negates the character set if it occurs as the
270 first character, i.e. immediately after the opening square bracket. 270 first character, i.e. immediately after the opening square bracket.
271 For example, <b>[abc]</b> matches 'a' or 'b' or 'c', but 271 For example, <b>[abc]</b> matches 'a' or 'b' or 'c', but
272 <b>[^abc]</b> matches anything \e except 'a' or 'b' or 'c'. 272 <b>[^abc]</b> matches anything \e except 'a' or 'b' or 'c'.
273 273
274 <li><b>-</b> The dash is used to indicate a range of characters, for 274 <li><b>-</b> The dash is used to indicate a range of characters, for
275 example <b>[W-Z]</b> matches 'W' or 'X' or 'Y' or 'Z'. 275 example <b>[W-Z]</b> matches 'W' or 'X' or 'Y' or 'Z'.
276 276
277 </ul> 277 </ul>
278 278
279 Using the predefined character set abbreviations is more portable 279 Using the predefined character set abbreviations is more portable
280 than using character ranges across platforms and languages. For 280 than using character ranges across platforms and languages. For
281 example, <b>[0-9]</b> matches a digit in Western alphabets but 281 example, <b>[0-9]</b> matches a digit in Western alphabets but
282 <b>\d</b> matches a digit in \e any alphabet. 282 <b>\d</b> matches a digit in \e any alphabet.
283 283
284 Note that in most regexp literature sets of characters are called 284 Note that in most regexp literature sets of characters are called
285 "character classes". 285 "character classes".
286 286
287 <a name="quantifiers"><b>Quantifiers</b></a> 287 <a name="quantifiers"><b>Quantifiers</b></a>
288 288
289 By default an expression is automatically quantified by 289 By default an expression is automatically quantified by
290 <b>{1,1}</b>, i.e. it should occur exactly once. In the following 290 <b>{1,1}</b>, i.e. it should occur exactly once. In the following
291 list <b><i>E</i></b> stands for any expression. An expression is a 291 list <b><i>E</i></b> stands for any expression. An expression is a
292 character or an abbreviation for a set of characters or a set of 292 character or an abbreviation for a set of characters or a set of
293 characters in square brackets or any parenthesised expression. 293 characters in square brackets or any parenthesised expression.
294 294
295 <ul> 295 <ul>
296 296
297 <li><b><i>E</i>?</b> Matches zero or one occurrence of <i>E</i>. 297 <li><b><i>E</i>?</b> Matches zero or one occurrence of <i>E</i>.
298 This quantifier means "the previous expression is optional" since it 298 This quantifier means "the previous expression is optional" since it
299 will match whether or not the expression occurs in the string. 299 will match whether or not the expression occurs in the string.
300 It is the same as <b><i>E</i>{0,1}</b>. For example <b>dents?</b> 300 It is the same as <b><i>E</i>{0,1}</b>. For example <b>dents?</b>
301 will match 'dent' and 'dents'. 301 will match 'dent' and 'dents'.
302 302
303 <li><b><i>E</i>+</b> Matches one or more occurrences of <i>E</i>. 303 <li><b><i>E</i>+</b> Matches one or more occurrences of <i>E</i>.
304 This is the same as <b><i>E</i>{1,MAXINT}</b>. For example, 304 This is the same as <b><i>E</i>{1,MAXINT}</b>. For example,
305 <b>0+</b> will match '0', '00', '000', etc. 305 <b>0+</b> will match '0', '00', '000', etc.
306 306
307 <li><b><i>E</i>*</b> Matches zero or more occurrences of <i>E</i>. 307 <li><b><i>E</i>*</b> Matches zero or more occurrences of <i>E</i>.
308 This is the same as <b><i>E</i>{0,MAXINT}</b>. The <b>*</b> 308 This is the same as <b><i>E</i>{0,MAXINT}</b>. The <b>*</b>
309 quantifier is often used by a mistake. Since it matches \e zero or 309 quantifier is often used by a mistake. Since it matches \e zero or
310 more occurrences it will match no occurrences at all. For example if 310 more occurrences it will match no occurrences at all. For example if
311 we want to match strings that end in whitespace and use the regexp 311 we want to match strings that end in whitespace and use the regexp
312 <b>\s*$</b> we would get a match on every string. This is because we 312 <b>\s*$</b> we would get a match on every string. This is because we
313 have said find zero or more whitespace followed by the end of string, 313 have said find zero or more whitespace followed by the end of string,
314 so even strings that don't end in whitespace will match. The regexp 314 so even strings that don't end in whitespace will match. The regexp
315 we want in this case is <b>\s+$</b> to match strings that have at 315 we want in this case is <b>\s+$</b> to match strings that have at
316 least one whitespace at the end. 316 least one whitespace at the end.
317 317
318 <li><b><i>E</i>{n}</b> Matches exactly \e n occurrences of the 318 <li><b><i>E</i>{n}</b> Matches exactly \e n occurrences of the
319 expression. This is the same as repeating the expression \e n times. 319 expression. This is the same as repeating the expression \e n times.
320 For example, <b>x{5}</b> is the same as <b>xxxxx</b>. It is also the 320 For example, <b>x{5}</b> is the same as <b>xxxxx</b>. It is also the
321 same as <b><i>E</i>{n,n}</b>, e.g. <b>x{5,5}</b>. 321 same as <b><i>E</i>{n,n}</b>, e.g. <b>x{5,5}</b>.
322 322
323 <li><b><i>E</i>{n,}</b> Matches at least \e n occurrences of the 323 <li><b><i>E</i>{n,}</b> Matches at least \e n occurrences of the
324 expression. This is the same as <b><i>E</i>{n,MAXINT}</b>. 324 expression. This is the same as <b><i>E</i>{n,MAXINT}</b>.
325 325
326 <li><b><i>E</i>{,m}</b> Matches at most \e m occurrences of the 326 <li><b><i>E</i>{,m}</b> Matches at most \e m occurrences of the
327 expression. This is the same as <b><i>E</i>{0,m}</b>. 327 expression. This is the same as <b><i>E</i>{0,m}</b>.
328 328
329 <li><b><i>E</i>{n,m}</b> Matches at least \e n occurrences of the 329 <li><b><i>E</i>{n,m}</b> Matches at least \e n occurrences of the
330 expression and at most \e m occurrences of the expression. 330 expression and at most \e m occurrences of the expression.
331 331
332 </ul> 332 </ul>
333 333
334 (MAXINT is implementation dependent but will not be smaller than 334 (MAXINT is implementation dependent but will not be smaller than
335 16384.) 335 16384.)
336 336
337 If we wish to apply a quantifier to more than just the preceeding 337 If we wish to apply a quantifier to more than just the preceeding
338 character we can use parenthesis to group characters together in an 338 character we can use parenthesis to group characters together in an
339 expression. For example, <b>tag+</b> matches a 't' followed by an 339 expression. For example, <b>tag+</b> matches a 't' followed by an
340 'a' followed by at least one 'g', whereas <b>(tag)+</b> matches at 340 'a' followed by at least one 'g', whereas <b>(tag)+</b> matches at
341 least one occurrence of 'tag'. 341 least one occurrence of 'tag'.
342 342
343 Note that quantifiers are "greedy", they will match as much text as 343 Note that quantifiers are "greedy", they will match as much text as
344 they can. For example, <b>0+</b> will match as many zeros as it can 344 they can. For example, <b>0+</b> will match as many zeros as it can
345 from the first zero it finds, e.g. '2.<u>000</u>5'. Quantifiers can 345 from the first zero it finds, e.g. '2.<u>000</u>5'. Quantifiers can
346 be made non-greedy, see setMinimal(). 346 be made non-greedy, see setMinimal().
347 347
348 <a name="capturing-text"><b>Capturing Text</b></a> 348 <a name="capturing-text"><b>Capturing Text</b></a>
349 349
350 Parenthesis allow us to group elements together so that we can 350 Parenthesis allow us to group elements together so that we can
351 quantify and capture them. For example if we have the expression 351 quantify and capture them. For example if we have the expression
352 <b>mail|letter|correspondence</b> that matches a string we know that 352 <b>mail|letter|correspondence</b> that matches a string we know that
353 \e one of the words matched but not which one. Using parenthesis 353 \e one of the words matched but not which one. Using parenthesis
354 allows us to "capture" whatever is matched within their bounds, so 354 allows us to "capture" whatever is matched within their bounds, so
355 if we used <b>(mail|letter|correspondence)</b> and matched this 355 if we used <b>(mail|letter|correspondence)</b> and matched this
356 regexp against the string "I sent you some email" we can use the 356 regexp against the string "I sent you some email" we can use the
357 cap() or capturedTexts() functions to extract the matched 357 cap() or capturedTexts() functions to extract the matched
358 characters, in this case 'mail'. 358 characters, in this case 'mail'.
359 359
360 We can use captured text within the regexp itself. To refer to the 360 We can use captured text within the regexp itself. To refer to the
361 captured text we use \e backreferences which are indexed from 1 the 361 captured text we use \e backreferences which are indexed from 1 the
362 same as for cap(). For example we could search for duplicate words 362 same as for cap(). For example we could search for duplicate words
363 in a string using <b>\b(\w+)\W+\1\b</b> which means match a word 363 in a string using <b>\b(\w+)\W+\1\b</b> which means match a word
364 boundary followed by one or more word characters followed by one or 364 boundary followed by one or more word characters followed by one or
365 more non-word characters followed by the same text as the first 365 more non-word characters followed by the same text as the first
366 parenthesised expression followed by a word boundary. 366 parenthesised expression followed by a word boundary.
367 367
368 If we want to use parenthesis purely for grouping and not for 368 If we want to use parenthesis purely for grouping and not for
369 capturing we use the non-capturing syntax, e.g. 369 capturing we use the non-capturing syntax, e.g.
370 <b>(?:green|blue)</b>. Non-capturing parenthesis begin '(?:' and end 370 <b>(?:green|blue)</b>. Non-capturing parenthesis begin '(?:' and end
371 ')'. In this example we match either 'green' or 'blue' but we do not 371 ')'. In this example we match either 'green' or 'blue' but we do not
372 capture the match so we can only know whether or not we matched but 372 capture the match so we can only know whether or not we matched but
373 not which color we actually found. Using non-capturing parenthesis 373 not which color we actually found. Using non-capturing parenthesis
374 is more efficient than using capturing parenthesis since the regexp 374 is more efficient than using capturing parenthesis since the regexp
375 engine has to do less book-keeping. 375 engine has to do less book-keeping.
376 376
377 Both capturing and non-capturing parenthesis may be nested. 377 Both capturing and non-capturing parenthesis may be nested.
378 378
379 <a name="assertions"><b>Assertions</b></a> 379 <a name="assertions"><b>Assertions</b></a>
380 380
381 Assertions make some statement about the text at the point where 381 Assertions make some statement about the text at the point where
382 they occur in the regexp but they do not match any characters. 382 they occur in the regexp but they do not match any characters.
383 In the following list <b><i>E</i></b> stands for any expression. 383 In the following list <b><i>E</i></b> stands for any expression.
384 384
385 <ul> 385 <ul>
386 <li><b>^</b> If the caret is the first character in the regexp 386 <li><b>^</b> If the caret is the first character in the regexp
387 (apart from opening parenthesis) it signifies the beginning of the 387 (apart from opening parenthesis) it signifies the beginning of the
388 string. It has no special meaning elsewhere (except as the first 388 string. It has no special meaning elsewhere (except as the first
389 character of a set of characters in square brackets). For example, 389 character of a set of characters in square brackets). For example,
390 <b>^#include</b> will only match strings which \e begin with the 390 <b>^#include</b> will only match strings which \e begin with the
391 characters '#include'. 391 characters '#include'.
392 392
393 <li><b>$</b> If the dollar is the last character in the regexp 393 <li><b>$</b> If the dollar is the last character in the regexp
394 (apart from closing parenthesis) it signifies the end of the string. 394 (apart from closing parenthesis) it signifies the end of the string.
395 It has no special meaning elsewhere. For example, <b>\d\s*$</b> 395 It has no special meaning elsewhere. For example, <b>\d\s*$</b>
396 will match strings which end with a digit optionally followed by 396 will match strings which end with a digit optionally followed by
397 whitespace. 397 whitespace.
398 398
399 <li><b>\\</b><b>b</b> A word boundary. For example the regexp 399 <li><b>\\</b><b>b</b> A word boundary. For example the regexp
400 <b>\\</b><b>bOK</b>\\</b><b>b</b> means match immediately after a 400 <b>\\</b><b>bOK</b>\\</b><b>b</b> means match immediately after a
401 word boundary (e.g. start of string or whitespace) the letter 'O' 401 word boundary (e.g. start of string or whitespace) the letter 'O'
402 then the letter 'K' immediately before another word boundary (e.g. 402 then the letter 'K' immediately before another word boundary (e.g.
403 end of string or whitespace). But note that the assertion does not 403 end of string or whitespace). But note that the assertion does not
404 actually match any whitespace so if we write 404 actually match any whitespace so if we write
405 <b>(</b><b>\\</b><b>bOK</b>\\</b><b>b)</b> and we have a match it 405 <b>(</b><b>\\</b><b>bOK</b>\\</b><b>b)</b> and we have a match it
406 will only contain 'OK' even if the string is "Its <u>OK</u> now". 406 will only contain 'OK' even if the string is "Its <u>OK</u> now".
407 407
408 <li><b>\\</b><b>B</b> A non-word boundary. This assertion is true 408 <li><b>\\</b><b>B</b> A non-word boundary. This assertion is true
409 wherever <b>\\</b><b>b</b> is false. For example if we searched for 409 wherever <b>\\</b><b>b</b> is false. For example if we searched for
410 <b>\\</b><b>Bon</b>\\</b><b>B</b> in "Left on" the match would fail 410 <b>\\</b><b>Bon</b>\\</b><b>B</b> in "Left on" the match would fail
411 (space and end of string aren't non-word boundaries), but it would 411 (space and end of string aren't non-word boundaries), but it would
412 match in "t<u>on</u>ne". 412 match in "t<u>on</u>ne".
413 413
414 <li><b>(?=<i>E</i>)</b> Positive lookahead. This assertion is true 414 <li><b>(?=<i>E</i>)</b> Positive lookahead. This assertion is true
415 if the expression matches at this point in the regex. This assertion 415 if the expression matches at this point in the regex. This assertion
416 does not match any characters. For example, 416 does not match any characters. For example,
417 <b>^#define\s+(\w+)(?=MAX)</b> will match strings which begin with 417 <b>^#define\s+(\w+)(?=MAX)</b> will match strings which begin with
418 '#define' followed by at least one whitespace followed by at least 418 '#define' followed by at least one whitespace followed by at least
419 one word character followed by 'MAX'. The first set of parenthesis 419 one word character followed by 'MAX'. The first set of parenthesis
420 will capture the word character(s) matched. This regexp will not 420 will capture the word character(s) matched. This regexp will not
421 match '#define DEBUG' but will match '#define <u>INT</u>MAX 421 match '#define DEBUG' but will match '#define <u>INT</u>MAX
422 32767'. 422 32767'.
423 423
424 <li><b>(?!<i>E</i>)</b> Negative lookahead. This assertion is true 424 <li><b>(?!<i>E</i>)</b> Negative lookahead. This assertion is true
425 if the expression does not match at this point in the regex. This 425 if the expression does not match at this point in the regex. This
426 assertion does not match any characters. For example, 426 assertion does not match any characters. For example,
427 <b>^#define\s+(\w+)\s*$</b> will match strings which begin with 427 <b>^#define\s+(\w+)\s*$</b> will match strings which begin with
428 '#define' followed by at least one whitespace followed by at least 428 '#define' followed by at least one whitespace followed by at least
429 one word character optionally followed by whitespace. This regexp 429 one word character optionally followed by whitespace. This regexp
430 will match define's that exist but have no value, i.e. it will not 430 will match define's that exist but have no value, i.e. it will not
431 match '#define INTMAX 32767' but it will match '#define <u>DEBUG</u>'. 431 match '#define INTMAX 32767' but it will match '#define <u>DEBUG</u>'.
432 432
433 </ul> 433 </ul>
434 434
435 <a name="wildcard-matching"><b>Wildcard Matching (globbing)</b></a> 435 <a name="wildcard-matching"><b>Wildcard Matching (globbing)</b></a>
436 436
437 Most command shells such as \e bash or \e cmd support "file 437 Most command shells such as \e bash or \e cmd support "file
438 globbing", the ability to identify a group of files by using 438 globbing", the ability to identify a group of files by using
439 wildcards. Wildcard matching is much simpler than full regexps and 439 wildcards. Wildcard matching is much simpler than full regexps and
440 has only four features: 440 has only four features:
441 441
442 <ul> 442 <ul>
443 443
444 <li><b>c</b> Any character represents itself apart from those 444 <li><b>c</b> Any character represents itself apart from those
445 mentioned below. Thus <b>c</b> matches the character \e c. 445 mentioned below. Thus <b>c</b> matches the character \e c.
446 446
447 <li><b>?</b> This matches any single character. It is the same as 447 <li><b>?</b> This matches any single character. It is the same as
448 <b>.</b> in full regexps. 448 <b>.</b> in full regexps.
449 449
450 <li><b>*</b> This matches zero or more of any characters. It is the 450 <li><b>*</b> This matches zero or more of any characters. It is the
451 same as <b>.*</b> in full regexps. 451 same as <b>.*</b> in full regexps.
452 452
453 <li><b>[...]</b> Sets of characters can be represented in square 453 <li><b>[...]</b> Sets of characters can be represented in square
454 brackets the same as for full regexps. 454 brackets the same as for full regexps.
455 455
456 <!-- JASMIN: Are the character classes, \w, etc supported in 456 <!-- JASMIN: Are the character classes, \w, etc supported in
457 wildcards? --> 457 wildcards? -->
458 458
459 </ul> 459 </ul>
460 460
461 For example if we are in wildcard mode and have strings which 461 For example if we are in wildcard mode and have strings which
462 contain filenames we could identify HTML files with <b>*.html</b>. 462 contain filenames we could identify HTML files with <b>*.html</b>.
463 This will match zero or more characters followed by a dot followed 463 This will match zero or more characters followed by a dot followed
464 by 'h', 't', 'm' and 'l'. 464 by 'h', 't', 'm' and 'l'.
465 465
466 <a name="perl-users"><b>Notes for Perl Users</b></a> 466 <a name="perl-users"><b>Notes for Perl Users</b></a>
467 467
468 Most of the character class abbreviations supported by Perl are 468 Most of the character class abbreviations supported by Perl are
469 supported by QRegExp, see 469 supported by QRegExp, see
470 <a href="#characters-and-abbreviations-for-sets-of-characters"> 470 <a href="#characters-and-abbreviations-for-sets-of-characters">
471 characters and abbreviations for sets of characters</a>. 471 characters and abbreviations for sets of characters</a>.
472 472
473 QRegExp's quantifiers are the same as Perl's greedy quantifiers. 473 QRegExp's quantifiers are the same as Perl's greedy quantifiers.
474 Non-greedy matching cannot be applied to individual quantifiers, but 474 Non-greedy matching cannot be applied to individual quantifiers, but
475 can be applied to all the quantifiers in the pattern. For example, 475 can be applied to all the quantifiers in the pattern. For example,
476 to match the Perl regex <b>ro+?m</b> requires: 476 to match the Perl regex <b>ro+?m</b> requires:
477 \code 477 \code
478 QRegExp rx( "ro+m" ); 478 QRegExp rx( "ro+m" );
479 rx.setMinimal( TRUE ); 479 rx.setMinimal( TRUE );
480 \endcode 480 \endcode
481 481
482 The equivalent of Perl's <tt>/i</tt> option is 482 The equivalent of Perl's <tt>/i</tt> option is
483 setCaseSensitive(FALSE). 483 setCaseSensitive(FALSE).
484 484
485 Perl's <tt>/g</tt> option can be emulated using a 485 Perl's <tt>/g</tt> option can be emulated using a
486 <a href="#cap_in_a_loop">loop</a>. 486 <a href="#cap_in_a_loop">loop</a>.
487 487
488 In QRegExp <b>.</b> matches any character, therefore all QRegExp 488 In QRegExp <b>.</b> matches any character, therefore all QRegExp
489 regexps have the equivalent of Perl's <tt>/s</tt> option. QRegExp 489 regexps have the equivalent of Perl's <tt>/s</tt> option. QRegExp
490 does not have an equivalent to Perl's <tt>/m</tt> option, but this 490 does not have an equivalent to Perl's <tt>/m</tt> option, but this
491 can be emulated in various ways for example by splitting the input 491 can be emulated in various ways for example by splitting the input
492 into lines or by looping with a regexp that searches for newlines. 492 into lines or by looping with a regexp that searches for newlines.
493 493
494 Because QRegExp is string oriented there are no \A, \Z or \z 494 Because QRegExp is string oriented there are no \A, \Z or \z
495 assertions. The \G assertion is not supported but can be emulated in 495 assertions. The \G assertion is not supported but can be emulated in
496 a loop. 496 a loop.
497 497
498 Perl's $& is cap(0) or capturedTexts()[0]. There are no QRegExp 498 Perl's $& is cap(0) or capturedTexts()[0]. There are no QRegExp
499 equivalents for $`, $' or $+. $1, $2 etc correspond to 499 equivalents for $`, $' or $+. $1, $2 etc correspond to
500 cap(1) or capturedTexts()[1], cap(2) or capturedTexts()[2], etc. 500 cap(1) or capturedTexts()[1], cap(2) or capturedTexts()[2], etc.
501 501
502 To substitute a pattern use QString::replace(). 502 To substitute a pattern use QString::replace().
503 503
504 Perl's extended <tt>/x</tt> syntax is not supported, nor are regexp 504 Perl's extended <tt>/x</tt> syntax is not supported, nor are regexp
505 comments (?#comment) or directives, e.g. (?i). 505 comments (?#comment) or directives, e.g. (?i).
506 506
507 Both zero-width positive and zero-width negative lookahead 507 Both zero-width positive and zero-width negative lookahead
508 assertions (?=pattern) and (?!pattern) are supported with the same 508 assertions (?=pattern) and (?!pattern) are supported with the same
509 syntax as Perl. Perl's lookbehind assertions, "independent" 509 syntax as Perl. Perl's lookbehind assertions, "independent"
510 subexpressions and conditional expressions are not supported. 510 subexpressions and conditional expressions are not supported.
511 511
512 Non-capturing parenthesis are also supported, with the same 512 Non-capturing parenthesis are also supported, with the same
513 (?:pattern) syntax. 513 (?:pattern) syntax.
514 514
515 See QStringList::split() and QStringList::join() for equivalents to 515 See QStringList::split() and QStringList::join() for equivalents to
516 Perl's split and join functions. 516 Perl's split and join functions.
517 517
518 Note: because C++ transforms \\'s they must be written \e twice in 518 Note: because C++ transforms \\'s they must be written \e twice in
519 code, e.g. <b>\\</b><b>b</b> must be written <b>\\</b><b>\\</b><b>b</b>. 519 code, e.g. <b>\\</b><b>b</b> must be written <b>\\</b><b>\\</b><b>b</b>.
520 520
521 <a name="code-examples"><b>Code Examples</b></a> 521 <a name="code-examples"><b>Code Examples</b></a>
522 522
523 \code 523 \code
524 QRegExp rx( "^\\d\\d?$" ); // Match integers 0 to 99 524 QRegExp rx( "^\\d\\d?$" ); // Match integers 0 to 99
525 rx.search( "123" ); // Returns -1 (no match) 525 rx.search( "123" ); // Returns -1 (no match)
526 rx.search( "-6" ); // Returns -1 (no match) 526 rx.search( "-6" ); // Returns -1 (no match)
527 rx.search( "6" ); // Returns 0 (matched as position 0) 527 rx.search( "6" ); // Returns 0 (matched as position 0)
528 \endcode 528 \endcode
529 529
530 The third string matches '<u>6</u>'. This is a simple validation 530 The third string matches '<u>6</u>'. This is a simple validation
531 regexp for integers in the range 0 to 99. 531 regexp for integers in the range 0 to 99.
532 532
533 \code 533 \code
534 QRegExp rx( "^\\S+$" ); // Match strings which have no whitespace 534 QRegExp rx( "^\\S+$" ); // Match strings which have no whitespace
535 rx.search( "Hello world" ); // Returns -1 (no match) 535 rx.search( "Hello world" ); // Returns -1 (no match)
536 rx.search( "This_is-OK" ); // Returns 0 (matched at position 0) 536 rx.search( "This_is-OK" ); // Returns 0 (matched at position 0)
537 \endcode 537 \endcode
538 538
539 The second string matches '<u>This_is-OK</u>'. We've used the 539 The second string matches '<u>This_is-OK</u>'. We've used the
540 character set abbreviation '\S' (non-whitespace) and the anchors to 540 character set abbreviation '\S' (non-whitespace) and the anchors to
541 match strings which contain no whitespace. 541 match strings which contain no whitespace.
542 542
543 In the following example we match strings containing 'mail' or 543 In the following example we match strings containing 'mail' or
544 'letter' or 'correspondence' but only match whole words i.e. not 544 'letter' or 'correspondence' but only match whole words i.e. not
545 'email' 545 'email'
546 546
547 \code 547 \code
548 QRegExp rx( "\\b(mail|letter|correspondence)\\b" ); 548 QRegExp rx( "\\b(mail|letter|correspondence)\\b" );
549 rx.search( "I sent you an email" ); // Returns -1 (no match) 549 rx.search( "I sent you an email" ); // Returns -1 (no match)
550 rx.search( "Please write the letter" ); // Returns 17 (matched at position 17) 550 rx.search( "Please write the letter" ); // Returns 17 (matched at position 17)
551 \endcode 551 \endcode
552 552
553 The second string matches "Please write the <u>letter</u>". The word 553 The second string matches "Please write the <u>letter</u>". The word
554 'letter' is also captured (because of the parenthesis). We can see 554 'letter' is also captured (because of the parenthesis). We can see
555 what text we've captured like this: 555 what text we've captured like this:
556 556
557 \code 557 \code
558 QString captured = rx.cap( 1 ); // captured contains "letter" 558 QString captured = rx.cap( 1 ); // captured contains "letter"
559 \endcode 559 \endcode
560 560
561 This will capture the text from the first set of capturing 561 This will capture the text from the first set of capturing
562 parenthesis (counting capturing left parenthesis from left to 562 parenthesis (counting capturing left parenthesis from left to
563 right). The parenthesis are counted from 1 since cap( 0 ) is the 563 right). The parenthesis are counted from 1 since cap( 0 ) is the
564 whole matched regexp (equivalent to '&' in most regexp engines). 564 whole matched regexp (equivalent to '&' in most regexp engines).
565 565
566 \code 566 \code
567 QRegExp rx( "&(?!amp;)" ); // Match ampersands but not &amp; 567 QRegExp rx( "&(?!amp;)" ); // Match ampersands but not &amp;
568 QString line1 = "This & that"; 568 QString line1 = "This & that";
569 line1.replace( rx, "&amp;" ); 569 line1.replace( rx, "&amp;" );
570 // line1 == "This &amp; that" 570 // line1 == "This &amp; that"
571 QString line2 = "His &amp; hers & theirs"; 571 QString line2 = "His &amp; hers & theirs";
572 line2.replace( rx, "&amp;" ); 572 line2.replace( rx, "&amp;" );
573 // line2 == "His &amp; hers &amp; theirs" 573 // line2 == "His &amp; hers &amp; theirs"
574 \endcode 574 \endcode
575 575
576 Here we've passed the QRegExp to QString's replace() function to 576 Here we've passed the QRegExp to QString's replace() function to
577 replace the matched text with new text. 577 replace the matched text with new text.
578 578
579 \code 579 \code
580 QString str = "One Eric another Eirik, and an Ericsson. How many Eiriks, Eric?"; 580 QString str = "One Eric another Eirik, and an Ericsson. How many Eiriks, Eric?";
581 QRegExp rx( "\\b(Eric|Eirik)\\b" ); // Match Eric or Eirik 581 QRegExp rx( "\\b(Eric|Eirik)\\b" ); // Match Eric or Eirik
582 int pos = 0; // Where we are in the string 582 int pos = 0; // Where we are in the string
583 int count = 0; // How many Eric and Eirik's we've counted 583 int count = 0; // How many Eric and Eirik's we've counted
584 while ( pos >= 0 ) { 584 while ( pos >= 0 ) {
585 pos = rx.search( str, pos ); 585 pos = rx.search( str, pos );
586 if ( pos >= 0 ) { 586 if ( pos >= 0 ) {
587 pos++; // Move along in str 587 pos++; // Move along in str
588 count++; // Count our Eric or Eirik 588 count++; // Count our Eric or Eirik
589 } 589 }
590 } 590 }
591 \endcode 591 \endcode
592 592
593 We've used the search() function to repeatedly match the regexp in 593 We've used the search() function to repeatedly match the regexp in
594 the string. Note that instead of moving forward by one character at 594 the string. Note that instead of moving forward by one character at
595 a time <tt>pos++</tt> we could have written <tt>pos += 595 a time <tt>pos++</tt> we could have written <tt>pos +=
596 rx.matchedLength()</tt> to skip over the already matched string. The 596 rx.matchedLength()</tt> to skip over the already matched string. The
597 count will equal 3, matching 'One <u>Eric</u> another <u>Eirik</u>, 597 count will equal 3, matching 'One <u>Eric</u> another <u>Eirik</u>,
598 and an Ericsson. How many Eiriks, <u>Eric</u>?'; it doesn't match 598 and an Ericsson. How many Eiriks, <u>Eric</u>?'; it doesn't match
599 'Ericsson' or 'Eiriks' because they are not bounded by non-word 599 'Ericsson' or 'Eiriks' because they are not bounded by non-word
600 boundaries. 600 boundaries.
601 601
602 One common use of regexps is to split lines of delimited data into 602 One common use of regexps is to split lines of delimited data into
603 their component fields. 603 their component fields.
604 604
605 \code 605 \code
606 str = "Trolltech AS\twww.trolltech.com\tNorway"; 606 str = "Trolltech AS\twww.trolltech.com\tNorway";
607 QString company, web, country; 607 QString company, web, country;
608 rx.setPattern( "^([^\t]+)\t([^\t]+)\t([^\t]+)$" ); 608 rx.setPattern( "^([^\t]+)\t([^\t]+)\t([^\t]+)$" );
609 if ( rx.search( str ) != -1 ) { 609 if ( rx.search( str ) != -1 ) {
610 company = rx.cap( 1 ); 610 company = rx.cap( 1 );
611 web = rx.cap( 2 ); 611 web = rx.cap( 2 );
612 country = rx.cap( 3 ); 612 country = rx.cap( 3 );
613 } 613 }
614 \endcode 614 \endcode
615 615
616 In this example our input lines have the format company name, web 616 In this example our input lines have the format company name, web
617 address and country. Unfortunately the regexp is rather long and not 617 address and country. Unfortunately the regexp is rather long and not
618 very versatile -- the code will break if we add any more fields. A 618 very versatile -- the code will break if we add any more fields. A
619 simpler and better solution is to look for the separator, '\t' in 619 simpler and better solution is to look for the separator, '\t' in
620 this case, and take the surrounding text. The QStringList split() 620 this case, and take the surrounding text. The QStringList split()
621 function can take a separator string or regexp as an argument and 621 function can take a separator string or regexp as an argument and
622 split a string accordingly. 622 split a string accordingly.
623 623
624 \code 624 \code
625 QStringList field = QStringList::split( "\t", str ); 625 QStringList field = QStringList::split( "\t", str );
626 \endcode 626 \endcode
627 627
628 Here field[0] is the company, field[1] the web address and so on. 628 Here field[0] is the company, field[1] the web address and so on.
629 629
630 To immitate the matching of a shell we can use wildcard mode. 630 To immitate the matching of a shell we can use wildcard mode.
631 631
632 \code 632 \code
633 QRegExp rx( "*.html" ); // Invalid regexp: * doesn't quantify anything 633 QRegExp rx( "*.html" ); // Invalid regexp: * doesn't quantify anything
634 rx.setWildcard( TRUE ); // Now its a valid wildcard regexp 634 rx.setWildcard( TRUE ); // Now its a valid wildcard regexp
635 rx.search( "index.html" ); // Returns 0 (matched at position 0) 635 rx.search( "index.html" ); // Returns 0 (matched at position 0)
636 rx.search( "default.htm" ); // Returns -1 (no match) 636 rx.search( "default.htm" ); // Returns -1 (no match)
637 rx.search( "readme.txt" ); // Returns -1 (no match) 637 rx.search( "readme.txt" ); // Returns -1 (no match)
638 \endcode 638 \endcode
639 639
640 Wildcard matching can be convenient because of its simplicity, but 640 Wildcard matching can be convenient because of its simplicity, but
641 any wildcard regex can be defined using full regexps, e.g. 641 any wildcard regex can be defined using full regexps, e.g.
642 <b>.*\.html$</b>. Notice that we can't match both \c .html and \c 642 <b>.*\.html$</b>. Notice that we can't match both \c .html and \c
643 .htm files with a wildcard unless we use <b>*.htm*</b> which will 643 .htm files with a wildcard unless we use <b>*.htm*</b> which will
644 also match 'test.html.bak'. A full regexp gives us the precision we 644 also match 'test.html.bak'. A full regexp gives us the precision we
645 need, <b>.*\.html?$</b>. 645 need, <b>.*\.html?$</b>.
646 646
647 QRegExp can match case insensitively using setCaseSensitive(), and 647 QRegExp can match case insensitively using setCaseSensitive(), and
648 can use non-greedy matching, see setMinimal(). By default QRegExp 648 can use non-greedy matching, see setMinimal(). By default QRegExp
649 uses full regexps but this can be changed with setWildcard(). 649 uses full regexps but this can be changed with setWildcard().
650 Searching can be forward with search() or backward with searchRev(). 650 Searching can be forward with search() or backward with searchRev().
651 Captured text can be accessed using capturedTexts() which returns a 651 Captured text can be accessed using capturedTexts() which returns a
652 string list of all captured strings, or using cap() which returns 652 string list of all captured strings, or using cap() which returns
653 the captured string for the given index. The pos() function takes a 653 the captured string for the given index. The pos() function takes a
654 match index and returns the position in the string where the match 654 match index and returns the position in the string where the match
655 was made (or -1 if there was no match). 655 was made (or -1 if there was no match).
656 656
657 \sa QRegExpValidator QString QStringList 657 \sa QRegExpValidator QString QStringList
658 658
659 <a name="member-function-documentation"/> 659 <a name="member-function-documentation"/>
660*/ 660*/
661 661
662static const int NumBadChars = 128; 662static const int NumBadChars = 128;
663#define BadChar( ch ) ( (ch).cell() % NumBadChars ) 663#define BadChar( ch ) ( (ch).cell() % NumBadChars )
664 664
665static const int NoOccurrence = INT_MAX; 665static const int NoOccurrence = INT_MAX;
666static const int EmptyCapture = INT_MAX; 666static const int EmptyCapture = INT_MAX;
667static const int InftyLen = INT_MAX; 667static const int InftyLen = INT_MAX;
668static const int InftyRep = 1000; 668static const int InftyRep = 1000;
669static const int EOS = -1; 669static const int EOS = -1;
670 670
671#ifndef QT_NO_REGEXP_OPTIM 671#ifndef QT_NO_REGEXP_OPTIM
672static int engCount = 0; 672static int engCount = 0;
673static QArray<int> *noOccurrences = 0; 673static QArray<int> *noOccurrences = 0;
674static QArray<int> *firstOccurrenceAtZero = 0; 674static QArray<int> *firstOccurrenceAtZero = 0;
675#endif 675#endif
676 676
677/* 677/*
678 Merges two QArrays of ints and puts the result into the first one. 678 Merges two QArrays of ints and puts the result into the first one.
679*/ 679*/
680static void mergeInto( QArray<int> *a, const QArray<int>& b ) 680static void mergeInto( QArray<int> *a, const QArray<int>& b )
681{ 681{
682 int asize = a->size(); 682 int asize = a->size();
683 int bsize = b.size(); 683 int bsize = b.size();
684 if ( asize == 0 ) { 684 if ( asize == 0 ) {
685 *a = b.copy(); 685 *a = b.copy();
686#ifndef QT_NO_REGEXP_OPTIM 686#ifndef QT_NO_REGEXP_OPTIM
687 } else if ( bsize == 1 && (*a)[asize - 1] < b[0] ) { 687 } else if ( bsize == 1 && (*a)[asize - 1] < b[0] ) {
688 a->resize( asize + 1 ); 688 a->resize( asize + 1 );
689 (*a)[asize] = b[0]; 689 (*a)[asize] = b[0];
690#endif 690#endif
691 } else if ( bsize >= 1 ) { 691 } else if ( bsize >= 1 ) {
692 int csize = asize + bsize; 692 int csize = asize + bsize;
693 QArray<int> c( csize ); 693 QArray<int> c( csize );
694 int i = 0, j = 0, k = 0; 694 int i = 0, j = 0, k = 0;
695 while ( i < asize ) { 695 while ( i < asize ) {
696 if ( j < bsize ) { 696 if ( j < bsize ) {
697 if ( (*a)[i] == b[j] ) { 697 if ( (*a)[i] == b[j] ) {
698 i++; 698 i++;
699 csize--; 699 csize--;
700 } else if ( (*a)[i] < b[j] ) { 700 } else if ( (*a)[i] < b[j] ) {
701 c[k++] = (*a)[i++]; 701 c[k++] = (*a)[i++];
702 } else { 702 } else {
703 c[k++] = b[j++]; 703 c[k++] = b[j++];
704 } 704 }
705 } else { 705 } else {
706 memcpy( c.data() + k, (*a).data() + i, 706 memcpy( c.data() + k, (*a).data() + i,
707 (asize - i) * sizeof(int) ); 707 (asize - i) * sizeof(int) );
708 break; 708 break;
709 } 709 }
710 } 710 }
711 c.resize( csize ); 711 c.resize( csize );
712 if ( j < bsize ) 712 if ( j < bsize )
713 memcpy( c.data() + k, b.data() + j, (bsize - j) * sizeof(int) ); 713 memcpy( c.data() + k, b.data() + j, (bsize - j) * sizeof(int) );
714 *a = c; 714 *a = c;
715 } 715 }
716} 716}
717 717
718/* 718/*
719 Merges two disjoint QMaps of (int, int) pairs and puts the result into the 719 Merges two disjoint QMaps of (int, int) pairs and puts the result into the
720 first one. 720 first one.
721*/ 721*/
722static void mergeInto( QMap<int, int> *a, const QMap<int, int>& b ) 722static void mergeInto( QMap<int, int> *a, const QMap<int, int>& b )
723{ 723{
724 QMap<int, int>::ConstIterator it; 724 QMap<int, int>::ConstIterator it;
725 for ( it = b.begin(); it != b.end(); ++it ) 725 for ( it = b.begin(); it != b.end(); ++it )
726 a->insert( it.key(), *it ); 726 a->insert( it.key(), *it );
727} 727}
728 728
729/* 729/*
730 Returns the value associated to key k in QMap m of (int, int) pairs, or 0 if 730 Returns the value associated to key k in QMap m of (int, int) pairs, or 0 if
731 no such value is explicitly present. 731 no such value is explicitly present.
732*/ 732*/
733static int at( const QMap<int, int>& m, int k ) 733static int at( const QMap<int, int>& m, int k )
734{ 734{
735 QMap<int, int>::ConstIterator it = m.find( k ); 735 QMap<int, int>::ConstIterator it = m.find( k );
736 if ( it == m.end() ) 736 if ( it == m.end() )
737 return 0; 737 return 0;
738 else 738 else
739 return *it; 739 return *it;
740} 740}
741 741
742#ifndef QT_NO_REGEXP_WILDCARD 742#ifndef QT_NO_REGEXP_WILDCARD
743/* 743/*
744 Translates a wildcard pattern to an equivalent regular expression pattern 744 Translates a wildcard pattern to an equivalent regular expression pattern
745 (e.g., *.cpp to .*\.cpp). 745 (e.g., *.cpp to .*\.cpp).
746*/ 746*/
747static QString wc2rx( const QString& wc ) 747static QString wc2rx( const QString& wc )
748{ 748{
749 int wclen = wc.length(); 749 int wclen = wc.length();
750 QString rx = QString::fromLatin1( "" ); 750 QString rx = QString::fromLatin1( "" );
751 int i = 0; 751 int i = 0;
752 while ( i < wclen ) { 752 while ( i < wclen ) {
753 QChar c = wc[i++]; 753 QChar c = wc[i++];
754 switch ( c.unicode() ) { 754 switch ( c.unicode() ) {
755 case '*': 755 case '*':
756 rx += QString::fromLatin1( ".*" ); 756 rx += QString::fromLatin1( ".*" );
757 break; 757 break;
758 case '?': 758 case '?':
759 rx += QChar( '.' ); 759 rx += QChar( '.' );
760 break; 760 break;
761 case '$': 761 case '$':
762 case '(': 762 case '(':
763 case ')': 763 case ')':
764 case '+': 764 case '+':
765 case '.': 765 case '.':
766 case '\\': 766 case '\\':
767 case '^': 767 case '^':
768 case '{': 768 case '{':
769 case '|': 769 case '|':
770 case '}': 770 case '}':
771 rx += QChar( '\\' ); 771 rx += QChar( '\\' );
772 rx += c; 772 rx += c;
773 break; 773 break;
774 case '[': 774 case '[':
775 rx += c; 775 rx += c;
776 if ( wc[i] == QChar('^') ) 776 if ( wc[i] == QChar('^') )
777 rx += wc[i++]; 777 rx += wc[i++];
778 if ( i < wclen ) { 778 if ( i < wclen ) {
779 if ( rx[i] == ']' ) 779 if ( rx[i] == ']' )
780 rx += wc[i++]; 780 rx += wc[i++];
781 while ( i < wclen && wc[i] != QChar(']') ) { 781 while ( i < wclen && wc[i] != QChar(']') ) {
782 if ( wc[i] == '\\' ) 782 if ( wc[i] == '\\' )
783 rx += QChar( '\\' ); 783 rx += QChar( '\\' );
784 rx += wc[i++]; 784 rx += wc[i++];
785 } 785 }
786 } 786 }
787 break; 787 break;
788 default: 788 default:
789 rx += c; 789 rx += c;
790 } 790 }
791 } 791 }
792 return rx; 792 return rx;
793} 793}
794#endif 794#endif
795 795
796/* 796/*
797 The class QRegExpEngine encapsulates a modified nondeterministic finite 797 The class QRegExpEngine encapsulates a modified nondeterministic finite
798 automaton (NFA). 798 automaton (NFA).
799*/ 799*/
800class QRegExpEngine : public QShared 800class QRegExpEngine : public QShared
801{ 801{
802public: 802public:
803#ifndef QT_NO_REGEXP_CCLASS 803#ifndef QT_NO_REGEXP_CCLASS
804 /* 804 /*
805 The class CharClass represents a set of characters, such as can be found 805 The class CharClass represents a set of characters, such as can be found
806 in regular expressions (e.g., [a-z] denotes the set {a, b, ..., z}). 806 in regular expressions (e.g., [a-z] denotes the set {a, b, ..., z}).
807 */ 807 */
808 class CharClass 808 class CharClass
809 { 809 {
810 public: 810 public:
811 CharClass(); 811 CharClass();
812 CharClass( const CharClass& cc ) { operator=( cc ); } 812 CharClass( const CharClass& cc ) { operator=( cc ); }
813 813
814 CharClass& operator=( const CharClass& cc ); 814 CharClass& operator=( const CharClass& cc );
815 815
816 void clear(); 816 void clear();
817 bool negative() const { return n; } 817 bool negative() const { return n; }
818 void setNegative( bool negative ); 818 void setNegative( bool negative );
819 void addCategories( int cats ); 819 void addCategories( int cats );
820 void addRange( ushort from, ushort to ); 820 void addRange( ushort from, ushort to );
821 void addSingleton( ushort ch ) { addRange( ch, ch ); } 821 void addSingleton( ushort ch ) { addRange( ch, ch ); }
822 822
823 bool in( QChar ch ) const; 823 bool in( QChar ch ) const;
824#ifndef QT_NO_REGEXP_OPTIM 824#ifndef QT_NO_REGEXP_OPTIM
825 const QArray<int>& firstOccurrence() const { return occ1; } 825 const QArray<int>& firstOccurrence() const { return occ1; }
826#endif 826#endif
827 827
828#if defined(QT_DEBUG) 828#if defined(QT_DEBUG)
829 void dump() const; 829 void dump() const;
830#endif 830#endif
831 831
832 private: 832 private:
833 /* 833 /*
834 The struct Range represents a range of characters (e.g., [0-9] denotes 834 The struct Range represents a range of characters (e.g., [0-9] denotes
835 range 48 to 57). 835 range 48 to 57).
836 */ 836 */
837 struct Range 837 struct Range
838 { 838 {
839 ushort from; // 48 839 ushort from; // 48
840 ushort to; // 57 840 ushort to; // 57
841 }; 841 };
842 842
843 int c; // character classes 843 int c; // character classes
844 QArray<Range> r; // character ranges 844 QArray<Range> r; // character ranges
845 bool n; // negative? 845 bool n; // negative?
846#ifndef QT_NO_REGEXP_OPTIM 846#ifndef QT_NO_REGEXP_OPTIM
847 QArray<int> occ1; // first-occurrence array 847 QArray<int> occ1; // first-occurrence array
848#endif 848#endif
849 }; 849 };
850#else 850#else
851 struct CharClass 851 struct CharClass
852 { 852 {
853 int x; // dummy 853 int x; // dummy
854 854
855#ifndef QT_NO_REGEXP_OPTIM 855#ifndef QT_NO_REGEXP_OPTIM
856 const QArray<int>& firstOccurrence() const { 856 const QArray<int>& firstOccurrence() const {
857 return *firstOccurrenceAtZero; 857 return *firstOccurrenceAtZero;
858 } 858 }
859#endif 859#endif
860 }; 860 };
861#endif 861#endif
862 862
863 QRegExpEngine( bool caseSensitive ) { setup( caseSensitive ); } 863 QRegExpEngine( bool caseSensitive ) { setup( caseSensitive ); }
864 QRegExpEngine( const QString& rx, bool caseSensitive ); 864 QRegExpEngine( const QString& rx, bool caseSensitive );
865#ifndef QT_NO_REGEXP_OPTIM 865#ifndef QT_NO_REGEXP_OPTIM
866 ~QRegExpEngine(); 866 ~QRegExpEngine();
867#endif 867#endif
868 868
869 bool isValid() const { return valid; } 869 bool isValid() const { return valid; }
870 bool caseSensitive() const { return cs; } 870 bool caseSensitive() const { return cs; }
871 int numCaptures() const { return realncap; } 871 int numCaptures() const { return realncap; }
872 QArray<int> match( const QString& str, int pos, bool minimal, 872 QArray<int> match( const QString& str, int pos, bool minimal,
873 bool oneTest ); 873 bool oneTest );
874 int matchedLength() const { return mmMatchedLen; } 874 int matchedLength() const { return mmMatchedLen; }
875 875
876 int createState( QChar ch ); 876 int createState( QChar ch );
877 int createState( const CharClass& cc ); 877 int createState( const CharClass& cc );
878#ifndef QT_NO_REGEXP_BACKREF 878#ifndef QT_NO_REGEXP_BACKREF
879 int createState( int bref ); 879 int createState( int bref );
880#endif 880#endif
881 881
882 void addCatTransitions( const QArray<int>& from, const QArray<int>& to ); 882 void addCatTransitions( const QArray<int>& from, const QArray<int>& to );
883#ifndef QT_NO_REGEXP_CAPTURE 883#ifndef QT_NO_REGEXP_CAPTURE
884 void addPlusTransitions( const QArray<int>& from, const QArray<int>& to, 884 void addPlusTransitions( const QArray<int>& from, const QArray<int>& to,
885 int atom ); 885 int atom );
886#endif 886#endif
887 887
888#ifndef QT_NO_REGEXP_ANCHOR_ALT 888#ifndef QT_NO_REGEXP_ANCHOR_ALT
889 int anchorAlternation( int a, int b ); 889 int anchorAlternation( int a, int b );
890 int anchorConcatenation( int a, int b ); 890 int anchorConcatenation( int a, int b );
891#else 891#else
892 int anchorAlternation( int a, int b ) { return a & b; } 892 int anchorAlternation( int a, int b ) { return a & b; }
893 int anchorConcatenation( int a, int b ) { return a | b; } 893 int anchorConcatenation( int a, int b ) { return a | b; }
894#endif 894#endif
895 void addAnchors( int from, int to, int a ); 895 void addAnchors( int from, int to, int a );
896 896
897#ifndef QT_NO_REGEXP_OPTIM 897#ifndef QT_NO_REGEXP_OPTIM
898 void setupGoodStringHeuristic( int earlyStart, int lateStart, 898 void setupGoodStringHeuristic( int earlyStart, int lateStart,
899 const QString& str ); 899 const QString& str );
900 void setupBadCharHeuristic( int minLen, const QArray<int>& firstOcc ); 900 void setupBadCharHeuristic( int minLen, const QArray<int>& firstOcc );
901 void heuristicallyChooseHeuristic(); 901 void heuristicallyChooseHeuristic();
902#endif 902#endif
903 903
904#if defined(QT_DEBUG) 904#if defined(QT_DEBUG)
905 void dump() const; 905 void dump() const;
906#endif 906#endif
907 907
908private: 908private:
909 enum { CharClassBit = 0x10000, BackRefBit = 0x20000 }; 909 enum { CharClassBit = 0x10000, BackRefBit = 0x20000 };
910 910
911 /* 911 /*
912 The struct State represents one state in a modified NFA. The input 912 The struct State represents one state in a modified NFA. The input
913 characters matched are stored in the state instead of on the transitions, 913 characters matched are stored in the state instead of on the transitions,
914 something possible for an automaton constructed from a regular expression. 914 something possible for an automaton constructed from a regular expression.
915 */ 915 */
916 struct State 916 struct State
917 { 917 {
918#ifndef QT_NO_REGEXP_CAPTURE 918#ifndef QT_NO_REGEXP_CAPTURE
919 int atom; // which atom does this state belong to? 919 int atom; // which atom does this state belong to?
920#endif 920#endif
921 int match; // what does it match? (see CharClassBit and BackRefBit) 921 int match; // what does it match? (see CharClassBit and BackRefBit)
922 QArray<int> outs; // out-transitions 922 QArray<int> outs; // out-transitions
923 QMap<int, int> *reenter; // atoms reentered when transiting out 923 QMap<int, int> *reenter; // atoms reentered when transiting out
924 QMap<int, int> *anchors; // anchors met when transiting out 924 QMap<int, int> *anchors; // anchors met when transiting out
925 925
926#ifndef QT_NO_REGEXP_CAPTURE 926#ifndef QT_NO_REGEXP_CAPTURE
927 State( int a, int m ) 927 State( int a, int m )
928 : atom( a ), match( m ), reenter( 0 ), anchors( 0 ) { } 928 : atom( a ), match( m ), reenter( 0 ), anchors( 0 ) { }
929#else 929#else
930 State( int m ) 930 State( int m )
931 : match( m ), reenter( 0 ), anchors( 0 ) { } 931 : match( m ), reenter( 0 ), anchors( 0 ) { }
932#endif 932#endif
933 ~State() { delete reenter; delete anchors; } 933 ~State() { delete reenter; delete anchors; }
934 }; 934 };
935 935
936#ifndef QT_NO_REGEXP_LOOKAHEAD 936#ifndef QT_NO_REGEXP_LOOKAHEAD
937 /* 937 /*
938 The struct Lookahead represents a lookahead a la Perl (e.g., (?=foo) and 938 The struct Lookahead represents a lookahead a la Perl (e.g., (?=foo) and
939 (?!bar)). 939 (?!bar)).
940 */ 940 */
941 struct Lookahead 941 struct Lookahead
942 { 942 {
943 QRegExpEngine *eng; // NFA representing the embedded regular expression 943 QRegExpEngine *eng; // NFA representing the embedded regular expression
944 bool neg; // negative lookahead? 944 bool neg; // negative lookahead?
945 945
946 Lookahead( QRegExpEngine *eng0, bool neg0 ) 946 Lookahead( QRegExpEngine *eng0, bool neg0 )
947 : eng( eng0 ), neg( neg0 ) { } 947 : eng( eng0 ), neg( neg0 ) { }
948 ~Lookahead() { delete eng; } 948 ~Lookahead() { delete eng; }
949 }; 949 };
950#endif 950#endif
951 951
952#ifndef QT_NO_REGEXP_CAPTURE 952#ifndef QT_NO_REGEXP_CAPTURE
953 /* 953 /*
954 The struct Atom represents one node in the hierarchy of regular expression 954 The struct Atom represents one node in the hierarchy of regular expression
955 atoms. 955 atoms.
956 */ 956 */
957 struct Atom 957 struct Atom
958 { 958 {
959 int parent; // index of parent in array of atoms 959 int parent; // index of parent in array of atoms
960 int capture; // index of capture, from 1 to ncap 960 int capture; // index of capture, from 1 to ncap
961 }; 961 };
962#endif 962#endif
963 963
964#ifndef QT_NO_REGEXP_ANCHOR_ALT 964#ifndef QT_NO_REGEXP_ANCHOR_ALT
965 /* 965 /*
966 The struct AnchorAlternation represents a pair of anchors with OR 966 The struct AnchorAlternation represents a pair of anchors with OR
967 semantics. 967 semantics.
968 */ 968 */
969 struct AnchorAlternation 969 struct AnchorAlternation
970 { 970 {
971 int a; // this anchor... 971 int a; // this anchor...
972 int b; // ...or this one 972 int b; // ...or this one
973 }; 973 };
974#endif 974#endif
975 975
976 enum { InitialState = 0, FinalState = 1 }; 976 enum { InitialState = 0, FinalState = 1 };
977 void setup( bool caseSensitive ); 977 void setup( bool caseSensitive );
978 int setupState( int match ); 978 int setupState( int match );
979 979
980 /* 980 /*
981 Let's hope that 13 lookaheads and 14 back-references are enough. 981 Let's hope that 13 lookaheads and 14 back-references are enough.
982 */ 982 */
983 enum { MaxLookaheads = 13, MaxBackRefs = 14 }; 983 enum { MaxLookaheads = 13, MaxBackRefs = 14 };
984 enum { Anchor_Dollar = 0x00000001, Anchor_Caret = 0x00000002, 984 enum { Anchor_Dollar = 0x00000001, Anchor_Caret = 0x00000002,
985 Anchor_Word = 0x00000004, Anchor_NonWord = 0x00000008, 985 Anchor_Word = 0x00000004, Anchor_NonWord = 0x00000008,
986 Anchor_FirstLookahead = 0x00000010, 986 Anchor_FirstLookahead = 0x00000010,
987 Anchor_BackRef1Empty = Anchor_FirstLookahead << MaxLookaheads, 987 Anchor_BackRef1Empty = Anchor_FirstLookahead << MaxLookaheads,
988 Anchor_BackRef0Empty = Anchor_BackRef1Empty >> 1, 988 Anchor_BackRef0Empty = Anchor_BackRef1Empty >> 1,
989 Anchor_Alternation = Anchor_BackRef1Empty << MaxBackRefs, 989 Anchor_Alternation = Anchor_BackRef1Empty << MaxBackRefs,
990 990
991 Anchor_LookaheadMask = ( Anchor_FirstLookahead - 1 ) ^ 991 Anchor_LookaheadMask = ( Anchor_FirstLookahead - 1 ) ^
992 ( (Anchor_FirstLookahead << MaxLookaheads) - 1 ) }; 992 ( (Anchor_FirstLookahead << MaxLookaheads) - 1 ) };
993#ifndef QT_NO_REGEXP_CAPTURE 993#ifndef QT_NO_REGEXP_CAPTURE
994 int startAtom( bool capture ); 994 int startAtom( bool capture );
995 void finishAtom( int atom ) { cf = f[atom].parent; } 995 void finishAtom( int atom ) { cf = f[atom].parent; }
996#endif 996#endif
997 997
998#ifndef QT_NO_REGEXP_LOOKAHEAD 998#ifndef QT_NO_REGEXP_LOOKAHEAD
999 int addLookahead( QRegExpEngine *eng, bool negative ); 999 int addLookahead( QRegExpEngine *eng, bool negative );
1000#endif 1000#endif
1001 1001
1002#ifndef QT_NO_REGEXP_CAPTURE 1002#ifndef QT_NO_REGEXP_CAPTURE
1003 bool isBetterCapture( const int *begin1, const int *end1, const int *begin2, 1003 bool isBetterCapture( const int *begin1, const int *end1, const int *begin2,
1004 const int *end2 ); 1004 const int *end2 );
1005#endif 1005#endif
1006 bool testAnchor( int i, int a, const int *capBegin ); 1006 bool testAnchor( int i, int a, const int *capBegin );
1007 1007
1008#ifndef QT_NO_REGEXP_OPTIM 1008#ifndef QT_NO_REGEXP_OPTIM
1009 bool goodStringMatch(); 1009 bool goodStringMatch();
1010 bool badCharMatch(); 1010 bool badCharMatch();
1011#else 1011#else
1012 bool bruteMatch(); 1012 bool bruteMatch();
1013#endif 1013#endif
1014 bool matchHere(); 1014 bool matchHere();
1015 1015
1016 QVector<State> s; // array of states 1016 QVector<State> s; // array of states
1017 int ns; // number of states 1017 int ns; // number of states
1018#ifndef QT_NO_REGEXP_CAPTURE 1018#ifndef QT_NO_REGEXP_CAPTURE
1019 QArray<Atom> f; // atom hierarchy 1019 QArray<Atom> f; // atom hierarchy
1020 int nf; // number of atoms 1020 int nf; // number of atoms
1021 int cf; // current atom 1021 int cf; // current atom
1022#endif 1022#endif
1023 int realncap; // number of captures, seen from the outside 1023 int realncap; // number of captures, seen from the outside
1024 int ncap; // number of captures, seen from the inside 1024 int ncap; // number of captures, seen from the inside
1025#ifndef QT_NO_REGEXP_CCLASS 1025#ifndef QT_NO_REGEXP_CCLASS
1026 QVector<CharClass> cl; // array of character classes 1026 QVector<CharClass> cl; // array of character classes
1027#endif 1027#endif
1028#ifndef QT_NO_REGEXP_LOOKAHEAD 1028#ifndef QT_NO_REGEXP_LOOKAHEAD
1029 QVector<Lookahead> ahead; // array of lookaheads 1029 QVector<Lookahead> ahead; // array of lookaheads
1030#endif 1030#endif
1031#ifndef QT_NO_REGEXP_ANCHOR_ALT 1031#ifndef QT_NO_REGEXP_ANCHOR_ALT
1032 QArray<AnchorAlternation> aa; // array of (a, b) pairs of anchors 1032 QArray<AnchorAlternation> aa; // array of (a, b) pairs of anchors
1033#endif 1033#endif
1034#ifndef QT_NO_REGEXP_OPTIM 1034#ifndef QT_NO_REGEXP_OPTIM
1035 bool caretAnchored; // does the regexp start with ^? 1035 bool caretAnchored; // does the regexp start with ^?
1036#endif 1036#endif
1037 bool valid; // is the regular expression valid? 1037 bool valid; // is the regular expression valid?
1038 bool cs; // case sensitive? 1038 bool cs; // case sensitive?
1039#ifndef QT_NO_REGEXP_BACKREF 1039#ifndef QT_NO_REGEXP_BACKREF
1040 int nbrefs; // number of back-references 1040 int nbrefs; // number of back-references
1041#endif 1041#endif
1042 1042
1043#ifndef QT_NO_REGEXP_OPTIM 1043#ifndef QT_NO_REGEXP_OPTIM
1044 bool useGoodStringHeuristic; // use goodStringMatch? otherwise badCharMatch 1044 bool useGoodStringHeuristic; // use goodStringMatch? otherwise badCharMatch
1045 1045
1046 int goodEarlyStart; // the index where goodStr can first occur in a match 1046 int goodEarlyStart; // the index where goodStr can first occur in a match
1047 int goodLateStart; // the index where goodStr can last occur in a match 1047 int goodLateStart; // the index where goodStr can last occur in a match
1048 QString goodStr; // the string that any match has to contain 1048 QString goodStr; // the string that any match has to contain
1049 1049
1050 int minl; // the minimum length of a match 1050 int minl; // the minimum length of a match
1051 QArray<int> occ1; // first-occurrence array 1051 QArray<int> occ1; // first-occurrence array
1052#endif 1052#endif
1053 1053
1054 /* 1054 /*
1055 The class Box is an abstraction for a regular expression fragment. It can 1055 The class Box is an abstraction for a regular expression fragment. It can
1056 also be seen as one node in the syntax tree of a regular expression with 1056 also be seen as one node in the syntax tree of a regular expression with
1057 synthetized attributes. 1057 synthetized attributes.
1058 1058
1059 It's interface is ugly for performance reasons. 1059 It's interface is ugly for performance reasons.
1060 */ 1060 */
1061 class Box 1061 class Box
1062 { 1062 {
1063 public: 1063 public:
1064 Box( QRegExpEngine *engine ); 1064 Box( QRegExpEngine *engine );
1065 Box( const Box& b ) { operator=( b ); } 1065 Box( const Box& b ) { operator=( b ); }
1066 1066
1067 Box& operator=( const Box& b ); 1067 Box& operator=( const Box& b );
1068 1068
1069 void clear() { operator=(Box(eng)); } 1069 void clear() { operator=(Box(eng)); }
1070 void set( QChar ch ); 1070 void set( QChar ch );
1071 void set( const CharClass& cc ); 1071 void set( const CharClass& cc );
1072#ifndef QT_NO_REGEXP_BACKREF 1072#ifndef QT_NO_REGEXP_BACKREF
1073 void set( int bref ); 1073 void set( int bref );
1074#endif 1074#endif
1075 1075
1076 void cat( const Box& b ); 1076 void cat( const Box& b );
1077 void orx( const Box& b ); 1077 void orx( const Box& b );
1078 void plus( int atom ); 1078 void plus( int atom );
1079 void opt(); 1079 void opt();
1080 void catAnchor( int a ); 1080 void catAnchor( int a );
1081#ifndef QT_NO_REGEXP_OPTIM 1081#ifndef QT_NO_REGEXP_OPTIM
1082 void setupHeuristics(); 1082 void setupHeuristics();
1083#endif 1083#endif
1084 1084
1085#if defined(QT_DEBUG) 1085#if defined(QT_DEBUG)
1086 void dump() const; 1086 void dump() const;
1087#endif 1087#endif
1088 1088
1089 private: 1089 private:
1090 void addAnchorsToEngine( const Box& to ) const; 1090 void addAnchorsToEngine( const Box& to ) const;
1091 1091
1092 QRegExpEngine *eng; // the automaton under construction 1092 QRegExpEngine *eng; // the automaton under construction
1093 QArray<int> ls; // the left states (firstpos) 1093 QArray<int> ls; // the left states (firstpos)
1094 QArray<int> rs; // the right states (lastpos) 1094 QArray<int> rs; // the right states (lastpos)
1095 QMap<int, int> lanchors; // the left anchors 1095 QMap<int, int> lanchors; // the left anchors
1096 QMap<int, int> ranchors; // the right anchors 1096 QMap<int, int> ranchors; // the right anchors
1097 int skipanchors; // the anchors to match if the box is skipped 1097 int skipanchors; // the anchors to match if the box is skipped
1098 1098
1099#ifndef QT_NO_REGEXP_OPTIM 1099#ifndef QT_NO_REGEXP_OPTIM
1100 int earlyStart; // the index where str can first occur 1100 int earlyStart; // the index where str can first occur
1101 int lateStart; // the index where str can last occur 1101 int lateStart; // the index where str can last occur
1102 QString str; // a string that has to occur in any match 1102 QString str; // a string that has to occur in any match
1103 QString leftStr; // a string occurring at the left of this box 1103 QString leftStr; // a string occurring at the left of this box
1104 QString rightStr; // a string occurring at the right of this box 1104 QString rightStr; // a string occurring at the right of this box
1105 int maxl; // the maximum length of this box (possibly InftyLen) 1105 int maxl; // the maximum length of this box (possibly InftyLen)
1106#endif 1106#endif
1107 1107
1108 int minl; // the minimum length of this box 1108 int minl; // the minimum length of this box
1109#ifndef QT_NO_REGEXP_OPTIM 1109#ifndef QT_NO_REGEXP_OPTIM
1110 QArray<int> occ1; // first-occurrence array 1110 QArray<int> occ1; // first-occurrence array
1111#endif 1111#endif
1112 }; 1112 };
1113 friend class Box; 1113 friend class Box;
1114 1114
1115 /* 1115 /*
1116 This is the lexical analyzer for regular expressions. 1116 This is the lexical analyzer for regular expressions.
1117 */ 1117 */
1118 enum { Tok_Eos, Tok_Dollar, Tok_LeftParen, Tok_MagicLeftParen, 1118 enum { Tok_Eos, Tok_Dollar, Tok_LeftParen, Tok_MagicLeftParen,
1119 Tok_PosLookahead, Tok_NegLookahead, Tok_RightParen, Tok_CharClass, 1119 Tok_PosLookahead, Tok_NegLookahead, Tok_RightParen, Tok_CharClass,
1120 Tok_Caret, Tok_Quantifier, Tok_Bar, Tok_Word, Tok_NonWord, 1120 Tok_Caret, Tok_Quantifier, Tok_Bar, Tok_Word, Tok_NonWord,
1121 Tok_Char = 0x10000, Tok_BackRef = 0x20000 }; 1121 Tok_Char = 0x10000, Tok_BackRef = 0x20000 };
1122 int getChar(); 1122 int getChar();
1123 int getEscape(); 1123 int getEscape();
1124#ifndef QT_NO_REGEXP_INTERVAL 1124#ifndef QT_NO_REGEXP_INTERVAL
1125 int getRep( int def ); 1125 int getRep( int def );
1126#endif 1126#endif
1127#ifndef QT_NO_REGEXP_LOOKAHEAD 1127#ifndef QT_NO_REGEXP_LOOKAHEAD
1128 void skipChars( int n ); 1128 void skipChars( int n );
1129#endif 1129#endif
1130 void startTokenizer( const QChar *rx, int len ); 1130 void startTokenizer( const QChar *rx, int len );
1131 int getToken(); 1131 int getToken();
1132 1132
1133 const QChar *yyIn; // a pointer to the input regular expression pattern 1133 const QChar *yyIn; // a pointer to the input regular expression pattern
1134 int yyPos0; // the position of yyTok in the input pattern 1134 int yyPos0; // the position of yyTok in the input pattern
1135 int yyPos; // the position of the next character to read 1135 int yyPos; // the position of the next character to read
1136 int yyLen; // the length of yyIn 1136 int yyLen; // the length of yyIn
1137 int yyCh; // the last character read 1137 int yyCh; // the last character read
1138 CharClass *yyCharClass; // attribute for Tok_CharClass tokens 1138 CharClass *yyCharClass; // attribute for Tok_CharClass tokens
1139 int yyMinRep; // attribute for Tok_Quantifier 1139 int yyMinRep; // attribute for Tok_Quantifier
1140 int yyMaxRep; // ditto 1140 int yyMaxRep; // ditto
1141 bool yyError; // syntax error or overflow during parsing? 1141 bool yyError; // syntax error or overflow during parsing?
1142 1142
1143 /* 1143 /*
1144 This is the syntactic analyzer for regular expressions. 1144 This is the syntactic analyzer for regular expressions.
1145 */ 1145 */
1146 int parse( const QChar *rx, int len ); 1146 int parse( const QChar *rx, int len );
1147 void parseAtom( Box *box ); 1147 void parseAtom( Box *box );
1148 void parseFactor( Box *box ); 1148 void parseFactor( Box *box );
1149 void parseTerm( Box *box ); 1149 void parseTerm( Box *box );
1150 void parseExpression( Box *box ); 1150 void parseExpression( Box *box );
1151 1151
1152 int yyTok; // the last token read 1152 int yyTok; // the last token read
1153 bool yyMayCapture; // set this to FALSE to disable capturing 1153 bool yyMayCapture; // set this to FALSE to disable capturing
1154 1154
1155 /* 1155 /*
1156 This is the engine state during matching. 1156 This is the engine state during matching.
1157 */ 1157 */
1158 const QString *mmStr; // a pointer to the input QString 1158 const QString *mmStr; // a pointer to the input QString
1159 const QChar *mmIn; // a pointer to the input string data 1159 const QChar *mmIn; // a pointer to the input string data
1160 int mmPos; // the current position in the string 1160 int mmPos; // the current position in the string
1161 int mmLen; // the length of the input string 1161 int mmLen; // the length of the input string
1162 bool mmMinimal; // minimal matching? 1162 bool mmMinimal; // minimal matching?
1163 QArray<int> mmCaptured; // an array of pairs (start, len) 1163 QArray<int> mmCaptured; // an array of pairs (start, len)
1164 QArray<int> mmCapturedNoMatch; // an array of pairs (-1, -1) 1164 QArray<int> mmCapturedNoMatch; // an array of pairs (-1, -1)
1165 QArray<int> mmBigArray; // big QArray<int> array 1165 QArray<int> mmBigArray; // big QArray<int> array
1166 int *mmInNextStack; // is state is mmNextStack? 1166 int *mmInNextStack; // is state is mmNextStack?
1167 int *mmCurStack; // stack of current states 1167 int *mmCurStack; // stack of current states
1168 int *mmNextStack; // stack of next states 1168 int *mmNextStack; // stack of next states
1169 int *mmCurCapBegin; // start of current states' captures 1169 int *mmCurCapBegin; // start of current states' captures
1170 int *mmNextCapBegin; // start of next states' captures 1170 int *mmNextCapBegin; // start of next states' captures
1171 int *mmCurCapEnd; // end of current states' captures 1171 int *mmCurCapEnd; // end of current states' captures
1172 int *mmNextCapEnd; // end of next states' captures 1172 int *mmNextCapEnd; // end of next states' captures
1173 int *mmTempCapBegin; // start of temporary captures 1173 int *mmTempCapBegin; // start of temporary captures
1174 int *mmTempCapEnd; // end of temporary captures 1174 int *mmTempCapEnd; // end of temporary captures
1175 int *mmCapBegin; // start of captures for a next state 1175 int *mmCapBegin; // start of captures for a next state
1176 int *mmCapEnd; // end of captures for a next state 1176 int *mmCapEnd; // end of captures for a next state
1177 int *mmSlideTab; // bump-along slide table for bad-character heuristic 1177 int *mmSlideTab; // bump-along slide table for bad-character heuristic
1178 int mmSlideTabSize; // size of slide table 1178 int mmSlideTabSize; // size of slide table
1179#ifndef QT_NO_REGEXP_BACKREF 1179#ifndef QT_NO_REGEXP_BACKREF
1180 QIntDict<int> mmSleeping; // dictionary of back-reference sleepers 1180 QIntDict<int> mmSleeping; // dictionary of back-reference sleepers
1181#endif 1181#endif
1182 int mmMatchedLen; // length of match or of matched string for partial match 1182 int mmMatchedLen; // length of match or of matched string for partial match
1183}; 1183};
1184 1184
1185QRegExpEngine::QRegExpEngine( const QString& rx, bool caseSensitive ) 1185QRegExpEngine::QRegExpEngine( const QString& rx, bool caseSensitive )
1186#ifndef QT_NO_REGEXP_BACKREF 1186#ifndef QT_NO_REGEXP_BACKREF
1187 : mmSleeping( 101 ) 1187 : mmSleeping( 101 )
1188#endif 1188#endif
1189{ 1189{
1190 setup( caseSensitive ); 1190 setup( caseSensitive );
1191 valid = ( parse(rx.unicode(), rx.length()) == (int) rx.length() ); 1191 valid = ( parse(rx.unicode(), rx.length()) == (int) rx.length() );
1192} 1192}
1193 1193
1194#ifndef QT_NO_REGEXP_OPTIM 1194#ifndef QT_NO_REGEXP_OPTIM
1195QRegExpEngine::~QRegExpEngine() 1195QRegExpEngine::~QRegExpEngine()
1196{ 1196{
1197 if ( --engCount == 0 ) { 1197 if ( --engCount == 0 ) {
1198 delete noOccurrences; 1198 delete noOccurrences;
1199 noOccurrences = 0; 1199 noOccurrences = 0;
1200 delete firstOccurrenceAtZero; 1200 delete firstOccurrenceAtZero;
1201 firstOccurrenceAtZero = 0; 1201 firstOccurrenceAtZero = 0;
1202 } 1202 }
1203} 1203}
1204#endif 1204#endif
1205 1205
1206/* 1206/*
1207 Tries to match in str and returns an array of (begin, length) pairs for 1207 Tries to match in str and returns an array of (begin, length) pairs for
1208 captured text. If there is no match, all pairs are (-1, -1). 1208 captured text. If there is no match, all pairs are (-1, -1).
1209*/ 1209*/
1210QArray<int> QRegExpEngine::match( const QString& str, int pos, bool minimal, 1210QArray<int> QRegExpEngine::match( const QString& str, int pos, bool minimal,
1211 bool oneTest ) 1211 bool oneTest )
1212{ 1212{
1213 mmStr = &str; 1213 mmStr = &str;
1214 mmIn = str.unicode(); 1214 mmIn = str.unicode();
1215 if ( mmIn == 0 ) 1215 if ( mmIn == 0 )
1216 mmIn = &QChar::null; 1216 mmIn = &QChar::null;
1217 mmPos = pos; 1217 mmPos = pos;
1218 mmLen = str.length(); 1218 mmLen = str.length();
1219 mmMinimal = minimal; 1219 mmMinimal = minimal;
1220 mmMatchedLen = 0; 1220 mmMatchedLen = 0;
1221 1221
1222 bool matched = FALSE; 1222 bool matched = FALSE;
1223 if ( valid && mmPos >= 0 && mmPos <= mmLen ) { 1223 if ( valid && mmPos >= 0 && mmPos <= mmLen ) {
1224#ifndef QT_NO_REGEXP_OPTIM 1224#ifndef QT_NO_REGEXP_OPTIM
1225 if ( mmPos <= mmLen - minl ) { 1225 if ( mmPos <= mmLen - minl ) {
1226 if ( caretAnchored || oneTest ) 1226 if ( caretAnchored || oneTest )
1227 matched = matchHere(); 1227 matched = matchHere();
1228 else if ( useGoodStringHeuristic ) 1228 else if ( useGoodStringHeuristic )
1229 matched = goodStringMatch(); 1229 matched = goodStringMatch();
1230 else 1230 else
1231 matched = badCharMatch(); 1231 matched = badCharMatch();
1232 } 1232 }
1233#else 1233#else
1234 matched = oneTest ? matchHere() : bruteMatch(); 1234 matched = oneTest ? matchHere() : bruteMatch();
1235#endif 1235#endif
1236 } 1236 }
1237 1237
1238 if ( matched ) { 1238 if ( matched ) {
1239 mmCaptured.detach(); 1239 mmCaptured.detach();
1240 mmCaptured[0] = mmPos; 1240 mmCaptured[0] = mmPos;
1241 mmCaptured[1] = mmMatchedLen; 1241 mmCaptured[1] = mmMatchedLen;
1242 for ( int j = 0; j < realncap; j++ ) { 1242 for ( int j = 0; j < realncap; j++ ) {
1243 int len = mmCapEnd[j] - mmCapBegin[j]; 1243 int len = mmCapEnd[j] - mmCapBegin[j];
1244 mmCaptured[2 + 2 * j] = len > 0 ? mmPos + mmCapBegin[j] : 0; 1244 mmCaptured[2 + 2 * j] = len > 0 ? mmPos + mmCapBegin[j] : 0;
1245 mmCaptured[2 + 2 * j + 1] = len; 1245 mmCaptured[2 + 2 * j + 1] = len;
1246 } 1246 }
1247 return mmCaptured; 1247 return mmCaptured;
1248 } else { 1248 } else {
1249 return mmCapturedNoMatch; 1249 return mmCapturedNoMatch;
1250 } 1250 }
1251} 1251}
1252 1252
1253/* 1253/*
1254 The three following functions add one state to the automaton and return the 1254 The three following functions add one state to the automaton and return the
1255 number of the state. 1255 number of the state.
1256*/ 1256*/
1257 1257
1258int QRegExpEngine::createState( QChar ch ) 1258int QRegExpEngine::createState( QChar ch )
1259{ 1259{
1260 return setupState( ch.unicode() ); 1260 return setupState( ch.unicode() );
1261} 1261}
1262 1262
1263int QRegExpEngine::createState( const CharClass& cc ) 1263int QRegExpEngine::createState( const CharClass& cc )
1264{ 1264{
1265#ifndef QT_NO_REGEXP_CCLASS 1265#ifndef QT_NO_REGEXP_CCLASS
1266 int n = cl.size(); 1266 int n = cl.size();
1267 cl.resize( n + 1 ); 1267 cl.resize( n + 1 );
1268 cl.insert( n, new CharClass(cc) ); 1268 cl.insert( n, new CharClass(cc) );
1269 return setupState( CharClassBit | n ); 1269 return setupState( CharClassBit | n );
1270#else 1270#else
1271 Q_UNUSED( cc ); 1271 Q_UNUSED( cc );
1272 return setupState( CharClassBit ); 1272 return setupState( CharClassBit );
1273#endif 1273#endif
1274} 1274}
1275 1275
1276#ifndef QT_NO_REGEXP_BACKREF 1276#ifndef QT_NO_REGEXP_BACKREF
1277int QRegExpEngine::createState( int bref ) 1277int QRegExpEngine::createState( int bref )
1278{ 1278{
1279 if ( bref > nbrefs ) { 1279 if ( bref > nbrefs ) {
1280 nbrefs = bref; 1280 nbrefs = bref;
1281 if ( nbrefs > MaxBackRefs ) { 1281 if ( nbrefs > MaxBackRefs ) {
1282 yyError = TRUE; 1282 yyError = TRUE;
1283 return 0; 1283 return 0;
1284 } 1284 }
1285 } 1285 }
1286 return setupState( BackRefBit | bref ); 1286 return setupState( BackRefBit | bref );
1287} 1287}
1288#endif 1288#endif
1289 1289
1290/* 1290/*
1291 The two following functions add a transition between all pairs of states 1291 The two following functions add a transition between all pairs of states
1292 (i, j) where i is fond in from, and j is found in to. 1292 (i, j) where i is fond in from, and j is found in to.
1293 1293
1294 Cat-transitions are distinguished from plus-transitions for capturing. 1294 Cat-transitions are distinguished from plus-transitions for capturing.
1295*/ 1295*/
1296 1296
1297void QRegExpEngine::addCatTransitions( const QArray<int>& from, 1297void QRegExpEngine::addCatTransitions( const QArray<int>& from,
1298 const QArray<int>& to ) 1298 const QArray<int>& to )
1299{ 1299{
1300 for ( int i = 0; i < (int) from.size(); i++ ) { 1300 for ( int i = 0; i < (int) from.size(); i++ ) {
1301 State *st = s[from[i]]; 1301 State *st = s[from[i]];
1302 mergeInto( &st->outs, to ); 1302 mergeInto( &st->outs, to );
1303 } 1303 }
1304} 1304}
1305 1305
1306#ifndef QT_NO_REGEXP_CAPTURE 1306#ifndef QT_NO_REGEXP_CAPTURE
1307void QRegExpEngine::addPlusTransitions( const QArray<int>& from, 1307void QRegExpEngine::addPlusTransitions( const QArray<int>& from,
1308 const QArray<int>& to, int atom ) 1308 const QArray<int>& to, int atom )
1309{ 1309{
1310 for ( int i = 0; i < (int) from.size(); i++ ) { 1310 for ( int i = 0; i < (int) from.size(); i++ ) {
1311 State *st = s[from[i]]; 1311 State *st = s[from[i]];
1312 QArray<int> oldOuts = st->outs.copy(); 1312 QArray<int> oldOuts = st->outs.copy();
1313 mergeInto( &st->outs, to ); 1313 mergeInto( &st->outs, to );
1314 if ( f[atom].capture >= 0 ) { 1314 if ( f[atom].capture >= 0 ) {
1315 if ( st->reenter == 0 ) 1315 if ( st->reenter == 0 )
1316 st->reenter = new QMap<int, int>; 1316 st->reenter = new QMap<int, int>;
1317 for ( int j = 0; j < (int) to.size(); j++ ) { 1317 for ( int j = 0; j < (int) to.size(); j++ ) {
1318 if ( !st->reenter->contains(to[j]) && 1318 if ( !st->reenter->contains(to[j]) &&
1319 oldOuts.bsearch(to[j]) < 0 ) 1319 oldOuts.bsearch(to[j]) < 0 )
1320 st->reenter->insert( to[j], atom ); 1320 st->reenter->insert( to[j], atom );
1321 } 1321 }
1322 } 1322 }
1323 } 1323 }
1324} 1324}
1325#endif 1325#endif
1326 1326
1327#ifndef QT_NO_REGEXP_ANCHOR_ALT 1327#ifndef QT_NO_REGEXP_ANCHOR_ALT
1328/* 1328/*
1329 Returns an anchor that means a OR b. 1329 Returns an anchor that means a OR b.
1330*/ 1330*/
1331int QRegExpEngine::anchorAlternation( int a, int b ) 1331int QRegExpEngine::anchorAlternation( int a, int b )
1332{ 1332{
1333 if ( ((a & b) == a || (a & b) == b) && ((a | b) & Anchor_Alternation) == 0 ) 1333 if ( ((a & b) == a || (a & b) == b) && ((a | b) & Anchor_Alternation) == 0 )
1334 return a & b; 1334 return a & b;
1335 1335
1336 int n = aa.size(); 1336 int n = aa.size();
1337 aa.resize( n + 1 ); 1337 aa.resize( n + 1 );
1338 aa[n].a = a; 1338 aa[n].a = a;
1339 aa[n].b = b; 1339 aa[n].b = b;
1340 return Anchor_Alternation | n; 1340 return Anchor_Alternation | n;
1341} 1341}
1342 1342
1343/* 1343/*
1344 Returns an anchor that means a AND b. 1344 Returns an anchor that means a AND b.
1345*/ 1345*/
1346int QRegExpEngine::anchorConcatenation( int a, int b ) 1346int QRegExpEngine::anchorConcatenation( int a, int b )
1347{ 1347{
1348 if ( ((a | b) & Anchor_Alternation) == 0 ) 1348 if ( ((a | b) & Anchor_Alternation) == 0 )
1349 return a | b; 1349 return a | b;
1350 if ( (b & Anchor_Alternation) != 0 ) 1350 if ( (b & Anchor_Alternation) != 0 )
1351 qSwap( a, b ); 1351 qSwap( a, b );
1352 int aprime = anchorConcatenation( aa[a ^ Anchor_Alternation].a, b ); 1352 int aprime = anchorConcatenation( aa[a ^ Anchor_Alternation].a, b );
1353 int bprime = anchorConcatenation( aa[a ^ Anchor_Alternation].b, b ); 1353 int bprime = anchorConcatenation( aa[a ^ Anchor_Alternation].b, b );
1354 return anchorAlternation( aprime, bprime ); 1354 return anchorAlternation( aprime, bprime );
1355} 1355}
1356#endif 1356#endif
1357 1357
1358/* 1358/*
1359 Adds anchor a on a transition caracterised by its from state and its to state. 1359 Adds anchor a on a transition caracterised by its from state and its to state.
1360*/ 1360*/
1361void QRegExpEngine::addAnchors( int from, int to, int a ) 1361void QRegExpEngine::addAnchors( int from, int to, int a )
1362{ 1362{
1363 State *st = s[from]; 1363 State *st = s[from];
1364 if ( st->anchors == 0 ) 1364 if ( st->anchors == 0 )
1365 st->anchors = new QMap<int, int>; 1365 st->anchors = new QMap<int, int>;
1366 if ( st->anchors->contains(to) ) 1366 if ( st->anchors->contains(to) )
1367 a = anchorAlternation( (*st->anchors)[to], a ); 1367 a = anchorAlternation( (*st->anchors)[to], a );
1368 st->anchors->insert( to, a ); 1368 st->anchors->insert( to, a );
1369} 1369}
1370 1370
1371#ifndef QT_NO_REGEXP_OPTIM 1371#ifndef QT_NO_REGEXP_OPTIM
1372/* 1372/*
1373 The two following functions provide the engine with the information needed by 1373 The two following functions provide the engine with the information needed by
1374 its matching heuristics. 1374 its matching heuristics.
1375*/ 1375*/
1376 1376
1377void QRegExpEngine::setupGoodStringHeuristic( int earlyStart, int lateStart, 1377void QRegExpEngine::setupGoodStringHeuristic( int earlyStart, int lateStart,
1378 const QString& str ) 1378 const QString& str )
1379{ 1379{
1380 goodEarlyStart = earlyStart; 1380 goodEarlyStart = earlyStart;
1381 goodLateStart = lateStart; 1381 goodLateStart = lateStart;
1382 goodStr = cs ? str : str.lower(); 1382 goodStr = cs ? str : str.lower();
1383} 1383}
1384 1384
1385void QRegExpEngine::setupBadCharHeuristic( int minLen, 1385void QRegExpEngine::setupBadCharHeuristic( int minLen,
1386 const QArray<int>& firstOcc ) 1386 const QArray<int>& firstOcc )
1387{ 1387{
1388 minl = minLen; 1388 minl = minLen;
1389 occ1 = cs ? firstOcc : *firstOccurrenceAtZero; 1389 occ1 = cs ? firstOcc : *firstOccurrenceAtZero;
1390} 1390}
1391 1391
1392/* 1392/*
1393 This function chooses between the good-string and the bad-character 1393 This function chooses between the good-string and the bad-character
1394 heuristics. It computes two scores and chooses the heuristic with the highest 1394 heuristics. It computes two scores and chooses the heuristic with the highest
1395 score. 1395 score.
1396 1396
1397 Here are some common-sense constraints on the scores that should be respected 1397 Here are some common-sense constraints on the scores that should be respected
1398 if the formulas are ever modified: (1) If goodStr is empty, the good-string 1398 if the formulas are ever modified: (1) If goodStr is empty, the good-string
1399 heuristic scores 0. (2) If the search is case insensitive, the good-string 1399 heuristic scores 0. (2) If the search is case insensitive, the good-string
1400 heuristic should be used, unless it scores 0. (Case insensitivity 1400 heuristic should be used, unless it scores 0. (Case insensitivity
1401 turns all entries of occ1 to 0.) (3) If (goodLateStart - goodEarlyStart) is 1401 turns all entries of occ1 to 0.) (3) If (goodLateStart - goodEarlyStart) is
1402 big, the good-string heuristic should score less. 1402 big, the good-string heuristic should score less.
1403*/ 1403*/
1404void QRegExpEngine::heuristicallyChooseHeuristic() 1404void QRegExpEngine::heuristicallyChooseHeuristic()
1405{ 1405{
1406 int i; 1406 int i;
1407 1407
1408 if ( minl == 0 ) 1408 if ( minl == 0 )
1409 return; 1409 return;
1410 1410
1411 /* 1411 /*
1412 Magic formula: The good string has to constitute a good proportion of the 1412 Magic formula: The good string has to constitute a good proportion of the
1413 minimum-length string, and appear at a more-or-less known index. 1413 minimum-length string, and appear at a more-or-less known index.
1414 */ 1414 */
1415 int goodStringScore = ( 64 * goodStr.length() / minl ) - 1415 int goodStringScore = ( 64 * goodStr.length() / minl ) -
1416 ( goodLateStart - goodEarlyStart ); 1416 ( goodLateStart - goodEarlyStart );
1417 1417
1418 /* 1418 /*
1419 Less magic formula: We pick a couple of characters at random, and check 1419 Less magic formula: We pick a couple of characters at random, and check
1420 whether they are good or bad. 1420 whether they are good or bad.
1421 */ 1421 */
1422 int badCharScore = 0; 1422 int badCharScore = 0;
1423 int step = QMAX( 1, NumBadChars / 32 ); 1423 int step = QMAX( 1, NumBadChars / 32 );
1424 for ( i = 1; i < NumBadChars; i += step ) { 1424 for ( i = 1; i < NumBadChars; i += step ) {
1425 if ( occ1[i] == NoOccurrence ) 1425 if ( occ1[i] == NoOccurrence )
1426 badCharScore += minl; 1426 badCharScore += minl;
1427 else 1427 else
1428 badCharScore += occ1[i]; 1428 badCharScore += occ1[i];
1429 } 1429 }
1430 badCharScore /= minl; 1430 badCharScore /= minl;
1431 1431
1432 useGoodStringHeuristic = ( goodStringScore > badCharScore ); 1432 useGoodStringHeuristic = ( goodStringScore > badCharScore );
1433} 1433}
1434#endif 1434#endif
1435 1435
1436#if defined(QT_DEBUG) 1436#if defined(QT_DEBUG)
1437void QRegExpEngine::dump() const 1437void QRegExpEngine::dump() const
1438{ 1438{
1439 int i, j; 1439 int i, j;
1440 odebug << "Case " << (cs ? "" : "in") << "sensitive engine" << oendl; 1440 odebug << "Case " << (cs ? "" : "in") << "sensitive engine" << oendl;
1441 odebug << " States" << oendl; 1441 odebug << " States" << oendl;
1442 for ( i = 0; i < ns; i++ ) { 1442 for ( i = 0; i < ns; i++ ) {
1443 odebug << " " << i 1443 odebug << " " << i
1444 << (i == InitialState ? " (initial)" : i == FinalState ? " (final)" : "") << oendl; 1444 << (i == InitialState ? " (initial)" : i == FinalState ? " (final)" : "") << oendl;
1445 1445
1446#ifndef QT_NO_REGEXP_CAPTURE 1446#ifndef QT_NO_REGEXP_CAPTURE
1447 odebug << " in atom " << s[i]->atom << oendl; 1447 odebug << " in atom " << s[i]->atom << oendl;
1448#endif 1448#endif
1449 int m = s[i]->match; 1449 int m = s[i]->match;
1450 if ( (m & CharClassBit) != 0 ) { 1450 if ( (m & CharClassBit) != 0 ) {
1451 odebug << " match character class " << (m ^ CharClassBit) << oendl; 1451 odebug << " match character class " << (m ^ CharClassBit) << oendl;
1452#ifndef QT_NO_REGEXP_CCLASS 1452#ifndef QT_NO_REGEXP_CCLASS
1453 cl[m ^ CharClassBit]->dump(); 1453 cl[m ^ CharClassBit]->dump();
1454#else 1454#else
1455 odebug << " negative character class" << oendl; 1455 odebug << " negative character class" << oendl;
1456#endif 1456#endif
1457 } else if ( (m & BackRefBit) != 0 ) { 1457 } else if ( (m & BackRefBit) != 0 ) {
1458 odebug << " match back-reference " << (m ^ BackRefBit) << oendl; 1458 odebug << " match back-reference " << (m ^ BackRefBit) << oendl;
1459 } else if ( m >= 0x20 && m <= 0x7e ) { 1459 } else if ( m >= 0x20 && m <= 0x7e ) {
1460 odebug << " match " << QString().sprintf( "0x%.4x", m) << " (" << m << ")" << oendl; 1460 odebug << " match " << QString().sprintf( "0x%.4x", m) << " (" << m << ")" << oendl;
1461 1461
1462 } else { 1462 } else {
1463 odebug << " match " << QString().sprintf( "0x%.4x", m) << oendl; 1463 odebug << " match " << QString().sprintf( "0x%.4x", m) << oendl;
1464 } 1464 }
1465 for ( j = 0; j < (int) s[i]->outs.size(); j++ ) { 1465 for ( j = 0; j < (int) s[i]->outs.size(); j++ ) {
1466 int next = s[i]->outs[j]; 1466 int next = s[i]->outs[j];
1467 odebug << " -> " << next << oendl; 1467 odebug << " -> " << next << oendl;
1468 if ( s[i]->reenter != 0 && s[i]->reenter->contains(next) ) 1468 if ( s[i]->reenter != 0 && s[i]->reenter->contains(next) )
1469 odebug << " [reenter " << (*s[i]->reenter)[next] << "]" << oendl; 1469 odebug << " [reenter " << (*s[i]->reenter)[next] << "]" << oendl;
1470 if ( s[i]->anchors != 0 && at(*s[i]->anchors, next) != 0 ) 1470 if ( s[i]->anchors != 0 && at(*s[i]->anchors, next) != 0 )
1471 odebug << " [anchors " << QString().sprintf( "0x%.8x]", (*s[i]->anchors)[next] ) << oendl; 1471 odebug << " [anchors " << QString().sprintf( "0x%.8x]", (*s[i]->anchors)[next] ) << oendl;
1472 } 1472 }
1473 } 1473 }
1474#ifndef QT_NO_REGEXP_CAPTURE 1474#ifndef QT_NO_REGEXP_CAPTURE
1475 if ( nf > 0 ) { 1475 if ( nf > 0 ) {
1476 odebug << " Atom Parent Capture" << oendl; 1476 odebug << " Atom Parent Capture" << oendl;
1477 for ( i = 0; i < nf; i++ ) 1477 for ( i = 0; i < nf; i++ )
1478 odebug << QString().sprintf(" %6d %6d %6d", i, f[i].parent, f[i].capture ) << oendl; 1478 odebug << QString().sprintf(" %6d %6d %6d", i, f[i].parent, f[i].capture ) << oendl;
1479 } 1479 }
1480#endif 1480#endif
1481#ifndef QT_NO_REGEXP_ANCHOR_ALT 1481#ifndef QT_NO_REGEXP_ANCHOR_ALT
1482 for ( i = 0; i < (int) aa.size(); i++ ) 1482 for ( i = 0; i < (int) aa.size(); i++ )
1483 odebug << QString().sprintf(" Anchor alternation 0x%.8x: 0x%.8x 0x%.9x", i, aa[i].a, aa[i].b ) << oendl; 1483 odebug << QString().sprintf(" Anchor alternation 0x%.8x: 0x%.8x 0x%.9x", i, aa[i].a, aa[i].b ) << oendl;
1484#endif 1484#endif
1485} 1485}
1486#endif 1486#endif
1487 1487
1488void QRegExpEngine::setup( bool caseSensitive ) 1488void QRegExpEngine::setup( bool caseSensitive )
1489{ 1489{
1490#ifndef QT_NO_REGEXP_OPTIM 1490#ifndef QT_NO_REGEXP_OPTIM
1491 if ( engCount++ == 0 ) { 1491 if ( engCount++ == 0 ) {
1492 noOccurrences = new QArray<int>( NumBadChars ); 1492 noOccurrences = new QArray<int>( NumBadChars );
1493 firstOccurrenceAtZero = new QArray<int>( NumBadChars ); 1493 firstOccurrenceAtZero = new QArray<int>( NumBadChars );
1494 noOccurrences->fill( NoOccurrence ); 1494 noOccurrences->fill( NoOccurrence );
1495 firstOccurrenceAtZero->fill( 0 ); 1495 firstOccurrenceAtZero->fill( 0 );
1496 } 1496 }
1497#endif 1497#endif
1498 s.setAutoDelete( TRUE ); 1498 s.setAutoDelete( TRUE );
1499 s.resize( 32 ); 1499 s.resize( 32 );
1500 ns = 0; 1500 ns = 0;
1501#ifndef QT_NO_REGEXP_CAPTURE 1501#ifndef QT_NO_REGEXP_CAPTURE
1502 f.resize( 32 ); 1502 f.resize( 32 );
1503 nf = 0; 1503 nf = 0;
1504 cf = -1; 1504 cf = -1;
1505#endif 1505#endif
1506 realncap = 0; 1506 realncap = 0;
1507 ncap = 0; 1507 ncap = 0;
1508#ifndef QT_NO_REGEXP_CCLASS 1508#ifndef QT_NO_REGEXP_CCLASS
1509 cl.setAutoDelete( TRUE ); 1509 cl.setAutoDelete( TRUE );
1510#endif 1510#endif
1511#ifndef QT_NO_REGEXP_LOOKAHEAD 1511#ifndef QT_NO_REGEXP_LOOKAHEAD
1512 ahead.setAutoDelete( TRUE ); 1512 ahead.setAutoDelete( TRUE );
1513#endif 1513#endif
1514#ifndef QT_NO_REGEXP_OPTIM 1514#ifndef QT_NO_REGEXP_OPTIM
1515 caretAnchored = TRUE; 1515 caretAnchored = TRUE;
1516#endif 1516#endif
1517 valid = FALSE; 1517 valid = FALSE;
1518 cs = caseSensitive; 1518 cs = caseSensitive;
1519#ifndef QT_NO_REGEXP_BACKREF 1519#ifndef QT_NO_REGEXP_BACKREF
1520 nbrefs = 0; 1520 nbrefs = 0;
1521#endif 1521#endif
1522#ifndef QT_NO_REGEXP_OPTIM 1522#ifndef QT_NO_REGEXP_OPTIM
1523 useGoodStringHeuristic = FALSE; 1523 useGoodStringHeuristic = FALSE;
1524 minl = 0; 1524 minl = 0;
1525 occ1 = *firstOccurrenceAtZero; 1525 occ1 = *firstOccurrenceAtZero;
1526#endif 1526#endif
1527 mmCapturedNoMatch.fill( -1, 2 ); 1527 mmCapturedNoMatch.fill( -1, 2 );
1528} 1528}
1529 1529
1530int QRegExpEngine::setupState( int match ) 1530int QRegExpEngine::setupState( int match )
1531{ 1531{
1532 if ( (ns & (ns + 1)) == 0 && ns + 1 >= (int) s.size() ) 1532 if ( (ns & (ns + 1)) == 0 && ns + 1 >= (int) s.size() )
1533 s.resize( (ns + 1) << 1 ); 1533 s.resize( (ns + 1) << 1 );
1534#ifndef QT_NO_REGEXP_CAPTURE 1534#ifndef QT_NO_REGEXP_CAPTURE
1535 s.insert( ns, new State(cf, match) ); 1535 s.insert( ns, new State(cf, match) );
1536#else 1536#else
1537 s.insert( ns, new State(match) ); 1537 s.insert( ns, new State(match) );
1538#endif 1538#endif
1539 return ns++; 1539 return ns++;
1540} 1540}
1541 1541
1542#ifndef QT_NO_REGEXP_CAPTURE 1542#ifndef QT_NO_REGEXP_CAPTURE
1543/* 1543/*
1544 Functions startAtom() and finishAtom() should be called to delimit atoms. 1544 Functions startAtom() and finishAtom() should be called to delimit atoms.
1545 When a state is created, it is assigned to the current atom. The information 1545 When a state is created, it is assigned to the current atom. The information
1546 is later used for capturing. 1546 is later used for capturing.
1547*/ 1547*/
1548int QRegExpEngine::startAtom( bool capture ) 1548int QRegExpEngine::startAtom( bool capture )
1549{ 1549{
1550 if ( (nf & (nf + 1)) == 0 && nf + 1 >= (int) f.size() ) 1550 if ( (nf & (nf + 1)) == 0 && nf + 1 >= (int) f.size() )
1551 f.resize( (nf + 1) << 1 ); 1551 f.resize( (nf + 1) << 1 );
1552 f[nf].parent = cf; 1552 f[nf].parent = cf;
1553 cf = nf++; 1553 cf = nf++;
1554 f[cf].capture = capture ? ncap++ : -1; 1554 f[cf].capture = capture ? ncap++ : -1;
1555 return cf; 1555 return cf;
1556} 1556}
1557#endif 1557#endif
1558 1558
1559#ifndef QT_NO_REGEXP_LOOKAHEAD 1559#ifndef QT_NO_REGEXP_LOOKAHEAD
1560/* 1560/*
1561 Creates a lookahead anchor. 1561 Creates a lookahead anchor.
1562*/ 1562*/
1563int QRegExpEngine::addLookahead( QRegExpEngine *eng, bool negative ) 1563int QRegExpEngine::addLookahead( QRegExpEngine *eng, bool negative )
1564{ 1564{
1565 int n = ahead.size(); 1565 int n = ahead.size();
1566 if ( n == MaxLookaheads ) { 1566 if ( n == MaxLookaheads ) {
1567 yyError = TRUE; 1567 yyError = TRUE;
1568 return 0; 1568 return 0;
1569 } 1569 }
1570 ahead.resize( n + 1 ); 1570 ahead.resize( n + 1 );
1571 ahead.insert( n, new Lookahead(eng, negative) ); 1571 ahead.insert( n, new Lookahead(eng, negative) );
1572 return Anchor_FirstLookahead << n; 1572 return Anchor_FirstLookahead << n;
1573} 1573}
1574#endif 1574#endif
1575 1575
1576#ifndef QT_NO_REGEXP_CAPTURE 1576#ifndef QT_NO_REGEXP_CAPTURE
1577/* 1577/*
1578 We want the longest leftmost captures. 1578 We want the longest leftmost captures.
1579*/ 1579*/
1580bool QRegExpEngine::isBetterCapture( const int *begin1, const int *end1, 1580bool QRegExpEngine::isBetterCapture( const int *begin1, const int *end1,
1581 const int *begin2, const int *end2 ) 1581 const int *begin2, const int *end2 )
1582{ 1582{
1583 for ( int i = 0; i < ncap; i++ ) { 1583 for ( int i = 0; i < ncap; i++ ) {
1584 int delta = begin2[i] - begin1[i]; // it has to start early... 1584 int delta = begin2[i] - begin1[i]; // it has to start early...
1585 if ( delta == 0 ) 1585 if ( delta == 0 )
1586 delta = end1[i] - end2[i]; // ...and end late (like a party) 1586 delta = end1[i] - end2[i]; // ...and end late (like a party)
1587 1587
1588 if ( delta != 0 ) 1588 if ( delta != 0 )
1589 return delta > 0; 1589 return delta > 0;
1590 } 1590 }
1591 return FALSE; 1591 return FALSE;
1592} 1592}
1593#endif 1593#endif
1594 1594
1595/* 1595/*
1596 Returns TRUE if anchor a matches at position mmPos + i in the input string, 1596 Returns TRUE if anchor a matches at position mmPos + i in the input string,
1597 otherwise FALSE. 1597 otherwise FALSE.
1598*/ 1598*/
1599bool QRegExpEngine::testAnchor( int i, int a, const int *capBegin ) 1599bool QRegExpEngine::testAnchor( int i, int a, const int *capBegin )
1600{ 1600{
1601 int j; 1601 int j;
1602 1602
1603#ifndef QT_NO_REGEXP_ANCHOR_ALT 1603#ifndef QT_NO_REGEXP_ANCHOR_ALT
1604 if ( (a & Anchor_Alternation) != 0 ) { 1604 if ( (a & Anchor_Alternation) != 0 ) {
1605 return testAnchor( i, aa[a ^ Anchor_Alternation].a, capBegin ) || 1605 return testAnchor( i, aa[a ^ Anchor_Alternation].a, capBegin ) ||
1606 testAnchor( i, aa[a ^ Anchor_Alternation].b, capBegin ); 1606 testAnchor( i, aa[a ^ Anchor_Alternation].b, capBegin );
1607 } 1607 }
1608#endif 1608#endif
1609 1609
1610 if ( (a & Anchor_Caret) != 0 ) { 1610 if ( (a & Anchor_Caret) != 0 ) {
1611 if ( mmPos + i != 0 ) 1611 if ( mmPos + i != 0 )
1612 return FALSE; 1612 return FALSE;
1613 } 1613 }
1614 if ( (a & Anchor_Dollar) != 0 ) { 1614 if ( (a & Anchor_Dollar) != 0 ) {
1615 if ( mmPos + i != mmLen ) 1615 if ( mmPos + i != mmLen )
1616 return FALSE; 1616 return FALSE;
1617 } 1617 }
1618#ifndef QT_NO_REGEXP_ESCAPE 1618#ifndef QT_NO_REGEXP_ESCAPE
1619 if ( (a & (Anchor_Word | Anchor_NonWord)) != 0 ) { 1619 if ( (a & (Anchor_Word | Anchor_NonWord)) != 0 ) {
1620 bool before = FALSE, after = FALSE; 1620 bool before = FALSE, after = FALSE;
1621 if ( mmPos + i != 0 ) 1621 if ( mmPos + i != 0 )
1622 before = mmIn[mmPos + i - 1].isLetterOrNumber(); 1622 before = mmIn[mmPos + i - 1].isLetterOrNumber();
1623 if ( mmPos + i != mmLen ) 1623 if ( mmPos + i != mmLen )
1624 after = mmIn[mmPos + i].isLetterOrNumber(); 1624 after = mmIn[mmPos + i].isLetterOrNumber();
1625 if ( (a & Anchor_Word) != 0 && (before == after) ) 1625 if ( (a & Anchor_Word) != 0 && (before == after) )
1626 return FALSE; 1626 return FALSE;
1627 if ( (a & Anchor_NonWord) != 0 && (before != after) ) 1627 if ( (a & Anchor_NonWord) != 0 && (before != after) )
1628 return FALSE; 1628 return FALSE;
1629 } 1629 }
1630#endif 1630#endif
1631#ifndef QT_NO_REGEXP_LOOKAHEAD 1631#ifndef QT_NO_REGEXP_LOOKAHEAD
1632 bool catchx = TRUE; 1632 bool catchx = TRUE;
1633 1633
1634 if ( (a & Anchor_LookaheadMask) != 0 ) { 1634 if ( (a & Anchor_LookaheadMask) != 0 ) {
1635 QConstString cstr = QConstString( (QChar *) mmIn + mmPos + i, 1635 QConstString cstr = QConstString( (QChar *) mmIn + mmPos + i,
1636 mmLen - mmPos - i ); 1636 mmLen - mmPos - i );
1637 for ( j = 0; j < (int) ahead.size(); j++ ) { 1637 for ( j = 0; j < (int) ahead.size(); j++ ) {
1638 if ( (a & (Anchor_FirstLookahead << j)) != 0 ) { 1638 if ( (a & (Anchor_FirstLookahead << j)) != 0 ) {
1639 catchx = ( ahead[j]->eng->match(cstr.string(), 0, TRUE, 1639 catchx = ( ahead[j]->eng->match(cstr.string(), 0, TRUE,
1640 TRUE)[0] == 0 ); 1640 TRUE)[0] == 0 );
1641 if ( catchx == ahead[j]->neg ) 1641 if ( catchx == ahead[j]->neg )
1642 return FALSE; 1642 return FALSE;
1643 } 1643 }
1644 } 1644 }
1645 } 1645 }
1646#endif 1646#endif
1647#ifndef QT_NO_REGEXP_CAPTURE 1647#ifndef QT_NO_REGEXP_CAPTURE
1648#ifndef QT_NO_REGEXP_BACKREF 1648#ifndef QT_NO_REGEXP_BACKREF
1649 for ( j = 0; j < nbrefs; j++ ) { 1649 for ( j = 0; j < nbrefs; j++ ) {
1650 if ( (a & (Anchor_BackRef1Empty << j)) != 0 ) { 1650 if ( (a & (Anchor_BackRef1Empty << j)) != 0 ) {
1651 if ( capBegin[j] != EmptyCapture ) 1651 if ( capBegin[j] != EmptyCapture )
1652 return FALSE; 1652 return FALSE;
1653 } 1653 }
1654 } 1654 }
1655#endif 1655#endif
1656#endif 1656#endif
1657 return TRUE; 1657 return TRUE;
1658} 1658}
1659 1659
1660#ifndef QT_NO_REGEXP_OPTIM 1660#ifndef QT_NO_REGEXP_OPTIM
1661/* 1661/*
1662 The three following functions are what Jeffrey Friedl would call transmissions 1662 The three following functions are what Jeffrey Friedl would call transmissions
1663 (or bump-alongs). Using one or the other should make no difference, except 1663 (or bump-alongs). Using one or the other should make no difference, except
1664 in performance. 1664 in performance.
1665*/ 1665*/
1666 1666
1667bool QRegExpEngine::goodStringMatch() 1667bool QRegExpEngine::goodStringMatch()
1668{ 1668{
1669 int k = mmPos + goodEarlyStart; 1669 int k = mmPos + goodEarlyStart;
1670 1670
1671 while ( (k = mmStr->find(goodStr, k, cs)) != -1 ) { 1671 while ( (k = mmStr->find(goodStr, k, cs)) != -1 ) {
1672 int from = k - goodLateStart; 1672 int from = k - goodLateStart;
1673 int to = k - goodEarlyStart; 1673 int to = k - goodEarlyStart;
1674 if ( from > mmPos ) 1674 if ( from > mmPos )
1675 mmPos = from; 1675 mmPos = from;
1676 1676
1677 while ( mmPos <= to ) { 1677 while ( mmPos <= to ) {
1678 if ( matchHere() ) 1678 if ( matchHere() )
1679 return TRUE; 1679 return TRUE;
1680 mmPos++; 1680 mmPos++;
1681 } 1681 }
1682 k++; 1682 k++;
1683 } 1683 }
1684 return FALSE; 1684 return FALSE;
1685} 1685}
1686 1686
1687bool QRegExpEngine::badCharMatch() 1687bool QRegExpEngine::badCharMatch()
1688{ 1688{
1689 int slideHead = 0; 1689 int slideHead = 0;
1690 int slideNext = 0; 1690 int slideNext = 0;
1691 int i; 1691 int i;
1692 int lastPos = mmLen - minl; 1692 int lastPos = mmLen - minl;
1693 memset( mmSlideTab, 0, mmSlideTabSize * sizeof(int) ); 1693 memset( mmSlideTab, 0, mmSlideTabSize * sizeof(int) );
1694 1694
1695 /* 1695 /*
1696 Set up the slide table, used for the bad-character heuristic, using 1696 Set up the slide table, used for the bad-character heuristic, using
1697 the table of first occurrence of each character. 1697 the table of first occurrence of each character.
1698 */ 1698 */
1699 for ( i = 0; i < minl; i++ ) { 1699 for ( i = 0; i < minl; i++ ) {
1700 int sk = occ1[BadChar(mmIn[mmPos + i])]; 1700 int sk = occ1[BadChar(mmIn[mmPos + i])];
1701 if ( sk == NoOccurrence ) 1701 if ( sk == NoOccurrence )
1702 sk = i + 1; 1702 sk = i + 1;
1703 if ( sk > 0 ) { 1703 if ( sk > 0 ) {
1704 int k = i + 1 - sk; 1704 int k = i + 1 - sk;
1705 if ( k < 0 ) { 1705 if ( k < 0 ) {
1706 sk = i + 1; 1706 sk = i + 1;
1707 k = 0; 1707 k = 0;
1708 } 1708 }
1709 if ( sk > mmSlideTab[k] ) 1709 if ( sk > mmSlideTab[k] )
1710 mmSlideTab[k] = sk; 1710 mmSlideTab[k] = sk;
1711 } 1711 }
1712 } 1712 }
1713 1713
1714 if ( mmPos > lastPos ) 1714 if ( mmPos > lastPos )
1715 return FALSE; 1715 return FALSE;
1716 1716
1717 while ( TRUE ) { 1717 while ( TRUE ) {
1718 if ( ++slideNext >= mmSlideTabSize ) 1718 if ( ++slideNext >= mmSlideTabSize )
1719 slideNext = 0; 1719 slideNext = 0;
1720 if ( mmSlideTab[slideHead] > 0 ) { 1720 if ( mmSlideTab[slideHead] > 0 ) {
1721 if ( mmSlideTab[slideHead] - 1 > mmSlideTab[slideNext] ) 1721 if ( mmSlideTab[slideHead] - 1 > mmSlideTab[slideNext] )
1722 mmSlideTab[slideNext] = mmSlideTab[slideHead] - 1; 1722 mmSlideTab[slideNext] = mmSlideTab[slideHead] - 1;
1723 mmSlideTab[slideHead] = 0; 1723 mmSlideTab[slideHead] = 0;
1724 } else { 1724 } else {
1725 if ( matchHere() ) 1725 if ( matchHere() )
1726 return TRUE; 1726 return TRUE;
1727 } 1727 }
1728 1728
1729 if ( mmPos == lastPos ) 1729 if ( mmPos == lastPos )
1730 break; 1730 break;
1731 1731
1732 /* 1732 /*
1733 Update the slide table. This code has much in common with the 1733 Update the slide table. This code has much in common with the
1734 initialization code. 1734 initialization code.
1735 */ 1735 */
1736 int sk = occ1[BadChar(mmIn[mmPos + minl])]; 1736 int sk = occ1[BadChar(mmIn[mmPos + minl])];
1737 if ( sk == NoOccurrence ) { 1737 if ( sk == NoOccurrence ) {
1738 mmSlideTab[slideNext] = minl; 1738 mmSlideTab[slideNext] = minl;
1739 } else if ( sk > 0 ) { 1739 } else if ( sk > 0 ) {
1740 int k = slideNext + minl - sk; 1740 int k = slideNext + minl - sk;
1741 if ( k >= mmSlideTabSize ) 1741 if ( k >= mmSlideTabSize )
1742 k -= mmSlideTabSize; 1742 k -= mmSlideTabSize;
1743 if ( sk > mmSlideTab[k] ) 1743 if ( sk > mmSlideTab[k] )
1744 mmSlideTab[k] = sk; 1744 mmSlideTab[k] = sk;
1745 } 1745 }
1746 slideHead = slideNext; 1746 slideHead = slideNext;
1747 mmPos++; 1747 mmPos++;
1748 } 1748 }
1749 return FALSE; 1749 return FALSE;
1750} 1750}
1751#else 1751#else
1752bool QRegExpEngine::bruteMatch() 1752bool QRegExpEngine::bruteMatch()
1753{ 1753{
1754 while ( mmPos <= mmLen ) { 1754 while ( mmPos <= mmLen ) {
1755 if ( matchHere() ) 1755 if ( matchHere() )
1756 return TRUE; 1756 return TRUE;
1757 mmPos++; 1757 mmPos++;
1758 } 1758 }
1759 return FALSE; 1759 return FALSE;
1760} 1760}
1761#endif 1761#endif
1762 1762
1763/* 1763/*
1764 Here's the core of the engine. It tries to do a match here and now. 1764 Here's the core of the engine. It tries to do a match here and now.
1765*/ 1765*/
1766bool QRegExpEngine::matchHere() 1766bool QRegExpEngine::matchHere()
1767{ 1767{
1768 int ncur = 1, nnext = 0; 1768 int ncur = 1, nnext = 0;
1769 int i = 0, j, k, m; 1769 int i = 0, j, k, m;
1770 bool match = FALSE; 1770 bool match = FALSE;
1771 1771
1772 mmMatchedLen = -1; 1772 mmMatchedLen = -1;
1773 mmCurStack[0] = InitialState; 1773 mmCurStack[0] = InitialState;
1774 1774
1775#ifndef QT_NO_REGEXP_CAPTURE 1775#ifndef QT_NO_REGEXP_CAPTURE
1776 if ( ncap > 0 ) { 1776 if ( ncap > 0 ) {
1777 for ( j = 0; j < ncap; j++ ) { 1777 for ( j = 0; j < ncap; j++ ) {
1778 mmCurCapBegin[j] = EmptyCapture; 1778 mmCurCapBegin[j] = EmptyCapture;
1779 mmCurCapEnd[j] = EmptyCapture; 1779 mmCurCapEnd[j] = EmptyCapture;
1780 } 1780 }
1781 } 1781 }
1782#endif 1782#endif
1783 1783
1784#ifndef QT_NO_REGEXP_BACKREF 1784#ifndef QT_NO_REGEXP_BACKREF
1785 int *zzZ = 0; 1785 int *zzZ = 0;
1786 1786
1787 while ( (ncur > 0 || mmSleeping.count() > 0) && i <= mmLen - mmPos && 1787 while ( (ncur > 0 || mmSleeping.count() > 0) && i <= mmLen - mmPos &&
1788 !match ) 1788 !match )
1789#else 1789#else
1790 while ( ncur > 0 && i <= mmLen - mmPos && !match ) 1790 while ( ncur > 0 && i <= mmLen - mmPos && !match )
1791#endif 1791#endif
1792 { 1792 {
1793 int ch = ( i < mmLen - mmPos ) ? mmIn[mmPos + i].unicode() : 0; 1793 int ch = ( i < mmLen - mmPos ) ? mmIn[mmPos + i].unicode() : 0;
1794 for ( j = 0; j < ncur; j++ ) { 1794 for ( j = 0; j < ncur; j++ ) {
1795 int cur = mmCurStack[j]; 1795 int cur = mmCurStack[j];
1796 State *scur = s[cur]; 1796 State *scur = s[cur];
1797 QArray<int>& outs = scur->outs; 1797 QArray<int>& outs = scur->outs;
1798 for ( k = 0; k < (int) outs.size(); k++ ) { 1798 for ( k = 0; k < (int) outs.size(); k++ ) {
1799 int next = outs[k]; 1799 int next = outs[k];
1800 State *snext = s[next]; 1800 State *snext = s[next];
1801 bool in = TRUE; 1801 bool in = TRUE;
1802#ifndef QT_NO_REGEXP_BACKREF 1802#ifndef QT_NO_REGEXP_BACKREF
1803 int needSomeSleep = 0; 1803 int needSomeSleep = 0;
1804#endif 1804#endif
1805 1805
1806 /* 1806 /*
1807 First, check if the anchors are anchored properly. 1807 First, check if the anchors are anchored properly.
1808 */ 1808 */
1809 if ( scur->anchors != 0 ) { 1809 if ( scur->anchors != 0 ) {
1810 int a = at( *scur->anchors, next ); 1810 int a = at( *scur->anchors, next );
1811 if ( a != 0 && !testAnchor(i, a, mmCurCapBegin + j * ncap) ) 1811 if ( a != 0 && !testAnchor(i, a, mmCurCapBegin + j * ncap) )
1812 in = FALSE; 1812 in = FALSE;
1813 } 1813 }
1814 /* 1814 /*
1815 If indeed they are, check if the input character is correct 1815 If indeed they are, check if the input character is correct
1816 for this transition. 1816 for this transition.
1817 */ 1817 */
1818 if ( in ) { 1818 if ( in ) {
1819 m = snext->match; 1819 m = snext->match;
1820 if ( (m & (CharClassBit | BackRefBit)) == 0 ) { 1820 if ( (m & (CharClassBit | BackRefBit)) == 0 ) {
1821 if ( cs ) 1821 if ( cs )
1822 in = ( m == ch ); 1822 in = ( m == ch );
1823 else 1823 else
1824 in = ( QChar(m).lower() == QChar(ch).lower() ); 1824 in = ( QChar(m).lower() == QChar(ch).lower() );
1825 } else if ( next == FinalState ) { 1825 } else if ( next == FinalState ) {
1826 mmMatchedLen = i; 1826 mmMatchedLen = i;
1827 match = mmMinimal; 1827 match = mmMinimal;
1828 in = TRUE; 1828 in = TRUE;
1829 } else if ( (m & CharClassBit) != 0 ) { 1829 } else if ( (m & CharClassBit) != 0 ) {
1830#ifndef QT_NO_REGEXP_CCLASS 1830#ifndef QT_NO_REGEXP_CCLASS
1831 const CharClass *cc = cl[m ^ CharClassBit]; 1831 const CharClass *cc = cl[m ^ CharClassBit];
1832 if ( cs ) 1832 if ( cs )
1833 in = cc->in( ch ); 1833 in = cc->in( ch );
1834 else if ( cc->negative() ) 1834 else if ( cc->negative() )
1835 in = cc->in( QChar(ch).lower() ) && 1835 in = cc->in( QChar(ch).lower() ) &&
1836 cc->in( QChar(ch).upper() ); 1836 cc->in( QChar(ch).upper() );
1837 else 1837 else
1838 in = cc->in( QChar(ch).lower() ) || 1838 in = cc->in( QChar(ch).lower() ) ||
1839 cc->in( QChar(ch).upper() ); 1839 cc->in( QChar(ch).upper() );
1840#endif 1840#endif
1841#ifndef QT_NO_REGEXP_BACKREF 1841#ifndef QT_NO_REGEXP_BACKREF
1842 } else { /* ( (m & BackRefBit) != 0 ) */ 1842 } else { /* ( (m & BackRefBit) != 0 ) */
1843 int bref = m ^ BackRefBit; 1843 int bref = m ^ BackRefBit;
1844 int ell = j * ncap + ( bref - 1 ); 1844 int ell = j * ncap + ( bref - 1 );
1845 1845
1846 in = bref <= ncap && mmCurCapBegin[ell] != EmptyCapture; 1846 in = bref <= ncap && mmCurCapBegin[ell] != EmptyCapture;
1847 if ( in ) { 1847 if ( in ) {
1848 if ( cs ) 1848 if ( cs )
1849 in = ( mmIn[mmPos + mmCurCapBegin[ell]] 1849 in = ( mmIn[mmPos + mmCurCapBegin[ell]]
1850 == QChar(ch) ); 1850 == QChar(ch) );
1851 else 1851 else
1852 in = ( mmIn[mmPos + mmCurCapBegin[ell]].lower() 1852 in = ( mmIn[mmPos + mmCurCapBegin[ell]].lower()
1853 == QChar(ch).lower() ); 1853 == QChar(ch).lower() );
1854 } 1854 }
1855 1855
1856 if ( in ) { 1856 if ( in ) {
1857 int delta; 1857 int delta;
1858 if ( mmCurCapEnd[ell] == EmptyCapture ) 1858 if ( mmCurCapEnd[ell] == EmptyCapture )
1859 delta = i - mmCurCapBegin[ell]; 1859 delta = i - mmCurCapBegin[ell];
1860 else 1860 else
1861 delta = mmCurCapEnd[ell] - mmCurCapBegin[ell]; 1861 delta = mmCurCapEnd[ell] - mmCurCapBegin[ell];
1862 1862
1863 in = ( delta <= mmLen - mmPos ); 1863 in = ( delta <= mmLen - mmPos );
1864 if ( in && delta > 1 ) { 1864 if ( in && delta > 1 ) {
1865 int n; 1865 int n;
1866 if ( cs ) { 1866 if ( cs ) {
1867 for ( n = 1; n < delta; n++ ) { 1867 for ( n = 1; n < delta; n++ ) {
1868 if ( mmIn[mmPos + 1868 if ( mmIn[mmPos +
1869 mmCurCapBegin[ell] + n] != 1869 mmCurCapBegin[ell] + n] !=
1870 mmIn[mmPos + i + n] ) 1870 mmIn[mmPos + i + n] )
1871 break; 1871 break;
1872 } 1872 }
1873 } else { 1873 } else {
1874 for ( n = 1; n < delta; n++ ) { 1874 for ( n = 1; n < delta; n++ ) {
1875 QChar a = mmIn[mmPos + 1875 QChar a = mmIn[mmPos +
1876 mmCurCapBegin[ell] + n]; 1876 mmCurCapBegin[ell] + n];
1877 QChar b = mmIn[mmPos + i + n]; 1877 QChar b = mmIn[mmPos + i + n];
1878 if ( a.lower() != b.lower() ) 1878 if ( a.lower() != b.lower() )
1879 break; 1879 break;
1880 } 1880 }
1881 } 1881 }
1882 in = ( n == delta ); 1882 in = ( n == delta );
1883 if ( in ) 1883 if ( in )
1884 needSomeSleep = delta - 1; 1884 needSomeSleep = delta - 1;
1885 } 1885 }
1886 } 1886 }
1887#endif 1887#endif
1888 } 1888 }
1889 } 1889 }
1890 1890
1891 /* 1891 /*
1892 All is right. We must now update our data structures. 1892 All is right. We must now update our data structures.
1893 */ 1893 */
1894 if ( in ) { 1894 if ( in ) {
1895#ifndef QT_NO_REGEXP_CAPTURE 1895#ifndef QT_NO_REGEXP_CAPTURE
1896 int *capBegin, *capEnd; 1896 int *capBegin, *capEnd;
1897#endif 1897#endif
1898 /* 1898 /*
1899 If the next state was not encountered yet, all is fine. 1899 If the next state was not encountered yet, all is fine.
1900 */ 1900 */
1901 if ( (m = mmInNextStack[next]) == -1 ) { 1901 if ( (m = mmInNextStack[next]) == -1 ) {
1902 m = nnext++; 1902 m = nnext++;
1903 mmNextStack[m] = next; 1903 mmNextStack[m] = next;
1904 mmInNextStack[next] = m; 1904 mmInNextStack[next] = m;
1905#ifndef QT_NO_REGEXP_CAPTURE 1905#ifndef QT_NO_REGEXP_CAPTURE
1906 capBegin = mmNextCapBegin + m * ncap; 1906 capBegin = mmNextCapBegin + m * ncap;
1907 capEnd = mmNextCapEnd + m * ncap; 1907 capEnd = mmNextCapEnd + m * ncap;
1908 1908
1909 /* 1909 /*
1910 Otherwise, we'll first maintain captures in temporary 1910 Otherwise, we'll first maintain captures in temporary
1911 arrays, and decide at the end whether it's best to keep 1911 arrays, and decide at the end whether it's best to keep
1912 the previous capture zones or the new ones. 1912 the previous capture zones or the new ones.
1913 */ 1913 */
1914 } else { 1914 } else {
1915 capBegin = mmTempCapBegin; 1915 capBegin = mmTempCapBegin;
1916 capEnd = mmTempCapEnd; 1916 capEnd = mmTempCapEnd;
1917#endif 1917#endif
1918 } 1918 }
1919 1919
1920#ifndef QT_NO_REGEXP_CAPTURE 1920#ifndef QT_NO_REGEXP_CAPTURE
1921 /* 1921 /*
1922 Updating the capture zones is much of a task. 1922 Updating the capture zones is much of a task.
1923 */ 1923 */
1924 if ( ncap > 0 ) { 1924 if ( ncap > 0 ) {
1925 memcpy( capBegin, mmCurCapBegin + j * ncap, 1925 memcpy( capBegin, mmCurCapBegin + j * ncap,
1926 ncap * sizeof(int) ); 1926 ncap * sizeof(int) );
1927 memcpy( capEnd, mmCurCapEnd + j * ncap, 1927 memcpy( capEnd, mmCurCapEnd + j * ncap,
1928 ncap * sizeof(int) ); 1928 ncap * sizeof(int) );
1929 int c = scur->atom, n = snext->atom; 1929 int c = scur->atom, n = snext->atom;
1930 int p = -1, q = -1; 1930 int p = -1, q = -1;
1931 int cap; 1931 int cap;
1932 1932
1933 /* 1933 /*
1934 Lemma 1. For any x in the range [0..nf), we have 1934 Lemma 1. For any x in the range [0..nf), we have
1935 f[x].parent < x. 1935 f[x].parent < x.
1936 1936
1937 Proof. By looking at startAtom(), it is clear that 1937 Proof. By looking at startAtom(), it is clear that
1938 cf < nf holds all the time, and thus that 1938 cf < nf holds all the time, and thus that
1939 f[nf].parent < nf. 1939 f[nf].parent < nf.
1940 */ 1940 */
1941 1941
1942 /* 1942 /*
1943 If we are reentering an atom, we empty all capture 1943 If we are reentering an atom, we empty all capture
1944 zones inside it. 1944 zones inside it.
1945 */ 1945 */
1946 if ( scur->reenter != 0 && 1946 if ( scur->reenter != 0 &&
1947 (q = at(*scur->reenter, next)) != 0 ) { 1947 (q = at(*scur->reenter, next)) != 0 ) {
1948 QBitArray b; 1948 QBitArray b;
1949 b.fill( FALSE, nf ); 1949 b.fill( FALSE, nf );
1950 b.setBit( q, TRUE ); 1950 b.setBit( q, TRUE );
1951 for ( int ell = q + 1; ell < nf; ell++ ) { 1951 for ( int ell = q + 1; ell < nf; ell++ ) {
1952 if ( b.testBit(f[ell].parent) ) { 1952 if ( b.testBit(f[ell].parent) ) {
1953 b.setBit( ell, TRUE ); 1953 b.setBit( ell, TRUE );
1954 cap = f[ell].capture; 1954 cap = f[ell].capture;
1955 if ( cap >= 0 ) { 1955 if ( cap >= 0 ) {
1956 capBegin[cap] = EmptyCapture; 1956 capBegin[cap] = EmptyCapture;
1957 capEnd[cap] = EmptyCapture; 1957 capEnd[cap] = EmptyCapture;
1958 } 1958 }
1959 } 1959 }
1960 } 1960 }
1961 p = f[q].parent; 1961 p = f[q].parent;
1962 1962
1963 /* 1963 /*
1964 Otherwise, close the capture zones we are leaving. 1964 Otherwise, close the capture zones we are leaving.
1965 We are leaving f[c].capture, f[f[c].parent].capture, 1965 We are leaving f[c].capture, f[f[c].parent].capture,
1966 f[f[f[c].parent].parent].capture, ..., until 1966 f[f[f[c].parent].parent].capture, ..., until
1967 f[x].capture, with x such that f[x].parent is the 1967 f[x].capture, with x such that f[x].parent is the
1968 youngest common ancestor for c and n. 1968 youngest common ancestor for c and n.
1969 1969
1970 We go up along c's and n's ancestry until we find x. 1970 We go up along c's and n's ancestry until we find x.
1971 */ 1971 */
1972 } else { 1972 } else {
1973 p = c; 1973 p = c;
1974 q = n; 1974 q = n;
1975 while ( p != q ) { 1975 while ( p != q ) {
1976 if ( p > q ) { 1976 if ( p > q ) {
1977 cap = f[p].capture; 1977 cap = f[p].capture;
1978 if ( cap >= 0 ) { 1978 if ( cap >= 0 ) {
1979 if ( capBegin[cap] == i ) { 1979 if ( capBegin[cap] == i ) {
1980 capBegin[cap] = EmptyCapture; 1980 capBegin[cap] = EmptyCapture;
1981 capEnd[cap] = EmptyCapture; 1981 capEnd[cap] = EmptyCapture;
1982 } else { 1982 } else {
1983 capEnd[cap] = i; 1983 capEnd[cap] = i;
1984 } 1984 }
1985 } 1985 }
1986 p = f[p].parent; 1986 p = f[p].parent;
1987 } else { 1987 } else {
1988 q = f[q].parent; 1988 q = f[q].parent;
1989 } 1989 }
1990 } 1990 }
1991 } 1991 }
1992 1992
1993 /* 1993 /*
1994 In any case, we now open the capture zones we are 1994 In any case, we now open the capture zones we are
1995 entering. We work upwards from n until we reach p 1995 entering. We work upwards from n until we reach p
1996 (the parent of the atom we reenter or the youngest 1996 (the parent of the atom we reenter or the youngest
1997 common ancestor). 1997 common ancestor).
1998 */ 1998 */
1999 while ( n > p ) { 1999 while ( n > p ) {
2000 cap = f[n].capture; 2000 cap = f[n].capture;
2001 if ( cap >= 0 ) { 2001 if ( cap >= 0 ) {
2002 capBegin[cap] = i; 2002 capBegin[cap] = i;
2003 capEnd[cap] = EmptyCapture; 2003 capEnd[cap] = EmptyCapture;
2004 } 2004 }
2005 n = f[n].parent; 2005 n = f[n].parent;
2006 } 2006 }
2007 /* 2007 /*
2008 If the next state was already in mmNextStack, we must 2008 If the next state was already in mmNextStack, we must
2009 choose carefully which capture zones we want to keep. 2009 choose carefully which capture zones we want to keep.
2010 */ 2010 */
2011 if ( capBegin == mmTempCapBegin && 2011 if ( capBegin == mmTempCapBegin &&
2012 isBetterCapture(capBegin, capEnd, 2012 isBetterCapture(capBegin, capEnd,
2013 mmNextCapBegin + m * ncap, 2013 mmNextCapBegin + m * ncap,
2014 mmNextCapEnd + m * ncap) ) { 2014 mmNextCapEnd + m * ncap) ) {
2015 memcpy( mmNextCapBegin + m * ncap, capBegin, 2015 memcpy( mmNextCapBegin + m * ncap, capBegin,
2016 ncap * sizeof(int) ); 2016 ncap * sizeof(int) );
2017 memcpy( mmNextCapEnd + m * ncap, capEnd, 2017 memcpy( mmNextCapEnd + m * ncap, capEnd,
2018 ncap * sizeof(int) ); 2018 ncap * sizeof(int) );
2019 } 2019 }
2020 } 2020 }
2021#ifndef QT_NO_REGEXP_BACKREF 2021#ifndef QT_NO_REGEXP_BACKREF
2022 /* 2022 /*
2023 We are done with updating the capture zones. It's now 2023 We are done with updating the capture zones. It's now
2024 time to put the next state to sleep, if it needs to, and 2024 time to put the next state to sleep, if it needs to, and
2025 to remove it from mmNextStack. 2025 to remove it from mmNextStack.
2026 */ 2026 */
2027 if ( needSomeSleep > 0 ) { 2027 if ( needSomeSleep > 0 ) {
2028 zzZ = new int[1 + 2 * ncap]; 2028 zzZ = new int[1 + 2 * ncap];
2029 zzZ[0] = next; 2029 zzZ[0] = next;
2030 if ( ncap > 0 ) { 2030 if ( ncap > 0 ) {
2031 memcpy( zzZ + 1, capBegin, ncap * sizeof(int) ); 2031 memcpy( zzZ + 1, capBegin, ncap * sizeof(int) );
2032 memcpy( zzZ + 1 + ncap, capEnd, 2032 memcpy( zzZ + 1 + ncap, capEnd,
2033 ncap * sizeof(int) ); 2033 ncap * sizeof(int) );
2034 } 2034 }
2035 mmInNextStack[mmNextStack[--nnext]] = -1; 2035 mmInNextStack[mmNextStack[--nnext]] = -1;
2036 mmSleeping.insert( i + needSomeSleep, zzZ ); 2036 mmSleeping.insert( i + needSomeSleep, zzZ );
2037 } 2037 }
2038#endif 2038#endif
2039#endif 2039#endif
2040 } 2040 }
2041 } 2041 }
2042 } 2042 }
2043#ifndef QT_NO_REGEXP_CAPTURE 2043#ifndef QT_NO_REGEXP_CAPTURE
2044 /* 2044 /*
2045 If we reached the final state, hurray! Copy the captured zone. 2045 If we reached the final state, hurray! Copy the captured zone.
2046 */ 2046 */
2047 if ( ncap > 0 && (m = mmInNextStack[FinalState]) != -1 ) { 2047 if ( ncap > 0 && (m = mmInNextStack[FinalState]) != -1 ) {
2048 memcpy( mmCapBegin, mmNextCapBegin + m * ncap, ncap * sizeof(int) ); 2048 memcpy( mmCapBegin, mmNextCapBegin + m * ncap, ncap * sizeof(int) );
2049 memcpy( mmCapEnd, mmNextCapEnd + m * ncap, ncap * sizeof(int) ); 2049 memcpy( mmCapEnd, mmNextCapEnd + m * ncap, ncap * sizeof(int) );
2050 } 2050 }
2051#ifndef QT_NO_REGEXP_BACKREF 2051#ifndef QT_NO_REGEXP_BACKREF
2052 /* 2052 /*
2053 It's time to wake up the sleepers. 2053 It's time to wake up the sleepers.
2054 */ 2054 */
2055 if ( mmSleeping.count() > 0 ) { 2055 if ( mmSleeping.count() > 0 ) {
2056 while ( (zzZ = mmSleeping.take(i)) != 0 ) { 2056 while ( (zzZ = mmSleeping.take(i)) != 0 ) {
2057 int next = zzZ[0]; 2057 int next = zzZ[0];
2058 int *capBegin = zzZ + 1; 2058 int *capBegin = zzZ + 1;
2059 int *capEnd = zzZ + 1 + ncap; 2059 int *capEnd = zzZ + 1 + ncap;
2060 bool copyOver = TRUE; 2060 bool copyOver = TRUE;
2061 2061
2062 if ( (m = mmInNextStack[zzZ[0]]) == -1 ) { 2062 if ( (m = mmInNextStack[zzZ[0]]) == -1 ) {
2063 m = nnext++; 2063 m = nnext++;
2064 mmNextStack[m] = next; 2064 mmNextStack[m] = next;
2065 mmInNextStack[next] = m; 2065 mmInNextStack[next] = m;
2066 } else { 2066 } else {
2067 copyOver = isBetterCapture( mmNextCapBegin + m * ncap, 2067 copyOver = isBetterCapture( mmNextCapBegin + m * ncap,
2068 mmNextCapEnd + m * ncap, 2068 mmNextCapEnd + m * ncap,
2069 capBegin, capEnd ); 2069 capBegin, capEnd );
2070 } 2070 }
2071 if ( copyOver ) { 2071 if ( copyOver ) {
2072 memcpy( mmNextCapBegin + m * ncap, capBegin, 2072 memcpy( mmNextCapBegin + m * ncap, capBegin,
2073 ncap * sizeof(int) ); 2073 ncap * sizeof(int) );
2074 memcpy( mmNextCapEnd + m * ncap, capEnd, 2074 memcpy( mmNextCapEnd + m * ncap, capEnd,
2075 ncap * sizeof(int) ); 2075 ncap * sizeof(int) );
2076 } 2076 }
2077 delete[] zzZ; 2077 delete[] zzZ;
2078 } 2078 }
2079 } 2079 }
2080#endif 2080#endif
2081#endif 2081#endif
2082 for ( j = 0; j < nnext; j++ ) 2082 for ( j = 0; j < nnext; j++ )
2083 mmInNextStack[mmNextStack[j]] = -1; 2083 mmInNextStack[mmNextStack[j]] = -1;
2084 2084
2085 qSwap( mmCurStack, mmNextStack ); 2085 qSwap( mmCurStack, mmNextStack );
2086#ifndef QT_NO_REGEXP_CAPTURE 2086#ifndef QT_NO_REGEXP_CAPTURE
2087 qSwap( mmCurCapBegin, mmNextCapBegin ); 2087 qSwap( mmCurCapBegin, mmNextCapBegin );
2088 qSwap( mmCurCapEnd, mmNextCapEnd ); 2088 qSwap( mmCurCapEnd, mmNextCapEnd );
2089#endif 2089#endif
2090 ncur = nnext; 2090 ncur = nnext;
2091 nnext = 0; 2091 nnext = 0;
2092 i++; 2092 i++;
2093 } 2093 }
2094 2094
2095#ifndef QT_NO_REGEXP_BACKREF 2095#ifndef QT_NO_REGEXP_BACKREF
2096 /* 2096 /*
2097 If minimal matching is enabled, we might have some sleepers left. 2097 If minimal matching is enabled, we might have some sleepers left.
2098 */ 2098 */
2099 while ( !mmSleeping.isEmpty() ) { 2099 while ( !mmSleeping.isEmpty() ) {
2100 zzZ = mmSleeping.take( *QIntDictIterator<int>(mmSleeping) ); 2100 zzZ = mmSleeping.take( *QIntDictIterator<int>(mmSleeping) );
2101 delete[] zzZ; 2101 delete[] zzZ;
2102 } 2102 }
2103#endif 2103#endif
2104 2104
2105 match = ( mmMatchedLen >= 0 ); 2105 match = ( mmMatchedLen >= 0 );
2106 if ( !match ) 2106 if ( !match )
2107 mmMatchedLen = i - 1; 2107 mmMatchedLen = i - 1;
2108 return match; 2108 return match;
2109} 2109}
2110 2110
2111#ifndef QT_NO_REGEXP_CCLASS 2111#ifndef QT_NO_REGEXP_CCLASS
2112 2112
2113QRegExpEngine::CharClass::CharClass() 2113QRegExpEngine::CharClass::CharClass()
2114 : c( 0 ), n( FALSE ) 2114 : c( 0 ), n( FALSE )
2115#ifndef QT_NO_REGEXP_OPTIM 2115#ifndef QT_NO_REGEXP_OPTIM
2116 , occ1( *noOccurrences ) 2116 , occ1( *noOccurrences )
2117#endif 2117#endif
2118{ 2118{
2119} 2119}
2120 2120
2121QRegExpEngine::CharClass& QRegExpEngine::CharClass::operator=( 2121QRegExpEngine::CharClass& QRegExpEngine::CharClass::operator=(
2122 const CharClass& cc ) 2122 const CharClass& cc )
2123{ 2123{
2124 c = cc.c; 2124 c = cc.c;
2125 r = cc.r.copy(); 2125 r = cc.r.copy();
2126 n = cc.n; 2126 n = cc.n;
2127#ifndef QT_NO_REGEXP_OPTIM 2127#ifndef QT_NO_REGEXP_OPTIM
2128 occ1 = cc.occ1; 2128 occ1 = cc.occ1;
2129#endif 2129#endif
2130 return *this; 2130 return *this;
2131} 2131}
2132 2132
2133void QRegExpEngine::CharClass::clear() 2133void QRegExpEngine::CharClass::clear()
2134{ 2134{
2135 c = 0; 2135 c = 0;
2136 r.resize( 0 ); 2136 r.resize( 0 );
2137 n = FALSE; 2137 n = FALSE;
2138} 2138}
2139 2139
2140void QRegExpEngine::CharClass::setNegative( bool negative ) 2140void QRegExpEngine::CharClass::setNegative( bool negative )
2141{ 2141{
2142 n = negative; 2142 n = negative;
2143#ifndef QT_NO_REGEXP_OPTIM 2143#ifndef QT_NO_REGEXP_OPTIM
2144 occ1 = *firstOccurrenceAtZero; 2144 occ1 = *firstOccurrenceAtZero;
2145#endif 2145#endif
2146} 2146}
2147 2147
2148void QRegExpEngine::CharClass::addCategories( int cats ) 2148void QRegExpEngine::CharClass::addCategories( int cats )
2149{ 2149{
2150 c |= cats; 2150 c |= cats;
2151#ifndef QT_NO_REGEXP_OPTIM 2151#ifndef QT_NO_REGEXP_OPTIM
2152 occ1 = *firstOccurrenceAtZero; 2152 occ1 = *firstOccurrenceAtZero;
2153#endif 2153#endif
2154} 2154}
2155 2155
2156void QRegExpEngine::CharClass::addRange( ushort from, ushort to ) 2156void QRegExpEngine::CharClass::addRange( ushort from, ushort to )
2157{ 2157{
2158 if ( from > to ) 2158 if ( from > to )
2159 qSwap( from, to ); 2159 qSwap( from, to );
2160 int n = r.size(); 2160 int n = r.size();
2161 r.resize( n + 1 ); 2161 r.resize( n + 1 );
2162 r[n].from = from; 2162 r[n].from = from;
2163 r[n].to = to; 2163 r[n].to = to;
2164 2164
2165#ifndef QT_NO_REGEXP_OPTIM 2165#ifndef QT_NO_REGEXP_OPTIM
2166 int i; 2166 int i;
2167 2167
2168 if ( to - from < NumBadChars ) { 2168 if ( to - from < NumBadChars ) {
2169 occ1.detach(); 2169 occ1.detach();
2170 if ( from % NumBadChars <= to % NumBadChars ) { 2170 if ( from % NumBadChars <= to % NumBadChars ) {
2171 for ( i = from % NumBadChars; i <= to % NumBadChars; i++ ) 2171 for ( i = from % NumBadChars; i <= to % NumBadChars; i++ )
2172 occ1[i] = 0; 2172 occ1[i] = 0;
2173 } else { 2173 } else {
2174 for ( i = 0; i <= to % NumBadChars; i++ ) 2174 for ( i = 0; i <= to % NumBadChars; i++ )
2175 occ1[i] = 0; 2175 occ1[i] = 0;
2176 for ( i = from % NumBadChars; i < NumBadChars; i++ ) 2176 for ( i = from % NumBadChars; i < NumBadChars; i++ )
2177 occ1[i] = 0; 2177 occ1[i] = 0;
2178 } 2178 }
2179 } else { 2179 } else {
2180 occ1 = *firstOccurrenceAtZero; 2180 occ1 = *firstOccurrenceAtZero;
2181 } 2181 }
2182#endif 2182#endif
2183} 2183}
2184 2184
2185bool QRegExpEngine::CharClass::in( QChar ch ) const 2185bool QRegExpEngine::CharClass::in( QChar ch ) const
2186{ 2186{
2187#ifndef QT_NO_REGEXP_OPTIM 2187#ifndef QT_NO_REGEXP_OPTIM
2188 if ( occ1[BadChar(ch)] == NoOccurrence ) 2188 if ( occ1[BadChar(ch)] == NoOccurrence )
2189 return n; 2189 return n;
2190#endif 2190#endif
2191 2191
2192 if ( c != 0 && (c & (1 << (int) ch.category())) != 0 ) 2192 if ( c != 0 && (c & (1 << (int) ch.category())) != 0 )
2193 return !n; 2193 return !n;
2194 for ( int i = 0; i < (int) r.size(); i++ ) { 2194 for ( int i = 0; i < (int) r.size(); i++ ) {
2195 if ( ch.unicode() >= r[i].from && ch.unicode() <= r[i].to ) 2195 if ( ch.unicode() >= r[i].from && ch.unicode() <= r[i].to )
2196 return !n; 2196 return !n;
2197 } 2197 }
2198 return n; 2198 return n;
2199} 2199}
2200 2200
2201#if defined(QT_DEBUG) 2201#if defined(QT_DEBUG)
2202void QRegExpEngine::CharClass::dump() const 2202void QRegExpEngine::CharClass::dump() const
2203{ 2203{
2204 int i; 2204 int i;
2205 odebug << " " << (n ? "nega" : "posi") << "tive character class" << oendl; 2205 odebug << " " << (n ? "nega" : "posi") << "tive character class" << oendl;
2206#ifndef QT_NO_REGEXP_CCLASS 2206#ifndef QT_NO_REGEXP_CCLASS
2207 if ( c != 0 ) 2207 if ( c != 0 )
2208 odebug << QString().sprintf(" categories 0x%.8x", c ) << oendl; 2208 odebug << QString().sprintf(" categories 0x%.8x", c ) << oendl;
2209#endif 2209#endif
2210 for ( i = 0; i < (int) r.size(); i++ ) 2210 for ( i = 0; i < (int) r.size(); i++ )
2211 odebug << QString().sprintf(" 0x%.4x through 0x%.4x", r[i].from, r[i].to ) << oendl; 2211 odebug << QString().sprintf(" 0x%.4x through 0x%.4x", r[i].from, r[i].to ) << oendl;
2212} 2212}
2213#endif 2213#endif
2214#endif 2214#endif
2215 2215
2216QRegExpEngine::Box::Box( QRegExpEngine *engine ) 2216QRegExpEngine::Box::Box( QRegExpEngine *engine )
2217 : eng( engine ), skipanchors( 0 ) 2217 : eng( engine ), skipanchors( 0 )
2218#ifndef QT_NO_REGEXP_OPTIM 2218#ifndef QT_NO_REGEXP_OPTIM
2219 , earlyStart( 0 ), lateStart( 0 ), maxl( 0 ), occ1( *noOccurrences ) 2219 , earlyStart( 0 ), lateStart( 0 ), maxl( 0 ), occ1( *noOccurrences )
2220#endif 2220#endif
2221{ 2221{
2222 minl = 0; 2222 minl = 0;
2223} 2223}
2224 2224
2225QRegExpEngine::Box& QRegExpEngine::Box::operator=( const Box& b ) 2225QRegExpEngine::Box& QRegExpEngine::Box::operator=( const Box& b )
2226{ 2226{
2227 eng = b.eng; 2227 eng = b.eng;
2228 ls = b.ls; 2228 ls = b.ls;
2229 rs = b.rs; 2229 rs = b.rs;
2230 lanchors = b.lanchors; 2230 lanchors = b.lanchors;
2231 ranchors = b.ranchors; 2231 ranchors = b.ranchors;
2232 skipanchors = b.skipanchors; 2232 skipanchors = b.skipanchors;
2233#ifndef QT_NO_REGEXP_OPTIM 2233#ifndef QT_NO_REGEXP_OPTIM
2234 earlyStart = b.earlyStart; 2234 earlyStart = b.earlyStart;
2235 lateStart = b.lateStart; 2235 lateStart = b.lateStart;
2236 str = b.str; 2236 str = b.str;
2237 leftStr = b.leftStr; 2237 leftStr = b.leftStr;
2238 rightStr = b.rightStr; 2238 rightStr = b.rightStr;
2239 maxl = b.maxl; 2239 maxl = b.maxl;
2240 occ1 = b.occ1; 2240 occ1 = b.occ1;
2241#endif 2241#endif
2242 minl = b.minl; 2242 minl = b.minl;
2243 return *this; 2243 return *this;
2244} 2244}
2245 2245
2246void QRegExpEngine::Box::set( QChar ch ) 2246void QRegExpEngine::Box::set( QChar ch )
2247{ 2247{
2248 ls.resize( 1 ); 2248 ls.resize( 1 );
2249 ls[0] = eng->createState( ch ); 2249 ls[0] = eng->createState( ch );
2250 rs = ls; 2250 rs = ls;
2251 rs.detach(); 2251 rs.detach();
2252#ifndef QT_NO_REGEXP_OPTIM 2252#ifndef QT_NO_REGEXP_OPTIM
2253 str = ch; 2253 str = ch;
2254 leftStr = ch; 2254 leftStr = ch;
2255 rightStr = ch; 2255 rightStr = ch;
2256 maxl = 1; 2256 maxl = 1;
2257 occ1.detach(); 2257 occ1.detach();
2258 occ1[BadChar(ch)] = 0; 2258 occ1[BadChar(ch)] = 0;
2259#endif 2259#endif
2260 minl = 1; 2260 minl = 1;
2261} 2261}
2262 2262
2263void QRegExpEngine::Box::set( const CharClass& cc ) 2263void QRegExpEngine::Box::set( const CharClass& cc )
2264{ 2264{
2265 ls.resize( 1 ); 2265 ls.resize( 1 );
2266 ls[0] = eng->createState( cc ); 2266 ls[0] = eng->createState( cc );
2267 rs = ls; 2267 rs = ls;
2268 rs.detach(); 2268 rs.detach();
2269#ifndef QT_NO_REGEXP_OPTIM 2269#ifndef QT_NO_REGEXP_OPTIM
2270 maxl = 1; 2270 maxl = 1;
2271 occ1 = cc.firstOccurrence(); 2271 occ1 = cc.firstOccurrence();
2272#endif 2272#endif
2273 minl = 1; 2273 minl = 1;
2274} 2274}
2275 2275
2276#ifndef QT_NO_REGEXP_BACKREF 2276#ifndef QT_NO_REGEXP_BACKREF
2277void QRegExpEngine::Box::set( int bref ) 2277void QRegExpEngine::Box::set( int bref )
2278{ 2278{
2279 ls.resize( 1 ); 2279 ls.resize( 1 );
2280 ls[0] = eng->createState( bref ); 2280 ls[0] = eng->createState( bref );
2281 rs = ls; 2281 rs = ls;
2282 rs.detach(); 2282 rs.detach();
2283 if ( bref >= 1 && bref <= MaxBackRefs ) 2283 if ( bref >= 1 && bref <= MaxBackRefs )
2284 skipanchors = Anchor_BackRef0Empty << bref; 2284 skipanchors = Anchor_BackRef0Empty << bref;
2285#ifndef QT_NO_REGEXP_OPTIM 2285#ifndef QT_NO_REGEXP_OPTIM
2286 maxl = InftyLen; 2286 maxl = InftyLen;
2287#endif 2287#endif
2288 minl = 0; 2288 minl = 0;
2289} 2289}
2290#endif 2290#endif
2291 2291
2292void QRegExpEngine::Box::cat( const Box& b ) 2292void QRegExpEngine::Box::cat( const Box& b )
2293{ 2293{
2294 eng->addCatTransitions( rs, b.ls ); 2294 eng->addCatTransitions( rs, b.ls );
2295 addAnchorsToEngine( b ); 2295 addAnchorsToEngine( b );
2296 if ( minl == 0 ) { 2296 if ( minl == 0 ) {
2297 mergeInto( &lanchors, b.lanchors ); 2297 mergeInto( &lanchors, b.lanchors );
2298 if ( skipanchors != 0 ) { 2298 if ( skipanchors != 0 ) {
2299 for ( int i = 0; i < (int) b.ls.size(); i++ ) { 2299 for ( int i = 0; i < (int) b.ls.size(); i++ ) {
2300 int a = eng->anchorConcatenation( at(lanchors, b.ls[i]), 2300 int a = eng->anchorConcatenation( at(lanchors, b.ls[i]),
2301 skipanchors ); 2301 skipanchors );
2302 lanchors.insert( b.ls[i], a ); 2302 lanchors.insert( b.ls[i], a );
2303 } 2303 }
2304 } 2304 }
2305 mergeInto( &ls, b.ls ); 2305 mergeInto( &ls, b.ls );
2306 } 2306 }
2307 if ( b.minl == 0 ) { 2307 if ( b.minl == 0 ) {
2308 mergeInto( &ranchors, b.ranchors ); 2308 mergeInto( &ranchors, b.ranchors );
2309 if ( b.skipanchors != 0 ) { 2309 if ( b.skipanchors != 0 ) {
2310 for ( int i = 0; i < (int) rs.size(); i++ ) { 2310 for ( int i = 0; i < (int) rs.size(); i++ ) {
2311 int a = eng->anchorConcatenation( at(ranchors, rs[i]), 2311 int a = eng->anchorConcatenation( at(ranchors, rs[i]),
2312 b.skipanchors ); 2312 b.skipanchors );
2313 ranchors.insert( rs[i], a ); 2313 ranchors.insert( rs[i], a );
2314 } 2314 }
2315 } 2315 }
2316 mergeInto( &rs, b.rs ); 2316 mergeInto( &rs, b.rs );
2317 } else { 2317 } else {
2318 ranchors = b.ranchors; 2318 ranchors = b.ranchors;
2319 rs = b.rs; 2319 rs = b.rs;
2320 } 2320 }
2321 2321
2322#ifndef QT_NO_REGEXP_OPTIM 2322#ifndef QT_NO_REGEXP_OPTIM
2323 if ( maxl != InftyLen ) { 2323 if ( maxl != InftyLen ) {
2324 if ( rightStr.length() + b.leftStr.length() > 2324 if ( rightStr.length() + b.leftStr.length() >
2325 QMAX(str.length(), b.str.length()) ) { 2325 QMAX(str.length(), b.str.length()) ) {
2326 earlyStart = minl - rightStr.length(); 2326 earlyStart = minl - rightStr.length();
2327 lateStart = maxl - rightStr.length(); 2327 lateStart = maxl - rightStr.length();
2328 str = rightStr + b.leftStr; 2328 str = rightStr + b.leftStr;
2329 } else if ( b.str.length() > str.length() ) { 2329 } else if ( b.str.length() > str.length() ) {
2330 earlyStart = minl + b.earlyStart; 2330 earlyStart = minl + b.earlyStart;
2331 lateStart = maxl + b.lateStart; 2331 lateStart = maxl + b.lateStart;
2332 str = b.str; 2332 str = b.str;
2333 } 2333 }
2334 } 2334 }
2335 2335
2336 if ( (int) leftStr.length() == maxl ) 2336 if ( (int) leftStr.length() == maxl )
2337 leftStr += b.leftStr; 2337 leftStr += b.leftStr;
2338 if ( (int) b.rightStr.length() == b.maxl ) 2338 if ( (int) b.rightStr.length() == b.maxl )
2339 rightStr += b.rightStr; 2339 rightStr += b.rightStr;
2340 else 2340 else
2341 rightStr = b.rightStr; 2341 rightStr = b.rightStr;
2342 2342
2343 if ( maxl == InftyLen || b.maxl == InftyLen ) 2343 if ( maxl == InftyLen || b.maxl == InftyLen )
2344 maxl = InftyLen; 2344 maxl = InftyLen;
2345 else 2345 else
2346 maxl += b.maxl; 2346 maxl += b.maxl;
2347 2347
2348 occ1.detach(); 2348 occ1.detach();
2349 for ( int i = 0; i < NumBadChars; i++ ) { 2349 for ( int i = 0; i < NumBadChars; i++ ) {
2350 if ( b.occ1[i] != NoOccurrence && minl + b.occ1[i] < occ1[i] ) 2350 if ( b.occ1[i] != NoOccurrence && minl + b.occ1[i] < occ1[i] )
2351 occ1[i] = minl + b.occ1[i]; 2351 occ1[i] = minl + b.occ1[i];
2352 } 2352 }
2353#endif 2353#endif
2354 2354
2355 minl += b.minl; 2355 minl += b.minl;
2356 if ( minl == 0 ) 2356 if ( minl == 0 )
2357 skipanchors = eng->anchorConcatenation( skipanchors, b.skipanchors ); 2357 skipanchors = eng->anchorConcatenation( skipanchors, b.skipanchors );
2358 else 2358 else
2359 skipanchors = 0; 2359 skipanchors = 0;
2360} 2360}
2361 2361
2362void QRegExpEngine::Box::orx( const Box& b ) 2362void QRegExpEngine::Box::orx( const Box& b )
2363{ 2363{
2364 mergeInto( &ls, b.ls ); 2364 mergeInto( &ls, b.ls );
2365 mergeInto( &lanchors, b.lanchors ); 2365 mergeInto( &lanchors, b.lanchors );
2366 mergeInto( &rs, b.rs ); 2366 mergeInto( &rs, b.rs );
2367 mergeInto( &ranchors, b.ranchors ); 2367 mergeInto( &ranchors, b.ranchors );
2368 skipanchors = eng->anchorAlternation( skipanchors, b.skipanchors ); 2368 skipanchors = eng->anchorAlternation( skipanchors, b.skipanchors );
2369 2369
2370#ifndef QT_NO_REGEXP_OPTIM 2370#ifndef QT_NO_REGEXP_OPTIM
2371 occ1.detach(); 2371 occ1.detach();
2372 for ( int i = 0; i < NumBadChars; i++ ) { 2372 for ( int i = 0; i < NumBadChars; i++ ) {
2373 if ( occ1[i] > b.occ1[i] ) 2373 if ( occ1[i] > b.occ1[i] )
2374 occ1[i] = b.occ1[i]; 2374 occ1[i] = b.occ1[i];
2375 } 2375 }
2376 earlyStart = 0; 2376 earlyStart = 0;
2377 lateStart = 0; 2377 lateStart = 0;
2378 str = QString::null; 2378 str = QString::null;
2379 leftStr = QString::null; 2379 leftStr = QString::null;
2380 rightStr = QString::null; 2380 rightStr = QString::null;
2381 if ( b.maxl > maxl ) 2381 if ( b.maxl > maxl )
2382 maxl = b.maxl; 2382 maxl = b.maxl;
2383#endif 2383#endif
2384 if ( b.minl < minl ) 2384 if ( b.minl < minl )
2385 minl = b.minl; 2385 minl = b.minl;
2386} 2386}
2387 2387
2388void QRegExpEngine::Box::plus( int atom ) 2388void QRegExpEngine::Box::plus( int atom )
2389{ 2389{
2390#ifndef QT_NO_REGEXP_CAPTURE 2390#ifndef QT_NO_REGEXP_CAPTURE
2391 eng->addPlusTransitions( rs, ls, atom ); 2391 eng->addPlusTransitions( rs, ls, atom );
2392#else 2392#else
2393 Q_UNUSED( atom ); 2393 Q_UNUSED( atom );
2394 eng->addCatTransitions( rs, ls ); 2394 eng->addCatTransitions( rs, ls );
2395#endif 2395#endif
2396 addAnchorsToEngine( *this ); 2396 addAnchorsToEngine( *this );
2397#ifndef QT_NO_REGEXP_OPTIM 2397#ifndef QT_NO_REGEXP_OPTIM
2398 maxl = InftyLen; 2398 maxl = InftyLen;
2399#endif 2399#endif
2400} 2400}
2401 2401
2402void QRegExpEngine::Box::opt() 2402void QRegExpEngine::Box::opt()
2403{ 2403{
2404#ifndef QT_NO_REGEXP_OPTIM 2404#ifndef QT_NO_REGEXP_OPTIM
2405 earlyStart = 0; 2405 earlyStart = 0;
2406 lateStart = 0; 2406 lateStart = 0;
2407 str = QString::null; 2407 str = QString::null;
2408 leftStr = QString::null; 2408 leftStr = QString::null;
2409 rightStr = QString::null; 2409 rightStr = QString::null;
2410#endif 2410#endif
2411 skipanchors = 0; 2411 skipanchors = 0;
2412 minl = 0; 2412 minl = 0;
2413} 2413}
2414 2414
2415void QRegExpEngine::Box::catAnchor( int a ) 2415void QRegExpEngine::Box::catAnchor( int a )
2416{ 2416{
2417 if ( a != 0 ) { 2417 if ( a != 0 ) {
2418 for ( int i = 0; i < (int) rs.size(); i++ ) { 2418 for ( int i = 0; i < (int) rs.size(); i++ ) {
2419 a = eng->anchorConcatenation( at(ranchors, rs[i]), a ); 2419 a = eng->anchorConcatenation( at(ranchors, rs[i]), a );
2420 ranchors.insert( rs[i], a ); 2420 ranchors.insert( rs[i], a );
2421 } 2421 }
2422 if ( minl == 0 ) 2422 if ( minl == 0 )
2423 skipanchors = eng->anchorConcatenation( skipanchors, a ); 2423 skipanchors = eng->anchorConcatenation( skipanchors, a );
2424 } 2424 }
2425} 2425}
2426 2426
2427#ifndef QT_NO_REGEXP_OPTIM 2427#ifndef QT_NO_REGEXP_OPTIM
2428void QRegExpEngine::Box::setupHeuristics() 2428void QRegExpEngine::Box::setupHeuristics()
2429{ 2429{
2430 eng->setupGoodStringHeuristic( earlyStart, lateStart, str ); 2430 eng->setupGoodStringHeuristic( earlyStart, lateStart, str );
2431 2431
2432 /* 2432 /*
2433 A regular expression such as 112|1 has occ1['2'] = 2 and minl = 1 at this 2433 A regular expression such as 112|1 has occ1['2'] = 2 and minl = 1 at this
2434 point. An entry of occ1 has to be at most minl or infinity for the rest 2434 point. An entry of occ1 has to be at most minl or infinity for the rest
2435 of the algorithm to go well. 2435 of the algorithm to go well.
2436 2436
2437 We waited until here before normalizing these cases (instead of doing it 2437 We waited until here before normalizing these cases (instead of doing it
2438 in Box::orx()) because sometimes things improve by themselves; consider 2438 in Box::orx()) because sometimes things improve by themselves; consider
2439 (112|1)34. 2439 (112|1)34.
2440 */ 2440 */
2441 for ( int i = 0; i < NumBadChars; i++ ) { 2441 for ( int i = 0; i < NumBadChars; i++ ) {
2442 if ( occ1[i] != NoOccurrence && occ1[i] >= minl ) 2442 if ( occ1[i] != NoOccurrence && occ1[i] >= minl )
2443 occ1[i] = minl; 2443 occ1[i] = minl;
2444 } 2444 }
2445 eng->setupBadCharHeuristic( minl, occ1 ); 2445 eng->setupBadCharHeuristic( minl, occ1 );
2446 2446
2447 eng->heuristicallyChooseHeuristic(); 2447 eng->heuristicallyChooseHeuristic();
2448} 2448}
2449#endif 2449#endif
2450 2450
2451#if defined(QT_DEBUG) 2451#if defined(QT_DEBUG)
2452void QRegExpEngine::Box::dump() const 2452void QRegExpEngine::Box::dump() const
2453{ 2453{
2454 int i; 2454 int i;
2455 odebug << "Box of at least " << minl << " character" << (minl == 1 ? "" : "s") << oendl; 2455 odebug << "Box of at least " << minl << " character" << (minl == 1 ? "" : "s") << oendl;
2456 odebug << " Left states:" << oendl; 2456 odebug << " Left states:" << oendl;
2457 for ( i = 0; i < (int) ls.size(); i++ ) { 2457 for ( i = 0; i < (int) ls.size(); i++ ) {
2458 if ( at(lanchors, ls[i]) == 0 ) 2458 if ( at(lanchors, ls[i]) == 0 )
2459 odebug << " " << ls[i] << oendl; 2459 odebug << " " << ls[i] << oendl;
2460 else 2460 else
2461 odebug << " " << ls[i] << QString().sprintf(" [anchors 0x%.8x]", lanchors[ls[i]]) << oendl; 2461 odebug << " " << ls[i] << QString().sprintf(" [anchors 0x%.8x]", lanchors[ls[i]]) << oendl;
2462 } 2462 }
2463 odebug << " Right states:" << oendl; 2463 odebug << " Right states:" << oendl;
2464 for ( i = 0; i < (int) rs.size(); i++ ) { 2464 for ( i = 0; i < (int) rs.size(); i++ ) {
2465 if ( at(ranchors, ls[i]) == 0 ) 2465 if ( at(ranchors, ls[i]) == 0 )
2466 odebug << " " << rs[i] << oendl; 2466 odebug << " " << rs[i] << oendl;
2467 else 2467 else
2468 odebug << " " << rs[i] << QString().sprintf(" [anchors 0x%.8x]", ranchors[rs[i]]) << oendl; 2468 odebug << " " << rs[i] << QString().sprintf(" [anchors 0x%.8x]", ranchors[rs[i]]) << oendl;
2469 } 2469 }
2470 odebug << QString().sprintf(" Skip anchors: 0x%.8x", skipanchors) << oendl; 2470 odebug << QString().sprintf(" Skip anchors: 0x%.8x", skipanchors) << oendl;
2471} 2471}
2472#endif 2472#endif
2473 2473
2474void QRegExpEngine::Box::addAnchorsToEngine( const Box& to ) const 2474void QRegExpEngine::Box::addAnchorsToEngine( const Box& to ) const
2475{ 2475{
2476 for ( int i = 0; i < (int) to.ls.size(); i++ ) { 2476 for ( int i = 0; i < (int) to.ls.size(); i++ ) {
2477 for ( int j = 0; j < (int) rs.size(); j++ ) { 2477 for ( int j = 0; j < (int) rs.size(); j++ ) {
2478 int a = eng->anchorConcatenation( at(ranchors, rs[j]), 2478 int a = eng->anchorConcatenation( at(ranchors, rs[j]),
2479 at(to.lanchors, to.ls[i]) ); 2479 at(to.lanchors, to.ls[i]) );
2480 eng->addAnchors( rs[j], to.ls[i], a ); 2480 eng->addAnchors( rs[j], to.ls[i], a );
2481 } 2481 }
2482 } 2482 }
2483} 2483}
2484 2484
2485int QRegExpEngine::getChar() 2485int QRegExpEngine::getChar()
2486{ 2486{
2487 return ( yyPos == yyLen ) ? EOS : yyIn[yyPos++].unicode(); 2487 return ( yyPos == yyLen ) ? EOS : yyIn[yyPos++].unicode();
2488} 2488}
2489 2489
2490int QRegExpEngine::getEscape() 2490int QRegExpEngine::getEscape()
2491{ 2491{
2492#ifndef QT_NO_REGEXP_ESCAPE 2492#ifndef QT_NO_REGEXP_ESCAPE
2493 const char tab[] = "afnrtv"; // no b, as \b means word boundary 2493 const char tab[] = "afnrtv"; // no b, as \b means word boundary
2494 const char backTab[] = "\a\f\n\r\t\v"; 2494 const char backTab[] = "\a\f\n\r\t\v";
2495 ushort low; 2495 ushort low;
2496 int i; 2496 int i;
2497#endif 2497#endif
2498 ushort val; 2498 ushort val;
2499 int prevCh = yyCh; 2499 int prevCh = yyCh;
2500 2500
2501 if ( prevCh == EOS ) { 2501 if ( prevCh == EOS ) {
2502 yyError = TRUE; 2502 yyError = TRUE;
2503 return Tok_Char | '\\'; 2503 return Tok_Char | '\\';
2504 } 2504 }
2505 yyCh = getChar(); 2505 yyCh = getChar();
2506#ifndef QT_NO_REGEXP_ESCAPE 2506#ifndef QT_NO_REGEXP_ESCAPE
2507 if ( (prevCh & ~0xff) == 0 ) { 2507 if ( (prevCh & ~0xff) == 0 ) {
2508 const char *p = strchr( tab, prevCh ); 2508 const char *p = strchr( tab, prevCh );
2509 if ( p != 0 ) 2509 if ( p != 0 )
2510 return Tok_Char | backTab[p - tab]; 2510 return Tok_Char | backTab[p - tab];
2511 } 2511 }
2512#endif 2512#endif
2513 2513
2514 switch ( prevCh ) { 2514 switch ( prevCh ) {
2515#ifndef QT_NO_REGEXP_ESCAPE 2515#ifndef QT_NO_REGEXP_ESCAPE
2516 case '0': 2516 case '0':
2517 val = 0; 2517 val = 0;
2518 for ( i = 0; i < 3; i++ ) { 2518 for ( i = 0; i < 3; i++ ) {
2519 if ( yyCh >= '0' && yyCh <= '7' ) 2519 if ( yyCh >= '0' && yyCh <= '7' )
2520 val = ( val << 3 ) | ( yyCh - '0' ); 2520 val = ( val << 3 ) | ( yyCh - '0' );
2521 else 2521 else
2522 break; 2522 break;
2523 yyCh = getChar(); 2523 yyCh = getChar();
2524 } 2524 }
2525 if ( (val & ~0377) != 0 ) 2525 if ( (val & ~0377) != 0 )
2526 yyError = TRUE; 2526 yyError = TRUE;
2527 return Tok_Char | val; 2527 return Tok_Char | val;
2528#endif 2528#endif
2529#ifndef QT_NO_REGEXP_ESCAPE 2529#ifndef QT_NO_REGEXP_ESCAPE
2530 case 'B': 2530 case 'B':
2531 return Tok_NonWord; 2531 return Tok_NonWord;
2532#endif 2532#endif
2533#ifndef QT_NO_REGEXP_CCLASS 2533#ifndef QT_NO_REGEXP_CCLASS
2534 case 'D': 2534 case 'D':
2535 // see QChar::isDigit() 2535 // see QChar::isDigit()
2536 yyCharClass->addCategories( 0x7fffffef ); 2536 yyCharClass->addCategories( 0x7fffffef );
2537 return Tok_CharClass; 2537 return Tok_CharClass;
2538 case 'S': 2538 case 'S':
2539 // see QChar::isSpace() 2539 // see QChar::isSpace()
2540 yyCharClass->addCategories( 0x7ffff87f ); 2540 yyCharClass->addCategories( 0x7ffff87f );
2541 yyCharClass->addRange( 0x0000, 0x0008 ); 2541 yyCharClass->addRange( 0x0000, 0x0008 );
2542 yyCharClass->addRange( 0x000e, 0x001f ); 2542 yyCharClass->addRange( 0x000e, 0x001f );
2543 yyCharClass->addRange( 0x007f, 0x009f ); 2543 yyCharClass->addRange( 0x007f, 0x009f );
2544 return Tok_CharClass; 2544 return Tok_CharClass;
2545 case 'W': 2545 case 'W':
2546 // see QChar::isLetterOrNumber() 2546 // see QChar::isLetterOrNumber()
2547 yyCharClass->addCategories( 0x7ff07f8f ); 2547 yyCharClass->addCategories( 0x7ff07f8f );
2548 return Tok_CharClass; 2548 return Tok_CharClass;
2549#endif 2549#endif
2550#ifndef QT_NO_REGEXP_ESCAPE 2550#ifndef QT_NO_REGEXP_ESCAPE
2551 case 'b': 2551 case 'b':
2552 return Tok_Word; 2552 return Tok_Word;
2553#endif 2553#endif
2554#ifndef QT_NO_REGEXP_CCLASS 2554#ifndef QT_NO_REGEXP_CCLASS
2555 case 'd': 2555 case 'd':
2556 // see QChar::isDigit() 2556 // see QChar::isDigit()
2557 yyCharClass->addCategories( 0x00000010 ); 2557 yyCharClass->addCategories( 0x00000010 );
2558 return Tok_CharClass; 2558 return Tok_CharClass;
2559 case 's': 2559 case 's':
2560 // see QChar::isSpace() 2560 // see QChar::isSpace()
2561 yyCharClass->addCategories( 0x00000380 ); 2561 yyCharClass->addCategories( 0x00000380 );
2562 yyCharClass->addRange( 0x0009, 0x000d ); 2562 yyCharClass->addRange( 0x0009, 0x000d );
2563 return Tok_CharClass; 2563 return Tok_CharClass;
2564 case 'w': 2564 case 'w':
2565 // see QChar::isLetterOrNumber() 2565 // see QChar::isLetterOrNumber()
2566 yyCharClass->addCategories( 0x000f8070 ); 2566 yyCharClass->addCategories( 0x000f8070 );
2567 return Tok_CharClass; 2567 return Tok_CharClass;
2568#endif 2568#endif
2569#ifndef QT_NO_REGEXP_ESCAPE 2569#ifndef QT_NO_REGEXP_ESCAPE
2570 case 'x': 2570 case 'x':
2571 val = 0; 2571 val = 0;
2572 for ( i = 0; i < 4; i++ ) { 2572 for ( i = 0; i < 4; i++ ) {
2573 low = QChar( yyCh ).lower(); 2573 low = QChar( yyCh ).lower();
2574 if ( low >= '0' && low <= '9' ) 2574 if ( low >= '0' && low <= '9' )
2575 val = ( val << 4 ) | ( low - '0' ); 2575 val = ( val << 4 ) | ( low - '0' );
2576 else if ( low >= 'a' && low <= 'f' ) 2576 else if ( low >= 'a' && low <= 'f' )
2577 val = ( val << 4 ) | ( low - 'a' + 10 ); 2577 val = ( val << 4 ) | ( low - 'a' + 10 );
2578 else 2578 else
2579 break; 2579 break;
2580 yyCh = getChar(); 2580 yyCh = getChar();
2581 } 2581 }
2582 return Tok_Char | val; 2582 return Tok_Char | val;
2583#endif 2583#endif
2584 default: 2584 default:
2585 if ( prevCh >= '1' && prevCh <= '9' ) { 2585 if ( prevCh >= '1' && prevCh <= '9' ) {
2586#ifndef QT_NO_REGEXP_BACKREF 2586#ifndef QT_NO_REGEXP_BACKREF
2587 val = prevCh - '0'; 2587 val = prevCh - '0';
2588 while ( yyCh >= '0' && yyCh <= '9' ) { 2588 while ( yyCh >= '0' && yyCh <= '9' ) {
2589 val = ( val *= 10 ) | ( yyCh - '0' ); 2589 val = ( val *= 10 ) | ( yyCh - '0' );
2590 yyCh = getChar(); 2590 yyCh = getChar();
2591 } 2591 }
2592 return Tok_BackRef | val; 2592 return Tok_BackRef | val;
2593#else 2593#else
2594 yyError = TRUE; 2594 yyError = TRUE;
2595#endif 2595#endif
2596 } 2596 }
2597 return Tok_Char | prevCh; 2597 return Tok_Char | prevCh;
2598 } 2598 }
2599} 2599}
2600 2600
2601#ifndef QT_NO_REGEXP_INTERVAL 2601#ifndef QT_NO_REGEXP_INTERVAL
2602int QRegExpEngine::getRep( int def ) 2602int QRegExpEngine::getRep( int def )
2603{ 2603{
2604 if ( yyCh >= '0' && yyCh <= '9' ) { 2604 if ( yyCh >= '0' && yyCh <= '9' ) {
2605 int rep = 0; 2605 int rep = 0;
2606 do { 2606 do {
2607 rep = 10 * rep + yyCh - '0'; 2607 rep = 10 * rep + yyCh - '0';
2608 if ( rep >= InftyRep ) { 2608 if ( rep >= InftyRep ) {
2609 yyError = TRUE; 2609 yyError = TRUE;
2610 rep = def; 2610 rep = def;
2611 } 2611 }
2612 yyCh = getChar(); 2612 yyCh = getChar();
2613 } while ( yyCh >= '0' && yyCh <= '9' ); 2613 } while ( yyCh >= '0' && yyCh <= '9' );
2614 return rep; 2614 return rep;
2615 } else { 2615 } else {
2616 return def; 2616 return def;
2617 } 2617 }
2618} 2618}
2619#endif 2619#endif
2620 2620
2621#ifndef QT_NO_REGEXP_LOOKAHEAD 2621#ifndef QT_NO_REGEXP_LOOKAHEAD
2622void QRegExpEngine::skipChars( int n ) 2622void QRegExpEngine::skipChars( int n )
2623{ 2623{
2624 if ( n > 0 ) { 2624 if ( n > 0 ) {
2625 yyPos += n - 1; 2625 yyPos += n - 1;
2626 yyCh = getChar(); 2626 yyCh = getChar();
2627 } 2627 }
2628} 2628}
2629#endif 2629#endif
2630 2630
2631void QRegExpEngine::startTokenizer( const QChar *rx, int len ) 2631void QRegExpEngine::startTokenizer( const QChar *rx, int len )
2632{ 2632{
2633 yyIn = rx; 2633 yyIn = rx;
2634 yyPos0 = 0; 2634 yyPos0 = 0;
2635 yyPos = 0; 2635 yyPos = 0;
2636 yyLen = len; 2636 yyLen = len;
2637 yyCh = getChar(); 2637 yyCh = getChar();
2638 yyCharClass = new CharClass; 2638 yyCharClass = new CharClass;
2639 yyMinRep = 0; 2639 yyMinRep = 0;
2640 yyMaxRep = 0; 2640 yyMaxRep = 0;
2641 yyError = FALSE; 2641 yyError = FALSE;
2642} 2642}
2643 2643
2644int QRegExpEngine::getToken() 2644int QRegExpEngine::getToken()
2645{ 2645{
2646#ifndef QT_NO_REGEXP_CCLASS 2646#ifndef QT_NO_REGEXP_CCLASS
2647 ushort pendingCh = 0; 2647 ushort pendingCh = 0;
2648 bool charPending; 2648 bool charPending;
2649 bool rangePending; 2649 bool rangePending;
2650 int tok; 2650 int tok;
2651#endif 2651#endif
2652 int prevCh = yyCh; 2652 int prevCh = yyCh;
2653 2653
2654 yyPos0 = yyPos - 1; 2654 yyPos0 = yyPos - 1;
2655#ifndef QT_NO_REGEXP_CCLASS 2655#ifndef QT_NO_REGEXP_CCLASS
2656 yyCharClass->clear(); 2656 yyCharClass->clear();
2657#endif 2657#endif
2658 yyMinRep = 0; 2658 yyMinRep = 0;
2659 yyMaxRep = 0; 2659 yyMaxRep = 0;
2660 yyCh = getChar(); 2660 yyCh = getChar();
2661 switch ( prevCh ) { 2661 switch ( prevCh ) {
2662 case EOS: 2662 case EOS:
2663 yyPos0 = yyPos; 2663 yyPos0 = yyPos;
2664 return Tok_Eos; 2664 return Tok_Eos;
2665 case '$': 2665 case '$':
2666 return Tok_Dollar; 2666 return Tok_Dollar;
2667 case '(': 2667 case '(':
2668 if ( yyCh == '?' ) { 2668 if ( yyCh == '?' ) {
2669 prevCh = getChar(); 2669 prevCh = getChar();
2670 yyCh = getChar(); 2670 yyCh = getChar();
2671 switch ( prevCh ) { 2671 switch ( prevCh ) {
2672#ifndef QT_NO_REGEXP_LOOKAHEAD 2672#ifndef QT_NO_REGEXP_LOOKAHEAD
2673 case '!': 2673 case '!':
2674 return Tok_NegLookahead; 2674 return Tok_NegLookahead;
2675 case '=': 2675 case '=':
2676 return Tok_PosLookahead; 2676 return Tok_PosLookahead;
2677#endif 2677#endif
2678 case ':': 2678 case ':':
2679 return Tok_MagicLeftParen; 2679 return Tok_MagicLeftParen;
2680 default: 2680 default:
2681 yyError = TRUE; 2681 yyError = TRUE;
2682 return Tok_MagicLeftParen; 2682 return Tok_MagicLeftParen;
2683 } 2683 }
2684 } else { 2684 } else {
2685 return Tok_LeftParen; 2685 return Tok_LeftParen;
2686 } 2686 }
2687 case ')': 2687 case ')':
2688 return Tok_RightParen; 2688 return Tok_RightParen;
2689 case '*': 2689 case '*':
2690 yyMinRep = 0; 2690 yyMinRep = 0;
2691 yyMaxRep = InftyRep; 2691 yyMaxRep = InftyRep;
2692 return Tok_Quantifier; 2692 return Tok_Quantifier;
2693 case '+': 2693 case '+':
2694 yyMinRep = 1; 2694 yyMinRep = 1;
2695 yyMaxRep = InftyRep; 2695 yyMaxRep = InftyRep;
2696 return Tok_Quantifier; 2696 return Tok_Quantifier;
2697 case '.': 2697 case '.':
2698#ifndef QT_NO_REGEXP_CCLASS 2698#ifndef QT_NO_REGEXP_CCLASS
2699 yyCharClass->setNegative( TRUE ); 2699 yyCharClass->setNegative( TRUE );
2700#endif 2700#endif
2701 return Tok_CharClass; 2701 return Tok_CharClass;
2702 case '?': 2702 case '?':
2703 yyMinRep = 0; 2703 yyMinRep = 0;
2704 yyMaxRep = 1; 2704 yyMaxRep = 1;
2705 return Tok_Quantifier; 2705 return Tok_Quantifier;
2706 case '[': 2706 case '[':
2707#ifndef QT_NO_REGEXP_CCLASS 2707#ifndef QT_NO_REGEXP_CCLASS
2708 if ( yyCh == '^' ) { 2708 if ( yyCh == '^' ) {
2709 yyCharClass->setNegative( TRUE ); 2709 yyCharClass->setNegative( TRUE );
2710 yyCh = getChar(); 2710 yyCh = getChar();
2711 } 2711 }
2712 charPending = FALSE; 2712 charPending = FALSE;
2713 rangePending = FALSE; 2713 rangePending = FALSE;
2714 do { 2714 do {
2715 if ( yyCh == '-' && charPending && !rangePending ) { 2715 if ( yyCh == '-' && charPending && !rangePending ) {
2716 rangePending = TRUE; 2716 rangePending = TRUE;
2717 yyCh = getChar(); 2717 yyCh = getChar();
2718 } else { 2718 } else {
2719 if ( charPending && !rangePending ) { 2719 if ( charPending && !rangePending ) {
2720 yyCharClass->addSingleton( pendingCh ); 2720 yyCharClass->addSingleton( pendingCh );
2721 charPending = FALSE; 2721 charPending = FALSE;
2722 } 2722 }
2723 if ( yyCh == '\\' ) { 2723 if ( yyCh == '\\' ) {
2724 yyCh = getChar(); 2724 yyCh = getChar();
2725 tok = getEscape(); 2725 tok = getEscape();
2726 if ( tok == Tok_Word ) 2726 if ( tok == Tok_Word )
2727 tok = '\b'; 2727 tok = '\b';
2728 } else { 2728 } else {
2729 tok = Tok_Char | yyCh; 2729 tok = Tok_Char | yyCh;
2730 yyCh = getChar(); 2730 yyCh = getChar();
2731 } 2731 }
2732 if ( tok == Tok_CharClass ) { 2732 if ( tok == Tok_CharClass ) {
2733 if ( rangePending ) { 2733 if ( rangePending ) {
2734 yyCharClass->addSingleton( '-' ); 2734 yyCharClass->addSingleton( '-' );
2735 yyCharClass->addSingleton( pendingCh ); 2735 yyCharClass->addSingleton( pendingCh );
2736 charPending = FALSE; 2736 charPending = FALSE;
2737 rangePending = FALSE; 2737 rangePending = FALSE;
2738 } 2738 }
2739 } else if ( (tok & Tok_Char) != 0 ) { 2739 } else if ( (tok & Tok_Char) != 0 ) {
2740 if ( rangePending ) { 2740 if ( rangePending ) {
2741 yyCharClass->addRange( pendingCh, tok ^ Tok_Char ); 2741 yyCharClass->addRange( pendingCh, tok ^ Tok_Char );
2742 charPending = FALSE; 2742 charPending = FALSE;
2743 rangePending = FALSE; 2743 rangePending = FALSE;
2744 } else { 2744 } else {
2745 pendingCh = tok ^ Tok_Char; 2745 pendingCh = tok ^ Tok_Char;
2746 charPending = TRUE; 2746 charPending = TRUE;
2747 } 2747 }
2748 } else { 2748 } else {
2749 yyError = TRUE; 2749 yyError = TRUE;
2750 } 2750 }
2751 } 2751 }
2752 } while ( yyCh != ']' && yyCh != EOS ); 2752 } while ( yyCh != ']' && yyCh != EOS );
2753 if ( rangePending ) 2753 if ( rangePending )
2754 yyCharClass->addSingleton( '-' ); 2754 yyCharClass->addSingleton( '-' );
2755 if ( charPending ) 2755 if ( charPending )
2756 yyCharClass->addSingleton( pendingCh ); 2756 yyCharClass->addSingleton( pendingCh );
2757 if ( yyCh == EOS ) 2757 if ( yyCh == EOS )
2758 yyError = TRUE; 2758 yyError = TRUE;
2759 else 2759 else
2760 yyCh = getChar(); 2760 yyCh = getChar();
2761 return Tok_CharClass; 2761 return Tok_CharClass;
2762#else 2762#else
2763 yyError = TRUE; 2763 yyError = TRUE;
2764 return Tok_Char | '['; 2764 return Tok_Char | '[';
2765#endif 2765#endif
2766 case '\\': 2766 case '\\':
2767 return getEscape(); 2767 return getEscape();
2768 case ']': 2768 case ']':
2769 yyError = TRUE; 2769 yyError = TRUE;
2770 return Tok_Char | ']'; 2770 return Tok_Char | ']';
2771 case '^': 2771 case '^':
2772 return Tok_Caret; 2772 return Tok_Caret;
2773#ifndef QT_NO_REGEXP_INTERVAL 2773#ifndef QT_NO_REGEXP_INTERVAL
2774 case '{': 2774 case '{':
2775 yyMinRep = getRep( 0 ); 2775 yyMinRep = getRep( 0 );
2776 yyMaxRep = yyMinRep; 2776 yyMaxRep = yyMinRep;
2777 if ( yyCh == ',' ) { 2777 if ( yyCh == ',' ) {
2778 yyCh = getChar(); 2778 yyCh = getChar();
2779 yyMaxRep = getRep( InftyRep ); 2779 yyMaxRep = getRep( InftyRep );
2780 } 2780 }
2781 if ( yyMaxRep < yyMinRep ) 2781 if ( yyMaxRep < yyMinRep )
2782 qSwap( yyMinRep, yyMaxRep ); 2782 qSwap( yyMinRep, yyMaxRep );
2783 if ( yyCh != '}' ) 2783 if ( yyCh != '}' )
2784 yyError = TRUE; 2784 yyError = TRUE;
2785 yyCh = getChar(); 2785 yyCh = getChar();
2786 return Tok_Quantifier; 2786 return Tok_Quantifier;
2787#else 2787#else
2788 yyError = TRUE; 2788 yyError = TRUE;
2789 return Tok_Char | '{'; 2789 return Tok_Char | '{';
2790#endif 2790#endif
2791 case '|': 2791 case '|':
2792 return Tok_Bar; 2792 return Tok_Bar;
2793 case '}': 2793 case '}':
2794 yyError = TRUE; 2794 yyError = TRUE;
2795 return Tok_Char | '}'; 2795 return Tok_Char | '}';
2796 default: 2796 default:
2797 return Tok_Char | prevCh; 2797 return Tok_Char | prevCh;
2798 } 2798 }
2799} 2799}
2800 2800
2801int QRegExpEngine::parse( const QChar *pattern, int len ) 2801int QRegExpEngine::parse( const QChar *pattern, int len )
2802{ 2802{
2803 valid = TRUE; 2803 valid = TRUE;
2804 startTokenizer( pattern, len ); 2804 startTokenizer( pattern, len );
2805 yyTok = getToken(); 2805 yyTok = getToken();
2806#ifndef QT_NO_REGEXP_CAPTURE 2806#ifndef QT_NO_REGEXP_CAPTURE
2807 yyMayCapture = TRUE; 2807 yyMayCapture = TRUE;
2808#else 2808#else
2809 yyMayCapture = FALSE; 2809 yyMayCapture = FALSE;
2810#endif 2810#endif
2811 2811
2812#ifndef QT_NO_REGEXP_CAPTURE 2812#ifndef QT_NO_REGEXP_CAPTURE
2813 int atom = startAtom( FALSE ); 2813 int atom = startAtom( FALSE );
2814#endif 2814#endif
2815 CharClass anything; 2815 CharClass anything;
2816 Box box( this ); // create InitialState 2816 Box box( this ); // create InitialState
2817 box.set( anything ); 2817 box.set( anything );
2818 Box rightBox( this ); // create FinalState 2818 Box rightBox( this ); // create FinalState
2819 rightBox.set( anything ); 2819 rightBox.set( anything );
2820 2820
2821 Box middleBox( this ); 2821 Box middleBox( this );
2822 parseExpression( &middleBox ); 2822 parseExpression( &middleBox );
2823#ifndef QT_NO_REGEXP_CAPTURE 2823#ifndef QT_NO_REGEXP_CAPTURE
2824 finishAtom( atom ); 2824 finishAtom( atom );
2825#endif 2825#endif
2826#ifndef QT_NO_REGEXP_OPTIM 2826#ifndef QT_NO_REGEXP_OPTIM
2827 middleBox.setupHeuristics(); 2827 middleBox.setupHeuristics();
2828#endif 2828#endif
2829 box.cat( middleBox ); 2829 box.cat( middleBox );
2830 box.cat( rightBox ); 2830 box.cat( rightBox );
2831 delete yyCharClass; 2831 delete yyCharClass;
2832 yyCharClass = 0; 2832 yyCharClass = 0;
2833 2833
2834 realncap = ncap; 2834 realncap = ncap;
2835#ifndef QT_NO_REGEXP_BACKREF 2835#ifndef QT_NO_REGEXP_BACKREF
2836 if ( nbrefs > ncap ) 2836 if ( nbrefs > ncap )
2837 ncap = nbrefs; 2837 ncap = nbrefs;
2838#endif 2838#endif
2839 2839
2840 mmCaptured.resize( 2 + 2 * realncap ); 2840 mmCaptured.resize( 2 + 2 * realncap );
2841 mmCapturedNoMatch.fill( -1, 2 + 2 * realncap ); 2841 mmCapturedNoMatch.fill( -1, 2 + 2 * realncap );
2842 2842
2843 /* 2843 /*
2844 We use one QArray<int> for all the big data used a lot in matchHere() and 2844 We use one QArray<int> for all the big data used a lot in matchHere() and
2845 friends. 2845 friends.
2846 */ 2846 */
2847#ifndef QT_NO_REGEXP_OPTIM 2847#ifndef QT_NO_REGEXP_OPTIM
2848 mmSlideTabSize = QMAX( minl + 1, 16 ); 2848 mmSlideTabSize = QMAX( minl + 1, 16 );
2849#else 2849#else
2850 mmSlideTabSize = 0; 2850 mmSlideTabSize = 0;
2851#endif 2851#endif
2852 mmBigArray.resize( (3 + 4 * ncap) * ns + 4 * ncap + mmSlideTabSize ); 2852 mmBigArray.resize( (3 + 4 * ncap) * ns + 4 * ncap + mmSlideTabSize );
2853 2853
2854 mmInNextStack = mmBigArray.data(); 2854 mmInNextStack = mmBigArray.data();
2855 memset( mmInNextStack, -1, ns * sizeof(int) ); 2855 memset( mmInNextStack, -1, ns * sizeof(int) );
2856 mmCurStack = mmInNextStack + ns; 2856 mmCurStack = mmInNextStack + ns;
2857 mmNextStack = mmInNextStack + 2 * ns; 2857 mmNextStack = mmInNextStack + 2 * ns;
2858 2858
2859 mmCurCapBegin = mmInNextStack + 3 * ns; 2859 mmCurCapBegin = mmInNextStack + 3 * ns;
2860 mmNextCapBegin = mmCurCapBegin + ncap * ns; 2860 mmNextCapBegin = mmCurCapBegin + ncap * ns;
2861 mmCurCapEnd = mmCurCapBegin + 2 * ncap * ns; 2861 mmCurCapEnd = mmCurCapBegin + 2 * ncap * ns;
2862 mmNextCapEnd = mmCurCapBegin + 3 * ncap * ns; 2862 mmNextCapEnd = mmCurCapBegin + 3 * ncap * ns;
2863 2863
2864 mmTempCapBegin = mmCurCapBegin + 4 * ncap * ns; 2864 mmTempCapBegin = mmCurCapBegin + 4 * ncap * ns;
2865 mmTempCapEnd = mmTempCapBegin + ncap; 2865 mmTempCapEnd = mmTempCapBegin + ncap;
2866 mmCapBegin = mmTempCapBegin + 2 * ncap; 2866 mmCapBegin = mmTempCapBegin + 2 * ncap;
2867 mmCapEnd = mmTempCapBegin + 3 * ncap; 2867 mmCapEnd = mmTempCapBegin + 3 * ncap;
2868 2868
2869 mmSlideTab = mmTempCapBegin + 4 * ncap; 2869 mmSlideTab = mmTempCapBegin + 4 * ncap;
2870 2870
2871 if ( yyError ) 2871 if ( yyError )
2872 return -1; 2872 return -1;
2873 2873
2874#ifndef QT_NO_REGEXP_OPTIM 2874#ifndef QT_NO_REGEXP_OPTIM
2875 State *sinit = s[InitialState]; 2875 State *sinit = s[InitialState];
2876 caretAnchored = ( sinit->anchors != 0 ); 2876 caretAnchored = ( sinit->anchors != 0 );
2877 if ( caretAnchored ) { 2877 if ( caretAnchored ) {
2878 QMap<int, int>& anchors = *sinit->anchors; 2878 QMap<int, int>& anchors = *sinit->anchors;
2879 QMap<int, int>::ConstIterator a; 2879 QMap<int, int>::ConstIterator a;
2880 for ( a = anchors.begin(); a != anchors.end(); ++a ) { 2880 for ( a = anchors.begin(); a != anchors.end(); ++a ) {
2881#ifndef QT_NO_REGEXP_ANCHOR_ALT 2881#ifndef QT_NO_REGEXP_ANCHOR_ALT
2882 if ( (*a & Anchor_Alternation) != 0 ) 2882 if ( (*a & Anchor_Alternation) != 0 )
2883 break; 2883 break;
2884#endif 2884#endif
2885 if ( (*a & Anchor_Caret) == 0 ) { 2885 if ( (*a & Anchor_Caret) == 0 ) {
2886 caretAnchored = FALSE; 2886 caretAnchored = FALSE;
2887 break; 2887 break;
2888 } 2888 }
2889 } 2889 }
2890 } 2890 }
2891#endif 2891#endif
2892 return yyPos0; 2892 return yyPos0;
2893} 2893}
2894 2894
2895void QRegExpEngine::parseAtom( Box *box ) 2895void QRegExpEngine::parseAtom( Box *box )
2896{ 2896{
2897#ifndef QT_NO_REGEXP_LOOKAHEAD 2897#ifndef QT_NO_REGEXP_LOOKAHEAD
2898 QRegExpEngine *eng = 0; 2898 QRegExpEngine *eng = 0;
2899 bool neg; 2899 bool neg;
2900 int len; 2900 int len;
2901#endif 2901#endif
2902 2902
2903 switch ( yyTok ) { 2903 switch ( yyTok ) {
2904 case Tok_Dollar: 2904 case Tok_Dollar:
2905 box->catAnchor( Anchor_Dollar ); 2905 box->catAnchor( Anchor_Dollar );
2906 break; 2906 break;
2907 case Tok_Caret: 2907 case Tok_Caret:
2908 box->catAnchor( Anchor_Caret ); 2908 box->catAnchor( Anchor_Caret );
2909 break; 2909 break;
2910#ifndef QT_NO_REGEXP_LOOKAHEAD 2910#ifndef QT_NO_REGEXP_LOOKAHEAD
2911 case Tok_PosLookahead: 2911 case Tok_PosLookahead:
2912 case Tok_NegLookahead: 2912 case Tok_NegLookahead:
2913 neg = ( yyTok == Tok_NegLookahead ); 2913 neg = ( yyTok == Tok_NegLookahead );
2914 eng = new QRegExpEngine( cs ); 2914 eng = new QRegExpEngine( cs );
2915 len = eng->parse( yyIn + yyPos - 1, yyLen - yyPos + 1 ); 2915 len = eng->parse( yyIn + yyPos - 1, yyLen - yyPos + 1 );
2916 if ( len >= 0 ) 2916 if ( len >= 0 )
2917 skipChars( len ); 2917 skipChars( len );
2918 else 2918 else
2919 yyError = TRUE; 2919 yyError = TRUE;
2920 box->catAnchor( addLookahead(eng, neg) ); 2920 box->catAnchor( addLookahead(eng, neg) );
2921 yyTok = getToken(); 2921 yyTok = getToken();
2922 if ( yyTok != Tok_RightParen ) 2922 if ( yyTok != Tok_RightParen )
2923 yyError = TRUE; 2923 yyError = TRUE;
2924 break; 2924 break;
2925#endif 2925#endif
2926#ifndef QT_NO_REGEXP_ESCAPE 2926#ifndef QT_NO_REGEXP_ESCAPE
2927 case Tok_Word: 2927 case Tok_Word:
2928 box->catAnchor( Anchor_Word ); 2928 box->catAnchor( Anchor_Word );
2929 break; 2929 break;
2930 case Tok_NonWord: 2930 case Tok_NonWord:
2931 box->catAnchor( Anchor_NonWord ); 2931 box->catAnchor( Anchor_NonWord );
2932 break; 2932 break;
2933#endif 2933#endif
2934 case Tok_LeftParen: 2934 case Tok_LeftParen:
2935 case Tok_MagicLeftParen: 2935 case Tok_MagicLeftParen:
2936 yyTok = getToken(); 2936 yyTok = getToken();
2937 parseExpression( box ); 2937 parseExpression( box );
2938 if ( yyTok != Tok_RightParen ) 2938 if ( yyTok != Tok_RightParen )
2939 yyError = TRUE; 2939 yyError = TRUE;
2940 break; 2940 break;
2941 case Tok_CharClass: 2941 case Tok_CharClass:
2942 box->set( *yyCharClass ); 2942 box->set( *yyCharClass );
2943 break; 2943 break;
2944 default: 2944 default:
2945 if ( (yyTok & Tok_Char) != 0 ) 2945 if ( (yyTok & Tok_Char) != 0 )
2946 box->set( QChar(yyTok ^ Tok_Char) ); 2946 box->set( QChar(yyTok ^ Tok_Char) );
2947#ifndef QT_NO_REGEXP_BACKREF 2947#ifndef QT_NO_REGEXP_BACKREF
2948 else if ( (yyTok & Tok_BackRef) != 0 ) 2948 else if ( (yyTok & Tok_BackRef) != 0 )
2949 box->set( yyTok ^ Tok_BackRef ); 2949 box->set( yyTok ^ Tok_BackRef );
2950#endif 2950#endif
2951 else 2951 else
2952 yyError = TRUE; 2952 yyError = TRUE;
2953 } 2953 }
2954 yyTok = getToken(); 2954 yyTok = getToken();
2955} 2955}
2956 2956
2957void QRegExpEngine::parseFactor( Box *box ) 2957void QRegExpEngine::parseFactor( Box *box )
2958{ 2958{
2959#ifndef QT_NO_REGEXP_CAPTURE 2959#ifndef QT_NO_REGEXP_CAPTURE
2960 int atom = startAtom( yyMayCapture && yyTok == Tok_LeftParen ); 2960 int atom = startAtom( yyMayCapture && yyTok == Tok_LeftParen );
2961#else 2961#else
2962 static const int atom = 0; 2962 static const int atom = 0;
2963#endif 2963#endif
2964 2964
2965#ifndef QT_NO_REGEXP_INTERVAL 2965#ifndef QT_NO_REGEXP_INTERVAL
2966#define YYREDO() \ 2966#define YYREDO() \
2967 yyIn = in, yyPos0 = pos0, yyPos = pos, yyLen = len, yyCh = ch, \ 2967 yyIn = in, yyPos0 = pos0, yyPos = pos, yyLen = len, yyCh = ch, \
2968 *yyCharClass = charClass, yyMinRep = 0, yyMaxRep = 0, yyTok = tok 2968 *yyCharClass = charClass, yyMinRep = 0, yyMaxRep = 0, yyTok = tok
2969 2969
2970 const QChar *in = yyIn; 2970 const QChar *in = yyIn;
2971 int pos0 = yyPos0; 2971 int pos0 = yyPos0;
2972 int pos = yyPos; 2972 int pos = yyPos;
2973 int len = yyLen; 2973 int len = yyLen;
2974 int ch = yyCh; 2974 int ch = yyCh;
2975 CharClass charClass; 2975 CharClass charClass;
2976 if ( yyTok == Tok_CharClass ) 2976 if ( yyTok == Tok_CharClass )
2977 charClass = *yyCharClass; 2977 charClass = *yyCharClass;
2978 int tok = yyTok; 2978 int tok = yyTok;
2979 bool mayCapture = yyMayCapture; 2979 bool mayCapture = yyMayCapture;
2980#endif 2980#endif
2981 2981
2982 parseAtom( box ); 2982 parseAtom( box );
2983#ifndef QT_NO_REGEXP_CAPTURE 2983#ifndef QT_NO_REGEXP_CAPTURE
2984 finishAtom( atom ); 2984 finishAtom( atom );
2985#endif 2985#endif
2986 2986
2987 if ( yyTok == Tok_Quantifier ) { 2987 if ( yyTok == Tok_Quantifier ) {
2988 if ( yyMaxRep == InftyRep ) { 2988 if ( yyMaxRep == InftyRep ) {
2989 box->plus( atom ); 2989 box->plus( atom );
2990#ifndef QT_NO_REGEXP_INTERVAL 2990#ifndef QT_NO_REGEXP_INTERVAL
2991 } else if ( yyMaxRep == 0 ) { 2991 } else if ( yyMaxRep == 0 ) {
2992 box->clear(); 2992 box->clear();
2993#endif 2993#endif
2994 } 2994 }
2995 if ( yyMinRep == 0 ) 2995 if ( yyMinRep == 0 )
2996 box->opt(); 2996 box->opt();
2997 2997
2998#ifndef QT_NO_REGEXP_INTERVAL 2998#ifndef QT_NO_REGEXP_INTERVAL
2999 yyMayCapture = FALSE; 2999 yyMayCapture = FALSE;
3000 int alpha = ( yyMinRep == 0 ) ? 0 : yyMinRep - 1; 3000 int alpha = ( yyMinRep == 0 ) ? 0 : yyMinRep - 1;
3001 int beta = ( yyMaxRep == InftyRep ) ? 0 : yyMaxRep - ( alpha + 1 ); 3001 int beta = ( yyMaxRep == InftyRep ) ? 0 : yyMaxRep - ( alpha + 1 );
3002 3002
3003 Box rightBox( this ); 3003 Box rightBox( this );
3004 int i; 3004 int i;
3005 3005
3006 for ( i = 0; i < beta; i++ ) { 3006 for ( i = 0; i < beta; i++ ) {
3007 YYREDO(); 3007 YYREDO();
3008 Box leftBox( this ); 3008 Box leftBox( this );
3009 parseAtom( &leftBox ); 3009 parseAtom( &leftBox );
3010 leftBox.cat( rightBox ); 3010 leftBox.cat( rightBox );
3011 leftBox.opt(); 3011 leftBox.opt();
3012 rightBox = leftBox; 3012 rightBox = leftBox;
3013 } 3013 }
3014 for ( i = 0; i < alpha; i++ ) { 3014 for ( i = 0; i < alpha; i++ ) {
3015 YYREDO(); 3015 YYREDO();
3016 Box leftBox( this ); 3016 Box leftBox( this );
3017 parseAtom( &leftBox ); 3017 parseAtom( &leftBox );
3018 leftBox.cat( rightBox ); 3018 leftBox.cat( rightBox );
3019 rightBox = leftBox; 3019 rightBox = leftBox;
3020 } 3020 }
3021 rightBox.cat( *box ); 3021 rightBox.cat( *box );
3022 *box = rightBox; 3022 *box = rightBox;
3023#endif 3023#endif
3024 yyTok = getToken(); 3024 yyTok = getToken();
3025#ifndef QT_NO_REGEXP_INTERVAL 3025#ifndef QT_NO_REGEXP_INTERVAL
3026 yyMayCapture = mayCapture; 3026 yyMayCapture = mayCapture;
3027#endif 3027#endif
3028 } 3028 }
3029#undef YYREDO 3029#undef YYREDO
3030} 3030}
3031 3031
3032void QRegExpEngine::parseTerm( Box *box ) 3032void QRegExpEngine::parseTerm( Box *box )
3033{ 3033{
3034#ifndef QT_NO_REGEXP_OPTIM 3034#ifndef QT_NO_REGEXP_OPTIM
3035 if ( yyTok != Tok_Eos && yyTok != Tok_RightParen && yyTok != Tok_Bar ) 3035 if ( yyTok != Tok_Eos && yyTok != Tok_RightParen && yyTok != Tok_Bar )
3036 parseFactor( box ); 3036 parseFactor( box );
3037#endif 3037#endif
3038 while ( yyTok != Tok_Eos && yyTok != Tok_RightParen && yyTok != Tok_Bar ) { 3038 while ( yyTok != Tok_Eos && yyTok != Tok_RightParen && yyTok != Tok_Bar ) {
3039 Box rightBox( this ); 3039 Box rightBox( this );
3040 parseFactor( &rightBox ); 3040 parseFactor( &rightBox );
3041 box->cat( rightBox ); 3041 box->cat( rightBox );
3042 } 3042 }
3043} 3043}
3044 3044
3045void QRegExpEngine::parseExpression( Box *box ) 3045void QRegExpEngine::parseExpression( Box *box )
3046{ 3046{
3047 parseTerm( box ); 3047 parseTerm( box );
3048 while ( yyTok == Tok_Bar ) { 3048 while ( yyTok == Tok_Bar ) {
3049 Box rightBox( this ); 3049 Box rightBox( this );
3050 yyTok = getToken(); 3050 yyTok = getToken();
3051 parseTerm( &rightBox ); 3051 parseTerm( &rightBox );
3052 box->orx( rightBox ); 3052 box->orx( rightBox );
3053 } 3053 }
3054} 3054}
3055 3055
3056/* 3056/*
3057 The class QRegExpPrivate contains the private data of a regular expression 3057 The class QRegExpPrivate contains the private data of a regular expression
3058 other than the automaton. It makes it possible for many QRegExp objects to 3058 other than the automaton. It makes it possible for many QRegExp objects to
3059 use the same QRegExpEngine object with different QRegExpPrivate objects. 3059 use the same QRegExpEngine object with different QRegExpPrivate objects.
3060*/ 3060*/
3061struct QRegExpPrivate 3061struct QRegExpPrivate
3062{ 3062{
3063 QString pattern; // regular-expression or wildcard pattern 3063 QString pattern; // regular-expression or wildcard pattern
3064 QString rxpattern; // regular-expression pattern 3064 QString rxpattern; // regular-expression pattern
3065#ifndef QT_NO_REGEXP_WILDCARD 3065#ifndef QT_NO_REGEXP_WILDCARD
3066 bool wc; // wildcard mode? 3066 bool wc; // wildcard mode?
3067#endif 3067#endif
3068 bool min; // minimal matching? (instead of maximal) 3068 bool min; // minimal matching? (instead of maximal)
3069#ifndef QT_NO_REGEXP_CAPTURE 3069#ifndef QT_NO_REGEXP_CAPTURE
3070 QString t; // last string passed to QRegExp::search() or searchRev() 3070 QString t; // last string passed to QRegExp::search() or searchRev()
3071 QStringList capturedCache; // what QRegExp::capturedTexts() returned last 3071 QStringList capturedCache; // what QRegExp::capturedTexts() returned last
3072#endif 3072#endif
3073 QArray<int> captured; // what QRegExpEngine::search() returned last 3073 QArray<int> captured; // what QRegExpEngine::search() returned last
3074 3074
3075 QRegExpPrivate() { captured.fill( -1, 2 ); } 3075 QRegExpPrivate() { captured.fill( -1, 2 ); }
3076}; 3076};
3077 3077
3078#ifndef QT_NO_REGEXP_OPTIM 3078#ifndef QT_NO_REGEXP_OPTIM
3079static QCache<QRegExpEngine> *engineCache = 0; 3079static QCache<QRegExpEngine> *engineCache = 0;
3080#endif 3080#endif
3081 3081
3082static QRegExpEngine *newEngine( const QString& pattern, bool caseSensitive ) 3082static QRegExpEngine *newEngine( const QString& pattern, bool caseSensitive )
3083{ 3083{
3084#ifndef QT_NO_REGEXP_OPTIM 3084#ifndef QT_NO_REGEXP_OPTIM
3085 if ( engineCache != 0 ) { 3085 if ( engineCache != 0 ) {
3086 QRegExpEngine *eng = engineCache->take( pattern ); 3086 QRegExpEngine *eng = engineCache->take( pattern );
3087 if ( eng == 0 || eng->caseSensitive() != caseSensitive ) { 3087 if ( eng == 0 || eng->caseSensitive() != caseSensitive ) {
3088 delete eng; 3088 delete eng;
3089 } else { 3089 } else {
3090 eng->ref(); 3090 eng->ref();
3091 return eng; 3091 return eng;
3092 } 3092 }
3093 } 3093 }
3094#endif 3094#endif
3095 return new QRegExpEngine( pattern, caseSensitive ); 3095 return new QRegExpEngine( pattern, caseSensitive );
3096} 3096}
3097 3097
3098static void derefEngine( QRegExpEngine *eng, const QString& pattern ) 3098static void derefEngine( QRegExpEngine *eng, const QString& pattern )
3099{ 3099{
3100 if ( eng != 0 && eng->deref() ) { 3100 if ( eng != 0 && eng->deref() ) {
3101#ifndef QT_NO_REGEXP_OPTIM 3101#ifndef QT_NO_REGEXP_OPTIM
3102 if ( engineCache == 0 ) { 3102 if ( engineCache == 0 ) {
3103 engineCache = new QCache<QRegExpEngine>; 3103 engineCache = new QCache<QRegExpEngine>;
3104 engineCache->setAutoDelete( TRUE ); 3104 engineCache->setAutoDelete( TRUE );
3105 } 3105 }
3106 if ( !pattern.isNull() && 3106 if ( !pattern.isNull() &&
3107 engineCache->insert(pattern, eng, 4 + pattern.length() / 4) ) 3107 engineCache->insert(pattern, eng, 4 + pattern.length() / 4) )
3108 return; 3108 return;
3109#else 3109#else
3110 Q_UNUSED( pattern ); 3110 Q_UNUSED( pattern );
3111#endif 3111#endif
3112 delete eng; 3112 delete eng;
3113 } 3113 }
3114} 3114}
3115 3115
3116/*! 3116/*!
3117 Constructs an empty regexp. 3117 Constructs an empty regexp.
3118 3118
3119 \sa isValid() 3119 \sa isValid()
3120*/ 3120*/
3121QRegExp3::QRegExp3() 3121QRegExp3::QRegExp3()
3122{ 3122{
3123 eng = new QRegExpEngine( TRUE ); 3123 eng = new QRegExpEngine( TRUE );
3124 priv = new QRegExpPrivate; 3124 priv = new QRegExpPrivate;
3125 priv->pattern = QString::null; 3125 priv->pattern = QString::null;
3126#ifndef QT_NO_REGEXP_WILDCARD 3126#ifndef QT_NO_REGEXP_WILDCARD
3127 priv->wc = FALSE; 3127 priv->wc = FALSE;
3128#endif 3128#endif
3129 priv->min = FALSE; 3129 priv->min = FALSE;
3130 compile( TRUE ); 3130 compile( TRUE );
3131} 3131}
3132 3132
3133/*! 3133/*!
3134 Constructs a regular expression object for the given \a pattern 3134 Constructs a regular expression object for the given \a pattern
3135 string. The pattern must be given using wildcard notation if \a 3135 string. The pattern must be given using wildcard notation if \a
3136 wildcard is TRUE (default is FALSE). The pattern is case sensitive, 3136 wildcard is TRUE (default is FALSE). The pattern is case sensitive,
3137 unless \a caseSensitive is FALSE. Matching is greedy (maximal), but 3137 unless \a caseSensitive is FALSE. Matching is greedy (maximal), but
3138 can be changed by calling setMinimal(). 3138 can be changed by calling setMinimal().
3139 3139
3140 \sa setPattern() setCaseSensitive() setWildcard() setMinimal() 3140 \sa setPattern() setCaseSensitive() setWildcard() setMinimal()
3141*/ 3141*/
3142QRegExp3::QRegExp3( const QString& pattern, bool caseSensitive, bool wildcard ) 3142QRegExp3::QRegExp3( const QString& pattern, bool caseSensitive, bool wildcard )
3143{ 3143{
3144 eng = 0; 3144 eng = 0;
3145 priv = new QRegExpPrivate; 3145 priv = new QRegExpPrivate;
3146 priv->pattern = pattern; 3146 priv->pattern = pattern;
3147#ifndef QT_NO_REGEXP_WILDCARD 3147#ifndef QT_NO_REGEXP_WILDCARD
3148 priv->wc = wildcard; 3148 priv->wc = wildcard;
3149#endif 3149#endif
3150 priv->min = FALSE; 3150 priv->min = FALSE;
3151 compile( caseSensitive ); 3151 compile( caseSensitive );
3152} 3152}
3153 3153
3154/*! 3154/*!
3155 Constructs a regular expression as a copy of \a rx. 3155 Constructs a regular expression as a copy of \a rx.
3156 3156
3157 \sa operator=() 3157 \sa operator=()
3158*/ 3158*/
3159QRegExp3::QRegExp3( const QRegExp3& rx ) 3159QRegExp3::QRegExp3( const QRegExp3& rx )
3160{ 3160{
3161 eng = 0; 3161 eng = 0;
3162 priv = new QRegExpPrivate; 3162 priv = new QRegExpPrivate;
3163 operator=( rx ); 3163 operator=( rx );
3164} 3164}
3165 3165
3166/*! 3166/*!
3167 Destroys the regular expression and cleans up its internal data. 3167 Destroys the regular expression and cleans up its internal data.
3168*/ 3168*/
3169QRegExp3::~QRegExp3() 3169QRegExp3::~QRegExp3()
3170{ 3170{
3171 derefEngine( eng, priv->rxpattern ); 3171 derefEngine( eng, priv->rxpattern );
3172 delete priv; 3172 delete priv;
3173} 3173}
3174 3174
3175/*! 3175/*!
3176 Copies the regular expression \a rx and returns a reference to the copy. 3176 Copies the regular expression \a rx and returns a reference to the copy.
3177 The case sensitivity, wildcard and minimal matching options are copied as 3177 The case sensitivity, wildcard and minimal matching options are copied as
3178 well. 3178 well.
3179*/ 3179*/
3180QRegExp3& QRegExp3::operator=( const QRegExp3& rx ) 3180QRegExp3& QRegExp3::operator=( const QRegExp3& rx )
3181{ 3181{
3182 rx.eng->ref(); 3182 rx.eng->ref();
3183 derefEngine( eng, priv->rxpattern ); 3183 derefEngine( eng, priv->rxpattern );
3184 eng = rx.eng; 3184 eng = rx.eng;
3185 priv->pattern = rx.priv->pattern; 3185 priv->pattern = rx.priv->pattern;
3186 priv->rxpattern = rx.priv->rxpattern; 3186 priv->rxpattern = rx.priv->rxpattern;
3187#ifndef QT_NO_REGEXP_WILDCARD 3187#ifndef QT_NO_REGEXP_WILDCARD
3188 priv->wc = rx.priv->wc; 3188 priv->wc = rx.priv->wc;
3189#endif 3189#endif
3190 priv->min = rx.priv->min; 3190 priv->min = rx.priv->min;
3191#ifndef QT_NO_REGEXP_CAPTURE 3191#ifndef QT_NO_REGEXP_CAPTURE
3192 priv->t = rx.priv->t; 3192 priv->t = rx.priv->t;
3193 priv->capturedCache = rx.priv->capturedCache; 3193 priv->capturedCache = rx.priv->capturedCache;
3194#endif 3194#endif
3195 priv->captured = rx.priv->captured; 3195 priv->captured = rx.priv->captured;
3196 return *this; 3196 return *this;
3197} 3197}
3198 3198
3199/*! 3199/*!
3200 Returns TRUE if this regular expression is equal to \a rx, otherwise 3200 Returns TRUE if this regular expression is equal to \a rx, otherwise
3201 returns FALSE. 3201 returns FALSE.
3202 3202
3203 Two QRegExp3 objects are equal if they have the same pattern strings 3203 Two QRegExp3 objects are equal if they have the same pattern strings
3204 and the same settings for case sensitivity, wildcard and minimal 3204 and the same settings for case sensitivity, wildcard and minimal
3205 matching. 3205 matching.
3206*/ 3206*/
3207bool QRegExp3::operator==( const QRegExp3& rx ) const 3207bool QRegExp3::operator==( const QRegExp3& rx ) const
3208{ 3208{
3209 return priv->pattern == rx.priv->pattern && 3209 return priv->pattern == rx.priv->pattern &&
3210 eng->caseSensitive() == rx.eng->caseSensitive() && 3210 eng->caseSensitive() == rx.eng->caseSensitive() &&
3211#ifndef QT_NO_REGEXP_WILDCARD 3211#ifndef QT_NO_REGEXP_WILDCARD
3212 priv->wc == rx.priv->wc && 3212 priv->wc == rx.priv->wc &&
3213#endif 3213#endif
3214 priv->min == rx.priv->min; 3214 priv->min == rx.priv->min;
3215} 3215}
3216 3216
3217/*! \fn bool QRegExp3::operator!=( const QRegExp& rx ) const 3217/*! \fn bool QRegExp3::operator!=( const QRegExp& rx ) const
3218 3218
3219 Returns TRUE if this regular expression is not equal to \a rx, otherwise 3219 Returns TRUE if this regular expression is not equal to \a rx, otherwise
3220 FALSE. 3220 FALSE.
3221 3221
3222 \sa operator==() 3222 \sa operator==()
3223*/ 3223*/
3224 3224
3225/*! 3225/*!
3226 Returns TRUE if the pattern string is empty, otherwise FALSE. 3226 Returns TRUE if the pattern string is empty, otherwise FALSE.
3227 3227
3228 If you call match() with an empty pattern on an empty string it will 3228 If you call match() with an empty pattern on an empty string it will
3229 return TRUE otherwise it returns FALSE since match() operates over the 3229 return TRUE otherwise it returns FALSE since match() operates over the
3230 whole string. If you call search() with an empty pattern on \e any 3230 whole string. If you call search() with an empty pattern on \e any
3231 string it will return the start position (0 by default) since it will 3231 string it will return the start position (0 by default) since it will
3232 match at the start position, because the empty pattern matches the 3232 match at the start position, because the empty pattern matches the
3233 'emptiness' at the start of the string, and the length of the match 3233 'emptiness' at the start of the string, and the length of the match
3234 returned by matchedLength() will be 0. 3234 returned by matchedLength() will be 0.
3235 3235
3236 See QString::isEmpty(). 3236 See QString::isEmpty().
3237*/ 3237*/
3238 3238
3239bool QRegExp3::isEmpty() const 3239bool QRegExp3::isEmpty() const
3240{ 3240{
3241 return priv->pattern.isEmpty(); 3241 return priv->pattern.isEmpty();
3242} 3242}
3243 3243
3244/*! 3244/*!
3245 Returns TRUE if the regular expression is valid, or FALSE if it's invalid. An 3245 Returns TRUE if the regular expression is valid, or FALSE if it's invalid. An
3246 invalid regular expression never matches. 3246 invalid regular expression never matches.
3247 3247
3248 The pattern <b>[a-z</b> is an example of an invalid pattern, since it lacks 3248 The pattern <b>[a-z</b> is an example of an invalid pattern, since it lacks
3249 a closing square bracket. 3249 a closing square bracket.
3250 3250
3251 Note that the validity of a regexp may also depend on the setting of 3251 Note that the validity of a regexp may also depend on the setting of
3252 the wildcard flag, for example <b>*.html</b> is a valid wildcard 3252 the wildcard flag, for example <b>*.html</b> is a valid wildcard
3253 regexp but an invalid full regexp. 3253 regexp but an invalid full regexp.
3254*/ 3254*/
3255bool QRegExp3::isValid() const 3255bool QRegExp3::isValid() const
3256{ 3256{
3257 return eng->isValid(); 3257 return eng->isValid();
3258} 3258}
3259 3259
3260/*! 3260/*!
3261 Returns the pattern string of the regular expression. The pattern has either 3261 Returns the pattern string of the regular expression. The pattern has either
3262 regular expression syntax or wildcard syntax, depending on wildcard(). 3262 regular expression syntax or wildcard syntax, depending on wildcard().
3263 3263
3264 \sa setPattern() 3264 \sa setPattern()
3265*/ 3265*/
3266QString QRegExp3::pattern() const 3266QString QRegExp3::pattern() const
3267{ 3267{
3268 return priv->pattern; 3268 return priv->pattern;
3269} 3269}
3270 3270
3271/*! 3271/*!
3272 Sets the pattern string to \a pattern and returns a reference to this regular 3272 Sets the pattern string to \a pattern and returns a reference to this regular
3273 expression. The case sensitivity, wildcard and minimal matching options are 3273 expression. The case sensitivity, wildcard and minimal matching options are
3274 not changed. 3274 not changed.
3275 3275
3276 \sa pattern() 3276 \sa pattern()
3277*/ 3277*/
3278void QRegExp3::setPattern( const QString& pattern ) 3278void QRegExp3::setPattern( const QString& pattern )
3279{ 3279{
3280 if ( priv->pattern != pattern ) { 3280 if ( priv->pattern != pattern ) {
3281 priv->pattern = pattern; 3281 priv->pattern = pattern;
3282 compile( caseSensitive() ); 3282 compile( caseSensitive() );
3283 } 3283 }
3284} 3284}
3285 3285
3286/*! 3286/*!
3287 Returns TRUE if case sensitivity is enabled, otherwise FALSE. The default is 3287 Returns TRUE if case sensitivity is enabled, otherwise FALSE. The default is
3288 TRUE. 3288 TRUE.
3289 3289
3290 \sa setCaseSensitive() 3290 \sa setCaseSensitive()
3291*/ 3291*/
3292bool QRegExp3::caseSensitive() const 3292bool QRegExp3::caseSensitive() const
3293{ 3293{
3294 return eng->caseSensitive(); 3294 return eng->caseSensitive();
3295} 3295}
3296 3296
3297/*! 3297/*!
3298 Sets case sensitive matching to \a sensitive. 3298 Sets case sensitive matching to \a sensitive.
3299 3299
3300 If \a sensitive is TRUE, <b>\\</b><b>.txt$</b> matches 3300 If \a sensitive is TRUE, <b>\\</b><b>.txt$</b> matches
3301 <tt>readme.txt</tt> but not <tt>README.TXT</tt>. 3301 <tt>readme.txt</tt> but not <tt>README.TXT</tt>.
3302 3302
3303 \sa caseSensitive() 3303 \sa caseSensitive()
3304*/ 3304*/
3305void QRegExp3::setCaseSensitive( bool sensitive ) 3305void QRegExp3::setCaseSensitive( bool sensitive )
3306{ 3306{
3307 if ( sensitive != eng->caseSensitive() ) 3307 if ( sensitive != eng->caseSensitive() )
3308 compile( sensitive ); 3308 compile( sensitive );
3309} 3309}
3310 3310
3311#ifndef QT_NO_REGEXP_WILDCARD 3311#ifndef QT_NO_REGEXP_WILDCARD
3312/*! 3312/*!
3313 Returns TRUE if wildcard mode is enabled, otherwise FALSE. The default is 3313 Returns TRUE if wildcard mode is enabled, otherwise FALSE. The default is
3314 FALSE. 3314 FALSE.
3315 3315
3316 \sa setWildcard() 3316 \sa setWildcard()
3317*/ 3317*/
3318bool QRegExp3::wildcard() const 3318bool QRegExp3::wildcard() const
3319{ 3319{
3320 return priv->wc; 3320 return priv->wc;
3321} 3321}
3322 3322
3323/*! Sets the wildcard mode for the regular expression. The default is FALSE. 3323/*! Sets the wildcard mode for the regular expression. The default is FALSE.
3324 3324
3325 Setting \a wildcard to TRUE enables simple shell-like wildcard 3325 Setting \a wildcard to TRUE enables simple shell-like wildcard
3326 matching. 3326 matching.
3327 (See <a href="#wildcard-matching">wildcard matching (globbing)</a>.) 3327 (See <a href="#wildcard-matching">wildcard matching (globbing)</a>.)
3328 3328
3329 For example, <b>r*.txt</b> matches the string <tt>readme.txt</tt> in wildcard 3329 For example, <b>r*.txt</b> matches the string <tt>readme.txt</tt> in wildcard
3330 mode, but does not match <tt>readme</tt>. 3330 mode, but does not match <tt>readme</tt>.
3331 3331
3332 \sa wildcard() 3332 \sa wildcard()
3333*/ 3333*/
3334void QRegExp3::setWildcard( bool wildcard ) 3334void QRegExp3::setWildcard( bool wildcard )
3335{ 3335{
3336 if ( wildcard != priv->wc ) { 3336 if ( wildcard != priv->wc ) {
3337 priv->wc = wildcard; 3337 priv->wc = wildcard;
3338 compile( caseSensitive() ); 3338 compile( caseSensitive() );
3339 } 3339 }
3340} 3340}
3341#endif 3341#endif
3342 3342
3343/*! Returns TRUE if minimal (non-greedy) matching is enabled, otherwise 3343/*! Returns TRUE if minimal (non-greedy) matching is enabled, otherwise
3344 returns FALSE. 3344 returns FALSE.
3345 3345
3346 \sa setMinimal() 3346 \sa setMinimal()
3347*/ 3347*/
3348bool QRegExp3::minimal() const 3348bool QRegExp3::minimal() const
3349{ 3349{
3350 return priv->min; 3350 return priv->min;
3351} 3351}
3352 3352
3353/*! 3353/*!
3354 Enables or disables minimal matching. If \a minimal is FALSE, matching is 3354 Enables or disables minimal matching. If \a minimal is FALSE, matching is
3355 greedy (maximal) which is the default. 3355 greedy (maximal) which is the default.
3356 3356
3357 For example, suppose we have the input string "We must be \<b>bold\</b>, 3357 For example, suppose we have the input string "We must be \<b>bold\</b>,
3358 very \<b>bold\</b>!" and the pattern <b>\<b>.*\</b></b>. With 3358 very \<b>bold\</b>!" and the pattern <b>\<b>.*\</b></b>. With
3359 the default greedy (maximal) matching, the match is 3359 the default greedy (maximal) matching, the match is
3360 "We must be <u>\<b>bold\</b>, very \<b>bold\</b></u>!". But with 3360 "We must be <u>\<b>bold\</b>, very \<b>bold\</b></u>!". But with
3361 minimal (non-greedy) matching the first match is: 3361 minimal (non-greedy) matching the first match is:
3362 "We must be <u>\<b>bold\</b></u>, very \<b>bold\</b>!" and the 3362 "We must be <u>\<b>bold\</b></u>, very \<b>bold\</b>!" and the
3363 second match is 3363 second match is
3364 "We must be \<b>bold\</b>, very <u>\<b>bold\</b></u>!". 3364 "We must be \<b>bold\</b>, very <u>\<b>bold\</b></u>!".
3365 In practice we might use the pattern <b>\<b>[^\<]+\</b></b>, 3365 In practice we might use the pattern <b>\<b>[^\<]+\</b></b>,
3366 although this will still fail for nested tags. 3366 although this will still fail for nested tags.
3367 3367
3368 \sa minimal() 3368 \sa minimal()
3369*/ 3369*/
3370void QRegExp3::setMinimal( bool minimal ) 3370void QRegExp3::setMinimal( bool minimal )
3371{ 3371{
3372 priv->min = minimal; 3372 priv->min = minimal;
3373} 3373}
3374 3374
3375/*! 3375/*!
3376 Returns TRUE if \a str is matched exactly by this regular expression 3376 Returns TRUE if \a str is matched exactly by this regular expression
3377 otherwise it returns FALSE. You can determine how much of the string was 3377 otherwise it returns FALSE. You can determine how much of the string was
3378 matched by calling matchedLength(). 3378 matched by calling matchedLength().
3379 3379
3380 For a given regexp string, R, <tt>match("R")</tt> is the equivalent 3380 For a given regexp string, R, <tt>match("R")</tt> is the equivalent
3381 of <tt>search("^R$")</tt> since match() effectively encloses the 3381 of <tt>search("^R$")</tt> since match() effectively encloses the
3382 regexp in the start of string and end of string anchors. 3382 regexp in the start of string and end of string anchors.
3383 3383
3384 For example, if the regular expression is <b>blue</b>, then match() 3384 For example, if the regular expression is <b>blue</b>, then match()
3385 returns TRUE only for input <tt>blue</tt>. For inputs 3385 returns TRUE only for input <tt>blue</tt>. For inputs
3386 <tt>bluebell</tt>, <tt>blutak</tt> and <tt>lightblue</tt>, match() 3386 <tt>bluebell</tt>, <tt>blutak</tt> and <tt>lightblue</tt>, match()
3387 returns FALSE and matchedLength() will return 4, 3 and 0 respectively. 3387 returns FALSE and matchedLength() will return 4, 3 and 0 respectively.
3388 3388
3389 \sa search() searchRev() QRegExpValidator 3389 \sa search() searchRev() QRegExpValidator
3390*/ 3390*/
3391bool QRegExp3::exactMatch( const QString& str ) 3391bool QRegExp3::exactMatch( const QString& str )
3392{ 3392{
3393#ifndef QT_NO_REGEXP_CAPTURE 3393#ifndef QT_NO_REGEXP_CAPTURE
3394 priv->t = str; 3394 priv->t = str;
3395 priv->capturedCache.clear(); 3395 priv->capturedCache.clear();
3396#endif 3396#endif
3397 3397
3398 priv->captured = eng->match( str, 0, priv->min, TRUE ); 3398 priv->captured = eng->match( str, 0, priv->min, TRUE );
3399 if ( priv->captured[1] == (int) str.length() ) { 3399 if ( priv->captured[1] == (int) str.length() ) {
3400 return TRUE; 3400 return TRUE;
3401 } else { 3401 } else {
3402 priv->captured.detach(); 3402 priv->captured.detach();
3403 priv->captured[0] = 0; 3403 priv->captured[0] = 0;
3404 priv->captured[1] = eng->matchedLength(); 3404 priv->captured[1] = eng->matchedLength();
3405 return FALSE; 3405 return FALSE;
3406 } 3406 }
3407} 3407}
3408 3408
3409/*! \overload 3409/*! \overload
3410 3410
3411 This version does not set matchedLength(), capturedTexts() and friends. 3411 This version does not set matchedLength(), capturedTexts() and friends.
3412*/ 3412*/
3413bool QRegExp3::exactMatch( const QString& str ) const 3413bool QRegExp3::exactMatch( const QString& str ) const
3414{ 3414{
3415 return eng->match(str, 0, priv->min, TRUE)[0] == 0 && 3415 return eng->match(str, 0, priv->min, TRUE)[0] == 0 &&
3416 eng->matchedLength() == (int) str.length(); 3416 eng->matchedLength() == (int) str.length();
3417} 3417}
3418 3418
3419/*! \obsolete 3419/*! \obsolete
3420 3420
3421 Attempts to match in \a str, starting from position \a index. Returns the 3421 Attempts to match in \a str, starting from position \a index. Returns the
3422 position of the match, or -1 if there was no match. 3422 position of the match, or -1 if there was no match.
3423 3423
3424 The length of the match is stored in \a *len, unless \a len is a null pointer. 3424 The length of the match is stored in \a *len, unless \a len is a null pointer.
3425 3425
3426 If \a indexIsStart is TRUE (the default), the position \a index in the string 3426 If \a indexIsStart is TRUE (the default), the position \a index in the string
3427 will match the start of string anchor, <b>^</b>, in the regexp, if present. 3427 will match the start of string anchor, <b>^</b>, in the regexp, if present.
3428 Otherwise, position 0 in \a str will match. 3428 Otherwise, position 0 in \a str will match.
3429 3429
3430 Use search() and matchedLength() instead of this function. 3430 Use search() and matchedLength() instead of this function.
3431 3431
3432 If you really need the \a indexIsStart functionality, try this: 3432 If you really need the \a indexIsStart functionality, try this:
3433 3433
3434 \code 3434 \code
3435 QRegExp3 rx( "some pattern" ); 3435 QRegExp3 rx( "some pattern" );
3436 int pos = rx.search( str.mid( index ) ); 3436 int pos = rx.search( str.mid( index ) );
3437 if ( pos != -1 ) 3437 if ( pos != -1 )
3438 pos += index; 3438 pos += index;
3439 int len = rx.matchedLength(); 3439 int len = rx.matchedLength();
3440 \endcode 3440 \endcode
3441*/ 3441*/
3442#ifndef QT_NO_COMPAT 3442#ifndef QT_NO_COMPAT
3443int QRegExp3::match( const QString& str, int index, int *len, 3443int QRegExp3::match( const QString& str, int index, int *len,
3444 bool indexIsStart ) 3444 bool indexIsStart )
3445{ 3445{
3446 int pos; 3446 int pos;
3447 if ( indexIsStart ) { 3447 if ( indexIsStart ) {
3448 pos = search( str.mid(index) ); 3448 pos = search( str.mid(index) );
3449 if ( pos >= 0 ) { 3449 if ( pos >= 0 ) {
3450 pos += index; 3450 pos += index;
3451 if ( len != 0 ) 3451 if ( len != 0 )
3452 *len = matchedLength(); 3452 *len = matchedLength();
3453 } else { 3453 } else {
3454 if ( len != 0 ) 3454 if ( len != 0 )
3455 *len = 0; 3455 *len = 0;
3456 } 3456 }
3457 } else { 3457 } else {
3458 pos = search( str, index ); 3458 pos = search( str, index );
3459 if ( len != 0 ) 3459 if ( len != 0 )
3460 *len = matchedLength(); 3460 *len = matchedLength();
3461 } 3461 }
3462 return pos; 3462 return pos;
3463} 3463}
3464#endif 3464#endif
3465 3465
3466/*! 3466/*!
3467 Attempts to find a match in \a str from position \a start (0 by default). If 3467 Attempts to find a match in \a str from position \a start (0 by default). If
3468 \a start is -1, the search starts at the last character; if -2, at the next to 3468 \a start is -1, the search starts at the last character; if -2, at the next to
3469 last character; etc. 3469 last character; etc.
3470 3470
3471 Returns the position of the first match, or -1 if there was no match. 3471 Returns the position of the first match, or -1 if there was no match.
3472 3472
3473 You might prefer to use QString::find(), QString::contains() or even 3473 You might prefer to use QString::find(), QString::contains() or even
3474 QStringList::grep(). To replace matches use QString::replace(). 3474 QStringList::grep(). To replace matches use QString::replace().
3475 3475
3476 Example: 3476 Example:
3477 \code 3477 \code
3478 QString str = "offsets: 1.23 .50 71.00 6.00"; 3478 QString str = "offsets: 1.23 .50 71.00 6.00";
3479 QRegExp3 rx( "\\d*\\.\\d+" ); // very simple floating point matching 3479 QRegExp3 rx( "\\d*\\.\\d+" ); // very simple floating point matching
3480 int count = 0; 3480 int count = 0;
3481 int pos = 0; 3481 int pos = 0;
3482 while ( pos >= 0 ) { 3482 while ( pos >= 0 ) {
3483 pos = rx.search( str, pos ); 3483 pos = rx.search( str, pos );
3484 count++; 3484 count++;
3485 } 3485 }
3486 // pos will be 9, 14, 18 and finally 24; count will end up as 4. 3486 // pos will be 9, 14, 18 and finally 24; count will end up as 4.
3487 \endcode 3487 \endcode
3488 3488
3489 \sa searchRev() match() matchedLength() capturedTexts() 3489 \sa searchRev() match() matchedLength() capturedTexts()
3490*/ 3490*/
3491// QChar versions 3491// QChar versions
3492 3492
3493#ifdef QCHAR_SUPPORT 3493#ifdef QCHAR_SUPPORT
3494const QString makeString(const QChar *str) 3494const QString makeString(const QChar *str)
3495{ 3495{
3496// A sentinel value checked in case the QChar *ptr is never null terminated 3496// A sentinel value checked in case the QChar *ptr is never null terminated
3497 const uint MAXLENGTH=65535; 3497 const uint MAXLENGTH=65535;
3498 3498
3499 const QChar *s=str; 3499 const QChar *s=str;
3500 uint i=0; 3500 uint i=0;
3501 while(i < MAXLENGTH && *s != QChar::null) { i++;s++ ;} 3501 while(i < MAXLENGTH && *s != QChar::null) { i++;s++ ;}
3502 return QString(str,i); 3502 return QString(str,i);
3503 3503
3504} 3504}
3505int QRegExp3::search(const QChar *str,int start) 3505int QRegExp3::search(const QChar *str,int start)
3506{ 3506{
3507 return search(makeString(str),start); 3507 return search(makeString(str),start);
3508} 3508}
3509int QRegExp3::search(const QChar *str,int start) const 3509int QRegExp3::search(const QChar *str,int start) const
3510{ 3510{
3511 return search(makeString(str),start); 3511 return search(makeString(str),start);
3512} 3512}
3513int QRegExp3::searchRev(const QChar *str,int start) 3513int QRegExp3::searchRev(const QChar *str,int start)
3514{ 3514{
3515 return searchRev(makeString(str),start); 3515 return searchRev(makeString(str),start);
3516} 3516}
3517int QRegExp3::searchRev(const QChar *str,int start) const 3517int QRegExp3::searchRev(const QChar *str,int start) const
3518{ 3518{
3519 return searchRev(makeString(str),start); 3519 return searchRev(makeString(str),start);
3520} 3520}
3521bool QRegExp3::exactMatch(const QChar *str) 3521bool QRegExp3::exactMatch(const QChar *str)
3522{ 3522{
3523 return exactMatch(makeString(str)); 3523 return exactMatch(makeString(str));
3524} 3524}
3525bool QRegExp3::exactMatch(const QChar *str) const 3525bool QRegExp3::exactMatch(const QChar *str) const
3526{ 3526{
3527 return exactMatch(makeString(str)); 3527 return exactMatch(makeString(str));
3528} 3528}
3529#endif // QCHAR_SUPPORT 3529#endif // QCHAR_SUPPORT
3530 3530
3531int QRegExp3::search( const QString& str, int start ) 3531int QRegExp3::search( const QString& str, int start )
3532{ 3532{
3533 if ( start < 0 ) 3533 if ( start < 0 )
3534 start += str.length(); 3534 start += str.length();
3535#ifndef QT_NO_REGEXP_CAPTURE 3535#ifndef QT_NO_REGEXP_CAPTURE
3536 priv->t = str; 3536 priv->t = str;
3537 priv->capturedCache.clear(); 3537 priv->capturedCache.clear();
3538#endif 3538#endif
3539 priv->captured = eng->match( str, start, priv->min, FALSE ); 3539 priv->captured = eng->match( str, start, priv->min, FALSE );
3540 return priv->captured[0]; 3540 return priv->captured[0];
3541} 3541}
3542 3542
3543/*! \overload 3543/*! \overload
3544 3544
3545 This version does not set matchedLength(), capturedTexts() and friends. 3545 This version does not set matchedLength(), capturedTexts() and friends.
3546*/ 3546*/
3547int QRegExp3::search( const QString& str, int start ) const 3547int QRegExp3::search( const QString& str, int start ) const
3548{ 3548{
3549 if ( start < 0 ) 3549 if ( start < 0 )
3550 start += str.length(); 3550 start += str.length();
3551 return eng->match( str, start, priv->min, FALSE )[0]; 3551 return eng->match( str, start, priv->min, FALSE )[0];
3552} 3552}
3553 3553
3554/*! 3554/*!
3555 Attempts to find a match backwards in \a str from position \a start. If 3555 Attempts to find a match backwards in \a str from position \a start. If
3556 \a start is -1 (the default), the search starts at the last character; if -2, 3556 \a start is -1 (the default), the search starts at the last character; if -2,
3557 at the next to last character; etc. 3557 at the next to last character; etc.
3558 3558
3559 Returns the position of the first match, or -1 if there was no match. 3559 Returns the position of the first match, or -1 if there was no match.
3560 3560
3561 You might prefer to use QString::findRev(). 3561 You might prefer to use QString::findRev().
3562 3562
3563 \sa search() matchedLength() capturedTexts() 3563 \sa search() matchedLength() capturedTexts()
3564*/ 3564*/
3565int QRegExp3::searchRev( const QString& str, int start ) 3565int QRegExp3::searchRev( const QString& str, int start )
3566{ 3566{
3567 if ( start < 0 ) 3567 if ( start < 0 )
3568 start += str.length(); 3568 start += str.length();
3569#ifndef QT_NO_REGEXP_CAPTURE 3569#ifndef QT_NO_REGEXP_CAPTURE
3570 priv->t = str; 3570 priv->t = str;
3571 priv->capturedCache.clear(); 3571 priv->capturedCache.clear();
3572#endif 3572#endif
3573 if ( start < 0 || start > (int) str.length() ) { 3573 if ( start < 0 || start > (int) str.length() ) {
3574 priv->captured.detach(); 3574 priv->captured.detach();
3575 priv->captured.fill( -1 ); 3575 priv->captured.fill( -1 );
3576 return -1; 3576 return -1;
3577 } 3577 }
3578 3578
3579 while ( start >= 0 ) { 3579 while ( start >= 0 ) {
3580 priv->captured = eng->match( str, start, priv->min, TRUE ); 3580 priv->captured = eng->match( str, start, priv->min, TRUE );
3581 if ( priv->captured[0] == start ) 3581 if ( priv->captured[0] == start )
3582 return start; 3582 return start;
3583 start--; 3583 start--;
3584 } 3584 }
3585 return -1; 3585 return -1;
3586} 3586}
3587 3587
3588/*! \overload 3588/*! \overload
3589 3589
3590 This version does not set matchedLength(), capturedText() and friends. 3590 This version does not set matchedLength(), capturedText() and friends.
3591*/ 3591*/
3592int QRegExp3::searchRev( const QString& str, int start ) const 3592int QRegExp3::searchRev( const QString& str, int start ) const
3593{ 3593{
3594 if ( start < 0 ) 3594 if ( start < 0 )
3595 start += str.length(); 3595 start += str.length();
3596 if ( start < 0 || start > (int) str.length() ) 3596 if ( start < 0 || start > (int) str.length() )
3597 return -1; 3597 return -1;
3598 3598
3599 while ( start >= 0 ) { 3599 while ( start >= 0 ) {
3600 if ( eng->match(str, start, priv->min, TRUE)[0] == start ) 3600 if ( eng->match(str, start, priv->min, TRUE)[0] == start )
3601 return start; 3601 return start;
3602 start--; 3602 start--;
3603 } 3603 }
3604 return -1; 3604 return -1;
3605} 3605}
3606 3606
3607/*! 3607/*!
3608 Returns the length of the last matched string, or -1 if there was no match. 3608 Returns the length of the last matched string, or -1 if there was no match.
3609 3609
3610 \sa match() search() 3610 \sa match() search()
3611*/ 3611*/
3612int QRegExp3::matchedLength() 3612int QRegExp3::matchedLength()
3613{ 3613{
3614 return priv->captured[1]; 3614 return priv->captured[1];
3615} 3615}
3616 3616
3617#ifndef QT_NO_REGEXP_CAPTURE 3617#ifndef QT_NO_REGEXP_CAPTURE
3618/*! 3618/*!
3619 Returns a list of the captured text strings. 3619 Returns a list of the captured text strings.
3620 3620
3621 The first string in the list is the entire matched string. Each 3621 The first string in the list is the entire matched string. Each
3622 subsequent list element contains a string that matched a 3622 subsequent list element contains a string that matched a
3623 (capturing) subexpression of the regexp. 3623 (capturing) subexpression of the regexp.
3624 3624
3625 For example: 3625 For example:
3626 \code 3626 \code
3627 QRegExp3 rx( "(\\d+)(\\s*)(cm|inch(es)?)" ); 3627 QRegExp3 rx( "(\\d+)(\\s*)(cm|inch(es)?)" );
3628 int pos = rx.search( "Length: 36 inches" ); 3628 int pos = rx.search( "Length: 36 inches" );
3629 QStringList list = rx.capturedTexts(); 3629 QStringList list = rx.capturedTexts();
3630 // list is now ( "36 inches", "36", " ", "inches", "es" ). 3630 // list is now ( "36 inches", "36", " ", "inches", "es" ).
3631 \endcode 3631 \endcode
3632 3632
3633 The above example also captures elements 3633 The above example also captures elements
3634 that may be present but which we have no interest in. This problem 3634 that may be present but which we have no interest in. This problem
3635 can be solved by using non-capturing parenthesis: 3635 can be solved by using non-capturing parenthesis:
3636 3636
3637 \code 3637 \code
3638 QRegExp3 rx( "(\\d+)(?:\\s*)(cm|inch(?:es)?)" ); 3638 QRegExp3 rx( "(\\d+)(?:\\s*)(cm|inch(?:es)?)" );
3639 int pos = rx.search( "Length: 36 inches" ); 3639 int pos = rx.search( "Length: 36 inches" );
3640 QStringList list = rx.capturedTexts(); 3640 QStringList list = rx.capturedTexts();
3641 // list is now ( "36 inches", "36", "inches" ). 3641 // list is now ( "36 inches", "36", "inches" ).
3642 \endcode 3642 \endcode
3643 3643
3644 Some regexps can match an indeterminate number of times. For example 3644 Some regexps can match an indeterminate number of times. For example
3645 if the input string is "Offsets: 12 14 99 231 7" and the regexp, 3645 if the input string is "Offsets: 12 14 99 231 7" and the regexp,
3646 <tt>rx</tt>, is <b>(</b><b>\\</b><b>d+)+</b>, we would hope to get a 3646 <tt>rx</tt>, is <b>(</b><b>\\</b><b>d+)+</b>, we would hope to get a
3647 list of all the numbers matched. However, after calling 3647 list of all the numbers matched. However, after calling
3648 <tt>rx.search(str)</tt>, capturedTexts() will return the list ( "12", 3648 <tt>rx.search(str)</tt>, capturedTexts() will return the list ( "12",
3649 "12" ), i.e. the entire match was "12" and the first subexpression 3649 "12" ), i.e. the entire match was "12" and the first subexpression
3650 matched was "12". The correct approach is to use cap() in a 3650 matched was "12". The correct approach is to use cap() in a
3651 <a href="#cap_in_a_loop">loop</a>. 3651 <a href="#cap_in_a_loop">loop</a>.
3652 3652
3653 The order of elements in the string list is as follows. The first 3653 The order of elements in the string list is as follows. The first
3654 element is the entire matching string. Each subsequent element 3654 element is the entire matching string. Each subsequent element
3655 corresponds to the next capturing open left parenthesis. Thus 3655 corresponds to the next capturing open left parenthesis. Thus
3656 capturedTexts()[1] is the text of the first capturing parenthesis, 3656 capturedTexts()[1] is the text of the first capturing parenthesis,
3657 capturedTexts()[2] is the text of the second and so on (corresponding 3657 capturedTexts()[2] is the text of the second and so on (corresponding
3658 to $1, $2 etc. in some other regexp languages). 3658 to $1, $2 etc. in some other regexp languages).
3659 3659
3660 \sa cap() pos() 3660 \sa cap() pos()
3661*/ 3661*/
3662QStringList QRegExp3::capturedTexts() 3662QStringList QRegExp3::capturedTexts()
3663{ 3663{
3664 if ( priv->capturedCache.isEmpty() ) { 3664 if ( priv->capturedCache.isEmpty() ) {
3665 for ( int i = 0; i < (int) priv->captured.size(); i += 2 ) { 3665 for ( int i = 0; i < (int) priv->captured.size(); i += 2 ) {
3666 QString m; 3666 QString m;
3667 if ( priv->captured[i + 1] == 0 ) 3667 if ( priv->captured[i + 1] == 0 )
3668 m = QString::fromLatin1( "" ); 3668 m = QString::fromLatin1( "" );
3669 else if ( priv->captured[i] >= 0 ) 3669 else if ( priv->captured[i] >= 0 )
3670 m = priv->t.mid( priv->captured[i], 3670 m = priv->t.mid( priv->captured[i],
3671 priv->captured[i + 1] ); 3671 priv->captured[i + 1] );
3672 priv->capturedCache.append( m ); 3672 priv->capturedCache.append( m );
3673 } 3673 }
3674 priv->t = QString::null; 3674 priv->t = QString::null;
3675 } 3675 }
3676 return priv->capturedCache; 3676 return priv->capturedCache;
3677} 3677}
3678 3678
3679/*! Returns the text captured by the \a nth subexpression. The entire match 3679/*! Returns the text captured by the \a nth subexpression. The entire match
3680 has index 0 and the parenthesised subexpressions have indices starting 3680 has index 0 and the parenthesised subexpressions have indices starting
3681 from 1 (excluding non-capturing parenthesis). 3681 from 1 (excluding non-capturing parenthesis).
3682 3682
3683 \code 3683 \code
3684 QRegExp3 rxlen( "(\\d+)(?:\\s*)(cm|inch)" ); 3684 QRegExp3 rxlen( "(\\d+)(?:\\s*)(cm|inch)" );
3685 int pos = rxlen.search( "Length: 189cm" ); 3685 int pos = rxlen.search( "Length: 189cm" );
3686 if ( pos > -1 ) { 3686 if ( pos > -1 ) {
3687 QString value = rxlen.cap( 1 ); // "189" 3687 QString value = rxlen.cap( 1 ); // "189"
3688 QString unit = rxlen.cap( 2 ); // "cm" 3688 QString unit = rxlen.cap( 2 ); // "cm"
3689 // ... 3689 // ...
3690 } 3690 }
3691 \endcode 3691 \endcode
3692 3692
3693 <a name="cap_in_a_loop"> 3693 <a name="cap_in_a_loop">
3694 Some patterns may lead to a number of matches which cannot be 3694 Some patterns may lead to a number of matches which cannot be
3695 determined in advance, for example:</a> 3695 determined in advance, for example:</a>
3696 3696
3697 \code 3697 \code
3698 QRegExp3 rx( "(\\d+)" ); 3698 QRegExp3 rx( "(\\d+)" );
3699 str = "Offsets: 12 14 99 231 7"; 3699 str = "Offsets: 12 14 99 231 7";
3700 QStringList list; 3700 QStringList list;
3701 pos = 0; 3701 pos = 0;
3702 while ( pos >= 0 ) { 3702 while ( pos >= 0 ) {
3703 pos = rx.search( str, pos ); 3703 pos = rx.search( str, pos );
3704 if ( pos > -1 ) { 3704 if ( pos > -1 ) {
3705 list += rx.cap( 1 ); 3705 list += rx.cap( 1 );
3706 pos += rx.matchedLength(); 3706 pos += rx.matchedLength();
3707 } 3707 }
3708 } 3708 }
3709 // list contains: ( "12", "14", "99", "231", "7" ). 3709 // list contains: ( "12", "14", "99", "231", "7" ).
3710 \endcode 3710 \endcode
3711 3711
3712 The order of elements matched by cap() is as follows. The first 3712 The order of elements matched by cap() is as follows. The first
3713 element, cap( 0 ), is the entire matching string. Each subsequent 3713 element, cap( 0 ), is the entire matching string. Each subsequent
3714 element corresponds to the next capturing open left parenthesis. Thus 3714 element corresponds to the next capturing open left parenthesis. Thus
3715 cap( 1 ) is the text of the first capturing parenthesis, cap( 2 ) is 3715 cap( 1 ) is the text of the first capturing parenthesis, cap( 2 ) is
3716 the text of the second and so on. 3716 the text of the second and so on.
3717 3717
3718 \sa search() pos() capturedTexts() 3718 \sa search() pos() capturedTexts()
3719*/ 3719*/
3720QString QRegExp3::cap( int nth ) 3720QString QRegExp3::cap( int nth )
3721{ 3721{
3722 if ( nth < 0 || nth >= (int) priv->captured.size() / 2 ) 3722 if ( nth < 0 || nth >= (int) priv->captured.size() / 2 )
3723 return QString::null; 3723 return QString::null;
3724 else 3724 else
3725 return capturedTexts()[nth]; 3725 return capturedTexts()[nth];
3726} 3726}
3727 3727
3728/*! Returns the position of the \a nth captured text in the 3728/*! Returns the position of the \a nth captured text in the
3729 searched string. If \a nth is 0 (the default), pos() returns the 3729 searched string. If \a nth is 0 (the default), pos() returns the
3730 position of the whole match. 3730 position of the whole match.
3731 3731
3732 Example: 3732 Example:
3733 \code 3733 \code
3734 QRegExp3 rx( "/([a-z]+)/([a-z]+)" ); 3734 QRegExp3 rx( "/([a-z]+)/([a-z]+)" );
3735 rx.search( "Output /dev/null" ); // Returns 7 (position of /dev/null) 3735 rx.search( "Output /dev/null" ); // Returns 7 (position of /dev/null)
3736 rx.pos( 0 ); // Returns 7 (position of /dev/null) 3736 rx.pos( 0 ); // Returns 7 (position of /dev/null)
3737 rx.pos( 1 ); // Returns 8 (position of dev) 3737 rx.pos( 1 ); // Returns 8 (position of dev)
3738 rx.pos( 2 ); // Returns 12 (position of null) 3738 rx.pos( 2 ); // Returns 12 (position of null)
3739 \endcode 3739 \endcode
3740 3740
3741 Note that pos() returns -1 for zero-length matches. (For example, if 3741 Note that pos() returns -1 for zero-length matches. (For example, if
3742 cap(4) would return an empty string, pos(4) returns -1.) This is due 3742 cap(4) would return an empty string, pos(4) returns -1.) This is due
3743 to an implementation tradeoff. 3743 to an implementation tradeoff.
3744 3744
3745 \sa capturedTexts() cap() 3745 \sa capturedTexts() cap()
3746*/ 3746*/
3747int QRegExp3::pos( int nth ) 3747int QRegExp3::pos( int nth )
3748{ 3748{
3749 if ( nth < 0 || nth >= (int) priv->captured.size() / 2 ) 3749 if ( nth < 0 || nth >= (int) priv->captured.size() / 2 )
3750 return -1; 3750 return -1;
3751 else 3751 else
3752 return priv->captured[2 * nth]; 3752 return priv->captured[2 * nth];
3753} 3753}
3754#endif 3754#endif
3755 3755
3756void QRegExp3::compile( bool caseSensitive ) 3756void QRegExp3::compile( bool caseSensitive )
3757{ 3757{
3758 derefEngine( eng, priv->rxpattern ); 3758 derefEngine( eng, priv->rxpattern );
3759#ifndef QT_NO_REGEXP_WILDCARD 3759#ifndef QT_NO_REGEXP_WILDCARD
3760 if ( priv->wc ) 3760 if ( priv->wc )
3761 priv->rxpattern = wc2rx( priv->pattern ); 3761 priv->rxpattern = wc2rx( priv->pattern );
3762 else 3762 else
3763#endif 3763#endif
3764 priv->rxpattern = priv->pattern.isNull() ? QString::fromLatin1( "" ) 3764 priv->rxpattern = priv->pattern.isNull() ? QString::fromLatin1( "" )
3765 : priv->pattern; 3765 : priv->pattern;
3766 eng = newEngine( priv->rxpattern, caseSensitive ); 3766 eng = newEngine( priv->rxpattern, caseSensitive );
3767#ifndef QT_NO_REGEXP_CAPTURE 3767#ifndef QT_NO_REGEXP_CAPTURE
3768 priv->t = QString::null; 3768 priv->t = QString::null;
3769 priv->capturedCache.clear(); 3769 priv->capturedCache.clear();
3770#endif 3770#endif
3771 priv->captured.detach(); 3771 priv->captured.detach();
3772 priv->captured.fill( -1, 2 + 2 * eng->numCaptures() ); 3772 priv->captured.fill( -1, 2 + 2 * eng->numCaptures() );
3773} 3773}
diff --git a/noncore/apps/tinykate/libkate/qt3back/qregexp3.h b/noncore/apps/tinykate/libkate/qt3back/qregexp3.h
index 5b75131..fd6bc78 100644
--- a/noncore/apps/tinykate/libkate/qt3back/qregexp3.h
+++ b/noncore/apps/tinykate/libkate/qt3back/qregexp3.h
@@ -1,111 +1,111 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Definition of QRegExp class 4** Definition of QRegExp class
5** 5**
6** Created : 950126 6** Created : 950126
7** 7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9** 9**
10** This file is part of the tools module of the Qt GUI Toolkit. 10** This file is part of the tools module of the Qt GUI Toolkit.
11** 11**
12** This file may be distributed under the terms of the Q Public License 12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file 13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file. 14** LICENSE.QPL included in the packaging of this file.
15** 15**
16** This file may be distributed and/or modified under the terms of the 16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software 17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the 18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file. 19** packaging of this file.
20** 20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License 22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software. 23** Agreement provided with the Software.
24** 24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27** 27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements. 29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information. 30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information. 31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32** 32**
33** Contact info@trolltech.com if any conditions of this licensing are 33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you. 34** not clear to you.
35** 35**
36**********************************************************************/ 36**********************************************************************/
37 37
38#ifndef QREGEXP3_H 38#ifndef QREGEXP3_H
39#define QREGEXP3_H 39#define QREGEXP3_H
40#ifndef QT_H 40#ifndef QT_H
41#include "qstringlist.h" 41#include "qstringlist.h"
42#endif // QT_H 42#endif // QT_H
43 43
44 44
45#if QT_VERSION >=300 45#if QT_VERSION >= 0x030000
46#include <qregexp.h> 46#include <qregexp.h>
47#else 47#else
48class QRegExpEngine; 48class QRegExpEngine;
49struct QRegExpPrivate; 49struct QRegExpPrivate;
50 50
51class Q_EXPORT QRegExp3 51class Q_EXPORT QRegExp3
52{ 52{
53public: 53public:
54 QRegExp3(); 54 QRegExp3();
55 QRegExp3( const QString& pattern, bool caseSensitive = TRUE, 55 QRegExp3( const QString& pattern, bool caseSensitive = TRUE,
56 bool wildcard = FALSE ); 56 bool wildcard = FALSE );
57 QRegExp3( const QRegExp3& rx ); 57 QRegExp3( const QRegExp3& rx );
58 ~QRegExp3(); 58 ~QRegExp3();
59 QRegExp3& operator=( const QRegExp3& rx ); 59 QRegExp3& operator=( const QRegExp3& rx );
60 60
61 bool operator==( const QRegExp3& rx ) const; 61 bool operator==( const QRegExp3& rx ) const;
62 bool operator!=( const QRegExp3& rx ) const { return !operator==( rx ); } 62 bool operator!=( const QRegExp3& rx ) const { return !operator==( rx ); }
63 63
64 bool isEmpty() const; 64 bool isEmpty() const;
65 bool isValid() const; 65 bool isValid() const;
66 QString pattern() const; 66 QString pattern() const;
67 void setPattern( const QString& pattern ); 67 void setPattern( const QString& pattern );
68 bool caseSensitive() const; 68 bool caseSensitive() const;
69 void setCaseSensitive( bool sensitive ); 69 void setCaseSensitive( bool sensitive );
70#ifndef QT_NO_REGEXP_WILDCARD 70#ifndef QT_NO_REGEXP_WILDCARD
71 bool wildcard() const; 71 bool wildcard() const;
72 void setWildcard( bool wildcard ); 72 void setWildcard( bool wildcard );
73#endif 73#endif
74 bool minimal() const; 74 bool minimal() const;
75 void setMinimal( bool minimal ); 75 void setMinimal( bool minimal );
76 76
77 bool exactMatch( const QString& str ); 77 bool exactMatch( const QString& str );
78 bool exactMatch( const QString& str ) const; 78 bool exactMatch( const QString& str ) const;
79#ifndef QT_NO_COMPAT 79#ifndef QT_NO_COMPAT
80 int match( const QString& str, int index, int *len = 0, 80 int match( const QString& str, int index, int *len = 0,
81 bool indexIsStart = TRUE ); 81 bool indexIsStart = TRUE );
82#endif 82#endif
83 int search( const QString& str, int start = 0 ); 83 int search( const QString& str, int start = 0 );
84 int search( const QString& str, int start = 0 ) const; 84 int search( const QString& str, int start = 0 ) const;
85// QChar versions 85// QChar versions
86#ifdef QCHAR_SUPPORT 86#ifdef QCHAR_SUPPORT
87 int search(const QChar *str,int start=0); 87 int search(const QChar *str,int start=0);
88 int search(const QChar *str,int start=0) const; 88 int search(const QChar *str,int start=0) const;
89 int searchRev(const QChar *str,int start=-1); 89 int searchRev(const QChar *str,int start=-1);
90 int searchRev(const QChar *str,int start=-1) const ; 90 int searchRev(const QChar *str,int start=-1) const ;
91 bool exactMatch(const QChar *str); 91 bool exactMatch(const QChar *str);
92 bool exactMatch(const QChar *str) const; 92 bool exactMatch(const QChar *str) const;
93 // end QChar versions 93 // end QChar versions
94#endif 94#endif
95 int searchRev( const QString& str, int start = -1 ); 95 int searchRev( const QString& str, int start = -1 );
96 int searchRev( const QString& str, int start = -1 ) const; 96 int searchRev( const QString& str, int start = -1 ) const;
97 int matchedLength(); 97 int matchedLength();
98#ifndef QT_NO_REGEXP_CAPTURE 98#ifndef QT_NO_REGEXP_CAPTURE
99 QStringList capturedTexts(); 99 QStringList capturedTexts();
100 QString cap( int nth = 0 ); 100 QString cap( int nth = 0 );
101 int pos( int nth = 0 ); 101 int pos( int nth = 0 );
102#endif 102#endif
103 103
104private: 104private:
105 void compile( bool caseSensitive ); 105 void compile( bool caseSensitive );
106 106
107 QRegExpEngine *eng; 107 QRegExpEngine *eng;
108 QRegExpPrivate *priv; 108 QRegExpPrivate *priv;
109}; 109};
110#endif // QT_VERSION >= 300 110#endif // QT_VERSION >= 0x030000
111#endif // QREGEXP_H 111#endif // QREGEXP_H
diff --git a/noncore/apps/zsafe/shadedlistitem.cpp b/noncore/apps/zsafe/shadedlistitem.cpp
index 72c6261..7f340f9 100644
--- a/noncore/apps/zsafe/shadedlistitem.cpp
+++ b/noncore/apps/zsafe/shadedlistitem.cpp
@@ -1,69 +1,69 @@
1/* 1/*
2 * shadedlistitem.cpp 2 * shadedlistitem.cpp
3 * 3 *
4 * (c) 2003 by Jeremy Bowman <jmbowman@alum.mit.edu> 4 * (c) 2003 by Jeremy Bowman <jmbowman@alum.mit.edu>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or 8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version. 9 * (at your option) any later version.
10 */ 10 */
11 11
12#include "zsafe.h" 12#include "zsafe.h"
13#include "shadedlistitem.h" 13#include "shadedlistitem.h"
14 14
15 15
16ShadedListItem::ShadedListItem(int index, QListViewItem *parent) 16ShadedListItem::ShadedListItem(int index, QListViewItem *parent)
17 : QListViewItem(parent) 17 : QListViewItem(parent)
18{ 18{
19 oddRow = (index % 2 != 0); 19 oddRow = (index % 2 != 0);
20} 20}
21 21
22ShadedListItem::ShadedListItem(int index, QListView *parent) 22ShadedListItem::ShadedListItem(int index, QListView *parent)
23 : QListViewItem(parent), lv(parent) 23 : QListViewItem(parent), lv(parent)
24{ 24{
25 oddRow = (index % 2 != 0); 25 oddRow = (index % 2 != 0);
26} 26}
27 27
28ShadedListItem::ShadedListItem(int index, QListView *parent, QListViewItem *after) 28ShadedListItem::ShadedListItem(int index, QListView *parent, QListViewItem *after)
29 : QListViewItem(parent, after), lv(parent) 29 : QListViewItem(parent, after), lv(parent)
30{ 30{
31 oddRow = (index % 2 != 0); 31 oddRow = (index % 2 != 0);
32} 32}
33 33
34ShadedListItem::ShadedListItem(int index, QListView *parent, QString label1, QString label2, QString label3) 34ShadedListItem::ShadedListItem(int index, QListView *parent, QString label1, QString label2, QString label3)
35 : QListViewItem(parent, label1, label2, label3), lv(parent) 35 : QListViewItem(parent, label1, label2, label3), lv(parent)
36{ 36{
37 oddRow = (index % 2 != 0); 37 oddRow = (index % 2 != 0);
38} 38}
39 39
40ShadedListItem::ShadedListItem(int index, QListView *parent, QListViewItem *after, QString label1, QString label2, QString label3) 40ShadedListItem::ShadedListItem(int index, QListView *parent, QListViewItem *after, QString label1, QString label2, QString label3)
41 : QListViewItem(parent, after, label1, label2, label3), lv(parent) 41 : QListViewItem(parent, after, label1, label2, label3), lv(parent)
42{ 42{
43 oddRow = (index % 2 != 0); 43 oddRow = (index % 2 != 0);
44} 44}
45 45
46ShadedListItem::~ShadedListItem() 46ShadedListItem::~ShadedListItem()
47{ 47{
48 48
49} 49}
50 50
51 51
52void ShadedListItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) 52void ShadedListItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
53{ 53{
54 QColorGroup colors(cg); 54 QColorGroup colors(cg);
55#if QT_VERSION >=300 55#if QT_VERSION >= 0x030000
56 const QColorGroup::ColorRole crole = QColorGroup::Base; 56 const QColorGroup::ColorRole crole = QColorGroup::Base;
57 // const QWidget::BackgroundMode bgmode = lv->viewport()->backgroundMode(); 57 // const QWidget::BackgroundMode bgmode = lv->viewport()->backgroundMode();
58 // const QColorGroup::ColorRole crole = QPalette::backgroundRoleFromMode(bgmode); 58 // const QColorGroup::ColorRole crole = QPalette::backgroundRoleFromMode(bgmode);
59#else 59#else
60 const QColorGroup::ColorRole crole = QColorGroup::Base; 60 const QColorGroup::ColorRole crole = QColorGroup::Base;
61#endif 61#endif
62 if (oddRow) { 62 if (oddRow) {
63 colors.setColor(crole, *ZSafe::oddRowColor); 63 colors.setColor(crole, *ZSafe::oddRowColor);
64 } 64 }
65 else { 65 else {
66 colors.setColor(crole, *ZSafe::evenRowColor); 66 colors.setColor(crole, *ZSafe::evenRowColor);
67 } 67 }
68 QListViewItem::paintCell(p, colors, column, width, alignment); 68 QListViewItem::paintCell(p, colors, column, width, alignment);
69} 69}
diff --git a/noncore/net/wellenreiter/gui/configwindow.cpp b/noncore/net/wellenreiter/gui/configwindow.cpp
index 1670f93..9ec5af9 100644
--- a/noncore/net/wellenreiter/gui/configwindow.cpp
+++ b/noncore/net/wellenreiter/gui/configwindow.cpp
@@ -1,496 +1,496 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
4** This file is part of Wellenreiter II. 4** This file is part of Wellenreiter II.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14**********************************************************************/ 14**********************************************************************/
15 15
16/* LOCAL */ 16/* LOCAL */
17#include "configwindow.h" 17#include "configwindow.h"
18#include "mainwindow.h" 18#include "mainwindow.h"
19#include "protolistview.h" 19#include "protolistview.h"
20 20
21/* OPIE */ 21/* OPIE */
22#include <opie2/onetwork.h> 22#include <opie2/onetwork.h>
23#ifdef QWS 23#ifdef QWS
24#include <opie2/oapplication.h> 24#include <opie2/oapplication.h>
25#include <opie2/oconfig.h> 25#include <opie2/oconfig.h>
26#include <opie2/odevice.h> 26#include <opie2/odevice.h>
27#include <opie2/odebug.h> 27#include <opie2/odebug.h>
28using namespace Opie::Core; 28using namespace Opie::Core;
29using namespace Opie::Net; 29using namespace Opie::Net;
30#endif 30#endif
31 31
32/* QT */ 32/* QT */
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qcheckbox.h> 34#include <qcheckbox.h>
35#include <qcombobox.h> 35#include <qcombobox.h>
36#include <qfile.h> 36#include <qfile.h>
37#include <qlineedit.h> 37#include <qlineedit.h>
38#include <qlayout.h> 38#include <qlayout.h>
39#include <qmap.h> 39#include <qmap.h>
40#include <qpushbutton.h> 40#include <qpushbutton.h>
41#include <qradiobutton.h> 41#include <qradiobutton.h>
42#include <qspinbox.h> 42#include <qspinbox.h>
43#include <qtabwidget.h> 43#include <qtabwidget.h>
44#include <qtoolbutton.h> 44#include <qtoolbutton.h>
45#include <qtextstream.h> 45#include <qtextstream.h>
46 46
47/* STD */ 47/* STD */
48#include <assert.h> 48#include <assert.h>
49 49
50WellenreiterConfigWindow* WellenreiterConfigWindow::_instance = 0; 50WellenreiterConfigWindow* WellenreiterConfigWindow::_instance = 0;
51 51
52WellenreiterConfigWindow::WellenreiterConfigWindow( QWidget * parent, const char * name, WFlags f ) 52WellenreiterConfigWindow::WellenreiterConfigWindow( QWidget * parent, const char * name, WFlags f )
53 :WellenreiterConfigBase( parent, name, true, f ) 53 :WellenreiterConfigBase( parent, name, true, f )
54{ 54{
55 _devicetype[ "cisco" ] = DEVTYPE_CISCO; 55 _devicetype[ "cisco" ] = DEVTYPE_CISCO;
56 _devicetype[ "wlan-ng" ] = DEVTYPE_WLAN_NG; 56 _devicetype[ "wlan-ng" ] = DEVTYPE_WLAN_NG;
57 _devicetype[ "hostap" ] = DEVTYPE_HOSTAP; 57 _devicetype[ "hostap" ] = DEVTYPE_HOSTAP;
58 _devicetype[ "orinoco" ] = DEVTYPE_ORINOCO; 58 _devicetype[ "orinoco" ] = DEVTYPE_ORINOCO;
59 _devicetype[ "<manual>" ] = DEVTYPE_MANUAL; 59 _devicetype[ "<manual>" ] = DEVTYPE_MANUAL;
60 _devicetype[ "<file>" ] = DEVTYPE_FILE; 60 _devicetype[ "<file>" ] = DEVTYPE_FILE;
61 61
62 // gather possible interface names from ONetwork 62 // gather possible interface names from ONetwork
63 ONetwork* net = ONetwork::instance(); 63 ONetwork* net = ONetwork::instance();
64 ONetwork::InterfaceIterator it = net->iterator(); 64 ONetwork::InterfaceIterator it = net->iterator();
65 while ( it.current() ) 65 while ( it.current() )
66 { 66 {
67 if ( it.current()->isWireless() ) 67 if ( it.current()->isWireless() )
68 interfaceName->insertItem( it.current()->name() ); 68 interfaceName->insertItem( it.current()->name() );
69 ++it; 69 ++it;
70 } 70 }
71 71
72 load(); 72 load();
73 73
74 #ifdef Q_WS_X11 // We're on X11: adding an Ok-Button for the Dialog here 74 #ifdef Q_WS_X11 // We're on X11: adding an Ok-Button for the Dialog here
75 QPushButton* okButton = new QPushButton( "ok", this ); 75 QPushButton* okButton = new QPushButton( "ok", this );
76 okButton->show(); 76 okButton->show();
77 WellenreiterConfigBaseLayout->addWidget( okButton, 0, 3 ); //FIXME: rename this in configbase.ui 77 WellenreiterConfigBaseLayout->addWidget( okButton, 0, 3 ); //FIXME: rename this in configbase.ui
78 connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); 78 connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
79 #endif 79 #endif
80 80
81 WellenreiterConfigWindow::_instance = this; 81 WellenreiterConfigWindow::_instance = this;
82 82
83 connect( deviceType, SIGNAL( activated(int) ), this, SLOT( changedDeviceType(int) ) ); 83 connect( deviceType, SIGNAL( activated(int) ), this, SLOT( changedDeviceType(int) ) );
84 connect( newNetworkAction, SIGNAL( activated(int) ), this, SLOT( changedNetworkAction(int) ) ); 84 connect( newNetworkAction, SIGNAL( activated(int) ), this, SLOT( changedNetworkAction(int) ) );
85 connect( newClientAction, SIGNAL( activated(int) ), this, SLOT( changedClientAction(int) ) ); 85 connect( newClientAction, SIGNAL( activated(int) ), this, SLOT( changedClientAction(int) ) );
86 connect( newStationAction, SIGNAL( activated(int) ), this, SLOT( changedStationAction(int) ) ); 86 connect( newStationAction, SIGNAL( activated(int) ), this, SLOT( changedStationAction(int) ) );
87 connect( getCaptureFileName, SIGNAL( clicked() ), this, SLOT( getCaptureFileNameClicked() ) ); 87 connect( getCaptureFileName, SIGNAL( clicked() ), this, SLOT( getCaptureFileNameClicked() ) );
88 88
89 // make the checkbox 'channelAll' control all other channels 89 // make the checkbox 'channelAll' control all other channels
90 connect( channelAll, SIGNAL( stateChanged(int) ), this, SLOT( channelAllClicked(int) ) ); 90 connect( channelAll, SIGNAL( stateChanged(int) ), this, SLOT( channelAllClicked(int) ) );
91 91
92 connect( autodetect, SIGNAL( clicked() ), this, SLOT( performAutodetection() ) ); 92 connect( autodetect, SIGNAL( clicked() ), this, SLOT( performAutodetection() ) );
93 93
94 // hide tab4 (parse) until Wellenreiter 1.2 94 // hide tab4 (parse) until Wellenreiter 1.2
95 tab->removePage( tab_4 ); 95 tab->removePage( tab_4 );
96}; 96};
97 97
98 98
99void WellenreiterConfigWindow::accept() 99void WellenreiterConfigWindow::accept()
100{ 100{
101 save(); 101 save();
102 QDialog::accept(); 102 QDialog::accept();
103} 103}
104 104
105 105
106WellenreiterConfigWindow::~WellenreiterConfigWindow() 106WellenreiterConfigWindow::~WellenreiterConfigWindow()
107{ 107{
108} 108}
109 109
110 110
111void WellenreiterConfigWindow::performAutodetection() 111void WellenreiterConfigWindow::performAutodetection()
112{ 112{
113 //TODO: insert modal splash screen here 113 //TODO: insert modal splash screen here
114 // and sleep a second, so that it looks 114 // and sleep a second, so that it looks
115 // like we're actually doing something fancy... ;-) 115 // like we're actually doing something fancy... ;-)
116 116
117 odebug << "WellenreiterConfigWindow::performAutodetection()" << oendl; 117 odebug << "WellenreiterConfigWindow::performAutodetection()" << oendl;
118 118
119 // try to guess device type 119 // try to guess device type
120 QFile m( "/proc/modules" ); 120 QFile m( "/proc/modules" );
121 if ( m.open( IO_ReadOnly ) ) 121 if ( m.open( IO_ReadOnly ) )
122 { 122 {
123 int devicetype(0); 123 int devicetype(0);
124 QString line; 124 QString line;
125 QTextStream modules( &m ); 125 QTextStream modules( &m );
126 while( !modules.atEnd() && !devicetype ) 126 while( !modules.atEnd() && !devicetype )
127 { 127 {
128 modules >> line; 128 modules >> line;
129 if ( line.contains( "cisco" ) ) devicetype = DEVTYPE_CISCO; 129 if ( line.contains( "cisco" ) ) devicetype = DEVTYPE_CISCO;
130 else if ( line.contains( "hostap" ) ) devicetype = DEVTYPE_HOSTAP; 130 else if ( line.contains( "hostap" ) ) devicetype = DEVTYPE_HOSTAP;
131 else if ( line.contains( "prism" ) ) devicetype = DEVTYPE_WLAN_NG; 131 else if ( line.contains( "prism" ) ) devicetype = DEVTYPE_WLAN_NG;
132 else if ( line.contains( "orinoco" ) ) devicetype = DEVTYPE_ORINOCO; 132 else if ( line.contains( "orinoco" ) ) devicetype = DEVTYPE_ORINOCO;
133 } 133 }
134 if ( devicetype ) 134 if ( devicetype )
135 { 135 {
136 deviceType->setCurrentItem( devicetype ); 136 deviceType->setCurrentItem( devicetype );
137 _guess = devicetype; 137 _guess = devicetype;
138 odebug << "Wellenreiter: guessed device type to be #" << devicetype << "" << oendl; 138 odebug << "Wellenreiter: guessed device type to be #" << devicetype << "" << oendl;
139 } 139 }
140 } 140 }
141} 141}
142 142
143 143
144int WellenreiterConfigWindow::driverType() const 144int WellenreiterConfigWindow::driverType() const
145{ 145{
146 QString name = deviceType->currentText(); 146 QString name = deviceType->currentText();
147 if ( _devicetype.contains( name ) ) 147 if ( _devicetype.contains( name ) )
148 { 148 {
149 return _devicetype[name]; 149 return _devicetype[name];
150 } 150 }
151 else 151 else
152 { 152 {
153 return 0; 153 return 0;
154 } 154 }
155}; 155};
156 156
157 157
158int WellenreiterConfigWindow::hoppingInterval() const 158int WellenreiterConfigWindow::hoppingInterval() const
159{ 159{
160 return hopInterval->cleanText().toInt(); 160 return hopInterval->cleanText().toInt();
161} 161}
162 162
163 163
164bool WellenreiterConfigWindow::usePrismHeader() const 164bool WellenreiterConfigWindow::usePrismHeader() const
165{ 165{
166 return prismHeader->isChecked(); 166 return prismHeader->isChecked();
167} 167}
168 168
169 169
170bool WellenreiterConfigWindow::isChannelChecked( int channel ) const 170bool WellenreiterConfigWindow::isChannelChecked( int channel ) const
171{ 171{
172 switch ( channel ) 172 switch ( channel )
173 { 173 {
174 case 1: return channel1->isOn(); 174 case 1: return channel1->isOn();
175 case 2: return channel2->isOn(); 175 case 2: return channel2->isOn();
176 case 3: return channel3->isOn(); 176 case 3: return channel3->isOn();
177 case 4: return channel4->isOn(); 177 case 4: return channel4->isOn();
178 case 5: return channel5->isOn(); 178 case 5: return channel5->isOn();
179 case 6: return channel6->isOn(); 179 case 6: return channel6->isOn();
180 case 7: return channel7->isOn(); 180 case 7: return channel7->isOn();
181 case 8: return channel8->isOn(); 181 case 8: return channel8->isOn();
182 case 9: return channel9->isOn(); 182 case 9: return channel9->isOn();
183 case 10: return channel10->isOn(); 183 case 10: return channel10->isOn();
184 case 11: return channel11->isOn(); 184 case 11: return channel11->isOn();
185 case 12: return channel12->isOn(); 185 case 12: return channel12->isOn();
186 case 13: return channel13->isOn(); 186 case 13: return channel13->isOn();
187 case 14: return channel14->isOn(); 187 case 14: return channel14->isOn();
188 default: return false; 188 default: return false;
189 } 189 }
190 190
191 191
192} 192}
193 193
194 194
195void WellenreiterConfigWindow::changedDeviceType(int t) 195void WellenreiterConfigWindow::changedDeviceType(int t)
196{ 196{
197 if ( t != DEVTYPE_FILE ) return; 197 if ( t != DEVTYPE_FILE ) return;
198 QString name = ( (WellenreiterMainWindow*) qApp->mainWidget() )->getFileName(false); 198 QString name = ( (WellenreiterMainWindow*) qApp->mainWidget() )->getFileName(false);
199 if ( !name.isEmpty() && QFile::exists( name ) ) 199 if ( !name.isEmpty() && QFile::exists( name ) )
200 { 200 {
201 interfaceName->insertItem( name ); 201 interfaceName->insertItem( name );
202 interfaceName->setCurrentItem( interfaceName->count()-1 ); 202 interfaceName->setCurrentItem( interfaceName->count()-1 );
203 } 203 }
204 else 204 else
205 { 205 {
206 deviceType->setCurrentItem( _guess ); 206 deviceType->setCurrentItem( _guess );
207 } 207 }
208 208
209} 209}
210 210
211 211
212void WellenreiterConfigWindow::synchronizeActionsAndScripts() 212void WellenreiterConfigWindow::synchronizeActionsAndScripts()
213{ 213{
214 if ( newNetworkAction->currentItem() == 4 ) newNetworkScript->show(); else newNetworkScript->hide(); 214 if ( newNetworkAction->currentItem() == 4 ) newNetworkScript->show(); else newNetworkScript->hide();
215 if ( newClientAction->currentItem() == 4 ) newClientScript->show(); else newClientScript->hide(); 215 if ( newClientAction->currentItem() == 4 ) newClientScript->show(); else newClientScript->hide();
216 if ( newStationAction->currentItem() == 4 ) newStationScript->show(); else newStationScript->hide(); 216 if ( newStationAction->currentItem() == 4 ) newStationScript->show(); else newStationScript->hide();
217 217
218 //newNetworkScript->setEnabled( newNetworkAction->currentItem() == 4 ); 218 //newNetworkScript->setEnabled( newNetworkAction->currentItem() == 4 );
219 //newClientScript->setEnabled( newClientAction->currentItem() == 4 ); 219 //newClientScript->setEnabled( newClientAction->currentItem() == 4 );
220 //newStationScript->setEnabled( newStationAction->currentItem() == 4 ); 220 //newStationScript->setEnabled( newStationAction->currentItem() == 4 );
221} 221}
222 222
223 223
224void WellenreiterConfigWindow::changedNetworkAction(int ) 224void WellenreiterConfigWindow::changedNetworkAction(int )
225{ 225{
226 synchronizeActionsAndScripts(); 226 synchronizeActionsAndScripts();
227} 227}
228 228
229 229
230void WellenreiterConfigWindow::changedClientAction(int ) 230void WellenreiterConfigWindow::changedClientAction(int )
231{ 231{
232 synchronizeActionsAndScripts(); 232 synchronizeActionsAndScripts();
233} 233}
234 234
235 235
236void WellenreiterConfigWindow::changedStationAction(int ) 236void WellenreiterConfigWindow::changedStationAction(int )
237{ 237{
238 synchronizeActionsAndScripts(); 238 synchronizeActionsAndScripts();
239} 239}
240 240
241 241
242void WellenreiterConfigWindow::getCaptureFileNameClicked() 242void WellenreiterConfigWindow::getCaptureFileNameClicked()
243{ 243{
244 QString name = ( (WellenreiterMainWindow*) qApp->mainWidget() )->getFileName(true); 244 QString name = ( (WellenreiterMainWindow*) qApp->mainWidget() )->getFileName(true);
245 odebug << "name = " << name << "" << oendl; 245 odebug << "name = " << name << "" << oendl;
246 if ( !name.isEmpty() ) 246 if ( !name.isEmpty() )
247 { 247 {
248 captureFileName->setText( name ); 248 captureFileName->setText( name );
249 } 249 }
250} 250}
251 251
252 252
253void WellenreiterConfigWindow::channelAllClicked(int state) 253void WellenreiterConfigWindow::channelAllClicked(int state)
254{ 254{
255 bool b = state; 255 bool b = state;
256 channel1->setChecked( b ); 256 channel1->setChecked( b );
257 channel2->setChecked( b ); 257 channel2->setChecked( b );
258 channel3->setChecked( b ); 258 channel3->setChecked( b );
259 channel4->setChecked( b ); 259 channel4->setChecked( b );
260 channel5->setChecked( b ); 260 channel5->setChecked( b );
261 channel6->setChecked( b ); 261 channel6->setChecked( b );
262 channel7->setChecked( b ); 262 channel7->setChecked( b );
263 channel8->setChecked( b ); 263 channel8->setChecked( b );
264 channel9->setChecked( b ); 264 channel9->setChecked( b );
265 channel10->setChecked( b ); 265 channel10->setChecked( b );
266 channel11->setChecked( b ); 266 channel11->setChecked( b );
267 channel12->setChecked( b ); 267 channel12->setChecked( b );
268 channel13->setChecked( b ); 268 channel13->setChecked( b );
269 channel14->setChecked( b ); 269 channel14->setChecked( b );
270} 270}
271 271
272 272
273bool WellenreiterConfigWindow::useGPS() const 273bool WellenreiterConfigWindow::useGPS() const
274{ 274{
275 return enableGPS->isChecked(); 275 return enableGPS->isChecked();
276} 276}
277 277
278 278
279const QString WellenreiterConfigWindow::gpsHost() const 279const QString WellenreiterConfigWindow::gpsHost() const
280{ 280{
281 return useGPS() ? gpsdHost->currentText() : QString::null; 281 return useGPS() ? gpsdHost->currentText() : QString::null;
282} 282}
283 283
284 284
285int WellenreiterConfigWindow::gpsPort() const 285int WellenreiterConfigWindow::gpsPort() const
286{ 286{
287 return useGPS() ? gpsdPort->value() : -1; 287 return useGPS() ? gpsdPort->value() : -1;
288} 288}
289 289
290 290
291void WellenreiterConfigWindow::performAction( const QString& type, 291void WellenreiterConfigWindow::performAction( const QString& type,
292 const QString& essid, 292 const QString& essid,
293 const QString& mac, 293 const QString& mac,
294 bool wep, 294 bool wep,
295 int channel, 295 int channel,
296 int /* signal */ 296 int /* signal */
297 /* , const GpsLocation& loc */ ) 297 /* , const GpsLocation& loc */ )
298{ 298{
299 int action; 299 int action;
300 QString script; 300 QString script;
301 301
302 if ( type == "network" ) 302 if ( type == "network" )
303 { 303 {
304 action = newNetworkAction->currentItem(); 304 action = newNetworkAction->currentItem();
305 script = newNetworkScript->text(); 305 script = newNetworkScript->text();
306 } 306 }
307 else if ( type == "managed" || type == "adhoc" ) 307 else if ( type == "managed" || type == "adhoc" )
308 { 308 {
309 action = newClientAction->currentItem(); 309 action = newClientAction->currentItem();
310 script = newClientScript->text(); 310 script = newClientScript->text();
311 } 311 }
312 else if ( type == "station" ) 312 else if ( type == "station" )
313 { 313 {
314 action = newStationAction->currentItem(); 314 action = newStationAction->currentItem();
315 script = newStationScript->text(); 315 script = newStationScript->text();
316 } 316 }
317 else 317 else
318 { 318 {
319 owarn << "WellenreiterConfigWindow::performAction(): unknown type '" << type << "'" << oendl; 319 owarn << "WellenreiterConfigWindow::performAction(): unknown type '" << type << "'" << oendl;
320 return; 320 return;
321 } 321 }
322 322
323 odebug << "for event '" << type << "' I'm going to perform action " << action << " (script='" << script << "')" << oendl; 323 odebug << "for event '" << type << "' I'm going to perform action " << action << " (script='" << script << "')" << oendl;
324 324
325 switch( action ) 325 switch( action )
326 { 326 {
327 case 0: /* Ignore */ return; 327 case 0: /* Ignore */ return;
328 case 1: /* Play Alarm */ ODevice::inst()->playAlarmSound(); return; 328 case 1: /* Play Alarm */ ODevice::inst()->playAlarmSound(); return;
329 case 2: /* Play Click */ ODevice::inst()->playTouchSound(); return; 329 case 2: /* Play Click */ ODevice::inst()->playTouchSound(); return;
330 case 3: /* Blink LED */ break; //FIXME: Implement this 330 case 3: /* Blink LED */ break; //FIXME: Implement this
331 case 4: /* Run Script */ 331 case 4: /* Run Script */
332 { 332 {
333 /** 333 /**
334 * 334 *
335 * Script Substitution Information: 335 * Script Substitution Information:
336 * 336 *
337 * $SSID = SSID 337 * $SSID = SSID
338 * $MAC = MAC 338 * $MAC = MAC
339 * $WEP = Wep 339 * $WEP = Wep
340 * $CHAN = Channel 340 * $CHAN = Channel
341 * 341 *
342 **/ 342 **/
343 script = script.replace( QRegExp( "$SSID" ), essid ); 343 script = script.replace( QRegExp( "$SSID" ), essid );
344 script = script.replace( QRegExp( "$MAC" ), mac ); 344 script = script.replace( QRegExp( "$MAC" ), mac );
345 script = script.replace( QRegExp( "$WEP" ), wep ? QString( "true" ) : QString( "false" ) ); 345 script = script.replace( QRegExp( "$WEP" ), wep ? QString( "true" ) : QString( "false" ) );
346 script = script.replace( QRegExp( "$CHAN" ), QString::number( channel ) ); 346 script = script.replace( QRegExp( "$CHAN" ), QString::number( channel ) );
347 347
348 odebug << "going to call script '" << script << "'" << oendl; 348 odebug << "going to call script '" << script << "'" << oendl;
349 ::system( script ); 349 ::system( script );
350 odebug << "script returned." << oendl; 350 odebug << "script returned." << oendl;
351 return; 351 return;
352 } 352 }
353 default: assert( false ); 353 default: assert( false );
354 } 354 }
355} 355}
356 356
357 357
358void WellenreiterConfigWindow::load() 358void WellenreiterConfigWindow::load()
359{ 359{
360#ifdef Q_WS_X11 360#ifdef Q_WS_X11
361 #warning Persistent Configuration not yet implemented for standalone X11 build 361 #warning Persistent Configuration not yet implemented for standalone X11 build
362 performAutodetection(); 362 performAutodetection();
363#else 363#else
364 odebug << "loading configuration settings..." << oendl; 364 odebug << "loading configuration settings..." << oendl;
365 365
366 /* This is dumb monkey typing stuff... We _need_ to do this automatically! */ 366 /* This is dumb monkey typing stuff... We _need_ to do this automatically! */
367 367
368 OConfig* c = oApp->config(); 368 OConfig* c = oApp->config();
369 369
370 c->setGroup( "Interface" ); 370 c->setGroup( "Interface" );
371 371
372 QString interface = c->readEntry( "name", "<none>" ); 372 QString interface = c->readEntry( "name", "<none>" );
373 if ( interface != "<none>" ) 373 if ( interface != "<none>" )
374 { 374 {
375#if QT_VERSION < 300 375#if QT_VERSION < 0x030000
376 interfaceName->insertItem( interface, 0 ); 376 interfaceName->insertItem( interface, 0 );
377 interfaceName->setCurrentItem( 0 ); 377 interfaceName->setCurrentItem( 0 );
378#else 378#else
379 interfaceName->setCurrentText( interface ); 379 interfaceName->setCurrentText( interface );
380#endif 380#endif
381 381
382 QString device = c->readEntry( "type", "<select>" ); 382 QString device = c->readEntry( "type", "<select>" );
383#if QT_VERSION < 300 383#if QT_VERSION < 0x030000
384 for ( int i = 0; i < deviceType->count(); ++i ) 384 for ( int i = 0; i < deviceType->count(); ++i )
385 { 385 {
386 if ( deviceType->text( i ) == device ) 386 if ( deviceType->text( i ) == device )
387 { 387 {
388 deviceType->setCurrentItem( i ); 388 deviceType->setCurrentItem( i );
389 break; 389 break;
390 } 390 }
391 } 391 }
392#else 392#else
393 deviceType->setCurrentText( device ); 393 deviceType->setCurrentText( device );
394#endif 394#endif
395 } 395 }
396 else 396 else
397 { 397 {
398 performAutodetection(); 398 performAutodetection();
399 } 399 }
400 400
401 prismHeader->setChecked( c->readBoolEntry( "prism", false ) ); 401 prismHeader->setChecked( c->readBoolEntry( "prism", false ) );
402 hopChannels->setChecked( c->readBoolEntry( "hop", true ) ); 402 hopChannels->setChecked( c->readBoolEntry( "hop", true ) );
403 hopInterval->setValue( c->readNumEntry( "interval", 250 ) ); 403 hopInterval->setValue( c->readNumEntry( "interval", 250 ) );
404 adaptiveHopping->setChecked( c->readBoolEntry( "adaptive", true ) ); 404 adaptiveHopping->setChecked( c->readBoolEntry( "adaptive", true ) );
405 405
406 c->setGroup( "Capture" ); 406 c->setGroup( "Capture" );
407 writeCaptureFile->setChecked( c->readBoolEntry( "writeCaptureFile", true ) ); 407 writeCaptureFile->setChecked( c->readBoolEntry( "writeCaptureFile", true ) );
408 captureFileName->setEnabled( writeCaptureFile->isChecked() ); 408 captureFileName->setEnabled( writeCaptureFile->isChecked() );
409 getCaptureFileName->setEnabled( writeCaptureFile->isChecked() ); 409 getCaptureFileName->setEnabled( writeCaptureFile->isChecked() );
410 parsePackets->setEnabled( writeCaptureFile->isChecked() ); 410 parsePackets->setEnabled( writeCaptureFile->isChecked() );
411 captureFileName->setText( c->readEntry( "filename", "/tmp/capture" ) ); 411 captureFileName->setText( c->readEntry( "filename", "/tmp/capture" ) );
412 hexViewBufferUnlimited->setChecked( c->readBoolEntry( "hexViewBufferUnlimited", true ) ); 412 hexViewBufferUnlimited->setChecked( c->readBoolEntry( "hexViewBufferUnlimited", true ) );
413 hexViewBufferLimited->setChecked( !c->readBoolEntry( "hexViewBufferUnlimited", true ) ); 413 hexViewBufferLimited->setChecked( !c->readBoolEntry( "hexViewBufferUnlimited", true ) );
414 hexViewBufferSize->setValue( c->readNumEntry( "hexViewBufferSize", 2000 ) ); 414 hexViewBufferSize->setValue( c->readNumEntry( "hexViewBufferSize", 2000 ) );
415 415
416 c->setGroup( "UI" ); 416 c->setGroup( "UI" );
417 lookupVendor->setChecked( c->readBoolEntry( "lookupVendor", true ) ); 417 lookupVendor->setChecked( c->readBoolEntry( "lookupVendor", true ) );
418 openTree->setChecked( c->readBoolEntry( "openTree", true ) ); 418 openTree->setChecked( c->readBoolEntry( "openTree", true ) );
419 disablePM->setChecked( c->readBoolEntry( "disablePM", true ) ); 419 disablePM->setChecked( c->readBoolEntry( "disablePM", true ) );
420 newNetworkAction->setCurrentItem( c->readNumEntry( "newNetworkAction", 1 ) ); // Default: Play Alarm 420 newNetworkAction->setCurrentItem( c->readNumEntry( "newNetworkAction", 1 ) ); // Default: Play Alarm
421 newNetworkScript->setText( c->readEntry( "newNetworkScript", "" ) ); 421 newNetworkScript->setText( c->readEntry( "newNetworkScript", "" ) );
422 newClientAction->setCurrentItem( c->readNumEntry( "newClientAction", 2 ) ); // Default: Play Click 422 newClientAction->setCurrentItem( c->readNumEntry( "newClientAction", 2 ) ); // Default: Play Click
423 newClientScript->setText( c->readEntry( "newClientScript", "" ) ); 423 newClientScript->setText( c->readEntry( "newClientScript", "" ) );
424 newStationAction->setCurrentItem( c->readNumEntry( "newStationAction", 2 ) ); // Default: Play Click 424 newStationAction->setCurrentItem( c->readNumEntry( "newStationAction", 2 ) ); // Default: Play Click
425 newStationScript->setText( c->readEntry( "newStationScript", "" ) ); 425 newStationScript->setText( c->readEntry( "newStationScript", "" ) );
426 synchronizeActionsAndScripts(); // needed for showing/hiding the script QLineEdit on demand 426 synchronizeActionsAndScripts(); // needed for showing/hiding the script QLineEdit on demand
427 427
428 c->setGroup( "GPS" ); 428 c->setGroup( "GPS" );
429 enableGPS->setChecked( c->readBoolEntry( "use", false ) ); 429 enableGPS->setChecked( c->readBoolEntry( "use", false ) );
430#if QT_VERSION < 300 430#if QT_VERSION < 0x030000
431 gpsdHost->insertItem( c->readEntry( "host", "localhost" ), 0 ); 431 gpsdHost->insertItem( c->readEntry( "host", "localhost" ), 0 );
432 gpsdHost->setCurrentItem( 0 ); 432 gpsdHost->setCurrentItem( 0 );
433#else 433#else
434 gpsdHost->setCurrentText( c->readEntry( "host", "localhost" ) ); 434 gpsdHost->setCurrentText( c->readEntry( "host", "localhost" ) );
435#endif 435#endif
436 gpsdPort->setValue( c->readNumEntry( "port", 2947 ) ); 436 gpsdPort->setValue( c->readNumEntry( "port", 2947 ) );
437 startGPS->setChecked( c->readBoolEntry( "start", false ) ); 437 startGPS->setChecked( c->readBoolEntry( "start", false ) );
438 commandGPS->setText( c->readEntry( "command", "gpsd -p /dev/ttyS3 -s 57600" ) ); 438 commandGPS->setText( c->readEntry( "command", "gpsd -p /dev/ttyS3 -s 57600" ) );
439 439
440#endif 440#endif
441} 441}
442 442
443 443
444void WellenreiterConfigWindow::save() 444void WellenreiterConfigWindow::save()
445{ 445{
446#ifdef Q_WS_X11 446#ifdef Q_WS_X11
447 #warning Persistent Configuration not yet implemented for standalone X11 build 447 #warning Persistent Configuration not yet implemented for standalone X11 build
448#else 448#else
449 odebug << "saving configuration settings..." << oendl; 449 odebug << "saving configuration settings..." << oendl;
450 450
451 /* This is dumb monkey typing stuff... We _need_ to do this automatically! */ 451 /* This is dumb monkey typing stuff... We _need_ to do this automatically! */
452 452
453 OConfig* c = oApp->config(); 453 OConfig* c = oApp->config();
454 454
455 c->setGroup( "Interface" ); 455 c->setGroup( "Interface" );
456 c->writeEntry( "name", interfaceName->currentText() ); 456 c->writeEntry( "name", interfaceName->currentText() );
457 c->writeEntry( "type", deviceType->currentText() ); 457 c->writeEntry( "type", deviceType->currentText() );
458 c->writeEntry( "prism", prismHeader->isChecked() ); 458 c->writeEntry( "prism", prismHeader->isChecked() );
459 c->writeEntry( "hop", hopChannels->isChecked() ); 459 c->writeEntry( "hop", hopChannels->isChecked() );
460 c->writeEntry( "interval", hopInterval->value() ); 460 c->writeEntry( "interval", hopInterval->value() );
461 c->writeEntry( "adaptive", adaptiveHopping->isChecked() ); 461 c->writeEntry( "adaptive", adaptiveHopping->isChecked() );
462 462
463 c->setGroup( "Capture" ); 463 c->setGroup( "Capture" );
464 c->writeEntry( "writeCaptureFile", writeCaptureFile->isChecked() ); 464 c->writeEntry( "writeCaptureFile", writeCaptureFile->isChecked() );
465 c->writeEntry( "filename", captureFileName->text() ); 465 c->writeEntry( "filename", captureFileName->text() );
466 c->writeEntry( "hexViewBufferUnlimited", hexViewBufferUnlimited->isChecked() ); 466 c->writeEntry( "hexViewBufferUnlimited", hexViewBufferUnlimited->isChecked() );
467 c->writeEntry( "hexViewBufferSize", hexViewBufferSize->value() ); 467 c->writeEntry( "hexViewBufferSize", hexViewBufferSize->value() );
468 468
469 c->setGroup( "UI" ); 469 c->setGroup( "UI" );
470 c->writeEntry( "lookupVendor", lookupVendor->isChecked() ); 470 c->writeEntry( "lookupVendor", lookupVendor->isChecked() );
471 c->writeEntry( "openTree", openTree->isChecked() ); 471 c->writeEntry( "openTree", openTree->isChecked() );
472 c->writeEntry( "disablePM", disablePM->isChecked() ); 472 c->writeEntry( "disablePM", disablePM->isChecked() );
473 c->writeEntry( "newNetworkAction", newNetworkAction->currentItem() ); 473 c->writeEntry( "newNetworkAction", newNetworkAction->currentItem() );
474 c->writeEntry( "newNetworkScript", newNetworkScript->text() ); 474 c->writeEntry( "newNetworkScript", newNetworkScript->text() );
475 c->writeEntry( "newClientAction", newClientAction->currentItem() ); 475 c->writeEntry( "newClientAction", newClientAction->currentItem() );
476 c->writeEntry( "newClientScript", newClientScript->text() ); 476 c->writeEntry( "newClientScript", newClientScript->text() );
477 c->writeEntry( "newStationAction", newStationAction->currentItem() ); 477 c->writeEntry( "newStationAction", newStationAction->currentItem() );
478 c->writeEntry( "newStationScript", newStationScript->text() ); 478 c->writeEntry( "newStationScript", newStationScript->text() );
479 479
480 c->setGroup( "GPS" ); 480 c->setGroup( "GPS" );
481 c->writeEntry( "use", enableGPS->isChecked() ); 481 c->writeEntry( "use", enableGPS->isChecked() );
482 c->writeEntry( "host", gpsdHost->currentText() ); 482 c->writeEntry( "host", gpsdHost->currentText() );
483 c->writeEntry( "port", gpsdPort->value() ); 483 c->writeEntry( "port", gpsdPort->value() );
484 c->writeEntry( "start", startGPS->isChecked() ); 484 c->writeEntry( "start", startGPS->isChecked() );
485 c->writeEntry( "command", commandGPS->text() ); 485 c->writeEntry( "command", commandGPS->text() );
486 486
487 c->write(); 487 c->write();
488 488
489#endif 489#endif
490} 490}
491 491
492 492
493int WellenreiterConfigWindow::hexViewBuffer() const 493int WellenreiterConfigWindow::hexViewBuffer() const
494{ 494{
495 return hexViewBufferUnlimited->isChecked() ? -1 : hexViewBufferSize->value(); 495 return hexViewBufferUnlimited->isChecked() ? -1 : hexViewBufferSize->value();
496} 496}
diff --git a/noncore/settings/appearance2/appearance.cpp b/noncore/settings/appearance2/appearance.cpp
index 9638686..088171c 100644
--- a/noncore/settings/appearance2/appearance.cpp
+++ b/noncore/settings/appearance2/appearance.cpp
@@ -1,892 +1,892 @@
1/* 1/*
2                This file is part of the OPIE Project 2                This file is part of the OPIE Project
3 Copyright (c) 2002 Trolltech AS <info@trolltech.com> 3 Copyright (c) 2002 Trolltech AS <info@trolltech.com>
4 =. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> 4 =. Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
5             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> 5             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org>
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This file is free software; you can 7 _;:,     .>    :=|. This file is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU General Public 9:`=1 )Y*s>-.--   : the terms of the GNU General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This file is distributed in the hope that 14    .i_,=:_.      -<s. This file is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
19..}^=.=       =       ; Public License for more details. 19..}^=.=       =       ; Public License for more details.
20++=   -.     .`     .: 20++=   -.     .`     .:
21 :     =  ...= . :.=- You should have received a copy of the GNU 21 :     =  ...= . :.=- You should have received a copy of the GNU
22 -.   .:....=;==+<; General Public License along with this file; 22 -.   .:....=;==+<; General Public License along with this file;
23  -_. . .   )=.  = see the file COPYING. If not, write to the 23  -_. . .   )=.  = see the file COPYING. If not, write to the
24    --        :-=` Free Software Foundation, Inc., 24    --        :-=` Free Software Foundation, Inc.,
25 59 Temple Place - Suite 330, 25 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27 27
28*/ 28*/
29 29
30#include "appearance.h" 30#include "appearance.h"
31#include "editScheme.h" 31#include "editScheme.h"
32#include "stylelistitem.h" 32#include "stylelistitem.h"
33#include "decolistitem.h" 33#include "decolistitem.h"
34#include "colorlistitem.h" 34#include "colorlistitem.h"
35#include "exceptlistitem.h" 35#include "exceptlistitem.h"
36#include "sample.h" 36#include "sample.h"
37 37
38/* OPIE */ 38/* OPIE */
39#include <opie2/odevice.h> 39#include <opie2/odevice.h>
40#include <opie2/ofiledialog.h> 40#include <opie2/ofiledialog.h>
41#include <opie2/otabwidget.h> 41#include <opie2/otabwidget.h>
42#include <opie2/odebug.h> 42#include <opie2/odebug.h>
43 43
44#include <qpe/config.h> 44#include <qpe/config.h>
45#include <qpe/global.h> 45#include <qpe/global.h>
46#include <qpe/qpeapplication.h> 46#include <qpe/qpeapplication.h>
47#include <qpe/qpemessagebox.h> 47#include <qpe/qpemessagebox.h>
48#include <qpe/qcopenvelope_qws.h> 48#include <qpe/qcopenvelope_qws.h>
49#include <qpe/qpestyle.h> 49#include <qpe/qpestyle.h>
50#include <qpe/lightstyle.h> 50#include <qpe/lightstyle.h>
51#include <qpe/styleinterface.h> 51#include <qpe/styleinterface.h>
52 52
53/* QT */ 53/* QT */
54#include <qbuttongroup.h> 54#include <qbuttongroup.h>
55#include <qcheckbox.h> 55#include <qcheckbox.h>
56#include <qcombobox.h> 56#include <qcombobox.h>
57#include <qdialog.h> 57#include <qdialog.h>
58#include <qdir.h> 58#include <qdir.h>
59#include <qlabel.h> 59#include <qlabel.h>
60#include <qlayout.h> 60#include <qlayout.h>
61#include <qlineedit.h> 61#include <qlineedit.h>
62#include <qlistbox.h> 62#include <qlistbox.h>
63#include <qmessagebox.h> 63#include <qmessagebox.h>
64#include <qpushbutton.h> 64#include <qpushbutton.h>
65#include <qradiobutton.h> 65#include <qradiobutton.h>
66#if QT_VERSION >= 300 66#if QT_VERSION >= 0x030000
67#include <qstylefactory.h> 67#include <qstylefactory.h>
68#endif 68#endif
69#include <qtoolbutton.h> 69#include <qtoolbutton.h>
70#include <qwindowsstyle.h> 70#include <qwindowsstyle.h>
71#include <qlistview.h> 71#include <qlistview.h>
72#include <qheader.h> 72#include <qheader.h>
73#include <qvbox.h> 73#include <qvbox.h>
74#include <qwhatsthis.h> 74#include <qwhatsthis.h>
75 75
76using namespace Opie; 76using namespace Opie;
77using namespace Opie::Ui; 77using namespace Opie::Ui;
78using namespace Opie::Core; 78using namespace Opie::Core;
79 79
80class DefaultWindowDecoration : public WindowDecorationInterface 80class DefaultWindowDecoration : public WindowDecorationInterface
81{ 81{
82public: 82public:
83 DefaultWindowDecoration() : ref(0) {} 83 DefaultWindowDecoration() : ref(0) {}
84 QString name() const 84 QString name() const
85 { 85 {
86 return "Default"; 86 return "Default";
87 } 87 }
88 QPixmap icon() const 88 QPixmap icon() const
89 { 89 {
90 return QPixmap(); 90 return QPixmap();
91 } 91 }
92 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) 92 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface )
93 { 93 {
94 *iface = 0; 94 *iface = 0;
95 if ( uuid == IID_QUnknown ) 95 if ( uuid == IID_QUnknown )
96 *iface = this; 96 *iface = this;
97 else if ( uuid == IID_WindowDecoration ) 97 else if ( uuid == IID_WindowDecoration )
98 *iface = this; 98 *iface = this;
99 99
100 if ( *iface ) 100 if ( *iface )
101 (*iface)->addRef(); 101 (*iface)->addRef();
102 return QS_OK; 102 return QS_OK;
103 } 103 }
104 Q_REFCOUNT 104 Q_REFCOUNT
105 105
106private: 106private:
107 ulong ref; 107 ulong ref;
108}; 108};
109 109
110 110
111 111
112 112
113 113
114 114
115 115
116QWidget *Appearance::createStyleTab ( QWidget *parent, Config &cfg ) 116QWidget *Appearance::createStyleTab ( QWidget *parent, Config &cfg )
117{ 117{
118 QWidget* tab = new QWidget( parent, "StyleTab" ); 118 QWidget* tab = new QWidget( parent, "StyleTab" );
119 QVBoxLayout* vertLayout = new QVBoxLayout( tab, 3, 3 ); 119 QVBoxLayout* vertLayout = new QVBoxLayout( tab, 3, 3 );
120 120
121 m_style_list = new QListBox( tab, "m_style_list" ); 121 m_style_list = new QListBox( tab, "m_style_list" );
122 vertLayout->addWidget( m_style_list ); 122 vertLayout->addWidget( m_style_list );
123 QWhatsThis::add( m_style_list, tr( "Styles control the way items such as buttons and scroll bars appear in all applications.\n\nClick here to select an available style." ) ); 123 QWhatsThis::add( m_style_list, tr( "Styles control the way items such as buttons and scroll bars appear in all applications.\n\nClick here to select an available style." ) );
124 124
125 m_style_settings = new QPushButton ( tr( "Settings..." ), tab ); 125 m_style_settings = new QPushButton ( tr( "Settings..." ), tab );
126 connect ( m_style_settings, SIGNAL( clicked()), this, SLOT( styleSettingsClicked())); 126 connect ( m_style_settings, SIGNAL( clicked()), this, SLOT( styleSettingsClicked()));
127 vertLayout-> addWidget ( m_style_settings ); 127 vertLayout-> addWidget ( m_style_settings );
128 QWhatsThis::add( m_style_settings, tr( "Click here to configure the currently selected style.\n\nNote: This option is not available for all styles." ) ); 128 QWhatsThis::add( m_style_settings, tr( "Click here to configure the currently selected style.\n\nNote: This option is not available for all styles." ) );
129 129
130 QString s = cfg. readEntry ( "Style", "Light" ); 130 QString s = cfg. readEntry ( "Style", "Light" );
131 131
132 132
133#if QT_VERSION >= 300 133#if QT_VERSION >= 0x030000
134 m_style_list->insertStringList(QStyleFactory::styles()); 134 m_style_list->insertStringList(QStyleFactory::styles());
135#else 135#else
136 m_style_list-> insertItem ( new StyleListItem ( "Windows", new QWindowsStyle ( ))); 136 m_style_list-> insertItem ( new StyleListItem ( "Windows", new QWindowsStyle ( )));
137 m_style_list-> insertItem ( new StyleListItem ( "Light", new LightStyle ( ))); 137 m_style_list-> insertItem ( new StyleListItem ( "Light", new LightStyle ( )));
138 m_style_list-> insertItem ( new StyleListItem ( "QPE", new QPEStyle ( ))); 138 m_style_list-> insertItem ( new StyleListItem ( "QPE", new QPEStyle ( )));
139#endif 139#endif
140 140
141 { 141 {
142 QString path = QPEApplication::qpeDir ( ); 142 QString path = QPEApplication::qpeDir ( );
143 path.append( "/plugins/styles/" ); 143 path.append( "/plugins/styles/" );
144 QStringList sl = QDir ( path, "lib*.so" ). entryList ( ); 144 QStringList sl = QDir ( path, "lib*.so" ). entryList ( );
145 145
146 for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) 146 for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it )
147 { 147 {
148 QString libstr = path; 148 QString libstr = path;
149 libstr.append( "/" ); 149 libstr.append( "/" );
150 libstr.append( *it ); 150 libstr.append( *it );
151 QLibrary *lib = new QLibrary ( libstr ); 151 QLibrary *lib = new QLibrary ( libstr );
152 StyleInterface *iface; 152 StyleInterface *iface;
153 153
154 if (( lib-> queryInterface ( IID_Style, (QUnknownInterface **) &iface ) == QS_OK ) && iface ) 154 if (( lib-> queryInterface ( IID_Style, (QUnknownInterface **) &iface ) == QS_OK ) && iface )
155 { 155 {
156 StyleListItem *slit = new StyleListItem ( lib, iface ); 156 StyleListItem *slit = new StyleListItem ( lib, iface );
157 m_style_list-> insertItem ( slit ); 157 m_style_list-> insertItem ( slit );
158 158
159 if ( slit-> key ( ) == s ) 159 if ( slit-> key ( ) == s )
160 m_style_list-> setCurrentItem ( slit ); 160 m_style_list-> setCurrentItem ( slit );
161 } 161 }
162 else 162 else
163 delete lib; 163 delete lib;
164 } 164 }
165 } 165 }
166 166
167 m_original_style = m_style_list-> currentItem ( ); 167 m_original_style = m_style_list-> currentItem ( );
168 styleClicked ( m_original_style ); 168 styleClicked ( m_original_style );
169 169
170 connect( m_style_list, SIGNAL( highlighted(int) ), this, SLOT( styleClicked(int) ) ); 170 connect( m_style_list, SIGNAL( highlighted(int) ), this, SLOT( styleClicked(int) ) );
171 171
172 return tab; 172 return tab;
173} 173}
174 174
175QWidget *Appearance::createDecoTab ( QWidget *parent, Config &cfg ) 175QWidget *Appearance::createDecoTab ( QWidget *parent, Config &cfg )
176{ 176{
177 QWidget* tab = new QWidget( parent, "DecoTab" ); 177 QWidget* tab = new QWidget( parent, "DecoTab" );
178 QVBoxLayout* vertLayout = new QVBoxLayout( tab, 3, 3 ); 178 QVBoxLayout* vertLayout = new QVBoxLayout( tab, 3, 3 );
179 179
180 m_deco_list = new QListBox( tab, "m_deco_list" ); 180 m_deco_list = new QListBox( tab, "m_deco_list" );
181 vertLayout->addWidget( m_deco_list ); 181 vertLayout->addWidget( m_deco_list );
182 QWhatsThis::add( m_deco_list, tr( "Window decorations control the way the application title bar and its buttons appear.\n\nClick here to select an available decoration." ) ); 182 QWhatsThis::add( m_deco_list, tr( "Window decorations control the way the application title bar and its buttons appear.\n\nClick here to select an available decoration." ) );
183 183
184 QString s = cfg. readEntry ( "Decoration", "libflat.so" ); 184 QString s = cfg. readEntry ( "Decoration", "libflat.so" );
185 185
186 m_deco_list-> insertItem ( new DecoListItem ( "QPE" )); 186 m_deco_list-> insertItem ( new DecoListItem ( "QPE" ));
187 187
188 { 188 {
189 QString path = QPEApplication::qpeDir(); 189 QString path = QPEApplication::qpeDir();
190 path.append( "/plugins/decorations/" ); 190 path.append( "/plugins/decorations/" );
191 QStringList sl = QDir ( path, "lib*.so" ). entryList ( ); 191 QStringList sl = QDir ( path, "lib*.so" ). entryList ( );
192 192
193 for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) 193 for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it )
194 { 194 {
195 QString libstr = path; 195 QString libstr = path;
196 libstr.append( "/" ); 196 libstr.append( "/" );
197 libstr.append( *it ); 197 libstr.append( *it );
198 QLibrary *lib = new QLibrary ( libstr ); 198 QLibrary *lib = new QLibrary ( libstr );
199 WindowDecorationInterface *iface; 199 WindowDecorationInterface *iface;
200 200
201 if ( lib-> queryInterface ( IID_WindowDecoration, (QUnknownInterface **) &iface ) == QS_OK ) 201 if ( lib-> queryInterface ( IID_WindowDecoration, (QUnknownInterface **) &iface ) == QS_OK )
202 { 202 {
203 DecoListItem *dlit = new DecoListItem ( lib, iface ); 203 DecoListItem *dlit = new DecoListItem ( lib, iface );
204 m_deco_list-> insertItem ( dlit ); 204 m_deco_list-> insertItem ( dlit );
205 205
206 if ( dlit-> key ( ) == s ) 206 if ( dlit-> key ( ) == s )
207 m_deco_list-> setCurrentItem ( dlit ); 207 m_deco_list-> setCurrentItem ( dlit );
208 } 208 }
209 else 209 else
210 delete lib; 210 delete lib;
211 } 211 }
212 } 212 }
213 213
214 m_original_deco = m_deco_list-> currentItem ( ); 214 m_original_deco = m_deco_list-> currentItem ( );
215 if ( m_deco_list-> currentItem ( ) < 0 ) 215 if ( m_deco_list-> currentItem ( ) < 0 )
216 m_deco_list-> setCurrentItem ( 0 ); 216 m_deco_list-> setCurrentItem ( 0 );
217 decoClicked ( m_original_deco ); 217 decoClicked ( m_original_deco );
218 218
219 connect( m_deco_list, SIGNAL( highlighted(int) ), this, SLOT( decoClicked(int) ) ); 219 connect( m_deco_list, SIGNAL( highlighted(int) ), this, SLOT( decoClicked(int) ) );
220 220
221 return tab; 221 return tab;
222} 222}
223 223
224QWidget *Appearance::createFontTab ( QWidget *parent, Config &cfg ) 224QWidget *Appearance::createFontTab ( QWidget *parent, Config &cfg )
225{ 225{
226 QString familyStr = cfg. readEntry ( "FontFamily", "Helvetica" ); 226 QString familyStr = cfg. readEntry ( "FontFamily", "Helvetica" );
227 QString styleStr = cfg. readEntry ( "FontStyle", "Regular" ); 227 QString styleStr = cfg. readEntry ( "FontStyle", "Regular" );
228 int size = cfg. readNumEntry ( "FontSize", 10 ); 228 int size = cfg. readNumEntry ( "FontSize", 10 );
229 229
230 m_fontselect = new OFontSelector ( false, parent, "FontTab" ); 230 m_fontselect = new OFontSelector ( false, parent, "FontTab" );
231 m_fontselect-> setSelectedFont ( familyStr, styleStr, size ); 231 m_fontselect-> setSelectedFont ( familyStr, styleStr, size );
232 QWhatsThis::add( m_fontselect, tr( "Select the desired name, style and size of the default font applications will use." ) ); 232 QWhatsThis::add( m_fontselect, tr( "Select the desired name, style and size of the default font applications will use." ) );
233 233
234 connect( m_fontselect, SIGNAL( fontSelected(const QFont&)), 234 connect( m_fontselect, SIGNAL( fontSelected(const QFont&)),
235 this, SLOT( fontClicked(const QFont&))); 235 this, SLOT( fontClicked(const QFont&)));
236 236
237 return m_fontselect; 237 return m_fontselect;
238} 238}
239 239
240QWidget *Appearance::createColorTab ( QWidget *parent, Config &cfg ) 240QWidget *Appearance::createColorTab ( QWidget *parent, Config &cfg )
241{ 241{
242 QWidget *tab = new QWidget( parent, "ColorTab" ); 242 QWidget *tab = new QWidget( parent, "ColorTab" );
243 QGridLayout *gridLayout = new QGridLayout( tab, 0, 0, 3, 3 ); 243 QGridLayout *gridLayout = new QGridLayout( tab, 0, 0, 3, 3 );
244 gridLayout->setRowStretch ( 3, 10 ); 244 gridLayout->setRowStretch ( 3, 10 );
245 245
246 m_color_list = new QListBox ( tab ); 246 m_color_list = new QListBox ( tab );
247 gridLayout->addMultiCellWidget ( m_color_list, 0, 3, 0, 0 ); 247 gridLayout->addMultiCellWidget ( m_color_list, 0, 3, 0, 0 );
248 connect( m_color_list, SIGNAL( highlighted(int) ), this, SLOT( colorClicked(int) ) ); 248 connect( m_color_list, SIGNAL( highlighted(int) ), this, SLOT( colorClicked(int) ) );
249 QWhatsThis::add( m_color_list, tr( "Color schemes are a collection of colors which are used for various parts of the display.\n\nClick here to select an available scheme." ) ); 249 QWhatsThis::add( m_color_list, tr( "Color schemes are a collection of colors which are used for various parts of the display.\n\nClick here to select an available scheme." ) );
250 250
251 m_color_list-> insertItem ( new ColorListItem ( tr( "Current scheme" ), cfg )); 251 m_color_list-> insertItem ( new ColorListItem ( tr( "Current scheme" ), cfg ));
252 252
253 QString path = QPEApplication::qpeDir ( ); 253 QString path = QPEApplication::qpeDir ( );
254 path.append( "/etc/colors/" ); 254 path.append( "/etc/colors/" );
255 QStringList sl = QDir ( path ). entryList ( "*.scheme" ); 255 QStringList sl = QDir ( path ). entryList ( "*.scheme" );
256 256
257 for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) 257 for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it )
258 { 258 {
259 QString name = (*it). left ((*it). find ( ".scheme" )); 259 QString name = (*it). left ((*it). find ( ".scheme" ));
260 QString pathstr = path; 260 QString pathstr = path;
261 pathstr.append( *it ); 261 pathstr.append( *it );
262 Config config ( pathstr, Config::File ); 262 Config config ( pathstr, Config::File );
263 config. setGroup ( "Colors" ); 263 config. setGroup ( "Colors" );
264 264
265 m_color_list-> insertItem ( new ColorListItem ( name, config )); 265 m_color_list-> insertItem ( new ColorListItem ( name, config ));
266 } 266 }
267 267
268 m_color_list-> setCurrentItem ( 0 ); 268 m_color_list-> setCurrentItem ( 0 );
269 269
270 QPushButton* tempButton = new QPushButton( tab, "editSchemeButton" ); 270 QPushButton* tempButton = new QPushButton( tab, "editSchemeButton" );
271 tempButton->setText( tr( "Edit..." ) ); 271 tempButton->setText( tr( "Edit..." ) );
272 connect( tempButton, SIGNAL( clicked() ), this, SLOT( editSchemeClicked() ) ); 272 connect( tempButton, SIGNAL( clicked() ), this, SLOT( editSchemeClicked() ) );
273 gridLayout->addWidget( tempButton, 0, 1 ); 273 gridLayout->addWidget( tempButton, 0, 1 );
274 QWhatsThis::add( tempButton, tr( "Click here to change the colors in the current color scheme." ) ); 274 QWhatsThis::add( tempButton, tr( "Click here to change the colors in the current color scheme." ) );
275 275
276 tempButton = new QPushButton( tab, "deleteSchemeButton" ); 276 tempButton = new QPushButton( tab, "deleteSchemeButton" );
277 tempButton->setText( tr( "Delete" ) ); 277 tempButton->setText( tr( "Delete" ) );
278 connect( tempButton, SIGNAL( clicked() ), this, SLOT( deleteSchemeClicked() ) ); 278 connect( tempButton, SIGNAL( clicked() ), this, SLOT( deleteSchemeClicked() ) );
279 gridLayout->addWidget( tempButton, 1, 1 ); 279 gridLayout->addWidget( tempButton, 1, 1 );
280 QWhatsThis::add( tempButton, tr( "Click here to delete the color scheme selected in the list to the left." ) ); 280 QWhatsThis::add( tempButton, tr( "Click here to delete the color scheme selected in the list to the left." ) );
281 281
282 tempButton = new QPushButton( tab, "saveSchemeButton" ); 282 tempButton = new QPushButton( tab, "saveSchemeButton" );
283 tempButton->setText( tr( "Save" ) ); 283 tempButton->setText( tr( "Save" ) );
284 connect( tempButton, SIGNAL( clicked() ), this, SLOT( saveSchemeClicked() ) ); 284 connect( tempButton, SIGNAL( clicked() ), this, SLOT( saveSchemeClicked() ) );
285 gridLayout->addWidget( tempButton, 2, 1 ); 285 gridLayout->addWidget( tempButton, 2, 1 );
286 QWhatsThis::add( tempButton, tr( "Click here to name and save the current color scheme." ) ); 286 QWhatsThis::add( tempButton, tr( "Click here to name and save the current color scheme." ) );
287 287
288 return tab; 288 return tab;
289} 289}
290 290
291QWidget *Appearance::createAdvancedTab ( QWidget *parent, Config &cfg ) 291QWidget *Appearance::createAdvancedTab ( QWidget *parent, Config &cfg )
292{ 292{
293 QWidget *tab = new QWidget ( parent ); 293 QWidget *tab = new QWidget ( parent );
294 QVBoxLayout *vertLayout = new QVBoxLayout( tab, 3, 3 ); 294 QVBoxLayout *vertLayout = new QVBoxLayout( tab, 3, 3 );
295 295
296 QGridLayout *lay = new QGridLayout ( vertLayout, 0, 0, 3, 0 ); 296 QGridLayout *lay = new QGridLayout ( vertLayout, 0, 0, 3, 0 );
297 297
298 m_force = new QCheckBox ( tr( "Force styling for all applications." ), tab ); 298 m_force = new QCheckBox ( tr( "Force styling for all applications." ), tab );
299 m_force-> setChecked ( cfg. readBoolEntry ( "ForceStyle" )); 299 m_force-> setChecked ( cfg. readBoolEntry ( "ForceStyle" ));
300 lay-> addMultiCellWidget ( m_force, 0, 0, 0, 1 ); 300 lay-> addMultiCellWidget ( m_force, 0, 0, 0, 1 );
301 QWhatsThis::add( m_force, tr( "Click here to allow all applications to use global appearance settings." ) ); 301 QWhatsThis::add( m_force, tr( "Click here to allow all applications to use global appearance settings." ) );
302 302
303 QLabel *l = new QLabel ( tab ); 303 QLabel *l = new QLabel ( tab );
304 l-> setText ( QString ( "<p>%1</p>" ). arg ( tr( "Disable styling for these applications ( <b>*</b> can be used as a wildcard):" ))); 304 l-> setText ( QString ( "<p>%1</p>" ). arg ( tr( "Disable styling for these applications ( <b>*</b> can be used as a wildcard):" )));
305 lay-> addMultiCellWidget ( l, 1, 1, 0, 1 ); 305 lay-> addMultiCellWidget ( l, 1, 1, 0, 1 );
306 QWhatsThis::add( l, tr( "If some applications do not display correctly with the global appearance settings, certain features can be turned off for that application.\n\nThis area allows you to select an application and which settings you wish to disable." ) ); 306 QWhatsThis::add( l, tr( "If some applications do not display correctly with the global appearance settings, certain features can be turned off for that application.\n\nThis area allows you to select an application and which settings you wish to disable." ) );
307 307
308 m_except = new QListView ( tab ); 308 m_except = new QListView ( tab );
309 m_except-> addColumn ( Resource::loadIconSet ( "appearance" ), "", 24 ); 309 m_except-> addColumn ( Resource::loadIconSet ( "appearance" ), "", 24 );
310 m_except-> addColumn ( Resource::loadIconSet ( "font" ), "", 24 ); 310 m_except-> addColumn ( Resource::loadIconSet ( "font" ), "", 24 );
311 m_except-> addColumn ( Resource::loadIconSet ( "appearance/deco" ), "", 24 ); 311 m_except-> addColumn ( Resource::loadIconSet ( "appearance/deco" ), "", 24 );
312 m_except-> addColumn ( tr( "Binary file(s)" )); 312 m_except-> addColumn ( tr( "Binary file(s)" ));
313 m_except-> setColumnAlignment ( 0, AlignCenter ); 313 m_except-> setColumnAlignment ( 0, AlignCenter );
314 m_except-> setColumnAlignment ( 1, AlignCenter ); 314 m_except-> setColumnAlignment ( 1, AlignCenter );
315 m_except-> setColumnAlignment ( 2, AlignCenter ); 315 m_except-> setColumnAlignment ( 2, AlignCenter );
316 m_except-> setAllColumnsShowFocus ( true ); 316 m_except-> setAllColumnsShowFocus ( true );
317 m_except-> setMinimumHeight ( 30 ); 317 m_except-> setMinimumHeight ( 30 );
318 m_except-> header ( )-> setClickEnabled ( false ); 318 m_except-> header ( )-> setClickEnabled ( false );
319 m_except-> header ( )-> setResizeEnabled ( false ); 319 m_except-> header ( )-> setResizeEnabled ( false );
320 m_except-> header ( )-> setMovingEnabled ( false ); 320 m_except-> header ( )-> setMovingEnabled ( false );
321 m_except-> setSorting ( -1 ); 321 m_except-> setSorting ( -1 );
322 lay-> addMultiCellWidget ( m_except, 2, 6, 0, 0 ); 322 lay-> addMultiCellWidget ( m_except, 2, 6, 0, 0 );
323 QWhatsThis::add( m_except, tr( "If some applications do not display correctly with the global appearance settings, certain features can be turned off for that application.\n\nThis area allows you to select an application and which settings you wish to disable." ) ); 323 QWhatsThis::add( m_except, tr( "If some applications do not display correctly with the global appearance settings, certain features can be turned off for that application.\n\nThis area allows you to select an application and which settings you wish to disable." ) );
324 324
325 connect ( m_except, SIGNAL( clicked(QListViewItem*,const QPoint&,int)), this, SLOT( clickedExcept(QListViewItem*,const QPoint&,int))); 325 connect ( m_except, SIGNAL( clicked(QListViewItem*,const QPoint&,int)), this, SLOT( clickedExcept(QListViewItem*,const QPoint&,int)));
326 326
327 QToolButton *tb = new QToolButton ( tab ); 327 QToolButton *tb = new QToolButton ( tab );
328 tb-> setIconSet ( Resource::loadIconSet ( "appearance/add" )); 328 tb-> setIconSet ( Resource::loadIconSet ( "appearance/add" ));
329 tb-> setFocusPolicy ( QWidget::StrongFocus ); 329 tb-> setFocusPolicy ( QWidget::StrongFocus );
330 lay-> addWidget ( tb, 2, 1 ); 330 lay-> addWidget ( tb, 2, 1 );
331 connect ( tb, SIGNAL( clicked()), this, SLOT( addExcept())); 331 connect ( tb, SIGNAL( clicked()), this, SLOT( addExcept()));
332 QWhatsThis::add( tb, tr( "Click here to add an application to the list above." ) ); 332 QWhatsThis::add( tb, tr( "Click here to add an application to the list above." ) );
333 333
334 tb = new QToolButton ( tab ); 334 tb = new QToolButton ( tab );
335 tb-> setIconSet ( Resource::loadIconSet ( "editdelete" )); 335 tb-> setIconSet ( Resource::loadIconSet ( "editdelete" ));
336 tb-> setFocusPolicy ( QWidget::StrongFocus ); 336 tb-> setFocusPolicy ( QWidget::StrongFocus );
337 lay-> addWidget ( tb, 3, 1 ); 337 lay-> addWidget ( tb, 3, 1 );
338 connect ( tb, SIGNAL( clicked()), this, SLOT( delExcept())); 338 connect ( tb, SIGNAL( clicked()), this, SLOT( delExcept()));
339 QWhatsThis::add( tb, tr( "Click here to delete the currently selected application." ) ); 339 QWhatsThis::add( tb, tr( "Click here to delete the currently selected application." ) );
340 340
341 tb = new QToolButton ( tab ); 341 tb = new QToolButton ( tab );
342 tb-> setIconSet ( Resource::loadIconSet ( "up" )); 342 tb-> setIconSet ( Resource::loadIconSet ( "up" ));
343 tb-> setFocusPolicy ( QWidget::StrongFocus ); 343 tb-> setFocusPolicy ( QWidget::StrongFocus );
344 lay-> addWidget ( tb, 4, 1 ); 344 lay-> addWidget ( tb, 4, 1 );
345 connect ( tb, SIGNAL( clicked()), this, SLOT( upExcept())); 345 connect ( tb, SIGNAL( clicked()), this, SLOT( upExcept()));
346 QWhatsThis::add( tb, tr( "Click here to move the currently selected application up in the list." ) ); 346 QWhatsThis::add( tb, tr( "Click here to move the currently selected application up in the list." ) );
347 347
348 tb = new QToolButton ( tab ); 348 tb = new QToolButton ( tab );
349 tb-> setIconSet ( Resource::loadIconSet ( "down" )); 349 tb-> setIconSet ( Resource::loadIconSet ( "down" ));
350 tb-> setFocusPolicy ( QWidget::StrongFocus ); 350 tb-> setFocusPolicy ( QWidget::StrongFocus );
351 lay-> addWidget ( tb, 5, 1 ); 351 lay-> addWidget ( tb, 5, 1 );
352 connect ( tb, SIGNAL( clicked()), this, SLOT( downExcept())); 352 connect ( tb, SIGNAL( clicked()), this, SLOT( downExcept()));
353 QWhatsThis::add( tb, tr( "Click here to move the currently selected application down in the list." ) ); 353 QWhatsThis::add( tb, tr( "Click here to move the currently selected application down in the list." ) );
354 354
355 lay-> setRowStretch ( 6, 10 ); 355 lay-> setRowStretch ( 6, 10 );
356 lay-> setColStretch ( 0, 10 ); 356 lay-> setColStretch ( 0, 10 );
357 357
358 QStringList sl = cfg. readListEntry ( "NoStyle", ';' ); 358 QStringList sl = cfg. readListEntry ( "NoStyle", ';' );
359 QListViewItem *lvit = 0; 359 QListViewItem *lvit = 0;
360 for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) 360 for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it )
361 { 361 {
362 int fl = ( *it ). left ( 1 ). toInt ( 0, 32 ); 362 int fl = ( *it ). left ( 1 ). toInt ( 0, 32 );
363 363
364 lvit = new ExceptListItem ( m_except, lvit, ( *it ). mid ( 1 ), fl & 0x01, fl & 0x02, fl & 0x04 ); 364 lvit = new ExceptListItem ( m_except, lvit, ( *it ). mid ( 1 ), fl & 0x01, fl & 0x02, fl & 0x04 );
365 } 365 }
366 366
367 367
368 vertLayout-> addSpacing ( 3 ); 368 vertLayout-> addSpacing ( 3 );
369 QFrame *f = new QFrame ( tab ); 369 QFrame *f = new QFrame ( tab );
370 f-> setFrameStyle ( QFrame::HLine | QFrame::Sunken ); 370 f-> setFrameStyle ( QFrame::HLine | QFrame::Sunken );
371 vertLayout-> addWidget ( f ); 371 vertLayout-> addWidget ( f );
372 vertLayout-> addSpacing ( 3 ); 372 vertLayout-> addSpacing ( 3 );
373 373
374 374
375 QGridLayout* gridLayout = new QGridLayout ( vertLayout, 0, 0, 3, 0 ); 375 QGridLayout* gridLayout = new QGridLayout ( vertLayout, 0, 0, 3, 0 );
376 376
377 int style = cfg. readNumEntry ( "TabStyle", 2 ) - 1; 377 int style = cfg. readNumEntry ( "TabStyle", 2 ) - 1;
378 bool tabtop = ( cfg. readEntry ( "TabPosition", "Top" ) == "Top" ); 378 bool tabtop = ( cfg. readEntry ( "TabPosition", "Top" ) == "Top" );
379 379
380 QLabel* label = new QLabel( tr( "Tab style:" ), tab ); 380 QLabel* label = new QLabel( tr( "Tab style:" ), tab );
381 gridLayout-> addWidget ( label, 0, 0 ); 381 gridLayout-> addWidget ( label, 0, 0 );
382 QWhatsThis::add( label, tr( "Click here to select a desired style for tabbed dialogs (such as this application). The styles available are:\n\n1. Tabs - normal tabs with text labels only\n2. Tabs w/icons - tabs with icons for each tab, text label only appears on current tab\n3. Drop down list - a vertical listing of tabs\n4. Drop down list w/icons - a vertical listing of tabs with icons" ) ); 382 QWhatsThis::add( label, tr( "Click here to select a desired style for tabbed dialogs (such as this application). The styles available are:\n\n1. Tabs - normal tabs with text labels only\n2. Tabs w/icons - tabs with icons for each tab, text label only appears on current tab\n3. Drop down list - a vertical listing of tabs\n4. Drop down list w/icons - a vertical listing of tabs with icons" ) );
383 383
384 QButtonGroup* btngrp = new QButtonGroup( tab, "buttongroup" ); 384 QButtonGroup* btngrp = new QButtonGroup( tab, "buttongroup" );
385 btngrp-> hide ( ); 385 btngrp-> hide ( );
386 btngrp-> setExclusive ( true ); 386 btngrp-> setExclusive ( true );
387 387
388 m_tabstyle_list = new QComboBox ( false, tab, "tabstyle" ); 388 m_tabstyle_list = new QComboBox ( false, tab, "tabstyle" );
389 m_tabstyle_list-> insertItem ( tr( "Tabs" )); 389 m_tabstyle_list-> insertItem ( tr( "Tabs" ));
390 m_tabstyle_list-> insertItem ( tr( "Tabs w/icons" )); 390 m_tabstyle_list-> insertItem ( tr( "Tabs w/icons" ));
391 m_tabstyle_list-> insertItem ( tr( "Drop down list" )); 391 m_tabstyle_list-> insertItem ( tr( "Drop down list" ));
392 m_tabstyle_list-> insertItem ( tr( "Drop down list w/icons" )); 392 m_tabstyle_list-> insertItem ( tr( "Drop down list w/icons" ));
393 m_tabstyle_list-> setCurrentItem ( style ); 393 m_tabstyle_list-> setCurrentItem ( style );
394 gridLayout-> addMultiCellWidget ( m_tabstyle_list, 0, 0, 1, 2 ); 394 gridLayout-> addMultiCellWidget ( m_tabstyle_list, 0, 0, 1, 2 );
395 QWhatsThis::add( m_tabstyle_list, tr( "Click here to select a desired style for tabbed dialogs (such as this application). The styles available are:\n\n1. Tabs - normal tabs with text labels only\n2. Tabs w/icons - tabs with icons for each tab, text label only appears on current tab\n3. Drop down list - a vertical listing of tabs\n4. Drop down list w/icons - a vertical listing of tabs with icons" ) ); 395 QWhatsThis::add( m_tabstyle_list, tr( "Click here to select a desired style for tabbed dialogs (such as this application). The styles available are:\n\n1. Tabs - normal tabs with text labels only\n2. Tabs w/icons - tabs with icons for each tab, text label only appears on current tab\n3. Drop down list - a vertical listing of tabs\n4. Drop down list w/icons - a vertical listing of tabs with icons" ) );
396 396
397 m_tabstyle_top = new QRadioButton( tr( "Top" ), tab, "tabpostop" ); 397 m_tabstyle_top = new QRadioButton( tr( "Top" ), tab, "tabpostop" );
398 btngrp-> insert ( m_tabstyle_top ); 398 btngrp-> insert ( m_tabstyle_top );
399 gridLayout-> addWidget( m_tabstyle_top, 1, 1 ); 399 gridLayout-> addWidget( m_tabstyle_top, 1, 1 );
400 QWhatsThis::add( m_tabstyle_top, tr( "Click here so that tabs appear at the top of the window." ) ); 400 QWhatsThis::add( m_tabstyle_top, tr( "Click here so that tabs appear at the top of the window." ) );
401 401
402 m_tabstyle_bottom = new QRadioButton( tr( "Bottom" ), tab, "tabposbottom" ); 402 m_tabstyle_bottom = new QRadioButton( tr( "Bottom" ), tab, "tabposbottom" );
403 btngrp-> insert ( m_tabstyle_bottom ); 403 btngrp-> insert ( m_tabstyle_bottom );
404 gridLayout-> addWidget( m_tabstyle_bottom, 1, 2 ); 404 gridLayout-> addWidget( m_tabstyle_bottom, 1, 2 );
405 QWhatsThis::add( m_tabstyle_bottom, tr( "Click here so that tabs appear at the bottom of the window." ) ); 405 QWhatsThis::add( m_tabstyle_bottom, tr( "Click here so that tabs appear at the bottom of the window." ) );
406 406
407 m_tabstyle_top-> setChecked ( tabtop ); 407 m_tabstyle_top-> setChecked ( tabtop );
408 m_tabstyle_bottom-> setChecked ( !tabtop ); 408 m_tabstyle_bottom-> setChecked ( !tabtop );
409 409
410 m_original_tabstyle = style; 410 m_original_tabstyle = style;
411 m_original_tabpos = tabtop; 411 m_original_tabpos = tabtop;
412 412
413 vertLayout-> addSpacing ( 3 ); 413 vertLayout-> addSpacing ( 3 );
414 QHBoxLayout *rotLay = new QHBoxLayout ( vertLayout, 3 ); 414 QHBoxLayout *rotLay = new QHBoxLayout ( vertLayout, 3 );
415 415
416 QLabel* rotlabel = new QLabel( tr( "Rotation direction:" ), tab ); 416 QLabel* rotlabel = new QLabel( tr( "Rotation direction:" ), tab );
417 m_rotdir_cw = new QRadioButton( tab, "rotdir_cw" ); 417 m_rotdir_cw = new QRadioButton( tab, "rotdir_cw" );
418 QPixmap cw1 = Resource::loadIconSet("redo"). pixmap( ); 418 QPixmap cw1 = Resource::loadIconSet("redo"). pixmap( );
419 m_rotdir_ccw = new QRadioButton( tab, "rotdir_ccw" ); 419 m_rotdir_ccw = new QRadioButton( tab, "rotdir_ccw" );
420 QImage ccwImage = cw1. convertToImage( ). mirror( 1, 0 ); 420 QImage ccwImage = cw1. convertToImage( ). mirror( 1, 0 );
421 QPixmap ccw1; 421 QPixmap ccw1;
422 m_rotdir_flip = new QRadioButton( tab, "rotdir_flip" ); 422 m_rotdir_flip = new QRadioButton( tab, "rotdir_flip" );
423 QPixmap flip1 = Resource::loadIconSet("pass"). pixmap( ); 423 QPixmap flip1 = Resource::loadIconSet("pass"). pixmap( );
424 QButtonGroup* rotbtngrp = new QButtonGroup( tab, "rotbuttongroup" ); 424 QButtonGroup* rotbtngrp = new QButtonGroup( tab, "rotbuttongroup" );
425 425
426 rotbtngrp-> hide ( ); 426 rotbtngrp-> hide ( );
427 rotbtngrp-> setExclusive ( true ); 427 rotbtngrp-> setExclusive ( true );
428 rotbtngrp-> insert ( m_rotdir_cw ); 428 rotbtngrp-> insert ( m_rotdir_cw );
429 rotbtngrp-> insert ( m_rotdir_ccw ); 429 rotbtngrp-> insert ( m_rotdir_ccw );
430 rotbtngrp-> insert ( m_rotdir_flip ); 430 rotbtngrp-> insert ( m_rotdir_flip );
431 431
432 ccw1. convertFromImage( ccwImage ); 432 ccw1. convertFromImage( ccwImage );
433 m_rotdir_cw-> setPixmap( cw1 ); 433 m_rotdir_cw-> setPixmap( cw1 );
434 m_rotdir_ccw-> setPixmap( ccw1 ); 434 m_rotdir_ccw-> setPixmap( ccw1 );
435 m_rotdir_flip-> setPixmap( flip1 ); 435 m_rotdir_flip-> setPixmap( flip1 );
436 436
437 rotLay-> addWidget ( rotlabel, 0 ); 437 rotLay-> addWidget ( rotlabel, 0 );
438 rotLay-> addWidget ( m_rotdir_cw, 0 ); 438 rotLay-> addWidget ( m_rotdir_cw, 0 );
439 rotLay-> addWidget ( m_rotdir_ccw, 0 ); 439 rotLay-> addWidget ( m_rotdir_ccw, 0 );
440 rotLay-> addWidget ( m_rotdir_flip, 0 ); 440 rotLay-> addWidget ( m_rotdir_flip, 0 );
441 441
442 int rotDirection = cfg.readNumEntry( "rotatedir" ); 442 int rotDirection = cfg.readNumEntry( "rotatedir" );
443 ODirection rot = CW; 443 ODirection rot = CW;
444 444
445 if (rotDirection == -1) 445 if (rotDirection == -1)
446 { 446 {
447 rot = ODevice::inst ( )-> direction ( ); 447 rot = ODevice::inst ( )-> direction ( );
448 } 448 }
449 else 449 else
450 { 450 {
451 rot = (ODirection)rotDirection; 451 rot = (ODirection)rotDirection;
452 } 452 }
453 453
454 m_rotdir_cw-> setChecked ( rot == CW ); 454 m_rotdir_cw-> setChecked ( rot == CW );
455 m_rotdir_ccw-> setChecked ( rot == CCW ); 455 m_rotdir_ccw-> setChecked ( rot == CCW );
456 m_rotdir_flip-> setChecked ( rot == Flip ); 456 m_rotdir_flip-> setChecked ( rot == Flip );
457 457
458 return tab; 458 return tab;
459} 459}
460 460
461 461
462Appearance::Appearance( QWidget* parent, const char* name, WFlags ) 462Appearance::Appearance( QWidget* parent, const char* name, WFlags )
463 : QDialog ( parent, name, true, WStyle_ContextHelp ) 463 : QDialog ( parent, name, true, WStyle_ContextHelp )
464{ 464{
465 setCaption( tr( "Appearance Settings" ) ); 465 setCaption( tr( "Appearance Settings" ) );
466 466
467 Config config( "qpe" ); 467 Config config( "qpe" );
468 config.setGroup( "Appearance" ); 468 config.setGroup( "Appearance" );
469 469
470 QVBoxLayout *top = new QVBoxLayout ( this, 3, 3 ); 470 QVBoxLayout *top = new QVBoxLayout ( this, 3, 3 );
471 471
472 m_sample = new SampleWindow ( this ); 472 m_sample = new SampleWindow ( this );
473 473
474 m_sample-> setDecoration ( new DefaultWindowDecoration ( ) ); 474 m_sample-> setDecoration ( new DefaultWindowDecoration ( ) );
475 QWhatsThis::add( m_sample, tr( "This is a preview window. Look here to see your new appearance as options are changed." ) ); 475 QWhatsThis::add( m_sample, tr( "This is a preview window. Look here to see your new appearance as options are changed." ) );
476 476
477 OTabWidget* tw = new OTabWidget ( this, "tabwidget", OTabWidget::Global, OTabWidget::Bottom ); 477 OTabWidget* tw = new OTabWidget ( this, "tabwidget", OTabWidget::Global, OTabWidget::Bottom );
478 QWidget *styletab; 478 QWidget *styletab;
479 479
480 m_color_list = 0; 480 m_color_list = 0;
481 481
482 tw-> addTab ( styletab = createStyleTab ( tw, config ), "appearance", tr( "Style" )); 482 tw-> addTab ( styletab = createStyleTab ( tw, config ), "appearance", tr( "Style" ));
483 tw-> addTab ( createFontTab ( tw, config ), "font", tr( "Font" )); 483 tw-> addTab ( createFontTab ( tw, config ), "font", tr( "Font" ));
484 tw-> addTab ( createColorTab ( tw, config ), "appearance/color", tr( "Colors" ) ); 484 tw-> addTab ( createColorTab ( tw, config ), "appearance/color", tr( "Colors" ) );
485 tw-> addTab ( createDecoTab ( tw, config ), "appearance/deco", tr( "Windows" ) ); 485 tw-> addTab ( createDecoTab ( tw, config ), "appearance/deco", tr( "Windows" ) );
486 tw-> addTab ( m_advtab = createAdvancedTab ( tw, config ), "SettingsIcon", tr( "Advanced" ) ); 486 tw-> addTab ( m_advtab = createAdvancedTab ( tw, config ), "SettingsIcon", tr( "Advanced" ) );
487 487
488 top-> addWidget ( tw, 10 ); 488 top-> addWidget ( tw, 10 );
489 top-> addWidget ( m_sample, 1 ); 489 top-> addWidget ( m_sample, 1 );
490 490
491 tw-> setCurrentTab ( styletab ); 491 tw-> setCurrentTab ( styletab );
492 connect ( tw, SIGNAL( currentChanged(QWidget*)), this, SLOT( tabChanged(QWidget*))); 492 connect ( tw, SIGNAL( currentChanged(QWidget*)), this, SLOT( tabChanged(QWidget*)));
493 493
494 m_style_changed = m_font_changed = m_color_changed = m_deco_changed = false; 494 m_style_changed = m_font_changed = m_color_changed = m_deco_changed = false;
495} 495}
496 496
497Appearance::~Appearance() 497Appearance::~Appearance()
498{} 498{}
499 499
500void Appearance::tabChanged ( QWidget *w ) 500void Appearance::tabChanged ( QWidget *w )
501{ 501{
502 if ( w == m_advtab ) 502 if ( w == m_advtab )
503 { 503 {
504 m_sample-> hide ( ); 504 m_sample-> hide ( );
505 updateGeometry ( ); // shouldn't be necessary ... 505 updateGeometry ( ); // shouldn't be necessary ...
506 } 506 }
507 else 507 else
508 m_sample-> show ( ); 508 m_sample-> show ( );
509} 509}
510 510
511void Appearance::accept ( ) 511void Appearance::accept ( )
512{ 512{
513 bool newtabpos = m_tabstyle_top-> isChecked ( ); 513 bool newtabpos = m_tabstyle_top-> isChecked ( );
514 int newtabstyle = m_tabstyle_list-> currentItem ( ); 514 int newtabstyle = m_tabstyle_list-> currentItem ( );
515 515
516 Config config ( "qpe" ); 516 Config config ( "qpe" );
517 config. setGroup ( "Appearance" ); 517 config. setGroup ( "Appearance" );
518 518
519 if ( m_style_changed ) 519 if ( m_style_changed )
520 { 520 {
521 StyleListItem *item = (StyleListItem *) m_style_list-> item ( m_style_list-> currentItem ( )); 521 StyleListItem *item = (StyleListItem *) m_style_list-> item ( m_style_list-> currentItem ( ));
522 if ( item ) 522 if ( item )
523 config.writeEntry( "Style", item-> key ( )); 523 config.writeEntry( "Style", item-> key ( ));
524 } 524 }
525 525
526 if ( m_deco_changed ) 526 if ( m_deco_changed )
527 { 527 {
528 DecoListItem *item = (DecoListItem *) m_deco_list-> item ( m_deco_list-> currentItem ( )); 528 DecoListItem *item = (DecoListItem *) m_deco_list-> item ( m_deco_list-> currentItem ( ));
529 if ( item ) 529 if ( item )
530 config.writeEntry( "Decoration", item-> key ( )); 530 config.writeEntry( "Decoration", item-> key ( ));
531 } 531 }
532 532
533 if (( newtabstyle != m_original_tabstyle ) || ( newtabpos != m_original_tabpos )) 533 if (( newtabstyle != m_original_tabstyle ) || ( newtabpos != m_original_tabpos ))
534 { 534 {
535 config. writeEntry ( "TabStyle", newtabstyle + 1 ); 535 config. writeEntry ( "TabStyle", newtabstyle + 1 );
536 config. writeEntry ( "TabPosition", newtabpos ? "Top" : "Bottom" ); 536 config. writeEntry ( "TabPosition", newtabpos ? "Top" : "Bottom" );
537 } 537 }
538 538
539 if ( m_font_changed ) 539 if ( m_font_changed )
540 { 540 {
541 config. writeEntry ( "FontFamily", m_fontselect-> fontFamily ( )); 541 config. writeEntry ( "FontFamily", m_fontselect-> fontFamily ( ));
542 config. writeEntry ( "FontStyle", m_fontselect-> fontStyle ( )); 542 config. writeEntry ( "FontStyle", m_fontselect-> fontStyle ( ));
543 config. writeEntry ( "FontSize", m_fontselect-> fontSize ( )); 543 config. writeEntry ( "FontSize", m_fontselect-> fontSize ( ));
544 } 544 }
545 545
546 546
547 if ( m_color_changed ) 547 if ( m_color_changed )
548 { 548 {
549 ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( )); 549 ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( ));
550 550
551 if ( item ) 551 if ( item )
552 item-> save ( config ); 552 item-> save ( config );
553 } 553 }
554 554
555 ODirection rot; 555 ODirection rot;
556 if (m_rotdir_ccw-> isChecked ( )) 556 if (m_rotdir_ccw-> isChecked ( ))
557 { 557 {
558 rot = CCW; 558 rot = CCW;
559 } 559 }
560 else if (m_rotdir_cw-> isChecked ( )) 560 else if (m_rotdir_cw-> isChecked ( ))
561 { 561 {
562 rot = CW; 562 rot = CW;
563 } 563 }
564 else 564 else
565 { 565 {
566 rot = Flip; 566 rot = Flip;
567 } 567 }
568 config. writeEntry ( "rotatedir", (int)rot ); 568 config. writeEntry ( "rotatedir", (int)rot );
569 569
570 m_except-> setFocus ( ); // if the focus was on the embedded line-edit, we have to move it away first, so the contents are updated 570 m_except-> setFocus ( ); // if the focus was on the embedded line-edit, we have to move it away first, so the contents are updated
571 571
572 QStringList sl; 572 QStringList sl;
573 QString exceptstr; 573 QString exceptstr;
574 for ( ExceptListItem *it = (ExceptListItem *) m_except-> firstChild ( ); it; it = (ExceptListItem *) it-> nextSibling ( )) 574 for ( ExceptListItem *it = (ExceptListItem *) m_except-> firstChild ( ); it; it = (ExceptListItem *) it-> nextSibling ( ))
575 { 575 {
576 int fl = 0; 576 int fl = 0;
577 fl |= ( it-> noStyle ( ) ? 0x01 : 0 ); 577 fl |= ( it-> noStyle ( ) ? 0x01 : 0 );
578 fl |= ( it-> noFont ( ) ? 0x02 : 0 ); 578 fl |= ( it-> noFont ( ) ? 0x02 : 0 );
579 fl |= ( it-> noDeco ( ) ? 0x04 : 0 ); 579 fl |= ( it-> noDeco ( ) ? 0x04 : 0 );
580 exceptstr = QString::number ( fl, 32 ); 580 exceptstr = QString::number ( fl, 32 );
581 exceptstr.append( it-> pattern ( )); 581 exceptstr.append( it-> pattern ( ));
582 sl << exceptstr; 582 sl << exceptstr;
583 } 583 }
584 config. writeEntry ( "NoStyle", sl, ';' ); 584 config. writeEntry ( "NoStyle", sl, ';' );
585 config. writeEntry ( "ForceStyle", m_force-> isChecked ( )); 585 config. writeEntry ( "ForceStyle", m_force-> isChecked ( ));
586 586
587 config. write ( ); // need to flush the config info first 587 config. write ( ); // need to flush the config info first
588 Global::applyStyle ( ); 588 Global::applyStyle ( );
589 589
590 QDialog::accept ( ); 590 QDialog::accept ( );
591} 591}
592 592
593void Appearance::done ( int r ) 593void Appearance::done ( int r )
594{ 594{
595 QDialog::done ( r ); 595 QDialog::done ( r );
596 close ( ); 596 close ( );
597} 597}
598 598
599 599
600void Appearance::styleClicked ( int index ) 600void Appearance::styleClicked ( int index )
601{ 601{
602 StyleListItem *sli = (StyleListItem *) m_style_list-> item ( index ); 602 StyleListItem *sli = (StyleListItem *) m_style_list-> item ( index );
603 m_style_settings-> setEnabled ( sli ? sli-> hasSettings ( ) : false ); 603 m_style_settings-> setEnabled ( sli ? sli-> hasSettings ( ) : false );
604 604
605 if ( m_sample && sli && sli-> style ( )) 605 if ( m_sample && sli && sli-> style ( ))
606 { 606 {
607 int ci = m_color_list ? m_color_list-> currentItem ( ) : -1; 607 int ci = m_color_list ? m_color_list-> currentItem ( ) : -1;
608 608
609 m_sample-> setStyle2 ( sli-> style ( ), ci < 0 ? palette ( ) : ((ColorListItem *) m_color_list-> item ( ci ))-> palette ( )); 609 m_sample-> setStyle2 ( sli-> style ( ), ci < 0 ? palette ( ) : ((ColorListItem *) m_color_list-> item ( ci ))-> palette ( ));
610 } 610 }
611 611
612 m_style_changed |= ( index != m_original_style ); 612 m_style_changed |= ( index != m_original_style );
613} 613}
614 614
615void Appearance::styleSettingsClicked ( ) 615void Appearance::styleSettingsClicked ( )
616{ 616{
617 StyleListItem *item = (StyleListItem *) m_style_list-> item ( m_style_list-> currentItem ( )); 617 StyleListItem *item = (StyleListItem *) m_style_list-> item ( m_style_list-> currentItem ( ));
618 618
619 if ( item && item-> hasSettings ( )) 619 if ( item && item-> hasSettings ( ))
620 { 620 {
621 QDialog *d = new QDialog ( this, "SETTINGS-DLG", true ); 621 QDialog *d = new QDialog ( this, "SETTINGS-DLG", true );
622 QVBoxLayout *vbox = new QVBoxLayout ( d, 3, 0 ); 622 QVBoxLayout *vbox = new QVBoxLayout ( d, 3, 0 );
623 623
624 QWidget *w = item-> settings ( d ); 624 QWidget *w = item-> settings ( d );
625 625
626 if ( w ) 626 if ( w )
627 { 627 {
628 vbox-> addWidget ( w ); 628 vbox-> addWidget ( w );
629 629
630 d-> setCaption ( w-> caption ( )); 630 d-> setCaption ( w-> caption ( ));
631 631
632 bool accepted = ( QPEApplication::execDialog ( d ) == QDialog::Accepted ); 632 bool accepted = ( QPEApplication::execDialog ( d ) == QDialog::Accepted );
633 633
634 if ( item-> setSettings ( accepted )) 634 if ( item-> setSettings ( accepted ))
635 m_style_changed = true; 635 m_style_changed = true;
636 } 636 }
637 delete d; 637 delete d;
638 } 638 }
639} 639}
640 640
641void Appearance::decoClicked ( int index ) 641void Appearance::decoClicked ( int index )
642{ 642{
643 DecoListItem *dli = (DecoListItem *) m_deco_list-> item ( index ); 643 DecoListItem *dli = (DecoListItem *) m_deco_list-> item ( index );
644 644
645 if ( m_sample ) 645 if ( m_sample )
646 { 646 {
647 if ( dli && dli-> interface ( )) 647 if ( dli && dli-> interface ( ))
648 m_sample-> setDecoration ( dli-> interface ( )); 648 m_sample-> setDecoration ( dli-> interface ( ));
649 else 649 else
650 m_sample-> setDecoration ( new DefaultWindowDecoration ( )); 650 m_sample-> setDecoration ( new DefaultWindowDecoration ( ));
651 m_sample-> repaint ( ); 651 m_sample-> repaint ( );
652 } 652 }
653 m_deco_changed |= ( index != m_original_deco ); 653 m_deco_changed |= ( index != m_original_deco );
654} 654}
655 655
656void Appearance::fontClicked ( const QFont &f ) 656void Appearance::fontClicked ( const QFont &f )
657{ 657{
658 m_font_changed |= ( f != m_sample-> font ( )); 658 m_font_changed |= ( f != m_sample-> font ( ));
659 m_sample-> setFont ( f ); 659 m_sample-> setFont ( f );
660} 660}
661 661
662void Appearance::colorClicked ( int index ) 662void Appearance::colorClicked ( int index )
663{ 663{
664 ColorListItem *item = (ColorListItem *) m_color_list-> item ( index ); 664 ColorListItem *item = (ColorListItem *) m_color_list-> item ( index );
665 665
666 if ( item ) 666 if ( item )
667 m_sample-> setPalette ( item-> palette ( )); 667 m_sample-> setPalette ( item-> palette ( ));
668 668
669 m_color_changed |= ( item-> palette ( ) != qApp-> palette ( )); 669 m_color_changed |= ( item-> palette ( ) != qApp-> palette ( ));
670} 670}
671 671
672 672
673void Appearance::editSchemeClicked ( ) 673void Appearance::editSchemeClicked ( )
674{ 674{
675 ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( )); 675 ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( ));
676 676
677 int cnt = 0; 677 int cnt = 0;
678 QString labels [QColorGroup::NColorRoles]; 678 QString labels [QColorGroup::NColorRoles];
679 QColor colors [QColorGroup::NColorRoles]; 679 QColor colors [QColorGroup::NColorRoles];
680 680
681 for ( int role = 0; role < (int) QColorGroup::NColorRoles; ++role ) 681 for ( int role = 0; role < (int) QColorGroup::NColorRoles; ++role )
682 { 682 {
683 QColor col = item->color( static_cast<QColorGroup::ColorRole>( role ) ); 683 QColor col = item->color( static_cast<QColorGroup::ColorRole>( role ) );
684 684
685 if ( col. isValid ( )) 685 if ( col. isValid ( ))
686 { 686 {
687 labels[cnt] = item->label( static_cast<QColorGroup::ColorRole>( role ) ); 687 labels[cnt] = item->label( static_cast<QColorGroup::ColorRole>( role ) );
688 colors[cnt] = col; 688 colors[cnt] = col;
689 689
690 cnt++; 690 cnt++;
691 } 691 }
692 } 692 }
693 693
694 EditScheme* editdlg = new EditScheme( cnt, labels, colors, this, "editScheme", true ); 694 EditScheme* editdlg = new EditScheme( cnt, labels, colors, this, "editScheme", true );
695 if ( QPEApplication::execDialog( editdlg ) == QDialog::Accepted ) 695 if ( QPEApplication::execDialog( editdlg ) == QDialog::Accepted )
696 { 696 {
697 ColorListItem *citem = (ColorListItem *) m_color_list-> item ( 0 ); 697 ColorListItem *citem = (ColorListItem *) m_color_list-> item ( 0 );
698 cnt = 0; 698 cnt = 0;
699 699
700 for ( int role = 0; role < (int) QColorGroup::NColorRoles; ++role ) 700 for ( int role = 0; role < (int) QColorGroup::NColorRoles; ++role )
701 { 701 {
702 if ( item->color( static_cast<QColorGroup::ColorRole>( role ) ).isValid() ) 702 if ( item->color( static_cast<QColorGroup::ColorRole>( role ) ).isValid() )
703 { 703 {
704 citem->setColor( static_cast<QColorGroup::ColorRole>( role ), colors[cnt] ); 704 citem->setColor( static_cast<QColorGroup::ColorRole>( role ), colors[cnt] );
705 cnt++; 705 cnt++;
706 } 706 }
707 } 707 }
708 708
709 m_color_list-> setCurrentItem ( 0 ); 709 m_color_list-> setCurrentItem ( 0 );
710 colorClicked ( 0 ); 710 colorClicked ( 0 );
711 711
712 m_color_changed = true; 712 m_color_changed = true;
713 } 713 }
714 delete editdlg; 714 delete editdlg;
715} 715}
716 716
717 717
718void Appearance::saveSchemeClicked() 718void Appearance::saveSchemeClicked()
719{ 719{
720 ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( )); 720 ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( ));
721 721
722 if ( !item ) 722 if ( !item )
723 return; 723 return;
724 724
725 QDialog *d = new QDialog ( this, 0, true ); 725 QDialog *d = new QDialog ( this, 0, true );
726 d-> setCaption ( tr( "Save Scheme" )); 726 d-> setCaption ( tr( "Save Scheme" ));
727 QLineEdit *ed = new QLineEdit ( d ); 727 QLineEdit *ed = new QLineEdit ( d );
728 ( new QVBoxLayout ( d, 3, 3 ))-> addWidget ( ed ); 728 ( new QVBoxLayout ( d, 3, 3 ))-> addWidget ( ed );
729 ed-> setFocus ( ); 729 ed-> setFocus ( );
730 730
731 if ( d-> exec ( ) == QDialog::Accepted ) 731 if ( d-> exec ( ) == QDialog::Accepted )
732 { 732 {
733 QString schemename = ed-> text ( ); 733 QString schemename = ed-> text ( );
734 QString filestr = QPEApplication::qpeDir(); 734 QString filestr = QPEApplication::qpeDir();
735 filestr.append( "/etc/colors/" ); 735 filestr.append( "/etc/colors/" );
736 filestr.append( schemename ); 736 filestr.append( schemename );
737 filestr.append( ".scheme" ); 737 filestr.append( ".scheme" );
738 QFile file ( filestr ); 738 QFile file ( filestr );
739 if ( !file. exists ( )) 739 if ( !file. exists ( ))
740 { 740 {
741 QPalette p = item-> palette ( ); 741 QPalette p = item-> palette ( );
742 742
743 Config config ( file.name(), Config::File ); 743 Config config ( file.name(), Config::File );
744 config. setGroup( "Colors" ); 744 config. setGroup( "Colors" );
745 745
746 item-> save ( config ); 746 item-> save ( config );
747 747
748 config. write ( ); // need to flush the config info first 748 config. write ( ); // need to flush the config info first
749 749
750 m_color_list-> insertItem ( new ColorListItem ( schemename, config )); 750 m_color_list-> insertItem ( new ColorListItem ( schemename, config ));
751 } 751 }
752 else 752 else
753 { 753 {
754 QMessageBox::information ( this, tr( "Save scheme" ), tr( "Scheme does already exist." )); 754 QMessageBox::information ( this, tr( "Save scheme" ), tr( "Scheme does already exist." ));
755 } 755 }
756 } 756 }
757 delete d; 757 delete d;
758} 758}
759 759
760void Appearance::deleteSchemeClicked() 760void Appearance::deleteSchemeClicked()
761{ 761{
762 ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( )); 762 ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( ));
763 763
764 if ( !item ) 764 if ( !item )
765 return; 765 return;
766 766
767 if ( m_color_list-> currentItem ( ) > 0 ) 767 if ( m_color_list-> currentItem ( ) > 0 )
768 { 768 {
769 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete scheme" ), item-> text ( ) ) ) 769 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete scheme" ), item-> text ( ) ) )
770 { 770 {
771 QString filestr = QPEApplication::qpeDir ( ); 771 QString filestr = QPEApplication::qpeDir ( );
772 filestr.append( "/etc/colors/" ); 772 filestr.append( "/etc/colors/" );
773 filestr.append( item-> text ( ) ); 773 filestr.append( item-> text ( ) );
774 filestr.append( ".scheme" ); 774 filestr.append( ".scheme" );
775 QFile::remove ( filestr ); 775 QFile::remove ( filestr );
776 delete item; 776 delete item;
777 } 777 }
778 } 778 }
779 else 779 else
780 { 780 {
781 QMessageBox::information( this, tr( "Delete scheme" ), tr( "Unable to delete current scheme." )); 781 QMessageBox::information( this, tr( "Delete scheme" ), tr( "Unable to delete current scheme." ));
782 } 782 }
783} 783}
784 784
785 785
786void Appearance::addExcept ( ) 786void Appearance::addExcept ( )
787{ 787{
788 ExceptListItem *it = new ExceptListItem ( m_except, 0, tr( "<new>" ), true, true, true ); 788 ExceptListItem *it = new ExceptListItem ( m_except, 0, tr( "<new>" ), true, true, true );
789 m_except-> ensureItemVisible ( it ); 789 m_except-> ensureItemVisible ( it );
790 m_except-> setSelected ( it, true ); 790 m_except-> setSelected ( it, true );
791} 791}
792 792
793void Appearance::delExcept ( ) 793void Appearance::delExcept ( )
794{ 794{
795 if ( m_except-> selectedItem ( )) 795 if ( m_except-> selectedItem ( ))
796 { 796 {
797 m_except-> setFocus ( ); 797 m_except-> setFocus ( );
798 delete m_except-> selectedItem ( ); 798 delete m_except-> selectedItem ( );
799 } 799 }
800} 800}
801 801
802void Appearance::upExcept ( ) 802void Appearance::upExcept ( )
803{ 803{
804 ExceptListItem *it = (ExceptListItem *) m_except-> selectedItem ( ); 804 ExceptListItem *it = (ExceptListItem *) m_except-> selectedItem ( );
805 805
806 if ( it && it-> itemAbove ( )) 806 if ( it && it-> itemAbove ( ))
807 it-> itemAbove ( )-> moveItem ( it ); 807 it-> itemAbove ( )-> moveItem ( it );
808} 808}
809 809
810void Appearance::downExcept ( ) 810void Appearance::downExcept ( )
811{ 811{
812 ExceptListItem *it = (ExceptListItem *) m_except-> selectedItem ( ); 812 ExceptListItem *it = (ExceptListItem *) m_except-> selectedItem ( );
813 813
814 if ( it && it-> itemBelow ( )) 814 if ( it && it-> itemBelow ( ))
815 it-> moveItem ( it-> itemBelow ( )); 815 it-> moveItem ( it-> itemBelow ( ));
816} 816}
817 817
818class ExEdit : public QLineEdit 818class ExEdit : public QLineEdit
819{ 819{
820public: 820public:
821 ExEdit ( ExceptListItem *item ) 821 ExEdit ( ExceptListItem *item )
822 : QLineEdit ( item-> listView ( )-> viewport ( ), "exedit" ), it ( item ) 822 : QLineEdit ( item-> listView ( )-> viewport ( ), "exedit" ), it ( item )
823 { 823 {
824 setFrame ( false ); 824 setFrame ( false );
825 825
826 QRect r = it-> listView ( )-> itemRect ( it ); 826 QRect r = it-> listView ( )-> itemRect ( it );
827 827
828 int x = it-> listView ( )-> header ( )-> cellPos ( 3 ) - 1; 828 int x = it-> listView ( )-> header ( )-> cellPos ( 3 ) - 1;
829 int y = r. y ( ); 829 int y = r. y ( );
830 int w = it-> listView ( )-> viewport ( )-> width ( ) - x; 830 int w = it-> listView ( )-> viewport ( )-> width ( ) - x;
831 int h = r. height ( ); // + 2; 831 int h = r. height ( ); // + 2;
832 832
833 setText ( it-> pattern ( )); 833 setText ( it-> pattern ( ));
834 setGeometry ( x, y, w, h ); 834 setGeometry ( x, y, w, h );
835 835
836 odebug << "ExEdit: [" << it->text(2).latin1() << "] at " 836 odebug << "ExEdit: [" << it->text(2).latin1() << "] at "
837 << x << "," << y << " " << w << "," << h << oendl; 837 << x << "," << y << " " << w << "," << h << oendl;
838 838
839 m_out = true; 839 m_out = true;
840 840
841 show ( ); 841 show ( );
842 setFocus ( ); 842 setFocus ( );
843 selectAll ( ); 843 selectAll ( );
844 end ( true ); 844 end ( true );
845 } 845 }
846 846
847 virtual void focusOutEvent ( QFocusEvent * ) 847 virtual void focusOutEvent ( QFocusEvent * )
848 { 848 {
849 hide ( ); 849 hide ( );
850 if ( m_out ) 850 if ( m_out )
851 it-> setPattern ( text ( )); 851 it-> setPattern ( text ( ));
852 delete this; 852 delete this;
853 } 853 }
854 854
855 virtual void keyPressEvent ( QKeyEvent *e ) 855 virtual void keyPressEvent ( QKeyEvent *e )
856 { 856 {
857 if ( e-> key ( ) == Key_Return ) 857 if ( e-> key ( ) == Key_Return )
858 it-> listView ( )-> setFocus ( ); 858 it-> listView ( )-> setFocus ( );
859 else if ( e-> key ( ) == Key_Escape ) 859 else if ( e-> key ( ) == Key_Escape )
860 { 860 {
861 m_out = false; 861 m_out = false;
862 it-> listView ( )-> setFocus ( ); 862 it-> listView ( )-> setFocus ( );
863 } 863 }
864 else 864 else
865 QLineEdit::keyPressEvent ( e ); 865 QLineEdit::keyPressEvent ( e );
866 } 866 }
867 867
868private: 868private:
869 ExceptListItem *it; 869 ExceptListItem *it;
870 bool m_out; 870 bool m_out;
871}; 871};
872 872
873void Appearance::clickedExcept ( QListViewItem *item, const QPoint &, int c ) 873void Appearance::clickedExcept ( QListViewItem *item, const QPoint &, int c )
874{ 874{
875 if ( !item || c < 0 || c > 3 ) 875 if ( !item || c < 0 || c > 3 )
876 return; 876 return;
877 877
878 ExceptListItem *it = (ExceptListItem *) item; 878 ExceptListItem *it = (ExceptListItem *) item;
879 879
880 if ( c == 0 ) 880 if ( c == 0 )
881 it-> setNoStyle ( !it-> noStyle ( )); 881 it-> setNoStyle ( !it-> noStyle ( ));
882 else if ( c == 1 ) 882 else if ( c == 1 )
883 it-> setNoFont ( !it-> noFont ( )); 883 it-> setNoFont ( !it-> noFont ( ));
884 else if ( c == 2 ) 884 else if ( c == 2 )
885 it-> setNoDeco ( !it-> noDeco ( )); 885 it-> setNoDeco ( !it-> noDeco ( ));
886 else if ( c == 3 ) 886 else if ( c == 3 )
887 { 887 {
888 m_except-> ensureItemVisible ( it ); 888 m_except-> ensureItemVisible ( it );
889 new ExEdit ( it ); 889 new ExEdit ( it );
890 } 890 }
891} 891}
892 892
diff --git a/noncore/settings/doctab/doctab.cpp b/noncore/settings/doctab/doctab.cpp
index feaf538..72eda6b 100644
--- a/noncore/settings/doctab/doctab.cpp
+++ b/noncore/settings/doctab/doctab.cpp
@@ -1,94 +1,94 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "doctab.h" 21#include "doctab.h"
22 22
23#include <qpe/global.h> 23#include <qpe/global.h>
24#include <qpe/fontmanager.h> 24#include <qpe/fontmanager.h>
25#include <qpe/config.h> 25#include <qpe/config.h>
26#include <qpe/applnk.h> 26#include <qpe/applnk.h>
27#include <qpe/qpedialog.h> 27#include <qpe/qpedialog.h>
28#include <qpe/qpeapplication.h> 28#include <qpe/qpeapplication.h>
29#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 29#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
30#include <qpe/qcopenvelope_qws.h> 30#include <qpe/qcopenvelope_qws.h>
31#endif 31#endif
32 32
33#include <qlabel.h> 33#include <qlabel.h>
34#include <qcheckbox.h> 34#include <qcheckbox.h>
35#include <qradiobutton.h> 35#include <qradiobutton.h>
36#include <qtabwidget.h> 36#include <qtabwidget.h>
37#include <qslider.h> 37#include <qslider.h>
38#include <qfile.h> 38#include <qfile.h>
39#include <qtextstream.h> 39#include <qtextstream.h>
40#include <qdatastream.h> 40#include <qdatastream.h>
41#include <qmessagebox.h> 41#include <qmessagebox.h>
42#include <qcombobox.h> 42#include <qcombobox.h>
43#include <qspinbox.h> 43#include <qspinbox.h>
44#include <qlistbox.h> 44#include <qlistbox.h>
45#include <qdir.h> 45#include <qdir.h>
46#if QT_VERSION >= 300 46#if QT_VERSION >= 0x030000
47#include <qstylefactory.h> 47#include <qstylefactory.h>
48#endif 48#endif
49 49
50#include <stdlib.h> 50#include <stdlib.h>
51 51
52 52
53DocTabSettings::DocTabSettings( QWidget* parent, const char* name, WFlags fl ) 53DocTabSettings::DocTabSettings( QWidget* parent, const char* name, WFlags fl )
54 : DocTabSettingsBase( parent, name, TRUE, fl ) 54 : DocTabSettingsBase( parent, name, TRUE, fl )
55{ 55{
56 dl = new QPEDialogListener(this); 56 dl = new QPEDialogListener(this);
57 reset(); 57 reset();
58} 58}
59 59
60DocTabSettings::~DocTabSettings() 60DocTabSettings::~DocTabSettings()
61{} 61{}
62 62
63void DocTabSettings::accept() 63void DocTabSettings::accept()
64{ 64{
65 applyDocTab(); 65 applyDocTab();
66 QDialog::accept(); 66 QDialog::accept();
67} 67}
68 68
69void DocTabSettings::applyDocTab() 69void DocTabSettings::applyDocTab()
70{ 70{
71 Config cfg( "Launcher" ); 71 Config cfg( "Launcher" );
72 cfg.setGroup( "DocTab" ); 72 cfg.setGroup( "DocTab" );
73 cfg.writeEntry( "Enable", yes->isChecked() ); 73 cfg.writeEntry( "Enable", yes->isChecked() );
74 cfg.write(); 74 cfg.write();
75} 75}
76 76
77 77
78void DocTabSettings::reject() 78void DocTabSettings::reject()
79{ 79{
80 reset(); 80 reset();
81 QDialog::reject(); 81 QDialog::reject();
82} 82}
83 83
84void DocTabSettings::reset() 84void DocTabSettings::reset()
85{ 85{
86} 86}
87 87
88QString DocTabSettings::actualDocTab; 88QString DocTabSettings::actualDocTab;
89 89
90void DocTabSettings::done(int r) 90void DocTabSettings::done(int r)
91{ 91{
92 QDialog::done(r); 92 QDialog::done(r);
93 close(); 93 close();
94} 94}
diff --git a/noncore/settings/language/language.cpp b/noncore/settings/language/language.cpp
index 14750ac..bf90576 100644
--- a/noncore/settings/language/language.cpp
+++ b/noncore/settings/language/language.cpp
@@ -1,159 +1,159 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "settings.h" 21#include "settings.h"
22 22
23#include <qpe/global.h> 23#include <qpe/global.h>
24#include <qpe/fontmanager.h> 24#include <qpe/fontmanager.h>
25#include <qpe/config.h> 25#include <qpe/config.h>
26#include <qpe/applnk.h> 26#include <qpe/applnk.h>
27#include <qpe/qpedialog.h> 27#include <qpe/qpedialog.h>
28#include <qpe/qpeapplication.h> 28#include <qpe/qpeapplication.h>
29#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 29#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
30#include <qpe/qcopenvelope_qws.h> 30#include <qpe/qcopenvelope_qws.h>
31#endif 31#endif
32 32
33#include <qlabel.h> 33#include <qlabel.h>
34#include <qcheckbox.h> 34#include <qcheckbox.h>
35#include <qradiobutton.h> 35#include <qradiobutton.h>
36#include <qtabwidget.h> 36#include <qtabwidget.h>
37#include <qslider.h> 37#include <qslider.h>
38#include <qfile.h> 38#include <qfile.h>
39#include <qtextstream.h> 39#include <qtextstream.h>
40#include <qdatastream.h> 40#include <qdatastream.h>
41#include <qmessagebox.h> 41#include <qmessagebox.h>
42#include <qcombobox.h> 42#include <qcombobox.h>
43#include <qspinbox.h> 43#include <qspinbox.h>
44#include <qlistbox.h> 44#include <qlistbox.h>
45#include <qdir.h> 45#include <qdir.h>
46#if QT_VERSION >= 300 46#if QT_VERSION >= 0x030000
47#include <qstylefactory.h> 47#include <qstylefactory.h>
48#endif 48#endif
49 49
50#include <stdlib.h> 50#include <stdlib.h>
51 51
52 52
53LanguageSettings::LanguageSettings( QWidget* parent, const char* name, WFlags fl ) 53LanguageSettings::LanguageSettings( QWidget* parent, const char* name, WFlags fl )
54 : LanguageSettingsBase( parent, name, TRUE, fl ) 54 : LanguageSettingsBase( parent, name, TRUE, fl )
55{ 55{
56 if ( FontManager::hasUnicodeFont() ) 56 if ( FontManager::hasUnicodeFont() )
57 languages->setFont(FontManager::unicodeFont(FontManager::Proportional)); 57 languages->setFont(FontManager::unicodeFont(FontManager::Proportional));
58 58
59 59
60 QString tfn = QPEApplication::qpeDir() + "i18n/"; 60 QString tfn = QPEApplication::qpeDir() + "i18n/";
61 QDir langDir = tfn; 61 QDir langDir = tfn;
62 QStringList list = langDir.entryList("*", QDir::Dirs ); 62 QStringList list = langDir.entryList("*", QDir::Dirs );
63 63
64 QStringList::Iterator it; 64 QStringList::Iterator it;
65 65
66 for ( it = list.begin(); it != list.end(); ++it ) { 66 for ( it = list.begin(); it != list.end(); ++it ) {
67 QString name = (*it); 67 QString name = (*it);
68 QFileInfo desktopFile( tfn + "/" + name + "/.directory" ); 68 QFileInfo desktopFile( tfn + "/" + name + "/.directory" );
69 if ( desktopFile.exists() ) { 69 if ( desktopFile.exists() ) {
70 langAvail.append(name); 70 langAvail.append(name);
71 Config conf( desktopFile.filePath(), Config::File ); 71 Config conf( desktopFile.filePath(), Config::File );
72 QString langName = conf.readEntry( "Name" ); 72 QString langName = conf.readEntry( "Name" );
73 QString ownName = conf.readEntryDirect( "Name[" + name + "]" ); 73 QString ownName = conf.readEntryDirect( "Name[" + name + "]" );
74 if ( ownName.isEmpty() ) 74 if ( ownName.isEmpty() )
75 ownName = conf.readEntryDirect( "Name" ); 75 ownName = conf.readEntryDirect( "Name" );
76 if ( !ownName.isEmpty() && ownName != langName ) 76 if ( !ownName.isEmpty() && ownName != langName )
77 langName = langName + " [" + ownName + "]"; 77 langName = langName + " [" + ownName + "]";
78 languages->insertItem( langName ); 78 languages->insertItem( langName );
79 79
80 } 80 }
81 } 81 }
82 if ( langAvail. find ( "en" ) == -1 ) { 82 if ( langAvail. find ( "en" ) == -1 ) {
83 langAvail. prepend ( "" ); // no tr 83 langAvail. prepend ( "" ); // no tr
84 languages-> insertItem ( QString ( "English [%1] (%2)" /* no tr (!) */ ). arg ( tr ( "English" )). arg ( tr( "default" )), 0 ); 84 languages-> insertItem ( QString ( "English [%1] (%2)" /* no tr (!) */ ). arg ( tr ( "English" )). arg ( tr( "default" )), 0 );
85 } 85 }
86 86
87 dl = new QPEDialogListener(this); 87 dl = new QPEDialogListener(this);
88 reset(); 88 reset();
89} 89}
90 90
91LanguageSettings::~LanguageSettings() 91LanguageSettings::~LanguageSettings()
92{} 92{}
93 93
94void LanguageSettings::accept() 94void LanguageSettings::accept()
95{ 95{
96 Config c( "qpe" ); 96 Config c( "qpe" );
97 c.setGroup( "Startup" ); 97 c.setGroup( "Startup" );
98 if ( ( c.readNumEntry( "FirstUse", 42 ) == 0 ) && 98 if ( ( c.readNumEntry( "FirstUse", 42 ) == 0 ) &&
99 ( QMessageBox::warning( this, tr("Language"), tr("<qt>Attention, all windows will be closed by changing the language\n" 99 ( QMessageBox::warning( this, tr("Language"), tr("<qt>Attention, all windows will be closed by changing the language\n"
100 "without saving the Data.<br><br>Go on?</qt>"), 1, 2) ) 100 "without saving the Data.<br><br>Go on?</qt>"), 1, 2) )
101 == QMessageBox::Cancel ) 101 == QMessageBox::Cancel )
102 return; 102 return;
103 applyLanguage(); 103 applyLanguage();
104 QDialog::accept(); 104 QDialog::accept();
105} 105}
106 106
107void LanguageSettings::applyLanguage() 107void LanguageSettings::applyLanguage()
108{ 108{
109 setLanguage ( langAvail. at ( languages-> currentItem ( ))); 109 setLanguage ( langAvail. at ( languages-> currentItem ( )));
110} 110}
111 111
112 112
113void LanguageSettings::reject() 113void LanguageSettings::reject()
114{ 114{
115 reset(); 115 reset();
116 QDialog::reject(); 116 QDialog::reject();
117} 117}
118 118
119void LanguageSettings::reset() 119void LanguageSettings::reset()
120{ 120{
121 QString l = getenv("LANG"); 121 QString l = getenv("LANG");
122 Config config("locale"); 122 Config config("locale");
123 config.setGroup("Language"); 123 config.setGroup("Language");
124 l = config.readEntry( "Language", l ); 124 l = config.readEntry( "Language", l );
125 actualLanguage = l; 125 actualLanguage = l;
126 if (l.isEmpty()) 126 if (l.isEmpty())
127 l = "en"; 127 l = "en";
128 128
129 int n = langAvail.find( l ); 129 int n = langAvail.find( l );
130 languages->setCurrentItem( n ); 130 languages->setCurrentItem( n );
131} 131}
132 132
133QString LanguageSettings::actualLanguage; 133QString LanguageSettings::actualLanguage;
134 134
135void LanguageSettings::setLanguage(const QString& lang) 135void LanguageSettings::setLanguage(const QString& lang)
136{ 136{
137 if ( lang != actualLanguage ) { 137 if ( lang != actualLanguage ) {
138 Config config("locale"); 138 Config config("locale");
139 config.setGroup( "Language" ); 139 config.setGroup( "Language" );
140 if ( lang. isEmpty ( )) 140 if ( lang. isEmpty ( ))
141 config. removeEntry ( "Language" ); 141 config. removeEntry ( "Language" );
142 else 142 else
143 config.writeEntry( "Language", lang ); 143 config.writeEntry( "Language", lang );
144 config.write(); 144 config.write();
145 145
146#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 146#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
147 147
148 QCopEnvelope e("QPE/System", "language(QString)"); 148 QCopEnvelope e("QPE/System", "language(QString)");
149 e << lang; 149 e << lang;
150#endif 150#endif
151 151
152 } 152 }
153} 153}
154 154
155void LanguageSettings::done(int r) 155void LanguageSettings::done(int r)
156{ 156{
157 QDialog::done(r); 157 QDialog::done(r);
158 close(); 158 close();
159} 159}
diff --git a/noncore/settings/networksettings/interfaces/module.h b/noncore/settings/networksettings/interfaces/module.h
index 9dc913e..13189c3 100644
--- a/noncore/settings/networksettings/interfaces/module.h
+++ b/noncore/settings/networksettings/interfaces/module.h
@@ -1,188 +1,188 @@
1#ifndef NETCONF_MODULE_H 1#ifndef NETCONF_MODULE_H
2#define NETCONF_MODULE_H 2#define NETCONF_MODULE_H
3 3
4#include <qobject.h> 4#include <qobject.h>
5#if QT_VERSION < 300 5#if QT_VERSION < 0x030000
6#include <qlist.h> 6#include <qlist.h>
7#else 7#else
8#include <qptrlist.h> 8#include <qptrlist.h>
9#endif 9#endif
10#include <qmap.h> 10#include <qmap.h>
11#include "interface.h" 11#include "interface.h"
12 12
13class QWidget; 13class QWidget;
14class QTabWidget; 14class QTabWidget;
15 15
16 16
17/** 17/**
18 * \brief The basis of all plugins 18 * \brief The basis of all plugins
19 * 19 *
20 * This is the way to extend networksettings with 20 * This is the way to extend networksettings with
21 * extra functionality. 21 * extra functionality.
22 * 22 *
23 * 23 *
24 * Networksettings in the 1.0 release does not use QCOM 24 * Networksettings in the 1.0 release does not use QCOM
25 * for activation. You need to provide the following function yourself. 25 * for activation. You need to provide the following function yourself.
26 * 26 *
27 * A module needs to provide Name, Images, and methods for 27 * A module needs to provide Name, Images, and methods for
28 * claiming interfaces. For example you can claim physicla 28 * claiming interfaces. For example you can claim physicla
29 * interfaces like wlan0, ppp0 or virtual like a VPN 29 * interfaces like wlan0, ppp0 or virtual like a VPN
30 * connection and hide the real ppp device or ethernet device 30 * connection and hide the real ppp device or ethernet device
31 * behind your VPN plugin. 31 * behind your VPN plugin.
32 * 32 *
33 * During start up. The main application searches for network devices 33 * During start up. The main application searches for network devices
34 * and then looks for an owner under the plugins for them. 34 * and then looks for an owner under the plugins for them.
35 * For example the WLAN Plugin looks if there is a WLAN Extension 35 * For example the WLAN Plugin looks if there is a WLAN Extension
36 * on that interface and then claims it by returning true from isOwner() 36 * on that interface and then claims it by returning true from isOwner()
37 * 37 *
38 * \code 38 * \code
39 * extern "C" 39 * extern "C"
40 * { 40 * {
41 * void* create_plugin() { 41 * void* create_plugin() {
42 * return new WLANModule(); 42 * return new WLANModule();
43 * } 43 * }
44 * }; 44 * };
45 * \endcode 45 * \endcode
46 * @see isOwner(Interface*) 46 * @see isOwner(Interface*)
47 */ 47 */
48class Module : private QObject{ 48class Module : private QObject{
49 49
50signals: 50signals:
51/** 51/**
52 * Emit this Signal once you change the Interface 52 * Emit this Signal once you change the Interface
53 * you're operating on 53 * you're operating on
54 * 54 *
55 * @param i The Interface 55 * @param i The Interface
56 */ 56 */
57 void updateInterface(Interface *i); 57 void updateInterface(Interface *i);
58 58
59 59
60public: 60public:
61 Module(){}; 61 Module(){};
62 62
63 /** 63 /**
64 * The type of the plugin 64 * The type of the plugin
65 * and the name of the qcop call 65 * and the name of the qcop call
66 */ 66 */
67 virtual const QString type() = 0; 67 virtual const QString type() = 0;
68 68
69 /** 69 /**
70 * The current profile has been changed and the module should do any 70 * The current profile has been changed and the module should do any
71 * neccesary changes also. 71 * neccesary changes also.
72 * As of Opie1.0 profiles are disabled. 72 * As of Opie1.0 profiles are disabled.
73 * 73 *
74 * @param newProfile what the profile should be changed to. 74 * @param newProfile what the profile should be changed to.
75 */ 75 */
76 virtual void setProfile(const QString &newProfile) = 0; 76 virtual void setProfile(const QString &newProfile) = 0;
77 77
78 /** 78 /**
79 * get the icon name for this device. 79 * get the icon name for this device.
80 * @param Interface* can be used in determining the icon. 80 * @param Interface* can be used in determining the icon.
81 * @return QString the icon name (minus .png, .gif etc) 81 * @return QString the icon name (minus .png, .gif etc)
82 */ 82 */
83 virtual QString getPixmapName(Interface *) = 0; 83 virtual QString getPixmapName(Interface *) = 0;
84 84
85 /** 85 /**
86 * Check to see if the interface i is owned by this module. 86 * Check to see if the interface i is owned by this module.
87 * See if you can handle it. And if you can claim ownership 87 * See if you can handle it. And if you can claim ownership
88 * by returning true. 88 * by returning true.
89 * For physical devices you will be asked if you want to own the 89 * For physical devices you will be asked if you want to own the
90 * device. But you can also create new \sa Interface Implementations. 90 * device. But you can also create new \sa Interface Implementations.
91 * 91 *
92 * If you want to own the Interface add it to your internal interface 92 * If you want to own the Interface add it to your internal interface
93 * list 93 * list
94 * 94 *
95 * @param Interface* interface to check against 95 * @param Interface* interface to check against
96 * @return bool true if i is owned by this module, false otherwise. 96 * @return bool true if i is owned by this module, false otherwise.
97 * 97 *
98 * @see getInterfaces 98 * @see getInterfaces
99 */ 99 */
100 virtual bool isOwner(Interface *){ return false; }; 100 virtual bool isOwner(Interface *){ return false; };
101 101
102 /** 102 /**
103 * Create and return the Configure Module 103 * Create and return the Configure Module
104 * @param Interface *i the interface to configure. 104 * @param Interface *i the interface to configure.
105 * @return QWidget* pointer to this modules configure. 105 * @return QWidget* pointer to this modules configure.
106 * 106 *
107 * @see InterfaceSetupImp 107 * @see InterfaceSetupImp
108 */ 108 */
109 virtual QWidget *configure(Interface *){ return NULL; } ; 109 virtual QWidget *configure(Interface *){ return NULL; } ;
110 110
111 /** 111 /**
112 * Create, and return the Information Module. 112 * Create, and return the Information Module.
113 * 113 *
114 * An default Implementation is InterfaceInformationImp 114 * An default Implementation is InterfaceInformationImp
115 * 115 *
116 * @param Interface *i the interface to get info on. 116 * @param Interface *i the interface to get info on.
117 * @return QWidget* pointer to this modules info. 117 * @return QWidget* pointer to this modules info.
118 * 118 *
119 * @see InterfaceInformationImp 119 * @see InterfaceInformationImp
120 * 120 *
121 */ 121 */
122 virtual QWidget *information(Interface *){ return NULL; }; 122 virtual QWidget *information(Interface *){ return NULL; };
123 123
124 /** 124 /**
125 * Get all active (up or down) interfaces managed by this 125 * Get all active (up or down) interfaces managed by this
126 * module. 126 * module.
127 * At the end of initialisation you will be asked to return your interfaces 127 * At the end of initialisation you will be asked to return your interfaces
128 * Return all of your interfaces even the ones you claimed by isOnwer. 128 * Return all of your interfaces even the ones you claimed by isOnwer.
129 * Here you can also return your 'virtual' Interface Objects 129 * Here you can also return your 'virtual' Interface Objects
130 * 130 *
131 * @return QList<Interface> A list of interfaces that exsist that havn't 131 * @return QList<Interface> A list of interfaces that exsist that havn't
132 * been called by isOwner() 132 * been called by isOwner()
133 */ 133 */
134 virtual QList<Interface> getInterfaces() = 0; 134 virtual QList<Interface> getInterfaces() = 0;
135 135
136 /** 136 /**
137 * Adds possible new interfaces to the list (Example: usb(ppp), ir(ppp), 137 * Adds possible new interfaces to the list (Example: usb(ppp), ir(ppp),
138 * modem ppp) 138 * modem ppp)
139 * Both strings need to be translated. The first string is a Shortcut 139 * Both strings need to be translated. The first string is a Shortcut
140 * like PPP and the second argument is a description. 140 * like PPP and the second argument is a description.
141 * 141 *
142 * <code> 142 * <code>
143 * list.insert( 143 * list.insert(
144 * 144 *
145 * </code> 145 * </code>
146 * 146 *
147 * @param list A reference to the list of supported additionns. 147 * @param list A reference to the list of supported additionns.
148 */ 148 */
149 virtual void possibleNewInterfaces(QMap<QString, QString> &list) = 0; 149 virtual void possibleNewInterfaces(QMap<QString, QString> &list) = 0;
150 150
151 /** 151 /**
152 * Attempts to create a new interface from name you gave 152 * Attempts to create a new interface from name you gave
153 * possibleNewInterfaces() 153 * possibleNewInterfaces()
154 * @return Interface* NULL if it was unable to be created. 154 * @return Interface* NULL if it was unable to be created.
155 * @param name the type of interface to create 155 * @param name the type of interface to create
156 * 156 *
157 * @see possibleNewInterfaces 157 * @see possibleNewInterfaces
158 */ 158 */
159 virtual Interface *addNewInterface(const QString &name) = 0; 159 virtual Interface *addNewInterface(const QString &name) = 0;
160 160
161 /** 161 /**
162 * Attempts to remove the interface, doesn't delete i 162 * Attempts to remove the interface, doesn't delete i
163 * @return bool true if successful, false otherwise. 163 * @return bool true if successful, false otherwise.
164 */ 164 */
165 virtual bool remove(Interface* i) = 0; 165 virtual bool remove(Interface* i) = 0;
166 166
167 /** 167 /**
168 * get dcop calls 168 * get dcop calls
169 */ 169 */
170 virtual void receive(const QCString &msg, const QByteArray &arg) = 0; 170 virtual void receive(const QCString &msg, const QByteArray &arg) = 0;
171 171
172 QStringList handledInterfaceNames()const { return m_inter; } 172 QStringList handledInterfaceNames()const { return m_inter; }
173protected: 173protected:
174 /** 174 /**
175 * set which interfaceNames should not be shown cause they're handled 175 * set which interfaceNames should not be shown cause they're handled
176 * internally of this module.. An already running ppp link or 176 * internally of this module.. An already running ppp link or
177 * a tunnel... VPN an such 177 * a tunnel... VPN an such
178 */ 178 */
179 void setHandledInterfaceNames( const QStringList& in) { m_inter = in; } 179 void setHandledInterfaceNames( const QStringList& in) { m_inter = in; }
180 180
181private: 181private:
182 QStringList m_inter; 182 QStringList m_inter;
183}; 183};
184 184
185#endif 185#endif
186 186
187// module.h 187// module.h
188 188
diff --git a/noncore/settings/networksettings/mainwindow/addconnectionimp.cpp b/noncore/settings/networksettings/mainwindow/addconnectionimp.cpp
index 84f1cf6..9049af4 100644
--- a/noncore/settings/networksettings/mainwindow/addconnectionimp.cpp
+++ b/noncore/settings/networksettings/mainwindow/addconnectionimp.cpp
@@ -1,41 +1,41 @@
1#include "addconnectionimp.h" 1#include "addconnectionimp.h"
2#include <qlistview.h> 2#include <qlistview.h>
3#if QT_VERSION < 300 3#if QT_VERSION < 0x030000
4#include <qlist.h> 4#include <qlist.h>
5#else 5#else
6#include <qptrlist.h> 6#include <qptrlist.h>
7#endif 7#endif
8#include <qlabel.h> 8#include <qlabel.h>
9#include <qheader.h> 9#include <qheader.h>
10 10
11/** 11/**
12 * Constructor 12 * Constructor
13 */ 13 */
14AddConnectionImp::AddConnectionImp(QWidget *parent, const char *name, WFlags f):AddConnection(parent, name, f){ 14AddConnectionImp::AddConnectionImp(QWidget *parent, const char *name, WFlags f):AddConnection(parent, name, f){
15 connect(registeredServicesList, SIGNAL(selectionChanged()), this, SLOT(changed())); 15 connect(registeredServicesList, SIGNAL(selectionChanged()), this, SLOT(changed()));
16 registeredServicesList->header()->hide(); 16 registeredServicesList->header()->hide();
17}; 17};
18 18
19/** 19/**
20 * The current item changed, update the discription. 20 * The current item changed, update the discription.
21 */ 21 */
22void AddConnectionImp::changed(){ 22void AddConnectionImp::changed(){
23 QListViewItem *item = registeredServicesList->currentItem(); 23 QListViewItem *item = registeredServicesList->currentItem();
24 if(item) 24 if(item)
25 help->setText(list[item->text(0)]); 25 help->setText(list[item->text(0)]);
26} 26}
27 27
28/** 28/**
29 * Save a copy of newList for the discriptions and append them all to the view 29 * Save a copy of newList for the discriptions and append them all to the view
30 * @param newList the new list of possible interfaces 30 * @param newList the new list of possible interfaces
31 */ 31 */
32void AddConnectionImp::addConnections(const QMap<QString, QString> &newList){ 32void AddConnectionImp::addConnections(const QMap<QString, QString> &newList){
33 list = newList; 33 list = newList;
34 QMap<QString, QString>::Iterator it; 34 QMap<QString, QString>::Iterator it;
35 for( it = list.begin(); it != list.end(); ++it ) 35 for( it = list.begin(); it != list.end(); ++it )
36 (void)new QListViewItem(registeredServicesList, it.key()); 36 (void)new QListViewItem(registeredServicesList, it.key());
37 registeredServicesList->setCurrentItem(registeredServicesList->firstChild()); 37 registeredServicesList->setCurrentItem(registeredServicesList->firstChild());
38} 38}
39 39
40// addserviceimp.cpp 40// addserviceimp.cpp
41 41
diff --git a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
index 5f23aea..8feb7a5 100644
--- a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
@@ -1,713 +1,713 @@
1 1
2#include "mainwindowimp.h" 2#include "mainwindowimp.h"
3#include "addconnectionimp.h" 3#include "addconnectionimp.h"
4#include "interfaceinformationimp.h" 4#include "interfaceinformationimp.h"
5#include "interfacesetupimp.h" 5#include "interfacesetupimp.h"
6#include "interfaces.h" 6#include "interfaces.h"
7#include "module.h" 7#include "module.h"
8 8
9/* OPIE */ 9/* OPIE */
10#include <opie2/odebug.h> 10#include <opie2/odebug.h>
11#include <qpe/qcopenvelope_qws.h> 11#include <qpe/qcopenvelope_qws.h>
12#include <qpe/qpeapplication.h> 12#include <qpe/qpeapplication.h>
13#include <qpe/config.h> 13#include <qpe/config.h>
14#include <qpe/qlibrary.h> 14#include <qpe/qlibrary.h>
15#include <qpe/resource.h> 15#include <qpe/resource.h>
16 16
17/* QT */ 17/* QT */
18#include <qpushbutton.h> 18#include <qpushbutton.h>
19#include <qlistbox.h> 19#include <qlistbox.h>
20#include <qlineedit.h> 20#include <qlineedit.h>
21#include <qlistview.h> 21#include <qlistview.h>
22#include <qheader.h> 22#include <qheader.h>
23#include <qlabel.h> 23#include <qlabel.h>
24#include <qtabwidget.h> // in order to disable the profiles tab 24#include <qtabwidget.h> // in order to disable the profiles tab
25#include <qmessagebox.h> 25#include <qmessagebox.h>
26 26
27 27
28#if QT_VERSION < 300 28#if QT_VERSION < 0x030000
29#include <qlist.h> 29#include <qlist.h>
30#else 30#else
31#include <qptrlist.h> 31#include <qptrlist.h>
32#endif 32#endif
33#include <qdir.h> 33#include <qdir.h>
34#include <qfile.h> 34#include <qfile.h>
35#include <qtextstream.h> 35#include <qtextstream.h>
36#include <qregexp.h> 36#include <qregexp.h>
37 37
38/* STD */ 38/* STD */
39#include <net/if.h> 39#include <net/if.h>
40#include <sys/ioctl.h> 40#include <sys/ioctl.h>
41#include <sys/socket.h> 41#include <sys/socket.h>
42 42
43#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" 43#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme"
44#define _PROCNETDEV "/proc/net/dev" 44#define _PROCNETDEV "/proc/net/dev"
45 45
46MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWindow(parent, name, Qt::WStyle_ContextHelp), advancedUserMode(true), scheme(DEFAULT_SCHEME) 46MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWindow(parent, name, Qt::WStyle_ContextHelp), advancedUserMode(true), scheme(DEFAULT_SCHEME)
47{ 47{
48 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); 48 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
49 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); 49 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
50 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); 50 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
51 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); 51 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
52 52
53 //remove tab with no function 53 //remove tab with no function
54 tabWidget->removePage( tab ); 54 tabWidget->removePage( tab );
55 55
56 // Load connections. 56 // Load connections.
57 // /usr/local/kde/lib/libinterfaces.la 57 // /usr/local/kde/lib/libinterfaces.la
58 loadModules(QPEApplication::qpeDir() + "plugins/networksettings"); 58 loadModules(QPEApplication::qpeDir() + "plugins/networksettings");
59 getAllInterfaces(); 59 getAllInterfaces();
60 60
61 Interfaces i; 61 Interfaces i;
62 QStringList list = i.getInterfaceList(); 62 QStringList list = i.getInterfaceList();
63 QMap<QString, Interface*>::Iterator it; 63 QMap<QString, Interface*>::Iterator it;
64 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) 64 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni )
65 { 65 {
66 /* 66 /*
67 * we skipped it in getAllInterfaces now 67 * we skipped it in getAllInterfaces now
68 * we need to ignore it as well 68 * we need to ignore it as well
69 */ 69 */
70 if (m_handledIfaces.contains( *ni) ) 70 if (m_handledIfaces.contains( *ni) )
71 { 71 {
72 odebug << "Not up iface handled by module" << oendl; 72 odebug << "Not up iface handled by module" << oendl;
73 continue; 73 continue;
74 } 74 }
75 bool found = false; 75 bool found = false;
76 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ) 76 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it )
77 { 77 {
78 if(it.key() == (*ni)) 78 if(it.key() == (*ni))
79 found = true; 79 found = true;
80 } 80 }
81 if(!found) 81 if(!found)
82 { 82 {
83 if(!(*ni).contains("_")) 83 if(!(*ni).contains("_"))
84 { 84 {
85 Interface *i = new Interface(this, *ni, false); 85 Interface *i = new Interface(this, *ni, false);
86 i->setAttached(false); 86 i->setAttached(false);
87 i->setHardwareName(tr("Disconnected")); 87 i->setHardwareName(tr("Disconnected"));
88 interfaceNames.insert(i->getInterfaceName(), i); 88 interfaceNames.insert(i->getInterfaceName(), i);
89 updateInterface(i); 89 updateInterface(i);
90 connect(i, SIGNAL(updateInterface(Interface*)), this, SLOT(updateInterface(Interface*))); 90 connect(i, SIGNAL(updateInterface(Interface*)), this, SLOT(updateInterface(Interface*)));
91 } 91 }
92 } 92 }
93 } 93 }
94 94
95 //getInterfaceList(); 95 //getInterfaceList();
96 connectionList->header()->hide(); 96 connectionList->header()->hide();
97 97
98 Config cfg("NetworkSetup"); 98 Config cfg("NetworkSetup");
99 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); 99 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
100 for ( QStringList::Iterator it = profiles.begin(); 100 for ( QStringList::Iterator it = profiles.begin();
101 it != profiles.end(); ++it) 101 it != profiles.end(); ++it)
102 profilesList->insertItem((*it)); 102 profilesList->insertItem((*it));
103 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); 103 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All"));
104 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); 104 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
105 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); 105 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME);
106 106
107 QFile file(scheme); 107 QFile file(scheme);
108 if ( file.open(IO_ReadOnly) ) 108 if ( file.open(IO_ReadOnly) )
109 { // file opened successfully 109 { // file opened successfully
110 QTextStream stream( &file ); // use a text stream 110 QTextStream stream( &file ); // use a text stream
111 while ( !stream.eof() ) 111 while ( !stream.eof() )
112 { // until end of file... 112 { // until end of file...
113 QString line = stream.readLine(); // line of text excluding '\n' 113 QString line = stream.readLine(); // line of text excluding '\n'
114 if(line.contains("SCHEME")) 114 if(line.contains("SCHEME"))
115 { 115 {
116 line = line.mid(7, line.length()); 116 line = line.mid(7, line.length());
117 currentProfileLabel->setText(line); 117 currentProfileLabel->setText(line);
118 break; 118 break;
119 } 119 }
120 } 120 }
121 file.close(); 121 file.close();
122 } 122 }
123 makeChannel(); 123 makeChannel();
124} 124}
125 125
126/** 126/**
127 * Deconstructor. Save profiles. Delete loaded libraries. 127 * Deconstructor. Save profiles. Delete loaded libraries.
128 */ 128 */
129MainWindowImp::~MainWindowImp() 129MainWindowImp::~MainWindowImp()
130{ 130{
131 // Save profiles. 131 // Save profiles.
132 Config cfg("NetworkSetup"); 132 Config cfg("NetworkSetup");
133 cfg.setGroup("General"); 133 cfg.setGroup("General");
134 cfg.writeEntry("Profiles", profiles.join(" ")); 134 cfg.writeEntry("Profiles", profiles.join(" "));
135 135
136 // Delete all interfaces that don't have owners. 136 // Delete all interfaces that don't have owners.
137 QMap<Interface*, QListViewItem*>::Iterator iIt; 137 QMap<Interface*, QListViewItem*>::Iterator iIt;
138 for( iIt = items.begin(); iIt != items.end(); ++iIt ) 138 for( iIt = items.begin(); iIt != items.end(); ++iIt )
139 { 139 {
140 if(iIt.key()->getModuleOwner() == NULL) 140 if(iIt.key()->getModuleOwner() == NULL)
141 delete iIt.key(); 141 delete iIt.key();
142 } 142 }
143 143
144 // Delete Modules and Libraries 144 // Delete Modules and Libraries
145 QMap<Module*, QLibrary*>::Iterator it; 145 QMap<Module*, QLibrary*>::Iterator it;
146 for( it = libraries.begin(); it != libraries.end(); ++it ) 146 for( it = libraries.begin(); it != libraries.end(); ++it )
147 { 147 {
148 delete it.key(); 148 delete it.key();
149 // I wonder why I can't delete the libraries 149 // I wonder why I can't delete the libraries
150 // What fucking shit this is. 150 // What fucking shit this is.
151 //delete it.data(); 151 //delete it.data();
152 } 152 }
153} 153}
154 154
155/** 155/**
156 * Query the kernel for all of the interfaces. 156 * Query the kernel for all of the interfaces.
157 */ 157 */
158void MainWindowImp::getAllInterfaces() 158void MainWindowImp::getAllInterfaces()
159{ 159{
160 int sockfd = socket(PF_INET, SOCK_DGRAM, 0); 160 int sockfd = socket(PF_INET, SOCK_DGRAM, 0);
161 if(sockfd == -1) 161 if(sockfd == -1)
162 return; 162 return;
163 163
164 struct ifreq ifr; 164 struct ifreq ifr;
165 QStringList ifaces; 165 QStringList ifaces;
166 QFile procFile(QString(_PROCNETDEV)); 166 QFile procFile(QString(_PROCNETDEV));
167 int result; 167 int result;
168 Interface *i; 168 Interface *i;
169 169
170 if (! procFile.exists()) 170 if (! procFile.exists())
171 { 171 {
172 struct ifreq ifrs[100]; 172 struct ifreq ifrs[100];
173 struct ifconf ifc; 173 struct ifconf ifc;
174 ifc.ifc_len = sizeof(ifrs); 174 ifc.ifc_len = sizeof(ifrs);
175 ifc.ifc_req = ifrs; 175 ifc.ifc_req = ifrs;
176 result = ioctl(sockfd, SIOCGIFCONF, &ifc); 176 result = ioctl(sockfd, SIOCGIFCONF, &ifc);
177 177
178 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) 178 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++)
179 { 179 {
180 struct ifreq *pifr = &ifrs[i]; 180 struct ifreq *pifr = &ifrs[i];
181 181
182 ifaces += pifr->ifr_name; 182 ifaces += pifr->ifr_name;
183 } 183 }
184 } 184 }
185 else 185 else
186 { 186 {
187 procFile.open(IO_ReadOnly); 187 procFile.open(IO_ReadOnly);
188 QString line; 188 QString line;
189 QTextStream procTs(&procFile); 189 QTextStream procTs(&procFile);
190 int loc = -1; 190 int loc = -1;
191 191
192 procTs.readLine(); // eat a line 192 procTs.readLine(); // eat a line
193 procTs.readLine(); // eat a line 193 procTs.readLine(); // eat a line
194 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) 194 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null)
195 { 195 {
196 if((loc = line.find(":")) != -1) 196 if((loc = line.find(":")) != -1)
197 { 197 {
198 ifaces += line.left(loc); 198 ifaces += line.left(loc);
199 } 199 }
200 } 200 }
201 } 201 }
202 202
203 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) 203 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it)
204 { 204 {
205 int flags = 0; 205 int flags = 0;
206 if ( m_handledIfaces.contains( (*it) ) ) 206 if ( m_handledIfaces.contains( (*it) ) )
207 { 207 {
208 odebug << " " << (*it).latin1() << " is handled by a module" << oendl; 208 odebug << " " << (*it).latin1() << " is handled by a module" << oendl;
209 continue; 209 continue;
210 } 210 }
211 // int family; 211 // int family;
212 i = NULL; 212 i = NULL;
213 213
214 strcpy(ifr.ifr_name, (*it).latin1()); 214 strcpy(ifr.ifr_name, (*it).latin1());
215 215
216 struct ifreq ifcopy; 216 struct ifreq ifcopy;
217 ifcopy = ifr; 217 ifcopy = ifr;
218 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy); 218 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy);
219 flags = ifcopy.ifr_flags; 219 flags = ifcopy.ifr_flags;
220 i = new Interface(this, ifr.ifr_name, false); 220 i = new Interface(this, ifr.ifr_name, false);
221 i->setAttached(true); 221 i->setAttached(true);
222 if ((flags & IFF_UP) == IFF_UP) 222 if ((flags & IFF_UP) == IFF_UP)
223 i->setStatus(true); 223 i->setStatus(true);
224 else 224 else
225 i->setStatus(false); 225 i->setStatus(false);
226 226
227 if ((flags & IFF_BROADCAST) == IFF_BROADCAST) 227 if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
228 i->setHardwareName("Ethernet"); 228 i->setHardwareName("Ethernet");
229 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) 229 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
230 i->setHardwareName("Point to Point"); 230 i->setHardwareName("Point to Point");
231 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) 231 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
232 i->setHardwareName("Multicast"); 232 i->setHardwareName("Multicast");
233 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) 233 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
234 i->setHardwareName("Loopback"); 234 i->setHardwareName("Loopback");
235 else 235 else
236 i->setHardwareName("Unknown"); 236 i->setHardwareName("Unknown");
237 237
238 owarn << "Adding interface " << ifr.ifr_name << " to interfaceNames\n" << oendl; 238 owarn << "Adding interface " << ifr.ifr_name << " to interfaceNames\n" << oendl;
239 interfaceNames.insert(i->getInterfaceName(), i); 239 interfaceNames.insert(i->getInterfaceName(), i);
240 updateInterface(i); 240 updateInterface(i);
241 connect(i, SIGNAL(updateInterface(Interface*)), 241 connect(i, SIGNAL(updateInterface(Interface*)),
242 this, SLOT(updateInterface(Interface*))); 242 this, SLOT(updateInterface(Interface*)));
243 } 243 }
244 // now lets ask the plugins too ;) 244 // now lets ask the plugins too ;)
245 QMap<Module*, QLibrary*>::Iterator it; 245 QMap<Module*, QLibrary*>::Iterator it;
246 QList<Interface> ilist; 246 QList<Interface> ilist;
247 for( it = libraries.begin(); it != libraries.end(); ++it ) 247 for( it = libraries.begin(); it != libraries.end(); ++it )
248 { 248 {
249 if(it.key()) 249 if(it.key())
250 { 250 {
251 ilist = it.key()->getInterfaces(); 251 ilist = it.key()->getInterfaces();
252 for( i = ilist.first(); i != 0; i = ilist.next() ) 252 for( i = ilist.first(); i != 0; i = ilist.next() )
253 { 253 {
254 owarn << "Adding interface " << i->getInterfaceName().latin1() << " to interfaceNames\n" << oendl; 254 owarn << "Adding interface " << i->getInterfaceName().latin1() << " to interfaceNames\n" << oendl;
255 interfaceNames.insert(i->getInterfaceName(), i); 255 interfaceNames.insert(i->getInterfaceName(), i);
256 updateInterface(i); 256 updateInterface(i);
257 connect(i, SIGNAL(updateInterface(Interface*)), 257 connect(i, SIGNAL(updateInterface(Interface*)),
258 this, SLOT(updateInterface(Interface*))); 258 this, SLOT(updateInterface(Interface*)));
259 } 259 }
260 } 260 }
261 } 261 }
262} 262}
263 263
264/** 264/**
265 * Load all modules that are found in the path 265 * Load all modules that are found in the path
266 * @param path a directory that is scaned for any plugins that can be loaded 266 * @param path a directory that is scaned for any plugins that can be loaded
267 * and attempts to load them 267 * and attempts to load them
268 */ 268 */
269void MainWindowImp::loadModules(const QString &path) 269void MainWindowImp::loadModules(const QString &path)
270{ 270{
271#ifdef DEBUG 271#ifdef DEBUG
272 odebug << "MainWindowImp::loadModules: " << path.latin1() << "" << oendl; 272 odebug << "MainWindowImp::loadModules: " << path.latin1() << "" << oendl;
273#endif 273#endif
274 QDir d(path); 274 QDir d(path);
275 if(!d.exists()) 275 if(!d.exists())
276 return; 276 return;
277 277
278 QString lang = ::getenv("LANG"); 278 QString lang = ::getenv("LANG");
279 // Don't want sym links 279 // Don't want sym links
280 d.setFilter( QDir::Files | QDir::NoSymLinks ); 280 d.setFilter( QDir::Files | QDir::NoSymLinks );
281 const QFileInfoList *list = d.entryInfoList(); 281 const QFileInfoList *list = d.entryInfoList();
282 QFileInfoListIterator it( *list ); 282 QFileInfoListIterator it( *list );
283 QFileInfo *fi; 283 QFileInfo *fi;
284 while ( (fi=it.current()) ) 284 while ( (fi=it.current()) )
285 { 285 {
286 if(fi->fileName().contains(".so")) 286 if(fi->fileName().contains(".so"))
287 { 287 {
288 /* if loaded install translation */ 288 /* if loaded install translation */
289 if( loadPlugin(path + "/" + fi->fileName()) != 0l ){ 289 if( loadPlugin(path + "/" + fi->fileName()) != 0l ){
290 QTranslator *trans = new QTranslator(qApp); 290 QTranslator *trans = new QTranslator(qApp);
291 QString fn = QPEApplication::qpeDir()+"i18n/"+lang+"/"+ fi->fileName().left( fi->fileName().find(".") )+".qm"; 291 QString fn = QPEApplication::qpeDir()+"i18n/"+lang+"/"+ fi->fileName().left( fi->fileName().find(".") )+".qm";
292 if( trans->load( fn ) ) 292 if( trans->load( fn ) )
293 qApp->installTranslator( trans ); 293 qApp->installTranslator( trans );
294 else 294 else
295 delete trans; 295 delete trans;
296 } 296 }
297 odebug << "loaded plugin: >" << QString(path + "/" + fi->fileName()).latin1() << "< " << oendl; 297 odebug << "loaded plugin: >" << QString(path + "/" + fi->fileName()).latin1() << "< " << oendl;
298 } 298 }
299 ++it; 299 ++it;
300 } 300 }
301} 301}
302 302
303/** 303/**
304 * Attempt to load a function and resolve a function. 304 * Attempt to load a function and resolve a function.
305 * @param pluginFileName - the name of the file in which to attempt to load 305 * @param pluginFileName - the name of the file in which to attempt to load
306 * @param resolveString - function pointer to resolve 306 * @param resolveString - function pointer to resolve
307 * @return pointer to the function with name resolveString or NULL 307 * @return pointer to the function with name resolveString or NULL
308 */ 308 */
309Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString) 309Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString)
310{ 310{
311#ifdef DEBUG 311#ifdef DEBUG
312 odebug << "MainWindowImp::loadPlugin: " << pluginFileName.latin1() << ": resolving " << resolveString.latin1() << "" << oendl; 312 odebug << "MainWindowImp::loadPlugin: " << pluginFileName.latin1() << ": resolving " << resolveString.latin1() << "" << oendl;
313#endif 313#endif
314 QLibrary *lib = new QLibrary(pluginFileName); 314 QLibrary *lib = new QLibrary(pluginFileName);
315 void *functionPointer = lib->resolve(resolveString); 315 void *functionPointer = lib->resolve(resolveString);
316 if( !functionPointer ) 316 if( !functionPointer )
317 { 317 {
318#ifdef DEBUG 318#ifdef DEBUG
319 odebug << "MainWindowImp::loadPlugin: Warning: " << pluginFileName.latin1() << " is not a plugin" << oendl; 319 odebug << "MainWindowImp::loadPlugin: Warning: " << pluginFileName.latin1() << " is not a plugin" << oendl;
320#endif 320#endif
321 delete lib; 321 delete lib;
322 return 0; 322 return 0;
323 } 323 }
324 // Try to get an object. 324 // Try to get an object.
325 Module *object = ((Module* (*)()) functionPointer)(); 325 Module *object = ((Module* (*)()) functionPointer)();
326 if(object == 0) 326 if(object == 0)
327 { 327 {
328#ifdef DEBUG 328#ifdef DEBUG
329 odebug << "MainWindowImp: Couldn't create object, but did load library!" << oendl; 329 odebug << "MainWindowImp: Couldn't create object, but did load library!" << oendl;
330#endif 330#endif
331 delete lib; 331 delete lib;
332 return 0; 332 return 0;
333 } 333 }
334 334
335 m_handledIfaces += object->handledInterfaceNames(); 335 m_handledIfaces += object->handledInterfaceNames();
336 // Store for deletion later 336 // Store for deletion later
337 libraries.insert(object, lib); 337 libraries.insert(object, lib);
338 return object; 338 return object;
339} 339}
340 340
341/** 341/**
342 * The Add button was clicked. Bring up the add dialog and if OK is hit 342 * The Add button was clicked. Bring up the add dialog and if OK is hit
343 * load the plugin and append it to the list 343 * load the plugin and append it to the list
344 */ 344 */
345void MainWindowImp::addClicked() 345void MainWindowImp::addClicked()
346{ 346{
347 QMap<Module*, QLibrary*>::Iterator it; 347 QMap<Module*, QLibrary*>::Iterator it;
348 QMap<QString, QString> list; 348 QMap<QString, QString> list;
349 QMap<QString, Module*> newInterfaceOwners; 349 QMap<QString, Module*> newInterfaceOwners;
350 350
351 for( it = libraries.begin(); it != libraries.end(); ++it ) 351 for( it = libraries.begin(); it != libraries.end(); ++it )
352 { 352 {
353 if(it.key()) 353 if(it.key())
354 { 354 {
355 (it.key())->possibleNewInterfaces(list); 355 (it.key())->possibleNewInterfaces(list);
356 } 356 }
357 } 357 }
358 // See if the list has anything that we can add. 358 // See if the list has anything that we can add.
359 if(list.count() == 0) 359 if(list.count() == 0)
360 { 360 {
361 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); 361 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok);
362 return; 362 return;
363 } 363 }
364 AddConnectionImp addNewConnection(this, "AddConnectionImp", true); 364 AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
365 addNewConnection.addConnections(list); 365 addNewConnection.addConnections(list);
366 if( QDialog::Accepted == QPEApplication::execDialog( &addNewConnection ) ) 366 if( QDialog::Accepted == QPEApplication::execDialog( &addNewConnection ) )
367 { 367 {
368 QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); 368 QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
369 if(!item) 369 if(!item)
370 return; 370 return;
371 371
372 for( it = libraries.begin(); it != libraries.end(); ++it ) 372 for( it = libraries.begin(); it != libraries.end(); ++it )
373 { 373 {
374 if(it.key()) 374 if(it.key())
375 { 375 {
376 Interface *i = (it.key())->addNewInterface(item->text(0)); 376 Interface *i = (it.key())->addNewInterface(item->text(0));
377 if(i) 377 if(i)
378 { 378 {
379 odebug << "iface name " << i->getInterfaceName().latin1() << "" << oendl; 379 odebug << "iface name " << i->getInterfaceName().latin1() << "" << oendl;
380 interfaceNames.insert(i->getInterfaceName(), i); 380 interfaceNames.insert(i->getInterfaceName(), i);
381 updateInterface(i); 381 updateInterface(i);
382 } 382 }
383 } 383 }
384 } 384 }
385 } 385 }
386} 386}
387 387
388/** 388/**
389 * Prompt the user to see if they really want to do this. 389 * Prompt the user to see if they really want to do this.
390 * If they do then remove from the list and unload. 390 * If they do then remove from the list and unload.
391 */ 391 */
392void MainWindowImp::removeClicked() 392void MainWindowImp::removeClicked()
393{ 393{
394 QListViewItem *item = connectionList->currentItem(); 394 QListViewItem *item = connectionList->currentItem();
395 if(!item) 395 if(!item)
396 { 396 {
397 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 397 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
398 return; 398 return;
399 } 399 }
400 400
401 Interface *i = interfaceItems[item]; 401 Interface *i = interfaceItems[item];
402 if(i->getModuleOwner() == NULL) 402 if(i->getModuleOwner() == NULL)
403 { 403 {
404 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); 404 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok);
405 } 405 }
406 else 406 else
407 { 407 {
408 if(!i->getModuleOwner()->remove(i)) 408 if(!i->getModuleOwner()->remove(i))
409 QMessageBox::information(this, tr("Error"), tr("Unable to remove."), QMessageBox::Ok); 409 QMessageBox::information(this, tr("Error"), tr("Unable to remove."), QMessageBox::Ok);
410 else 410 else
411 { 411 {
412 delete item; 412 delete item;
413 // QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); 413 // QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok);
414 } 414 }
415 } 415 }
416} 416}
417 417
418/** 418/**
419 * Pull up the configure about the currently selected interface. 419 * Pull up the configure about the currently selected interface.
420 * Report an error if no interface is selected. 420 * Report an error if no interface is selected.
421 * If the interface has a module owner then request its configure. 421 * If the interface has a module owner then request its configure.
422 */ 422 */
423void MainWindowImp::configureClicked() 423void MainWindowImp::configureClicked()
424{ 424{
425 QListViewItem *item = connectionList->currentItem(); 425 QListViewItem *item = connectionList->currentItem();
426 if(!item) 426 if(!item)
427 { 427 {
428 QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok); 428 QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok);
429 return; 429 return;
430 } 430 }
431 431
432 QString currentProfileText = currentProfileLabel->text(); 432 QString currentProfileText = currentProfileLabel->text();
433 if(currentProfileText.upper() == "ALL"); 433 if(currentProfileText.upper() == "ALL");
434 currentProfileText = ""; 434 currentProfileText = "";
435 435
436 Interface *i = interfaceItems[item]; 436 Interface *i = interfaceItems[item];
437 437
438 if(i->getModuleOwner()) 438 if(i->getModuleOwner())
439 { 439 {
440 QWidget *moduleConfigure = i->getModuleOwner()->configure(i); 440 QWidget *moduleConfigure = i->getModuleOwner()->configure(i);
441 if(moduleConfigure != NULL) 441 if(moduleConfigure != NULL)
442 { 442 {
443 i->getModuleOwner()->setProfile(currentProfileText); 443 i->getModuleOwner()->setProfile(currentProfileText);
444 QPEApplication::showWidget( moduleConfigure ); 444 QPEApplication::showWidget( moduleConfigure );
445 return; 445 return;
446 } 446 }
447 } 447 }
448 448
449 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose | Qt::WStyle_ContextHelp ); 449 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose | Qt::WStyle_ContextHelp );
450 configure->setProfile(currentProfileText); 450 configure->setProfile(currentProfileText);
451 QPEApplication::showDialog( configure ); 451 QPEApplication::showDialog( configure );
452} 452}
453 453
454/** 454/**
455 * Pull up the information about the currently selected interface. 455 * Pull up the information about the currently selected interface.
456 * Report an error if no interface is selected. 456 * Report an error if no interface is selected.
457 * If the interface has a module owner then request its configure. 457 * If the interface has a module owner then request its configure.
458 */ 458 */
459void MainWindowImp::informationClicked() 459void MainWindowImp::informationClicked()
460{ 460{
461 QListViewItem *item = connectionList->currentItem(); 461 QListViewItem *item = connectionList->currentItem();
462 if(!item) 462 if(!item)
463 { 463 {
464 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 464 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
465 return; 465 return;
466 } 466 }
467 467
468 Interface *i = interfaceItems[item]; 468 Interface *i = interfaceItems[item];
469 // if(!i->isAttached()){ 469 // if(!i->isAttached()){
470 // QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); 470 // QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok);
471 // return; 471 // return;
472 // } 472 // }
473 473
474 if(i->getModuleOwner()) 474 if(i->getModuleOwner())
475 { 475 {
476 QWidget *moduleInformation = i->getModuleOwner()->information(i); 476 QWidget *moduleInformation = i->getModuleOwner()->information(i);
477 if(moduleInformation != NULL) 477 if(moduleInformation != NULL)
478 { 478 {
479 QPEApplication::showWidget( moduleInformation ); 479 QPEApplication::showWidget( moduleInformation );
480#ifdef DEBUG 480#ifdef DEBUG
481 odebug << "MainWindowImp::informationClicked:: Module owner has created, we showed." << oendl; 481 odebug << "MainWindowImp::informationClicked:: Module owner has created, we showed." << oendl;
482#endif 482#endif
483 return; 483 return;
484 } 484 }
485 } 485 }
486 InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog | Qt::WStyle_ContextHelp); 486 InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog | Qt::WStyle_ContextHelp);
487 QPEApplication::showWidget( information ); 487 QPEApplication::showWidget( information );
488} 488}
489 489
490/** 490/**
491 * Update this interface. If no QListViewItem exists create one. 491 * Update this interface. If no QListViewItem exists create one.
492 * @param Interface* pointer to the interface that needs to be updated. 492 * @param Interface* pointer to the interface that needs to be updated.
493 */ 493 */
494void MainWindowImp::updateInterface(Interface *i) 494void MainWindowImp::updateInterface(Interface *i)
495{ 495{
496 if(!advancedUserMode) 496 if(!advancedUserMode)
497 { 497 {
498 if(i->getInterfaceName() == "lo") 498 if(i->getInterfaceName() == "lo")
499 return; 499 return;
500 } 500 }
501 501
502 QListViewItem *item = NULL; 502 QListViewItem *item = NULL;
503 503
504 // Find the interface, making it if needed. 504 // Find the interface, making it if needed.
505 if(items.find(i) == items.end()) 505 if(items.find(i) == items.end())
506 { 506 {
507 item = new QListViewItem(connectionList, "", "", ""); 507 item = new QListViewItem(connectionList, "", "", "");
508 // See if you can't find a module owner for this interface 508 // See if you can't find a module owner for this interface
509 QMap<Module*, QLibrary*>::Iterator it; 509 QMap<Module*, QLibrary*>::Iterator it;
510 for( it = libraries.begin(); it != libraries.end(); ++it ) 510 for( it = libraries.begin(); it != libraries.end(); ++it )
511 { 511 {
512 if(it.key()->isOwner(i)) 512 if(it.key()->isOwner(i))
513 i->setModuleOwner(it.key()); 513 i->setModuleOwner(it.key());
514 } 514 }
515 items.insert(i, item); 515 items.insert(i, item);
516 interfaceItems.insert(item, i); 516 interfaceItems.insert(item, i);
517 } 517 }
518 else 518 else
519 item = items[i]; 519 item = items[i];
520 520
521 // Update the icons and information 521 // Update the icons and information
522#ifdef QWS 522#ifdef QWS
523 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); 523 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
524#else 524#else
525 item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down"))); 525 item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down")));
526#endif 526#endif
527 527
528 QString typeName = "lan"; 528 QString typeName = "lan";
529 if(i->getInterfaceName() == "lo") 529 if(i->getInterfaceName() == "lo")
530 typeName = "lo"; 530 typeName = "lo";
531 if(i->getInterfaceName().contains("irda")) 531 if(i->getInterfaceName().contains("irda"))
532 typeName = "irda"; 532 typeName = "irda";
533 if(i->getInterfaceName().contains("wlan")) 533 if(i->getInterfaceName().contains("wlan"))
534 typeName = "wlan"; 534 typeName = "wlan";
535 if(i->getInterfaceName().contains("usb")) 535 if(i->getInterfaceName().contains("usb"))
536 typeName = "usb"; 536 typeName = "usb";
537 537
538 if(!i->isAttached()) 538 if(!i->isAttached())
539 typeName = "connect_no"; 539 typeName = "connect_no";
540 // Actually try to use the Module 540 // Actually try to use the Module
541 if(i->getModuleOwner() != NULL) 541 if(i->getModuleOwner() != NULL)
542 typeName = i->getModuleOwner()->getPixmapName(i); 542 typeName = i->getModuleOwner()->getPixmapName(i);
543 543
544#ifdef QWS 544#ifdef QWS
545 item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName))); 545 item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName)));
546#else 546#else
547 item->setPixmap(1, (SmallIcon(typeName))); 547 item->setPixmap(1, (SmallIcon(typeName)));
548#endif 548#endif
549 item->setText(2, i->getHardwareName()); 549 item->setText(2, i->getHardwareName());
550 item->setText(3, QString("(%1)").arg(i->getInterfaceName())); 550 item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
551 item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); 551 item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
552} 552}
553 553
554void MainWindowImp::newProfileChanged(const QString& newText) 554void MainWindowImp::newProfileChanged(const QString& newText)
555{ 555{
556 if(newText.length() > 0) 556 if(newText.length() > 0)
557 newProfileButton->setEnabled(true); 557 newProfileButton->setEnabled(true);
558 else 558 else
559 newProfileButton->setEnabled(false); 559 newProfileButton->setEnabled(false);
560} 560}
561 561
562/** 562/**
563 * Adds a new profile to the list of profiles. 563 * Adds a new profile to the list of profiles.
564 * Don't add profiles that already exists. 564 * Don't add profiles that already exists.
565 * Appends to the list and QStringList 565 * Appends to the list and QStringList
566 */ 566 */
567void MainWindowImp::addProfile() 567void MainWindowImp::addProfile()
568{ 568{
569 QString newProfileName = newProfile->text(); 569 QString newProfileName = newProfile->text();
570 if(profiles.grep(newProfileName).count() > 0) 570 if(profiles.grep(newProfileName).count() > 0)
571 { 571 {
572 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); 572 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok);
573 return; 573 return;
574 } 574 }
575 profiles.append(newProfileName); 575 profiles.append(newProfileName);
576 profilesList->insertItem(newProfileName); 576 profilesList->insertItem(newProfileName);
577} 577}
578 578
579/** 579/**
580 * Removes the currently selected profile in the combo. 580 * Removes the currently selected profile in the combo.
581 * Doesn't delete if there are less then 2 profiles. 581 * Doesn't delete if there are less then 2 profiles.
582 */ 582 */
583void MainWindowImp::removeProfile() 583void MainWindowImp::removeProfile()
584{ 584{
585 if(profilesList->count() <= 1) 585 if(profilesList->count() <= 1)
586 { 586 {
587 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); 587 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok);
588 return; 588 return;
589 } 589 }
590 QString profileToRemove = profilesList->currentText(); 590 QString profileToRemove = profilesList->currentText();
591 if(profileToRemove == "All") 591 if(profileToRemove == "All")
592 { 592 {
593 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); 593 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok);
594 return; 594 return;
595 } 595 }
596 // Can't remove the curent profile 596 // Can't remove the curent profile
597 if(profileToRemove == currentProfileLabel->text()) 597 if(profileToRemove == currentProfileLabel->text())
598 { 598 {
599 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); 599 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok);
600 return; 600 return;
601 601
602 } 602 }
603 603
604 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) 604 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
605 { 605 {
606 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 606 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
607 profilesList->clear(); 607 profilesList->clear();
608 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 608 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
609 profilesList->insertItem((*it)); 609 profilesList->insertItem((*it));
610 610
611 // Remove any interface settings and mappings. 611 // Remove any interface settings and mappings.
612 Interfaces interfaces; 612 Interfaces interfaces;
613 // Go through them one by one 613 // Go through them one by one
614 QMap<Interface*, QListViewItem*>::Iterator it; 614 QMap<Interface*, QListViewItem*>::Iterator it;
615 for( it = items.begin(); it != items.end(); ++it ) 615 for( it = items.begin(); it != items.end(); ++it )
616 { 616 {
617 QString interfaceName = it.key()->getInterfaceName(); 617 QString interfaceName = it.key()->getInterfaceName();
618 odebug << interfaceName.latin1() << oendl; 618 odebug << interfaceName.latin1() << oendl;
619 if(interfaces.setInterface(interfaceName + "_" + profileToRemove)) 619 if(interfaces.setInterface(interfaceName + "_" + profileToRemove))
620 { 620 {
621 interfaces.removeInterface(); 621 interfaces.removeInterface();
622 if(interfaces.setMapping(interfaceName)) 622 if(interfaces.setMapping(interfaceName))
623 { 623 {
624 if(profilesList->count() == 1) 624 if(profilesList->count() == 1)
625 interfaces.removeMapping(); 625 interfaces.removeMapping();
626 else 626 else
627 { 627 {
628 interfaces.removeMap("map", interfaceName + "_" + profileToRemove); 628 interfaces.removeMap("map", interfaceName + "_" + profileToRemove);
629 } 629 }
630 } 630 }
631 interfaces.write(); 631 interfaces.write();
632 break; 632 break;
633 } 633 }
634 } 634 }
635 } 635 }
636} 636}
637 637
638/** 638/**
639 * A new profile has been selected, change. 639 * A new profile has been selected, change.
640 * @param newProfile the new profile. 640 * @param newProfile the new profile.
641 */ 641 */
642void MainWindowImp::changeProfile() 642void MainWindowImp::changeProfile()
643{ 643{
644 if(profilesList->currentItem() == -1) 644 if(profilesList->currentItem() == -1)
645 { 645 {
646 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok); 646 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok);
647 return; 647 return;
648 } 648 }
649 QString newProfile = profilesList->text(profilesList->currentItem()); 649 QString newProfile = profilesList->text(profilesList->currentItem());
650 if(newProfile != currentProfileLabel->text()) 650 if(newProfile != currentProfileLabel->text())
651 { 651 {
652 currentProfileLabel->setText(newProfile); 652 currentProfileLabel->setText(newProfile);
653 QFile::remove(scheme); 653 QFile::remove(scheme);
654 QFile file(scheme); 654 QFile file(scheme);
655 if ( file.open(IO_ReadWrite) ) 655 if ( file.open(IO_ReadWrite) )
656 { 656 {
657 QTextStream stream( &file ); 657 QTextStream stream( &file );
658 stream << QString("SCHEME=%1").arg(newProfile); 658 stream << QString("SCHEME=%1").arg(newProfile);
659 file.close(); 659 file.close();
660 } 660 }
661 // restart all up devices? 661 // restart all up devices?
662 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok) 662 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok)
663 { 663 {
664 // Go through them one by one 664 // Go through them one by one
665 QMap<Interface*, QListViewItem*>::Iterator it; 665 QMap<Interface*, QListViewItem*>::Iterator it;
666 for( it = items.begin(); it != items.end(); ++it ) 666 for( it = items.begin(); it != items.end(); ++it )
667 { 667 {
668 if(it.key()->getStatus() == true) 668 if(it.key()->getStatus() == true)
669 it.key()->restart(); 669 it.key()->restart();
670 } 670 }
671 } 671 }
672 } 672 }
673 // TODO change the profile in the modules 673 // TODO change the profile in the modules
674} 674}
675 675
676 676
677void MainWindowImp::makeChannel() 677void MainWindowImp::makeChannel()
678{ 678{
679 channel = new QCopChannel( "QPE/Application/networksettings", this ); 679 channel = new QCopChannel( "QPE/Application/networksettings", this );
680 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), 680 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
681 this, SLOT(receive(const QCString&,const QByteArray&)) ); 681 this, SLOT(receive(const QCString&,const QByteArray&)) );
682} 682}
683 683
684void MainWindowImp::receive(const QCString &msg, const QByteArray &arg) 684void MainWindowImp::receive(const QCString &msg, const QByteArray &arg)
685{ 685{
686 bool found = false; 686 bool found = false;
687 odebug << "MainWindowImp::receive QCop msg >"+msg+"<" << oendl; 687 odebug << "MainWindowImp::receive QCop msg >"+msg+"<" << oendl;
688 if (msg == "raise") 688 if (msg == "raise")
689 { 689 {
690 raise(); 690 raise();
691 return; 691 return;
692 } 692 }
693 693
694 QString dest = msg.left(msg.find("(")); 694 QString dest = msg.left(msg.find("("));
695 QCString param = msg.right(msg.length() - msg.find("(") - 1); 695 QCString param = msg.right(msg.length() - msg.find("(") - 1);
696 param = param.left( param.length() - 1 ); 696 param = param.left( param.length() - 1 );
697 odebug << "dest >" << dest.latin1() << "< param >"+param+"<" << oendl; 697 odebug << "dest >" << dest.latin1() << "< param >"+param+"<" << oendl;
698 698
699 QMap<Module*, QLibrary*>::Iterator it; 699 QMap<Module*, QLibrary*>::Iterator it;
700 for( it = libraries.begin(); it != libraries.end(); ++it ) 700 for( it = libraries.begin(); it != libraries.end(); ++it )
701 { 701 {
702 odebug << "plugin >" << it.key()->type().latin1() << "<" << oendl; 702 odebug << "plugin >" << it.key()->type().latin1() << "<" << oendl;
703 if(it.key()->type() == dest) 703 if(it.key()->type() == dest)
704 { 704 {
705 it.key()->receive( param, arg ); 705 it.key()->receive( param, arg );
706 found = true; 706 found = true;
707 } 707 }
708 } 708 }
709 709
710 710
711 if (found) QPEApplication::setKeepRunning(); 711 if (found) QPEApplication::setKeepRunning();
712 else odebug << "Huh what do ya want" << oendl; 712 else odebug << "Huh what do ya want" << oendl;
713} 713}
diff --git a/noncore/unsupported/qpdf/QOutputDev.cpp b/noncore/unsupported/qpdf/QOutputDev.cpp
index 022d938..487177c 100644
--- a/noncore/unsupported/qpdf/QOutputDev.cpp
+++ b/noncore/unsupported/qpdf/QOutputDev.cpp
@@ -1,1053 +1,1053 @@
1///======================================================================== 1///========================================================================
2// 2//
3// QOutputDev.cc 3// QOutputDev.cc
4// 4//
5// Copyright 1996 Derek B. Noonburg 5// Copyright 1996 Derek B. Noonburg
6// CopyRight 2002 Robert Griebl 6// CopyRight 2002 Robert Griebl
7// 7//
8//======================================================================== 8//========================================================================
9 9
10#ifdef __GNUC__ 10#ifdef __GNUC__
11#pragma implementation 11#pragma implementation
12#endif 12#endif
13 13
14#include <aconf.h> 14#include <aconf.h>
15#include <stdio.h> 15#include <stdio.h>
16#include <stdlib.h> 16#include <stdlib.h>
17#include <stddef.h> 17#include <stddef.h>
18#include <unistd.h> 18#include <unistd.h>
19#include <string.h> 19#include <string.h>
20#include <ctype.h> 20#include <ctype.h>
21#include <math.h> 21#include <math.h>
22#include <iostream> 22#include <iostream>
23 23
24#include "GString.h" 24#include "GString.h"
25#include "Object.h" 25#include "Object.h"
26#include "Stream.h" 26#include "Stream.h"
27#include "Link.h" 27#include "Link.h"
28#include "GfxState.h" 28#include "GfxState.h"
29#include "GfxFont.h" 29#include "GfxFont.h"
30#include "UnicodeMap.h" 30#include "UnicodeMap.h"
31#include "CharCodeToUnicode.h" 31#include "CharCodeToUnicode.h"
32#include "FontFile.h" 32#include "FontFile.h"
33#include "Error.h" 33#include "Error.h"
34#include "TextOutputDev.h" 34#include "TextOutputDev.h"
35#include "QOutputDev.h" 35#include "QOutputDev.h"
36 36
37 37
38#include <qpixmap.h> 38#include <qpixmap.h>
39#include <qimage.h> 39#include <qimage.h>
40#include <qpainter.h> 40#include <qpainter.h>
41#include <qdict.h> 41#include <qdict.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#include <qapplication.h> 43#include <qapplication.h>
44#include <qclipboard.h> 44#include <qclipboard.h>
45 45
46 //#define QPDFDBG(x) x // special debug mode 46 //#define QPDFDBG(x) x // special debug mode
47 #define QPDFDBG(x) // normal compilation 47 #define QPDFDBG(x) // normal compilation
48 48
49 49
50//------------------------------------------------------------------------ 50//------------------------------------------------------------------------
51// Constants and macros 51// Constants and macros
52//------------------------------------------------------------------------ 52//------------------------------------------------------------------------
53 53
54 54
55static inline QColor q_col ( const GfxRGB &rgb ) 55static inline QColor q_col ( const GfxRGB &rgb )
56{ 56{
57 return QColor ( lrint ( rgb. r * 255 ), lrint ( rgb. g * 255 ), lrint ( rgb. b * 255 )); 57 return QColor ( lrint ( rgb. r * 255 ), lrint ( rgb. g * 255 ), lrint ( rgb. b * 255 ));
58} 58}
59 59
60 60
61//------------------------------------------------------------------------ 61//------------------------------------------------------------------------
62// Font substitutions 62// Font substitutions
63//------------------------------------------------------------------------ 63//------------------------------------------------------------------------
64 64
65struct QOutFontSubst { 65struct QOutFontSubst {
66 char * m_name; 66 char * m_name;
67 char * m_sname; 67 char * m_sname;
68 bool m_bold; 68 bool m_bold;
69 bool m_italic; 69 bool m_italic;
70 QFont::StyleHint m_hint; 70 QFont::StyleHint m_hint;
71}; 71};
72 72
73static QOutFontSubst qStdFonts [] = { 73static QOutFontSubst qStdFonts [] = {
74 { "Helvetica", "Helvetica", false, false, QFont::Helvetica }, 74 { "Helvetica", "Helvetica", false, false, QFont::Helvetica },
75 { "Helvetica-Oblique", "Helvetica", false, true, QFont::Helvetica }, 75 { "Helvetica-Oblique", "Helvetica", false, true, QFont::Helvetica },
76 { "Helvetica-Bold", "Helvetica", true, false, QFont::Helvetica }, 76 { "Helvetica-Bold", "Helvetica", true, false, QFont::Helvetica },
77 { "Helvetica-BoldOblique", "Helvetica", true, true, QFont::Helvetica }, 77 { "Helvetica-BoldOblique", "Helvetica", true, true, QFont::Helvetica },
78 { "Times-Roman", "Times", false, false, QFont::Times }, 78 { "Times-Roman", "Times", false, false, QFont::Times },
79 { "Times-Italic", "Times", false, true, QFont::Times }, 79 { "Times-Italic", "Times", false, true, QFont::Times },
80 { "Times-Bold", "Times", true, false, QFont::Times }, 80 { "Times-Bold", "Times", true, false, QFont::Times },
81 { "Times-BoldItalic", "Times", true, true, QFont::Times }, 81 { "Times-BoldItalic", "Times", true, true, QFont::Times },
82 { "Courier", "Courier", false, false, QFont::Courier }, 82 { "Courier", "Courier", false, false, QFont::Courier },
83 { "Courier-Oblique", "Courier", false, true, QFont::Courier }, 83 { "Courier-Oblique", "Courier", false, true, QFont::Courier },
84 { "Courier-Bold", "Courier", true, false, QFont::Courier }, 84 { "Courier-Bold", "Courier", true, false, QFont::Courier },
85 { "Courier-BoldOblique", "Courier", true, true, QFont::Courier }, 85 { "Courier-BoldOblique", "Courier", true, true, QFont::Courier },
86 86
87 { "Symbol", 0, false, false, QFont::AnyStyle }, 87 { "Symbol", 0, false, false, QFont::AnyStyle },
88 { "Zapf-Dingbats", 0, false, false, QFont::AnyStyle }, 88 { "Zapf-Dingbats", 0, false, false, QFont::AnyStyle },
89 89
90 { 0, 0, false, false, QFont::AnyStyle } 90 { 0, 0, false, false, QFont::AnyStyle }
91}; 91};
92 92
93 93
94 94
95 95
96 96
97 97
98 98
99QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp_t m22 ) 99QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp_t m22 )
100{ 100{
101 static QDict<QOutFontSubst> stdfonts; 101 static QDict<QOutFontSubst> stdfonts;
102 102
103 // build dict for std. fonts on first invocation 103 // build dict for std. fonts on first invocation
104 if ( stdfonts. isEmpty ( )) { 104 if ( stdfonts. isEmpty ( )) {
105 for ( QOutFontSubst *ptr = qStdFonts; ptr-> m_name; ptr++ ) { 105 for ( QOutFontSubst *ptr = qStdFonts; ptr-> m_name; ptr++ ) {
106 stdfonts. insert ( QString ( ptr-> m_name ), ptr ); 106 stdfonts. insert ( QString ( ptr-> m_name ), ptr );
107 } 107 }
108 } 108 }
109 109
110 // compute size and normalized transform matrix 110 // compute size and normalized transform matrix
111 int size = lrint ( sqrt ( m21 * m21 + m22 * m22 )); 111 int size = lrint ( sqrt ( m21 * m21 + m22 * m22 ));
112 112
113 QPDFDBG( printf ( "SET FONT: Name=%s, Size=%d, Bold=%d, Italic=%d, Mono=%d, Serif=%d, Symbol=%d, CID=%d, EmbFN=%s, M=(%f,%f,%f,%f)\n", 113 QPDFDBG( printf ( "SET FONT: Name=%s, Size=%d, Bold=%d, Italic=%d, Mono=%d, Serif=%d, Symbol=%d, CID=%d, EmbFN=%s, M=(%f,%f,%f,%f)\n",
114 (( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" ), 114 (( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" ),
115 size, 115 size,
116 gfxFont-> isBold ( ), 116 gfxFont-> isBold ( ),
117 gfxFont-> isItalic ( ), 117 gfxFont-> isItalic ( ),
118 gfxFont-> isFixedWidth ( ), 118 gfxFont-> isFixedWidth ( ),
119 gfxFont-> isSerif ( ), 119 gfxFont-> isSerif ( ),
120 gfxFont-> isSymbolic ( ), 120 gfxFont-> isSymbolic ( ),
121 gfxFont-> isCIDFont ( ), 121 gfxFont-> isCIDFont ( ),
122 ( gfxFont-> getEmbeddedFontName ( ) ? gfxFont-> getEmbeddedFontName()-> getCString ( ) : "<n/a>" ), 122 ( gfxFont-> getEmbeddedFontName ( ) ? gfxFont-> getEmbeddedFontName()-> getCString ( ) : "<n/a>" ),
123 (double) m11, (double) m12, (double) m21, (double) m22 ) ); 123 (double) m11, (double) m12, (double) m21, (double) m22 ) );
124 124
125 125
126 QString fname (( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" ); 126 QString fname (( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" );
127 127
128 QFont f; 128 QFont f;
129 f. setPixelSize ( size > 0 ? size : 8 ); // type3 fonts misbehave sometimes 129 f. setPixelSize ( size > 0 ? size : 8 ); // type3 fonts misbehave sometimes
130 130
131 // fast lookup for std. fonts 131 // fast lookup for std. fonts
132 QOutFontSubst *subst = stdfonts [fname]; 132 QOutFontSubst *subst = stdfonts [fname];
133 133
134 if ( subst ) { 134 if ( subst ) {
135 if ( subst-> m_sname ) 135 if ( subst-> m_sname )
136 f. setFamily ( subst-> m_sname ); 136 f. setFamily ( subst-> m_sname );
137 f. setStyleHint ( subst-> m_hint, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality )); 137 f. setStyleHint ( subst-> m_hint, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality ));
138 f. setBold ( subst-> m_bold ); 138 f. setBold ( subst-> m_bold );
139 f. setItalic ( subst-> m_italic ); 139 f. setItalic ( subst-> m_italic );
140 } 140 }
141 else { 141 else {
142 QFont::StyleHint sty; 142 QFont::StyleHint sty;
143 143
144 if ( gfxFont-> isSerif ( )) 144 if ( gfxFont-> isSerif ( ))
145 sty = QFont::Serif; 145 sty = QFont::Serif;
146 else if ( gfxFont-> isFixedWidth ( )) 146 else if ( gfxFont-> isFixedWidth ( ))
147 sty = QFont::TypeWriter; 147 sty = QFont::TypeWriter;
148 else 148 else
149 sty = QFont::Helvetica; 149 sty = QFont::Helvetica;
150 150
151 f. setStyleHint ( sty, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality )); 151 f. setStyleHint ( sty, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality ));
152 f. setBold ( gfxFont-> isBold ( ) > 0 ); 152 f. setBold ( gfxFont-> isBold ( ) > 0 );
153 f. setItalic ( gfxFont-> isItalic ( ) > 0 ); 153 f. setItalic ( gfxFont-> isItalic ( ) > 0 );
154 f. setFixedPitch ( gfxFont-> isFixedWidth ( ) > 0 ); 154 f. setFixedPitch ( gfxFont-> isFixedWidth ( ) > 0 );
155 155
156 // common specifiers in font names 156 // common specifiers in font names
157 if ( fname. contains ( "Oblique" ) || fname. contains ( "Italic" )) 157 if ( fname. contains ( "Oblique" ) || fname. contains ( "Italic" ))
158 f. setItalic ( true ); 158 f. setItalic ( true );
159 if ( fname. contains ( "Bold" )) 159 if ( fname. contains ( "Bold" ))
160 f. setWeight ( QFont::Bold ); 160 f. setWeight ( QFont::Bold );
161 if ( fname. contains ( "Demi" )) 161 if ( fname. contains ( "Demi" ))
162 f. setWeight ( QFont::DemiBold ); 162 f. setWeight ( QFont::DemiBold );
163 if ( fname. contains ( "Light" )) 163 if ( fname. contains ( "Light" ))
164 f. setWeight ( QFont::Light ); 164 f. setWeight ( QFont::Light );
165 if ( fname. contains ( "Black" )) 165 if ( fname. contains ( "Black" ))
166 f. setWeight ( QFont::Black ); 166 f. setWeight ( QFont::Black );
167 } 167 }
168 // Treat x-sheared fonts as italic 168 // Treat x-sheared fonts as italic
169 if (( m12 > -0.1 ) && ( m12 < 0.1 ) && ((( m21 > -5.0 ) && ( m21 < -0.1 )) || (( m21 > 0.1 ) && ( m21 < 5.0 )))) { 169 if (( m12 > -0.1 ) && ( m12 < 0.1 ) && ((( m21 > -5.0 ) && ( m21 < -0.1 )) || (( m21 > 0.1 ) && ( m21 < 5.0 )))) {
170 f. setItalic ( true ); 170 f. setItalic ( true );
171 } 171 }
172 return f; 172 return f;
173} 173}
174 174
175 175
176 176
177//------------------------------------------------------------------------ 177//------------------------------------------------------------------------
178// QOutputDev 178// QOutputDev
179//------------------------------------------------------------------------ 179//------------------------------------------------------------------------
180 180
181QOutputDev::QOutputDev ( QWidget *parent, const char *name, int flags ) : QScrollView ( parent, name, WRepaintNoErase | WResizeNoErase | flags ) 181QOutputDev::QOutputDev ( QWidget *parent, const char *name, int flags ) : QScrollView ( parent, name, WRepaintNoErase | WResizeNoErase | flags )
182{ 182{
183 m_pixmap = 0; 183 m_pixmap = 0;
184 m_painter = 0; 184 m_painter = 0;
185 185
186 // create text object 186 // create text object
187 m_text = new TextPage ( gFalse ); 187 m_text = new TextPage ( gFalse );
188} 188}
189 189
190QOutputDev::~QOutputDev ( ) 190QOutputDev::~QOutputDev ( )
191{ 191{
192 delete m_painter; 192 delete m_painter;
193 delete m_pixmap; 193 delete m_pixmap;
194 delete m_text; 194 delete m_text;
195} 195}
196 196
197 197
198void QOutputDev::startPage ( int /*pageNum*/, GfxState *state ) 198void QOutputDev::startPage ( int /*pageNum*/, GfxState *state )
199{ 199{
200 delete m_pixmap; 200 delete m_pixmap;
201 delete m_painter; 201 delete m_painter;
202 202
203 m_pixmap = new QPixmap ( lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( ))); 203 m_pixmap = new QPixmap ( lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( )));
204 m_painter = new QPainter ( m_pixmap ); 204 m_painter = new QPainter ( m_pixmap );
205 205
206 QPDFDBG( printf ( "NEW PIXMAP (%ld x %ld)\n", lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( )))); 206 QPDFDBG( printf ( "NEW PIXMAP (%ld x %ld)\n", lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( ))));
207 207
208 resizeContents ( m_pixmap-> width ( ), m_pixmap-> height ( )); 208 resizeContents ( m_pixmap-> width ( ), m_pixmap-> height ( ));
209 setContentsPos ( 0, 0 ); 209 setContentsPos ( 0, 0 );
210 210
211 m_pixmap-> fill ( white ); // clear window 211 m_pixmap-> fill ( white ); // clear window
212 m_text-> clear ( ); // cleat text object 212 m_text-> clear ( ); // cleat text object
213 viewport ( )-> repaint ( ); 213 viewport ( )-> repaint ( );
214} 214}
215 215
216void QOutputDev::endPage ( ) 216void QOutputDev::endPage ( )
217{ 217{
218 QPDFDBG( printf("End page\n") ); 218 QPDFDBG( printf("End page\n") );
219 m_text-> coalesce ( ); 219 m_text-> coalesce ( );
220 220
221 /* 221 /*
222 * I get stupid crashes after endPage is called and then we do clipping 222 * I get stupid crashes after endPage is called and then we do clipping
223 * and other stuff..... 223 * and other stuff.....
224 */ 224 */
225#if 0 225#if 0
226 delete m_painter; 226 delete m_painter;
227 m_painter = 0; 227 m_painter = 0;
228#endif 228#endif
229 229
230 updateContents ( 0, 0, contentsWidth ( ), contentsHeight ( )); 230 updateContents ( 0, 0, contentsWidth ( ), contentsHeight ( ));
231} 231}
232 232
233void QOutputDev::drawLink ( Link *link, Catalog */*catalog*/ ) 233void QOutputDev::drawLink ( Link *link, Catalog */*catalog*/ )
234{ 234{
235 fp_t x1, y1, x2, y2, w; 235 fp_t x1, y1, x2, y2, w;
236 236
237 link-> getBorder ( &x1, &y1, &x2, &y2, &w ); 237 link-> getBorder ( &x1, &y1, &x2, &y2, &w );
238 238
239 if ( w > 0 ) { 239 if ( w > 0 ) {
240 int x, y, dx, dy; 240 int x, y, dx, dy;
241 241
242 cvtUserToDev ( x1, y1, &x, &y ); 242 cvtUserToDev ( x1, y1, &x, &y );
243 cvtUserToDev ( x2, y2, &dx, &dy ); 243 cvtUserToDev ( x2, y2, &dx, &dy );
244 244
245 QPen oldpen = m_painter-> pen ( ); 245 QPen oldpen = m_painter-> pen ( );
246 m_painter-> setPen ( blue ); 246 m_painter-> setPen ( blue );
247 m_painter-> drawRect ( x, y, dx, dy ); 247 m_painter-> drawRect ( x, y, dx, dy );
248 m_painter-> setPen ( oldpen ); 248 m_painter-> setPen ( oldpen );
249 } 249 }
250} 250}
251 251
252void QOutputDev::saveState ( GfxState */*state*/ ) 252void QOutputDev::saveState ( GfxState */*state*/ )
253{ 253{
254 if ( ! m_painter ) 254 if ( ! m_painter )
255 return; 255 return;
256 256
257 QPDFDBG( printf ( "SAVE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( ))); 257 QPDFDBG( printf ( "SAVE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( )));
258 258
259 m_painter-> save ( ); 259 m_painter-> save ( );
260} 260}
261 261
262void QOutputDev::restoreState ( GfxState */*state*/ ) 262void QOutputDev::restoreState ( GfxState */*state*/ )
263{ 263{
264 if( ! m_painter ) 264 if( ! m_painter )
265 return; 265 return;
266 266
267 m_painter-> restore ( ); 267 m_painter-> restore ( );
268 268
269 //m_painter-> setClipRegion ( QRect ( 0, 0, m_pixmap-> width ( ), m_pixmap-> height ( ))); 269 //m_painter-> setClipRegion ( QRect ( 0, 0, m_pixmap-> width ( ), m_pixmap-> height ( )));
270 //m_painter-> setClipping ( false ); 270 //m_painter-> setClipping ( false );
271 QPDFDBG ( printf ( "RESTORE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( ))); 271 QPDFDBG ( printf ( "RESTORE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( )));
272} 272}
273 273
274void QOutputDev::updateAll ( GfxState *state ) 274void QOutputDev::updateAll ( GfxState *state )
275{ 275{
276 updateLineAttrs ( state, gTrue ); 276 updateLineAttrs ( state, gTrue );
277 //updateFlatness ( state ); 277 //updateFlatness ( state );
278 //updateMiterLimit ( state ); 278 //updateMiterLimit ( state );
279 updateFillColor ( state ); 279 updateFillColor ( state );
280 updateStrokeColor ( state ); 280 updateStrokeColor ( state );
281 updateFont ( state ); 281 updateFont ( state );
282} 282}
283 283
284void QOutputDev::updateCTM ( GfxState *state, fp_t /*m11*/, fp_t /*m12*/, fp_t /*m21*/, fp_t /*m22*/, fp_t /*m31*/, fp_t /*m32*/ ) 284void QOutputDev::updateCTM ( GfxState *state, fp_t /*m11*/, fp_t /*m12*/, fp_t /*m21*/, fp_t /*m22*/, fp_t /*m31*/, fp_t /*m32*/ )
285{ 285{
286 updateLineAttrs ( state, gTrue ); 286 updateLineAttrs ( state, gTrue );
287} 287}
288 288
289void QOutputDev::updateLineDash ( GfxState *state ) 289void QOutputDev::updateLineDash ( GfxState *state )
290{ 290{
291 updateLineAttrs ( state, gTrue ); 291 updateLineAttrs ( state, gTrue );
292} 292}
293 293
294void QOutputDev::updateFlatness ( GfxState */*state*/ ) 294void QOutputDev::updateFlatness ( GfxState */*state*/ )
295{ 295{
296 // not supported 296 // not supported
297 QPDFDBG( printf ( "updateFlatness not supported !\n" )); 297 QPDFDBG( printf ( "updateFlatness not supported !\n" ));
298} 298}
299 299
300void QOutputDev::updateLineJoin ( GfxState *state ) 300void QOutputDev::updateLineJoin ( GfxState *state )
301{ 301{
302 updateLineAttrs ( state, gFalse ); 302 updateLineAttrs ( state, gFalse );
303} 303}
304 304
305void QOutputDev::updateLineCap ( GfxState *state ) 305void QOutputDev::updateLineCap ( GfxState *state )
306{ 306{
307 updateLineAttrs ( state, gFalse ); 307 updateLineAttrs ( state, gFalse );
308} 308}
309 309
310// unimplemented 310// unimplemented
311void QOutputDev::updateMiterLimit ( GfxState */*state*/ ) 311void QOutputDev::updateMiterLimit ( GfxState */*state*/ )
312{ 312{
313 QPDFDBG( printf ( "updateMiterLimit not supported !\n" )); 313 QPDFDBG( printf ( "updateMiterLimit not supported !\n" ));
314} 314}
315 315
316void QOutputDev::updateLineWidth ( GfxState *state ) 316void QOutputDev::updateLineWidth ( GfxState *state )
317{ 317{
318 updateLineAttrs ( state, gFalse ); 318 updateLineAttrs ( state, gFalse );
319} 319}
320 320
321void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash ) 321void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash )
322{ 322{
323 fp_t *dashPattern; 323 fp_t *dashPattern;
324 int dashLength; 324 int dashLength;
325 fp_t dashStart; 325 fp_t dashStart;
326 326
327 Qt::PenCapStyle cap; 327 Qt::PenCapStyle cap;
328 Qt::PenJoinStyle join; 328 Qt::PenJoinStyle join;
329 int width; 329 int width;
330 330
331 width = lrint ( state-> getTransformedLineWidth ( )); 331 width = lrint ( state-> getTransformedLineWidth ( ));
332 332
333 switch ( state-> getLineCap ( )) { 333 switch ( state-> getLineCap ( )) {
334 case 0: cap = FlatCap; break; 334 case 0: cap = FlatCap; break;
335 case 1: cap = RoundCap; break; 335 case 1: cap = RoundCap; break;
336 case 2: cap = SquareCap; break; 336 case 2: cap = SquareCap; break;
337 default: 337 default:
338 qWarning ( "Bad line cap style (%d)\n", state-> getLineCap ( )); 338 qWarning ( "Bad line cap style (%d)\n", state-> getLineCap ( ));
339 cap = FlatCap; 339 cap = FlatCap;
340 break; 340 break;
341 } 341 }
342 342
343 switch (state->getLineJoin()) { 343 switch (state->getLineJoin()) {
344 case 0: join = MiterJoin; break; 344 case 0: join = MiterJoin; break;
345 case 1: join = RoundJoin; break; 345 case 1: join = RoundJoin; break;
346 case 2: join = BevelJoin; break; 346 case 2: join = BevelJoin; break;
347 default: 347 default:
348 qWarning ( "Bad line join style (%d)\n", state->getLineJoin ( )); 348 qWarning ( "Bad line join style (%d)\n", state->getLineJoin ( ));
349 join = MiterJoin; 349 join = MiterJoin;
350 break; 350 break;
351 } 351 }
352 352
353 state-> getLineDash ( &dashPattern, &dashLength, &dashStart ); 353 state-> getLineDash ( &dashPattern, &dashLength, &dashStart );
354 354
355 QColor oldcol = m_painter-> pen ( ). color ( ); 355 QColor oldcol = m_painter-> pen ( ). color ( );
356 GfxRGB rgb; 356 GfxRGB rgb;
357 357
358 state-> getStrokeRGB ( &rgb ); 358 state-> getStrokeRGB ( &rgb );
359 oldcol = q_col ( rgb ); 359 oldcol = q_col ( rgb );
360 360
361 m_painter-> setPen ( QPen ( oldcol, width, dashLength > 0 ? DashLine : SolidLine, cap, join )); 361 m_painter-> setPen ( QPen ( oldcol, width, dashLength > 0 ? DashLine : SolidLine, cap, join ));
362 362
363 if ( updateDash && ( dashLength > 0 )) { 363 if ( updateDash && ( dashLength > 0 )) {
364 // Not supported by QT 364 // Not supported by QT
365/* 365/*
366 char dashList[20]; 366 char dashList[20];
367 if (dashLength > 20) 367 if (dashLength > 20)
368 dashLength = 20; 368 dashLength = 20;
369 for ( int i = 0; i < dashLength; ++i ) { 369 for ( int i = 0; i < dashLength; ++i ) {
370 dashList[i] = xoutRound(state->transformWidth(dashPattern[i])); 370 dashList[i] = xoutRound(state->transformWidth(dashPattern[i]));
371 if (dashList[i] == 0) 371 if (dashList[i] == 0)
372 dashList[i] = 1; 372 dashList[i] = 1;
373 } 373 }
374 XSetDashes(display, strokeGC, xoutRound(dashStart), dashList, dashLength); 374 XSetDashes(display, strokeGC, xoutRound(dashStart), dashList, dashLength);
375*/ 375*/
376 } 376 }
377} 377}
378 378
379void QOutputDev::updateFillColor ( GfxState *state ) 379void QOutputDev::updateFillColor ( GfxState *state )
380{ 380{
381 GfxRGB rgb; 381 GfxRGB rgb;
382 state-> getFillRGB ( &rgb ); 382 state-> getFillRGB ( &rgb );
383 383
384 m_painter-> setBrush ( q_col ( rgb )); 384 m_painter-> setBrush ( q_col ( rgb ));
385} 385}
386 386
387void QOutputDev::updateStrokeColor ( GfxState *state ) 387void QOutputDev::updateStrokeColor ( GfxState *state )
388{ 388{
389 GfxRGB rgb; 389 GfxRGB rgb;
390 state-> getStrokeRGB ( &rgb ); 390 state-> getStrokeRGB ( &rgb );
391 391
392 QPen pen = m_painter-> pen ( ); 392 QPen pen = m_painter-> pen ( );
393 pen. setColor ( q_col ( rgb )); 393 pen. setColor ( q_col ( rgb ));
394 m_painter-> setPen ( pen ); 394 m_painter-> setPen ( pen );
395} 395}
396 396
397void QOutputDev::updateFont ( GfxState *state ) 397void QOutputDev::updateFont ( GfxState *state )
398{ 398{
399 fp_t m11, m12, m21, m22; 399 fp_t m11, m12, m21, m22;
400 GfxFont *gfxFont = state-> getFont ( ); 400 GfxFont *gfxFont = state-> getFont ( );
401 401
402 if ( !gfxFont ) 402 if ( !gfxFont )
403 return; 403 return;
404 404
405 state-> getFontTransMat ( &m11, &m12, &m21, &m22 ); 405 state-> getFontTransMat ( &m11, &m12, &m21, &m22 );
406 m11 *= state-> getHorizScaling ( ); 406 m11 *= state-> getHorizScaling ( );
407 m12 *= state-> getHorizScaling ( ); 407 m12 *= state-> getHorizScaling ( );
408 408
409 QFont font = matchFont ( gfxFont, m11, m12, m21, m22 ); 409 QFont font = matchFont ( gfxFont, m11, m12, m21, m22 );
410 410
411 m_painter-> setFont ( font ); 411 m_painter-> setFont ( font );
412 m_text-> updateFont ( state ); 412 m_text-> updateFont ( state );
413} 413}
414 414
415void QOutputDev::stroke ( GfxState *state ) 415void QOutputDev::stroke ( GfxState *state )
416{ 416{
417 QPointArray points; 417 QPointArray points;
418 QArray<int> lengths; 418 QArray<int> lengths;
419 419
420 // transform points 420 // transform points
421 int n = convertPath ( state, points, lengths ); 421 int n = convertPath ( state, points, lengths );
422 422
423 QPDFDBG( printf ( "DRAWING: %d POLYS\n", n )); 423 QPDFDBG( printf ( "DRAWING: %d POLYS\n", n ));
424 424
425 // draw each subpath 425 // draw each subpath
426 int j = 0; 426 int j = 0;
427 for ( int i = 0; i < n; i++ ) { 427 for ( int i = 0; i < n; i++ ) {
428 int len = lengths [i]; 428 int len = lengths [i];
429 429
430 if ( len >= 2 ) { 430 if ( len >= 2 ) {
431 QPDFDBG( printf ( " - POLY %d: ", i )); 431 QPDFDBG( printf ( " - POLY %d: ", i ));
432 QPDFDBG( for ( int ii = 0; ii < len; ii++ )) 432 QPDFDBG( for ( int ii = 0; ii < len; ii++ ))
433 QPDFDBG( printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( ))); 433 QPDFDBG( printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( )));
434 QPDFDBG( printf ( "\n" )); 434 QPDFDBG( printf ( "\n" ));
435 435
436 m_painter-> drawPolyline ( points, j, len ); 436 m_painter-> drawPolyline ( points, j, len );
437 } 437 }
438 j += len; 438 j += len;
439 } 439 }
440 qApp-> processEvents ( ); 440 qApp-> processEvents ( );
441} 441}
442 442
443void QOutputDev::fill ( GfxState *state ) 443void QOutputDev::fill ( GfxState *state )
444{ 444{
445 doFill ( state, true ); 445 doFill ( state, true );
446} 446}
447 447
448void QOutputDev::eoFill ( GfxState *state ) 448void QOutputDev::eoFill ( GfxState *state )
449{ 449{
450 doFill ( state, false ); 450 doFill ( state, false );
451} 451}
452 452
453// 453//
454// X doesn't color the pixels on the right-most and bottom-most 454// X doesn't color the pixels on the right-most and bottom-most
455// borders of a polygon. This means that one-pixel-thick polygons 455// borders of a polygon. This means that one-pixel-thick polygons
456// are not colored at all. I think this is supposed to be a 456// are not colored at all. I think this is supposed to be a
457// feature, but I can't figure out why. So after it fills a 457// feature, but I can't figure out why. So after it fills a
458// polygon, it also draws lines around the border. This is done 458// polygon, it also draws lines around the border. This is done
459// only for single-component polygons, since it's not very 459// only for single-component polygons, since it's not very
460// compatible with the compound polygon kludge (see convertPath()). 460// compatible with the compound polygon kludge (see convertPath()).
461// 461//
462void QOutputDev::doFill ( GfxState *state, bool winding ) 462void QOutputDev::doFill ( GfxState *state, bool winding )
463{ 463{
464 QPointArray points; 464 QPointArray points;
465 QArray<int> lengths; 465 QArray<int> lengths;
466 466
467 // transform points 467 // transform points
468 int n = convertPath ( state, points, lengths ); 468 int n = convertPath ( state, points, lengths );
469 469
470 QPDFDBG( printf ( "FILLING: %d POLYS\n", n )); 470 QPDFDBG( printf ( "FILLING: %d POLYS\n", n ));
471 471
472 QPen oldpen = m_painter-> pen ( ); 472 QPen oldpen = m_painter-> pen ( );
473 m_painter-> setPen ( QPen ( NoPen )); 473 m_painter-> setPen ( QPen ( NoPen ));
474 474
475 // draw each subpath 475 // draw each subpath
476 int j = 0; 476 int j = 0;
477 for ( int i = 0; i < n; i++ ) { 477 for ( int i = 0; i < n; i++ ) {
478 int len = lengths [i]; 478 int len = lengths [i];
479 479
480 if ( len >= 3 ) { 480 if ( len >= 3 ) {
481 QPDFDBG( printf ( " - POLY %d: ", i )); 481 QPDFDBG( printf ( " - POLY %d: ", i ));
482 QPDFDBG( for ( int ii = 0; ii < len; ii++ )) 482 QPDFDBG( for ( int ii = 0; ii < len; ii++ ))
483 QPDFDBG( printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( ))); 483 QPDFDBG( printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( )));
484 QPDFDBG( printf ( "\n" )); 484 QPDFDBG( printf ( "\n" ));
485 485
486 m_painter-> drawPolygon ( points, winding, j, len ); 486 m_painter-> drawPolygon ( points, winding, j, len );
487 } 487 }
488 j += len; 488 j += len;
489 } 489 }
490 m_painter-> setPen ( oldpen ); 490 m_painter-> setPen ( oldpen );
491 491
492 qApp-> processEvents ( ); 492 qApp-> processEvents ( );
493} 493}
494 494
495void QOutputDev::clip ( GfxState *state ) 495void QOutputDev::clip ( GfxState *state )
496{ 496{
497 doClip ( state, true ); 497 doClip ( state, true );
498} 498}
499 499
500void QOutputDev::eoClip ( GfxState *state ) 500void QOutputDev::eoClip ( GfxState *state )
501{ 501{
502 doClip ( state, false ); 502 doClip ( state, false );
503} 503}
504 504
505void QOutputDev::doClip ( GfxState *state, bool winding ) 505void QOutputDev::doClip ( GfxState *state, bool winding )
506{ 506{
507 QPointArray points; 507 QPointArray points;
508 QArray<int> lengths; 508 QArray<int> lengths;
509 509
510 // transform points 510 // transform points
511 int n = convertPath ( state, points, lengths ); 511 int n = convertPath ( state, points, lengths );
512 512
513 QRegion region; 513 QRegion region;
514 514
515 QPDFDBG( printf ( "CLIPPING: %d POLYS\n", n )); 515 QPDFDBG( printf ( "CLIPPING: %d POLYS\n", n ));
516 516
517 // draw each subpath 517 // draw each subpath
518 int j = 0; 518 int j = 0;
519 for ( int i = 0; i < n; i++ ) { 519 for ( int i = 0; i < n; i++ ) {
520 int len = lengths [i]; 520 int len = lengths [i];
521 521
522 if ( len >= 3 ) { 522 if ( len >= 3 ) {
523 QPointArray dummy; 523 QPointArray dummy;
524 dummy. setRawData ( points. data ( ) + j, len ); 524 dummy. setRawData ( points. data ( ) + j, len );
525 525
526 QPDFDBG( printf ( " - POLY %d: ", i )); 526 QPDFDBG( printf ( " - POLY %d: ", i ));
527 QPDFDBG( for ( int ii = 0; ii < len; ii++ ) printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( ))); 527 QPDFDBG( for ( int ii = 0; ii < len; ii++ ) printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( )));
528 QPDFDBG( printf ( "\n" )); 528 QPDFDBG( printf ( "\n" ));
529 529
530 region |= QRegion ( dummy, winding ); 530 region |= QRegion ( dummy, winding );
531 531
532 dummy. resetRawData ( points. data ( ) + j, len ); 532 dummy. resetRawData ( points. data ( ) + j, len );
533 } 533 }
534 j += len; 534 j += len;
535 } 535 }
536 536
537 if ( m_painter && m_painter-> hasClipping ( )) 537 if ( m_painter && m_painter-> hasClipping ( ))
538 region &= m_painter-> clipRegion ( ); 538 region &= m_painter-> clipRegion ( );
539 539
540 //m_painter-> setClipRegion ( region ); 540 //m_painter-> setClipRegion ( region );
541 //m_painter-> setClipping ( true ); 541 //m_painter-> setClipping ( true );
542 542
543 //m_painter-> fillRect ( 0, 0, m_pixmap-> width ( ), m_pixmap-> height ( ), red ); 543 //m_painter-> fillRect ( 0, 0, m_pixmap-> width ( ), m_pixmap-> height ( ), red );
544 //m_painter-> drawText ( points [0]. x ( ) + 10, points [0]. y ( ) + 10, "Bla bla" ); 544 //m_painter-> drawText ( points [0]. x ( ) + 10, points [0]. y ( ) + 10, "Bla bla" );
545 qApp-> processEvents ( ); 545 qApp-> processEvents ( );
546} 546}
547 547
548// 548//
549// Transform points in the path and convert curves to line segments. 549// Transform points in the path and convert curves to line segments.
550// Builds a set of subpaths and returns the number of subpaths. 550// Builds a set of subpaths and returns the number of subpaths.
551// If <fillHack> is set, close any unclosed subpaths and activate a 551// If <fillHack> is set, close any unclosed subpaths and activate a
552// kludge for polygon fills: First, it divides up the subpaths into 552// kludge for polygon fills: First, it divides up the subpaths into
553// non-overlapping polygons by simply comparing bounding rectangles. 553// non-overlapping polygons by simply comparing bounding rectangles.
554// Then it connects subaths within a single compound polygon to a single 554// Then it connects subaths within a single compound polygon to a single
555// point so that X can fill the polygon (sort of). 555// point so that X can fill the polygon (sort of).
556// 556//
557int QOutputDev::convertPath ( GfxState *state, QPointArray &points, QArray<int> &lengths ) 557int QOutputDev::convertPath ( GfxState *state, QPointArray &points, QArray<int> &lengths )
558{ 558{
559 GfxPath *path = state-> getPath ( ); 559 GfxPath *path = state-> getPath ( );
560 int n = path-> getNumSubpaths ( ); 560 int n = path-> getNumSubpaths ( );
561 561
562 lengths. resize ( n ); 562 lengths. resize ( n );
563 563
564 // do each subpath 564 // do each subpath
565 for ( int i = 0; i < n; i++ ) { 565 for ( int i = 0; i < n; i++ ) {
566 // transform the points 566 // transform the points
567 lengths [i] = convertSubpath ( state, path-> getSubpath ( i ), points ); 567 lengths [i] = convertSubpath ( state, path-> getSubpath ( i ), points );
568 } 568 }
569 569
570 return n; 570 return n;
571} 571}
572 572
573// 573//
574// Transform points in a single subpath and convert curves to line 574// Transform points in a single subpath and convert curves to line
575// segments. 575// segments.
576// 576//
577int QOutputDev::convertSubpath ( GfxState *state, GfxSubpath *subpath, QPointArray &points ) 577int QOutputDev::convertSubpath ( GfxState *state, GfxSubpath *subpath, QPointArray &points )
578{ 578{
579 int oldcnt = points. count ( ); 579 int oldcnt = points. count ( );
580 580
581 fp_t x0, y0, x1, y1, x2, y2, x3, y3; 581 fp_t x0, y0, x1, y1, x2, y2, x3, y3;
582 582
583 int m = subpath-> getNumPoints ( ); 583 int m = subpath-> getNumPoints ( );
584 int i = 0; 584 int i = 0;
585 585
586 while ( i < m ) { 586 while ( i < m ) {
587 if ( i >= 1 && subpath-> getCurve ( i )) { 587 if ( i >= 1 && subpath-> getCurve ( i )) {
588 state-> transform ( subpath-> getX ( i - 1 ), subpath-> getY ( i - 1 ), &x0, &y0 ); 588 state-> transform ( subpath-> getX ( i - 1 ), subpath-> getY ( i - 1 ), &x0, &y0 );
589 state-> transform ( subpath-> getX ( i ), subpath-> getY ( i ), &x1, &y1 ); 589 state-> transform ( subpath-> getX ( i ), subpath-> getY ( i ), &x1, &y1 );
590 state-> transform ( subpath-> getX ( i + 1 ), subpath-> getY ( i + 1 ), &x2, &y2 ); 590 state-> transform ( subpath-> getX ( i + 1 ), subpath-> getY ( i + 1 ), &x2, &y2 );
591 state-> transform ( subpath-> getX ( i + 2 ), subpath-> getY ( i + 2 ), &x3, &y3 ); 591 state-> transform ( subpath-> getX ( i + 2 ), subpath-> getY ( i + 2 ), &x3, &y3 );
592 592
593 QPointArray tmp; 593 QPointArray tmp;
594 tmp. setPoints ( 4, lrint ( x0 ), lrint ( y0 ), lrint ( x1 ), lrint ( y1 ), 594 tmp. setPoints ( 4, lrint ( x0 ), lrint ( y0 ), lrint ( x1 ), lrint ( y1 ),
595 lrint ( x2 ), lrint ( y2 ), lrint ( x3 ), lrint ( y3 )); 595 lrint ( x2 ), lrint ( y2 ), lrint ( x3 ), lrint ( y3 ));
596 596
597#if QT_VERSION < 300 597#if QT_VERSION < 0x030000
598 tmp = tmp. quadBezier ( ); 598 tmp = tmp. quadBezier ( );
599 599
600 for ( uint loop = 0; loop < tmp. count ( ); loop++ ) { 600 for ( uint loop = 0; loop < tmp. count ( ); loop++ ) {
601 QPoint p = tmp. point ( loop ); 601 QPoint p = tmp. point ( loop );
602 points. putPoints ( points. count ( ), 1, p. x ( ), p. y ( )); 602 points. putPoints ( points. count ( ), 1, p. x ( ), p. y ( ));
603 } 603 }
604#else 604#else
605 tmp = tmp. cubicBezier ( ); 605 tmp = tmp. cubicBezier ( );
606 points. putPoints ( points. count ( ), tmp. count ( ), tmp ); 606 points. putPoints ( points. count ( ), tmp. count ( ), tmp );
607#endif 607#endif
608 608
609 i += 3; 609 i += 3;
610 } 610 }
611 else { 611 else {
612 state-> transform ( subpath-> getX ( i ), subpath-> getY ( i ), &x1, &y1 ); 612 state-> transform ( subpath-> getX ( i ), subpath-> getY ( i ), &x1, &y1 );
613 613
614 points. putPoints ( points. count ( ), 1, lrint ( x1 ), lrint ( y1 )); 614 points. putPoints ( points. count ( ), 1, lrint ( x1 ), lrint ( y1 ));
615 ++i; 615 ++i;
616 } 616 }
617 } 617 }
618 return points. count ( ) - oldcnt; 618 return points. count ( ) - oldcnt;
619} 619}
620 620
621 621
622void QOutputDev::beginString ( GfxState *state, GString */*s*/ ) 622void QOutputDev::beginString ( GfxState *state, GString */*s*/ )
623{ 623{
624 m_text-> beginString ( state ); 624 m_text-> beginString ( state );
625} 625}
626 626
627void QOutputDev::endString ( GfxState */*state*/ ) 627void QOutputDev::endString ( GfxState */*state*/ )
628{ 628{
629 m_text-> endString ( ); 629 m_text-> endString ( );
630} 630}
631 631
632void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y, 632void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y,
633 fp_t dx, fp_t dy, fp_t originX, fp_t originY, 633 fp_t dx, fp_t dy, fp_t originX, fp_t originY,
634 CharCode code, Unicode *u, int uLen ) 634 CharCode code, Unicode *u, int uLen )
635{ 635{
636 fp_t x1, y1, dx1, dy1; 636 fp_t x1, y1, dx1, dy1;
637 637
638 if ( uLen > 0 ) 638 if ( uLen > 0 )
639 m_text-> addChar ( state, x, y, dx, dy, u, uLen ); 639 m_text-> addChar ( state, x, y, dx, dy, u, uLen );
640 640
641 // check for invisible text -- this is used by Acrobat Capture 641 // check for invisible text -- this is used by Acrobat Capture
642 if (( state-> getRender ( ) & 3 ) == 3 ) { 642 if (( state-> getRender ( ) & 3 ) == 3 ) {
643 return; 643 return;
644 } 644 }
645 645
646 x -= originX; 646 x -= originX;
647 y -= originY; 647 y -= originY;
648 state-> transform ( x, y, &x1, &y1 ); 648 state-> transform ( x, y, &x1, &y1 );
649 state-> transformDelta ( dx, dy, &dx1, &dy1 ); 649 state-> transformDelta ( dx, dy, &dx1, &dy1 );
650 650
651 651
652 if ( uLen > 0 ) { 652 if ( uLen > 0 ) {
653 QString str; 653 QString str;
654 QFontMetrics fm = m_painter-> fontMetrics ( ); 654 QFontMetrics fm = m_painter-> fontMetrics ( );
655 655
656 for ( int i = 0; i < uLen; i++ ) { 656 for ( int i = 0; i < uLen; i++ ) {
657 QChar c = QChar ( u [i] ); 657 QChar c = QChar ( u [i] );
658 658
659 if ( fm. inFont ( c )) { 659 if ( fm. inFont ( c )) {
660 str [i] = QChar ( u [i] ); 660 str [i] = QChar ( u [i] );
661 } 661 }
662 else { 662 else {
663 str [i] = ' '; 663 str [i] = ' ';
664 QPDFDBG( printf ( "CHARACTER NOT IN FONT: %hx\n", c. unicode ( ))); 664 QPDFDBG( printf ( "CHARACTER NOT IN FONT: %hx\n", c. unicode ( )));
665 } 665 }
666 } 666 }
667 667
668 if (( uLen == 1 ) && ( str [0] == ' ' )) 668 if (( uLen == 1 ) && ( str [0] == ' ' ))
669 return; 669 return;
670 670
671 671
672 fp_t m11, m12, m21, m22; 672 fp_t m11, m12, m21, m22;
673 673
674 state-> getFontTransMat ( &m11, &m12, &m21, &m22 ); 674 state-> getFontTransMat ( &m11, &m12, &m21, &m22 );
675 m11 *= state-> getHorizScaling ( ); 675 m11 *= state-> getHorizScaling ( );
676 m12 *= state-> getHorizScaling ( ); 676 m12 *= state-> getHorizScaling ( );
677 677
678 fp_t fsize = m_painter-> font ( ). pixelSize ( ); 678 fp_t fsize = m_painter-> font ( ). pixelSize ( );
679 679
680#ifndef QT_NO_TRANSFORMATIONS 680#ifndef QT_NO_TRANSFORMATIONS
681 QWMatrix oldmat; 681 QWMatrix oldmat;
682 682
683 bool dorot = (( m12 < -0.1 ) || ( m12 > 0.1 )) && (( m21 < -0.1 ) || ( m21 > 0.1 )); 683 bool dorot = (( m12 < -0.1 ) || ( m12 > 0.1 )) && (( m21 < -0.1 ) || ( m21 > 0.1 ));
684 684
685 if ( dorot ) { 685 if ( dorot ) {
686 oldmat = m_painter-> worldMatrix ( ); 686 oldmat = m_painter-> worldMatrix ( );
687 687
688 std::cerr << std::endl << "ROTATED: " << m11 << ", " << m12 << ", " << m21 << ", " << m22 << " / SIZE: " << fsize << " / TEXT: " << str. local8Bit ( ) << endl << endl; 688 std::cerr << std::endl << "ROTATED: " << m11 << ", " << m12 << ", " << m21 << ", " << m22 << " / SIZE: " << fsize << " / TEXT: " << str. local8Bit ( ) << endl << endl;
689 689
690 QWMatrix mat ( lrint ( m11 / fsize ), lrint ( m12 / fsize ), -lrint ( m21 / fsize ), -lrint ( m22 / fsize ), lrint ( x1 ), lrint ( y1 )); 690 QWMatrix mat ( lrint ( m11 / fsize ), lrint ( m12 / fsize ), -lrint ( m21 / fsize ), -lrint ( m22 / fsize ), lrint ( x1 ), lrint ( y1 ));
691 691
692 m_painter-> setWorldMatrix ( mat ); 692 m_painter-> setWorldMatrix ( mat );
693 693
694 x1 = 0; 694 x1 = 0;
695 y1 = 0; 695 y1 = 0;
696 } 696 }
697#endif 697#endif
698 698
699 QPen oldpen = m_painter-> pen ( ); 699 QPen oldpen = m_painter-> pen ( );
700 700
701 if (!( state-> getRender ( ) & 1 )) { 701 if (!( state-> getRender ( ) & 1 )) {
702 QPen fillpen = oldpen; 702 QPen fillpen = oldpen;
703 703
704 fillpen. setColor ( m_painter-> brush ( ). color ( )); 704 fillpen. setColor ( m_painter-> brush ( ). color ( ));
705 m_painter-> setPen ( fillpen ); 705 m_painter-> setPen ( fillpen );
706 } 706 }
707 707
708 if ( fsize > 5 ) 708 if ( fsize > 5 )
709 m_painter-> drawText ( lrint ( x1 ), lrint ( y1 ), str ); 709 m_painter-> drawText ( lrint ( x1 ), lrint ( y1 ), str );
710 else 710 else
711 m_painter-> fillRect ( lrint ( x1 ), lrint ( y1 ), lrint ( QMAX( fp_t(1), dx1 )), lrint ( QMAX( fsize, dy1 )), m_painter-> pen ( ). color ( )); 711 m_painter-> fillRect ( lrint ( x1 ), lrint ( y1 ), lrint ( QMAX( fp_t(1), dx1 )), lrint ( QMAX( fsize, dy1 )), m_painter-> pen ( ). color ( ));
712 712
713 m_painter-> setPen ( oldpen ); 713 m_painter-> setPen ( oldpen );
714 714
715#ifndef QT_NO_TRANSFORMATIONS 715#ifndef QT_NO_TRANSFORMATIONS
716 if ( dorot ) 716 if ( dorot )
717 m_painter-> setWorldMatrix ( oldmat ); 717 m_painter-> setWorldMatrix ( oldmat );
718#endif 718#endif
719 719
720 QPDFDBG( printf ( "DRAW TEXT: \"%s\" at (%ld/%ld)\n", str. local8Bit ( ). data ( ), lrint ( x1 ), lrint ( y1 ))); 720 QPDFDBG( printf ( "DRAW TEXT: \"%s\" at (%ld/%ld)\n", str. local8Bit ( ). data ( ), lrint ( x1 ), lrint ( y1 )));
721 } 721 }
722 else if ( code != 0 ) { 722 else if ( code != 0 ) {
723 // some PDF files use CID 0, which is .notdef, so just ignore it 723 // some PDF files use CID 0, which is .notdef, so just ignore it
724 qWarning ( "Unknown character (CID=%d Unicode=%hx)\n", code, (unsigned short) ( uLen > 0 ? u [0] : (Unicode) 0 )); 724 qWarning ( "Unknown character (CID=%d Unicode=%hx)\n", code, (unsigned short) ( uLen > 0 ? u [0] : (Unicode) 0 ));
725 } 725 }
726 qApp-> processEvents ( ); 726 qApp-> processEvents ( );
727} 727}
728 728
729 729
730 730
731void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str, int width, int height, GBool invert, GBool inlineImg ) 731void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str, int width, int height, GBool invert, GBool inlineImg )
732{ 732{
733 // get CTM, check for singular matrix 733 // get CTM, check for singular matrix
734 fp_t *ctm = state-> getCTM ( ); 734 fp_t *ctm = state-> getCTM ( );
735 735
736 if ( fabs ( ctm [0] * ctm [3] - ctm [1] * ctm [2] ) < 0.000001 ) { 736 if ( fabs ( ctm [0] * ctm [3] - ctm [1] * ctm [2] ) < 0.000001 ) {
737 qWarning ( "Singular CTM in drawImage\n" ); 737 qWarning ( "Singular CTM in drawImage\n" );
738 738
739 if ( inlineImg ) { 739 if ( inlineImg ) {
740 str-> reset ( ); 740 str-> reset ( );
741 int j = height * (( width + 7 ) / 8 ); 741 int j = height * (( width + 7 ) / 8 );
742 for ( int i = 0; i < j; i++ ) 742 for ( int i = 0; i < j; i++ )
743 str->getChar(); 743 str->getChar();
744 744
745 str->close(); 745 str->close();
746 } 746 }
747 return; 747 return;
748 } 748 }
749 749
750 GfxRGB rgb; 750 GfxRGB rgb;
751 state-> getFillRGB ( &rgb ); 751 state-> getFillRGB ( &rgb );
752 uint val = ( lrint ( rgb. r * 255 ) & 0xff ) << 16 | ( lrint ( rgb. g * 255 ) & 0xff ) << 8 | ( lrint ( rgb. b * 255 ) & 0xff ); 752 uint val = ( lrint ( rgb. r * 255 ) & 0xff ) << 16 | ( lrint ( rgb. g * 255 ) & 0xff ) << 8 | ( lrint ( rgb. b * 255 ) & 0xff );
753 753
754 754
755 QImage img ( width, height, 32 ); 755 QImage img ( width, height, 32 );
756 img. setAlphaBuffer ( true ); 756 img. setAlphaBuffer ( true );
757 757
758 QPDFDBG( printf ( "IMAGE MASK (%dx%d)\n", width, height )); 758 QPDFDBG( printf ( "IMAGE MASK (%dx%d)\n", width, height ));
759 759
760 // initialize the image stream 760 // initialize the image stream
761 ImageStream *imgStr = new ImageStream ( str, width, 1, 1 ); 761 ImageStream *imgStr = new ImageStream ( str, width, 1, 1 );
762 imgStr-> reset ( ); 762 imgStr-> reset ( );
763 763
764 uchar **scanlines = img. jumpTable ( ); 764 uchar **scanlines = img. jumpTable ( );
765 765
766 if ( ctm [3] > 0 ) 766 if ( ctm [3] > 0 )
767 scanlines += ( height - 1 ); 767 scanlines += ( height - 1 );
768 768
769 for ( int y = 0; y < height; y++ ) { 769 for ( int y = 0; y < height; y++ ) {
770 QRgb *scanline = (QRgb *) *scanlines; 770 QRgb *scanline = (QRgb *) *scanlines;
771 771
772 if ( ctm [0] < 0 ) 772 if ( ctm [0] < 0 )
773 scanline += ( width - 1 ); 773 scanline += ( width - 1 );
774 774
775 for ( int x = 0; x < width; x++ ) { 775 for ( int x = 0; x < width; x++ ) {
776 Guchar alpha; 776 Guchar alpha;
777 777
778 imgStr-> getPixel ( &alpha ); 778 imgStr-> getPixel ( &alpha );
779 779
780 if ( invert ) 780 if ( invert )
781 alpha ^= 1; 781 alpha ^= 1;
782 782
783 *scanline = ( alpha == 0 ) ? 0xff000000 | val : val; 783 *scanline = ( alpha == 0 ) ? 0xff000000 | val : val;
784 784
785 ctm [0] < 0 ? scanline-- : scanline++; 785 ctm [0] < 0 ? scanline-- : scanline++;
786 } 786 }
787 ctm [3] > 0 ? scanlines-- : scanlines++; 787 ctm [3] > 0 ? scanlines-- : scanlines++;
788 788
789 qApp-> processEvents ( ); 789 qApp-> processEvents ( );
790 } 790 }
791 791
792#ifndef QT_NO_TRANSFORMATIONS 792#ifndef QT_NO_TRANSFORMATIONS
793 QWMatrix mat ( ctm [0] / width, ctm [1], ctm [2], ctm [3] / height, ctm [4], ctm [5] ); 793 QWMatrix mat ( ctm [0] / width, ctm [1], ctm [2], ctm [3] / height, ctm [4], ctm [5] );
794 794
795 std::cerr << "MATRIX T=" << mat. dx ( ) << "/" << mat. dy ( ) << std::endl 795 std::cerr << "MATRIX T=" << mat. dx ( ) << "/" << mat. dy ( ) << std::endl
796 << " - M=" << mat. m11 ( ) << "/" << mat. m12 ( ) << "/" << mat. m21 ( ) << "/" << mat. m22 ( ) << std::endl; 796 << " - M=" << mat. m11 ( ) << "/" << mat. m12 ( ) << "/" << mat. m21 ( ) << "/" << mat. m22 ( ) << std::endl;
797 797
798 QWMatrix oldmat = m_painter-> worldMatrix ( ); 798 QWMatrix oldmat = m_painter-> worldMatrix ( );
799 m_painter-> setWorldMatrix ( mat, true ); 799 m_painter-> setWorldMatrix ( mat, true );
800 800
801#ifdef QWS 801#ifdef QWS
802 QPixmap pm; 802 QPixmap pm;
803 pm. convertFromImage ( img ); 803 pm. convertFromImage ( img );
804 m_painter-> drawPixmap ( 0, 0, pm ); 804 m_painter-> drawPixmap ( 0, 0, pm );
805#else 805#else
806 m_painter-> drawImage ( QPoint ( 0, 0 ), img ); 806 m_painter-> drawImage ( QPoint ( 0, 0 ), img );
807#endif 807#endif
808 808
809 m_painter-> setWorldMatrix ( oldmat ); 809 m_painter-> setWorldMatrix ( oldmat );
810 810
811#else 811#else
812 if (( ctm [1] < -0.1 ) || ( ctm [1] > 0.1 ) || ( ctm [2] < -0.1 ) || ( ctm [2] > 0.1 )) { 812 if (( ctm [1] < -0.1 ) || ( ctm [1] > 0.1 ) || ( ctm [2] < -0.1 ) || ( ctm [2] > 0.1 )) {
813 QPDFDBG( printf ( "### ROTATED / SHEARED / ETC -- CANNOT DISPLAY THIS IMAGE\n" )); 813 QPDFDBG( printf ( "### ROTATED / SHEARED / ETC -- CANNOT DISPLAY THIS IMAGE\n" ));
814 } 814 }
815 else { 815 else {
816 int x = lrint ( ctm [4] ); 816 int x = lrint ( ctm [4] );
817 int y = lrint ( ctm [5] ); 817 int y = lrint ( ctm [5] );
818 818
819 int w = lrint ( ctm [0] ); 819 int w = lrint ( ctm [0] );
820 int h = lrint ( ctm [3] ); 820 int h = lrint ( ctm [3] );
821 821
822 if ( w < 0 ) { 822 if ( w < 0 ) {
823 x += w; 823 x += w;
824 w = -w; 824 w = -w;
825 } 825 }
826 if ( h < 0 ) { 826 if ( h < 0 ) {
827 y += h; 827 y += h;
828 h = -h; 828 h = -h;
829 } 829 }
830 830
831 QPDFDBG( printf ( "DRAWING IMAGE MASKED: %d/%d - %dx%d\n", x, y, w, h )); 831 QPDFDBG( printf ( "DRAWING IMAGE MASKED: %d/%d - %dx%d\n", x, y, w, h ));
832 832
833 img = img. smoothScale ( w, h ); 833 img = img. smoothScale ( w, h );
834 qApp-> processEvents ( ); 834 qApp-> processEvents ( );
835 m_painter-> drawImage ( x, y, img ); 835 m_painter-> drawImage ( x, y, img );
836 } 836 }
837 837
838#endif 838#endif
839 839
840 delete imgStr; 840 delete imgStr;
841 qApp-> processEvents ( ); 841 qApp-> processEvents ( );
842} 842}
843 843
844 844
845void QOutputDev::drawImage(GfxState *state, Object */*ref*/, Stream *str, int width, int height, GfxImageColorMap *colorMap, int *maskColors, GBool inlineImg ) 845void QOutputDev::drawImage(GfxState *state, Object */*ref*/, Stream *str, int width, int height, GfxImageColorMap *colorMap, int *maskColors, GBool inlineImg )
846{ 846{
847 int nComps, nVals, nBits; 847 int nComps, nVals, nBits;
848 848
849 // image parameters 849 // image parameters
850 nComps = colorMap->getNumPixelComps ( ); 850 nComps = colorMap->getNumPixelComps ( );
851 nVals = width * nComps; 851 nVals = width * nComps;
852 nBits = colorMap-> getBits ( ); 852 nBits = colorMap-> getBits ( );
853 853
854 // get CTM, check for singular matrix 854 // get CTM, check for singular matrix
855 fp_t *ctm = state-> getCTM ( ); 855 fp_t *ctm = state-> getCTM ( );
856 856
857 if ( fabs ( ctm [0] * ctm [3] - ctm [1] * ctm [2] ) < 0.000001 ) { 857 if ( fabs ( ctm [0] * ctm [3] - ctm [1] * ctm [2] ) < 0.000001 ) {
858 qWarning ( "Singular CTM in drawImage\n" ); 858 qWarning ( "Singular CTM in drawImage\n" );
859 859
860 if ( inlineImg ) { 860 if ( inlineImg ) {
861 str-> reset ( ); 861 str-> reset ( );
862 int j = height * (( nVals * nBits + 7 ) / 8 ); 862 int j = height * (( nVals * nBits + 7 ) / 8 );
863 for ( int i = 0; i < j; i++ ) 863 for ( int i = 0; i < j; i++ )
864 str->getChar(); 864 str->getChar();
865 865
866 str->close(); 866 str->close();
867 } 867 }
868 return; 868 return;
869 } 869 }
870 870
871 QImage img ( width, height, 32 ); 871 QImage img ( width, height, 32 );
872 872
873 if ( maskColors ) 873 if ( maskColors )
874 img. setAlphaBuffer ( true ); 874 img. setAlphaBuffer ( true );
875 875
876 QPDFDBG( printf ( "IMAGE (%dx%d)\n", width, height )); 876 QPDFDBG( printf ( "IMAGE (%dx%d)\n", width, height ));
877 877
878 // initialize the image stream 878 // initialize the image stream
879 ImageStream *imgStr = new ImageStream ( str, width, nComps, nBits ); 879 ImageStream *imgStr = new ImageStream ( str, width, nComps, nBits );
880 imgStr-> reset ( ); 880 imgStr-> reset ( );
881 881
882 Guchar pixBuf [gfxColorMaxComps]; 882 Guchar pixBuf [gfxColorMaxComps];
883 GfxRGB rgb; 883 GfxRGB rgb;
884 884
885 885
886 uchar **scanlines = img. jumpTable ( ); 886 uchar **scanlines = img. jumpTable ( );
887 887
888 if ( ctm [3] > 0 ) 888 if ( ctm [3] > 0 )
889 scanlines += ( height - 1 ); 889 scanlines += ( height - 1 );
890 890
891 for ( int y = 0; y < height; y++ ) { 891 for ( int y = 0; y < height; y++ ) {
892 QRgb *scanline = (QRgb *) *scanlines; 892 QRgb *scanline = (QRgb *) *scanlines;
893 893
894 if ( ctm [0] < 0 ) 894 if ( ctm [0] < 0 )
895 scanline += ( width - 1 ); 895 scanline += ( width - 1 );
896 896
897 for ( int x = 0; x < width; x++ ) { 897 for ( int x = 0; x < width; x++ ) {
898 imgStr-> getPixel ( pixBuf ); 898 imgStr-> getPixel ( pixBuf );
899 colorMap-> getRGB ( pixBuf, &rgb ); 899 colorMap-> getRGB ( pixBuf, &rgb );
900 900
901 uint val = ( lrint ( rgb. r * 255 ) & 0xff ) << 16 | ( lrint ( rgb. g * 255 ) & 0xff ) << 8 | ( lrint ( rgb. b * 255 ) & 0xff ); 901 uint val = ( lrint ( rgb. r * 255 ) & 0xff ) << 16 | ( lrint ( rgb. g * 255 ) & 0xff ) << 8 | ( lrint ( rgb. b * 255 ) & 0xff );
902 902
903 if ( maskColors ) { 903 if ( maskColors ) {
904 for ( int k = 0; k < nComps; ++k ) { 904 for ( int k = 0; k < nComps; ++k ) {
905 if (( pixBuf [k] < maskColors [2 * k] ) || ( pixBuf [k] > maskColors [2 * k] )) { 905 if (( pixBuf [k] < maskColors [2 * k] ) || ( pixBuf [k] > maskColors [2 * k] )) {
906 val |= 0xff000000; 906 val |= 0xff000000;
907 break; 907 break;
908 } 908 }
909 } 909 }
910 } 910 }
911 *scanline = val; 911 *scanline = val;
912 912
913 ctm [0] < 0 ? scanline-- : scanline++; 913 ctm [0] < 0 ? scanline-- : scanline++;
914 } 914 }
915 ctm [3] > 0 ? scanlines-- : scanlines++; 915 ctm [3] > 0 ? scanlines-- : scanlines++;
916 916
917 qApp-> processEvents ( ); 917 qApp-> processEvents ( );
918 } 918 }
919 919
920 920
921#ifndef QT_NO_TRANSFORMATIONS 921#ifndef QT_NO_TRANSFORMATIONS
922 QWMatrix mat ( ctm [0] / width, ctm [1], ctm [2], ctm [3] / height, ctm [4], ctm [5] ); 922 QWMatrix mat ( ctm [0] / width, ctm [1], ctm [2], ctm [3] / height, ctm [4], ctm [5] );
923 923
924 std::cerr << "MATRIX T=" << mat. dx ( ) << "/" << mat. dy ( ) << std::endl 924 std::cerr << "MATRIX T=" << mat. dx ( ) << "/" << mat. dy ( ) << std::endl
925 << " - M=" << mat. m11 ( ) << "/" << mat. m12 ( ) << "/" << mat. m21 ( ) << "/" << mat. m22 ( ) << std::endl; 925 << " - M=" << mat. m11 ( ) << "/" << mat. m12 ( ) << "/" << mat. m21 ( ) << "/" << mat. m22 ( ) << std::endl;
926 926
927 QWMatrix oldmat = m_painter-> worldMatrix ( ); 927 QWMatrix oldmat = m_painter-> worldMatrix ( );
928 m_painter-> setWorldMatrix ( mat, true ); 928 m_painter-> setWorldMatrix ( mat, true );
929 929
930#ifdef QWS 930#ifdef QWS
931 QPixmap pm; 931 QPixmap pm;
932 pm. convertFromImage ( img ); 932 pm. convertFromImage ( img );
933 m_painter-> drawPixmap ( 0, 0, pm ); 933 m_painter-> drawPixmap ( 0, 0, pm );
934#else 934#else
935 m_painter-> drawImage ( QPoint ( 0, 0 ), img ); 935 m_painter-> drawImage ( QPoint ( 0, 0 ), img );
936#endif 936#endif
937 937
938 m_painter-> setWorldMatrix ( oldmat ); 938 m_painter-> setWorldMatrix ( oldmat );
939 939
940#else // QT_NO_TRANSFORMATIONS 940#else // QT_NO_TRANSFORMATIONS
941 941
942 if (( ctm [1] < -0.1 ) || ( ctm [1] > 0.1 ) || ( ctm [2] < -0.1 ) || ( ctm [2] > 0.1 )) { 942 if (( ctm [1] < -0.1 ) || ( ctm [1] > 0.1 ) || ( ctm [2] < -0.1 ) || ( ctm [2] > 0.1 )) {
943 QPDFDBG( printf ( "### ROTATED / SHEARED / ETC -- CANNOT DISPLAY THIS IMAGE\n" )); 943 QPDFDBG( printf ( "### ROTATED / SHEARED / ETC -- CANNOT DISPLAY THIS IMAGE\n" ));
944 } 944 }
945 else { 945 else {
946 int x = lrint ( ctm [4] ); 946 int x = lrint ( ctm [4] );
947 int y = lrint ( ctm [5] ); 947 int y = lrint ( ctm [5] );
948 948
949 int w = lrint ( ctm [0] ); 949 int w = lrint ( ctm [0] );
950 int h = lrint ( ctm [3] ); 950 int h = lrint ( ctm [3] );
951 951
952 if ( w < 0 ) { 952 if ( w < 0 ) {
953 x += w; 953 x += w;
954 w = -w; 954 w = -w;
955 } 955 }
956 if ( h < 0 ) { 956 if ( h < 0 ) {
957 y += h; 957 y += h;
958 h = -h; 958 h = -h;
959 } 959 }
960 960
961 QPDFDBG( printf ( "DRAWING IMAGE: %d/%d - %dx%d\n", x, y, w, h )); 961 QPDFDBG( printf ( "DRAWING IMAGE: %d/%d - %dx%d\n", x, y, w, h ));
962 962
963 img = img. smoothScale ( w, h ); 963 img = img. smoothScale ( w, h );
964 qApp-> processEvents ( ); 964 qApp-> processEvents ( );
965 m_painter-> drawImage ( x, y, img ); 965 m_painter-> drawImage ( x, y, img );
966 } 966 }
967 967
968#endif 968#endif
969 969
970 970
971 delete imgStr; 971 delete imgStr;
972 qApp-> processEvents ( ); 972 qApp-> processEvents ( );
973} 973}
974 974
975 975
976 976
977bool QOutputDev::findText ( const QString &str, QRect &r, bool top, bool bottom ) 977bool QOutputDev::findText ( const QString &str, QRect &r, bool top, bool bottom )
978{ 978{
979 int l, t, w, h; 979 int l, t, w, h;
980 r. rect ( &l, &t, &w, &h ); 980 r. rect ( &l, &t, &w, &h );
981 981
982 bool res = findText ( str, l, t, w, h, top, bottom ); 982 bool res = findText ( str, l, t, w, h, top, bottom );
983 983
984 r. setRect ( l, t, w, h ); 984 r. setRect ( l, t, w, h );
985 return res; 985 return res;
986} 986}
987 987
988bool QOutputDev::findText ( const QString &str, int &l, int &t, int &w, int &h, bool top, bool bottom ) 988bool QOutputDev::findText ( const QString &str, int &l, int &t, int &w, int &h, bool top, bool bottom )
989{ 989{
990 bool found = false; 990 bool found = false;
991 uint len = str. length ( ); 991 uint len = str. length ( );
992 Unicode *s = new Unicode [len]; 992 Unicode *s = new Unicode [len];
993 993
994 for ( uint i = 0; i < len; i++ ) 994 for ( uint i = 0; i < len; i++ )
995 s [i] = str [i]. unicode ( ); 995 s [i] = str [i]. unicode ( );
996 996
997 fp_t x1 = (fp_t) l; 997 fp_t x1 = (fp_t) l;
998 fp_t y1 = (fp_t) t; 998 fp_t y1 = (fp_t) t;
999 fp_t x2 = (fp_t) l + w - 1; 999 fp_t x2 = (fp_t) l + w - 1;
1000 fp_t y2 = (fp_t) t + h - 1; 1000 fp_t y2 = (fp_t) t + h - 1;
1001 1001
1002 if ( m_text-> findText ( s, len, top, bottom, &x1, &y1, &x2, &y2 )) { 1002 if ( m_text-> findText ( s, len, top, bottom, &x1, &y1, &x2, &y2 )) {
1003 l = lrint ( x1 ); 1003 l = lrint ( x1 );
1004 t = lrint ( y1 ); 1004 t = lrint ( y1 );
1005 w = lrint ( x2 ) - l + 1; 1005 w = lrint ( x2 ) - l + 1;
1006 h = lrint ( y2 ) - t + 1; 1006 h = lrint ( y2 ) - t + 1;
1007 found = true; 1007 found = true;
1008 } 1008 }
1009 delete [] s; 1009 delete [] s;
1010 1010
1011 return found; 1011 return found;
1012} 1012}
1013 1013
1014GBool QOutputDev::findText ( Unicode *s, int len, GBool top, GBool bottom, int *xMin, int *yMin, int *xMax, int *yMax ) 1014GBool QOutputDev::findText ( Unicode *s, int len, GBool top, GBool bottom, int *xMin, int *yMin, int *xMax, int *yMax )
1015{ 1015{
1016 bool found = false; 1016 bool found = false;
1017 fp_t xMin1 = (double) *xMin; 1017 fp_t xMin1 = (double) *xMin;
1018 fp_t yMin1 = (double) *yMin; 1018 fp_t yMin1 = (double) *yMin;
1019 fp_t xMax1 = (double) *xMax; 1019 fp_t xMax1 = (double) *xMax;
1020 fp_t yMax1 = (double) *yMax; 1020 fp_t yMax1 = (double) *yMax;
1021 1021
1022 if ( m_text-> findText ( s, len, top, bottom, &xMin1, &yMin1, &xMax1, &yMax1 )) { 1022 if ( m_text-> findText ( s, len, top, bottom, &xMin1, &yMin1, &xMax1, &yMax1 )) {
1023 *xMin = lrint ( xMin1 ); 1023 *xMin = lrint ( xMin1 );
1024 *xMax = lrint ( xMax1 ); 1024 *xMax = lrint ( xMax1 );
1025 *yMin = lrint ( yMin1 ); 1025 *yMin = lrint ( yMin1 );
1026 *yMax = lrint ( yMax1 ); 1026 *yMax = lrint ( yMax1 );
1027 found = true; 1027 found = true;
1028 } 1028 }
1029 return found; 1029 return found;
1030} 1030}
1031 1031
1032QString QOutputDev::getText ( int l, int t, int w, int h ) 1032QString QOutputDev::getText ( int l, int t, int w, int h )
1033{ 1033{
1034 GString *gstr = m_text-> getText ( l, t, l + w - 1, t + h - 1 ); 1034 GString *gstr = m_text-> getText ( l, t, l + w - 1, t + h - 1 );
1035 QString str = gstr-> getCString ( ); 1035 QString str = gstr-> getCString ( );
1036 delete gstr; 1036 delete gstr;
1037 return str; 1037 return str;
1038} 1038}
1039 1039
1040QString QOutputDev::getText ( const QRect &r ) 1040QString QOutputDev::getText ( const QRect &r )
1041{ 1041{
1042 return getText ( r. left ( ), r. top ( ), r. width ( ), r. height ( )); 1042 return getText ( r. left ( ), r. top ( ), r. width ( ), r. height ( ));
1043} 1043}
1044 1044
1045 1045
1046 1046
1047void QOutputDev::drawContents ( QPainter *p, int clipx, int clipy, int clipw, int cliph ) 1047void QOutputDev::drawContents ( QPainter *p, int clipx, int clipy, int clipw, int cliph )
1048{ 1048{
1049 if ( m_pixmap ) 1049 if ( m_pixmap )
1050 p-> drawPixmap ( clipx, clipy, *m_pixmap, clipx, clipy, clipw, cliph ); 1050 p-> drawPixmap ( clipx, clipy, *m_pixmap, clipx, clipy, clipw, cliph );
1051 else 1051 else
1052 p-> fillRect ( clipx, clipy, clipw, cliph, white ); 1052 p-> fillRect ( clipx, clipy, clipw, cliph, white );
1053} 1053}
diff --git a/scripts/kconfig/qconf.cc b/scripts/kconfig/qconf.cc
index 52419ad..0459caf 100644
--- a/scripts/kconfig/qconf.cc
+++ b/scripts/kconfig/qconf.cc
@@ -1,1304 +1,1304 @@
1/* 1/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0. 3 * Released under the terms of the GNU GPL v2.0.
4 */ 4 */
5 5
6#include <qapplication.h> 6#include <qapplication.h>
7#include <qmainwindow.h> 7#include <qmainwindow.h>
8#include <qtoolbar.h> 8#include <qtoolbar.h>
9#include <qvbox.h> 9#include <qvbox.h>
10#include <qsplitter.h> 10#include <qsplitter.h>
11#include <qlistview.h> 11#include <qlistview.h>
12#include <qtextview.h> 12#include <qtextview.h>
13#include <qlineedit.h> 13#include <qlineedit.h>
14#include <qmenubar.h> 14#include <qmenubar.h>
15#include <qmessagebox.h> 15#include <qmessagebox.h>
16#include <qaction.h> 16#include <qaction.h>
17#include <qheader.h> 17#include <qheader.h>
18#include <qfiledialog.h> 18#include <qfiledialog.h>
19#include <qregexp.h> 19#include <qregexp.h>
20#if QT_VERSION >= 300 20#if QT_VERSION >= 0x030000
21#include <qsettings.h> 21#include <qsettings.h>
22#endif 22#endif
23 23
24#include <stdlib.h> 24#include <stdlib.h>
25 25
26#include "lkc.h" 26#include "lkc.h"
27#include "qconf.h" 27#include "qconf.h"
28 28
29#include "qconf.moc" 29#include "qconf.moc"
30#include "images.c" 30#include "images.c"
31 31
32static QApplication *configApp; 32static QApplication *configApp;
33#if QT_VERSION >= 300 33#if QT_VERSION >= 0x030000
34static QSettings *configSettings; 34static QSettings *configSettings;
35#endif 35#endif
36 36
37/* 37/*
38 * update all the children of a menu entry 38 * update all the children of a menu entry
39 * removes/adds the entries from the parent widget as necessary 39 * removes/adds the entries from the parent widget as necessary
40 * 40 *
41 * parent: either the menu list widget or a menu entry widget 41 * parent: either the menu list widget or a menu entry widget
42 * menu: entry to be updated 42 * menu: entry to be updated
43 */ 43 */
44template <class P> 44template <class P>
45void ConfigList::updateMenuList(P* parent, struct menu* menu) 45void ConfigList::updateMenuList(P* parent, struct menu* menu)
46{ 46{
47 struct menu* child; 47 struct menu* child;
48 ConfigItem* item; 48 ConfigItem* item;
49 ConfigItem* last; 49 ConfigItem* last;
50 bool visible; 50 bool visible;
51 enum prop_type type; 51 enum prop_type type;
52 52
53 if (!menu) { 53 if (!menu) {
54 while ((item = parent->firstChild())) 54 while ((item = parent->firstChild()))
55 delete item; 55 delete item;
56 return; 56 return;
57 } 57 }
58 58
59 last = parent->firstChild(); 59 last = parent->firstChild();
60 if (last && !last->goParent) 60 if (last && !last->goParent)
61 last = 0; 61 last = 0;
62 for (child = menu->list; child; child = child->next) { 62 for (child = menu->list; child; child = child->next) {
63 item = last ? last->nextSibling() : parent->firstChild(); 63 item = last ? last->nextSibling() : parent->firstChild();
64 type = child->prompt ? child->prompt->type : P_UNKNOWN; 64 type = child->prompt ? child->prompt->type : P_UNKNOWN;
65 65
66 switch (mode) { 66 switch (mode) {
67 case menuMode: 67 case menuMode:
68 if (!(child->flags & MENU_ROOT)) 68 if (!(child->flags & MENU_ROOT))
69 goto hide; 69 goto hide;
70 break; 70 break;
71 case symbolMode: 71 case symbolMode:
72 if (child->flags & MENU_ROOT) 72 if (child->flags & MENU_ROOT)
73 goto hide; 73 goto hide;
74 break; 74 break;
75 default: 75 default:
76 break; 76 break;
77 } 77 }
78 78
79 visible = menu_is_visible(child); 79 visible = menu_is_visible(child);
80 if (showAll || visible) { 80 if (showAll || visible) {
81 if (!item || item->menu != child) 81 if (!item || item->menu != child)
82 item = new ConfigItem(parent, last, child, visible); 82 item = new ConfigItem(parent, last, child, visible);
83 else 83 else
84 item->testUpdateMenu(visible); 84 item->testUpdateMenu(visible);
85 85
86 if (mode == fullMode || mode == menuMode || type != P_MENU) 86 if (mode == fullMode || mode == menuMode || type != P_MENU)
87 updateMenuList(item, child); 87 updateMenuList(item, child);
88 else 88 else
89 updateMenuList(item, 0); 89 updateMenuList(item, 0);
90 last = item; 90 last = item;
91 continue; 91 continue;
92 } 92 }
93 hide: 93 hide:
94 if (item && item->menu == child) { 94 if (item && item->menu == child) {
95 last = parent->firstChild(); 95 last = parent->firstChild();
96 if (last == item) 96 if (last == item)
97 last = 0; 97 last = 0;
98 else while (last->nextSibling() != item) 98 else while (last->nextSibling() != item)
99 last = last->nextSibling(); 99 last = last->nextSibling();
100 delete item; 100 delete item;
101 } 101 }
102 } 102 }
103} 103}
104 104
105#if QT_VERSION >= 300 105#if QT_VERSION >= 0x030000
106/* 106/*
107 * set the new data 107 * set the new data
108 * TODO check the value 108 * TODO check the value
109 */ 109 */
110void ConfigItem::okRename(int col) 110void ConfigItem::okRename(int col)
111{ 111{
112 Parent::okRename(col); 112 Parent::okRename(col);
113 sym_set_string_value(menu->sym, text(dataColIdx).latin1()); 113 sym_set_string_value(menu->sym, text(dataColIdx).latin1());
114} 114}
115#endif 115#endif
116 116
117/* 117/*
118 * update the displayed of a menu entry 118 * update the displayed of a menu entry
119 */ 119 */
120void ConfigItem::updateMenu(void) 120void ConfigItem::updateMenu(void)
121{ 121{
122 ConfigList* list; 122 ConfigList* list;
123 struct symbol* sym; 123 struct symbol* sym;
124 struct property *prop; 124 struct property *prop;
125 QString prompt; 125 QString prompt;
126 int type; 126 int type;
127 tristate expr; 127 tristate expr;
128 128
129 list = listView(); 129 list = listView();
130 if (goParent) { 130 if (goParent) {
131 setPixmap(promptColIdx, list->menuBackPix); 131 setPixmap(promptColIdx, list->menuBackPix);
132 prompt = ".."; 132 prompt = "..";
133 goto set_prompt; 133 goto set_prompt;
134 } 134 }
135 135
136 sym = menu->sym; 136 sym = menu->sym;
137 prop = menu->prompt; 137 prop = menu->prompt;
138 prompt = menu_get_prompt(menu); 138 prompt = menu_get_prompt(menu);
139 139
140 if (prop) switch (prop->type) { 140 if (prop) switch (prop->type) {
141 case P_MENU: 141 case P_MENU:
142 if (list->mode == singleMode || list->mode == symbolMode) { 142 if (list->mode == singleMode || list->mode == symbolMode) {
143 /* a menuconfig entry is displayed differently 143 /* a menuconfig entry is displayed differently
144 * depending whether it's at the view root or a child. 144 * depending whether it's at the view root or a child.
145 */ 145 */
146 if (sym && list->rootEntry == menu) 146 if (sym && list->rootEntry == menu)
147 break; 147 break;
148 setPixmap(promptColIdx, list->menuPix); 148 setPixmap(promptColIdx, list->menuPix);
149 } else { 149 } else {
150 if (sym) 150 if (sym)
151 break; 151 break;
152 setPixmap(promptColIdx, 0); 152 setPixmap(promptColIdx, 0);
153 } 153 }
154 goto set_prompt; 154 goto set_prompt;
155 case P_COMMENT: 155 case P_COMMENT:
156 setPixmap(promptColIdx, 0); 156 setPixmap(promptColIdx, 0);
157 goto set_prompt; 157 goto set_prompt;
158 default: 158 default:
159 ; 159 ;
160 } 160 }
161 if (!sym) 161 if (!sym)
162 goto set_prompt; 162 goto set_prompt;
163 163
164 setText(nameColIdx, sym->name); 164 setText(nameColIdx, sym->name);
165 165
166 type = sym_get_type(sym); 166 type = sym_get_type(sym);
167 switch (type) { 167 switch (type) {
168 case S_BOOLEAN: 168 case S_BOOLEAN:
169 case S_TRISTATE: 169 case S_TRISTATE:
170 char ch; 170 char ch;
171 171
172 if (!sym_is_changable(sym) && !list->showAll) { 172 if (!sym_is_changable(sym) && !list->showAll) {
173 setPixmap(promptColIdx, 0); 173 setPixmap(promptColIdx, 0);
174 setText(noColIdx, 0); 174 setText(noColIdx, 0);
175 setText(modColIdx, 0); 175 setText(modColIdx, 0);
176 setText(yesColIdx, 0); 176 setText(yesColIdx, 0);
177 break; 177 break;
178 } 178 }
179 expr = sym_get_tristate_value(sym); 179 expr = sym_get_tristate_value(sym);
180 switch (expr) { 180 switch (expr) {
181 case yes: 181 case yes:
182 if (sym_is_choice_value(sym) && type == S_BOOLEAN) 182 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
183 setPixmap(promptColIdx, list->choiceYesPix); 183 setPixmap(promptColIdx, list->choiceYesPix);
184 else 184 else
185 setPixmap(promptColIdx, list->symbolYesPix); 185 setPixmap(promptColIdx, list->symbolYesPix);
186 setText(yesColIdx, "Y"); 186 setText(yesColIdx, "Y");
187 ch = 'Y'; 187 ch = 'Y';
188 break; 188 break;
189 case mod: 189 case mod:
190 setPixmap(promptColIdx, list->symbolModPix); 190 setPixmap(promptColIdx, list->symbolModPix);
191 setText(modColIdx, "M"); 191 setText(modColIdx, "M");
192 ch = 'M'; 192 ch = 'M';
193 break; 193 break;
194 default: 194 default:
195 if (sym_is_choice_value(sym) && type == S_BOOLEAN) 195 if (sym_is_choice_value(sym) && type == S_BOOLEAN)
196 setPixmap(promptColIdx, list->choiceNoPix); 196 setPixmap(promptColIdx, list->choiceNoPix);
197 else 197 else
198 setPixmap(promptColIdx, list->symbolNoPix); 198 setPixmap(promptColIdx, list->symbolNoPix);
199 setText(noColIdx, "N"); 199 setText(noColIdx, "N");
200 ch = 'N'; 200 ch = 'N';
201 break; 201 break;
202 } 202 }
203 if (expr != no) 203 if (expr != no)
204 setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0); 204 setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0);
205 if (expr != mod) 205 if (expr != mod)
206 setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0); 206 setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0);
207 if (expr != yes) 207 if (expr != yes)
208 setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0); 208 setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0);
209 209
210 setText(dataColIdx, QChar(ch)); 210 setText(dataColIdx, QChar(ch));
211 break; 211 break;
212 case S_INT: 212 case S_INT:
213 case S_HEX: 213 case S_HEX:
214 case S_STRING: 214 case S_STRING:
215 const char* data; 215 const char* data;
216 216
217 data = sym_get_string_value(sym); 217 data = sym_get_string_value(sym);
218#if QT_VERSION >= 300 218#if QT_VERSION >= 0x030000
219 int i = list->mapIdx(dataColIdx); 219 int i = list->mapIdx(dataColIdx);
220 if (i >= 0) 220 if (i >= 0)
221 setRenameEnabled(i, TRUE); 221 setRenameEnabled(i, TRUE);
222#endif 222#endif
223 setText(dataColIdx, data); 223 setText(dataColIdx, data);
224 if (type == S_STRING) 224 if (type == S_STRING)
225 prompt.sprintf("%s: %s", prompt.latin1(), data); 225 prompt.sprintf("%s: %s", prompt.latin1(), data);
226 else 226 else
227 prompt.sprintf("(%s) %s", data, prompt.latin1()); 227 prompt.sprintf("(%s) %s", data, prompt.latin1());
228 break; 228 break;
229 } 229 }
230 if (!sym_has_value(sym) && visible) 230 if (!sym_has_value(sym) && visible)
231 prompt += " (NEW)"; 231 prompt += " (NEW)";
232set_prompt: 232set_prompt:
233 setText(promptColIdx, prompt); 233 setText(promptColIdx, prompt);
234} 234}
235 235
236void ConfigItem::testUpdateMenu(bool v) 236void ConfigItem::testUpdateMenu(bool v)
237{ 237{
238 ConfigItem* i; 238 ConfigItem* i;
239 239
240 visible = v; 240 visible = v;
241 if (!menu) 241 if (!menu)
242 return; 242 return;
243 243
244 sym_calc_value(menu->sym); 244 sym_calc_value(menu->sym);
245 if (menu->flags & MENU_CHANGED) { 245 if (menu->flags & MENU_CHANGED) {
246 /* the menu entry changed, so update all list items */ 246 /* the menu entry changed, so update all list items */
247 menu->flags &= ~MENU_CHANGED; 247 menu->flags &= ~MENU_CHANGED;
248 for (i = (ConfigItem*)menu->data; i; i = i->nextItem) 248 for (i = (ConfigItem*)menu->data; i; i = i->nextItem)
249 i->updateMenu(); 249 i->updateMenu();
250 } else if (listView()->updateAll) 250 } else if (listView()->updateAll)
251 updateMenu(); 251 updateMenu();
252} 252}
253 253
254void ConfigItem::paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align) 254void ConfigItem::paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align)
255{ 255{
256 ConfigList* list = listView(); 256 ConfigList* list = listView();
257 257
258 if (visible) { 258 if (visible) {
259 if (isSelected() && !list->hasFocus() && list->mode == menuMode) 259 if (isSelected() && !list->hasFocus() && list->mode == menuMode)
260 Parent::paintCell(p, list->inactivedColorGroup, column, width, align); 260 Parent::paintCell(p, list->inactivedColorGroup, column, width, align);
261 else 261 else
262 Parent::paintCell(p, cg, column, width, align); 262 Parent::paintCell(p, cg, column, width, align);
263 } else 263 } else
264 Parent::paintCell(p, list->disabledColorGroup, column, width, align); 264 Parent::paintCell(p, list->disabledColorGroup, column, width, align);
265} 265}
266 266
267/* 267/*
268 * construct a menu entry 268 * construct a menu entry
269 */ 269 */
270void ConfigItem::init(void) 270void ConfigItem::init(void)
271{ 271{
272 if (menu) { 272 if (menu) {
273 ConfigList* list = listView(); 273 ConfigList* list = listView();
274 nextItem = (ConfigItem*)menu->data; 274 nextItem = (ConfigItem*)menu->data;
275 menu->data = this; 275 menu->data = this;
276 276
277 if (list->mode != fullMode) 277 if (list->mode != fullMode)
278 setOpen(TRUE); 278 setOpen(TRUE);
279 sym_calc_value(menu->sym); 279 sym_calc_value(menu->sym);
280 } 280 }
281 updateMenu(); 281 updateMenu();
282} 282}
283 283
284/* 284/*
285 * destruct a menu entry 285 * destruct a menu entry
286 */ 286 */
287ConfigItem::~ConfigItem(void) 287ConfigItem::~ConfigItem(void)
288{ 288{
289 if (menu) { 289 if (menu) {
290 ConfigItem** ip = (ConfigItem**)&menu->data; 290 ConfigItem** ip = (ConfigItem**)&menu->data;
291 for (; *ip; ip = &(*ip)->nextItem) { 291 for (; *ip; ip = &(*ip)->nextItem) {
292 if (*ip == this) { 292 if (*ip == this) {
293 *ip = nextItem; 293 *ip = nextItem;
294 break; 294 break;
295 } 295 }
296 } 296 }
297 } 297 }
298} 298}
299 299
300void ConfigLineEdit::show(ConfigItem* i) 300void ConfigLineEdit::show(ConfigItem* i)
301{ 301{
302 item = i; 302 item = i;
303 if (sym_get_string_value(item->menu->sym)) 303 if (sym_get_string_value(item->menu->sym))
304 setText(sym_get_string_value(item->menu->sym)); 304 setText(sym_get_string_value(item->menu->sym));
305 else 305 else
306 setText(0); 306 setText(0);
307 Parent::show(); 307 Parent::show();
308 setFocus(); 308 setFocus();
309} 309}
310 310
311void ConfigLineEdit::keyPressEvent(QKeyEvent* e) 311void ConfigLineEdit::keyPressEvent(QKeyEvent* e)
312{ 312{
313 switch (e->key()) { 313 switch (e->key()) {
314 case Key_Escape: 314 case Key_Escape:
315 break; 315 break;
316 case Key_Return: 316 case Key_Return:
317 case Key_Enter: 317 case Key_Enter:
318 sym_set_string_value(item->menu->sym, text().latin1()); 318 sym_set_string_value(item->menu->sym, text().latin1());
319 parent()->updateList(item); 319 parent()->updateList(item);
320 break; 320 break;
321 default: 321 default:
322 Parent::keyPressEvent(e); 322 Parent::keyPressEvent(e);
323 return; 323 return;
324 } 324 }
325 e->accept(); 325 e->accept();
326 parent()->list->setFocus(); 326 parent()->list->setFocus();
327 hide(); 327 hide();
328} 328}
329 329
330ConfigList::ConfigList(ConfigView* p, ConfigMainWindow* cv) 330ConfigList::ConfigList(ConfigView* p, ConfigMainWindow* cv)
331 : Parent(p), cview(cv), 331 : Parent(p), cview(cv),
332 updateAll(false), 332 updateAll(false),
333 symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no), 333 symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
334 choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no), 334 choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
335 menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void), 335 menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
336 showAll(false), showName(false), showRange(false), showData(false), 336 showAll(false), showName(false), showRange(false), showData(false),
337 rootEntry(0) 337 rootEntry(0)
338{ 338{
339 int i; 339 int i;
340 340
341 setSorting(-1); 341 setSorting(-1);
342 setRootIsDecorated(TRUE); 342 setRootIsDecorated(TRUE);
343 disabledColorGroup = palette().active(); 343 disabledColorGroup = palette().active();
344 disabledColorGroup.setColor(QColorGroup::Text, palette().disabled().text()); 344 disabledColorGroup.setColor(QColorGroup::Text, palette().disabled().text());
345 inactivedColorGroup = palette().active(); 345 inactivedColorGroup = palette().active();
346 inactivedColorGroup.setColor(QColorGroup::Highlight, palette().disabled().highlight()); 346 inactivedColorGroup.setColor(QColorGroup::Highlight, palette().disabled().highlight());
347 347
348 connect(this, SIGNAL(selectionChanged(void)), 348 connect(this, SIGNAL(selectionChanged(void)),
349 SLOT(updateSelection(void))); 349 SLOT(updateSelection(void)));
350 350
351 for (i = 0; i < colNr; i++) 351 for (i = 0; i < colNr; i++)
352 colMap[i] = colRevMap[i] = -1; 352 colMap[i] = colRevMap[i] = -1;
353 addColumn(promptColIdx, "Option"); 353 addColumn(promptColIdx, "Option");
354 354
355 reinit(); 355 reinit();
356} 356}
357 357
358void ConfigList::reinit(void) 358void ConfigList::reinit(void)
359{ 359{
360 removeColumn(dataColIdx); 360 removeColumn(dataColIdx);
361 removeColumn(yesColIdx); 361 removeColumn(yesColIdx);
362 removeColumn(modColIdx); 362 removeColumn(modColIdx);
363 removeColumn(noColIdx); 363 removeColumn(noColIdx);
364 removeColumn(nameColIdx); 364 removeColumn(nameColIdx);
365 365
366 if (showName) 366 if (showName)
367 addColumn(nameColIdx, "Name"); 367 addColumn(nameColIdx, "Name");
368 if (showRange) { 368 if (showRange) {
369 addColumn(noColIdx, "N"); 369 addColumn(noColIdx, "N");
370 addColumn(modColIdx, "M"); 370 addColumn(modColIdx, "M");
371 addColumn(yesColIdx, "Y"); 371 addColumn(yesColIdx, "Y");
372 } 372 }
373 if (showData) 373 if (showData)
374 addColumn(dataColIdx, "Value"); 374 addColumn(dataColIdx, "Value");
375 375
376 updateListAll(); 376 updateListAll();
377} 377}
378 378
379void ConfigList::updateSelection(void) 379void ConfigList::updateSelection(void)
380{ 380{
381 struct menu *menu; 381 struct menu *menu;
382 enum prop_type type; 382 enum prop_type type;
383 383
384 ConfigItem* item = (ConfigItem*)selectedItem(); 384 ConfigItem* item = (ConfigItem*)selectedItem();
385 if (!item) 385 if (!item)
386 return; 386 return;
387 387
388 cview->setHelp(item); 388 cview->setHelp(item);
389 389
390 menu = item->menu; 390 menu = item->menu;
391 if (!menu) 391 if (!menu)
392 return; 392 return;
393 type = menu->prompt ? menu->prompt->type : P_UNKNOWN; 393 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
394 if (mode == menuMode && type == P_MENU) 394 if (mode == menuMode && type == P_MENU)
395 emit menuSelected(menu); 395 emit menuSelected(menu);
396} 396}
397 397
398void ConfigList::updateList(ConfigItem* item) 398void ConfigList::updateList(ConfigItem* item)
399{ 399{
400 ConfigItem* last = 0; 400 ConfigItem* last = 0;
401 401
402 if (!rootEntry) 402 if (!rootEntry)
403 goto update; 403 goto update;
404 404
405 if (rootEntry != &rootmenu && (mode == singleMode || 405 if (rootEntry != &rootmenu && (mode == singleMode ||
406 (mode == symbolMode && rootEntry->parent != &rootmenu))) { 406 (mode == symbolMode && rootEntry->parent != &rootmenu))) {
407 item = firstChild(); 407 item = firstChild();
408 if (!item) 408 if (!item)
409 item = new ConfigItem(this, 0, true); 409 item = new ConfigItem(this, 0, true);
410 last = item; 410 last = item;
411 } 411 }
412 if (mode == singleMode && rootEntry->sym && rootEntry->prompt) { 412 if (mode == singleMode && rootEntry->sym && rootEntry->prompt) {
413 item = last ? last->nextSibling() : firstChild(); 413 item = last ? last->nextSibling() : firstChild();
414 if (!item) 414 if (!item)
415 item = new ConfigItem(this, last, rootEntry, true); 415 item = new ConfigItem(this, last, rootEntry, true);
416 416
417 updateMenuList(item, rootEntry); 417 updateMenuList(item, rootEntry);
418 triggerUpdate(); 418 triggerUpdate();
419 return; 419 return;
420 } 420 }
421update: 421update:
422 updateMenuList(this, rootEntry); 422 updateMenuList(this, rootEntry);
423 triggerUpdate(); 423 triggerUpdate();
424} 424}
425 425
426void ConfigList::setAllOpen(bool open) 426void ConfigList::setAllOpen(bool open)
427{ 427{
428 QListViewItemIterator it(this); 428 QListViewItemIterator it(this);
429 429
430 for (; it.current(); it++) 430 for (; it.current(); it++)
431 it.current()->setOpen(open); 431 it.current()->setOpen(open);
432} 432}
433 433
434void ConfigList::setValue(ConfigItem* item, tristate val) 434void ConfigList::setValue(ConfigItem* item, tristate val)
435{ 435{
436 struct symbol* sym; 436 struct symbol* sym;
437 int type; 437 int type;
438 tristate oldval; 438 tristate oldval;
439 439
440 sym = item->menu ? item->menu->sym : 0; 440 sym = item->menu ? item->menu->sym : 0;
441 if (!sym) 441 if (!sym)
442 return; 442 return;
443 443
444 type = sym_get_type(sym); 444 type = sym_get_type(sym);
445 switch (type) { 445 switch (type) {
446 case S_BOOLEAN: 446 case S_BOOLEAN:
447 case S_TRISTATE: 447 case S_TRISTATE:
448 oldval = sym_get_tristate_value(sym); 448 oldval = sym_get_tristate_value(sym);
449 449
450 if (!sym_set_tristate_value(sym, val)) 450 if (!sym_set_tristate_value(sym, val))
451 return; 451 return;
452 if (oldval == no && item->menu->list) 452 if (oldval == no && item->menu->list)
453 item->setOpen(TRUE); 453 item->setOpen(TRUE);
454 parent()->updateList(item); 454 parent()->updateList(item);
455 break; 455 break;
456 } 456 }
457} 457}
458 458
459void ConfigList::changeValue(ConfigItem* item) 459void ConfigList::changeValue(ConfigItem* item)
460{ 460{
461 struct symbol* sym; 461 struct symbol* sym;
462 struct menu* menu; 462 struct menu* menu;
463 int type, oldexpr, newexpr; 463 int type, oldexpr, newexpr;
464 464
465 menu = item->menu; 465 menu = item->menu;
466 if (!menu) 466 if (!menu)
467 return; 467 return;
468 sym = menu->sym; 468 sym = menu->sym;
469 if (!sym) { 469 if (!sym) {
470 if (item->menu->list) 470 if (item->menu->list)
471 item->setOpen(!item->isOpen()); 471 item->setOpen(!item->isOpen());
472 return; 472 return;
473 } 473 }
474 474
475 type = sym_get_type(sym); 475 type = sym_get_type(sym);
476 switch (type) { 476 switch (type) {
477 case S_BOOLEAN: 477 case S_BOOLEAN:
478 case S_TRISTATE: 478 case S_TRISTATE:
479 oldexpr = sym_get_tristate_value(sym); 479 oldexpr = sym_get_tristate_value(sym);
480 newexpr = sym_toggle_tristate_value(sym); 480 newexpr = sym_toggle_tristate_value(sym);
481 if (item->menu->list) { 481 if (item->menu->list) {
482 if (oldexpr == newexpr) 482 if (oldexpr == newexpr)
483 item->setOpen(!item->isOpen()); 483 item->setOpen(!item->isOpen());
484 else if (oldexpr == no) 484 else if (oldexpr == no)
485 item->setOpen(TRUE); 485 item->setOpen(TRUE);
486 } 486 }
487 if (oldexpr != newexpr) 487 if (oldexpr != newexpr)
488 parent()->updateList(item); 488 parent()->updateList(item);
489 break; 489 break;
490 case S_INT: 490 case S_INT:
491 case S_HEX: 491 case S_HEX:
492 case S_STRING: 492 case S_STRING:
493#if QT_VERSION >= 300 493#if QT_VERSION >= 0x030000
494 if (colMap[dataColIdx] >= 0) 494 if (colMap[dataColIdx] >= 0)
495 item->startRename(colMap[dataColIdx]); 495 item->startRename(colMap[dataColIdx]);
496 else 496 else
497#endif 497#endif
498 parent()->lineEdit->show(item); 498 parent()->lineEdit->show(item);
499 break; 499 break;
500 } 500 }
501} 501}
502 502
503void ConfigList::setRootMenu(struct menu *menu) 503void ConfigList::setRootMenu(struct menu *menu)
504{ 504{
505 enum prop_type type; 505 enum prop_type type;
506 506
507 if (rootEntry == menu) 507 if (rootEntry == menu)
508 return; 508 return;
509 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN; 509 type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN;
510 if (type != P_MENU) 510 if (type != P_MENU)
511 return; 511 return;
512 updateMenuList(this, 0); 512 updateMenuList(this, 0);
513 rootEntry = menu; 513 rootEntry = menu;
514 updateListAll(); 514 updateListAll();
515 setSelected(currentItem(), hasFocus()); 515 setSelected(currentItem(), hasFocus());
516} 516}
517 517
518void ConfigList::setParentMenu(void) 518void ConfigList::setParentMenu(void)
519{ 519{
520 ConfigItem* item; 520 ConfigItem* item;
521 struct menu *oldroot; 521 struct menu *oldroot;
522 522
523 oldroot = rootEntry; 523 oldroot = rootEntry;
524 if (rootEntry == &rootmenu) 524 if (rootEntry == &rootmenu)
525 return; 525 return;
526 setRootMenu(menu_get_parent_menu(rootEntry->parent)); 526 setRootMenu(menu_get_parent_menu(rootEntry->parent));
527 527
528 QListViewItemIterator it(this); 528 QListViewItemIterator it(this);
529 for (; (item = (ConfigItem*)it.current()); it++) { 529 for (; (item = (ConfigItem*)it.current()); it++) {
530 if (item->menu == oldroot) { 530 if (item->menu == oldroot) {
531 setCurrentItem(item); 531 setCurrentItem(item);
532 ensureItemVisible(item); 532 ensureItemVisible(item);
533 break; 533 break;
534 } 534 }
535 } 535 }
536} 536}
537 537
538void ConfigList::keyPressEvent(QKeyEvent* ev) 538void ConfigList::keyPressEvent(QKeyEvent* ev)
539{ 539{
540 QListViewItem* i = currentItem(); 540 QListViewItem* i = currentItem();
541 ConfigItem* item; 541 ConfigItem* item;
542 struct menu *menu; 542 struct menu *menu;
543 enum prop_type type; 543 enum prop_type type;
544 544
545 if (ev->key() == Key_Escape && mode != fullMode) { 545 if (ev->key() == Key_Escape && mode != fullMode) {
546 emit parentSelected(); 546 emit parentSelected();
547 ev->accept(); 547 ev->accept();
548 return; 548 return;
549 } 549 }
550 550
551 if (!i) { 551 if (!i) {
552 Parent::keyPressEvent(ev); 552 Parent::keyPressEvent(ev);
553 return; 553 return;
554 } 554 }
555 item = (ConfigItem*)i; 555 item = (ConfigItem*)i;
556 556
557 switch (ev->key()) { 557 switch (ev->key()) {
558 case Key_Return: 558 case Key_Return:
559 case Key_Enter: 559 case Key_Enter:
560 if (item->goParent) { 560 if (item->goParent) {
561 emit parentSelected(); 561 emit parentSelected();
562 break; 562 break;
563 } 563 }
564 menu = item->menu; 564 menu = item->menu;
565 if (!menu) 565 if (!menu)
566 break; 566 break;
567 type = menu->prompt ? menu->prompt->type : P_UNKNOWN; 567 type = menu->prompt ? menu->prompt->type : P_UNKNOWN;
568 if (type == P_MENU && rootEntry != menu && 568 if (type == P_MENU && rootEntry != menu &&
569 mode != fullMode && mode != menuMode) { 569 mode != fullMode && mode != menuMode) {
570 emit menuSelected(menu); 570 emit menuSelected(menu);
571 break; 571 break;
572 } 572 }
573 case Key_Space: 573 case Key_Space:
574 changeValue(item); 574 changeValue(item);
575 break; 575 break;
576 case Key_N: 576 case Key_N:
577 setValue(item, no); 577 setValue(item, no);
578 break; 578 break;
579 case Key_M: 579 case Key_M:
580 setValue(item, mod); 580 setValue(item, mod);
581 break; 581 break;
582 case Key_Y: 582 case Key_Y:
583 setValue(item, yes); 583 setValue(item, yes);
584 break; 584 break;
585 default: 585 default:
586 Parent::keyPressEvent(ev); 586 Parent::keyPressEvent(ev);
587 return; 587 return;
588 } 588 }
589 ev->accept(); 589 ev->accept();
590} 590}
591 591
592void ConfigList::contentsMousePressEvent(QMouseEvent* e) 592void ConfigList::contentsMousePressEvent(QMouseEvent* e)
593{ 593{
594 //QPoint p(contentsToViewport(e->pos())); 594 //QPoint p(contentsToViewport(e->pos()));
595 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y()); 595 //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y());
596 Parent::contentsMousePressEvent(e); 596 Parent::contentsMousePressEvent(e);
597} 597}
598 598
599void ConfigList::contentsMouseReleaseEvent(QMouseEvent* e) 599void ConfigList::contentsMouseReleaseEvent(QMouseEvent* e)
600{ 600{
601 QPoint p(contentsToViewport(e->pos())); 601 QPoint p(contentsToViewport(e->pos()));
602 ConfigItem* item = (ConfigItem*)itemAt(p); 602 ConfigItem* item = (ConfigItem*)itemAt(p);
603 struct menu *menu; 603 struct menu *menu;
604 enum prop_type ptype; 604 enum prop_type ptype;
605 const QPixmap* pm; 605 const QPixmap* pm;
606 int idx, x; 606 int idx, x;
607 607
608 if (!item) 608 if (!item)
609 goto skip; 609 goto skip;
610 610
611 menu = item->menu; 611 menu = item->menu;
612 x = header()->offset() + p.x(); 612 x = header()->offset() + p.x();
613 idx = colRevMap[header()->sectionAt(x)]; 613 idx = colRevMap[header()->sectionAt(x)];
614 switch (idx) { 614 switch (idx) {
615 case promptColIdx: 615 case promptColIdx:
616 pm = item->pixmap(promptColIdx); 616 pm = item->pixmap(promptColIdx);
617 if (pm) { 617 if (pm) {
618 int off = header()->sectionPos(0) + itemMargin() + 618 int off = header()->sectionPos(0) + itemMargin() +
619 treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0)); 619 treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0));
620 if (x >= off && x < off + pm->width()) { 620 if (x >= off && x < off + pm->width()) {
621 if (item->goParent) { 621 if (item->goParent) {
622 emit parentSelected(); 622 emit parentSelected();
623 break; 623 break;
624 } else if (!menu) 624 } else if (!menu)
625 break; 625 break;
626 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN; 626 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
627 if (ptype == P_MENU && rootEntry != menu && 627 if (ptype == P_MENU && rootEntry != menu &&
628 mode != fullMode && mode != menuMode) 628 mode != fullMode && mode != menuMode)
629 emit menuSelected(menu); 629 emit menuSelected(menu);
630 else 630 else
631 changeValue(item); 631 changeValue(item);
632 } 632 }
633 } 633 }
634 break; 634 break;
635 case noColIdx: 635 case noColIdx:
636 setValue(item, no); 636 setValue(item, no);
637 break; 637 break;
638 case modColIdx: 638 case modColIdx:
639 setValue(item, mod); 639 setValue(item, mod);
640 break; 640 break;
641 case yesColIdx: 641 case yesColIdx:
642 setValue(item, yes); 642 setValue(item, yes);
643 break; 643 break;
644 case dataColIdx: 644 case dataColIdx:
645 changeValue(item); 645 changeValue(item);
646 break; 646 break;
647 } 647 }
648 648
649skip: 649skip:
650 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y()); 650 //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y());
651 Parent::contentsMouseReleaseEvent(e); 651 Parent::contentsMouseReleaseEvent(e);
652} 652}
653 653
654void ConfigList::contentsMouseMoveEvent(QMouseEvent* e) 654void ConfigList::contentsMouseMoveEvent(QMouseEvent* e)
655{ 655{
656 //QPoint p(contentsToViewport(e->pos())); 656 //QPoint p(contentsToViewport(e->pos()));
657 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y()); 657 //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y());
658 Parent::contentsMouseMoveEvent(e); 658 Parent::contentsMouseMoveEvent(e);
659} 659}
660 660
661void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent* e) 661void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent* e)
662{ 662{
663 QPoint p(contentsToViewport(e->pos())); 663 QPoint p(contentsToViewport(e->pos()));
664 ConfigItem* item = (ConfigItem*)itemAt(p); 664 ConfigItem* item = (ConfigItem*)itemAt(p);
665 struct menu *menu; 665 struct menu *menu;
666 enum prop_type ptype; 666 enum prop_type ptype;
667 667
668 if (!item) 668 if (!item)
669 goto skip; 669 goto skip;
670 if (item->goParent) { 670 if (item->goParent) {
671 emit parentSelected(); 671 emit parentSelected();
672 goto skip; 672 goto skip;
673 } 673 }
674 menu = item->menu; 674 menu = item->menu;
675 if (!menu) 675 if (!menu)
676 goto skip; 676 goto skip;
677 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN; 677 ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
678 if (ptype == P_MENU && (mode == singleMode || mode == symbolMode)) 678 if (ptype == P_MENU && (mode == singleMode || mode == symbolMode))
679 emit menuSelected(menu); 679 emit menuSelected(menu);
680 else if (menu->sym) 680 else if (menu->sym)
681 changeValue(item); 681 changeValue(item);
682 682
683skip: 683skip:
684 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y()); 684 //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y());
685 Parent::contentsMouseDoubleClickEvent(e); 685 Parent::contentsMouseDoubleClickEvent(e);
686} 686}
687 687
688void ConfigList::focusInEvent(QFocusEvent *e) 688void ConfigList::focusInEvent(QFocusEvent *e)
689{ 689{
690 Parent::focusInEvent(e); 690 Parent::focusInEvent(e);
691 691
692 QListViewItem* item = currentItem(); 692 QListViewItem* item = currentItem();
693 if (!item) 693 if (!item)
694 return; 694 return;
695 695
696 setSelected(item, TRUE); 696 setSelected(item, TRUE);
697 emit gotFocus(); 697 emit gotFocus();
698} 698}
699 699
700ConfigView* ConfigView::viewList; 700ConfigView* ConfigView::viewList;
701 701
702ConfigView::ConfigView(QWidget* parent, ConfigMainWindow* cview) 702ConfigView::ConfigView(QWidget* parent, ConfigMainWindow* cview)
703 : Parent(parent) 703 : Parent(parent)
704{ 704{
705 list = new ConfigList(this, cview); 705 list = new ConfigList(this, cview);
706 lineEdit = new ConfigLineEdit(this); 706 lineEdit = new ConfigLineEdit(this);
707 lineEdit->hide(); 707 lineEdit->hide();
708 708
709 this->nextView = viewList; 709 this->nextView = viewList;
710 viewList = this; 710 viewList = this;
711} 711}
712 712
713ConfigView::~ConfigView(void) 713ConfigView::~ConfigView(void)
714{ 714{
715 ConfigView** vp; 715 ConfigView** vp;
716 716
717 for (vp = &viewList; *vp; vp = &(*vp)->nextView) { 717 for (vp = &viewList; *vp; vp = &(*vp)->nextView) {
718 if (*vp == this) { 718 if (*vp == this) {
719 *vp = nextView; 719 *vp = nextView;
720 break; 720 break;
721 } 721 }
722 } 722 }
723} 723}
724 724
725void ConfigView::updateList(ConfigItem* item) 725void ConfigView::updateList(ConfigItem* item)
726{ 726{
727 ConfigView* v; 727 ConfigView* v;
728 728
729 for (v = viewList; v; v = v->nextView) 729 for (v = viewList; v; v = v->nextView)
730 v->list->updateList(item); 730 v->list->updateList(item);
731} 731}
732 732
733void ConfigView::updateListAll(void) 733void ConfigView::updateListAll(void)
734{ 734{
735 ConfigView* v; 735 ConfigView* v;
736 736
737 for (v = viewList; v; v = v->nextView) 737 for (v = viewList; v; v = v->nextView)
738 v->list->updateListAll(); 738 v->list->updateListAll();
739} 739}
740 740
741/* 741/*
742 * Construct the complete config widget 742 * Construct the complete config widget
743 */ 743 */
744ConfigMainWindow::ConfigMainWindow(void) 744ConfigMainWindow::ConfigMainWindow(void)
745{ 745{
746 QMenuBar* menu; 746 QMenuBar* menu;
747 QSplitter* split1; 747 QSplitter* split1;
748 QSplitter* split2; 748 QSplitter* split2;
749 bool ok; 749 bool ok;
750 int x, y, width, height; 750 int x, y, width, height;
751 751
752 QWidget *d = configApp->desktop(); 752 QWidget *d = configApp->desktop();
753 753
754#if QT_VERSION >= 300 754#if QT_VERSION >= 0x030000
755 width = configSettings->readNumEntry("/kconfig/qconf/window width", d->width() - 64); 755 width = configSettings->readNumEntry("/kconfig/qconf/window width", d->width() - 64);
756 height = configSettings->readNumEntry("/kconfig/qconf/window height", d->height() - 64); 756 height = configSettings->readNumEntry("/kconfig/qconf/window height", d->height() - 64);
757 resize(width, height); 757 resize(width, height);
758 x = configSettings->readNumEntry("/kconfig/qconf/window x", 0, &ok); 758 x = configSettings->readNumEntry("/kconfig/qconf/window x", 0, &ok);
759 if (ok) 759 if (ok)
760 y = configSettings->readNumEntry("/kconfig/qconf/window y", 0, &ok); 760 y = configSettings->readNumEntry("/kconfig/qconf/window y", 0, &ok);
761 if (ok) 761 if (ok)
762 move(x, y); 762 move(x, y);
763#else 763#else
764 width = d->width() - 64; 764 width = d->width() - 64;
765 height = d->height() - 64; 765 height = d->height() - 64;
766 resize(width, height); 766 resize(width, height);
767#endif 767#endif
768 768
769 showDebug = false; 769 showDebug = false;
770 770
771 split1 = new QSplitter(this); 771 split1 = new QSplitter(this);
772 split1->setOrientation(QSplitter::Horizontal); 772 split1->setOrientation(QSplitter::Horizontal);
773 setCentralWidget(split1); 773 setCentralWidget(split1);
774 774
775 menuView = new ConfigView(split1, this); 775 menuView = new ConfigView(split1, this);
776 menuList = menuView->list; 776 menuList = menuView->list;
777 777
778 split2 = new QSplitter(split1); 778 split2 = new QSplitter(split1);
779 split2->setOrientation(QSplitter::Vertical); 779 split2->setOrientation(QSplitter::Vertical);
780 780
781 // create config tree 781 // create config tree
782 configView = new ConfigView(split2, this); 782 configView = new ConfigView(split2, this);
783 configList = configView->list; 783 configList = configView->list;
784 784
785 helpText = new QTextView(split2); 785 helpText = new QTextView(split2);
786 helpText->setTextFormat(Qt::RichText); 786 helpText->setTextFormat(Qt::RichText);
787 787
788 setTabOrder(configList, helpText); 788 setTabOrder(configList, helpText);
789 configList->setFocus(); 789 configList->setFocus();
790 790
791 menu = menuBar(); 791 menu = menuBar();
792 toolBar = new QToolBar("Tools", this); 792 toolBar = new QToolBar("Tools", this);
793 793
794 backAction = new QAction("Back", QPixmap(xpm_back), "Back", 0, this); 794 backAction = new QAction("Back", QPixmap(xpm_back), "Back", 0, this);
795 connect(backAction, SIGNAL(activated()), SLOT(goBack())); 795 connect(backAction, SIGNAL(activated()), SLOT(goBack()));
796 backAction->setEnabled(FALSE); 796 backAction->setEnabled(FALSE);
797 QAction *quitAction = new QAction("Quit", "&Quit", CTRL+Key_Q, this); 797 QAction *quitAction = new QAction("Quit", "&Quit", CTRL+Key_Q, this);
798 connect(quitAction, SIGNAL(activated()), SLOT(close())); 798 connect(quitAction, SIGNAL(activated()), SLOT(close()));
799 QAction *loadAction = new QAction("Load", QPixmap(xpm_load), "&Load", CTRL+Key_L, this); 799 QAction *loadAction = new QAction("Load", QPixmap(xpm_load), "&Load", CTRL+Key_L, this);
800 connect(loadAction, SIGNAL(activated()), SLOT(loadConfig())); 800 connect(loadAction, SIGNAL(activated()), SLOT(loadConfig()));
801 QAction *saveAction = new QAction("Save", QPixmap(xpm_save), "&Save", CTRL+Key_S, this); 801 QAction *saveAction = new QAction("Save", QPixmap(xpm_save), "&Save", CTRL+Key_S, this);
802 connect(saveAction, SIGNAL(activated()), SLOT(saveConfig())); 802 connect(saveAction, SIGNAL(activated()), SLOT(saveConfig()));
803 QAction *saveAsAction = new QAction("Save As...", "Save &As...", 0, this); 803 QAction *saveAsAction = new QAction("Save As...", "Save &As...", 0, this);
804 connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs())); 804 connect(saveAsAction, SIGNAL(activated()), SLOT(saveConfigAs()));
805 QAction *singleViewAction = new QAction("Single View", QPixmap(xpm_single_view), "Split View", 0, this); 805 QAction *singleViewAction = new QAction("Single View", QPixmap(xpm_single_view), "Split View", 0, this);
806 connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView())); 806 connect(singleViewAction, SIGNAL(activated()), SLOT(showSingleView()));
807 QAction *splitViewAction = new QAction("Split View", QPixmap(xpm_split_view), "Split View", 0, this); 807 QAction *splitViewAction = new QAction("Split View", QPixmap(xpm_split_view), "Split View", 0, this);
808 connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView())); 808 connect(splitViewAction, SIGNAL(activated()), SLOT(showSplitView()));
809 QAction *fullViewAction = new QAction("Full View", QPixmap(xpm_tree_view), "Full View", 0, this); 809 QAction *fullViewAction = new QAction("Full View", QPixmap(xpm_tree_view), "Full View", 0, this);
810 connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView())); 810 connect(fullViewAction, SIGNAL(activated()), SLOT(showFullView()));
811 811
812 QAction *showNameAction = new QAction(NULL, "Show Name", 0, this); 812 QAction *showNameAction = new QAction(NULL, "Show Name", 0, this);
813 showNameAction->setToggleAction(TRUE); 813 showNameAction->setToggleAction(TRUE);
814 showNameAction->setOn(configList->showName); 814 showNameAction->setOn(configList->showName);
815 connect(showNameAction, SIGNAL(toggled(bool)), SLOT(setShowName(bool))); 815 connect(showNameAction, SIGNAL(toggled(bool)), SLOT(setShowName(bool)));
816 QAction *showRangeAction = new QAction(NULL, "Show Range", 0, this); 816 QAction *showRangeAction = new QAction(NULL, "Show Range", 0, this);
817 showRangeAction->setToggleAction(TRUE); 817 showRangeAction->setToggleAction(TRUE);
818 showRangeAction->setOn(configList->showRange); 818 showRangeAction->setOn(configList->showRange);
819 connect(showRangeAction, SIGNAL(toggled(bool)), SLOT(setShowRange(bool))); 819 connect(showRangeAction, SIGNAL(toggled(bool)), SLOT(setShowRange(bool)));
820 QAction *showDataAction = new QAction(NULL, "Show Data", 0, this); 820 QAction *showDataAction = new QAction(NULL, "Show Data", 0, this);
821 showDataAction->setToggleAction(TRUE); 821 showDataAction->setToggleAction(TRUE);
822 showDataAction->setOn(configList->showData); 822 showDataAction->setOn(configList->showData);
823 connect(showDataAction, SIGNAL(toggled(bool)), SLOT(setShowData(bool))); 823 connect(showDataAction, SIGNAL(toggled(bool)), SLOT(setShowData(bool)));
824 QAction *showAllAction = new QAction(NULL, "Show All Options", 0, this); 824 QAction *showAllAction = new QAction(NULL, "Show All Options", 0, this);
825 showAllAction->setToggleAction(TRUE); 825 showAllAction->setToggleAction(TRUE);
826 showAllAction->setOn(configList->showAll); 826 showAllAction->setOn(configList->showAll);
827 connect(showAllAction, SIGNAL(toggled(bool)), SLOT(setShowAll(bool))); 827 connect(showAllAction, SIGNAL(toggled(bool)), SLOT(setShowAll(bool)));
828 QAction *showDebugAction = new QAction(NULL, "Show Debug Info", 0, this); 828 QAction *showDebugAction = new QAction(NULL, "Show Debug Info", 0, this);
829 showDebugAction->setToggleAction(TRUE); 829 showDebugAction->setToggleAction(TRUE);
830 showDebugAction->setOn(showDebug); 830 showDebugAction->setOn(showDebug);
831 connect(showDebugAction, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool))); 831 connect(showDebugAction, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
832 832
833 QAction *showIntroAction = new QAction(NULL, "Introduction", 0, this); 833 QAction *showIntroAction = new QAction(NULL, "Introduction", 0, this);
834 connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro())); 834 connect(showIntroAction, SIGNAL(activated()), SLOT(showIntro()));
835 QAction *showAboutAction = new QAction(NULL, "About", 0, this); 835 QAction *showAboutAction = new QAction(NULL, "About", 0, this);
836 connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout())); 836 connect(showAboutAction, SIGNAL(activated()), SLOT(showAbout()));
837 837
838 // init tool bar 838 // init tool bar
839 backAction->addTo(toolBar); 839 backAction->addTo(toolBar);
840 toolBar->addSeparator(); 840 toolBar->addSeparator();
841 loadAction->addTo(toolBar); 841 loadAction->addTo(toolBar);
842 saveAction->addTo(toolBar); 842 saveAction->addTo(toolBar);
843 toolBar->addSeparator(); 843 toolBar->addSeparator();
844 singleViewAction->addTo(toolBar); 844 singleViewAction->addTo(toolBar);
845 splitViewAction->addTo(toolBar); 845 splitViewAction->addTo(toolBar);
846 fullViewAction->addTo(toolBar); 846 fullViewAction->addTo(toolBar);
847 847
848 // create config menu 848 // create config menu
849 QPopupMenu* config = new QPopupMenu(this); 849 QPopupMenu* config = new QPopupMenu(this);
850 menu->insertItem("&File", config); 850 menu->insertItem("&File", config);
851 loadAction->addTo(config); 851 loadAction->addTo(config);
852 saveAction->addTo(config); 852 saveAction->addTo(config);
853 saveAsAction->addTo(config); 853 saveAsAction->addTo(config);
854 config->insertSeparator(); 854 config->insertSeparator();
855 quitAction->addTo(config); 855 quitAction->addTo(config);
856 856
857 // create options menu 857 // create options menu
858 QPopupMenu* optionMenu = new QPopupMenu(this); 858 QPopupMenu* optionMenu = new QPopupMenu(this);
859 menu->insertItem("&Option", optionMenu); 859 menu->insertItem("&Option", optionMenu);
860 showNameAction->addTo(optionMenu); 860 showNameAction->addTo(optionMenu);
861 showRangeAction->addTo(optionMenu); 861 showRangeAction->addTo(optionMenu);
862 showDataAction->addTo(optionMenu); 862 showDataAction->addTo(optionMenu);
863 optionMenu->insertSeparator(); 863 optionMenu->insertSeparator();
864 showAllAction->addTo(optionMenu); 864 showAllAction->addTo(optionMenu);
865 showDebugAction->addTo(optionMenu); 865 showDebugAction->addTo(optionMenu);
866 866
867 // create help menu 867 // create help menu
868 QPopupMenu* helpMenu = new QPopupMenu(this); 868 QPopupMenu* helpMenu = new QPopupMenu(this);
869 menu->insertSeparator(); 869 menu->insertSeparator();
870 menu->insertItem("&Help", helpMenu); 870 menu->insertItem("&Help", helpMenu);
871 showIntroAction->addTo(helpMenu); 871 showIntroAction->addTo(helpMenu);
872 showAboutAction->addTo(helpMenu); 872 showAboutAction->addTo(helpMenu);
873 873
874 connect(configList, SIGNAL(menuSelected(struct menu *)), 874 connect(configList, SIGNAL(menuSelected(struct menu *)),
875 SLOT(changeMenu(struct menu *))); 875 SLOT(changeMenu(struct menu *)));
876 connect(configList, SIGNAL(parentSelected()), 876 connect(configList, SIGNAL(parentSelected()),
877 SLOT(goBack())); 877 SLOT(goBack()));
878 connect(menuList, SIGNAL(menuSelected(struct menu *)), 878 connect(menuList, SIGNAL(menuSelected(struct menu *)),
879 SLOT(changeMenu(struct menu *))); 879 SLOT(changeMenu(struct menu *)));
880 880
881 connect(configList, SIGNAL(gotFocus(void)), 881 connect(configList, SIGNAL(gotFocus(void)),
882 SLOT(listFocusChanged(void))); 882 SLOT(listFocusChanged(void)));
883 connect(menuList, SIGNAL(gotFocus(void)), 883 connect(menuList, SIGNAL(gotFocus(void)),
884 SLOT(listFocusChanged(void))); 884 SLOT(listFocusChanged(void)));
885 885
886 showSplitView(); 886 showSplitView();
887} 887}
888 888
889static QString print_filter(const char *str) 889static QString print_filter(const char *str)
890{ 890{
891 QRegExp re("[<>&\"\\n]"); 891 QRegExp re("[<>&\"\\n]");
892 QString res = str; 892 QString res = str;
893 for (int i = 0; (i = res.find(re, i)) >= 0;) { 893 for (int i = 0; (i = res.find(re, i)) >= 0;) {
894 switch (res[i].latin1()) { 894 switch (res[i].latin1()) {
895 case '<': 895 case '<':
896 res.replace(i, 1, "&lt;"); 896 res.replace(i, 1, "&lt;");
897 i += 4; 897 i += 4;
898 break; 898 break;
899 case '>': 899 case '>':
900 res.replace(i, 1, "&gt;"); 900 res.replace(i, 1, "&gt;");
901 i += 4; 901 i += 4;
902 break; 902 break;
903 case '&': 903 case '&':
904 res.replace(i, 1, "&amp;"); 904 res.replace(i, 1, "&amp;");
905 i += 5; 905 i += 5;
906 break; 906 break;
907 case '"': 907 case '"':
908 res.replace(i, 1, "&quot;"); 908 res.replace(i, 1, "&quot;");
909 i += 6; 909 i += 6;
910 break; 910 break;
911 case '\n': 911 case '\n':
912 res.replace(i, 1, "<br>"); 912 res.replace(i, 1, "<br>");
913 i += 4; 913 i += 4;
914 break; 914 break;
915 } 915 }
916 } 916 }
917 return res; 917 return res;
918} 918}
919 919
920static void expr_print_help(void *data, const char *str) 920static void expr_print_help(void *data, const char *str)
921{ 921{
922 ((QString*)data)->append(print_filter(str)); 922 ((QString*)data)->append(print_filter(str));
923} 923}
924 924
925/* 925/*
926 * display a new help entry as soon as a new menu entry is selected 926 * display a new help entry as soon as a new menu entry is selected
927 */ 927 */
928void ConfigMainWindow::setHelp(QListViewItem* item) 928void ConfigMainWindow::setHelp(QListViewItem* item)
929{ 929{
930 struct symbol* sym; 930 struct symbol* sym;
931 struct menu* menu = 0; 931 struct menu* menu = 0;
932 932
933 configList->parent()->lineEdit->hide(); 933 configList->parent()->lineEdit->hide();
934 if (item) 934 if (item)
935 menu = ((ConfigItem*)item)->menu; 935 menu = ((ConfigItem*)item)->menu;
936 if (!menu) { 936 if (!menu) {
937 helpText->setText(NULL); 937 helpText->setText(NULL);
938 return; 938 return;
939 } 939 }
940 940
941 QString head, debug, help; 941 QString head, debug, help;
942 menu = ((ConfigItem*)item)->menu; 942 menu = ((ConfigItem*)item)->menu;
943 sym = menu->sym; 943 sym = menu->sym;
944 if (sym) { 944 if (sym) {
945 if (menu->prompt) { 945 if (menu->prompt) {
946 head += "<big><b>"; 946 head += "<big><b>";
947 head += print_filter(menu->prompt->text); 947 head += print_filter(menu->prompt->text);
948 head += "</b></big>"; 948 head += "</b></big>";
949 if (sym->name) { 949 if (sym->name) {
950 head += " ("; 950 head += " (";
951 head += print_filter(sym->name); 951 head += print_filter(sym->name);
952 head += ")"; 952 head += ")";
953 } 953 }
954 } else if (sym->name) { 954 } else if (sym->name) {
955 head += "<big><b>"; 955 head += "<big><b>";
956 head += print_filter(sym->name); 956 head += print_filter(sym->name);
957 head += "</b></big>"; 957 head += "</b></big>";
958 } 958 }
959 head += "<br><br>"; 959 head += "<br><br>";
960 960
961 if (showDebug) { 961 if (showDebug) {
962 debug += "type: "; 962 debug += "type: ";
963 debug += print_filter(sym_type_name(sym->type)); 963 debug += print_filter(sym_type_name(sym->type));
964 if (sym_is_choice(sym)) 964 if (sym_is_choice(sym))
965 debug += " (choice)"; 965 debug += " (choice)";
966 debug += "<br>"; 966 debug += "<br>";
967 if (sym->rev_dep.expr) { 967 if (sym->rev_dep.expr) {
968 debug += "reverse dep: "; 968 debug += "reverse dep: ";
969 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE); 969 expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
970 debug += "<br>"; 970 debug += "<br>";
971 } 971 }
972 for (struct property *prop = sym->prop; prop; prop = prop->next) { 972 for (struct property *prop = sym->prop; prop; prop = prop->next) {
973 switch (prop->type) { 973 switch (prop->type) {
974 case P_PROMPT: 974 case P_PROMPT:
975 case P_MENU: 975 case P_MENU:
976 debug += "prompt: "; 976 debug += "prompt: ";
977 debug += print_filter(prop->text); 977 debug += print_filter(prop->text);
978 debug += "<br>"; 978 debug += "<br>";
979 break; 979 break;
980 case P_DEFAULT: 980 case P_DEFAULT:
981 debug += "default: "; 981 debug += "default: ";
982 expr_print(prop->expr, expr_print_help, &debug, E_NONE); 982 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
983 debug += "<br>"; 983 debug += "<br>";
984 break; 984 break;
985 case P_CHOICE: 985 case P_CHOICE:
986 if (sym_is_choice(sym)) { 986 if (sym_is_choice(sym)) {
987 debug += "choice: "; 987 debug += "choice: ";
988 expr_print(prop->expr, expr_print_help, &debug, E_NONE); 988 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
989 debug += "<br>"; 989 debug += "<br>";
990 } 990 }
991 break; 991 break;
992 case P_SELECT: 992 case P_SELECT:
993 debug += "select: "; 993 debug += "select: ";
994 expr_print(prop->expr, expr_print_help, &debug, E_NONE); 994 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
995 debug += "<br>"; 995 debug += "<br>";
996 break; 996 break;
997 case P_RANGE: 997 case P_RANGE:
998 debug += "range: "; 998 debug += "range: ";
999 expr_print(prop->expr, expr_print_help, &debug, E_NONE); 999 expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1000 debug += "<br>"; 1000 debug += "<br>";
1001 break; 1001 break;
1002 default: 1002 default:
1003 debug += "unknown property: "; 1003 debug += "unknown property: ";
1004 debug += prop_get_type_name(prop->type); 1004 debug += prop_get_type_name(prop->type);
1005 debug += "<br>"; 1005 debug += "<br>";
1006 } 1006 }
1007 if (prop->visible.expr) { 1007 if (prop->visible.expr) {
1008 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: "; 1008 debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1009 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE); 1009 expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1010 debug += "<br>"; 1010 debug += "<br>";
1011 } 1011 }
1012 } 1012 }
1013 debug += "<br>"; 1013 debug += "<br>";
1014 } 1014 }
1015 1015
1016 help = print_filter(sym->help); 1016 help = print_filter(sym->help);
1017 } else if (menu->prompt) { 1017 } else if (menu->prompt) {
1018 head += "<big><b>"; 1018 head += "<big><b>";
1019 head += print_filter(menu->prompt->text); 1019 head += print_filter(menu->prompt->text);
1020 head += "</b></big><br><br>"; 1020 head += "</b></big><br><br>";
1021 if (showDebug) { 1021 if (showDebug) {
1022 if (menu->prompt->visible.expr) { 1022 if (menu->prompt->visible.expr) {
1023 debug += "&nbsp;&nbsp;dep: "; 1023 debug += "&nbsp;&nbsp;dep: ";
1024 expr_print(menu->prompt->visible.expr, expr_print_help, &debug, E_NONE); 1024 expr_print(menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
1025 debug += "<br><br>"; 1025 debug += "<br><br>";
1026 } 1026 }
1027 } 1027 }
1028 } 1028 }
1029 if (showDebug) 1029 if (showDebug)
1030 debug += QString().sprintf("defined at %s:%d<br><br>", menu->file->name, menu->lineno); 1030 debug += QString().sprintf("defined at %s:%d<br><br>", menu->file->name, menu->lineno);
1031 helpText->setText(head + debug + help); 1031 helpText->setText(head + debug + help);
1032} 1032}
1033 1033
1034void ConfigMainWindow::loadConfig(void) 1034void ConfigMainWindow::loadConfig(void)
1035{ 1035{
1036 QString s = QFileDialog::getOpenFileName(".config", NULL, this); 1036 QString s = QFileDialog::getOpenFileName(".config", NULL, this);
1037 if (s.isNull()) 1037 if (s.isNull())
1038 return; 1038 return;
1039 if (conf_read(s.latin1())) 1039 if (conf_read(s.latin1()))
1040 QMessageBox::information(this, "qconf", "Unable to load configuration!"); 1040 QMessageBox::information(this, "qconf", "Unable to load configuration!");
1041 ConfigView::updateListAll(); 1041 ConfigView::updateListAll();
1042} 1042}
1043 1043
1044void ConfigMainWindow::saveConfig(void) 1044void ConfigMainWindow::saveConfig(void)
1045{ 1045{
1046 if (conf_write(NULL)) 1046 if (conf_write(NULL))
1047 QMessageBox::information(this, "qconf", "Unable to save configuration!"); 1047 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1048} 1048}
1049 1049
1050void ConfigMainWindow::saveConfigAs(void) 1050void ConfigMainWindow::saveConfigAs(void)
1051{ 1051{
1052 QString s = QFileDialog::getSaveFileName(".config", NULL, this); 1052 QString s = QFileDialog::getSaveFileName(".config", NULL, this);
1053 if (s.isNull()) 1053 if (s.isNull())
1054 return; 1054 return;
1055 if (conf_write(s.latin1())) 1055 if (conf_write(s.latin1()))
1056 QMessageBox::information(this, "qconf", "Unable to save configuration!"); 1056 QMessageBox::information(this, "qconf", "Unable to save configuration!");
1057} 1057}
1058 1058
1059void ConfigMainWindow::changeMenu(struct menu *menu) 1059void ConfigMainWindow::changeMenu(struct menu *menu)
1060{ 1060{
1061 configList->setRootMenu(menu); 1061 configList->setRootMenu(menu);
1062 backAction->setEnabled(TRUE); 1062 backAction->setEnabled(TRUE);
1063} 1063}
1064 1064
1065void ConfigMainWindow::listFocusChanged(void) 1065void ConfigMainWindow::listFocusChanged(void)
1066{ 1066{
1067 if (menuList->hasFocus()) { 1067 if (menuList->hasFocus()) {
1068 if (menuList->mode == menuMode) 1068 if (menuList->mode == menuMode)
1069 configList->clearSelection(); 1069 configList->clearSelection();
1070 setHelp(menuList->selectedItem()); 1070 setHelp(menuList->selectedItem());
1071 } else if (configList->hasFocus()) { 1071 } else if (configList->hasFocus()) {
1072 setHelp(configList->selectedItem()); 1072 setHelp(configList->selectedItem());
1073 } 1073 }
1074} 1074}
1075 1075
1076void ConfigMainWindow::goBack(void) 1076void ConfigMainWindow::goBack(void)
1077{ 1077{
1078 ConfigItem* item; 1078 ConfigItem* item;
1079 1079
1080 configList->setParentMenu(); 1080 configList->setParentMenu();
1081 if (configList->rootEntry == &rootmenu) 1081 if (configList->rootEntry == &rootmenu)
1082 backAction->setEnabled(FALSE); 1082 backAction->setEnabled(FALSE);
1083 item = (ConfigItem*)menuList->selectedItem(); 1083 item = (ConfigItem*)menuList->selectedItem();
1084 while (item) { 1084 while (item) {
1085 if (item->menu == configList->rootEntry) { 1085 if (item->menu == configList->rootEntry) {
1086 menuList->setSelected(item, TRUE); 1086 menuList->setSelected(item, TRUE);
1087 break; 1087 break;
1088 } 1088 }
1089 item = (ConfigItem*)item->parent(); 1089 item = (ConfigItem*)item->parent();
1090 } 1090 }
1091} 1091}
1092 1092
1093void ConfigMainWindow::showSingleView(void) 1093void ConfigMainWindow::showSingleView(void)
1094{ 1094{
1095 menuView->hide(); 1095 menuView->hide();
1096 menuList->setRootMenu(0); 1096 menuList->setRootMenu(0);
1097 configList->mode = singleMode; 1097 configList->mode = singleMode;
1098 if (configList->rootEntry == &rootmenu) 1098 if (configList->rootEntry == &rootmenu)
1099 configList->updateListAll(); 1099 configList->updateListAll();
1100 else 1100 else
1101 configList->setRootMenu(&rootmenu); 1101 configList->setRootMenu(&rootmenu);
1102 configList->setAllOpen(TRUE); 1102 configList->setAllOpen(TRUE);
1103 configList->setFocus(); 1103 configList->setFocus();
1104} 1104}
1105 1105
1106void ConfigMainWindow::showSplitView(void) 1106void ConfigMainWindow::showSplitView(void)
1107{ 1107{
1108 configList->mode = symbolMode; 1108 configList->mode = symbolMode;
1109 if (configList->rootEntry == &rootmenu) 1109 if (configList->rootEntry == &rootmenu)
1110 configList->updateListAll(); 1110 configList->updateListAll();
1111 else 1111 else
1112 configList->setRootMenu(&rootmenu); 1112 configList->setRootMenu(&rootmenu);
1113 configList->setAllOpen(TRUE); 1113 configList->setAllOpen(TRUE);
1114 configApp->processEvents(); 1114 configApp->processEvents();
1115 menuList->mode = menuMode; 1115 menuList->mode = menuMode;
1116 menuList->setRootMenu(&rootmenu); 1116 menuList->setRootMenu(&rootmenu);
1117 menuList->setAllOpen(TRUE); 1117 menuList->setAllOpen(TRUE);
1118 menuView->show(); 1118 menuView->show();
1119 menuList->setFocus(); 1119 menuList->setFocus();
1120} 1120}
1121 1121
1122void ConfigMainWindow::showFullView(void) 1122void ConfigMainWindow::showFullView(void)
1123{ 1123{
1124 menuView->hide(); 1124 menuView->hide();
1125 menuList->setRootMenu(0); 1125 menuList->setRootMenu(0);
1126 configList->mode = fullMode; 1126 configList->mode = fullMode;
1127 if (configList->rootEntry == &rootmenu) 1127 if (configList->rootEntry == &rootmenu)
1128 configList->updateListAll(); 1128 configList->updateListAll();
1129 else 1129 else
1130 configList->setRootMenu(&rootmenu); 1130 configList->setRootMenu(&rootmenu);
1131 configList->setAllOpen(FALSE); 1131 configList->setAllOpen(FALSE);
1132 configList->setFocus(); 1132 configList->setFocus();
1133} 1133}
1134 1134
1135void ConfigMainWindow::setShowAll(bool b) 1135void ConfigMainWindow::setShowAll(bool b)
1136{ 1136{
1137 if (configList->showAll == b) 1137 if (configList->showAll == b)
1138 return; 1138 return;
1139 configList->showAll = b; 1139 configList->showAll = b;
1140 configList->updateListAll(); 1140 configList->updateListAll();
1141 menuList->showAll = b; 1141 menuList->showAll = b;
1142 menuList->updateListAll(); 1142 menuList->updateListAll();
1143} 1143}
1144 1144
1145void ConfigMainWindow::setShowDebug(bool b) 1145void ConfigMainWindow::setShowDebug(bool b)
1146{ 1146{
1147 if (showDebug == b) 1147 if (showDebug == b)
1148 return; 1148 return;
1149 showDebug = b; 1149 showDebug = b;
1150} 1150}
1151 1151
1152void ConfigMainWindow::setShowName(bool b) 1152void ConfigMainWindow::setShowName(bool b)
1153{ 1153{
1154 if (configList->showName == b) 1154 if (configList->showName == b)
1155 return; 1155 return;
1156 configList->showName = b; 1156 configList->showName = b;
1157 configList->reinit(); 1157 configList->reinit();
1158 menuList->showName = b; 1158 menuList->showName = b;
1159 menuList->reinit(); 1159 menuList->reinit();
1160} 1160}
1161 1161
1162void ConfigMainWindow::setShowRange(bool b) 1162void ConfigMainWindow::setShowRange(bool b)
1163{ 1163{
1164 if (configList->showRange == b) 1164 if (configList->showRange == b)
1165 return; 1165 return;
1166 configList->showRange = b; 1166 configList->showRange = b;
1167 configList->reinit(); 1167 configList->reinit();
1168 menuList->showRange = b; 1168 menuList->showRange = b;
1169 menuList->reinit(); 1169 menuList->reinit();
1170} 1170}
1171 1171
1172void ConfigMainWindow::setShowData(bool b) 1172void ConfigMainWindow::setShowData(bool b)
1173{ 1173{
1174 if (configList->showData == b) 1174 if (configList->showData == b)
1175 return; 1175 return;
1176 configList->showData = b; 1176 configList->showData = b;
1177 configList->reinit(); 1177 configList->reinit();
1178 menuList->showData = b; 1178 menuList->showData = b;
1179 menuList->reinit(); 1179 menuList->reinit();
1180} 1180}
1181 1181
1182/* 1182/*
1183 * ask for saving configuration before quitting 1183 * ask for saving configuration before quitting
1184 * TODO ask only when something changed 1184 * TODO ask only when something changed
1185 */ 1185 */
1186void ConfigMainWindow::closeEvent(QCloseEvent* e) 1186void ConfigMainWindow::closeEvent(QCloseEvent* e)
1187{ 1187{
1188 if (!sym_change_count) { 1188 if (!sym_change_count) {
1189 e->accept(); 1189 e->accept();
1190 return; 1190 return;
1191 } 1191 }
1192 QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning, 1192 QMessageBox mb("qconf", "Save configuration?", QMessageBox::Warning,
1193 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape); 1193 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape);
1194 mb.setButtonText(QMessageBox::Yes, "&Save Changes"); 1194 mb.setButtonText(QMessageBox::Yes, "&Save Changes");
1195 mb.setButtonText(QMessageBox::No, "&Discard Changes"); 1195 mb.setButtonText(QMessageBox::No, "&Discard Changes");
1196 mb.setButtonText(QMessageBox::Cancel, "Cancel Exit"); 1196 mb.setButtonText(QMessageBox::Cancel, "Cancel Exit");
1197 switch (mb.exec()) { 1197 switch (mb.exec()) {
1198 case QMessageBox::Yes: 1198 case QMessageBox::Yes:
1199 conf_write(NULL); 1199 conf_write(NULL);
1200 case QMessageBox::No: 1200 case QMessageBox::No:
1201 e->accept(); 1201 e->accept();
1202 break; 1202 break;
1203 case QMessageBox::Cancel: 1203 case QMessageBox::Cancel:
1204 e->ignore(); 1204 e->ignore();
1205 break; 1205 break;
1206 } 1206 }
1207} 1207}
1208 1208
1209void ConfigMainWindow::showIntro(void) 1209void ConfigMainWindow::showIntro(void)
1210{ 1210{
1211 static char str[] = "Welcome to the qconf graphical kernel configuration tool for Linux.\n\n" 1211 static char str[] = "Welcome to the qconf graphical kernel configuration tool for Linux.\n\n"
1212 "For each option, a blank box indicates the feature is disabled, a check\n" 1212 "For each option, a blank box indicates the feature is disabled, a check\n"
1213 "indicates it is enabled, and a dot indicates that it is to be compiled\n" 1213 "indicates it is enabled, and a dot indicates that it is to be compiled\n"
1214 "as a module. Clicking on the box will cycle through the three states.\n\n" 1214 "as a module. Clicking on the box will cycle through the three states.\n\n"
1215 "If you do not see an option (e.g., a device driver) that you believe\n" 1215 "If you do not see an option (e.g., a device driver) that you believe\n"
1216 "should be present, try turning on Show All Options under the Options menu.\n" 1216 "should be present, try turning on Show All Options under the Options menu.\n"
1217 "Although there is no cross reference yet to help you figure out what other\n" 1217 "Although there is no cross reference yet to help you figure out what other\n"
1218 "options must be enabled to support the option you are interested in, you can\n" 1218 "options must be enabled to support the option you are interested in, you can\n"
1219 "still view the help of a grayed-out option.\n\n" 1219 "still view the help of a grayed-out option.\n\n"
1220 "Toggling Show Debug Info under the Options menu will show the dependencies,\n" 1220 "Toggling Show Debug Info under the Options menu will show the dependencies,\n"
1221 "which you can then match by examining other options.\n\n"; 1221 "which you can then match by examining other options.\n\n";
1222 1222
1223 QMessageBox::information(this, "qconf", str); 1223 QMessageBox::information(this, "qconf", str);
1224} 1224}
1225 1225
1226void ConfigMainWindow::showAbout(void) 1226void ConfigMainWindow::showAbout(void)
1227{ 1227{
1228 static char str[] = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n" 1228 static char str[] = "qconf is Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>.\n\n"
1229 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n"; 1229 "Bug reports and feature request can also be entered at http://bugzilla.kernel.org/\n";
1230 1230
1231 QMessageBox::information(this, "qconf", str); 1231 QMessageBox::information(this, "qconf", str);
1232} 1232}
1233 1233
1234void fixup_rootmenu(struct menu *menu) 1234void fixup_rootmenu(struct menu *menu)
1235{ 1235{
1236 struct menu *child; 1236 struct menu *child;
1237 static int menu_cnt = 0; 1237 static int menu_cnt = 0;
1238 1238
1239 menu->flags |= MENU_ROOT; 1239 menu->flags |= MENU_ROOT;
1240 for (child = menu->list; child; child = child->next) { 1240 for (child = menu->list; child; child = child->next) {
1241 if (child->prompt && child->prompt->type == P_MENU) { 1241 if (child->prompt && child->prompt->type == P_MENU) {
1242 menu_cnt++; 1242 menu_cnt++;
1243 fixup_rootmenu(child); 1243 fixup_rootmenu(child);
1244 menu_cnt--; 1244 menu_cnt--;
1245 } else if (!menu_cnt) 1245 } else if (!menu_cnt)
1246 fixup_rootmenu(child); 1246 fixup_rootmenu(child);
1247 } 1247 }
1248} 1248}
1249 1249
1250static const char *progname; 1250static const char *progname;
1251 1251
1252static void usage(void) 1252static void usage(void)
1253{ 1253{
1254 printf("%s <config>\n", progname); 1254 printf("%s <config>\n", progname);
1255 exit(0); 1255 exit(0);
1256} 1256}
1257 1257
1258int main(int ac, char** av) 1258int main(int ac, char** av)
1259{ 1259{
1260 ConfigMainWindow* v; 1260 ConfigMainWindow* v;
1261 const char *name; 1261 const char *name;
1262 1262
1263#ifndef LKC_DIRECT_LINK 1263#ifndef LKC_DIRECT_LINK
1264 kconfig_load(); 1264 kconfig_load();
1265#endif 1265#endif
1266 1266
1267 progname = av[0]; 1267 progname = av[0];
1268 configApp = new QApplication(ac, av); 1268 configApp = new QApplication(ac, av);
1269#if QT_VERSION >= 300 1269#if QT_VERSION >= 0x030000
1270 configSettings = new QSettings; 1270 configSettings = new QSettings;
1271#endif 1271#endif
1272 if (ac > 1 && av[1][0] == '-') { 1272 if (ac > 1 && av[1][0] == '-') {
1273 switch (av[1][1]) { 1273 switch (av[1][1]) {
1274 case 'h': 1274 case 'h':
1275 case '?': 1275 case '?':
1276 usage(); 1276 usage();
1277 } 1277 }
1278 name = av[2]; 1278 name = av[2];
1279 } else 1279 } else
1280 name = av[1]; 1280 name = av[1];
1281 if (!name) 1281 if (!name)
1282 usage(); 1282 usage();
1283 1283
1284 conf_parse(name); 1284 conf_parse(name);
1285 fixup_rootmenu(&rootmenu); 1285 fixup_rootmenu(&rootmenu);
1286 conf_read(NULL); 1286 conf_read(NULL);
1287 //zconfdump(stdout); 1287 //zconfdump(stdout);
1288 1288
1289 v = new ConfigMainWindow(); 1289 v = new ConfigMainWindow();
1290 1290
1291 //zconfdump(stdout); 1291 //zconfdump(stdout);
1292 v->show(); 1292 v->show();
1293 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit())); 1293 configApp->connect(configApp, SIGNAL(lastWindowClosed()), SLOT(quit()));
1294 configApp->exec(); 1294 configApp->exec();
1295 1295
1296#if QT_VERSION >= 300 1296#if QT_VERSION >= 0x030000
1297 configSettings->writeEntry("/kconfig/qconf/window x", v->pos().x()); 1297 configSettings->writeEntry("/kconfig/qconf/window x", v->pos().x());
1298 configSettings->writeEntry("/kconfig/qconf/window y", v->pos().y()); 1298 configSettings->writeEntry("/kconfig/qconf/window y", v->pos().y());
1299 configSettings->writeEntry("/kconfig/qconf/window width", v->size().width()); 1299 configSettings->writeEntry("/kconfig/qconf/window width", v->size().width());
1300 configSettings->writeEntry("/kconfig/qconf/window height", v->size().height()); 1300 configSettings->writeEntry("/kconfig/qconf/window height", v->size().height());
1301 delete configSettings; 1301 delete configSettings;
1302#endif 1302#endif
1303 return 0; 1303 return 0;
1304} 1304}
diff --git a/scripts/kconfig/qconf.h b/scripts/kconfig/qconf.h
index c548884..dee5254 100644
--- a/scripts/kconfig/qconf.h
+++ b/scripts/kconfig/qconf.h
@@ -1,238 +1,238 @@
1/* 1/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0. 3 * Released under the terms of the GNU GPL v2.0.
4 */ 4 */
5 5
6#include <qlistview.h> 6#include <qlistview.h>
7 7
8class ConfigList; 8class ConfigList;
9class ConfigItem; 9class ConfigItem;
10class ConfigLineEdit; 10class ConfigLineEdit;
11class ConfigMainWindow; 11class ConfigMainWindow;
12 12
13class ConfigView : public QVBox { 13class ConfigView : public QVBox {
14 Q_OBJECT 14 Q_OBJECT
15 typedef class QVBox Parent; 15 typedef class QVBox Parent;
16public: 16public:
17 ConfigView(QWidget* parent, ConfigMainWindow* cview); 17 ConfigView(QWidget* parent, ConfigMainWindow* cview);
18 ~ConfigView(void); 18 ~ConfigView(void);
19 static void updateList(ConfigItem* item); 19 static void updateList(ConfigItem* item);
20 static void updateListAll(void); 20 static void updateListAll(void);
21 21
22public: 22public:
23 ConfigList* list; 23 ConfigList* list;
24 ConfigLineEdit* lineEdit; 24 ConfigLineEdit* lineEdit;
25 25
26 static ConfigView* viewList; 26 static ConfigView* viewList;
27 ConfigView* nextView; 27 ConfigView* nextView;
28}; 28};
29 29
30enum colIdx { 30enum colIdx {
31 promptColIdx, nameColIdx, noColIdx, modColIdx, yesColIdx, dataColIdx, colNr 31 promptColIdx, nameColIdx, noColIdx, modColIdx, yesColIdx, dataColIdx, colNr
32}; 32};
33enum listMode { 33enum listMode {
34 singleMode, menuMode, symbolMode, fullMode 34 singleMode, menuMode, symbolMode, fullMode
35}; 35};
36 36
37class ConfigList : public QListView { 37class ConfigList : public QListView {
38 Q_OBJECT 38 Q_OBJECT
39 typedef class QListView Parent; 39 typedef class QListView Parent;
40public: 40public:
41 ConfigList(ConfigView* p, ConfigMainWindow* cview); 41 ConfigList(ConfigView* p, ConfigMainWindow* cview);
42 void reinit(void); 42 void reinit(void);
43 ConfigView* parent(void) const 43 ConfigView* parent(void) const
44 { 44 {
45 return (ConfigView*)Parent::parent(); 45 return (ConfigView*)Parent::parent();
46 } 46 }
47 47
48protected: 48protected:
49 ConfigMainWindow* cview; 49 ConfigMainWindow* cview;
50 50
51 void keyPressEvent(QKeyEvent *e); 51 void keyPressEvent(QKeyEvent *e);
52 void contentsMousePressEvent(QMouseEvent *e); 52 void contentsMousePressEvent(QMouseEvent *e);
53 void contentsMouseReleaseEvent(QMouseEvent *e); 53 void contentsMouseReleaseEvent(QMouseEvent *e);
54 void contentsMouseMoveEvent(QMouseEvent *e); 54 void contentsMouseMoveEvent(QMouseEvent *e);
55 void contentsMouseDoubleClickEvent(QMouseEvent *e); 55 void contentsMouseDoubleClickEvent(QMouseEvent *e);
56 void focusInEvent(QFocusEvent *e); 56 void focusInEvent(QFocusEvent *e);
57public slots: 57public slots:
58 void setRootMenu(struct menu *menu); 58 void setRootMenu(struct menu *menu);
59 59
60 void updateList(ConfigItem *item); 60 void updateList(ConfigItem *item);
61 void setValue(ConfigItem* item, tristate val); 61 void setValue(ConfigItem* item, tristate val);
62 void changeValue(ConfigItem* item); 62 void changeValue(ConfigItem* item);
63 void updateSelection(void); 63 void updateSelection(void);
64signals: 64signals:
65 void menuSelected(struct menu *menu); 65 void menuSelected(struct menu *menu);
66 void parentSelected(void); 66 void parentSelected(void);
67 void gotFocus(void); 67 void gotFocus(void);
68 68
69public: 69public:
70 void updateListAll(void) 70 void updateListAll(void)
71 { 71 {
72 updateAll = true; 72 updateAll = true;
73 updateList(NULL); 73 updateList(NULL);
74 updateAll = false; 74 updateAll = false;
75 } 75 }
76 ConfigList* listView() 76 ConfigList* listView()
77 { 77 {
78 return this; 78 return this;
79 } 79 }
80 ConfigItem* firstChild() const 80 ConfigItem* firstChild() const
81 { 81 {
82 return (ConfigItem *)Parent::firstChild(); 82 return (ConfigItem *)Parent::firstChild();
83 } 83 }
84 int mapIdx(colIdx idx) 84 int mapIdx(colIdx idx)
85 { 85 {
86 return colMap[idx]; 86 return colMap[idx];
87 } 87 }
88 void addColumn(colIdx idx, const QString& label) 88 void addColumn(colIdx idx, const QString& label)
89 { 89 {
90 colMap[idx] = Parent::addColumn(label); 90 colMap[idx] = Parent::addColumn(label);
91 colRevMap[colMap[idx]] = idx; 91 colRevMap[colMap[idx]] = idx;
92 } 92 }
93 void removeColumn(colIdx idx) 93 void removeColumn(colIdx idx)
94 { 94 {
95 int col = colMap[idx]; 95 int col = colMap[idx];
96 if (col >= 0) { 96 if (col >= 0) {
97 Parent::removeColumn(col); 97 Parent::removeColumn(col);
98 colRevMap[col] = colMap[idx] = -1; 98 colRevMap[col] = colMap[idx] = -1;
99 } 99 }
100 } 100 }
101 void setAllOpen(bool open); 101 void setAllOpen(bool open);
102 void setParentMenu(void); 102 void setParentMenu(void);
103 103
104 template <class P> 104 template <class P>
105 void ConfigList::updateMenuList(P*, struct menu*); 105 void ConfigList::updateMenuList(P*, struct menu*);
106 106
107 bool updateAll; 107 bool updateAll;
108 108
109 QPixmap symbolYesPix, symbolModPix, symbolNoPix; 109 QPixmap symbolYesPix, symbolModPix, symbolNoPix;
110 QPixmap choiceYesPix, choiceNoPix; 110 QPixmap choiceYesPix, choiceNoPix;
111 QPixmap menuPix, menuInvPix, menuBackPix, voidPix; 111 QPixmap menuPix, menuInvPix, menuBackPix, voidPix;
112 112
113 bool showAll, showName, showRange, showData; 113 bool showAll, showName, showRange, showData;
114 enum listMode mode; 114 enum listMode mode;
115 struct menu *rootEntry; 115 struct menu *rootEntry;
116 QColorGroup disabledColorGroup; 116 QColorGroup disabledColorGroup;
117 QColorGroup inactivedColorGroup; 117 QColorGroup inactivedColorGroup;
118 118
119private: 119private:
120 int colMap[colNr]; 120 int colMap[colNr];
121 int colRevMap[colNr]; 121 int colRevMap[colNr];
122}; 122};
123 123
124class ConfigItem : public QListViewItem { 124class ConfigItem : public QListViewItem {
125 typedef class QListViewItem Parent; 125 typedef class QListViewItem Parent;
126public: 126public:
127 ConfigItem(QListView *parent, ConfigItem *after, struct menu *m, bool v) 127 ConfigItem(QListView *parent, ConfigItem *after, struct menu *m, bool v)
128 : Parent(parent, after), menu(m), visible(v), goParent(false) 128 : Parent(parent, after), menu(m), visible(v), goParent(false)
129 { 129 {
130 init(); 130 init();
131 } 131 }
132 ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v) 132 ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v)
133 : Parent(parent, after), menu(m), visible(v), goParent(false) 133 : Parent(parent, after), menu(m), visible(v), goParent(false)
134 { 134 {
135 init(); 135 init();
136 } 136 }
137 ConfigItem(QListView *parent, ConfigItem *after, bool v) 137 ConfigItem(QListView *parent, ConfigItem *after, bool v)
138 : Parent(parent, after), menu(0), visible(v), goParent(true) 138 : Parent(parent, after), menu(0), visible(v), goParent(true)
139 { 139 {
140 init(); 140 init();
141 } 141 }
142 ~ConfigItem(void); 142 ~ConfigItem(void);
143 void init(void); 143 void init(void);
144#if QT_VERSION >= 300 144#if QT_VERSION >= 0x030000
145 void okRename(int col); 145 void okRename(int col);
146#endif 146#endif
147 void updateMenu(void); 147 void updateMenu(void);
148 void testUpdateMenu(bool v); 148 void testUpdateMenu(bool v);
149 ConfigList* listView() const 149 ConfigList* listView() const
150 { 150 {
151 return (ConfigList*)Parent::listView(); 151 return (ConfigList*)Parent::listView();
152 } 152 }
153 ConfigItem* firstChild() const 153 ConfigItem* firstChild() const
154 { 154 {
155 return (ConfigItem *)Parent::firstChild(); 155 return (ConfigItem *)Parent::firstChild();
156 } 156 }
157 ConfigItem* nextSibling() const 157 ConfigItem* nextSibling() const
158 { 158 {
159 return (ConfigItem *)Parent::nextSibling(); 159 return (ConfigItem *)Parent::nextSibling();
160 } 160 }
161 void setText(colIdx idx, const QString& text) 161 void setText(colIdx idx, const QString& text)
162 { 162 {
163 Parent::setText(listView()->mapIdx(idx), text); 163 Parent::setText(listView()->mapIdx(idx), text);
164 } 164 }
165 QString text(colIdx idx) const 165 QString text(colIdx idx) const
166 { 166 {
167 return Parent::text(listView()->mapIdx(idx)); 167 return Parent::text(listView()->mapIdx(idx));
168 } 168 }
169 void setPixmap(colIdx idx, const QPixmap& pm) 169 void setPixmap(colIdx idx, const QPixmap& pm)
170 { 170 {
171 Parent::setPixmap(listView()->mapIdx(idx), pm); 171 Parent::setPixmap(listView()->mapIdx(idx), pm);
172 } 172 }
173 const QPixmap* pixmap(colIdx idx) const 173 const QPixmap* pixmap(colIdx idx) const
174 { 174 {
175 return Parent::pixmap(listView()->mapIdx(idx)); 175 return Parent::pixmap(listView()->mapIdx(idx));
176 } 176 }
177 void paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align); 177 void paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align);
178 178
179 ConfigItem* nextItem; 179 ConfigItem* nextItem;
180 struct menu *menu; 180 struct menu *menu;
181 bool visible; 181 bool visible;
182 bool goParent; 182 bool goParent;
183}; 183};
184 184
185class ConfigLineEdit : public QLineEdit { 185class ConfigLineEdit : public QLineEdit {
186 Q_OBJECT 186 Q_OBJECT
187 typedef class QLineEdit Parent; 187 typedef class QLineEdit Parent;
188public: 188public:
189 ConfigLineEdit(ConfigView* parent) 189 ConfigLineEdit(ConfigView* parent)
190 : Parent(parent) 190 : Parent(parent)
191 { } 191 { }
192 ConfigView* parent(void) const 192 ConfigView* parent(void) const
193 { 193 {
194 return (ConfigView*)Parent::parent(); 194 return (ConfigView*)Parent::parent();
195 } 195 }
196 void show(ConfigItem *i); 196 void show(ConfigItem *i);
197 void keyPressEvent(QKeyEvent *e); 197 void keyPressEvent(QKeyEvent *e);
198 198
199public: 199public:
200 ConfigItem *item; 200 ConfigItem *item;
201}; 201};
202 202
203class ConfigMainWindow : public QMainWindow { 203class ConfigMainWindow : public QMainWindow {
204 Q_OBJECT 204 Q_OBJECT
205public: 205public:
206 ConfigMainWindow(void); 206 ConfigMainWindow(void);
207public slots: 207public slots:
208 void setHelp(QListViewItem* item); 208 void setHelp(QListViewItem* item);
209 void changeMenu(struct menu *); 209 void changeMenu(struct menu *);
210 void listFocusChanged(void); 210 void listFocusChanged(void);
211 void goBack(void); 211 void goBack(void);
212 void loadConfig(void); 212 void loadConfig(void);
213 void saveConfig(void); 213 void saveConfig(void);
214 void saveConfigAs(void); 214 void saveConfigAs(void);
215 void showSingleView(void); 215 void showSingleView(void);
216 void showSplitView(void); 216 void showSplitView(void);
217 void showFullView(void); 217 void showFullView(void);
218 void setShowAll(bool); 218 void setShowAll(bool);
219 void setShowDebug(bool); 219 void setShowDebug(bool);
220 void setShowRange(bool); 220 void setShowRange(bool);
221 void setShowName(bool); 221 void setShowName(bool);
222 void setShowData(bool); 222 void setShowData(bool);
223 void showIntro(void); 223 void showIntro(void);
224 void showAbout(void); 224 void showAbout(void);
225 225
226protected: 226protected:
227 void closeEvent(QCloseEvent *e); 227 void closeEvent(QCloseEvent *e);
228 228
229 ConfigView *menuView; 229 ConfigView *menuView;
230 ConfigList *menuList; 230 ConfigList *menuList;
231 ConfigView *configView; 231 ConfigView *configView;
232 ConfigList *configList; 232 ConfigList *configList;
233 QTextView *helpText; 233 QTextView *helpText;
234 QToolBar *toolBar; 234 QToolBar *toolBar;
235 QAction *backAction; 235 QAction *backAction;
236 236
237 bool showDebug; 237 bool showDebug;
238}; 238};