Commit 11b8783d authored by David Edmundson's avatar David Edmundson
Browse files

Reduce items in delegates

We have a lot of delegates, we need them as light as possible.

Currently a simple cell delegate contains:
 - A mouseArea for tooltips
 - A QQuickToolTipAttached (albeit, this is just a light object)
 - Another mouseArea in the background handling clicks

We can move this all up to be one MouseArea covering the table. It
requires a tiny bit more manual mapping, and the view making assumptions
about the delegates, but it's a big reduction in objects.
parent 6601ba80
......@@ -84,6 +84,83 @@ FocusScope {
}
}
MouseArea {
id: tableViewMouseArea
z: 1000
property Item delegateUnderMouse: null
onDelegateUnderMouseChanged: function() {
ToolTip.hide();
if (delegateUnderMouse) {
var currentIndex = delegateUnderMouse.background.__modelIndex;
tableView.selectionModel.setCurrentIndex(currentIndex, ItemSelectionModel.NoUpdate);
} else {
tableView.selectionModel.clearCurrentIndex()
}
if (delegateUnderMouse && delegateUnderMouse.truncated){
tooltipTimer.restart()
} else {
tooltipTimer.stop()
}
}
hoverEnabled: true
anchors.fill: scrollView
onExited: delegateUnderMouse = null
onPositionChanged: function(mouse) {
var viewportPos = tableView.contentItem.mapFromItem(scrollView, mouse.x, mouse.y)
delegateUnderMouse = tableView.contentItem.childAt(viewportPos.x, viewportPos.y)
}
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
var viewportPos = tableView.contentItem.mapFromItem(scrollView, mouse.x, mouse.y)
delegateUnderMouse = tableView.contentItem.childAt(viewportPos.x, viewportPos.y)
if (!delegateUnderMouse) {
return;
}
var currentIndex = delegateUnderMouse.background.__modelIndex;
if (tableView.selectionModel.isSelected(currentIndex) && mouse.button == Qt.RightButton) {
tableView.contextMenuRequested(currentIndex, mapToGlobal(mouse.x, mouse.y))
return;
}
if (mouse.modifiers & Qt.ShiftModifier) {
//TODO: Implement range selection
tableView.selectionModel.select(currentIndex, ItemSelectionModel.Toggle | ItemSelectionModel.Rows)
} else if (mouse.modifiers & Qt.ControlModifier) {
tableView.selectionModel.select(currentIndex, ItemSelectionModel.Toggle | ItemSelectionModel.Rows)
} else {
tableView.selectionModel.select(currentIndex, ItemSelectionModel.ClearAndSelect | ItemSelectionModel.Rows)
}
if (mouse.button == Qt.RightButton) {
tableView.contextMenuRequested(currentIndex, mapToGlobal(mouse.x, mouse.y))
}
}
Timer {
id: tooltipTimer
interval: Kirigami.Units.toolTipDelay
onTriggered: function() {
var pos = tableViewMouseArea.delegateUnderMouse.mapToItem(tableView, 0, 0)
tableViewMouseArea.ToolTip.toolTip.x = pos.x;
tableViewMouseArea.ToolTip.toolTip.y = pos.y - tableViewMouseArea.delegateUnderMouse.height;
tableViewMouseArea.ToolTip.show(tableViewMouseArea.delegateUnderMouse.text)
}
}
}
ScrollView {
id: scrollView
anchors.fill: parent
......
......@@ -24,15 +24,4 @@ Label {
horizontalAlignment: Text.AlignHCenter
background: CellBackground { view: delegate.TableView.view; row: model.row; column: model.column }
MouseArea {
id: mouse
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.NoButton
ToolTip.text: delegate.text
ToolTip.delay: Kirigami.Units.toolTipDelay
ToolTip.visible: mouse.containsMouse && delegate.truncated
}
}
......@@ -52,7 +52,6 @@ Rectangle {
updateIsSelected();
}
Rectangle {
anchors.fill: parent
color: Kirigami.Theme.backgroundColor
......@@ -60,46 +59,4 @@ Rectangle {
Kirigami.Theme.colorSet: Kirigami.Theme.Selection
opacity: selected ? 1 : (root.__selection.currentIndex.row == root.__modelIndex.row ? 0.3 : 0)
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
onEntered: root.__selection.setCurrentIndex(root.__modelIndex, ItemSelectionModel.NoUpdate)
onExited: Qt.callLater(maybeClearCurrent)
onClicked: {
if (root.__selection.isSelected(root.__modelIndex) && mouse.button == Qt.RightButton) {
view.contextMenuRequested(root.__modelIndex, mapToGlobal(mouse.x, mouse.y))
return
}
if (mouse.modifiers & Qt.ShiftModifier) {
//TODO: Implement range selection
root.__selection.select(root.__modelIndex, ItemSelectionModel.Toggle | ItemSelectionModel.Rows)
} else if (mouse.modifiers & Qt.ControlModifier) {
root.__selection.select(root.__modelIndex, ItemSelectionModel.Toggle | ItemSelectionModel.Rows)
} else {
root.__selection.select(root.__modelIndex, ItemSelectionModel.ClearAndSelect | ItemSelectionModel.Rows)
}
if (mouse.button == Qt.RightButton) {
view.contextMenuRequested(root.__modelIndex, mapToGlobal(mouse.x, mouse.y))
}
}
function maybeClearCurrent() {
// We (ab)use currentIndex to indicate the currently hovered row. This means
// we shouldn't just clear the current index when the mouse leaves this item
// since it may just be hovering a different table cell. However, if the mouse
// exited but the currentIndex is still the current cell, then we can be fairly
// sure the mouse is no longer over a table cell and we can safely clear the
// current index.
if (__selection.currentIndex == __modelIndex) {
__selection.clearCurrentIndex()
}
}
}
}
......@@ -17,6 +17,7 @@ Control {
property string iconName
property string text: model.display != undefined ? model.display : ""
property alias truncated: label.truncated
property real iconSize: Kirigami.Units.iconSizes.small
property alias treeDecorationVisible: treeDecoration.visible
......@@ -89,7 +90,4 @@ Control {
}
hoverEnabled: true
ToolTip.text: delegate.text
ToolTip.delay: Kirigami.Units.toolTipDelay
ToolTip.visible: delegate.hovered && label.truncated
}
......@@ -16,6 +16,7 @@ Control {
id: delegate
property string text: model.display != undefined ? model.display : ""
property alias truncated: label.truncated
property real maximum: 100
property alias valueSources: chart.valueSources
......
Supports Markdown
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