diff options
author | Yann Bodson <yann.bodson@nokia.com> | 2009-05-07 00:32:34 (GMT) |
---|---|---|
committer | Yann Bodson <yann.bodson@nokia.com> | 2009-05-07 00:32:34 (GMT) |
commit | 71601dfd3cf877e14796b7304f1bcc9e01248476 (patch) | |
tree | a45a85c131f066ad4ec3e85e3d2058c9f84b5a5b /tools/qmlviewer | |
parent | 46c8be899a5e11030d174ac569bb7e77ab0b00a9 (diff) | |
download | Qt-71601dfd3cf877e14796b7304f1bcc9e01248476.zip Qt-71601dfd3cf877e14796b7304f1bcc9e01248476.tar.gz Qt-71601dfd3cf877e14796b7304f1bcc9e01248476.tar.bz2 |
Add simple menubar to qmlviewer.
Diffstat (limited to 'tools/qmlviewer')
-rw-r--r-- | tools/qmlviewer/main.cpp | 1 | ||||
-rw-r--r-- | tools/qmlviewer/qmlviewer.cpp | 50 | ||||
-rw-r--r-- | tools/qmlviewer/qmlviewer.h | 6 |
3 files changed, 47 insertions, 10 deletions
diff --git a/tools/qmlviewer/main.cpp b/tools/qmlviewer/main.cpp index 26ff213..b588111 100644 --- a/tools/qmlviewer/main.cpp +++ b/tools/qmlviewer/main.cpp @@ -18,7 +18,6 @@ #include "qfxtestengine.h" #include <QApplication> - void usage() { qWarning("Usage: qmlviewer [options] <filename>"); diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 094d779..dbbe233 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -32,10 +32,14 @@ #include <QFileInfo> #include <QVBoxLayout> #include <QProcess> +#include <QMenuBar> #include <QMenu> +#include <QAction> +#include <QFileDialog> +#include <QTimer> QmlViewer::QmlViewer(QFxTestEngine::TestMode testMode, const QString &testDir, QWidget *parent, Qt::WindowFlags flags) - : QWidget(parent, flags), frame_stream(0) + : QMainWindow(parent, flags), frame_stream(0) { testEngine = 0; devicemode = false; @@ -44,10 +48,12 @@ QmlViewer::QmlViewer(QFxTestEngine::TestMode testMode, const QString &testDir, Q record_autotime = 0; record_period = 20; - int width=240; - int height=320; + int width = 240; + int height = 320; + setAttribute(Qt::WA_OpaquePaintEvent); setAttribute(Qt::WA_NoSystemBackground); + createMenuBar(); canvas = new QFxView(this); if(testMode != QFxTestEngine::NoTest) @@ -56,6 +62,27 @@ QmlViewer::QmlViewer(QFxTestEngine::TestMode testMode, const QString &testDir, Q QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize))); canvas->setFixedSize(width, height); resize(width, height); + setCentralWidget(canvas); +} + +void QmlViewer::createMenuBar() +{ + QMenu *fileMenu = menuBar()->addMenu(tr("&File")); + + QAction *openAction = new QAction(tr("&Open..."), this); + openAction->setShortcut(QKeySequence("Ctrl+O")); + connect(openAction, SIGNAL(triggered()), this, SLOT(open())); + fileMenu->addAction(openAction); + + QAction *reloadAction = new QAction(tr("&Reload"), this); + reloadAction->setShortcut(QKeySequence("Ctrl+R")); + connect(reloadAction, SIGNAL(triggered()), this, SLOT(reload())); + fileMenu->addAction(reloadAction); + + QMenu *helpMenu = menuBar()->addMenu(tr("&Help")); + QAction *aboutAction = new QAction(tr("&About Qt..."), this); + connect(aboutAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); + helpMenu->addAction(aboutAction); } void QmlViewer::reload() @@ -63,6 +90,15 @@ void QmlViewer::reload() openQml(currentFileName); } +void QmlViewer::open() +{ + QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), "", tr("QML Files (*.qml)")); + if (!fileName.isEmpty()) { + openQml(fileName); + QTimer::singleShot(0, this, SLOT(reload())); + } +} + void QmlViewer::openQml(const QString& fileName) { setWindowTitle(tr("%1 - Qt Declarative UI Viewer").arg(fileName)); @@ -187,7 +223,6 @@ void PreviewDeviceSkin::populateContextMenu(QMenu *menu) connect(menu->addAction(tr("&Close")), SIGNAL(triggered()), parentWidget(), SLOT(close())); } - void QmlViewer::setSkin(const QString& skinDirectory) { DeviceSkinParameters parameters; @@ -239,10 +274,11 @@ void QmlViewer::sceneResized(QSize size) } } -void QmlViewer::resizeEvent(QResizeEvent *) +void QmlViewer::resizeEvent(QResizeEvent *e) { - if (!skin) - canvas->setFixedSize(width(),height()); + QMainWindow::resizeEvent(e); + //if (!skin) + //canvas->setFixedSize(width(),height()); } void QmlViewer::keyPressEvent(QKeyEvent *event) diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index fc65ebf..b4117a2 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -14,7 +14,7 @@ #ifndef QMLVIEWER_H #define QMLVIEWER_H -#include <QWidget> +#include <QMainWindow> #include <QBasicTimer> #include <QTime> #include <qfxtestengine.h> @@ -25,12 +25,13 @@ class QFxView; class PreviewDeviceSkin; class QFxTestEngine; -class QmlViewer : public QWidget +class QmlViewer : public QMainWindow { Q_OBJECT public: QmlViewer(QFxTestEngine::TestMode = QFxTestEngine::NoTest, const QString &testDir = QString(), QWidget *parent=0, Qt::WindowFlags flags=0); + void createMenuBar(); void setRecordDither(const QString& s) { record_dither = s; } void setRecordPeriod(int ms); void setRecordFile(const QString&); @@ -45,6 +46,7 @@ public: public slots: void sceneResized(QSize size); void openQml(const QString& fileName); + void open(); void reload(); protected: |