From e63561161beeb901a3ed72c6d7ed41919abfe9b6 Mon Sep 17 00:00:00 2001 From: ShaopengLin Date: Sun, 9 Jun 2024 04:27:02 -0400 Subject: [PATCH] Fixed hover misbehaviour over zim description Clicking and hovering the description dropdown of zim no longer whites out. Replaced manual drawing with default handling as it is no longer necessary. --- src/contentmanagerdelegate.cpp | 12 +++--------- src/contentmanagermodel.cpp | 9 ++++++--- src/contentmanagerview.cpp | 7 +++++++ src/contentmanagerview.h | 1 + src/descriptionnode.cpp | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/contentmanagerdelegate.cpp b/src/contentmanagerdelegate.cpp index 2ba8666..e9abade 100644 --- a/src/contentmanagerdelegate.cpp +++ b/src/contentmanagerdelegate.cpp @@ -193,15 +193,9 @@ void ContentManagerDelegate::paintBookState(QPainter *p, const QStyleOptionViewI void ContentManagerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { - QRect r = option.rect; - if (isDescriptionIndex(index)) { - // additional info - QRect nRect = r; - auto viewWidth = KiwixApp::instance()->getContentManager()->getView()->getView()->width(); - nRect.setWidth(viewWidth); - painter->drawText(nRect, Qt::AlignLeft | Qt::AlignVCenter, index.data(Qt::UserRole+1).toString()); - return; - } + if (isDescriptionIndex(index)) + return QStyledItemDelegate::paint(painter, option, index); + QStyleOptionViewItem eOpt = option; if (index.column() == 1) { auto bFont = painter->font(); diff --git a/src/contentmanagermodel.cpp b/src/contentmanagermodel.cpp index dd9e3b9..68c7a34 100644 --- a/src/contentmanagermodel.cpp +++ b/src/contentmanagermodel.cpp @@ -60,10 +60,13 @@ QVariant ContentManagerModel::data(const QModelIndex& index, int role) const return QVariant(); const auto col = index.column(); - const bool isThumbnailRequest = col == 0 && role == Qt::DecorationRole; - const bool otherDataRequest = col != 0 && (role == Qt::DisplayRole || role == Qt::UserRole+1 ); + const bool isThumbnailRequest = + !isDescriptionIndex(index) && col == 0 && role == Qt::DecorationRole; + const bool isDescriptionRequest = + isDescriptionIndex(index) && col == 0 && role == Qt::DisplayRole; + const bool otherDataRequest = col != 0 && role == Qt::DisplayRole; - if ( !isThumbnailRequest && !otherDataRequest ) + if ( !isThumbnailRequest && !otherDataRequest && !isDescriptionRequest ) return QVariant(); const auto item = static_cast(index.internalPointer()); diff --git a/src/contentmanagerview.cpp b/src/contentmanagerview.cpp index 75847d3..bce5a78 100644 --- a/src/contentmanagerview.cpp +++ b/src/contentmanagerview.cpp @@ -20,6 +20,7 @@ ContentManagerView::ContentManagerView(QWidget *parent) mp_ui->stackedWidget->setCurrentIndex(0); connect(mp_ui->m_view, &QTreeView::clicked, this, &ContentManagerView::onClicked); + connect(mp_ui->m_view, &QTreeView::expanded, this, &ContentManagerView::onExpanded); } ContentManagerView::~ContentManagerView() @@ -49,3 +50,9 @@ void ContentManagerView::onClicked(QModelIndex index) mp_ui->m_view->expand(zeroColIndex); } } + +void ContentManagerView::onExpanded(QModelIndex index) +{ + if (!mp_ui->m_view->isFirstColumnSpanned(0, index)) + mp_ui->m_view->setFirstColumnSpanned(0, index, true); +} diff --git a/src/contentmanagerview.h b/src/contentmanagerview.h index 790faf3..b5b5140 100644 --- a/src/contentmanagerview.h +++ b/src/contentmanagerview.h @@ -21,6 +21,7 @@ public: public slots: void showLoader(bool show); void onClicked(QModelIndex index); + void onExpanded(QModelIndex index); private: Ui::contentmanagerview *mp_ui; diff --git a/src/descriptionnode.cpp b/src/descriptionnode.cpp index b2bb544..fd5c549 100644 --- a/src/descriptionnode.cpp +++ b/src/descriptionnode.cpp @@ -36,7 +36,7 @@ int DescriptionNode::columnCount() const QVariant DescriptionNode::data(int column) { - if (column == 1) + if (column == 0) return m_desc; return QVariant(); }