This repository has been archived by the owner on Nov 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathShellView.cpp
85 lines (74 loc) · 2.98 KB
/
ShellView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Copyright (C) 2015 Canonical, Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ShellView.h"
// Qt
#include <QQmlContext>
#include <QQuickItem>
#include <QtQuick/private/qquickitem_p.h>
#include <QtQuick/private/qquickrectangle_p.h>
#include <QtQuick/private/qquicktext_p.h>
// local
#include <paths.h>
ShellView::ShellView(QQmlEngine *engine, QObject *qmlArgs)
: QQuickView(engine, nullptr)
{
setResizeMode(QQuickView::SizeRootObjectToView);
setColor("black");
setTitle(QStringLiteral("Unity8"));
rootContext()->setContextProperty(QStringLiteral("applicationArguments"), qmlArgs);
connect(this, &QQuickView::statusChanged, this, [this] {
if (status() == QQuickView::Error) {
QQuickRectangle *rect = new QQuickRectangle(contentItem());
rect->setColor(Qt::white);
QQuickItemPrivate::get(rect)->anchors()->setFill(contentItem());
QString errorsString;
for(const QQmlError &e: errors()) {
errorsString += e.toString() + "\n";
}
QQuickText *text = new QQuickText(rect);
text->setColor(Qt::black);
text->setWrapMode(QQuickText::Wrap);
text->setText(QString("There was an error loading Unity8:\n%1").arg(errorsString));
QQuickItemPrivate::get(text)->anchors()->setFill(rect);
}
}
);
QUrl source(::qmlDirectory() + "/OrientedShell.qml");
setSource(source);
connect(this, &QWindow::widthChanged, this, &ShellView::onWidthChanged);
connect(this, &QWindow::heightChanged, this, &ShellView::onHeightChanged);
}
void ShellView::onWidthChanged(int w)
{
// For good measure in case SizeRootObjectToView doesn't fulfill its promise.
//
// There's at least one situation that's know to leave the root object with an outdated size.
// (really looks like Qt bug)
// Happens when starting unity8 with an external monitor already connected.
// The QResizeEvent we get still has the size of the first screen and since the resize move is triggered
// from the resize event handler, the root item doesn't get resized.
// TODO: Confirm the Qt bug and submit a patch upstream
if (rootObject()) {
rootObject()->setWidth(w);
}
}
void ShellView::onHeightChanged(int h)
{
// See comment in ShellView::onWidthChanged()
if (rootObject()) {
rootObject()->setHeight(h);
}
}