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

preferencesAboutTextFull
Clément Fauconnier 3 years ago
parent bfcaace42e
commit ac43610fb6
  1. 4
      src/board/UBBoardController.cpp
  2. 5
      src/document/UBDocumentContainer.cpp
  3. 1
      src/document/UBDocumentContainer.h
  4. 7
      src/document/UBDocumentController.cpp
  5. 18
      src/gui/UBDocumentNavigator.cpp
  6. 3
      src/gui/UBDocumentThumbnailWidget.cpp
  7. 2
      src/gui/UBThumbnailWidget.cpp

@ -584,9 +584,7 @@ void UBBoardController::duplicateScene(int nIndex)
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
persistCurrentScene(false,true); persistCurrentScene(false,true);
QList<int> scIndexes; duplicatePage(nIndex);
scIndexes << nIndex;
duplicatePages(scIndexes);
insertThumbPage(nIndex); insertThumbPage(nIndex);
if (UBApplication::documentController->selectedDocument() == selectedDocument()) if (UBApplication::documentController->selectedDocument() == selectedDocument())
{ {

@ -65,6 +65,11 @@ void UBDocumentContainer::duplicatePages(QList<int>& pageIndexes)
} }
} }
void UBDocumentContainer::duplicatePage(int index)
{
UBPersistenceManager::persistenceManager()->duplicateDocumentScene(mCurrentDocument, index);
}
void UBDocumentContainer::moveThumbPage(int source, int target) void UBDocumentContainer::moveThumbPage(int source, int target)
{ {
mDocumentThumbs.move(source, target); mDocumentThumbs.move(source, target);

@ -61,6 +61,7 @@ class UBDocumentContainer : public QObject
static int sceneIndexFromPage(int sceneIndex); static int sceneIndexFromPage(int sceneIndex);
void duplicatePages(QList<int>& pageIndexes); void duplicatePages(QList<int>& pageIndexes);
void duplicatePage(int index);
void deletePages(QList<int>& pageIndexes); void deletePages(QList<int>& pageIndexes);

@ -3618,7 +3618,11 @@ void UBDocumentController::deletePages(QList<QGraphicsItem *> itemsToDelete)
} }
} }
UBDocumentContainer::deletePages(sceneIndexes); 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())); proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(proxy); UBMetadataDcSubsetAdaptor::persist(proxy);
@ -3635,7 +3639,6 @@ void UBDocumentController::deletePages(QList<QGraphicsItem *> itemsToDelete)
mDocumentUI->thumbnailWidget->selectItemAt(minIndex); mDocumentUI->thumbnailWidget->selectItemAt(minIndex);
mBoardController->setActiveDocumentScene(minIndex); mBoardController->setActiveDocumentScene(minIndex);
mBoardController->reloadThumbnails();
} }
} }

@ -240,8 +240,6 @@ void UBDocumentNavigator::updateThumbnail(int index)
oldItem = NULL; oldItem = NULL;
} }
ensureVisible(0, 0, 10, 10);
refreshScene(); refreshScene();
} }
@ -259,6 +257,7 @@ void UBDocumentNavigator::removeThumbnail(int index)
//update thumbs page number accordingly //update thumbs page number accordingly
for (int i=0; i < mThumbsWithLabels.length(); i++) 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)); mThumbsWithLabels.at(i).getCaption()->setText(tr("Page %0").arg(i+1));
} }
@ -372,11 +371,11 @@ void UBDocumentNavigator::resizeEvent(QResizeEvent *event)
// Update the thumbnails width // Update the thumbnails width
mThumbnailWidth = (width() > mThumbnailMinWidth) ? width() - 2*border() : mThumbnailMinWidth; mThumbnailWidth = (width() > mThumbnailMinWidth) ? width() - 2*border() : mThumbnailMinWidth;
if(mSelectedThumbnail)
ensureVisible(mSelectedThumbnail);
// Refresh the scene // Refresh the scene
refreshScene(); refreshScene();
if(mSelectedThumbnail)
ensureVisible(mSelectedThumbnail);
} }
/** /**
@ -617,8 +616,6 @@ void UBDocumentNavigator::dragMoveEvent(QDragMoveEvent *event)
int thumbnailHeight = mThumbnailWidth / UBSettings::minScreenRatio; int thumbnailHeight = mThumbnailWidth / UBSettings::minScreenRatio;
QRectF thumbnailArea(0, scenePos.y() - thumbnailHeight/2, mThumbnailWidth, thumbnailHeight); QRectF thumbnailArea(0, scenePos.y() - thumbnailHeight/2, mThumbnailWidth, thumbnailHeight);
ensureVisible(thumbnailArea);
UBSceneThumbnailNavigPixmap* item = dynamic_cast<UBSceneThumbnailNavigPixmap*>(itemAt(position.toPoint())); UBSceneThumbnailNavigPixmap* item = dynamic_cast<UBSceneThumbnailNavigPixmap*>(itemAt(position.toPoint()));
if (item) if (item)
{ {
@ -642,7 +639,7 @@ void UBDocumentNavigator::dragMoveEvent(QDragMoveEvent *event)
{ {
y = item->pos().y() - UBSettings::thumbnailSpacing / 2; y = item->pos().y() - UBSettings::thumbnailSpacing / 2;
if (mDropBar->y() != y) 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 else
@ -651,11 +648,14 @@ void UBDocumentNavigator::dragMoveEvent(QDragMoveEvent *event)
{ {
y = item->pos().y() + item->boundingRect().height() * scale + UBSettings::thumbnailSpacing / 2; y = item->pos().y() + item->boundingRect().height() * scale + UBSettings::thumbnailSpacing / 2;
if (mDropBar->y() != y) 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(); event->acceptProposedAction();
} }

@ -318,6 +318,9 @@ void UBDocumentThumbnailWidget::removeThumbnail(int sceneIndex)
UBSceneThumbnailPixmap *thumbnail = dynamic_cast<UBSceneThumbnailPixmap*>(thumbnailItem); UBSceneThumbnailPixmap *thumbnail = dynamic_cast<UBSceneThumbnailPixmap*>(thumbnailItem);
if (thumbnail) if (thumbnail)
{ {
if (thumbnail->isSelected())
scene()->removeItem(thumbnail->selectionItem());
mGraphicItems.removeAt(sceneIndex); mGraphicItems.removeAt(sceneIndex);
if (thumbnailItem) if (thumbnailItem)
scene()->removeItem(thumbnailItem); scene()->removeItem(thumbnailItem);

@ -202,6 +202,8 @@ void UBThumbnailWidget::refreshScene()
if (mLabelsItems.size() > i) if (mLabelsItems.size() > i)
{ {
mLabelsItems.at(i)->setWidth(mThumbnailWidth);
mLabelsItems.at(i)->setPageNumber(i+1);
QFontMetrics fm(mLabelsItems.at(i)->font(), this); QFontMetrics fm(mLabelsItems.at(i)->font(), this);
QString elidedText = fm.elidedText(mLabelsItems.at(i)->toPlainText(), Qt::ElideRight, mThumbnailWidth); QString elidedText = fm.elidedText(mLabelsItems.at(i)->toPlainText(), Qt::ElideRight, mThumbnailWidth);

Loading…
Cancel
Save