From 921953e06901d6bccce025ba9706e6c475573fca Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Thu, 12 Apr 2012 15:56:17 +0300 Subject: [PATCH] PDF view: performance fix --- src/core/UBApplicationController.cpp | 3 ++ src/document/UBDocumentController.cpp | 44 +++++++++++++++++++++------ src/document/UBDocumentController.h | 4 ++- src/gui/UBDocumentNavigator.cpp | 1 - 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/core/UBApplicationController.cpp b/src/core/UBApplicationController.cpp index 0ee793e1..89af16fa 100644 --- a/src/core/UBApplicationController.cpp +++ b/src/core/UBApplicationController.cpp @@ -337,6 +337,9 @@ void UBApplicationController::showBoard() mMainWindow->tutorialToolBar->hide(); mMainWindow->boardToolBar->show(); + if (mMainMode == Document && UBApplication::documentController->getSelectedItemIndex() != -1) + UBApplication::boardController->setActiveDocumentScene(UBApplication::documentController->getCurrentDocument(), UBApplication::documentController->getSelectedItemIndex()); + mMainMode = Board; adaptToolBar(); diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index f75ccc4d..acc5495e 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -160,6 +160,9 @@ void UBDocumentController::selectDocument(UBDocumentProxy* proxy, bool setAsCurr mDocumentUI->documentTreeWidget->scrollToItem(selected); + mDocumentThumbs = UBThumbnailAdaptor::load(selectedDocumentProxy()); + refreshDocumentThumbnailsView(); + mSelectionType = Document; } } @@ -268,11 +271,10 @@ void UBDocumentController::refreshDocumentThumbnailsView() if (proxy) { mCurrentDocument = proxy; - QList thumbs = UBThumbnailAdaptor::load(proxy); - for (int i = 0; i < thumbs.count(); i++) + for (int i = 0; i < mDocumentThumbs.count(); i++) { - QPixmap pix = thumbs.at(i); + QPixmap pix = mDocumentThumbs.at(i); QGraphicsPixmapItem *pixmapItem = new UBSceneThumbnailPixmap(pix, proxy, i); // deleted by the tree widget if (proxy == mBoardController->activeDocument() && mBoardController->activeSceneIndex() == i) @@ -507,7 +509,7 @@ void UBDocumentController::openSelectedItem() if (proxy && isOKToOpenDocument(proxy)) { - mBoardController->setActiveDocumentScene(proxy, thumb->sceneIndex()); + //mBoardController->setActiveDocumentScene(proxy, thumb->sceneIndex()); UBApplication::applicationController->showBoard(); } } @@ -561,6 +563,7 @@ void UBDocumentController::duplicateSelectedItem() foreach (int sceneIndex, selectedSceneIndexes) { UBPersistenceManager::persistenceManager()->duplicateDocumentScene(proxy, sceneIndex + offset); + mDocumentThumbs.insert(sceneIndex + offset, mDocumentThumbs.at(sceneIndex + offset)); offset++; } } @@ -921,6 +924,7 @@ void UBDocumentController::itemClicked(QTreeWidgetItem * item, int column ) Q_UNUSED(item); Q_UNUSED(column); + selectDocument(selectedDocumentProxy(), false); itemSelectionChanged(); } @@ -1043,6 +1047,7 @@ void UBDocumentController::addFolderOfImages() { document->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); UBMetadataDcSubsetAdaptor::persist(document); + mDocumentThumbs = UBThumbnailAdaptor::load(selectedDocumentProxy()); refreshDocumentThumbnailsView(); } } @@ -1057,6 +1062,7 @@ void UBDocumentController::addFileToDocument() if (document) { addFileToDocument(document); + mDocumentThumbs = UBThumbnailAdaptor::load(document); refreshDocumentThumbnailsView(); } } @@ -1108,12 +1114,9 @@ void UBDocumentController::moveSceneToIndex(UBDocumentProxy* proxy, int source, proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); UBMetadataDcSubsetAdaptor::persist(proxy); + mDocumentThumbs.insert(target, mDocumentThumbs.takeAt(source)); refreshDocumentThumbnailsView(); - - // Notify the move to anyone interested in knowing it - emit movedToIndex(target); - - UBApplication::boardController->setActiveDocumentScene(proxy, target); + mDocumentUI->thumbnailWidget->hightlightItem(target); } @@ -1321,7 +1324,8 @@ void UBDocumentController::addToDocument() } int newActiveSceneIndex = selectedItems.count() == mBoardController->activeDocument()->pageCount() ? 0 : oldActiveSceneIndex + 1; - mBoardController->setActiveDocumentScene(mBoardController->activeDocument(), newActiveSceneIndex); + mDocumentUI->thumbnailWidget->selectItemAt(newActiveSceneIndex, false); + selectDocument(mBoardController->activeDocument()); mBoardController->activeDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); UBMetadataDcSubsetAdaptor::persist(mBoardController->activeDocument()); @@ -1495,6 +1499,7 @@ void UBDocumentController::addImages() { document->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); UBMetadataDcSubsetAdaptor::persist(document); + mDocumentThumbs = UBThumbnailAdaptor::load(selectedDocumentProxy()); refreshDocumentThumbnailsView(); } } @@ -1605,6 +1610,13 @@ void UBDocumentController::deletePages(QList itemsToDelete) UBPersistenceManager::persistenceManager()->deleteDocumentScenes(proxy, sceneIndexes); proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); UBMetadataDcSubsetAdaptor::persist(proxy); + + int offset = 0; + foreach(int index, sceneIndexes) + { + mDocumentThumbs.removeAt(index - offset); + offset++; + } refreshDocumentThumbnailsView(); int minIndex = proxy->pageCount() - 1; @@ -1616,3 +1628,15 @@ void UBDocumentController::deletePages(QList itemsToDelete) } } } + +int UBDocumentController::getSelectedItemIndex() +{ + QList selectedItems = mDocumentUI->thumbnailWidget->selectedItems(); + + if (selectedItems.count() > 0) + { + UBSceneThumbnailPixmap* thumb = dynamic_cast (selectedItems.last()); + return thumb->sceneIndex(); + } + else return -1; +} \ No newline at end of file diff --git a/src/document/UBDocumentController.h b/src/document/UBDocumentController.h index 4baf8b36..5b1daa2b 100644 --- a/src/document/UBDocumentController.h +++ b/src/document/UBDocumentController.h @@ -48,8 +48,9 @@ class UBDocumentController : public QObject QWidget* controlView(); UBDocumentProxyTreeItem* findDocument(UBDocumentProxy* proxy); bool addFileToDocument(UBDocumentProxy* document); - UBDocumentProxy* getCurrentDocument(); + UBDocumentProxy* getCurrentDocument() { return mCurrentDocument; }; void deletePages(QList itemsToDelete); + int getSelectedItemIndex(); signals: void refreshThumbnails(); @@ -111,6 +112,7 @@ class UBDocumentController : public QObject bool mToolsPalettePositionned; UBDocumentGroupTreeItem* mTrashTi; UBDocumentProxy* mCurrentDocument; + QList mDocumentThumbs; // UBKeyboardPalette *mKeyboardPalette; diff --git a/src/gui/UBDocumentNavigator.cpp b/src/gui/UBDocumentNavigator.cpp index 7abf129b..efb3e04a 100644 --- a/src/gui/UBDocumentNavigator.cpp +++ b/src/gui/UBDocumentNavigator.cpp @@ -56,7 +56,6 @@ UBDocumentNavigator::UBDocumentNavigator(QWidget *parent, const char *name):QGra setFrameShadow(QFrame::Plain); connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(addNewPage())); - connect(UBApplication::boardController, SIGNAL(setDocOnPageNavigator(UBDocumentProxy*)), this, SLOT(generateThumbnails())); connect(mScene, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); connect(UBApplication::boardController, SIGNAL(documentReorganized(int)), this, SLOT(onMovedToIndex(int))); }