summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-05-15 04:12:53 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-05-15 04:12:53 (GMT)
commit214b89c2e754c389433ae28889520647b198007d (patch)
tree2ad3fdaaa099c69bef37ef90bee44d30d27d8dc2
parent520c11a1af023b444a9cc0f0720d606cc6146486 (diff)
downloadQt-214b89c2e754c389433ae28889520647b198007d.zip
Qt-214b89c2e754c389433ae28889520647b198007d.tar.gz
Qt-214b89c2e754c389433ae28889520647b198007d.tar.bz2
Skins in UI
(now that deviceskins includes them as qrc, we may as well use them)
-rw-r--r--tools/qmlviewer/main.cpp2
-rw-r--r--tools/qmlviewer/qmlviewer.cpp101
-rw-r--r--tools/qmlviewer/qmlviewer.h2
3 files changed, 82 insertions, 23 deletions
diff --git a/tools/qmlviewer/main.cpp b/tools/qmlviewer/main.cpp
index f27606e..da13c1a 100644
--- a/tools/qmlviewer/main.cpp
+++ b/tools/qmlviewer/main.cpp
@@ -137,7 +137,7 @@ int main(int argc, char ** argv)
viewer.setRecordPeriod(period);
if (autorecord_to)
viewer.setAutoRecord(autorecord_from,autorecord_to);
- if (QDir(skin).exists())
+ if (!skin.isEmpty() && QDir(skin).exists())
viewer.setSkin(skin);
if (devkeys)
viewer.setDeviceKeys(true);
diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp
index 2eddb6a..97e29f1 100644
--- a/tools/qmlviewer/qmlviewer.cpp
+++ b/tools/qmlviewer/qmlviewer.cpp
@@ -24,6 +24,7 @@
#include <QNetworkDiskCache>
#include <QNetworkAccessManager>
+#include <QSignalMapper>
#include <QmlComponent>
#include <QWidget>
#include <QApplication>
@@ -77,14 +78,16 @@ QSize QmlViewer::sizeHint() const
void QmlViewer::createMenu(QMenuBar *menu, QMenu *flatmenu)
{
+ QObject *parent = flatmenu ? (QObject*)flatmenu : (QObject*)menu;
+
QMenu *fileMenu = flatmenu ? flatmenu : menu->addMenu(tr("&File"));
- QAction *openAction = new QAction(tr("&Open..."), this);
+ QAction *openAction = new QAction(tr("&Open..."), parent);
openAction->setShortcut(QKeySequence("Ctrl+O"));
connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
fileMenu->addAction(openAction);
- QAction *reloadAction = new QAction(tr("&Reload"), this);
+ QAction *reloadAction = new QAction(tr("&Reload"), parent);
reloadAction->setShortcut(QKeySequence("Ctrl+R"));
connect(reloadAction, SIGNAL(triggered()), this, SLOT(reload()));
fileMenu->addAction(reloadAction);
@@ -93,27 +96,51 @@ void QmlViewer::createMenu(QMenuBar *menu, QMenu *flatmenu)
QMenu *recordMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Recording"));
- QAction *snapshotAction = new QAction(tr("&Take Snapsot\tF3"), this);
+ QAction *snapshotAction = new QAction(tr("&Take Snapsot\tF3"), parent);
connect(snapshotAction, SIGNAL(triggered()), this, SLOT(takeSnapShot()));
recordMenu->addAction(snapshotAction);
- recordAction = new QAction(tr("Start Recording &Video\tF2"), this);
+ recordAction = new QAction(tr("Start Recording &Video\tF2"), parent);
connect(recordAction, SIGNAL(triggered()), this, SLOT(toggleRecordingWithSelection()));
recordMenu->addAction(recordAction);
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);
+ skinActions->addAction(skinAction);
+ skinMenu->addAction(skinAction);
+ mapper->setMapping(skinAction, "");
+ connect(skinAction, SIGNAL(triggered()), mapper, SLOT(map()));
+ skinMenu->addSeparator();
+ 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);
+ mapper->setMapping(skinAction, file);
+ connect(skinAction, SIGNAL(triggered()), mapper, SLOT(map()));
+ }
+ //connect(skinActions, SIGNAL(triggered(QAction*)), mapper, SLOT(map(QObject*))); // "incompatible"
+ connect(mapper, SIGNAL(mapped(QString)), this, SLOT(setSkin(QString)));
+
+ if (flatmenu) flatmenu->addSeparator();
+
QMenu *helpMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Help"));
- QAction *aboutAction = new QAction(tr("&About Qt..."), this);
+ QAction *aboutAction = new QAction(tr("&About Qt..."), parent);
connect(aboutAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
helpMenu->addAction(aboutAction);
- QAction *quitAction = new QAction(tr("&Quit"), this);
+ QAction *quitAction = new QAction(tr("&Quit"), parent);
quitAction->setShortcut(QKeySequence("Ctrl+Q"));
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
fileMenu->addSeparator();
fileMenu->addAction(quitAction);
-
}
void QmlViewer::takeSnapShot()
@@ -217,13 +244,16 @@ void QmlViewer::openQml(const QString& fileName)
#endif
}
-class PreviewDeviceSkin : public DeviceSkin
+
+class PreviewDeviceSkin : public DeviceSkin
{
Q_OBJECT
public:
explicit PreviewDeviceSkin(const DeviceSkinParameters &parameters, QWidget *parent);
void setPreview(QWidget *formWidget);
+ void setPreviewAndScale(QWidget *formWidget);
+
void setScreenSize(const QSize& size)
{
QMatrix fit;
@@ -264,6 +294,15 @@ void PreviewDeviceSkin::setPreview(QWidget *formWidget)
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()) {
@@ -288,22 +327,43 @@ void PreviewDeviceSkin::slotPopupMenu()
void QmlViewer::setSkin(const QString& skinDirectory)
{
- DeviceSkinParameters parameters;
+ // 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...
+
QString err;
- if (parameters.read(skinDirectory,DeviceSkinParameters::ReadAll,&err)) {
- delete skin;
+ if (skin) {
+ skin->hide();
+ skin->deleteLater();
+ }
+
+ DeviceSkinParameters parameters;
+ if (!skinDirectory.isEmpty() && parameters.read(skinDirectory,DeviceSkinParameters::ReadAll,&err)) {
+ if (menuBar())
+ menuBar()->deleteLater();
if (!err.isEmpty())
qWarning() << err;
- delete menuBar();
skin = new PreviewDeviceSkin(parameters,this);
- skin->setScreenSize(canvas->sizeHint());
- canvas->setParent(skin, Qt::SubWindow);
- canvas->setAutoFillBackground(true);
- skin->setView(canvas);
+ skin->setPreviewAndScale(canvas);
createMenu(0,skin->menu);
-
- canvas->show();
+ skin->show();
+ QApplication::syncX();
+ } else {
+ skin = 0;
+ clearMask();
+ menuBar()->clear();
+ canvas->setParent(this, Qt::SubWindow);
+ createMenu(menuBar(),0);
+ setMinimumSize(QSize(0,0));
+ setMaximumSize(QSize(16777215,16777215));
+ QRect g = geometry();
+ g.setSize(sizeHint());
+ setParent(0,windowFlags()); // recreate
+ canvas->move(0,menuBar()->sizeHint().height()+1);
+ setGeometry(g);
+ show();
}
+ canvas->show();
}
void QmlViewer::setAutoRecord(int from, int to)
@@ -335,8 +395,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);
}
}
@@ -395,7 +455,6 @@ void QmlViewer::setRecording(bool on)
connect(proc, SIGNAL(finished(int)), this, SLOT(ffmpegFinished(int)));
frame_stream = proc;
-qDebug() << canvas->width() << canvas->height();
QStringList args;
args << "-sameq"; // ie. high
args << "-y";
diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h
index 0748de4..8bbe275 100644
--- a/tools/qmlviewer/qmlviewer.h
+++ b/tools/qmlviewer/qmlviewer.h
@@ -40,7 +40,6 @@ public:
void setRecording(bool on);
bool isRecording() const { return recordTimer.isActive(); }
void setAutoRecord(int from, int to);
- void setSkin(const QString& skinDirectory);
void setDeviceKeys(bool);
void setCacheEnabled(bool);
@@ -55,6 +54,7 @@ public slots:
void toggleRecording();
void toggleRecordingWithSelection();
void ffmpegFinished(int code);
+ void setSkin(const QString& skinDirectory);
protected:
virtual void keyPressEvent(QKeyEvent *);