on xenial help sign in
Rework Dash Preview column margins
3d551b3Albert Astals Cid
qml/Dash/Previews/Preview.qml+19−7
@@ -56,11 +56,12 @@ Item {
56 Row {
56 Row {
57 id: row
57 id: row
58
58
59− spacing: units.gu(1)
59+ spacing: units.gu(4)
60− anchors { fill: parent; margins: spacing }
60+ anchors.fill: parent
61
61
62− property int columns: width >= units.gu(80) ? 2 : 1
62+ readonly property int columns: width >= units.gu(80) ? 2 : 1
63− property real columnWidth: width / columns
63+ readonly property real columnWidth: (width - (spacing * (columns - 1))) / columns
64+ readonly property int singleColumnMargin: units.gu(2)
64
65
65 Repeater {
66 Repeater {
66 model: previewModel
67 model: previewModel
@@ -72,8 +73,11 @@ Item {
72 top: parent.top
73 top: parent.top
73 bottom: parent.bottom
74 bottom: parent.bottom
74 }
75 }
76+ topMargin: units.gu(2)
75 width: row.columnWidth
77 width: row.columnWidth
76− spacing: row.spacing
78+ spacing: units.gu(1)
79+
80+ readonly property int columnNumber: index
77
81
78 ListViewOSKScroller {
82 ListViewOSKScroller {
79 id: oskScroller
83 id: oskScroller
@@ -96,8 +100,16 @@ Item {
96 anchors {
100 anchors {
97 left: parent.left
101 left: parent.left
98 right: parent.right
102 right: parent.right
99− leftMargin: widgetMargins
103+ leftMargin: if (row.columns == 1) {
104+ return singleColumnMarginless ? 0 : row.singleColumnMargin;
105+ } else {
106+ return column.columnNumber == 0 ? row.singleColumnMargin : 0;
107+ }
100− rightMargin: widgetMargins
108+ rightMargin: if (row.columns == 1) {
109+ return singleColumnMarginless ? 0 : row.singleColumnMargin;
110+ } else {
111+ return column.columnNumber == 1 ? row.singleColumnMargin : 0;
112+ }
101 }
113 }
102
114
103 onTriggered: {
115 onTriggered: {
qml/Dash/Previews/PreviewInlineVideo.qml+1−1
@@ -33,7 +33,7 @@ PreviewWidget {
33 implicitWidth: units.gu(35)
33 implicitWidth: units.gu(35)
34 implicitHeight: services.height
34 implicitHeight: services.height
35
35
36− widgetMargins: -units.gu(1)
36+ singleColumnMarginless: true
37 orientationLock: services.fullscreen
37 orientationLock: services.fullscreen
38
38
39 property alias rootItem: services.rootItem
39 property alias rootItem: services.rootItem
qml/Dash/Previews/PreviewVideoPlayback.qml+1−1
@@ -30,7 +30,7 @@ PreviewWidget {
30 implicitWidth: units.gu(35)
30 implicitWidth: units.gu(35)
31 implicitHeight: childrenRect.height
31 implicitHeight: childrenRect.height
32
32
33− widgetMargins: -units.gu(1)
33+ singleColumnMarginless: true
34
34
35 LazyImage {
35 LazyImage {
36 objectName: "screenshot"
36 objectName: "screenshot"
qml/Dash/Previews/PreviewWidget.qml+2−2
@@ -34,8 +34,8 @@ Item {
34 //! Should the orientation be locked
34 //! Should the orientation be locked
35 property bool orientationLock: false
35 property bool orientationLock: false
36
36
37− //! Set margins width.
37+ //! Should it have margins when on a single columns?
38− property real widgetMargins: units.gu(1)
38+ property bool singleColumnMarginless: false
39
39
40 /// The parent (vertical) flickable this widget is in (if any)
40 /// The parent (vertical) flickable this widget is in (if any)
41 property var parentFlickable: null
41 property var parentFlickable: null
qml/Dash/Previews/PreviewWidgetFactory.qml+2−2
@@ -40,8 +40,8 @@ Loader {
40 //! Should the orientation be locked
40 //! Should the orientation be locked
41 readonly property bool orientationLock: status === Loader.Ready ? item.orientationLock : false
41 readonly property bool orientationLock: status === Loader.Ready ? item.orientationLock : false
42
42
43− //! Set margins width.
43+ //! Should it have margins when on a single columns?
44− property real widgetMargins: status === Loader.Ready ? item.widgetMargins : units.gu(1)
44+ readonly property bool singleColumnMarginless: status === Loader.Ready ? item.singleColumnMarginless : false
45
45
46 /// The parent (vertical) flickable this widget is in (if any)
46 /// The parent (vertical) flickable this widget is in (if any)
47 property var parentFlickable: null
47 property var parentFlickable: null
qml/Dash/Previews/PreviewZoomableImage.qml+1−1
@@ -30,7 +30,7 @@ PreviewWidget {
30 implicitWidth: units.gu(35)
30 implicitWidth: units.gu(35)
31 implicitHeight: lazyImage.height
31 implicitHeight: lazyImage.height
32
32
33− widgetMargins: -units.gu(1)
33+ singleColumnMarginless: true
34 orientationLock: overlay.visible
34 orientationLock: overlay.visible
35
35
36 property Item rootItem: QuickUtils.rootItem(root)
36 property Item rootItem: QuickUtils.rootItem(root)
tests/mocks/Unity/fake_previewmodel.cpp+15−7
@@ -34,22 +34,30 @@ PreviewModel::PreviewModel(QObject* parent, Scope* scope)
34 , m_loaded(true)
34 , m_loaded(true)
35 , m_scope(scope)
35 , m_scope(scope)
36{
36{
37− // we have one column by default
37+ setWidgetColumnCount(1);
38− PreviewWidgetModel* columnModel = new PreviewWidgetModel(this);
39− m_previewWidgetModels.append(columnModel);
40 connect(this, &PreviewModel::triggered, this, &PreviewModel::triggeredSlot);
38 connect(this, &PreviewModel::triggered, this, &PreviewModel::triggeredSlot);
41}
39}
42
40
43void PreviewModel::setWidgetColumnCount(int count)
41void PreviewModel::setWidgetColumnCount(int count)
44{
42{
45− if (count != 1) {
43+ if (count != widgetColumnCount()) {
46− qWarning("PreviewModel::setWidgetColumnCount != 1 not implemented");
44+ beginResetModel();
45+
46+ m_previewWidgetModels.clear();
47+ for (int i = 0; i < count; ++i) {
48+ PreviewWidgetModel* columnModel = new PreviewWidgetModel(this);
49+ m_previewWidgetModels.append(columnModel);
50+ }
51+
52+ endResetModel();
53+
54+ Q_EMIT widgetColumnCountChanged();
47 }
55 }
48}
56}
49
57
50int PreviewModel::widgetColumnCount() const
58int PreviewModel::widgetColumnCount() const
51{
59{
52− return 1;
60+ return m_previewWidgetModels.size();
53}
61}
54
62
55bool PreviewModel::loaded() const
63bool PreviewModel::loaded() const
@@ -64,7 +72,7 @@ bool PreviewModel::processingAction() const
64
72
65int PreviewModel::rowCount(const QModelIndex&) const
73int PreviewModel::rowCount(const QModelIndex&) const
66{
74{
67− return m_previewWidgetModels.size();
75+ return widgetColumnCount();
68}
76}
69
77
70QVariant PreviewModel::data(const QModelIndex& index, int role) const
78QVariant PreviewModel::data(const QModelIndex& index, int role) const
tests/mocks/Unity/fake_previewwidgetmodel.cpp+18−10
@@ -54,18 +54,26 @@ void PreviewWidgetModel::populateWidgets()
54 m_previewWidgets.append(QSharedPointer<PreviewData>(preview_data));
54 m_previewWidgets.append(QSharedPointer<PreviewData>(preview_data));
55 }
55 }
56
56
57− QVariantMap attributes;
57+ {
58− QVariantMap buttonData;
58+ QVariantMap attributes;
59− buttonData["label"] = "Button";
59+ attributes["source"] = QVariant("qrc:///Unity/Application/screenshots/browser@12.png");
60− buttonData["id"] = "open_click";
61− QVariantList buttons;
62− buttons << buttonData << buttonData << buttonData;
63− attributes["actions"] = QVariant::fromValue(buttons);
64− PreviewData* preview_data = new PreviewData(QString("widget-21"), QString("actions"), attributes);
60+ PreviewData* preview_data = new PreviewData(QString("widget-22"), QString("image"), attributes);
65− m_previewWidgets.append(QSharedPointer<PreviewData>(preview_data));
61+ m_previewWidgets.append(QSharedPointer<PreviewData>(preview_data));
62+ }
66
63
67− endResetModel();
64+ {
65+ QVariantMap attributes;
66+ QVariantMap buttonData;
67+ buttonData["label"] = "Button";
68+ buttonData["id"] = "open_click";
69+ QVariantList buttons;
70+ buttons << buttonData << buttonData << buttonData;
71+ attributes["actions"] = QVariant::fromValue(buttons);
72+ PreviewData* preview_data = new PreviewData(QString("widget-21"), QString("actions"), attributes);
73+ m_previewWidgets.append(QSharedPointer<PreviewData>(preview_data));
74+ }
68
75
76+ endResetModel();
69}
77}
70
78
71int PreviewWidgetModel::rowCount(const QModelIndex&) const
79int PreviewWidgetModel::rowCount(const QModelIndex&) const