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. 45
      src/document/UBDocumentController.cpp
  7. 5
      src/document/UBDocumentController.h
  8. 109
      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);
UBDocumentContainer::addPage(mActiveSceneIndex + 1);
if (UBApplication::documentController->selectedDocument() == selectedDocument())
{
UBApplication::documentController->insertThumbPage(mActiveSceneIndex+1);
}
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
@ -584,7 +588,11 @@ void UBBoardController::duplicateScene(int nIndex)
scIndexes << nIndex;
duplicatePages(scIndexes);
insertThumbPage(nIndex);
emit documentThumbnailsUpdated(this);
if (UBApplication::documentController->selectedDocument() == selectedDocument())
{
UBApplication::documentController->insertThumbPage(nIndex);
}
//emit documentThumbnailsUpdated(this);
emit addThumbnailRequired(this, nIndex + 1);
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
@ -779,6 +787,10 @@ void UBBoardController::deleteScene(int nIndex)
QList<int> scIndexes;
scIndexes << nIndex;
deletePages(scIndexes);
if (UBApplication::documentController->selectedDocument() == selectedDocument())
{
UBApplication::documentController->deleteThumbPage(nIndex);
}
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(selectedDocument());
@ -1618,7 +1630,12 @@ void UBBoardController::moveSceneToIndex(int source, int target)
{
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()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(selectedDocument());
@ -1877,7 +1894,7 @@ void UBBoardController::documentSceneChanged(UBDocumentProxy* pDocumentProxy, in
if(selectedDocument() == pDocumentProxy)
{
setActiveDocumentScene(mActiveSceneIndex);
updatePage(pIndex);
updateThumbPage(pIndex);
}
}
@ -2021,7 +2038,11 @@ void UBBoardController::persistCurrentScene(bool isAnAutomaticBackup, bool force
&& (mActiveScene->isModified()))
{
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)
{
int selectedSceneIndex = UBApplication::documentController->getSelectedItemIndex();
if (selectedSceneIndex != -1)
{
UBApplication::boardController->setActiveDocumentScene(UBApplication::documentController->selectedDocument(), selectedSceneIndex);
}
// int selectedSceneIndex = UBApplication::documentController->getSelectedItemIndex();
// if (selectedSceneIndex != -1)
// {
// UBApplication::boardController->setActiveDocumentScene(UBApplication::documentController->selectedDocument(), selectedSceneIndex);
// }
}
mMainMode = Board;
@ -435,6 +435,7 @@ void UBApplicationController::showDocument()
{
if (UBApplication::boardController->activeScene()->isModified())
UBApplication::boardController->persistCurrentScene();
UBApplication::boardController->hide();
}

@ -827,7 +827,6 @@ UBGraphicsScene* UBPersistenceManager::createDocumentSceneAt(UBDocumentProxy* pr
for(int i = count - 1; i >= index; i--)
{
UBApplication::showMessage(tr("renaming pages (%1/%2)").arg(i).arg(count));
renamePage(proxy, i , i + 1);
}
@ -977,6 +976,7 @@ UBDocumentProxy* UBPersistenceManager::persistDocumentMetadata(UBDocumentProxy*
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));
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
UBPersistenceManager::persistenceManager()->moveSceneToIndex(mCurrentDocument, source, target);
deleteThumbPage(source);
insertThumbPage(target);
emit documentThumbnailsUpdated(this);
//on board thumbnails view
mDocumentThumbs.move(source, target);
//on board thumbnails view (UBDocumentNavigator)
emit documentPageMoved(source, target);
//on board thumbnails view (UBoardThumbnailsView)
emit moveThumbnailRequired(source, target);
return true;
}
void UBDocumentContainer::deletePages(QList<int>& pageIndexes)
@ -84,26 +83,20 @@ void UBDocumentContainer::deletePages(QList<int>& pageIndexes)
foreach(int index, pageIndexes)
{
deleteThumbPage(index - offset);
emit removeThumbnailRequired(index - offset);
offset++;
}
emit documentThumbnailsUpdated(this);
}
void UBDocumentContainer::addPage(int index)
{
UBPersistenceManager::persistenceManager()->createDocumentSceneAt(mCurrentDocument, index);
insertThumbPage(index);
emit documentThumbnailsUpdated(this);
emit addThumbnailRequired(this, 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);
}
void UBDocumentContainer::updatePage(int index)
{
updateThumbPage(index);
}
void UBDocumentContainer::deleteThumbPage(int 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)
@ -136,30 +130,26 @@ void UBDocumentContainer::updateThumbPage(int index)
{
QPixmap pixmap = UBThumbnailAdaptor::get(mCurrentDocument, index);
mDocumentThumbs[index] = std::make_shared<QPixmap>(pixmap);
emit documentPageUpdated(index); //refresh specific thumbnail in board
}
else
{
qDebug() << "error [updateThumbPage] : index > mDocumentThumbs' size.";
emit documentPageUpdated(index);
}
}
void UBDocumentContainer::insertThumbPage(int index)
{
QPixmap newPixmap = UBThumbnailAdaptor::get(mCurrentDocument, index);
if (index < documentThumbs().size())
{
*documentThumbs().at(index) = newPixmap;
}
else
{
documentThumbs().insert(index, std::make_shared<QPixmap>(newPixmap));
}
mDocumentThumbs.insert(index, std::make_shared<QPixmap>(newPixmap));
emit documentPageInserted(index);
emit addThumbnailRequired(this, index);
}
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()

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

@ -1555,9 +1555,14 @@ void UBDocumentTreeView::dropEvent(QDropEvent *event)
Q_ASSERT(QFileInfo(thumbTmp).exists());
Q_ASSERT(QFileInfo(thumbTo).exists());
auto pix = std::make_shared<QPixmap>(thumbTmp);
UBDocumentController *ctrl = UBApplication::documentController;
ctrl->addPixmapAt(pix, toIndex);
if (UBApplication::boardController->selectedDocument() == targetDocProxy)
{
UBApplication::boardController->insertThumbPage(toIndex);
}
}
QApplication::restoreOverrideCursor();
@ -1800,6 +1805,10 @@ UBDocumentController::UBDocumentController(UBMainWindow* mainWindow)
setupToolbar();
connect(this, SIGNAL(exportDone()), mMainWindow, SLOT(onExportDone()));
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()));
}
@ -3048,23 +3057,45 @@ bool UBDocumentController::addFileToDocument(UBDocumentProxy* document)
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);
UBDocumentContainer::moveThumbPage(source, target);
if (UBApplication::boardController->selectedDocument() == selectedDocument())
{
UBApplication::boardController->moveThumbPage(source, target);
}
mDocumentUI->thumbnailWidget->hightlightItem(target);
mBoardController->setActiveDocumentScene(target);
mBoardController->reloadThumbnails();
}
//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()
{

@ -501,7 +501,10 @@ class UBDocumentController : public UBDocumentContainer
void collapseAll();
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:
virtual void setupViews();

@ -83,7 +83,10 @@ UBDocumentNavigator::UBDocumentNavigator(QWidget *parent, const char *name):QGra
setFrameShadow(QFrame::Plain);
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(&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->pageAt(i))
{
found = true;
@ -154,9 +158,11 @@ void UBDocumentNavigator::generateThumbnails(UBDocumentContainer* source)
//claudio This is a very bad hack and shows a architectural problem
// source->selectedDocument()->pageCount() != source->pageCount()
if(i>=source->pageCount() || !source->pageAt(i))
{
source->insertThumbPage(i);
}
else
{
auto pix = source->pageAt(i);
Q_ASSERT(!pix->isNull());
int pageIndex = UBDocumentContainer::pageFromSceneIndex(i);
@ -176,6 +182,8 @@ void UBDocumentNavigator::generateThumbnails(UBDocumentContainer* source)
mScene->addItem(pixmapItem);
mScene->addItem(labelItem);
}
}
}
if (selectedIndex >= 0 && selectedIndex < mThumbsWithLabels.count())
mSelectedThumbnail = mThumbsWithLabels.at(selectedIndex).getThumbnail();
@ -210,18 +218,20 @@ void UBDocumentNavigator::onScrollToSelectedPage(int index)
* \brief Refresh the given 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);
UBSceneThumbnailNavigPixmap* newItem = new UBSceneThumbnailNavigPixmap(*pix, UBApplication::boardController->selectedDocument(), iPage);
auto pix = UBApplication::boardController->pageAt(index);
UBSceneThumbnailNavigPixmap* newItem = new UBSceneThumbnailNavigPixmap(*pix, UBApplication::boardController->selectedDocument(), index);
// Get the old thumbnail
UBSceneThumbnailNavigPixmap* oldItem = mThumbsWithLabels.at(iPage).getThumbnail();
UBSceneThumbnailNavigPixmap* oldItem = mThumbsWithLabels.at(index).getThumbnail();
if(oldItem)
{
if (oldItem->isSelected())
mScene->removeItem(oldItem->selectionItem());
mScene->removeItem(oldItem);
mScene->addItem(newItem);
mThumbsWithLabels[iPage].setThumbnail(newItem);
mThumbsWithLabels[index].setThumbnail(newItem);
if (mLastClickedThumbnail == oldItem)
mLastClickedThumbnail = newItem;
if (mSelectedThumbnail == oldItem)
@ -233,15 +243,59 @@ void UBDocumentNavigator::updateSpecificThumbnail(int iPage)
ensureVisible(0, 0, 10, 10);
refreshScene();
}
if (UBApplication::documentController)
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());
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));
}
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)
{
//update the pixmap in document mode
UBApplication::documentController->updateThumbnailPixmap(iPage, *pix);
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();
}
/**
@ -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* clickedThumbnail = NULL;
@ -600,8 +665,12 @@ void UBDocumentNavigator::dropEvent(QDropEvent *event)
if (mDropSource && mDropTarget)
{
if (mDropSource->sceneIndex() != mDropTarget->sceneIndex())
UBApplication::boardController->moveSceneToIndex(mDropSource->sceneIndex(), mDropTarget->sceneIndex());
int sourceIndex = mDropSource->sceneIndex();
int targetIndex = mDropTarget->sceneIndex();
if (sourceIndex != targetIndex)
{
UBApplication::boardController->moveSceneToIndex(sourceIndex, targetIndex);
}
}
mDropSource = NULL;
@ -611,3 +680,17 @@ void UBDocumentNavigator::dropEvent(QDropEvent *event)
mDropBar->setRect(QRectF());
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();
void setThumbnailMinWidth(int width);
int thumbnailMinWidth();
void clearSelection();
UBSceneThumbnailNavigPixmap* clickedThumbnail(const QPoint pos) const;
public slots:
void onScrollToSelectedPage(int index);// { if (mCrntItem) centerOn(mCrntItem); }
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 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)
{
if (0 <= index && index < mLabelsItems.length())

@ -49,6 +49,9 @@ class UBDocumentThumbnailWidget: public UBThumbnailWidget
public slots:
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(""));
signals:

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

@ -81,6 +81,7 @@ class UBThumbnailWidget : public QGraphicsView
void setThumbnailWidth(qreal pThumbnailWidth);
void setSpacing(qreal pSpacing);
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 sceneSelectionChanged();
@ -184,7 +185,6 @@ class UBThumbnail
item->sceneBoundingRect().height() + 10);
mSelectionItem->show();
}
else
{
@ -199,6 +199,7 @@ class UBThumbnail
void setRow(int row) { mRow = row; }
UBThumbnailTextItem *label(){return mLabel;}
void setLabel(UBThumbnailTextItem *label){mLabel = label;}
QGraphicsRectItem* selectionItem(){ return mSelectionItem; }
protected:
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()
{
QFontMetricsF fm(font());
@ -339,6 +352,11 @@ class UBSceneThumbnailPixmap : public UBThumbnailPixmap
return mSceneIndex;
}
void setSceneIndex(int i)
{
mSceneIndex = i;
}
void highlight()
{
//NOOP

Loading…
Cancel
Save