Unity 8
ShellView.cpp
1 /*
2  * Copyright (C) 2015 Canonical, Ltd.
3  *
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
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #include "ShellView.h"
18 
19 // Qt
20 #include <QQmlContext>
21 #include <QQuickItem>
22 
23 // local
24 #include <paths.h>
25 
26 ShellView::ShellView(QQmlEngine *engine, QObject *qmlArgs)
27  : QQuickView(engine, nullptr)
28 {
29  setResizeMode(QQuickView::SizeRootObjectToView);
30  setColor("black");
31  setTitle(QStringLiteral("Unity8"));
32 
33  rootContext()->setContextProperty(QStringLiteral("applicationArguments"), qmlArgs);
34 
35  QUrl source(::qmlDirectory() + "/OrientedShell.qml");
36  setSource(source);
37 
38  connect(this, &QWindow::widthChanged, this, &ShellView::onWidthChanged);
39  connect(this, &QWindow::heightChanged, this, &ShellView::onHeightChanged);
40 }
41 
42 void ShellView::onWidthChanged(int w)
43 {
44  // For good measure in case SizeRootObjectToView doesn't fulfill its promise.
45  //
46  // There's at least one situation that's know to leave the root object with an outdated size.
47  // (really looks like Qt bug)
48  // Happens when starting unity8 with an external monitor already connected.
49  // The QResizeEvent we get still has the size of the first screen and since the resize move is triggered
50  // from the resize event handler, the root item doesn't get resized.
51  // TODO: Confirm the Qt bug and submit a patch upstream
52  rootObject()->setWidth(w);
53 }
54 
55 void ShellView::onHeightChanged(int h)
56 {
57  // See comment in ShellView::onWidthChanged()
58  rootObject()->setHeight(h);
59 }