From c7cc7fa0fd7c1e05deaa1d945b0977007f26e8c6 Mon Sep 17 00:00:00 2001 From: Tomas Pavlicek Date: Sun, 3 Oct 2021 13:43:53 +0200 Subject: [PATCH 1/3] TechDraw - Balloon updates --- src/Mod/TechDraw/App/DrawPage.cpp | 1 - src/Mod/TechDraw/App/DrawPage.h | 1 - src/Mod/TechDraw/App/DrawViewBalloon.cpp | 1 + src/Mod/TechDraw/Gui/Command.cpp | 54 ++++++- .../Gui/DlgPrefsTechDrawAnnotation.ui | 9 ++ src/Mod/TechDraw/Gui/QGIView.cpp | 2 - src/Mod/TechDraw/Gui/QGIViewBalloon.cpp | 15 +- src/Mod/TechDraw/Gui/QGVPage.cpp | 144 ++++++++++++------ src/Mod/TechDraw/Gui/QGVPage.h | 15 +- src/Mod/TechDraw/Gui/Resources/TechDraw.qrc | 1 + .../Gui/Resources/icons/bottomline.svg | 35 +++++ src/Mod/TechDraw/Gui/TaskBalloon.ui | 9 ++ src/Mod/TechDraw/Gui/ViewProviderPage.h | 1 + 13 files changed, 233 insertions(+), 55 deletions(-) create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/bottomline.svg diff --git a/src/Mod/TechDraw/App/DrawPage.cpp b/src/Mod/TechDraw/App/DrawPage.cpp index 7d944593e8..f35835c0f6 100644 --- a/src/Mod/TechDraw/App/DrawPage.cpp +++ b/src/Mod/TechDraw/App/DrawPage.cpp @@ -100,7 +100,6 @@ DrawPage::DrawPage(void) "Auto-numbering for Balloons"); Scale.setConstraints(&scaleRange); - balloonPlacing = false; balloonParent = nullptr; } diff --git a/src/Mod/TechDraw/App/DrawPage.h b/src/Mod/TechDraw/App/DrawPage.h index 17b2c383bd..f9973b9d3a 100644 --- a/src/Mod/TechDraw/App/DrawPage.h +++ b/src/Mod/TechDraw/App/DrawPage.h @@ -94,7 +94,6 @@ public: bool isUnsetting(void) { return nowUnsetting; } void requestPaint(void); std::vector getAllViews(void) ; - bool balloonPlacing; DrawViewPart *balloonParent; //could be many balloons on page? int getNextBalloonIndex(void); diff --git a/src/Mod/TechDraw/App/DrawViewBalloon.cpp b/src/Mod/TechDraw/App/DrawViewBalloon.cpp index 684cbc934b..0bad648181 100644 --- a/src/Mod/TechDraw/App/DrawViewBalloon.cpp +++ b/src/Mod/TechDraw/App/DrawViewBalloon.cpp @@ -87,6 +87,7 @@ const char* DrawViewBalloon::balloonTypeEnums[]= {"Circular", "Hexagon", "Square", "Rectangle", + "Line", NULL}; DrawViewBalloon::DrawViewBalloon(void) diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index 49cf9170d0..2002008728 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -94,7 +94,11 @@ #include "TaskActiveView.h" #include "TaskDetail.h" #include "ViewProviderPage.h" +#include "ViewProviderViewPart.h" +#include "QGIViewPart.h" +#include "Rez.h" +class Vertex; using namespace TechDrawGui; using namespace TechDraw; using namespace std; @@ -801,6 +805,34 @@ bool _checkDrawViewPartBalloon(Gui::Command* cmd) { return true; } +bool _checkDirectPlacement(const QGIViewPart *viewPart, const std::vector &subNames, QPointF &placement) +{ + if (subNames.size() != 1) { + return false; + } + + std::string geoType = TechDraw::DrawUtil::getGeomTypeFromName(subNames[0]); + if (geoType == "Vertex") { + int index = TechDraw::DrawUtil::getIndexFromName(subNames[0]); + TechDraw::Vertex *vertex = static_cast(viewPart->getViewObject())->getProjVertexByIndex(index); + if (vertex) { + placement = viewPart->mapToScene(Rez::guiX(vertex->x()), Rez::guiX(vertex->y())); + return true; + } + } + else if (geoType == "Edge") { + int index = TechDraw::DrawUtil::getIndexFromName(subNames[0]); + TechDraw::BaseGeom *geo = static_cast(viewPart->getViewObject())->getGeomByIndex(index); + if (geo) { + Base::Vector3d midPoint(Rez::guiX(geo->getMidPoint())); + placement = viewPart->mapToScene(midPoint.x, midPoint.y); + return true; + } + } + + return false; +} + DEF_STD_CMD_A(CmdTechDrawBalloon) CmdTechDrawBalloon::CmdTechDrawBalloon() @@ -826,6 +858,7 @@ void CmdTechDrawBalloon::activated(int iMsg) return; std::vector selection = getSelection().getSelectionEx(); + auto objFeat( dynamic_cast(selection[0].getObject()) ); if( objFeat == nullptr ) { return; @@ -833,10 +866,25 @@ void CmdTechDrawBalloon::activated(int iMsg) TechDraw::DrawPage* page = objFeat->findParentPage(); std::string PageName = page->getNameInDocument(); - - page->balloonParent = objFeat; - page->balloonPlacing = true; + page->balloonParent = objFeat; + + Gui::Document *guiDoc = Gui::Application::Instance->getDocument(page->getDocument()); + ViewProviderPage *pageVP = dynamic_cast(guiDoc->getViewProvider(page)); + ViewProviderViewPart *partVP = dynamic_cast(guiDoc->getViewProvider(objFeat)); + + if (pageVP && partVP) { + QGVPage *viewPage = pageVP->getGraphicsView(); + if (viewPage) { + viewPage->startBalloonPlacing(); + + QGIViewPart *viewPart = dynamic_cast(partVP->getQView()); + QPointF placement; + if (viewPart && _checkDirectPlacement(viewPart, selection[0].getSubNames(), placement)) { + viewPage->createBalloon(placement, objFeat); + } + } + } } bool CmdTechDrawBalloon::isActive(void) diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotation.ui b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotation.ui index 0e6d4f080d..1f484413a9 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotation.ui +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotation.ui @@ -424,6 +424,15 @@ :/icons/rectangle.svg:/icons/rectangle.svg + + + Line + + + + :/icons/bottomline.svg:/icons/bottomline.svg + + diff --git a/src/Mod/TechDraw/Gui/QGIView.cpp b/src/Mod/TechDraw/Gui/QGIView.cpp index 71d7fe6913..70c7f2d2e3 100644 --- a/src/Mod/TechDraw/Gui/QGIView.cpp +++ b/src/Mod/TechDraw/Gui/QGIView.cpp @@ -118,8 +118,6 @@ QGIView::QGIView() m_lockWidth = (double) sizeLock.width(); m_lockHeight = (double) sizeLock.height(); m_lock->hide(); - - setCursor(Qt::ArrowCursor); } QGIView::~QGIView() diff --git a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp index a100894875..6a06f65beb 100644 --- a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp @@ -676,6 +676,7 @@ void QGIViewBalloon::drawBalloon(bool dragged) float scale = balloon->ShapeScale.getValue(); double offsetLR = 0; + double offsetUD = 0; QPainterPath balloonPath; if (strcmp(balloonType, "Circular") == 0) { @@ -747,16 +748,26 @@ void QGIViewBalloon::drawBalloon(bool dragged) balloonPath.moveTo(lblCenter.x + (radius * cos(startAngle)), lblCenter.y + (radius * sin(startAngle))); balloonPath.addPolygon(triangle); } + else if (strcmp(balloonType, "Line") == 0) { + textHeight = textHeight*scale + Rez::guiX(0.5); + textWidth = textWidth*scale + Rez::guiX(1.0); + + offsetLR = textWidth/2.0; + offsetUD = textHeight/2.0; + + balloonPath.moveTo(lblCenter.x - textWidth/2.0, lblCenter.y + offsetUD); + balloonPath.lineTo(lblCenter.x + textWidth/2.0, lblCenter.y + offsetUD); + } balloonShape->setPath(balloonPath); offsetLR = (lblCenter.x < arrowTipX) ? offsetLR : -offsetLR ; - if (DrawUtil::fpCompare(kinkLength, 0.0)) { //if no kink, then dLine start sb on line from center to arrow + if (DrawUtil::fpCompare(kinkLength, 0.0) && strcmp(balloonType, "Line")) { //if no kink, then dLine start sb on line from center to arrow dLineStart = lblCenter; kinkPoint = dLineStart; } else { - dLineStart.y = lblCenter.y; + dLineStart.y = lblCenter.y + offsetUD; dLineStart.x = lblCenter.x + offsetLR ; kinkLength = (lblCenter.x < arrowTipX) ? kinkLength : -kinkLength; kinkPoint.y = dLineStart.y; diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index 76e84a9748..81654e5d04 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -57,6 +57,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include #include @@ -126,6 +132,7 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene* s, QWidget *parent) m_renderer(Native), drawBkg(true), m_vpPage(0), + balloonPlacing(false), panningActive(false) { assert(vp); @@ -166,13 +173,13 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene* s, QWidget *parent) setAlignment(Qt::AlignCenter); setDragMode(ScrollHandDrag); - setCursor(QCursor(Qt::ArrowCursor)); + resetCursor(); setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); bkgBrush = new QBrush(getBackgroundColor()); balloonCursor = new QLabel(this); - balloonCursor->setPixmap(QPixmap(QString::fromUtf8(":/icons/TechDraw_Balloon.svg"))); + balloonCursor->setPixmap(prepareCursorPixmap("TechDraw_Balloon.svg", balloonHotspot = QPoint(8, 59))); balloonCursor->hide(); resetCachedContent(); @@ -184,11 +191,17 @@ QGVPage::~QGVPage() } +void QGVPage::startBalloonPlacing(void) +{ + balloonPlacing = true; + activateCursor(QCursor(*balloonCursor->pixmap(), balloonHotspot.x(), balloonHotspot.y())); +} + void QGVPage::cancelBalloonPlacing(void) { - getDrawPage()->balloonPlacing = false; - balloonCursor->hide(); - QApplication::restoreOverrideCursor(); + balloonPlacing = false; + balloonCursor->hide(); + resetCursor(); } void QGVPage::drawBackground(QPainter *p, const QRectF &) @@ -448,12 +461,13 @@ QGIView * QGVPage::addViewBalloon(TechDraw::DrawViewBalloon *balloon) QGIView *parent = 0; parent = findParent(vBalloon); - if(parent) + if (parent) { addBalloonToParent(vBalloon,parent); + } - if (getDrawPage()->balloonPlacing) { - vBalloon->placeBalloon(balloon->origin); - cancelBalloonPlacing(); + if (balloonPlacing) { + vBalloon->placeBalloon(balloon->origin); + cancelBalloonPlacing(); } return vBalloon; @@ -470,6 +484,32 @@ void QGVPage::addBalloonToParent(QGIViewBalloon* balloon, QGIView* parent) balloon->setZValue(ZVALUE::DIMENSION); } +void QGVPage::createBalloon(QPointF origin, DrawViewPart *parent) +{ + std::string featName = getDrawPage()->getDocument()->getUniqueObjectName("Balloon"); + std::string pageName = getDrawPage()->getNameInDocument(); + + Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Balloon")); + TechDraw::DrawViewBalloon *balloon = 0; + + Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Balloon")); + Command::doCommand(Command::Doc, "App.activeDocument().addObject('TechDraw::DrawViewBalloon','%s')", featName.c_str()); + Command::doCommand(Command::Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", pageName.c_str(), featName.c_str()); + + balloon = dynamic_cast(getDrawPage()->getDocument()->getObject(featName.c_str())); + if (!balloon) { + throw Base::TypeError("CmdTechDrawNewBalloon - balloon not found\n"); + } + + balloon->SourceView.setValue(parent); + balloon->origin = origin; + + Gui::Command::commitCommand(); + + balloon->recomputeFeature(); + parent->touch(true); +} + QGIView * QGVPage::addViewDimension(TechDraw::DrawViewDimension *dim) { auto dimGroup( new QGIViewDimension ); @@ -1119,21 +1159,14 @@ void QGVPage::kbPanScroll(int xMove, int yMove) void QGVPage::enterEvent(QEvent *event) { QGraphicsView::enterEvent(event); - if(getDrawPage()->balloonPlacing) { + if (balloonPlacing) { balloonCursor->hide(); - QApplication::setOverrideCursor(QCursor(QPixmap(QString::fromUtf8(":/icons/TechDraw_Balloon.svg")),0,32)); - } else { - QApplication::restoreOverrideCursor(); - viewport()->setCursor(Qt::ArrowCursor); } } void QGVPage::leaveEvent(QEvent * event) { - QApplication::restoreOverrideCursor(); - if(getDrawPage()->balloonPlacing) { - - + if (balloonPlacing) { int left_x; if (balloonCursorPos.x() < 32) left_x = 0; @@ -1192,33 +1225,9 @@ void QGVPage::mouseMoveEvent(QMouseEvent *event) void QGVPage::mouseReleaseEvent(QMouseEvent *event) { - if(getDrawPage()->balloonPlacing) { - QApplication::restoreOverrideCursor(); + if (balloonPlacing) { balloonCursor->hide(); - - std::string FeatName = getDrawPage()->getDocument()->getUniqueObjectName("Balloon"); - std::string PageName = getDrawPage()->getNameInDocument(); - Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Balloon")); - TechDraw::DrawViewBalloon *balloon = 0; - - Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Balloon")); - Command::doCommand(Command::Doc,"App.activeDocument().addObject('TechDraw::DrawViewBalloon','%s')",FeatName.c_str()); - Command::doCommand(Command::Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); - - balloon = dynamic_cast(getDrawPage()->getDocument()->getObject(FeatName.c_str())); - if (!balloon) { - throw Base::TypeError("CmdTechDrawNewBalloon - balloon not found\n"); - } - - balloon->SourceView.setValue(getDrawPage()->balloonParent); - balloon->origin = mapToScene(event->pos()); - - Gui::Command::commitCommand(); - balloon->recomputeFeature(); - - //Horrible hack to force Tree update - double x = getDrawPage()->balloonParent->X.getValue(); - getDrawPage()->balloonParent->X.setValue(x); + createBalloon(mapToScene(event->pos()), getDrawPage()->balloonParent); } if (event->button()&Qt::MiddleButton) { @@ -1227,7 +1236,7 @@ void QGVPage::mouseReleaseEvent(QMouseEvent *event) } QGraphicsView::mouseReleaseEvent(event); - viewport()->setCursor(Qt::ArrowCursor); + resetCursor(); } TechDraw::DrawPage* QGVPage::getDrawPage() @@ -1244,4 +1253,49 @@ QColor QGVPage::getBackgroundColor() return fcColor.asValue(); } +double QGVPage::getDevicePixelRatio() const { + for (Gui::MDIView *view : m_vpPage->getDocument()->getMDIViews()) { + if (view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { + return static_cast(view)->getViewer()->devicePixelRatio(); + } + } + + return 1.0; +} + +QPixmap QGVPage::prepareCursorPixmap(const char *iconName, QPoint &hotspot) { + double cursorSize = 64.0; + double pixelRatio = getDevicePixelRatio(); + + if (pixelRatio != 1.0) { + cursorSize = 32.0*pixelRatio; + } + + QPixmap pixmap = Gui::BitmapFactory().pixmapFromSvg(iconName, QSizeF(cursorSize, cursorSize)); + if (pixelRatio == 1.0) { + pixmap = pixmap.scaled(32, 32); + hotspot /= 2; + } + pixmap.setDevicePixelRatio(pixelRatio); + +#if !defined(Q_OS_WIN32) && !defined(Q_OS_MAC) + if (qGuiApp->platformName() == QLatin1String("xcb")) { + hotspot *= pixelRatio; + } +#endif + + return pixmap; +} + +void QGVPage::activateCursor(QCursor cursor) { + this->setCursor(cursor); + viewport()->setCursor(cursor); +} + +void QGVPage::resetCursor() { + this->setCursor(Qt::ArrowCursor); + viewport()->setCursor(Qt::ArrowCursor); +} + + #include diff --git a/src/Mod/TechDraw/Gui/QGVPage.h b/src/Mod/TechDraw/Gui/QGVPage.h index 52bbde1583..427d87a4f6 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.h +++ b/src/Mod/TechDraw/Gui/QGVPage.h @@ -93,6 +93,10 @@ public: QGIView* findParent(QGIView *) const; void addBalloonToParent(QGIViewBalloon* balloon, QGIView* parent); + void createBalloon(QPointF origin, TechDraw::DrawViewPart *parent); + void startBalloonPlacing(void); + void cancelBalloonPlacing(void); + void addDimToParent(QGIViewDimension* dim, QGIView* parent); void addLeaderToParent(QGILeaderLine* lead, QGIView* parent); @@ -118,6 +122,7 @@ public: void saveSvg(QString filename); void postProcessXml(QTemporaryFile& tempFile, QString filename, QString pagename); + public Q_SLOTS: void setHighQualityAntialiasing(bool highQualityAntialiasing); @@ -140,6 +145,12 @@ protected: QGITemplate *pageTemplate; + double getDevicePixelRatio() const; + QPixmap prepareCursorPixmap(const char *iconName, QPoint &hotspot); + + void activateCursor(QCursor cursor); + void resetCursor(); + private: RendererType m_renderer; @@ -153,9 +164,11 @@ private: double m_zoomIncrement; int m_reversePan; int m_reverseScroll; + + bool balloonPlacing; QLabel *balloonCursor; QPoint balloonCursorPos; - void cancelBalloonPlacing(void); + QPoint balloonHotspot; QPoint panOrigin; bool panningActive; diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index 45b09b6e62..887953a5dd 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -109,6 +109,7 @@ icons/rectangle.svg icons/triangle.svg icons/square.svg + icons/bottomline.svg icons/MRTE/menu.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/bottomline.svg b/src/Mod/TechDraw/Gui/Resources/icons/bottomline.svg new file mode 100644 index 0000000000..f97073b88b --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/bottomline.svg @@ -0,0 +1,35 @@ + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/TaskBalloon.ui b/src/Mod/TechDraw/Gui/TaskBalloon.ui index b4c1911af1..fd58abd15e 100644 --- a/src/Mod/TechDraw/Gui/TaskBalloon.ui +++ b/src/Mod/TechDraw/Gui/TaskBalloon.ui @@ -164,6 +164,15 @@ :/icons/rectangle.svg:/icons/rectangle.svg + + + Line + + + + :/icons/bottomline.svg:/icons/bottomline.svg + + diff --git a/src/Mod/TechDraw/Gui/ViewProviderPage.h b/src/Mod/TechDraw/Gui/ViewProviderPage.h index 443feb3047..895f92f740 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderPage.h +++ b/src/Mod/TechDraw/Gui/ViewProviderPage.h @@ -91,6 +91,7 @@ public: void setFrameState(bool state); void toggleFrameState(void); void setTemplateMarkers(bool state); + QGVPage *getGraphicsView() { return m_graphicsView; } void setGraphicsView(QGVPage* gv); virtual bool canDelete(App::DocumentObject* obj) const override; From f43226f1f665bcf32c7dea72377718fba6bbf537 Mon Sep 17 00:00:00 2001 From: Tomas Pavlicek Date: Fri, 8 Oct 2021 16:12:01 +0200 Subject: [PATCH 2/3] TechDraw - Balloon updates - review based changes --- src/Mod/TechDraw/Gui/Command.cpp | 15 ++++++++++++--- src/Mod/TechDraw/Gui/QGVPage.cpp | 28 ++++++++++++++-------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index 2002008728..e512a96e1a 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -87,16 +87,17 @@ #include #include "DrawGuiUtil.h" -#include "PreferencesGui.h" #include "MDIViewPage.h" +#include "PreferencesGui.h" +#include "QGIViewPart.h" +#include "Rez.h" #include "TaskProjGroup.h" #include "TaskSectionView.h" #include "TaskActiveView.h" #include "TaskDetail.h" #include "ViewProviderPage.h" #include "ViewProviderViewPart.h" -#include "QGIViewPart.h" -#include "Rez.h" + class Vertex; using namespace TechDrawGui; @@ -807,7 +808,15 @@ bool _checkDrawViewPartBalloon(Gui::Command* cmd) { bool _checkDirectPlacement(const QGIViewPart *viewPart, const std::vector &subNames, QPointF &placement) { + // Let's see, if we can help speed up the placement of the balloon: + // As of now we support: + // Single selected vertex: place the ballon tip end here + // Single selected edge: place the ballon tip at its midpoint (suggested placement for e.g. chamfer dimensions) + // + // Single selected faces are currently not supported, but maybe we could in this case use the center of mass? + if (subNames.size() != 1) { + // If nothing or more than one subjects are selected, let the user decide, where to place the balloon return false; } diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index 81654e5d04..a977ae0589 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -489,14 +489,11 @@ void QGVPage::createBalloon(QPointF origin, DrawViewPart *parent) std::string featName = getDrawPage()->getDocument()->getUniqueObjectName("Balloon"); std::string pageName = getDrawPage()->getNameInDocument(); - Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Balloon")); - TechDraw::DrawViewBalloon *balloon = 0; - Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Balloon")); Command::doCommand(Command::Doc, "App.activeDocument().addObject('TechDraw::DrawViewBalloon','%s')", featName.c_str()); Command::doCommand(Command::Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", pageName.c_str(), featName.c_str()); - balloon = dynamic_cast(getDrawPage()->getDocument()->getObject(featName.c_str())); + TechDraw::DrawViewBalloon *balloon = dynamic_cast(getDrawPage()->getDocument()->getObject(featName.c_str())); if (!balloon) { throw Base::TypeError("CmdTechDrawNewBalloon - balloon not found\n"); } @@ -506,8 +503,8 @@ void QGVPage::createBalloon(QPointF origin, DrawViewPart *parent) Gui::Command::commitCommand(); - balloon->recomputeFeature(); parent->touch(true); + Gui::Command::updateActive(); } QGIView * QGVPage::addViewDimension(TechDraw::DrawViewDimension *dim) @@ -1264,21 +1261,24 @@ double QGVPage::getDevicePixelRatio() const { } QPixmap QGVPage::prepareCursorPixmap(const char *iconName, QPoint &hotspot) { - double cursorSize = 64.0; + double pixelRatio = getDevicePixelRatio(); - if (pixelRatio != 1.0) { - cursorSize = 32.0*pixelRatio; - } - + // Due to impossibility to query cursor size via Qt API, we stick to (32x32)*device_pixel_ratio + // as FreeCAD Wiki suggests - see https://wiki.freecadweb.org/HiDPI_support#Custom_cursor_size + double cursorSize = 32.0*pixelRatio; + QPixmap pixmap = Gui::BitmapFactory().pixmapFromSvg(iconName, QSizeF(cursorSize, cursorSize)); - if (pixelRatio == 1.0) { - pixmap = pixmap.scaled(32, 32); - hotspot /= 2; - } pixmap.setDevicePixelRatio(pixelRatio); + // The default (and here expected) SVG cursor graphics size is 64x64 pixels, thus we must adjust + // the 64x64 based hotspot position for our 32x32 based cursor pixmaps accordingly + hotspot /= 2; + #if !defined(Q_OS_WIN32) && !defined(Q_OS_MAC) + // On XCB platform, the pixmap device pixel ratio is not taken into account for cursor hot spot, + // therefore we must take care of the transformation ourselves... + // Refer to QTBUG-68571 - https://bugreports.qt.io/browse/QTBUG-68571 if (qGuiApp->platformName() == QLatin1String("xcb")) { hotspot *= pixelRatio; } From b485155c33bb81f743053b300f88dddc2df534c4 Mon Sep 17 00:00:00 2001 From: Tomas Pavlicek Date: Sat, 9 Oct 2021 00:30:28 +0200 Subject: [PATCH 3/3] TechDraw - Balloon updates - improve hospot calculation --- src/Mod/TechDraw/Gui/QGVPage.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index a977ae0589..903f9354fc 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -1262,6 +1262,7 @@ double QGVPage::getDevicePixelRatio() const { QPixmap QGVPage::prepareCursorPixmap(const char *iconName, QPoint &hotspot) { + QPointF floatHotspot(hotspot); double pixelRatio = getDevicePixelRatio(); // Due to impossibility to query cursor size via Qt API, we stick to (32x32)*device_pixel_ratio @@ -1273,17 +1274,18 @@ QPixmap QGVPage::prepareCursorPixmap(const char *iconName, QPoint &hotspot) { // The default (and here expected) SVG cursor graphics size is 64x64 pixels, thus we must adjust // the 64x64 based hotspot position for our 32x32 based cursor pixmaps accordingly - hotspot /= 2; + floatHotspot *= 0.5; #if !defined(Q_OS_WIN32) && !defined(Q_OS_MAC) // On XCB platform, the pixmap device pixel ratio is not taken into account for cursor hot spot, // therefore we must take care of the transformation ourselves... // Refer to QTBUG-68571 - https://bugreports.qt.io/browse/QTBUG-68571 if (qGuiApp->platformName() == QLatin1String("xcb")) { - hotspot *= pixelRatio; + floatHotspot *= pixelRatio; } #endif + hotspot = floatHotspot.toPoint(); return pixmap; }