on xenial help sign in
set minimum window sizes on dash
a8aaf6bMichael Zanetti
qml/Dash/DashApplication.qml+16−5
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2014,2015 Canonical, Ltd.
2+ * Copyright (C) 2014-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU General Public License as published by
@@ -15,14 +15,25 @@
15 */
15 */
16
16
17import QtQuick 2.4
17import QtQuick 2.4
18+import QtQuick.Window 2.2
18import Ubuntu.Components 1.3
19import Ubuntu.Components 1.3
19import Ubuntu.Thumbnailer 0.1 // Register support for image://thumbnailer/ and image://albumart/
20import Ubuntu.Thumbnailer 0.1 // Register support for image://thumbnailer/ and image://albumart/
20
21
21−MainView {
22+Window {
22− implicitWidth: units.gu(40)
23+ visible: true
23− implicitHeight: units.gu(68)
24+ title: "Scopes" // Intentionally not translated
24
25
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 {
26 anchors.fill: parent
33 anchors.fill: parent
34+
35+ Dash {
36+ anchors.fill: parent
37+ }
27 }
38 }
28}
39}
src/Dash/main.cpp+22−21
@@ -25,6 +25,7 @@
25#include <QCommandLineParser>
25#include <QCommandLineParser>
26#include <QLibrary>
26#include <QLibrary>
27#include <libintl.h>
27#include <libintl.h>
28+#include <QQmlApplicationEngine>
28
29
29#include <paths.h>
30#include <paths.h>
30#include "../qmldebuggerutils.h"
31#include "../qmldebuggerutils.h"
@@ -83,40 +84,40 @@ int main(int argc, const char *argv[])
83 bindtextdomain("unity8", translationDirectory().toUtf8().data());
84 bindtextdomain("unity8", translationDirectory().toUtf8().data());
84 textdomain("unity8");
85 textdomain("unity8");
85
86
86− QQuickView* view = new QQuickView();
87+ #ifdef UNITY8_ENABLE_TOUCH_EMULATION
87− view->setResizeMode(QQuickView::SizeRootObjectToView);
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
88
95
96+ QQmlApplicationEngine *engine = new QQmlApplicationEngine(application);
97+
98+ int initialWidth = -1;
99+ int initialHeight = -1;
89 if (parser.isSet(windowGeometryOption) &&
100 if (parser.isSet(windowGeometryOption) &&
90 parser.value(windowGeometryOption).split('x').size() == 2)
101 parser.value(windowGeometryOption).split('x').size() == 2)
91 {
102 {
92 QStringList geom = parser.value(windowGeometryOption).split('x');
103 QStringList geom = parser.value(windowGeometryOption).split('x');
93 QSize windowSize(geom.at(0).toInt(), geom.at(1).toInt());
104 QSize windowSize(geom.at(0).toInt(), geom.at(1).toInt());
94 if (windowSize.isValid()) {
105 if (windowSize.isValid()) {
95− view->setWidth(windowSize.width());
106+ initialWidth = windowSize.width();
96− view->setHeight(windowSize.height());
107+ initialHeight = windowSize.height();
97 }
108 }
98 }
109 }
99−
110+ engine->rootContext()->setContextProperty("initialWidth", initialWidth);
100− view->setTitle(QStringLiteral("Scopes"));
111+ engine->rootContext()->setContextProperty("initialHeight", initialHeight);
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
112
111 QUrl source(::qmlDirectory() + "/Dash/DashApplication.qml");
113 QUrl source(::qmlDirectory() + "/Dash/DashApplication.qml");
112− prependImportPaths(view->engine(), ::overrideImportPaths());
114+ prependImportPaths(engine, ::overrideImportPaths());
113− appendImportPaths(view->engine(), ::fallbackImportPaths());
115+ appendImportPaths(engine, ::fallbackImportPaths());
114
116
115 CachingNetworkManagerFactory *managerFactory = new CachingNetworkManagerFactory();
117 CachingNetworkManagerFactory *managerFactory = new CachingNetworkManagerFactory();
116− view->engine()->setNetworkAccessManagerFactory(managerFactory);
118+ engine->setNetworkAccessManagerFactory(managerFactory);
117
119
118− view->setSource(source);
120+ engine->load(source);
119− view->show();
120
121
121 UnixSignalHandler signalHandler([]{
122 UnixSignalHandler signalHandler([]{
122 QGuiApplication::exit(0);
123 QGuiApplication::exit(0);
@@ -125,7 +126,7 @@ int main(int argc, const char *argv[])
125
126
126 int result = application->exec();
127 int result = application->exec();
127
128
128− delete view;
129+ delete engine;
129
130
130 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
131 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
131 delete mouseTouchAdaptor;
132 delete mouseTouchAdaptor;