From 5343dfef24f364ecb55dbe2a4f04004b84b095f0 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 28 Mar 2016 10:19:38 -0700 Subject: [PATCH] PR feedback on 7480 --- libraries/ui/src/QmlWindowClass.cpp | 12 +++++------- libraries/ui/src/QmlWindowClass.h | 1 - 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/libraries/ui/src/QmlWindowClass.cpp b/libraries/ui/src/QmlWindowClass.cpp index c43433e87c..d18ada1f5a 100644 --- a/libraries/ui/src/QmlWindowClass.cpp +++ b/libraries/ui/src/QmlWindowClass.cpp @@ -32,6 +32,8 @@ static const char* const WIDTH_PROPERTY = "width"; static const char* const HEIGHT_PROPERTY = "height"; static const char* const VISIBILE_PROPERTY = "visible"; static const char* const TOOLWINDOW_PROPERTY = "toolWindow"; +static const uvec2 MAX_QML_WINDOW_SIZE { 1280, 720 }; +static const uvec2 MIN_QML_WINDOW_SIZE { 120, 80 }; QVariantMap QmlWindowClass::parseArguments(QScriptContext* context) { const auto argumentCount = context->argumentCount(); @@ -110,13 +112,9 @@ void QmlWindowClass::initQml(QVariantMap properties) { object->setProperty(TITLE_PROPERTY, properties[TITLE_PROPERTY].toString()); } if (properties.contains(HEIGHT_PROPERTY) && properties.contains(WIDTH_PROPERTY)) { - auto height = properties[HEIGHT_PROPERTY].toInt(); - auto width = properties[WIDTH_PROPERTY].toInt(); - if (width != -1 && height != -1) { - width = std::max(100, std::min(1280, width)); - height = std::max(100, std::min(720, height)); - asQuickItem()->setSize(QSize(width, height)); - } + uvec2 requestedSize { properties[WIDTH_PROPERTY].toUInt(), properties[HEIGHT_PROPERTY].toUInt() }; + requestedSize = glm::clamp(requestedSize, MIN_QML_WINDOW_SIZE, MAX_QML_WINDOW_SIZE); + asQuickItem()->setSize(QSize(requestedSize.x, requestedSize.y)); } bool visible = !properties.contains(VISIBILE_PROPERTY) || properties[VISIBILE_PROPERTY].toBool(); diff --git a/libraries/ui/src/QmlWindowClass.h b/libraries/ui/src/QmlWindowClass.h index bf3f37aae3..242f9b0dd4 100644 --- a/libraries/ui/src/QmlWindowClass.h +++ b/libraries/ui/src/QmlWindowClass.h @@ -22,7 +22,6 @@ class QScriptContext; // FIXME refactor this class to be a QQuickItem derived type and eliminate the needless wrapping class QmlWindowClass : public QObject { Q_OBJECT -// Q_PROPERTY(QObject* eventBridge READ getEventBridge CONSTANT) Q_PROPERTY(glm::vec2 position READ getPosition WRITE setPosition NOTIFY positionChanged) Q_PROPERTY(glm::vec2 size READ getSize WRITE setSize NOTIFY sizeChanged) Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibilityChanged)