~unity-team/+junk/dashboard-playground

« back to all changes in this revision

Viewing changes to Components/ListItems/Base.qml

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.0
 
18
import Ubuntu.Components 0.1
 
19
 
 
20
AbstractButton {
 
21
    id: emptyListItem
 
22
    width: parent ? parent.width : units.gu(31)
 
23
    height: body.height + bottomDividerLine.height
 
24
 
 
25
    /*!
 
26
      \preliminary
 
27
      Specifies whether the list item is selected.
 
28
     */
 
29
    property bool selected: false
 
30
 
 
31
    /*!
 
32
      \preliminary
 
33
      Highlight the list item when it is pressed.
 
34
      This is used to disable the highlighting of the full list item
 
35
      when custom highlighting needs to be implemented (for example in
 
36
      ListItem.Standard which can have a split).
 
37
    */
 
38
    property bool highlightWhenPressed: true
 
39
 
 
40
    /*!
 
41
      \preliminary
 
42
      Set to show or hide the thin bottom divider line (drawn by the \l ThinDivider component).
 
43
      This line is shown by default except in cases where this item is the delegate of a ListView.
 
44
     */
 
45
    property bool showDivider: __showDivider()
 
46
 
 
47
    /*!
 
48
      \internal
 
49
      Method to automatically determine if the bottom divider line should be drawn.
 
50
      This always returns true, unless item is a delegate in a ListView. If in a ListView
 
51
      it will return false only when:
 
52
       + if this is the final item in the list, and ListView.footer is set (again as thin
 
53
         divider line won't look well with footer below it)
 
54
     */
 
55
    function __showDivider() {
 
56
        // if we're not in ListView, always show a thin dividing line at the bottom
 
57
        if (ListView.view !== null) {
 
58
 
 
59
            // if we're last item in ListView don't show divider
 
60
            if (index === ListView.view.model.count - 1) return false;
 
61
        }
 
62
        return true;
 
63
    }
 
64
 
 
65
    property bool __clippingRequired: ListView.view !== null
 
66
                                      && ListView.view.section.labelPositioning & ViewSection.CurrentLabelAtStart
 
67
 
 
68
    property real __yPositionRelativeToListView: ListView.view ? y - ListView.view.contentY : y
 
69
 
 
70
    property real __heightToClip: {
 
71
        // Check this is in position where clipping is needed
 
72
        if (__clippingRequired && __yPositionRelativeToListView <= __sectionDelegateHeight
 
73
                && __yPositionRelativeToListView > -height) {
 
74
            return Math.min(__sectionDelegateHeight - __yPositionRelativeToListView, height);
 
75
        } else {
 
76
            return 0;
 
77
        }
 
78
    }
 
79
 
 
80
    property int __sectionDelegateHeight: {
 
81
        if (__clippingRequired && ListView.view.hasOwnProperty("__sectionDelegateHeight")) {
 
82
            return ListView.view.__sectionDelegateHeight;
 
83
        } else {
 
84
            return 0;
 
85
        }
 
86
    }
 
87
 
 
88
    /*!
 
89
      \internal
 
90
      Reparent so that the visuals of the children does not
 
91
      occlude the bottom divider line.
 
92
     */
 
93
    default property alias children: body.children
 
94
 
 
95
    Item {
 
96
        id: clippingContainer
 
97
        height: parent.height - __heightToClip
 
98
        anchors { left: parent.left; right: parent.right; bottom: parent.bottom }
 
99
        clip: __heightToClip > 0
 
100
 
 
101
        Item {
 
102
            id: body
 
103
            anchors {
 
104
                left: parent.left
 
105
                right: parent.right
 
106
                bottom: bottomDividerLine.top
 
107
            }
 
108
            height: childrenRect.height
 
109
        }
 
110
 
 
111
        ThinDivider {
 
112
            id: bottomDividerLine
 
113
            anchors.bottom: parent.bottom
 
114
            visible: showDivider
 
115
        }
 
116
 
 
117
        Highlight {
 
118
            anchors {
 
119
                top: parent.top
 
120
                left: parent.left
 
121
                right: parent.right
 
122
                bottom: bottomDividerLine.top
 
123
            }
 
124
            pressed: (emptyListItem.selected || (emptyListItem.highlightWhenPressed && emptyListItem.pressed)) ? "pressed" : ""
 
125
        }
 
126
    }
 
127
}