Add plasma default ListView (ListItemView)

- Components added to the api: ListItemView, ListHighlight and ListItem
- Example added in the components gallery

Signed-off-by: Daker Fernandes Pinheiro <dakerfp@gmail.com>
This commit is contained in:
Daker Fernandes Pinheiro 2011-05-18 16:38:21 -03:00
parent dada80f42d
commit a2597e35a2
6 changed files with 180 additions and 39 deletions

View File

@ -0,0 +1,47 @@
/*
* Copyright 2011 Daker Fernandes Pinheiro <dakerfp@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 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.
*/
import QtQuick 1.1
import org.kde.plasma.core 0.1 as PlasmaCore
Item {
id: listHighlight
property bool hover: false
property bool pressed: false
PlasmaCore.FrameSvgItem {
id : background
imagePath: "widgets/viewitem"
prefix: {
if (pressed)
return hover ? "selected+hover" : "selected";
if (hover)
return "hover";
return "normal";
}
anchors {
fill: parent
topMargin: 2
bottomMargin: 2
}
}
}

View File

@ -1,5 +1,6 @@
/*
* Copyright 2010 Marco Martin <notmart@gmail.com>
* Copyright 2011 Daker Fernandes Pinheiro <dakerfp@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
@ -16,39 +17,31 @@
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import QtQuick 1.0
import QtQuick 1.1
import org.kde.plasma.core 0.1 as PlasmaCore
Item {
id: listItem
property alias padding: paddingRectangle
signal clicked;
width: parent.width
height: childrenRect.height+4
// Plasma API
property Item view: null
property alias hoverEnabled: mouse.hoverEnabled
property alias hover: mouse.containsMouse
property alias pressed: mouse.pressed
signal selected(int index)
PlasmaCore.FrameSvgItem {
id : background
imagePath: "widgets/frame"
prefix: "plain"
implicitWidth: view.width
implicitHeight: childrenRect.height + 4
MouseArea {
id: mouse
anchors.fill: parent
anchors.topMargin: 2
anchors.bottomMargin: 2
MouseArea {
id: itemMouse
anchors.fill: background
onClicked: listItem.clicked()
hoverEnabled: false
onEntered: { view.currentIndex = index; }
onClicked: {
view.currentIndex = index;
listItem.selected(index);
}
}
Item {
id: paddingRectangle
anchors.fill: background
anchors.leftMargin: background.margins.left
anchors.topMargin: background.margins.top
anchors.rightMargin: background.margins.right
anchors.bottomMargin: background.margins.bottom
}
}

View File

@ -0,0 +1,54 @@
/*
* Copyright 2011 Daker Fernandes Pinheiro <dakerfp@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 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.
*/
import QtQuick 1.1
ListView {
id: list
// Plasma API
property alias scrollVisible: scrollBar.visible
// Convinience API
property bool __isVertical: orientation == Qt.Vertical
orientation: Qt.Vertical
highlightFollowsCurrentItem: true
highlight: ListHighlight {
width: ListView.view.width
height: ListView.view.currentItem.height
pressed: ListView.view.currentItem.pressed
hover: ListView.view.currentItem.hover
}
ScrollBar {
id: scrollBar
anchors {
top: __isVertical ? parent.top : undefined
left: __isVertical ? undefined : parent.left
right: parent.right
bottom: parent.bottom
}
animated: true
stepSize: highlightItem.height
orientation: parent.orientation
flickableItem: parent
}
}

View File

@ -17,7 +17,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import QtQuick 1.0
import QtQuick 1.1
import org.kde.plasma.core 0.1 as PlasmaCore
// TODO: add support mouse wheel and key events
@ -29,7 +29,7 @@ Item {
// Plasma API
property int orientation: Qt.Horizontal
property bool animated: false
property bool animated: true
property bool inverted: false
property bool updateValueWhileDragging: true
property alias stepSize: range.stepSize
@ -43,8 +43,8 @@ Item {
!scrollbar.inverted : scrollbar.inverted
property alias _value: range.value
width: _isVertical ? 22 : 200
height: _isVertical ? 200 : 22
implicitWidth: _isVertical ? 22 : 200
implicitHeight: _isVertical ? 200 : 22
visible: flickableItem && handle.width < contents.width

View File

@ -4,7 +4,9 @@ CheckBox 0.1 CheckBox.qml
FlashingLabel 0.1 FlashingLabel.qml
Frame 0.1 Frame.qml
IconWidget 0.1 IconWidget.qml
ListHighlight 0.1 ListHighlight.qml
ListItem 0.1 ListItem.qml
ListItemView 0.1 ListItemView.qml
PushButton 0.1 PushButton.qml
RadioButton 0.1 RadioButton.qml
ScrollBar 0.1 ScrollBar.qml

View File

@ -238,19 +238,64 @@ Rectangle {
color: "grey"
opacity: 0.3
}
PlasmaComponents.ScrollBar {
orientation: Qt.Vertical
flickableItem: scrollList
animated: true
stepSize: 40
scrollButtonInterval: 50
anchors {
top: scrollList.top
right: scrollList.right
bottom: scrollList.bottom
}
}
}
}
Column {
id: listColumn
spacing: 20
Text {
font.pixelSize: 20
text: "ListItemView"
}
PlasmaComponents.ScrollBar {
orientation: Qt.Vertical
flickableItem: scrollList
animated: true
stepSize: 40
scrollButtonInterval: 50
anchors {
top: scrollList.top
right: scrollList.right
bottom: scrollList.bottom
PlasmaComponents.ListItemView {
id: listItemView
property bool hoverEnabled: hoverCheck.checked
width: 200
height: 200
clip: true
model: 15
scrollVisible: false
delegate: PlasmaComponents.ListItem {
view: listItemView
height: 30
hoverEnabled: view.hoverEnabled
Text {
id: label
anchors.fill: parent
anchors.margins: 4
text: index
font.pixelSize: 14
}
onSelected: {
listItemView.currentIndex = index;
}
}
Component.onCompleted: currentIndex = 3;
}
PlasmaComponents.CheckBox {
id: hoverCheck
text: "Hover Enabled"
checked: true
}
}
}