diff --git a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp index b60221f295..529ca9d5e7 100644 --- a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp @@ -36,6 +36,7 @@ # include # include # include + # include # include #endif @@ -171,8 +172,9 @@ void QGIViewBalloon::onAttachPointPicked(QGIView *view, QPointF pos) auto bnd = boost::bind(&QGIViewBalloon::parentViewMousePressed, this, _1, _2); if (balloon->OriginIsSet.getValue() == false) { - balloon->OriginX.setValue(pos.x()); - balloon->OriginY.setValue(pos.y()); + /* Move origin by half of cursor size */ + balloon->OriginX.setValue(pos.x() - 16); + balloon->OriginY.setValue(pos.y() + 16); balloon->OriginIsSet.setValue(true); m_parent->signalSelectPoint.disconnect(bnd); @@ -182,6 +184,8 @@ void QGIViewBalloon::onAttachPointPicked(QGIView *view, QPointF pos) if (mdi != nullptr) { page = mdi->getQGVPage(); + page->balloonPlacing(false); + QString labelText = QString::fromUtf8(std::to_string(page->balloonIndex).c_str()); balloon->Text.setValue(std::to_string(page->balloonIndex++).c_str()); @@ -194,6 +198,8 @@ void QGIViewBalloon::onAttachPointPicked(QGIView *view, QPointF pos) // Default label position balloonLabel->setPosFromCenter(pos.x() + 200, pos.y() -200); balloonLabel->setDimString(labelText, Rez::guiX(balloon->TextWrapLen.getValue())); + + QApplication::setOverrideCursor(Qt::ArrowCursor); } } diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index 8077e60e51..50c0a73856 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -137,6 +137,7 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene* s, QWidget *parent) bkgBrush = new QBrush(getBackgroundColor()); balloonIndex = 1; + balloonPlacing(false); resetCachedContent(); } @@ -407,9 +408,13 @@ QGIView * QGVPage::addViewBalloon(TechDraw::DrawViewBalloon *balloon) QGIView *parent = 0; parent = findParent(balloonGroup); - if(parent) { - balloonGroup->connect(parent); - addBalloonToParent(balloonGroup,parent); + if(balloon->OriginIsSet.getValue() == false) { + if(parent) { + balloonPlacing(true); + QApplication::setOverrideCursor(QCursor(QPixmap(QString::fromUtf8(":/icons/cursor-balloon.png")))); + balloonGroup->connect(parent); + addBalloonToParent(balloonGroup,parent); + } } return balloonGroup; @@ -854,6 +859,30 @@ void QGVPage::enterEvent(QEvent *event) viewport()->setCursor(Qt::ArrowCursor); } +void QGVPage::leaveEvent(QEvent * event) +{ + if(m_balloonPlacing) { + + // Get the window geometry & cursor position + const QRect &rect = geometry(); + QPoint position = this->mapFromGlobal(QCursor::pos()); + + // Check the bounds + qint32 x = qBound(rect.left(), position.x(), rect.right()); + qint32 y = qBound(rect.top(), position.y(), rect.bottom()); + + QPoint newPoint(x, y); + + // Adjust the cursor + if (x != position.x() || y != position.y()) + QCursor::setPos(this->mapToGlobal(newPoint)); + + event->accept(); + } + + QGraphicsView::leaveEvent(event); +} + void QGVPage::mousePressEvent(QMouseEvent *event) { QGraphicsView::mousePressEvent(event); diff --git a/src/Mod/TechDraw/Gui/QGVPage.h b/src/Mod/TechDraw/Gui/QGVPage.h index 0280e434bf..c49673dcb5 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.h +++ b/src/Mod/TechDraw/Gui/QGVPage.h @@ -93,6 +93,8 @@ public: int removeQViewByName(const char* name); void removeQViewFromScene(QGIView *view); + void balloonPlacing(bool val) { m_balloonPlacing = val; }; + //void setViews(const std::vector &view) {views = view; } void setPageTemplate(TechDraw::DrawTemplate *pageTemplate); @@ -117,6 +119,7 @@ protected: void wheelEvent(QWheelEvent *event) override; void paintEvent(QPaintEvent *event) override; void enterEvent(QEvent *event) override; + void leaveEvent(QEvent *event) override; void mousePressEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; void keyPressEvent(QKeyEvent *event) override; @@ -143,6 +146,7 @@ private: double m_zoomIncrement; int m_reversePan; int m_reverseScroll; + bool m_balloonPlacing; }; } // namespace MDIViewPageGui diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index 9d57b36d32..1aa5015dbc 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -71,6 +71,7 @@ icons/arrow-ccw.svg icons/arrow-cw.svg icons/techdraw-lock.png + icons/cursor-balloon.png translations/TechDraw_af.qm translations/TechDraw_zh-CN.qm translations/TechDraw_zh-TW.qm diff --git a/src/Mod/TechDraw/Gui/Resources/icons/cursor-balloon.png b/src/Mod/TechDraw/Gui/Resources/icons/cursor-balloon.png new file mode 100644 index 0000000000..dd755464c9 Binary files /dev/null and b/src/Mod/TechDraw/Gui/Resources/icons/cursor-balloon.png differ