From fc15dfe45ca504b20c9148b6dec52d42f5a4e789 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Wed, 4 Jul 2012 14:18:21 +0200 Subject: [PATCH] exported all the logic for page actions on UBDocumentController --- src/document/UBDocumentController.cpp | 26 +++++++++++++++++ src/document/UBDocumentController.h | 5 ++++ src/gui/UBThumbnailWidget.cpp | 42 ++++++++------------------- 3 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index 1f9e1407..3f7f112b 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -1645,3 +1645,29 @@ int UBDocumentController::getSelectedItemIndex() } else return -1; } + +bool UBDocumentController::pageCanBeMovedUp(int page) +{ + if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool()) + return page >= 2; + else + return page >= 1; +} + +bool UBDocumentController::pageCanBeMovedDown(int page) +{ + if(UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool()) + return page != 0 && page < mCurrentDocument->pageCount() - 1; + else + return page < mCurrentDocument->pageCount() - 1; +} + +bool UBDocumentController::pageCanBeDuplicated(int page) +{ + return page != 0; +} + +bool UBDocumentController::pageCanBeDeleted(int page) +{ + return page != 0; +} diff --git a/src/document/UBDocumentController.h b/src/document/UBDocumentController.h index f3e387ba..7280d48c 100644 --- a/src/document/UBDocumentController.h +++ b/src/document/UBDocumentController.h @@ -51,6 +51,11 @@ class UBDocumentController : public QObject void deletePages(QList itemsToDelete); int getSelectedItemIndex(); + bool pageCanBeMovedUp(int page); + bool pageCanBeMovedDown(int page); + bool pageCanBeDuplicated(int page); + bool pageCanBeDeleted(int page); + signals: void refreshThumbnails(); void exportDone(); diff --git a/src/gui/UBThumbnailWidget.cpp b/src/gui/UBThumbnailWidget.cpp index 5debf1b4..c3c5f9e2 100644 --- a/src/gui/UBThumbnailWidget.cpp +++ b/src/gui/UBThumbnailWidget.cpp @@ -823,40 +823,22 @@ void UBSceneThumbnailNavigPixmap::mousePressEvent(QGraphicsSceneMouseEvent *even void UBSceneThumbnailNavigPixmap::updateButtonsState() { - bCanDelete = false; + + bCanDelete = false; bCanMoveUp = false; bCanMoveDown = false; - bCanDuplicate = true; - - UBDocumentProxy* p = proxy(); - if(NULL != p && 0 <= UBApplication::boardController->pageFromSceneIndex(sceneIndex())) - { - int iNbPages = p->pageCount(); - if(1 < iNbPages) - { - bCanDelete = true; - if(sceneIndex() > 0) - { - bCanMoveUp = true; - } - if(sceneIndex() != iNbPages - 1) - { - bCanMoveDown = true; - } - } + bCanDuplicate = false; + + if(proxy()){ + int pageIndex = UBApplication::boardController->pageFromSceneIndex(sceneIndex()); + UBDocumentController* documentController = UBApplication::documentController; + bCanDelete = documentController->pageCanBeDeleted(pageIndex); + bCanMoveUp = documentController->pageCanBeMovedUp(pageIndex); + bCanMoveDown = documentController->pageCanBeMovedDown(pageIndex); + bCanDuplicate = documentController->pageCanBeDuplicated(pageIndex); } - if(UBSettings::settings()->teacherGuidePageZeroActivated && sceneIndex()<=1) - bCanMoveUp = false; - - if(UBSettings::settings()->teacherGuidePageZeroActivated && sceneIndex() == 0){ - bCanDelete = false; - bCanDuplicate = false; - bCanMoveUp = false; - bCanMoveDown = false; - } - - if(bCanDelete || bCanMoveUp || bCanMoveDown) + if(bCanDelete || bCanMoveUp || bCanMoveDown || bCanDuplicate) bButtonsVisible = true; }