on xenial help sign in
set minimum window sizes on dash

We can't just set them on C++ level because that would not be DGU aware, instead of going for hackery with qml bindings to the C++, lets go for using QtQuick.Window directly.

commit34b3f6035c5aa4e2143561c8e779d92ee9be4ded authorMichael Zanetti <michael.zanetti@canonical.com> dateFri 20 May 2016, 11:43 (10 years ago) parent0365d75
2 files changed+39−29
qml/Dash/DashApplication.qml+18−7 src/Dash/main.cpp+21−22
qml/Dash/DashApplication.qml+18−7
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2014,2015 Canonical, Ltd.
2+ * Copyright (C) 2014-2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -17,15 +17,26 @@
1717import QtQuick 2.4
1818import Ubuntu.Components 1.3
1919import Ubuntu.Thumbnailer 0.1 // Register support for image://thumbnailer/ and image://albumart/
20+import QtQuick.Window 2.0
2021
21−MainView {
22− implicitWidth: units.gu(40)
23− implicitHeight: units.gu(68)
22+Window {
23+ visible: true
24+ title: i18n.tr("Scopes")
2425
25− // Workaround bug #1475643
26− headerColor: Qt.rgba(0, 0, 0, 0)
26+ width: initialWidth > 0 ? initialWidth : units.gu(40)
27+ height: initialHeight > 0 ? initialHeight : units.gu(68)
2728
28− Dash {
29+ minimumWidth: units.gu(40)
30+ minimumHeight: units.gu(40)
31+
32+ MainView {
2933 anchors.fill: parent
34+
35+ // Workaround bug #1475643
36+ headerColor: Qt.rgba(0, 0, 0, 0)
37+
38+ Dash {
39+ anchors.fill: parent
40+ }
3041 }
3142}
src/Dash/main.cpp+21−22
@@ -25,6 +25,7 @@
2525#include <QCommandLineParser>
2626#include <QLibrary>
2727#include <libintl.h>
28+#include <QQmlApplicationEngine>
2829
2930#include <paths.h>
3031#include "../qmldebuggerutils.h"
@@ -81,45 +82,43 @@ int main(int argc, const char *argv[])
8182 bindtextdomain("unity8", translationDirectory().toUtf8().data());
8283 textdomain("unity8");
8384
84− QQuickView* view = new QQuickView();
85− view->setResizeMode(QQuickView::SizeRootObjectToView);
85+ #ifdef UNITY8_ENABLE_TOUCH_EMULATION
86+ // You will need this if you want to interact with touch-only components using a mouse
87+ // Needed only when manually testing on a desktop.
88+ MouseTouchAdaptor *mouseTouchAdaptor = 0;
89+ if (parser.isSet(mousetouchOption)) {
90+ mouseTouchAdaptor = MouseTouchAdaptor::instance();
91+ }
92+ #endif
8693
94+ QQmlApplicationEngine engine;
95+
96+ int initialWidth = -1;
97+ int initialHeight = -1;
8798 if (parser.isSet(windowGeometryOption) &&
8899 parser.value(windowGeometryOption).split('x').size() == 2)
89100 {
90101 QStringList geom = parser.value(windowGeometryOption).split('x');
91102 QSize windowSize(geom.at(0).toInt(), geom.at(1).toInt());
92103 if (windowSize.isValid()) {
93− view->setWidth(windowSize.width());
94− view->setHeight(windowSize.height());
104+ initialWidth = windowSize.width();
105+ initialHeight = windowSize.height();
95106 }
96107 }
97−
98− view->setTitle(QStringLiteral("Scopes"));
99−
100− #ifdef UNITY8_ENABLE_TOUCH_EMULATION
101− // You will need this if you want to interact with touch-only components using a mouse
102− // Needed only when manually testing on a desktop.
103− MouseTouchAdaptor *mouseTouchAdaptor = 0;
104− if (parser.isSet(mousetouchOption)) {
105− mouseTouchAdaptor = MouseTouchAdaptor::instance();
106− }
107− #endif
108+ engine.rootContext()->setContextProperty("initialWidth", initialWidth);
109+ engine.rootContext()->setContextProperty("initialHeight", initialHeight);
108110
109111 QUrl source(::qmlDirectory() + "/Dash/DashApplication.qml");
110− prependImportPaths(view->engine(), ::overrideImportPaths());
111− appendImportPaths(view->engine(), ::fallbackImportPaths());
112+ prependImportPaths(&engine, ::overrideImportPaths());
113+ appendImportPaths(&engine, ::fallbackImportPaths());
112114
113115 CachingNetworkManagerFactory *managerFactory = new CachingNetworkManagerFactory();
114− view->engine()->setNetworkAccessManagerFactory(managerFactory);
116+ engine.setNetworkAccessManagerFactory(managerFactory);
115117
116− view->setSource(source);
117− view->show();
118+ engine.load(source);
118119
119120 int result = application->exec();
120121
121− delete view;
122−
123122 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
124123 delete mouseTouchAdaptor;
125124 #endif