diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 3d755d01..6bc5da91 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -597,12 +597,12 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() QList polygonItems = polygonItemsFromPolylineSvg(mScene->isDarkBackground() ? Qt::white : Qt::black); + QString newParentId = QUuid::createUuid().toString(); + foreach(UBGraphicsPolygonItem* polygonItem, polygonItems) { if (annotationGroup) - { polygonItem->setStroke(annotationGroup); - } if(strokesGroup){ @@ -614,6 +614,10 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic)); QString parentId = mXmlReader.attributes().value(mNamespaceUri, "parent").toString(); + + if(parentId.isEmpty()) + parentId = newParentId; + Q_ASSERT(!parentId.isEmpty()); UBGraphicsStrokesGroup* group; if(!mStrokesList.contains(parentId)){ @@ -623,8 +627,10 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() else group = mStrokesList.value(parentId); + group->addToGroup(polygonItem); polygonItem->show(); } + } else if (mXmlReader.name() == "image") { @@ -984,10 +990,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() { if (mXmlReader.name() == "g") { -// if(strokesGroup && mScene){ -// mScene->addItem(strokesGroup); -// } - if (annotationGroup) { if (!annotationGroup->polygons().empty()) @@ -1010,12 +1012,12 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() QMapIterator iterator(mStrokesList); while (iterator.hasNext()) { iterator.next(); + qDebug() << "Number of polygons : " << (int)(((UBGraphicsStrokesGroup*)iterator.value())->childItems().count()); mScene->addItem(iterator.value()); } - if (mScene) { + if (mScene) mScene->setModified(false); - } if (annotationGroup && annotationGroup->polygons().empty()){ delete annotationGroup; @@ -1557,17 +1559,8 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistGroupToDom(QGraphicsItem *gro foreach (QGraphicsItem *item, groupItem->childItems()) { QUuid tmpUuid = UBGraphicsScene::getPersonalUuid(item); if (!tmpUuid.isNull()) { - if (item->type() == UBGraphicsGroupContainerItem::Type && item->childItems().count()) { + if (item->type() == UBGraphicsGroupContainerItem::Type && item->childItems().count()) persistGroupToDom(item, curParent, groupDomDocument); - } -// else if (item->type() == UBGraphicsStrokesGroup::Type) { -// foreach (QGraphicsItem *polygonItem, item->childItems()) { -// QDomElement curPolygonElement = groupDomDocument->createElement(tElement); -// curPolygonElement.setAttribute(aId, tmpUuid.toString() -// + UBGraphicsItem::getOwnUuid(polygonItem).toString()); -// curGroupElement.appendChild(curPolygonElement); -// } -// } else { QDomElement curSubElement = groupDomDocument->createElement(tElement); diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 7d5a42e3..b975eef2 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -357,9 +357,7 @@ void UBBoardController::setupToolbar() void UBBoardController::setToolCursor(int tool) { if (mActiveScene) - { mActiveScene->setToolCursor(tool); - } mControlView->setToolCursor(tool); } @@ -648,7 +646,7 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item, bool bAsync) QList duplicatedItems; QList children = groupItem->childItems(); - + mActiveScene->setURStackEnable(false); foreach(QGraphicsItem* pIt, children){ UBItem* pItem = dynamic_cast(pIt); diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 0fef3ac5..01a6ad2f 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -80,217 +80,217 @@ #include "core/memcheck.h" UBBoardView::UBBoardView (UBBoardController* pController, QWidget* pParent, bool isControl, bool isDesktop) -: QGraphicsView (pParent) -, mController (pController) -, mIsCreatingTextZone (false) -, mIsCreatingSceneGrabZone (false) -, mOkOnWidget(false) -, suspendedMousePressEvent(NULL) -, mLongPressInterval(1000) -, mIsDragInProgress(false) -, mMultipleSelectionIsEnabled(false) -, bIsControl(isControl) -, bIsDesktop(isDesktop) -, mRubberBandInPlayMode(false) //enables rubberband with play tool + : QGraphicsView (pParent) + , mController (pController) + , mIsCreatingTextZone (false) + , mIsCreatingSceneGrabZone (false) + , mOkOnWidget(false) + , suspendedMousePressEvent(NULL) + , mLongPressInterval(1000) + , mIsDragInProgress(false) + , mMultipleSelectionIsEnabled(false) + , bIsControl(isControl) + , bIsDesktop(isDesktop) + , mRubberBandInPlayMode(false) //enables rubberband with play tool { - init (); + init (); - mFilterZIndex = false; + mFilterZIndex = false; - mLongPressTimer.setInterval(mLongPressInterval); - mLongPressTimer.setSingleShot(true); + mLongPressTimer.setInterval(mLongPressInterval); + mLongPressTimer.setSingleShot(true); } UBBoardView::UBBoardView (UBBoardController* pController, int pStartLayer, int pEndLayer, QWidget* pParent, bool isControl, bool isDesktop) -: QGraphicsView (pParent) -, mController (pController) -, suspendedMousePressEvent(NULL) -, mLongPressInterval(1000) -, mIsDragInProgress(false) -, mMultipleSelectionIsEnabled(false) -, bIsControl(isControl) -, bIsDesktop(isDesktop) + : QGraphicsView (pParent) + , mController (pController) + , suspendedMousePressEvent(NULL) + , mLongPressInterval(1000) + , mIsDragInProgress(false) + , mMultipleSelectionIsEnabled(false) + , bIsControl(isControl) + , bIsDesktop(isDesktop) { - init (); + init (); - mStartLayer = pStartLayer; - mEndLayer = pEndLayer; + mStartLayer = pStartLayer; + mEndLayer = pEndLayer; - mFilterZIndex = true; + mFilterZIndex = true; - mLongPressTimer.setInterval(mLongPressInterval); - mLongPressTimer.setSingleShot(true); + mLongPressTimer.setInterval(mLongPressInterval); + mLongPressTimer.setSingleShot(true); } UBBoardView::~UBBoardView () { - //NOOP + //NOOP if (suspendedMousePressEvent) delete suspendedMousePressEvent; } void UBBoardView::init () { - connect (UBSettings::settings ()->boardPenPressureSensitive, SIGNAL (changed (QVariant)), - this, SLOT (settingChanged (QVariant))); + connect (UBSettings::settings ()->boardPenPressureSensitive, SIGNAL (changed (QVariant)), + this, SLOT (settingChanged (QVariant))); - connect (UBSettings::settings ()->boardMarkerPressureSensitive, SIGNAL (changed (QVariant)), - this, SLOT (settingChanged (QVariant))); + connect (UBSettings::settings ()->boardMarkerPressureSensitive, SIGNAL (changed (QVariant)), + this, SLOT (settingChanged (QVariant))); - connect (UBSettings::settings ()->boardUseHighResTabletEvent, SIGNAL (changed (QVariant)), - this, SLOT (settingChanged (QVariant))); + connect (UBSettings::settings ()->boardUseHighResTabletEvent, SIGNAL (changed (QVariant)), + this, SLOT (settingChanged (QVariant))); - setWindowFlags (Qt::FramelessWindowHint); - setFrameStyle (QFrame::NoFrame); - setRenderHints (QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing); - setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff); - setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff); - setAcceptDrops (true); + setWindowFlags (Qt::FramelessWindowHint); + setFrameStyle (QFrame::NoFrame); + setRenderHints (QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing); + setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff); + setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff); + setAcceptDrops (true); - setOptimizationFlag (QGraphicsView::IndirectPainting); // enable UBBoardView::drawItems filter + setOptimizationFlag (QGraphicsView::IndirectPainting); // enable UBBoardView::drawItems filter - mTabletStylusIsPressed = false; - mMouseButtonIsPressed = false; - mPendingStylusReleaseEvent = false; + mTabletStylusIsPressed = false; + mMouseButtonIsPressed = false; + mPendingStylusReleaseEvent = false; - setCacheMode (QGraphicsView::CacheBackground); + setCacheMode (QGraphicsView::CacheBackground); - mUsingTabletEraser = false; - mIsCreatingTextZone = false; - mRubberBand = 0; - mUBRubberBand = 0; + mUsingTabletEraser = false; + mIsCreatingTextZone = false; + mRubberBand = 0; + mUBRubberBand = 0; - mVirtualKeyboardActive = false; + mVirtualKeyboardActive = false; - settingChanged (QVariant ()); + settingChanged (QVariant ()); - unsetCursor(); + unsetCursor(); - movingItem = NULL; - mWidgetMoved = false; + movingItem = NULL; + mWidgetMoved = false; } UBGraphicsScene* UBBoardView::scene () { - return qobject_cast (QGraphicsView::scene ()); + return qobject_cast (QGraphicsView::scene ()); } void UBBoardView::hideEvent (QHideEvent * event) { - Q_UNUSED (event); - emit hidden (); + Q_UNUSED (event); + emit hidden (); } void UBBoardView::showEvent (QShowEvent * event) { - Q_UNUSED (event); - emit shown (); + Q_UNUSED (event); + emit shown (); } void UBBoardView::keyPressEvent (QKeyEvent *event) { - // send to the scene anyway - QApplication::sendEvent (scene (), event); + // send to the scene anyway + QApplication::sendEvent (scene (), event); - if (!event->isAccepted ()) + if (!event->isAccepted ()) { - switch (event->key ()) + switch (event->key ()) { case Qt::Key_Up: case Qt::Key_PageUp: case Qt::Key_Left: - { + { mController->previousScene (); break; - } + } case Qt::Key_Down: case Qt::Key_PageDown: case Qt::Key_Right: case Qt::Key_Space: - { + { mController->nextScene (); break; - } + } case Qt::Key_Home: - { + { mController->firstScene (); break; - } + } case Qt::Key_End: - { + { mController->lastScene (); break; - } + } case Qt::Key_Insert: - { + { mController->addScene (); break; - } + } case Qt::Key_Control: case Qt::Key_Shift: - { + { setMultiselection(true); - }break; + }break; } - if (event->modifiers () & Qt::ControlModifier) // keep only ctrl/cmd keys + if (event->modifiers () & Qt::ControlModifier) // keep only ctrl/cmd keys { - switch (event->key ()) + switch (event->key ()) { case Qt::Key_Plus: case Qt::Key_I: - { + { mController->zoomIn (); event->accept (); break; - } + } case Qt::Key_Minus: case Qt::Key_O: - { + { mController->zoomOut (); event->accept (); break; - } + } case Qt::Key_0: - { + { mController->zoomRestore (); event->accept (); break; - } + } case Qt::Key_Left: - { + { mController->handScroll (-100, 0); event->accept (); break; - } + } case Qt::Key_Right: - { + { mController->handScroll (100, 0); event->accept (); break; - } + } case Qt::Key_Up: - { + { mController->handScroll (0, -100); event->accept (); break; - } + } case Qt::Key_Down: - { + { mController->handScroll (0, 100); event->accept (); break; - } + } default: - { + { // NOOP - } + } } } } @@ -303,10 +303,10 @@ UBBoardView::keyPressEvent (QKeyEvent *event) void UBBoardView::keyReleaseEvent(QKeyEvent *event) { - // if (!event->isAccepted ()) + // if (!event->isAccepted ()) { if (Qt::Key_Shift == event->key() - ||Qt::Key_Control == event->key()) + ||Qt::Key_Control == event->key()) { setMultiselection(false); } @@ -318,30 +318,30 @@ void UBBoardView::keyReleaseEvent(QKeyEvent *event) bool UBBoardView::event (QEvent * e) { - if (e->type () == QEvent::Gesture) + if (e->type () == QEvent::Gesture) { - QGestureEvent *gestureEvent = dynamic_cast (e); - if (gestureEvent) + QGestureEvent *gestureEvent = dynamic_cast (e); + if (gestureEvent) { - QSwipeGesture* swipe = dynamic_cast (gestureEvent->gesture (Qt::SwipeGesture)); - if (swipe) + QSwipeGesture* swipe = dynamic_cast (gestureEvent->gesture (Qt::SwipeGesture)); + if (swipe) { - if (swipe->horizontalDirection () == QSwipeGesture::Left) + if (swipe->horizontalDirection () == QSwipeGesture::Left) { - mController->previousScene (); - gestureEvent->setAccepted (swipe, true); + mController->previousScene (); + gestureEvent->setAccepted (swipe, true); } - if (swipe->horizontalDirection () == QSwipeGesture::Right) + if (swipe->horizontalDirection () == QSwipeGesture::Right) { - mController->nextScene (); - gestureEvent->setAccepted (swipe, true); + mController->nextScene (); + gestureEvent->setAccepted (swipe, true); } } } } - return QGraphicsView::event (e); + return QGraphicsView::event (e); } void UBBoardView::tabletEvent (QTabletEvent * event) @@ -474,20 +474,20 @@ bool UBBoardView::isUBItem(QGraphicsItem *item) bool UBBoardView::isCppTool(QGraphicsItem *item) { return (item->type() == UBGraphicsItemType::CompassItemType - || item->type() == UBGraphicsItemType::RulerItemType - || item->type() == UBGraphicsItemType::ProtractorItemType - || item->type() == UBGraphicsItemType::TriangleItemType - || item->type() == UBGraphicsItemType::CurtainItemType); + || item->type() == UBGraphicsItemType::RulerItemType + || item->type() == UBGraphicsItemType::ProtractorItemType + || item->type() == UBGraphicsItemType::TriangleItemType + || item->type() == UBGraphicsItemType::CurtainItemType); } void UBBoardView::handleItemsSelection(QGraphicsItem *item) { -// we need to select new pressed itemOnBoard and deselect all other items. -// the trouble is in: -// some items can has parents (groupped items or strokes, or strokes in groups). -// some items is already selected and we don't need to reselect them -// -// item selection managed by QGraphicsView::mousePressEvent(). It should be called later. + // we need to select new pressed itemOnBoard and deselect all other items. + // the trouble is in: + // some items can has parents (groupped items or strokes, or strokes in groups). + // some items is already selected and we don't need to reselect them + // + // item selection managed by QGraphicsView::mousePressEvent(). It should be called later. if (item) { @@ -530,7 +530,7 @@ void UBBoardView::handleItemsSelection(QGraphicsItem *item) bool UBBoardView::itemShouldReceiveMousePressEvent(QGraphicsItem *item) { -/* + /* Some items should receive mouse press events averytime, some items should receive that events when they are selected, some items shouldn't receive mouse press events at mouse press, but should receive them at mouse release (suspended mouse press event) @@ -570,6 +570,8 @@ Here we determines cases when items should to get mouse press event at pressing case UBGraphicsSvgItem::Type: case UBGraphicsPixmapItem::Type: case UBGraphicsTextItem::Type: + if (currentTool == UBStylusTool::Play) + return true; if ((currentTool == UBStylusTool::Selector) && item->isSelected()) return true; if ((currentTool == UBStylusTool::Selector) && item->parentItem() && item->parentItem()->isSelected()) @@ -577,19 +579,19 @@ Here we determines cases when items should to get mouse press event at pressing if (currentTool != UBStylusTool::Selector) return false; break; - - // Groups shouldn't reacts on any presses and moves for Play tool. + case UBGraphicsItemType::StrokeItemType: + if (currentTool == UBStylusTool::Play) + return true; + break; case UBGraphicsGroupContainerItem::Type: + // Groups shouldn't reacts on any presses and moves for Play tool. if(currentTool == UBStylusTool::Play) { movingItem = NULL; + return true; } return false; break; - - //case UBToolWidget::Type: - // return true; - case QGraphicsWebView::Type: return true; @@ -693,9 +695,9 @@ QGraphicsItem* UBBoardView::determineItemToPress(QGraphicsItem *item) // if item is on group and group is not selected - group should take press. if (UBStylusTool::Selector == currentTool - && item->parentItem() - && UBGraphicsGroupContainerItem::Type == item->parentItem()->type() - && !item->parentItem()->isSelected()) + && item->parentItem() + && UBGraphicsGroupContainerItem::Type == item->parentItem()->type() + && !item->parentItem()->isSelected()) return item->parentItem(); // items like polygons placed in two groups nested, so we need to recursive call. @@ -715,7 +717,7 @@ QGraphicsItem* UBBoardView::determineItemToMove(QGraphicsItem *item) //W3C widgets should take mouse move events from play tool. if ((UBStylusTool::Play == currentTool) && (UBGraphicsWidgetItem::Type == item->type())) - return item; + return item; // if item is in group if(item->parentItem() && UBGraphicsGroupContainerItem::Type == item->parentItem()->type()) @@ -759,12 +761,10 @@ void UBBoardView::handleItemMousePress(QMouseEvent *event) if (isMultipleSelectionEnabled()) return; - if (itemShouldReceiveMousePressEvent(movingItem)) - { + if (itemShouldReceiveMousePressEvent(movingItem)) { QGraphicsView::mousePressEvent (event); } - else - { + else { if (movingItem) { UBGraphicsItem *graphicsItem = dynamic_cast(movingItem); @@ -813,7 +813,7 @@ void UBBoardView::handleItemMouseMove(QMouseEvent *event) QGraphicsView::mouseMoveEvent (event); if (movingItem) - posAfterMove = movingItem->pos(); + posAfterMove = movingItem->pos(); mWidgetMoved = ((posAfterMove-posBeforeMove).manhattanLength() != 0); @@ -845,14 +845,14 @@ void UBBoardView::moveRubberedItems(QPointF movingVector) { 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) + || item->type() == UBGraphicsPixmapItem::Type + || item->type() == UBGraphicsMediaItem::Type + || item->type() == UBGraphicsSvgItem::Type + || item->type() == UBGraphicsTextItem::Type + || item->type() == UBGraphicsStrokesGroup::Type + || item->type() == UBGraphicsGroupContainerItem::Type) { - item->setPos(item->pos()+movingVector); + item->setPos(item->pos()+movingVector); } } @@ -866,26 +866,26 @@ void UBBoardView::setMultiselection(bool enable) void UBBoardView::longPressEvent() { - UBDrawingController *drawingController = UBDrawingController::drawingController(); - UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool (); + UBDrawingController *drawingController = UBDrawingController::drawingController(); + UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool (); - disconnect(&mLongPressTimer, SIGNAL(timeout()), this, SLOT(longPressEvent())); + disconnect(&mLongPressTimer, SIGNAL(timeout()), this, SLOT(longPressEvent())); - if (UBStylusTool::Selector == currentTool) - { + if (UBStylusTool::Selector == currentTool) + { drawingController->setStylusTool(UBStylusTool::Play); - } - else - if (currentTool == UBStylusTool::Play) - { - drawingController->setStylusTool(UBStylusTool::Selector); - } - else - if (UBStylusTool::Eraser == currentTool) - { - UBApplication::boardController->paletteManager()->toggleErasePalette(true); - } + } + else + if (currentTool == UBStylusTool::Play) + { + drawingController->setStylusTool(UBStylusTool::Selector); + } + else + if (UBStylusTool::Eraser == currentTool) + { + UBApplication::boardController->paletteManager()->toggleErasePalette(true); + } } @@ -898,8 +898,7 @@ void UBBoardView::mousePressEvent (QMouseEvent *event) mIsDragInProgress = false; - if (isAbsurdPoint (event->pos ())) - { + if (isAbsurdPoint (event->pos ())) { event->accept (); return; } @@ -935,8 +934,7 @@ void UBBoardView::mousePressEvent (QMouseEvent *event) mPreviousPoint = event->posF (); event->accept (); } - else if (currentTool == UBStylusTool::Selector || currentTool == UBStylusTool::Play) - { + else if (currentTool == UBStylusTool::Selector || currentTool == UBStylusTool::Play) { if (bIsDesktop) { event->ignore(); return; @@ -957,8 +955,7 @@ void UBBoardView::mousePressEvent (QMouseEvent *event) mUBRubberBand->setGeometry (QRect (mMouseDownPos, QSize ())); mUBRubberBand->show(); } - else - { + else { if(mUBRubberBand) mUBRubberBand->hide(); } @@ -1035,110 +1032,110 @@ void UBBoardView::mousePressEvent (QMouseEvent *event) void UBBoardView::mouseMoveEvent (QMouseEvent *event) { - if(!mIsDragInProgress && ((mapToScene(event->pos()) - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance())) - { - return; - } + if(!mIsDragInProgress && ((mapToScene(event->pos()) - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance())) + { + return; + } - mIsDragInProgress = true; - UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool (); + mIsDragInProgress = true; + UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool (); - mLongPressTimer.stop(); + mLongPressTimer.stop(); - if (isAbsurdPoint (event->pos ())) + if (isAbsurdPoint (event->pos ())) { - event->accept (); - return; + event->accept (); + return; } - if (currentTool == UBStylusTool::Hand && (mMouseButtonIsPressed || mTabletStylusIsPressed)) + if (currentTool == UBStylusTool::Hand && (mMouseButtonIsPressed || mTabletStylusIsPressed)) { - QPointF eventPosition = event->posF (); - qreal dx = eventPosition.x () - mPreviousPoint.x (); - qreal dy = eventPosition.y () - mPreviousPoint.y (); - mController->handScroll (dx, dy); - mPreviousPoint = eventPosition; - event->accept (); + 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; - } - - if (bIsDesktop) { - event->ignore(); - return; - } - - if (currentTool != UBStylusTool::Play || mRubberBandInPlayMode) { - - if (!movingItem && (mMouseButtonIsPressed || mTabletStylusIsPressed) && mUBRubberBand && mUBRubberBand->isVisible()) { - - QRect bandRect(mMouseDownPos, event->pos()); - - bandRect = bandRect.normalized(); - - mUBRubberBand->setGeometry(bandRect); - - QList rubberItems = items(bandRect); - foreach (QGraphicsItem *item, mJustSelectedItems) { - if (!rubberItems.contains(item)) { - item->setSelected(false); - mJustSelectedItems.remove(item); - } - } - - 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)) { - item->setSelected(true); - mJustSelectedItems.insert(item); - } - } - } - } - } - - handleItemMouseMove(event); + else if (currentTool == UBStylusTool::Selector || currentTool == UBStylusTool::Play) + { + if((event->pos() - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance()) { + return; + } + + if (bIsDesktop) { + event->ignore(); + return; + } + + if (currentTool != UBStylusTool::Play || mRubberBandInPlayMode) { + + if (!movingItem && (mMouseButtonIsPressed || mTabletStylusIsPressed) && mUBRubberBand && mUBRubberBand->isVisible()) { + + QRect bandRect(mMouseDownPos, event->pos()); + + bandRect = bandRect.normalized(); + + mUBRubberBand->setGeometry(bandRect); + + QList rubberItems = items(bandRect); + foreach (QGraphicsItem *item, mJustSelectedItems) { + if (!rubberItems.contains(item)) { + item->setSelected(false); + mJustSelectedItems.remove(item); + } + } + + 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)) { + item->setSelected(true); + mJustSelectedItems.insert(item); + } + } + } + } + } + + handleItemMouseMove(event); + } + else if ((UBDrawingController::drawingController()->isDrawingTool()) + && !mMouseButtonIsPressed) + { + QGraphicsView::mouseMoveEvent (event); } - else if ((UBDrawingController::drawingController()->isDrawingTool()) - && !mMouseButtonIsPressed) - { - QGraphicsView::mouseMoveEvent (event); - } - else if (currentTool == UBStylusTool::Text || currentTool == UBStylusTool::Capture) + else if (currentTool == UBStylusTool::Text || currentTool == UBStylusTool::Capture) { - if (mRubberBand && (mIsCreatingTextZone || mIsCreatingSceneGrabZone)) + if (mRubberBand && (mIsCreatingTextZone || mIsCreatingSceneGrabZone)) { - mRubberBand->setGeometry (QRect (mMouseDownPos, event->pos ()).normalized ()); - event->accept (); + mRubberBand->setGeometry (QRect (mMouseDownPos, event->pos ()).normalized ()); + event->accept (); } - else + else { - QGraphicsView::mouseMoveEvent (event); + QGraphicsView::mouseMoveEvent (event); } } - else + else { - if (!mTabletStylusIsPressed && scene ()) - { - scene ()->inputDeviceMove (mapToScene (UBGeometryUtils::pointConstrainedInRect (event->pos (), rect ())), mMouseButtonIsPressed); - } - event->accept (); + if (!mTabletStylusIsPressed && scene ()) + { + scene ()->inputDeviceMove (mapToScene (UBGeometryUtils::pointConstrainedInRect (event->pos (), rect ())), mMouseButtonIsPressed); + } + event->accept (); } - if((event->pos() - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance()) - mWidgetMoved = true; + if((event->pos() - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance()) + mWidgetMoved = true; } void @@ -1146,207 +1143,199 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event) { UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool (); - setToolCursor (currentTool); - // first/ propagate device release to the scene - if (scene ()) - scene ()->inputDeviceRelease (); - - if (currentTool == UBStylusTool::Selector) - { - if (bIsDesktop) { - event->ignore(); - return; - } - - UBGraphicsItem *graphicsItem = dynamic_cast(movingItem); - if (graphicsItem) - graphicsItem->Delegate()->commitUndoStep(); - - bool bReleaseIsNeed = true; - if (movingItem != determineItemToPress(scene()->itemAt(this->mapToScene(event->posF().toPoint())))) - { - movingItem = NULL; - bReleaseIsNeed = false; - } - if (mWidgetMoved) - { - mWidgetMoved = false; - movingItem = NULL; - } - else - if (movingItem && (!isCppTool(movingItem) || UBGraphicsCurtainItem::Type == movingItem->type())) - { - if (suspendedMousePressEvent) - { - QGraphicsView::mousePressEvent(suspendedMousePressEvent); // suspendedMousePressEvent is deleted by old Qt event loop - movingItem = NULL; - delete suspendedMousePressEvent; - suspendedMousePressEvent = NULL; - bReleaseIsNeed = true; - } - else - { - if (isUBItem(movingItem) && - DelegateButton::Type != movingItem->type() && - QGraphicsSvgItem::Type != movingItem->type() && - UBGraphicsDelegateFrame::Type != movingItem->type() && - UBGraphicsCache::Type != movingItem->type() && - QGraphicsWebView::Type != movingItem->type() && // for W3C widgets as Tools. - !(!isMultipleSelectionEnabled() && movingItem->parentItem() && UBGraphicsWidgetItem::Type == movingItem->type() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type())) - { - bReleaseIsNeed = false; - if (movingItem->isSelected() && isMultipleSelectionEnabled()) - movingItem->setSelected(false); - else - if (movingItem->parentItem() && movingItem->parentItem()->isSelected() && isMultipleSelectionEnabled()) - movingItem->parentItem()->setSelected(false); - else - { - if (movingItem->isSelected()) - bReleaseIsNeed = true; - - movingItem->setSelected(true); - } - - } - } - } - else - bReleaseIsNeed = true; - - if (mUBRubberBand && mUBRubberBand->isVisible()) { - mUBRubberBand->hide(); - } - - if (bReleaseIsNeed) - { - QGraphicsView::mouseReleaseEvent (event); - } - } - else if (currentTool == UBStylusTool::Play) - { - if (bIsDesktop) { - event->ignore(); - return; - } - - if (mWidgetMoved) - { - movingItem = NULL; - mWidgetMoved = false; - } - else - { - if (suspendedMousePressEvent) - { - QGraphicsView::mousePressEvent(suspendedMousePressEvent); // suspendedMousePressEvent is deleted by old Qt event loop - movingItem = NULL; - delete suspendedMousePressEvent; - suspendedMousePressEvent = NULL; - } - } - QGraphicsView::mouseReleaseEvent (event); - } - else if (currentTool == UBStylusTool::Text) + setToolCursor (currentTool); + // first/ propagate device release to the scene + if (scene ()) + scene ()->inputDeviceRelease (); + + if (currentTool == UBStylusTool::Selector) { - if (mRubberBand) - mRubberBand->hide (); + if (bIsDesktop) { + event->ignore(); + return; + } - if (scene () && mRubberBand && mIsCreatingTextZone) - { - QRect rubberRect = mRubberBand->geometry (); + UBGraphicsItem *graphicsItem = dynamic_cast(movingItem); + if (graphicsItem) + graphicsItem->Delegate()->commitUndoStep(); - UBGraphicsTextItem* textItem = scene()->addTextHtml ("", mapToScene (rubberRect.topLeft ())); - event->accept (); + bool bReleaseIsNeed = true; + if (movingItem != determineItemToPress(scene()->itemAt(this->mapToScene(event->posF().toPoint())))) + { + movingItem = NULL; + bReleaseIsNeed = false; + } + if (mWidgetMoved) + { + mWidgetMoved = false; + movingItem = NULL; + } + else + if (movingItem && (!isCppTool(movingItem) || UBGraphicsCurtainItem::Type == movingItem->type())) + { + if (suspendedMousePressEvent) + { + QGraphicsView::mousePressEvent(suspendedMousePressEvent); // suspendedMousePressEvent is deleted by old Qt event loop + movingItem = NULL; + delete suspendedMousePressEvent; + suspendedMousePressEvent = NULL; + bReleaseIsNeed = true; + } + else + { + if (isUBItem(movingItem) && + DelegateButton::Type != movingItem->type() && + QGraphicsSvgItem::Type != movingItem->type() && + UBGraphicsDelegateFrame::Type != movingItem->type() && + UBGraphicsCache::Type != movingItem->type() && + QGraphicsWebView::Type != movingItem->type() && // for W3C widgets as Tools. + !(!isMultipleSelectionEnabled() && movingItem->parentItem() && UBGraphicsWidgetItem::Type == movingItem->type() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type())) + { + bReleaseIsNeed = false; + if (movingItem->isSelected() && isMultipleSelectionEnabled()) + movingItem->setSelected(false); + else + if (movingItem->parentItem() && movingItem->parentItem()->isSelected() && isMultipleSelectionEnabled()) + movingItem->parentItem()->setSelected(false); + else + { + if (movingItem->isSelected()) + bReleaseIsNeed = true; + + movingItem->setSelected(true); + } - UBDrawingController::drawingController ()->setStylusTool (UBStylusTool::Selector); + } + } + } + else + bReleaseIsNeed = true; - textItem->setSelected (true); - textItem->setFocus(); + if (mUBRubberBand && mUBRubberBand->isVisible()) { + mUBRubberBand->hide(); } - else + + if (bReleaseIsNeed) { - QGraphicsView::mouseReleaseEvent (event); + QGraphicsView::mouseReleaseEvent (event); + } + } + else if (currentTool == UBStylusTool::Play) { + if (bIsDesktop) { + event->ignore(); + return; } - mIsCreatingTextZone = false; + if (mWidgetMoved) { + movingItem = NULL; + mWidgetMoved = false; + } + else { + if (suspendedMousePressEvent) { + QGraphicsView::mousePressEvent(suspendedMousePressEvent); // suspendedMousePressEvent is deleted by old Qt event loop + movingItem = NULL; + delete suspendedMousePressEvent; + suspendedMousePressEvent = NULL; + } + } + QGraphicsView::mouseReleaseEvent (event); + } + else if (currentTool == UBStylusTool::Text) { + if (mRubberBand) + mRubberBand->hide (); + + if (scene () && mRubberBand && mIsCreatingTextZone) { + QRect rubberRect = mRubberBand->geometry (); + + UBGraphicsTextItem* textItem = scene()->addTextHtml ("", mapToScene (rubberRect.topLeft ())); + event->accept (); + + UBDrawingController::drawingController ()->setStylusTool (UBStylusTool::Selector); + + textItem->setSelected (true); + textItem->setFocus(); + } + else + QGraphicsView::mouseReleaseEvent (event); + + mIsCreatingTextZone = false; } - else if (currentTool == UBStylusTool::Capture) + else if (currentTool == UBStylusTool::Capture) { - if (mRubberBand) - mRubberBand->hide (); + if (mRubberBand) + mRubberBand->hide (); - if (scene () && mRubberBand && mIsCreatingSceneGrabZone && mRubberBand->geometry ().width () > 16) + if (scene () && mRubberBand && mIsCreatingSceneGrabZone && mRubberBand->geometry ().width () > 16) { - QRect rect = mRubberBand->geometry (); - QPointF sceneTopLeft = mapToScene (rect.topLeft ()); - QPointF sceneBottomRight = mapToScene (rect.bottomRight ()); - QRectF sceneRect (sceneTopLeft, sceneBottomRight); + QRect rect = mRubberBand->geometry (); + QPointF sceneTopLeft = mapToScene (rect.topLeft ()); + QPointF sceneBottomRight = mapToScene (rect.bottomRight ()); + QRectF sceneRect (sceneTopLeft, sceneBottomRight); - mController->grabScene (sceneRect); + mController->grabScene (sceneRect); - event->accept (); + event->accept (); } - else + else { - QGraphicsView::mouseReleaseEvent (event); + QGraphicsView::mouseReleaseEvent (event); } - mIsCreatingSceneGrabZone = false; + mIsCreatingSceneGrabZone = false; } - else + else { - if (mPendingStylusReleaseEvent || mMouseButtonIsPressed) + if (mPendingStylusReleaseEvent || mMouseButtonIsPressed) { - event->accept (); + event->accept (); } } - mMouseButtonIsPressed = false; - mPendingStylusReleaseEvent = false; - mTabletStylusIsPressed = false; - movingItem = NULL; + mMouseButtonIsPressed = false; + mPendingStylusReleaseEvent = false; + mTabletStylusIsPressed = false; + movingItem = NULL; - mLongPressTimer.stop(); + mLongPressTimer.stop(); } void UBBoardView::forcedTabletRelease () { - if (mMouseButtonIsPressed || mTabletStylusIsPressed || mPendingStylusReleaseEvent) + if (mMouseButtonIsPressed || mTabletStylusIsPressed || mPendingStylusReleaseEvent) { - qWarning () << "dirty mouse/tablet state:"; - qWarning () << "mMouseButtonIsPressed =" << mMouseButtonIsPressed; - qWarning () << "mTabletStylusIsPressed = " << mTabletStylusIsPressed; - qWarning () << "mPendingStylusReleaseEvent" << mPendingStylusReleaseEvent; - qWarning () << "forcing device release"; + qWarning () << "dirty mouse/tablet state:"; + qWarning () << "mMouseButtonIsPressed =" << mMouseButtonIsPressed; + qWarning () << "mTabletStylusIsPressed = " << mTabletStylusIsPressed; + qWarning () << "mPendingStylusReleaseEvent" << mPendingStylusReleaseEvent; + qWarning () << "forcing device release"; - scene ()->inputDeviceRelease (); + scene ()->inputDeviceRelease (); - mMouseButtonIsPressed = false; - mTabletStylusIsPressed = false; - mPendingStylusReleaseEvent = false; + mMouseButtonIsPressed = false; + mTabletStylusIsPressed = false; + mPendingStylusReleaseEvent = false; } } void UBBoardView::mouseDoubleClickEvent (QMouseEvent *event) { - // We don't want a double click, we want two clicks - mousePressEvent (event); + // We don't want a double click, we want two clicks + mousePressEvent (event); } void UBBoardView::wheelEvent (QWheelEvent *wheelEvent) { - if (isInteractive () && wheelEvent->orientation () == Qt::Vertical) + if (isInteractive () && wheelEvent->orientation () == Qt::Vertical) { - // Too many wheelEvent are sent, how should we handle them to "smoothly" zoom ? - // something like zoom( pow(zoomFactor, event->delta() / 120) ) + // Too many wheelEvent are sent, how should we handle them to "smoothly" zoom ? + // something like zoom( pow(zoomFactor, event->delta() / 120) ) - // use DateTime man, store last event time, and if if less than 300ms than this is one big scroll - // and move scroll with one const speed. + // use DateTime man, store last event time, and if if less than 300ms than this is one big scroll + // and move scroll with one const speed. // so, you no will related with scroll event count } @@ -1375,10 +1364,10 @@ UBBoardView::wheelEvent (QWheelEvent *wheelEvent) void UBBoardView::leaveEvent (QEvent * event) { - if (scene ()) - scene ()->leaveEvent (event); + if (scene ()) + scene ()->leaveEvent (event); - QGraphicsView::leaveEvent (event); + QGraphicsView::leaveEvent (event); } void @@ -1386,39 +1375,39 @@ UBBoardView::drawItems (QPainter *painter, int numItems, QGraphicsItem* items[], const QStyleOptionGraphicsItem options[]) { - if (!mFilterZIndex) + if (!mFilterZIndex) { - QGraphicsView::drawItems (painter, numItems, items, options); + QGraphicsView::drawItems (painter, numItems, items, options); } - else + else { - int count = 0; + int count = 0; - QGraphicsItem** itemsFiltered = new QGraphicsItem*[numItems]; - QStyleOptionGraphicsItem *optionsFiltered = new QStyleOptionGraphicsItem[numItems]; + QGraphicsItem** itemsFiltered = new QGraphicsItem*[numItems]; + QStyleOptionGraphicsItem *optionsFiltered = new QStyleOptionGraphicsItem[numItems]; - for (int i = 0; i < numItems; i++) + for (int i = 0; i < numItems; i++) { - if (shouldDisplayItem (items[i])) + if (shouldDisplayItem (items[i])) { - itemsFiltered[count] = items[i]; - optionsFiltered[count] = options[i]; - count++; + itemsFiltered[count] = items[i]; + optionsFiltered[count] = options[i]; + count++; } } - QGraphicsView::drawItems (painter, count, itemsFiltered, optionsFiltered); + QGraphicsView::drawItems (painter, count, itemsFiltered, optionsFiltered); - delete[] optionsFiltered; - delete[] itemsFiltered; + delete[] optionsFiltered; + delete[] itemsFiltered; } } void UBBoardView::dragMoveEvent(QDragMoveEvent *event) { - QGraphicsView::dragMoveEvent(event); - event->acceptProposedAction(); + QGraphicsView::dragMoveEvent(event); + event->acceptProposedAction(); } void UBBoardView::dropEvent (QDropEvent *event) @@ -1447,94 +1436,94 @@ void UBBoardView::dropEvent (QDropEvent *event) void UBBoardView::resizeEvent (QResizeEvent * event) { - const qreal maxWidth = width () * 10; - const qreal maxHeight = height () * 10; + const qreal maxWidth = width () * 10; + const qreal maxHeight = height () * 10; - setSceneRect (-(maxWidth / 2), -(maxHeight / 2), maxWidth, maxHeight); - centerOn (0, 0); + setSceneRect (-(maxWidth / 2), -(maxHeight / 2), maxWidth, maxHeight); + centerOn (0, 0); - emit resized (event); + emit resized (event); } void UBBoardView::drawBackground (QPainter *painter, const QRectF &rect) { - if (testAttribute (Qt::WA_TranslucentBackground)) + if (testAttribute (Qt::WA_TranslucentBackground)) { - QGraphicsView::drawBackground (painter, rect); - return; + QGraphicsView::drawBackground (painter, rect); + return; } - bool darkBackground = scene () && scene ()->isDarkBackground (); + bool darkBackground = scene () && scene ()->isDarkBackground (); - if (darkBackground) + if (darkBackground) { - painter->fillRect (rect, QBrush (QColor (Qt::black))); + painter->fillRect (rect, QBrush (QColor (Qt::black))); } - else + else { - painter->fillRect (rect, QBrush (QColor (Qt::white))); + painter->fillRect (rect, QBrush (QColor (Qt::white))); } - if (transform ().m11 () > 0.5) + if (transform ().m11 () > 0.5) { - QColor bgCrossColor; + QColor bgCrossColor; - if (darkBackground) - bgCrossColor = UBSettings::crossDarkBackground; - else - bgCrossColor = UBSettings::crossLightBackground; + if (darkBackground) + bgCrossColor = UBSettings::crossDarkBackground; + else + bgCrossColor = UBSettings::crossLightBackground; - if (transform ().m11 () < 1.0) + if (transform ().m11 () < 1.0) { - int alpha = 255 * transform ().m11 () / 2; - bgCrossColor.setAlpha (alpha); // fade the crossing on small zooms + int alpha = 255 * transform ().m11 () / 2; + bgCrossColor.setAlpha (alpha); // fade the crossing on small zooms } - painter->setPen (bgCrossColor); + painter->setPen (bgCrossColor); - if (scene () && scene ()->isCrossedBackground ()) + if (scene () && scene ()->isCrossedBackground ()) { - qreal firstY = ((int) (rect.y () / UBSettings::crossSize)) * UBSettings::crossSize; + qreal firstY = ((int) (rect.y () / UBSettings::crossSize)) * UBSettings::crossSize; - for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += UBSettings::crossSize) + for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += UBSettings::crossSize) { - painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos); + painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos); } - qreal firstX = ((int) (rect.x () / UBSettings::crossSize)) * UBSettings::crossSize; + qreal firstX = ((int) (rect.x () / UBSettings::crossSize)) * UBSettings::crossSize; - for (qreal xPos = firstX; xPos < rect.x () + rect.width (); xPos += UBSettings::crossSize) + for (qreal xPos = firstX; xPos < rect.x () + rect.width (); xPos += UBSettings::crossSize) { - painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ()); + painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ()); } } } - if (!mFilterZIndex && scene ()) + if (!mFilterZIndex && scene ()) { - QSize pageNominalSize = scene ()->nominalSize (); + QSize pageNominalSize = scene ()->nominalSize (); - if (pageNominalSize.isValid ()) + if (pageNominalSize.isValid ()) { - qreal penWidth = 8.0 / transform ().m11 (); + qreal penWidth = 8.0 / transform ().m11 (); - QRectF pageRect (pageNominalSize.width () / -2, pageNominalSize.height () / -2 - , pageNominalSize.width (), pageNominalSize.height ()); + QRectF pageRect (pageNominalSize.width () / -2, pageNominalSize.height () / -2 + , pageNominalSize.width (), pageNominalSize.height ()); - pageRect.adjust (-penWidth / 2, -penWidth / 2, penWidth / 2, penWidth / 2); + pageRect.adjust (-penWidth / 2, -penWidth / 2, penWidth / 2, penWidth / 2); - QColor docSizeColor; + QColor docSizeColor; - if (darkBackground) - docSizeColor = UBSettings::documentSizeMarkColorDarkBackground; - else - docSizeColor = UBSettings::documentSizeMarkColorLightBackground; + if (darkBackground) + docSizeColor = UBSettings::documentSizeMarkColorDarkBackground; + else + docSizeColor = UBSettings::documentSizeMarkColorLightBackground; - QPen pen (docSizeColor); - pen.setWidth (penWidth); - painter->setPen (pen); - painter->drawRect (pageRect); + QPen pen (docSizeColor); + pen.setWidth (penWidth); + painter->setPen (pen); + painter->drawRect (pageRect); } } } @@ -1542,11 +1531,11 @@ UBBoardView::drawBackground (QPainter *painter, const QRectF &rect) void UBBoardView::settingChanged (QVariant newValue) { - Q_UNUSED (newValue); + Q_UNUSED (newValue); - mPenPressureSensitive = UBSettings::settings ()->boardPenPressureSensitive->get ().toBool (); - mMarkerPressureSensitive = UBSettings::settings ()->boardMarkerPressureSensitive->get ().toBool (); - mUseHighResTabletEvent = UBSettings::settings ()->boardUseHighResTabletEvent->get ().toBool (); + mPenPressureSensitive = UBSettings::settings ()->boardPenPressureSensitive->get ().toBool (); + mMarkerPressureSensitive = UBSettings::settings ()->boardMarkerPressureSensitive->get ().toBool (); + mUseHighResTabletEvent = UBSettings::settings ()->boardUseHighResTabletEvent->get ().toBool (); } void UBBoardView::virtualKeyboardActivated(bool b) @@ -1566,8 +1555,8 @@ bool UBBoardView::isAbsurdPoint(QPoint point) for (int i = 0; i < desktop->numScreens (); i++) { - QRect screenRect = desktop->screenGeometry (i); - isValidPoint = isValidPoint || screenRect.contains (mapToGlobal(point)); + QRect screenRect = desktop->screenGeometry (i); + isValidPoint = isValidPoint || screenRect.contains (mapToGlobal(point)); } return !isValidPoint; @@ -1576,56 +1565,56 @@ bool UBBoardView::isAbsurdPoint(QPoint point) void UBBoardView::focusOutEvent (QFocusEvent * event) { - Q_UNUSED (event); + Q_UNUSED (event); } void UBBoardView::setToolCursor (int tool) { - QWidget *controlViewport = viewport (); - switch (tool) + QWidget *controlViewport = viewport (); + switch (tool) { case UBStylusTool::Pen: - controlViewport->setCursor (UBResources::resources ()->penCursor); - break; + controlViewport->setCursor (UBResources::resources ()->penCursor); + break; case UBStylusTool::Eraser: - controlViewport->setCursor (UBResources::resources ()->eraserCursor); - scene()->hideEraser(); - break; + controlViewport->setCursor (UBResources::resources ()->eraserCursor); + scene()->hideEraser(); + break; case UBStylusTool::Marker: - controlViewport->setCursor (UBResources::resources ()->markerCursor); - break; + controlViewport->setCursor (UBResources::resources ()->markerCursor); + break; case UBStylusTool::Pointer: - controlViewport->setCursor (UBResources::resources ()->pointerCursor); - break; + controlViewport->setCursor (UBResources::resources ()->pointerCursor); + break; case UBStylusTool::Hand: - controlViewport->setCursor (UBResources::resources ()->handCursor); - break; + controlViewport->setCursor (UBResources::resources ()->handCursor); + break; case UBStylusTool::ZoomIn: - controlViewport->setCursor (UBResources::resources ()->zoomInCursor); - break; + controlViewport->setCursor (UBResources::resources ()->zoomInCursor); + break; case UBStylusTool::ZoomOut: - controlViewport->setCursor (UBResources::resources ()->zoomOutCursor); - break; + controlViewport->setCursor (UBResources::resources ()->zoomOutCursor); + break; case UBStylusTool::Selector: - controlViewport->setCursor (UBResources::resources ()->arrowCursor); - break; + controlViewport->setCursor (UBResources::resources ()->arrowCursor); + break; case UBStylusTool::Play: - controlViewport->setCursor (UBResources::resources ()->playCursor); - break; + controlViewport->setCursor (UBResources::resources ()->playCursor); + break; case UBStylusTool::Line: - controlViewport->setCursor (UBResources::resources ()->penCursor); - break; + controlViewport->setCursor (UBResources::resources ()->penCursor); + break; case UBStylusTool::Text: - controlViewport->setCursor (UBResources::resources ()->textCursor); - break; + controlViewport->setCursor (UBResources::resources ()->textCursor); + break; case UBStylusTool::Capture: - controlViewport->setCursor (UBResources::resources ()->penCursor); - break; + controlViewport->setCursor (UBResources::resources ()->penCursor); + break; default: - Q_ASSERT (false); - //failsafe - controlViewport->setCursor (UBResources::resources ()->penCursor); + Q_ASSERT (false); + //failsafe + controlViewport->setCursor (UBResources::resources ()->penCursor); } } diff --git a/src/board/UBDrawingController.cpp b/src/board/UBDrawingController.cpp index ec8af0d9..c07fcbd7 100644 --- a/src/board/UBDrawingController.cpp +++ b/src/board/UBDrawingController.cpp @@ -159,35 +159,23 @@ bool UBDrawingController::isDrawingTool() int UBDrawingController::currentToolWidthIndex() { if (stylusTool() == UBStylusTool::Pen || stylusTool() == UBStylusTool::Line) - { return UBSettings::settings()->penWidthIndex(); - } else if (stylusTool() == UBStylusTool::Marker) - { return UBSettings::settings()->markerWidthIndex(); - } else - { return -1; - } } qreal UBDrawingController::currentToolWidth() { if (stylusTool() == UBStylusTool::Pen || stylusTool() == UBStylusTool::Line) - { return UBSettings::settings()->currentPenWidth(); - } else if (stylusTool() == UBStylusTool::Marker) - { return UBSettings::settings()->currentMarkerWidth(); - } else - { //failsafe return UBSettings::settings()->currentPenWidth(); - } } diff --git a/src/core/UB.h b/src/core/UB.h index ec6bb00a..2f8615dc 100644 --- a/src/core/UB.h +++ b/src/core/UB.h @@ -50,17 +50,17 @@ struct UBStylusTool { enum Enum { - Pen = 0, - Eraser, - Marker, - Selector, + Pen = 0, + Eraser, + Marker, + Selector, Play, - Hand, - ZoomIn, - ZoomOut, - Pointer, - Line, - Text, + Hand, + ZoomIn, + ZoomOut, + Pointer, + Line, + Text, Capture }; }; @@ -138,17 +138,17 @@ struct UBGraphicsItemType { enum Enum { - PolygonItemType = QGraphicsItem::UserType + 1, + PolygonItemType = QGraphicsItem::UserType + 1, PixmapItemType, - SvgItemType, + SvgItemType, DelegateButtonType, - MediaItemType, - PDFItemType, + MediaItemType, + PDFItemType, TextItemType, CurtainItemType, - RulerItemType, - CompassItemType, - ProtractorItemType, + RulerItemType, + CompassItemType, + ProtractorItemType, StrokeItemType, TriangleItemType, MagnifierItemType, diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 1ec52624..a6a93f12 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -236,9 +236,7 @@ UBGraphicsItemDelegate::~UBGraphicsItemDelegate() QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { - if(change == QGraphicsItem::ItemChildAddedChange){ - - }else if (change == QGraphicsItem::ItemSelectedHasChanged) { + if (change == QGraphicsItem::ItemSelectedHasChanged) { bool ok; bool selected = value.toUInt(&ok); if (ok) { @@ -286,6 +284,8 @@ bool UBGraphicsItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event) { mDragStartPosition = event->pos(); + mMoved = false; + startUndoStep(); if (!delegated()->isSelected()) @@ -315,6 +315,7 @@ bool UBGraphicsItemDelegate::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } mDrag->exec(); mDragPixmap = QPixmap(); + mMoved = true; return true; } return false; @@ -439,22 +440,9 @@ void UBGraphicsItemDelegate::setZOrderButtonsVisible(bool visible) void UBGraphicsItemDelegate::remove(bool canUndo) { - /*UBGraphicsScene* scene = dynamic_cast(mDelegated->scene()); - if (scene && canUndo) - { - UBGraphicsItemUndoCommand *uc = new UBGraphicsItemUndoCommand(scene, mDelegated, 0); - UBApplication::undoStack->push(uc); - } - mDelegated->hide(); */ - UBGraphicsScene* scene = dynamic_cast(mDelegated->scene()); if (scene) { -// bool shownOnDisplay = mDelegated->data(UBGraphicsItemData::ItemLayerType).toInt() != UBItemLayerType::Control; -// showHide(shownOnDisplay); -// updateFrame(); -// updateButtons(); - if (mFrame && !mFrame->scene() && mDelegated->scene()) { mDelegated->scene()->addItem(mFrame); @@ -734,7 +722,7 @@ void UBGraphicsItemDelegate::updateButtons(bool showUpdated) mDelegated->scene()->addItem(mDeleteButton); } - if (showUpdated /*&& mFrame->isResizing()*/) + if (showUpdated) mDeleteButton->show(); int i = 1, j = 0, k = 0; @@ -772,7 +760,7 @@ void UBGraphicsItemDelegate::setButtonsVisible(bool visible) } -UBGraphicsToolBarItem::UBGraphicsToolBarItem(QGraphicsItem * parent) : +UBGraphicsToolBarItem::UBGraphicsToolBarItem(QGraphicsItem * parent) : QGraphicsRectItem(parent), mShifting(true), mVisible(false), @@ -785,7 +773,6 @@ UBGraphicsToolBarItem::UBGraphicsToolBarItem(QGraphicsItem * parent) : rect.setWidth(parent->boundingRect().width()); this->setRect(rect); - // setBrush(QColor(UBSettings::paletteColor)); setPen(Qt::NoPen); hide(); @@ -815,36 +802,40 @@ void UBGraphicsToolBarItem::paint(QPainter *painter, const QStyleOptionGraphicsI Q_UNUSED(widget); QPainterPath path; - path.addRoundedRect(rect(), 10, 10); + path.addRoundedRect(rect(), 10, 10); setBrush(QBrush(UBSettings::paletteColor)); painter->fillPath(path, brush()); } -MediaTimer::MediaTimer(QGraphicsItem * parent): QGraphicsRectItem(parent) +MediaTimer::MediaTimer(QGraphicsItem * parent): QGraphicsRectItem(parent) { val = 0; smallPoint = false; - setNumDigits(4); + setNumDigits(6); } MediaTimer::~MediaTimer() {} +void MediaTimer::positionHandles() +{ + digitSpace = smallPoint ? 2 : 1; + ySegLen = rect().height()*5/12; + xSegLen = ySegLen*2/3; + segLen = xSegLen; + xAdvance = segLen*(5 + digitSpace)/5; + xOffset = (rect().width() - ndigits*xAdvance + segLen/5)/2; + yOffset = rect().height() - ySegLen*2; + + setRect(rect().x(), rect().y(), xOffset + xAdvance*ndigits, rect().height()); +} + void MediaTimer::drawString(const QString &s, QPainter &p, QBitArray *newPoints, bool newString) { QPoint pos; - - int digitSpace = smallPoint ? 2 : 1; - int xSegLen = (rect().width()/1)*5/(ndigits*(5 + digitSpace) + digitSpace); - int ySegLen = rect().height()*5/12; - int segLen = ySegLen > xSegLen ? xSegLen : ySegLen; - int xAdvance = segLen*(5 + digitSpace)/5; - int xOffset = rect().x() + (rect().width()/1 - ndigits*xAdvance + segLen/5)/2; - int yOffset = (rect().height() - segLen*2)/2; - for (int i=0; ifont(); - f.setPointSizeF(f.pointSizeF()); - p->setFont(f); - if (smallPoint) drawString(digitStr, *p, &points, false); else @@ -1178,7 +1165,7 @@ void MediaTimer::setNumDigits(int numDigits) numDigits = 0; } if (digitStr.isNull()) { // from constructor - ndigits = numDigits; + ndigits = numDigits + numDigits/2 - 1; digitStr.fill(QLatin1Char(' '), ndigits); points.fill(0, ndigits); digitStr[ndigits - 1] = QLatin1Char('0'); // "0" is the default number @@ -1208,6 +1195,7 @@ void MediaTimer::setNumDigits(int numDigits) ndigits = numDigits; update(); } + positionHandles(); } DelegateMediaControl::DelegateMediaControl(UBGraphicsMediaItem* pDelegated, QGraphicsItem * parent) @@ -1235,15 +1223,8 @@ void DelegateMediaControl::paint(QPainter *painter, { Q_UNUSED(option); Q_UNUSED(widget); - - QPainterPath path; - mLCDTimerArea.setHeight(rect().height()); - mLCDTimerArea.setWidth(rect().height()); - - mSeecArea.setWidth(rect().width()-mLCDTimerArea.width()-2); - mSeecArea.setHeight(rect().height()-2*mSeecAreaBorderHeight); - mSeecArea.setY(mSeecAreaBorderHeight); + QPainterPath path; path.addRoundedRect(mSeecArea, mSeecArea.height()/2, mSeecArea.height()/2); painter->fillPath(path, brush()); @@ -1274,28 +1255,59 @@ QPainterPath DelegateMediaControl::shape() const void DelegateMediaControl::positionHandles() { - mLCDTimerArea.setWidth(parentItem()->boundingRect().height()); + QRectF selfRect = rect(); + selfRect.setHeight(parentItem()->boundingRect().height()); + setRect(selfRect); + + QTime tTotal; + tTotal = tTotal.addMSecs(mTotalTimeInMs); + mLCDTimerArea.setHeight(parentItem()->boundingRect().height()); + + int digitsCount = 2; + int timerWidth = mLCDTimerArea.height(); + + mDisplayFormat = "ss"; + + if (tTotal.minute() > 0) + { + mDisplayFormat = "mm:" + mDisplayFormat; + digitsCount += 3; + timerWidth += mLCDTimerArea.height()*0.5; + } + + if (tTotal.hour() > 0) + { + mDisplayFormat = "hh:" + mDisplayFormat; + digitsCount += 3; + timerWidth += mLCDTimerArea.height(); + } + + lcdTimer->setNumDigits(digitsCount); + + mLCDTimerArea.setWidth(timerWidth); + lcdTimer->setRect(mLCDTimerArea); - lcdTimer->setPos(mSeecArea.width()-mLCDTimerArea.width(),0); + + // not the best solution, but it works. + lcdTimer->positionHandles(); + mLCDTimerArea = lcdTimer->rect(); + // ------------------------------------- + + lcdTimer->setPos(rect().width() - mLCDTimerArea.width(), 0); mSeecAreaBorderHeight = rect().height()/20; mSeecArea.setWidth(rect().width()-mLCDTimerArea.width()-2); mSeecArea.setHeight(rect().height()-2*mSeecAreaBorderHeight); mSeecArea.setY(mSeecAreaBorderHeight); - - QRectF selfRect = rect(); - selfRect.setHeight(parentItem()->boundingRect().height()); - setRect(selfRect); - - lcdTimer->setPos(rect().width() - mLCDTimerArea.width(), 0); } void DelegateMediaControl::update() { - QTime t; - t = t.addMSecs(mCurrentTimeInMs < 0 ? 0 : mCurrentTimeInMs); - lcdTimer->display(t.toString("m:ss")); + QTime tCurrent; + tCurrent = tCurrent.addMSecs(mCurrentTimeInMs < 0 ? 0 : mCurrentTimeInMs); + + lcdTimer->display(tCurrent.toString(mDisplayFormat)); QGraphicsRectItem::update(); } @@ -1309,17 +1321,21 @@ void DelegateMediaControl::updateTicker(qint64 time ) void DelegateMediaControl::totalTimeChanged(qint64 newTotalTime) { - mTotalTimeInMs = newTotalTime; - update(); + if (mTotalTimeInMs != newTotalTime) + { + mTotalTimeInMs = newTotalTime; + positionHandles(); + update(); + } } void DelegateMediaControl::mousePressEvent(QGraphicsSceneMouseEvent *event) { qreal frameWidth = mSeecArea.height()/2; - if (boundingRect().contains(event->pos() - QPointF(frameWidth,0)) + if (boundingRect().contains(event->pos() - QPointF(frameWidth,0)) && boundingRect().contains(event->pos() + QPointF(frameWidth,0))) - { + { mDisplayCurrentTime = true; seekToMousePos(event->pos()); this->update(); @@ -1331,9 +1347,9 @@ void DelegateMediaControl::mousePressEvent(QGraphicsSceneMouseEvent *event) void DelegateMediaControl::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { qreal frameWidth = mSeecArea.height() / 2; - if (boundingRect().contains(event->pos() - QPointF(frameWidth,0)) + if (boundingRect().contains(event->pos() - QPointF(frameWidth,0)) && boundingRect().contains(event->pos() + QPointF(frameWidth,0))) - { + { seekToMousePos(event->pos()); this->update(); event->accept(); @@ -1347,7 +1363,7 @@ void DelegateMediaControl::seekToMousePos(QPointF mousePos) qreal frameWidth = rect().height() / 2; minX = frameWidth; - length = mSeecArea.width() - lcdTimer->rect().width(); + length = mSeecArea.width() - mSeecArea.height(); qreal mouseX = mousePos.x(); if (mouseX >= (mSeecArea.width() - mSeecArea.height()/2)) diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index abe83f4e..2d3acab1 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -104,10 +104,12 @@ public: MediaTimer(QGraphicsItem * parent = 0); ~MediaTimer(); + void positionHandles(); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void display(const QString &str); + void setNumDigits(int nDigits); private: @@ -117,7 +119,6 @@ private: void drawSegment(const QPoint &, char, QPainter &, int, bool = false); void addPoint(QPolygon&, const QPoint&); void internalSetString(const QString& s); - void setNumDigits(int nDigits); static char segments [][8]; @@ -128,6 +129,14 @@ private: uint shadow : 1; uint smallPoint : 1; + + int digitSpace; + int xSegLen; + int ySegLen; + int segLen; + int xAdvance; + int xOffset; + int yOffset; }; class DelegateMediaControl: public QObject, public QGraphicsRectItem @@ -178,6 +187,8 @@ class DelegateMediaControl: public QObject, public QGraphicsRectItem QRectF mLCDTimerArea; MediaTimer *lcdTimer; + + QString mDisplayFormat; }; class UBGraphicsToolBarItem : public QGraphicsRectItem, public QObject @@ -189,7 +200,7 @@ class UBGraphicsToolBarItem : public QGraphicsRectItem, public QObject bool isVisibleOnBoard() const { return mVisible; } void setVisibleOnBoard(bool visible) { mVisible = visible; } bool isShifting() const { return mShifting; } - void setShifting(bool shifting) { mShifting = shifting; } + void setShifting(bool shifting) { mShifting = shifting; } QList itemsOnToolBar() const { return mItemsOnToolBar; } void setItemsOnToolBar(QList itemsOnToolBar) { mItemsOnToolBar = itemsOnToolBar;} int minWidth() { return mMinWidth; } @@ -340,6 +351,8 @@ private: bool mToolBarUsed; bool mShowGoContentButton; + + bool mMoved; }; diff --git a/src/domain/UBGraphicsMediaItem.cpp b/src/domain/UBGraphicsMediaItem.cpp index 5c71fdc2..e84bfb21 100644 --- a/src/domain/UBGraphicsMediaItem.cpp +++ b/src/domain/UBGraphicsMediaItem.cpp @@ -85,7 +85,7 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte if ("" == mediaPath) mediaPath = pMediaFileUrl.toLocalFile(); - if (mediaPath.toLower().contains("videos")) + if (mediaPath.toLower().contains("videos")) { mMediaType = mediaType_Video; @@ -102,8 +102,7 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte haveLinkedImage = true; } - else - if (mediaPath.toLower().contains("audios")) + else if (mediaPath.toLower().contains("audios")) { mMediaType = mediaType_Audio; mAudioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); @@ -117,20 +116,20 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte borderSize = pAudioWidget->borderSize(); } - mAudioWidget->resize(320,26+3*borderSize); + mAudioWidget->resize(320,26+2*borderSize); //3*border size with enabled title mAudioWidget->setMinimumSize(150,26+borderSize); haveLinkedImage = false; } Phonon::createPath(mMediaObject, mAudioOutput); - + mSource = Phonon::MediaSource(pMediaFileUrl); mMediaObject->setCurrentSource(mSource); // we should create delegate after media objects because delegate uses his properties at creation. setDelegate(new UBGraphicsMediaItemDelegate(this, mMediaObject)); - + // delegate should be created earler because we setWidget calls resize event for graphics proxy widgt. // resize uses delegate. if (mediaType_Video == mMediaType) @@ -320,13 +319,13 @@ void UBGraphicsMediaItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { QGraphicsItem *curItem = group->getCurrentItem(); if (curItem && this != curItem) - { - group->deselectCurrentItem(); - } + { + group->deselectCurrentItem(); + } group->setCurrentItem(this); this->setSelected(true); Delegate()->positionHandles(); - } + } } } @@ -339,7 +338,7 @@ void UBGraphicsMediaItem::mousePressEvent(QGraphicsSceneMouseEvent *event) event->accept(); } } - else + else { mShouldMove = (event->buttons() & Qt::LeftButton); mMousePressPos = event->scenePos(); diff --git a/src/domain/UBGraphicsMediaItemDelegate.cpp b/src/domain/UBGraphicsMediaItemDelegate.cpp index c22a3e21..ea1ae07f 100644 --- a/src/domain/UBGraphicsMediaItemDelegate.cpp +++ b/src/domain/UBGraphicsMediaItemDelegate.cpp @@ -255,6 +255,11 @@ void UBGraphicsMediaItemDelegate::mediaStateChanged ( Phonon::State newstate, Ph { Q_UNUSED(newstate); Q_UNUSED(oldstate); + + if (oldstate == Phonon::LoadingState) + { + mMediaControl->totalTimeChanged(delegated()->mediaObject()->totalTime()); + } updatePlayPauseState(); } diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index a6a9b6fa..61330bf6 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -335,8 +335,8 @@ void UBGraphicsScene::updateGroupButtonState() { UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool(); - if (UBStylusTool::Selector != currentTool) - UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); + if (UBStylusTool::Selector != currentTool && UBStylusTool::Play != currentTool) + return; QAction *groupAction = UBApplication::mainWindow->actionGroupItems; QList selItems = selectedItems(); @@ -362,24 +362,18 @@ void UBGraphicsScene::updateGroupButtonState() bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pressure) { - //mMesure1Ms = 0; - //mMesure2Ms = 0; - bool accepted = false; - if (mInputDeviceIsPressed) - { + if (mInputDeviceIsPressed) { qWarning() << "scene received input device pressed, without input device release, muting event as input device move"; accepted = inputDeviceMove(scenePos, pressure); } - else - { + else { mInputDeviceIsPressed = true; UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool(); - if (UBDrawingController::drawingController()->isDrawingTool()) - { + if (UBDrawingController::drawingController()->isDrawingTool()) { // ----------------------------------------------------------------- // We fall here if we are using the Pen, the Marker or the Line tool // ----------------------------------------------------------------- @@ -399,7 +393,8 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre if (currentTool != UBStylusTool::Line){ // Handle the pressure width = UBDrawingController::drawingController()->currentToolWidth() * pressure; - }else{ + } + else{ // Ignore pressure for the line tool width = UBDrawingController::drawingController()->currentToolWidth(); } @@ -411,18 +406,14 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre mRemovedItems.clear(); if (UBDrawingController::drawingController()->mActiveRuler) - { UBDrawingController::drawingController()->mActiveRuler->StartLine(scenePos, width); - } - else - { + else { moveTo(scenePos); drawLineTo(scenePos, width, UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line); } accepted = true; } - else if (currentTool == UBStylusTool::Eraser) - { + else if (currentTool == UBStylusTool::Eraser) { mAddedItems.clear(); mRemovedItems.clear(); moveTo(scenePos); @@ -436,8 +427,7 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre accepted = true; } - else if (currentTool == UBStylusTool::Pointer) - { + else if (currentTool == UBStylusTool::Pointer) { drawPointer(scenePos, true); accepted = true; } @@ -516,7 +506,8 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres if(dc->mActiveRuler){ dc->mActiveRuler->DrawLine(position, width); - }else{ + } + else{ drawLineTo(position, width, UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line); } } @@ -1487,15 +1478,14 @@ UBGraphicsTextItem* UBGraphicsScene::textForObjectName(const QString& pString, c if(!textItem){ textItem = addTextWithFont(pString,QPointF(0,0) ,72,UBSettings::settings()->fontFamily(),true,false); textItem->setObjectName(objectName); - QSizeF size = textItem->size(); - textItem->setPos(QPointF(-size.width()/2.0,-size.height()/2.0)); textItem->setData(UBGraphicsItemData::ItemEditable,QVariant(false)); + textItem->adjustSize(); + textItem->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); } textItem->setPlainText(pString); - textItem->adjustSize(); + textItem->clearFocus(); - textItem->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); return textItem; } @@ -2286,9 +2276,8 @@ void UBGraphicsScene::createPointer() void UBGraphicsScene::setToolCursor(int tool) { if (tool == (int)UBStylusTool::Selector || - tool == (int)UBStylusTool::Text || - tool == (int)UBStylusTool::Play) - { + tool == (int)UBStylusTool::Text || + tool == (int)UBStylusTool::Play) { deselectAllItems(); } diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index 32c10fe3..62e5b891 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -609,7 +609,9 @@ void UBGraphicsWidgetItem::mainFrameLoadFinished (bool ok) { mLoadIsErronous = !ok; update(boundingRect()); - takeSnapshot(); + + if (mInitialLoadDone && scene() && scene()->renderingContext() == UBGraphicsScene::Screen) + takeSnapshot(); } void UBGraphicsWidgetItem::wheelEvent(QGraphicsSceneWheelEvent *event) diff --git a/src/frameworks/UBCoreGraphicsScene.cpp b/src/frameworks/UBCoreGraphicsScene.cpp index 9f0cd120..03637a22 100644 --- a/src/frameworks/UBCoreGraphicsScene.cpp +++ b/src/frameworks/UBCoreGraphicsScene.cpp @@ -40,15 +40,9 @@ UBCoreGraphicsScene::~UBCoreGraphicsScene() { //we must delete removed items that are no more in any scene //at groups deleting some items can be added to mItemsToDelete, so we need to use iterators. - foreach(QGraphicsItem* item, mItemsToDelete) - { - if (item) - { - if (item->scene() == NULL || item->scene() == this) - { - delete item; - } - } + foreach(QGraphicsItem* item, mItemsToDelete){ + if (item && item->type() != UBGraphicsItemType::PolygonItemType && item->type() != QGraphicsItem::UserType && item->type() != UBGraphicsItemType::groupContainerType && (item->scene() == NULL || item->scene() == this)) + delete item; } mItemsToDelete.clear(); } @@ -62,7 +56,7 @@ void UBCoreGraphicsScene::addItem(QGraphicsItem* item) removeItemFromDeletion(curItem); } } - + if (item->scene() != this) QGraphicsScene::addItem(item); diff --git a/src/gui/UBNavigatorPalette.cpp b/src/gui/UBNavigatorPalette.cpp index f29f69e6..5be18c8e 100644 --- a/src/gui/UBNavigatorPalette.cpp +++ b/src/gui/UBNavigatorPalette.cpp @@ -98,13 +98,13 @@ UBNavigatorPalette::~UBNavigatorPalette() } if(NULL != mLayout) { - delete mLayout; - mLayout = NULL; + delete mLayout; + mLayout = NULL; } if(NULL != mNavigator) { - delete mNavigator; - mNavigator = NULL; + delete mNavigator; + mNavigator = NULL; } } diff --git a/src/gui/UBTeacherGuideWidget.cpp b/src/gui/UBTeacherGuideWidget.cpp index 443ec9d2..025466fe 100644 --- a/src/gui/UBTeacherGuideWidget.cpp +++ b/src/gui/UBTeacherGuideWidget.cpp @@ -273,8 +273,8 @@ void UBTeacherGuideEditionWidget::onActiveSceneChanged() void UBTeacherGuideEditionWidget::cleanData() { - mpPageTitle->setText(""); - mpComment->setText(""); + mpPageTitle->resetText(); + mpComment->resetText(); QList children = mpAddAnActionItem->takeChildren(); children << mpAddAMediaItem->takeChildren(); children << mpAddALinkItem->takeChildren(); diff --git a/src/gui/UBTeacherGuideWidgetsTools.cpp b/src/gui/UBTeacherGuideWidgetsTools.cpp index 77ef3add..4a96d7b7 100644 --- a/src/gui/UBTeacherGuideWidgetsTools.cpp +++ b/src/gui/UBTeacherGuideWidgetsTools.cpp @@ -224,6 +224,19 @@ void UBTGAdaptableText::setInitialText(const QString& text) onTextChanged(); } +void UBTGAdaptableText::resetText() +{ + if(mHasPlaceHolder && !mPlaceHolderText.isEmpty()){ + setTextColor(QColor(Qt::lightGray)); + setText(mPlaceHolderText); + } + else{ + setText(""); + setTextColor(QColor(Qt::black)); + } + onTextChanged(); +} + void UBTGAdaptableText::showText(const QString & text) { setText(text); @@ -252,14 +265,40 @@ void UBTGAdaptableText::focusOutEvent(QFocusEvent* e) QTextEdit::focusOutEvent(e); } +void UBTGAdaptableText::insertFromMimeData(const QMimeData *source) +{ + QMimeData editedMimeData; + QTextDocument textDoc; + QString plainText; + + if (source->hasHtml()) + { + textDoc.setHtml(source->html()); + plainText += textDoc.toPlainText(); + } + if (source->hasText()) + if (textDoc.toPlainText() != source->text()) + plainText += source->text(); + if (source->hasUrls()) + { + foreach(QUrl url, source->urls()) + { + plainText += url.toString(); + } + } + + editedMimeData.setText(plainText); + QTextEdit::insertFromMimeData(&editedMimeData); +} + void UBTGAdaptableText::managePlaceholder(bool focus) { if(focus){ if(toPlainText() == mPlaceHolderText){ setTextColor(QColor(Qt::black)); setPlainText(""); + setCursorToTheEnd(); } - setCursorToTheEnd(); } else{ if(toPlainText().isEmpty()){ @@ -537,9 +576,9 @@ void UBTGMediaWidget::createWorkWidget(bool forceFlashMediaType) mpMediaLayout = new QHBoxLayout(mpWorkWidget); mpWorkWidget->setLayout(mpMediaLayout); } - + mpMediaLayout->addStretch(1); - + if(mpMediaLabelWidget){ mpMediaLabelWidget->setFixedHeight(mMediaWidgetHeight); mpMediaLabelWidget->setParent(mpWorkWidget); diff --git a/src/gui/UBTeacherGuideWidgetsTools.h b/src/gui/UBTeacherGuideWidgetsTools.h index 50e671dc..9ed6252c 100644 --- a/src/gui/UBTeacherGuideWidgetsTools.h +++ b/src/gui/UBTeacherGuideWidgetsTools.h @@ -103,6 +103,7 @@ class UBTGAdaptableText : public QTextEdit public: explicit UBTGAdaptableText(QTreeWidgetItem* widget = 0, QWidget *parent = 0, const char* name = "UBTGAdaptableText"); void showText(const QString & text); + void resetText(); void bottomMargin(int newValue); void setPlaceHolderText(QString text); QString text(); @@ -118,6 +119,7 @@ protected: void showEvent(QShowEvent* e); void focusInEvent(QFocusEvent* e); void focusOutEvent(QFocusEvent* e); + virtual void insertFromMimeData(const QMimeData *source); private: void setCursorToTheEnd(); diff --git a/src/gui/UBThumbnailWidget.cpp b/src/gui/UBThumbnailWidget.cpp index c67f14f8..4ef5af24 100644 --- a/src/gui/UBThumbnailWidget.cpp +++ b/src/gui/UBThumbnailWidget.cpp @@ -87,6 +87,7 @@ void UBThumbnailWidget::setGraphicsItems(const QList& pGraphicsI , const QStringList pLabels , const QString& pMimeType) { + Q_ASSERT(pItemsPaths.count() == pLabels.count()); mGraphicItems = pGraphicsItems; mItemsPaths = pItemsPaths; mMimeType = pMimeType; @@ -224,13 +225,6 @@ void UBThumbnailWidget::mousePressEvent(QMouseEvent *event) event->ignore(); return; } - //if(sceneItem){ - // int pageIndex = UBDocumentContainer::pageFromSceneIndex(sceneItem->sceneIndex()); - // if(pageIndex == 0){ - // event->ignore(); - // return; - // } - //} mMousePressScenePos = mapToScene(mMousePressPos); QGraphicsItem* underlyingItem = itemAt(mMousePressPos);