📄 qpeapplication.cpp
字号:
#endif } else if ( msg == "reload()" ) { emit reload(); } else if ( msg == "setDocument(QString)" ) { d->keep_running = TRUE; QDataStream stream( data, IO_ReadOnly ); QString doc; stream >> doc; QWidget *mw = mainWidget(); if ( !mw ) mw = d->qpe_main_widget; if ( mw ) Global::setDocument( mw, doc ); } else if ( msg == "timeChange(QString)" ) { // Same as the QPE/System message if ( d->skiptimechanged ) { // Was handled in pidMessage() // (ie. we must offer TimeMonitor service) --d->skiptimechanged; } else { QDataStream stream( data, IO_ReadOnly ); QString t; stream >> t; if ( t.isNull() ) unsetenv( "TZ" ); else setenv( "TZ", t.latin1(), 1 ); // emit the signal so everyone else knows... emit timeChanged(); } } else if ( msg == "QPEProcessQCop()") { processQCopFile(); d->sendQCopQ(); } else { bool p = d->keep_running; d->keep_running = FALSE; emit appMessage( msg, data); if ( d->keep_running ) { d->notbusysent = FALSE; raiseAppropriateWindow(); if ( !p ) { // Tell the system we're still chugging along...#ifndef QT_NO_COP QCopEnvelope e("QPE/System", "appRaised(QString)"); e << d->appName;#endif } } if ( p ) d->keep_running = p; }#endif}/*! Sets widget \a mw as the mainWidget() and shows it. For small windows, consider passing TRUE for \a nomaximize rather than the default FALSE. \sa showMainDocumentWidget()*/void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ){ d->show(mw,nomaximize);}/*! Sets widget \a mw as the mainWidget() and shows it. For small windows, consider passing TRUE for \a nomaximize rather than the default FALSE. This calls designates the application as a \link docwidget.html document-oriented\endlink application. The \a mw widget \e must have this slot: setDocument(const QString&). \sa showMainWidget()*/void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ){#ifdef Q_WS_QWS if ( mw && argc() == 2 ) Global::setDocument( mw, QString::fromUtf8(argv()[1]) );#endif d->show(mw,nomaximize);}/*! If an application is started via a \link qcop.html QCop\endlink message, the application will process the \link qcop.html QCop\endlink message and then quit. If the application calls this function while processing a \link qcop.html QCop\endlink message, after processing its outstanding \link qcop.html QCop\endlink messages the application will start 'properly' and show itself. \sa keepRunning()*/void QPEApplication::setKeepRunning(){ if ( qApp && qApp->inherits( "QPEApplication" ) ) { QPEApplication *qpeApp = (QPEApplication*)qApp; qpeApp->d->keep_running = TRUE; }}/*! Returns TRUE if the application will quit after processing the current list of qcop messages; otherwise returns FALSE. \sa setKeepRunning()*/bool QPEApplication::keepRunning() const{ return d->keep_running;}/*! \internal*/void QPEApplication::internalSetStyle( const QString &style ){#ifdef Q_WS_QWS if ( style == d->styleName ) return; QStyle *newStyle = 0;#if QT_VERSION >= 0x030000 if ( style == "QPE" || style == "Qtopia" ) { newStyle = new QPEStyle; } else { newStyle = QStyleFactory::create(style); }#else StyleInterface *oldIface = d->styleIface; d->styleIface = 0; if ( style == "Windows" ) { // No tr newStyle = new QWindowsStyle; } else if ( style == "QPE" || style == "Qtopia" ) { newStyle = new QPEStyle; } else { if ( !d->styleLoader.inSafeMode() && d->styleLoader.isEnabled( style ) ) { StyleInterface *iface = 0; if ( d->styleLoader.queryInterface( style, IID_Style, (QUnknownInterface**)&iface ) == QS_OK && iface ) { newStyle = iface->style(); d->styleIface = iface; } } }#endif if ( !newStyle ) { newStyle = new QPEStyle; d->styleName = "QPE"; } else { d->styleName = style; } setStyle( newStyle );#if QT_VERSION < 0x030000 // cleanup old plugin. if ( oldIface ) d->styleLoader.releaseInterface( oldIface );#endif#endif}/*! \internal*/void QPEApplication::prepareForTermination(bool willrestart){ if ( willrestart ) { // Draw a big wait icon, the image can be altered in later revisions// QWidget *d = QApplication::desktop(); QPixmap pix;#ifdef Q_WS_QWS pix = Resource::loadPixmap("bigwait");#else //### revise add a different pix map qDebug("Missing pixmap : QPEApplication::prepareForTermination()");#endif QLabel *lblWait = new QLabel(0, "wait hack!", QWidget::WStyle_Customize | // No tr QWidget::WStyle_NoBorder | QWidget::WStyle_Tool | QWidget::WStyle_StaysOnTop | QWidget::WDestructiveClose ); lblWait->setPixmap( pix ); lblWait->setAlignment( QWidget::AlignCenter ); lblWait->setGeometry( desktop()->geometry() ); lblWait->show(); QTimer::singleShot( 5000, lblWait, SLOT(close()) ); // If we don't restart we want to get this out of the way }#ifndef SINGLE_APP#ifndef QT_NO_COP { QCopEnvelope envelope("QPE/System", "forceQuit()"); }#endif processEvents(); // ensure the message goes out.#ifndef Q_OS_WIN32 sleep(1); // You have 1 second to comply.#else Sleep(1000);#endif#endif}/*! \internal*/void QPEApplication::shutdown(){ // Implement in server's QPEApplication subclass}/*! \internal*/void QPEApplication::restart(){ // Implement in server's QPEApplication subclass}static QPtrDict<void>* stylusDict=0;static void createDict(){ if ( !stylusDict ) stylusDict = new QPtrDict<void>;}/*! Returns the current StylusMode for widget \a w. \sa setStylusOperation() StylusMode*/QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w ){ if ( stylusDict ) return (StylusMode)(int)stylusDict->find(w); return LeftOnly;}/*! \enum QPEApplication::StylusMode \value LeftOnly the stylus only generates LeftButton events (the default). \value RightOnHold the stylus generates RightButton events if the user uses the press-and-hold gesture. \sa setStylusOperation() stylusOperation()*//*! Causes widget \a w to receive mouse events according to the stylus \a mode. \sa stylusOperation() StylusMode*/void QPEApplication::setStylusOperation( QWidget* w, StylusMode mode ){ createDict(); if ( mode == LeftOnly ) { stylusDict->remove(w); } else { stylusDict->insert(w,(void*)mode); connect(w,SIGNAL(destroyed()),qApp,SLOT(removeSenderFromStylusDict())); }}/*! \reimp*/bool QPEApplication::eventFilter( QObject *o, QEvent *e ){ if ( !o->isWidgetType() ) return FALSE; if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { QMouseEvent* me = (QMouseEvent*)e; StylusMode mode = (StylusMode)(int)stylusDict->find(o); switch (mode) { case RightOnHold: switch ( me->type() ) { case QEvent::MouseButtonPress: if ( me->button() == LeftButton ) { if ( !d->presstimer ) d->presstimer = startTimer(500); // #### pref. d->presswidget = (QWidget*)o; d->presspos = me->pos(); d->rightpressed = FALSE; } break; case QEvent::MouseMove: if (d->presstimer && (me->pos()-d->presspos).manhattanLength() > 8) { killTimer(d->presstimer); d->presstimer = 0; } break; case QEvent::MouseButtonRelease: if ( me->button() == LeftButton ) { if ( d->presstimer ) { killTimer(d->presstimer); d->presstimer = 0; } if ( d->rightpressed && d->presswidget ) { // Right released postEvent( d->presswidget, new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), RightButton, LeftButton+RightButton ) ); // Left released, off-widget postEvent( d->presswidget, new QMouseEvent( QEvent::MouseMove, QPoint(-1,-1), LeftButton, LeftButton ) ); postEvent( d->presswidget, new QMouseEvent( QEvent::MouseButtonRelease, QPoint(-1,-1), LeftButton, LeftButton ) ); d->rightpressed = FALSE; return TRUE; // don't send the real Left release } } break; default: break; } break; default: ; } } else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { QKeyEvent *ke = (QKeyEvent *)e; if ( ke->key() == Key_Enter ) { if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); return TRUE; } } } return FALSE;}/*! \reimp*/void QPEApplication::timerEvent( QTimerEvent *e ){ if ( e->timerId() == d->presstimer && d->presswidget ) { // Right pressed postEvent( d->presswidget, new QMouseEvent( QEvent::MouseButtonPress, d->presspos, RightButton, LeftButton ) ); killTimer( d->presstimer ); d->presstimer = 0; d->rightpressed = TRUE; }}void QPEApplication::removeSenderFromStylusDict(){ stylusDict->remove((void*)sender()); if ( d->presswidget == sender() ) d->presswidget = 0;}/*! \internal*/bool QPEApplication::keyboardGrabbed() const{ return d->kbgrabber;}/*! Reverses the effect of grabKeyboard(). This is called automatically on program exit.*/void QPEApplication::ungrabKeyboard(){ QPEApplicationData* d = ((QPEApplication*)qApp)->d; if ( d->kbgrabber == 2 ) {#ifndef QT_NO_COP QCopEnvelope e("QPE/System", "grabKeyboard(QString)" ); e << QString::null;#endif d->kbregrab = FALSE; d->kbgrabber = 0; }}/*! Grabs the physical keyboard keys, e.g. the application's launching keys. Instead of launching applications when these keys are pressed the signals emitted are sent to this application instead. Some games programs take over the launch keys in this way to make interaction easier. \sa ungrabKeyboard()*/void QPEApplication::grabKeyboard(){ QPEApplicationData* d = ((QPEApplication*)qApp)->d; if ( qApp->type() == QApplication::GuiServer ) d->kbgrabber = 0; else {#ifndef QT_NO_COP QCopEnvelope e("QPE/System", "grabKeyboard(QString)" ); e << d->appName;#endif d->kbgrabber = 2; // me }}/*! \reimp*/int QPEApplication::exec(){ d->execCalled = TRUE;#ifndef QT_NO_COP d->sendQCopQ(); if ( !d->keep_running ) processEvents(); // we may have received QCop messages in the meantime.#endif if ( d->keep_running) //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) return QApplication::exec();#ifndef QT_NO_COP { QCopEnvelope e("QPE/System", "closing(QString)" ); e << d->appName; }#endif processEvents(); return 0;}/*! \internal External request for application to quit. Quits if possible without loosing state.*/void QPEApplication::tryQuit(){ if ( activeModalWidget() || strcmp( argv()[0], "embeddedkonsole") == 0 ) return; // Inside modal loop or konsole. Too hard to save state.#ifndef QT_NO_COP { QCopEnvelope e("QPE/System", "closing(QString)" ); e << d->appName; }#endif if ( d->keep_running ) d->store_widget_rect(d->qpe_main_widget, d->appName); processEvents(); quit();}/*! \internal User initiated quit. Makes the window 'Go Away'. If preloaded this means hiding the window. If not it means quitting the application. As this is user initiated we don't need to check state.*/void QPEApplication::hideOrQuit(){ if ( d->keep_running ) d->store_widget_rect(d->qpe_main_widget, d->appName); processEvents(); // If we are a preloaded application we don't actually quit, so emit // a System message indicating we're quasi-closing. if ( d->preloaded && d->qpe_main_widget ) {#ifndef QT_NO_COP QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); e << d->appName;#endif d->qpe_main_widget->hide(); } else { quit(); }}#ifdef Q_WS_QWSextern PluginLibraryManager *pluginLibraryManagerInstanceIntern();#endifvoid QPEApplication::pluginLibraryManager( PluginLibraryManager **m ){#ifdef Q_WS_QWS *m = pluginLibraryManagerInstanceIntern();#else *m = 0;#endif}/*! \fn void QPEApplication::showDialog( QDialog* dialog, bool nomax ) Shows \a dialog. An heuristic approach is taken to determine the size and maximization of the dialog. \a nomax forces it to not be maximized.*//*! \fn int QPEApplication::execDialog( QDialog* dialog, bool nomax ) Shows and calls exec() on \a dialog. An heuristic approach is taken to determine the size and maximization of the dialog. \a nomax forces it to not be maximized.*/#if (__GNUC__ > 2)extern "C" void __cxa_pure_virtual();void __cxa_pure_virtual(){ fprintf( stderr, "Pure virtual called\n"); // No tr abort();}#endif#if defined(QPE_USE_MALLOC_FOR_NEW)// The libraries with the skiff package (and possibly others) have// completely useless implementations of builtin new and delete that// use about 50% of your CPU. Here we revert to the simple libc// functions.void* operator new[](size_t size){ return malloc(size);}void* operator new(size_t size){ return malloc(size);}void operator delete[](void* p){ free(p);}void operator delete[](void* p, size_t /*size*/){ free(p);}void operator delete(void* p){ free(p);}void operator delete(void* p, size_t /*size*/){ free(p);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -