📄 qpeapplication.cpp
字号:
\list \i "email" \i "netmask" \i "url"\endlist The effect in the phone key input method is to modify the binding of phone keys to characters (such as making "@" easier to input), and to add additional "words" to the recognition word lists (such as "www"). If the current input method doesn't understand the hint, it will be ignored. \sa inputMethodHint() InputMethodHint*/void QPEApplication::setInputMethodHint( QWidget *w, const QString& named ){ setInputMethodHint(w,Named,named);}/*! Hints to the system that widget \a w has use for text input methods as specified by \a mode. \sa inputMethodHint() InputMethodHint*/void QPEApplication::setInputMethodHint( QWidget* w, InputMethodHint mode, const QString& param ){ createInputMethodDict(); if ( mode == Normal ) { inputMethodDict->remove(w); } else { InputMethodHintRec *r = inputMethodDict->find(w); if ( r ) { r->hint = mode; r->param = param; } else { r = new InputMethodHintRec(mode,param); inputMethodDict->replace(w,r); } }#ifdef QTOPIA_INTERNAL_SENDINPUTHINT if ( w->hasFocus() ) sendInputHintFor(w,QEvent::None);#endif}class HackDialog : public QDialog{public: void acceptIt() { qDebug("hack accept"); accept(); } void rejectIt() { reject(); }};void QPEApplication::mapToDefaultAction( QWSKeyEvent *ke, int key ){ // specialised actions for certain widgets. May want to // add more stuff here. if ( activePopupWidget() && activePopupWidget()->inherits( "QListBox" ) && activePopupWidget()->parentWidget() && activePopupWidget()->parentWidget()->inherits( "QComboBox" ) ) key = Qt::Key_Return; if ( activePopupWidget() && activePopupWidget()->inherits( "QPopupMenu" ) ) key = Qt::Key_Return;#ifdef Q_WS_QWS ke->simpleData.keycode = key;#else Q_UNUSED( ke );#endif}#ifdef Q_WS_QWS/*! Filters Qt event \a e to implement Qtopia-specific functionality.*/bool QPEApplication::qwsEventFilter( QWSEvent *e ){ if ( type() == GuiServer ) { switch ( e->type ) { case QWSEvent::Mouse: if ( e->asMouse()->simpleData.state && !QWidget::find(e->window()) ) emit clientMoused(); } } if ( e->type == QWSEvent::Key ) { if ( d->kbgrabber == 1 ) return TRUE; QWSKeyEvent *ke = (QWSKeyEvent *)e;#ifndef QTOPIA_PHONE if ( ke->simpleData.keycode == Qt::Key_F33 ) { // Use special "OK" key to press "OK" on top level widgets QWidget *active = activeWindow(); QWidget *popup = 0; if ( active && active->isPopup() ) { popup = active; active = active->parentWidget(); } if ( active && (int)active->winId() == ke->simpleData.window && !active->testWFlags( WStyle_Customize|WType_Popup|WType_Desktop )) { if ( ke->simpleData.is_press ) { if ( popup ) popup->close(); if ( active->inherits( "QDialog" ) ) { HackDialog *d = (HackDialog *)active;#ifdef QTOPIA_PHONE if (isMenuLike(d)) d->rejectIt(); else#endif d->acceptIt(); return TRUE; } else if ( ((HackWidget *)active)->needsOk() ) { QSignal s; s.connect( active, SLOT( accept() ) ); s.activate(); } else { // do the same as with the select key: Map to the default action of the widget: mapToDefaultAction( ke, Qt::Key_Return ); } } } } else if ( ke->simpleData.keycode == Qt::Key_F30 ) { // Use special "select" key to do whatever default action a widget has mapToDefaultAction( ke, Qt::Key_Space ); } else if ( ke->simpleData.keycode == Qt::Key_Escape && ke->simpleData.is_press ) { // Escape key closes app if focus on toplevel QWidget *active = activeWindow(); if ( active && active->testWFlags( WType_TopLevel ) && (int)active->winId() == ke->simpleData.window && !active->testWFlags( WStyle_Dialog|WStyle_Customize|WType_Popup|WType_Desktop )) { if ( active->inherits( "QDialog" ) ) { HackDialog *d = (HackDialog *)active; d->rejectIt(); return TRUE; } else if ( strcmp( argv()[0], "embeddedkonsole") != 0 ) { active->close(); } } }#else# ifdef QT_QWS_SL5XXX if ( ke->simpleData.keycode == Qt::Key_F33 ) ke->simpleData.keycode = Qt::Key_Back; else if (ke->simpleData.keycode == Qt::Key_F30) ke->simpleData.keycode = Qt::Key_Select; else if (ke->simpleData.keycode == Qt::Key_Escape) ke->simpleData.keycode = Qt::Key_Back;# endif if (ke->simpleData.keycode == Qt::Key_Back || ke->simpleData.keycode == Qt::Key_No) { QWidget *active = activeWindow(); QWidget *popup = 0; if ( active && active->isPopup() ) { popup = active; active = active->parentWidget(); } else if (active) { // If the focus widget (or parent) requires the context key // then we can't close the dialog. QWidget *focus = active->focusWidget(); if (focus) { QWidget *tw = ContextKeyManager::instance() ->findTargetWidget(focus, ke->simpleData.keycode, (mousePreferred || focus->isModalEditing()) ); if ( tw && tw != active ) active = 0; } } if ( active && (int)active->winId() == ke->simpleData.window && !active->testWFlags( WStyle_Customize|WType_Popup|WType_Desktop )) { if ( ke->simpleData.is_press ) { if ( popup ) popup->close(); bool qt_singleFocusWidget(const QWidget *in); // qwidget.cpp if ( active->inherits( "QDialog" ) && (mousePreferred || (!active->editingWidget() || qt_singleFocusWidget(active->editingWidget()))) && ke->simpleData.keycode != Qt::Key_No && active->testWFlags(WType_Modal)) { HackDialog *d = (HackDialog *)active; if (isMenuLike(d)) { d->rejectIt(); } else { d->acceptIt(); } return TRUE; } } } }#endif#if QT_VERSION < 231 // Filter out the F4/Launcher key from apps // ### The launcher key may not always be F4 on all devices if ( ((QWSKeyEvent *)e)->simpleData.keycode == Qt::Key_F4 ) return TRUE;#endif } else if ( e->type == QWSEvent::Focus ) { if ( !d->notbusysent ) { if ( qApp->type() != QApplication::GuiServer ) {#ifndef QT_NO_COP QCopEnvelope e("QPE/System", "notBusy(QString)" ); e << d->appName;#endif } d->notbusysent=TRUE; } QWSFocusEvent *fe = (QWSFocusEvent*)e; QWidget* nfw = QWidget::find(e->window()); if ( !fe->simpleData.get_focus ) { QWidget *active = activeWindow(); while ( active && active->isPopup() ) { active->close(); active = activeWindow(); } if ( !nfw && d->kbgrabber == 2 ) { ungrabKeyboard(); d->kbregrab = TRUE; // want kb back when we're active } } else { // make sure our modal widget is ALWAYS on top QWidget *topm = activeModalWidget(); if ( topm && (int)topm->winId() != fe->simpleData.window) { topm->raise(); } if ( d->kbregrab ) { grabKeyboard(); d->kbregrab = FALSE; } } if ( fe->simpleData.get_focus && inputMethodDict ) { InputMethodHint m = inputMethodHint( QWidget::find(e->window()) ); if ( m == AlwaysOff ) Global::hideInputMethod(); if ( m == AlwaysOn ) Global::showInputMethod(); } } return QApplication::qwsEventFilter( e );}#endif/*! Destroys the QPEApplication.*/QPEApplication::~QPEApplication(){ if ( !d->notbusysent ) { // maybe we didn't map a window - still tell the server we're not // busy anymore. if ( qApp->type() != QApplication::GuiServer ) {#ifndef QT_NO_COP QCopEnvelope e("QPE/System", "notBusy(QString)" ); e << d->appName;#endif } } ungrabKeyboard();#if defined(Q_WS_QWS) && !defined(QT_NO_COP) // Need to delete QCopChannels early, since the display will // be gone by the time we get to ~QObject(). delete sysChannel; delete pidChannel;#endif#ifdef QTOPIA_PHONE delete d->editMenu;#endif delete d;}/*! Returns \c{$QPEDIR/}.*/QString QPEApplication::qpeDir(){#ifdef QTOPIA_DESKTOP return gQtopiaDesktopConfig->installedDir();#endif#ifdef Q_WS_QWS return *global_qtopiapaths().begin();#endif // Q_WS_QWS}/*! Returns the user's current Document directory. There is a trailing "/".*/QString QPEApplication::documentDir(){ QString r = ::qtopia_internal_homeDirPath(); QString base = r; if (base.length() > 0){ return base + "/Documents/"; } return QString( "../Documents/" );}static int deforient=-1;/*! \internal*/int QPEApplication::defaultRotation(){ if ( deforient < 0 ) { QString d = getenv("QWS_DISPLAY"); Config config("qpe"); config.setGroup( "Rotation" ); d = config.readEntry("Screen", d); if ( d.contains("Rot90") ) { // No tr deforient = 90; } else if ( d.contains("Rot180") ) { // No tr deforient = 180; } else if ( d.contains("Rot270") ) { // No tr deforient = 270; } else { deforient=0; } } return deforient;}/*! \internal*/#ifdef Q_WS_QWSextern int qws_display_id;#endif/*! Rotates Qtopia by \a r degrees. */void QPEApplication::setDefaultRotation(int r){ if ( qApp->type() == GuiServer ) { deforient = r;#if defined(Q_WS_QWS) && !defined(Q_OS_WIN32) setenv("QWS_DISPLAY", QString("Transformed:Rot%1:%2").arg(r).arg(qws_display_id).latin1(), 1);#endif Config config("qpe"); config.setGroup( "Rotation" ); config.writeEntry( "Screen", getenv("QWS_DISPLAY") ); } else {#ifndef QT_NO_COP QCopEnvelope("QPE/System", "setDefaultRotation(int)") << r;#endif }}#define setPaletteEntry(pal, cfg, role, defaultVal) \ setPalEntry(pal, cfg, #role, QColorGroup::role, defaultVal)static void setPalEntry( QPalette &pal, const Config &config, const QString &entry, QColorGroup::ColorRole role, const QString &defaultVal ){ QString value = ((Config*)&config)-> // FIX in Qtopia 4 (no need to cast) readEntry( entry, defaultVal ); if ( value[0] == '#' ) pal.setColor( role, QColor(value) ); else { QPixmap pix;#ifdef SIZE_WALLPAPER_TO_DESKTOP_SIZE // Disabled at the moment QSize siz = qApp->desktop()->size(); int wid = siz.width(), h = siz.height(); pix = Resource::loadImage(value).smoothScale(wid,h);#endif pix = Resource::loadPixmap(value); pal.setBrush( role, QBrush(QColor(defaultVal), pix) ); }}/*! \internal*/void QPEApplication::applyStyle(){#ifdef Q_WS_QWS QString styleName; Config config( "qpe" ); config.setGroup( "Appearance" );#ifdef QTOPIA_PHONE QString theme = config.readEntry("Theme", "qtopia.conf"); QString themeDir = QPEApplication::qpeDir() + "etc/themes/"; theme = theme.replace(QRegExp("\\.desktop"), ".conf"); // backwards compat if (theme.isEmpty() || !QFile::exists(themeDir + theme)) theme = "qtopia.conf"; Config themeCfg(themeDir + theme, Config::File); themeCfg.setGroup("Theme"); // Update the icon path bool iconsChanged = FALSE; QStringList extraPath = qpe_pathCache[Resource::PixResource]; if (d->iconPath.count()) { // remove paths that the last theme set QStringList::Iterator it; for (it = d->iconPath.begin(); it != d->iconPath.end(); ++it) { extraPath.remove(QPEApplication::qpeDir() + *it); extraPath.remove(*it); } iconsChanged = TRUE; } d->iconPath = themeCfg.readListEntry("IconPath", ';'); if (d->iconPath.count()) iconsChanged = TRUE; extraPath += d->iconPath; qpe_pathCache[Resource::PixResource].clear(); for (QStringList::ConstIterator prefix = extraPath.begin(); prefix!=extraPath.end(); ++prefix) { QString resourcePath = QPEApplication::qpeDir() + *prefix; if (QFile::exists(resourcePath)) { qpe_pathCache[Resource::PixResource].append(resourcePath); } else { if (QFile::exists( *prefix )) qpe_pathCache[Resource::PixResource].append( *prefix ); } } if (iconsChanged) QPixmapCache::clear(); styleName = config.readEntry( "Style", "phonestyle" );#else styleName = config.readEntry( "Style", "Qtopia" );#endif // Widget style internalSetStyle( styleName ); // Colors // This first bit is same as settings/appearence/appearence.cpp, readColorScheme() QPalette tempPal; setPaletteEntry( tempPal, config, Button, "#F0F0F0" ); setPaletteEntry( tempPal, config, Background, "#EEEEEE" ); QPalette pal( tempPal.normal().button(), tempPal.normal().background() ); setPaletteEntry( pal, config, Button, "#F0F0F0" ); setPaletteEntry( pal, config, Background, "#EEEEEE" ); setPaletteEntry( pal, config, Base, "#FFFFFF" ); setPaletteEntry( pal, config, Highlight, "#8BAF31" ); setPaletteEntry( pal, config, Foreground, "#000000" ); QString color = config.readEntry( "HighlightedText", "#FFFFFF" ); pal.setColor( QColorGroup::HighlightedText, QColor(color) ); color = config.readEntry( "Text", "#000000" ); pal.setColor( QColorGroup::Text, QColor(color) ); color = config.readEntry( "ButtonText", "#000000" ); pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor(color) ); QString val = config.readEntry( "Shadow" ); if (!val.isEmpty()) { pal.setColor( QColorGroup::Shadow, QColor(val)); } else { pal.setColor( QColorGroup::Shadow, pal.color(QPalette::Normal, QColorGroup::Button).dark(400) ); } val = config.readEntry( "Text_disabled" ); if (!val.isEmpty()) { pal.setColor( QPalette::Disabled, QColorGroup::Text, QColor(val)); } else { pal.setColor( QPalette::Disabled, QColorGroup::Text, pal.color(QPalette::Active, QColorGroup::Base).dark() ); } val = config.readEntry( "Foreground_disabled" ); if (!val.isEmpty()) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -