~ci-train-bot/unity8/unity8-ubuntu-zesty-2404

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
/*
 * 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>

// 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);

    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);
    }
}