summaryrefslogtreecommitdiffstats
path: root/tools/qmlviewer
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2009-10-27 05:46:40 (GMT)
committerBea Lam <bea.lam@nokia.com>2009-10-27 05:46:40 (GMT)
commitf2c0f63c2db21e3a0dd2fb78312084a835840be8 (patch)
tree2d54cc4b04864f30637bf7267799cd1bd38f35b6 /tools/qmlviewer
parent07bdaf208962b1c8605736f30920f4e6dfb0418e (diff)
parenta8fb485e1f2a7c2d6de913a2f0b3809b95c47e36 (diff)
downloadQt-f2c0f63c2db21e3a0dd2fb78312084a835840be8.zip
Qt-f2c0f63c2db21e3a0dd2fb78312084a835840be8.tar.gz
Qt-f2c0f63c2db21e3a0dd2fb78312084a835840be8.tar.bz2
Merge branch 'kinetic-declarativeui' of scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'tools/qmlviewer')
-rw-r--r--tools/qmlviewer/qmlviewer.cpp103
-rw-r--r--tools/qmlviewer/qmlviewer.h5
2 files changed, 63 insertions, 45 deletions
diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp
index 60fa13a..3aeb0da 100644
--- a/tools/qmlviewer/qmlviewer.cpp
+++ b/tools/qmlviewer/qmlviewer.cpp
@@ -310,6 +310,7 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags)
canvas->setFocus();
QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize)));
+ QObject::connect(canvas, SIGNAL(initialSize(QSize)), this, SLOT(adjustSizeSlot()));
QObject::connect(canvas, SIGNAL(errors(QList<QmlError>)), this, SLOT(executeErrors()));
if (!(flags & Qt::FramelessWindowHint))
@@ -335,6 +336,11 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags)
recordTimer.setRepeating(true);
}
+void QmlViewer::adjustSizeSlot()
+{
+ adjustSize();
+}
+
QMenuBar *QmlViewer::menuBar() const
{
if (!mb)
@@ -363,7 +369,7 @@ void QmlViewer::createMenu(QMenuBar *menu, QMenu *flatmenu)
QMenu *recordMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Recording"));
- QAction *snapshotAction = new QAction(tr("&Take Snapsot\tF3"), parent);
+ QAction *snapshotAction = new QAction(tr("&Take Snapshot\tF3"), parent);
connect(snapshotAction, SIGNAL(triggered()), this, SLOT(takeSnapShot()));
recordMenu->addAction(snapshotAction);
@@ -600,14 +606,17 @@ void QmlViewer::addLibraryPath(const QString& lib)
void QmlViewer::reload()
{
- openQml(currentFileName);
+ openQml(currentFileOrUrl);
}
void QmlViewer::open()
{
- QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), currentFileName, tr("QML Files (*.qml)"));
- if (!fileName.isEmpty())
- openQml(fileName);
+ QString cur = canvas->url().toLocalFile();
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), cur, tr("QML Files (*.qml)"));
+ if (!fileName.isEmpty()) {
+ QFileInfo fi(fileName);
+ openQml(fi.absoluteFilePath());
+ }
}
void QmlViewer::executeErrors()
@@ -615,55 +624,63 @@ void QmlViewer::executeErrors()
if (tester) tester->executefailure();
}
-void QmlViewer::openQml(const QString& fileName)
+void QmlViewer::openQml(const QString& file_or_url)
{
- setWindowTitle(tr("%1 - Qt Declarative UI Viewer").arg(fileName));
+ currentFileOrUrl = file_or_url;
+
+ QUrl url;
+ QFileInfo fi(file_or_url);
+ if (fi.exists())
+ url = QUrl::fromLocalFile(fi.absoluteFilePath());
+ else
+ url = QUrl(file_or_url);
+ setWindowTitle(tr("%1 - Qt Declarative UI Viewer").arg(file_or_url));
if (!m_script.isEmpty())
tester = new QFxTester(m_script, m_scriptOptions, canvas);
canvas->reset();
- currentFileName = fileName;
- QUrl url(fileName);
- QFileInfo fi(fileName);
- if (fi.exists()) {
- if (fi.suffix().toLower() != QLatin1String("qml")) {
- qWarning() << "qmlviewer cannot open non-QML file" << fileName;
- return;
- }
+ QString fileName = url.toLocalFile();
+ if (!fileName.isEmpty()) {
+ QFileInfo fi(fileName);
+ if (fi.exists()) {
+ if (fi.suffix().toLower() != QLatin1String("qml")) {
+ qWarning() << "qmlviewer cannot open non-QML file" << fileName;
+ return;
+ }
- url = QUrl::fromLocalFile(fi.absoluteFilePath());
- QmlContext *ctxt = canvas->rootContext();
- QDir dir(fi.path()+"/dummydata", "*.qml");
- QStringList list = dir.entryList();
- for (int i = 0; i < list.size(); ++i) {
- QString qml = list.at(i);
- QFile f(dir.filePath(qml));
- f.open(QIODevice::ReadOnly);
- QByteArray data = f.readAll();
- QmlComponent comp(canvas->engine());
- comp.setData(data, QUrl());
- QObject *dummyData = comp.create();
-
- if(comp.isError()) {
- QList<QmlError> errors = comp.errors();
- foreach (const QmlError &error, errors) {
- qWarning() << error;
+ QmlContext *ctxt = canvas->rootContext();
+ QDir dir(fi.path()+"/dummydata", "*.qml");
+ QStringList list = dir.entryList();
+ for (int i = 0; i < list.size(); ++i) {
+ QString qml = list.at(i);
+ QFile f(dir.filePath(qml));
+ f.open(QIODevice::ReadOnly);
+ QByteArray data = f.readAll();
+ QmlComponent comp(canvas->engine());
+ comp.setData(data, QUrl());
+ QObject *dummyData = comp.create();
+
+ if(comp.isError()) {
+ QList<QmlError> errors = comp.errors();
+ foreach (const QmlError &error, errors) {
+ qWarning() << error;
+ }
+ if (tester) tester->executefailure();
}
- if (tester) tester->executefailure();
- }
- if (dummyData) {
- qWarning() << "Loaded dummy data:" << dir.filePath(qml);
- qml.truncate(qml.length()-4);
- ctxt->setContextProperty(qml, dummyData);
- dummyData->setParent(this);
+ if (dummyData) {
+ qWarning() << "Loaded dummy data:" << dir.filePath(qml);
+ qml.truncate(qml.length()-4);
+ ctxt->setContextProperty(qml, dummyData);
+ dummyData->setParent(this);
+ }
}
+ } else {
+ qWarning() << "qmlviewer cannot find file:" << fileName;
+ return;
}
- } else {
- qWarning() << "qmlviewer cannot find file:" << fileName;
- return;
}
canvas->setUrl(url);
@@ -677,7 +694,7 @@ void QmlViewer::openQml(const QString& fileName)
canvas->updateGeometry();
if (mb)
mb->updateGeometry();
- resize(sizeHint());
+ adjustSize();
} else {
if (scaleSkin)
canvas->resize(canvas->sizeHint());
diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h
index 7f9dca0..e1f53f9 100644
--- a/tools/qmlviewer/qmlviewer.h
+++ b/tools/qmlviewer/qmlviewer.h
@@ -63,7 +63,7 @@ public:
public slots:
void sceneResized(QSize size);
- void openQml(const QString& fileName);
+ void openQml(const QString&);
void open();
void reload();
void takeSnapShot();
@@ -88,15 +88,16 @@ private slots:
void chooseRecordingOptions();
void pickRecordingFile();
void setScaleSkin();
+ void adjustSizeSlot();
private:
void setupProxy();
QString getVideoFileName();
- QString currentFileName;
PreviewDeviceSkin *skin;
QSize skinscreensize;
QmlView *canvas;
+ QString currentFileOrUrl;
QmlTimer recordTimer;
QString frame_fmt;
QImage frame;