improvements on the document mode behavior

preferencesAboutTextFull
Clément Fauconnier 6 years ago
parent 681acce85b
commit fca4b6c989
  1. 10
      src/document/UBDocumentContainer.h
  2. 79
      src/document/UBDocumentController.cpp
  3. 11
      src/document/UBDocumentController.h
  4. 1
      src/document/UBDocumentProxy.cpp
  5. 2
      src/gui/UBDocumentNavigator.cpp

@ -46,7 +46,15 @@ class UBDocumentContainer : public QObject
UBDocumentProxy* selectedDocument(){return mCurrentDocument;} UBDocumentProxy* selectedDocument(){return mCurrentDocument;}
int pageCount(){return mCurrentDocument->pageCount();} int pageCount(){return mCurrentDocument->pageCount();}
const QPixmap* pageAt(int index){return mDocumentThumbs[index];} const QPixmap* pageAt(int index)
{
if (index < mDocumentThumbs.size())
return mDocumentThumbs[index];
else
{
return NULL;
}
}
static int pageFromSceneIndex(int sceneIndex); static int pageFromSceneIndex(int sceneIndex);
static int sceneIndexFromPage(int sceneIndex); static int sceneIndexFromPage(int sceneIndex);

@ -353,8 +353,8 @@ UBDocumentTreeModel::UBDocumentTreeModel(QObject *parent) :
//rootNode->addChild(modelsNode); //rootNode->addChild(modelsNode);
UBDocumentTreeNode *trashNode = new UBDocumentTreeNode(UBDocumentTreeNode::Catalog, trashName, tr("Trash")); UBDocumentTreeNode *trashNode = new UBDocumentTreeNode(UBDocumentTreeNode::Catalog, trashName, tr("Trash"));
rootNode->addChild(trashNode); rootNode->addChild(trashNode);
UBDocumentTreeNode *untitledDocumentsNode = new UBDocumentTreeNode(UBDocumentTreeNode::Catalog, UBPersistenceManager::untitledDocumentsName, tr("Untitled documents")); //UBDocumentTreeNode *untitledDocumentsNode = new UBDocumentTreeNode(UBDocumentTreeNode::Catalog, UBPersistenceManager::untitledDocumentsName, tr("Untitled documents"));
myDocsNode->addChild(untitledDocumentsNode); //myDocsNode->addChild(untitledDocumentsNode);
setRootNode(rootNode); setRootNode(rootNode);
@ -1353,7 +1353,13 @@ void UBDocumentTreeView::dragLeaveEvent(QDragLeaveEvent *event)
void UBDocumentTreeView::dragMoveEvent(QDragMoveEvent *event) void UBDocumentTreeView::dragMoveEvent(QDragMoveEvent *event)
{ {
bool acceptIt = isAcceptable(selectedIndexes().first(), indexAt(event->pos())); QModelIndex index;
if (selectedIndexes().count() > 0)
{
index = selectedIndexes().first();
}
bool acceptIt = isAcceptable(index, indexAt(event->pos()));
if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage)) { if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage)) {
UBSortFilterProxyModel *proxy = dynamic_cast<UBSortFilterProxyModel*>(model()); UBSortFilterProxyModel *proxy = dynamic_cast<UBSortFilterProxyModel*>(model());
@ -1400,21 +1406,21 @@ void UBDocumentTreeView::dropEvent(QDropEvent *event)
QModelIndexList dropIndex = mapIndexesToSource(selectedIndexes()); QModelIndexList dropIndex = mapIndexesToSource(selectedIndexes());
//clear the selection right after //clear the selection right after
selectionModel()->clearSelection(); //selectionModel()->clearSelection();
bool isUBPage = event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage); bool isUBPage = event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage);
bool inModel = false;
//just check the first index, because the selection is exclusive between
//myDocuments, Model and Tash
bool isSourceAModel = false;
//issue 1629 - NNE - 20131212 //issue 1629 - NNE - 20131212
bool targetIsInTrash = docModel->inTrash(targetIndex) || docModel->trashIndex() == targetIndex; bool targetIsInTrash = docModel->inTrash(targetIndex) || docModel->trashIndex() == targetIndex;
bool targetIsInMyDocuments = docModel->inMyDocuments(targetIndex) || docModel->myDocumentsIndex() == targetIndex;
if (!targetIsInMyDocuments && !targetIsInTrash)
return;
if (isUBPage) { if (isUBPage)
{
UBDocumentProxy *targetDocProxy = docModel->proxyData(targetIndex); UBDocumentProxy *targetDocProxy = docModel->proxyData(targetIndex);
const UBMimeData *ubMime = qobject_cast <const UBMimeData*>(event->mimeData()); const UBMimeData *ubMime = qobject_cast <const UBMimeData*>(event->mimeData());
if (!targetDocProxy || !ubMime || !ubMime->items().count()) { if (!targetDocProxy || !ubMime || !ubMime->items().count()) {
qDebug() << "an error ocured while parsing " << UBApplication::mimeTypeUniboardPage; qDebug() << "an error ocured while parsing " << UBApplication::mimeTypeUniboardPage;
@ -1440,29 +1446,9 @@ void UBDocumentTreeView::dropEvent(QDropEvent *event)
docModel->setHighLighted(QModelIndex()); docModel->setHighLighted(QModelIndex());
} }
else if(isSourceAModel){
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
if(targetIsInTrash){
//issue 1629 - NNE - 20131212 : If the source is a model and we want to delete it
UBApplication::documentController->moveIndexesToTrash(dropIndex, docModel);
}else{
UBDocumentTreeNode* node = docModel->nodeFromIndex(targetIndex);
QModelIndex targetParentIndex;
if(node->nodeType() == UBDocumentTreeNode::Catalog)
targetParentIndex = docModel->indexForNode(node);
else
targetParentIndex = docModel->indexForNode(node->parentNode());
docModel->copyIndexToNewParent(dropIndex, targetParentIndex,UBDocumentTreeModel::aContentCopy);
docModel->setHighLighted(QModelIndex());
}
QApplication::restoreOverrideCursor(); if(targetIsInTrash)
} {
else if(!inModel){
//issue 1632 - NNE - 20131212
if(targetIsInTrash){
UBApplication::documentController->moveIndexesToTrash(dropIndex, docModel); UBApplication::documentController->moveIndexesToTrash(dropIndex, docModel);
}else{ }else{
docModel->moveIndexes(dropIndex, targetIndex); docModel->moveIndexes(dropIndex, targetIndex);
@ -1470,11 +1456,6 @@ void UBDocumentTreeView::dropEvent(QDropEvent *event)
expand(proxy->mapFromSource(targetIndex)); expand(proxy->mapFromSource(targetIndex));
//issue 1632 - NNE - 20131212 : END
}else if(inModel){
event->setDropAction(Qt::CopyAction);
}
QTreeView::dropEvent(event); QTreeView::dropEvent(event);
} }
@ -2231,6 +2212,9 @@ void UBDocumentController::deleteSelectedItem()
QModelIndexList indexes = selectedTreeIndexes(); QModelIndexList indexes = selectedTreeIndexes();
if (!UBApplication::mainWindow->yesNoQuestion(tr("Remove Item"), tr("Are you sure you want to remove the selected item(s) ?")))
return;
//we iterate in backward because if we iterate in normal order, //we iterate in backward because if we iterate in normal order,
//indexes are invalid after the first deletion //indexes are invalid after the first deletion
for(int i = indexes.size()-1; i >= 0; i--){ for(int i = indexes.size()-1; i >= 0; i--){
@ -2258,6 +2242,7 @@ void UBDocumentController::deleteSelectedItem()
case CompleteDelete: case CompleteDelete:
{ {
deleteIndexAndAssociatedData(currentIndex); deleteIndexAndAssociatedData(currentIndex);
emit documentThumbnailsUpdated(this);
break; break;
} }
case EmptyFolder: case EmptyFolder:
@ -2299,7 +2284,6 @@ void UBDocumentController::deleteSelectedItem()
} }
} }
} }
} }
//N/C - NNE - 20140410 //N/C - NNE - 20140410
@ -2355,11 +2339,11 @@ void UBDocumentController::moveIndexesToTrash(const QModelIndexList &list, UBDoc
deleteCurrentScene = false; deleteCurrentScene = false;
} }
} }
} }
else else
{ {
setDocument(NULL); UBDocumentProxy* proxy = docModel->proxyForIndex(currentScene);
setDocument(proxy);
} }
docModel->moveIndexes(list, docModel->trashIndex()); docModel->moveIndexes(list, docModel->trashIndex());
@ -2368,8 +2352,7 @@ void UBDocumentController::moveIndexesToTrash(const QModelIndexList &list, UBDoc
createNewDocumentInUntitledFolder(); createNewDocumentInUntitledFolder();
} }
selectionModel->clearSelection(); //selectionModel->clearSelection();
} }
//N/C - NNE - 20140410 : END //N/C - NNE - 20140410 : END
@ -2960,7 +2943,6 @@ void UBDocumentController::paste()
void UBDocumentController::focusChanged(QWidget *old, QWidget *current) void UBDocumentController::focusChanged(QWidget *old, QWidget *current)
{ {
Q_UNUSED(old);
UBDocumentTreeModel *treeModel = UBPersistenceManager::persistenceManager()->mDocumentTreeStructureModel; UBDocumentTreeModel *treeModel = UBPersistenceManager::persistenceManager()->mDocumentTreeStructureModel;
if (current == mDocumentUI->thumbnailWidget) if (current == mDocumentUI->thumbnailWidget)
@ -2992,6 +2974,7 @@ void UBDocumentController::focusChanged(QWidget *old, QWidget *current)
old != mDocumentUI->documentTreeView && old != mDocumentUI->documentTreeView &&
old != mDocumentUI->documentZoomSlider) old != mDocumentUI->documentZoomSlider)
{ {
if (current && (current->metaObject()->className() != QPushButton::staticMetaObject.className()))
mSelectionType = None; mSelectionType = None;
} }
} }
@ -3164,7 +3147,7 @@ void UBDocumentController::deletePages(QList<QGraphicsItem *> itemsToDelete)
} }
} }
if(UBApplication::mainWindow->yesNoQuestion(tr("Remove Page"),tr("This is an irreversible action!") +"\n\n" + tr("Are you sure you want to remove %n page(s) from the selected document '%1'?", "", sceneIndexes.count()).arg(proxy->metaData(UBSettings::documentName).toString()))) if(UBApplication::mainWindow->yesNoQuestion(tr("Remove Page"), tr("Are you sure you want to remove %n page(s) from the selected document '%1'?", "", sceneIndexes.count()).arg(proxy->metaData(UBSettings::documentName).toString())))
{ {
UBDocumentContainer::deletePages(sceneIndexes); UBDocumentContainer::deletePages(sceneIndexes);
emit UBApplication::boardController->documentThumbnailsUpdated(this); emit UBApplication::boardController->documentThumbnailsUpdated(this);
@ -3291,7 +3274,8 @@ void UBDocumentController::refreshDocumentThumbnailsView(UBDocumentContainer*)
QModelIndex current = docModel->indexForProxy(currentDocumentProxy); QModelIndex current = docModel->indexForProxy(currentDocumentProxy);
if (!current.isValid()) { if (!current.isValid())
{
mDocumentUI->thumbnailWidget->setGraphicsItems(QList<QGraphicsItem*>() mDocumentUI->thumbnailWidget->setGraphicsItems(QList<QGraphicsItem*>()
, QList<QUrl>() , QList<QUrl>()
, QStringList() , QStringList()
@ -3348,7 +3332,8 @@ void UBDocumentController::refreshDocumentThumbnailsView(UBDocumentContainer*)
mDocumentUI->thumbnailWidget->ensureVisible(0, 0, 10, 10); mDocumentUI->thumbnailWidget->ensureVisible(0, 0, 10, 10);
if (selection) { if (selection)
{
disconnect(mDocumentUI->thumbnailWidget->scene(), SIGNAL(selectionChanged()), this, SLOT(pageSelectionChanged())); disconnect(mDocumentUI->thumbnailWidget->scene(), SIGNAL(selectionChanged()), this, SLOT(pageSelectionChanged()));
UBSceneThumbnailPixmap *currentScene = dynamic_cast<UBSceneThumbnailPixmap*>(selection); UBSceneThumbnailPixmap *currentScene = dynamic_cast<UBSceneThumbnailPixmap*>(selection);
if (currentScene) if (currentScene)

@ -111,7 +111,14 @@ public:
void removeChild(int index); void removeChild(int index);
UBDocumentProxy *proxyData() const {return mProxy;} UBDocumentProxy *proxyData() const {return mProxy;}
bool isRoot() {return !mParent;} bool isRoot() {return !mParent;}
bool isTopLevel() {return mParent && !mParent->mParent;} bool isTopLevel()
{
if (mParent)
{
return !mParent->mParent;
}
else return false;
}
UBDocumentTreeNode *clone(); UBDocumentTreeNode *clone();
QString dirPathInHierarchy(); QString dirPathInHierarchy();
@ -216,7 +223,7 @@ public:
QPersistentModelIndex myDocumentsIndex() const {return mMyDocuments;} QPersistentModelIndex myDocumentsIndex() const {return mMyDocuments;}
QPersistentModelIndex trashIndex() const {return mTrash;} QPersistentModelIndex trashIndex() const {return mTrash;}
QPersistentModelIndex untitledDocumentsIndex() const {return mUntitledDocuments;} QPersistentModelIndex untitledDocumentsIndex() const {return mMyDocuments;}
UBDocumentTreeNode *nodeFromIndex(const QModelIndex &pIndex) const; UBDocumentTreeNode *nodeFromIndex(const QModelIndex &pIndex) const;
static bool nodeLessThan(const UBDocumentTreeNode *firstIndex, const UBDocumentTreeNode *secondIndex); static bool nodeLessThan(const UBDocumentTreeNode *firstIndex, const UBDocumentTreeNode *secondIndex);
void setHighLighted(const QModelIndex &newHighLighted) {mHighLighted = newHighLighted;} void setHighLighted(const QModelIndex &newHighLighted) {mHighLighted = newHighLighted;}

@ -42,6 +42,7 @@
UBDocumentProxy::UBDocumentProxy() UBDocumentProxy::UBDocumentProxy()
: mPageCount(0) : mPageCount(0)
, mPageDpi(0) , mPageDpi(0)
, mPersistencePath("")
{ {
init(); init();
} }

@ -127,7 +127,7 @@ 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)->isNull()) if(i>=source->pageCount() || !source->pageAt(i))
source->insertThumbPage(i); source->insertThumbPage(i);
const QPixmap* pix = source->pageAt(i); const QPixmap* pix = source->pageAt(i);

Loading…
Cancel
Save