on xenial help sign in
drop all the unity-mir style code in MockApplicationManager.

There's no need to fake that surface behind the shell any more. Actually this should have gone away with QtComp already, but only this branch makes it visible now.

commitf7f70638b73ac26e49396c40b173d7c3c580c1de authorMichael Zanetti <michael.zanetti@canonical.com> dateFri 25 Jul 2014, 02:10 (12 years ago) parent5fa08c1
5 files changed+1−230
tests/mocks/Unity/Application/ApplicationInfo.cpp−62 tests/mocks/Unity/Application/ApplicationInfo.h−10 tests/mocks/Unity/Application/ApplicationManager.cpp−141 tests/mocks/Unity/Application/ApplicationManager.h−16 tests/mocks/Unity/Application/ApplicationScreenshotProvider.cpp+1−1
tests/mocks/Unity/Application/ApplicationInfo.cpp−62
@@ -31,8 +31,6 @@ ApplicationInfo::ApplicationInfo(const QString &appId, QObject *parent)
3131 , m_state(Starting)
3232 , m_focused(false)
3333 , m_fullscreen(false)
34− , m_windowItem(0)
35− , m_windowComponent(0)
3634 , m_parentItem(0)
3735 , m_surface(0)
3836{
@@ -45,8 +43,6 @@ ApplicationInfo::ApplicationInfo(QObject *parent)
4543 , m_state(Starting)
4644 , m_focused(false)
4745 , m_fullscreen(false)
48− , m_windowItem(0)
49− , m_windowComponent(0)
5046 , m_parentItem(0)
5147 , m_surface(0)
5248{
@@ -61,12 +57,6 @@ ApplicationInfo::~ApplicationInfo()
6157 }
6258}
6359
64−void ApplicationInfo::onWindowComponentStatusChanged(QQmlComponent::Status status)
65−{
66− if (status == QQmlComponent::Ready && !m_windowItem)
67− doCreateWindowItem();
68−}
69−
7060void ApplicationInfo::onStateChanged(State state)
7161{
7262 if (state == ApplicationInfo::Running) {
@@ -108,55 +98,3 @@ void ApplicationInfo::setSurface(MirSurfaceItem* surface)
10898 Q_EMIT surfaceChanged(m_surface);
10999 SurfaceManager::singleton()->registerSurface(m_surface);
110100}
111−
112−void ApplicationInfo::createWindowComponent()
113−{
114− // The assumptions I make here really should hold.
115− QQuickView *quickView =
116− qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
117−
118− QQmlEngine *engine = quickView->engine();
119−
120− m_windowComponent = new QQmlComponent(engine, this);
121− m_windowComponent->setData(m_windowQml.toLatin1(), QUrl());
122−}
123−
124−void ApplicationInfo::doCreateWindowItem()
125−{
126− m_windowItem = qobject_cast<QQuickItem *>(m_windowComponent->create());
127− m_windowItem->setParentItem(m_parentItem);
128−}
129−
130−void ApplicationInfo::createWindowItem()
131−{
132− if (!m_windowComponent)
133− createWindowComponent();
134−
135− // only create the windowItem once the component is ready
136− if (!m_windowComponent->isReady()) {
137− connect(m_windowComponent, &QQmlComponent::statusChanged,
138− this, &ApplicationInfo::onWindowComponentStatusChanged);
139− } else {
140− doCreateWindowItem();
141− }
142−}
143−
144−void ApplicationInfo::showWindow(QQuickItem *parent)
145−{
146− m_parentItem = parent;
147−
148− if (!m_windowItem)
149− createWindowItem();
150−
151− if (m_windowItem) {
152− m_windowItem->setVisible(true);
153− }
154−}
155−
156−void ApplicationInfo::hideWindow()
157−{
158− if (!m_windowItem)
159− return;
160−
161− m_windowItem->setVisible(false);
162−}
tests/mocks/Unity/Application/ApplicationInfo.h−10
@@ -88,22 +88,12 @@ public:
8888Q_SIGNALS:
8989 void surfaceChanged(MirSurfaceItem*);
9090
91−public:
92− void showWindow(QQuickItem *parent);
93− void hideWindow();
94−
9591private Q_SLOTS:
96− void onWindowComponentStatusChanged(QQmlComponent::Status status);
9792 void onStateChanged(State state);
9893
9994 void createSurface();
10095
10196private:
102− void createWindowItem();
103− void doCreateWindowItem();
104− void createWindowComponent();
105− QQuickItem *m_windowItem;
106− QQmlComponent *m_windowComponent;
10797 QQuickItem *m_parentItem;
10898 MirSurfaceItem* m_surface;
10999};
tests/mocks/Unity/Application/ApplicationManager.cpp−141
@@ -48,11 +48,6 @@ ApplicationManager *ApplicationManager::singleton()
4848ApplicationManager::ApplicationManager(QObject *parent)
4949 : ApplicationManagerInterface(parent)
5050 , m_suspended(false)
51− , m_mainStageComponent(0)
52− , m_mainStage(0)
53− , m_sideStageComponent(0)
54− , m_sideStage(0)
55− , m_rightMargin(0)
5651{
5752 m_roleNames.insert(RoleSurface, "surface");
5853 m_roleNames.insert(RoleFullscreen, "fullscreen");
@@ -300,39 +295,25 @@ bool ApplicationManager::focusApplication(const QString &appId)
300295 for (ApplicationInfo *app : m_runningApplications) {
301296 if (app->focused() && app->stage() == ApplicationInfo::MainStage) {
302297 app->setFocused(false);
303− app->hideWindow();
304298 app->setState(ApplicationInfo::Suspended);
305299 }
306300 }
307301
308302 // focus this app
309303 application->setFocused(true);
310− if (!m_mainStage)
311− createMainStage();
312304 application->setState(ApplicationInfo::Running);
313− application->showWindow(m_mainStage);
314− m_mainStage->setZ(-1000);
315− if (m_sideStage)
316− m_sideStage->setZ(-2000);
317305 } else if (application->stage() == ApplicationInfo::SideStage) {
318306 // unfocus currently focused sidestage app
319307 for (ApplicationInfo *app : m_runningApplications) {
320308 if (app->focused() && app->stage() == ApplicationInfo::SideStage) {
321309 app->setFocused(false);
322− app->hideWindow();
323310 app->setState(ApplicationInfo::Suspended);
324311 }
325312 }
326313
327314 // focus this app
328315 application->setFocused(true);
329− if (!m_sideStage)
330− createSideStage();
331316 application->setState(ApplicationInfo::Running);
332− application->showWindow(m_sideStage);
333− m_sideStage->setZ(-1000);
334− if (m_mainStage)
335− m_mainStage->setZ(-2000);
336317 }
337318
338319 // move app to top of stack
@@ -354,7 +335,6 @@ void ApplicationManager::unfocusCurrentApplication()
354335{
355336 for (ApplicationInfo *app : m_runningApplications) {
356337 if (app->focused()) {
357− app->hideWindow();
358338 app->setFocused(false);
359339 }
360340 }
@@ -363,42 +343,6 @@ void ApplicationManager::unfocusCurrentApplication()
363343
364344void ApplicationManager::generateQmlStrings(ApplicationInfo *application)
365345{
366− // TODO: Is there a better way of solving this fullscreen vs. regular
367− // application height?
368− QString topMargin;
369− if (application->fullscreen()) {
370− topMargin.append("0");
371− } else {
372− // Taken from Panel.panelHeight
373− topMargin.append("units.gu(3) + units.dp(2)");
374− }
375−
376− QString windowQml = QString(
377− "import QtQuick 2.0\n"
378− "Image {\n"
379− " anchors.fill: parent\n"
380− " anchors.topMargin: %1\n"
381− " anchors.rightMargin: %2\n"
382− " source: \"file://%3/Dash/graphics/phone/screenshots/%4.png\"\n"
383− " smooth: true\n"
384− " fillMode: Image.PreserveAspectCrop\n"
385− "}").arg(topMargin)
386− .arg(m_rightMargin)
387− .arg(qmlDirectory())
388− .arg(application->icon().toString());
389− application->setWindowQml(windowQml);
390−
391− QString imageQml = QString(
392− "import QtQuick 2.0\n"
393− "Image {\n"
394− " anchors.fill: parent\n"
395− " source: \"file://%1/Dash/graphics/phone/screenshots/%2.png\"\n"
396− " smooth: true\n"
397− " fillMode: Image.PreserveAspectCrop\n"
398− "}").arg(qmlDirectory())
399− .arg(application->icon().toString());
400− application->setImageQml(imageQml);
401−
402346 application->setScreenshot(QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png").arg(qmlDirectory())
403347 .arg(application->icon().toString()));
404348}
@@ -535,78 +479,6 @@ void ApplicationManager::buildListOfAvailableApplications()
535479 m_availableApplications.append(application);
536480}
537481
538−void ApplicationManager::createMainStageComponent()
539−{
540− // The assumptions I make here really should hold.
541− QQuickView *quickView =
542− qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
543−
544− QQmlEngine *engine = quickView->engine();
545−
546− m_mainStageComponent = new QQmlComponent(engine, this);
547− QString mainStageQml =
548− "import QtQuick 2.0\n"
549− "Rectangle {\n"
550− " anchors.fill: parent\n"
551− " color: 'black'\n"
552− " z: -2000\n"
553− "}\n";
554− m_mainStageComponent->setData(mainStageQml.toLatin1(), QUrl());
555−}
556−
557−void ApplicationManager::createMainStage()
558−{
559− if (!m_mainStageComponent)
560− createMainStageComponent();
561−
562− // The assumptions I make here really should hold.
563− QQuickView *quickView =
564− qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
565−
566− QQuickItem *shell = quickView->rootObject();
567−
568− m_mainStage = qobject_cast<QQuickItem *>(m_mainStageComponent->create());
569− m_mainStage->setParentItem(shell);
570−}
571−
572−void ApplicationManager::createSideStageComponent()
573−{
574− // The assumptions I make here really should hold.
575− QQuickView *quickView =
576− qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
577−
578− QQmlEngine *engine = quickView->engine();
579−
580− m_sideStageComponent = new QQmlComponent(engine, this);
581− QString sideStageQml =
582− "import QtQuick 2.0\n"
583− "import Ubuntu.Components 0.1\n"
584− "Item {\n"
585− " width: units.gu(40)\n" // from SideStage in Shell.qml
586− " anchors.top: parent.top\n"
587− " anchors.bottom: parent.bottom\n"
588− " anchors.right: parent.right\n"
589− " z: -1000\n"
590− "}\n";
591− m_sideStageComponent->setData(sideStageQml.toLatin1(), QUrl());
592−}
593−
594−void ApplicationManager::createSideStage()
595−{
596− if (!m_sideStageComponent)
597− createSideStageComponent();
598−
599− // The assumptions I make here really should hold.
600− QQuickView *quickView =
601− qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
602−
603− QQuickItem *shell = quickView->rootObject();
604−
605− m_sideStage = qobject_cast<QQuickItem *>(m_sideStageComponent->create());
606− m_sideStage->setParentItem(shell);
607− m_sideStage->setFlag(QQuickItem::ItemHasContents, false);
608−}
609−
610482QStringList ApplicationManager::availableApplications()
611483{
612484 QStringList appIds;
@@ -616,19 +488,6 @@ QStringList ApplicationManager::availableApplications()
616488 return appIds;
617489}
618490
619−int ApplicationManager::rightMargin() const
620−{
621− return m_rightMargin;
622−}
623−
624−void ApplicationManager::setRightMargin(int rightMargin)
625−{
626− m_rightMargin = rightMargin;
627− Q_FOREACH(ApplicationInfo *app, m_availableApplications) {
628− generateQmlStrings(app);
629− }
630−}
631−
632491bool ApplicationManager::isEmpty() const
633492{
634493 return m_runningApplications.isEmpty();
tests/mocks/Unity/Application/ApplicationManager.h−16
@@ -44,10 +44,6 @@ class ApplicationManager : public ApplicationManagerInterface {
4444
4545 Q_PROPERTY(bool fake READ fake CONSTANT)
4646
47− // Only for testing
48− // This can be used to place some controls to right, like make tryPhoneStage for example
49− Q_PROPERTY(int rightMargin READ rightMargin WRITE setRightMargin)
50−
5147 public:
5248 ApplicationManager(QObject *parent = NULL);
5349 virtual ~ApplicationManager();
@@ -108,8 +104,6 @@ class ApplicationManager : public ApplicationManagerInterface {
108104
109105 // Only for testing
110106 Q_INVOKABLE QStringList availableApplications();
111− int rightMargin() const;
112− void setRightMargin(int rightMargin);
113107
114108 QModelIndex findIndex(ApplicationInfo* application);
115109
@@ -126,19 +120,9 @@ class ApplicationManager : public ApplicationManagerInterface {
126120 void showApplicationWindow(ApplicationInfo *application);
127121 void buildListOfAvailableApplications();
128122 void generateQmlStrings(ApplicationInfo *application);
129− void createMainStageComponent();
130− void createMainStage();
131− void createSideStageComponent();
132− void createSideStage();
133123 bool m_suspended;
134124 QList<ApplicationInfo*> m_runningApplications;
135125 QList<ApplicationInfo*> m_availableApplications;
136− QQmlComponent *m_mainStageComponent;
137− QQuickItem *m_mainStage;
138− QQmlComponent *m_sideStageComponent;
139− QQuickItem *m_sideStage;
140−
141− int m_rightMargin;
142126
143127 static ApplicationManager *the_application_manager;
144128};
tests/mocks/Unity/Application/ApplicationScreenshotProvider.cpp+1−1
@@ -64,7 +64,7 @@ QImage ApplicationScreenshotProvider::requestImage(const QString &imageId, QSize
6464 Q_FOREACH (QWindow *win, unity->allWindows()) {
6565 QQuickWindow *quickWin = qobject_cast<QQuickWindow*>(win);
6666 if (quickWin) {
67− image = image.scaledToWidth(quickWin->width() - m_appManager->rightMargin());
67+ image = image.scaledToWidth(quickWin->width());
6868 break;
6969 }
7070 }