mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 19:46:12 -04:00
Merge pull request #1115 from ShaopengLin/Issue#1112-fix-bookmark-description
Fixed Whiteouts of Book Descriptions on Hover
This commit is contained in:
commit
b59155aeb0
@ -193,15 +193,9 @@ void ContentManagerDelegate::paintBookState(QPainter *p, const QStyleOptionViewI
|
|||||||
|
|
||||||
void ContentManagerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
void ContentManagerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
QRect r = option.rect;
|
if (isDescriptionIndex(index))
|
||||||
if (index.parent().isValid()) {
|
return QStyledItemDelegate::paint(painter, option, 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;
|
|
||||||
}
|
|
||||||
QStyleOptionViewItem eOpt = option;
|
QStyleOptionViewItem eOpt = option;
|
||||||
if (index.column() == 1) {
|
if (index.column() == 1) {
|
||||||
auto bFont = painter->font();
|
auto bFont = painter->font();
|
||||||
@ -291,10 +285,22 @@ void ContentManagerDelegate::handleLastColumnClicked(const QModelIndex& index, Q
|
|||||||
|
|
||||||
QSize ContentManagerDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
QSize ContentManagerDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(option);
|
if (isDescriptionIndex(index))
|
||||||
|
{
|
||||||
|
const auto treeView = KiwixApp::instance()->getContentManager()->getView()->getView();
|
||||||
|
|
||||||
if (index.parent().isValid()) {
|
const int width = treeView->header()->length() - 2*treeView->indentation();
|
||||||
return QSize(300, 70);
|
// XXX: see QTreeView::padding in resources/css/_contentManager.css
|
||||||
|
const int verticalPadding = 4;
|
||||||
|
const int horizontalPadding = 4;
|
||||||
|
QRect descRect(0, 0, width - 2 * horizontalPadding, 0);
|
||||||
|
|
||||||
|
/* Based on the rectangle and text, find the best fitting size. */
|
||||||
|
QFontMetrics fm(option.font);
|
||||||
|
const QString text = index.data().toString();
|
||||||
|
const auto format = Qt::AlignLeft | Qt::AlignVCenter | Qt::TextWordWrap;
|
||||||
|
const int textHeight = fm.boundingRect(descRect, format, text).height();
|
||||||
|
return QSize(width, std::max(textHeight + verticalPadding, 70));
|
||||||
}
|
}
|
||||||
return QSize(50, 70);
|
return QSize(50, 70);
|
||||||
}
|
}
|
||||||
|
@ -60,10 +60,13 @@ QVariant ContentManagerModel::data(const QModelIndex& index, int role) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
const auto col = index.column();
|
const auto col = index.column();
|
||||||
const bool isThumbnailRequest = col == 0 && role == Qt::DecorationRole;
|
const bool isThumbnailRequest =
|
||||||
const bool otherDataRequest = col != 0 && (role == Qt::DisplayRole || role == Qt::UserRole+1 );
|
!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();
|
return QVariant();
|
||||||
|
|
||||||
const auto item = static_cast<Node*>(index.internalPointer());
|
const auto item = static_cast<Node*>(index.internalPointer());
|
||||||
@ -86,7 +89,7 @@ QVariant ContentManagerModel::data(const QModelIndex& index, int role) const
|
|||||||
Qt::ItemFlags ContentManagerModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags ContentManagerModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index);
|
Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index);
|
||||||
if (index.isValid() && index.parent().isValid()) {
|
if (isDescriptionIndex(index)) {
|
||||||
return defaultFlags & ~Qt::ItemIsDropEnabled & ~Qt::ItemIsDragEnabled & ~Qt::ItemIsSelectable & ~Qt::ItemIsEditable & ~Qt::ItemIsUserCheckable;
|
return defaultFlags & ~Qt::ItemIsDropEnabled & ~Qt::ItemIsDragEnabled & ~Qt::ItemIsSelectable & ~Qt::ItemIsEditable & ~Qt::ItemIsUserCheckable;
|
||||||
}
|
}
|
||||||
return defaultFlags;
|
return defaultFlags;
|
||||||
|
@ -97,4 +97,9 @@ private: // data
|
|||||||
QMap<QString, QByteArray> m_iconMap;
|
QMap<QString, QByteArray> m_iconMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline bool isDescriptionIndex(const QModelIndex& index)
|
||||||
|
{
|
||||||
|
return index.parent().isValid();
|
||||||
|
}
|
||||||
|
|
||||||
#endif // CONTENTMANAGERMODEL_H
|
#endif // CONTENTMANAGERMODEL_H
|
||||||
|
@ -19,17 +19,9 @@ ContentManagerView::ContentManagerView(QWidget *parent)
|
|||||||
loader = new KiwixLoader(mp_ui->loading);
|
loader = new KiwixLoader(mp_ui->loading);
|
||||||
mp_ui->stackedWidget->setCurrentIndex(0);
|
mp_ui->stackedWidget->setCurrentIndex(0);
|
||||||
|
|
||||||
connect(mp_ui->m_view, &QTreeView::clicked, [=](QModelIndex index) {
|
connect(mp_ui->m_view, &QTreeView::clicked, this, &ContentManagerView::onClicked);
|
||||||
if (index.column() == (mp_ui->m_view->model()->columnCount() - 1))
|
connect(mp_ui->m_view, &QTreeView::expanded, this, &ContentManagerView::onExpanded);
|
||||||
return;
|
connect(this, &ContentManagerView::sizeHintChanged, managerDelegate, &QStyledItemDelegate::sizeHintChanged);
|
||||||
|
|
||||||
auto zeroColIndex = index.siblingAtColumn(0);
|
|
||||||
if (mp_ui->m_view->isExpanded(zeroColIndex)) {
|
|
||||||
mp_ui->m_view->collapse(zeroColIndex);
|
|
||||||
} else {
|
|
||||||
mp_ui->m_view->expand(zeroColIndex);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentManagerView::~ContentManagerView()
|
ContentManagerView::~ContentManagerView()
|
||||||
@ -46,3 +38,40 @@ void ContentManagerView::showLoader(bool show)
|
|||||||
loader->stopAnimation();
|
loader->stopAnimation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ContentManagerView::onClicked(QModelIndex index)
|
||||||
|
{
|
||||||
|
if (index.column() == (mp_ui->m_view->model()->columnCount() - 1))
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto zeroColIndex = index.siblingAtColumn(0);
|
||||||
|
if (mp_ui->m_view->isExpanded(zeroColIndex)) {
|
||||||
|
mp_ui->m_view->collapse(zeroColIndex);
|
||||||
|
} else {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Notify delegate to update size hint of the visible description rows.
|
||||||
|
*/
|
||||||
|
void ContentManagerView::updateSizeHint()
|
||||||
|
{
|
||||||
|
auto view = this->getView();
|
||||||
|
if (!view->isVisible())
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto visibleIndex = view->indexAt(view->rect().topLeft());
|
||||||
|
while (visibleIndex.isValid())
|
||||||
|
{
|
||||||
|
if (isDescriptionIndex(visibleIndex))
|
||||||
|
emit sizeHintChanged(visibleIndex);
|
||||||
|
visibleIndex = view->indexBelow(visibleIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -20,6 +20,12 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void showLoader(bool show);
|
void showLoader(bool show);
|
||||||
|
void onClicked(QModelIndex index);
|
||||||
|
void onExpanded(QModelIndex index);
|
||||||
|
void updateSizeHint();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sizeHintChanged(const QModelIndex& index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::contentmanagerview *mp_ui;
|
Ui::contentmanagerview *mp_ui;
|
||||||
|
@ -36,7 +36,7 @@ int DescriptionNode::columnCount() const
|
|||||||
|
|
||||||
QVariant DescriptionNode::data(int column)
|
QVariant DescriptionNode::data(int column)
|
||||||
{
|
{
|
||||||
if (column == 1)
|
if (column == 0)
|
||||||
return m_desc;
|
return m_desc;
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
@ -125,6 +125,12 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
|||||||
QMainWindow::closeEvent(event);
|
QMainWindow::closeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
QMainWindow::resizeEvent(event);
|
||||||
|
KiwixApp::instance()->getContentManager()->getView()->updateSizeHint();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::readingListToggled(bool state)
|
void MainWindow::readingListToggled(bool state)
|
||||||
{
|
{
|
||||||
if (state) {
|
if (state) {
|
||||||
|
@ -29,6 +29,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject* object, QEvent* event) override;
|
bool eventFilter(QObject* object, QEvent* event) override;
|
||||||
void closeEvent(QCloseEvent *event) override;
|
void closeEvent(QCloseEvent *event) override;
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void toggleFullScreen();
|
void toggleFullScreen();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user