From b0ce8c583f734479a38dbd61eae931067169876c Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Fri, 17 May 2024 13:09:10 +0400 Subject: [PATCH] Full length library entry line separator Now the library entry line separator extends all the way to the right (into the book open/download control column). This is achieved by having QStyledItemDelegate::paint() execute before ContentManagerDelegate::paintBookState() and the latter must take care to not paint over the line separator painted by the former. --- src/contentmanagerdelegate.cpp | 20 ++++++++++++-------- src/contentmanagerdelegate.h | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/contentmanagerdelegate.cpp b/src/contentmanagerdelegate.cpp index a4c3929..bcdf7d5 100644 --- a/src/contentmanagerdelegate.cpp +++ b/src/contentmanagerdelegate.cpp @@ -164,8 +164,14 @@ void ContentManagerDelegate::paintButton(QPainter *p, const QRect &r, QString t) baseButton->style()->drawControl( QStyle::CE_PushButton, &button, p, baseButton.data()); } -void ContentManagerDelegate::paintBookState(QPainter *p, QRect r, const QModelIndex &index) const +void ContentManagerDelegate::paintBookState(QPainter *p, const QStyleOptionViewItem &opt, const QModelIndex &index) const { + const QRect r = opt.rect; + if (opt.state & QStyle::State_MouseOver) { + // don't paint over the line separator + const auto cellInternalArea = r.adjusted(0, 0, 0, -1); + p->fillRect(cellInternalArea, QBrush("#eaecf0")); + } const auto node = static_cast(index.internalPointer()); const auto id = node->getBookId(); switch ( KiwixApp::instance()->getContentManager()->getBookState(id) ) { @@ -197,13 +203,6 @@ void ContentManagerDelegate::paint(QPainter *painter, const QStyleOptionViewItem return; } QStyleOptionViewItem eOpt = option; - if (index.column() == 5) { - if (option.state & QStyle::State_MouseOver) { - painter->fillRect(option.rect, QBrush("#eaecf0")); - } - paintBookState(painter, option.rect, index); - return; - } if (index.column() == 1) { auto bFont = painter->font(); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) @@ -213,7 +212,12 @@ void ContentManagerDelegate::paint(QPainter *painter, const QStyleOptionViewItem #endif eOpt.font = bFont; } + QStyledItemDelegate::paint(painter, eOpt, index); + + if (index.column() == 5) { + paintBookState(painter, eOpt, index); + } } bool ContentManagerDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) diff --git a/src/contentmanagerdelegate.h b/src/contentmanagerdelegate.h index 6466b13..48c5cef 100644 --- a/src/contentmanagerdelegate.h +++ b/src/contentmanagerdelegate.h @@ -16,7 +16,7 @@ public: QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; private: // functions - void paintBookState(QPainter *p, QRect r, const QModelIndex &index) const; + void paintBookState(QPainter *p, const QStyleOptionViewItem &opt, const QModelIndex &index) const; void paintButton(QPainter *p, const QRect &r, QString t) const; private: