diff options
author | Gunnar Sletta <gunnar.sletta@digia.com> | 2013-04-23 11:17:56 +0200 |
---|---|---|
committer | Gunnar Sletta <gunnar.sletta@digia.com> | 2013-04-23 12:32:08 +0300 |
commit | 1e1738828728a73ba60b029e48fa4e74240bc54e (patch) | |
tree | 2138150d18ffce1caed96a20ad759d9c1afc5e38 /screenshot | |
parent | afde6c1b4d53fa6d405d9e6e2f34995a63318bef (diff) |
reskinned launcher
Change-Id: Id4d77db856930e49f2f0e5262da8c580c8fc466e
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@digia.com>
Diffstat (limited to 'screenshot')
-rw-r--r-- | screenshot/Button.qml | 37 | ||||
-rw-r--r-- | screenshot/Main.qml | 137 | ||||
-rw-r--r-- | screenshot/plugin/plugin.cpp | 49 | ||||
-rw-r--r-- | screenshot/plugin/qmldir | 3 | ||||
-rw-r--r-- | screenshot/plugin/screenshot.pro | 17 |
5 files changed, 243 insertions, 0 deletions
diff --git a/screenshot/Button.qml b/screenshot/Button.qml new file mode 100644 index 0000000..0e086a1 --- /dev/null +++ b/screenshot/Button.qml @@ -0,0 +1,37 @@ +import QtQuick 2.0 + +Rectangle { + + width: 100 + height: 40 + + gradient: Gradient { + GradientStop { position: 0; color: pressed ? "steelblue" : "white" } + GradientStop { position: 1; color: pressed ? "lightsteelblue" : "darkgray" } + } + + border.color: pressed ? "darkgray" : "lightgray" + border.width: 1; + + radius: height / 4 + + property alias text: label.text + property alias pressed: mouse.pressed + + signal clicked; + + Text { + id: label + color: "black" + font.pixelSize: parent.size / 2; + anchors.centerIn: parent; + } + + MouseArea { + id: mouse + anchors.fill: parent + + onClicked: parent.clicked() + + } +} diff --git a/screenshot/Main.qml b/screenshot/Main.qml new file mode 100644 index 0000000..8c35868 --- /dev/null +++ b/screenshot/Main.qml @@ -0,0 +1,137 @@ +import QtQuick 2.0 + +import Qt.labs.screenshot 1.0 + +Item +{ + id: root; + + width: 1280 + height: 720 + + Connections { + target: applicationsModel + onReady: listView.listIndex = 0; + } + + ListView { + id: listView + + anchors.fill: parent; + + model: applicationsModel + + delegate: Loader { + width: root.width + height: root.height + source: location + "/main.qml"; + focus: false + clip: true + } + + interactive: false + + property int listIndex: -1; + onListIndexChanged: positionViewAtIndex(listIndex, ListView.Beginning); + function next() { + if (listIndex < count - 1) + ++listIndex; + print("next: updating list index to: ", listIndex, count); + } + function previous() { + if (listIndex > 0) + --listIndex; + print("prev: updating list index to: ", listIndex); + } + + } + + ScreenShot { + id: screenshot; + } + + SequentialAnimation { + id: grabAnimation; + PropertyAction{ target: controls; property: "visible"; value: false } + PauseAnimation { duration: 100 } + ScriptAction { + script: { + var isPortrait = root.width < root.height; + + var size = Qt.size(400, 225); + var smallSize = Qt.size(128, 72); + var loc = applicationsModel.locationAt(listView.listIndex) + "/" + var name = "preview_l" + var ext = ".jpg" + + if (isPortrait) { + name = "preview_p" + size = Qt.size(400, 225); + smallSize = Qt.size(128, 72); + } + + screenshot.grab(loc + name + ext, size); // medium resolution + screenshot.grab(loc + name + "_lr" + ext, smallSize); // low resolution + } + } + PauseAnimation { duration: 100 } + PropertyAction { target: controls; property: "visible"; value: true } + } + + Item { + id: controls + + height: 40 + width: parent.width + + Button { + id: prevButton + width: 100 + text: "<<"; + anchors.left: parent.left + anchors.top: parent.top + anchors.bottom: parent.bottom + anchors.margins: 2 + + onClicked: listView.previous(); + } + + Button { + id: nextButton + width: 100 + height: parent.height + text: ">>"; + + anchors.right: parent.right + anchors.margins: 2 + anchors.top: parent.top + anchors.bottom: parent.bottom + + onClicked: listView.next(); + } + + Button { + text: 'Grab: "' + applicationsModel.nameAt(listView.listIndex) + '"' + height: parent.height + anchors.left: prevButton.right + anchors.right: nextButton.left + anchors.top: parent.top + anchors.bottom: parent.bottom + anchors.margins: 2 + + onClicked: { + grabAnimation.running = true; + } + } + } + + Rectangle { + id: blackOutLine + anchors.fill: parent + color: "transparent" + border.color: "black" + border.width: 3 + visible: !controls.visible + } + +} diff --git a/screenshot/plugin/plugin.cpp b/screenshot/plugin/plugin.cpp new file mode 100644 index 0000000..a06910f --- /dev/null +++ b/screenshot/plugin/plugin.cpp @@ -0,0 +1,49 @@ +#include <QtQml/QQmlExtensionPlugin> + +#include <QtQuick/QQuickItem> +#include <QtQuick/QQuickWindow> + +#include <QtGui/QImageWriter> + +class ScreenShot : public QQuickItem +{ + Q_OBJECT + +public slots: + bool grab(const QString &name, const QSize &size = QSize()) { + if (window()) { + QImage image = window()->grabWindow(); + if (size.width() > 0 && size.height() > 0) + image = image.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + + QImageWriter writer(name); + writer.setQuality(95); + bool ok = writer.write(image); + if (ok) + qDebug("ScreenShot::grab: saved '%s'", qPrintable(name)); + else + qDebug("ScreenShot::grab: Failed to save '%s'", qPrintable(name)); + return ok; + } else { + qWarning("ScreenShot::grab: no window to grab !!"); + } + return false; + } +}; + +QML_DECLARE_TYPE(ScreenShot) + +class ScreenShotPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0") + +public: + virtual void registerTypes(const char *uri) + { + qmlRegisterType<ScreenShot>(uri, 1, 0, "ScreenShot"); + } +}; + +#include "plugin.moc" + diff --git a/screenshot/plugin/qmldir b/screenshot/plugin/qmldir new file mode 100644 index 0000000..49db718 --- /dev/null +++ b/screenshot/plugin/qmldir @@ -0,0 +1,3 @@ +module Qt.labs.screenshot +plugin screenshotplugin + diff --git a/screenshot/plugin/screenshot.pro b/screenshot/plugin/screenshot.pro new file mode 100644 index 0000000..8d672dc --- /dev/null +++ b/screenshot/plugin/screenshot.pro @@ -0,0 +1,17 @@ +TEMPLATE = lib +TARGET = screenshotplugin +QT += quick +CONFIG += qt plugin + +TARGETPATH=Qt/labs/screenshot + +SOURCES += plugin.cpp + +OTHER_FILES = qmldir + +target.path = $$[QT_INSTALL_QML]/$$TARGETPATH + +qmldir.files = qmldir +qmldir.path = $$[QT_INSTALL_QML]/$$TARGETPATH + +INSTALLS = target qmldir |