on xenial help sign in
Make zoomable and video playback widgets edge to edge

Approved by: Albert Astals Cid

commitb90131890bd10e2211ca5e2ea969e3a4a35a8374 authorAndrea Cimitan <andrea.cimitan@gmail.com> dateWed 4 Nov 2015, 14:56 (11 years ago) parent59eee290ee4a1a
8 files changed+45−21
qml/Components/LazyImage.qml+23−10 qml/Dash/Previews/Preview.qml+2−2 qml/Dash/Previews/PreviewVideoPlayback.qml+3 qml/Dash/Previews/PreviewWidget.qml+3 qml/Dash/Previews/PreviewWidgetFactory.qml+3 qml/Dash/Previews/PreviewZoomableImage.qml+8−6 tests/qmltests/Dash/Previews/tst_PreviewExpandable.qml+2−2 tests/qmltests/Dash/Previews/tst_PreviewZoomableImage.qml+1−1
qml/Components/LazyImage.qml+23−10
@@ -34,6 +34,8 @@ Item {
3434 property alias asynchronous: image.asynchronous
3535 property alias cache: image.cache
3636 property alias sourceImage: image
37+
38+ property bool useUbuntuShape: true
3739 property bool pressed: false
3840
3941 state: "default"
@@ -47,12 +49,15 @@ Item {
4749 }
4850 }
4951
50− UbuntuShape {
52+ Loader {
5153 id: placeholder
5254 objectName: "placeholder"
53− backgroundColor: "#22FFFFFF"
5455 anchors.fill: shape
56+ active: useUbuntuShape
5557 visible: opacity != 0
58+ sourceComponent: UbuntuShape {
59+ backgroundColor: "#22FFFFFF"
60+ }
5661
5762 ActivityIndicator {
5863 id: activity
@@ -75,27 +80,35 @@ Item {
7580 }
7681 }
7782
78− UbuntuShapeOverlay {
83+ Loader {
7984 id: shape
8085 objectName: "shape"
8186 height: root.initialHeight
8287 width: root.initialWidth
8388 anchors.centerIn: root.scaleTo == "fit" ? parent : undefined
84−
89+ active: useUbuntuShape
8590 opacity: 0
8691 visible: opacity != 0
87− overlayColor: Qt.rgba(0, 0, 0, root.pressed ? 0.1 : 0)
88− overlayRect: Qt.rect(0.0, 0.0, 1.0, 1.0)
89− sourceFillMode: UbuntuShape.PreserveAspectCrop
90− sourceHorizontalAlignment: UbuntuShape.AlignHCenter
91− sourceVerticalAlignment: UbuntuShape.AlignVCenter
92− source: Image {
92+ sourceComponent: UbuntuShapeOverlay {
93+ property bool pressed: false
94+ overlayColor: Qt.rgba(0, 0, 0, pressed ? 0.1 : 0)
95+ overlayRect: Qt.rect(0.0, 0.0, 1.0, 1.0)
96+ }
97+ onLoaded: {
98+ item.source = image;
99+ item.pressed = Qt.binding(function() { return root.pressed; });
100+ }
101+
102+ Image {
93103 id: image
94104 objectName: "image"
95105
96106 property url nextSource
97107 property string format: image.implicitWidth > image.implicitHeight ? "landscape" : "portrait"
98108
109+ anchors.fill: parent
110+ visible: !useUbuntuShape
111+ fillMode: Image.PreserveAspectFit
99112 asynchronous: true
100113 cache: false
101114 sourceSize.width: root.scaleTo == "width" ? root.width
qml/Dash/Previews/Preview.qml+2−2
@@ -100,8 +100,8 @@ Item {
100100 anchors {
101101 left: parent.left
102102 right: parent.right
103− leftMargin: units.gu(1)
104− rightMargin: units.gu(1)
103+ leftMargin: widgetMargins
104+ rightMargin: widgetMargins
105105 }
106106
107107 onTriggered: {
qml/Dash/Previews/PreviewVideoPlayback.qml+3
@@ -30,6 +30,8 @@ PreviewWidget {
3030 implicitWidth: units.gu(35)
3131 implicitHeight: childrenRect.height
3232
33+ widgetMargins: -units.gu(1)
34+
3335 LazyImage {
3436 objectName: "screenshot"
3537 anchors {
@@ -51,6 +53,7 @@ PreviewWidget {
5153 return "";
5254 }
5355 initialHeight: width * 10 / 16
56+ useUbuntuShape: false
5457
5558 Image {
5659 objectName: "playButton"
qml/Dash/Previews/PreviewWidget.qml+3
@@ -34,6 +34,9 @@ Item {
3434 //! Should the widget show in expanded mode (For those that support it)
3535 property bool expanded: true
3636
37+ //! Set margins width.
38+ property real widgetMargins: units.gu(1)
39+
3740 /*! \brief This signal should be emitted when a preview action was triggered.
3841 *
3942 * \param widgetId, actionId Respective identifiers from widgetData.
qml/Dash/Previews/PreviewWidgetFactory.qml+3
@@ -40,6 +40,9 @@ Loader {
4040 //! Set to true if the parent preview is displayed.
4141 property bool isCurrentPreview: false
4242
43+ //! Set margins width.
44+ property real widgetMargins: status === Loader.Ready ? item.widgetMargins : units.gu(1)
45+
4346 //! Triggered signal forwarded from the widgets.
4447 signal triggered(string widgetId, string actionId, var data)
4548
qml/Dash/Previews/PreviewZoomableImage.qml+8−6
@@ -27,7 +27,10 @@ import "../../Components"
2727
2828PreviewWidget {
2929 id: root
30− implicitHeight: units.gu(22)
30+ implicitWidth: units.gu(35)
31+ implicitHeight: lazyImage.height
32+
33+ widgetMargins: -units.gu(1)
3134
3235 property Item rootItem: QuickUtils.rootItem(root)
3336
@@ -35,14 +38,13 @@ PreviewWidget {
3538 id: lazyImage
3639 objectName: "lazyImage"
3740 anchors {
38− top: parent.top
39− bottom: parent.bottom
40− horizontalCenter: parent.horizontalCenter
41+ left: parent.left
42+ right: parent.right
4143 }
42− scaleTo: "height"
44+ scaleTo: "width"
4345 source: widgetData["source"]
4446 asynchronous: true
45−
47+ useUbuntuShape: false
4648 pressed: mouseArea.pressed
4749
4850 MouseArea {
tests/qmltests/Dash/Previews/tst_PreviewExpandable.qml+2−2
@@ -319,9 +319,9 @@ Rectangle {
319319 previewWidgetFactory.widgetType = allWidgetsModel.get(i).type;
320320 previewWidgetFactory.active = true;
321321
322− // Wait for the height ot settle by waiting twice the time of the
322+ // Wait for the height ot settle by waiting four times the time of the
323323 // longest of the height behaviour animations
324− wait(UbuntuAnimation.SnapDuration * 2);
324+ wait(UbuntuAnimation.SnapDuration * 4);
325325
326326 // Check the item inside the expandable has the same height
327327 // as the one straight from the factory
tests/qmltests/Dash/Previews/tst_PreviewZoomableImage.qml+1−1
@@ -41,7 +41,7 @@ Rectangle {
4141
4242 Loader {
4343 id: loader
44− anchors.centerIn: parent
44+ width: parent.width
4545 sourceComponent: PreviewZoomableImage {
4646 widgetData: widgetData0
4747 }