diff --git a/src/board/UBBoardPaletteManager.cpp b/src/board/UBBoardPaletteManager.cpp index a05ca1f7..44d1c08a 100644 --- a/src/board/UBBoardPaletteManager.cpp +++ b/src/board/UBBoardPaletteManager.cpp @@ -346,6 +346,24 @@ void UBBoardPaletteManager::pagePaletteButtonReleased() { if( mPageButtonPressedTime.msecsTo(QTime::currentTime()) > 900) { + // The palette is reinstanciate because the duplication depends on the current scene + delete(mPagePalette); + mPagePalette = 0; + QListpageActions; + pageActions << UBApplication::mainWindow->actionNewPage; + UBBoardController* boardController = UBApplication::boardController; + if(UBApplication::documentController->pageCanBeDuplicated(boardController->pageFromSceneIndex(boardController->activeSceneIndex()))) + pageActions << UBApplication::mainWindow->actionDuplicatePage; + pageActions << UBApplication::mainWindow->actionImportPage; + + mPagePalette = new UBActionPalette(pageActions, Qt::Horizontal , mContainer); + mPagePalette->setButtonIconSize(QSize(128, 128)); + mPagePalette->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + mPagePalette->groupActions(); + mPagePalette->setClosable(true); + mPagePalette->adjustSizeAndPosition(); + + togglePagePalette(true); } else diff --git a/src/board/UBBoardPaletteManager.h b/src/board/UBBoardPaletteManager.h index eef04194..ba341bf9 100644 --- a/src/board/UBBoardPaletteManager.h +++ b/src/board/UBBoardPaletteManager.h @@ -37,7 +37,6 @@ class UBPageNumberPalette; class UBZoomPalette; class UBActionPalette; class UBBoardController; -class UBFloatingPalette; class UBServerXMLHttpRequest; class UBKeyboardPalette; class UBMainWindow; @@ -45,7 +44,7 @@ class UBApplicationController; class UBDockTeacherGuideWidget; // Uncomment this to use old-styles lib paletter - #define USE_WEB_WIDGET +// #define USE_WEB_WIDGET class UBBoardPaletteManager : public QObject diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index 3f7f112b..7428d1a2 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -1177,7 +1177,27 @@ void UBDocumentController::selectionChanged() mMainWindow->actionNewDocument->setEnabled((groupSelected || docSelected || pageSelected) && !trashSelected); mMainWindow->actionExport->setEnabled((docSelected || pageSelected) && !trashSelected); - mMainWindow->actionDuplicate->setEnabled((docSelected || pageSelected) && !trashSelected); + bool firstSceneSelected = false; + if(docSelected) + mMainWindow->actionDuplicate->setEnabled(!trashSelected); + else if(pageSelected){ + QList selection = mDocumentUI->thumbnailWidget->selectedItems(); + if(pageCount == 1) + mMainWindow->actionDuplicate->setEnabled(!trashSelected && pageCanBeDuplicated(UBApplication::boardController->pageFromSceneIndex(0))); + else{ + for(int i = 0; i < selection.count() && !firstSceneSelected; i += 1){ + if(dynamic_cast(selection.at(i))->sceneIndex() == 0){ + mMainWindow->actionDuplicate->setEnabled(!trashSelected && pageCanBeDuplicated(UBApplication::boardController->pageFromSceneIndex(0))); + firstSceneSelected = true; + } + } + if(!firstSceneSelected) + mMainWindow->actionDuplicate->setEnabled(!trashSelected); + } + } + else + mMainWindow->actionDuplicate->setEnabled(false); + mMainWindow->actionOpen->setEnabled((docSelected || pageSelected) && !trashSelected); mMainWindow->actionRename->setEnabled((groupSelected || docSelected) && !trashSelected && !defaultGroupSelected); @@ -1205,6 +1225,9 @@ void UBDocumentController::selectionChanged() deleteEnabled = false; } + if(pageSelected && firstSceneSelected) + deleteEnabled = false; + mMainWindow->actionDelete->setEnabled(deleteEnabled); if (trashSelected) @@ -1671,3 +1694,4 @@ bool UBDocumentController::pageCanBeDeleted(int page) { return page != 0; } + diff --git a/src/gui/UBDocumentThumbnailWidget.cpp b/src/gui/UBDocumentThumbnailWidget.cpp index 9820adfc..d3a6c523 100644 --- a/src/gui/UBDocumentThumbnailWidget.cpp +++ b/src/gui/UBDocumentThumbnailWidget.cpp @@ -19,6 +19,10 @@ #include "core/UBMimeData.h" #include "core/UBSettings.h" +#include "board/UBBoardController.h" + +#include "document/UBDocumentController.h" + #include "core/memcheck.h" @@ -51,8 +55,7 @@ void UBDocumentThumbnailWidget::mouseMoveEvent(QMouseEvent *event) if (!(event->buttons() & Qt::LeftButton)) return; - if ((event->pos() - mMousePressPos).manhattanLength() - < QApplication::startDragDistance()) + if ((event->pos() - mMousePressPos).manhattanLength() < QApplication::startDragDistance()) return; QList graphicsItems = items(mMousePressPos); @@ -60,24 +63,25 @@ void UBDocumentThumbnailWidget::mouseMoveEvent(QMouseEvent *event) UBSceneThumbnailPixmap* sceneItem = 0; while (!graphicsItems.isEmpty() && !sceneItem) - { sceneItem = dynamic_cast(graphicsItems.takeFirst()); - } if (sceneItem) { - QDrag *drag = new QDrag(this); - QList mimeDataItems; - foreach (QGraphicsItem *item, selectedItems()) - mimeDataItems.append(UBMimeDataItem(sceneItem->proxy(), mGraphicItems.indexOf(item))); - UBMimeData *mime = new UBMimeData(mimeDataItems); - drag->setMimeData(mime); + int pageIndex = UBApplication::boardController->pageFromSceneIndex(sceneItem->sceneIndex()); + if(pageIndex != 0){ + QDrag *drag = new QDrag(this); + QList mimeDataItems; + foreach (QGraphicsItem *item, selectedItems()) + mimeDataItems.append(UBMimeDataItem(sceneItem->proxy(), mGraphicItems.indexOf(item))); + + UBMimeData *mime = new UBMimeData(mimeDataItems); + drag->setMimeData(mime); - drag->setPixmap(sceneItem->pixmap().scaledToWidth(100)); - drag->setHotSpot(QPoint(drag->pixmap().width()/2, - drag->pixmap().height() / 2)); + drag->setPixmap(sceneItem->pixmap().scaledToWidth(100)); + drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height() / 2)); - drag->exec(Qt::MoveAction); + drag->exec(Qt::MoveAction); + } } UBThumbnailWidget::mouseMoveEvent(event); @@ -104,6 +108,7 @@ void UBDocumentThumbnailWidget::dragLeaveEvent(QDragLeaveEvent *event) mScrollTimer->stop(); } deleteDropCaret(); + UBThumbnailWidget::dragLeaveEvent(event); } void UBDocumentThumbnailWidget::autoScroll() @@ -145,6 +150,14 @@ void UBDocumentThumbnailWidget::dragMoveEvent(QDragMoveEvent *event) QGraphicsItem *underlyingItem = itemAt(event->pos()); mClosestDropItem = dynamic_cast(underlyingItem); + int pageIndex = -1; + if(mClosestDropItem){ + pageIndex = UBApplication::boardController->pageFromSceneIndex(mClosestDropItem->sceneIndex()); + if(pageIndex == 0){ + event->acceptProposedAction(); + return; + } + } if (!mClosestDropItem) { foreach (UBSceneThumbnailPixmap *item, pixmapItems) @@ -159,11 +172,12 @@ void UBDocumentThumbnailWidget::dragMoveEvent(QDragMoveEvent *event) { mClosestDropItem = item; minDistance = distance; + pageIndex = UBApplication::boardController->pageFromSceneIndex(mClosestDropItem->sceneIndex()); } } } - if (mClosestDropItem) + if (mClosestDropItem && pageIndex != 0) { qreal scale = mClosestDropItem->transform().m11(); @@ -206,6 +220,10 @@ void UBDocumentThumbnailWidget::dropEvent(QDropEvent *event) if (mClosestDropItem) { int targetIndex = mDropIsRight ? mGraphicItems.indexOf(mClosestDropItem) + 1 : mGraphicItems.indexOf(mClosestDropItem); + if(UBApplication::boardController->pageFromSceneIndex(targetIndex) == 0){ + event->ignore(); + return; + } QList mimeDataItems; if (event->mimeData()->hasFormat(UBApplication::mimeTypeUniboardPage)) @@ -233,7 +251,6 @@ void UBDocumentThumbnailWidget::dropEvent(QDropEvent *event) actualSourceIndex += sourceIndexOffset; event->acceptProposedAction(); - if (sourceItem.sceneIndex() < targetIndex) { if (actualSourceIndex != actualTargetIndex - 1) @@ -248,6 +265,7 @@ void UBDocumentThumbnailWidget::dropEvent(QDropEvent *event) } } } + } void UBDocumentThumbnailWidget::deleteDropCaret() diff --git a/src/gui/UBFeaturesActionBar.cpp b/src/gui/UBFeaturesActionBar.cpp index a151406d..2b5edb0a 100644 --- a/src/gui/UBFeaturesActionBar.cpp +++ b/src/gui/UBFeaturesActionBar.cpp @@ -28,7 +28,6 @@ UBFeaturesActionBar::UBFeaturesActionBar( UBFeaturesController *controller, QWid mButtonGroup = new QButtonGroup(this); mSearchBar = new QLineEdit(this); mSearchBar->setStyleSheet(QString("background-color:white; border-radius : 10px; padding : 2px;")); - //connect(mSearchBar, SIGNAL(returnPressed()), this, SLOT(onActionSearch())); mLayout = new QHBoxLayout(); setLayout(mLayout); @@ -47,7 +46,6 @@ UBFeaturesActionBar::UBFeaturesActionBar( UBFeaturesController *controller, QWid // Create the buttons mpFavoriteBtn = new UBActionButton(this, mpFavoriteAction); mpSocialBtn = new UBActionButton(this, mpSocialAction); - //mpSearchBtn = new UBActionButton(this, mpSearchAction); mpDeleteBtn = new UBActionButton(this, mpDeleteAction); mpCloseBtn = new UBActionButton(this, mpCloseAction); mpRemoveFavoriteBtn = new UBActionButton(this, mpRemoveFavorite); diff --git a/src/gui/UBThumbnailWidget.cpp b/src/gui/UBThumbnailWidget.cpp index c3c5f9e2..640c6036 100644 --- a/src/gui/UBThumbnailWidget.cpp +++ b/src/gui/UBThumbnailWidget.cpp @@ -208,9 +208,18 @@ void UBThumbnailWidget::mousePressEvent(QMouseEvent *event) { mClickTime = QTime::currentTime(); mMousePressPos = event->pos(); + + UBSceneThumbnailPixmap* sceneItem = dynamic_cast(itemAt(mMousePressPos)); + if(sceneItem){ + int pageIndex = UBApplication::boardController->pageFromSceneIndex(sceneItem->sceneIndex()); + if(pageIndex == 0){ + event->ignore(); + return; + } + } + mMousePressScenePos = mapToScene(mMousePressPos); QGraphicsItem* underlyingItem = itemAt(mMousePressPos); - UBThumbnail *previousSelectedThumbnail = mLastSelectedThumbnail; if (!dynamic_cast(underlyingItem))