diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-07-29 01:26:42 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-07-29 01:26:42 (GMT) |
commit | 707554cfe8acd115e2ee965b538d1d5fb8f82dc6 (patch) | |
tree | 46f237fe70928dc59abbc6001000013eabb9c563 /examples/declarative/loader | |
parent | 25608cd8f785ec91a86dc861fe191a1a7c716b60 (diff) | |
download | Qt-707554cfe8acd115e2ee965b538d1d5fb8f82dc6.zip Qt-707554cfe8acd115e2ee965b538d1d5fb8f82dc6.tar.gz Qt-707554cfe8acd115e2ee965b538d1d5fb8f82dc6.tar.bz2 |
loader improvements.
Diffstat (limited to 'examples/declarative/loader')
-rw-r--r-- | examples/declarative/loader/loader.qrc | 1 | ||||
-rw-r--r-- | examples/declarative/loader/main.cpp | 118 |
2 files changed, 118 insertions, 1 deletions
diff --git a/examples/declarative/loader/loader.qrc b/examples/declarative/loader/loader.qrc index bdbcd5c..73ee253 100644 --- a/examples/declarative/loader/loader.qrc +++ b/examples/declarative/loader/loader.qrc @@ -4,5 +4,6 @@ <file>Browser.qml</file> <file>images/fileopen.png</file> <file>images/up.png</file> + <file>Button.qml</file> </qresource> </RCC> diff --git a/examples/declarative/loader/main.cpp b/examples/declarative/loader/main.cpp index aa86f8f..fd02b6a 100644 --- a/examples/declarative/loader/main.cpp +++ b/examples/declarative/loader/main.cpp @@ -2,6 +2,12 @@ #include <QUrl> #include <QFileInfo> #include <QDir> +#include <QPlainTextEdit> +#include <QAction> +#include <QVBoxLayout> +#include <QMainWindow> +#include <QMenuBar> +#include <QDebug> #include <QmlContext> #include <QmlComponent> #include <qfxview.h> @@ -9,6 +15,61 @@ QFxView *canvas = 0; +class Logger : public QWidget +{ + Q_OBJECT +public: + Logger() : QWidget() { + logText = new QPlainTextEdit; + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(logText); + layout->setMargin(0); + setLayout(layout); +#ifdef Q_OS_SYMBIAN + QAction *closeAction = new QAction("Close", this); + closeAction->setSoftKeyRole(QAction::BackSoftKey); + connect(closeAction, SIGNAL(triggered()), this, SLOT(close())); + + QList<QAction*> softKeys; + softKeys.append(closeAction); + setSoftKeys(softKeys); +#endif + } + + void append(const QString &text) { + logText->appendPlainText(text); + } + + static Logger *instance() { + static Logger *logger = 0; + if (!logger) + logger = new Logger(); + return logger; + } + +private: + QPlainTextEdit *logText; +}; + +void myMessageOutput(QtMsgType type, const char *msg) +{ + switch (type) { + case QtDebugMsg: + Logger::instance()->append(QString(msg)); + break; + case QtWarningMsg: + Logger::instance()->append(QString(msg)); + break; + case QtCriticalMsg: + Logger::instance()->append(QString(msg)); + break; + case QtFatalMsg: + Logger::instance()->append(QString(msg)); + abort(); + } +} + + class QmlLauncher : public QObject { Q_OBJECT @@ -51,21 +112,76 @@ public: canvas->setUrl(fileName); canvas->execute(); } + +signals: + void logUpdated(); +}; + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + MainWindow() : QMainWindow() {} + + +public slots: + void toggleFullScreen() + { + if (isFullScreen()) { +#ifdef Q_OS_SYMBIAN + showMaximized(); +#else + showNormal(); +#endif + } else { + showFullScreen(); + } + } + + void showLog() + { +#ifdef Q_OS_SYMBIAN + Logger::instance()->showMaximized(); +#else + Logger::instance()->show(); +#endif + } }; + int main(int argc, char *argv[]) { + qInstallMsgHandler(myMessageOutput); QApplication app(argc, argv); + MainWindow *mw = new MainWindow; + QmlLauncher *launcher = new QmlLauncher; + QObject::connect(Logger::instance(), SIGNAL(textChanged()), launcher, SIGNAL(logUpdated())); + canvas = new QFxView; + mw->setCentralWidget(canvas); + + QMenuBar *mb = mw->menuBar(); + QAction *showLogAction = new QAction("View Log...", mw); + mb->addAction(showLogAction); + QObject::connect(showLogAction, SIGNAL(triggered()), mw, SLOT(showLog())); + QAction *toggleFSAction = new QAction("Fullscreen", mw); + mb->addAction(toggleFSAction); + QObject::connect(toggleFSAction, SIGNAL(triggered()), mw, SLOT(toggleFullScreen())); + QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("qmlLauncher", launcher); ctxt->setContextProperty("activePalette", new QmlPalette); canvas->setUrl(QUrl("qrc:/loader.qml")); +#ifdef Q_OS_SYMBIAN + canvas->setContentResizable(true); + mw->showMaximized(); +#else + mw->show(); +#endif canvas->execute(); - canvas->show(); return app.exec(); } |