CollectionDelegate.qml 6.46 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
    Copyright (C) 2010 Klarälvdalens Datakonsult AB,
        a KDAB Group company, info@kdab.net,
        author Stephen Kelly <stephen@kdab.com>

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This library is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
*/

import Qt 4.7
import org.kde 4.5
24
import org.kde.akonadi 4.5
25

26
27
Item {
  id: wrapper
28
  clip: true
29
30
31

  property bool fullClickArea : false
  property bool showChildIndicator : false
32
  property bool selectedDelegate : false
33
  property bool topItem : false
34
  property bool showUnread : false
35
  property bool showCheckbox : false
36
37
  property bool checkable : false
  property bool uncheckable : false
38
  property bool alternatingRowColors : false
39
  property int indentation : 0
40
  property real dragCheckThreshold : 0.5
41

42
43
  property alias dragParent : dragTarget.parent

44
45
  property variant checkModel

46
  signal indexSelected(int row)
47

48
  x : indentation
49
  width : ListView.view.width - indentation
50

51
  Rectangle {
52
53
54
55
    // This is the same as anchors.fill : parent, but ParentAnimation only works
    // if positional layouting is used instead of anchor layouting.
    x : 0
    y : 0
56
57
    width : wrapper.width
    height : wrapper.height
58
    id : nestedItem
59
    color : ( alternatingRowColors && model.index % 2 == 0 ) ? "#33ffffff" : "#00000000"
60

61
    Behavior on x {
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
      id : dragFinishedBehavior
      SequentialAnimation {
        NumberAnimation {
          easing.type: "OutQuad"
          easing.amplitude: 100
          duration: 800
        }
        ScriptAction {
          script : {
            nestedItem.parent = wrapper
            nestedItem.y = 0
            dragFinishedBehavior.enabled = false
            nestedItem.x = 0
            dragFinishedBehavior.enabled = true
          }
        }
78
79
80
      }
    }

81
82
83
84
    MouseArea {
      anchors.fill: parent
      onClicked: {
        if ( fullClickArea )
85
86
87
88
89
90
91
92
93
94
95
96
        {
          if (topItem)
          {
            indexSelected(model.index);
            return;
          }

          if (showChildIndicator)
          {
            nestedItem.state = "before_select_child";
          } else if (!selectedDelegate)
            nestedItem.state = "before_select_breadcrumb";
97
          indexSelected(model.index);
98
        }
99
      }
100
      drag.target : (checkable || uncheckable) ? nestedItem : undefined
101
      drag.axis : Drag.XAxis
102
103
      drag.minimumX : uncheckable ? -nestedItem.width : wrapper.indentation
      drag.maximumX : checkable ? nestedItem.width : wrapper.indentation
104
105
106
107
108
109
110
111
      drag.onActiveChanged : {
        if (!drag.active) {
          if ((checkable && nestedItem.x > nestedItem.width * dragCheckThreshold)
            || (uncheckable && nestedItem.x < nestedItem.width * dragCheckThreshold))
          {
            // 8 is QItemSelectionModel::Toggle
            checkModel.select(model.index, 8);
          }
112
113
114
115
116
117
118
119
120
121
          nestedItem.x = wrapper.indentation
        } else {
          var point = mapToItem(dragParent, nestedItem.x, nestedItem.y)
          nestedItem.y = point.y
          dragFinishedBehavior.enabled = false;
          nestedItem.x = point.x + wrapper.indentation
          dragFinishedBehavior.enabled = true;
          nestedItem.parent = dragParent
          // Using the state directly does not seem to work.
//           nestedItem.state = "dragging"
122
123
        }
      }
124
    }
125
126
127
    Row {
      id: topLayout
      x: 10; y: 10;
128
      height: 48
129
130
131
      width: parent.width
      spacing: 10

132
      Image {
133
        id : checkbox
134
135
136
        y : -10
        source : "check.png"
        visible : wrapper.showCheckbox && model.checkOn;
137
138
139
140
      }

      //Image {
        //  id: collectionIcon
141
142
          // http://lists.trolltech.com/pipermail/qt-qml/2010-July/000668.html
  //        pixmap: KDE.iconToPixmap( model.decoration, height );
143
  //        width: 48; height: 48
144
//       }
145

146
      Column {
147
        height : parent.height
148
        Text {
149
          width: wrapper.width - 48 - 50
150
151
152
153
          text : model.display
          //### requires a newer QML version
          //wrapMode: "WrapAnywhere" // Needs the anchors.fill to work properly
        }
154
155

        Text {
156
157
158
          text : wrapper.showUnread && model.unreadCount > 0 ? KDE.i18n( "Unread: %1", model.unreadCount ) : ""
          color: "#0C55BB"
          font.pixelSize: 16
159
        }
160
161
162
163
164
165
166
167
168
169
170
171
172
173
        Rectangle {
          id: progressBar
          color: "black"
          width: parent.width
          height: 7
          visible: (model.collectionSyncProgress != undefined && model.collectionSyncProgress != 0 && model.collectionSyncProgress != 100)
          Rectangle {
            color: "blue"
            x: 1
            y: 1
            height: 5
            width: ((parent.width * (model.collectionSyncProgress == 100 ? 0 : model.collectionSyncProgress)) / 100)
          }
        }
174
175
      }
    }
176
177
178

    Image {
      width : height
179
      anchors.right : nestedItem.right
180
      anchors.rightMargin : 5
181
      anchors.verticalCenter : nestedItem.verticalCenter
182
      opacity : ( showChildIndicator && breadcrumbComponentFactory.childCollectionHasChildren( model.index ) ) ? 1 : 0
183
      source: "transparentplus.png"
184
    }
185
186

    states : [
187
188
189
190
      State {
        name : "dragging"
        ParentChange { id : dragTarget; target : nestedItem }
      },
191
192
193
      State {
        name : "before_select_child"
        ParentChange { target : nestedItem; parent : selectedItemPlaceHolder; }
194
        PropertyChanges { target : nestedItem; x : indentation; y : 0 }
195
196
197
198
      },
      State {
        name : "before_select_breadcrumb"
        ParentChange { target : nestedItem; parent : selectedItemPlaceHolder; }
199
        PropertyChanges { target : nestedItem; x : indentation; y : 0 }
200
201
202
203
204
205
206
207
208
209
210
211
212
213
      }
    ]
    transitions : [
      Transition {
        ParentAnimation {
          target : nestedItem
          NumberAnimation {
            properties: "x,y";
            duration : 500
            easing.type: Easing.OutQuad;
          }
        }
      }
    ]
214
  }
215
}
216