diff options
Diffstat (limited to 'tools/qml')
-rw-r--r-- | tools/qml/Info_mac.plist | 2 | ||||
-rw-r--r-- | tools/qml/content/Browser.qml | 6 | ||||
-rw-r--r-- | tools/qml/loggerwidget.cpp | 120 | ||||
-rw-r--r-- | tools/qml/loggerwidget.h | 32 | ||||
-rw-r--r-- | tools/qml/main.cpp | 79 | ||||
-rw-r--r-- | tools/qml/qdeclarativefolderlistmodel.cpp | 5 | ||||
-rw-r--r-- | tools/qml/qdeclarativefolderlistmodel.h | 1 | ||||
-rw-r--r-- | tools/qml/qml.icns | bin | 0 -> 196156 bytes | |||
-rw-r--r-- | tools/qml/qml.pri | 8 | ||||
-rw-r--r-- | tools/qml/qml.pro | 5 | ||||
-rw-r--r-- | tools/qml/qmlruntime.cpp | 386 | ||||
-rw-r--r-- | tools/qml/qmlruntime.h | 29 |
12 files changed, 339 insertions, 334 deletions
diff --git a/tools/qml/Info_mac.plist b/tools/qml/Info_mac.plist index ce4ebe3..80ca6a3 100644 --- a/tools/qml/Info_mac.plist +++ b/tools/qml/Info_mac.plist @@ -2,6 +2,8 @@ <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> <plist version="0.1"> <dict> + <key>CFBundleIconFile</key> + <string>@ICON@</string> <key>CFBundleIdentifier</key> <string>com.nokia.qt.qml</string> <key>CFBundlePackageType</key> diff --git a/tools/qml/content/Browser.qml b/tools/qml/content/Browser.qml index 0912f58..c3a2cc0 100644 --- a/tools/qml/content/Browser.qml +++ b/tools/qml/content/Browser.qml @@ -12,12 +12,12 @@ Rectangle { FolderListModel { id: folders1 nameFilters: [ "*.qml" ] - folder: qmlViewerFolder + folder: qmlLauncherFolder } FolderListModel { id: folders2 nameFilters: [ "*.qml" ] - folder: qmlViewerFolder + folder: qmlLauncherFolder } SystemPalette { id: palette } @@ -62,7 +62,7 @@ Rectangle { if (folders.isFolder(index)) { down(filePath); } else { - qmlViewer.launch(filePath); + qmlLauncher.launch(filePath); } } width: root.width diff --git a/tools/qml/loggerwidget.cpp b/tools/qml/loggerwidget.cpp index 9eca4a6..3ae2b5e 100644 --- a/tools/qml/loggerwidget.cpp +++ b/tools/qml/loggerwidget.cpp @@ -42,29 +42,141 @@ #include "loggerwidget.h" #include <qglobal.h> #include <QDebug> +#include <QSettings> +#include <QActionGroup> +#include <QMenu> QT_BEGIN_NAMESPACE LoggerWidget::LoggerWidget(QWidget *parent) : QPlainTextEdit(parent), - m_keepClosed(false) + m_visibilityOrigin(SettingsOrigin) { setAttribute(Qt::WA_QuitOnClose, false); - setWindowTitle(tr("Logger")); + setWindowTitle(tr("Warnings")); + + readSettings(); + setupPreferencesMenu(); } void LoggerWidget::append(const QString &msg) { appendPlainText(msg); - if (!m_keepClosed && !isVisible()) + if (!isVisible() && (defaultVisibility() == AutoShowWarnings)) setVisible(true); } +LoggerWidget::Visibility LoggerWidget::defaultVisibility() const +{ + return m_visibility; +} + +void LoggerWidget::setDefaultVisibility(LoggerWidget::Visibility visibility) +{ + if (m_visibility == visibility) + return; + + m_visibility = visibility; + m_visibilityOrigin = CommandLineOrigin; + + m_preferencesMenu->setEnabled(m_visibilityOrigin == SettingsOrigin); +} + +QMenu *LoggerWidget::preferencesMenu() +{ + return m_preferencesMenu; +} + +QAction *LoggerWidget::showAction() +{ + return m_showWidgetAction; +} + +void LoggerWidget::readSettings() +{ + QSettings settings; + QString warningsPreferences = settings.value("warnings", "hide").toString(); + if (warningsPreferences == "show") { + m_visibility = ShowWarnings; + } else if (warningsPreferences == "hide") { + m_visibility = HideWarnings; + } else { + m_visibility = AutoShowWarnings; + } +} + +void LoggerWidget::saveSettings() +{ + if (m_visibilityOrigin != SettingsOrigin) + return; + + QString value = "autoShow"; + if (defaultVisibility() == ShowWarnings) { + value = "show"; + } else if (defaultVisibility() == HideWarnings) { + value = "hide"; + } + + QSettings settings; + settings.setValue("warnings", value); +} + +void LoggerWidget::warningsPreferenceChanged(QAction *action) +{ + Visibility newSetting = static_cast<Visibility>(action->data().toInt()); + m_visibility = newSetting; + saveSettings(); +} + +void LoggerWidget::showEvent(QShowEvent *event) +{ + QWidget::showEvent(event); + emit opened(); +} + void LoggerWidget::closeEvent(QCloseEvent *event) { - m_keepClosed = true; QWidget::closeEvent(event); + emit closed(); +} + +void LoggerWidget::setupPreferencesMenu() +{ + m_preferencesMenu = new QMenu(tr("Warnings")); + QActionGroup *warnings = new QActionGroup(m_preferencesMenu); + warnings->setExclusive(true); + + connect(warnings, SIGNAL(triggered(QAction*)), this, SLOT(warningsPreferenceChanged(QAction*))); + + QAction *showWarningsPreference = new QAction(tr("Show by default"), m_preferencesMenu); + showWarningsPreference->setCheckable(true); + showWarningsPreference->setData(LoggerWidget::ShowWarnings); + warnings->addAction(showWarningsPreference); + m_preferencesMenu->addAction(showWarningsPreference); + + QAction *hideWarningsPreference = new QAction(tr("Hide by default"), m_preferencesMenu); + hideWarningsPreference->setCheckable(true); + hideWarningsPreference->setData(LoggerWidget::HideWarnings); + warnings->addAction(hideWarningsPreference); + m_preferencesMenu->addAction(hideWarningsPreference); + + QAction *autoWarningsPreference = new QAction(tr("Show for first warning"), m_preferencesMenu); + autoWarningsPreference->setCheckable(true); + autoWarningsPreference->setData(LoggerWidget::AutoShowWarnings); + warnings->addAction(autoWarningsPreference); + m_preferencesMenu->addAction(autoWarningsPreference); + + switch (defaultVisibility()) { + case LoggerWidget::ShowWarnings: + showWarningsPreference->setChecked(true); + break; + case LoggerWidget::HideWarnings: + hideWarningsPreference->setChecked(true); + break; + default: + autoWarningsPreference->setChecked(true); + } } QT_END_NAMESPACE diff --git a/tools/qml/loggerwidget.h b/tools/qml/loggerwidget.h index 5c4a701..fd20c41 100644 --- a/tools/qml/loggerwidget.h +++ b/tools/qml/loggerwidget.h @@ -50,14 +50,44 @@ class LoggerWidget : public QPlainTextEdit { Q_OBJECT public: LoggerWidget(QWidget *parent=0); + + enum Visibility { ShowWarnings, HideWarnings, AutoShowWarnings }; + + Visibility defaultVisibility() const; + void setDefaultVisibility(Visibility visibility); + + QMenu *preferencesMenu(); + QAction *showAction(); + public slots: void append(const QString &msg); + +private slots: + void warningsPreferenceChanged(QAction *action); + void readSettings(); + void saveSettings(); + protected: + void showEvent(QShowEvent *event); void closeEvent(QCloseEvent *event); + +signals: + void opened(); + void closed(); + private: - bool m_keepClosed; + void setupPreferencesMenu(); + + QMenu *m_preferencesMenu; + QAction *m_showWidgetAction; + + enum ConfigOrigin { CommandLineOrigin, SettingsOrigin }; + ConfigOrigin m_visibilityOrigin; + Visibility m_visibility; }; QT_END_NAMESPACE +Q_DECLARE_METATYPE(LoggerWidget::Visibility) + #endif // LOGGERWIDGET_H diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 9ccc3d2..380f5cc 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -54,7 +54,7 @@ QT_USE_NAMESPACE -QtMsgHandler systemMsgOutput; +QtMsgHandler systemMsgOutput = 0; #if defined (Q_OS_SYMBIAN) #include <unistd.h> @@ -86,7 +86,7 @@ QString warnings; void showWarnings() { if (!warnings.isEmpty()) { - QMessageBox::warning(0, QApplication::tr("Qt Declarative UI Runtime"), warnings); + QMessageBox::warning(0, QApplication::tr("Qt QML Launcher"), warnings); } } @@ -118,14 +118,11 @@ void usage() qWarning(" -frameless ............................... run with no window frame"); qWarning(" -maximized................................ run maximized"); qWarning(" -fullscreen............................... run fullscreen"); - qWarning(" -stayontop................................ keep viewer window on top"); - qWarning(" -skin <qvfbskindir> ...................... run with a skin window frame"); - qWarning(" \"list\" for a list of built-ins"); - qWarning(" -resizeview .............................. resize the view, not the skin"); + qWarning(" -stayontop................................ keep launcher window on top"); qWarning(" -sizeviewtorootobject .................... the view resizes to the changes in the content"); qWarning(" -sizerootobjecttoview .................... the content resizes to the changes in the view"); qWarning(" -qmlbrowser .............................. use a QML-based file browser"); - qWarning(" -nolog ................................... do not show log window"); + qWarning(" -warnings [show|hide]..................... show warnings in a separate log window"); qWarning(" -recordfile <output> ..................... set video recording file"); qWarning(" - ImageMagick 'convert' for GIF)"); qWarning(" - png file for raw frames"); @@ -160,14 +157,16 @@ void scriptOptsUsage() qWarning(" testerror ................................ test 'error' property of root item on playback"); qWarning(" snapshot ................................. file being recorded is static,"); qWarning(" only one frame will be recorded or tested"); - qWarning(" exitoncomplete ........................... cleanly exit the viewer on script completion"); - qWarning(" exitonfailure ............................ immediately exit the viewer on script failure"); - qWarning(" saveonexit ............................... save recording on viewer exit"); + qWarning(" exitoncomplete ........................... cleanly exit the launcher on script completion"); + qWarning(" exitonfailure ............................ immediately exit the launcher on script failure"); + qWarning(" saveonexit ............................... save recording on launcher exit"); qWarning(" "); qWarning(" One of record, play or both must be specified."); exit(1); } +enum WarningsConfig { ShowWarnings, HideWarnings, DefaultWarnings }; + int main(int argc, char ** argv) { #if defined (Q_OS_SYMBIAN) @@ -198,7 +197,7 @@ int main(int argc, char ** argv) #endif QApplication app(argc, argv); - app.setApplicationName("QtQmlRuntime"); + app.setApplicationName("QtQmlLauncher"); app.setOrganizationName("Nokia"); app.setOrganizationDomain("nokia.com"); @@ -207,7 +206,6 @@ int main(int argc, char ** argv) QDeclarativeFolderListModel::registerTypes(); bool frameless = false; - bool resizeview = false; QString fileName; double fps = 0; int autorecord_from = 0; @@ -217,7 +215,6 @@ int main(int argc, char ** argv) QStringList recordargs; QStringList imports; QStringList plugins; - QString skin; QString script; QString scriptopts; bool runScript = false; @@ -229,7 +226,9 @@ int main(int argc, char ** argv) bool stayOnTop = false; bool maximized = false; bool useNativeFileBrowser = true; - bool showLogWidget = true; + bool experimentalGestures = false; + + WarningsConfig warningsConfig = DefaultWarnings; bool sizeToView = true; #if defined(Q_OS_SYMBIAN) @@ -248,11 +247,6 @@ int main(int argc, char ** argv) fullScreen = true; } else if (arg == "-stayontop") { stayOnTop = true; - } else if (arg == "-skin") { - if (lastArg) usage(); - skin = QString(argv[++i]); - } else if (arg == "-resizeview") { - resizeview = true; } else if (arg == "-netcache") { if (lastArg) usage(); cache = QString(argv[++i]).toInt(); @@ -281,7 +275,7 @@ int main(int argc, char ** argv) if (lastArg) usage(); app.setStartDragDistance(QString(argv[++i]).toInt()); } else if (arg == QLatin1String("-v") || arg == QLatin1String("-version")) { - qWarning("Qt Qml Runtime version %s", QT_VERSION_STR); + qWarning("Qt QML Launcher version %s", QT_VERSION_STR); exit(0); } else if (arg == "-translation") { if (lastArg) usage(); @@ -290,8 +284,16 @@ int main(int argc, char ** argv) useGL = true; } else if (arg == "-qmlbrowser") { useNativeFileBrowser = false; - } else if (arg == "-nolog") { - showLogWidget = false; + } else if (arg == "-warnings") { + if (lastArg) usage(); + QString warningsStr = QString(argv[++i]); + if (warningsStr == QLatin1String("show")) { + warningsConfig = ShowWarnings; + } else if (warningsStr == QLatin1String("hide")) { + warningsConfig = HideWarnings; + } else { + usage(); + } } else if (arg == "-I" || arg == "-L") { if (arg == "-L") qWarning("-L option provided for compatibility only, use -I instead"); @@ -323,6 +325,8 @@ int main(int argc, char ** argv) sizeToView = false; } else if (arg == "-sizerootobjecttoview") { sizeToView = true; + } else if (arg == "-experimentalgestures") { + experimentalGestures = true; } else if (arg[0] != '-') { fileName = arg; } else if (1 || arg == "-help") { @@ -340,13 +344,6 @@ int main(int argc, char ** argv) if (stayOnTop) wflags |= Qt::WindowStaysOnTopHint; -#if !defined(Q_OS_SYMBIAN) - LoggerWidget loggerWidget(0); - if (showLogWidget) { - logger = &loggerWidget; - } -#endif - QDeclarativeViewer *viewer = new QDeclarativeViewer(0, wflags); if (!scriptopts.isEmpty()) { QStringList options = @@ -389,6 +386,19 @@ int main(int argc, char ** argv) usage(); } +#if !defined(Q_OS_SYMBIAN) + logger = viewer->warningsWidget(); + if (warningsConfig == ShowWarnings) { + logger.data()->setDefaultVisibility(LoggerWidget::ShowWarnings); + logger.data()->show(); + } else if (warningsConfig == HideWarnings){ + logger.data()->setDefaultVisibility(LoggerWidget::HideWarnings); + } +#endif + + if (experimentalGestures) + viewer->enableExperimentalGestures(); + foreach (QString lib, imports) viewer->addLibraryPath(lib); @@ -398,21 +408,10 @@ int main(int argc, char ** argv) viewer->setNetworkCacheSize(cache); viewer->setRecordFile(recordfile); viewer->setSizeToView(sizeToView); - if (resizeview) - viewer->setScaleView(); if (fps>0) viewer->setRecordRate(fps); if (autorecord_to) viewer->setAutoRecord(autorecord_from,autorecord_to); - if (!skin.isEmpty()) { - if (skin == "list") { - foreach (QString s, viewer->builtinSkins()) - qWarning() << qPrintable(s); - exit(0); - } else { - viewer->setSkin(skin); - } - } if (devkeys) viewer->setDeviceKeys(true); viewer->setRecordDither(dither); diff --git a/tools/qml/qdeclarativefolderlistmodel.cpp b/tools/qml/qdeclarativefolderlistmodel.cpp index 5a9d88b..7ac25d6 100644 --- a/tools/qml/qdeclarativefolderlistmodel.cpp +++ b/tools/qml/qdeclarativefolderlistmodel.cpp @@ -256,6 +256,10 @@ void QDeclarativeFolderListModel::setNameFilters(const QStringList &filters) d->model.setNameFilters(d->nameFilters); } +void QDeclarativeFolderListModel::classBegin() +{ +} + void QDeclarativeFolderListModel::componentComplete() { if (!d->folder.isValid() || !QDir().exists(d->folder.toLocalFile())) @@ -340,7 +344,6 @@ void QDeclarativeFolderListModel::removed(const QModelIndex &index, int start, i void QDeclarativeFolderListModel::dataChanged(const QModelIndex &start, const QModelIndex &end) { - qDebug() << "data changed"; if (start.parent() == d->folderIndex) emit itemsChanged(start.row(), end.row() - start.row() + 1, roles()); } diff --git a/tools/qml/qdeclarativefolderlistmodel.h b/tools/qml/qdeclarativefolderlistmodel.h index 57b7fe5..1ecc784 100644 --- a/tools/qml/qdeclarativefolderlistmodel.h +++ b/tools/qml/qdeclarativefolderlistmodel.h @@ -87,6 +87,7 @@ public: QStringList nameFilters() const; void setNameFilters(const QStringList &filters); + virtual void classBegin(); virtual void componentComplete(); Q_INVOKABLE bool isFolder(int index) const; diff --git a/tools/qml/qml.icns b/tools/qml/qml.icns Binary files differnew file mode 100644 index 0000000..c760516 --- /dev/null +++ b/tools/qml/qml.icns diff --git a/tools/qml/qml.pri b/tools/qml/qml.pri index d343c76..a2058c7 100644 --- a/tools/qml/qml.pri +++ b/tools/qml/qml.pri @@ -24,7 +24,11 @@ maemo5 { } else { SOURCES += $$PWD/deviceorientation.cpp } + +symbian { + INCLUDEPATH += $$QT_SOURCE_TREE/examples/network/qftp/ + LIBS += -lesock -lcommdb -lconnmon -linsock +} + FORMS = $$PWD/recopts.ui \ $$PWD/proxysettings.ui - -include(../shared/deviceskin/deviceskin.pri) diff --git a/tools/qml/qml.pro b/tools/qml/qml.pro index b33d48b..6129639 100644 --- a/tools/qml/qml.pro +++ b/tools/qml/qml.pro @@ -32,12 +32,11 @@ wince* { symbian { TARGET.UID3 = 0x20021317 include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) - INCLUDEPATH += $$QT_SOURCE_TREE/examples/network/qftp/ TARGET.EPOCHEAPSIZE = 0x20000 0x2000000 - LIBS += -lesock -lcommdb -lconnmon -linsock TARGET.CAPABILITY = NetworkServices ReadUserData } mac { QMAKE_INFO_PLIST=Info_mac.plist - TARGET=Qml + TARGET="QML Launcher" + ICON=qml.icns } diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 008f163..9700090 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -53,7 +53,6 @@ #include "qdeclarative.h" #include <private/qabstractanimation_p.h> #include <QAbstractAnimation> -#include "deviceskin.h" #include <QSettings> #include <QXmlStreamReader> @@ -66,6 +65,7 @@ #include <QDeclarativeComponent> #include <QWidget> #include <QApplication> +#include <QTranslator> #include <QDir> #include <QTextBrowser> #include <QFile> @@ -167,89 +167,6 @@ private: QWidget *refWidget; }; - -class PreviewDeviceSkin : public DeviceSkin -{ - Q_OBJECT -public: - explicit PreviewDeviceSkin(const DeviceSkinParameters ¶meters, QWidget *parent); - - void setPreview(QWidget *formWidget); - void setPreviewAndScale(QWidget *formWidget); - - void setScreenSize(const QSize& size) - { - QMatrix fit; - fit = fit.scale(qreal(size.width())/m_screenSize.width(), - qreal(size.height())/m_screenSize.height()); - setTransform(fit); - QApplication::syncX(); - } - - QSize standardScreenSize() const { return m_screenSize; } - - QMenu* menu; - -private slots: - void slotSkinKeyPressEvent(int code, const QString& text, bool autorep); - void slotSkinKeyReleaseEvent(int code, const QString& text, bool autorep); - void slotPopupMenu(); - -private: - const QSize m_screenSize; -}; - - -PreviewDeviceSkin::PreviewDeviceSkin(const DeviceSkinParameters ¶meters, QWidget *parent) : - DeviceSkin(parameters, parent), - m_screenSize(parameters.screenSize()) -{ - menu = new QMenu(this); - connect(this, SIGNAL(skinKeyPressEvent(int,QString,bool)), - this, SLOT(slotSkinKeyPressEvent(int,QString,bool))); - connect(this, SIGNAL(skinKeyReleaseEvent(int,QString,bool)), - this, SLOT(slotSkinKeyReleaseEvent(int,QString,bool))); - connect(this, SIGNAL(popupMenu()), this, SLOT(slotPopupMenu())); -} - -void PreviewDeviceSkin::setPreview(QWidget *formWidget) -{ - formWidget->setFixedSize(m_screenSize); - formWidget->setParent(this, Qt::SubWindow); - formWidget->setAutoFillBackground(true); - setView(formWidget); -} - -void PreviewDeviceSkin::setPreviewAndScale(QWidget *formWidget) -{ - setScreenSize(formWidget->sizeHint()); - formWidget->setParent(this, Qt::SubWindow); - formWidget->setAutoFillBackground(true); - setView(formWidget); -} - -void PreviewDeviceSkin::slotSkinKeyPressEvent(int code, const QString& text, bool autorep) -{ - if (QWidget *focusWidget = QApplication::focusWidget()) { - QKeyEvent e(QEvent::KeyPress,code,0,text,autorep); - QApplication::sendEvent(focusWidget, &e); - } - -} - -void PreviewDeviceSkin::slotSkinKeyReleaseEvent(int code, const QString& text, bool autorep) -{ - if (QWidget *focusWidget = QApplication::focusWidget()) { - QKeyEvent e(QEvent::KeyRelease,code,0,text,autorep); - QApplication::sendEvent(focusWidget, &e); - } -} - -void PreviewDeviceSkin::slotPopupMenu() -{ - menu->exec(QCursor::pos()); -} - static struct { const char *name, *args; } ffmpegprofiles[] = { {"Maximum Quality", "-sameq"}, {"High Quality", "-qmax 2"}, @@ -433,7 +350,7 @@ QNetworkAccessManager *NetworkAccessManagerFactory::create(QObject *parent) setupProxy(manager); if (cacheSize > 0) { QNetworkDiskCache *cache = new QNetworkDiskCache; - cache->setCacheDirectory(QDir::tempPath()+QLatin1String("/qml-duiviewer-network-cache")); + cache->setCacheDirectory(QDir::tempPath()+QLatin1String("/qml-launcher-network-cache")); cache->setMaximumCacheSize(cacheSize); manager->setCache(cache); } else { @@ -461,15 +378,19 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) #else : QWidget(parent, flags) #endif - , frame_stream(0), scaleSkin(true), mb(0) + , loggerWindow(new LoggerWidget()) + , frame_stream(0), mb(0) , portraitOrientation(0), landscapeOrientation(0) - , m_scriptOptions(0), tester(0), useQmlFileBrowser(true) + , showWarningsWindow(0) + , m_scriptOptions(0) + , tester(0) + , useQmlFileBrowser(true) + , translator(0) { QDeclarativeViewer::registerTypes(); - setWindowTitle(tr("Qt Qml Runtime")); + setWindowTitle(tr("Qt QML Launcher")); devicemode = false; - skin = 0; canvas = 0; record_autotime = 0; record_rate = 50; @@ -495,6 +416,7 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) } canvas = new QDeclarativeView(this); + canvas->setAttribute(Qt::WA_OpaquePaintEvent); canvas->setAttribute(Qt::WA_NoSystemBackground); @@ -504,6 +426,9 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) QObject::connect(canvas, SIGNAL(statusChanged(QDeclarativeView::Status)), this, SLOT(statusChanged())); QObject::connect(canvas->engine(), SIGNAL(quit()), QCoreApplication::instance (), SLOT(quit())); + QObject::connect(warningsWidget(), SIGNAL(opened()), this, SLOT(warningsWidgetOpened())); + QObject::connect(warningsWidget(), SIGNAL(closed()), this, SLOT(warningsWidgetClosed())); + if (!(flags & Qt::FramelessWindowHint)) { createMenu(menuBar(),0); setPortrait(); @@ -526,6 +451,8 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) connect(&autoStartTimer, SIGNAL(triggered()), this, SLOT(autoStartRecording())); connect(&autoStopTimer, SIGNAL(triggered()), this, SLOT(autoStopRecording())); connect(&recordTimer, SIGNAL(triggered()), this, SLOT(recordFrame())); + connect(DeviceOrientation::instance(), SIGNAL(orientationChanged()), + this, SLOT(orientationChanged()), Qt::QueuedConnection); autoStartTimer.setRunning(false); autoStopTimer.setRunning(false); recordTimer.setRunning(false); @@ -534,10 +461,21 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) QDeclarativeViewer::~QDeclarativeViewer() { + delete loggerWindow; canvas->engine()->setNetworkAccessManagerFactory(0); delete namFactory; } +void QDeclarativeViewer::enableExperimentalGestures() +{ + canvas->viewport()->grabGesture(Qt::TapGesture,Qt::DontStartGestureOnChildren|Qt::ReceivePartialGestures|Qt::IgnoredGesturesPropagateToParent); + canvas->viewport()->grabGesture(Qt::TapAndHoldGesture,Qt::DontStartGestureOnChildren|Qt::ReceivePartialGestures|Qt::IgnoredGesturesPropagateToParent); + canvas->viewport()->grabGesture(Qt::PanGesture,Qt::DontStartGestureOnChildren|Qt::ReceivePartialGestures|Qt::IgnoredGesturesPropagateToParent); + canvas->viewport()->grabGesture(Qt::PinchGesture,Qt::DontStartGestureOnChildren|Qt::ReceivePartialGestures|Qt::IgnoredGesturesPropagateToParent); + canvas->viewport()->grabGesture(Qt::SwipeGesture,Qt::DontStartGestureOnChildren|Qt::ReceivePartialGestures|Qt::IgnoredGesturesPropagateToParent); + canvas->viewport()->setAttribute(Qt::WA_AcceptTouchEvents); +} + int QDeclarativeViewer::menuBarHeight() const { if (!(windowFlags() & Qt::FramelessWindowHint)) @@ -563,6 +501,11 @@ QDeclarativeView *QDeclarativeViewer::view() const return canvas; } +LoggerWidget *QDeclarativeViewer::warningsWidget() const +{ + return loggerWindow; +} + void QDeclarativeViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) { QObject *parent = flatmenu ? (QObject*)flatmenu : (QObject*)menu; @@ -614,53 +557,17 @@ void QDeclarativeViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) connect(slowAction, SIGNAL(triggered(bool)), this, SLOT(setSlowMode(bool))); debugMenu->addAction(slowAction); - if (flatmenu) flatmenu->addSeparator(); + showWarningsWindow = new QAction(tr("Show Warnings"), parent); + showWarningsWindow->setCheckable((true)); + showWarningsWindow->setChecked(loggerWindow->isVisible()); + connect(showWarningsWindow, SIGNAL(triggered(bool)), this, SLOT(showWarnings(bool))); - QMenu *skinMenu = flatmenu ? flatmenu->addMenu(tr("&Skin")) : menu->addMenu(tr("&Skin")); - - QActionGroup *skinActions; - QAction *skinAction; - - skinActions = new QActionGroup(parent); - skinAction = new QAction(tr("Scale skin"), parent); - skinAction->setCheckable(true); - skinAction->setChecked(scaleSkin); - skinActions->addAction(skinAction); - skinMenu->addAction(skinAction); - connect(skinAction, SIGNAL(triggered()), this, SLOT(setScaleSkin())); - skinAction = new QAction(tr("Resize view"), parent); - skinAction->setCheckable(true); - skinAction->setChecked(!scaleSkin); - skinActions->addAction(skinAction); - skinMenu->addAction(skinAction); - connect(skinAction, SIGNAL(triggered()), this, SLOT(setScaleView())); - skinMenu->addSeparator(); - - skinActions = new QActionGroup(parent); - QSignalMapper *mapper = new QSignalMapper(parent); - skinAction = new QAction(tr("None"), parent); - skinAction->setCheckable(true); - if (currentSkin.isEmpty()) - skinAction->setChecked(true); - skinActions->addAction(skinAction); - skinMenu->addAction(skinAction); - mapper->setMapping(skinAction, ""); - connect(skinAction, SIGNAL(triggered()), mapper, SLOT(map())); - skinMenu->addSeparator(); - - foreach (QString name, builtinSkins()) { - skinAction = new QAction(name, parent); - skinActions->addAction(skinAction); - skinMenu->addAction(skinAction); - skinAction->setCheckable(true); - if (":skin/"+name+".skin" == currentSkin) - skinAction->setChecked(true); - mapper->setMapping(skinAction, name); - connect(skinAction, SIGNAL(triggered()), mapper, SLOT(map())); - } - connect(mapper, SIGNAL(mapped(QString)), this, SLOT(setSkin(QString))); +#if !defined(Q_OS_SYMBIAN) + debugMenu->addAction(showWarningsWindow); +#endif if (flatmenu) flatmenu->addSeparator(); + #endif // Q_OS_SYMBIAN QMenu *settingsMenu = flatmenu ? flatmenu : menu->addMenu(tr("S&ettings")); @@ -670,6 +577,8 @@ void QDeclarativeViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) #if !defined(Q_OS_SYMBIAN) if (!flatmenu) settingsMenu->addAction(recordOptions); + + settingsMenu->addMenu(loggerWindow->preferencesMenu()); #else QAction *fullscreenAction = new QAction(tr("Full Screen"), parent); fullscreenAction->setCheckable(true); @@ -677,7 +586,10 @@ void QDeclarativeViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) settingsMenu->addAction(fullscreenAction); #endif + if (flatmenu) flatmenu->addSeparator(); + QMenu *propertiesMenu = settingsMenu->addMenu(tr("Properties")); + QActionGroup *orientation = new QActionGroup(parent); QAction *toggleOrientation = new QAction(tr("&Toggle Orientation"), parent); @@ -756,30 +668,20 @@ void QDeclarativeViewer::toggleFullScreen() showFullScreen(); } -void QDeclarativeViewer::setScaleSkin() +void QDeclarativeViewer::showWarnings(bool show) { - if (scaleSkin) - return; - scaleSkin = true; - if (skin) { - canvas->resize(initialSize); - canvas->setFixedSize(initialSize); - canvas->setResizeMode(QDeclarativeView::SizeViewToRootObject); - updateSizeHints(); - } + loggerWindow->setVisible(show); } -void QDeclarativeViewer::setScaleView() +void QDeclarativeViewer::warningsWidgetOpened() { - if (!scaleSkin) - return; - scaleSkin = false; - if (skin) { - canvas->setResizeMode(QDeclarativeView::SizeRootObjectToView); - updateSizeHints(); - } + showWarningsWindow->setChecked(true); } +void QDeclarativeViewer::warningsWidgetClosed() +{ + showWarningsWindow->setChecked(false); +} void QDeclarativeViewer::takeSnapShot() { @@ -924,10 +826,8 @@ void QDeclarativeViewer::statusChanged() if (canvas->status() == QDeclarativeView::Ready) { initialSize = canvas->sizeHint(); if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) { - QSize newWindowSize = initialSize; - newWindowSize.setHeight(newWindowSize.height()+menuBarHeight()); updateSizeHints(); - resize(newWindowSize); + resize(QSize(initialSize.width(), initialSize.height()+menuBarHeight())); } } } @@ -937,6 +837,46 @@ void QDeclarativeViewer::launch(const QString& file_or_url) QMetaObject::invokeMethod(this, "open", Qt::QueuedConnection, Q_ARG(QString, file_or_url)); } +void QDeclarativeViewer::loadTranslationFile(const QString& directory) +{ + if (!translator) { + translator = new QTranslator(this); + QApplication::installTranslator(translator); + } + + translator->load(QLatin1String("qml_" )+QLocale::system().name(), directory + QLatin1String("/i18n")); +} + +void QDeclarativeViewer::loadDummyDataFiles(const QString& directory) +{ + QDir dir(directory+"/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(); + QDeclarativeComponent comp(canvas->engine()); + comp.setData(data, QUrl()); + QObject *dummyData = comp.create(); + + if(comp.isError()) { + QList<QDeclarativeError> errors = comp.errors(); + foreach (const QDeclarativeError &error, errors) { + qWarning() << error; + } + if (tester) tester->executefailure(); + } + + if (dummyData) { + qWarning() << "Loaded dummy data:" << dir.filePath(qml); + qml.truncate(qml.length()-4); + canvas->rootContext()->setContextProperty(qml, dummyData); + dummyData->setParent(this); + } + } +} + bool QDeclarativeViewer::open(const QString& file_or_url) { currentFileOrUrl = file_or_url; @@ -947,7 +887,7 @@ bool QDeclarativeViewer::open(const QString& file_or_url) url = QUrl::fromLocalFile(fi.absoluteFilePath()); else url = QUrl(file_or_url); - setWindowTitle(tr("%1 - Qt Qml Runtime").arg(file_or_url)); + setWindowTitle(tr("%1 - Qt QML Launcher").arg(file_or_url)); if (!m_script.isEmpty()) tester = new QDeclarativeTester(m_script, m_scriptOptions, canvas); @@ -955,50 +895,26 @@ bool QDeclarativeViewer::open(const QString& file_or_url) delete canvas->rootObject(); canvas->engine()->clearComponentCache(); QDeclarativeContext *ctxt = canvas->rootContext(); - ctxt->setContextProperty("qmlViewer", this); + ctxt->setContextProperty("qmlLauncher", this); #ifdef Q_OS_SYMBIAN - ctxt->setContextProperty("qmlViewerFolder", "E:\\"); // Documents on your S60 phone + ctxt->setContextProperty("qmlLauncherFolder", "E:\\"); // Documents on your S60 phone #else - ctxt->setContextProperty("qmlViewerFolder", QDir::currentPath()); + ctxt->setContextProperty("qmlLauncherFolder", QDir::currentPath()); #endif ctxt->setContextProperty("runtime", Runtime::instance()); QString fileName = url.toLocalFile(); if (!fileName.isEmpty()) { - QFileInfo fi(fileName); if (fi.exists()) { if (fi.suffix().toLower() != QLatin1String("qml")) { qWarning() << "qml cannot open non-QML file" << fileName; return false; } - 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(); - QDeclarativeComponent comp(canvas->engine()); - comp.setData(data, QUrl()); - QObject *dummyData = comp.create(); - - if(comp.isError()) { - QList<QDeclarativeError> errors = comp.errors(); - foreach (const QDeclarativeError &error, errors) { - qWarning() << error; - } - 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); - } - } + QFileInfo fi(fileName); + loadTranslationFile(fi.path()); + loadDummyDataFiles(fi.path()); } else { qWarning() << "qml cannot find file:" << fileName; return false; @@ -1020,83 +936,6 @@ void QDeclarativeViewer::startNetwork() #endif } -QStringList QDeclarativeViewer::builtinSkins() const -{ - QDir dir(":/skins/","*.skin"); - const QFileInfoList l = dir.entryInfoList(); - QStringList r; - for (QFileInfoList::const_iterator it = l.begin(); it != l.end(); ++it) { - r += (*it).baseName(); - } - return r; -} - -void QDeclarativeViewer::setSkin(const QString& skinDirOrName) -{ - QString skinDirectory = skinDirOrName; - - if (!QDir(skinDirOrName).exists() && QDir(":/skins/"+skinDirOrName+".skin").exists()) - skinDirectory = ":/skins/"+skinDirOrName+".skin"; - - if (currentSkin == skinDirectory) - return; - - currentSkin = skinDirectory; - - // XXX QWidget::setMask does not handle changes well, and we may - // XXX have been signalled from an item in a menu we're replacing, - // XXX hence some rather convoluted resetting here... - - QString err; - if (skin) { - skin->hide(); - skin->deleteLater(); - } - - DeviceSkinParameters parameters; - if (!skinDirectory.isEmpty() && parameters.read(skinDirectory,DeviceSkinParameters::ReadAll,&err)) { - layout()->setEnabled(false); - if (mb) - mb->hide(); - if (!err.isEmpty()) - qWarning() << err; - skin = new PreviewDeviceSkin(parameters,this); - if (scaleSkin) - skin->setPreviewAndScale(canvas); - else - skin->setPreview(canvas); - createMenu(0,skin->menu); - if (scaleSkin) { - canvas->setResizeMode(QDeclarativeView::SizeViewToRootObject); - } - updateSizeHints(); - skin->show(); - } else if (skin) { - skin = 0; - clearMask(); - if ((windowFlags() & Qt::FramelessWindowHint)) { - menuBar()->clear(); - createMenu(menuBar(),0); - } - canvas->setParent(this, Qt::SubWindow); - setParent(0,windowFlags()); // recreate - mb->show(); - canvas->setResizeMode(QDeclarativeView::SizeRootObjectToView); - updateSizeHints(); - - layout()->setEnabled(true); - if (!scaleSkin) { - canvas->resize(initialSize); - canvas->setFixedSize(initialSize); - } - QSize newWindowSize = canvas->size(); - newWindowSize.setHeight(newWindowSize.height()+menuBarHeight()); - resize(newWindowSize); - show(); - } - canvas->show(); -} - void QDeclarativeViewer::setAutoRecord(int from, int to) { if (from==0) from=1; // ensure resized @@ -1365,6 +1204,19 @@ void QDeclarativeViewer::recordFrame() } } +void QDeclarativeViewer::orientationChanged() +{ + if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) { + if (canvas->rootObject()) { + QSizeF rootObjectSize = canvas->rootObject()->boundingRect().size(); + QSize newSize(rootObjectSize.width(), rootObjectSize.height()+menuBarHeight()); + if (size() != newSize) { + resize(newSize); + } + } + } +} + void QDeclarativeViewer::setDeviceKeys(bool on) { devicemode = on; @@ -1412,24 +1264,16 @@ void QDeclarativeViewer::updateSizeHints() { if (canvas->resizeMode() == QDeclarativeView::SizeViewToRootObject) { QSize newWindowSize = canvas->sizeHint(); - if (!skin) - newWindowSize.setHeight(newWindowSize.height()+menuBarHeight()); + newWindowSize.setHeight(newWindowSize.height()+menuBarHeight()); if (!isFullScreen() && !isMaximized()) { resize(newWindowSize); setFixedSize(newWindowSize); - if (skin && scaleSkin) { - skin->setScreenSize(newWindowSize); - } } } else { // QDeclarativeView::SizeRootObjectToView canvas->setMinimumSize(QSize(0,0)); canvas->setMaximumSize(QSize(16777215,16777215)); setMinimumSize(QSize(0,0)); setMaximumSize(QSize(16777215,16777215)); - if (skin && !scaleSkin) { - canvas->setFixedSize(skin->standardScreenSize()); - skin->setScreenSize(skin->standardScreenSize()); - } } updateGeometry(); } diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h index 2a0a07d..0416b32 100644 --- a/tools/qml/qmlruntime.h +++ b/tools/qml/qmlruntime.h @@ -48,6 +48,8 @@ #include <QTime> #include <QList> +#include "loggerwidget.h" + QT_BEGIN_NAMESPACE class QDeclarativeView; @@ -59,6 +61,7 @@ class QDeclarativeTester; class QNetworkReply; class QNetworkCookieJar; class NetworkAccessManagerFactory; +class QTranslator; class QDeclarativeViewer #if defined(Q_OS_SYMBIAN) @@ -102,11 +105,13 @@ public: void setUseNativeFileBrowser(bool); void updateSizeHints(); void setSizeToView(bool sizeToView); - QStringList builtinSkins() const; QMenuBar *menuBar() const; QDeclarativeView *view() const; + LoggerWidget *warningsWidget() const; + + void enableExperimentalGestures(); public slots: void sceneResized(QSize size); @@ -117,10 +122,9 @@ public slots: void toggleRecording(); void toggleRecordingWithSelection(); void ffmpegFinished(int code); - void setSkin(const QString& skinDirectory); void showProxySettings (); void proxySettingsChanged (); - void setScaleView(); + void toggleOrientation(); void statusChanged(); void setSlowMode(bool); void launch(const QString &); @@ -128,7 +132,6 @@ public slots: protected: virtual void keyPressEvent(QKeyEvent *); virtual bool event(QEvent *); - void createMenu(QMenuBar *menu, QMenu *flatmenu); private slots: @@ -137,19 +140,21 @@ private slots: void recordFrame(); void chooseRecordingOptions(); void pickRecordingFile(); - void setScaleSkin(); void setPortrait(); void setLandscape(); - void toggleOrientation(); void startNetwork(); void toggleFullScreen(); + void orientationChanged(); + + void showWarnings(bool show); + void warningsWidgetOpened(); + void warningsWidgetClosed(); private: QString getVideoFileName(); int menuBarHeight() const; - PreviewDeviceSkin *skin; - QSize skinscreensize; + LoggerWidget *loggerWindow; QDeclarativeView *canvas; QSize initialSize; QString currentFileOrUrl; @@ -182,16 +187,22 @@ private: QAction *portraitOrientation; QAction *landscapeOrientation; + QAction *showWarningsWindow; + QString m_script; ScriptOptions m_scriptOptions; QDeclarativeTester *tester; QNetworkReply *wgtreply; QString wgtdir; - NetworkAccessManagerFactory *namFactory; bool useQmlFileBrowser; + + QTranslator *translator; + void loadTranslationFile(const QString& directory); + + void loadDummyDataFiles(const QString& directory); }; Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeViewer::ScriptOptions) |