From b9ea6fd2e717ffe558c37f4a446e8a90dd9fafb4 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Fri, 26 Feb 2021 16:51:03 -0500 Subject: [PATCH] Show sort indicators on fixed width columns --- src/gui/entry/EntryView.cpp | 18 +++++++++------- src/gui/styles/base/BaseStyle.cpp | 35 +++++++++++++++++++++++++------ 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/gui/entry/EntryView.cpp b/src/gui/entry/EntryView.cpp index 9dd021453..d6130b809 100644 --- a/src/gui/entry/EntryView.cpp +++ b/src/gui/entry/EntryView.cpp @@ -109,11 +109,6 @@ EntryView::EntryView(QWidget* parent) m_columnActions->addAction(action); } connect(m_columnActions, SIGNAL(triggered(QAction*)), this, SLOT(toggleColumnVisibility(QAction*))); - connect(header(), &QHeaderView::sortIndicatorChanged, [this](int index, Qt::SortOrder order) { - Q_UNUSED(order) - header()->setSortIndicatorShown(index != EntryModel::Paperclip && index != EntryModel::Totp - && index != EntryModel::PasswordStrength); - }); m_headerMenu->addSeparator(); m_headerMenu->addAction(tr("Fit to window"), this, SLOT(fitColumnsToWindow())); @@ -121,7 +116,6 @@ EntryView::EntryView(QWidget* parent) m_headerMenu->addSeparator(); m_headerMenu->addAction(tr("Reset to defaults"), this, SLOT(resetViewToDefaults())); - header()->setMinimumSectionSize(24); header()->setDefaultSectionSize(100); header()->setStretchLastSection(false); header()->setContextMenuPolicy(Qt::CustomContextMenu); @@ -164,6 +158,9 @@ void EntryView::sortIndicatorChanged(int logicalIndex, Qt::SortOrder order) emit entrySelectionChanged(currentEntry()); emit viewStateChanged(); } + + header()->setSortIndicatorShown(true); + resetFixedColumns(); } void EntryView::keyPressEvent(QKeyEvent* event) @@ -421,7 +418,14 @@ void EntryView::resetFixedColumns() for (const auto& col : {EntryModel::Paperclip, EntryModel::Totp, EntryModel::PasswordStrength}) { if (!isColumnHidden(col)) { header()->setSectionResizeMode(col, QHeaderView::Fixed); - header()->resizeSection(col, ICON_ONLY_SECTION_SIZE); + + // Increase column width, if sorting, to accommodate icon and arrow + auto width = ICON_ONLY_SECTION_SIZE; + if (header()->sortIndicatorSection() == col + && config()->get(Config::GUI_ApplicationTheme).toString() != "classic") { + width += 18; + } + header()->resizeSection(col, width); } } } diff --git a/src/gui/styles/base/BaseStyle.cpp b/src/gui/styles/base/BaseStyle.cpp index e53ebf9d0..504126552 100644 --- a/src/gui/styles/base/BaseStyle.cpp +++ b/src/gui/styles/base/BaseStyle.cpp @@ -86,9 +86,10 @@ namespace Phantom // These two are currently not based on font, but could be constexpr qint16 LineEdit_ContentsHPad = 5; constexpr qint16 ComboBox_NonEditable_ContentsHPad = 7; - constexpr qint16 HeaderSortIndicator_HOffset = 1; - constexpr qint16 HeaderSortIndicator_VOffset = 2; - constexpr qint16 TabBar_InctiveVShift = 0; + constexpr qint16 HeaderSortIndicator_HOffset = 6; + constexpr qint16 HeaderSortIndicator_VOffset = 4; + constexpr qint16 HeaderSortIndicator_Width = 12; + constexpr qint16 TabBar_InactiveVShift = 0; constexpr qreal TabBarTab_Rounding = 1.0; constexpr qreal SpinBox_Rounding = 1.0; @@ -3928,7 +3929,7 @@ int BaseStyle::pixelMetric(PixelMetric metric, const QStyleOption* option, const return widget->fontMetrics().height(); } case PM_TabBarTabShiftVertical: { - val = Phantom::TabBar_InctiveVShift; + val = Phantom::TabBar_InactiveVShift; break; } case PM_SubMenuOverlap: @@ -4164,9 +4165,9 @@ QSize BaseStyle::sizeFromContents(ContentsType type, sz.setWidth((nullIcon ? 0 : margin) + iconSize + (hdr->text.isNull() ? 0 : margin) + txt.width() + margin); if (hdr->sortIndicator != QStyleOptionHeader::None) { if (hdr->orientation == Qt::Horizontal) - sz.rwidth() += sz.height() + margin; + sz.rwidth() += Phantom::dpiScaled(Phantom::HeaderSortIndicator_Width); else - sz.rheight() += sz.width() + margin; + sz.rheight() += Phantom::dpiScaled(Phantom::HeaderSortIndicator_Width); } return sz; } @@ -4773,6 +4774,28 @@ QRect BaseStyle::subElementRect(SubElement sr, const QStyleOption* opt, const QW pad = Phantom::dpiScaled(pad); return r.adjusted(pad, 0, -pad, 0); } + case SE_HeaderLabel: { + int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, w); + QRect r(opt->rect.x() + margin, + opt->rect.y() + margin, + opt->rect.width() - margin * 2, + opt->rect.height() - margin * 2); + if (auto header = qstyleoption_cast(opt)) { + // Subtract width needed for arrow, if there is one + if (header->sortIndicator != QStyleOptionHeader::None) { + if (opt->state & State_Horizontal) + r.setWidth(r.width() - Phantom::dpiScaled(Phantom::HeaderSortIndicator_Width)); + else + r.setHeight(r.height() - Phantom::dpiScaled(Phantom::HeaderSortIndicator_Width)); + } + } + return visualRect(opt->direction, opt->rect, r); + } + case SE_HeaderArrow: { + QRect r = QCommonStyle::subElementRect(sr, opt, w); + r.setWidth(Phantom::dpiScaled(Phantom::HeaderSortIndicator_Width)); + return r; + } default: break; }