From 0b36923501e0c5eaf28e25a928cf8aeea11b0062 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 15 May 2009 16:12:34 +1000 Subject: Fix opening new XML when skinned. --- tools/qmlviewer/qmlviewer.cpp | 29 ++++++++++++++++++++++------- tools/qmlviewer/qmlviewer.h | 1 + 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 97e29f1..9bce7ed 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -112,6 +112,9 @@ void QmlViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) QDir dir(":/skins/","*.skin"); const QFileInfoList l = dir.entryInfoList(); QAction *skinAction = new QAction(tr("None"), parent); + skinAction->setCheckable(true); + if (currentSkin.isEmpty()) + skinAction->setChecked(true); skinActions->addAction(skinAction); skinMenu->addAction(skinAction); mapper->setMapping(skinAction, ""); @@ -123,6 +126,9 @@ void QmlViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) skinAction = new QAction(name, parent); skinActions->addAction(skinAction); skinMenu->addAction(skinAction); + skinAction->setCheckable(true); + if (file == currentSkin) + skinAction->setChecked(true); mapper->setMapping(skinAction, file); connect(skinAction, SIGNAL(triggered()), mapper, SLOT(map())); } @@ -237,7 +243,10 @@ void QmlViewer::openQml(const QString& fileName) canvas->execute(); qWarning() << "Wall startup time:" << t.elapsed(); - resize(sizeHint()); + canvas->resize(canvas->sizeHint()); + + if (!skin) + resize(sizeHint()); #ifdef QTOPIA show(); @@ -260,6 +269,7 @@ public: fit = fit.scale(qreal(size.width())/m_screenSize.width(), qreal(size.height())/m_screenSize.height()); setTransform(fit); + QApplication::syncX(); } QMenu* menu; @@ -297,7 +307,6 @@ void PreviewDeviceSkin::setPreview(QWidget *formWidget) void PreviewDeviceSkin::setPreviewAndScale(QWidget *formWidget) { setScreenSize(formWidget->sizeHint()); - formWidget->setFixedSize(formWidget->sizeHint()); formWidget->setParent(this, Qt::SubWindow); formWidget->setAutoFillBackground(true); setView(formWidget); @@ -331,6 +340,11 @@ void QmlViewer::setSkin(const QString& skinDirectory) // XXX have been signalled from an item in a menu we're replacing, // XXX hence some rather convoluted resetting here... + if (currentSkin == skinDirectory) + return; + + currentSkin = skinDirectory; + QString err; if (skin) { skin->hide(); @@ -339,15 +353,15 @@ void QmlViewer::setSkin(const QString& skinDirectory) DeviceSkinParameters parameters; if (!skinDirectory.isEmpty() && parameters.read(skinDirectory,DeviceSkinParameters::ReadAll,&err)) { - if (menuBar()) - menuBar()->deleteLater(); + layout()->setEnabled(false); + setMenuBar(0); if (!err.isEmpty()) qWarning() << err; skin = new PreviewDeviceSkin(parameters,this); + canvas->resize(canvas->sizeHint()); skin->setPreviewAndScale(canvas); createMenu(0,skin->menu); skin->show(); - QApplication::syncX(); } else { skin = 0; clearMask(); @@ -361,6 +375,7 @@ void QmlViewer::setSkin(const QString& skinDirectory) setParent(0,windowFlags()); // recreate canvas->move(0,menuBar()->sizeHint().height()+1); setGeometry(g); + layout()->setEnabled(true); show(); } canvas->show(); @@ -395,8 +410,8 @@ void QmlViewer::setRecordPeriod(int ms) void QmlViewer::sceneResized(QSize size) { if (size.width() > 0 && size.height() > 0) { - //if (skin) - //skin->setScreenSize(size); + if (skin) + skin->setScreenSize(size); } } diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index 8bbe275..74044b3 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -80,6 +80,7 @@ private: int record_autotime; bool devicemode; QAction *recordAction; + QString currentSkin; QFxTestEngine *testEngine; }; -- cgit v0.12 From dc75d22da65984df342809b3c60d41ac08c14459 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 15 May 2009 17:54:47 +1000 Subject: Control resizing of content like QScrollArea::widgetResizable --- src/declarative/util/qfxview.cpp | 65 ++++++++++++++++++++++++++++++++++++---- src/declarative/util/qfxview.h | 2 ++ 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/declarative/util/qfxview.cpp b/src/declarative/util/qfxview.cpp index 1c24e28..0d5b796 100644 --- a/src/declarative/util/qfxview.cpp +++ b/src/declarative/util/qfxview.cpp @@ -93,7 +93,7 @@ class QFxViewPrivate { public: QFxViewPrivate(QFxView *w) - : q(w), root(0), component(0) {} + : q(w), root(0), component(0), resizable(false) {} QFxView *q; QFxItem *root; @@ -106,6 +106,7 @@ public: QBasicTimer resizetimer; QSize initialSize; + bool resizable; void init(); }; @@ -344,7 +345,18 @@ void QFxView::continueExecute() d->root = item; connect(item, SIGNAL(widthChanged()), this, SLOT(sizeChanged())); connect(item, SIGNAL(heightChanged()), this, SLOT(sizeChanged())); - emit sceneResized(QSize(d->root->width(),d->root->height())); + if (d->initialSize.height() <= 0 && d->root->width() > 0) + d->initialSize.setWidth(d->root->width()); + if (d->initialSize.height() <= 0 && d->root->height() > 0) + d->initialSize.setHeight(d->root->height()); + if (d->resizable) { + d->root->setWidth(width()); + d->root->setHeight(height()); + } else { + QSize sz(d->root->width(),d->root->height()); + emit sceneResized(sz); + resize(sz); + } } else if (QWidget *wid = qobject_cast(obj)) { window()->setAttribute(Qt::WA_OpaquePaintEvent, false); window()->setAttribute(Qt::WA_NoSystemBackground, false); @@ -381,14 +393,55 @@ void QFxView::sizeChanged() */ void QFxView::timerEvent(QTimerEvent* e) { - if (e->timerId() == d->resizetimer.timerId()) { - if (d->root) - emit sceneResized(QSize(d->root->width(),d->root->height())); + if (!e || e->timerId() == d->resizetimer.timerId()) { + if (d->root) { + QSize sz(d->root->width(),d->root->height()); + emit sceneResized(sz); + //if (!d->resizable) + //resize(sz); + } d->resizetimer.stop(); updateGeometry(); } } +// modelled on QScrollArea::widgetResizable +/*! + \property QFxView::contentResizable + \brief whether the view should resize the canvas contents + + If this property is set to false (the default), the view + resizes with the root item in the QML. + + If this property is set to true, the view will + automatically resize the root item. + + Regardless of this property, the sizeHint of the view + is the initial size of the root item. +*/ + +void QFxView::setContentResizable(bool on) +{ + if (d->resizable != on) { + d->resizable = on; + if (d->root) { + if (on) { + d->root->setWidth(width()); + d->root->setHeight(height()); + } else { + d->root->setWidth(d->initialSize.width()); + d->root->setHeight(d->initialSize.height()); + } + } + } +} + +bool QFxView::contentResizable() const +{ + return d->resizable; +} + + /*! The size hint is the size of the root item. */ @@ -481,7 +534,7 @@ QFxItem *QFxView::root() const */ void QFxView::resizeEvent(QResizeEvent *e) { - if (d->root) { + if (d->resizable && d->root) { d->root->setWidth(width()); d->root->setHeight(height()); } diff --git a/src/declarative/util/qfxview.h b/src/declarative/util/qfxview.h index d6f786c..8dd9e2c 100644 --- a/src/declarative/util/qfxview.h +++ b/src/declarative/util/qfxview.h @@ -82,6 +82,8 @@ public: virtual QFxItem *root() const; + void setContentResizable(bool); + bool contentResizable() const; QSize sizeHint() const; void dumpRoot(); -- cgit v0.12 From 4fe1dc315385fb8d3ab021b682419312a79c379d Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 15 May 2009 17:55:41 +1000 Subject: Resizing options (scale skin to fit view or reverse) --- tools/qmlviewer/qmlviewer.cpp | 248 ++++++++++++++++++++++++++---------------- tools/qmlviewer/qmlviewer.h | 5 + 2 files changed, 162 insertions(+), 91 deletions(-) diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 9bce7ed..97db22e 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -40,8 +40,91 @@ #include #include +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()); +} + + QmlViewer::QmlViewer(QFxTestEngine::TestMode testMode, const QString &testDir, QWidget *parent, Qt::WindowFlags flags) - : QMainWindow(parent, flags), frame_stream(0) + : QMainWindow(parent, flags), frame_stream(0), scaleSkin(true) { testEngine = 0; devicemode = false; @@ -56,6 +139,8 @@ QmlViewer::QmlViewer(QFxTestEngine::TestMode testMode, const QString &testDir, Q createMenu(menuBar(),0); canvas = new QFxView(this); + canvas->setContentResizable(!skin || !scaleSkin); + if(testMode != QFxTestEngine::NoTest) testEngine = new QFxTestEngine(testMode, testDir, canvas, this); @@ -106,12 +191,29 @@ void QmlViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) if (flatmenu) flatmenu->addSeparator(); - QActionGroup *skinActions = new QActionGroup(parent); - QSignalMapper *mapper = new QSignalMapper(parent); QMenu *skinMenu = flatmenu ? flatmenu->addMenu(tr("&Skin")) : menu->addMenu(tr("&Skin")); - QDir dir(":/skins/","*.skin"); - const QFileInfoList l = dir.entryInfoList(); - QAction *skinAction = new QAction(tr("None"), parent); + + 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("Scale 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); @@ -120,6 +222,9 @@ void QmlViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) mapper->setMapping(skinAction, ""); connect(skinAction, SIGNAL(triggered()), mapper, SLOT(map())); skinMenu->addSeparator(); + + QDir dir(":/skins/","*.skin"); + const QFileInfoList l = dir.entryInfoList(); for (QFileInfoList::const_iterator it = l.begin(); it != l.end(); ++it) { QString name = (*it).baseName(); // should perhaps be in file QString file = (*it).filePath(); @@ -149,6 +254,33 @@ void QmlViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) fileMenu->addAction(quitAction); } +void QmlViewer::setScaleSkin() +{ + if (scaleSkin) + return; + scaleSkin = true; + canvas->setContentResizable(!skin || !scaleSkin); + if (skin) { + canvas->setFixedSize(canvas->sizeHint()); + skin->setScreenSize(canvas->sizeHint()); + } +} + +void QmlViewer::setScaleView() +{ + if (!scaleSkin) + return; + scaleSkin = false; + if (skin) { + canvas->setContentResizable(!skin || !scaleSkin); + canvas->setMinimumSize(QSize(0,0)); + canvas->setMaximumSize(QSize(16777215,16777215)); + canvas->resize(skin->standardScreenSize()); + skin->setScreenSize(skin->standardScreenSize()); + } +} + + void QmlViewer::takeSnapShot() { static int snapshotcount = 1; @@ -243,10 +375,17 @@ void QmlViewer::openQml(const QString& fileName) canvas->execute(); qWarning() << "Wall startup time:" << t.elapsed(); - canvas->resize(canvas->sizeHint()); - - if (!skin) + if (!skin) { + canvas->resize(canvas->sizeHint()); resize(sizeHint()); + } else { + if (scaleSkin) + canvas->resize(canvas->sizeHint()); + else { + canvas->setFixedSize(skin->standardScreenSize()); + canvas->resize(skin->standardScreenSize()); + } + } #ifdef QTOPIA show(); @@ -254,86 +393,6 @@ void QmlViewer::openQml(const QString& fileName) } -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(); - } - - 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()); -} - void QmlViewer::setSkin(const QString& skinDirectory) { // XXX QWidget::setMask does not handle changes well, and we may @@ -351,6 +410,8 @@ void QmlViewer::setSkin(const QString& skinDirectory) skin->deleteLater(); } + canvas->setContentResizable(!skin || !scaleSkin); + DeviceSkinParameters parameters; if (!skinDirectory.isEmpty() && parameters.read(skinDirectory,DeviceSkinParameters::ReadAll,&err)) { layout()->setEnabled(false); @@ -359,7 +420,10 @@ void QmlViewer::setSkin(const QString& skinDirectory) qWarning() << err; skin = new PreviewDeviceSkin(parameters,this); canvas->resize(canvas->sizeHint()); - skin->setPreviewAndScale(canvas); + if (scaleSkin) + skin->setPreviewAndScale(canvas); + else + skin->setPreview(canvas); createMenu(0,skin->menu); skin->show(); } else { @@ -370,6 +434,8 @@ void QmlViewer::setSkin(const QString& skinDirectory) createMenu(menuBar(),0); setMinimumSize(QSize(0,0)); setMaximumSize(QSize(16777215,16777215)); + canvas->setMinimumSize(QSize(0,0)); + canvas->setMaximumSize(QSize(16777215,16777215)); QRect g = geometry(); g.setSize(sizeHint()); setParent(0,windowFlags()); // recreate @@ -410,7 +476,7 @@ void QmlViewer::setRecordPeriod(int ms) void QmlViewer::sceneResized(QSize size) { if (size.width() > 0 && size.height() > 0) { - if (skin) + if (skin && scaleSkin) skin->setScreenSize(size); } } diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index 74044b3..09b2b5b 100644 --- a/tools/qmlviewer/qmlviewer.h +++ b/tools/qmlviewer/qmlviewer.h @@ -62,6 +62,10 @@ protected: void createMenu(QMenuBar *menu, QMenu *flatmenu); +private slots: + void setScaleSkin(); + void setScaleView(); + private: QString currentFileName; PreviewDeviceSkin *skin; @@ -81,6 +85,7 @@ private: bool devicemode; QAction *recordAction; QString currentSkin; + bool scaleSkin; QFxTestEngine *testEngine; }; -- cgit v0.12