From f20fc9132fdc92eb13e9fe49d73d82f37b8724d3 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Wed, 28 Feb 2024 15:21:32 +0100 Subject: [PATCH] Axivion: Fix sort toggling glitches The resize handle of a header has some margin to decide whether to start a resize attempt. This margin interfered with our randomly chosen one. Take the needed margin into account and beside this store an additional information about the column that triggered our sort toggling attempt. This avoids starting to toggle some column and moving slightly to the next one and ending up in sorting the final column of the move. Change-Id: I8199f90fd06145c61d2c5e7574b6f040c72022b6 Reviewed-by: Jarek Kobus --- src/plugins/axivion/issueheaderview.cpp | 19 +++++++++++++------ src/plugins/axivion/issueheaderview.h | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/plugins/axivion/issueheaderview.cpp b/src/plugins/axivion/issueheaderview.cpp index 3f8efd86c6e..ce432eb1265 100644 --- a/src/plugins/axivion/issueheaderview.cpp +++ b/src/plugins/axivion/issueheaderview.cpp @@ -61,8 +61,10 @@ void IssueHeaderView::mousePressEvent(QMouseEvent *event) if (y > 1 && y < height() - 2) { // TODO improve const int pos = position.x(); const int logical = logicalIndexAt(pos); - const int end = sectionViewportPosition(logical) + sectionSize(logical); - const int start = end - ICON_SIZE - 2; + m_lastToggleLogicalPos = logical; + const int margin = style()->pixelMetric(QStyle::PM_HeaderGripMargin, nullptr, this); + const int end = sectionViewportPosition(logical) + sectionSize(logical) - margin; + const int start = end - ICON_SIZE; m_maybeToggleSort = start < pos && end > pos; } } @@ -79,7 +81,8 @@ void IssueHeaderView::mouseReleaseEvent(QMouseEvent *event) const QPoint position = event->position().toPoint(); const int y = position.y(); const int logical = logicalIndexAt(position.x()); - if (logical > -1 && logical < m_sortableColumns.size()) { + if (logical == m_lastToggleLogicalPos + && logical > -1 && logical < m_sortableColumns.size()) { if (m_sortableColumns.at(logical)) { // ignore non-sortable if (y < height() / 2) // TODO improve onToggleSort(logical, SortOrder::Ascending); @@ -88,6 +91,7 @@ void IssueHeaderView::mouseReleaseEvent(QMouseEvent *event) } } } + m_lastToggleLogicalPos = -1; QHeaderView::mouseReleaseEvent(event); } @@ -118,8 +122,10 @@ QSize IssueHeaderView::sectionSizeFromContents(int logicalIndex) const const QSize oldSize = QHeaderView::sectionSizeFromContents(logicalIndex); const QSize newSize = logicalIndex < m_columnWidths.size() ? QSize(qMax(m_columnWidths.at(logicalIndex), oldSize.width()), oldSize.height()) : oldSize; - // add icon size and margin (2) - return QSize{newSize.width() + ICON_SIZE + 2, qMax(newSize.height(), ICON_SIZE)}; + + const int margin = style()->pixelMetric(QStyle::PM_HeaderGripMargin, nullptr, this); + // add icon size and margin (default resize handle margin + 1) + return QSize{newSize.width() + ICON_SIZE + margin, qMax(newSize.height(), ICON_SIZE)}; } void IssueHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const @@ -132,9 +138,10 @@ void IssueHeaderView::paintSection(QPainter *painter, const QRect &rect, int log if (!m_sortableColumns.at(logicalIndex)) return; + const int margin = style()->pixelMetric(QStyle::PM_HeaderGripMargin, nullptr, this); const QIcon icon = iconForSorted(logicalIndex == m_currentSortIndex ? m_currentSortOrder : SortOrder::None); const int offset = qMax((rect.height() - ICON_SIZE), 0) / 2; - const QRect iconRect(rect.left() + rect.width() - ICON_SIZE - 2, offset, ICON_SIZE, ICON_SIZE); + const QRect iconRect(rect.left() + rect.width() - ICON_SIZE - margin, offset, ICON_SIZE, ICON_SIZE); icon.paint(painter, iconRect); } diff --git a/src/plugins/axivion/issueheaderview.h b/src/plugins/axivion/issueheaderview.h index 1fbbd9b76fd..c1c8230440c 100644 --- a/src/plugins/axivion/issueheaderview.h +++ b/src/plugins/axivion/issueheaderview.h @@ -35,6 +35,7 @@ private: void onToggleSort(int index, SortOrder order); bool m_dragging = false; bool m_maybeToggleSort = false; + int m_lastToggleLogicalPos = -1; int m_currentSortIndex = -1; SortOrder m_currentSortOrder = SortOrder::None; QList m_sortableColumns;