~phablet-team/ubuntu-printing-app/trunk

« back to all changes in this revision

Viewing changes to ubuntu-printing-app/components/PreviewRow.qml

  • Committer: Bileto Bot
  • Author(s): Andrew Hayzen
  • Date: 2017-03-08 13:03:24 UTC
  • mfrom: (23.1.63 additional-fixes)
  • Revision ID: ci-train-bot@canonical.com-20170308130324-s668yxbda5n2ynpm
* Set max width of options
* Set NoDisplay=true to hide the app in unity
* Hide left/right buttons when they are disabled
* Change the default height of the preview to 40%
* Set a minimum height of 15GU for the preview
* Allow use of a separator to resize the preview height and workaround ScrollView limitations
* Move collate and reverse to the bottom
* Set the content-hub json as this to be a share of content-hub
* Add tests for new separate resize and minimum height

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright 2016 Canonical Ltd.
 
2
 * Copyright 2016, 2017 Canonical Ltd.
3
3
 *
4
4
 * This file is part of ubuntu-printing-app.
5
5
 *
31
31
    }
32
32
    // Use foreground as this element is ontop of the background
33
33
    color: theme.palette.normal.foreground
34
 
    // Height is smallest of
 
34
 
 
35
    // Height is the calculated height + the difference given by the separator
 
36
    // but also has a minimumHeight, otherwise it can be resized too small
 
37
    implicitHeight: Math.max(separator.heightDiff + calcHeight, minimumHeight)
 
38
 
 
39
    // Calculated height is smallest of
35
40
    // - calc'd height using aspect and width of image
36
 
    // - 2/3 height of the view
37
 
    implicitHeight: Math.min((view.width - units.gu(10)) / pageHelper.aspect, view.height / 1.5)
 
41
    // - 40% height of the view
 
42
    readonly property double calcHeight: Math.min((view.width - units.gu(10)) / pageHelper.aspect, view.height * 0.4)
38
43
 
39
44
    property Document document
 
45
    property double minimumHeight: units.gu(15)
 
46
    // This is the MouseArea that the separator uses to monitor when to change
 
47
    // the cursorShape
 
48
    property MouseArea monitorMouseArea: null
40
49
    property var printerJob
41
50
    property var view
42
51
 
65
74
        objectName: "previousButton"
66
75
        text: "<"
67
76
        width: units.gu(4)
 
77
        visible: enabled
68
78
 
69
79
        onClicked: pageHelper.page--
70
80
    }
110
120
        objectName: "nextButton"
111
121
        text: ">"
112
122
        width: units.gu(4)
 
123
        visible: enabled
113
124
 
114
125
        onClicked: pageHelper.page++
115
126
    }
117
128
    Rectangle {
118
129
        id: pageOverlay
119
130
        anchors {
120
 
            bottom: parent.bottom
 
131
            bottom: separator.top
121
132
            left: previewImage.left
122
133
            right: previewImage.right
123
134
        }
139
150
            width: parent.width
140
151
        }
141
152
    }
 
153
 
 
154
    Item {
 
155
        id: separator
 
156
        anchors {
 
157
            bottom: parent.bottom
 
158
        }
 
159
        height: units.gu(1)
 
160
        objectName: "separator"
 
161
        width: parent.width
 
162
 
 
163
        readonly property alias heightDiff: resizer.y
 
164
 
 
165
        // So that qmltests can find the resizer (it has no parent)
 
166
        readonly property var resizer: resizer
 
167
 
 
168
        Rectangle {
 
169
            anchors {
 
170
                bottom: parent.bottom
 
171
                left: parent.left
 
172
                right: parent.right
 
173
            }
 
174
            color: theme.palette.normal.base
 
175
            height: 1
 
176
        }
 
177
 
 
178
        Item {
 
179
            id: resizer
 
180
            parent: null
 
181
        }
 
182
 
 
183
        MouseArea {
 
184
            id: mouseArea
 
185
            anchors {
 
186
                fill: parent
 
187
            }
 
188
            cursorShape: Qt.SizeVerCursor
 
189
            drag {
 
190
                axis: Drag.YAxis
 
191
                // Prevent the view being resized smaller than minimumHeight
 
192
                // otherwise you cannot resize it back
 
193
                minimumY: -calcHeight + previewRow.minimumHeight
 
194
                target: resizer
 
195
            }
 
196
 
 
197
            // ScrollView has a MouseArea which doesn't propagate hover events
 
198
            // down to us. So instead we have a global MouseArea that is above
 
199
            // the ScrollView and passed to us as monitorMouseArea
 
200
            //
 
201
            // monitorContainsMouse then tells us if the mouse in the global
 
202
            // MouseArea is also inside this MouseArea
 
203
            readonly property bool monitorContainsMouse: {
 
204
                var relativePos = mapFromItem(monitorMouseArea, monitorMouseArea.mouseX, monitorMouseArea.mouseY);
 
205
                return contains(Qt.point(relativePos.x, relativePos.y));
 
206
            }
 
207
 
 
208
            // When the mouse is inside this MouseArea set the global MouseArea
 
209
            // cursorShape to be the cursor we want
 
210
            Binding {
 
211
                target: monitorMouseArea
 
212
                property: "cursorShape"
 
213
                value: mouseArea.monitorContainsMouse ? Qt.SizeVerCursor : Qt.ArrowCursor
 
214
            }
 
215
        }
 
216
    }
142
217
}