on xenial help sign in
better handling of sizing
commit83db16eca71ff2e3f21f3cf8047505875970b8b4 authorNick Dedekind <nick.dedekind@canonical.com> dateFri 19 Jun 2015, 16:25 (11 years ago) parentaa52a65
6 files changed+94−34
qml/Components/MediaServices/MediaServices.qml+40−30 qml/Components/MediaServices/VideoPlayer.qml+17−2 qml/Dash/Previews/PreviewInlineVideo.qml+1 tests/mocks/QtMultimedia/mediaplayer.cpp+8 tests/mocks/QtMultimedia/mediaplayer.h+4−2 tests/qmltests/Components/tst_MediaServices.qml+24
qml/Components/MediaServices/MediaServices.qml+40−30
@@ -24,6 +24,7 @@ FocusScope {
2424 property string context: ""
2525 property list<Action> actions
2626 property Item rootItem: QuickUtils.rootItem(root)
27+ property var maximumEmbeddedHeight
2728
2829 property alias header: headerContent.item
2930 property alias content: contentLoader.item
@@ -32,39 +33,47 @@ FocusScope {
3233
3334 signal close();
3435
35− implicitHeight: {
36− if (fullscreen && parent) {
37− return parent.height;
38− }
39− return content ? content.implicitHeight : parent.height
40− }
41−
4236 onFullscreenChanged: {
4337 if (!fullscreen) rotationAction.checked = false;
4438 }
4539
4640 OrientationHelper {
4741 id: orientationHelper
48− automaticOrientation: fullscreen && !rotationAction.checked
49−
50− states: [
51− State {
52− name: "portrait"
53− when: !orientationHelper.automaticOrientation && !rotationAction.checked
54− PropertyChanges {
55− target: orientationHelper
56− orientationAngle: 0
42+ automaticOrientation: fullscreen
43+
44+ StateGroup {
45+ id: orientationState
46+
47+ states: [
48+ State {
49+ name: "portrait"
50+ when: !rotationAction.checked
51+ },
52+ State {
53+ name: "landscape"
54+ when: rotationAction.checked
5755 }
58− },
59− State {
60− name: "landscape"
61− when: !orientationHelper.automaticOrientation && rotationAction.checked
62− PropertyChanges {
63− target: orientationHelper
64− orientationAngle: orientationHelper.orientationAngle == 270 ? 270 : 90
56+ ]
57+
58+ transitions: [
59+ Transition {
60+ to: "landscape"
61+ SequentialAnimation {
62+ PropertyAction { target: orientationHelper; property: "automaticOrientation"; value: false }
63+ PropertyAction { target: orientationHelper; property: "orientationAngle"; value: 90 }
64+ PropertyAction { target: orientationHelper; property: "automaticOrientation"; value: false }
65+ }
66+ },
67+ Transition {
68+ to: "portrait"
69+ SequentialAnimation {
70+ PropertyAction { target: orientationHelper; property: "automaticOrientation"; value: false }
71+ PropertyAction { target: orientationHelper; property: "orientationAngle"; value: 0 }
72+ PropertyAction { target: orientationHelper; property: "automaticOrientation"; value: fullscreen }
73+ }
6574 }
66− }
67− ]
75+ ]
76+ }
6877
6978 Loader {
7079 id: contentLoader
@@ -91,9 +100,9 @@ FocusScope {
91100
92101 width: orientationHelper.width
93102 height: orientationHelper.height
94−
103+ maximumEmbeddedHeight: root.maximumEmbeddedHeight
95104 fixedHeight: fullscreen
96− orientation: orientationHelper.state == "portrait" ? Qt.PortraitOrientation : Qt.LandscapeOrientation
105+ orientation: orientationState.state == "landscape" ? Qt.LandscapeOrientation : Qt.PortraitOrientation
97106
98107 screenshot: {
99108 var screenshot = root.sourceData["screenshot"];
@@ -323,21 +332,22 @@ FocusScope {
323332 State {
324333 name: "minimized"
325334 when: !priv.fullscreen
335+ PropertyChanges { target: root; implicitHeight: content ? content.implicitHeight : 0; }
326336 },
327337 State {
328338 name: "fullscreen"
329339 when: priv.fullscreen
330− ParentChange { target: root; parent: rootItem; x: 0; y: 0; width: parent.width; height: parent.height }
340+ ParentChange { target: root; parent: rootItem; x: 0; y: 0; width: parent.width; }
341+ PropertyChanges { target: root; implicitHeight: root.parent ? root.parent.height : 0; }
331342 PropertyChanges { target: fullscreenAction; iconName: "view-restore" }
332343 }
333344 ]
334345
335346 transitions: Transition {
336347 ParentAnimation {
337− UbuntuNumberAnimation { properties: "x,y,width,height"; duration: UbuntuAnimation.FastDuration }
348+ UbuntuNumberAnimation { properties: "x,y,width,implicitHeight"; duration: UbuntuAnimation.FastDuration }
338349 }
339350 }
340−
341351 }
342352
343353 QtObject {
qml/Components/MediaServices/VideoPlayer.qml+17−2
@@ -27,6 +27,7 @@ Item {
2727 property alias mediaPlayer: videoOutput.source
2828 property int orientation: Qt.PortraitOrientation
2929 property bool fixedHeight: false
30+ property var maximumEmbeddedHeight
3031
3132 implicitHeight: {
3233 if (parent && orientation == Qt.LandscapeOrientation) {
@@ -45,7 +46,17 @@ Item {
4546 right: parent.right
4647 verticalCenter: parent.verticalCenter
4748 }
48− height: root.orientation == Qt.LandscapeOrientation || fixedHeight ? root.height : Math.max(image.height, videoOutput.height);
49+ height: {
50+ if (root.orientation == Qt.LandscapeOrientation || fixedHeight) {
51+ return root.height;
52+ }
53+ var proposedHeight = videoOutput.height;
54+ if (maximumEmbeddedHeight !== undefined && maximumEmbeddedHeight < proposedHeight) {
55+ return maximumEmbeddedHeight;
56+ }
57+ return proposedHeight;
58+ }
59+ clip: image.height > videoOutput.height
4960
5061 LazyImage {
5162 id: image
@@ -69,9 +80,13 @@ Item {
6980 if (fixedHeight) {
7081 return root.height;
7182 }
72− return mediaPlayer && mediaPlayer.metaData.resolution !== undefined ?
83+ var proposedHeight = mediaPlayer && mediaPlayer.metaData.resolution !== undefined ?
7384 (mediaPlayer.metaData.resolution.height / mediaPlayer.metaData.resolution.width ) * width :
7485 image.height;
86+ if (maximumEmbeddedHeight !== undefined && maximumEmbeddedHeight < proposedHeight) {
87+ return maximumEmbeddedHeight;
88+ }
89+ return proposedHeight;
7590 }
7691
7792 source: mediaPlayer
qml/Dash/Previews/PreviewInlineVideo.qml+1
@@ -41,6 +41,7 @@ PreviewWidget {
4141 context: "video"
4242 sourceData: root.isCurrentPreview ? widgetData : undefined
4343 fullscreen: false
44+ maximumEmbeddedHeight: rootItem.height / 2
4445
4546 onClose: fullscreen = false
4647
tests/mocks/QtMultimedia/mediaplayer.cpp+8
@@ -67,6 +67,7 @@ MediaPlayer::MediaPlayer(QObject* parent)
6767 disconnect(dataSource, &MediaDataSource::durationChanged, this, &MediaPlayer::durationChanged);
6868 disconnect(dataSource, &MediaDataSource::seekableChanged, this, &MediaPlayer::seekableChanged);
6969 disconnect(dataSource, &MediaDataSource::availabilityChanged, this, &MediaPlayer::availabilityChanged);
70+ disconnect(dataSource, &MediaDataSource::metaDataChanged, m_metaData, &MetaDataObject::metaDataChanged);
7071 });
7172
7273 connect(MediaPlayerDataController::instance(), &MediaPlayerDataController::sourceAdded,
@@ -77,6 +78,7 @@ MediaPlayer::MediaPlayer(QObject* parent)
7778 connect(dataSource, &MediaDataSource::durationChanged, this, &MediaPlayer::durationChanged);
7879 connect(dataSource, &MediaDataSource::seekableChanged,this, &MediaPlayer::seekableChanged);
7980 connect(dataSource, &MediaDataSource::availabilityChanged,this, &MediaPlayer::availabilityChanged);
81+ connect(dataSource, &MediaDataSource::metaDataChanged, m_metaData, &MetaDataObject::metaDataChanged);
8082 });
8183}
8284
@@ -96,6 +98,7 @@ void MediaPlayer::setSource(const QUrl &source)
9698
9799 m_position = 0;
98100 Q_EMIT positionChanged(m_position);
101+ Q_EMIT m_metaData->metaDataChanged();
99102
100103 m_status = availability()==Available ? Loaded : InvalidMedia;
101104 Q_EMIT statusChanged();
@@ -204,6 +207,11 @@ MediaPlayer::Availability MediaPlayer::availability() const
204207 return Available;
205208}
206209
210+QObject *MediaPlayer::metaData() const
211+{
212+ return m_metaData;
213+}
214+
207215
208216MediaDataSource::MediaDataSource(QObject *parent)
209217 : QObject(parent)
tests/mocks/QtMultimedia/mediaplayer.h+4−2
@@ -25,6 +25,8 @@
2525#include <QHash>
2626#include <QVariant>
2727
28+class MetaDataObject;
29+
2830class MediaPlayer: public QObject
2931{
3032 Q_OBJECT
@@ -109,7 +111,7 @@ public:
109111 bool isSeekable() const;
110112 MediaPlayer::Availability availability() const;
111113 Status status() const { return m_status; }
112− QObject *metaData() const { return m_metaData; }
114+ QObject *metaData() const;
113115
114116public Q_SLOTS:
115117 void pause();
@@ -139,7 +141,7 @@ private:
139141 QTimer m_timer;
140142 int m_position;
141143 Status m_status;
142− QObject *m_metaData;
144+ MetaDataObject *m_metaData;
143145};
144146
145147class MediaDataSource : public QObject
tests/qmltests/Components/tst_MediaServices.qml+24
@@ -32,6 +32,11 @@ Rectangle {
3232 "screenshot": Qt.resolvedUrl("../Dash/artwork/avatar.png")
3333 }
3434
35+ property var sourceData2: {
36+ "source": "file:///home/nick/Videos/test-mpeg2.ogv",
37+ "screenshot": Qt.resolvedUrl("../Dash/artwork/checkers.png")
38+ }
39+
3540 MediaDataSource {
3641 source: root.sourceData["source"]
3742 duration: 60000
@@ -41,6 +46,15 @@ Rectangle {
4146 }
4247 }
4348
49+ MediaDataSource {
50+ source: root.sourceData2["source"]
51+ duration: 30000
52+ metaData: {
53+ "title" : "TEST MPEG",
54+ "resolution" : { "width": 90, "height": 240 }
55+ }
56+ }
57+
4458 Item {
4559 anchors.fill: parent
4660
@@ -61,6 +75,7 @@ Rectangle {
6175 context: "video"
6276
6377 rootItem: parent
78+ maximumEmbeddedHeight: undefined
6479 }
6580 }
6681
@@ -99,6 +114,7 @@ Rectangle {
99114 property int oldControlTimerInterval: 0;
100115
101116 function init() {
117+ services.sourceData = root.sourceData
102118 services.context = "video";
103119
104120 var controlHideTimer = findInvisibleChild(services, "controlHideTimer");
@@ -110,6 +126,7 @@ Rectangle {
110126 serviceCloseSpy.clear();
111127 services.context = "";
112128 services.fullscreen = false;
129+ services.maximumEmbeddedHeight = undefined;
113130 tryCompareFunction(function() { return services.header ? services.header.visible : false }, false);
114131 tryCompareFunction(function() { return services.footer ? services.footer.visible : false }, false);
115132
@@ -200,5 +217,12 @@ Rectangle {
200217 tap(navigationButton);
201218 compare(serviceCloseSpy.count, 1, "close was not called");
202219 }
220+
221+ function test_maximumVideoSize() {
222+ services.maximumEmbeddedHeight = root.height / 2
223+ services.sourceData = root.sourceData2
224+ verify(services.content !== null);
225+ tryCompare(services.content, "height", root.height/2);
226+ }
203227 }
204228}