summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.cpp60
1 files changed, 1 insertions, 59 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index e1edd4c..df313ce 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -101,337 +101,279 @@
101 101
102 102
103static bool useBigPixmaps = 0; 103static bool useBigPixmaps = 0;
104 104
105class HackWidget : public QWidget 105class HackWidget : public QWidget
106{ 106{
107public: 107public:
108 bool needsOk() 108 bool needsOk()
109 { return (getWState() & WState_Reserved1 ); } 109 { return (getWState() & WState_Reserved1 ); }
110 110
111 QRect normalGeometry() 111 QRect normalGeometry()
112 { return topData()->normalGeometry; }; 112 { return topData()->normalGeometry; };
113}; 113};
114 114
115class QPEApplicationData 115class QPEApplicationData
116{ 116{
117public: 117public:
118 QPEApplicationData ( ) : 118 QPEApplicationData ( ) :
119 presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), 119 presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ),
120 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), 120 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ),
121 keep_running( true ), qcopQok( false ), 121 keep_running( true ), qcopQok( false ),
122 fontFamily( "Vera" ), fontSize( 10 ), smallIconSize( 14 ), 122 fontFamily( "Vera" ), fontSize( 10 ), smallIconSize( 14 ),
123 bigIconSize( 32 ), qpe_main_widget( 0 ) 123 bigIconSize( 32 ), qpe_main_widget( 0 )
124 { 124 {
125 Config cfg( "qpe" ); 125 Config cfg( "qpe" );
126 cfg.setGroup( "Appearance" ); 126 cfg.setGroup( "Appearance" );
127 useBigPixmaps = cfg.readBoolEntry( "useBigPixmaps", false ); 127 useBigPixmaps = cfg.readBoolEntry( "useBigPixmaps", false );
128 fontFamily = cfg.readEntry( "FontFamily", "Vera" ); 128 fontFamily = cfg.readEntry( "FontFamily", "Vera" );
129 fontSize = cfg.readNumEntry( "FontSize", 10 ); 129 fontSize = cfg.readNumEntry( "FontSize", 10 );
130 smallIconSize = cfg.readNumEntry( "SmallIconSize", 14 ); 130 smallIconSize = cfg.readNumEntry( "SmallIconSize", 14 );
131 bigIconSize = cfg.readNumEntry( "BigIconSize", 32 ); 131 bigIconSize = cfg.readNumEntry( "BigIconSize", 32 );
132#ifdef OPIE_WITHROHFEEDBACK 132#ifdef OPIE_WITHROHFEEDBACK
133 RoH = 0; 133 RoH = 0;
134#endif 134#endif
135 } 135 }
136 136
137 int presstimer; 137 int presstimer;
138 QWidget* presswidget; 138 QWidget* presswidget;
139 QPoint presspos; 139 QPoint presspos;
140#ifdef OPIE_WITHROHFEEDBACK 140#ifdef OPIE_WITHROHFEEDBACK
141 Opie::Internal::RoHFeedback *RoH; 141 Opie::Internal::RoHFeedback *RoH;
142#endif 142#endif
143 143
144 bool rightpressed : 1; 144 bool rightpressed : 1;
145 bool kbgrabbed : 1; 145 bool kbgrabbed : 1;
146 bool notbusysent : 1; 146 bool notbusysent : 1;
147 bool preloaded : 1; 147 bool preloaded : 1;
148 bool forceshow : 1; 148 bool forceshow : 1;
149 bool nomaximize : 1; 149 bool nomaximize : 1;
150 bool keep_running : 1; 150 bool keep_running : 1;
151 bool qcopQok : 1; 151 bool qcopQok : 1;
152 152
153 QCString fontFamily; 153 QCString fontFamily;
154 int fontSize; 154 int fontSize;
155 int smallIconSize; 155 int smallIconSize;
156 int bigIconSize; 156 int bigIconSize;
157 157
158 QStringList langs; 158 QStringList langs;
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 { 202 {
203 if ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) 203 if ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") )
204 { 204 {
205 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( useBigPixmaps ); 205 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( useBigPixmaps );
206 } 206 }
207 QPoint p; 207 QPoint p;
208 QSize s; 208 QSize s;
209 bool max; 209 bool max;
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 qpe_show_dialog((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
252static void qpe_show_dialog( QDialog* d, bool nomax )
253{
254 QSize sh = d->sizeHint();
255 int w = QMAX(sh.width(),d->width());
256 int h = QMAX(sh.height(),d->height());
257
258 if ( d->parentWidget() && !d->parentWidget()->topLevelWidget()->isMaximized() )
259 nomax = TRUE;
260
261#ifndef Q_WS_QWS
262 QSize s(qApp->desktop()->width(), qApp->desktop()->height() );
263#else
264 QSize s(qt_maxWindowRect.width(), qt_maxWindowRect.height() );
265#endif
266
267 int maxX = s.width() - (d->frameGeometry().width() - d->geometry().width());
268 int maxY = s.height() - (d->frameGeometry().height() - d->geometry().height());
269
270 if ( (w >= maxX && h >= maxY) || ( (!nomax) && ( w > s.width()*3/4 || h > s.height()*3/4 ) ) ) {
271 d->showMaximized();
272 } else {
273 // try centering the dialog around its parent
274 QPoint p(0,0);
275 if ( d->parentWidget() ) {
276 QPoint pp = d->parentWidget()->mapToGlobal( QPoint(0,0) );
277 p = QPoint( pp.x() + d->parentWidget()->width()/2,
278 pp.y() + d->parentWidget()->height()/ 2 );
279 } else {
280 p = QPoint( maxX/2, maxY/2 );
281 }
282
283 p = QPoint( p.x() - w/2, p.y() - h/2 );
284// qDebug("p(x,y) is %d %d", p.x(), p.y() );
285
286 if ( w >= maxX ) {
287 if ( p.y() < 0 )
288 p.setY(0);
289 if ( p.y() + h > maxY )
290 p.setY( maxY - h);
291
292 d->resize(maxX, h);
293 d->move(0, p.y() );
294 } else if ( h >= maxY ) {
295 if ( p.x() < 0 )
296 p.setX(0);
297 if ( p.x() + w > maxX )
298 p.setX( maxX - w);
299
300 d->resize(w, maxY);
301 d->move(p.x(),0);
302 } else {
303 d->resize(w, h);
304 }
305
306 d->show();
307 }
308}
309
310 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)
311 { 253 {
312 maximized = TRUE; 254 maximized = TRUE;
313 // 350 is the trigger in qwsdefaultdecoration for providing a resize button 255 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
314 if ( qApp->desktop()->width() <= 350 ) 256 if ( qApp->desktop()->width() <= 350 )
315 return FALSE; 257 return FALSE;
316 258
317 Config cfg( "qpe" ); 259 Config cfg( "qpe" );
318 cfg.setGroup("ApplicationPositions"); 260 cfg.setGroup("ApplicationPositions");
319 QString str = cfg.readEntry( app, QString::null ); 261 QString str = cfg.readEntry( app, QString::null );
320 QStringList l = QStringList::split(",", str); 262 QStringList l = QStringList::split(",", str);
321 263
322 if ( l.count() == 5) { 264 if ( l.count() == 5) {
323 p.setX( l[0].toInt() ); 265 p.setX( l[0].toInt() );
324 p.setY( l[1].toInt() ); 266 p.setY( l[1].toInt() );
325 267
326 s.setWidth( l[2].toInt() ); 268 s.setWidth( l[2].toInt() );
327 s.setHeight( l[3].toInt() ); 269 s.setHeight( l[3].toInt() );
328 270
329 maximized = l[4].toInt(); 271 maximized = l[4].toInt();
330 272
331 return TRUE; 273 return TRUE;
332 } 274 }
333 275
334 return FALSE; 276 return FALSE;
335 } 277 }
336 278
337 279
338 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)
339 { 281 {
340#ifndef Q_WS_QWS 282#ifndef Q_WS_QWS
341 QRect qt_maxWindowRect = qApp->desktop()->geometry(); 283 QRect qt_maxWindowRect = qApp->desktop()->geometry();
342#endif 284#endif
343 int maxX = qt_maxWindowRect.width(); 285 int maxX = qt_maxWindowRect.width();
344 int maxY = qt_maxWindowRect.height(); 286 int maxY = qt_maxWindowRect.height();
345 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); 287 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() );
346 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); 288 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() );
347 289
348 // 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
349 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) 291 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) )
350 return FALSE; 292 return FALSE;
351 293
352 if ( wWidth > maxX ) { 294 if ( wWidth > maxX ) {
353 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); 295 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) );
354 wWidth = maxX; 296 wWidth = maxX;
355 } 297 }
356 298
357 if ( wHeight > maxY ) { 299 if ( wHeight > maxY ) {
358 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); 300 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) );
359 wHeight = maxY; 301 wHeight = maxY;
360 } 302 }
361 303
362 // 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
363 if ( wWidth < 80 || wHeight < 60 ) 305 if ( wWidth < 80 || wHeight < 60 )
364 return FALSE; 306 return FALSE;
365 307
366 if ( p.x() < 0 ) 308 if ( p.x() < 0 )
367 p.setX(0); 309 p.setX(0);
368 if ( p.y() < 0 ) 310 if ( p.y() < 0 )
369 p.setY(0); 311 p.setY(0);
370 312
371 if ( p.x() + wWidth > maxX ) 313 if ( p.x() + wWidth > maxX )
372 p.setX( maxX - wWidth ); 314 p.setX( maxX - wWidth );
373 if ( p.y() + wHeight > maxY ) 315 if ( p.y() + wHeight > maxY )
374 p.setY( maxY - wHeight ); 316 p.setY( maxY - wHeight );
375 317
376 return TRUE; 318 return TRUE;
377 } 319 }
378 320
379 static void store_widget_rect(QWidget *w, QString &app) 321 static void store_widget_rect(QWidget *w, QString &app)
380 { 322 {
381 // 350 is the trigger in qwsdefaultdecoration for providing a resize button 323 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
382 if ( qApp->desktop()->width() <= 350 ) 324 if ( qApp->desktop()->width() <= 350 )
383 return; 325 return;
384 // 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
385 // 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 )
386 int offsetX = w->x() - w->geometry().left(); 328 int offsetX = w->x() - w->geometry().left();
387 int offsetY = w->y() - w->geometry().top(); 329 int offsetY = w->y() - w->geometry().top();
388 330
389 QRect r; 331 QRect r;
390 if ( w->isMaximized() ) 332 if ( w->isMaximized() )
391 r = ( (HackWidget *) w)->normalGeometry(); 333 r = ( (HackWidget *) w)->normalGeometry();
392 else 334 else
393 r = w->geometry(); 335 r = w->geometry();
394 336
395 // 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)
396 Config cfg( "qpe" ); 338 Config cfg( "qpe" );
397 cfg.setGroup("ApplicationPositions"); 339 cfg.setGroup("ApplicationPositions");
398 QString s; 340 QString s;
399 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() );
400 cfg.writeEntry( app, s ); 342 cfg.writeEntry( app, s );
401 } 343 }
402 344
403 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 345 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
404 { 346 {
405 /* 347 /*
406 // 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
407 // 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
408 // the applnk that has the corresponding argv[0] as this program 350 // the applnk that has the corresponding argv[0] as this program
409 // 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
410 // for the main widget. This saves duplicating translations for 352 // for the main widget. This saves duplicating translations for
411 // the app name in the program and in the .desktop files. 353 // the app name in the program and in the .desktop files.
412 354
413 AppLnkSet apps( appsPath ); 355 AppLnkSet apps( appsPath );
414 356
415 QList<AppLnk> appsList = apps.children(); 357 QList<AppLnk> appsList = apps.children();
416 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 358 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
417 if ( (*it)->exec() == appName ) { 359 if ( (*it)->exec() == appName ) {
418 mw->setCaption( (*it)->name() ); 360 mw->setCaption( (*it)->name() );
419 return TRUE; 361 return TRUE;
420 } 362 }
421 } 363 }
422 */ 364 */
423 return FALSE; 365 return FALSE;
424 } 366 }
425 367
426 368
427 void show(QWidget* mw, bool nomax) 369 void show(QWidget* mw, bool nomax)
428 { 370 {
429 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 371 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
430 nomaximize = nomax; 372 nomaximize = nomax;
431 qpe_main_widget = mw; 373 qpe_main_widget = mw;
432 qcopQok = TRUE; 374 qcopQok = TRUE;
433#ifndef QT_NO_COP 375#ifndef QT_NO_COP
434 376
435 sendQCopQ(); 377 sendQCopQ();
436#endif 378#endif
437 379