diff options
author | Bea Lam <bea.lam@nokia.com> | 2009-10-07 00:49:27 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2009-10-07 00:49:27 (GMT) |
commit | 1042b1e1930131750d54112ec8f3deb6f70a9c76 (patch) | |
tree | eb21c6aefe0830ff78fcf9c8cca2ede86aaa4ab2 /tools/qmlviewer | |
parent | e0eca3530d566200da46bb5d52abb76fcd98a2f8 (diff) | |
download | Qt-1042b1e1930131750d54112ec8f3deb6f70a9c76.zip Qt-1042b1e1930131750d54112ec8f3deb6f70a9c76.tar.gz Qt-1042b1e1930131750d54112ec8f3deb6f70a9c76.tar.bz2 |
Fix so items are stretched to width of viewer if viewer is resized;
otherwise, shrink viewer to width of main canvas item. (Last fix did
not work because usually items should resize with the viewer.)
Diffstat (limited to 'tools/qmlviewer')
-rw-r--r-- | tools/qmlviewer/qmlviewer.cpp | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index e185536..07b68ea 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -55,6 +55,26 @@ QT_BEGIN_NAMESPACE + +class SizedMenuBar : public QMenuBar +{ + Q_OBJECT +public: + SizedMenuBar(QWidget *parent, QWidget *referenceWidget) + : QMenuBar(parent), refWidget(referenceWidget) + { + } + + virtual QSize sizeHint() const + { + return QSize(refWidget->sizeHint().width(), QMenuBar::sizeHint().height()); + } + +private: + QWidget *refWidget; +}; + + class PreviewDeviceSkin : public DeviceSkin { Q_OBJECT @@ -281,10 +301,6 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) } else { recdlg->warning->hide(); } - - - if (!(flags & Qt::FramelessWindowHint)) - createMenu(menuBar(),0); canvas = new QmlView(this); canvas->setAttribute(Qt::WA_OpaquePaintEvent); @@ -296,13 +312,16 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize))); QObject::connect(canvas, SIGNAL(errors(QList<QmlError>)), this, SLOT(executeErrors())); + if (!(flags & Qt::FramelessWindowHint)) + createMenu(menuBar(),0); + QVBoxLayout *layout = new QVBoxLayout; layout->setMargin(0); layout->setSpacing(0); setLayout(layout); if (mb) layout->addWidget(mb); - layout->addWidget(canvas, 0, Qt::AlignLeft); + layout->addWidget(canvas); setupProxy(); canvas->engine()->networkAccessManager()->setCookieJar(new PersistentCookieJar(this)); @@ -319,7 +338,7 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) QMenuBar *QmlViewer::menuBar() const { if (!mb) - mb = new QMenuBar((QWidget*)this); + mb = new SizedMenuBar((QWidget*)this, canvas); return mb; } @@ -650,8 +669,8 @@ void QmlViewer::openQml(const QString& fileName) if (!skin) { canvas->updateGeometry(); - canvas->resize(canvas->sizeHint()); - canvas->updateGeometry(); + if (mb) + mb->updateGeometry(); resize(sizeHint()); } else { if (scaleSkin) |