diff --git a/framework/qml/CalendarSelector.qml b/framework/qml/CalendarSelector.qml index dc93ecd4..240dbc02 100644 --- a/framework/qml/CalendarSelector.qml +++ b/framework/qml/CalendarSelector.qml @@ -1,169 +1,170 @@ /* * Copyright (C) 2018 Michael Bohlender, * Copyright (C) 2019 Christian Mollekopf, * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, 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 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 2.9 import QtQuick.Controls 2 import QtQuick.Layouts 1.2 import org.kube.framework 1.0 as Kube Kube.InlineAccountSwitcher { id: root property bool selectionEnabled: false property string contentType: "event" property alias enabledCalendars: calendarFilterCollector.checkedEntities property var currentCalendar: null - property var currentListView: null - function clearSelection() { - if (root.currentListView) { - root.currentListView.currentIndex = -1 + if (root.currentDelegate) { + root.currentDelegate.clearSelection() } } Kube.CheckedEntities { id: calendarFilterCollector } delegate: Kube.ListView { id: listView + function clearSelection() { + listView.currentIndex = -1 + } + property bool editMode: false property Component buttonDelegate: Kube.IconButton { height: Kube.Units.gridUnit padding: 0 iconName: Kube.Icons.overflowMenu_inverted onClicked: listView.editMode = !listView.editMode; checkable: true checked: listView.editMode } currentIndex: -1 Layout.fillWidth: true Layout.maximumHeight: Math.min(contentHeight, parent.height - Kube.Units.gridUnit) Layout.preferredHeight: contentHeight onCurrentItemChanged: { - root.currentListView = listView if (currentItem) { root.currentCalendar = currentItem.currentData.identifier } } model: Kube.CheckableEntityModel { id: calendarModel type: "calendar" roles: ["name", "color", "enabled"] sortRole: "name" filter: listView.editMode ? {"contentTypes": contentType} : {"contentTypes": contentType, enabled: true} accountId: listView.parent.accountId checkedEntities: calendarFilterCollector onInitialItemsLoaded: { //Automatically enable edit mode if no calendars are enabled if (rowCount() == 0) { listView.editMode = true; } } } delegate: Kube.ListDelegate { id: delegate selectionEnabled: root.selectionEnabled width: listView.availableWidth height: Kube.Units.gridUnit * 1.5 hoverEnabled: true property bool isActive: listView.currentIndex === index background: Kube.DelegateBackground { anchors.fill: parent color: Kube.Colors.textColor focused: delegate.activeFocus || delegate.hovered selected: isActive } RowLayout { anchors { fill: parent leftMargin: Kube.Units.smallSpacing } spacing: Kube.Units.smallSpacing Kube.CheckBox { id: checkBox opacity: 0.9 visible: listView.editMode checked: model.checked || model.enabled onCheckedChanged: { model.checked = checked model.enabled = checked } indicator: Rectangle { width: Kube.Units.gridUnit * 0.8 height: Kube.Units.gridUnit * 0.8 color: model.color Rectangle { id: highlight anchors.fill: parent visible: checkBox.hovered || checkBox.visualFocus color: Kube.Colors.highlightColor opacity: 0.4 } Kube.Icon { anchors.centerIn: parent height: Kube.Units.gridUnit width: Kube.Units.gridUnit visible: checkBox.checked iconName: Kube.Icons.checkbox_inverted } } } Kube.Label { id: label Layout.fillWidth: true text: model.name color: Kube.Colors.highlightedTextColor elide: Text.ElideLeft clip: true } Rectangle { visible: !listView.editMode width: Kube.Units.gridUnit * 0.8 height: Kube.Units.gridUnit * 0.8 radius: width / 2 color: model.color } ToolTip { id: toolTipItem visible: delegate.hovered && label.truncated text: label.text } } } } } diff --git a/framework/qml/InlineAccountSwitcher.qml b/framework/qml/InlineAccountSwitcher.qml index d092eb68..0cebf204 100644 --- a/framework/qml/InlineAccountSwitcher.qml +++ b/framework/qml/InlineAccountSwitcher.qml @@ -1,111 +1,115 @@ /* * Copyright (C) 2017 Michael Bohlender, * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, 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 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 2.4 import QtQuick.Layouts 1.1 import org.kube.framework 1.0 as Kube FocusScope { id: root property Component delegate: null + property var currentDelegate: null ColumnLayout { id: layout anchors.fill: parent Repeater { model: Kube.AccountsModel {} onItemAdded: { //Autoselect the first account to appear if (!Kube.Context.currentAccountId) { Kube.Context.currentAccountId = item.currentData.accountId } } delegate: ColumnLayout { id: accountDelegate property variant currentData: model property bool isCurrent: false states: [ State { name: "current" when: model.accountId == Kube.Context.currentAccountId PropertyChanges {target: accountDelegate; isCurrent: true} } ] Layout.minimumHeight: Kube.Units.gridUnit Layout.fillHeight: isCurrent Layout.fillWidth: true Item { Layout.fillWidth: true Layout.preferredHeight: Kube.Units.gridUnit Kube.TextButton { anchors { left: parent.left top: parent.top } height: Kube.Units.gridUnit width: parent.width - Kube.Units.gridUnit textColor: Kube.Colors.highlightedTextColor activeFocusOnTab: !isCurrent hoverEnabled: !isCurrent onClicked: { Kube.Context.currentAccountId = model.accountId } text: model.name font.weight: Font.Bold font.family: Kube.Font.fontFamily horizontalAlignment: Text.AlignHLeft padding: 0 } Loader { anchors { right: parent.right top: parent.top } focus: isCurrent activeFocusOnTab: isCurrent visible: isCurrent sourceComponent: delegateLoader.item.buttonDelegate } } Loader { id: delegateLoader Layout.fillWidth: true Layout.fillHeight: true focus: accountDelegate.isCurrent activeFocusOnTab: true visible: accountDelegate.isCurrent sourceComponent: root.delegate property variant accountId: currentData.accountId property bool isCurrent: accountDelegate.isCurrent onIsCurrentChanged: { if (!!item && 'currentChanged' in item) { item.currentChanged() } + if (isCurrent) { + root.currentDelegate = item + } } } } } } }