diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index ae0d80fe..92e8c48b 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -524,7 +524,7 @@ void UBBoardController::addScene() if (UBApplication::documentController->selectedDocument() == selectedDocument()) { UBApplication::documentController->insertThumbPage(mActiveSceneIndex+1); - emit UBApplication::documentController->reloadThumbnails(); + UBApplication::documentController->reloadThumbnails(); } selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); diff --git a/src/core/UBApplicationController.cpp b/src/core/UBApplicationController.cpp index 27c5d75b..cf03215b 100644 --- a/src/core/UBApplicationController.cpp +++ b/src/core/UBApplicationController.cpp @@ -441,7 +441,6 @@ void UBApplicationController::showDocument() if (UBApplication::documentController) { - emit UBApplication::documentController->reorderDocumentsRequested(); UBApplication::documentController->show(); } diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index e826a7ba..e163668e 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -686,8 +686,7 @@ void UBPersistenceManager::deleteDocumentScenes(UBDocumentProxy* proxy, const QL d.mkpath(d.absolutePath()); QFile::copy(source, target); } - - insertDocumentSceneAt(trashDocProxy, scene, trashDocProxy->pageCount()); + insertDocumentSceneAt(trashDocProxy, scene, trashDocProxy->pageCount(), true, true); } } @@ -890,7 +889,7 @@ UBGraphicsScene* UBPersistenceManager::createDocumentSceneAt(UBDocumentProxy* pr } -void UBPersistenceManager::insertDocumentSceneAt(UBDocumentProxy* proxy, UBGraphicsScene* scene, int index, bool persist) +void UBPersistenceManager::insertDocumentSceneAt(UBDocumentProxy* proxy, UBGraphicsScene* scene, int index, bool persist, bool deleting) { scene->setDocument(proxy); @@ -911,7 +910,8 @@ void UBPersistenceManager::insertDocumentSceneAt(UBDocumentProxy* proxy, UBGraph persistDocumentScene(proxy, scene, index); } - emit documentSceneCreated(proxy, index); + if (!deleting) + emit documentSceneCreated(proxy, index); } diff --git a/src/core/UBPersistenceManager.h b/src/core/UBPersistenceManager.h index 18353b0b..cdcba56f 100644 --- a/src/core/UBPersistenceManager.h +++ b/src/core/UBPersistenceManager.h @@ -107,7 +107,7 @@ class UBPersistenceManager : public QObject virtual UBGraphicsScene* createDocumentSceneAt(UBDocumentProxy* pDocumentProxy, int index, bool useUndoRedoStack = true); - virtual void insertDocumentSceneAt(UBDocumentProxy* pDocumentProxy, UBGraphicsScene* scene, int index, bool persist = true); + virtual void insertDocumentSceneAt(UBDocumentProxy* pDocumentProxy, UBGraphicsScene* scene, int index, bool persist = true, bool deleting = false); virtual void moveSceneToIndex(UBDocumentProxy* pDocumentProxy, int source, int target); diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index e76c7ecd..8578e04f 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -1341,6 +1341,7 @@ UBDocumentTreeView::UBDocumentTreeView(QWidget *parent) : QTreeView(parent) { setObjectName("UBDocumentTreeView"); setRootIsDecorated(true); + setSelectionBehavior(SelectRows); } void UBDocumentTreeView::setSelectedAndExpanded(const QModelIndex &pIndex, bool pExpand, bool pEdit) @@ -1358,9 +1359,9 @@ void UBDocumentTreeView::setSelectedAndExpanded(const QModelIndex &pIndex, bool ? QItemSelectionModel::Select : QItemSelectionModel::Deselect; - setCurrentIndex(pExpand - ? indexCurrentDoc - : QModelIndex()); + setCurrentIndex(indexCurrentDoc); + + selectionModel()->setCurrentIndex(proxy->mapFromSource(indexCurrentDoc), QItemSelectionModel::SelectCurrent); selectionModel()->select(proxy->mapFromSource(indexCurrentDoc), QItemSelectionModel::Rows | sel); @@ -1369,7 +1370,7 @@ void UBDocumentTreeView::setSelectedAndExpanded(const QModelIndex &pIndex, bool indexCurrentDoc = indexCurrentDoc.parent(); } - scrollTo(proxy->mapFromSource(pIndex), QAbstractItemView::PositionAtCenter); + scrollTo(proxy->mapFromSource(pIndex)); if (pEdit) edit(proxy->mapFromSource(pIndex)); @@ -1860,7 +1861,8 @@ void UBDocumentController::selectDocument(UBDocumentProxy* proxy, bool setAsCurr return; } - if (setAsCurrentDocument) { + if (setAsCurrentDocument) + { UBPersistenceManager::persistenceManager()->mDocumentTreeStructureModel->setCurrentDocument(proxy); QModelIndex indexCurrentDoc = UBPersistenceManager::persistenceManager()->mDocumentTreeStructureModel->indexForProxy(proxy); if (indexCurrentDoc.isValid()) @@ -1873,9 +1875,12 @@ void UBDocumentController::selectDocument(UBDocumentProxy* proxy, bool setAsCurr mBoardController->setActiveDocumentScene(proxy, 0, true, onImport); } } + else + { + qWarning() << "an issue occured while trying to select current index in document tree"; + } } - mSelectionType = Document; setDocument(proxy); } @@ -1953,7 +1958,7 @@ void UBDocumentController::TreeViewSelectionChanged(const QModelIndex ¤t, mCurrentIndexMoved = false; } - itemSelectionChanged(docModel->isCatalog(current_index) ? Folder : Document); + pageSelectionChanged(); } //N/C - NNE - 20140402 : workaround for using a proxy model @@ -2181,8 +2186,6 @@ void UBDocumentController::setupViews() connect(mDocumentUI->thumbnailWidget, SIGNAL(mouseDoubleClick(QGraphicsItem*,int)), this, SLOT(thumbnailPageDoubleClicked(QGraphicsItem*,int))); connect(mDocumentUI->thumbnailWidget, SIGNAL(mouseClick(QGraphicsItem*, int)), this, SLOT(pageClicked(QGraphicsItem*, int))); - connect(mDocumentUI->thumbnailWidget->scene(), SIGNAL(selectionChanged()), this, SLOT(pageSelectionChanged())); - connect(UBPersistenceManager::persistenceManager(), SIGNAL(documentSceneCreated(UBDocumentProxy*, int)), this, SLOT(documentSceneChanged(UBDocumentProxy*, int))); mDocumentUI->thumbnailWidget->setBackgroundBrush(UBSettings::documentViewLightColor); @@ -2248,6 +2251,8 @@ void UBDocumentController::sortDocuments(int kind, int order) mDocumentUI->documentTreeView->hideColumn(2); } } + + mDocumentUI->documentTreeView->setSelectedAndExpanded(firstSelectedTreeIndex(), true); } void UBDocumentController::onSortOrderChanged(bool order) @@ -2308,6 +2313,8 @@ void UBDocumentController::show() { selectDocument(mBoardController->selectedDocument()); + reorderDocuments(); + updateActions(); if(!mToolsPalette) @@ -2435,6 +2442,8 @@ void UBDocumentController::deleteSelectedItem() deleteSingleItem(indexes.at(0), docModel); } + pageSelectionChanged(); + updateActions(); } @@ -3134,8 +3143,6 @@ void UBDocumentController::pageSelectionChanged() itemSelectionChanged(Folder); else itemSelectionChanged(None); - - updateActions(); } void UBDocumentController::documentSceneChanged(UBDocumentProxy* proxy, int pSceneIndex) @@ -3401,16 +3408,6 @@ void UBDocumentController::focusChanged(QWidget *old, QWidget *current) else mSelectionType = None; } - else - { - if (old != mDocumentUI->thumbnailWidget && - old != mDocumentUI->documentTreeView && - old != mDocumentUI->documentZoomSlider) - { - if (current && (current->metaObject()->className() != QPushButton::staticMetaObject.className())) - mSelectionType = None; - } - } } void UBDocumentController::updateActions() @@ -3567,6 +3564,24 @@ void UBDocumentController::updateActions() mMainWindow->actionDelete->setIcon(QIcon(":/images/trash-empty.png")); mMainWindow->actionDelete->setText(tr("Empty")); break; + case NoDeletion : + default: + if (mSelectionType == Folder) + { + mMainWindow->actionDelete->setIcon(QIcon(":/images/trash-delete-folder.png")); + mMainWindow->actionDelete->setText(tr("Delete")); + } + else if (mSelectionType == Document) + { + mMainWindow->actionDelete->setIcon(QIcon(":/images/trash-delete-document.png")); + mMainWindow->actionDelete->setText(tr("Delete")); + } + else if (mSelectionType == Page) + { + mMainWindow->actionDelete->setIcon(QIcon(":/images/trash-document-page.png")); + mMainWindow->actionDelete->setText(tr("Delete")); + } + break; } mMainWindow->actionDocumentAdd->setEnabled((docSelected || pageSelected) && !trashSelected); @@ -3837,11 +3852,9 @@ void UBDocumentController:: refreshDocumentThumbnailsView(UBDocumentContainer* s if (selection) { - disconnect(mDocumentUI->thumbnailWidget->scene(), SIGNAL(selectionChanged()), this, SLOT(pageSelectionChanged())); UBSceneThumbnailPixmap *currentSceneThumbnailPixmap = dynamic_cast(selection); if (currentSceneThumbnailPixmap) mDocumentUI->thumbnailWidget->hightlightItem(currentSceneThumbnailPixmap->sceneIndex()); - connect(mDocumentUI->thumbnailWidget->scene(), SIGNAL(selectionChanged()), this, SLOT(pageSelectionChanged())); } QApplication::restoreOverrideCursor(); diff --git a/src/gui/UBThumbnailWidget.cpp b/src/gui/UBThumbnailWidget.cpp index 9a866847..abb217e2 100644 --- a/src/gui/UBThumbnailWidget.cpp +++ b/src/gui/UBThumbnailWidget.cpp @@ -67,13 +67,11 @@ UBThumbnailWidget::UBThumbnailWidget(QWidget* parent) setAlignment(Qt::AlignLeft | Qt::AlignTop); - connect(&mThumbnailsScene, SIGNAL(selectionChanged()), this, SLOT(sceneSelectionChanged())); } UBThumbnailWidget::~UBThumbnailWidget() { - disconnect(&mThumbnailsScene, SIGNAL(selectionChanged())); } @@ -108,7 +106,6 @@ void UBThumbnailWidget::setGraphicsItems(const QList& pGraphicsI { mThumbnailsScene.removeItem(it, true); } - // set lasso to 0 as it has been cleared as well mLassoRectItem = 0;