From fc693d7317c1435719b49ca8326638f301c05119 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Wed, 4 Jul 2012 12:53:17 +0200 Subject: [PATCH] developed Sankore-208 --- resources/images/duplicateDisabled.svg | 91 ++++++++++++++++++++++++++ resources/sankore.qrc | 1 + src/document/UBDocumentController.cpp | 15 ++++- src/document/UBDocumentController.h | 2 + src/gui/UBDocumentThumbnailWidget.cpp | 3 +- src/gui/UBThumbnailWidget.cpp | 47 ++++++++----- src/gui/UBThumbnailWidget.h | 2 + 7 files changed, 144 insertions(+), 17 deletions(-) create mode 100644 resources/images/duplicateDisabled.svg diff --git a/resources/images/duplicateDisabled.svg b/resources/images/duplicateDisabled.svg new file mode 100644 index 00000000..be9083f9 --- /dev/null +++ b/resources/images/duplicateDisabled.svg @@ -0,0 +1,91 @@ + + + +image/svg+xml + + + + + + + + + \ No newline at end of file diff --git a/resources/sankore.qrc b/resources/sankore.qrc index 2d05cf89..c06ee37b 100644 --- a/resources/sankore.qrc +++ b/resources/sankore.qrc @@ -355,5 +355,6 @@ images/teacherGuide/link.png images/teacherGuide/movie.png images/teacherGuide/w3c.png + images/duplicateDisabled.svg diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index 7f7bf5a3..634c3dcb 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -535,6 +535,20 @@ void UBDocumentController::openSelectedItem() } +void UBDocumentController::duplicateScenes(UBDocumentProxy* proxy, QList scenesIndex) +{ + if(scenesIndex.count()){ + int offset = 0; + foreach (int eachSceneIndex, scenesIndex){ + UBPersistenceManager::persistenceManager()->duplicateDocumentScene(proxy, eachSceneIndex + offset); + mDocumentThumbs.insert(eachSceneIndex + offset, mDocumentThumbs.at(eachSceneIndex + offset)); + UBApplication::boardController->setActiveDocumentScene(proxy,eachSceneIndex+offset+1); + offset++; + } + } + +} + void UBDocumentController::duplicateSelectedItem() { if (UBApplication::applicationController->displayMode() != UBApplicationController::Document) @@ -558,7 +572,6 @@ void UBDocumentController::duplicateSelectedItem() } } } - if (selectedSceneIndexes.count() > 0) { UBSceneThumbnailPixmap *thumb = dynamic_cast(selectedItems.at(0)); diff --git a/src/document/UBDocumentController.h b/src/document/UBDocumentController.h index f3e387ba..d74654a3 100644 --- a/src/document/UBDocumentController.h +++ b/src/document/UBDocumentController.h @@ -50,6 +50,8 @@ class UBDocumentController : public QObject UBDocumentProxy* getCurrentDocument() { return mCurrentDocument; }; void deletePages(QList itemsToDelete); int getSelectedItemIndex(); + void duplicateScenes(UBDocumentProxy* proxy, QList scenesIndex); + signals: void refreshThumbnails(); diff --git a/src/gui/UBDocumentThumbnailWidget.cpp b/src/gui/UBDocumentThumbnailWidget.cpp index debeb9a1..9820adfc 100644 --- a/src/gui/UBDocumentThumbnailWidget.cpp +++ b/src/gui/UBDocumentThumbnailWidget.cpp @@ -26,7 +26,8 @@ UBDocumentThumbnailWidget::UBDocumentThumbnailWidget(QWidget* parent) : UBThumbnailWidget(parent) , mDropCaretRectItem(0) , mClosestDropItem(0) - , mDragEnabled(true), mScrollMagnitude(0) + , mDragEnabled(true) + , mScrollMagnitude(0) { mScrollTimer = new QTimer(this); connect(mScrollTimer, SIGNAL(timeout()), this, SLOT(autoScroll())); diff --git a/src/gui/UBThumbnailWidget.cpp b/src/gui/UBThumbnailWidget.cpp index e42122bb..abc1df48 100644 --- a/src/gui/UBThumbnailWidget.cpp +++ b/src/gui/UBThumbnailWidget.cpp @@ -750,6 +750,7 @@ UBSceneThumbnailNavigPixmap::UBSceneThumbnailNavigPixmap(const QPixmap& pix, UBD , bCanDelete(false) , bCanMoveUp(false) , bCanMoveDown(false) + , bCanDuplicate(false) { if(0 <= UBApplication::boardController->pageFromSceneIndex(pSceneIndex)){ setAcceptsHoverEvents(true); @@ -788,14 +789,18 @@ void UBSceneThumbnailNavigPixmap::paint(QPainter *painter, const QStyleOptionGra painter->drawPixmap(0, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/close.svg")); else painter->drawPixmap(0, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/closeDisabled.svg")); + if(bCanDuplicate) + painter->drawPixmap(BUTTONSIZE + BUTTONSPACING, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/duplicate.svg")); + else + painter->drawPixmap(BUTTONSIZE + BUTTONSPACING, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/duplicateDisabled.svg")); if(bCanMoveUp) - painter->drawPixmap(BUTTONSIZE + BUTTONSPACING, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/moveUp.svg")); + painter->drawPixmap(2*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/moveUp.svg")); else - painter->drawPixmap(BUTTONSIZE + BUTTONSPACING, 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/moveUpDisabled.svg")); + painter->drawPixmap(2*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/moveUpDisabled.svg")); if(bCanMoveDown) - painter->drawPixmap(2*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/menu.svg")); + painter->drawPixmap(3*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/menu.svg")); else - painter->drawPixmap(2*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/menuDisabled.svg")); + painter->drawPixmap(3*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/menuDisabled.svg")); } } @@ -805,17 +810,14 @@ void UBSceneThumbnailNavigPixmap::mousePressEvent(QGraphicsSceneMouseEvent *even // Here we check the position of the click and verify if it has to trig an action or not. if(bCanDelete && p.x() >= 0 && p.x() <= BUTTONSIZE && p.y() >= 0 && p.y() <= BUTTONSIZE) - { deletePage(); - } - if(bCanMoveUp && p.x() >= BUTTONSIZE + BUTTONSPACING && p.x() <= 2*BUTTONSIZE + BUTTONSPACING && p.y() >= 0 && p.y() <= BUTTONSIZE) - { + if(bCanDuplicate && p.x() >= BUTTONSIZE + BUTTONSPACING && p.x() <= 2*BUTTONSIZE + BUTTONSPACING && p.y() >= 0 && p.y() <= BUTTONSIZE) + duplicatePage(); + if(bCanMoveUp && p.x() >= 2*(BUTTONSIZE + BUTTONSPACING) && p.x() <= 3*BUTTONSIZE + 2*BUTTONSPACING && p.y() >= 0 && p.y() <= BUTTONSIZE) moveUpPage(); - } - if(bCanMoveDown && p.x() >= 2*(BUTTONSIZE + BUTTONSPACING) && p.x() <= 2*(BUTTONSIZE + BUTTONSPACING) + BUTTONSIZE && p.y() >= 0 && p.y() <= BUTTONSIZE) - { + if(bCanMoveDown && p.x() >= 3*(BUTTONSIZE + BUTTONSPACING) && p.x() <= 4*BUTTONSIZE + 3*BUTTONSPACING && p.y() >= 0 && p.y() <= BUTTONSIZE) moveDownPage(); - } + event->accept(); } @@ -824,6 +826,7 @@ void UBSceneThumbnailNavigPixmap::updateButtonsState() bCanDelete = false; bCanMoveUp = false; bCanMoveDown = false; + bCanDuplicate = true; UBDocumentProxy* p = proxy(); if(NULL != p && 0 <= UBApplication::boardController->pageFromSceneIndex(sceneIndex())) @@ -842,13 +845,19 @@ void UBSceneThumbnailNavigPixmap::updateButtonsState() } } } - if(UBSettings::settings()->teacherGuidePageZeroActivated && sceneIndex()<1) + 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) - { bButtonsVisible = true; - } } void UBSceneThumbnailNavigPixmap::deletePage() @@ -859,6 +868,14 @@ void UBSceneThumbnailNavigPixmap::deletePage() UBApplication::documentController->deletePages(itemsToDelete); } +void UBSceneThumbnailNavigPixmap::duplicatePage() +{ + QList itemsToDelete; + itemsToDelete << sceneIndex(); + + UBApplication::documentController->duplicateScenes(proxy(),itemsToDelete); +} + void UBSceneThumbnailNavigPixmap::moveUpPage() { UBApplication::documentController->moveSceneToIndex(proxy(), sceneIndex(), sceneIndex() - 1); diff --git a/src/gui/UBThumbnailWidget.h b/src/gui/UBThumbnailWidget.h index 0429e370..b188ce00 100644 --- a/src/gui/UBThumbnailWidget.h +++ b/src/gui/UBThumbnailWidget.h @@ -306,6 +306,7 @@ class UBSceneThumbnailNavigPixmap : public UBSceneThumbnailPixmap private: void updateButtonsState(); void deletePage(); + void duplicatePage(); void moveUpPage(); void moveDownPage(); @@ -313,6 +314,7 @@ class UBSceneThumbnailNavigPixmap : public UBSceneThumbnailPixmap bool bCanDelete; bool bCanMoveUp; bool bCanMoveDown; + bool bCanDuplicate; }; class UBThumbnailVideo : public UBThumbnailPixmap