2011-10-31 16:41:43 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Marco Martin <notmart@gmail.com>
|
|
|
|
*
|
|
|
|
* This program 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, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2013-02-06 13:37:56 +01:00
|
|
|
import QtQuick 2.0
|
2011-10-31 16:41:43 +01:00
|
|
|
import org.kde.plasma.core 0.1 as PlasmaCore
|
2012-08-10 11:42:53 +02:00
|
|
|
import "private/Config.js" as Config
|
2011-10-31 16:41:43 +01:00
|
|
|
|
2012-12-17 18:41:57 +01:00
|
|
|
/**
|
|
|
|
* An item delegate for the primitive ListView component.
|
|
|
|
*
|
|
|
|
* It's intended to make all listviews look coherent.
|
|
|
|
*/
|
2011-10-31 16:41:43 +01:00
|
|
|
Item {
|
|
|
|
id: listItem
|
|
|
|
default property alias content: paddingItem.data
|
|
|
|
|
2012-12-17 18:41:57 +01:00
|
|
|
/**
|
|
|
|
* type:bool Holds if the item emits signals related to mouse interaction.
|
|
|
|
*
|
|
|
|
* The default value is false.
|
|
|
|
*/
|
2012-03-24 00:52:40 +01:00
|
|
|
property alias enabled: itemMouse.enabled
|
2011-10-31 16:41:43 +01:00
|
|
|
//item has been clicked or pressed+hold
|
2012-12-17 18:41:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This signal is emitted when there is a click.
|
|
|
|
*
|
|
|
|
* This is disabled by default, set enabled to true to use it.
|
|
|
|
* @see enabled
|
|
|
|
*/
|
2011-10-31 16:41:43 +01:00
|
|
|
signal clicked
|
2012-12-17 18:41:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The user pressed the item with the mouse and didn't release it for a
|
|
|
|
* certain amount of time.
|
|
|
|
*
|
|
|
|
* This is disabled by default, set enabled to true to use it.
|
|
|
|
* @see enabled
|
|
|
|
*/
|
2011-10-31 16:41:43 +01:00
|
|
|
signal pressAndHold
|
|
|
|
|
2012-12-17 18:41:57 +01:00
|
|
|
/**
|
|
|
|
* If true makes the list item look as checked or pressed. It has to be set
|
|
|
|
* from the code, it won't change by itself.
|
|
|
|
*/
|
2011-10-31 16:41:43 +01:00
|
|
|
//plasma extension
|
|
|
|
//always look pressed?
|
|
|
|
property bool checked: false
|
2012-12-17 18:41:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If true the item will be a delegate for a section, so will look like a
|
|
|
|
* "title" for the otems under it.
|
|
|
|
*/
|
2011-10-31 16:41:43 +01:00
|
|
|
//is this to be used as section delegate?
|
|
|
|
property bool sectionDelegate: false
|
|
|
|
|
2012-10-25 14:47:16 +02:00
|
|
|
width: parent ? parent.width : childrenRect.width
|
2011-10-31 16:41:43 +01:00
|
|
|
height: paddingItem.childrenRect.height + background.margins.top + background.margins.bottom
|
|
|
|
|
|
|
|
property int implicitHeight: paddingItem.childrenRect.height + background.margins.top + background.margins.bottom
|
|
|
|
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: listItem
|
|
|
|
onCheckedChanged: background.prefix = (listItem.checked ? "pressed" : "normal")
|
|
|
|
onSectionDelegateChanged: background.prefix = (listItem.sectionDelegate ? "section" : "normal")
|
|
|
|
}
|
2012-03-24 00:52:40 +01:00
|
|
|
|
2011-10-31 16:41:43 +01:00
|
|
|
PlasmaCore.FrameSvgItem {
|
|
|
|
id : background
|
|
|
|
imagePath: "widgets/listitem"
|
|
|
|
prefix: "normal"
|
|
|
|
|
|
|
|
anchors.fill: parent
|
2013-01-25 12:48:52 +01:00
|
|
|
visible: listItem.ListView.view ? listItem.ListView.view.highlight === null : true
|
2012-08-10 11:42:53 +02:00
|
|
|
opacity: itemMouse.containsMouse && !itemMouse.pressed ? 0.5 : 1
|
2011-10-31 16:41:43 +01:00
|
|
|
Component.onCompleted: {
|
|
|
|
prefix = (listItem.sectionDelegate ? "section" : (listItem.checked ? "pressed" : "normal"))
|
|
|
|
}
|
2012-08-10 11:28:52 +02:00
|
|
|
Behavior on opacity { NumberAnimation { duration: 200 } }
|
2011-10-31 16:41:43 +01:00
|
|
|
}
|
|
|
|
PlasmaCore.SvgItem {
|
|
|
|
svg: PlasmaCore.Svg {imagePath: "widgets/listitem"}
|
|
|
|
elementId: "separator"
|
|
|
|
anchors {
|
|
|
|
left: parent.left
|
|
|
|
right: parent.right
|
|
|
|
top: parent.top
|
|
|
|
}
|
|
|
|
height: naturalSize.height
|
2012-10-25 00:02:10 +02:00
|
|
|
visible: listItem.sectionDelegate || (typeof(index) != "undefined" && index > 0 && !listItem.checked && !itemMouse.pressed)
|
2011-10-31 16:41:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: itemMouse
|
|
|
|
property bool changeBackgroundOnPress: !listItem.checked && !listItem.sectionDelegate
|
|
|
|
anchors.fill: background
|
2012-03-24 00:52:40 +01:00
|
|
|
enabled: false
|
2012-08-10 11:42:53 +02:00
|
|
|
hoverEnabled: Config.mouseOverEnabled
|
2011-10-31 16:41:43 +01:00
|
|
|
|
|
|
|
onClicked: listItem.clicked()
|
|
|
|
onPressAndHold: listItem.pressAndHold()
|
|
|
|
onPressed: if (changeBackgroundOnPress) background.prefix = "pressed"
|
|
|
|
onReleased: if (changeBackgroundOnPress) background.prefix = "normal"
|
|
|
|
onCanceled: if (changeBackgroundOnPress) background.prefix = "normal"
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: paddingItem
|
|
|
|
anchors {
|
|
|
|
fill: background
|
|
|
|
leftMargin: background.margins.left
|
|
|
|
topMargin: background.margins.top
|
|
|
|
rightMargin: background.margins.right
|
|
|
|
bottomMargin: background.margins.bottom
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|