summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--demos/declarative/flickr/flickr.qml25
-rw-r--r--src/declarative/util/qfxview.cpp17
-rw-r--r--src/declarative/util/qfxview.h2
-rw-r--r--tools/qmlviewer/qmlviewer.cpp70
-rw-r--r--tools/qmlviewer/qmlviewer.h6
5 files changed, 81 insertions, 39 deletions
diff --git a/demos/declarative/flickr/flickr.qml b/demos/declarative/flickr/flickr.qml
index fa3bc35..b33b00f 100644
--- a/demos/declarative/flickr/flickr.qml
+++ b/demos/declarative/flickr/flickr.qml
@@ -119,8 +119,10 @@ Item {
Item {
id: Background
+
+ anchors.fill: parent
- Image { source: "content/pics/background.png"; opaque: true }
+ Image { source: "content/pics/background.png"; opaque: true; anchors.fill: parent }
GridView {
id: PhotoGridView; model: FeedModel; delegate: PhotoDelegate; cacheBuffer: 100
@@ -203,4 +205,25 @@ Item {
(FeedModel.tags=="" ? "Uploads from everyone" : "Recent Uploads tagged " + FeedModel.tags)
font.size: 16; font.bold: true; color: "white"; style: "Raised"; styleColor: "black"
}
+
+ Image {
+ source: "content/pics/fingerpoint.png"
+ opacity: finger.pressed ? 0 : 1
+ x: finger.mouseX-16
+ y: finger.mouseY-16
+ }
+
+ Image {
+ source: "content/pics/fingerpoint-pressed.png"
+ opacity: finger.pressed ? 1.0 : 0.0
+ x: finger.mouseX-16
+ y: finger.mouseY-16
+ }
+
+ MouseRegion {
+ // this region is just to show where the finger is (good for videos)
+ id: finger
+ absorb: false
+ anchors.fill: parent
+ }
}
diff --git a/src/declarative/util/qfxview.cpp b/src/declarative/util/qfxview.cpp
index 078916b..e17decf 100644
--- a/src/declarative/util/qfxview.cpp
+++ b/src/declarative/util/qfxview.cpp
@@ -105,6 +105,8 @@ public:
QmlComponent *component;
QBasicTimer resizetimer;
+ QSize initialSize;
+
void init();
};
@@ -137,6 +139,7 @@ public:
QFxView::QFxView(QWidget *parent)
: QSimpleCanvas(parent), d(new QFxViewPrivate(this))
{
+ setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
d->init();
}
@@ -150,6 +153,7 @@ QFxView::QFxView(QWidget *parent)
QFxView::QFxView(QSimpleCanvas::CanvasMode mode, QWidget *parent)
: QSimpleCanvas(mode, parent), d(new QFxViewPrivate(this))
{
+ setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
d->init();
}
@@ -381,10 +385,23 @@ void QFxView::timerEvent(QTimerEvent* e)
if (d->root)
emit sceneResized(QSize(d->root->width(),d->root->height()));
d->resizetimer.stop();
+ updateGeometry();
}
}
/*!
+ The size hint is the size of the root item.
+*/
+QSize QFxView::sizeHint() const
+{
+ if (d->initialSize.width() <= 0)
+ d->initialSize.setWidth(d->root->width());
+ if (d->initialSize.height() <= 0)
+ d->initialSize.setHeight(d->root->height());
+ return d->initialSize;
+}
+
+/*!
Creates a \l{QmlComponent} {component} from the \a qml
string, and returns it as an \l {QFxItem} {item}. If the
\a parent item is provided, it becomes the new item's
diff --git a/src/declarative/util/qfxview.h b/src/declarative/util/qfxview.h
index f575f27..d6f786c 100644
--- a/src/declarative/util/qfxview.h
+++ b/src/declarative/util/qfxview.h
@@ -82,6 +82,8 @@ public:
virtual QFxItem *root() const;
+ QSize sizeHint() const;
+
void dumpRoot();
static void printErrorLine(const QmlError &);
diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp
index 8457972..bd52b46 100644
--- a/tools/qmlviewer/qmlviewer.cpp
+++ b/tools/qmlviewer/qmlviewer.cpp
@@ -49,27 +49,34 @@ QmlViewer::QmlViewer(QFxTestEngine::TestMode testMode, const QString &testDir, Q
record_autotime = 0;
record_period = 20;
- int width = 240;
- int height = 320;
-
setAttribute(Qt::WA_OpaquePaintEvent);
setAttribute(Qt::WA_NoSystemBackground);
if (!(flags & Qt::FramelessWindowHint))
- createMenuBar();
+ createMenu(menuBar(),0);
canvas = new QFxView(this);
if(testMode != QFxTestEngine::NoTest)
testEngine = new QFxTestEngine(testMode, testDir, canvas, this);
QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize)));
- canvas->setFixedSize(width, height);
- resize(width, height);
+
setCentralWidget(canvas);
}
-void QmlViewer::createMenuBar()
+QSize QmlViewer::sizeHint() const
{
- QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
+ if (skin)
+ return QMainWindow::sizeHint();
+ else {
+ QSize sh = canvas->sizeHint();
+ sh.setHeight(sh.height()+menuBar()->sizeHint().height());
+ return sh;
+ }
+}
+
+void QmlViewer::createMenu(QMenuBar *menu, QMenu *flatmenu)
+{
+ QMenu *fileMenu = flatmenu ? flatmenu : menu->addMenu(tr("&File"));
QAction *openAction = new QAction(tr("&Open..."), this);
openAction->setShortcut(QKeySequence("Ctrl+O"));
@@ -81,13 +88,9 @@ void QmlViewer::createMenuBar()
connect(reloadAction, SIGNAL(triggered()), this, SLOT(reload()));
fileMenu->addAction(reloadAction);
- QAction *quitAction = new QAction(tr("&Quit"), this);
- quitAction->setShortcut(QKeySequence("Ctrl+Q"));
- connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
- fileMenu->addSeparator();
- fileMenu->addAction(quitAction);
+ if (flatmenu) flatmenu->addSeparator();
- QMenu *recordMenu = menuBar()->addMenu(tr("&Recording"));
+ QMenu *recordMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Recording"));
QAction *snapshotAction = new QAction(tr("&Take Snapsot\tF3"), this);
connect(snapshotAction, SIGNAL(triggered()), this, SLOT(takeSnapShot()));
@@ -97,10 +100,19 @@ void QmlViewer::createMenuBar()
connect(recordAction, SIGNAL(triggered()), this, SLOT(toggleRecordingWithSelection()));
recordMenu->addAction(recordAction);
- QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
+ if (flatmenu) flatmenu->addSeparator();
+
+ QMenu *helpMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Help"));
QAction *aboutAction = new QAction(tr("&About Qt..."), this);
connect(aboutAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
helpMenu->addAction(aboutAction);
+
+ QAction *quitAction = new QAction(tr("&Quit"), this);
+ quitAction->setShortcut(QKeySequence("Ctrl+Q"));
+ connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ fileMenu->addSeparator();
+ fileMenu->addAction(quitAction);
+
}
void QmlViewer::takeSnapShot()
@@ -216,13 +228,14 @@ public:
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:
- void populateContextMenu(QMenu *menu);
const QSize m_screenSize;
};
@@ -231,6 +244,7 @@ PreviewDeviceSkin::PreviewDeviceSkin(const DeviceSkinParameters &parameters, QWi
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)),
@@ -265,14 +279,7 @@ void PreviewDeviceSkin::slotSkinKeyReleaseEvent(int code, const QString& text, b
void PreviewDeviceSkin::slotPopupMenu()
{
- QMenu menu(this);
- populateContextMenu(&menu);
- menu.exec(QCursor::pos());
-}
-
-void PreviewDeviceSkin::populateContextMenu(QMenu *menu)
-{
- connect(menu->addAction(tr("&Close")), SIGNAL(triggered()), parentWidget(), SLOT(close()));
+ menu->exec(QCursor::pos());
}
void QmlViewer::setSkin(const QString& skinDirectory)
@@ -283,12 +290,13 @@ void QmlViewer::setSkin(const QString& skinDirectory)
delete skin;
if (!err.isEmpty())
qWarning() << err;
+ delete menuBar();
skin = new PreviewDeviceSkin(parameters,this);
- skin->setScreenSize(canvas->size());
+ skin->setScreenSize(canvas->sizeHint());
canvas->setParent(skin, Qt::SubWindow);
canvas->setAutoFillBackground(true);
skin->setView(canvas);
- delete layout();
+ createMenu(0,skin->menu);
canvas->show();
}
@@ -318,21 +326,11 @@ void QmlViewer::setRecordPeriod(int ms)
void QmlViewer::sceneResized(QSize size)
{
if (size.width() > 0 && size.height() > 0) {
- canvas->setFixedSize(size.width(), size.height());
if (skin)
skin->setScreenSize(size);
- else
- resize(size);
}
}
-void QmlViewer::resizeEvent(QResizeEvent *e)
-{
- QMainWindow::resizeEvent(e);
- //if (!skin)
- //canvas->setFixedSize(width(),height());
-}
-
void QmlViewer::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_0 && devicemode)
diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h
index fc8a427..3f17912 100644
--- a/tools/qmlviewer/qmlviewer.h
+++ b/tools/qmlviewer/qmlviewer.h
@@ -31,7 +31,6 @@ Q_OBJECT
public:
QmlViewer(QFxTestEngine::TestMode = QFxTestEngine::NoTest, const QString &testDir = QString(), QWidget *parent=0, Qt::WindowFlags flags=0);
- void createMenuBar();
void setRecordDither(const QString& s) { record_dither = s; }
void setRecordPeriod(int ms);
void setRecordFile(const QString&);
@@ -43,6 +42,8 @@ public:
void setDeviceKeys(bool);
void setCacheEnabled(bool);
+ QSize sizeHint() const;
+
public slots:
void sceneResized(QSize size);
void openQml(const QString& fileName);
@@ -55,7 +56,8 @@ public slots:
protected:
virtual void keyPressEvent(QKeyEvent *);
virtual void timerEvent(QTimerEvent *);
- virtual void resizeEvent(QResizeEvent *);
+
+ void createMenu(QMenuBar *menu, QMenu *flatmenu);
private:
QString currentFileName;