summaryrefslogtreecommitdiffstats
path: root/tools/qml
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@nokia.com>2010-04-23 15:22:16 (GMT)
committerKai Koehne <kai.koehne@nokia.com>2010-05-05 13:29:07 (GMT)
commitd340dc6e4b3f1f4f8737d0d1d34e76ae68e007d6 (patch)
tree26572c3d6e80022da7be812875fdc1a1f0ff3695 /tools/qml
parent39e992988f21553df7e839f36ced75ca5bf8588c (diff)
downloadQt-d340dc6e4b3f1f4f8737d0d1d34e76ae68e007d6.zip
Qt-d340dc6e4b3f1f4f8737d0d1d34e76ae68e007d6.tar.gz
Qt-d340dc6e4b3f1f4f8737d0d1d34e76ae68e007d6.tar.bz2
Add a switch to the menu to hide/show the runtime warnings
Reviewed-by: mae
Diffstat (limited to 'tools/qml')
-rw-r--r--tools/qml/loggerwidget.cpp120
-rw-r--r--tools/qml/loggerwidget.h32
-rw-r--r--tools/qml/main.cpp33
-rw-r--r--tools/qml/qmlruntime.cpp44
-rw-r--r--tools/qml/qmlruntime.h10
5 files changed, 222 insertions, 17 deletions
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..b68ecc5 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;
};
+Q_DECLARE_METATYPE(LoggerWidget::Visibility);
+
QT_END_NAMESPACE
#endif // LOGGERWIDGET_H
diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp
index f2c0530..78f0c87 100644
--- a/tools/qml/main.cpp
+++ b/tools/qml/main.cpp
@@ -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(" -warnings ................................ show warnings in a separate 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)
@@ -230,7 +232,7 @@ int main(int argc, char ** argv)
bool maximized = false;
bool useNativeFileBrowser = true;
- bool showLogWidget = false;
+ WarningsConfig warningsConfig = DefaultWarnings;
bool sizeToView = true;
#if defined(Q_OS_SYMBIAN)
@@ -292,7 +294,15 @@ int main(int argc, char ** argv)
} else if (arg == "-qmlbrowser") {
useNativeFileBrowser = false;
} else if (arg == "-warnings") {
- showLogWidget = true;
+ 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");
@@ -341,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 =
@@ -390,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/qmlruntime.cpp b/tools/qml/qmlruntime.cpp
index da31284..1229df2 100644
--- a/tools/qml/qmlruntime.cpp
+++ b/tools/qml/qmlruntime.cpp
@@ -462,10 +462,13 @@ 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)
- , translator(0)
+ , showWarningsWindow(0)
+ , m_scriptOptions(0)
+ , tester(0)
+ , useQmlFileBrowser(true)
{
QDeclarativeViewer::registerTypes();
setWindowTitle(tr("Qt Qml Runtime"));
@@ -506,6 +509,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();
@@ -565,6 +571,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;
@@ -616,6 +627,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"));
@@ -672,6 +692,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);
@@ -679,7 +701,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);
@@ -758,6 +783,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)
diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h
index 0b23303..655feea 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;
@@ -108,6 +110,7 @@ public:
QMenuBar *menuBar() const;
QDeclarativeView *view() const;
+ LoggerWidget *warningsWidget() const;
public slots:
void sceneResized(QSize size);
@@ -145,10 +148,15 @@ private slots:
void startNetwork();
void toggleFullScreen();
+ void showWarnings(bool show);
+ void warningsWidgetOpened();
+ void warningsWidgetClosed();
+
private:
QString getVideoFileName();
int menuBarHeight() const;
+ LoggerWidget *loggerWindow;
PreviewDeviceSkin *skin;
QSize skinscreensize;
QDeclarativeView *canvas;
@@ -183,6 +191,8 @@ private:
QAction *portraitOrientation;
QAction *landscapeOrientation;
+ QAction *showWarningsWindow;
+
QString m_script;
ScriptOptions m_scriptOptions;
QDeclarativeTester *tester;