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.

commita8aaf6b37f04fa19bd4d3a86922a19347e4d37fb authorMichael Zanetti <michael.zanetti@canonical.com> dateMon 27 Jun 2016, 18:41 (10 years ago) parent9e913d81963ac6
2 files changed+38−26
qml/Dash/DashApplication.qml+16−5 src/Dash/main.cpp+22−21
qml/Dash/DashApplication.qml+16−5
@@ -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
@@ -15,14 +15,25 @@
1515 */
1616
1717import QtQuick 2.4
18+import QtQuick.Window 2.2
1819import Ubuntu.Components 1.3
1920import Ubuntu.Thumbnailer 0.1 // Register support for image://thumbnailer/ and image://albumart/
2021
21−MainView {
22− implicitWidth: units.gu(40)
23− implicitHeight: units.gu(68)
22+Window {
23+ visible: true
24+ title: "Scopes" // Intentionally not translated
2425
25− Dash {
26+ width: initialWidth > 0 ? initialWidth : units.gu(40)
27+ height: initialHeight > 0 ? initialHeight : units.gu(68)
28+
29+ minimumWidth: units.gu(40)
30+ minimumHeight: units.gu(40)
31+
32+ MainView {
2633 anchors.fill: parent
34+
35+ Dash {
36+ anchors.fill: parent
37+ }
2738 }
2839}
src/Dash/main.cpp+22−21
@@ -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"
@@ -83,40 +84,40 @@ int main(int argc, const char *argv[])
8384 bindtextdomain("unity8", translationDirectory().toUtf8().data());
8485 textdomain("unity8");
8586
86− QQuickView* view = new QQuickView();
87− view->setResizeMode(QQuickView::SizeRootObjectToView);
87+ #ifdef UNITY8_ENABLE_TOUCH_EMULATION
88+ // You will need this if you want to interact with touch-only components using a mouse
89+ // Needed only when manually testing on a desktop.
90+ MouseTouchAdaptor *mouseTouchAdaptor = 0;
91+ if (parser.isSet(mousetouchOption)) {
92+ mouseTouchAdaptor = MouseTouchAdaptor::instance();
93+ }
94+ #endif
8895
96+ QQmlApplicationEngine *engine = new QQmlApplicationEngine(application);
97+
98+ int initialWidth = -1;
99+ int initialHeight = -1;
89100 if (parser.isSet(windowGeometryOption) &&
90101 parser.value(windowGeometryOption).split('x').size() == 2)
91102 {
92103 QStringList geom = parser.value(windowGeometryOption).split('x');
93104 QSize windowSize(geom.at(0).toInt(), geom.at(1).toInt());
94105 if (windowSize.isValid()) {
95− view->setWidth(windowSize.width());
96− view->setHeight(windowSize.height());
106+ initialWidth = windowSize.width();
107+ initialHeight = windowSize.height();
97108 }
98109 }
99−
100− view->setTitle(QStringLiteral("Scopes"));
101−
102− #ifdef UNITY8_ENABLE_TOUCH_EMULATION
103− // You will need this if you want to interact with touch-only components using a mouse
104− // Needed only when manually testing on a desktop.
105− MouseTouchAdaptor *mouseTouchAdaptor = 0;
106− if (parser.isSet(mousetouchOption)) {
107− mouseTouchAdaptor = MouseTouchAdaptor::instance();
108− }
109− #endif
110+ engine->rootContext()->setContextProperty("initialWidth", initialWidth);
111+ engine->rootContext()->setContextProperty("initialHeight", initialHeight);
110112
111113 QUrl source(::qmlDirectory() + "/Dash/DashApplication.qml");
112− prependImportPaths(view->engine(), ::overrideImportPaths());
113− appendImportPaths(view->engine(), ::fallbackImportPaths());
114+ prependImportPaths(engine, ::overrideImportPaths());
115+ appendImportPaths(engine, ::fallbackImportPaths());
114116
115117 CachingNetworkManagerFactory *managerFactory = new CachingNetworkManagerFactory();
116− view->engine()->setNetworkAccessManagerFactory(managerFactory);
118+ engine->setNetworkAccessManagerFactory(managerFactory);
117119
118− view->setSource(source);
119− view->show();
120+ engine->load(source);
120121
121122 UnixSignalHandler signalHandler([]{
122123 QGuiApplication::exit(0);
@@ -125,7 +126,7 @@ int main(int argc, const char *argv[])
125126
126127 int result = application->exec();
127128
128− delete view;
129+ delete engine;
129130
130131 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
131132 delete mouseTouchAdaptor;