Commit 1fa8e836 authored by Carl Schwan's avatar Carl Schwan 🚴 Committed by Claudio Cambra
Browse files

Add ltr to the treeview

and do a bit of cleanup

![image](/uploads/2f09218de266910823b60d12ac90ebb7/image.png)
parent 2dcdcfb4
Pipeline #122989 passed with stage
in 4 minutes and 46 seconds
......@@ -129,19 +129,10 @@ TreeListView {
sortBy: root.sortBy
sortAscending: root.ascendingOrder
}
delegate: BasicTreeItem {
delegate: AbstractTreeItem {
id: listItem
objectName: "taskDelegate"
Layout.fillWidth: true
Binding {
target: contentItem.anchors
property: "right"
value: this.right
}
background.anchors.right: this.right
separatorVisible: true
decoration.decorationHighlightColor: model.color
activeBackgroundColor: LabelUtils.getIncidenceBackgroundColor(model.color, root.isDark)
onActiveBackgroundColorChanged: activeBackgroundColor.a = 0.15
......@@ -198,9 +189,9 @@ TreeListView {
contentItem: IncidenceMouseArea {
id: mouseArea
anchors.fill: undefined
implicitWidth: todoItemContents.implicitWidth
implicitHeight: Kirigami.Settings.isMobile ?
todoItemContents.implicitHeight + Kirigami.Units.largeSpacing : todoItemContents.implicitHeight + Kirigami.Units.smallSpacing
implicitHeight: todoItemContents.implicitHeight + (Kirigami.Settings.isMobile ? Kirigami.Units.largeSpacing : Kirigami.Units.smallSpacing)
incidenceData: model
collectionId: model.collectionId
propagateComposedEvents: true
......
/*
* SPDX-FileCopyrightText: 2020 Marco Martin <mart@kde.org>
*
......@@ -9,7 +8,7 @@ import QtQuick 2.12
import QtQuick.Layouts 1.4
import QtQuick.Controls 2.2 as QQC2
import org.kde.kirigami 2.13 as Kirigami
import org.kde.kitemmodels 1.0
import org.kde.kitemmodels 1.0
/**
* An item delegate for the TreeListView and TreeTableView components.
......@@ -18,12 +17,66 @@ import org.kde.kitemmodels 1.0
* which has to be set as contentItem
*
*/
Kirigami.AbstractListItem {
QQC2.ItemDelegate {
id: delegate
separatorVisible: false
/**
* This property holds the tree decoration of the list item.
*/
property alias decoration: decoration
/**
* This propery holds the color for the text in the item.
* It is advised to leave the default value (Kirigami.Theme.textColor)
*
* @Note If custom text elements are inserted in an AbstractListItem,
* their color property will have to be manually bound with this property
*
* @since org.kde.kirigamiaddons.treeview 1.0
*/
property color textColor: Kirigami.Theme.textColor
/**
* This property holds the color for the background of the item.
* It is advised to leave the default value ('transparent')
*
* @since org.kde.kirigamiaddons.treeview 1.0
*/
property color backgroundColor: "transparent"
/**
* This property holds the background color to use if alternatingBackground is true.
* It is advised to leave the default.
*
* @since org.kde.kirigamiaddons.treeview 1.0
*/
property color alternateBackgroundColor: Kirigami.Theme.alternateBackgroundColor
/**
* This property holds the color for the text in the item when pressed or
* selected. It is advised to leave the default value (Kirigami.Theme.highlightedTextColor).
*
* @note If custom text elements are inserted in an AbstractListItem,
* their color property will have to be manually bound with this property.
*/
property color activeTextColor: Kirigami.Theme.highlightedTextColor
/**
* This property holds the color for the background of the item when pressed or
* selected. It is advised to leave the default value (Kirigami.Theme.highlightColor).
*/
property color activeBackgroundColor: Kirigami.Theme.highlightColor
width: parent && parent.width > 0 ? parent.width : implicitWidth
padding: Kirigami.Settings.tabletMode ? Kirigami.Units.largeSpacing : Kirigami.Units.smallSpacing
Accessible.role: Accessible.ListItem
hoverEnabled: true
height: visible ? implicitHeight : 0
implicitHeight: contentItem.implicitHeight + topPadding + bottomPadding
implicitWidth: contentItem ? contentItem.implicitWidth + leftPadding + rightPadding : Kirigami.Units.gridUnit * 12
Layout.fillWidth: true
data: [
TreeViewDecoration {
id: decoration
......@@ -37,16 +90,6 @@ Kirigami.AbstractListItem {
parentDelegate: delegate
model: delegate.ListView.view ? delegate.ListView.view.descendantsModel :
(delegate.TableView.view ? delegate.TableView.view.descendantsModel : null)
},
Binding {
target: contentItem.anchors
property: "left"
value: delegate.left
},
Binding {
target: contentItem.anchors
property: "leftMargin"
value: decoration.width + delegate.padding * 2 + Kirigami.Units.smallSpacing
}
]
......@@ -60,8 +103,8 @@ Kirigami.AbstractListItem {
}
}
Keys.onRightPressed: if (kDescendantExpandable) {
if (kDescendantExpanded && delegate.ListView.view) {
Keys.onRightPressed: if (kDescendantExpandable && delegate.ListView.view) {
if (kDescendantExpanded) {
ListView.view.incrementCurrentIndex();
} else {
decoration.model.expandChildren(index);
......@@ -72,9 +115,9 @@ Kirigami.AbstractListItem {
decoration.model.toggleChildren(index);
}
// FIXME: it should probably use leftInset property but Kirigami.AbstractListItem doesn't have it because can't import QQC2 more than 2.0
background.anchors {
left: delegate.left
leftMargin: decoration.width + delegate.padding * 2
}
leftInset: Qt.application.layoutDirection !== Qt.RightToLeft ? decoration.width + listItem.padding * 2 : 0
leftPadding: Qt.application.layoutDirection !== Qt.RightToLeft ? decoration.width + listItem.padding * 2 : 0
rightPadding: Qt.application.layoutDirection === Qt.RightToLeft ? decoration.width + listItem.padding * 2 : 0
rightInset: Qt.application.layoutDirection === Qt.RightToLeft ? decoration.width + listItem.padding * 2 : 0
}
......@@ -15,75 +15,70 @@ import org.kde.kirigami 2.14
* It's intended to make all tree views look coherent.
* It has a default icon and a label
*
* @since org.kde.kirigamiaddons.treeview 1.0
*/
AbstractTreeItem {
id: listItem
/**
* string: bool
* A single text label the list item will contain
* This property holds the single text label the list item will contain.
*
* @since org.kde.kirigamiaddons.treeview 1.0
*/
property alias label: listItem.text
/**
* A subtitle that goes below the main label
* Optional; if not defined, the list item will only have a main label
* @since 5.70
* @since org.kde.kirigami 2.12
* This property holds a subtitle that goes below the main label.
* Optional; if not defined, the list item will only have a main label.
*
* @since org.kde.kirigamiaddons.treeview 1.0
*/
property alias subtitle: subtitleItem.text
/**
* bold: bool
* Control whether the text (in both primary text and subtitle) should be rendered as bold
* @since 5.71
* @since org.kde.kirigami 2.13
* This property controls whether the text (in both primary text and subtitle)
* should be rendered as bold.
*
* @since org.kde.kirigamiaddons.treeview 1.0
*/
property bool bold: false
/**
* icon: var
* A single icon that will be displayed in the list item.
* The icon can be a grouped property with name,size,color etc, as QtQuickControls2 icons are defined.
* The icon can also be either a QIcon, a string name of a fdo compatible name,
* or any url accepted by the Image element.
*/
property var icon
/**
* iconSize: int
* The preferred size for the icon
* @since 2.5
* This property holds the preferred size for the icon.
*
* @since org.kde.kirigamiaddons.treeview 1.0
*/
property alias iconSize: iconItem.size
/**
* iconColor: color
* The color the icon should be colorized to.
* By default it will be the text color.
* This property holds the color the icon should be colorized to.
* If the icon shouldn't be colorized in any way, set it to "transparent"
* @since 2.7
*
* By default it will be the text color.
*
* @since org.kde.kirigamiaddons.treeview 1.0
*/
property alias iconColor: iconItem.color
/**
* reserveSpaceForIcon: bool
* If true, even when there is no icon the space will be reserved for it
* It's useful in layouts where only some entries have an icon,
* having the text all horizontally aligned
* @brief This property holds whether when there is no icon the space will
* still be reserved for it.
*
* It's useful in layouts where only some entries have an icon, having the
* text all horizontally aligned.
*/
property alias reserveSpaceForIcon: iconItem.visible
/**
* reserveSpaceForLabel: bool
* If false, the label will not try to be as wide as possible
* It's useful in layouts containing entries without text
* @brief This property holds whether the label will try to be as wide as
* possible.
*
* It's useful in layouts containing entries without text. By default, true.
*/
property alias reserveSpaceForLabel: labelItem.visible
default property alias _basicDefault: layout.data
icon: action ? action.icon.name || action.icon.source : undefined
contentItem: RowLayout {
id: layout
spacing: LayoutMirroring.enabled ? listItem.rightPadding : listItem.leftPadding
......@@ -134,4 +129,3 @@ AbstractTreeItem {
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment