diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qdoc3/htmlgenerator.cpp | 8 | ||||
-rw-r--r-- | tools/qml/loggerwidget.cpp | 120 | ||||
-rw-r--r-- | tools/qml/loggerwidget.h | 32 | ||||
-rw-r--r-- | tools/qml/main.cpp | 38 | ||||
-rw-r--r-- | tools/qml/qdeclarativefolderlistmodel.cpp | 5 | ||||
-rw-r--r-- | tools/qml/qdeclarativefolderlistmodel.h | 1 | ||||
-rw-r--r-- | tools/qml/qmlruntime.cpp | 135 | ||||
-rw-r--r-- | tools/qml/qmlruntime.h | 21 |
8 files changed, 300 insertions, 60 deletions
diff --git a/tools/qdoc3/htmlgenerator.cpp b/tools/qdoc3/htmlgenerator.cpp index a0cd560..6004c74 100644 --- a/tools/qdoc3/htmlgenerator.cpp +++ b/tools/qdoc3/htmlgenerator.cpp @@ -4410,14 +4410,6 @@ void HtmlGenerator::generateDetailedQmlMember(const Node *node, out() << "<span class=\"qmldefault\">default </span>"; generateQmlItem(qpn, relative, marker, false); out() << "</td></tr>"; - if (qpgn->isDefault()) { - out() << "</table>" - << "</div></div>" - << "<div class=\"qmlitem\">" - << "<div class=\"qmlproto\">" - << "<table class=\"qmlname\">" - << "<tr><td>default</td></tr>"; - } } ++p; } 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..fb687ac 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> @@ -125,7 +125,7 @@ void usage() 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"); @@ -168,6 +168,8 @@ void scriptOptsUsage() exit(1); } +enum WarningsConfig { ShowWarnings, HideWarnings, DefaultWarnings }; + int main(int argc, char ** argv) { #if defined (Q_OS_SYMBIAN) @@ -229,7 +231,8 @@ int main(int argc, char ** argv) bool stayOnTop = false; bool maximized = false; bool useNativeFileBrowser = true; - bool showLogWidget = true; + + WarningsConfig warningsConfig = DefaultWarnings; bool sizeToView = true; #if defined(Q_OS_SYMBIAN) @@ -290,8 +293,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"); @@ -340,13 +351,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 +393,16 @@ 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 + foreach (QString lib, imports) viewer->addLibraryPath(lib); 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/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 008f163..06fa004 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -66,6 +66,7 @@ #include <QDeclarativeComponent> #include <QWidget> #include <QApplication> +#include <QTranslator> #include <QDir> #include <QTextBrowser> #include <QFile> @@ -461,9 +462,14 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) #else : QWidget(parent, flags) #endif + , loggerWindow(new LoggerWidget()) , frame_stream(0), scaleSkin(true), 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")); @@ -504,6 +510,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 +535,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,6 +545,7 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) QDeclarativeViewer::~QDeclarativeViewer() { + delete loggerWindow; canvas->engine()->setNetworkAccessManagerFactory(0); delete namFactory; } @@ -563,6 +575,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,6 +631,15 @@ void QDeclarativeViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) connect(slowAction, SIGNAL(triggered(bool)), this, SLOT(setSlowMode(bool))); debugMenu->addAction(slowAction); + showWarningsWindow = new QAction(tr("Show Warnings"), parent); + showWarningsWindow->setCheckable((true)); + showWarningsWindow->setChecked(loggerWindow->isVisible()); + connect(showWarningsWindow, SIGNAL(triggered(bool)), this, SLOT(showWarnings(bool))); + +#if !defined(Q_OS_SYMBIAN) + debugMenu->addAction(showWarningsWindow); +#endif + if (flatmenu) flatmenu->addSeparator(); QMenu *skinMenu = flatmenu ? flatmenu->addMenu(tr("&Skin")) : menu->addMenu(tr("&Skin")); @@ -670,6 +696,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 +705,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,6 +787,21 @@ void QDeclarativeViewer::toggleFullScreen() showFullScreen(); } +void QDeclarativeViewer::showWarnings(bool show) +{ + loggerWindow->setVisible(show); +} + +void QDeclarativeViewer::warningsWidgetOpened() +{ + showWarningsWindow->setChecked(true); +} + +void QDeclarativeViewer::warningsWidgetClosed() +{ + showWarningsWindow->setChecked(false); +} + void QDeclarativeViewer::setScaleSkin() { if (scaleSkin) @@ -924,10 +970,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 +981,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; @@ -966,39 +1050,15 @@ bool QDeclarativeViewer::open(const QString& file_or_url) 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; @@ -1365,6 +1425,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; diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h index 2a0a07d..9551090 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) @@ -107,6 +110,7 @@ public: QMenuBar *menuBar() const; QDeclarativeView *view() const; + LoggerWidget *warningsWidget() const; public slots: void sceneResized(QSize size); @@ -121,6 +125,7 @@ public slots: void showProxySettings (); void proxySettingsChanged (); void setScaleView(); + void toggleOrientation(); void statusChanged(); void setSlowMode(bool); void launch(const QString &); @@ -128,7 +133,6 @@ public slots: protected: virtual void keyPressEvent(QKeyEvent *); virtual bool event(QEvent *); - void createMenu(QMenuBar *menu, QMenu *flatmenu); private slots: @@ -140,14 +144,19 @@ private slots: 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; + LoggerWidget *loggerWindow; PreviewDeviceSkin *skin; QSize skinscreensize; QDeclarativeView *canvas; @@ -182,16 +191,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) |