diff --git a/framework/qml/CalendarSelector.qml b/framework/qml/CalendarSelector.qml index f92c8237..dc93ecd4 100644 --- a/framework/qml/CalendarSelector.qml +++ b/framework/qml/CalendarSelector.qml @@ -1,167 +1,169 @@ /* * 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 } } Kube.CheckedEntities { id: calendarFilterCollector } delegate: Kube.ListView { id: listView 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 - spacing: Kube.Units.smallSpacing 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 + 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 + 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/TreeView.qml b/framework/qml/TreeView.qml index 3509b0dc..66f829ba 100644 --- a/framework/qml/TreeView.qml +++ b/framework/qml/TreeView.qml @@ -1,139 +1,139 @@ /* Copyright (C) 2016 Michael Bohlender, Copyright (C) 2017 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 import QtQuick.Controls 2 import QtQuick.Layouts 1 import org.kube.framework 1.0 as Kube FocusScope { id: root property var model: null property var currentIndex: null property alias count: listView.count signal dropped(var index, var drop) function clearSelection() { listView.currentIndex = -1 } function selectRootIndex() { if (listView.count >= 1) { listView.currentIndex = 0 } } function selectNext() { listView.incrementCurrentIndex() } function selectPrevious() { listView.decrementCurrentIndex() } Kube.ListView { id: listView anchors.fill: parent focus: true model: Kube.TreeModelAdaptor { id: modelAdaptor model: root.model } onCurrentIndexChanged: { root.currentIndex = modelAdaptor.mapRowToModelIndex(listView.currentIndex) } ScrollBar.vertical: Kube.ScrollBar { invertedColors: true } delegate: Kube.ListDelegate { id: delegate width: listView.availableWidth height: Kube.Units.gridUnit * 1.5 hoverEnabled: true property bool isActive: listView.currentIndex === index DropArea { anchors.fill: parent Rectangle { anchors.fill: parent color: Kube.Colors.viewBackgroundColor opacity: 0.3 visible: parent.containsDrag } onDropped: root.dropped(modelAdaptor.mapRowToModelIndex(index), drop) } background: Kube.DelegateBackground { anchors.fill: parent color: Kube.Colors.textColor focused: delegate.activeFocus || delegate.hovered selected: isActive } function toggleExpanded() { var idx = model._q_TreeView_ModelIndex if (modelAdaptor.isExpanded(idx)) { modelAdaptor.collapse(idx) } else { modelAdaptor.expand(idx) } } Keys.onSpacePressed: toggleExpanded() RowLayout { anchors { fill: parent - leftMargin: 2 + (model._q_TreeView_ItemDepth + 1) * Kube.Units.largeSpacing + leftMargin: Kube.Units.smallSpacing + (model._q_TreeView_ItemDepth) * Kube.Units.largeSpacing } spacing: Kube.Units.smallSpacing Kube.Label { id: label Layout.fillWidth: true text: model.name color: Kube.Colors.highlightedTextColor elide: Text.ElideLeft clip: false Kube.IconButton { anchors { right: label.left verticalCenter: label.verticalCenter } visible: model._q_TreeView_HasChildren iconName: model._q_TreeView_ItemExpanded ? Kube.Icons.goDown_inverted : Kube.Icons.goNext_inverted padding: 0 width: Kube.Units.gridUnit height: Kube.Units.gridUnit onClicked: toggleExpanded() activeFocusOnTab: false hoverEnabled: false } } } } } }