diff options
-rw-r--r-- | tools/qmlviewer/content/Browser.qml | 4 | ||||
-rw-r--r-- | tools/qmlviewer/main.cpp | 30 | ||||
-rw-r--r-- | tools/qmlviewer/qmlfolderlistmodel.cpp | 24 | ||||
-rw-r--r-- | tools/qmlviewer/qmlviewer.cpp | 77 | ||||
-rw-r--r-- | tools/qmlviewer/qmlviewer.h | 11 |
5 files changed, 115 insertions, 31 deletions
diff --git a/tools/qmlviewer/content/Browser.qml b/tools/qmlviewer/content/Browser.qml index ce9aed2..7643a57 100644 --- a/tools/qmlviewer/content/Browser.qml +++ b/tools/qmlviewer/content/Browser.qml @@ -11,12 +11,12 @@ Rectangle { FolderListModel { id: folders1 nameFilters: [ "*.qml" ] - folder: initialFolder + folder: qmlViewerFolder } FolderListModel { id: folders2 nameFilters: [ "*.qml" ] - folder: initialFolder + folder: qmlViewerFolder } SystemPalette { id: palette } diff --git a/tools/qmlviewer/main.cpp b/tools/qmlviewer/main.cpp index 34e5060..412d3ef 100644 --- a/tools/qmlviewer/main.cpp +++ b/tools/qmlviewer/main.cpp @@ -48,19 +48,11 @@ #include <QDebug> #if defined (Q_OS_SYMBIAN) -#define SYMBIAN_NETWORK_INIT +#include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include <unistd.h> -#endif -#if defined (SYMBIAN_NETWORK_INIT) -#include <QTextCodec> -#include "sym_iap_util.h" -#endif - -#if defined (Q_OS_SYMBIAN) void myMessageOutput(QtMsgType type, const char *msg) { static int fd = -1; @@ -149,7 +141,6 @@ int main(int argc, char ** argv) QApplication::setGraphicsSystem("raster"); #endif - QApplication app(argc, argv); app.setApplicationName("viewer"); app.setOrganizationName("Nokia"); @@ -176,6 +167,12 @@ int main(int argc, char ** argv) bool fullScreen = false; bool stayOnTop = false; bool maximized = false; + bool useNativeFileBrowser = true; + +#if defined(Q_OS_SYMBIAN) + maximized = true; + useNativeFileBrowser = false; +#endif for (int i = 1; i < argc; ++i) { bool lastArg = (i == argc - 1); @@ -258,7 +255,7 @@ int main(int argc, char ** argv) Qt::WFlags wflags = (frameless ? Qt::FramelessWindowHint : Qt::Widget); if (stayOnTop) wflags |= Qt::WindowStaysOnTopHint; - + QmlViewer viewer(0, wflags); if (!scriptopts.isEmpty()) { QStringList options = @@ -299,10 +296,6 @@ int main(int argc, char ** argv) usage(); } -#if defined(SYMBIAN_NETWORK_INIT) - qt_SetDefaultIap(); -#endif - viewer.setUseGL(useGL); foreach (QString lib, libraries) viewer.addLibraryPath(lib); @@ -328,14 +321,19 @@ int main(int argc, char ** argv) viewer.setRecordDither(dither); if (recordargs.count()) viewer.setRecordArgs(recordargs); + + viewer.setUseNativeFileBrowser(useNativeFileBrowser); if (fullScreen && maximized) qWarning() << "Both -fullscreen and -maximized specified. Using -fullscreen."; if (!fileName.isEmpty()) { viewer.openQml(fileName); fullScreen ? viewer.showFullScreen() : maximized ? viewer.showMaximized() : viewer.show(); } else { + if (!useNativeFileBrowser) + viewer.open(); fullScreen ? viewer.showFullScreen() : maximized ? viewer.showMaximized() : viewer.show(); - viewer.open(); + if (useNativeFileBrowser) + viewer.open(); } viewer.raise(); diff --git a/tools/qmlviewer/qmlfolderlistmodel.cpp b/tools/qmlviewer/qmlfolderlistmodel.cpp index 14d2324..4cbc426 100644 --- a/tools/qmlviewer/qmlfolderlistmodel.cpp +++ b/tools/qmlviewer/qmlfolderlistmodel.cpp @@ -193,11 +193,25 @@ void QmlFolderListModel::setFolder(const QUrl &folder) QUrl QmlFolderListModel::parentFolder() const { - int pos = d->folder.path().lastIndexOf(QLatin1Char('/')); - if (pos == -1) - return QUrl(); - QUrl r = d->folder; - r.setPath(d->folder.path().left(pos)); + QUrl r; + QString localFile = d->folder.toLocalFile(); + if (!localFile.isEmpty()) { + QDir dir(localFile); +#if defined(Q_OS_SYMBIAN) + if (dir.isRoot()) + dir.setPath(""); + else +#endif + dir.cdUp(); + r = d->folder; + r.setPath(dir.path()); + } else { + int pos = d->folder.path().lastIndexOf(QLatin1Char('/')); + if (pos == -1) + return QUrl(); + r = d->folder; + r.setPath(d->folder.path().left(pos)); + } return r; } diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 8d8d66a..1811327 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -82,6 +82,19 @@ #include <qfxtester.h> +#if defined (Q_OS_SYMBIAN) +#define SYMBIAN_NETWORK_INIT +#endif + +#if defined (SYMBIAN_NETWORK_INIT) +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> +#include <QTextCodec> +#include "sym_iap_util.h" +#endif + QT_BEGIN_NAMESPACE @@ -327,7 +340,12 @@ QString QmlViewer::getVideoFileName() QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) - : QWidget(parent, flags), frame_stream(0), scaleSkin(true), mb(0) +#if defined(Q_OS_SYMBIAN) + : QMainWindow(parent, flags) +#else + : QWidget(parent, flags) +#endif + , frame_stream(0), scaleSkin(true), mb(0) , portraitOrientation(0), landscapeOrientation(0) , m_scriptOptions(0), tester(0), useQmlFileBrowser(true) { @@ -374,6 +392,7 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) setPortrait(); } +#if !defined(Q_OS_SYMBIAN) QVBoxLayout *layout = new QVBoxLayout; layout->setMargin(0); layout->setSpacing(0); @@ -381,6 +400,9 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) if (mb) layout->addWidget(mb); layout->addWidget(canvas); +#else + setCentralWidget(canvas); +#endif setupProxy(); canvas->engine()->networkAccessManager()->setCookieJar(new PersistentCookieJar(this)); @@ -401,8 +423,12 @@ void QmlViewer::adjustSizeSlot() QMenuBar *QmlViewer::menuBar() const { +#if !defined(Q_OS_SYMBIAN) if (!mb) mb = new SizedMenuBar((QWidget*)this, canvas); +#else + mb = QMainWindow::menuBar(); +#endif return mb; } @@ -423,6 +449,13 @@ void QmlViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) connect(reloadAction, SIGNAL(triggered()), this, SLOT(reload())); fileMenu->addAction(reloadAction); +#if defined(Q_OS_SYMBIAN) + QAction *networkAction = new QAction(tr("Start &Network"), parent); + connect(networkAction, SIGNAL(triggered()), this, SLOT(startNetwork())); + fileMenu->addAction(networkAction); +#endif + +#if !defined(Q_OS_SYMBIAN) if (flatmenu) flatmenu->addSeparator(); QMenu *recordMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Recording")); @@ -498,13 +531,21 @@ void QmlViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) connect(mapper, SIGNAL(mapped(QString)), this, SLOT(setSkin(QString))); if (flatmenu) flatmenu->addSeparator(); +#endif // Q_OS_SYMBIAN QMenu *settingsMenu = flatmenu ? flatmenu : menu->addMenu(tr("S&ettings")); QAction *proxyAction = new QAction(tr("Http &proxy..."), parent); connect(proxyAction, SIGNAL(triggered()), this, SLOT(showProxySettings())); settingsMenu->addAction(proxyAction); +#if !defined(Q_OS_SYMBIAN) if (!flatmenu) settingsMenu->addAction(recordOptions); +#else + QAction *fullscreenAction = new QAction(tr("Full Screen"), parent); + fullscreenAction->setCheckable(true); + connect(fullscreenAction, SIGNAL(triggered()), this, SLOT(toggleFullScreen())); + settingsMenu->addAction(fullscreenAction); +#endif QMenu *propertiesMenu = new QMenu(tr("Properties")); QActionGroup *orientation = new QActionGroup(parent); @@ -568,6 +609,14 @@ void QmlViewer::setLandscape() landscapeOrientation->setChecked(true); } +void QmlViewer::toggleFullScreen() +{ + if (isFullScreen()) + showMaximized(); + else + showFullScreen(); +} + void QmlViewer::setScaleSkin() { if (scaleSkin) @@ -715,11 +764,6 @@ void QmlViewer::open() { QString cur = canvas->url().toLocalFile(); if (useQmlFileBrowser) { -#ifdef Q_OS_SYMBIAN - canvas->rootContext()->setContextProperty("initialFolder", "E:\\"); // Documents on your S60 phone -#else - canvas->rootContext()->setContextProperty("initialFolder", QDir::currentPath()); -#endif openQml("qrc:/content/Browser.qml"); } else { QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), cur, tr("QML Files (*.qml)")); @@ -758,6 +802,11 @@ void QmlViewer::openQml(const QString& file_or_url) canvas->reset(); QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("qmlViewer", this); +#ifdef Q_OS_SYMBIAN + ctxt->setContextProperty("qmlViewerFolder", "E:\\"); // Documents on your S60 phone +#else + ctxt->setContextProperty("qmlViewerFolder", QDir::currentPath()); +#endif QString fileName = url.toLocalFile(); if (!fileName.isEmpty()) { @@ -811,7 +860,8 @@ void QmlViewer::openQml(const QString& file_or_url) canvas->updateGeometry(); if (mb) mb->updateGeometry(); - resize(sizeHint()); + if (!isFullScreen() && !isMaximized()) + resize(sizeHint()); } else { if (scaleSkin) canvas->resize(canvas->sizeHint()); @@ -826,6 +876,13 @@ void QmlViewer::openQml(const QString& file_or_url) #endif } +void QmlViewer::startNetwork() +{ +#if defined(SYMBIAN_NETWORK_INIT) + qt_SetDefaultIap(); +#endif +} + QStringList QmlViewer::builtinSkins() const { QDir dir(":/skins/","*.skin"); @@ -1237,6 +1294,12 @@ void QmlViewer::setUseGL(bool useGL) } #endif } + +void QmlViewer::setUseNativeFileBrowser(bool use) +{ + useQmlFileBrowser = !use; +} + QT_END_NAMESPACE #include "qmlviewer.moc" diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index c7d5c24..717258c 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -42,6 +42,7 @@ #ifndef QMLVIEWER_H #define QMLVIEWER_H +#include <QMainWindow> #include <QMenuBar> #include <private/qmltimer_p.h> #include <QTime> @@ -56,7 +57,12 @@ class QProcess; class RecordingDialog; class QmlGraphicsTester; -class QmlViewer : public QWidget +class QmlViewer +#if defined(Q_OS_SYMBIAN) + : public QMainWindow +#else + : public QWidget +#endif { Q_OBJECT public: @@ -85,6 +91,7 @@ public: void setNetworkCacheSize(int size); void addLibraryPath(const QString& lib); void setUseGL(bool use); + void setUseNativeFileBrowser(bool); QStringList builtinSkins() const; @@ -122,6 +129,8 @@ private slots: void adjustSizeSlot(); void setPortrait(); void setLandscape(); + void startNetwork(); + void toggleFullScreen(); private: void setupProxy(); |