~ubuntu-docviewer-dev/ubuntu-docviewer-app/lo-viewer

« back to all changes in this revision

Viewing changes to src/app/qml/loView/PartsView.qml

  • Committer: Tarmac
  • Author(s): Stefano Verzegnassi
  • Date: 2016-01-07 11:31:23 UTC
  • mfrom: (217.2.1 ubuntu-docviewer-app)
  • Revision ID: tarmac-20160107113123-a2nwqwels4w3zkvf
[loviewer] PartsView: Ensure that items next to the current item are always visible. Fixes: https://bugs.launchpad.net/bugs/1521386.

Approved by Roman Shchekin, Jenkins Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import QtQuick.Layouts 1.1
20
20
import DocumentViewer.LibreOffice 1.0 as LibreOffice
21
21
 
 
22
// TODO: If we'll be planning to reorganise QML components, consider to provide
 
23
// delegates in some separate documents.
 
24
 
22
25
ListView {
23
26
    id: view
24
27
    objectName: "view"
32
35
    property bool isWide: width > units.gu(24)
33
36
 
34
37
    currentIndex: view.model ? loView.document.currentPart : -1
35
 
    highlightMoveDuration: UbuntuAnimation.SnapDuration
36
 
 
37
 
    delegate: (orientation == ListView.Vertical) ? verticalDelegate : horizontalDelegate
 
38
 
 
39
    // Ensure that items next to current item are always visible (and then
 
40
    // clickable) without the need of extra interaction from the user.
 
41
    // FIXME: If the current item is out the visible area, the 'highlightMove'
 
42
    // animation shouldn't be fully performed, but applied from the first visible
 
43
    // item instead. This actually seems to be a limitation of ListView itself.
 
44
    highlightRangeMode: ListView.ApplyRange
 
45
    highlightMoveDuration: UbuntuAnimation.FastDuration
 
46
    preferredHighlightBegin: internal.isVerticalView ? (view.height - internal.verticalItemHeight) * 0.5
 
47
                                                     : (view.width - internal.horizontalItemWidth) * 0.5
 
48
    preferredHighlightEnd: internal.isVerticalView ? (view.height - internal.verticalItemHeight) * 0.5
 
49
                                                   : (view.width - internal.horizontalItemWidth) * 0.5
 
50
 
 
51
    delegate: internal.isVerticalView ? verticalDelegate : horizontalDelegate
 
52
 
 
53
    Component.onCompleted: {
 
54
        // WORKAROUND: Fix for wrong grid unit size
 
55
        flickDeceleration = 1500 * units.gridUnit / 8
 
56
        maximumFlickVelocity = 2500 * units.gridUnit / 8
 
57
    }
38
58
 
39
59
    Component {
40
60
        id: verticalDelegate
41
61
 
42
62
        ListItem {
43
63
            id: delegate
44
 
            width: parent.width
45
 
            height: units.gu(16)
 
64
 
 
65
            // Defined at the end of this document
 
66
            width: internal.verticalItemWidth
 
67
            height: internal.verticalItemHeight
46
68
 
47
69
            color: (loView.document.currentPart === model.index) ? theme.palette.selected.background
48
70
                                                                 : "transparent"
98
120
 
99
121
        ListItem {
100
122
            id: delegate
101
 
            height: parent.height; width: height
 
123
 
 
124
            // Defined at the end of this document
 
125
            width: internal.horizontalItemWidth
 
126
            height: internal.horizontalItemHeight
102
127
 
103
128
            color: (loView.document.currentPart === model.index) ? theme.palette.selected.background
104
129
                                                                 : "transparent"
137
162
    QtObject {
138
163
        id: internal
139
164
 
 
165
        readonly property bool isVerticalView: view.orientation == ListView.Vertical
 
166
 
 
167
        // Vertical delegate size
 
168
        readonly property int verticalItemWidth: view.width
 
169
        readonly property int verticalItemHeight: units.gu(16)
 
170
 
 
171
        // Horizontal delegate size
 
172
        readonly property int horizontalItemWidth: horizontalItemHeight
 
173
        readonly property int horizontalItemHeight: view.height
 
174
 
140
175
        function delegate_onClicked(index) {
141
176
            loView.document.currentPart = index
142
177