diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-05-18 00:14:42 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-05-18 00:14:42 (GMT) |
commit | 35f3438ae8a06aeba7b784df8de984d9d00aeff4 (patch) | |
tree | 4a4e706e4122dc860fa07c976ba374406e9f1d4f | |
parent | deed3896f48d52475bf1585534bca500666d9744 (diff) | |
parent | 86cc7c0d6dffc5cabe215606cb6fadf98e8214cc (diff) | |
download | Qt-35f3438ae8a06aeba7b784df8de984d9d00aeff4.zip Qt-35f3438ae8a06aeba7b784df8de984d9d00aeff4.tar.gz Qt-35f3438ae8a06aeba7b784df8de984d9d00aeff4.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into t
-rw-r--r-- | src/declarative/util/qfxview.cpp | 65 | ||||
-rw-r--r-- | src/declarative/util/qfxview.h | 2 | ||||
-rw-r--r-- | tools/qmlviewer/qmlviewer.cpp | 267 | ||||
-rw-r--r-- | tools/qmlviewer/qmlviewer.h | 6 |
4 files changed, 241 insertions, 99 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<QWidget *>(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(); diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index 97e29f1..97db22e 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -40,8 +40,91 @@ #include <QFileDialog> #include <QTimer> +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,23 +191,49 @@ 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); skinActions->addAction(skinAction); skinMenu->addAction(skinAction); 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(); 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())); } @@ -143,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; @@ -237,7 +375,17 @@ void QmlViewer::openQml(const QString& fileName) canvas->execute(); qWarning() << "Wall startup time:" << t.elapsed(); - resize(sizeHint()); + 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(); @@ -245,109 +393,39 @@ 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); - } - - 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->setFixedSize(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 // 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(); skin->deleteLater(); } + canvas->setContentResizable(!skin || !scaleSkin); + 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); - skin->setPreviewAndScale(canvas); + canvas->resize(canvas->sizeHint()); + if (scaleSkin) + skin->setPreviewAndScale(canvas); + else + skin->setPreview(canvas); createMenu(0,skin->menu); skin->show(); - QApplication::syncX(); } else { skin = 0; clearMask(); @@ -356,11 +434,14 @@ 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 canvas->move(0,menuBar()->sizeHint().height()+1); setGeometry(g); + layout()->setEnabled(true); show(); } canvas->show(); @@ -395,8 +476,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 && scaleSkin) + skin->setScreenSize(size); } } diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h index 8bbe275..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; @@ -80,6 +84,8 @@ private: int record_autotime; bool devicemode; QAction *recordAction; + QString currentSkin; + bool scaleSkin; QFxTestEngine *testEngine; }; |