on xenial help sign in
render screenshot directly on surface
09bb3ebNick Dedekind
tests/mocks/Unity/Application/ApplicationInfo.cpp+1−1
@@ -84,7 +84,7 @@ void ApplicationInfo::createSurface()
84 m_surface = new MirSurfaceItem(name(),
84 m_surface = new MirSurfaceItem(name(),
85 MirSurfaceItem::Normal,
85 MirSurfaceItem::Normal,
86 fullscreen() ? MirSurfaceItem::Fullscreen : MirSurfaceItem::Maximized,
86 fullscreen() ? MirSurfaceItem::Fullscreen : MirSurfaceItem::Maximized,
87− imageQml());
87+ screenshot());
88 Q_EMIT surfaceChanged(m_surface);
88 Q_EMIT surfaceChanged(m_surface);
89 Q_EMIT SurfaceManager::singleton()->surfaceCreated(m_surface);
89 Q_EMIT SurfaceManager::singleton()->surfaceCreated(m_surface);
90}
90}
tests/mocks/Unity/Application/ApplicationManager.cpp+2−2
@@ -380,8 +380,8 @@ void ApplicationManager::generateQmlStrings(ApplicationInfo *application)
380 .arg(application->icon().toString());
380 .arg(application->icon().toString());
381 application->setImageQml(imageQml);
381 application->setImageQml(imageQml);
382
382
383− application->setScreenshot(QString("file://%1/Dash/graphics/phone/screenshots/%2.png").arg(qmlDirectory())
383+ application->setScreenshot(QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png").arg(qmlDirectory())
384− .arg(application->icon().toString()));
384+ .arg(application->icon().toString()));
385}
385}
386
386
387void ApplicationManager::buildListOfAvailableApplications()
387void ApplicationManager::buildListOfAvailableApplications()
tests/mocks/Unity/Application/MirSurfaceItem.cpp+8−29
@@ -16,46 +16,25 @@
16
16
17#include "MirSurfaceItem.h"
17#include "MirSurfaceItem.h"
18
18
19−#include <QQmlEngine>
19+#include <QPainter>
20−#include <QQmlComponent>
21−#include <QQmlContext>
22−#include <QTimer>
23
20
24MirSurfaceItem::MirSurfaceItem(const QString& name,
21MirSurfaceItem::MirSurfaceItem(const QString& name,
25 MirSurfaceItem::Type type,
22 MirSurfaceItem::Type type,
26 MirSurfaceItem::State state,
23 MirSurfaceItem::State state,
27− const QString& imageQml,
24+ const QUrl& screenshot,
28 QQuickItem *parent)
25 QQuickItem *parent)
29− : QQuickItem(parent)
26+ : QQuickPaintedItem(parent)
30 , m_name(name)
27 , m_name(name)
31 , m_type(type)
28 , m_type(type)
32 , m_state(state)
29 , m_state(state)
33− , m_imageQml(imageQml)
30+ , m_img(screenshot.isLocalFile() ? screenshot.toLocalFile() : screenshot.toString())
34− , m_imageComponent(nullptr)
35− , m_imageItem(nullptr)
36{
31{
32+ setFillColor(Qt::white);
37}
33}
38
34
39−void MirSurfaceItem::itemChange(ItemChange change, const ItemChangeData & value)
35+void MirSurfaceItem::paint(QPainter * painter)
40{
36{
41− QQuickItem::itemChange(change, value);
37+ if (!m_img.isNull()) {
42−
38+ painter->drawImage(contentsBoundingRect(), m_img, QRect(QPoint(0,0), m_img.size()));
43− Q_UNUSED(value)
44− if (change == QQuickItem::ItemParentHasChanged) {
45− createImage();
46− }
47−}
48−
49−void MirSurfaceItem::createImage()
50−{
51− if (!m_imageComponent) {
52− QQmlContext* context = QQmlEngine::contextForObject(parentItem());
53− if (!context) return;
54− m_imageComponent = new QQmlComponent(context->engine(), this);
55− m_imageComponent->setData(m_imageQml.toUtf8(), QUrl());
56− }
57− if (!m_imageItem) {
58− m_imageItem = qobject_cast<QQuickItem *>(m_imageComponent->create());
59− if (m_imageItem) m_imageItem->setParentItem(this);
60 }
39 }
61}
40}
tests/mocks/Unity/Application/MirSurfaceItem.h+7−15
@@ -17,11 +17,10 @@
17#ifndef MIRSURFACEITEM_H
17#ifndef MIRSURFACEITEM_H
18#define MIRSURFACEITEM_H
18#define MIRSURFACEITEM_H
19
19
20−#include <QQuickItem>
20+#include <QQuickPaintedItem>
21+#include <QImage>
21
22
22−class QQmlComponent;
23−
24−class MirSurfaceItem : public QQuickItem
23+class MirSurfaceItem : public QQuickPaintedItem
25{
24{
26 Q_OBJECT
25 Q_OBJECT
27 Q_ENUMS(Type)
26 Q_ENUMS(Type)
@@ -55,7 +54,7 @@ public:
55 explicit MirSurfaceItem(const QString& name,
54 explicit MirSurfaceItem(const QString& name,
56 Type type,
55 Type type,
57 State state,
56 State state,
58− QString const& imageQml,
57+ const QUrl& screenshot,
59 QQuickItem *parent = 0);
58 QQuickItem *parent = 0);
60
59
61 //getters
60 //getters
@@ -65,26 +64,19 @@ public:
65
64
66 Q_INVOKABLE void release() {}
65 Q_INVOKABLE void release() {}
67
66
67+ void paint(QPainter * painter) override;
68+
68Q_SIGNALS:
69Q_SIGNALS:
69 void typeChanged(Type);
70 void typeChanged(Type);
70 void stateChanged(State);
71 void stateChanged(State);
71 void nameChanged(QString);
72 void nameChanged(QString);
72
73
73−protected:
74− void itemChange(ItemChange change, const ItemChangeData& value) override;
75−
76−private Q_SLOTS:
77− void createImage();
78−
79private:
74private:
80
75
81 const QString m_name;
76 const QString m_name;
82 const Type m_type;
77 const Type m_type;
83 const State m_state;
78 const State m_state;
84− const QString m_imageQml;
79+ const QImage m_img;
85−
86− QQmlComponent *m_imageComponent;
87− QQuickItem* m_imageItem;
88};
80};
89
81
90Q_DECLARE_METATYPE(MirSurfaceItem*)
82Q_DECLARE_METATYPE(MirSurfaceItem*)