fixed a lot of issues regarding thumbnails

preferencesAboutTextFull
Clément Fauconnier 3 years ago
parent 09fc069edd
commit bfcaace42e
  1. 29
      src/board/UBBoardController.cpp
  2. 11
      src/core/UBApplicationController.cpp
  3. 2
      src/core/UBPersistenceManager.cpp
  4. 58
      src/document/UBDocumentContainer.cpp
  5. 27
      src/document/UBDocumentContainer.h
  6. 49
      src/document/UBDocumentController.cpp
  7. 5
      src/document/UBDocumentController.h
  8. 143
      src/gui/UBDocumentNavigator.cpp
  9. 6
      src/gui/UBDocumentNavigator.h
  10. 43
      src/gui/UBDocumentThumbnailWidget.cpp
  11. 3
      src/gui/UBDocumentThumbnailWidget.h
  12. 12
      src/gui/UBThumbnailWidget.cpp
  13. 20
      src/gui/UBThumbnailWidget.h

@ -521,6 +521,10 @@ void UBBoardController::addScene()
persistCurrentScene(false,true); persistCurrentScene(false,true);
UBDocumentContainer::addPage(mActiveSceneIndex + 1); UBDocumentContainer::addPage(mActiveSceneIndex + 1);
if (UBApplication::documentController->selectedDocument() == selectedDocument())
{
UBApplication::documentController->insertThumbPage(mActiveSceneIndex+1);
}
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
@ -584,7 +588,11 @@ void UBBoardController::duplicateScene(int nIndex)
scIndexes << nIndex; scIndexes << nIndex;
duplicatePages(scIndexes); duplicatePages(scIndexes);
insertThumbPage(nIndex); insertThumbPage(nIndex);
emit documentThumbnailsUpdated(this); if (UBApplication::documentController->selectedDocument() == selectedDocument())
{
UBApplication::documentController->insertThumbPage(nIndex);
}
//emit documentThumbnailsUpdated(this);
emit addThumbnailRequired(this, nIndex + 1); emit addThumbnailRequired(this, nIndex + 1);
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
@ -779,6 +787,10 @@ void UBBoardController::deleteScene(int nIndex)
QList<int> scIndexes; QList<int> scIndexes;
scIndexes << nIndex; scIndexes << nIndex;
deletePages(scIndexes); deletePages(scIndexes);
if (UBApplication::documentController->selectedDocument() == selectedDocument())
{
UBApplication::documentController->deleteThumbPage(nIndex);
}
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(selectedDocument()); UBMetadataDcSubsetAdaptor::persist(selectedDocument());
@ -1618,7 +1630,12 @@ void UBBoardController::moveSceneToIndex(int source, int target)
{ {
persistCurrentScene(false,true); persistCurrentScene(false,true);
UBDocumentContainer::movePageToIndex(source, target); UBPersistenceManager::persistenceManager()->moveSceneToIndex(selectedDocument(), source, target);
UBDocumentContainer::moveThumbPage(source, target);
if (UBApplication::documentController->selectedDocument() == selectedDocument())
{
UBApplication::documentController->moveThumbPage(source, target);
}
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(selectedDocument()); UBPersistenceManager::persistenceManager()->persistDocumentMetadata(selectedDocument());
@ -1877,7 +1894,7 @@ void UBBoardController::documentSceneChanged(UBDocumentProxy* pDocumentProxy, in
if(selectedDocument() == pDocumentProxy) if(selectedDocument() == pDocumentProxy)
{ {
setActiveDocumentScene(mActiveSceneIndex); setActiveDocumentScene(mActiveSceneIndex);
updatePage(pIndex); updateThumbPage(pIndex);
} }
} }
@ -2021,7 +2038,11 @@ void UBBoardController::persistCurrentScene(bool isAnAutomaticBackup, bool force
&& (mActiveScene->isModified())) && (mActiveScene->isModified()))
{ {
UBPersistenceManager::persistenceManager()->persistDocumentScene(selectedDocument(), mActiveScene, mActiveSceneIndex, isAnAutomaticBackup); UBPersistenceManager::persistenceManager()->persistDocumentScene(selectedDocument(), mActiveScene, mActiveSceneIndex, isAnAutomaticBackup);
updatePage(mActiveSceneIndex); updateThumbPage(mActiveSceneIndex);
if (UBApplication::documentController->selectedDocument() == selectedDocument())
{
UBApplication::documentController->updateThumbPage(mActiveSceneIndex);
}
} }
} }

@ -351,11 +351,11 @@ void UBApplicationController::showBoard()
if (mMainMode == Document) if (mMainMode == Document)
{ {
int selectedSceneIndex = UBApplication::documentController->getSelectedItemIndex(); // int selectedSceneIndex = UBApplication::documentController->getSelectedItemIndex();
if (selectedSceneIndex != -1) // if (selectedSceneIndex != -1)
{ // {
UBApplication::boardController->setActiveDocumentScene(UBApplication::documentController->selectedDocument(), selectedSceneIndex); // UBApplication::boardController->setActiveDocumentScene(UBApplication::documentController->selectedDocument(), selectedSceneIndex);
} // }
} }
mMainMode = Board; mMainMode = Board;
@ -435,6 +435,7 @@ void UBApplicationController::showDocument()
{ {
if (UBApplication::boardController->activeScene()->isModified()) if (UBApplication::boardController->activeScene()->isModified())
UBApplication::boardController->persistCurrentScene(); UBApplication::boardController->persistCurrentScene();
UBApplication::boardController->hide(); UBApplication::boardController->hide();
} }

@ -827,7 +827,6 @@ UBGraphicsScene* UBPersistenceManager::createDocumentSceneAt(UBDocumentProxy* pr
for(int i = count - 1; i >= index; i--) for(int i = count - 1; i >= index; i--)
{ {
UBApplication::showMessage(tr("renaming pages (%1/%2)").arg(i).arg(count));
renamePage(proxy, i , i + 1); renamePage(proxy, i , i + 1);
} }
@ -977,6 +976,7 @@ UBDocumentProxy* UBPersistenceManager::persistDocumentMetadata(UBDocumentProxy*
void UBPersistenceManager::renamePage(UBDocumentProxy* pDocumentProxy, const int sourceIndex, const int targetIndex) void UBPersistenceManager::renamePage(UBDocumentProxy* pDocumentProxy, const int sourceIndex, const int targetIndex)
{ {
UBApplication::showMessage(tr("renaming pages (%1/%2)").arg(sourceIndex).arg(pDocumentProxy->pageCount()));
QFile svg(pDocumentProxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", sourceIndex)); QFile svg(pDocumentProxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", sourceIndex));
svg.rename(pDocumentProxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", targetIndex)); svg.rename(pDocumentProxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", targetIndex));

@ -65,16 +65,15 @@ void UBDocumentContainer::duplicatePages(QList<int>& pageIndexes)
} }
} }
bool UBDocumentContainer::movePageToIndex(int source, int target) void UBDocumentContainer::moveThumbPage(int source, int target)
{ {
//on document view mDocumentThumbs.move(source, target);
UBPersistenceManager::persistenceManager()->moveSceneToIndex(mCurrentDocument, source, target);
deleteThumbPage(source); //on board thumbnails view (UBDocumentNavigator)
insertThumbPage(target); emit documentPageMoved(source, target);
emit documentThumbnailsUpdated(this);
//on board thumbnails view //on board thumbnails view (UBoardThumbnailsView)
emit moveThumbnailRequired(source, target); emit moveThumbnailRequired(source, target);
return true;
} }
void UBDocumentContainer::deletePages(QList<int>& pageIndexes) void UBDocumentContainer::deletePages(QList<int>& pageIndexes)
@ -84,26 +83,20 @@ void UBDocumentContainer::deletePages(QList<int>& pageIndexes)
foreach(int index, pageIndexes) foreach(int index, pageIndexes)
{ {
deleteThumbPage(index - offset); deleteThumbPage(index - offset);
emit removeThumbnailRequired(index - offset);
offset++; offset++;
} }
emit documentThumbnailsUpdated(this);
} }
void UBDocumentContainer::addPage(int index) void UBDocumentContainer::addPage(int index)
{ {
UBPersistenceManager::persistenceManager()->createDocumentSceneAt(mCurrentDocument, index); UBPersistenceManager::persistenceManager()->createDocumentSceneAt(mCurrentDocument, index);
insertThumbPage(index); insertThumbPage(index);
emit documentThumbnailsUpdated(this);
emit addThumbnailRequired(this, index);
} }
void UBDocumentContainer::addPixmapAt(std::shared_ptr<QPixmap> pix, int index) void UBDocumentContainer::addPixmapAt(std::shared_ptr<QPixmap> pix, int index)
{ {
documentThumbs().insert(index, pix); mDocumentThumbs.insert(index, pix);
} }
@ -120,14 +113,15 @@ void UBDocumentContainer::initThumbPage()
insertThumbPage(i); insertThumbPage(i);
} }
void UBDocumentContainer::updatePage(int index)
{
updateThumbPage(index);
}
void UBDocumentContainer::deleteThumbPage(int index) void UBDocumentContainer::deleteThumbPage(int index)
{ {
mDocumentThumbs.removeAt(index); mDocumentThumbs.removeAt(index);
//on board thumbnails view (UBDocumentNavigator)
emit documentPageRemoved(index);
//on board thumbnails view (UBoardThumbnailsView)
emit removeThumbnailRequired(index);
} }
void UBDocumentContainer::updateThumbPage(int index) void UBDocumentContainer::updateThumbPage(int index)
@ -136,30 +130,26 @@ void UBDocumentContainer::updateThumbPage(int index)
{ {
QPixmap pixmap = UBThumbnailAdaptor::get(mCurrentDocument, index); QPixmap pixmap = UBThumbnailAdaptor::get(mCurrentDocument, index);
mDocumentThumbs[index] = std::make_shared<QPixmap>(pixmap); mDocumentThumbs[index] = std::make_shared<QPixmap>(pixmap);
emit documentPageUpdated(index); //refresh specific thumbnail in board
} emit documentPageUpdated(index);
else
{
qDebug() << "error [updateThumbPage] : index > mDocumentThumbs' size.";
} }
} }
void UBDocumentContainer::insertThumbPage(int index) void UBDocumentContainer::insertThumbPage(int index)
{ {
QPixmap newPixmap = UBThumbnailAdaptor::get(mCurrentDocument, index); QPixmap newPixmap = UBThumbnailAdaptor::get(mCurrentDocument, index);
if (index < documentThumbs().size()) mDocumentThumbs.insert(index, std::make_shared<QPixmap>(newPixmap));
{
*documentThumbs().at(index) = newPixmap; emit documentPageInserted(index);
} emit addThumbnailRequired(this, index);
else
{
documentThumbs().insert(index, std::make_shared<QPixmap>(newPixmap));
}
} }
void UBDocumentContainer::insertExistingThumbPage(int index, std::shared_ptr<QPixmap> thumbnailPixmap) void UBDocumentContainer::insertExistingThumbPage(int index, std::shared_ptr<QPixmap> thumbnailPixmap)
{ {
documentThumbs().insert(index, thumbnailPixmap); mDocumentThumbs.insert(index, thumbnailPixmap);
emit documentPageInserted(index);
emit addThumbnailRequired(this, index);
} }
void UBDocumentContainer::reloadThumbnails() void UBDocumentContainer::reloadThumbnails()

@ -61,39 +61,40 @@ class UBDocumentContainer : public QObject
static int sceneIndexFromPage(int sceneIndex); static int sceneIndexFromPage(int sceneIndex);
void duplicatePages(QList<int>& pageIndexes); void duplicatePages(QList<int>& pageIndexes);
bool movePageToIndex(int source, int target);
void deletePages(QList<int>& pageIndexes); void deletePages(QList<int>& pageIndexes);
void clearThumbPage();
void initThumbPage();
void addPage(int index); void addPage(int index);
void addPixmapAt(std::shared_ptr<QPixmap> pix, int index); void addPixmapAt(std::shared_ptr<QPixmap> pix, int index);
void updatePage(int index);
void addEmptyThumbPage();
virtual void reloadThumbnails(); virtual void reloadThumbnails();
void insertThumbPage(int index); void clearThumbPage();
void initThumbPage();
void insertExistingThumbPage(int index, std::shared_ptr<QPixmap> thumbnailPixmap); void insertExistingThumbPage(int index, std::shared_ptr<QPixmap> thumbnailPixmap);
void insertThumbPage(int index);
void addEmptyThumbPage();
void deleteThumbPage(int index);
void updateThumbPage(int index);
void moveThumbPage(int source, int target);
private: private:
UBDocumentProxy* mCurrentDocument; UBDocumentProxy* mCurrentDocument;
QList<std::shared_ptr<QPixmap>> mDocumentThumbs; QList<std::shared_ptr<QPixmap>> mDocumentThumbs;
protected:
void deleteThumbPage(int index);
void updateThumbPage(int index);
signals: signals:
void documentSet(UBDocumentProxy* document); void documentSet(UBDocumentProxy* document);
void documentPageInserted(int index);
void documentPageUpdated(int index); void documentPageUpdated(int index);
void documentPageRemoved(int index);
void documentPageMoved(int from, int to);
void documentThumbnailsUpdated(UBDocumentContainer* source);
void initThumbnailsRequired(UBDocumentContainer* source); void initThumbnailsRequired(UBDocumentContainer* source);
void addThumbnailRequired(UBDocumentContainer* source, int index); void addThumbnailRequired(UBDocumentContainer* source, int index);
void removeThumbnailRequired(int index); void removeThumbnailRequired(int index);
void moveThumbnailRequired(int from, int to); void moveThumbnailRequired(int from, int to);
void updateThumbnailsRequired(); void updateThumbnailsRequired();
void documentThumbnailsUpdated(UBDocumentContainer* source);
}; };

@ -1555,9 +1555,14 @@ void UBDocumentTreeView::dropEvent(QDropEvent *event)
Q_ASSERT(QFileInfo(thumbTmp).exists()); Q_ASSERT(QFileInfo(thumbTmp).exists());
Q_ASSERT(QFileInfo(thumbTo).exists()); Q_ASSERT(QFileInfo(thumbTo).exists());
auto pix = std::make_shared<QPixmap>(thumbTmp); auto pix = std::make_shared<QPixmap>(thumbTmp);
UBDocumentController *ctrl = UBApplication::documentController; UBDocumentController *ctrl = UBApplication::documentController;
ctrl->addPixmapAt(pix, toIndex); ctrl->addPixmapAt(pix, toIndex);
if (UBApplication::boardController->selectedDocument() == targetDocProxy)
{
UBApplication::boardController->insertThumbPage(toIndex);
}
} }
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
@ -1800,6 +1805,10 @@ UBDocumentController::UBDocumentController(UBMainWindow* mainWindow)
setupToolbar(); setupToolbar();
connect(this, SIGNAL(exportDone()), mMainWindow, SLOT(onExportDone())); connect(this, SIGNAL(exportDone()), mMainWindow, SLOT(onExportDone()));
connect(this, SIGNAL(documentThumbnailsUpdated(UBDocumentContainer*)), this, SLOT(refreshDocumentThumbnailsView(UBDocumentContainer*))); connect(this, SIGNAL(documentThumbnailsUpdated(UBDocumentContainer*)), this, SLOT(refreshDocumentThumbnailsView(UBDocumentContainer*)));
connect(this, SIGNAL(documentPageInserted(int)), this, SLOT(insertThumbnail(int)));
connect(this, SIGNAL(documentPageUpdated(int)), this, SLOT(updateThumbnail(int)));
connect(this, SIGNAL(documentPageRemoved(int)), this, SLOT(removeThumbnail(int)));
connect(this, SIGNAL(documentPageMoved(int, int)), this, SLOT(moveThumbnail(int, int)));
connect(this, SIGNAL(reorderDocumentsRequested()), this, SLOT(reorderDocuments())); connect(this, SIGNAL(reorderDocumentsRequested()), this, SLOT(reorderDocuments()));
} }
@ -3048,23 +3057,45 @@ bool UBDocumentController::addFileToDocument(UBDocumentProxy* document)
void UBDocumentController::moveSceneToIndex(UBDocumentProxy* proxy, int source, int target) void UBDocumentController::moveSceneToIndex(UBDocumentProxy* proxy, int source, int target)
{ {
if (UBDocumentContainer::movePageToIndex(source, target)) UBPersistenceManager::persistenceManager()->moveSceneToIndex(proxy, source, target);
{
proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(proxy);
mDocumentUI->thumbnailWidget->hightlightItem(target); proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(proxy);
mBoardController->setActiveDocumentScene(target); UBDocumentContainer::moveThumbPage(source, target);
mBoardController->reloadThumbnails(); if (UBApplication::boardController->selectedDocument() == selectedDocument())
{
UBApplication::boardController->moveThumbPage(source, target);
} }
mDocumentUI->thumbnailWidget->hightlightItem(target);
//mBoardController->setActiveDocumentScene(target);
}
void UBDocumentController::insertThumbnail(int index, const QPixmap& pix)
{
QGraphicsPixmapItem *newThumbnail = new UBSceneThumbnailPixmap(pix, selectedDocument(), index); // deleted by the tree widget
mDocumentUI->thumbnailWidget->insertThumbnail(index, newThumbnail);
}
void UBDocumentController::updateThumbnail(int index)
{
auto pix = UBApplication::boardController->pageAt(index);
mDocumentUI->thumbnailWidget->updateThumbnailPixmap(index, *pix);
} }
void UBDocumentController::updateThumbnailPixmap(int index, const QPixmap& newThumbnail)
void UBDocumentController::removeThumbnail(int index)
{ {
mDocumentUI->thumbnailWidget->updateThumbnailPixmap(index, newThumbnail); mDocumentUI->thumbnailWidget->removeThumbnail(index);
} }
void UBDocumentController::moveThumbnail(int from, int to)
{
mDocumentUI->thumbnailWidget->moveThumbnail(from, to);
}
void UBDocumentController::thumbnailViewResized() void UBDocumentController::thumbnailViewResized()
{ {

@ -501,7 +501,10 @@ class UBDocumentController : public UBDocumentContainer
void collapseAll(); void collapseAll();
void expandAll(); void expandAll();
void updateThumbnailPixmap(int index, const QPixmap& newThumbnail); void updateThumbnail(int index);
void removeThumbnail(int index);
void moveThumbnail(int from, int to);
void insertThumbnail(int index, const QPixmap& pix);
protected: protected:
virtual void setupViews(); virtual void setupViews();

@ -83,7 +83,10 @@ UBDocumentNavigator::UBDocumentNavigator(QWidget *parent, const char *name):QGra
setFrameShadow(QFrame::Plain); setFrameShadow(QFrame::Plain);
connect(UBApplication::boardController, SIGNAL(documentThumbnailsUpdated(UBDocumentContainer*)), this, SLOT(generateThumbnails(UBDocumentContainer*))); connect(UBApplication::boardController, SIGNAL(documentThumbnailsUpdated(UBDocumentContainer*)), this, SLOT(generateThumbnails(UBDocumentContainer*)));
connect(UBApplication::boardController, SIGNAL(documentPageUpdated(int)), this, SLOT(updateSpecificThumbnail(int))); connect(UBApplication::boardController, SIGNAL(documentPageInserted(int)), this, SLOT(insertThumbnail(int)));
connect(UBApplication::boardController, SIGNAL(documentPageUpdated(int)), this, SLOT(updateThumbnail(int)));
connect(UBApplication::boardController, SIGNAL(documentPageRemoved(int)), this, SLOT(removeThumbnail(int)));
connect(UBApplication::boardController, SIGNAL(documentPageMoved(int, int)), this, SLOT(moveThumbnail(int, int)));
connect(UBApplication::boardController, SIGNAL(pageSelectionChanged(int)), this, SLOT(onScrollToSelectedPage(int))); connect(UBApplication::boardController, SIGNAL(pageSelectionChanged(int)), this, SLOT(onScrollToSelectedPage(int)));
connect(&mLongPressTimer, SIGNAL(timeout()), this, SLOT(longPressTimeout()), Qt::UniqueConnection); connect(&mLongPressTimer, SIGNAL(timeout()), this, SLOT(longPressTimeout()), Qt::UniqueConnection);
@ -140,6 +143,7 @@ void UBDocumentNavigator::generateThumbnails(UBDocumentContainer* source)
{ {
if (UBApplication::documentController->selectedDocument() == source->selectedDocument()) if (UBApplication::documentController->selectedDocument() == source->selectedDocument())
{ {
if (UBApplication::documentController->pageAt(i)) if (UBApplication::documentController->pageAt(i))
{ {
found = true; found = true;
@ -154,27 +158,31 @@ void UBDocumentNavigator::generateThumbnails(UBDocumentContainer* source)
//claudio This is a very bad hack and shows a architectural problem //claudio This is a very bad hack and shows a architectural problem
// source->selectedDocument()->pageCount() != source->pageCount() // source->selectedDocument()->pageCount() != source->pageCount()
if(i>=source->pageCount() || !source->pageAt(i)) if(i>=source->pageCount() || !source->pageAt(i))
{
source->insertThumbPage(i); source->insertThumbPage(i);
} }
else
auto pix = source->pageAt(i); {
Q_ASSERT(!pix->isNull()); auto pix = source->pageAt(i);
int pageIndex = UBDocumentContainer::pageFromSceneIndex(i); Q_ASSERT(!pix->isNull());
int pageIndex = UBDocumentContainer::pageFromSceneIndex(i);
UBSceneThumbnailNavigPixmap* pixmapItem = new UBSceneThumbnailNavigPixmap(*pix, source->selectedDocument(), i); UBSceneThumbnailNavigPixmap* pixmapItem = new UBSceneThumbnailNavigPixmap(*pix, source->selectedDocument(), i);
QString label = tr("Page %0").arg(pageIndex); QString label = tr("Page %0").arg(pageIndex);
UBThumbnailTextItem *labelItem = new UBThumbnailTextItem(label); UBThumbnailTextItem *labelItem = new UBThumbnailTextItem(label);
UBImgTextThumbnailElement thumbWithText(pixmapItem, labelItem); UBImgTextThumbnailElement thumbWithText(pixmapItem, labelItem);
thumbWithText.setBorder(border()); thumbWithText.setBorder(border());
mThumbsWithLabels.append(thumbWithText); mThumbsWithLabels.append(thumbWithText);
if (lastClickedIndex == i) if (lastClickedIndex == i)
mLastClickedThumbnail = pixmapItem; mLastClickedThumbnail = pixmapItem;
mScene->addItem(pixmapItem); mScene->addItem(pixmapItem);
mScene->addItem(labelItem); mScene->addItem(labelItem);
}
}
} }
if (selectedIndex >= 0 && selectedIndex < mThumbsWithLabels.count()) if (selectedIndex >= 0 && selectedIndex < mThumbsWithLabels.count())
@ -210,18 +218,20 @@ void UBDocumentNavigator::onScrollToSelectedPage(int index)
* \brief Refresh the given thumbnail * \brief Refresh the given thumbnail
* @param iPage as the given page related thumbnail * @param iPage as the given page related thumbnail
*/ */
void UBDocumentNavigator::updateSpecificThumbnail(int iPage) void UBDocumentNavigator::updateThumbnail(int index)
{ {
auto pix = UBApplication::boardController->pageAt(iPage); auto pix = UBApplication::boardController->pageAt(index);
UBSceneThumbnailNavigPixmap* newItem = new UBSceneThumbnailNavigPixmap(*pix, UBApplication::boardController->selectedDocument(), iPage); UBSceneThumbnailNavigPixmap* newItem = new UBSceneThumbnailNavigPixmap(*pix, UBApplication::boardController->selectedDocument(), index);
// Get the old thumbnail // Get the old thumbnail
UBSceneThumbnailNavigPixmap* oldItem = mThumbsWithLabels.at(iPage).getThumbnail(); UBSceneThumbnailNavigPixmap* oldItem = mThumbsWithLabels.at(index).getThumbnail();
if(oldItem) if(oldItem)
{ {
if (oldItem->isSelected())
mScene->removeItem(oldItem->selectionItem());
mScene->removeItem(oldItem); mScene->removeItem(oldItem);
mScene->addItem(newItem); mScene->addItem(newItem);
mThumbsWithLabels[iPage].setThumbnail(newItem); mThumbsWithLabels[index].setThumbnail(newItem);
if (mLastClickedThumbnail == oldItem) if (mLastClickedThumbnail == oldItem)
mLastClickedThumbnail = newItem; mLastClickedThumbnail = newItem;
if (mSelectedThumbnail == oldItem) if (mSelectedThumbnail == oldItem)
@ -233,15 +243,59 @@ void UBDocumentNavigator::updateSpecificThumbnail(int iPage)
ensureVisible(0, 0, 10, 10); ensureVisible(0, 0, 10, 10);
refreshScene(); refreshScene();
}
void UBDocumentNavigator::removeThumbnail(int index)
{
//remove selectionItem
if (mThumbsWithLabels.at(index).getThumbnail()->isSelected())
mScene->removeItem(mThumbsWithLabels.at(index).getThumbnail()->selectionItem());
mScene->removeItem(mThumbsWithLabels.at(index).getCaption());
mScene->removeItem(mThumbsWithLabels.at(index).getThumbnail());
if (UBApplication::documentController) mThumbsWithLabels.removeAt(index);
//update thumbs page number accordingly
for (int i=0; i < mThumbsWithLabels.length(); i++)
{ {
if (UBApplication::documentController->selectedDocument() == UBApplication::boardController->selectedDocument()) mThumbsWithLabels.at(i).getCaption()->setText(tr("Page %0").arg(i+1));
{ }
//update the pixmap in document mode
UBApplication::documentController->updateThumbnailPixmap(iPage, *pix); refreshScene();
} }
void UBDocumentNavigator::insertThumbnail(int index)
{
auto pix = UBApplication::boardController->pageAt(index);
UBSceneThumbnailNavigPixmap* pixmapItem = new UBSceneThumbnailNavigPixmap(*pix, UBApplication::boardController->selectedDocument(), index);
QString label = tr("Page %0").arg(index+1);
UBThumbnailTextItem *labelItem = new UBThumbnailTextItem(label);
labelItem->setWidth(mThumbnailWidth);
UBImgTextThumbnailElement thumbWithText(pixmapItem, labelItem);
thumbWithText.setBorder(border());
mThumbsWithLabels.insert(index, thumbWithText);
if (mLastClickedThumbnail)
{
if (mLastClickedThumbnail->sceneIndex() == index)
mLastClickedThumbnail = pixmapItem;
} }
//sceneIndex is 0-based while pageNumber is 1-based
for (int i=0; i < mThumbsWithLabels.size(); i++)
{
mThumbsWithLabels.at(i).getThumbnail()->setSceneIndex(i);
mThumbsWithLabels.at(i).getCaption()->setPageNumber(i+1);
}
mScene->addItem(pixmapItem);
mScene->addItem(labelItem);
refreshScene();
} }
/** /**
@ -319,7 +373,7 @@ void UBDocumentNavigator::resizeEvent(QResizeEvent *event)
mThumbnailWidth = (width() > mThumbnailMinWidth) ? width() - 2*border() : mThumbnailMinWidth; mThumbnailWidth = (width() > mThumbnailMinWidth) ? width() - 2*border() : mThumbnailMinWidth;
if(mSelectedThumbnail) if(mSelectedThumbnail)
ensureVisible(mSelectedThumbnail); ensureVisible(mSelectedThumbnail);
// Refresh the scene // Refresh the scene
refreshScene(); refreshScene();
@ -351,6 +405,17 @@ void UBDocumentNavigator::mousePressEvent(QMouseEvent *event)
} }
} }
void UBDocumentNavigator::clearSelection()
{
for (auto item : mScene->items())
{
if (item->type() == QGraphicsRectItem::Type && item != mDropBar)
{
mScene->removeItem(item);
}
}
}
UBSceneThumbnailNavigPixmap* UBDocumentNavigator::clickedThumbnail(const QPoint pos) const UBSceneThumbnailNavigPixmap* UBDocumentNavigator::clickedThumbnail(const QPoint pos) const
{ {
UBSceneThumbnailNavigPixmap* clickedThumbnail = NULL; UBSceneThumbnailNavigPixmap* clickedThumbnail = NULL;
@ -600,8 +665,12 @@ void UBDocumentNavigator::dropEvent(QDropEvent *event)
if (mDropSource && mDropTarget) if (mDropSource && mDropTarget)
{ {
if (mDropSource->sceneIndex() != mDropTarget->sceneIndex()) int sourceIndex = mDropSource->sceneIndex();
UBApplication::boardController->moveSceneToIndex(mDropSource->sceneIndex(), mDropTarget->sceneIndex()); int targetIndex = mDropTarget->sceneIndex();
if (sourceIndex != targetIndex)
{
UBApplication::boardController->moveSceneToIndex(sourceIndex, targetIndex);
}
} }
mDropSource = NULL; mDropSource = NULL;
@ -611,3 +680,17 @@ void UBDocumentNavigator::dropEvent(QDropEvent *event)
mDropBar->setRect(QRectF()); mDropBar->setRect(QRectF());
mDropBar->hide(); mDropBar->hide();
} }
void UBDocumentNavigator::moveThumbnail(int from, int to)
{
mThumbsWithLabels.move(from, to);
//sceneIndex is 0-based while pageNumber is 1-based
for (int i=0; i < mThumbsWithLabels.size(); i++)
{
mThumbsWithLabels.at(i).getThumbnail()->setSceneIndex(i);
mThumbsWithLabels.at(i).getCaption()->setPageNumber(i+1);
}
refreshScene();
}

@ -53,12 +53,16 @@ public:
int nbColumns(); int nbColumns();
void setThumbnailMinWidth(int width); void setThumbnailMinWidth(int width);
int thumbnailMinWidth(); int thumbnailMinWidth();
void clearSelection();
UBSceneThumbnailNavigPixmap* clickedThumbnail(const QPoint pos) const; UBSceneThumbnailNavigPixmap* clickedThumbnail(const QPoint pos) const;
public slots: public slots:
void onScrollToSelectedPage(int index);// { if (mCrntItem) centerOn(mCrntItem); } void onScrollToSelectedPage(int index);// { if (mCrntItem) centerOn(mCrntItem); }
void generateThumbnails(UBDocumentContainer* source); void generateThumbnails(UBDocumentContainer* source);
void updateSpecificThumbnail(int iPage); void insertThumbnail(int index);
void updateThumbnail(int index);
void removeThumbnail(int index);
void moveThumbnail(int from, int to);
void longPressTimeout(); void longPressTimeout();
void mousePressAndHoldEvent(); void mousePressAndHoldEvent();

@ -309,6 +309,49 @@ void UBDocumentThumbnailWidget::updateThumbnailPixmap(int index, const QPixmap&
} }
} }
void UBDocumentThumbnailWidget::removeThumbnail(int sceneIndex)
{
if (sceneIndex >= 0 && sceneIndex < mGraphicItems.length())
{
QGraphicsItem* thumbnailItem = mGraphicItems.at(sceneIndex);
QGraphicsItem* textItem = mLabelsItems.at(sceneIndex);
UBSceneThumbnailPixmap *thumbnail = dynamic_cast<UBSceneThumbnailPixmap*>(thumbnailItem);
if (thumbnail)
{
mGraphicItems.removeAt(sceneIndex);
if (thumbnailItem)
scene()->removeItem(thumbnailItem);
mLabelsItems.removeAt(sceneIndex);
if (textItem)
scene()->removeItem(textItem);
}
refreshScene();
}
}
void UBDocumentThumbnailWidget::insertThumbnail(int index, QGraphicsPixmapItem* newThumbnail)
{
if (!mGraphicItems.contains(newThumbnail)) //sometimes, refreshDocumentThumbnailsView is called before
{
auto thumbnailTextItem = new UBThumbnailTextItem(index);
mGraphicItems.insert(index, newThumbnail);
mLabelsItems.insert(index, thumbnailTextItem);
}
refreshScene();
}
void UBDocumentThumbnailWidget::moveThumbnail(int from, int to)
{
UBSceneThumbnailPixmap *thumbnail = dynamic_cast<UBSceneThumbnailPixmap*>(mGraphicItems.at(from));
if (thumbnail)
{
mGraphicItems.move(from, to);
}
refreshScene();
}
void UBDocumentThumbnailWidget::hightlightItem(int index) void UBDocumentThumbnailWidget::hightlightItem(int index)
{ {
if (0 <= index && index < mLabelsItems.length()) if (0 <= index && index < mLabelsItems.length())

@ -49,6 +49,9 @@ class UBDocumentThumbnailWidget: public UBThumbnailWidget
public slots: public slots:
void updateThumbnailPixmap(int index, const QPixmap& newThumbnail); void updateThumbnailPixmap(int index, const QPixmap& newThumbnail);
void removeThumbnail(int index);
void moveThumbnail(int from, int to);
void insertThumbnail(int index, QGraphicsPixmapItem *newThumbnail);
virtual void setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems, const QList<QUrl>& pItemPaths, const QStringList pLabels = QStringList(), const QString& pMimeType = QString("")); virtual void setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems, const QList<QUrl>& pItemPaths, const QStringList pLabels = QStringList(), const QString& pMimeType = QString(""));
signals: signals:

@ -136,6 +136,12 @@ void UBThumbnailWidget::setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsI
mLastSelectedThumbnail = 0; mLastSelectedThumbnail = 0;
} }
void UBThumbnailWidget::insertThumbnailToScene(QGraphicsPixmapItem* newThumbnail, UBThumbnailTextItem* thumbnailTextItem)
{
mThumbnailsScene.addItem(newThumbnail);
mThumbnailsScene.addItem(thumbnailTextItem);
}
void UBThumbnailWidget::refreshScene() void UBThumbnailWidget::refreshScene()
{ {
@ -156,6 +162,10 @@ void UBThumbnailWidget::refreshScene()
{ {
QGraphicsItem* item = mGraphicItems.at(i); QGraphicsItem* item = mGraphicItems.at(i);
UBSceneThumbnailPixmap *thumbnail = dynamic_cast<UBSceneThumbnailPixmap*>(item);
if (thumbnail)
thumbnail->setSceneIndex(i);
qreal scaleWidth = mThumbnailWidth / item->boundingRect().width(); qreal scaleWidth = mThumbnailWidth / item->boundingRect().width();
qreal scaleHeight = thumbnailHeight / item->boundingRect().height(); qreal scaleHeight = thumbnailHeight / item->boundingRect().height();
@ -193,7 +203,7 @@ void UBThumbnailWidget::refreshScene()
if (mLabelsItems.size() > i) if (mLabelsItems.size() > i)
{ {
QFontMetrics fm(mLabelsItems.at(i)->font(), this); QFontMetrics fm(mLabelsItems.at(i)->font(), this);
QString elidedText = fm.elidedText(mLabels.at(i), Qt::ElideRight, mThumbnailWidth); QString elidedText = fm.elidedText(mLabelsItems.at(i)->toPlainText(), Qt::ElideRight, mThumbnailWidth);
mLabelsItems.at(i)->setPlainText(elidedText); mLabelsItems.at(i)->setPlainText(elidedText);
mLabelsItems.at(i)->setWidth(fm.width(elidedText) + 2 * mLabelsItems.at(i)->document()->documentMargin()); mLabelsItems.at(i)->setWidth(fm.width(elidedText) + 2 * mLabelsItems.at(i)->document()->documentMargin());

@ -81,6 +81,7 @@ class UBThumbnailWidget : public QGraphicsView
void setThumbnailWidth(qreal pThumbnailWidth); void setThumbnailWidth(qreal pThumbnailWidth);
void setSpacing(qreal pSpacing); void setSpacing(qreal pSpacing);
virtual void setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems, const QList<QUrl>& pItemPaths, const QStringList pLabels = QStringList(), const QString& pMimeType = QString("")); virtual void setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems, const QList<QUrl>& pItemPaths, const QStringList pLabels = QStringList(), const QString& pMimeType = QString(""));
void insertThumbnailToScene(QGraphicsPixmapItem* newThumbnail, UBThumbnailTextItem* thumbnailTextItem);
void refreshScene(); void refreshScene();
void sceneSelectionChanged(); void sceneSelectionChanged();
@ -184,7 +185,6 @@ class UBThumbnail
item->sceneBoundingRect().height() + 10); item->sceneBoundingRect().height() + 10);
mSelectionItem->show(); mSelectionItem->show();
} }
else else
{ {
@ -199,6 +199,7 @@ class UBThumbnail
void setRow(int row) { mRow = row; } void setRow(int row) { mRow = row; }
UBThumbnailTextItem *label(){return mLabel;} UBThumbnailTextItem *label(){return mLabel;}
void setLabel(UBThumbnailTextItem *label){mLabel = label;} void setLabel(UBThumbnailTextItem *label){mLabel = label;}
QGraphicsRectItem* selectionItem(){ return mSelectionItem; }
protected: protected:
QGraphicsRectItem *mSelectionItem; QGraphicsRectItem *mSelectionItem;
@ -255,6 +256,18 @@ class UBThumbnailTextItem : public QGraphicsTextItem
} }
} }
void setPageNumber(int i)
{
mUnelidedText = tr("Page %0").arg(i);
computeText();
}
void setText(const QString& text)
{
mUnelidedText = text;
computeText();
}
void computeText() void computeText()
{ {
QFontMetricsF fm(font()); QFontMetricsF fm(font());
@ -339,6 +352,11 @@ class UBSceneThumbnailPixmap : public UBThumbnailPixmap
return mSceneIndex; return mSceneIndex;
} }
void setSceneIndex(int i)
{
mSceneIndex = i;
}
void highlight() void highlight()
{ {
//NOOP //NOOP

Loading…
Cancel
Save