diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 7cd7ed40..fecac50c 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -71,6 +71,7 @@ UBBoardView::UBBoardView (UBBoardController* pController, QWidget* pParent) , suspendedMousePressEvent(NULL) , mLongPressInterval(1000) , mIsDragInProgress(false) +, mMultipleSelectionIsEnabled(false) { init (); @@ -86,6 +87,7 @@ UBBoardView::UBBoardView (UBBoardController* pController, int pStartLayer, int p , suspendedMousePressEvent(NULL) , mLongPressInterval(1000) , mIsDragInProgress(false) +, mMultipleSelectionIsEnabled(false) { init (); @@ -206,6 +208,11 @@ UBBoardView::keyPressEvent (QKeyEvent *event) mController->addScene (); break; } + case Qt::Key_Control: + case Qt::Key_Shift: + { + mMultipleSelectionIsEnabled = true; + }break; } @@ -266,6 +273,21 @@ UBBoardView::keyPressEvent (QKeyEvent *event) } } + +void UBBoardView::keyReleaseEvent(QKeyEvent *event) +{ + // if (!event->isAccepted ()) + { + if (Qt::Key_Shift == event->key() + ||Qt::Key_Control == event->key()) + { + mMultipleSelectionIsEnabled = false; + } + } + + QGraphicsView::keyReleaseEvent(event); +} + bool UBBoardView::event (QEvent * e) { @@ -576,7 +598,8 @@ void UBBoardView::handleItemMousePress(QMouseEvent *event) if (movingItem && QGraphicsSvgItem::Type != movingItem->type() - && UBGraphicsDelegateFrame::Type != movingItem->type()) + && UBGraphicsDelegateFrame::Type != movingItem->type() + && !mMultipleSelectionIsEnabled) { foreach(QGraphicsItem *item, scene()->selectedItems()) { @@ -587,6 +610,9 @@ void UBBoardView::handleItemMousePress(QMouseEvent *event) } } + if (mMultipleSelectionIsEnabled) + return; + if (itemShouldReceiveMousePressEvent(movingItem)) QGraphicsView::mousePressEvent (event); else @@ -944,6 +970,7 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event) if (currentTool == UBStylusTool::Selector) { + bool bReleaseIsNeed = true; if (mWidgetMoved) { mWidgetMoved = false; @@ -957,13 +984,25 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event) QGraphicsView::mousePressEvent(suspendedMousePressEvent); // suspendedMousePressEvent is deleted by old Qt event loop movingItem = NULL; delete suspendedMousePressEvent; - suspendedMousePressEvent = NULL; + suspendedMousePressEvent = NULL; } else { if ( QGraphicsSvgItem::Type != movingItem->type() && UBGraphicsDelegateFrame::Type != movingItem->type()) - movingItem->setSelected(true); + { + bReleaseIsNeed = false; + if (movingItem->isSelected() && mMultipleSelectionIsEnabled) + movingItem->setSelected(false); + else + { + if (movingItem->isSelected()) + bReleaseIsNeed = true; + + movingItem->setSelected(true); + } + + } } } @@ -971,7 +1010,11 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event) mUBRubberBand->hide(); } - QGraphicsView::mouseReleaseEvent (event); + if (bReleaseIsNeed) + { + qDebug() << "mre"; + QGraphicsView::mouseReleaseEvent (event); + } } else if (currentTool == UBStylusTool::Play) { diff --git a/src/board/UBBoardView.h b/src/board/UBBoardView.h index 0df2dc6e..34cf7fc7 100644 --- a/src/board/UBBoardView.h +++ b/src/board/UBBoardView.h @@ -65,6 +65,7 @@ class UBBoardView : public QGraphicsView virtual bool event (QEvent * e); virtual void keyPressEvent(QKeyEvent *event); + virtual void keyReleaseEvent(QKeyEvent *event); virtual void tabletEvent(QTabletEvent * event); virtual void mouseDoubleClickEvent(QMouseEvent *event); virtual void mousePressEvent(QMouseEvent *event); @@ -145,6 +146,7 @@ class UBBoardView : public QGraphicsView QTimer mLongPressTimer; bool mIsDragInProgress; + bool mMultipleSelectionIsEnabled; private slots: