⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qpeapplication.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS.  All rights reserved.**** This file is part of the Qtopia Environment.** ** This program is free software; you can redistribute it and/or modify it** under the terms of the GNU General Public License as published by the** Free Software Foundation; either version 2 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** This program is distributed in the hope that it will be useful, but** WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ** See the GNU General Public License for more details.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#define QTOPIA_INTERNAL_LOADTRANSLATIONS#define QTOPIA_INTERNAL_LANGLIST#ifndef QTOPIA_INTERNAL_FILEOPERATIONS#define QTOPIA_INTERNAL_FILEOPERATIONS#endif#include <qtopia/custom.h>#include <stdlib.h>#include <qfile.h>#include <qlist.h>#include <qqueue.h>#include <qpainter.h>#include <qvalidator.h>#include <qlineedit.h>#include <qmultilineedit.h>#ifndef QTOPIA_DESKTOP#include <qsoundqss_qws.h>#endif#ifdef Q_WS_QWS#  ifndef QT_NO_COP#    if QT_VERSION <= 231#      define private public#      define sendLocally processEvent#      include <qtopia/qcopenvelope_qws.h>#      undef private#    else#      include <qtopia/qcopenvelope_qws.h>#    endif#  endif#  include <qwindowsystem_qws.h>#endif#include <qtextstream.h>#include <qpalette.h>#include <qwidgetlist.h>#include <qbuffer.h>#include <qptrdict.h>#include <qregexp.h>#include <qdir.h>#include <qlabel.h>#include <qdialog.h>#include <qdragobject.h>#include <qtextcodec.h>#include <qevent.h>#include <qtooltip.h>#include <qmessagebox.h>#include <qsignal.h>#include <qclipboard.h>#include <qtimer.h>#include <qpixmapcache.h>#include <qmessagebox.h>#include <qpushbutton.h>#include <qaccel.h>#include <qobjectlist.h>#ifdef Q_WS_QWS#define QTOPIA_INTERNAL_SENDINPUTHINT#include <qwsdisplay_qws.h>#endif#if defined(Q_WS_QWS) && !defined(QT_NO_COP)#define QTOPIA_INTERNAL_INITAPP#endif#include <qtopia/qpeapplication.h>#if QT_VERSION >= 0x030000#  include <qstylefactory.h>#else#  include <qwindowsstyle.h>#endif#include <qtopia/global.h>#if QT_VERSION <= 230 && defined(QT_NO_CODECS)#  include <qutfcodec.h>#endif#include <qtopia/config.h>#include <qtopia/storage.h>#include <qtopia/network.h>#include <qtopia/applnk.h>#include <qtopia/resource.h>#ifdef Q_WS_QWS#  include <qtopia/fontmanager.h>#  include <qtopia/fontdatabase.h>#  include <qtopia/power.h>#  include <qtopia/qpemenubar.h>#  include <qtopia/imagecodecinterface.h>#  include <qtopia/textcodecinterface.h>#  include <qtopia/styleinterface.h>#  ifdef QTOPIA_PHONE#    include <qtopia/phonestyle.h>#  else#    include <qtopia/qpestyle.h>#  endif#  include <qtopia/private/qpedecoration_p.h>#endif#include <qtopia/alarmserver.h>#include <qtopia/private/pluginloader_p.h>#ifdef Q_OS_UNIX#include <unistd.h>#include <sys/file.h>#ifdef Q_WS_QWS#include <errno.h>#include <sys/stat.h>#endif#endif#ifndef QTOPIA_DESKTOP#ifndef Q_OS_WIN32#include <sys/ioctl.h>#include <sys/soundcard.h>#else#include <mmsystem.h>#include <io.h>#include <fcntl.h>#include <sys/types.h>#include <sys/stat.h>#endif // Q_OS_WIN32#endif // QTOPIA_DESKTOP#include "../qtopia1/qpe_show_dialog.cpp"#if defined(QTOPIA_TEST)#include <asm/timex.h>#endif#ifdef QTOPIA_PHONE#include <qtopia/private/contextkeymanager_p.h>#include <qtopia/contextmenu.h>// from Resourceextern QStringList qpe_pathCache[Resource::AllResources + 1];#endifQIconSet qtopia_internal_loadIconSet( const QString &pix );#ifdef QTOPIA_PHONEextern bool qt_modalEditingEnabled;bool mousePreferred = FALSE;#endif#ifdef QTOPIA_DESKTOP#include <qdconfig.h>#endifQString qtopia_internal_homeDirPath();QString qtopia_internal_defaultButtonsFile();#ifdef QTOPIA_PHONEconst QArray<int> qpe_systemButtons(){    static QArray<int> *buttons = 0;    if (!buttons) {	buttons = new QArray<int>;	Config cfg(qtopia_internal_defaultButtonsFile(), Config::File);	cfg.setGroup("SystemButtons");	int count = cfg.readNumEntry("Count", 0);	if (count > 0) {	    buttons->resize(count);	    for (int i = 0; i < count; i++) {		QString is = QString::number(i);		(*buttons)[i] = QAccel::stringToKey(cfg.readEntry("Key"+is));	    }	}    }    return *buttons;}enum {    MenuLikeDialog = 0x01,} QPEWidgetFlags;QMap<const QWidget *, int> qpeWidgetFlags;#endif#if defined(QTOPIA_TEST)static cycles_t cycl_start, cycl_stop;#endifclass HackWidget : public QWidget{public:    bool needsOk()    {#ifndef QTOPIA_DESKTOP	return (getWState() & WState_Reserved1 );#else	return FALSE;#endif    }    QRect normalGeometry()    { return topData()->normalGeometry; };};#ifdef Q_WS_QWSextern Q_EXPORT QRect qt_maxWindowRect;#endifstatic const int npressticks=10;class QPEApplicationData {public:    QPEApplicationData() : presstimer(0), presswidget(0), rightpressed(FALSE),	kbgrabber(0), kbregrab(FALSE), notbusysent(FALSE), preloaded(FALSE),	forceshow(FALSE), nomaximize(FALSE), qpe_main_widget(0),	keep_running(TRUE), skiptimechanged(0), qcopQok(FALSE)#ifdef Q_WS_QWS	,styleLoader("styles"), styleIface(0), textPluginLoader("textcodecs"), // No tr	imagePluginLoader("imagecodecs")#endif#ifdef QTOPIA_PHONE	, editMenu(0)#endif    {    }    void drawPressTick()    {	if ( presstick < npressticks-2 ) {	    QPainter p(presswidget);	    Config cfg("presstick");	    cfg.setGroup("PressTick");	    QPixmap pm = Resource::loadPixmap(cfg.readEntry("Image"));	    cfg.setGroup("Tick"+QString::number(presstick));	    int dx = cfg.readNumEntry("Dx");	    int dy = cfg.readNumEntry("Dy");	    p.drawPixmap(presspos.x()+dx,presspos.y()+dy,pm);	    pressdirty |= QRect(presspos.x()+dx,presspos.y()+dy,pm.width(),pm.height());	}    }    void cancelPressAndHold()    {	if ( !pressdirty.isEmpty() ) {	    presswidget->repaint(pressdirty);	    pressdirty = QRect();	}	qApp->killTimer( presstimer );	presstimer = 0;    }    int presstimer;    QWidget* presswidget;    QPoint presspos;    int presstick;    QRect pressdirty;    bool rightpressed;    int kbgrabber;    bool kbregrab;    bool notbusysent;    QString appName;    struct QCopRec {	QCopRec(const QCString &ch, const QCString &msg,                               const QByteArray &d) :	    channel(ch), message(msg), data(d)	    {		channel.detach();		message.detach();		data.detach();	    }	QCString channel;	QCString message;	QByteArray data;    };    bool preloaded;    bool forceshow;    bool nomaximize;    QWidget* qpe_main_widget;    QGuardedPtr<QWidget> lastraised;    bool keep_running;    int skiptimechanged;    bool qcopQok;    QQueue<QCopRec> qcopq;    void enqueueQCop(const QCString &ch, const QCString &msg,                               const QByteArray &data)    {	qcopq.enqueue(new QCopRec(ch,msg,data));    }    void sendQCopQ()    {	if ( qcopQok ) {	    QCopRec* r;	    while((r=qcopq.dequeue())) {		// remove from queue before sending... 		// event loop can come around again before getting		// back from sendLocally#ifndef QT_NO_COP		QCopChannel::sendLocally(r->channel,r->message,r->data);#endif		delete r;	    }	}    }    static void show_mx(QWidget* mw, bool nomaximize, QString &strName)    {	if ( mw->isVisible() ) {	    mw->raise();	} else {	    QPoint p;	    QSize s;	    if ( mw->layout() && mw->inherits("QDialog") ) {		bool max;		if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {		    mw->resize(s);		    mw->move(p);		    if ( max && !nomaximize )			mw->showMaximized();		    else			mw->show();		} else {		    qpe_show_dialog((QDialog*)mw,nomaximize);		}	    } else {		bool max;		if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {		    mw->resize(s);		    mw->move(p);		} else {    //no stored rectangle, make an estimation		    int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2;		    int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2;		    mw->move( QMAX(x,0), QMAX(y,0) );#ifdef Q_WS_QWS		    if ( !nomaximize )			mw->showMaximized();#endif		}		if ( max && !nomaximize )		    mw->showMaximized();		else		    mw->show();	    }	}    }    static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s)    {	maximized = TRUE;	// 350 is the trigger in qwsdefaultdecoration for providing a resize button	if ( qApp->desktop()->width() <= 350 )	    return FALSE;	Config cfg( "qpe" );	cfg.setGroup("ApplicationPositions");	QString str = cfg.readEntry( app, QString::null );	QStringList l = QStringList::split(",", str);	if ( l.count() == 5) {	    p.setX( l[0].toInt() );	    p.setY( l[1].toInt() );	    s.setWidth( l[2].toInt() );	    s.setHeight( l[3].toInt() );	    maximized = l[4].toInt();	    return TRUE;	}	return FALSE;    }    static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s)    {#ifndef Q_WS_QWS	QRect qt_maxWindowRect = qApp->desktop()->geometry();#endif	int maxX = qt_maxWindowRect.width();	int maxY = qt_maxWindowRect.height();	int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() );	int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() );	// total window size is not allowed to be larger than desktop window size	if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) )	    return FALSE;	if ( wWidth > maxX ) {	    s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) );	    wWidth = maxX;	}	if ( wHeight > maxY ) {	    s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) );	    wHeight = maxY;	}	// any smaller than this and the maximize/close/help buttons will be overlapping	if ( wWidth < 80 || wHeight < 60 )	    return FALSE;	if ( p.x() < 0 )	    p.setX(0);	if ( p.y() < 0 )	    p.setY(0);	if ( p.x() + wWidth > maxX )	    p.setX( maxX - wWidth );	if ( p.y() + wHeight > maxY )	    p.setY( maxY - wHeight );	return TRUE;    }    static void store_widget_rect(QWidget *w, QString &app)    {	// 350 is the trigger in qwsdefaultdecoration for providing a resize button	if ( qApp->desktop()->width() <= 350 )	    return;	// we use these to map the offset of geometry and pos.  ( we can only use normalGeometry to	// get the non-maximized version, so we have to do it the hard way )	int offsetX = w->x() - w->geometry().left();	int offsetY = w->y() - w->geometry().top();	QRect r;	if ( w->isMaximized() )	    r = ( (HackWidget *) w)->normalGeometry();	else	    r = w->geometry();	// Stores the window placement as pos(), size()  (due to the offset mapping)	Config cfg( "qpe" );	cfg.setGroup("ApplicationPositions");	QString s;	s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() );	cfg.writeEntry( app, s );    }    static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )    {    /*	// This works but disable it for now until it is safe to apply	// What is does is scan the .desktop files of all the apps for	// the applnk that has the corresponding argv[0] as this program	// then it uses the name stored in the .desktop file as the caption	// for the main widget. This saves duplicating translations for	// the app name in the program and in the .desktop files.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -