diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index cac36774..282c6f7d 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -421,9 +421,7 @@ UBBoardView::mousePressEvent (QMouseEvent *event) } else if (currentTool == UBStylusTool::Selector) { - QSet existingTools = scene()->tools(); - - movingItem = scene()->itemAt(this->mapToScene(event->posF().toPoint())); + movingItem = scene()->itemAt(this->mapToScene(event->posF().toPoint())); if (!movingItem || movingItem->isSelected() @@ -432,7 +430,8 @@ UBBoardView::mousePressEvent (QMouseEvent *event) || movingItem->type() == UBGraphicsCompass::Type || movingItem->type() == UBGraphicsPDFItem::Type || movingItem->type() == UBGraphicsPolygonItem::Type - || movingItem->type() == UBGraphicsCache::Type) + || movingItem->type() == UBGraphicsCache::Type + || scene()->isBackgroundObject(movingItem)) { movingItem = NULL; QGraphicsView::mousePressEvent (event); diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 86b93b68..de710f82 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -147,12 +147,7 @@ QVariant UBGraphicsItemDelegate::itemChange(QGraphicsItem::GraphicsItemChange ch bool UBGraphicsItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if(NULL != mMimeData) - { - QDrag* mDrag = new QDrag(event->widget()); - mDrag->setMimeData(mMimeData); - mDrag->start(); - } + mDragStartPosition = event->pos(); startUndoStep(); @@ -186,13 +181,27 @@ void UBGraphicsItemDelegate::setMimeData(QMimeData *mimeData) bool UBGraphicsItemDelegate::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { + if((NULL != mMimeData) && ((event->pos() - mDragStartPosition).manhattanLength() < QApplication::startDragDistance())) + { + QDrag* mDrag = new QDrag(event->widget()); + mDrag->setMimeData(mMimeData); + if (!mDragPixmap.isNull()) { + mDrag->setPixmap(mDragPixmap); + mDrag->setHotSpot(mDragPixmap.rect().center()); + } + mDrag->exec(); + mDragPixmap = QPixmap(); + + return true; + } + if(isLocked()) { event->accept(); return true; } - else - return false; + + return true; } bool UBGraphicsItemDelegate::weelEvent(QGraphicsSceneWheelEvent *event) diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index 9986db6b..c9cbba54 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -129,6 +129,7 @@ class UBGraphicsItemDelegate : public QObject QMimeData* mimeData(){ return mMimeData; } void setMimeData(QMimeData* mimeData); + void setDragPixmap(const QPixmap &pix) {mDragPixmap = pix;} signals: void showOnDisplayChanged(bool shown); @@ -174,12 +175,15 @@ private: QPointF mOffset; QTransform mPreviousTransform; QPointF mPreviousPosition; + QPointF mDragStartPosition; qreal mPreviousZValue; QSizeF mPreviousSize; bool mCanRotate; bool mCanDuplicate; bool mRespectRatio; QMimeData* mMimeData; + QPixmap mDragPixmap; + }; diff --git a/src/domain/UBGraphicsPixmapItem.cpp b/src/domain/UBGraphicsPixmapItem.cpp index ceb4fd28..29605a00 100644 --- a/src/domain/UBGraphicsPixmapItem.cpp +++ b/src/domain/UBGraphicsPixmapItem.cpp @@ -53,6 +53,11 @@ void UBGraphicsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) QMimeData* pMime = new QMimeData(); pMime->setImageData(pixmap().toImage()); mDelegate->setMimeData(pMime); + int k = pixmap().width() / 100; + QSize newSize(pixmap().width() / k, pixmap().height() / k); + + mDelegate->setDragPixmap(pixmap().scaled(newSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + if (mDelegate->mousePressEvent(event)) { //NOOP diff --git a/src/domain/UBGraphicsPixmapItem.h b/src/domain/UBGraphicsPixmapItem.h index 56608ba1..93b26efc 100644 --- a/src/domain/UBGraphicsPixmapItem.h +++ b/src/domain/UBGraphicsPixmapItem.h @@ -62,9 +62,6 @@ protected: virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); - -// UBGraphicsItemDelegate* mDelegate; - }; #endif /* UBGRAPHICSPIXMAPITEM_H_ */ diff --git a/src/domain/UBGraphicsVideoItem.cpp b/src/domain/UBGraphicsVideoItem.cpp index c1e57e4d..a7d12d35 100644 --- a/src/domain/UBGraphicsVideoItem.cpp +++ b/src/domain/UBGraphicsVideoItem.cpp @@ -109,11 +109,6 @@ void UBGraphicsVideoItem::showOnDisplayChanged(bool shown) void UBGraphicsVideoItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - QDrag* mDrag = new QDrag(event->widget()); - QMimeData* pMime = new QMimeData(); - mDrag->setMimeData(pMime); - mDrag->start(); - mShouldMove = (event->buttons() & Qt::LeftButton); mMousePressPos = event->scenePos(); mMouseMovePos = mMousePressPos;