summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index 90cd5f1..ae1632e 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -130,117 +130,121 @@ public:
130 bool qcopQok : 1; 130 bool qcopQok : 1;
131 131
132 132
133 QStringList langs; 133 QStringList langs;
134 QString appName; 134 QString appName;
135 struct QCopRec 135 struct QCopRec
136 { 136 {
137 QCopRec( const QCString &ch, const QCString &msg, 137 QCopRec( const QCString &ch, const QCString &msg,
138 const QByteArray &d ) : 138 const QByteArray &d ) :
139 channel( ch ), message( msg ), data( d ) 139 channel( ch ), message( msg ), data( d )
140 { } 140 { }
141 141
142 QCString channel; 142 QCString channel;
143 QCString message; 143 QCString message;
144 QByteArray data; 144 QByteArray data;
145 }; 145 };
146 QWidget* qpe_main_widget; 146 QWidget* qpe_main_widget;
147 QGuardedPtr<QWidget> lastraised; 147 QGuardedPtr<QWidget> lastraised;
148 QQueue<QCopRec> qcopq; 148 QQueue<QCopRec> qcopq;
149 QString styleName; 149 QString styleName;
150 QString decorationName; 150 QString decorationName;
151 151
152 void enqueueQCop( const QCString &ch, const QCString &msg, 152 void enqueueQCop( const QCString &ch, const QCString &msg,
153 const QByteArray &data ) 153 const QByteArray &data )
154 { 154 {
155 qcopq.enqueue( new QCopRec( ch, msg, data ) ); 155 qcopq.enqueue( new QCopRec( ch, msg, data ) );
156 } 156 }
157 void sendQCopQ() 157 void sendQCopQ()
158 { 158 {
159 if (!qcopQok ) 159 if (!qcopQok )
160 return; 160 return;
161 161
162 QCopRec * r; 162 QCopRec * r;
163 163
164 while((r=qcopq.dequeue())) { 164 while((r=qcopq.dequeue())) {
165 // remove from queue before sending... 165 // remove from queue before sending...
166 // event loop can come around again before getting 166 // event loop can come around again before getting
167 // back from sendLocally 167 // back from sendLocally
168#ifndef QT_NO_COP 168#ifndef QT_NO_COP
169 QCopChannel::sendLocally( r->channel, r->message, r->data ); 169 QCopChannel::sendLocally( r->channel, r->message, r->data );
170#endif 170#endif
171 171
172 delete r; 172 delete r;
173 } 173 }
174 } 174 }
175 175
176 static void show_mx(QWidget* mw, bool nomaximize, QString &strName/* = QString::null */) 176 static void show_mx(QWidget* mw, bool nomaximize, QString &strName/* = QString::null */)
177 { 177 {
178 if ( mw->isVisible() ) {
179 mw->raise();
180 } else {
181 QPoint p; 178 QPoint p;
182 QSize s; 179 QSize s;
180 bool max;
181 if ( mw->isVisible() ) {
182 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
183 mw->resize(s);
184 mw->move(p);
185 }
186 mw->raise();
187 } else {
183 188
184 if ( mw->layout() && mw->inherits("QDialog") ) { 189 if ( mw->layout() && mw->inherits("QDialog") ) {
185 bool max;
186 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { 190 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
187 mw->resize(s); 191 mw->resize(s);
188 mw->move(p); 192 mw->move(p);
189 193
190 if ( max && !nomaximize ) 194 if ( max && !nomaximize ) {
191 mw->showMaximized(); 195 mw->showMaximized();
192 else 196 } else {
193 mw->show(); 197 mw->show();
198 }
194 } else { 199 } else {
195 qpe_show_dialog((QDialog*)mw,nomaximize); 200 qpe_show_dialog((QDialog*)mw,nomaximize);
196 } 201 }
197 } else { 202 } else {
198 bool max;
199 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { 203 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
200 mw->resize(s); 204 mw->resize(s);
201 mw->move(p); 205 mw->move(p);
202 } else { //no stored rectangle, make an estimation 206 } else { //no stored rectangle, make an estimation
203 int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2; 207 int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2;
204 int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2; 208 int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2;
205 mw->move( QMAX(x,0), QMAX(y,0) ); 209 mw->move( QMAX(x,0), QMAX(y,0) );
206#ifdef Q_WS_QWS 210#ifdef Q_WS_QWS
207 if ( !nomaximize ) 211 if ( !nomaximize )
208 mw->showMaximized(); 212 mw->showMaximized();
209#endif 213#endif
210 } 214 }
211 if ( max && !nomaximize ) 215 if ( max && !nomaximize )
212 mw->showMaximized(); 216 mw->showMaximized();
213 else 217 else
214 mw->show(); 218 mw->show();
215 } 219 }
216 } 220 }
217 } 221 }
218// // ugly hack, remove that later after finding a sane solution 222// // ugly hack, remove that later after finding a sane solution
219// // Addendum: Only Sharp currently has models with high resolution but (physically) small displays, 223// // Addendum: Only Sharp currently has models with high resolution but (physically) small displays,
220// // so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has 224// // so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has
221// // a (physically) large enough display to use the small icons 225// // a (physically) large enough display to use the small icons
222// #if defined(OPIE_HIGH_RES_SMALL_PHY) 226// #if defined(OPIE_HIGH_RES_SMALL_PHY)
223// if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) { 227// if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) {
224// ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true ); 228// ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true );
225// } 229// }
226// #endif 230// #endif
227 231
228 // if ( mw->layout() && mw->inherits("QDialog") ) { 232 // if ( mw->layout() && mw->inherits("QDialog") ) {
229 // QPEApplication::showDialog((QDialog*)mw, nomaximize); 233 // QPEApplication::showDialog((QDialog*)mw, nomaximize);
230 // } 234 // }
231 // else { 235 // else {
232// #ifdef Q_WS_QWS 236// #ifdef Q_WS_QWS
233 // if ( !nomaximize ) { 237 // if ( !nomaximize ) {
234 // qDebug("QDialog special case XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); 238 // qDebug("QDialog special case XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
235 // mw->showMaximized(); 239 // mw->showMaximized();
236 // //QPEApplication::showWidget( mw, !nomaximize ); 240 // //QPEApplication::showWidget( mw, !nomaximize );
237 // }else 241 // }else
238// #endif 242// #endif
239 // mw->show(); 243 // mw->show();
240 // } 244 // }
241 //} 245 //}
242 246
243 247
244static void qpe_show_dialog( QDialog* d, bool nomax ) 248static void qpe_show_dialog( QDialog* d, bool nomax )
245{ 249{
246 QSize sh = d->sizeHint(); 250 QSize sh = d->sizeHint();
@@ -257,169 +261,169 @@ static void qpe_show_dialog( QDialog* d, bool nomax )
257#endif 261#endif
258 262
259 int maxX = s.width() - (d->frameGeometry().width() - d->geometry().width()); 263 int maxX = s.width() - (d->frameGeometry().width() - d->geometry().width());
260 int maxY = s.height() - (d->frameGeometry().height() - d->geometry().height()); 264 int maxY = s.height() - (d->frameGeometry().height() - d->geometry().height());
261 265
262 if ( (w >= maxX && h >= maxY) || ( (!nomax) && ( w > s.width()*3/4 || h > s.height()*3/4 ) ) ) { 266 if ( (w >= maxX && h >= maxY) || ( (!nomax) && ( w > s.width()*3/4 || h > s.height()*3/4 ) ) ) {
263 d->showMaximized(); 267 d->showMaximized();
264 } else { 268 } else {
265 // try centering the dialog around its parent 269 // try centering the dialog around its parent
266 QPoint p(0,0); 270 QPoint p(0,0);
267 if ( d->parentWidget() ) { 271 if ( d->parentWidget() ) {
268 QPoint pp = d->parentWidget()->mapToGlobal( QPoint(0,0) ); 272 QPoint pp = d->parentWidget()->mapToGlobal( QPoint(0,0) );
269 p = QPoint( pp.x() + d->parentWidget()->width()/2, 273 p = QPoint( pp.x() + d->parentWidget()->width()/2,
270 pp.y() + d->parentWidget()->height()/ 2 ); 274 pp.y() + d->parentWidget()->height()/ 2 );
271 } else { 275 } else {
272 p = QPoint( maxX/2, maxY/2 ); 276 p = QPoint( maxX/2, maxY/2 );
273 } 277 }
274 278
275 p = QPoint( p.x() - w/2, p.y() - h/2 ); 279 p = QPoint( p.x() - w/2, p.y() - h/2 );
276 //qDebug("p(x,y) is %d %d", p.x(), p.y() ); 280 //qDebug("p(x,y) is %d %d", p.x(), p.y() );
277 281
278 if ( w >= maxX ) { 282 if ( w >= maxX ) {
279 if ( p.y() < 0 ) 283 if ( p.y() < 0 )
280 p.setY(0); 284 p.setY(0);
281 if ( p.y() + h > maxY ) 285 if ( p.y() + h > maxY )
282 p.setY( maxY - h); 286 p.setY( maxY - h);
283 287
284 d->resize(maxX, h); 288 d->resize(maxX, h);
285 d->move(0, p.y() ); 289 d->move(0, p.y() );
286 } else if ( h >= maxY ) { 290 } else if ( h >= maxY ) {
287 if ( p.x() < 0 ) 291 if ( p.x() < 0 )
288 p.setX(0); 292 p.setX(0);
289 if ( p.x() + w > maxX ) 293 if ( p.x() + w > maxX )
290 p.setX( maxX - w); 294 p.setX( maxX - w);
291 295
292 d->resize(w, maxY); 296 d->resize(w, maxY);
293 d->move(p.x(),0); 297 d->move(p.x(),0);
294 } else { 298 } else {
295 d->resize(w, h); 299 d->resize(w, h);
296 } 300 }
297 301
298 d->show(); 302 d->show();
299 } 303 }
300} 304}
301 305
302 static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s) 306 static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s)
303 { 307 {
304 maximized = TRUE; 308 maximized = TRUE;
305 309 qDebug("read_widget_rect");
306 // 350 is the trigger in qwsdefaultdecoration for providing a resize button 310 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
307 if ( qApp->desktop()->width() <= 350 ) 311 if ( qApp->desktop()->width() <= 350 )
308 return FALSE; 312 return FALSE;
309 313
310 Config cfg( "qpe" ); 314 Config cfg( "qpe" );
311 cfg.setGroup("ApplicationPositions"); 315 cfg.setGroup("ApplicationPositions");
312 QString str = cfg.readEntry( app, QString::null ); 316 QString str = cfg.readEntry( app, QString::null );
313 QStringList l = QStringList::split(",", str); 317 QStringList l = QStringList::split(",", str);
314 318
315 if ( l.count() == 5) { 319 if ( l.count() == 5) {
316 p.setX( l[0].toInt() ); 320 p.setX( l[0].toInt() );
317 p.setY( l[1].toInt() ); 321 p.setY( l[1].toInt() );
318 322
319 s.setWidth( l[2].toInt() ); 323 s.setWidth( l[2].toInt() );
320 s.setHeight( l[3].toInt() ); 324 s.setHeight( l[3].toInt() );
321 325
322 maximized = l[4].toInt(); 326 maximized = l[4].toInt();
323 327
324 return TRUE; 328 return TRUE;
325 } 329 }
326 330
327 return FALSE; 331 return FALSE;
328 } 332 }
329 333
330 334
331 static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) 335 static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s)
332 { 336 {
333#ifndef Q_WS_QWS 337#ifndef Q_WS_QWS
334 QRect qt_maxWindowRect = qApp->desktop()->geometry(); 338 QRect qt_maxWindowRect = qApp->desktop()->geometry();
335#endif 339#endif
336 int maxX = qt_maxWindowRect.width(); 340 int maxX = qt_maxWindowRect.width();
337 int maxY = qt_maxWindowRect.height(); 341 int maxY = qt_maxWindowRect.height();
338 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); 342 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() );
339 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); 343 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() );
340 344
341 // total window size is not allowed to be larger than desktop window size 345 // total window size is not allowed to be larger than desktop window size
342 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) 346 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) )
343 return FALSE; 347 return FALSE;
344 348
345 if ( wWidth > maxX ) { 349 if ( wWidth > maxX ) {
346 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); 350 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) );
347 wWidth = maxX; 351 wWidth = maxX;
348 } 352 }
349 353
350 if ( wHeight > maxY ) { 354 if ( wHeight > maxY ) {
351 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); 355 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) );
352 wHeight = maxY; 356 wHeight = maxY;
353 } 357 }
354 358
355 // any smaller than this and the maximize/close/help buttons will be overlapping 359 // any smaller than this and the maximize/close/help buttons will be overlapping
356 if ( wWidth < 80 || wHeight < 60 ) 360 if ( wWidth < 80 || wHeight < 60 )
357 return FALSE; 361 return FALSE;
358 362
359 if ( p.x() < 0 ) 363 if ( p.x() < 0 )
360 p.setX(0); 364 p.setX(0);
361 if ( p.y() < 0 ) 365 if ( p.y() < 0 )
362 p.setY(0); 366 p.setY(0);
363 367
364 if ( p.x() + wWidth > maxX ) 368 if ( p.x() + wWidth > maxX )
365 p.setX( maxX - wWidth ); 369 p.setX( maxX - wWidth );
366 if ( p.y() + wHeight > maxY ) 370 if ( p.y() + wHeight > maxY )
367 p.setY( maxY - wHeight ); 371 p.setY( maxY - wHeight );
368 372
369 return TRUE; 373 return TRUE;
370 } 374 }
371 375
372 static void store_widget_rect(QWidget *w, QString &app) 376 static void store_widget_rect(QWidget *w, QString &app)
373 { 377 {
374 // 350 is the trigger in qwsdefaultdecoration for providing a resize button 378 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
375 if ( qApp->desktop()->width() <= 350 ) 379 if ( qApp->desktop()->width() <= 350 )
376 return; 380 return;
377 381 qDebug("store_widget_rect");
378 // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to 382 // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to
379 // get the non-maximized version, so we have to do it the hard way ) 383 // get the non-maximized version, so we have to do it the hard way )
380 int offsetX = w->x() - w->geometry().left(); 384 int offsetX = w->x() - w->geometry().left();
381 int offsetY = w->y() - w->geometry().top(); 385 int offsetY = w->y() - w->geometry().top();
382 386
383 QRect r; 387 QRect r;
384 if ( w->isMaximized() ) 388 if ( w->isMaximized() )
385 r = ( (HackWidget *) w)->normalGeometry(); 389 r = ( (HackWidget *) w)->normalGeometry();
386 else 390 else
387 r = w->geometry(); 391 r = w->geometry();
388 392
389 // Stores the window placement as pos(), size() (due to the offset mapping) 393 // Stores the window placement as pos(), size() (due to the offset mapping)
390 Config cfg( "qpe" ); 394 Config cfg( "qpe" );
391 cfg.setGroup("ApplicationPositions"); 395 cfg.setGroup("ApplicationPositions");
392 QString s; 396 QString s;
393 s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); 397 s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() );
394 cfg.writeEntry( app, s ); 398 cfg.writeEntry( app, s );
395 } 399 }
396 400
397 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 401 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
398 { 402 {
399 /* 403 /*
400 // This works but disable it for now until it is safe to apply 404 // This works but disable it for now until it is safe to apply
401 // What is does is scan the .desktop files of all the apps for 405 // What is does is scan the .desktop files of all the apps for
402 // the applnk that has the corresponding argv[0] as this program 406 // the applnk that has the corresponding argv[0] as this program
403 // then it uses the name stored in the .desktop file as the caption 407 // then it uses the name stored in the .desktop file as the caption
404 // for the main widget. This saves duplicating translations for 408 // for the main widget. This saves duplicating translations for
405 // the app name in the program and in the .desktop files. 409 // the app name in the program and in the .desktop files.
406 410
407 AppLnkSet apps( appsPath ); 411 AppLnkSet apps( appsPath );
408 412
409 QList<AppLnk> appsList = apps.children(); 413 QList<AppLnk> appsList = apps.children();
410 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 414 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
411 if ( (*it)->exec() == appName ) { 415 if ( (*it)->exec() == appName ) {
412 mw->setCaption( (*it)->name() ); 416 mw->setCaption( (*it)->name() );
413 return TRUE; 417 return TRUE;
414 } 418 }
415 } 419 }
416 */ 420 */
417 return FALSE; 421 return FALSE;
418 } 422 }
419 423
420 424
421 void show(QWidget* mw, bool nomax) 425 void show(QWidget* mw, bool nomax)
422 { 426 {
423 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 427 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
424 nomaximize = nomax; 428 nomaximize = nomax;
425 qpe_main_widget = mw; 429 qpe_main_widget = mw;