From 80c36823983a1f1da61578d5d20117cb6b106461 Mon Sep 17 00:00:00 2001 From: Raphael Dumusc Date: Fri, 26 Oct 2018 17:51:20 +0200 Subject: [PATCH] Respect size hints when resizing Qml streamer --- deflect/qt/QmlStreamerImpl.cpp | 32 +++++++++++++++++++++++++++++++- deflect/qt/QmlStreamerImpl.h | 8 +++++--- doc/Changelog.md | 3 +++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/deflect/qt/QmlStreamerImpl.cpp b/deflect/qt/QmlStreamerImpl.cpp index 6cdb16c..7af41e0 100644 --- a/deflect/qt/QmlStreamerImpl.cpp +++ b/deflect/qt/QmlStreamerImpl.cpp @@ -246,6 +246,33 @@ void QmlStreamer::Impl::_setupSizeHintsConnections() [this](int size_) { _sizeHints.preferredHeight = size_; }); } +bool QmlStreamer::Impl::_isWithinSizeHintsRange(const QSize& size) const +{ + return !size.isEmpty() && + _isWithinSizeHintsRange(static_cast(size.width()), + static_cast(size.height())); +} + +bool QmlStreamer::Impl::_isWithinSizeHintsRange(const uint width, + const uint height) const +{ + const auto minWidth = _sizeHints.minWidth == SizeHints::UNSPECIFIED_SIZE + ? std::numeric_limits::min() + : _sizeHints.minWidth; + const auto maxWidth = _sizeHints.maxWidth == SizeHints::UNSPECIFIED_SIZE + ? std::numeric_limits::max() + : _sizeHints.maxWidth; + const auto minHeight = _sizeHints.minHeight == SizeHints::UNSPECIFIED_SIZE + ? std::numeric_limits::min() + : _sizeHints.minHeight; + const auto maxHeight = _sizeHints.maxHeight == SizeHints::UNSPECIFIED_SIZE + ? std::numeric_limits::max() + : _sizeHints.maxHeight; + + return minWidth <= width && width <= maxWidth && minHeight <= height && + height <= maxHeight; +} + std::string QmlStreamer::Impl::_getDeflectStreamIdentifier() const { if (!_streamId.empty()) @@ -281,7 +308,10 @@ void QmlStreamer::Impl::_setupDeflectStream() // handle view resize connect(_eventReceiver.get(), &EventReceiver::resized, - [this](const QSize size) { _quickView->resize(size); }); + [this](const QSize size) { + if (_isWithinSizeHintsRange(size)) + _quickView->resize(size); + }); // inject key events connect(_eventReceiver.get(), &EventReceiver::keyPress, this, diff --git a/deflect/qt/QmlStreamerImpl.h b/deflect/qt/QmlStreamerImpl.h index b98690f..d654c75 100644 --- a/deflect/qt/QmlStreamerImpl.h +++ b/deflect/qt/QmlStreamerImpl.h @@ -1,7 +1,7 @@ /*********************************************************************/ -/* Copyright (c) 2015-2016, EPFL/Blue Brain Project */ -/* Daniel.Nachbaur */ -/* Raphael Dumusc */ +/* Copyright (c) 2015-2018, EPFL/Blue Brain Project */ +/* Daniel.Nachbaur */ +/* Raphael Dumusc */ /* All rights reserved. */ /* */ /* Redistribution and use in source and binary forms, with or */ @@ -93,6 +93,8 @@ private slots: private: void _setupSizeHintsConnections(); + bool _isWithinSizeHintsRange(const QSize& size) const; + bool _isWithinSizeHintsRange(uint width, uint height) const; void _send(QKeyEvent& keyEvent); bool _sendToWebengineviewItems(QKeyEvent& keyEvent); std::string _getDeflectStreamIdentifier() const; diff --git a/doc/Changelog.md b/doc/Changelog.md index 8d8c85c..b531602 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -4,6 +4,9 @@ Changelog {#Changelog} ## Deflect 1.0 ### 1.0.1 (master) +* [203](https://github.com/BlueBrain/Deflect/pull/203): + QmlStreamer resizes the window only if the received size event is within the + specified min/max size hints. * [200](https://github.com/BlueBrain/Deflect/pull/200): The Server now rejects Streams attempting to late-join after the first frame was finished.