~ubuntu-branches/ubuntu/raring/kde-runtime/raring-proposed

1.1.5 by Jonathan Riddell
Import upstream version 4.7.90
1
/*
2
 *   Copyright 2010 Marco Martin <notmart@gmail.com>
3
 *
4
 *   This program is free software; you can redistribute it and/or modify
5
 *   it under the terms of the GNU Library General Public License as
6
 *   published by the Free Software Foundation; either version 2, or
7
 *   (at your option) any later version.
8
 *
9
 *   This program is distributed in the hope that it will be useful,
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *   GNU Library General Public License for more details
13
 *
14
 *   You should have received a copy of the GNU Library General Public
15
 *   License along with this program; if not, write to the
16
 *   Free Software Foundation, Inc.,
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
 */
19
20
import QtQuick 1.0
21
import org.kde.plasma.core 0.1 as PlasmaCore
1.1.15 by Harald Sitter
Import upstream version 4.9.1
22
import "private/Config.js" as Config
1.1.5 by Jonathan Riddell
Import upstream version 4.7.90
23
1.1.21 by Philip Muškovac
Import upstream version 4.9.97
24
/**
25
 * An item delegate for the primitive ListView component.
26
 *
27
 * It's intended to make all listviews look coherent.
28
 */
1.1.5 by Jonathan Riddell
Import upstream version 4.7.90
29
Item {
30
    id: listItem
31
    default property alias content: paddingItem.data
32
1.1.21 by Philip Muškovac
Import upstream version 4.9.97
33
    /**
34
     * type:bool Holds if the item emits signals related to mouse interaction.
35
     *
36
     * The default value is false.
37
     */
1.1.12 by Philip Muškovac
Import upstream version 4.8.80
38
    property alias enabled: itemMouse.enabled
1.1.5 by Jonathan Riddell
Import upstream version 4.7.90
39
    //item has been clicked or pressed+hold
1.1.21 by Philip Muškovac
Import upstream version 4.9.97
40
41
    /**
42
     * This signal is emitted when there is a click.
43
     *
44
     * This is disabled by default, set enabled to true to use it.
45
     * @see enabled
46
     */
1.1.5 by Jonathan Riddell
Import upstream version 4.7.90
47
    signal clicked
1.1.21 by Philip Muškovac
Import upstream version 4.9.97
48
49
50
    /**
51
     * The user pressed the item with the mouse and didn't release it for a
52
     * certain amount of time.
53
     *
54
     * This is disabled by default, set enabled to true to use it.
55
     * @see enabled
56
     */
1.1.5 by Jonathan Riddell
Import upstream version 4.7.90
57
    signal pressAndHold
58
1.1.21 by Philip Muškovac
Import upstream version 4.9.97
59
    /**
60
     * If true makes the list item look as checked or pressed. It has to be set
61
     * from the code, it won't change by itself.
62
     */
1.1.5 by Jonathan Riddell
Import upstream version 4.7.90
63
    //plasma extension
64
    //always look pressed?
65
    property bool checked: false
1.1.21 by Philip Muškovac
Import upstream version 4.9.97
66
67
    /**
68
     * If true the item will be a delegate for a section, so will look like a
69
     * "title" for the otems under it.
70
     */
1.1.5 by Jonathan Riddell
Import upstream version 4.7.90
71
    //is this to be used as section delegate?
72
    property bool sectionDelegate: false
73
1.1.17 by Philip Muškovac
Import upstream version 4.9.3
74
    width: parent ? parent.width : childrenRect.width
1.1.5 by Jonathan Riddell
Import upstream version 4.7.90
75
    height: paddingItem.childrenRect.height + background.margins.top + background.margins.bottom
76
77
    property int implicitHeight: paddingItem.childrenRect.height + background.margins.top + background.margins.bottom
78
79
80
    Connections {
81
        target: listItem
82
        onCheckedChanged: background.prefix = (listItem.checked ? "pressed" : "normal")
83
        onSectionDelegateChanged: background.prefix = (listItem.sectionDelegate ? "section" : "normal")
84
    }
1.1.12 by Philip Muškovac
Import upstream version 4.8.80
85
1.1.5 by Jonathan Riddell
Import upstream version 4.7.90
86
    PlasmaCore.FrameSvgItem {
87
        id : background
88
        imagePath: "widgets/listitem"
89
        prefix: "normal"
90
91
        anchors.fill: parent
1.1.22 by Jonathan Riddell
Import upstream version 4.9.98
92
        visible: listItem.ListView.view ? listItem.ListView.view.highlight === null : false
1.1.15 by Harald Sitter
Import upstream version 4.9.1
93
        opacity: itemMouse.containsMouse && !itemMouse.pressed ? 0.5 : 1
1.1.5 by Jonathan Riddell
Import upstream version 4.7.90
94
        Component.onCompleted: {
95
            prefix = (listItem.sectionDelegate ? "section" : (listItem.checked ? "pressed" : "normal"))
96
        }
1.1.15 by Harald Sitter
Import upstream version 4.9.1
97
        Behavior on opacity { NumberAnimation { duration: 200 } }
1.1.5 by Jonathan Riddell
Import upstream version 4.7.90
98
    }
99
    PlasmaCore.SvgItem {
100
        svg: PlasmaCore.Svg {imagePath: "widgets/listitem"}
101
        elementId: "separator"
102
        anchors {
103
            left: parent.left
104
            right: parent.right
105
            top: parent.top
106
        }
107
        height: naturalSize.height
1.1.17 by Philip Muškovac
Import upstream version 4.9.3
108
        visible: listItem.sectionDelegate || (typeof(index) != "undefined" && index > 0 && !listItem.checked && !itemMouse.pressed)
1.1.5 by Jonathan Riddell
Import upstream version 4.7.90
109
    }
110
111
    MouseArea {
112
        id: itemMouse
113
        property bool changeBackgroundOnPress: !listItem.checked && !listItem.sectionDelegate
114
        anchors.fill: background
1.1.12 by Philip Muškovac
Import upstream version 4.8.80
115
        enabled: false
1.1.15 by Harald Sitter
Import upstream version 4.9.1
116
        hoverEnabled: Config.mouseOverEnabled
1.1.5 by Jonathan Riddell
Import upstream version 4.7.90
117
118
        onClicked: listItem.clicked()
119
        onPressAndHold: listItem.pressAndHold()
120
        onPressed: if (changeBackgroundOnPress) background.prefix = "pressed"
121
        onReleased: if (changeBackgroundOnPress) background.prefix = "normal"
122
        onCanceled: if (changeBackgroundOnPress) background.prefix = "normal"
123
    }
124
125
    Item {
126
        id: paddingItem
127
        anchors {
128
            fill: background
129
            leftMargin: background.margins.left
130
            topMargin: background.margins.top
131
            rightMargin: background.margins.right
132
            bottomMargin: background.margins.bottom
133
        }
134
    }
135
}