summaryrefslogtreecommitdiffstats
path: root/examples/declarative/loader/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/declarative/loader/main.cpp')
-rw-r--r--examples/declarative/loader/main.cpp118
1 files changed, 117 insertions, 1 deletions
diff --git a/examples/declarative/loader/main.cpp b/examples/declarative/loader/main.cpp
index 762212b..070ba75 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,20 +112,75 @@ 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);
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();
}