Commit 81e175f1 authored by Tranter Madi's avatar Tranter Madi 🌧 Committed by Nate Graham
Browse files

Clean up ViewSelector's code

parent ac4e1b54
Pipeline #147062 canceled with stage
......@@ -15,8 +15,7 @@ ScrollView {
id: scrollView
readonly property alias currentIndex: viewModeView.currentIndex
property double textOpacity
property alias model: pageDelegateModel.model
property alias model: viewModeView.model
signal switchView(int viewIndex)
......@@ -34,6 +33,7 @@ ScrollView {
contentItem: ListView {
id: viewModeView
property bool ignoreCurrentItemChanges: false
Accessible.role: Accessible.List
......@@ -43,65 +43,36 @@ ScrollView {
keyNavigationEnabled: true
interactive: true
property bool ignoreCurrentItemChanges: false
model: DelegateModel {
id: pageDelegateModel
delegate: ViewSelectorDelegate {
id: entry
height: Kirigami.Units.iconSizes.smallMedium + 3 * Kirigami.Units.smallSpacing
width: viewModeView.width
focus: true
isSelected: viewModeView.currentIndex === index
delegate: ViewSelectorDelegate {
id: entry
image: model.image
title: model.display
secondTitle: model.secondTitle
useSecondTitle: model.useSecondTitle
databaseId: model.databaseId
height: Kirigami.Units.iconSizes.smallMedium + 3 * Kirigami.Units.smallSpacing
width: viewModeView.width
onClicked: {
viewModeView.currentIndex = index
entry.forceActiveFocus()
}
onClicked: {
viewModeView.currentIndex = index
entry.forceActiveFocus()
}
}
section.property: 'entryCategory'
section.delegate: Kirigami.ListSectionHeader {
label: (section != 'default' ? section : '')
height: if (section == 'default') 0
width: viewModeView.width
section.delegate: Loader {
active: section !== "default"
sourceComponent: Kirigami.ListSectionHeader {
label: section
width: viewModeView.width
}
}
onCurrentItemChanged: if (!ignoreCurrentItemChanges) switchView(currentIndex)
}
Behavior on implicitWidth {
NumberAnimation {
easing.type: Easing.InOutQuad
duration: Kirigami.Units.longDuration
}
}
Behavior on width {
NumberAnimation {
easing.type: Easing.InOutQuad
duration: Kirigami.Units.longDuration
}
}
states: [
State {
name: 'iconsAndText'
when: mainWindow.width >= elisaTheme.viewSelectorSmallSizeThreshold
PropertyChanges {
target: scrollView
textOpacity: 1
implicitWidth: 225
}
},
......@@ -110,10 +81,16 @@ ScrollView {
when: mainWindow.width < elisaTheme.viewSelectorSmallSizeThreshold
PropertyChanges {
target: scrollView
textOpacity: 0
implicitWidth: Kirigami.Units.iconSizes.smallMedium + 2 * Kirigami.Units.largeSpacing
}
}
]
transitions: Transition {
NumberAnimation {
properties: "implicitWidth"
easing.type: Easing.InOutQuad
duration: Kirigami.Units.longDuration
}
}
}
......@@ -9,216 +9,19 @@ import QtQuick.Controls 2.2
import QtGraphicalEffects 1.0
import org.kde.kirigami 2.5 as Kirigami
FocusScope {
id: rootItem
property bool isSelected
property string title
property alias image: viewIcon.source
property int databaseId
property string secondTitle
property bool useSecondTitle
signal clicked()
Rectangle {
id: backgroundHighlight
anchors.fill: parent
z: 0
color: "transparent"
}
Kirigami.BasicListItem {
Accessible.role: Accessible.ListItem
Accessible.description: title
Accessible.name: title
MouseArea {
id: hoverArea
anchors.fill: parent
z: 1
hoverEnabled: true
acceptedButtons: Qt.LeftButton
onClicked: {
rootItem.clicked()
}
Loader {
id: hoverLoader
anchors.fill: parent
active: false
sourceComponent: ToolTip {
delay: Qt.styleHints.mousePressAndHoldInterval
text: title
visible: hoverArea && hoverArea.containsMouse && !nameLabel.visible
contentItem: Label {
text: title
color: myPalette.highlightedText
}
enter: Transition { NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad; from: 0.0; to: 1.0; duration: Kirigami.Units.longDuration; } }
exit: Transition { NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad; from: 1.0; to: 0.0; duration: Kirigami.Units.longDuration; } }
background: Rectangle {
color: myPalette.shadow
radius: elisaTheme.tooltipRadius
layer.enabled: true
layer.effect: DropShadow {
horizontalOffset: elisaTheme.shadowOffset
verticalOffset: elisaTheme.shadowOffset
radius: 8
samples: 17
color: myPalette.shadow
}
}
}
}
Kirigami.Icon {
id: viewIcon
z: 1
anchors {
verticalCenter: parent.verticalCenter
leftMargin: Kirigami.Units.largeSpacing
left: parent.left
}
height: Kirigami.Units.iconSizes.smallMedium
width: Kirigami.Units.iconSizes.smallMedium
}
LabelWithToolTip {
id: nameLabel
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: Kirigami.Units.largeSpacing
anchors.left: viewIcon.right
anchors.right: parent.right
anchors.rightMargin: Kirigami.Units.largeSpacing
verticalAlignment: "AlignVCenter"
text: title
elide: Text.ElideRight
Accessible.description: model.display
Accessible.name: model.display
opacity: textOpacity
visible: opacity > 0
padding: Kirigami.Units.smallSpacing
separatorVisible: false
alternatingBackground: false
color: (viewModeView.currentIndex === index || hoverArea.containsMouse ? myPalette.highlight : myPalette.text)
}
}
icon: model.image
label: model.display
states: [
State {
name: 'notSelected'
when: !rootItem.activeFocus && !hoverArea.containsMouse && !rootItem.isSelected
PropertyChanges {
target: hoverLoader
active: false
}
PropertyChanges {
target: hoverLoader
opacity: 0.0
}
PropertyChanges {
target: viewIcon
active: false
selected: false
}
PropertyChanges {
target: nameLabel
color: myPalette.buttonText
}
PropertyChanges {
target: backgroundHighlight
color: 'transparent'
}
},
State {
name: 'hovered'
when: !rootItem.activeFocus && hoverArea.containsMouse
PropertyChanges {
target: hoverLoader
active: true
}
PropertyChanges {
target: hoverLoader
opacity: 1.0
}
PropertyChanges {
target: viewIcon
active: true
selected: false
}
PropertyChanges {
target: nameLabel
color: myPalette.buttonText
}
PropertyChanges {
target: backgroundHighlight
color: Qt.rgba(myPalette.highlight.r, myPalette.highlight.g, myPalette.highlight.b, 0.2)
}
},
State {
name: 'selected'
when: !rootItem.activeFocus && rootItem.isSelected
PropertyChanges {
target: hoverLoader
active: false
}
PropertyChanges {
target: hoverLoader
opacity: 0.0
}
PropertyChanges {
target: viewIcon
active: false
selected: true
}
PropertyChanges {
target: nameLabel
color: myPalette.buttonText
}
PropertyChanges {
target: backgroundHighlight
color: myPalette.mid
}
},
State {
name: 'focused'
when: rootItem.activeFocus
PropertyChanges {
target: hoverLoader
active: false
}
PropertyChanges {
target: hoverLoader
opacity: 0.0
}
PropertyChanges {
target: viewIcon
active: false
selected: true
}
PropertyChanges {
target: nameLabel
color: myPalette.highlightedText
}
PropertyChanges {
target: backgroundHighlight
color: myPalette.highlight
}
}
]
ToolTip.visible: labelItem.truncated && hovered
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
ToolTip.text: model.display
}
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