Unity 8
 All Classes Functions Properties
Base.qml
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 
29  property bool selected: false
30 
38  property bool highlightWhenPressed: true
39 
45  property bool showDivider: __showDivider()
46 
47 
55  function __showDivider() {
56  // if we're not in ListView, always show a thin dividing line at the bottom
57  var model = null;
58  if (typeof ListViewWithPageHeader !== 'undefined') {
59  if (typeof ListViewWithPageHeader.model !== 'undefined') {
60  model = ListViewWithPageHeader.model;
61  }
62  } else if (ListView.view !== null) {
63  model = ListView.view.model;
64  }
65  // if we're last item in ListView don't show divider
66  if (model && index === model.count - 1) return false;
67 
68  return true;
69  }
70 
71  /* Relevant really only for ListViewWithPageHeader case: specify how many pixels we can overlap with the section header */
72  readonly property int allowedOverlap: units.dp(1)
73 
74  property real __heightToClip: {
75  // Check this is in position where clipping is needed
76  if (typeof ListViewWithPageHeader !== 'undefined') {
77  if (typeof heightToClip !== 'undefined') {
78  if (heightToClip >= allowedOverlap) {
79  return heightToClip - allowedOverlap;
80  }
81  }
82  }
83  return 0;
84  }
85 
91  default property alias children: body.children
92 
93  Item {
94  id: clippingContainer
95  height: parent.height - __heightToClip
96  anchors { left: parent.left; right: parent.right; bottom: parent.bottom }
97  clip: __heightToClip > 0
98 
99  Item {
100  id: body
101  anchors {
102  left: parent.left
103  right: parent.right
104  bottom: bottomDividerLine.top
105  }
106  height: childrenRect.height
107  }
108 
109  ThinDivider {
110  id: bottomDividerLine
111  anchors.bottom: parent.bottom
112  visible: showDivider
113  }
114 
115  Highlight {
116  anchors {
117  top: parent.top
118  left: parent.left
119  right: parent.right
120  bottom: bottomDividerLine.top
121  }
122  pressed: (emptyListItem.selected || (emptyListItem.highlightWhenPressed && emptyListItem.pressed)) ? "pressed" : ""
123  }
124  }
125 }