diff --git a/Sankore_3.1.pro b/Sankore_3.1.pro index c70aebd1..b3116be0 100644 --- a/Sankore_3.1.pro +++ b/Sankore_3.1.pro @@ -374,7 +374,7 @@ macx { linux-g++* { CONFIG += link_prl LIBS += -lcrypto - LIBS += -lprofiler + #LIBS += -lprofiler LIBS += -lX11 QMAKE_CFLAGS += -fopenmp QMAKE_CXXFLAGS += -fopenmp diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index a97c7635..0d0c0981 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -973,38 +973,36 @@ void UBBoardView::mousePressEvent (QMouseEvent *event) } mMouseDownPos = event->pos (); - movingItem = scene()->itemAt(this->mapToScene(event->posF().toPoint())); if (!movingItem) emit clickOnBoard(); - if (event->button () == Qt::LeftButton && isInteractive ()) + if (event->button () == Qt::LeftButton && isInteractive()) { - - UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool (); - + int currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool (); if (!mTabletStylusIsPressed) mMouseButtonIsPressed = true; - if (currentTool == UBStylusTool::ZoomIn) - { + switch (currentTool) { + case UBStylusTool::ZoomIn : mController->zoomIn (mapToScene (event->pos ())); - event->accept (); - } - else if (currentTool == UBStylusTool::ZoomOut) - { + event->accept(); + break; + + case UBStylusTool::ZoomOut : mController->zoomOut (mapToScene (event->pos ())); - event->accept (); - } - else if (currentTool == UBStylusTool::Hand) - { - viewport ()->setCursor (QCursor (Qt::ClosedHandCursor)); - mPreviousPoint = event->posF (); - event->accept (); - } - else if (currentTool == UBStylusTool::Selector || currentTool == UBStylusTool::Play) - { + event->accept(); + break; + + case UBStylusTool::Hand : + viewport()->setCursor(QCursor (Qt::ClosedHandCursor)); + mPreviousPoint = event->posF(); + event->accept(); + break; + + case UBStylusTool::Selector : + case UBStylusTool::Play : if (bIsDesktop) { event->ignore(); return; @@ -1018,27 +1016,27 @@ void UBBoardView::mousePressEvent (QMouseEvent *event) mLongPressTimer.start(); if (!movingItem) { - // Rubberband selection implementation - if (!mUBRubberBand) { - mUBRubberBand = new UBRubberBand(QRubberBand::Rectangle, this); - } - mUBRubberBand->setGeometry (QRect (mMouseDownPos, QSize ())); - mUBRubberBand->show(); - scene()->setMultipleSelectionProcess(true); +// Rubberband selection implementation +// if (!mUBRubberBand) { +// mUBRubberBand = new UBRubberBand(QRubberBand::Rectangle, this); +// } +// mUBRubberBand->setGeometry (QRect (mMouseDownPos, QSize ())); +// mUBRubberBand->show(); +// scene()->updateMultipleSelectionFrame(); + scene()->clearSelectionFrame(); } - else - { - if(mUBRubberBand) { - mUBRubberBand->hide(); - scene()->setMultipleSelectionProcess(false); - } + + if(mUBRubberBand) { + mUBRubberBand->hide(); + scene()->setMultipleSelectionProcess(false); + } handleItemMousePress(event); event->accept(); - } - else if (currentTool == UBStylusTool::Text) - { + break; + + case UBStylusTool::Text : { int frameWidth = UBSettings::settings ()->objectFrameWidth; QRectF fuzzyRect (0, 0, frameWidth * 4, frameWidth * 4); fuzzyRect.moveCenter (mapToScene (mMouseDownPos)); @@ -1058,20 +1056,19 @@ void UBBoardView::mousePressEvent (QMouseEvent *event) } else { - scene ()->deselectAllItems (); + scene()->deselectAllItems(); if (!mRubberBand) mRubberBand = new UBRubberBand (QRubberBand::Rectangle, this); mRubberBand->setGeometry (QRect (mMouseDownPos, QSize ())); - mRubberBand->show (); + mRubberBand->show(); mIsCreatingTextZone = true; - scene()->setMultipleSelectionProcess(true); event->accept (); } - } - else if (currentTool == UBStylusTool::Capture) - { + } break; + + case UBStylusTool::Capture : scene ()->deselectAllItems (); if (!mRubberBand) @@ -1083,22 +1080,19 @@ void UBBoardView::mousePressEvent (QMouseEvent *event) scene()->setMultipleSelectionProcess(true); event->accept (); - } - else - { - if(UBDrawingController::drawingController()->mActiveRuler==NULL) - { + break; + + default: + if(UBDrawingController::drawingController()->mActiveRuler==NULL) { viewport()->setCursor (QCursor (Qt::BlankCursor)); } - if (scene () && !mTabletStylusIsPressed) - { - if (currentTool == UBStylusTool::Eraser) - { + if (scene () && !mTabletStylusIsPressed) { + if (currentTool == UBStylusTool::Eraser) { connect(&mLongPressTimer, SIGNAL(timeout()), this, SLOT(longPressEvent())); mLongPressTimer.start(); } - scene ()->inputDevicePress (mapToScene (UBGeometryUtils::pointConstrainedInRect (event->pos (), rect ()))); + scene()->inputDevicePress(mapToScene(UBGeometryUtils::pointConstrainedInRect(event->pos(), rect()))); } event->accept (); } @@ -1114,127 +1108,131 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event) } QTime mouseMoveTime = QTime::currentTime(); - if(!mIsDragInProgress && ((mapToScene(event->pos()) - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance())) - { + if(!mIsDragInProgress + && ((mapToScene(event->pos()) - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance())) { + qDebug() << "mouse move event canceled"; return; } mIsDragInProgress = true; - UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool (); - + mWidgetMoved = true; mLongPressTimer.stop(); - if (isAbsurdPoint (event->pos ())) - { + if (isAbsurdPoint (event->pos ())) { event->accept (); return; - } + } - if (currentTool == UBStylusTool::Hand && (mMouseButtonIsPressed || mTabletStylusIsPressed)) - { + if ((UBDrawingController::drawingController()->isDrawingTool()) + && !mMouseButtonIsPressed) { + QGraphicsView::mouseMoveEvent(event); + } + + int currentTool = static_cast(UBDrawingController::drawingController()->stylusTool()); + switch (currentTool) { + + case UBStylusTool::Hand : { + if (!mMouseButtonIsPressed && mTabletStylusIsPressed) { + break; + } QPointF eventPosition = event->posF (); qreal dx = eventPosition.x () - mPreviousPoint.x (); qreal dy = eventPosition.y () - mPreviousPoint.y (); mController->handScroll (dx, dy); mPreviousPoint = eventPosition; event->accept (); - } - else if (currentTool == UBStylusTool::Selector || currentTool == UBStylusTool::Play) - { - if((event->pos() - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance()) { - return; - } + } break; + case UBStylusTool::Selector : + case UBStylusTool::Play : { if (bIsDesktop) { event->ignore(); return; } - if (currentTool != UBStylusTool::Play || mRubberBandInPlayMode) { + bool rubberMove = currentTool != (UBStylusTool::Play || mRubberBandInPlayMode) + && (mMouseButtonIsPressed || mTabletStylusIsPressed) + && !movingItem; + + if (rubberMove) { + QRect bandRect(mMouseDownPos, event->pos()); + + bandRect = bandRect.normalized(); - if (!movingItem && (mMouseButtonIsPressed || mTabletStylusIsPressed) && mUBRubberBand && mUBRubberBand->isVisible()) { + if (!mUBRubberBand) { + mUBRubberBand = new UBRubberBand(QRubberBand::Rectangle, this); + } +// mUBRubberBand->setGeometry (QRect (mMouseDownPos, QSize ())); + mUBRubberBand->setGeometry(bandRect); + mUBRubberBand->show(); + scene()->setMultipleSelectionProcess(true); + + + QTime startTime = QTime::currentTime(); + QTime testTime = QTime::currentTime(); + QList rubberItems = items(bandRect); + qDebug() << "=================="; + qDebug() << "| ====rubber items" << testTime.msecsTo(QTime::currentTime()); + testTime = QTime::currentTime(); + foreach (QGraphicsItem *item, mJustSelectedItems) { + if (!rubberItems.contains(item)) { + item->setSelected(false); + mJustSelectedItems.remove(item); + } + } + qDebug() << "| ===foreach length" << testTime.msecsTo(QTime::currentTime()); + testTime = QTime::currentTime(); - QRect bandRect(mMouseDownPos, event->pos()); + int counter = 0; + if (currentTool == UBStylusTool::Selector) { + foreach (QGraphicsItem *item, items(bandRect)) { - bandRect = bandRect.normalized(); + if (item->type() == UBGraphicsW3CWidgetItem::Type + || item->type() == UBGraphicsPixmapItem::Type + || item->type() == UBGraphicsMediaItem::Type + || item->type() == UBGraphicsSvgItem::Type + || item->type() == UBGraphicsTextItem::Type + || item->type() == UBGraphicsStrokesGroup::Type + || item->type() == UBGraphicsGroupContainerItem::Type) { - mUBRubberBand->setGeometry(bandRect); - QTime startTime = QTime::currentTime(); - QTime testTime = QTime::currentTime(); - QList rubberItems = items(bandRect); - qDebug() << "=================="; - qDebug() << "| ====rubber items" << testTime.msecsTo(QTime::currentTime()); - testTime = QTime::currentTime(); - foreach (QGraphicsItem *item, mJustSelectedItems) { - if (!rubberItems.contains(item)) { - item->setSelected(false); - mJustSelectedItems.remove(item); - } - } - qDebug() << "| ===foreach length" << testTime.msecsTo(QTime::currentTime()); - testTime = QTime::currentTime(); - - int counter = 0; - if (currentTool == UBStylusTool::Selector) { - foreach (QGraphicsItem *item, items(bandRect)) { - - if (item->type() == UBGraphicsW3CWidgetItem::Type - || item->type() == UBGraphicsPixmapItem::Type - || item->type() == UBGraphicsMediaItem::Type - || item->type() == UBGraphicsSvgItem::Type - || item->type() == UBGraphicsTextItem::Type - || item->type() == UBGraphicsStrokesGroup::Type - || item->type() == UBGraphicsGroupContainerItem::Type) { - - - if (!mJustSelectedItems.contains(item)) { - counter++; - item->setSelected(true); - mJustSelectedItems.insert(item); - } + if (!mJustSelectedItems.contains(item)) { + counter++; item->setSelected(true); + mJustSelectedItems.insert(item); } + item->setSelected(true); } } - - qDebug() << "| ==selected items count" << counter << endl - << "| ==selection time" << testTime.msecsTo(QTime::currentTime()) << endl - << "| =elapsed time " << startTime.msecsTo(QTime::currentTime()) << endl - << "=================="; } - } + qDebug() << "| ==selected items count" << counter << endl + << "| ==selection time" << testTime.msecsTo(QTime::currentTime()) << endl + << "| =elapsed time " << startTime.msecsTo(QTime::currentTime()) << endl + << "=================="; + } handleItemMouseMove(event); - } - else if ((UBDrawingController::drawingController()->isDrawingTool()) - && !mMouseButtonIsPressed) - { - QGraphicsView::mouseMoveEvent (event); - } - else if (currentTool == UBStylusTool::Text || currentTool == UBStylusTool::Capture) - { - if (mRubberBand && (mIsCreatingTextZone || mIsCreatingSceneGrabZone)) - { - mRubberBand->setGeometry (QRect (mMouseDownPos, event->pos ()).normalized ()); - event->accept (); - } - else - { + } break; + + case UBStylusTool::Text : + case UBStylusTool::Capture : { + if (mRubberBand + && (mIsCreatingTextZone || mIsCreatingSceneGrabZone)) { + mRubberBand->setGeometry(QRect(mMouseDownPos, event->pos()).normalized()); + event->accept(); + } else { QGraphicsView::mouseMoveEvent (event); - } - } - else - { - if (!mTabletStylusIsPressed && scene ()) - { - scene ()->inputDeviceMove (mapToScene (UBGeometryUtils::pointConstrainedInRect (event->pos (), rect ())), mMouseButtonIsPressed); + } + } break; + + default: + if (!mTabletStylusIsPressed && scene()) { + scene()->inputDeviceMove(mapToScene(UBGeometryUtils::pointConstrainedInRect(event->pos(), rect())) + , mMouseButtonIsPressed); } event->accept (); - } + } - if((event->pos() - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance()) - mWidgetMoved = true; qDebug() << "mouse move time" << mouseMoveTime.msecsTo(QTime::currentTime()); lastCallTime = QTime::currentTime(); } diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 0dfcd8ba..6826a0c8 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -158,6 +158,8 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec , mDeleteButton(NULL) , mDuplicateButton(NULL) , mMenuButton(NULL) + , mZOrderUpButton(0) + , mZOrderDownButton(0) , mMenu(0) , mLockAction(0) , mShowOnDisplayAction(0) @@ -243,13 +245,10 @@ void UBGraphicsItemDelegate::createControls() void UBGraphicsItemDelegate::freeControls() { QGraphicsScene *controlsScene = delegated()->scene(); + Q_ASSERT(controlsScene); - UB_FREE_CONTROL(mFrame, controlsScene); - UB_FREE_CONTROL(mDeleteButton, controlsScene); - UB_FREE_CONTROL(mMenuButton, controlsScene); - UB_FREE_CONTROL(mZOrderUpButton, controlsScene); - UB_FREE_CONTROL(mZOrderDownButton, controlsScene); + UB_FREE_CONTROL(mFrame, controlsScene); freeButtons(); } @@ -263,7 +262,6 @@ bool UBGraphicsItemDelegate::controlsExist() const ; } - UBGraphicsItemDelegate::~UBGraphicsItemDelegate() { if (UBApplication::boardController) @@ -277,43 +275,34 @@ UBGraphicsItemDelegate::~UBGraphicsItemDelegate() QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { UBGraphicsScene *ubScene = castUBGraphicsScene(); - - if (change == QGraphicsItem::ItemSelectedHasChanged) { - bool ok; - bool selected = value.toUInt(&ok); - - if (ok) { - if (ubScene && !ubScene->multipleSelectionProcess()) { - if (selected) { + switch (static_cast(change)) { + + case QGraphicsItem::ItemSelectedHasChanged : { + if (ubScene && !ubScene->multipleSelectionProcess()) { + if (value.toBool()) { //selected(true) + if (!controlsExist()) { + createControls(); + mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom()); + positionHandles(); ubScene->setSelectedZLevel(delegated()); - } else { - ubScene->setOwnZlevel(delegated()); } + } else { + ubScene->setOwnZlevel(delegated()); + freeControls(); } } - } - if ((change == QGraphicsItem::ItemSelectedHasChanged - || change == QGraphicsItem::ItemPositionHasChanged - || change == QGraphicsItem::ItemTransformHasChanged) - && ubScene - && !ubScene->multipleSelectionProcess() - && UBApplication::boardController) - { - if (!controlsExist()) { - createControls(); - } + } break; + + case QGraphicsItem::ItemPositionHasChanged : + case QGraphicsItem::ItemTransformHasChanged : + case QGraphicsItem::ItemZValueHasChanged : mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom()); positionHandles(); - } - - if (change == QGraphicsItem::ItemPositionHasChanged - || change == QGraphicsItem::ItemTransformHasChanged - || change == QGraphicsItem::ItemZValueHasChanged) - { - UBGraphicsScene* ubScene = qobject_cast(mDelegated->scene()); - if(ubScene) + if (ubScene) { ubScene->setModified(true); + } + break; } return value; @@ -425,6 +414,10 @@ QGraphicsItem *UBGraphicsItemDelegate::delegated() void UBGraphicsItemDelegate::positionHandles() { + if (!controlsExist()) { + return; + } + if (mDelegated->isSelected()) { bool shownOnDisplay = mDelegated->data(UBGraphicsItemData::ItemLayerType).toInt() != UBItemLayerType::Control; showHide(shownOnDisplay); @@ -644,6 +637,13 @@ void UBGraphicsItemDelegate::buildButtons() } void UBGraphicsItemDelegate::freeButtons() { + //Previously deleted with the frame + // Rimplement for some specific behavior + mButtons.clear(); + mDeleteButton = 0; + mMenuButton = 0; + mZOrderUpButton = 0; + mZOrderDownButton = 0; } void UBGraphicsItemDelegate::decorateMenu(QMenu* menu) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 654e6324..51300c00 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1034,6 +1034,13 @@ UBGraphicsPolygonItem* UBGraphicsScene::arcToPolygonItem(const QLineF& pStartRad return polygonToPolygonItem(polygon); } +void UBGraphicsScene::clearSelectionFrame() +{ + if (mSelectionFrame) { + mSelectionFrame->setEnclosedItems(QList()); + } +} + void UBGraphicsScene::updateMultipleSelectionFrame() { qDebug() << "selected item count" << selectedItems().count(); diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index ce56c86c..54e0fa1a 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -311,6 +311,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem UBGraphicsPolygonItem* polygonToPolygonItem(const QPolygonF pPolygon); void setMultipleSelectionProcess(bool pEnabled) {mMultipleSelectionProcess = pEnabled;} bool multipleSelectionProcess() const {return mMultipleSelectionProcess;} + void clearSelectionFrame(); void updateMultipleSelectionFrame(); public slots: