From 9894964eb69e9014f6f14afbf9188b0477cb7fc8 Mon Sep 17 00:00:00 2001 From: Wanderer Fan Date: Fri, 8 Apr 2022 19:24:15 -0400 Subject: [PATCH] [TD]implement navigation styles --- src/Mod/TechDraw/App/DrawViewBalloon.cpp | 15 + src/Mod/TechDraw/App/DrawViewBalloon.h | 4 +- src/Mod/TechDraw/Gui/CMakeLists.txt | 49 +- src/Mod/TechDraw/Gui/Command.cpp | 6 +- src/Mod/TechDraw/Gui/CommandExtensionPack.cpp | 7 +- src/Mod/TechDraw/Gui/DrawGuiUtil.cpp | 3 +- src/Mod/TechDraw/Gui/MDIViewPage.cpp | 106 +- src/Mod/TechDraw/Gui/MDIViewPage.h | 12 +- src/Mod/TechDraw/Gui/QGIDrawingTemplate.cpp | 2 +- src/Mod/TechDraw/Gui/QGIDrawingTemplate.h | 3 +- src/Mod/TechDraw/Gui/QGISVGTemplate.cpp | 3 +- src/Mod/TechDraw/Gui/QGISVGTemplate.h | 3 +- src/Mod/TechDraw/Gui/QGITemplate.cpp | 3 +- src/Mod/TechDraw/Gui/QGITemplate.h | 3 +- src/Mod/TechDraw/Gui/QGIView.cpp | 18 +- src/Mod/TechDraw/Gui/QGIView.h | 2 + src/Mod/TechDraw/Gui/QGIViewBalloon.cpp | 1 - src/Mod/TechDraw/Gui/QGIViewDimension.h | 3 + src/Mod/TechDraw/Gui/QGSPage.cpp | 910 +++++++++++++++ src/Mod/TechDraw/Gui/QGSPage.h | 149 +++ src/Mod/TechDraw/Gui/QGTracker.cpp | 3 +- src/Mod/TechDraw/Gui/QGTracker.h | 7 +- src/Mod/TechDraw/Gui/QGVNavStyle.cpp | 414 +++++++ src/Mod/TechDraw/Gui/QGVNavStyle.h | 123 ++ src/Mod/TechDraw/Gui/QGVNavStyleBlender.cpp | 101 ++ src/Mod/TechDraw/Gui/QGVNavStyleBlender.h | 55 + src/Mod/TechDraw/Gui/QGVNavStyleCAD.cpp | 150 +++ src/Mod/TechDraw/Gui/QGVNavStyleCAD.h | 55 + src/Mod/TechDraw/Gui/QGVNavStyleGesture.cpp | 78 ++ src/Mod/TechDraw/Gui/QGVNavStyleGesture.h | 53 + src/Mod/TechDraw/Gui/QGVNavStyleInventor.cpp | 106 ++ src/Mod/TechDraw/Gui/QGVNavStyleInventor.h | 51 + src/Mod/TechDraw/Gui/QGVNavStyleMaya.cpp | 123 ++ src/Mod/TechDraw/Gui/QGVNavStyleMaya.h | 55 + src/Mod/TechDraw/Gui/QGVNavStyleOCC.cpp | 109 ++ src/Mod/TechDraw/Gui/QGVNavStyleOCC.h | 52 + src/Mod/TechDraw/Gui/QGVNavStyleOpenSCAD.cpp | 114 ++ src/Mod/TechDraw/Gui/QGVNavStyleOpenSCAD.h | 55 + src/Mod/TechDraw/Gui/QGVNavStyleRevit.cpp | 89 ++ src/Mod/TechDraw/Gui/QGVNavStyleRevit.h | 54 + src/Mod/TechDraw/Gui/QGVNavStyleTinkerCAD.cpp | 83 ++ src/Mod/TechDraw/Gui/QGVNavStyleTinkerCAD.h | 53 + src/Mod/TechDraw/Gui/QGVNavStyleTouchpad.cpp | 130 +++ src/Mod/TechDraw/Gui/QGVNavStyleTouchpad.h | 53 + src/Mod/TechDraw/Gui/QGVPage.cpp | 1020 +++-------------- src/Mod/TechDraw/Gui/QGVPage.h | 86 +- src/Mod/TechDraw/Gui/TaskActiveView.h | 1 + src/Mod/TechDraw/Gui/TaskCenterLine.h | 1 + src/Mod/TechDraw/Gui/TaskCosVertex.cpp | 5 +- src/Mod/TechDraw/Gui/TaskCosVertex.h | 4 +- src/Mod/TechDraw/Gui/TaskCosmeticLine.h | 1 + src/Mod/TechDraw/Gui/TaskCustomizeFormat.h | 1 + src/Mod/TechDraw/Gui/TaskDetail.cpp | 5 +- src/Mod/TechDraw/Gui/TaskDetail.h | 3 +- src/Mod/TechDraw/Gui/TaskLeaderLine.cpp | 15 +- src/Mod/TechDraw/Gui/TaskLeaderLine.h | 4 +- src/Mod/TechDraw/Gui/TaskRichAnno.cpp | 9 +- src/Mod/TechDraw/Gui/TaskRichAnno.h | 2 + .../TechDraw/Gui/TaskSelectLineAttributes.h | 1 + src/Mod/TechDraw/Gui/TaskWeldingSymbol.h | 1 + .../TechDraw/Gui/ViewProviderDrawingView.cpp | 9 +- src/Mod/TechDraw/Gui/ViewProviderPage.cpp | 13 +- src/Mod/TechDraw/Gui/ViewProviderPage.h | 4 + src/Mod/TechDraw/Gui/ViewProviderTemplate.cpp | 4 +- 64 files changed, 3623 insertions(+), 1034 deletions(-) create mode 100644 src/Mod/TechDraw/Gui/QGSPage.cpp create mode 100644 src/Mod/TechDraw/Gui/QGSPage.h create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyle.cpp create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyle.h create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleBlender.cpp create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleBlender.h create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleCAD.cpp create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleCAD.h create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleGesture.cpp create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleGesture.h create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleInventor.cpp create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleInventor.h create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleMaya.cpp create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleMaya.h create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleOCC.cpp create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleOCC.h create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleOpenSCAD.cpp create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleOpenSCAD.h create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleRevit.cpp create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleRevit.h create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleTinkerCAD.cpp create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleTinkerCAD.h create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleTouchpad.cpp create mode 100644 src/Mod/TechDraw/Gui/QGVNavStyleTouchpad.h diff --git a/src/Mod/TechDraw/App/DrawViewBalloon.cpp b/src/Mod/TechDraw/App/DrawViewBalloon.cpp index fc0581e3dd..05ae795ad3 100644 --- a/src/Mod/TechDraw/App/DrawViewBalloon.cpp +++ b/src/Mod/TechDraw/App/DrawViewBalloon.cpp @@ -286,6 +286,21 @@ int DrawViewBalloon::prefEnd(void) const return Preferences::balloonArrow(); } +QPointF DrawViewBalloon::getOrigin() +{ + double x = OriginX.getValue(); + double y = OriginY.getValue(); + QPointF result(x, y); + return result; +} + +void DrawViewBalloon::setOrigin(QPointF p) +{ + OriginX.setValue(p.x()); + OriginY.setValue(p.y()); + origin = p; +} + Base::Vector3d DrawViewBalloon::getOriginOffset() const { double x = X.getValue(); diff --git a/src/Mod/TechDraw/App/DrawViewBalloon.h b/src/Mod/TechDraw/App/DrawViewBalloon.h index 91090015ea..dcc5d24c6e 100644 --- a/src/Mod/TechDraw/App/DrawViewBalloon.h +++ b/src/Mod/TechDraw/App/DrawViewBalloon.h @@ -62,7 +62,9 @@ public: short mustExecute() const override; DrawViewPart* getViewPart() const; - QPointF origin; + QPointF origin; //WF never used?? + QPointF getOrigin(); + void setOrigin(QPointF p); //virtual PyObject *getPyObject(void); diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index 7d6d8007ce..306111ac2c 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -146,9 +146,6 @@ SET(TechDrawGui_SRCS DlgPrefsTechDrawHLR.ui DlgPrefsTechDrawHLRImp.cpp DlgPrefsTechDrawHLRImp.h - TaskLinkDim.ui - TaskLinkDim.cpp - TaskLinkDim.h DlgTemplateField.ui DlgTemplateField.cpp DlgTemplateField.h @@ -182,6 +179,9 @@ SET(TechDrawGui_SRCS TaskLineDecor.ui TaskLineDecor.cpp TaskLineDecor.h + TaskLinkDim.ui + TaskLinkDim.cpp + TaskLinkDim.h TaskRestoreLines.ui TaskWeldingSymbol.ui TaskWeldingSymbol.cpp @@ -223,6 +223,8 @@ SET(TechDrawGuiView_SRCS MDIViewPage.h QGVPage.cpp QGVPage.h + QGSPage.cpp + QGSPage.h QGCustomText.cpp QGCustomText.h QGICaption.cpp @@ -315,6 +317,32 @@ SET(TechDrawGuiView_SRCS QGIGhostHighlight.cpp QGIGhostHighlight.h ) + +SET(TechDrawGuiNav_SRCS + QGVNavStyle.cpp + QGVNavStyle.h + QGVNavStyleBlender.cpp + QGVNavStyleBlender.h + QGVNavStyleCAD.cpp + QGVNavStyleCAD.h + QGVNavStyleGesture.cpp + QGVNavStyleGesture.h + QGVNavStyleInventor.cpp + QGVNavStyleInventor.h + QGVNavStyleMaya.cpp + QGVNavStyleMaya.h + QGVNavStyleOCC.cpp + QGVNavStyleOCC.h + QGVNavStyleOpenSCAD.cpp + QGVNavStyleOpenSCAD.h + QGVNavStyleRevit.cpp + QGVNavStyleRevit.h + QGVNavStyleTinkerCAD.cpp + QGVNavStyleTinkerCAD.h + QGVNavStyleTouchpad.cpp + QGVNavStyleTouchpad.h +) + SET(TechDrawGuiViewProvider_SRCS ViewProviderPage.cpp ViewProviderPage.h @@ -360,11 +388,6 @@ SET(TechDrawGuiViewProvider_SRCS ViewProviderCosmeticExtension.h ) -SOURCE_GROUP("MRTE" FILES ${MRTE_SRCS}) -SOURCE_GROUP("Mod" FILES ${TechDrawGui_SRCS}) -SOURCE_GROUP("SVG-View" FILES ${TechDrawGuiView_SRCS}) -SOURCE_GROUP("ViewProvider" FILES ${TechDrawGuiViewProvider_SRCS}) - SET(TechDrawGuiTaskDlgs_SRCS TaskProjGroup.ui TaskLinkDim.ui @@ -389,8 +412,13 @@ SET(TechDrawGuiTaskDlgs_SRCS TaskCustomizeFormat.ui TaskMoveView.ui TaskProjection.ui - ) + +SOURCE_GROUP("MRTE" FILES ${MRTE_SRCS}) +SOURCE_GROUP("Mod" FILES ${TechDrawGui_SRCS}) +SOURCE_GROUP("View" FILES ${TechDrawGuiView_SRCS}) +SOURCE_GROUP("Nav" FILES ${TechDrawGuiNav_SRCS}) +SOURCE_GROUP("ViewProvider" FILES ${TechDrawGuiViewProvider_SRCS}) SOURCE_GROUP("TaskDialogs" FILES ${TechDrawGuiTaskDlgs_SRCS}) SET(TechDrawGuiIcon_SVG @@ -406,12 +434,13 @@ SET(TechDrawGuiFonts if(FREECAD_USE_PCH) add_definitions(-D_PreComp_) GET_MSVC_PRECOMPILED_SOURCE("PreCompiled.cpp" PCH_SRCS ${TechDrawGui_SRCS} ${TechDrawGuiView_SRCS} + ${TechDrawGuiNav_SRCS} ${TechDrawGuiViewProvider_SRCS} ${MRTE_SRCS}) ADD_MSVC_PRECOMPILED_HEADER(TechDrawGui PreCompiled.h PreCompiled.cpp PCH_SRCS) endif(FREECAD_USE_PCH) add_library(TechDrawGui SHARED ${TechDrawGui_SRCS} ${TechDrawGuiView_SRCS} ${TechDrawGuiViewProvider_SRCS} - ${TechDrawGuiIcon_SVG} ${TechDrawGuiFonts} ${MRTE_SRCS}) + ${TechDrawGuiNav_SRCS} ${TechDrawGuiIcon_SVG} ${TechDrawGuiFonts} ${MRTE_SRCS}) target_link_libraries(TechDrawGui ${TechDrawGui_LIBS}) fc_copy_sources(TechDrawGui "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/TechDraw/" ${TechDrawGuiIcon_SVG}) diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index 4eb58025bd..732b820f2f 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -85,9 +85,10 @@ #include #include #include -#include #include "DrawGuiUtil.h" +#include "QGSPage.h" +#include "QGVPage.h" #include "MDIViewPage.h" #include "PreferencesGui.h" #include "QGIViewPart.h" @@ -890,13 +891,14 @@ void CmdTechDrawBalloon::activated(int iMsg) if (pageVP && partVP) { QGVPage* viewPage = pageVP->getGraphicsView(); + QGSPage* scenePage = pageVP->getGraphicsScene(); if (viewPage) { viewPage->startBalloonPlacing(); QGIViewPart* viewPart = dynamic_cast(partVP->getQView()); QPointF placement; if (viewPart && _checkDirectPlacement(viewPart, selection[0].getSubNames(), placement)) { - viewPage->createBalloon(placement, objFeat); + scenePage->createBalloon(placement, objFeat); } } } diff --git a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp index 166817891e..d7cf2c4814 100644 --- a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp +++ b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp @@ -66,6 +66,7 @@ # include # include "ViewProviderBalloon.h" +# include "QGSPage.h" # include "QGVPage.h" # include "DrawGuiUtil.h" # include "ViewProviderPage.h" @@ -1884,9 +1885,9 @@ namespace TechDrawGui { Gui::Document* guiDoc = Gui::Application::Instance->getDocument(page->getDocument()); ViewProviderPage* pageVP = dynamic_cast(guiDoc->getViewProvider(page)); if (pageVP) { - QGVPage* viewPage = pageVP->getGraphicsView(); - featName = viewPage->getDrawPage()->getDocument()->getUniqueObjectName("Balloon"); - std::string pageName = viewPage->getDrawPage()->getNameInDocument(); + QGSPage* scenePage = pageVP->getGraphicsScene(); + featName = scenePage->getDrawPage()->getDocument()->getUniqueObjectName("Balloon"); + std::string pageName = scenePage->getDrawPage()->getNameInDocument(); cmd->doCommand(cmd->Doc, "App.activeDocument().addObject('TechDraw::DrawViewBalloon','%s')", featName.c_str()); cmd->doCommand(cmd->Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", diff --git a/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp b/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp index 5d4b0c5752..4d3be0aa33 100644 --- a/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp +++ b/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp @@ -78,6 +78,7 @@ #include #include +#include "QGSPage.h" #include "QGVPage.h" #include "MDIViewPage.h" #include "ViewProviderPage.h" @@ -128,7 +129,7 @@ TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd) MDIViewPage* mvp = dynamic_cast(mv); if (mvp) { QString windowTitle = mvp->windowTitle(); - QGVPage* qp = mvp->getQGVPage(); + QGSPage* qp = mvp->getQGSPage(); page = qp->getDrawPage(); } else { diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.cpp b/src/Mod/TechDraw/Gui/MDIViewPage.cpp index 2648a6c7e3..4e0ddf4050 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.cpp +++ b/src/Mod/TechDraw/Gui/MDIViewPage.cpp @@ -101,6 +101,7 @@ #include "QGIEdge.h" #include "QGIFace.h" #include "ViewProviderPage.h" +#include "QGSPage.h" #include "QGVPage.h" #include "QGILeaderLine.h" #include "QGIRichAnno.h" @@ -126,7 +127,7 @@ MDIViewPage::MDIViewPage(ViewProviderPage *pageVp, Gui::Document* doc, QWidget* { setMouseTracking(true); - m_scene = new QGraphicsScene(this); + m_scene = new QGSPage(pageVp, this); m_scene->setItemIndexMethod(QGraphicsScene::NoIndex); //this prevents crash when deleting dims. //scene(view?) indices of dirty regions gets //out of sync. missing prepareGeometryChange @@ -161,7 +162,7 @@ MDIViewPage::MDIViewPage(ViewProviderPage *pageVp, Gui::Document* doc, QWidget* // Connect Signals and Slots QObject::connect( - m_view->scene(), SIGNAL(selectionChanged()), + m_scene, SIGNAL(selectionChanged()), this , SLOT (sceneSelectionChanged()) ); @@ -169,6 +170,8 @@ MDIViewPage::MDIViewPage(ViewProviderPage *pageVp, Gui::Document* doc, QWidget* App::Document* appDoc = m_vpPage->getDocument()->getDocument(); auto bnd = boost::bind(&MDIViewPage::onDeleteObject, this, bp::_1); connectDeletedObject = appDoc->signalDeletedObject.connect(bnd); + +// setContextMenuPolicy(Qt::NoContextMenu); } @@ -218,22 +221,22 @@ void MDIViewPage::matchSceneRectToTemplate(void) //make sceneRect 1 pagesize bigger in every direction double width = Rez::guiX(pageTemplate->Width.getValue()); double height = Rez::guiX(pageTemplate->Height.getValue()); - m_view->scene()->setSceneRect(QRectF(-width,-2.0 * height,3.0*width,3.0*height)); + m_scene->setSceneRect(QRectF(-width,-2.0 * height,3.0*width,3.0*height)); } } void MDIViewPage::setDimensionGroups(void) { - const std::vector &allItems = m_view->getViews(); + const std::vector &allItems = m_scene->getViews(); std::vector::const_iterator itInspect; int dimItemType = QGraphicsItem::UserType + 106; for (itInspect = allItems.begin(); itInspect != allItems.end(); itInspect++) { if (((*itInspect)->type() == dimItemType) && (!(*itInspect)->group())) { - QGIView* parent = m_view->findParent((*itInspect)); + QGIView* parent = m_scene->findParent((*itInspect)); if (parent) { QGIViewDimension* dim = dynamic_cast((*itInspect)); - m_view->addDimToParent(dim,parent); + m_scene->addDimToParent(dim,parent); } } } @@ -241,16 +244,16 @@ void MDIViewPage::setDimensionGroups(void) void MDIViewPage::setBalloonGroups(void) { - const std::vector &allItems = m_view->getViews(); + const std::vector &allItems = m_scene->getViews(); std::vector::const_iterator itInspect; int balloonItemType = QGraphicsItem::UserType + 140; for (itInspect = allItems.begin(); itInspect != allItems.end(); itInspect++) { if (((*itInspect)->type() == balloonItemType) && (!(*itInspect)->group())) { - QGIView* parent = m_view->findParent((*itInspect)); + QGIView* parent = m_scene->findParent((*itInspect)); if (parent) { QGIViewBalloon* balloon = dynamic_cast((*itInspect)); - m_view->addBalloonToParent(balloon,parent); + m_scene->addBalloonToParent(balloon,parent); } } } @@ -259,7 +262,7 @@ void MDIViewPage::setBalloonGroups(void) void MDIViewPage::setLeaderGroups(void) { // Base::Console().Message("MDIVP::setLeaderGroups()\n"); - const std::vector &allItems = m_view->getViews(); + const std::vector &allItems = m_scene->getViews(); std::vector::const_iterator itInspect; int leadItemType = QGraphicsItem::UserType + 232; @@ -267,10 +270,10 @@ void MDIViewPage::setLeaderGroups(void) //quite possibly redundant for (itInspect = allItems.begin(); itInspect != allItems.end(); itInspect++) { if (((*itInspect)->type() == leadItemType) && (!(*itInspect)->group())) { - QGIView* parent = m_view->findParent((*itInspect)); + QGIView* parent = m_scene->findParent((*itInspect)); if (parent) { QGILeaderLine* lead = dynamic_cast((*itInspect)); - m_view->addLeaderToParent(lead,parent); + m_scene->addLeaderToParent(lead,parent); } } } @@ -309,7 +312,7 @@ void MDIViewPage::closeEvent(QCloseEvent* ev) void MDIViewPage::attachTemplate(TechDraw::DrawTemplate *obj) { - m_view->setPageTemplate(obj); + m_scene->setPageTemplate(obj); pagewidth = obj->Width.getValue(); pageheight = obj->Height.getValue(); m_paperSize = QPageSize::id(QSizeF(pagewidth, pageheight), QPageSize::Millimeter, QPageSize::FuzzyOrientationMatch); @@ -350,46 +353,46 @@ bool MDIViewPage::attachView(App::DocumentObject *obj) QGIView *qview(nullptr); if (typeId.isDerivedFrom(TechDraw::DrawViewSection::getClassTypeId()) ) { - qview = m_view->addViewSection( static_cast(obj) ); + qview = m_scene->addViewSection( static_cast(obj) ); } else if (typeId.isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId()) ) { - qview = m_view->addViewPart( static_cast(obj) ); + qview = m_scene->addViewPart( static_cast(obj) ); } else if (typeId.isDerivedFrom(TechDraw::DrawProjGroup::getClassTypeId()) ) { - qview = m_view->addProjectionGroup( static_cast(obj) ); + qview = m_scene->addProjectionGroup( static_cast(obj) ); } else if (typeId.isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId()) ) { - qview = m_view->addDrawView( static_cast(obj) ); + qview = m_scene->addDrawView( static_cast(obj) ); } else if (typeId.isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()) ) { - qview = m_view->addViewDimension( static_cast(obj) ); + qview = m_scene->addViewDimension( static_cast(obj) ); } else if (typeId.isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId()) ) { - qview = m_view->addViewBalloon( static_cast(obj) ); + qview = m_scene->addViewBalloon( static_cast(obj) ); } else if (typeId.isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId()) ) { - qview = m_view->addDrawViewAnnotation( static_cast(obj) ); + qview = m_scene->addDrawViewAnnotation( static_cast(obj) ); } else if (typeId.isDerivedFrom(TechDraw::DrawViewSymbol::getClassTypeId()) ) { - qview = m_view->addDrawViewSymbol( static_cast(obj) ); + qview = m_scene->addDrawViewSymbol( static_cast(obj) ); } else if (typeId.isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId()) ) { - qview = m_view->addDrawViewClip( static_cast(obj) ); + qview = m_scene->addDrawViewClip( static_cast(obj) ); } else if (typeId.isDerivedFrom(TechDraw::DrawViewSpreadsheet::getClassTypeId()) ) { - qview = m_view->addDrawViewSpreadsheet( static_cast(obj) ); + qview = m_scene->addDrawViewSpreadsheet( static_cast(obj) ); } else if (typeId.isDerivedFrom(TechDraw::DrawViewImage::getClassTypeId()) ) { - qview = m_view->addDrawViewImage( static_cast(obj) ); + qview = m_scene->addDrawViewImage( static_cast(obj) ); } else if (typeId.isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId()) ) { - qview = m_view->addViewLeader( static_cast(obj) ); + qview = m_scene->addViewLeader( static_cast(obj) ); } else if (typeId.isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId()) ) { - qview = m_view->addRichAnno( static_cast(obj) ); + qview = m_scene->addRichAnno( static_cast(obj) ); } else if (typeId.isDerivedFrom(TechDraw::DrawWeldSymbol::getClassTypeId()) ) { - qview = m_view->addWeldSymbol( static_cast(obj) ); + qview = m_scene->addWeldSymbol( static_cast(obj) ); } else if (typeId.isDerivedFrom(TechDraw::DrawHatch::getClassTypeId()) ) { //Hatch is not attached like other Views (since it isn't really a View) @@ -408,7 +411,7 @@ void MDIViewPage::onDeleteObject(const App::DocumentObject& obj) //if this page has a QView for this obj, delete it. blockSceneSelection(true); if (obj.isDerivedFrom(TechDraw::DrawView::getClassTypeId())) { - (void) m_view->removeQViewByName(obj.getNameInDocument()); + (void) m_scene->removeQViewByName(obj.getNameInDocument()); } blockSceneSelection(false); } @@ -432,7 +435,7 @@ void MDIViewPage::updateTemplate(bool forceUpdate) if(forceUpdate || (templObj && templObj->isTouched() && templObj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) ) { - QGITemplate *qItemTemplate = m_view->getTemplate(); + QGITemplate *qItemTemplate = m_scene->getTemplate(); if(qItemTemplate) { TechDraw::DrawTemplate *pageTemplate = dynamic_cast(templObj); @@ -470,13 +473,13 @@ void MDIViewPage::fixOrphans(bool force) if (dv->isRemoving()) { continue; } - QGIView* qv = m_view->findQViewForDocObj(dv); + QGIView* qv = m_scene->findQViewForDocObj(dv); if (qv == nullptr) { attachView(dv); } } // if qView doesn't have a Feature on this Page, delete it - std::vector qvss = m_view->getViews(); + std::vector qvss = m_scene->getViews(); // qvss may contain an item and its child item(s) and to avoid to access a deleted item a QPointer is needed std::vector> qvs; std::for_each(qvss.begin(), qvss.end(), [&qvs](QGIView* v) { @@ -489,21 +492,21 @@ void MDIViewPage::fixOrphans(bool force) App::DocumentObject* obj = doc->getObject(qv->getViewName()); if (obj == nullptr) { //no DrawView anywhere in Document - m_view->removeQView(qv); + m_scene->removeQView(qv); } else { //DrawView exists in Document. Does it belong to this DrawPage? int numParentPages = qv->getViewObject()->countParentPages(); if (numParentPages == 0) { //DrawView does not belong to any DrawPage //remove QGItem from QGScene - m_view->removeQView(qv); + m_scene->removeQView(qv); } else if (numParentPages == 1) { //Does DrawView belong to this DrawPage? TechDraw::DrawPage* pp = qv->getViewObject()->findParentPage(); if (thisPage != pp) { //DrawView does not belong to this DrawPage //remove QGItem from QGScene - m_view->removeQView(qv); + m_scene->removeQView(qv); } } else if (numParentPages > 1) { //DrawView belongs to multiple DrawPages @@ -519,7 +522,7 @@ void MDIViewPage::fixOrphans(bool force) } if (!found) { //none of the parent Pages for View correspond to this Page - m_view->removeQView(qv); + m_scene->removeQView(qv); } } } @@ -529,7 +532,7 @@ void MDIViewPage::fixOrphans(bool force) //NOTE: this doesn't add missing views. see fixOrphans() void MDIViewPage::redrawAllViews() { - const std::vector &upviews = m_view->getViews(); + const std::vector &upviews = m_scene->getViews(); for(std::vector::const_iterator it = upviews.begin(); it != upviews.end(); ++it) { (*it)->updateView(true); } @@ -539,7 +542,7 @@ void MDIViewPage::redrawAllViews() void MDIViewPage::redraw1View(TechDraw::DrawView* dv) { std::string dvName = dv->getNameInDocument(); - const std::vector &upviews = m_view->getViews(); + const std::vector &upviews = m_scene->getViews(); for(std::vector::const_iterator it = upviews.begin(); it != upviews.end(); ++it) { std::string qgivName = (*it)->getViewName(); if(dvName == qgivName) { @@ -572,7 +575,7 @@ void MDIViewPage::findMissingViews(const std::vector &list /// Helper function bool MDIViewPage::hasQView(App::DocumentObject *obj) { - const std::vector &views = m_view->getViews(); + const std::vector &views = m_scene->getViews(); std::vector::const_iterator qview = views.begin(); while(qview != views.end()) { @@ -807,7 +810,7 @@ void MDIViewPage::print(QPrinter* printer) bool saveState = m_vpPage->getFrameState(); m_vpPage->setFrameState(false); m_vpPage->setTemplateMarkers(false); - m_view->refreshViews(); + m_scene->refreshViews(); Gui::Selection().clearSelection(); @@ -821,12 +824,12 @@ void MDIViewPage::print(QPrinter* printer) } QRectF sourceRect(0.0,-height,width,height); - m_view->scene()->render(&p, targetRect,sourceRect); + m_scene->render(&p, targetRect,sourceRect); // Reset m_vpPage->setFrameState(saveState); m_vpPage->setTemplateMarkers(saveState); - m_view->refreshViews(); + m_scene->refreshViews(); //bool block = static_cast (blockSelection(false)); } @@ -842,6 +845,7 @@ PyObject* MDIViewPage::getPyObject() void MDIViewPage::contextMenuEvent(QContextMenuEvent *event) { +// Base::Console().Message("MDIVP::contextMenuEvent() - reason: %d\n", event->reason()); QMenu menu; menu.addAction(m_toggleFrameAction); menu.addAction(m_toggleKeepUpdatedAction); @@ -864,8 +868,7 @@ void MDIViewPage::toggleKeepUpdated(void) void MDIViewPage::viewAll() { - //m_view->fitInView(m_view->scene()->sceneRect(), Qt::KeepAspectRatio); - m_view->fitInView(m_view->scene()->itemsBoundingRect(), Qt::KeepAspectRatio); + m_view->fitInView(m_scene->itemsBoundingRect(), Qt::KeepAspectRatio); } void MDIViewPage::saveSVG() @@ -880,7 +883,7 @@ void MDIViewPage::saveSVG() } static_cast (blockSelection(true)); // avoid to be notified by itself - m_view->saveSvg(fn); + m_scene->saveSvg(fn); } void MDIViewPage::saveSVG(std::string file) @@ -890,7 +893,7 @@ void MDIViewPage::saveSVG(std::string file) return; } QString filename = QString::fromUtf8(file.data(),file.size()); - m_view->saveSvg(filename); + m_scene->saveSvg(filename); } void MDIViewPage::saveDXF() @@ -1007,7 +1010,7 @@ void MDIViewPage::clearSceneSelection() blockSceneSelection(true); m_qgSceneSelected.clear(); - std::vector views = m_view->getViews(); + std::vector views = m_scene->getViews(); // Iterate through all views and unselect all for (std::vector::iterator it = views.begin(); it != views.end(); ++it) { @@ -1037,7 +1040,7 @@ void MDIViewPage::clearSceneSelection() //!Update QGIView's selection state based on Selection made outside Drawing Interface void MDIViewPage::selectQGIView(App::DocumentObject *obj, const bool isSelected) { - QGIView *view = m_view->findQViewForDocObj(obj); + QGIView *view = m_scene->findQViewForDocObj(obj); blockSceneSelection(true); if(view) { @@ -1081,7 +1084,7 @@ void MDIViewPage::onSelectionChanged(const Gui::SelectionChanges& msg) void MDIViewPage::sceneSelectionManager() { // Base::Console().Message("MDIVP::sceneSelectionManager()\n"); - QList sceneSel = m_view->scene()->selectedItems(); + QList sceneSel = m_scene->selectedItems(); if (sceneSel.isEmpty()) { m_qgSceneSelected.clear(); //TODO: need to signal somebody? Tree? handled elsewhere @@ -1124,13 +1127,11 @@ void MDIViewPage::sceneSelectionManager() } //! update Tree Selection from QGraphicsScene selection -//triggered by m_view->scene() signal +//triggered by m_scene signal void MDIViewPage::sceneSelectionChanged() { sceneSelectionManager(); -// QList dbsceneSel = m_view->scene()->selectedItems(); - if(isSelectionBlocked) { return; } @@ -1393,7 +1394,8 @@ void MDIViewPage::showStatusMsg(const char* s1, const char* s2, const char* s3) } } -MDIViewPage *MDIViewPage::getFromScene(const QGraphicsScene *scene) +//return the MDIViewPage that owns the scene +MDIViewPage *MDIViewPage::getFromScene(const QGSPage *scene) { if (scene != nullptr && scene->parent() != nullptr) { return dynamic_cast(scene->parent()); diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.h b/src/Mod/TechDraw/Gui/MDIViewPage.h index 459d0b37fa..c7ee1c4514 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.h +++ b/src/Mod/TechDraw/Gui/MDIViewPage.h @@ -51,6 +51,7 @@ namespace TechDrawGui class ViewProviderPage; class QGVPage; +class QGSPage; class QGIView; class TechDrawGuiExport MDIViewPage : public Gui::MDIView, public Gui::SelectionObserver @@ -98,8 +99,8 @@ public: TechDraw::DrawPage * getPage() { return m_vpPage->getDrawPage(); } QGVPage* getQGVPage(void) {return m_view;} - - QGraphicsScene* m_scene; + QGSPage* getQGSPage(void) {return m_scene;} + ViewProviderPage* getViewProviderPage() {return m_vpPage;} QPointF getTemplateCenter(TechDraw::DrawTemplate *obj); void centerOnPage(void); @@ -111,7 +112,7 @@ public: bool addView(const App::DocumentObject *obj); - static MDIViewPage *getFromScene(const QGraphicsScene *scene); + static MDIViewPage *getFromScene(const QGSPage *scene); public Q_SLOTS: void viewAll(); @@ -129,7 +130,7 @@ protected: bool hasQView(App::DocumentObject *obj); bool orphanExists(const char *viewName, const std::vector &list); - /// Attaches view of obj to m_view. Returns true on success, false otherwise + /// Attaches view of obj to m_scene. Returns true on success, false otherwise bool attachView(App::DocumentObject *obj); void contextMenuEvent(QContextMenuEvent *event); @@ -161,6 +162,7 @@ private: std::string m_objectName; std::string m_documentName; bool isSelectionBlocked; + QGSPage* m_scene; QGVPage *m_view; QTimer *m_timer; @@ -171,7 +173,7 @@ private: ViewProviderPage *m_vpPage; QList m_qgSceneSelected; //items in selection order - QList deleteItems; +// QList deleteItems; }; class MDIViewPagePy : public Py::PythonExtension diff --git a/src/Mod/TechDraw/Gui/QGIDrawingTemplate.cpp b/src/Mod/TechDraw/Gui/QGIDrawingTemplate.cpp index 42c52625f2..aeb1da358d 100644 --- a/src/Mod/TechDraw/Gui/QGIDrawingTemplate.cpp +++ b/src/Mod/TechDraw/Gui/QGIDrawingTemplate.cpp @@ -47,7 +47,7 @@ using namespace TechDrawGui; -QGIDrawingTemplate::QGIDrawingTemplate(QGraphicsScene *scene) : QGITemplate(scene), +QGIDrawingTemplate::QGIDrawingTemplate(QGSPage* scene) : QGITemplate(scene), pathItem(nullptr) { pathItem = new QGraphicsPathItem; diff --git a/src/Mod/TechDraw/Gui/QGIDrawingTemplate.h b/src/Mod/TechDraw/Gui/QGIDrawingTemplate.h index 65427fefe8..98846c783b 100644 --- a/src/Mod/TechDraw/Gui/QGIDrawingTemplate.h +++ b/src/Mod/TechDraw/Gui/QGIDrawingTemplate.h @@ -36,13 +36,14 @@ class DrawParametricTemplate; namespace TechDrawGui { +class QGSPage; class TechDrawGuiExport QGIDrawingTemplate : public QGITemplate { Q_OBJECT public: - QGIDrawingTemplate(QGraphicsScene *); + QGIDrawingTemplate(QGSPage *); ~QGIDrawingTemplate(); enum {Type = QGraphicsItem::UserType + 151}; diff --git a/src/Mod/TechDraw/Gui/QGISVGTemplate.cpp b/src/Mod/TechDraw/Gui/QGISVGTemplate.cpp index ae64d6b80b..c06906dd83 100644 --- a/src/Mod/TechDraw/Gui/QGISVGTemplate.cpp +++ b/src/Mod/TechDraw/Gui/QGISVGTemplate.cpp @@ -48,12 +48,13 @@ #include "Rez.h" #include "ZVALUE.h" +#include "QGSPage.h" #include "TemplateTextField.h" #include "QGISVGTemplate.h" using namespace TechDrawGui; -QGISVGTemplate::QGISVGTemplate(QGraphicsScene *scene) +QGISVGTemplate::QGISVGTemplate(QGSPage* scene) : QGITemplate(scene), firstTime(true) { diff --git a/src/Mod/TechDraw/Gui/QGISVGTemplate.h b/src/Mod/TechDraw/Gui/QGISVGTemplate.h index e1ad90f127..06a11b637c 100644 --- a/src/Mod/TechDraw/Gui/QGISVGTemplate.h +++ b/src/Mod/TechDraw/Gui/QGISVGTemplate.h @@ -39,13 +39,14 @@ class DrawSVGTemplate; namespace TechDrawGui { +class QGSPage; class TechDrawGuiExport QGISVGTemplate : public QGITemplate { Q_OBJECT public: - QGISVGTemplate(QGraphicsScene *scene); + QGISVGTemplate(QGSPage* scene); virtual ~QGISVGTemplate(); enum {Type = QGraphicsItem::UserType + 153}; diff --git a/src/Mod/TechDraw/Gui/QGITemplate.cpp b/src/Mod/TechDraw/Gui/QGITemplate.cpp index 83477bd7f9..52e08b57f9 100644 --- a/src/Mod/TechDraw/Gui/QGITemplate.cpp +++ b/src/Mod/TechDraw/Gui/QGITemplate.cpp @@ -32,11 +32,12 @@ #include "ZVALUE.h" #include "TemplateTextField.h" +#include "QGSPage.h" #include "QGITemplate.h" using namespace TechDrawGui; -QGITemplate::QGITemplate(QGraphicsScene *scene) : QGraphicsItemGroup(), +QGITemplate::QGITemplate(QGSPage *scene) : QGraphicsItemGroup(), pageTemplate(nullptr) { setHandlesChildEvents(false); diff --git a/src/Mod/TechDraw/Gui/QGITemplate.h b/src/Mod/TechDraw/Gui/QGITemplate.h index e0d83ebbf2..2e33931ef5 100644 --- a/src/Mod/TechDraw/Gui/QGITemplate.h +++ b/src/Mod/TechDraw/Gui/QGITemplate.h @@ -37,13 +37,14 @@ class DrawTemplate; namespace TechDrawGui { class TemplateTextField; +class QGSPage; class TechDrawGuiExport QGITemplate : public QObject, public QGraphicsItemGroup { Q_OBJECT public: - QGITemplate(QGraphicsScene *); + QGITemplate(QGSPage *); ~QGITemplate(); enum {Type = QGraphicsItem::UserType + 150}; diff --git a/src/Mod/TechDraw/Gui/QGIView.cpp b/src/Mod/TechDraw/Gui/QGIView.cpp index 8ade335d3b..e18dce5fc7 100644 --- a/src/Mod/TechDraw/Gui/QGIView.cpp +++ b/src/Mod/TechDraw/Gui/QGIView.cpp @@ -53,6 +53,7 @@ #include "Rez.h" #include "ZVALUE.h" #include "DrawGuiUtil.h" +#include "QGSPage.h" #include "QGVPage.h" #include "QGCustomLabel.h" #include "QGCustomBorder.h" @@ -628,9 +629,24 @@ QGVPage* QGIView::getGraphicsView(TechDraw::DrawView* dv) return graphicsView; } +QGSPage* QGIView::getGraphicsScene(TechDraw::DrawView* dv) +{ + QGSPage* graphicsScene = nullptr; + Gui::ViewProvider* vp = getViewProvider(dv); + ViewProviderDrawingView* vpdv = dynamic_cast(vp); + if (vpdv != nullptr) { + MDIViewPage* mdi = vpdv->getMDIViewPage(); + if (mdi != nullptr) { + graphicsScene = mdi->getQGSPage(); + } + } + return graphicsScene; +} + MDIViewPage* QGIView::getMDIViewPage(void) const { - return MDIViewPage::getFromScene(scene()); + QGSPage* qgsp = static_cast(scene()); + return MDIViewPage::getFromScene(qgsp); } //remove a child of this from scene while keeping scene indexes valid diff --git a/src/Mod/TechDraw/Gui/QGIView.h b/src/Mod/TechDraw/Gui/QGIView.h index cfc381515f..71610e9def 100644 --- a/src/Mod/TechDraw/Gui/QGIView.h +++ b/src/Mod/TechDraw/Gui/QGIView.h @@ -58,6 +58,7 @@ class DrawView; namespace TechDrawGui { +class QGSPage; class QGVPage; class QGCustomBorder; class QGCustomLabel; @@ -129,6 +130,7 @@ public: static Gui::ViewProvider* getViewProvider(App::DocumentObject* obj); static QGVPage* getGraphicsView(TechDraw::DrawView* dv); + static QGSPage* getGraphicsScene(TechDraw::DrawView* dv); static int calculateFontPixelSize(double sizeInMillimetres); static int calculateFontPixelWidth(const QFont &font); static const double DefaultFontSizeInMM; diff --git a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp index 67aeda1ae1..1788d172e2 100644 --- a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp @@ -578,7 +578,6 @@ void QGIViewBalloon::placeBalloon(QPointF pos) return; } - QGIView* qgivParent = nullptr; QPointF viewPos; Gui::ViewProvider* objVp = QGIView::getViewProvider(balloonParent); diff --git a/src/Mod/TechDraw/Gui/QGIViewDimension.h b/src/Mod/TechDraw/Gui/QGIViewDimension.h index cff2c7f2a7..4be07c71ca 100644 --- a/src/Mod/TechDraw/Gui/QGIViewDimension.h +++ b/src/Mod/TechDraw/Gui/QGIViewDimension.h @@ -23,6 +23,8 @@ #ifndef DRAWINGGUI_QGRAPHICSITEMVIEWDIMENSION_H #define DRAWINGGUI_QGRAPHICSITEMVIEWDIMENSION_H +#include + #include #include #include @@ -47,6 +49,7 @@ class AOC; namespace TechDrawGui { +class QGCustomText; class QGIArrow; class QGIDimLines; class QGIViewDimension; diff --git a/src/Mod/TechDraw/Gui/QGSPage.cpp b/src/Mod/TechDraw/Gui/QGSPage.cpp new file mode 100644 index 0000000000..c9aa9ef802 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGSPage.cpp @@ -0,0 +1,910 @@ +/*************************************************************************** + * Copyright (c) 2020 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#include +# include +#include +#include +#include +#include +#include +#include +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Rez.h" +#include "PreferencesGui.h" +#include "QGIDrawingTemplate.h" +#include "QGITemplate.h" +#include "QGISVGTemplate.h" +#include "TemplateTextField.h" +#include "QGIViewCollection.h" +#include "QGIViewDimension.h" +#include "QGIViewBalloon.h" +#include "QGIProjGroup.h" +#include "QGIViewPart.h" +#include "QGIViewSection.h" +#include "QGIViewAnnotation.h" +#include "QGIViewSymbol.h" +#include "QGIViewClip.h" +#include "QGIViewSpreadsheet.h" +#include "QGIViewImage.h" +#include "QGIFace.h" +#include "QGILeaderLine.h" +#include "QGIRichAnno.h" +#include "QGIWeldSymbol.h" +#include "QGITile.h" + +#include "ZVALUE.h" +#include "ViewProviderPage.h" +#include "QGSPage.h" +#include "MDIViewPage.h" + +// used SVG namespaces +#define CC_NS_URI "http://creativecommons.org/ns#" +#define DC_NS_URI "http://purl.org/dc/elements/1.1/" +#define RDF_NS_URI "http://www.w3.org/1999/02/22-rdf-syntax-ns#" +#define INKSCAPE_NS_URI "http://www.inkscape.org/namespaces/inkscape" +#define SODIPODI_NS_URI "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + +using namespace Gui; +using namespace TechDraw; +using namespace TechDrawGui; + +QGSPage::QGSPage(ViewProviderPage *vp, QWidget *parent) + : QGraphicsScene(parent), + pageTemplate(nullptr), + m_renderer(Native), + drawBkg(true), + m_vpPage(nullptr) +{ + assert(vp); + m_vpPage = vp; + const char* name = vp->getDrawPage()->getNameInDocument(); + setObjectName(QString::fromLocal8Bit(name)); + m_vpPage->setGraphicsScene(this); + + bkgBrush = new QBrush(getBackgroundColor()); + +} + +QGSPage::~QGSPage() +{ + delete bkgBrush; + +} + +//! retrieve the QGIView objects currently in the scene +std::vector QGSPage::getViews() const +{ + std::vector result; + QList items = this->items(); + for (auto& v:items) { + QGIView* qv = dynamic_cast(v); + if (qv != nullptr) { + result.push_back(qv); + } + } + return result; +} + +int QGSPage::addQView(QGIView *view) +{ + //don't add twice! + QGIView* existing = getQGIVByName(view->getViewName()); + if (existing == nullptr) { + addItem(view); + + // Find if it belongs to a parent + QGIView *parent = nullptr; + parent = findParent(view); + + QPointF viewPos(Rez::guiX(view->getViewObject()->X.getValue()), + Rez::guiX(view->getViewObject()->Y.getValue() * -1)); + + if(parent) { + // move child view to center of parent + QPointF posRef(0.,0.); + QPointF mapPos = view->mapToItem(parent, posRef); + view->moveBy(-mapPos.x(), -mapPos.y()); + + parent->addToGroup(view); + } + + view->setPos(viewPos); + view->updateView(true); + } + return 0; +} + +int QGSPage::removeQView(QGIView *view) +{ + if (view != nullptr) { + removeQViewFromScene(view); + delete view; + } + return 0; +} + +int QGSPage::removeQViewByName(const char* name) +{ + std::vector items = getViews(); + QString qsName = QString::fromUtf8(name); + bool found = false; + QGIView* ourItem = nullptr; + for (auto& i:items) { + if (qsName == i->data(1).toString()) { //is there a QGIV with this name in scene? + found = true; + ourItem = i; + break; + } + } + + if (found) { + int balloonItemType = QGraphicsItem::UserType + 140; + if (ourItem->type() == balloonItemType) { + QGIViewBalloon* balloon = dynamic_cast(ourItem); + balloon->disconnect(); + } + removeQViewFromScene(ourItem); + delete ourItem; //commenting this prevents crash but means a small memory waste. + //alternate fix(?) is to change indexing/caching option in scene/view + } + + return 0; +} + +void QGSPage::removeQViewFromScene(QGIView *view) +{ + QGIView* qgParent = dynamic_cast(view->parentItem()); + if (qgParent != nullptr) { + qgParent->removeChild(view); + } else { + removeItem(view); + } +} + + +QGIView * QGSPage::addViewPart(TechDraw::DrawViewPart *part) +{ +// Base::Console().Message("QGSP::addViewPart(%s)\n", part->getNameInDocument()); + QGIView* existing = findQViewForDocObj(part); + if (existing != nullptr) { + return existing; + } + + auto viewPart( new QGIViewPart ); + + viewPart->setViewPartFeature(part); + + addQView(viewPart); + return viewPart; +} + +QGIView * QGSPage::addViewSection(TechDraw::DrawViewPart *part) +{ + auto viewSection( new QGIViewSection ); + + viewSection->setViewPartFeature(part); + + addQView(viewSection); + return viewSection; +} + +QGIView * QGSPage::addProjectionGroup(TechDraw::DrawProjGroup *view) { + auto qview( new QGIProjGroup ); + + qview->setViewFeature(view); + addQView(qview); + return qview; +} + +QGIView * QGSPage::addDrawView(TechDraw::DrawView *view) +{ + auto qview( new QGIView ); + + qview->setViewFeature(view); + addQView(qview); + return qview; +} + +QGIView * QGSPage::addDrawViewCollection(TechDraw::DrawViewCollection *view) +{ + auto qview( new QGIViewCollection ); + + qview->setViewFeature(view); + addQView(qview); + return qview; +} + +QGIView * QGSPage::addDrawViewAnnotation(TechDraw::DrawViewAnnotation *view) +{ + auto qview( new QGIViewAnnotation ); + + qview->setViewAnnoFeature(view); + + addQView(qview); + return qview; +} + +QGIView * QGSPage::addDrawViewSymbol(TechDraw::DrawViewSymbol *view) +{ + auto qview( new QGIViewSymbol ); + + qview->setViewFeature(view); + + addQView(qview); + return qview; +} + +QGIView * QGSPage::addDrawViewClip(TechDraw::DrawViewClip *view) +{ + auto qview( new QGIViewClip ); + + qview->setPosition(Rez::guiX(view->X.getValue()), Rez::guiX(view->Y.getValue())); + qview->setViewFeature(view); + + addQView(qview); + return qview; +} + +QGIView * QGSPage::addDrawViewSpreadsheet(TechDraw::DrawViewSpreadsheet *view) +{ + auto qview( new QGIViewSpreadsheet ); + + qview->setViewFeature(view); + + addQView(qview); + return qview; +} + +QGIView * QGSPage::addDrawViewImage(TechDraw::DrawViewImage *view) +{ + auto qview( new QGIViewImage ); + + qview->setViewFeature(view); + + addQView(qview); + return qview; +} + +QGIView * QGSPage::addViewBalloon(TechDraw::DrawViewBalloon *balloon) +{ +// Base::Console().Message("QGSP::addViewBalloon(%s)\n", balloon->getNameInDocument()); + auto vBalloon( new QGIViewBalloon ); + + addItem(vBalloon); + + vBalloon->setViewPartFeature(balloon); + vBalloon->dvBalloon = balloon; + + QGIView *parent = nullptr; + parent = findParent(vBalloon); + + if (parent) { + addBalloonToParent(vBalloon,parent); + } + + return vBalloon; +} + +void QGSPage::addBalloonToParent(QGIViewBalloon* balloon, QGIView* parent) +{ +// Base::Console().Message("QGSP::addBalloonToParent()\n"); + assert(balloon); + assert(parent); //blow up if we don't have Dimension or Parent + QPointF posRef(0.,0.); + QPointF mapPos = balloon->mapToItem(parent, posRef); + balloon->moveBy(-mapPos.x(), -mapPos.y()); + parent->addToGroup(balloon); + balloon->setZValue(ZVALUE::DIMENSION); +} + +//origin is in scene coordinates from QGViewPage +void QGSPage::createBalloon(QPointF origin, DrawViewPart *parent) +{ +// Base::Console().Message("QGSP::createBalloon(%s)\n", DrawUtil::formatVector(origin).c_str()); + std::string featName = getDrawPage()->getDocument()->getUniqueObjectName("Balloon"); + std::string pageName = getDrawPage()->getNameInDocument(); + + Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Balloon")); + Command::doCommand(Command::Doc, "App.activeDocument().addObject('TechDraw::DrawViewBalloon','%s')", featName.c_str()); + TechDraw::DrawViewBalloon *balloon = dynamic_cast(getDrawPage()->getDocument()->getObject(featName.c_str())); + if (!balloon) { + throw Base::TypeError("QGSP::createBalloon - balloon not found\n"); + } + Command::doCommand(Command::Doc,"App.activeDocument().%s.SourceView = (App.activeDocument().%s)", + featName.c_str(), parent->getNameInDocument()); + + QGIView* qgParent = getQGIVByName(parent->getNameInDocument()); + //convert from scene coords to qgParent coords and unscale + QPointF parentOrigin = qgParent->mapFromScene(origin) / parent->getScale(); + balloon->setOrigin(parentOrigin); + //convert origin to App side coords + QPointF appOrigin = Rez::appPt(parentOrigin); + appOrigin = DrawUtil::invertY(appOrigin); + balloon->OriginX.setValue(appOrigin.x()); + balloon->OriginY.setValue(appOrigin.y()); + double textOffset = 20.0 / parent->getScale(); + balloon->X.setValue(appOrigin.x() + textOffset); + balloon->Y.setValue(appOrigin.y() + textOffset); + + int idx = getDrawPage()->getNextBalloonIndex(); + QString labelText = QString::number(idx); + balloon->Text.setValue(std::to_string(idx).c_str()); + + Command::doCommand(Command::Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", pageName.c_str(), featName.c_str()); + + Gui::Command::commitCommand(); +} + +QGIView * QGSPage::addViewDimension(TechDraw::DrawViewDimension *dim) +{ + auto dimGroup( new QGIViewDimension ); + + addItem(dimGroup); + + dimGroup->setViewPartFeature(dim); + dimGroup->dvDimension = dim; + + // Find if it belongs to a parent + QGIView *parent = nullptr; + parent = findParent(dimGroup); + + if(parent) { + addDimToParent(dimGroup,parent); + } + + return dimGroup; +} + +void QGSPage::addDimToParent(QGIViewDimension* dim, QGIView* parent) +{ +// Base::Console().Message("QGVP::addDimToParent()\n"); + assert(dim); + assert(parent); //blow up if we don't have Dimension or Parent + QPointF posRef(0.,0.); + QPointF mapPos = dim->mapToItem(parent, posRef); + dim->moveBy(-mapPos.x(), -mapPos.y()); + parent->addToGroup(dim); + dim->setZValue(ZVALUE::DIMENSION); +} + +QGIView * QGSPage::addViewLeader(TechDraw::DrawLeaderLine *leader) +{ +// Base::Console().Message("QGVP::addViewLeader(%s)\n",leader->getNameInDocument()); + QGILeaderLine* leaderGroup = new QGILeaderLine(); + addItem(leaderGroup); + + leaderGroup->setLeaderFeature(leader); + + QGIView *parent = nullptr; + parent = findParent(leaderGroup); + + if(parent) { + addLeaderToParent(leaderGroup,parent); + } + + leaderGroup->updateView(true); + + return leaderGroup; +} + +void QGSPage::addLeaderToParent(QGILeaderLine* lead, QGIView* parent) +{ +// Base::Console().Message("QGVP::addLeaderToParent()\n"); + parent->addToGroup(lead); + lead->setZValue(ZVALUE::DIMENSION); +} + +QGIView * QGSPage::addRichAnno(TechDraw::DrawRichAnno* anno) +{ + QGIRichAnno* annoGroup = nullptr; + TechDraw::DrawView* parentDV = nullptr; + + App::DocumentObject* parentObj = anno->AnnoParent.getValue(); + if (parentObj != nullptr) { + parentDV = dynamic_cast(parentObj); + } + if (parentDV != nullptr) { + QGIView* parentQV = findQViewForDocObj(parentObj); + annoGroup = new QGIRichAnno(parentQV, anno); + annoGroup->updateView(true); + } else { + annoGroup = new QGIRichAnno(nullptr, anno); + addItem(annoGroup); + annoGroup->updateView(true); + } + return annoGroup; +} + +QGIView * QGSPage::addWeldSymbol(TechDraw::DrawWeldSymbol* weld) +{ +// Base::Console().Message("QGVP::addWeldSymbol()\n"); + QGIWeldSymbol* weldGroup = nullptr; + TechDraw::DrawView* parentDV = nullptr; + + App::DocumentObject* parentObj = weld->Leader.getValue(); + if (parentObj != nullptr) { + parentDV = dynamic_cast(parentObj); + } else { +// Base::Console().Message("QGVP::addWeldSymbol - no parent doc obj\n"); + } + if (parentDV != nullptr) { + QGIView* parentQV = findQViewForDocObj(parentObj); + QGILeaderLine* leadParent = dynamic_cast(parentQV); + if (leadParent != nullptr) { + weldGroup = new QGIWeldSymbol(leadParent); + weldGroup->setFeature(weld); //for QGIWS + weldGroup->setViewFeature(weld); //for QGIV + weldGroup->updateView(true); + } else { + Base::Console().Error("QGVP::addWeldSymbol - no parent QGILL\n"); + } + } else { + Base::Console().Error("QGVP::addWeldSymbol - parent is not DV!\n"); + } + return weldGroup; +} + + +//! find the graphic for a DocumentObject +QGIView * QGSPage::findQViewForDocObj(App::DocumentObject *obj) const +{ + if(obj) { + const std::vector qviews = getViews(); + for(std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { + if(strcmp(obj->getNameInDocument(), (*it)->getViewName()) == 0) + return *it; + } + } + return nullptr; +} + +//! find the graphic for DocumentObject with name +QGIView* QGSPage::getQGIVByName(std::string name) +{ + QList qgItems = items(); + QList::iterator it = qgItems.begin(); + for (; it != qgItems.end(); it++) { + QGIView* qv = dynamic_cast((*it)); + if (qv) { + const char* qvName = qv->getViewName(); + if(name.compare(qvName) == 0) { + return (qv); + } + } + } + return nullptr; +} + +//find the parent of a QGIV based on the corresponding feature's parentage +QGIView * QGSPage::findParent(QGIView *view) const +{ + const std::vector qviews = getViews(); + TechDraw::DrawView *myFeat = view->getViewObject(); + + //If type is dimension we check references first + TechDraw::DrawViewDimension *dim = nullptr; + dim = dynamic_cast(myFeat); + if(dim) { + std::vector objs = dim->References2D.getValues(); + + if(objs.size() > 0) { + std::vector objs = dim->References2D.getValues(); + // Attach the dimension to the first object's group + for(std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { + if(strcmp((*it)->getViewName(), objs.at(0)->getNameInDocument()) == 0) { + return *it; + } + } + } + } + + //If type is balloon we check references first + TechDraw::DrawViewBalloon *balloon = nullptr; + balloon = dynamic_cast(myFeat); + + if(balloon) { + App::DocumentObject* obj = balloon->SourceView.getValue(); + + if(obj) { + // Attach the dimension to the first object's group + for(std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { + if(strcmp((*it)->getViewName(), obj->getNameInDocument()) == 0) { + return *it; + } + } + } + } + + // Check if part of view collection + for(std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { + QGIViewCollection *grp = nullptr; + grp = dynamic_cast(*it); + if(grp) { + TechDraw::DrawViewCollection *collection = nullptr; + collection = dynamic_cast(grp->getViewObject()); + if(collection) { + std::vector objs = collection->Views.getValues(); + for( std::vector::iterator it = objs.begin(); it != objs.end(); ++it) { + if(strcmp(myFeat->getNameInDocument(), (*it)->getNameInDocument()) == 0) + + return grp; + } + } + } + } + + //If type is LeaderLine we check LeaderParent + TechDraw::DrawLeaderLine *lead = nullptr; + lead = dynamic_cast(myFeat); + + if(lead) { + App::DocumentObject* obj = lead->LeaderParent.getValue(); + if(obj != nullptr) { + std::string parentName = obj->getNameInDocument(); + for(std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { + if(strcmp((*it)->getViewName(), parentName.c_str()) == 0) { + return *it; + } + } + } + } + // Not found a parent + return nullptr; +} + +void QGSPage::setPageTemplate(TechDraw::DrawTemplate *obj) +{ + removeTemplate(); + + if(obj->isDerivedFrom(TechDraw::DrawParametricTemplate::getClassTypeId())) { + pageTemplate = new QGIDrawingTemplate(this); + } else if(obj->isDerivedFrom(TechDraw::DrawSVGTemplate::getClassTypeId())) { + pageTemplate = new QGISVGTemplate(this); + } + pageTemplate->setTemplate(obj); + pageTemplate->updateView(); +} + +QGITemplate* QGSPage::getTemplate() const +{ + return pageTemplate; +} + +void QGSPage::removeTemplate() +{ + if(pageTemplate) { + removeItem(pageTemplate); + pageTemplate->deleteLater(); + pageTemplate = nullptr; + } +} + +void QGSPage::refreshViews(void) +{ +// Base::Console().Message("QGVP::refreshViews()\n"); + QList list = items(); + QList qgiv; + //find only QGIV's + for (auto q: list) { + QString viewFamily = QString::fromUtf8("QGIV"); + if (viewFamily == q->data(0).toString()) { + qgiv.push_back(q); + } + } + for (auto q: qgiv) { + QGIView *itemView = dynamic_cast(q); + if(itemView) { + itemView->updateView(true); + } + } +} + +void QGSPage::setExporting(bool enable) +{ + QList sceneItems = items(); + std::vector dvps; + for (auto& qgi:sceneItems) { + QGIViewPart* qgiPart = dynamic_cast(qgi); + QGIRichAnno* qgiRTA = dynamic_cast(qgi); + if(qgiPart) { + qgiPart->setExporting(enable); + dvps.push_back(qgiPart); + } + if (qgiRTA) { + qgiRTA->setExporting(enable); + } + } + for (auto& v: dvps) { + v->draw(); + } +} + +void QGSPage::saveSvg(QString filename) +{ + // TODO: We only have m_vpPage because constructor gets passed a view provider... + //NOTE: this makes wrong size pages in low-Rez + TechDraw::DrawPage *page( m_vpPage->getDrawPage() ); + + const QString docName( QString::fromUtf8(page->getDocument()->getName()) ); + const QString pageName( QString::fromUtf8(page->getNameInDocument()) ); + QString svgDescription = QString::fromUtf8("Drawing page: ") + + pageName + + QString::fromUtf8(" exported from FreeCAD document: ") + + docName; + + QSvgGenerator svgGen; + QTemporaryFile temporaryFile; + svgGen.setOutputDevice(&temporaryFile); + + // Set resolution in DPI. Use the actual one, i.e. Rez::guiX(inch) + svgGen.setResolution(Rez::guiX(25.4)); + + // Set size in pixels, which Qt recomputes using DPI to mm. + int pixelWidth = Rez::guiX(page->getPageWidth()); + int pixelHeight = Rez::guiX(page->getPageHeight()); + svgGen.setSize(QSize(pixelWidth, pixelHeight)); + + //"By default this property is set to QSize(-1, -1), which indicates that the generator should not output + // the width and height attributes of the element." >> but Inkscape won't read it without size info?? + svgGen.setViewBox(QRect(0, 0, pixelWidth, pixelHeight)); + + svgGen.setTitle(QString::fromUtf8("FreeCAD SVG Export")); + svgGen.setDescription(svgDescription); + + Gui::Selection().clearSelection(); + + bool saveState = m_vpPage->getFrameState(); + m_vpPage->setFrameState(false); + m_vpPage->setTemplateMarkers(false); + setExporting(true); + + // Here we temporarily hide the page template, because Qt would otherwise convert the SVG template + // texts into series of paths, making the later document edits practically unfeasible. + // We will insert the SVG template ourselves in the final XML postprocessing operation. + QGISVGTemplate *svgTemplate = dynamic_cast(pageTemplate); + bool templateVisible = false; + if (svgTemplate) { + templateVisible = svgTemplate->isVisible(); + svgTemplate->hide(); + } + + refreshViews(); +// viewport()->repaint(); + + double width = Rez::guiX(page->getPageWidth()); + double height = Rez::guiX(page->getPageHeight()); + QRectF sourceRect(0.0,-height,width,height); + QRectF targetRect(0.0,0.0,width,height); + + Gui::Selection().clearSelection(); + QPainter p; + + p.begin(&svgGen); + render(&p, targetRect,sourceRect); //note: scene render, not item render! + p.end(); + + m_vpPage->setFrameState(saveState); + m_vpPage->setTemplateMarkers(saveState); + setExporting(false); + if (templateVisible && svgTemplate) { + svgTemplate->show(); + } + + refreshViews(); +// viewport()->repaint(); + + temporaryFile.close(); + postProcessXml(temporaryFile, filename, pageName); +} + +static void removeEmptyGroups(QDomElement e) +{ + while (!e.isNull()) { + QDomElement next = e.nextSiblingElement(); + if (e.hasChildNodes()) { + removeEmptyGroups(e.firstChildElement()); + } else if (e.tagName() == QLatin1String("g")) { + e.parentNode().removeChild(e); + } + e = next; + } +} + +void QGSPage::postProcessXml(QTemporaryFile& temporaryFile, QString fileName, QString pageName) +{ + QDomDocument exportDoc(QString::fromUtf8("SvgDoc")); + QFile file(temporaryFile.fileName()); + if (!file.open(QIODevice::ReadOnly)) { + Base::Console().Message("QGSPage::ppsvg - tempfile open error\n"); + return; + } + if (!exportDoc.setContent(&file)) { + Base::Console().Message("QGSPage::ppsvg - xml error\n"); + file.close(); + return; + } + file.close(); + + QDomElement exportDocElem = exportDoc.documentElement(); //root + + // Insert Freecad SVG namespace into namespace declarations + exportDocElem.setAttribute(QString::fromUtf8("xmlns:freecad"), + QString::fromUtf8(FREECAD_SVG_NS_URI)); + // Insert all namespaces used by TechDraw's page template SVGs + exportDocElem.setAttribute(QString::fromUtf8("xmlns:svg"), + QString::fromUtf8(SVG_NS_URI)); + exportDocElem.setAttribute(QString::fromUtf8("xmlns:cc"), + QString::fromUtf8(CC_NS_URI)); + exportDocElem.setAttribute(QString::fromUtf8("xmlns:dc"), + QString::fromUtf8(DC_NS_URI)); + exportDocElem.setAttribute(QString::fromUtf8("xmlns:rdf"), + QString::fromUtf8(RDF_NS_URI)); + exportDocElem.setAttribute(QString::fromUtf8("xmlns:inkscape"), + QString::fromUtf8(INKSCAPE_NS_URI)); + exportDocElem.setAttribute(QString::fromUtf8("xmlns:sodipodi"), + QString::fromUtf8(SODIPODI_NS_URI)); + + // Create the root group which will host the drawing group and the template group + QDomElement rootGroup = exportDoc.createElement(QString::fromUtf8("g")); + rootGroup.setAttribute(QString::fromUtf8("id"), pageName); + rootGroup.setAttribute(QString::fromUtf8("inkscape:groupmode"), + QString::fromUtf8("layer")); + rootGroup.setAttribute(QString::fromUtf8("inkscape:label"), + QString::fromUtf8("TechDraw")); + + // Now insert our template + QGISVGTemplate *svgTemplate = dynamic_cast(pageTemplate); + if (svgTemplate) { + DrawSVGTemplate *drawTemplate = svgTemplate->getSVGTemplate(); + if (drawTemplate) { + QFile templateResultFile(QString::fromUtf8(drawTemplate->PageResult.getValue())); + if (templateResultFile.open(QIODevice::ReadOnly)) { + QDomDocument templateResultDoc(QString::fromUtf8("SvgDoc")); + if (templateResultDoc.setContent(&templateResultFile)) { + QDomElement templateDocElem = templateResultDoc.documentElement(); + + // Insert the template into a new group with id set to template name + QDomElement templateGroup = exportDoc.createElement(QString::fromUtf8("g")); + Base::FileInfo fi(drawTemplate->Template.getValue()); + templateGroup.setAttribute(QString::fromUtf8("id"), + QString::fromUtf8(fi.fileName().c_str())); + templateGroup.setAttribute(QString::fromUtf8("style"), + QString::fromUtf8("stroke: none;")); + + // Scale the template group correctly +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) + templateGroup.setAttribute(QString::fromUtf8("transform"), + QString().sprintf("scale(%f, %f)", Rez::guiX(1.0), Rez::guiX(1.0))); +#else + templateGroup.setAttribute(QString::fromUtf8("transform"), + QString::fromLatin1("scale(%1, %2)").arg(Rez::guiX(1.0), 0, 'f').arg(Rez::guiX(1.0), 0, 'f')); +#endif + + // Finally, transfer all template document child nodes under the template group + while (!templateDocElem.firstChild().isNull()) { + templateGroup.appendChild(templateDocElem.firstChild()); + } + + rootGroup.appendChild(templateGroup); + } + } + } + } + + // Obtain the drawing group element, move it under root node and set its id to "DrawingContent" + QDomElement drawingGroup = exportDocElem.firstChildElement(QLatin1String("g")); + if (!drawingGroup.isNull()) { + drawingGroup.setAttribute(QString::fromUtf8("id"), QString::fromUtf8("DrawingContent")); + rootGroup.appendChild(drawingGroup); + } + exportDocElem.appendChild(rootGroup); + + // As icing on the cake, get rid of the empty 's Qt SVG generator painting inserts. + removeEmptyGroups(exportDocElem); + + // Time to save our product + QFile outFile( fileName ); + if( !outFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) { + Base::Console().Message("QGVP::ppxml - failed to open file for writing: %s\n",qPrintable(fileName) ); + } + + QTextStream stream( &outFile ); + stream.setGenerateByteOrderMark(false); + stream.setCodec("UTF-8"); + + stream << exportDoc.toByteArray(); + outFile.close(); +} + +TechDraw::DrawPage* QGSPage::getDrawPage() +{ + return m_vpPage->getDrawPage(); +} + +QColor QGSPage::getBackgroundColor() +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); + App::Color fcColor; + fcColor.setPackedValue(hGrp->GetUnsigned("Background", 0x70707000)); + return fcColor.asValue(); +} + + +#include diff --git a/src/Mod/TechDraw/Gui/QGSPage.h b/src/Mod/TechDraw/Gui/QGSPage.h new file mode 100644 index 0000000000..8b8902ae8e --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGSPage.h @@ -0,0 +1,149 @@ +/*************************************************************************** + * Copyright (c) 2022 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef TECHDRAWGUI_QGSCENE_H +#define TECHDRAWGUI_QGSCENE_H + +#include + +#include + +class QTemporaryFile; +class QLabel; + +namespace App { +class DocumentObject; +} + +namespace TechDraw { +class DrawView; +class DrawViewPart; +class DrawProjGroup; +class DrawViewDimension; +class DrawPage; +class DrawTemplate; +class DrawViewAnnotation; +class DrawViewSymbol; +class DrawViewClip; +class DrawViewCollection; +class DrawViewSpreadsheet; +class DrawViewImage; +class DrawLeaderLine; +class DrawViewBalloon; +class DrawRichAnno; +class DrawWeldSymbol; +} + +namespace TechDrawGui +{ +class QGIView; +class QGIViewDimension; +class QGITemplate; +class ViewProviderPage; +class QGIViewBalloon; +class QGILeaderLine; +class QGIRichAnno; +class QGITile; + +class TechDrawGuiExport QGSPage : public QGraphicsScene +{ + Q_OBJECT + +public: + enum RendererType { Native, OpenGL, Image }; + + QGSPage(ViewProviderPage *vp, QWidget *parent = nullptr); + virtual ~QGSPage(); + + QGIView * addViewDimension(TechDraw::DrawViewDimension *dim); + QGIView * addViewBalloon(TechDraw::DrawViewBalloon *balloon); + QGIView * addProjectionGroup(TechDraw::DrawProjGroup *view); + QGIView * addViewPart(TechDraw::DrawViewPart *part); + QGIView * addViewSection(TechDraw::DrawViewPart *part); + QGIView * addDrawView(TechDraw::DrawView *view); + QGIView * addDrawViewCollection(TechDraw::DrawViewCollection *view); + QGIView * addDrawViewAnnotation(TechDraw::DrawViewAnnotation *view); + QGIView * addDrawViewSymbol(TechDraw::DrawViewSymbol *view); + QGIView * addDrawViewClip(TechDraw::DrawViewClip *view); + QGIView * addDrawViewSpreadsheet(TechDraw::DrawViewSpreadsheet *view); + QGIView * addDrawViewImage(TechDraw::DrawViewImage *view); + QGIView * addViewLeader(TechDraw::DrawLeaderLine* view); + QGIView * addRichAnno(TechDraw::DrawRichAnno* anno); + QGIView * addWeldSymbol(TechDraw::DrawWeldSymbol* weld); + + QGIView* findQViewForDocObj(App::DocumentObject *obj) const; + QGIView* getQGIVByName(std::string name); + QGIView* findParent(QGIView *) const; + + void addBalloonToParent(QGIViewBalloon* balloon, QGIView* parent); + void createBalloon(QPointF origin, TechDraw::DrawViewPart *parent); + + void addDimToParent(QGIViewDimension* dim, QGIView* parent); + void addLeaderToParent(QGILeaderLine* lead, QGIView* parent); + + std::vector getViews() const; + + int addQView(QGIView * view); + int removeQView(QGIView *view); + int removeQViewByName(const char* name); + void removeQViewFromScene(QGIView *view); + + void setPageTemplate(TechDraw::DrawTemplate *pageTemplate); + + QGITemplate * getTemplate() const; + void removeTemplate(); + + TechDraw::DrawPage * getDrawPage(); + + void setExporting(bool enable); + virtual void refreshViews(void); + + /// Renders the page to SVG with filename. + void saveSvg(QString filename); + void postProcessXml(QTemporaryFile& tempFile, QString filename, QString pagename); + +public Q_SLOTS: + +protected: + static QColor SelectColor; + static QColor PreselectColor; + QColor getBackgroundColor(); + + + QGITemplate *pageTemplate; + +private: + RendererType m_renderer; + + bool drawBkg; + QBrush* bkgBrush; + QImage m_image; + ViewProviderPage *m_vpPage; + + QLabel *balloonCursor; + QPoint balloonCursorPos; + QPoint balloonHotspot; +}; + +} // namespace + +#endif // TECHDRAWGUI_QGSCENE_H diff --git a/src/Mod/TechDraw/Gui/QGTracker.cpp b/src/Mod/TechDraw/Gui/QGTracker.cpp index 87b79460d0..78fd8cde61 100644 --- a/src/Mod/TechDraw/Gui/QGTracker.cpp +++ b/src/Mod/TechDraw/Gui/QGTracker.cpp @@ -46,13 +46,14 @@ #include "Rez.h" #include "ZVALUE.h" +#include "QGSPage.h" #include "DrawGuiUtil.h" #include "QGIView.h" #include "QGTracker.h" using namespace TechDrawGui; -QGTracker::QGTracker(QGraphicsScene* inScene, TrackerMode m): +QGTracker::QGTracker(QGSPage* inScene, TrackerMode m): m_sleep(false), m_qgParent(nullptr), m_lastClick(QPointF(FLT_MAX,FLT_MAX)) diff --git a/src/Mod/TechDraw/Gui/QGTracker.h b/src/Mod/TechDraw/Gui/QGTracker.h index 41df76ad4b..3a7652e2f6 100644 --- a/src/Mod/TechDraw/Gui/QGTracker.h +++ b/src/Mod/TechDraw/Gui/QGTracker.h @@ -23,6 +23,8 @@ #ifndef DRAWINGGUI_TRACKER_H #define DRAWINGGUI_TRACKER_H +#include + #include QT_BEGIN_NAMESPACE @@ -37,13 +39,16 @@ QT_END_NAMESPACE namespace TechDrawGui { +class QGSPage; +class QGIView; + class TechDrawGuiExport QGTracker : public QObject, public QGIPrimPath { Q_OBJECT public: enum TrackerMode { None, Line, Circle, Rectangle, Point }; - explicit QGTracker(QGraphicsScene* scene = nullptr, QGTracker::TrackerMode m = QGTracker::TrackerMode::None); + explicit QGTracker(QGSPage* scene = nullptr, QGTracker::TrackerMode m = QGTracker::TrackerMode::None); ~QGTracker(); diff --git a/src/Mod/TechDraw/Gui/QGVNavStyle.cpp b/src/Mod/TechDraw/Gui/QGVNavStyle.cpp new file mode 100644 index 0000000000..7a3d4ca13a --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyle.cpp @@ -0,0 +1,414 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#endif + +#include +#include + +#include + +#include +#include + +#include "QGVNavStyle.h" +#include "QGVPage.h" +#include "QGSPage.h" + +using namespace TechDrawGui; + +namespace TechDrawGui { + +QGVNavStyle::QGVNavStyle() : m_viewer(nullptr) +{ + initialize(); +} + +QGVNavStyle::~QGVNavStyle() +{ +} + +void QGVNavStyle::initialize() +{ + this->button1down = false; + this->button2down = false; + this->button3down = false; + this->ctrldown = false; + this->shiftdown = false; + this->altdown = false; + this->invertZoom = App::GetApplication().GetParameterGroupByPath + ("User parameter:BaseApp/Preferences/View")->GetBool("InvertZoom",true); + this->zoomAtCursor = App::GetApplication().GetParameterGroupByPath + ("User parameter:BaseApp/Preferences/View")->GetBool("ZoomAtCursor",true); + this->zoomStep = App::GetApplication().GetParameterGroupByPath + ("User parameter:BaseApp/Preferences/View")->GetFloat("ZoomStep",0.2f); + + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General"); + m_reversePan = hGrp->GetInt("KbPan",1); + m_reverseScroll = hGrp->GetInt("KbScroll",1); + + panningActive = false; + zoomingActive = false; + m_clickPending = false; + m_panPending = false; + m_zoomPending = false; + m_clickButton = Qt::NoButton; +} + +void QGVNavStyle::setAnchor() +{ + if (m_viewer != nullptr) { + if (zoomAtCursor) { + m_viewer->setResizeAnchor(QGraphicsView::AnchorUnderMouse); + m_viewer->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + } else { + m_viewer->setResizeAnchor(QGraphicsView::AnchorViewCenter); + m_viewer->setTransformationAnchor(QGraphicsView::AnchorViewCenter); + } + } +} + +void QGVNavStyle::handleEnterEvent(QEvent *event) +{ + Q_UNUSED(event); + if (getViewer()->isBalloonPlacing()) { + getViewer()->getBalloonCursor()->hide(); + } +} + +void QGVNavStyle::handleFocusOutEvent(QFocusEvent *event) +{ + Q_UNUSED(event); + getViewer()->cancelBalloonPlacing(); +} + +void QGVNavStyle::handleKeyPressEvent(QKeyEvent *event) +{ + if(event->modifiers().testFlag(Qt::ControlModifier)) { + switch(event->key()) { + case Qt::Key_Plus: { + zoom(1.0 + zoomStep); + event->accept(); + break; + } + case Qt::Key_Minus: { + zoom(1.0 - zoomStep); + event->accept(); + break; + } + default: { + break; + } + } + } + + if(event->modifiers().testFlag( Qt::NoModifier)) { + switch(event->key()) { + case Qt::Key_Left: { + getViewer()->kbPanScroll(1, 0); + event->accept(); + break; + } + case Qt::Key_Up: { + getViewer()->kbPanScroll(0, 1); + event->accept(); + break; + } + case Qt::Key_Right: { + getViewer()->kbPanScroll(-1, 0); + event->accept(); + break; + } + case Qt::Key_Down: { + getViewer()->kbPanScroll(0, -1); + event->accept(); + break; + } + case Qt::Key_Escape: { + getViewer()->cancelBalloonPlacing(); + event->accept(); + break; + } + case Qt::Key_Shift: { + this->shiftdown = true; + Base::Console().Message("QGVNS::handleKeyPressEvent - shift pressed\n"); + event->accept(); + break; + } + default: { + break; + } + } + } +} + +void QGVNavStyle::handleKeyReleaseEvent(QKeyEvent *event) +{ +// Q_UNUSED(event); + if(event->modifiers().testFlag( Qt::NoModifier)) { + switch(event->key()) { + case Qt::Key_Shift: { + this->shiftdown = false; + Base::Console().Message("QGVNS::handleKeyPressEvent - shift released\n"); + event->accept(); + break; + } + default: { + break; + } + } + } +} + +void QGVNavStyle::handleLeaveEvent(QEvent *event) +{ + Q_UNUSED(event); + if (getViewer()->isBalloonPlacing()) { + int left_x; + if (getViewer()->getBalloonCursorPos().x() < 32) + left_x = 0; + else if (getViewer()->getBalloonCursorPos().x() > (getViewer()->contentsRect().right() - 32)) + left_x = getViewer()->contentsRect().right() - 32; + else + left_x = getViewer()->getBalloonCursorPos().x(); + + int left_y; + if (getViewer()->getBalloonCursorPos().y() < 32) + left_y = 0; + else if (getViewer()->getBalloonCursorPos().y() > (getViewer()->contentsRect().bottom() - 32)) + left_y = getViewer()->contentsRect().bottom() - 32; + else + left_y = getViewer()->getBalloonCursorPos().y(); + + /* When cursor leave the page, display getViewer()->balloonCursor where it left */ + getViewer()->getBalloonCursor()->setGeometry(left_x ,left_y, 32, 32); + getViewer()->getBalloonCursor()->show(); + } +} + +void QGVNavStyle::handleMousePressEvent(QMouseEvent *event) +{ +// Base::Console().Message("QGVNS::handleMousePressEvent()\n"); + if (!panningActive && (event->button() == Qt::MiddleButton)) { + startPan(event->pos()); + event->accept(); + } +} + +void QGVNavStyle::handleMouseMoveEvent(QMouseEvent *event) +{ +// Base::Console().Message("QGVNS::handleMouseMoveEvent()\n"); + if (getViewer()->isBalloonPlacing()) { + getViewer()->setBalloonCursorPos(event->pos()); + } + + if (panningActive) { + pan(event->pos()); + event->accept(); + } +} + +void QGVNavStyle::handleMouseReleaseEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + placeBalloon(event->pos()); + } + + if (panningActive && (event->button() == Qt::MiddleButton)) { + stopPan(); + event->accept(); + } +} + +void QGVNavStyle::handleWheelEvent(QWheelEvent *event) +{ +//Delta is the distance that the wheel is rotated, in eighths of a degree. +//positive indicates rotation forwards away from the user; negative backwards toward the user. +//Most mouse types work in steps of 15 degrees, in which case the delta value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees. +//1 click = 15 degrees. 15 degrees = 120 deltas. delta/240 -> 1 click = 0.5 ==> factor = 1.2^0.5 = 1.095 +// 1 click = -0.5 ==> factor = 1.2^-0.5 = 0.91 +//so to change wheel direction, multiply (event->delta() / 240.0) by +/-1 + double mouseBase = 1.2; //magic numbers. change for different mice? + double mouseAdjust = -240.0; + if (invertZoom) { + mouseAdjust = -mouseAdjust; + } + + int delta = event->angleDelta().y(); + qreal factor = std::pow(mouseBase, delta / mouseAdjust); + zoom(factor); +} + +void QGVNavStyle::zoom(double factor) +{ + QPoint center = getViewer()->viewport()->rect().center(); + getViewer()->scale(factor, + factor); + + QPoint newCenter = getViewer()->viewport()->rect().center(); + QPoint change = newCenter - center; + getViewer()->translate(change.x(), change.y()); +} + +void QGVNavStyle::startZoom(QPoint p) +{ +// Base::Console().Message("QGVNS::startZoom(%s)\n", TechDraw::DrawUtil::formatVector(p).c_str()); + zoomOrigin = p; + zoomingActive = true; +} + +double QGVNavStyle::mouseZoomFactor(QPoint p) +{ + +// Base::Console().Message("QGVNS::mouseZoomFactor(%s)\n", TechDraw::DrawUtil::formatVector(p).c_str()); + QPoint movement = p - zoomOrigin; + double sensitivity = 0.1; + double direction = 1.0; + double invert = 1.0; + if (movement.y() < 0.0) { + direction = -direction; + } + if (invertZoom) { + invert = -invert; + } + double factor = 1.0 + (direction * invert * zoomStep * sensitivity); + zoomOrigin = p; + return factor; +} + +void QGVNavStyle::startPan(QPoint p) +{ + panOrigin = p; + panningActive = true; + QApplication::setOverrideCursor(Qt::SizeAllCursor); + +} + +void QGVNavStyle::pan(QPoint p) +{ + QScrollBar *horizontalScrollbar = getViewer()->horizontalScrollBar(); + QScrollBar *verticalScrollbar = getViewer()->verticalScrollBar(); + QPoint direction = p - panOrigin; + + horizontalScrollbar->setValue(horizontalScrollbar->value() - m_reversePan*direction.x()); + verticalScrollbar->setValue(verticalScrollbar->value() - m_reverseScroll*direction.y()); + + panOrigin = p; +} + +void QGVNavStyle::stopPan() +{ + QApplication::restoreOverrideCursor(); + panningActive = false; +} + +void QGVNavStyle::startClick(Qt::MouseButton b) +{ + m_clickPending = true; + m_clickButton = b; +} + +void QGVNavStyle::stopClick(void) +{ + m_clickPending = false; + m_clickButton = Qt::MouseButton::NoButton; +} + +void QGVNavStyle::placeBalloon(QPoint p) +{ + getViewer()->getBalloonCursor()->hide(); + getViewer()->getScene()->createBalloon(getViewer()->mapToScene(p), + getViewer()->getDrawPage()->balloonParent); + getViewer()->setBalloonPlacing(false); +} + +//**************************************** +KeyCombination::KeyCombination() +{ +} + +KeyCombination::~KeyCombination() +{ +} + +void KeyCombination::addKey(int inKey) +{ + bool found = false; + //check for inKey already in keys + if (!keys.empty()) { + for (auto& k: keys) { + if (k == inKey) { + found = true; + } + } + } + if (!found) { + keys.push_back(inKey); + } +} + +void KeyCombination::removeKey(int inKey) +{ + std::vector newKeys; + for (auto& k: keys) { + if (k != inKey) { + newKeys.push_back(k); + } + } + keys = newKeys; +} + +void KeyCombination::clear() +{ + keys.clear(); +} + +bool KeyCombination::empty() +{ + return keys.empty(); +} + +//does inCombo match the keys we have in current combination +bool KeyCombination::haveCombination(int inCombo) +{ + bool matched = false; + int combo = 0; //no key + if (keys.size() < 2) { + //not enough keys for a combination + return false; + } + for (auto& k: keys) { + combo = combo | k; + } + if (combo == inCombo) { + matched = true; + } + return matched; +} + +} //namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/QGVNavStyle.h b/src/Mod/TechDraw/Gui/QGVNavStyle.h new file mode 100644 index 0000000000..3623d5ccd9 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyle.h @@ -0,0 +1,123 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef TECHDRAW_NAVIGATIONSTYLE_H +#include +#define TECHDRAW_NAVIGATIONSTYLE_H + +#include + +class QEvent; +class QFocusEvent; +class QKeyEvent; +class QMouseEvent; +class QWheelEvent; + +#include + +namespace TechDrawGui { + +class QGVPage; + +//class to support multiple key combinations +class KeyCombination +{ +public: + KeyCombination(); + ~KeyCombination(); + + void addKey(int inKey); + void removeKey(int inKey); + void clear(); + bool empty(); + + bool haveCombination(int inCombo); + +private: + std::vector keys; +}; + +class TechDrawGuiExport QGVNavStyle : public Base::BaseClass +{ +public: + QGVNavStyle(); + virtual ~QGVNavStyle(); + + void setViewer(QGVPage* qgvp) { m_viewer = qgvp;} ; + QGVPage* getViewer() { return m_viewer;}; + + virtual void handleEnterEvent(QEvent *event); + virtual void handleFocusOutEvent(QFocusEvent *event); + virtual void handleKeyPressEvent(QKeyEvent *event); + virtual void handleKeyReleaseEvent(QKeyEvent *event); + virtual void handleLeaveEvent(QEvent *event); + virtual void handleMouseMoveEvent(QMouseEvent *event); + virtual void handleMousePressEvent(QMouseEvent *event); + virtual void handleMouseReleaseEvent(QMouseEvent *event); + virtual void handleWheelEvent(QWheelEvent *event); + + virtual bool allowContextMenu() {return true;}; + + virtual void zoom(double factor); + virtual double mouseZoomFactor(QPoint p); + virtual void startZoom(QPoint p); + + virtual void startPan(QPoint p); + virtual void pan(QPoint p); + virtual void stopPan(); + + virtual void startClick(Qt::MouseButton b); + virtual void stopClick(void); + + virtual void placeBalloon(QPoint p); + +protected: + virtual void initialize(); + virtual void setAnchor(); + QGVPage* m_viewer; + int m_currentmode; + + bool ctrldown, shiftdown, altdown; + bool button1down, button2down, button3down; + bool invertZoom; + bool zoomAtCursor; + double zoomStep; + int m_reversePan; + int m_reverseScroll; + QPoint panOrigin; + bool panningActive; + QPoint zoomOrigin; + bool zoomingActive; + bool m_clickPending; + bool m_panPending; + bool m_zoomPending; + Qt::MouseButton m_clickButton; + + KeyCombination m_keyCombo; + +private: + +}; + +} +#endif // TECHDRAW_NAVIGATIONSTYLE_H diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleBlender.cpp b/src/Mod/TechDraw/Gui/QGVNavStyleBlender.cpp new file mode 100644 index 0000000000..518e9de84e --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleBlender.cpp @@ -0,0 +1,101 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#endif + +#include "QGVPage.h" +#include "QGVNavStyleBlender.h" + +using namespace TechDrawGui; + +namespace TechDrawGui { + +QGVNavStyleBlender::QGVNavStyleBlender() +{ +} + +QGVNavStyleBlender::~QGVNavStyleBlender() +{ +} + +void QGVNavStyleBlender::handleKeyReleaseEvent(QKeyEvent *event) +{ + if ((event->key() == Qt::Key_Shift) && panningActive) { + stopPan(); + event->accept(); + } +} + +void QGVNavStyleBlender::handleMousePressEvent(QMouseEvent *event) +{ + if (event->buttons() == (Qt::LeftButton | Qt::RightButton)) { + //pan mode 1 - LMB + RMB + mouse move + startPan(event->pos()); + event->accept(); + } else if ((event->button() == Qt::MiddleButton) && + QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)) { + //pan mode 2 - Shift + MMB + startPan(event->pos()); + event->accept(); + } +} + +void QGVNavStyleBlender::handleMouseMoveEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + getViewer()->setBalloonCursorPos(event->pos()); + } + + if (panningActive) { + pan(event->pos()); + event->accept(); + } +} + +void QGVNavStyleBlender::handleMouseReleaseEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + placeBalloon(event->pos()); + } + + if (panningActive) { + //pan mode 1 - LMB + RMB + mouse move + //stop panning if either button release + if ( (event->button() == Qt::LeftButton) || + (event->button() == Qt::RightButton)) { + stopPan(); + event->accept(); + } + //pan mode 2 - Shift + MMB + //stop panning if MMB released + if (event->button() == Qt::MiddleButton) { + stopPan(); + event->accept(); + } + } +} +} // namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleBlender.h b/src/Mod/TechDraw/Gui/QGVNavStyleBlender.h new file mode 100644 index 0000000000..ac67a9a86e --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleBlender.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef TECHDRAW_BLENDERNAVSTYLE_H +#define TECHDRAW_BLENDERNAVSTYLE_H + +#include + +#include "QGVNavStyle.h" + +namespace TechDrawGui { + +class QGVPage; + +class TechDrawGuiExport QGVNavStyleBlender : public QGVNavStyle +{ +public: + QGVNavStyleBlender(); + virtual ~QGVNavStyleBlender(); + + virtual void handleKeyReleaseEvent(QKeyEvent *event) override; + virtual void handleMousePressEvent(QMouseEvent *event) override; + virtual void handleMouseMoveEvent(QMouseEvent *event) override; + virtual void handleMouseReleaseEvent(QMouseEvent *event) override; + + //context menu (RMB) prevents pan mode 2 (LMB + RMB) + virtual bool allowContextMenu() override {return false;}; + +protected: +private: + +}; + +} +#endif // TECHDRAW_BLENDERNAVSTYLE_H diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleCAD.cpp b/src/Mod/TechDraw/Gui/QGVNavStyleCAD.cpp new file mode 100644 index 0000000000..6664775977 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleCAD.cpp @@ -0,0 +1,150 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#endif + +#include "QGVPage.h" +#include "QGVNavStyleCAD.h" + +using namespace TechDrawGui; + +namespace TechDrawGui { + +QGVNavStyleCAD::QGVNavStyleCAD() +{ +} + +QGVNavStyleCAD::~QGVNavStyleCAD() +{ +} + +void QGVNavStyleCAD::handleKeyReleaseEvent(QKeyEvent *event) +{ + //zoom mode 2 + if ( ((event->key() == Qt::Key_Control) || + (event->key() == Qt::Key_Shift)) && zoomingActive) { + zoomingActive = false; + event->accept(); + } + + //pan mode 2 + if ((event->key() == Qt::Key_Control) && panningActive) { + stopPan(); + event->accept(); + } +} + +void QGVNavStyleCAD::handleMousePressEvent(QMouseEvent *event) +{ + //pan mode 1 hold MMB + mouse movement + if (event->button() == Qt::MiddleButton) { + startClick(Qt::MiddleButton); //for MMB center view + startPan(event->pos()); + event->accept(); + } + + //zoom mode 2 Control + Shift + RMB click + if ((event->button() == Qt::RightButton) && + QApplication::keyboardModifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) { + startClick(Qt::RightButton); + event->accept(); + } + + //pan mode 2 Control + RMB click + if ((event->button() == Qt::RightButton) && + QApplication::keyboardModifiers() == Qt::ControlModifier) { + startClick(Qt::RightButton); + event->accept(); + } +} + +void QGVNavStyleCAD::handleMouseMoveEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + getViewer()->setBalloonCursorPos(event->pos()); + } + + //if the mouse moves between press and release, then it isn't a click + if (m_clickPending) { + stopClick(); + event->accept(); + return; + } + + if (panningActive) { + pan(event->pos()); + event->accept(); + } + + if (zoomingActive) { + zoom(mouseZoomFactor(event->pos())); + event->accept(); + } +} + +void QGVNavStyleCAD::handleMouseReleaseEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + placeBalloon(event->pos()); + } + + if (event->button() == Qt::MiddleButton) { + if (m_clickPending && (m_clickButton == Qt::MiddleButton)) { + stopClick(); + getViewer()->centerOn(getViewer()->mapToScene(event->pos())); + event->accept(); + } + //pan mode 1 hold MMB + mouse move + if (panningActive) { + stopPan(); + event->accept(); + } + } + + //zoom mode 2 Control + Shift + RMB click + if ((event->button() == Qt::RightButton) && + QApplication::keyboardModifiers() == (Qt::ControlModifier | Qt::ShiftModifier) && + m_clickPending) { + stopClick(); + startZoom(event->pos()); + event->accept(); + return; + } + + //pan mode 2 starts with Control + RMB click + if ((event->button() == Qt::RightButton) && + QApplication::keyboardModifiers() == (Qt::ControlModifier) && + m_clickPending) { + stopClick(); + startPan(event->pos()); + event->accept(); + } + + +} + +} // namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleCAD.h b/src/Mod/TechDraw/Gui/QGVNavStyleCAD.h new file mode 100644 index 0000000000..d347697bdc --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleCAD.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef TECHDRAW_CADNAVSTYLE_H +#define TECHDRAW_CADNAVSTYLE_H + +#include + +#include "QGVNavStyle.h" + +namespace TechDrawGui { + +class QGVPage; + +class TechDrawGuiExport QGVNavStyleCAD : public QGVNavStyle +{ +public: + QGVNavStyleCAD(); + virtual ~QGVNavStyleCAD(); + + virtual void handleKeyReleaseEvent(QKeyEvent *event) override; + virtual void handleMousePressEvent(QMouseEvent *event) override; + virtual void handleMouseMoveEvent(QMouseEvent *event) override; + virtual void handleMouseReleaseEvent(QMouseEvent *event) override; + + //context menu (RMB) prevents pan mode 2 (LMB + RMB) + virtual bool allowContextMenu() override {return false;}; + +protected: +private: + +}; + +} +#endif // TECHDRAW_CADNAVSTYLE_H diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleGesture.cpp b/src/Mod/TechDraw/Gui/QGVNavStyleGesture.cpp new file mode 100644 index 0000000000..8f8dde60a2 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleGesture.cpp @@ -0,0 +1,78 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#endif + +#include "QGVPage.h" +#include "QGVNavStyleGesture.h" + +using namespace TechDrawGui; + +namespace TechDrawGui { + +QGVNavStyleGesture::QGVNavStyleGesture() +{ +} + +QGVNavStyleGesture::~QGVNavStyleGesture() +{ +} + +void QGVNavStyleGesture::handleMousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::RightButton) { + startPan(event->pos()); + event->accept(); + } + +} + +void QGVNavStyleGesture::handleMouseMoveEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + getViewer()->setBalloonCursorPos(event->pos()); + } + + if (panningActive) { + pan(event->pos()); + event->accept(); + } +} + +void QGVNavStyleGesture::handleMouseReleaseEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + placeBalloon(event->pos()); + } + + if (event->button() == Qt::RightButton) { + stopPan(); + event->accept(); + } +} + +} // namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleGesture.h b/src/Mod/TechDraw/Gui/QGVNavStyleGesture.h new file mode 100644 index 0000000000..fa27b82765 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleGesture.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef TECHDRAW_GESTURENAVSTYLE_H +#define TECHDRAW_GESTURENAVSTYLE_H + +#include + +#include "QGVNavStyle.h" + +namespace TechDrawGui { + +class QGVPage; + +class TechDrawGuiExport QGVNavStyleGesture : public QGVNavStyle +{ +public: + QGVNavStyleGesture(); + virtual ~QGVNavStyleGesture(); + + virtual void handleMousePressEvent(QMouseEvent *event) override; + virtual void handleMouseMoveEvent(QMouseEvent *event) override; + virtual void handleMouseReleaseEvent(QMouseEvent *event) override; + + virtual bool allowContextMenu() override {return false;}; + +protected: +private: + +}; + +} +#endif // TECHDRAW_GESTURENAVSTYLE_H diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleInventor.cpp b/src/Mod/TechDraw/Gui/QGVNavStyleInventor.cpp new file mode 100644 index 0000000000..7830c56312 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleInventor.cpp @@ -0,0 +1,106 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#endif + +#include "QGVPage.h" +#include "QGVNavStyleInventor.h" + +using namespace TechDrawGui; + +namespace TechDrawGui { + +//********** +// Issue: select should be Shift + LMB +// currently is just LMB like all the other styles +// need to just accept LMB w/o Shift and pass Shift + LMB to +// QGraphicsView? +//********** + +QGVNavStyleInventor::QGVNavStyleInventor() +{ +} + +QGVNavStyleInventor::~QGVNavStyleInventor() +{ +} + +void QGVNavStyleInventor::handleMousePressEvent(QMouseEvent *event) +{ + if (event->buttons() == (Qt::LeftButton | Qt::MiddleButton)) { + //zoom mode 2 LMB + MMB + startZoom(event->pos()); + event->accept(); + } else if (event->button() == Qt::MiddleButton) { + //pan mode MMB + mouse movement + startPan(event->pos()); + event->accept(); + } +} + +void QGVNavStyleInventor::handleMouseMoveEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + getViewer()->setBalloonCursorPos(event->pos()); + } + + if (panningActive) { + pan(event->pos()); + event->accept(); + } + + if (zoomingActive) { + zoom(mouseZoomFactor(event->pos())); + event->accept(); + } +} + +void QGVNavStyleInventor::handleMouseReleaseEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + placeBalloon(event->pos()); + } + + if (event->button() == Qt::MiddleButton) { + //pan mode MMB + if (panningActive) { + stopPan(); + event->accept(); + } + } + + if ((event->button() == Qt::LeftButton) || + (event->button() == Qt::MiddleButton) ){ + //zoom mode 2 LMB + MMB + if (zoomingActive) { + zoomingActive = false; + event->accept(); + } + } +} + +} // namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleInventor.h b/src/Mod/TechDraw/Gui/QGVNavStyleInventor.h new file mode 100644 index 0000000000..0f2a74cc5f --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleInventor.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef TECHDRAW_INVENTORNAVSTYLE_H +#define TECHDRAW_INVENTORNAVSTYLE_H + +#include + +#include "QGVNavStyle.h" + +namespace TechDrawGui { + +class QGVPage; + +class TechDrawGuiExport QGVNavStyleInventor : public QGVNavStyle +{ +public: + QGVNavStyleInventor(); + virtual ~QGVNavStyleInventor(); + + virtual void handleMousePressEvent(QMouseEvent *event) override; + virtual void handleMouseMoveEvent(QMouseEvent *event) override; + virtual void handleMouseReleaseEvent(QMouseEvent *event) override; + +protected: +private: + +}; + +} +#endif // TECHDRAW_INVENTORNAVSTYLE_H diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleMaya.cpp b/src/Mod/TechDraw/Gui/QGVNavStyleMaya.cpp new file mode 100644 index 0000000000..3287e30de3 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleMaya.cpp @@ -0,0 +1,123 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#endif + +#include "QGVPage.h" +#include "QGVNavStyleMaya.h" + +using namespace TechDrawGui; + +namespace TechDrawGui { + +//****** +// Issue: on linux mint, ALT + mouse button doesn't get to the application. +// system eats the event for menus, accessibility magnifier, etc. +// only wheel zoom is known to work. +// need to test in different environment. +//****** + +QGVNavStyleMaya::QGVNavStyleMaya() +{ +} + +QGVNavStyleMaya::~QGVNavStyleMaya() +{ +} + +void QGVNavStyleMaya::handleKeyReleaseEvent(QKeyEvent *event) +{ + //zoom mode 2 + if ( (event->key() == Qt::Key_Alt) && zoomingActive) { + zoomingActive = false; + event->accept(); + } + + //pan mode + if ((event->key() == Qt::Key_Alt) && panningActive) { + stopPan(); + event->accept(); + } +} +void QGVNavStyleMaya::handleMousePressEvent(QMouseEvent *event) +{ + //pan mode alt + MMB + mouse movement + if ((event->button() == Qt::MiddleButton) && + (QApplication::keyboardModifiers() == Qt::AltModifier)) { + startPan(event->pos()); + event->accept(); + } + + //zoom mode 2 ALT + RMB + if ((event->button() == Qt::RightButton) && + (QApplication::keyboardModifiers() == Qt::AltModifier)) { + startZoom(event->pos()); + event->accept(); + } +} + +void QGVNavStyleMaya::handleMouseMoveEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + getViewer()->setBalloonCursorPos(event->pos()); + } + + if (panningActive) { + pan(event->pos()); + event->accept(); + } + + if (zoomingActive) { + zoom(mouseZoomFactor(event->pos())); + event->accept(); + } +} + +void QGVNavStyleMaya::handleMouseReleaseEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + placeBalloon(event->pos()); + } + + if (event->button() == Qt::MiddleButton) { + //pan mode ALT + MMB + if (panningActive) { + stopPan(); + event->accept(); + } + } + + if (event->button() == Qt::RightButton) { + //zoom mode 2 ALT + RMB + if (zoomingActive) { + zoomingActive = false; + event->accept(); + } + } +} + +} // namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleMaya.h b/src/Mod/TechDraw/Gui/QGVNavStyleMaya.h new file mode 100644 index 0000000000..4e60c44650 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleMaya.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef TECHDRAW_MAYANAVSTYLE_H +#define TECHDRAW_MAYANAVSTYLE_H + +#include + +#include "QGVNavStyle.h" + +namespace TechDrawGui { + +class QGVPage; + +class TechDrawGuiExport QGVNavStyleMaya : public QGVNavStyle +{ +public: + QGVNavStyleMaya(); + virtual ~QGVNavStyleMaya(); + + virtual void handleKeyReleaseEvent(QKeyEvent *event) override; + virtual void handleMousePressEvent(QMouseEvent *event) override; + virtual void handleMouseMoveEvent(QMouseEvent *event) override; + virtual void handleMouseReleaseEvent(QMouseEvent *event) override; + + //context menu (RMB) prevents zoom mode 2 (ALT + RMB) + virtual bool allowContextMenu() override {return false;}; + +protected: +private: + +}; + +} +#endif // TECHDRAW_MAYANAVSTYLE_H diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleOCC.cpp b/src/Mod/TechDraw/Gui/QGVNavStyleOCC.cpp new file mode 100644 index 0000000000..4777b374cd --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleOCC.cpp @@ -0,0 +1,109 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#endif + +#include "QGVPage.h" +#include "QGVNavStyleOCC.h" + +using namespace TechDrawGui; + +namespace TechDrawGui { + +QGVNavStyleOCC::QGVNavStyleOCC() +{ +} + +QGVNavStyleOCC::~QGVNavStyleOCC() +{ +} + +void QGVNavStyleOCC::handleKeyReleaseEvent(QKeyEvent *event) +{ + //zoom mode 2 + if ( (event->key() == Qt::Key_Control) && zoomingActive) { + zoomingActive = false; + event->accept(); + } +} +void QGVNavStyleOCC::handleMousePressEvent(QMouseEvent *event) +{ + //pan mode MMB + mouse movement + //also Control + MMB + mouse movement, but this is redundant for our purposes + if (event->button() == Qt::MiddleButton) { + startPan(event->pos()); + event->accept(); + } + + //zoom mode 2 Control + LMB + if ((event->button() == Qt::LeftButton) && + (QApplication::keyboardModifiers() == Qt::ControlModifier)) { + startZoom(event->pos()); + event->accept(); + } +} + +void QGVNavStyleOCC::handleMouseMoveEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + getViewer()->setBalloonCursorPos(event->pos()); + } + + if (panningActive) { + pan(event->pos()); + event->accept(); + } + + if (zoomingActive) { + zoom(mouseZoomFactor(event->pos())); + } +} + +void QGVNavStyleOCC::handleMouseReleaseEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + placeBalloon(event->pos()); + } + + if (event->button() == Qt::MiddleButton) { + //pan mode [Control] + MMB + if (panningActive) { + stopPan(); + event->accept(); + } + } + + if (event->button() == Qt::LeftButton) { + //zoom mode 2 Control + LMB + if (zoomingActive) { + zoomingActive = false; + event->accept(); + } + } +} + +} // namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleOCC.h b/src/Mod/TechDraw/Gui/QGVNavStyleOCC.h new file mode 100644 index 0000000000..936af821ea --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleOCC.h @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef TECHDRAW_OCCNAVSTYLE_H +#define TECHDRAW_OCCNAVSTYLE_H + +#include + +#include "QGVNavStyle.h" + +namespace TechDrawGui { + +class QGVPage; + +class TechDrawGuiExport QGVNavStyleOCC : public QGVNavStyle +{ +public: + QGVNavStyleOCC(); + virtual ~QGVNavStyleOCC(); + + virtual void handleKeyReleaseEvent(QKeyEvent *event) override; + virtual void handleMousePressEvent(QMouseEvent *event) override; + virtual void handleMouseMoveEvent(QMouseEvent *event) override; + virtual void handleMouseReleaseEvent(QMouseEvent *event) override; + +protected: +private: + +}; + +} +#endif // TECHDRAW_OCCNAVSTYLE_H diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleOpenSCAD.cpp b/src/Mod/TechDraw/Gui/QGVNavStyleOpenSCAD.cpp new file mode 100644 index 0000000000..324388459d --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleOpenSCAD.cpp @@ -0,0 +1,114 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#endif + +#include "QGVPage.h" +#include "QGVNavStyleOpenSCAD.h" + +using namespace TechDrawGui; + +namespace TechDrawGui { + +QGVNavStyleOpenSCAD::QGVNavStyleOpenSCAD() +{ +} + +QGVNavStyleOpenSCAD::~QGVNavStyleOpenSCAD() +{ +} + +void QGVNavStyleOpenSCAD::handleKeyReleaseEvent(QKeyEvent *event) +{ + //zoom mode 2 + if ( (event->key() == Qt::Key_Shift) && zoomingActive) { + zoomingActive = false; + event->accept(); + } +} + +//eat the RMB event so it doesn't trigger MDIViewPage context +void QGVNavStyleOpenSCAD::handleMousePressEvent(QMouseEvent *event) +{ + //zoom mode 2 Shift + RMB + if ((event->button() == Qt::RightButton) && + (QApplication::keyboardModifiers() == Qt::ShiftModifier)) { + startZoom(event->pos()); + event->accept(); + } else if (event->button() == Qt::RightButton) { + //pan mode + startPan(event->pos()); + event->accept(); + } + + //zoom mode 2 MMB + if (event->button() == Qt::MiddleButton) { + startZoom(event->pos()); + event->accept(); + } +} + +void QGVNavStyleOpenSCAD::handleMouseMoveEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + getViewer()->setBalloonCursorPos(event->pos()); + } + + if (panningActive) { + pan(event->pos()); + event->accept(); + } + + if (zoomingActive) { + zoom(mouseZoomFactor(event->pos())); + event->accept(); + } +} + +void QGVNavStyleOpenSCAD::handleMouseReleaseEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + placeBalloon(event->pos()); + } + + if ((event->button() == Qt::RightButton) && panningActive) { + stopPan(); + event->accept(); + } + + if ((event->button() == Qt::RightButton) && zoomingActive) { + zoomingActive = false; + event->accept(); + } + + if ((event->button() == Qt::MiddleButton) && zoomingActive) { + zoomingActive = false; + event->accept(); + } +} + +} // namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleOpenSCAD.h b/src/Mod/TechDraw/Gui/QGVNavStyleOpenSCAD.h new file mode 100644 index 0000000000..a22d64cfd1 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleOpenSCAD.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef TECHDRAW_OPENSCADNAVSTYLE_H +#define TECHDRAW_OPENSCADNAVSTYLE_H + +#include + +#include "QGVNavStyle.h" + +namespace TechDrawGui { + +class QGVPage; + +class TechDrawGuiExport QGVNavStyleOpenSCAD : public QGVNavStyle +{ +public: + QGVNavStyleOpenSCAD(); + virtual ~QGVNavStyleOpenSCAD(); + + virtual void handleKeyReleaseEvent(QKeyEvent *event) override; + virtual void handleMouseMoveEvent(QMouseEvent *event) override; + virtual void handleMousePressEvent(QMouseEvent *event) override; + virtual void handleMouseReleaseEvent(QMouseEvent *event) override; + + //context menu (RMB) prevents pan and zoom + virtual bool allowContextMenu() override {return false;}; + +protected: +private: + +}; + +} +#endif // TECHDRAW_OPENSCADNAVSTYLE_H diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleRevit.cpp b/src/Mod/TechDraw/Gui/QGVNavStyleRevit.cpp new file mode 100644 index 0000000000..fe07fa1a9c --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleRevit.cpp @@ -0,0 +1,89 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#endif + +#include "QGVPage.h" +#include "QGVNavStyleRevit.h" + +using namespace TechDrawGui; + +namespace TechDrawGui { + +QGVNavStyleRevit::QGVNavStyleRevit() +{ +} + +QGVNavStyleRevit::~QGVNavStyleRevit() +{ +} + +void QGVNavStyleRevit::handleMousePressEvent(QMouseEvent *event) +{ + //pan mode 1 - LMB + RMB + if (event->buttons() == (Qt::LeftButton & Qt::RightButton)) { + startPan(event->pos()); + event->accept(); + } + + //pan mode 2 - MMB + if (event->button() == Qt::MiddleButton) { + startPan(event->pos()); + event->accept(); + } +} + +void QGVNavStyleRevit::handleMouseMoveEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + getViewer()->setBalloonCursorPos(event->pos()); + } + + if (panningActive) { + pan(event->pos()); + event->accept(); + } +} + +void QGVNavStyleRevit::handleMouseReleaseEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + placeBalloon(event->pos()); + } + + if (panningActive) { + //stop panning if any button release + if ( (event->button() == Qt::LeftButton) || + (event->button() == Qt::RightButton) || + (event->button() == Qt::MiddleButton) ){ + stopPan(); + event->accept(); + } + } +} + +} // namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleRevit.h b/src/Mod/TechDraw/Gui/QGVNavStyleRevit.h new file mode 100644 index 0000000000..d1762be0c7 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleRevit.h @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef TECHDRAW_REVITNAVSTYLE_H +#define TECHDRAW_REVITNAVSTYLE_H + +#include + +#include "QGVNavStyle.h" + +namespace TechDrawGui { + +class QGVPage; + +class TechDrawGuiExport QGVNavStyleRevit : public QGVNavStyle +{ +public: + QGVNavStyleRevit(); + virtual ~QGVNavStyleRevit(); + + virtual void handleMousePressEvent(QMouseEvent *event) override; + virtual void handleMouseMoveEvent(QMouseEvent *event) override; + virtual void handleMouseReleaseEvent(QMouseEvent *event) override; + + //context menu (RMB) prevents pan mode 2 (LMB + RMB) + virtual bool allowContextMenu() override {return false;}; + +protected: +private: + +}; + +} +#endif // TECHDRAW_REVITNAVSTYLE_H diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleTinkerCAD.cpp b/src/Mod/TechDraw/Gui/QGVNavStyleTinkerCAD.cpp new file mode 100644 index 0000000000..c8ff743a6d --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleTinkerCAD.cpp @@ -0,0 +1,83 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#include +#endif + +#include + +#include "QGVPage.h" +#include "QGSPage.h" +#include "QGVNavStyleTinkerCAD.h" + +using namespace TechDrawGui; + +namespace TechDrawGui { + +QGVNavStyleTinkerCAD::QGVNavStyleTinkerCAD() +{ +} + +QGVNavStyleTinkerCAD::~QGVNavStyleTinkerCAD() +{ +} + +void QGVNavStyleTinkerCAD::handleMousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::MiddleButton) { + startPan(event->pos()); + event->accept(); + } +} + +void QGVNavStyleTinkerCAD::handleMouseMoveEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + getViewer()->setBalloonCursorPos(event->pos()); + } + + if (panningActive) { + pan(event->pos()); + event->accept(); + } +} + +void QGVNavStyleTinkerCAD::handleMouseReleaseEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + placeBalloon(event->pos()); + } + + if (panningActive) { + if (event->button() == Qt::MiddleButton) { + stopPan(); + event->accept(); + } + } +} + +} // namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleTinkerCAD.h b/src/Mod/TechDraw/Gui/QGVNavStyleTinkerCAD.h new file mode 100644 index 0000000000..3cf77ea5a6 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleTinkerCAD.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef TECHDRAW_TINKERNAVSTYLE_H +#define TECHDRAW_TINKERNAVSTYLE_H + +#include + +#include "QGVNavStyle.h" + +namespace TechDrawGui { + +class QGVPage; + +class TechDrawGuiExport QGVNavStyleTinkerCAD : public QGVNavStyle +{ +// TYPESYSTEM_HEADER(); + +public: + QGVNavStyleTinkerCAD(); + virtual ~QGVNavStyleTinkerCAD(); + + virtual void handleMouseMoveEvent(QMouseEvent *event) override; + virtual void handleMousePressEvent(QMouseEvent *event) override; + virtual void handleMouseReleaseEvent(QMouseEvent *event) override; + +protected: +private: + +}; + +} +#endif // TECHDRAW_TINKERNAVSTYLE_H diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleTouchpad.cpp b/src/Mod/TechDraw/Gui/QGVNavStyleTouchpad.cpp new file mode 100644 index 0000000000..0090209fda --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleTouchpad.cpp @@ -0,0 +1,130 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#endif + +#include "QGVPage.h" +#include "QGVNavStyleTouchpad.h" + +using namespace TechDrawGui; + +namespace TechDrawGui { + +QGVNavStyleTouchpad::QGVNavStyleTouchpad() +{ +} + +QGVNavStyleTouchpad::~QGVNavStyleTouchpad() +{ +} + +void QGVNavStyleTouchpad::handleKeyPressEvent(QKeyEvent *event) +{ +// Q_UNUSED(event) + if (event->key() == Qt::Key_PageUp) { + setAnchor(); + zoom(1.0 + zoomStep); + event->accept(); + return; + } + + if (event->key() == Qt::Key_PageDown) { + setAnchor(); + zoom(1.0 - zoomStep); + event->accept(); + return; + } +} + +void QGVNavStyleTouchpad::handleKeyReleaseEvent(QKeyEvent *event) +{ +// Q_UNUSED(event) + if (event->key() == Qt::Key_Shift) { + if (panningActive == true) { + stopPan(); + } + zoomingActive = false; + } + + if (event->key() == Qt::Key_Control) { + zoomingActive = false; + } + +} + +void QGVNavStyleTouchpad::handleMouseMoveEvent(QMouseEvent *event) +{ + if (getViewer()->isBalloonPlacing()) { + getViewer()->setBalloonCursorPos(event->pos()); + } + + if (QApplication::keyboardModifiers() == Qt::ShiftModifier) { + //if shift is down then we are panning + if (!panningActive) { + startPan(event->pos()); + } + zoomingActive = false; + } else if (QApplication::keyboardModifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) { + // if control and shift are down then we are zooming + if (panningActive == true) { + stopPan(); + } + if (!zoomingActive) { + startZoom(event->pos()); + event->accept(); + return; //don't zoom on first movement + } + } else { + if (panningActive == true) { + stopPan(); + } + zoomingActive = false; + } + + if (panningActive) { + pan(event->pos()); + event->accept(); + } + + if (zoomingActive) { +// setAnchor(); + zoom(mouseZoomFactor(event->pos())); + event->accept(); + } +} + +void QGVNavStyleTouchpad::setAnchor() +{ + //this navigation style can not anchor under mouse since mouse is moving as part of zoom action + if (m_viewer != nullptr) { + m_viewer->setResizeAnchor(QGraphicsView::AnchorViewCenter); + m_viewer->setTransformationAnchor(QGraphicsView::AnchorViewCenter); + } +} + + +} //namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/QGVNavStyleTouchpad.h b/src/Mod/TechDraw/Gui/QGVNavStyleTouchpad.h new file mode 100644 index 0000000000..ff73958caa --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGVNavStyleTouchpad.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (c) 2022 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef TECHDRAW_TOUCHPADNAVSTYLE_H +#define TECHDRAW_TOUCHPADNAVSTYLE_H + +#include + +#include "QGVNavStyle.h" + +namespace TechDrawGui { + +class QGVPage; + +class TechDrawGuiExport QGVNavStyleTouchpad : public QGVNavStyle +{ +public: + QGVNavStyleTouchpad(); + virtual ~QGVNavStyleTouchpad(); + + virtual void handleKeyPressEvent(QKeyEvent *event) override; + virtual void handleKeyReleaseEvent(QKeyEvent *event) override; + virtual void handleMouseMoveEvent(QMouseEvent *event) override; + +protected: + virtual void setAnchor() override; + +private: + +}; + +} +#endif // TECHDRAW_TOUCHPADNAVSTYLE_H diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index 6f21729c97..317ef1374a 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -60,6 +60,7 @@ #include #include #include +#include #include #include @@ -110,8 +111,20 @@ #include "ZVALUE.h" #include "ViewProviderPage.h" +#include "QGSPage.h" #include "QGVPage.h" #include "MDIViewPage.h" +#include "QGVNavStyle.h" +#include "QGVNavStyleBlender.h" +#include "QGVNavStyleTouchpad.h" +#include "QGVNavStyleCAD.h" +#include "QGVNavStyleTinkerCAD.h" +#include "QGVNavStyleGesture.h" +#include "QGVNavStyleInventor.h" +#include "QGVNavStyleMaya.h" +#include "QGVNavStyleOCC.h" +#include "QGVNavStyleOpenSCAD.h" +#include "QGVNavStyleRevit.h" // used SVG namespaces #define CC_NS_URI "http://creativecommons.org/ns#" @@ -124,15 +137,16 @@ using namespace Gui; using namespace TechDraw; using namespace TechDrawGui; -QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene* s, QWidget *parent) +QGVPage::QGVPage(ViewProviderPage *vp, QGSPage* s, QWidget *parent) : QGraphicsView(parent), - pageTemplate(nullptr), m_renderer(Native), drawBkg(true), m_vpPage(nullptr), + m_scene(s), balloonPlacing(false), panningActive(false), - m_showGrid(false) + m_showGrid(false), + m_navStyle(nullptr) { assert(vp); m_vpPage = vp; @@ -182,12 +196,91 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene* s, QWidget *parent) balloonCursor->hide(); resetCachedContent(); + + // attach parameter Observer + hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); + hGrp->Attach(this); + + initNavigationStyle(); } QGVPage::~QGVPage() { delete bkgBrush; + delete m_navStyle; +} +void QGVPage::initNavigationStyle() +{ + std::string navParm = getNavStyleParameter(); + setNavigationStyle(navParm); +} + +void QGVPage::setNavigationStyle(std::string navParm) +{ +// Base::Console().Message("QGVP::setNavigationStyle(%s)\n", navParm.c_str()); + if (m_navStyle != nullptr) { + delete m_navStyle; + } + + std::size_t foundBlender = navParm.find("Blender"); + std::size_t foundCAD = navParm.find("Gui::CAD"); + std::size_t foundTouchPad = navParm.find("Touchpad"); + std::size_t foundInventor = navParm.find("Inventor"); + std::size_t foundTinker = navParm.find("TinkerCAD"); + std::size_t foundGesture = navParm.find("Gui::Gesture"); + std::size_t foundMaya = navParm.find("Gui::Maya"); + std::size_t foundOCC = navParm.find("OpenCascade"); + std::size_t foundOpenSCAD = navParm.find("OpenSCAD"); + std::size_t foundRevit = navParm.find("Revit"); + + if (foundBlender != std::string::npos) { + m_navStyle = static_cast(new QGVNavStyleBlender()); + } else if (foundCAD != std::string::npos) { + m_navStyle = static_cast(new QGVNavStyleCAD()); + } else if (foundTouchPad != std::string::npos) { + m_navStyle = static_cast(new QGVNavStyleTouchpad()); + } else if (foundInventor != std::string::npos) { + m_navStyle = static_cast(new QGVNavStyleInventor()); + } else if (foundTinker != std::string::npos) { + m_navStyle = static_cast(new QGVNavStyleTinkerCAD()); + } else if (foundGesture != std::string::npos) { + m_navStyle = static_cast(new QGVNavStyleGesture()); + } else if (foundMaya != std::string::npos) { + m_navStyle = static_cast(new QGVNavStyleMaya()); + } else if (foundOCC != std::string::npos) { + m_navStyle = static_cast(new QGVNavStyleOCC()); + } else if (foundOpenSCAD != std::string::npos) { + m_navStyle = static_cast(new QGVNavStyleOpenSCAD()); + } else if (foundRevit != std::string::npos) { + m_navStyle = static_cast(new QGVNavStyleRevit()); + } else { + m_navStyle = new QGVNavStyle(); + } + + m_navStyle->setViewer(this); +} + +void QGVPage::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::MessageType Reason) +{ + const ParameterGrp& rGrp = static_cast(rCaller); + if (strcmp(Reason,"NavigationStyle") == 0) { + std::string model = rGrp.GetASCII("NavigationStyle",CADNavigationStyle::getClassTypeId().getName()); + setNavigationStyle(model); + } else if (strcmp(Reason,"InvertZoom") == 0) { + m_invertZoom = rGrp.GetBool("InvertZoom", true); + } else if (strcmp(Reason,"ZoomStep") == 0) { + m_zoomIncrement = rGrp.GetFloat("ZoomStep", 0.0f); + } else if (strcmp(Reason,"ZoomAtCursor") == 0) { + m_atCursor = rGrp.GetBool("ZoomAtCursor", true); + if (m_atCursor) { + setResizeAnchor(AnchorUnderMouse); + setTransformationAnchor(AnchorUnderMouse); + } else { + setResizeAnchor(AnchorViewCenter); + setTransformationAnchor(AnchorViewCenter); + } + } } void QGVPage::startBalloonPlacing(void) @@ -251,526 +344,7 @@ void QGVPage::drawBackground(QPainter *p, const QRectF &) p->restore(); } -//! retrieve the QGIView objects currently in the scene -std::vector QGVPage::getViews() const -{ - std::vector result; - QList items = scene()->items(); - for (auto& v:items) { - QGIView* qv = dynamic_cast(v); - if (qv != nullptr) { - result.push_back(qv); - } - } - return result; -} -int QGVPage::addQView(QGIView *view) -{ - //don't add twice! - QGIView* existing = getQGIVByName(view->getViewName()); - if (existing == nullptr) { - auto ourScene( scene() ); - assert(ourScene); - - ourScene->addItem(view); - - // Find if it belongs to a parent - QGIView *parent = nullptr; - parent = findParent(view); - - QPointF viewPos(Rez::guiX(view->getViewObject()->X.getValue()), - Rez::guiX(view->getViewObject()->Y.getValue() * -1)); - - if(parent) { - // move child view to center of parent - QPointF posRef(0.,0.); - QPointF mapPos = view->mapToItem(parent, posRef); - view->moveBy(-mapPos.x(), -mapPos.y()); - - parent->addToGroup(view); - } - - view->setPos(viewPos); - view->updateView(true); - } - return 0; -} - -int QGVPage::removeQView(QGIView *view) -{ - if (view != nullptr) { - removeQViewFromScene(view); - delete view; - } - return 0; -} - -int QGVPage::removeQViewByName(const char* name) -{ - std::vector items = getViews(); - QString qsName = QString::fromUtf8(name); - bool found = false; - QGIView* ourItem = nullptr; - for (auto& i:items) { - if (qsName == i->data(1).toString()) { //is there a QGIV with this name in scene? - found = true; - ourItem = i; - break; - } - } - - if (found) { - int balloonItemType = QGraphicsItem::UserType + 140; - if (ourItem->type() == balloonItemType) { - QGIViewBalloon* balloon = dynamic_cast(ourItem); - balloon->disconnect(); - } - removeQViewFromScene(ourItem); - delete ourItem; //commenting this prevents crash but means a small memory waste. - //alternate fix(?) is to change indexing/caching option in scene/view - } - - return 0; -} - -void QGVPage::removeQViewFromScene(QGIView *view) -{ - if (view->scene() != nullptr) { - QGIView* qgParent = dynamic_cast(view->parentItem()); - if (qgParent != nullptr) { - qgParent->removeChild(view); - } else { - view->scene()->removeItem(view); - } - } -} - - -QGIView * QGVPage::addViewPart(TechDraw::DrawViewPart *part) -{ - QGIView* existing = findQViewForDocObj(part); - if (existing != nullptr) { - return existing; - } - - auto viewPart( new QGIViewPart ); - - viewPart->setViewPartFeature(part); - - addQView(viewPart); - return viewPart; -} - -QGIView * QGVPage::addViewSection(TechDraw::DrawViewPart *part) -{ - auto viewSection( new QGIViewSection ); - - viewSection->setViewPartFeature(part); - - addQView(viewSection); - return viewSection; -} - -QGIView * QGVPage::addProjectionGroup(TechDraw::DrawProjGroup *view) { - auto qview( new QGIProjGroup ); - - qview->setViewFeature(view); - addQView(qview); - return qview; -} - -QGIView * QGVPage::addDrawView(TechDraw::DrawView *view) -{ - auto qview( new QGIView ); - - qview->setViewFeature(view); - addQView(qview); - return qview; -} - -QGIView * QGVPage::addDrawViewCollection(TechDraw::DrawViewCollection *view) -{ - auto qview( new QGIViewCollection ); - - qview->setViewFeature(view); - addQView(qview); - return qview; -} - -// TODO change to (App?) annotation object ?? -QGIView * QGVPage::addDrawViewAnnotation(TechDraw::DrawViewAnnotation *view) -{ - auto qview( new QGIViewAnnotation ); - - qview->setViewAnnoFeature(view); - - addQView(qview); - return qview; -} - -QGIView * QGVPage::addDrawViewSymbol(TechDraw::DrawViewSymbol *view) -{ - auto qview( new QGIViewSymbol ); - - qview->setViewFeature(view); - - addQView(qview); - return qview; -} - -QGIView * QGVPage::addDrawViewClip(TechDraw::DrawViewClip *view) -{ - auto qview( new QGIViewClip ); - - qview->setPosition(Rez::guiX(view->X.getValue()), Rez::guiX(view->Y.getValue())); - qview->setViewFeature(view); - - addQView(qview); - return qview; -} - -QGIView * QGVPage::addDrawViewSpreadsheet(TechDraw::DrawViewSpreadsheet *view) -{ - auto qview( new QGIViewSpreadsheet ); - - qview->setViewFeature(view); - - addQView(qview); - return qview; -} - -QGIView * QGVPage::addDrawViewImage(TechDraw::DrawViewImage *view) -{ - auto qview( new QGIViewImage ); - - qview->setViewFeature(view); - - addQView(qview); - return qview; -} - -QGIView * QGVPage::addViewBalloon(TechDraw::DrawViewBalloon *balloon) -{ - auto vBalloon( new QGIViewBalloon ); - - auto ourScene( scene() ); - assert(ourScene); - ourScene->addItem(vBalloon); - - vBalloon->setViewPartFeature(balloon); - vBalloon->dvBalloon = balloon; - - QGIView *parent = nullptr; - parent = findParent(vBalloon); - - if (parent) { - addBalloonToParent(vBalloon,parent); - } - - if (balloonPlacing) { - vBalloon->placeBalloon(balloon->origin); - cancelBalloonPlacing(); - } - - return vBalloon; -} - -void QGVPage::addBalloonToParent(QGIViewBalloon* balloon, QGIView* parent) -{ - assert(balloon); - assert(parent); //blow up if we don't have Dimension or Parent - QPointF posRef(0.,0.); - QPointF mapPos = balloon->mapToItem(parent, posRef); - balloon->moveBy(-mapPos.x(), -mapPos.y()); - parent->addToGroup(balloon); - 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")); - 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()); - - TechDraw::DrawViewBalloon *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(); - - parent->touch(true); - Gui::Command::updateActive(); -} - -QGIView * QGVPage::addViewDimension(TechDraw::DrawViewDimension *dim) -{ - auto dimGroup( new QGIViewDimension ); - - auto ourScene( scene() ); - assert(ourScene); - ourScene->addItem(dimGroup); - - dimGroup->setViewPartFeature(dim); - dimGroup->dvDimension = dim; - - // Find if it belongs to a parent - QGIView *parent = nullptr; - parent = findParent(dimGroup); - - if(parent) { - addDimToParent(dimGroup,parent); - } - - return dimGroup; -} - -void QGVPage::addDimToParent(QGIViewDimension* dim, QGIView* parent) -{ -// Base::Console().Message("QGVP::addDimToParent()\n"); - assert(dim); - assert(parent); //blow up if we don't have Dimension or Parent - QPointF posRef(0.,0.); - QPointF mapPos = dim->mapToItem(parent, posRef); - dim->moveBy(-mapPos.x(), -mapPos.y()); - parent->addToGroup(dim); - dim->setZValue(ZVALUE::DIMENSION); -} - -QGIView * QGVPage::addViewLeader(TechDraw::DrawLeaderLine *leader) -{ -// Base::Console().Message("QGVP::addViewLeader(%s)\n",leader->getNameInDocument()); - QGILeaderLine* leaderGroup = new QGILeaderLine(); - - auto ourScene( scene() ); - ourScene->addItem(leaderGroup); - - leaderGroup->setLeaderFeature(leader); - - QGIView *parent = nullptr; - parent = findParent(leaderGroup); - - if(parent) { - addLeaderToParent(leaderGroup,parent); - } - - leaderGroup->updateView(true); - - return leaderGroup; -} - -void QGVPage::addLeaderToParent(QGILeaderLine* lead, QGIView* parent) -{ -// Base::Console().Message("QGVP::addLeaderToParent()\n"); - parent->addToGroup(lead); - lead->setZValue(ZVALUE::DIMENSION); -} - -QGIView * QGVPage::addRichAnno(TechDraw::DrawRichAnno* anno) -{ - QGIRichAnno* annoGroup = nullptr; - TechDraw::DrawView* parentDV = nullptr; - - App::DocumentObject* parentObj = anno->AnnoParent.getValue(); - if (parentObj != nullptr) { - parentDV = dynamic_cast(parentObj); - } - if (parentDV != nullptr) { - QGIView* parentQV = findQViewForDocObj(parentObj); - annoGroup = new QGIRichAnno(parentQV, anno); - annoGroup->updateView(true); - } else { - annoGroup = new QGIRichAnno(nullptr, anno); - if (annoGroup->scene() == nullptr) { - scene()->addItem(annoGroup); - } - annoGroup->updateView(true); - } - return annoGroup; -} - -QGIView * QGVPage::addWeldSymbol(TechDraw::DrawWeldSymbol* weld) -{ -// Base::Console().Message("QGVP::addWeldSymbol()\n"); - QGIWeldSymbol* weldGroup = nullptr; - TechDraw::DrawView* parentDV = nullptr; - - App::DocumentObject* parentObj = weld->Leader.getValue(); - if (parentObj != nullptr) { - parentDV = dynamic_cast(parentObj); - } else { -// Base::Console().Message("QGVP::addWeldSymbol - no parent doc obj\n"); - } - if (parentDV != nullptr) { - QGIView* parentQV = findQViewForDocObj(parentObj); - QGILeaderLine* leadParent = dynamic_cast(parentQV); - if (leadParent != nullptr) { - weldGroup = new QGIWeldSymbol(leadParent); - weldGroup->setFeature(weld); //for QGIWS - weldGroup->setViewFeature(weld); //for QGIV - weldGroup->updateView(true); - } else { - Base::Console().Error("QGVP::addWeldSymbol - no parent QGILL\n"); - } - } else { - Base::Console().Error("QGVP::addWeldSymbol - parent is not DV!\n"); - } - return weldGroup; -} - - -//! find the graphic for a DocumentObject -QGIView * QGVPage::findQViewForDocObj(App::DocumentObject *obj) const -{ - if(obj) { - const std::vector qviews = getViews(); - for(std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { - if(strcmp(obj->getNameInDocument(), (*it)->getViewName()) == 0) - return *it; - } - } - return nullptr; -} - -//! find the graphic for DocumentObject with name -QGIView* QGVPage::getQGIVByName(std::string name) -{ - QList qgItems = scene()->items(); - QList::iterator it = qgItems.begin(); - for (; it != qgItems.end(); it++) { - QGIView* qv = dynamic_cast((*it)); - if (qv) { - const char* qvName = qv->getViewName(); - if(name.compare(qvName) == 0) { - return (qv); - } - } - } - return nullptr; -} - -//find the parent of a QGIV based on the corresponding feature's parentage -QGIView * QGVPage::findParent(QGIView *view) const -{ - const std::vector qviews = getViews(); - TechDraw::DrawView *myFeat = view->getViewObject(); - -//LandmarkDimension shouldn't require special handling -// TechDraw::LandmarkDimension *robust = nullptr; -// robust = dynamic_cast(myFeat); -// if (robust != nullptr) { -// App::DocumentObject* robustParent = robust->ParentView.getValue(); -// for (auto& qv: qviews) { -// if(strcmp(qv->getViewName(), robustParent->getNameInDocument()) == 0) { -// return qv; -// } -// } -// } - - //If type is dimension we check references first - TechDraw::DrawViewDimension *dim = nullptr; - dim = dynamic_cast(myFeat); - if(dim) { - std::vector objs = dim->References2D.getValues(); - - if(objs.size() > 0) { - std::vector objs = dim->References2D.getValues(); - // Attach the dimension to the first object's group - for(std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { - if(strcmp((*it)->getViewName(), objs.at(0)->getNameInDocument()) == 0) { - return *it; - } - } - } - } - - //If type is balloon we check references first - TechDraw::DrawViewBalloon *balloon = nullptr; - balloon = dynamic_cast(myFeat); - - if(balloon) { - App::DocumentObject* obj = balloon->SourceView.getValue(); - - if(obj) { - // Attach the dimension to the first object's group - for(std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { - if(strcmp((*it)->getViewName(), obj->getNameInDocument()) == 0) { - return *it; - } - } - } - } - - // Check if part of view collection - for(std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { - QGIViewCollection *grp = nullptr; - grp = dynamic_cast(*it); - if(grp) { - TechDraw::DrawViewCollection *collection = nullptr; - collection = dynamic_cast(grp->getViewObject()); - if(collection) { - std::vector objs = collection->Views.getValues(); - for( std::vector::iterator it = objs.begin(); it != objs.end(); ++it) { - if(strcmp(myFeat->getNameInDocument(), (*it)->getNameInDocument()) == 0) - - return grp; - } - } - } - } - - //If type is LeaderLine we check LeaderParent - TechDraw::DrawLeaderLine *lead = nullptr; - lead = dynamic_cast(myFeat); - - if(lead) { - App::DocumentObject* obj = lead->LeaderParent.getValue(); - if(obj != nullptr) { - std::string parentName = obj->getNameInDocument(); - for(std::vector::const_iterator it = qviews.begin(); it != qviews.end(); ++it) { - if(strcmp((*it)->getViewName(), parentName.c_str()) == 0) { - return *it; - } - } - } - } - // Not found a parent - return nullptr; -} - -void QGVPage::setPageTemplate(TechDraw::DrawTemplate *obj) -{ - removeTemplate(); - - if(obj->isDerivedFrom(TechDraw::DrawParametricTemplate::getClassTypeId())) { - pageTemplate = new QGIDrawingTemplate(scene()); - } else if(obj->isDerivedFrom(TechDraw::DrawSVGTemplate::getClassTypeId())) { - pageTemplate = new QGISVGTemplate(scene()); - } - pageTemplate->setTemplate(obj); - pageTemplate->updateView(); -} - -QGITemplate* QGVPage::getTemplate() const -{ - return pageTemplate; -} - -void QGVPage::removeTemplate() -{ - if(pageTemplate) { - scene()->removeItem(pageTemplate); - pageTemplate->deleteLater(); - pageTemplate = nullptr; - } -} void QGVPage::setRenderer(RendererType type) { m_renderer = type; @@ -793,241 +367,23 @@ void QGVPage::setHighQualityAntialiasing(bool highQualityAntialiasing) #endif } -void QGVPage::refreshViews(void) +void QGVPage::contextMenuEvent(QContextMenuEvent *event) { -// Base::Console().Message("QGVP::refreshViews()\n"); - QList list = scene()->items(); - QList qgiv; - //find only QGIV's - for (auto q: list) { - QString viewFamily = QString::fromUtf8("QGIV"); - if (viewFamily == q->data(0).toString()) { - qgiv.push_back(q); - } + if (m_navStyle->allowContextMenu()) { + QGraphicsView::contextMenuEvent(event); } - for (auto q: qgiv) { - QGIView *itemView = dynamic_cast(q); - if(itemView) { - itemView->updateView(true); - } - } -} - -void QGVPage::setExporting(bool enable) -{ - QList sceneItems = scene()->items(); - std::vector dvps; - for (auto& qgi:sceneItems) { - QGIViewPart* qgiPart = dynamic_cast(qgi); - QGIRichAnno* qgiRTA = dynamic_cast(qgi); - if(qgiPart) { - qgiPart->setExporting(enable); - dvps.push_back(qgiPart); - } - if (qgiRTA) { - qgiRTA->setExporting(enable); - } - } - for (auto& v: dvps) { - v->draw(); - } -} - -void QGVPage::saveSvg(QString filename) -{ - // TODO: We only have m_vpPage because constructor gets passed a view provider... - //NOTE: this makes wrong size pages in low-Rez - TechDraw::DrawPage *page( m_vpPage->getDrawPage() ); - - const QString docName( QString::fromUtf8(page->getDocument()->getName()) ); - const QString pageName( QString::fromUtf8(page->getNameInDocument()) ); - QString svgDescription = QString::fromUtf8("Drawing page: ") + - pageName + - QString::fromUtf8(" exported from FreeCAD document: ") + - docName; - - QSvgGenerator svgGen; - QTemporaryFile temporaryFile; - svgGen.setOutputDevice(&temporaryFile); - - // Set resolution in DPI. Use the actual one, i.e. Rez::guiX(inch) - svgGen.setResolution(Rez::guiX(25.4)); - - // Set size in pixels, which Qt recomputes using DPI to mm. - int pixelWidth = Rez::guiX(page->getPageWidth()); - int pixelHeight = Rez::guiX(page->getPageHeight()); - svgGen.setSize(QSize(pixelWidth, pixelHeight)); - - //"By default this property is set to QSize(-1, -1), which indicates that the generator should not output - // the width and height attributes of the element." >> but Inkscape won't read it without size info?? - svgGen.setViewBox(QRect(0, 0, pixelWidth, pixelHeight)); - - svgGen.setTitle(QString::fromUtf8("FreeCAD SVG Export")); - svgGen.setDescription(svgDescription); - - Gui::Selection().clearSelection(); - - bool saveState = m_vpPage->getFrameState(); - m_vpPage->setFrameState(false); - m_vpPage->setTemplateMarkers(false); - setExporting(true); - - // Here we temporarily hide the page template, because Qt would otherwise convert the SVG template - // texts into series of paths, making the later document edits practically unfeasible. - // We will insert the SVG template ourselves in the final XML postprocessing operation. - QGISVGTemplate *svgTemplate = dynamic_cast(pageTemplate); - bool templateVisible = false; - if (svgTemplate) { - templateVisible = svgTemplate->isVisible(); - svgTemplate->hide(); - } - - refreshViews(); - viewport()->repaint(); - - double width = Rez::guiX(page->getPageWidth()); - double height = Rez::guiX(page->getPageHeight()); - QRectF sourceRect(0.0,-height,width,height); - QRectF targetRect(0.0,0.0,width,height); - - Gui::Selection().clearSelection(); - QPainter p; - - p.begin(&svgGen); - scene()->render(&p, targetRect,sourceRect); //note: scene render, not item render! - p.end(); - - m_vpPage->setFrameState(saveState); - m_vpPage->setTemplateMarkers(saveState); - setExporting(false); - if (templateVisible && svgTemplate) { - svgTemplate->show(); - } - - refreshViews(); - viewport()->repaint(); - - temporaryFile.close(); - postProcessXml(temporaryFile, filename, pageName); -} - -static void removeEmptyGroups(QDomElement e) -{ - while (!e.isNull()) { - QDomElement next = e.nextSiblingElement(); - if (e.hasChildNodes()) { - removeEmptyGroups(e.firstChildElement()); - } else if (e.tagName() == QLatin1String("g")) { - e.parentNode().removeChild(e); - } - e = next; - } -} - -void QGVPage::postProcessXml(QTemporaryFile& temporaryFile, QString fileName, QString pageName) -{ - QDomDocument exportDoc(QString::fromUtf8("SvgDoc")); - QFile file(temporaryFile.fileName()); - if (!file.open(QIODevice::ReadOnly)) { - Base::Console().Message("QGVPage::ppsvg - tempfile open error\n"); - return; - } - if (!exportDoc.setContent(&file)) { - Base::Console().Message("QGVPage::ppsvg - xml error\n"); - file.close(); - return; - } - file.close(); - - QDomElement exportDocElem = exportDoc.documentElement(); //root - - // Insert Freecad SVG namespace into namespace declarations - exportDocElem.setAttribute(QString::fromUtf8("xmlns:freecad"), - QString::fromUtf8(FREECAD_SVG_NS_URI)); - // Insert all namespaces used by TechDraw's page template SVGs - exportDocElem.setAttribute(QString::fromUtf8("xmlns:svg"), - QString::fromUtf8(SVG_NS_URI)); - exportDocElem.setAttribute(QString::fromUtf8("xmlns:cc"), - QString::fromUtf8(CC_NS_URI)); - exportDocElem.setAttribute(QString::fromUtf8("xmlns:dc"), - QString::fromUtf8(DC_NS_URI)); - exportDocElem.setAttribute(QString::fromUtf8("xmlns:rdf"), - QString::fromUtf8(RDF_NS_URI)); - exportDocElem.setAttribute(QString::fromUtf8("xmlns:inkscape"), - QString::fromUtf8(INKSCAPE_NS_URI)); - exportDocElem.setAttribute(QString::fromUtf8("xmlns:sodipodi"), - QString::fromUtf8(SODIPODI_NS_URI)); - - // Create the root group which will host the drawing group and the template group - QDomElement rootGroup = exportDoc.createElement(QString::fromUtf8("g")); - rootGroup.setAttribute(QString::fromUtf8("id"), pageName); - rootGroup.setAttribute(QString::fromUtf8("inkscape:groupmode"), - QString::fromUtf8("layer")); - rootGroup.setAttribute(QString::fromUtf8("inkscape:label"), - QString::fromUtf8("TechDraw")); - - // Now insert our template - QGISVGTemplate *svgTemplate = dynamic_cast(pageTemplate); - if (svgTemplate) { - DrawSVGTemplate *drawTemplate = svgTemplate->getSVGTemplate(); - if (drawTemplate) { - QFile templateResultFile(QString::fromUtf8(drawTemplate->PageResult.getValue())); - if (templateResultFile.open(QIODevice::ReadOnly)) { - QDomDocument templateResultDoc(QString::fromUtf8("SvgDoc")); - if (templateResultDoc.setContent(&templateResultFile)) { - QDomElement templateDocElem = templateResultDoc.documentElement(); - - // Insert the template into a new group with id set to template name - QDomElement templateGroup = exportDoc.createElement(QString::fromUtf8("g")); - Base::FileInfo fi(drawTemplate->Template.getValue()); - templateGroup.setAttribute(QString::fromUtf8("id"), - QString::fromUtf8(fi.fileName().c_str())); - templateGroup.setAttribute(QString::fromUtf8("style"), - QString::fromUtf8("stroke: none;")); - - // Scale the template group correctly -#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) - templateGroup.setAttribute(QString::fromUtf8("transform"), - QString().sprintf("scale(%f, %f)", Rez::guiX(1.0), Rez::guiX(1.0))); -#else - templateGroup.setAttribute(QString::fromUtf8("transform"), - QString::fromLatin1("scale(%1, %2)").arg(Rez::guiX(1.0), 0, 'f').arg(Rez::guiX(1.0), 0, 'f')); -#endif - - // Finally, transfer all template document child nodes under the template group - while (!templateDocElem.firstChild().isNull()) { - templateGroup.appendChild(templateDocElem.firstChild()); - } - - rootGroup.appendChild(templateGroup); - } - } - } - } - - // Obtain the drawing group element, move it under root node and set its id to "DrawingContent" - QDomElement drawingGroup = exportDocElem.firstChildElement(QLatin1String("g")); - if (!drawingGroup.isNull()) { - drawingGroup.setAttribute(QString::fromUtf8("id"), QString::fromUtf8("DrawingContent")); - rootGroup.appendChild(drawingGroup); - } - exportDocElem.appendChild(rootGroup); - - // As icing on the cake, get rid of the empty 's Qt SVG generator painting inserts. - removeEmptyGroups(exportDocElem); - - // Time to save our product - QFile outFile( fileName ); - if( !outFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) { - Base::Console().Message("QGVP::ppxml - failed to open file for writing: %s\n",qPrintable(fileName) ); - } - - QTextStream stream( &outFile ); - stream.setGenerateByteOrderMark(false); - stream.setCodec("UTF-8"); - - stream << exportDoc.toByteArray(); - outFile.close(); + //TODO: allow RMB press and context menu + // by triggering pseudo-mousePressEvent, then calling QGV::contextMenuEvent + // QMouseEvent* mouseEvent(QEvent::MouseButtonPress, + // event->pos(), //local pos + // event->globalPos(), //window pos + // event->globalPos(), //screen pos + // Qt::RightButton, //button + // Qt::RightButton, //buttons, + // Qt::NoModifier, //KB modifiers + // Qt::MouseEventSynthesizedByApplication) //source + // m_navStyle->handleMousePressEvent(mouseEvent); + // QGraphicsView::contextMenuEvent(event); } void QGVPage::paintEvent(QPaintEvent *event) @@ -1051,81 +407,29 @@ void QGVPage::paintEvent(QPaintEvent *event) void QGVPage::wheelEvent(QWheelEvent *event) { -//Delta is the distance that the wheel is rotated, in eighths of a degree. -//positive indicates rotation forwards away from the user; negative backwards toward the user. -//Most mouse types work in steps of 15 degrees, in which case the delta value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees. -//1 click = 15 degrees. 15 degrees = 120 deltas. delta/240 -> 1 click = 0.5 ==> factor = 1.2^0.5 = 1.095 -// 1 click = -0.5 ==> factor = 1.2^-0.5 = 0.91 -//so to change wheel direction, multiply (event->delta() / 240.0) by +/-1 - double mouseBase = 1.2; //magic numbers. change for different mice? - double mouseAdjust = -240.0; - if (m_invertZoom) { - mouseAdjust = -mouseAdjust; - } - - QPointF center = mapToScene(viewport()->rect().center()); - int delta = event->angleDelta().y(); - qreal factor = std::pow(mouseBase, delta / mouseAdjust); - scale(factor, factor); - - QPointF newCenter = mapToScene(viewport()->rect().center()); - QPointF change = newCenter - center; - translate(change.x(), change.y()); - + m_navStyle->handleWheelEvent(event); event->accept(); } void QGVPage::keyPressEvent(QKeyEvent *event) { - if(event->modifiers().testFlag(Qt::ControlModifier)) { - switch(event->key()) { - case Qt::Key_Plus: { - scale(1.0 + m_zoomIncrement, 1.0 + m_zoomIncrement); - break; - } - case Qt::Key_Minus: { - scale(1.0 - m_zoomIncrement, 1.0 - m_zoomIncrement); - break; - } - default: { - break; - } - } + m_navStyle->handleKeyPressEvent(event); + if (!event->isAccepted()) { + QGraphicsView::keyPressEvent(event); } +} - if(event->modifiers().testFlag( Qt::NoModifier)) { - switch(event->key()) { - case Qt::Key_Left: { - kbPanScroll(1, 0); - break; - } - case Qt::Key_Up: { - kbPanScroll(0, 1); - break; - } - case Qt::Key_Right: { - kbPanScroll(-1, 0); - break; - } - case Qt::Key_Down: { - kbPanScroll(0, -1); - break; - } - case Qt::Key_Escape: { - cancelBalloonPlacing(); - break; - } - default: { - break; - } - } +void QGVPage::keyReleaseEvent(QKeyEvent *event) +{ + m_navStyle->handleKeyReleaseEvent(event); + if (!event->isAccepted()) { + QGraphicsView::keyReleaseEvent(event); } - QGraphicsView::keyPressEvent(event); } void QGVPage::focusOutEvent(QFocusEvent *event) { - Q_UNUSED(event); - cancelBalloonPlacing(); + Q_UNUSED(event); + m_navStyle->handleFocusOutEvent(event); } void QGVPage::kbPanScroll(int xMove, int yMove) @@ -1149,82 +453,31 @@ void QGVPage::kbPanScroll(int xMove, int yMove) void QGVPage::enterEvent(QEvent *event) { QGraphicsView::enterEvent(event); - if (balloonPlacing) { - balloonCursor->hide(); - } + m_navStyle->handleEnterEvent(event); + QGraphicsView::enterEvent(event); } void QGVPage::leaveEvent(QEvent * event) { - if (balloonPlacing) { - int left_x; - if (balloonCursorPos.x() < 32) - left_x = 0; - else if (balloonCursorPos.x() > (this->contentsRect().right() - 32)) - left_x = this->contentsRect().right() - 32; - else - left_x = balloonCursorPos.x(); - - int left_y; - if (balloonCursorPos.y() < 32) - left_y = 0; - else if (balloonCursorPos.y() > (this->contentsRect().bottom() - 32)) - left_y = this->contentsRect().bottom() - 32; - else - left_y = balloonCursorPos.y(); - - /* When cursor leave the page, display balloonCursor where it left */ - balloonCursor->setGeometry(left_x ,left_y, 32, 32); - balloonCursor->show(); - } - + m_navStyle->handleLeaveEvent(event); QGraphicsView::leaveEvent(event); } void QGVPage::mousePressEvent(QMouseEvent *event) { - if (event->button() == Qt::MiddleButton) { - panOrigin = event->pos(); - panningActive = true; - event->accept(); - - QApplication::setOverrideCursor(Qt::ClosedHandCursor); - } - + m_navStyle->handleMousePressEvent(event); QGraphicsView::mousePressEvent(event); } void QGVPage::mouseMoveEvent(QMouseEvent *event) { - balloonCursorPos = event->pos(); - - if (panningActive) { - QScrollBar *horizontalScrollbar = horizontalScrollBar(); - QScrollBar *verticalScrollbar = verticalScrollBar(); - QPoint direction = event->pos() - panOrigin; - - horizontalScrollbar->setValue(horizontalScrollbar->value() - m_reversePan*direction.x()); - verticalScrollbar->setValue(verticalScrollbar->value() - m_reverseScroll*direction.y()); - - panOrigin = event->pos(); - event->accept(); - } - + m_navStyle->handleMouseMoveEvent(event); QGraphicsView::mouseMoveEvent(event); } void QGVPage::mouseReleaseEvent(QMouseEvent *event) { - if (balloonPlacing) { - balloonCursor->hide(); - createBalloon(mapToScene(event->pos()), getDrawPage()->balloonParent); - } - - if (event->button()&Qt::MiddleButton) { - QApplication::restoreOverrideCursor(); - panningActive = false; - } - + m_navStyle->handleMouseReleaseEvent(event); QGraphicsView::mouseReleaseEvent(event); resetCursor(); } @@ -1335,4 +588,19 @@ void QGVPage::makeGrid(int gridWidth, int gridHeight, double gridStep) m_gridPath = grid; } + +std::string QGVPage::getNavStyleParameter() +{ + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath + ("User parameter:BaseApp/Preferences/View"); + std::string model = hGrp->GetASCII("NavigationStyle", NavigationStyle::getClassTypeId().getName()); + return model; +} + +Base::Type QGVPage::getStyleType(std::string model) +{ + Base::Type type = Base::Type::fromName(model.c_str()); + return type; +} + #include diff --git a/src/Mod/TechDraw/Gui/QGVPage.h b/src/Mod/TechDraw/Gui/QGVPage.h index ea0b1d3f3c..65cd5ff90f 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.h +++ b/src/Mod/TechDraw/Gui/QGVPage.h @@ -25,11 +25,13 @@ #include -#include #include #include #include +#include +#include + class QTemporaryFile; namespace App { @@ -57,6 +59,7 @@ class DrawWeldSymbol; namespace TechDrawGui { +class QGSPage; class QGIView; class QGIViewDimension; class QGITemplate; @@ -65,74 +68,52 @@ class QGIViewBalloon; class QGILeaderLine; class QGIRichAnno; class QGITile; +class QGVNavStyle; -class TechDrawGuiExport QGVPage : public QGraphicsView +class TechDrawGuiExport QGVPage : public QGraphicsView, public ParameterGrp::ObserverType { Q_OBJECT public: enum RendererType { Native, OpenGL, Image }; - QGVPage(ViewProviderPage *vp, QGraphicsScene* s, QWidget *parent = nullptr); + QGVPage(ViewProviderPage *vp, QGSPage* s, QWidget *parent = nullptr); virtual ~QGVPage(); + /// Observer message from the ParameterGrp + virtual void OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::MessageType Reason) override; + + void setRenderer(RendererType type = Native); void drawBackground(QPainter *p, const QRectF &rect) override; - QGIView * addViewDimension(TechDraw::DrawViewDimension *dim); - QGIView * addViewBalloon(TechDraw::DrawViewBalloon *balloon); - QGIView * addProjectionGroup(TechDraw::DrawProjGroup *view); - QGIView * addViewPart(TechDraw::DrawViewPart *part); - QGIView * addViewSection(TechDraw::DrawViewPart *part); - QGIView * addDrawView(TechDraw::DrawView *view); - QGIView * addDrawViewCollection(TechDraw::DrawViewCollection *view); - QGIView * addDrawViewAnnotation(TechDraw::DrawViewAnnotation *view); - QGIView * addDrawViewSymbol(TechDraw::DrawViewSymbol *view); - QGIView * addDrawViewClip(TechDraw::DrawViewClip *view); - QGIView * addDrawViewSpreadsheet(TechDraw::DrawViewSpreadsheet *view); - QGIView * addDrawViewImage(TechDraw::DrawViewImage *view); - QGIView * addViewLeader(TechDraw::DrawLeaderLine* view); - QGIView * addRichAnno(TechDraw::DrawRichAnno* anno); - QGIView * addWeldSymbol(TechDraw::DrawWeldSymbol* weld); + QGSPage* getScene() {return m_scene; }; - QGIView* findQViewForDocObj(App::DocumentObject *obj) const; - QGIView* getQGIVByName(std::string name); - 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); - - std::vector getViews() const; - - int addQView(QGIView * view); - int removeQView(QGIView *view); - int removeQViewByName(const char* name); - void removeQViewFromScene(QGIView *view); - - void setPageTemplate(TechDraw::DrawTemplate *pageTemplate); - - QGITemplate * getTemplate() const; - void removeTemplate(); - TechDraw::DrawPage * getDrawPage(); void setExporting(bool enable); - virtual void refreshViews(void); - /// Renders the page to SVG with filename. - void saveSvg(QString filename); - void postProcessXml(QTemporaryFile& tempFile, QString filename, QString pagename); +// void saveSvg(QString filename); +// void postProcessXml(QTemporaryFile& tempFile, QString filename, QString pagename); void makeGrid(int width, int height, double step); void showGrid(bool state) {m_showGrid = state;} void updateViewport(void) {viewport()->repaint();} + bool isBalloonPlacing() {return balloonPlacing; }; + void setBalloonPlacing(bool s) {balloonPlacing = s;}; + + QLabel* getBalloonCursor() {return balloonCursor;}; + void setBalloonCursor(QLabel* l) {balloonCursor = l;}; + + void kbPanScroll(int xMove = 1, int yMove = 1); + QPointF getBalloonCursorPos() {return balloonCursorPos;}; + void setBalloonCursorPos(QPoint p) { balloonCursorPos = p;}; + public Q_SLOTS: void setHighQualityAntialiasing(bool highQualityAntialiasing); @@ -146,14 +127,12 @@ protected: void mouseReleaseEvent(QMouseEvent *event) override; void focusOutEvent(QFocusEvent *event) override; void keyPressEvent(QKeyEvent *event) override; - void kbPanScroll(int xMove = 1, int yMove = 1); + void keyReleaseEvent(QKeyEvent *event) override; + virtual void contextMenuEvent(QContextMenuEvent *event) override; static QColor SelectColor; static QColor PreselectColor; QColor getBackgroundColor(); - - - QGITemplate *pageTemplate; double getDevicePixelRatio() const; QPixmap prepareCursorPixmap(const char *iconName, QPoint &hotspot); @@ -161,6 +140,12 @@ protected: void activateCursor(QCursor cursor); void resetCursor(); virtual void drawForeground(QPainter *painter, const QRectF &rect) override; + + std::string getNavStyleParameter(); + Base::Type getStyleType(std::string model); + + void initNavigationStyle(); + void setNavigationStyle(std::string navParm); private: RendererType m_renderer; @@ -176,6 +161,7 @@ private: int m_reversePan; int m_reverseScroll; + QGSPage* m_scene; bool balloonPlacing; QLabel *balloonCursor; QPoint balloonCursorPos; @@ -186,6 +172,12 @@ private: bool m_showGrid; QPainterPath m_gridPath; + + QGVNavStyle* m_navStyle; + + /// handle to the viewer parameter group + ParameterGrp::handle hGrp; + }; } // namespace diff --git a/src/Mod/TechDraw/Gui/TaskActiveView.h b/src/Mod/TechDraw/Gui/TaskActiveView.h index 09c3c77fa0..ce98255493 100644 --- a/src/Mod/TechDraw/Gui/TaskActiveView.h +++ b/src/Mod/TechDraw/Gui/TaskActiveView.h @@ -39,6 +39,7 @@ class DrawViewSymbol; namespace TechDrawGui { +class QGSPage; class QGVPage; class QGIView; class MDIViewPage; diff --git a/src/Mod/TechDraw/Gui/TaskCenterLine.h b/src/Mod/TechDraw/Gui/TaskCenterLine.h index b352713839..d32695479b 100644 --- a/src/Mod/TechDraw/Gui/TaskCenterLine.h +++ b/src/Mod/TechDraw/Gui/TaskCenterLine.h @@ -47,6 +47,7 @@ class LineFormat; namespace TechDrawGui { +class QGSPage; class QGVPage; class QGIView; class QGIPrimPath; diff --git a/src/Mod/TechDraw/Gui/TaskCosVertex.cpp b/src/Mod/TechDraw/Gui/TaskCosVertex.cpp index d8620fa232..955f6e3c16 100644 --- a/src/Mod/TechDraw/Gui/TaskCosVertex.cpp +++ b/src/Mod/TechDraw/Gui/TaskCosVertex.cpp @@ -53,6 +53,7 @@ #include +#include "QGSPage.h" #include "QGVPage.h" #include "QGIView.h" #include "QGIPrimPath.h" @@ -95,7 +96,7 @@ TaskCosVertex::TaskCosVertex(TechDraw::DrawViewPart* baseFeat, Gui::ViewProvider* vp = activeGui->getViewProvider(m_basePage); ViewProviderPage* vpp = static_cast(vp); m_mdi = vpp->getMDIViewPage(); - m_scene = m_mdi->m_scene; + m_scene = m_mdi->getQGSPage(); m_view = m_mdi->getQGVPage(); setUiPrimary(); @@ -285,7 +286,7 @@ void TaskCosVertex::removeTracker(void) void TaskCosVertex::setEditCursor(QCursor c) { if (m_baseFeat != nullptr) { - QGIView* qgivBase = m_view->findQViewForDocObj(m_baseFeat); + QGIView* qgivBase = m_scene->findQViewForDocObj(m_baseFeat); qgivBase->setCursor(c); } } diff --git a/src/Mod/TechDraw/Gui/TaskCosVertex.h b/src/Mod/TechDraw/Gui/TaskCosVertex.h index ee085dac75..0e0116837a 100644 --- a/src/Mod/TechDraw/Gui/TaskCosVertex.h +++ b/src/Mod/TechDraw/Gui/TaskCosVertex.h @@ -39,11 +39,13 @@ namespace TechDraw { class DrawPage; class DrawView; +class DrawViewPart; class DrawCosVertex; } namespace TechDrawGui { +class QGSPage; class QGVPage; class QGIView; class QGIPrimPath; @@ -98,7 +100,7 @@ private: QGTracker* m_tracker; MDIViewPage* m_mdi; - QGraphicsScene* m_scene; + QGSPage* m_scene; QGVPage* m_view; TechDraw::DrawViewPart* m_baseFeat; TechDraw::DrawPage* m_basePage; diff --git a/src/Mod/TechDraw/Gui/TaskCosmeticLine.h b/src/Mod/TechDraw/Gui/TaskCosmeticLine.h index 12995b702d..f188523459 100644 --- a/src/Mod/TechDraw/Gui/TaskCosmeticLine.h +++ b/src/Mod/TechDraw/Gui/TaskCosmeticLine.h @@ -40,6 +40,7 @@ class LineFormat; namespace TechDrawGui { +class QGSPage; class QGVPage; class QGIView; class QGIPrimPath; diff --git a/src/Mod/TechDraw/Gui/TaskCustomizeFormat.h b/src/Mod/TechDraw/Gui/TaskCustomizeFormat.h index 2a933031a3..96ba6e3479 100644 --- a/src/Mod/TechDraw/Gui/TaskCustomizeFormat.h +++ b/src/Mod/TechDraw/Gui/TaskCustomizeFormat.h @@ -47,6 +47,7 @@ class Face; namespace TechDrawGui { +class QGSPage; class QGVPage; class QGIView; class QGIPrimPath; diff --git a/src/Mod/TechDraw/Gui/TaskDetail.cpp b/src/Mod/TechDraw/Gui/TaskDetail.cpp index 78fe93ea76..e6b6a23cb4 100644 --- a/src/Mod/TechDraw/Gui/TaskDetail.cpp +++ b/src/Mod/TechDraw/Gui/TaskDetail.cpp @@ -54,6 +54,7 @@ #include +#include "QGSPage.h" #include "QGVPage.h" #include "QGIView.h" #include "QGIPrimPath.h" @@ -116,7 +117,7 @@ TaskDetail::TaskDetail(TechDraw::DrawViewPart* baseFeat): Gui::ViewProvider* vp = activeGui->getViewProvider(m_basePage); ViewProviderPage* vpp = static_cast(vp); m_mdi = vpp->getMDIViewPage(); - m_scene = m_mdi->m_scene; + m_scene = m_mdi->getQGSPage(); m_view = m_mdi->getQGVPage(); createDetail(); @@ -202,7 +203,7 @@ TaskDetail::TaskDetail(TechDraw::DrawViewDetail* detailFeat): Gui::ViewProvider* vp = activeGui->getViewProvider(m_basePage); ViewProviderPage* vpp = static_cast(vp); m_mdi = vpp->getMDIViewPage(); - m_scene = m_mdi->m_scene; + m_scene = m_mdi->getQGSPage(); m_view = m_mdi->getQGVPage(); saveDetailState(); diff --git a/src/Mod/TechDraw/Gui/TaskDetail.h b/src/Mod/TechDraw/Gui/TaskDetail.h index 88ed8c1a12..2cc1d43d84 100644 --- a/src/Mod/TechDraw/Gui/TaskDetail.h +++ b/src/Mod/TechDraw/Gui/TaskDetail.h @@ -44,6 +44,7 @@ class DrawViewPart; namespace TechDrawGui { +class QGSPage; class QGVPage; class QGIView; class QGIPrimPath; @@ -109,7 +110,7 @@ private: QGIGhostHighlight* m_ghost; MDIViewPage* m_mdi; - QGraphicsScene* m_scene; + QGSPage* m_scene; QGVPage* m_view; TechDraw::DrawViewDetail* m_detailFeat; TechDraw::DrawViewPart* m_baseFeat; diff --git a/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp b/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp index e8bbedc83f..b914c901c4 100644 --- a/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp +++ b/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp @@ -54,6 +54,7 @@ #include "DrawGuiUtil.h" #include "PreferencesGui.h" +#include "QGSPage.h" #include "QGVPage.h" #include "QGIView.h" #include "QGIPrimPath.h" @@ -121,10 +122,10 @@ TaskLeaderLine::TaskLeaderLine(TechDrawGui::ViewProviderLeader* leadVP) : m_haveMdi = true; m_mdi = vpp->getMDIViewPage(); if (m_mdi != nullptr) { - m_scene = m_mdi->m_scene; + m_scene = m_mdi->getQGSPage(); m_view = m_mdi->getQGVPage(); if (m_baseFeat != nullptr) { - m_qgParent = m_view->findQViewForDocObj(m_baseFeat); + m_qgParent = m_scene->findQViewForDocObj(m_baseFeat); } } else { m_haveMdi = false; @@ -197,10 +198,10 @@ TaskLeaderLine::TaskLeaderLine(TechDraw::DrawView* baseFeat, m_haveMdi = true; m_mdi = vpp->getMDIViewPage(); if (m_mdi != nullptr) { - m_scene = m_mdi->m_scene; + m_scene = m_mdi->getQGSPage(); m_view = m_mdi->getQGVPage(); if (baseFeat != nullptr) { - m_qgParent = m_view->findQViewForDocObj(baseFeat); + m_qgParent = m_scene->findQViewForDocObj(baseFeat); } } else { m_haveMdi = false; @@ -558,8 +559,8 @@ void TaskLeaderLine::onTrackerClicked(bool b) m_inProgressLock = true; m_saveContextPolicy = m_mdi->contextMenuPolicy(); m_mdi->setContextMenuPolicy(Qt::PreventContextMenu); - QGVPage* qgvp = m_mdi->getQGVPage(); - QGIView* qgiv = qgvp->findQViewForDocObj(m_lineFeat); + QGSPage* qgsp = m_mdi->getQGSPage(); + QGIView* qgiv = qgsp->findQViewForDocObj(m_lineFeat); QGILeaderLine* qgLead = dynamic_cast(qgiv); if (qgLead == nullptr) { @@ -712,7 +713,7 @@ void TaskLeaderLine::setEditCursor(QCursor c) return; } if (m_baseFeat != nullptr) { - QGIView* qgivBase = m_view->findQViewForDocObj(m_baseFeat); + QGIView* qgivBase = m_scene->findQViewForDocObj(m_baseFeat); qgivBase->setCursor(c); } } diff --git a/src/Mod/TechDraw/Gui/TaskLeaderLine.h b/src/Mod/TechDraw/Gui/TaskLeaderLine.h index 7a2f047922..8e6694ae75 100644 --- a/src/Mod/TechDraw/Gui/TaskLeaderLine.h +++ b/src/Mod/TechDraw/Gui/TaskLeaderLine.h @@ -29,7 +29,6 @@ #include "QGTracker.h" - //TODO: make this a proper enum #define TRACKERPICK 0 #define TRACKEREDIT 1 @@ -47,6 +46,7 @@ class DrawLeaderLine; namespace TechDrawGui { +class QGSPage; class QGVPage; class QGIView; class QGIPrimPath; @@ -129,7 +129,7 @@ private: QGTracker* m_tracker; MDIViewPage* m_mdi; - QGraphicsScene* m_scene; + QGSPage* m_scene; QGVPage* m_view; ViewProviderLeader* m_lineVP; TechDraw::DrawView* m_baseFeat; diff --git a/src/Mod/TechDraw/Gui/TaskRichAnno.cpp b/src/Mod/TechDraw/Gui/TaskRichAnno.cpp index d3207e31e2..974f6c9dd7 100644 --- a/src/Mod/TechDraw/Gui/TaskRichAnno.cpp +++ b/src/Mod/TechDraw/Gui/TaskRichAnno.cpp @@ -54,6 +54,7 @@ #include #include "PreferencesGui.h" +#include "QGSPage.h" #include "QGVPage.h" #include "QGIView.h" #include "QGIPrimPath.h" @@ -120,9 +121,9 @@ TaskRichAnno::TaskRichAnno(TechDrawGui::ViewProviderRichAnno* annoVP) : m_qgParent = nullptr; m_haveMdi = true; if (m_mdi != nullptr) { - m_view = m_mdi->getQGVPage(); + m_scene = m_mdi->getQGSPage(); if (m_baseFeat != nullptr) { - m_qgParent = m_view->findQViewForDocObj(m_baseFeat); + m_qgParent = m_scene->findQViewForDocObj(m_baseFeat); } } else { m_haveMdi = false; @@ -175,8 +176,8 @@ TaskRichAnno::TaskRichAnno(TechDraw::DrawView* baseFeat, m_haveMdi = true; m_mdi = dvp->getMDIViewPage(); if (m_mdi != nullptr) { - m_view = m_mdi->getQGVPage(); - m_qgParent = m_view->findQViewForDocObj(baseFeat); + m_scene= m_mdi->getQGSPage(); + m_qgParent = m_scene->findQViewForDocObj(baseFeat); } else { m_haveMdi = false; } diff --git a/src/Mod/TechDraw/Gui/TaskRichAnno.h b/src/Mod/TechDraw/Gui/TaskRichAnno.h index e08fdb2f24..2936ff0ab5 100644 --- a/src/Mod/TechDraw/Gui/TaskRichAnno.h +++ b/src/Mod/TechDraw/Gui/TaskRichAnno.h @@ -41,6 +41,7 @@ class DrawRichAnno; namespace TechDrawGui { +class QGSPage; class QGVPage; class QGIView; class QGIPrimPath; @@ -101,6 +102,7 @@ private: bool blockUpdate; MDIViewPage* m_mdi; + QGSPage* m_scene; QGVPage* m_view; ViewProviderRichAnno* m_annoVP; TechDraw::DrawView* m_baseFeat; diff --git a/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.h b/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.h index 845222add3..54e23c5f6d 100644 --- a/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.h +++ b/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.h @@ -59,6 +59,7 @@ class Face; namespace TechDrawGui { +class QGSPage; class QGVPage; class QGIView; class QGIPrimPath; diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h index 679209183b..7aa9c82c89 100644 --- a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h @@ -50,6 +50,7 @@ class Face; namespace TechDrawGui { +class QGSPage; class QGVPage; class QGIView; class QGILeaderLine; diff --git a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp index d692b424a4..e858cb1180 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp @@ -39,6 +39,7 @@ #include "ViewProviderDrawingView.h" #include "MDIViewPage.h" #include "QGIView.h" +#include "QGSPage.h" #include "QGVPage.h" #include "ViewProviderPage.h" @@ -171,9 +172,9 @@ QGIView* ViewProviderDrawingView::getQView(void) ViewProviderPage* dvp = dynamic_cast(vp); if (dvp) { if (dvp->getMDIViewPage()) { - if (dvp->getMDIViewPage()->getQGVPage()) { + if (dvp->getMDIViewPage()->getQGSPage()) { qView = dynamic_cast(dvp->getMDIViewPage()-> - getQGVPage()->findQViewForDocObj(getViewObject())); + getQGSPage()->findQViewForDocObj(getViewObject())); } } } @@ -266,9 +267,9 @@ void ViewProviderDrawingView::onGuiRepaint(const TechDraw::DrawView* dv) ViewProviderPage* vpPage = dynamic_cast(vp); if (vpPage != nullptr) { if (vpPage->getMDIViewPage() != nullptr) { - if (vpPage->getMDIViewPage()->getQGVPage()) { + if (vpPage->getMDIViewPage()->getQGSPage()) { QGIView* qView = dynamic_cast(vpPage->getMDIViewPage()-> - getQGVPage()->findQViewForDocObj(v)); + getQGSPage()->findQViewForDocObj(v)); if (qView != nullptr) { qView->updateView(true); } diff --git a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp index 622f034def..d76dfe7ab0 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp @@ -57,6 +57,7 @@ #include "MDIViewPage.h" #include "PreferencesGui.h" #include "QGITemplate.h" +#include "QGSPage.h" #include "QGVPage.h" #include "ViewProviderTemplate.h" #include "ViewProviderPage.h" @@ -79,7 +80,8 @@ ViewProviderPage::ViewProviderPage() : m_mdiView(nullptr), m_docReady(true), m_pageName(""), - m_graphicsView(nullptr) + m_graphicsView(nullptr), + m_graphicsScene(nullptr) { sPixmap = "TechDraw_TreePage"; static const char *group = "Grid"; @@ -432,9 +434,9 @@ void ViewProviderPage::setFrameState(bool state) void ViewProviderPage::toggleFrameState(void) { // Base::Console().Message("VPP::toggleFrameState()\n"); - if (m_graphicsView != nullptr) { + if (m_graphicsScene != nullptr) { setFrameState(!getFrameState()); - m_graphicsView->refreshViews(); + m_graphicsScene->refreshViews(); setTemplateMarkers(getFrameState()); } } @@ -461,6 +463,11 @@ void ViewProviderPage::setGraphicsView(QGVPage* gv) m_graphicsView = gv; } +void ViewProviderPage::setGraphicsScene(QGSPage* gs) +{ + m_graphicsScene = gs; +} + bool ViewProviderPage::canDelete(App::DocumentObject *obj) const { // deletions from a page don't necessarily destroy anything diff --git a/src/Mod/TechDraw/Gui/ViewProviderPage.h b/src/Mod/TechDraw/Gui/ViewProviderPage.h index 3cf768be23..5c6e4cef7d 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderPage.h +++ b/src/Mod/TechDraw/Gui/ViewProviderPage.h @@ -41,6 +41,7 @@ namespace TechDrawGui { class MDIViewPage; class QGVPage; +class QGSPage; class TechDrawGuiExport ViewProviderPage : public Gui::ViewProviderDocumentObject { @@ -97,7 +98,9 @@ public: void toggleFrameState(void); void setTemplateMarkers(bool state); QGVPage *getGraphicsView() { return m_graphicsView; } + QGSPage* getGraphicsScene() { return m_graphicsScene; } void setGraphicsView(QGVPage* gv); + void setGraphicsScene(QGSPage* gs); virtual bool canDelete(App::DocumentObject* obj) const override; void setGrid(void); @@ -109,6 +112,7 @@ private: bool m_docReady; std::string m_pageName; QGVPage* m_graphicsView; + QGSPage* m_graphicsScene; }; } // namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/ViewProviderTemplate.cpp b/src/Mod/TechDraw/Gui/ViewProviderTemplate.cpp index c4ba364658..a19045c22d 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderTemplate.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderTemplate.cpp @@ -43,6 +43,7 @@ #include "QGITemplate.h" #include "QGISVGTemplate.h" #include "QGVPage.h" +#include "QGSPage.h" #include "MDIViewPage.h" #include "TemplateTextField.h" #include "ViewProviderPage.h" @@ -94,6 +95,7 @@ void ViewProviderTemplate::updateData(const App::Property* prop) if (mdi != nullptr) { mdi->attachTemplate(t); mdi->viewAll(); + mdi->getViewProviderPage()->setGrid(); } } } @@ -151,7 +153,7 @@ QGITemplate* ViewProviderTemplate::getQTemplate(void) if (dt) { MDIViewPage* mdi = getMDIViewPage(); if (mdi != nullptr) { - result = mdi->getQGVPage()->getTemplate(); + result = mdi->getQGSPage()->getTemplate(); } } return result;