From ac43610fb6c6e386b6ab281b867ea6934f1bd260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= Date: Thu, 18 Nov 2021 10:29:27 +0100 Subject: [PATCH] fixed other issues regarding thumbnails. A lot of issues were hidden by the fact that we were regenerating everything, almost everytime an action would imply a change in thumbnails --- src/board/UBBoardController.cpp | 4 +--- src/document/UBDocumentContainer.cpp | 5 +++++ src/document/UBDocumentContainer.h | 1 + src/document/UBDocumentController.cpp | 7 +++++-- src/gui/UBDocumentNavigator.cpp | 18 +++++++++--------- src/gui/UBDocumentThumbnailWidget.cpp | 3 +++ src/gui/UBThumbnailWidget.cpp | 2 ++ 7 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 6ab9bd9a..2401d30a 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -584,9 +584,7 @@ void UBBoardController::duplicateScene(int nIndex) QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); persistCurrentScene(false,true); - QList scIndexes; - scIndexes << nIndex; - duplicatePages(scIndexes); + duplicatePage(nIndex); insertThumbPage(nIndex); if (UBApplication::documentController->selectedDocument() == selectedDocument()) { diff --git a/src/document/UBDocumentContainer.cpp b/src/document/UBDocumentContainer.cpp index c1164ce3..86e857a7 100644 --- a/src/document/UBDocumentContainer.cpp +++ b/src/document/UBDocumentContainer.cpp @@ -65,6 +65,11 @@ void UBDocumentContainer::duplicatePages(QList& pageIndexes) } } +void UBDocumentContainer::duplicatePage(int index) +{ + UBPersistenceManager::persistenceManager()->duplicateDocumentScene(mCurrentDocument, index); +} + void UBDocumentContainer::moveThumbPage(int source, int target) { mDocumentThumbs.move(source, target); diff --git a/src/document/UBDocumentContainer.h b/src/document/UBDocumentContainer.h index aa220895..e02556b5 100644 --- a/src/document/UBDocumentContainer.h +++ b/src/document/UBDocumentContainer.h @@ -61,6 +61,7 @@ class UBDocumentContainer : public QObject static int sceneIndexFromPage(int sceneIndex); void duplicatePages(QList& pageIndexes); + void duplicatePage(int index); void deletePages(QList& pageIndexes); diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index 4038656c..1d2b08d3 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -3618,7 +3618,11 @@ void UBDocumentController::deletePages(QList itemsToDelete) } } UBDocumentContainer::deletePages(sceneIndexes); - emit mBoardController->documentThumbnailsUpdated(this); + if (mBoardController->selectedDocument() == selectedDocument()) + { + for (auto index : sceneIndexes) + mBoardController->deleteThumbPage(index); + } proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); UBMetadataDcSubsetAdaptor::persist(proxy); @@ -3635,7 +3639,6 @@ void UBDocumentController::deletePages(QList itemsToDelete) mDocumentUI->thumbnailWidget->selectItemAt(minIndex); mBoardController->setActiveDocumentScene(minIndex); - mBoardController->reloadThumbnails(); } } diff --git a/src/gui/UBDocumentNavigator.cpp b/src/gui/UBDocumentNavigator.cpp index 60ecc1f4..345afcdd 100644 --- a/src/gui/UBDocumentNavigator.cpp +++ b/src/gui/UBDocumentNavigator.cpp @@ -240,8 +240,6 @@ void UBDocumentNavigator::updateThumbnail(int index) oldItem = NULL; } - ensureVisible(0, 0, 10, 10); - refreshScene(); } @@ -259,6 +257,7 @@ void UBDocumentNavigator::removeThumbnail(int index) //update thumbs page number accordingly for (int i=0; i < mThumbsWithLabels.length(); i++) { + mThumbsWithLabels.at(i).getThumbnail()->setSceneIndex(i); mThumbsWithLabels.at(i).getCaption()->setText(tr("Page %0").arg(i+1)); } @@ -372,11 +371,11 @@ void UBDocumentNavigator::resizeEvent(QResizeEvent *event) // Update the thumbnails width mThumbnailWidth = (width() > mThumbnailMinWidth) ? width() - 2*border() : mThumbnailMinWidth; - if(mSelectedThumbnail) - ensureVisible(mSelectedThumbnail); - // Refresh the scene refreshScene(); + + if(mSelectedThumbnail) + ensureVisible(mSelectedThumbnail); } /** @@ -617,8 +616,6 @@ void UBDocumentNavigator::dragMoveEvent(QDragMoveEvent *event) int thumbnailHeight = mThumbnailWidth / UBSettings::minScreenRatio; QRectF thumbnailArea(0, scenePos.y() - thumbnailHeight/2, mThumbnailWidth, thumbnailHeight); - ensureVisible(thumbnailArea); - UBSceneThumbnailNavigPixmap* item = dynamic_cast(itemAt(position.toPoint())); if (item) { @@ -642,7 +639,7 @@ void UBDocumentNavigator::dragMoveEvent(QDragMoveEvent *event) { y = item->pos().y() - UBSettings::thumbnailSpacing / 2; if (mDropBar->y() != y) - mDropBar->setRect(QRectF(item->pos().x(), y, mThumbnailWidth-verticalScrollBar()->width(), 3)); + mDropBar->setRect(QRectF(item->pos().x(), y, (item->boundingRect().width()-verticalScrollBar()->width())*scale, 3)); } } else @@ -651,11 +648,14 @@ void UBDocumentNavigator::dragMoveEvent(QDragMoveEvent *event) { y = item->pos().y() + item->boundingRect().height() * scale + UBSettings::thumbnailSpacing / 2; if (mDropBar->y() != y) - mDropBar->setRect(QRectF(item->pos().x(), y, mThumbnailWidth-verticalScrollBar()->width(), 3)); + mDropBar->setRect(QRectF(item->pos().x(), y, (item->boundingRect().width()-verticalScrollBar()->width())*scale, 3)); } } } } + + ensureVisible(thumbnailArea); + event->acceptProposedAction(); } diff --git a/src/gui/UBDocumentThumbnailWidget.cpp b/src/gui/UBDocumentThumbnailWidget.cpp index 45dbc52d..a948a9b1 100644 --- a/src/gui/UBDocumentThumbnailWidget.cpp +++ b/src/gui/UBDocumentThumbnailWidget.cpp @@ -318,6 +318,9 @@ void UBDocumentThumbnailWidget::removeThumbnail(int sceneIndex) UBSceneThumbnailPixmap *thumbnail = dynamic_cast(thumbnailItem); if (thumbnail) { + if (thumbnail->isSelected()) + scene()->removeItem(thumbnail->selectionItem()); + mGraphicItems.removeAt(sceneIndex); if (thumbnailItem) scene()->removeItem(thumbnailItem); diff --git a/src/gui/UBThumbnailWidget.cpp b/src/gui/UBThumbnailWidget.cpp index ba3694d2..9a866847 100644 --- a/src/gui/UBThumbnailWidget.cpp +++ b/src/gui/UBThumbnailWidget.cpp @@ -202,6 +202,8 @@ void UBThumbnailWidget::refreshScene() if (mLabelsItems.size() > i) { + mLabelsItems.at(i)->setWidth(mThumbnailWidth); + mLabelsItems.at(i)->setPageNumber(i+1); QFontMetrics fm(mLabelsItems.at(i)->font(), this); QString elidedText = fm.elidedText(mLabelsItems.at(i)->toPlainText(), Qt::ElideRight, mThumbnailWidth);