on xenial help sign in
Use Item.grabToImage() instead of qtmir's ApplicationScreenshot provider
ad46288Daniel d'Andrada
qml/Stages/ApplicationWindow.qml+5−7
@@ -121,13 +121,11 @@ FocusScope {
121 function take() {
121 function take() {
122 // Save memory by using a half-resolution (thus quarter size) screenshot.
122 // Save memory by using a half-resolution (thus quarter size) screenshot.
123 // Do not make this a binding, we can only take the screenshot once!
123 // Do not make this a binding, we can only take the screenshot once!
124− sourceSize.width = root.width / 2;
124+ sessionContainer.grabToImage(
125− sourceSize.height = root.height / 2;
125+ function(result) {
126−
126+ screenshotImage.source = result.url;
127− // Format: "image://application/$APP_ID/$CURRENT_TIME_MS"
127+ },
128− // eg: "image://application/calculator-app/123456"
128+ Qt.size(root.width / 2, root.height / 2));
129− var timeMs = new Date().getTime();
130− source = "image://application/" + root.application.appId + "/" + timeMs;
131 }
129 }
132 }
130 }
133
131
tests/mocks/Unity/Application/ApplicationScreenshotProvider.cppdeleted−79
@@ -1,79 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software: you can redistribute it and/or modify it under
5− * the terms of the GNU Lesser General Public License version 3, as published by
6− * the Free Software Foundation.
7− *
8− * This program is distributed in the hope that it will be useful, but WITHOUT
9− * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10− * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11− * Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "ApplicationScreenshotProvider.h"
18−#include "ApplicationManager.h"
19−#include "ApplicationInfo.h"
20−
21−#include "paths.h"
22−
23−#include <QDebug>
24−#include <QGuiApplication>
25−#include <QWindow>
26−#include <QQuickWindow>
27−
28−ApplicationScreenshotProvider::ApplicationScreenshotProvider(ApplicationManager *appManager)
29− : QQuickImageProvider(QQuickImageProvider::Image)
30− , m_appManager(appManager)
31−{
32−}
33−
34−QImage ApplicationScreenshotProvider::requestImage(const QString &imageId, QSize * size,
35− const QSize &requestedSize)
36−{
37− // We ignore requestedSize here intentionally to avoid keeping scaled copies around
38− Q_UNUSED(requestedSize)
39−
40− QString appId = imageId.split('/').first();
41−
42− ApplicationInfo* app = static_cast<ApplicationInfo*>(m_appManager->findApplication(appId));
43− if (app == nullptr) {
44− return QImage();
45− }
46−
47− QString screenshot = app->screenshot();
48− // QImage doesn't understand qrc:/// but we have QUrls in use which don't like the empty protcol ":/"
49− screenshot.replace("qrc:///", ":/");
50−
51− QImage image;
52− if (!image.load(screenshot)) {
53− qWarning() << "failed loading app image" << screenshot;
54− }
55−
56−
57− if (app->stage() == ApplicationInfo::SideStage) {
58− QByteArray gus = qgetenv("GRID_UNIT_PX");
59− if (gus.isEmpty() || gus.toInt() == 0) {
60− gus = "8";
61− }
62− image = image.scaledToWidth(gus.toInt() * 48);
63− } else {
64− // Lets scale main stage applications to be the size of the screen/window.
65− QGuiApplication *unity = qobject_cast<QGuiApplication*>(qApp);
66− Q_FOREACH (QWindow *win, unity->allWindows()) {
67− QQuickWindow *quickWin = qobject_cast<QQuickWindow*>(win);
68− if (quickWin) {
69− image = image.scaledToWidth(quickWin->width());
70− break;
71− }
72− }
73− }
74−
75− size->setWidth(image.width());
76− size->setHeight(image.height());
77−
78− return image;
79−}
tests/mocks/Unity/Application/ApplicationScreenshotProvider.hdeleted−34
@@ -1,34 +0,0 @@
1−/*
2− * Copyright (C) 201 Canonical, Ltd.
3− *
4− * This program is free software: you can redistribute it and/or modify it under
5− * the terms of the GNU Lesser General Public License version 3, as published by
6− * the Free Software Foundation.
7− *
8− * This program is distributed in the hope that it will be useful, but WITHOUT
9− * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10− * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11− * Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#ifndef APPLICATIONSCREENSHOTPROVIDER_H
18−#define APPLICATIONSCREENSHOTPROVIDER_H
19−
20−#include <QQuickImageProvider>
21−
22−class ApplicationManager;
23−class ApplicationScreenshotProvider : public QQuickImageProvider
24−{
25−public:
26− explicit ApplicationScreenshotProvider(ApplicationManager *appManager);
27−
28− QImage requestImage(const QString &appId, QSize *size, const QSize &requestedSize) override;
29−
30−private:
31− ApplicationManager* m_appManager;
32−};
33−
34−#endif // APPLICATIONSCREENSHOTPROVIDER_H
tests/mocks/Unity/Application/CMakeLists.txt−1
@@ -2,7 +2,6 @@ set(FakeUnityApplicationQml_SOURCES
2 plugin.cpp
2 plugin.cpp
3 ApplicationInfo.cpp
3 ApplicationInfo.cpp
4 ApplicationManager.cpp
4 ApplicationManager.cpp
5− ApplicationScreenshotProvider.cpp
6 ApplicationTestInterface.cpp
5 ApplicationTestInterface.cpp
7 MirSurface.cpp
6 MirSurface.cpp
8 MirSurfaceItem.cpp
7 MirSurfaceItem.cpp
tests/mocks/Unity/Application/plugin.cpp+1−3
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2013-2015 Canonical, Ltd.
2+ * Copyright (C) 2013-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -17,7 +17,6 @@
17#include "plugin.h"
17#include "plugin.h"
18#include "ApplicationInfo.h"
18#include "ApplicationInfo.h"
19#include "ApplicationManager.h"
19#include "ApplicationManager.h"
20−#include "ApplicationScreenshotProvider.h"
21#include "Session.h"
20#include "Session.h"
22#include "MirSurfaceItem.h"
21#include "MirSurfaceItem.h"
23#include "SurfaceManager.h"
22#include "SurfaceManager.h"
@@ -96,7 +95,6 @@ void FakeUnityApplicationQmlPlugin::initializeEngine(QQmlEngine *engine, const c
96{
95{
97 QQmlExtensionPlugin::initializeEngine(engine, uri);
96 QQmlExtensionPlugin::initializeEngine(engine, uri);
98
97
99− engine->addImageProvider(QLatin1String("application"), new ApplicationScreenshotProvider(ApplicationManager::singleton()));
100 // make sure we initialise our test interface.
98 // make sure we initialise our test interface.
101 applicationTestInterface(engine, nullptr);
99 applicationTestInterface(engine, nullptr);
102}
100}