From 6c699887c02268c697a580aceaf0687d4dc53df0 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Wed, 1 May 2019 08:49:09 -0400 Subject: [PATCH] Leader and RichText block improvements --- src/Mod/TechDraw/App/AppTechDraw.cpp | 6 +- src/Mod/TechDraw/App/CMakeLists.txt | 10 +- src/Mod/TechDraw/App/DrawLeaderLine.cpp | 43 +- src/Mod/TechDraw/App/DrawLeaderLine.h | 6 + .../{DrawTextLeader.cpp => DrawRichAnno.cpp} | 63 +- .../App/{DrawTextLeader.h => DrawRichAnno.h} | 27 +- ...rawTextLeaderPy.xml => DrawRichAnnoPy.xml} | 14 +- ...tLeaderPyImp.cpp => DrawRichAnnoPyImp.cpp} | 16 +- src/Mod/TechDraw/Gui/AppTechDrawGui.cpp | 3 +- src/Mod/TechDraw/Gui/CMakeLists.txt | 26 +- src/Mod/TechDraw/Gui/CommandDecorate.cpp | 55 +- src/Mod/TechDraw/Gui/MDIViewPage.cpp | 70 ++- src/Mod/TechDraw/Gui/MDIViewPage.h | 1 + src/Mod/TechDraw/Gui/QGCustomText.h | 6 +- src/Mod/TechDraw/Gui/QGEPath.cpp | 47 +- src/Mod/TechDraw/Gui/QGEPath.h | 4 + src/Mod/TechDraw/Gui/QGILeaderLine.cpp | 94 ++- src/Mod/TechDraw/Gui/QGILeaderLine.h | 5 + src/Mod/TechDraw/Gui/QGIPrimPath.cpp | 7 +- .../{QGITextLeader.cpp => QGIRichAnno.cpp} | 153 +++-- .../Gui/{QGITextLeader.h => QGIRichAnno.h} | 27 +- src/Mod/TechDraw/Gui/QGIUserTypes.h | 2 +- src/Mod/TechDraw/Gui/QGIView.cpp | 4 - src/Mod/TechDraw/Gui/QGMText.cpp | 23 +- src/Mod/TechDraw/Gui/QGMText.h | 6 + src/Mod/TechDraw/Gui/QGTracker.cpp | 38 +- src/Mod/TechDraw/Gui/QGTracker.h | 2 + src/Mod/TechDraw/Gui/QGVPage.cpp | 85 ++- src/Mod/TechDraw/Gui/QGVPage.h | 8 +- ...{TaskTextLeader.cpp => TaskLeaderLine.cpp} | 301 +++------- .../{TaskTextLeader.h => TaskLeaderLine.h} | 53 +- .../{TaskTextLeader.ui => TaskLeaderLine.ui} | 53 +- src/Mod/TechDraw/Gui/TaskRichAnno.cpp | 560 ++++++++++++++++++ src/Mod/TechDraw/Gui/TaskRichAnno.h | 170 ++++++ src/Mod/TechDraw/Gui/TaskRichAnno.ui | 156 +++++ .../TechDraw/Gui/ViewProviderDrawingView.cpp | 3 +- src/Mod/TechDraw/Gui/ViewProviderLeader.cpp | 131 +--- src/Mod/TechDraw/Gui/ViewProviderLeader.h | 35 +- src/Mod/TechDraw/Gui/ViewProviderPage.cpp | 15 +- src/Mod/TechDraw/Gui/ViewProviderRichAnno.cpp | 174 ++++++ src/Mod/TechDraw/Gui/ViewProviderRichAnno.h | 78 +++ src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp | 4 + src/Mod/TechDraw/Gui/Workbench.cpp | 6 +- src/Mod/TechDraw/Gui/mrichtextedit.cpp | 2 + src/Mod/TechDraw/Gui/mrichtextedit.h | 1 + 45 files changed, 1910 insertions(+), 683 deletions(-) rename src/Mod/TechDraw/App/{DrawTextLeader.cpp => DrawRichAnno.cpp} (56%) rename src/Mod/TechDraw/App/{DrawTextLeader.h => DrawRichAnno.h} (74%) rename src/Mod/TechDraw/App/{DrawTextLeaderPy.xml => DrawRichAnnoPy.xml} (57%) rename src/Mod/TechDraw/App/{DrawTextLeaderPyImp.cpp => DrawRichAnnoPyImp.cpp} (80%) rename src/Mod/TechDraw/Gui/{QGITextLeader.cpp => QGIRichAnno.cpp} (64%) rename src/Mod/TechDraw/Gui/{QGITextLeader.h => QGIRichAnno.h} (83%) rename src/Mod/TechDraw/Gui/{TaskTextLeader.cpp => TaskLeaderLine.cpp} (68%) rename src/Mod/TechDraw/Gui/{TaskTextLeader.h => TaskLeaderLine.h} (82%) rename src/Mod/TechDraw/Gui/{TaskTextLeader.ui => TaskLeaderLine.ui} (90%) create mode 100644 src/Mod/TechDraw/Gui/TaskRichAnno.cpp create mode 100644 src/Mod/TechDraw/Gui/TaskRichAnno.h create mode 100644 src/Mod/TechDraw/Gui/TaskRichAnno.ui create mode 100644 src/Mod/TechDraw/Gui/ViewProviderRichAnno.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderRichAnno.h diff --git a/src/Mod/TechDraw/App/AppTechDraw.cpp b/src/Mod/TechDraw/App/AppTechDraw.cpp index 21060efd9030..761731a5a9d6 100644 --- a/src/Mod/TechDraw/App/AppTechDraw.cpp +++ b/src/Mod/TechDraw/App/AppTechDraw.cpp @@ -41,7 +41,7 @@ #include "DrawViewDetail.h" #include "DrawViewBalloon.h" #include "DrawLeaderLine.h" -#include "DrawTextLeader.h" +#include "DrawRichAnno.h" namespace TechDraw { extern PyObject* initModule(); @@ -83,7 +83,7 @@ PyMOD_INIT_FUNC(TechDraw) TechDraw::DrawViewDetail ::init(); TechDraw::DrawViewBalloon ::init(); TechDraw::DrawLeaderLine ::init(); - TechDraw::DrawTextLeader ::init(); + TechDraw::DrawRichAnno ::init(); TechDraw::DrawTemplate ::init(); TechDraw::DrawParametricTemplate::init(); @@ -103,6 +103,6 @@ PyMOD_INIT_FUNC(TechDraw) TechDraw::DrawTemplatePython ::init(); TechDraw::DrawViewSymbolPython::init(); TechDraw::DrawLeaderLinePython::init(); - TechDraw::DrawTextLeaderPython::init(); + TechDraw::DrawRichAnnoPython::init(); PyMOD_Return(mod); } diff --git a/src/Mod/TechDraw/App/CMakeLists.txt b/src/Mod/TechDraw/App/CMakeLists.txt index 1670d9ea8923..61f8659a0f45 100644 --- a/src/Mod/TechDraw/App/CMakeLists.txt +++ b/src/Mod/TechDraw/App/CMakeLists.txt @@ -45,7 +45,7 @@ generate_from_xml(DrawProjGroupPy) generate_from_xml(DrawProjGroupItemPy) generate_from_xml(DrawViewAnnotationPy) generate_from_xml(DrawLeaderLinePy) -generate_from_xml(DrawTextLeaderPy) +generate_from_xml(DrawRichAnnoPy) SET(Draw_SRCS @@ -97,8 +97,8 @@ SET(Draw_SRCS DrawViewDetail.h DrawLeaderLine.cpp DrawLeaderLine.h - DrawTextLeader.cpp - DrawTextLeader.h + DrawRichAnno.cpp + DrawRichAnno.h ) SET(TechDraw_SRCS @@ -158,8 +158,8 @@ SET(Python_SRCS DrawViewAnnotationPyImp.cpp DrawLeaderLinePy.xml DrawLeaderLinePyImp.cpp - DrawTextLeaderPy.xml - DrawTextLeaderPyImp.cpp + DrawRichAnnoPy.xml + DrawRichAnnoPyImp.cpp ) SOURCE_GROUP("Mod" FILES ${TechDraw_SRCS}) diff --git a/src/Mod/TechDraw/App/DrawLeaderLine.cpp b/src/Mod/TechDraw/App/DrawLeaderLine.cpp index 1adc9f623886..8f530bf577fe 100644 --- a/src/Mod/TechDraw/App/DrawLeaderLine.cpp +++ b/src/Mod/TechDraw/App/DrawLeaderLine.cpp @@ -57,6 +57,7 @@ DrawLeaderLine::DrawLeaderLine(void) ADD_PROPERTY_TYPE(StartSymbol, (-1), group, App::Prop_None, "Symbol (arrowhead) for start of line"); ADD_PROPERTY_TYPE(EndSymbol, (-1), group, App::Prop_None, "Symbol (arrowhead) for end of line"); ADD_PROPERTY_TYPE(Scalable ,(false),group,App::Prop_None,"Scale line with LeaderParent"); + ADD_PROPERTY_TYPE(AutoHorizontal ,(getDefAuto()),group,App::Prop_None,"Forces last line segment horizontal"); //hide the DrawView properties that don't apply to Leader ScaleType.setStatus(App::Property::ReadOnly,true); @@ -76,11 +77,9 @@ DrawLeaderLine::~DrawLeaderLine() void DrawLeaderLine::onChanged(const App::Property* prop) { - if (!isRestoring()) { - //nothing in particular - } +// if (!isRestoring()) { +// } DrawView::onChanged(prop); - } short DrawLeaderLine::mustExecute() const @@ -113,6 +112,15 @@ App::DocumentObjectExecReturn *DrawLeaderLine::execute(void) return DrawView::execute(); } +//this doesn't really work because LeaderParent is not available? +void DrawLeaderLine::onDocumentRestored(void) +{ +// Base::Console().Message("DLL::onDocumentRestored()\n"); + requestPaint(); + DrawView::onDocumentRestored(); +} + + DrawView* DrawLeaderLine::getBaseView(void) const { DrawView* result = nullptr; @@ -168,6 +176,33 @@ Base::Vector3d DrawLeaderLine::getAttachPoint(void) return result; } +void DrawLeaderLine::adjustLastSegment(void) +{ +// Base::Console().Message("DLL::adjustLastSegment()\n"); + bool adjust = AutoHorizontal.getValue(); + std::vector wp = WayPoints.getValues(); + if (adjust) { + if (wp.size() > 1) { + int iLast = wp.size() - 1; + int iPen = wp.size() - 2; + Base::Vector3d last = wp.at(iLast); + Base::Vector3d penUlt = wp.at(iPen); + last.y = penUlt.y; + wp.at(iLast) = last; + } + } + WayPoints.setValues(wp); +} + +bool DrawLeaderLine::getDefAuto(void) const +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> + GetGroup("Preferences")->GetGroup("Mod/TechDraw/LeaderLines"); + bool result = hGrp->GetBool("AutoHorizontal",true); + return result; +} + + PyObject *DrawLeaderLine::getPyObject(void) { if (PythonObject.is(Py::_None())) { diff --git a/src/Mod/TechDraw/App/DrawLeaderLine.h b/src/Mod/TechDraw/App/DrawLeaderLine.h index b75549426762..20d97671a791 100644 --- a/src/Mod/TechDraw/App/DrawLeaderLine.h +++ b/src/Mod/TechDraw/App/DrawLeaderLine.h @@ -47,9 +47,12 @@ class TechDrawExport DrawLeaderLine : public TechDraw::DrawView App::PropertyInteger StartSymbol; App::PropertyInteger EndSymbol; App::PropertyBool Scalable; + App::PropertyBool AutoHorizontal; virtual short mustExecute() const; virtual App::DocumentObjectExecReturn *execute(void); + virtual void onDocumentRestored(void) override; + virtual const char* getViewProviderName(void) const { return "TechDrawGui::ViewProviderLeader"; @@ -62,6 +65,9 @@ class TechDrawExport DrawLeaderLine : public TechDraw::DrawView virtual App::DocumentObject* getBaseObject(void) const; bool keepUpdated(void); double getScale(void); + void adjustLastSegment(void); + bool getDefAuto(void) const; + protected: virtual void onChanged(const App::Property* prop); diff --git a/src/Mod/TechDraw/App/DrawTextLeader.cpp b/src/Mod/TechDraw/App/DrawRichAnno.cpp similarity index 56% rename from src/Mod/TechDraw/App/DrawTextLeader.cpp rename to src/Mod/TechDraw/App/DrawRichAnno.cpp index 6e19d10ac854..8799f74ed068 100644 --- a/src/Mod/TechDraw/App/DrawTextLeader.cpp +++ b/src/Mod/TechDraw/App/DrawRichAnno.cpp @@ -32,31 +32,35 @@ #include "DrawUtil.h" -#include // generated from DrawTextLeaderPy.xml -#include "DrawTextLeader.h" +#include // generated from DrawRichAnnoPy.xml +#include "DrawRichAnno.h" using namespace TechDraw; //=========================================================================== -// DrawTextLeader - DrawLeaderLine + movable text block +// DrawRichAnno - movable rich text block //=========================================================================== -PROPERTY_SOURCE(TechDraw::DrawTextLeader, TechDraw::DrawLeaderLine) +PROPERTY_SOURCE(TechDraw::DrawRichAnno, TechDraw::DrawView) -DrawTextLeader::DrawTextLeader(void) +DrawRichAnno::DrawRichAnno(void) { - static const char *group = "Text Leader"; - - ADD_PROPERTY_TYPE(LeaderText, (""), group, App::Prop_None, "Leader text"); - Base::Vector3d pos(0.0,0.0,0.0); - ADD_PROPERTY_TYPE(TextPosition, (pos), group, App::Prop_None, "Text position relative to parent"); + static const char *group = "Text Block"; + + ADD_PROPERTY_TYPE(AnnoParent,(0),group,(App::PropertyType)(App::Prop_None), + "Object to which this annontation is attached"); + ADD_PROPERTY_TYPE(AnnoText, (""), group, App::Prop_None, "Anno text"); +// Base::Vector3d pos(0.0,0.0,0.0); +// ADD_PROPERTY_TYPE(TextPosition, (pos), group, App::Prop_None, "Anno position relative to parent"); + ADD_PROPERTY_TYPE(ShowFrame, (true), group, App::Prop_None, "Outline rectangle on/off"); + ADD_PROPERTY_TYPE(MaxWidth, (-1.0), group, App::Prop_None, "Width limit before auto wrap"); } -DrawTextLeader::~DrawTextLeader() +DrawRichAnno::~DrawRichAnno() { } -void DrawTextLeader::onChanged(const App::Property* prop) +void DrawRichAnno::onChanged(const App::Property* prop) { if (!isRestoring()) { //nothing in particular @@ -65,11 +69,11 @@ void DrawTextLeader::onChanged(const App::Property* prop) } -short DrawTextLeader::mustExecute() const +short DrawRichAnno::mustExecute() const { bool result = 0; if (!isRestoring()) { - result = (LeaderText.isTouched()); + result = (AnnoText.isTouched()); } if (result) { return result; @@ -78,20 +82,35 @@ short DrawTextLeader::mustExecute() const return DrawView::mustExecute(); } -App::DocumentObjectExecReturn *DrawTextLeader::execute(void) +App::DocumentObjectExecReturn *DrawRichAnno::execute(void) { -// Base::Console().Message("DTL::execute()\n"); +// Base::Console().Message("DRA::execute()\n"); if (!keepUpdated()) { return App::DocumentObject::StdReturn; } return DrawView::execute(); } -PyObject *DrawTextLeader::getPyObject(void) +DrawView* DrawRichAnno::getBaseView(void) const +{ +// Base::Console().Message("DRA::getBaseView() - %s\n", getNameInDocument()); + DrawView* result = nullptr; + App::DocumentObject* baseObj = AnnoParent.getValue(); + if (baseObj != nullptr) { + DrawView* cast = dynamic_cast(baseObj); + if (cast != nullptr) { + result = cast; + } + } + return result; +} + + +PyObject *DrawRichAnno::getPyObject(void) { if (PythonObject.is(Py::_None())) { // ref counter is set to 1 - PythonObject = Py::Object(new DrawTextLeaderPy(this),true); + PythonObject = Py::Object(new DrawRichAnnoPy(this),true); } return Py::new_reference_to(PythonObject); } @@ -100,13 +119,13 @@ PyObject *DrawTextLeader::getPyObject(void) namespace App { /// @cond DOXERR -PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawTextLeaderPython, TechDraw::DrawTextLeader) -template<> const char* TechDraw::DrawTextLeaderPython::getViewProviderName(void) const { - return "TechDrawGui::ViewProviderTextLeader"; +PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawRichAnnoPython, TechDraw::DrawRichAnno) +template<> const char* TechDraw::DrawRichAnnoPython::getViewProviderName(void) const { + return "TechDrawGui::ViewProviderRichAnno"; } /// @endcond // explicit template instantiation -template class TechDrawExport FeaturePythonT; +template class TechDrawExport FeaturePythonT; } diff --git a/src/Mod/TechDraw/App/DrawTextLeader.h b/src/Mod/TechDraw/App/DrawRichAnno.h similarity index 74% rename from src/Mod/TechDraw/App/DrawTextLeader.h rename to src/Mod/TechDraw/App/DrawRichAnno.h index caa847283e47..7e59902f58df 100644 --- a/src/Mod/TechDraw/App/DrawTextLeader.h +++ b/src/Mod/TechDraw/App/DrawRichAnno.h @@ -20,37 +20,42 @@ * * ***************************************************************************/ -#ifndef _TechDraw_DrawTextLeader_h_ -#define _TechDraw_DrawTextLeader_h_ +#ifndef _TechDraw_DrawRichAnno_h_ +#define _TechDraw_DrawRichAnno_h_ # include # include -#include "DrawLeaderLine.h" +#include "DrawView.h" namespace TechDraw { -class TechDrawExport DrawTextLeader : public TechDraw::DrawLeaderLine +class TechDrawExport DrawRichAnno : public TechDraw::DrawView { - PROPERTY_HEADER(TechDraw::DrawTextLeader); + PROPERTY_HEADER(TechDraw::DrawRichAnno); public: - DrawTextLeader(); - virtual ~DrawTextLeader(); + DrawRichAnno(); + virtual ~DrawRichAnno(); - App::PropertyString LeaderText; - App::PropertyVector TextPosition; + App::PropertyLink AnnoParent; + App::PropertyString AnnoText; +// App::PropertyVector TextPosition; + App::PropertyBool ShowFrame; + App::PropertyFloat MaxWidth; + App::PropertyVector AttachPoint; virtual short mustExecute() const; virtual App::DocumentObjectExecReturn *execute(void); virtual const char* getViewProviderName(void) const { - return "TechDrawGui::ViewProviderTextLeader"; + return "TechDrawGui::ViewProviderRichAnno"; } virtual PyObject *getPyObject(void); virtual QRectF getRect() const { return QRectF(0,0,1,1);} + DrawView* getBaseView(void) const; protected: virtual void onChanged(const App::Property* prop); @@ -58,7 +63,7 @@ class TechDrawExport DrawTextLeader : public TechDraw::DrawLeaderLine private: }; -typedef App::FeaturePythonT DrawTextLeaderPython; +typedef App::FeaturePythonT DrawRichAnnoPython; } //namespace TechDraw #endif diff --git a/src/Mod/TechDraw/App/DrawTextLeaderPy.xml b/src/Mod/TechDraw/App/DrawRichAnnoPy.xml similarity index 57% rename from src/Mod/TechDraw/App/DrawTextLeaderPy.xml rename to src/Mod/TechDraw/App/DrawRichAnnoPy.xml index 43fbf1d32960..5b8111b6e8f9 100644 --- a/src/Mod/TechDraw/App/DrawTextLeaderPy.xml +++ b/src/Mod/TechDraw/App/DrawRichAnnoPy.xml @@ -1,17 +1,17 @@  - Feature for adding text leaders to Technical Drawings + Feature for adding rich annotation blocks to Technical Drawings diff --git a/src/Mod/TechDraw/App/DrawTextLeaderPyImp.cpp b/src/Mod/TechDraw/App/DrawRichAnnoPyImp.cpp similarity index 80% rename from src/Mod/TechDraw/App/DrawTextLeaderPyImp.cpp rename to src/Mod/TechDraw/App/DrawRichAnnoPyImp.cpp index c47375debab7..d50a0abbd46f 100644 --- a/src/Mod/TechDraw/App/DrawTextLeaderPyImp.cpp +++ b/src/Mod/TechDraw/App/DrawRichAnnoPyImp.cpp @@ -28,27 +28,27 @@ #include #include -#include "DrawTextLeader.h" +#include "DrawRichAnno.h" -// inclusion of the generated files (generated out of DrawTextLeaderPy.xml) +// inclusion of the generated files (generated out of DrawRichAnnoPy.xml) #include -#include -#include +#include +#include using namespace TechDraw; // returns a string which represents the object e.g. when printed in python -std::string DrawTextLeaderPy::representation(void) const +std::string DrawRichAnnoPy::representation(void) const { - return std::string(""); + return std::string(""); } -PyObject *DrawTextLeaderPy::getCustomAttributes(const char* /*attr*/) const +PyObject *DrawRichAnnoPy::getCustomAttributes(const char* /*attr*/) const { return 0; } -int DrawTextLeaderPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +int DrawRichAnnoPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) { return 0; } diff --git a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp index dea779abdb69..7d49d667f1b3 100644 --- a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp +++ b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp @@ -56,6 +56,7 @@ #include "ViewProviderGeomHatch.h" #include "ViewProviderSpreadsheet.h" #include "ViewProviderImage.h" +#include "ViewProviderRichAnno.h" #include "ViewProviderLeader.h" @@ -130,7 +131,7 @@ PyMOD_INIT_FUNC(TechDrawGui) TechDrawGui::ViewProviderSpreadsheet::init(); TechDrawGui::ViewProviderImage::init(); TechDrawGui::ViewProviderLeader::init(); - TechDrawGui::ViewProviderTextLeader::init(); + TechDrawGui::ViewProviderRichAnno::init(); // register preferences pages new Gui::PrefPageProducer ("TechDraw"); diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index f97834d91408..40c2dce92f87 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -38,11 +38,12 @@ set(TechDrawGui_MOC_HDRS DlgTemplateField.h TaskSectionView.h TaskGeomHatch.h - TaskTextLeader.h + TaskLeaderLine.h + TaskRichAnno.h QGEPath.h QGTracker.h QGILeaderLine.h - QGITextLeader.h + QGIRichAnno.h QGMText.h mrichtextedit.h mtextedit.h @@ -65,7 +66,8 @@ set(TechDrawGui_UIC_SRCS DlgTemplateField.ui TaskSectionView.ui TaskGeomHatch.ui - TaskTextLeader.ui + TaskLeaderLine.ui + TaskRichAnno.ui mrichtextedit.ui ) @@ -123,9 +125,12 @@ SET(TechDrawGui_SRCS TaskGeomHatch.ui TaskGeomHatch.cpp TaskGeomHatch.h - TaskTextLeader.ui - TaskTextLeader.cpp - TaskTextLeader.h + TaskLeaderLine.ui + TaskLeaderLine.cpp + TaskLeaderLine.h + TaskRichAnno.ui + TaskRichAnno.cpp + TaskRichAnno.h DrawGuiUtil.cpp DrawGuiUtil.h Rez.cpp @@ -215,8 +220,8 @@ SET(TechDrawGuiView_SRCS QGTracker.h QGILeaderLine.cpp QGILeaderLine.h - QGITextLeader.cpp - QGITextLeader.h + QGIRichAnno.cpp + QGIRichAnno.h QGMText.h QGMText.cpp TemplateTextField.cpp @@ -258,6 +263,8 @@ SET(TechDrawGuiViewProvider_SRCS ViewProviderImage.h ViewProviderLeader.cpp ViewProviderLeader.h + ViewProviderRichAnno.cpp + ViewProviderRichAnno.h ) SOURCE_GROUP("MRTE" FILES ${MRTE_SRCS}) @@ -270,7 +277,8 @@ SET(TechDrawGuiTaskDlgs_SRCS TaskLinkDim.ui TaskSectionView.ui TaskGeomHatch.ui - TaskTextLeader.ui + TaskLeaderLine.ui + TaskRichAnno.ui mrichtextedit.ui ) SOURCE_GROUP("TaskDialogs" FILES ${TechDrawGuiTaskDlgs_SRCS}) diff --git a/src/Mod/TechDraw/Gui/CommandDecorate.cpp b/src/Mod/TechDraw/Gui/CommandDecorate.cpp index d88b38fbaaed..776375e3d70b 100644 --- a/src/Mod/TechDraw/Gui/CommandDecorate.cpp +++ b/src/Mod/TechDraw/Gui/CommandDecorate.cpp @@ -57,7 +57,8 @@ #include "DrawGuiUtil.h" #include "MDIViewPage.h" #include "TaskGeomHatch.h" -#include "TaskTextLeader.h" +#include "TaskLeaderLine.h" +#include "TaskRichAnno.h" #include "ViewProviderGeomHatch.h" #include "ViewProviderPage.h" @@ -89,9 +90,6 @@ CmdTechDrawLeaderLine::CmdTechDrawLeaderLine() void CmdTechDrawLeaderLine::activated(int iMsg) { Q_UNUSED(iMsg); - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Not Available"), - QObject::tr("Line function is not available. Use Text Leader.")); - return; Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); if (dlg != nullptr) { @@ -120,12 +118,8 @@ void CmdTechDrawLeaderLine::activated(int iMsg) return; } - Gui::Control().showDialog(new TaskDlgTextLeader(LINEMODE, - baseFeat, + Gui::Control().showDialog(new TechDrawGui::TaskDlgLeaderLine(baseFeat, page)); -// Gui::Control().showDialog(new TaskDlgLeaderLine(1, -// baseFeat, -// page)); } bool CmdTechDrawLeaderLine::isActive(void) @@ -136,24 +130,24 @@ bool CmdTechDrawLeaderLine::isActive(void) } //=========================================================================== -// TechDraw_TextLeader +// TechDraw_RichAnno //=========================================================================== -DEF_STD_CMD_A(CmdTechDrawTextLeader); +DEF_STD_CMD_A(CmdTechDrawRichAnno); -CmdTechDrawTextLeader::CmdTechDrawTextLeader() - : Command("TechDraw_TextLeader") +CmdTechDrawRichAnno::CmdTechDrawRichAnno() + : Command("TechDraw_RichAnno") { sAppModule = "TechDraw"; sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add a text leader to a view"); - sToolTipText = QT_TR_NOOP("Add a text leader to a view"); - sWhatsThis = "TechDraw_TextLeader"; + sMenuText = QT_TR_NOOP("Add a rich text annotation"); + sToolTipText = QT_TR_NOOP("Add a rich text annotation"); + sWhatsThis = "TechDraw_RichAnno"; sStatusTip = sToolTipText; sPixmap = "actions/techdraw-textleader"; } -void CmdTechDrawTextLeader::activated(int iMsg) +void CmdTechDrawRichAnno::activated(int iMsg) { Q_UNUSED(iMsg); Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); @@ -172,23 +166,22 @@ void CmdTechDrawTextLeader::activated(int iMsg) TechDraw::DrawView* baseFeat = nullptr; if (!selection.empty()) { baseFeat = dynamic_cast(selection[0].getObject()); - if( baseFeat == nullptr ) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), - QObject::tr("Can not attach leader. No base View selected.")); - return; - } - } else { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), - QObject::tr("You must select a base View for the line.")); - return; +// if( baseFeat == nullptr ) { +// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), +// QObject::tr("Can not attach leader. No base View selected.")); +// return; +// } +// } else { +// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), +// QObject::tr("You must select a base View for the line.")); +// return; } - Gui::Control().showDialog(new TaskDlgTextLeader(TEXTMODE, - baseFeat, - page)); + Gui::Control().showDialog(new TaskDlgRichAnno(baseFeat, + page)); } -bool CmdTechDrawTextLeader::isActive(void) +bool CmdTechDrawRichAnno::isActive(void) { bool havePage = DrawGuiUtil::needPage(this); bool haveView = DrawGuiUtil::needView(this, false); @@ -477,7 +470,7 @@ void CreateTechDrawCommandsDecorate(void) rcCmdMgr.addCommand(new CmdTechDrawToggleFrame()); // rcCmdMgr.addCommand(new CmdTechDrawRedrawPage()); rcCmdMgr.addCommand(new CmdTechDrawLeaderLine()); - rcCmdMgr.addCommand(new CmdTechDrawTextLeader()); + rcCmdMgr.addCommand(new CmdTechDrawRichAnno()); } //=========================================================================== diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.cpp b/src/Mod/TechDraw/Gui/MDIViewPage.cpp index 30765c17c0c5..a4bb764d220d 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.cpp +++ b/src/Mod/TechDraw/Gui/MDIViewPage.cpp @@ -82,6 +82,7 @@ #include #include #include +#include #include "Rez.h" #include "QGIDrawingTemplate.h" @@ -96,6 +97,8 @@ #include "ViewProviderPage.h" #include "QGVPage.h" #include "QGILeaderLine.h" +#include "QGIRichAnno.h" +#include "QGMText.h" using namespace TechDrawGui; @@ -167,6 +170,7 @@ MDIViewPage::MDIViewPage(ViewProviderPage *pageVp, Gui::Document* doc, QWidget* //therefore we need to make sure parentage of the graphics representation is set properly. bit of a kludge. setDimensionGroups(); setBalloonGroups(); + setLeaderGroups(); App::DocumentObject *obj = m_vpPage->getDrawPage()->Template.getValue(); auto pageTemplate( dynamic_cast(obj) ); @@ -228,6 +232,23 @@ void MDIViewPage::setBalloonGroups(void) } } +void MDIViewPage::setLeaderGroups(void) +{ + const std::vector &allItems = m_view->getViews(); + std::vector::const_iterator itInspect; + int leadItemType = QGraphicsItem::UserType + 232; + + for (itInspect = allItems.begin(); itInspect != allItems.end(); itInspect++) { + if (((*itInspect)->type() == leadItemType) && (!(*itInspect)->group())) { + QGIView* parent = m_view->findParent((*itInspect)); + if (parent) { + QGILeaderLine* lead = dynamic_cast((*itInspect)); + m_view->addLeaderToParent(lead,parent); + } + } + } +} + void MDIViewPage::setDocumentObject(const std::string& name) { m_objectName = name; @@ -238,7 +259,6 @@ void MDIViewPage::setDocumentName(const std::string& name) m_documentName = name; } - void MDIViewPage::closeEvent(QCloseEvent* ev) { MDIView::closeEvent(ev); @@ -338,6 +358,9 @@ bool MDIViewPage::attachView(App::DocumentObject *obj) } else if (typeId.isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId()) ) { qview = m_view->addViewLeader( static_cast(obj) ); + } else if (typeId.isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId()) ) { + qview = m_view->addRichAnno( static_cast(obj) ); + } else if (typeId.isDerivedFrom(TechDraw::DrawHatch::getClassTypeId()) ) { //Hatch is not attached like other Views (since it isn't really a View) return true; @@ -1107,7 +1130,7 @@ void MDIViewPage::sceneSelectionChanged() setTreeToSceneSelect(); } -//Note: no guarantee of selection order??? +//Note: Qt says: "no guarantee of selection order"!!! void MDIViewPage::setTreeToSceneSelect(void) { bool saveBlock = blockConnection(true); // block selectionChanged signal from Tree/Observer @@ -1118,6 +1141,8 @@ void MDIViewPage::setTreeToSceneSelect(void) for (QList::iterator it = sceneSel.begin(); it != sceneSel.end(); ++it) { QGIView *itemView = dynamic_cast(*it); if(itemView == 0) { +// Base::Console().Message("MDIVP::setTreeToScene - selection not QGIView - type: %d\n", +// (*it)->type() - QGraphicsItem::UserType); QGIEdge *edge = dynamic_cast(*it); if(edge) { QGraphicsItem*parent = edge->parentItem(); @@ -1214,7 +1239,48 @@ void MDIViewPage::setTreeToSceneSelect(void) //bool accepted = static_cast (Gui::Selection().addSelection(dimObj->getDocument()->getName(),dimObj->getNameInDocument())); } + + QGMText *mText = dynamic_cast(*it); + if(mText) { +// Base::Console().Message("MDIVP::setTreeToScene - mTextSelected!\n"); + QGraphicsItem* textParent = mText->QGraphicsItem::parentItem(); + if(!textParent) { +// Base::Console().Message("MDIVP::setTreeToScene - mText has no parent item\n"); + continue; + } + + QGIView *parent = dynamic_cast(textParent); + + if(!parent) { +// Base::Console().Message("MDIVP::setTreeToScene - mText parent is not QGIV\n"); + continue; + } + + TechDraw::DrawView *parentFeat = parent->getViewObject(); + if (!parentFeat) { +// Base::Console().Message("MDIVP::setTreeToScene - mText has no parent Feature\n"); + continue; + } +// if (!parentFeat->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId())) { +// //mtext is parented to something other than Leader +// //need special cases here? +// Base::Console().Message("MDIVP::setTreeToScene - mText parentFeat is not LeaderLine\n"); +// continue; +// } + const char* name = parentFeat->getNameInDocument(); + if (!name) { //can happen during undo/redo if Dim is selected??? +// Base::Console().Message("INFO - MDIVP::sceneSelectionChanged - parentFeat name is null!\n"); + continue; + } + + //bool accepted = + static_cast (Gui::Selection().addSelection(parentFeat->getDocument()->getName(),parentFeat->getNameInDocument())); + } + } else { +// Base::Console().Message("MDIVP::setTreeToScene - selection IS a QGIView - type: %d\n", +// itemView->type() - QGraphicsItem::UserType); + TechDraw::DrawView *viewObj = itemView->getViewObject(); if (viewObj && !viewObj->isRemoving()) { std::string doc_name = viewObj->getDocument()->getName(); diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.h b/src/Mod/TechDraw/Gui/MDIViewPage.h index dbfd6cab98ec..5e2b87f22efc 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.h +++ b/src/Mod/TechDraw/Gui/MDIViewPage.h @@ -127,6 +127,7 @@ public Q_SLOTS: QPrinter::PaperSize getPaperSize(int w, int h) const; void setDimensionGroups(void); void setBalloonGroups(void); + void setLeaderGroups(void); void showStatusMsg(const char* s1, const char* s2, const char* s3) const; void onDeleteObject(const App::DocumentObject& obj); diff --git a/src/Mod/TechDraw/Gui/QGCustomText.h b/src/Mod/TechDraw/Gui/QGCustomText.h index dd73693d992f..b2ad795ef5e5 100644 --- a/src/Mod/TechDraw/Gui/QGCustomText.h +++ b/src/Mod/TechDraw/Gui/QGCustomText.h @@ -48,9 +48,9 @@ class TechDrawGuiExport QGCustomText : public QGraphicsTextItem int type() const { return Type;} void setHighlighted(bool state); - void setPrettyNormal(); - void setPrettyPre(); - void setPrettySel(); + virtual void setPrettyNormal(); + virtual void setPrettyPre(); + virtual void setPrettySel(); virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); virtual void centerAt(QPointF centerPos); diff --git a/src/Mod/TechDraw/Gui/QGEPath.cpp b/src/Mod/TechDraw/Gui/QGEPath.cpp index 9d99b050ab10..d708b1b7cbfb 100644 --- a/src/Mod/TechDraw/Gui/QGEPath.cpp +++ b/src/Mod/TechDraw/Gui/QGEPath.cpp @@ -174,8 +174,8 @@ QGEPath::QGEPath() : m_parentItem(nullptr) { setHandlesChildEvents(false); - setAcceptHoverEvents(false); - setFlag(QGraphicsItem::ItemIsSelectable, false); + setAcceptHoverEvents(true); + setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemIsMovable, false); // setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true); setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); @@ -190,12 +190,47 @@ QGEPath::QGEPath() : QVariant QGEPath::itemChange(GraphicsItemChange change, const QVariant &value) { -// Base::Console().Message("QGEPath::itemChange(%d)\n",change); -// Q_EMIT dragging(); - +// Base::Console().Message("QGEP::itemChange(%d) - type: %d\n", change,type() - QGraphicsItem::UserType); + if (change == ItemSelectedHasChanged && scene()) { + if(isSelected()) { + Q_EMIT selected(true); + setPrettySel(); + } else { + Q_EMIT selected(false); + setPrettyNormal(); + } + } return QGIPrimPath::itemChange(change, value); } +void QGEPath::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + Q_EMIT hover(true); + if (!isSelected()) { + setPrettyPre(); + } + QGIPrimPath::hoverEnterEvent(event); +} + +void QGEPath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + QGIView *view = dynamic_cast (parentItem()); + assert(view != 0); + Q_UNUSED(view); + + Q_EMIT hover(false); + QGraphicsItem* parent = parentItem(); + bool parentSel(false); + if (parent != nullptr) { + parentSel = parent->isSelected(); + } + if (!parentSel && !isSelected()) { + setPrettyNormal(); + } + QGraphicsPathItem::hoverLeaveEvent(event); +// QGIPrimPath::hoverLeaveEvent(event); //QGIPP::hoverleave will reset pretty to normal +} + void QGEPath::startPathEdit() { // Base::Console().Message("QGEPath::startPathEdit()\n"); @@ -325,7 +360,7 @@ void QGEPath::updatePath(void) } } setPath(result); - setPrettyNormal(); +// setPrettyNormal(); } void QGEPath::makeDeltasFromPoints(std::vector pts) diff --git a/src/Mod/TechDraw/Gui/QGEPath.h b/src/Mod/TechDraw/Gui/QGEPath.h index 699ba91f86fe..9805047c9730 100644 --- a/src/Mod/TechDraw/Gui/QGEPath.h +++ b/src/Mod/TechDraw/Gui/QGEPath.h @@ -120,9 +120,13 @@ public Q_SLOTS: Q_SIGNALS: void pointsUpdated(std::vector pts); + void hover(bool state); + void selected(bool state); protected: virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; + virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; std::vector m_deltas; //deltas between points 1:1 scale, starts at (0,0) std::vector m_markers; QPointF m_attach; diff --git a/src/Mod/TechDraw/Gui/QGILeaderLine.cpp b/src/Mod/TechDraw/Gui/QGILeaderLine.cpp index 1bde7544be5a..34b8444b3822 100644 --- a/src/Mod/TechDraw/Gui/QGILeaderLine.cpp +++ b/src/Mod/TechDraw/Gui/QGILeaderLine.cpp @@ -74,11 +74,13 @@ QGILeaderLine::QGILeaderLine(QGraphicsItem* myParent, TechDraw::DrawLeaderLine* leader) : m_parentItem(myParent), m_lineWidth(0.0), - m_lineColor(Qt::black) + m_lineColor(Qt::black), + m_hasHover(false) + { setHandlesChildEvents(false); - setAcceptHoverEvents(false); - setFlag(QGraphicsItem::ItemIsSelectable, false); + setAcceptHoverEvents(true); + setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemIsMovable, false); setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); setFlag(QGraphicsItem::ItemSendsGeometryChanges,true); @@ -88,11 +90,13 @@ QGILeaderLine::QGILeaderLine(QGraphicsItem* myParent, m_lineColor = Qt::blue; m_line = new QGEPath(); + m_line->setNormalColor(getNormalColor()); +// m_line->setPrettyNormal(); + addToGroup(m_line); m_line->setFlag(QGraphicsItem::ItemIsSelectable, false); m_line->setFlag(QGraphicsItem::ItemIsMovable, false); setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); - m_line->setAcceptHoverEvents(false); m_line->setZValue(ZVALUE::DIMENSION); m_arrow1 = new QGIArrow(); @@ -112,19 +116,48 @@ QGILeaderLine::QGILeaderLine(QGraphicsItem* myParent, m_line, SIGNAL(pointsUpdated(std::vector)), this , SLOT (onLineEditFinished(std::vector)) ); + QObject::connect( + m_line, SIGNAL(selected(bool)), + this , SLOT (select(bool))); + + QObject::connect( + m_line, SIGNAL(hover(bool)), + this , SLOT (hover(bool))); + } QVariant QGILeaderLine::itemChange(GraphicsItemChange change, const QVariant &value) { -// Base::Console().Message("QGIV::itemChange(%d)\n", change); +// Base::Console().Message("QGILL::itemChange(%d)\n", change); if (change == ItemSelectedHasChanged && scene()) { - //There's nothing special for QGIVL to do when selection changes! + if(isSelected()) { + m_line->setSelected(true); + m_arrow1->setSelected(true); + m_arrow2->setSelected(true); + } else { + m_line->setSelected(false); + m_arrow1->setSelected(false); + m_arrow2->setSelected(false); + } + draw(); } else if(change == ItemSceneChange && scene()) { // nothing special! } return QGIView::itemChange(change, value); } +void QGILeaderLine::select(bool state) +{ + setSelected(state); + draw(); +} + +void QGILeaderLine::hover(bool state) +{ + m_hasHover = state; + draw(); +} + void QGILeaderLine::onLineEditFinished(std::vector pts) { // Base::Console().Message("QGIVL::onLineEditFinished(%d)\n",pts.size()); @@ -135,7 +168,7 @@ void QGILeaderLine::onLineEditFinished(std::vector pts) } if (m_parentItem == nullptr) { - Base::Console().Log("QGIVL::onLineEditFinished - m_parentItem is NULL\n"); + Base::Console().Log("QGILL::onLineEditFinished - m_parentItem is NULL\n"); } else { QGIView* qgiv = dynamic_cast(m_parentItem); if (qgiv != nullptr) { @@ -158,7 +191,7 @@ void QGILeaderLine::updateView(bool update) Q_UNUSED(update); auto leadFeat( dynamic_cast(getViewObject()) ); if ( leadFeat == nullptr ) { - Base::Console().Log("QGIL::updateView - no feature!\n"); + Base::Console().Log("QGILL::updateView - no feature!\n"); return; } @@ -172,7 +205,7 @@ void QGILeaderLine::updateView(bool update) void QGILeaderLine::draw() { -// Base::Console().("QGIL::draw()- %s\n", getViewObject()->getNameInDocument()); +// Base::Console().Message("QGILL::draw()- %s\n", getViewObject()->getNameInDocument()); if (!isVisible()) { Base::Console().Log("QGIL::draw - not visible\n"); return; @@ -224,7 +257,6 @@ void QGILeaderLine::draw() Base::Console().Log("QGIL::draw - no points\n"); return; } -// m_line->setAttach(aPoint); m_line->setStyle(m_lineStyle); double scaler = 1.0; m_line->setWidth(scaler * m_lineWidth); @@ -239,7 +271,19 @@ void QGILeaderLine::draw() setArrows(qPoints); - QGIView::draw(); + if (m_hasHover && !isSelected()) { + m_arrow1->setPrettyPre(); + m_arrow2->setPrettyPre(); + m_line->setPrettyPre(); + } else if (isSelected()) { + m_arrow1->setPrettySel(); + m_arrow2->setPrettySel(); + m_line->setPrettySel(); + } else { + m_arrow1->setPrettyNormal(); + m_arrow2->setPrettyNormal(); + m_line->setPrettyNormal(); + } } void QGILeaderLine::drawBorder() @@ -285,6 +329,8 @@ void QGILeaderLine::setArrows(std::vector pathPoints) m_arrow1->setSize(QGIArrow::getPrefArrowSize()); m_arrow1->setDirMode(true); m_arrow1->setDirection(stdX); + m_arrow1->setNormalColor(m_lineColor); + if (pathPoints.size() > 1) { auto it = pathPoints.begin(); QPointF s = (*it); @@ -292,9 +338,7 @@ void QGILeaderLine::setArrows(std::vector pathPoints) QPointF qsVec = s - e; Base::Vector3d sVec(qsVec.x(),qsVec.y(),0.0); m_arrow1->setDirection(sVec); - m_arrow1->setNormalColor(m_lineColor); m_arrow1->setPos(0.0,0.0); - m_arrow1->setPrettyNormal(); } m_arrow1->draw(); m_arrow1->show(); @@ -307,6 +351,7 @@ void QGILeaderLine::setArrows(std::vector pathPoints) m_arrow2->setWidth(m_lineWidth); m_arrow2->setDirMode(true); m_arrow2->setDirection(-stdX); + m_arrow2->setNormalColor(m_lineColor); if (pathPoints.size() > 1) { auto itr = pathPoints.rbegin(); QPointF s = (*itr); @@ -314,9 +359,7 @@ void QGILeaderLine::setArrows(std::vector pathPoints) QPointF qeVec = s - e; Base::Vector3d eVec(qeVec.x(),qeVec.y(),0.0); m_arrow2->setDirection(eVec); - m_arrow2->setNormalColor(m_lineColor); m_arrow2->setPos(lastOffset); - m_arrow2->setPrettyNormal(); } m_arrow2->draw(); m_arrow2->show(); @@ -355,6 +398,27 @@ double QGILeaderLine::getEdgeFuzz(void) const return result; } +QColor QGILeaderLine::getNormalColor() +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/LeaderLinens"); + App::Color fcColor; + fcColor.setPackedValue(hGrp->GetUnsigned("Color", 0x00000000)); + m_colNormal = fcColor.asValue(); + + auto lead( dynamic_cast(getViewObject()) ); + if( lead == nullptr ) + return m_colNormal; + + auto vp = static_cast(getViewProvider(getViewObject())); + if ( vp == nullptr ) { + return m_colNormal; + } + + m_colNormal = vp->Color.getValue().asValue(); + return m_colNormal; +} + QRectF QGILeaderLine::boundingRect() const { return childrenBoundingRect(); diff --git a/src/Mod/TechDraw/Gui/QGILeaderLine.h b/src/Mod/TechDraw/Gui/QGILeaderLine.h index 76cba3ae9123..08d86efc1859 100644 --- a/src/Mod/TechDraw/Gui/QGILeaderLine.h +++ b/src/Mod/TechDraw/Gui/QGILeaderLine.h @@ -82,6 +82,8 @@ class TechDrawGuiExport QGILeaderLine : public QGIView public Q_SLOTS: void onLineEditFinished(std::vector pts); //QGEPath is finished editing points + void select(bool state); + void hover(bool state); Q_SIGNALS: void editComplete(std::vector pts, QGIView* parent); //tell caller that edit session is finished @@ -94,6 +96,8 @@ public Q_SLOTS: Base::Vector3d m_attachPoint; protected: + QColor getNormalColor(); + QGraphicsItem* m_parentItem; QGEPath* m_line; QGIArrow* m_arrow1; @@ -101,6 +105,7 @@ public Q_SLOTS: double m_lineWidth; QColor m_lineColor; Qt::PenStyle m_lineStyle; + bool m_hasHover; }; } diff --git a/src/Mod/TechDraw/Gui/QGIPrimPath.cpp b/src/Mod/TechDraw/Gui/QGIPrimPath.cpp index 426c5074e9cf..634019b4d3bd 100644 --- a/src/Mod/TechDraw/Gui/QGIPrimPath.cpp +++ b/src/Mod/TechDraw/Gui/QGIPrimPath.cpp @@ -65,6 +65,7 @@ QGIPrimPath::QGIPrimPath(): QVariant QGIPrimPath::itemChange(GraphicsItemChange change, const QVariant &value) { +// Base::Console().Message("QGIPP::itemChange(%d) - type: %d\n", change,type() - QGraphicsItem::UserType); if (change == ItemSelectedHasChanged && scene()) { if(isSelected()) { setPrettySel(); @@ -85,15 +86,13 @@ void QGIPrimPath::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void QGIPrimPath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { -// QGIView *view = dynamic_cast (parentItem()); //this is temp for debug?? -// assert(view != 0); -// Q_UNUSED(view); - if(!isSelected() && !isHighlighted) { + if(!isSelected()) { setPrettyNormal(); } QGraphicsPathItem::hoverLeaveEvent(event); } +//set highlighted is obsolete void QGIPrimPath::setHighlighted(bool b) { isHighlighted = b; diff --git a/src/Mod/TechDraw/Gui/QGITextLeader.cpp b/src/Mod/TechDraw/Gui/QGIRichAnno.cpp similarity index 64% rename from src/Mod/TechDraw/Gui/QGITextLeader.cpp rename to src/Mod/TechDraw/Gui/QGIRichAnno.cpp index e2c482a17b91..4031453a1acf 100644 --- a/src/Mod/TechDraw/Gui/QGITextLeader.cpp +++ b/src/Mod/TechDraw/Gui/QGIRichAnno.cpp @@ -51,46 +51,52 @@ #include -#include +#include #include #include #include "Rez.h" #include "ZVALUE.h" #include "QGIArrow.h" -#include "ViewProviderLeader.h" +#include "ViewProviderRichAnno.h" #include "MDIViewPage.h" #include "DrawGuiUtil.h" #include "QGVPage.h" #include "QGIPrimPath.h" #include "QGEPath.h" #include "QGMText.h" -#include "QGILeaderLine.h" +#include "QGIView.h" -#include "QGITextLeader.h" +#include "QGIRichAnno.h" using namespace TechDraw; using namespace TechDrawGui; //************************************************************** -QGITextLeader::QGITextLeader(QGraphicsItem* myParent, - TechDraw::DrawTextLeader* leader) : - QGILeaderLine(myParent,leader) +QGIRichAnno::QGIRichAnno(QGraphicsItem* myParent, + TechDraw::DrawRichAnno* anno) { -// Base::Console().Message("QGITL::QGITL() - %s\n", leader->getNameInDocument()); setHandlesChildEvents(false); setAcceptHoverEvents(false); - setFlag(QGraphicsItem::ItemIsSelectable, false); + setFlag(QGraphicsItem::ItemIsSelectable, false); //we actually select & drag m_text setFlag(QGraphicsItem::ItemIsMovable, false); setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges,true); + if (myParent != nullptr) { + setParentItem(myParent); + } + setViewFeature(anno); + m_text = new QGMText(); m_text->setTextInteractionFlags(Qt::NoTextInteraction); addToGroup(m_text); -// m_text->setZValue(ZVALUE::DIMENSION); + m_text->setZValue(ZVALUE::DIMENSION); + setZValue(ZVALUE::DIMENSION); + +// we should be able to just drag QGIRA instead of m_text item?? QObject::connect( m_text, SIGNAL(dragging()), this , SLOT (textDragging()) @@ -99,24 +105,31 @@ QGITextLeader::QGITextLeader(QGraphicsItem* myParent, m_text, SIGNAL(dragFinished()), this , SLOT (textDragFinished()) ); + QObject::connect( + m_text, SIGNAL(selected(bool)), + this , SLOT (select(bool))); + + QObject::connect( + m_text, SIGNAL(hover(bool)), + this , SLOT (hover(bool))); } -QVariant QGITextLeader::itemChange(GraphicsItemChange change, const QVariant &value) +QVariant QGIRichAnno::itemChange(GraphicsItemChange change, const QVariant &value) { if (change == ItemSelectedHasChanged && scene()) { - //There's nothing special for QGIVL to do when selection changes! + //There's nothing special for QGIRA to do when selection changes! } else if(change == ItemSceneChange && scene()) { // nothing special! } - return QGILeaderLine::itemChange(change, value); + return QGIView::itemChange(change, value); } -void QGITextLeader::textDragging(void) +void QGIRichAnno::textDragging(void) { // Base::Console().Message("QGIL::textDragging()\n"); //this is the long way around. can we do it without crossing the App/Gui boundary? //just update graphics until drag finished. -// auto lead( dynamic_cast(getFeature()) ); +// auto lead( dynamic_cast(getFeature()) ); // if( lead == nullptr ) { // return; @@ -131,68 +144,90 @@ void QGITextLeader::textDragging(void) // draw(); } -void QGITextLeader::textDragFinished(void) +void QGIRichAnno::textDragFinished(void) { // Base::Console().Message("QGIL::textDragFinished()\n"); - auto lead( dynamic_cast(getFeature()) ); + auto anno( dynamic_cast(getFeature()) ); - if( lead == nullptr ) { + if( anno == nullptr ) { return; } double x = Rez::appX(m_text->x()), - y = Rez::appX(m_text->y()); - Base::Vector3d tPos(x,-y,0.0); - lead->TextPosition.setValue(tPos); + y = - Rez::appX(m_text->y()); + anno->X.setValue(x); + anno->Y.setValue(y); } -void QGITextLeader::onTextSelect(bool state) +void QGIRichAnno::select(bool state) { - Q_UNUSED(state); + setSelected(state); draw(); } -void QGITextLeader::draw() +void QGIRichAnno::hover(bool state) { -// Base::Console().Message("QGITL::draw()- %s\n", getViewObject()->getNameInDocument()); + m_hasHover = state; + draw(); +} + +void QGIRichAnno::updateView(bool update) +{ +// Base::Console().Message("QGIRA::updateView() - %s\n", getViewName()); + Q_UNUSED(update); + auto annoFeat( dynamic_cast(getViewObject()) ); + if ( annoFeat == nullptr ) { + Base::Console().Log("QGIRA::updateView - no feature!\n"); + return; + } + + auto vp = static_cast(getViewProvider(getViewObject())); + if ( vp == nullptr ) { + return; + } + + draw(); +} + +void QGIRichAnno::drawBorder() +{ +////Leaders have no border! +// QGIView::drawBorder(); //good for debugging +} + + +void QGIRichAnno::draw() +{ +// Base::Console().Log("QGITL::draw() - %s\n",getFeature()->getNameInDocument()); if (!isVisible()) { Base::Console().Log("QGITL::draw - not visible\n"); return; } - TechDraw::DrawTextLeader* leadFeat = getFeature(); - if((!leadFeat) ) { + TechDraw::DrawRichAnno* annoFeat = getFeature(); + if((!annoFeat) ) { Base::Console().Log("QGITL::draw - no feature\n"); return; } - auto vp = static_cast(getViewProvider(getFeature())); + auto vp = static_cast(getViewProvider(getFeature())); if ( vp == nullptr ) { Base::Console().Log("QGITL::draw - no viewprovider\n"); return; } - TechDraw::DrawView* parent = leadFeat->getBaseView(); - QGVPage* view = QGILeaderLine::getGraphicsView(parent); - if (view == nullptr) { - Base::Console().Log("QGITL::draw - no graphcisView for parent!! - setup?\n"); - return; - } - -// double scale = leadFeat->getScale(); - QGILeaderLine::draw(); + QGIView::draw(); setTextItem(); - } -void QGITextLeader::setTextItem() +void QGIRichAnno::setTextItem() { -// Base::Console().Message("QGIVL::setTextItem()\n"); - TechDraw::DrawTextLeader* leadFeat = getFeature(); - auto vp = static_cast(getViewProvider(getFeature())); +// Base::Console().Message("QGIRA::setTextItem() - %s\n",getViewName()); + TechDraw::DrawRichAnno* annoFeat = getFeature(); + auto vp = static_cast(getViewProvider(annoFeat)); if ( vp == nullptr ) { - Base::Console().Log("QGIVL::setTextItem - no ViewProvider\n"); + Base::Console().Log("QGIRA::setTextItem - no ViewProvider\n"); return; } QFont font = m_text->font(); @@ -202,7 +237,7 @@ void QGITextLeader::setTextItem() //convert point font sizes to (Rez,mm) font sizes QRegExp rxFontSize(QString::fromUtf8("font-size:([0-9]*)pt;")); - QString inHtml = QString::fromUtf8(leadFeat->LeaderText.getValue()); + QString inHtml = QString::fromUtf8(annoFeat->AnnoText.getValue()); QString match; double mmPerPoint = 0.353; double sizeConvert = Rez::getRezFactor() * mmPerPoint; @@ -230,48 +265,50 @@ void QGITextLeader::setTextItem() } m_text->setHtml(outHtml); - m_text->setPrettyNormal(); - m_text->setTextWidth(Rez::guiX(vp->MaxWidth.getValue())); - m_text->showBox(vp->ShowFrame.getValue()); + m_text->setTextWidth(Rez::guiX(annoFeat->MaxWidth.getValue())); + m_text->showBox(annoFeat->ShowFrame.getValue()); double scale = getScale(); - Base::Vector3d textPos = Rez::guiX(leadFeat->TextPosition.getValue()); + double x = Rez::guiX(annoFeat->X.getValue()); + double y = Rez::guiX(annoFeat->Y.getValue()); + Base::Vector3d textPos(x,y,0.0); QPointF tPos(textPos.x * scale,- textPos.y * scale); m_text->setPos(tPos); } -//void QGITextLeader::drawBorder() +//void QGIRichAnno::drawBorder() //{ //////Leaders have no border! //// QGIView::drawBorder(); //good for debugging //} -TechDraw::DrawTextLeader* QGITextLeader::getFeature(void) +TechDraw::DrawRichAnno* QGIRichAnno::getFeature(void) { - TechDraw::DrawTextLeader* result = - static_cast(getViewObject()); + TechDraw::DrawRichAnno* result = + static_cast(getViewObject()); return result; } -QRectF QGITextLeader::boundingRect() const +QRectF QGIRichAnno::boundingRect() const { - return childrenBoundingRect(); + QRectF rect = mapFromItem(m_text,m_text->boundingRect()).boundingRect(); + return rect.adjusted(-10.,-10.,10.,10.); } -QPainterPath QGITextLeader::shape() const +QPainterPath QGIRichAnno::shape() const { return QGraphicsItemGroup::shape(); } -void QGITextLeader::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { +void QGIRichAnno::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { QStyleOptionGraphicsItem myOption(*option); myOption.state &= ~QStyle::State_Selected; // painter->drawRect(boundingRect()); //good for debugging - QGILeaderLine::paint (painter, &myOption, widget); + QGIView::paint (painter, &myOption, widget); } -#include +#include diff --git a/src/Mod/TechDraw/Gui/QGITextLeader.h b/src/Mod/TechDraw/Gui/QGIRichAnno.h similarity index 83% rename from src/Mod/TechDraw/Gui/QGITextLeader.h rename to src/Mod/TechDraw/Gui/QGIRichAnno.h index 77a3e9d6dcc6..38991fc9c881 100644 --- a/src/Mod/TechDraw/Gui/QGITextLeader.h +++ b/src/Mod/TechDraw/Gui/QGIRichAnno.h @@ -20,8 +20,8 @@ * * ***************************************************************************/ -#ifndef DRAWINGGUI_QGRAPHICSITEMTEXTLEADER_H -#define DRAWINGGUI_QGRAPHICSITEMTEXTLEADER_H +#ifndef TECHDRAWGUI_QGIRICHANNO_H +#define TECHDRAWGUI_QGIRICHANNO_H #include #include @@ -37,7 +37,7 @@ #include "QGILeaderLine.h" namespace TechDraw { -class DrawTextLeader; +class DrawRichAnno; class DrawLeaderLine; } @@ -51,16 +51,16 @@ class QGMText; //******************************************************************* -class TechDrawGuiExport QGITextLeader : public QGILeaderLine +class TechDrawGuiExport QGIRichAnno : public QGIView { Q_OBJECT public: enum {Type = QGraphicsItem::UserType + 233}; - explicit QGITextLeader(QGraphicsItem* myParent = nullptr, - TechDraw::DrawTextLeader* lead = nullptr); - ~QGITextLeader() = default; + explicit QGIRichAnno(QGraphicsItem* myParent = nullptr, + TechDraw::DrawRichAnno* lead = nullptr); + ~QGIRichAnno() = default; int type() const override { return Type;} virtual void paint( QPainter * painter, @@ -68,16 +68,19 @@ class TechDrawGuiExport QGITextLeader : public QGILeaderLine QWidget * widget = 0 ) override; virtual QRectF boundingRect() const override; virtual QPainterPath shape(void) const override; -/* virtual void updateView(bool update = false) override;*/ + + virtual void drawBorder() override; + virtual void updateView(bool update = false) override; void setTextItem(void); - virtual TechDraw::DrawTextLeader* getFeature(void); + virtual TechDraw::DrawRichAnno* getFeature(void); public Q_SLOTS: void textDragging(void); void textDragFinished(void); - void onTextSelect(bool state); + void hover(bool state); + void select(bool state); protected: virtual void draw() override; @@ -86,8 +89,10 @@ public Q_SLOTS: protected: QGMText* m_text; + bool m_hasHover; + }; } -#endif // DRAWINGGUI_QGRAPHICSITEMTEXTLEADER_H +#endif // TECHDRAWGUI_QGIRICHANNO_H diff --git a/src/Mod/TechDraw/Gui/QGIUserTypes.h b/src/Mod/TechDraw/Gui/QGIUserTypes.h index 4cc1437328e0..fa573c94e630 100644 --- a/src/Mod/TechDraw/Gui/QGIUserTypes.h +++ b/src/Mod/TechDraw/Gui/QGIUserTypes.h @@ -43,7 +43,7 @@ QGCustomImage: 201 QGIMatting: 205 QGTracker: 210 QGILeaderLine: 232 -QGITextLeader: 233 +QGIRichAnno: 233 QGMText: 300 QGEPath: 301 QGMarker: 302 diff --git a/src/Mod/TechDraw/Gui/QGIView.cpp b/src/Mod/TechDraw/Gui/QGIView.cpp index 4d54b7d1b250..ac1bfd27543c 100644 --- a/src/Mod/TechDraw/Gui/QGIView.cpp +++ b/src/Mod/TechDraw/Gui/QGIView.cpp @@ -226,10 +226,6 @@ void QGIView::mousePressEvent(QGraphicsSceneMouseEvent * event) // Base::Console().Message("QGIV::mousePressEvent() - %s\n",getViewName()); signalSelectPoint(this, event->pos()); - if(m_locked) { - event->ignore(); - return; - } QGraphicsItem::mousePressEvent(event); } diff --git a/src/Mod/TechDraw/Gui/QGMText.cpp b/src/Mod/TechDraw/Gui/QGMText.cpp index 91fa521be6a9..f5e59e846774 100644 --- a/src/Mod/TechDraw/Gui/QGMText.cpp +++ b/src/Mod/TechDraw/Gui/QGMText.cpp @@ -35,7 +35,9 @@ using namespace TechDraw; using namespace TechDrawGui; -QGMText::QGMText() +QGMText::QGMText() : + m_showBox(false), + m_prettyState("Normal") { setCacheMode(QGCustomText::NoCache); setFlag(ItemSendsGeometryChanges, true); @@ -94,11 +96,30 @@ void QGMText::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) QGCustomText::hoverLeaveEvent(event); } +void QGMText::setPrettySel(void) +{ + m_prettyState = "Sel"; + QGCustomText::setPrettySel(); +} + +void QGMText::setPrettyPre(void) +{ + m_prettyState = "Pre"; + QGCustomText::setPrettyPre(); +} + +void QGMText::setPrettyNormal(void) +{ + m_prettyState = "Normal"; + QGCustomText::setPrettyNormal(); +} + void QGMText::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { QStyleOptionGraphicsItem myOption(*option); myOption.state &= ~QStyle::State_Selected; // painter->drawRect(boundingRect()); //good for debugging + //TODO: this should be changed to a rectItem in the parent if (showBox()) { painter->drawRect(boundingRect().adjusted(1,1,-1,-1)); } diff --git a/src/Mod/TechDraw/Gui/QGMText.h b/src/Mod/TechDraw/Gui/QGMText.h index ee6145bfa126..5c4fb5bbc0de 100644 --- a/src/Mod/TechDraw/Gui/QGMText.h +++ b/src/Mod/TechDraw/Gui/QGMText.h @@ -59,6 +59,10 @@ Q_OBJECT virtual void showBox(bool b) { m_showBox = b; } virtual bool showBox(void) { return m_showBox; } + virtual void setPrettyNormal() override; + virtual void setPrettyPre() override; + virtual void setPrettySel() override; + Q_SIGNALS: void dragging(); void hover(bool state); @@ -74,6 +78,8 @@ Q_OBJECT private: bool m_showBox; + std::string m_prettyState; + QPointF m_lastClick; }; diff --git a/src/Mod/TechDraw/Gui/QGTracker.cpp b/src/Mod/TechDraw/Gui/QGTracker.cpp index 5c780d1f9c14..ebf97c8a3978 100644 --- a/src/Mod/TechDraw/Gui/QGTracker.cpp +++ b/src/Mod/TechDraw/Gui/QGTracker.cpp @@ -35,6 +35,8 @@ #include #endif +#include + #include #include #include @@ -52,7 +54,9 @@ using namespace TechDrawGui; QGTracker::QGTracker(QGraphicsScene* inScene, TrackerMode m): m_width(0), m_sleep(false), - m_qgParent(nullptr) + m_qgParent(nullptr), + m_lastClick(QPointF(FLT_MAX,FLT_MAX)), + m_2clickPending(false) { setTrackerMode(m); if (inScene != nullptr) { @@ -76,7 +80,6 @@ QGTracker::QGTracker(QGraphicsScene* inScene, TrackerMode m): double tWeight = getTrackerWeight(); setWidth(tWeight); setStyle(Qt::DashLine); -// setStyle(Qt::SolidLine); setNormalColor(tailColor); setPrettyNormal(); @@ -110,32 +113,47 @@ QVariant QGTracker::itemChange(GraphicsItemChange change, const QVariant &value) void QGTracker::mousePressEvent(QGraphicsSceneMouseEvent *event) { + QPointF myScenePos = event->scenePos(); if (!m_sleep) { - QPointF scenePos(event->scenePos()); - if (event->button() == Qt::LeftButton) { - if (event->modifiers() & Qt::ControlModifier) { - scenePos = snapToAngle(scenePos); + double someLimit = Rez::guiX(10.0); + QPointF manhat = myScenePos - m_lastClick; +// Base::Console().Message("QGT::mousePressEvent - scenePos: (%.3f, %.3f) lastClick:(%.3f,%.3f)\n", +// myScenePos.x(), myScenePos.y(), m_lastClick.x(),m_lastClick.y()); +// Base::Console().Message("QGT::mousePressEvent - manhat(%.3f, %.3f) mLength: %.3f\n", +// manhat.x(),manhat.y(), manhat.manhattanLength()); + if (manhat.manhattanLength() < someLimit) { +// Base::Console().Message("QGT::mousePressEvent - too close to last click\n"); + } else { + if (event->button() == Qt::LeftButton) { + if (event->modifiers() & Qt::ControlModifier) { + myScenePos = snapToAngle(myScenePos); + } + onMousePress(myScenePos); + + } else if (event->button() == Qt::RightButton) { + terminateDrawing(); } - onMousePress(scenePos); - - } else if (event->button() == Qt::RightButton) { - terminateDrawing(); } } + m_lastClick = myScenePos; QGIPrimPath::mousePressEvent(event); } void QGTracker::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + m_lastClick = event->scenePos(); QGIPrimPath::mouseReleaseEvent(event); } +//TODO: fix this to handle click-release-doubleclick-release nonsense. +// can generate two add points void QGTracker::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event) { // Base::Console().Message("QGT::mouseDoubleClickEvent()\n"); if (!m_sleep) { onDoubleClick(event->scenePos()); } + m_lastClick = event->scenePos(); QGIPrimPath::mouseDoubleClickEvent(event); } diff --git a/src/Mod/TechDraw/Gui/QGTracker.h b/src/Mod/TechDraw/Gui/QGTracker.h index c86b3cb030bb..954790f82a0b 100644 --- a/src/Mod/TechDraw/Gui/QGTracker.h +++ b/src/Mod/TechDraw/Gui/QGTracker.h @@ -102,6 +102,8 @@ class TechDrawGuiExport QGTracker : public QObject, public QGIPrimPath TrackerMode m_trackerMode; QPen m_trackPen; QPen m_tailPen; + QPointF m_lastClick; + bool m_2clickPending; }; } // namespace diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index 8fc1e832c9f0..fb840c6676a2 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -69,7 +69,7 @@ #include #include #include -#include +#include #include "Rez.h" #include "QGIDrawingTemplate.h" @@ -89,7 +89,7 @@ #include "QGIViewImage.h" #include "QGIFace.h" #include "QGILeaderLine.h" -#include "QGITextLeader.h" +#include "QGIRichAnno.h" #include "ZVALUE.h" #include "ViewProviderPage.h" @@ -469,43 +469,63 @@ void QGVPage::addDimToParent(QGIViewDimension* dim, QGIView* parent) dim->setZValue(ZVALUE::DIMENSION); } - QGIView * QGVPage::addViewLeader(TechDraw::DrawLeaderLine *leader) { +// Base::Console().Message("QGVP::addViewLeader(%s)\n",leader->getNameInDocument()); QGILeaderLine* leaderGroup = nullptr; - QGITextLeader* textGroup = nullptr; App::DocumentObject* parentObj = leader->LeaderParent.getValue(); TechDraw::DrawView* parentDV = dynamic_cast(parentObj); - TechDraw::DrawTextLeader* textFeat = dynamic_cast(leader); - + + //NOTE: if Leaders are ever allowed to not be attached to a View, this next bit will have to change if (parentDV != nullptr) { QGIView* parentQV = findQViewForDocObj(parentObj); if (parentQV != nullptr) { - if (textFeat != nullptr) { - textGroup = new QGITextLeader(parentQV, textFeat); - textGroup->updateView(true); - return textGroup; - } else { - leaderGroup = new QGILeaderLine(parentQV, leader); - leaderGroup->updateView(true); //this is different from everybody else, - //but it works. - return leaderGroup; - } - } else { - throw Base::TypeError("QGVP::addViewLeader - parent DV has no QGIV"); + leaderGroup = new QGILeaderLine(parentQV, leader); + leaderGroup->updateView(true); //this is different from everybody else, + //but it works. + return leaderGroup; } -// } else if (parentDP != nullptr) { -// leaderGroup = new QGILeaderLine(nullptr,leader); -// ourScene->addItem(leaderGroup); } else { - //TARFU - throw Base::TypeError("QGVP::addViewLeader - parent obj wrong type"); + throw Base::TypeError("QGVP::addViewLeader - parent DV has no QGIV"); } - return nullptr; } +void QGVPage::addLeaderToParent(QGILeaderLine* lead, QGIView* parent) +{ + assert(lead); + assert(parent); //blow up if we don't have Leader or Parent + QPointF posRef(0.,0.); + QPointF mapPos = lead->mapToItem(parent, posRef); + lead->moveBy(-mapPos.x(), -mapPos.y()); + parent->addToGroup(lead); //vs lead->setParentItem(parent)?? + 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; +} + //! find the graphic for a DocumentObject QGIView * QGVPage::findQViewForDocObj(App::DocumentObject *obj) const { @@ -593,8 +613,23 @@ QGIView * QGVPage::findParent(QGIView *view) const } } } - } + } + + //If type is LeaderLine we check LeaderParent + TechDraw::DrawLeaderLine *lead = 0; + 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; } diff --git a/src/Mod/TechDraw/Gui/QGVPage.h b/src/Mod/TechDraw/Gui/QGVPage.h index 310eb8efc46e..9b9f073d50ba 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.h +++ b/src/Mod/TechDraw/Gui/QGVPage.h @@ -42,7 +42,9 @@ class DrawViewCollection; class DrawViewSpreadsheet; class DrawViewImage; class DrawLeaderLine; -class DrawViewBalloon;} +class DrawViewBalloon; +class DrawRichAnno; +} namespace TechDrawGui { @@ -52,6 +54,7 @@ class QGITemplate; class ViewProviderPage; class QGIViewBalloon; class QGILeaderLine; +class QGIRichAnno; class TechDrawGuiExport QGVPage : public QGraphicsView { @@ -79,6 +82,7 @@ class TechDrawGuiExport QGVPage : public QGraphicsView QGIView * addDrawViewSpreadsheet(TechDraw::DrawViewSpreadsheet *view); QGIView * addDrawViewImage(TechDraw::DrawViewImage *view); QGIView * addViewLeader(TechDraw::DrawLeaderLine* view); + QGIView * addRichAnno(TechDraw::DrawRichAnno* anno); QGIView* findQViewForDocObj(App::DocumentObject *obj) const; QGIView* getQGIVByName(std::string name); @@ -86,6 +90,8 @@ class TechDrawGuiExport QGVPage : public QGraphicsView void addBalloonToParent(QGIViewBalloon* balloon, QGIView* parent); void addDimToParent(QGIViewDimension* dim, QGIView* parent); + void addLeaderToParent(QGILeaderLine* lead, QGIView* parent); + // const std::vector & getViews() const { return views; } //only used in MDIVP std::vector getViews() const; //only used in MDIVP diff --git a/src/Mod/TechDraw/Gui/TaskTextLeader.cpp b/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp similarity index 68% rename from src/Mod/TechDraw/Gui/TaskTextLeader.cpp rename to src/Mod/TechDraw/Gui/TaskLeaderLine.cpp index 82259fd97187..0d4057d5acc2 100644 --- a/src/Mod/TechDraw/Gui/TaskTextLeader.cpp +++ b/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp @@ -45,9 +45,9 @@ #include #include #include -#include +#include -#include +#include #include "DrawGuiStd.h" #include "QGVPage.h" @@ -58,25 +58,20 @@ #include "ViewProviderLeader.h" #include "QGTracker.h" #include "QGEPath.h" -#include "QGMText.h" -#include "QGITextLeader.h" +#include "QGILeaderLine.h" #include "Rez.h" -#include "mrichtextedit.h" -#include "mtextedit.h" -#include "TaskTextLeader.h" +#include "TaskLeaderLine.h" using namespace Gui; using namespace TechDraw; using namespace TechDrawGui; //ctor for edit -TaskTextLeader::TaskTextLeader(int mode, - TechDrawGui::ViewProviderLeader* leadVP) : - ui(new Ui_TaskTextLeader), +TaskLeaderLine::TaskLeaderLine(TechDrawGui::ViewProviderLeader* leadVP) : + ui(new Ui_TaskLeaderLine), m_tracker(nullptr), m_lineVP(leadVP), - m_textVP(nullptr), m_baseFeat(nullptr), m_basePage(nullptr), m_lineFeat(nullptr), @@ -84,24 +79,16 @@ TaskTextLeader::TaskTextLeader(int mode, m_leadLine(nullptr), m_inProgressLock(false), m_qgLine(nullptr), - m_qgText(nullptr), - m_textDialog(nullptr), - m_rte(nullptr), - m_mode(mode), m_pbTrackerState(TRACKEREDIT) { if (m_lineVP == nullptr) { //should be caught in CMD caller - Base::Console().Error("TaskTextLeader - bad parameters. Can not proceed.\n"); + Base::Console().Error("TaskLeaderLine - bad parameters. Can not proceed.\n"); return; } ui->setupUi(this); m_lineFeat = m_lineVP->getFeature(); - if (m_mode == TEXTMODE) { - m_textFeat = static_cast(m_lineFeat); - m_textVP = static_cast(m_lineVP); - } App::DocumentObject* obj = m_lineFeat->LeaderParent.getValue(); if ( obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId()) ) { @@ -109,10 +96,11 @@ TaskTextLeader::TaskTextLeader(int mode, } m_basePage = m_lineFeat->findParentPage(); + //TODO: when/if leaders are allowed to be parented to Page, check for m_baseFeat will be removed if ( (m_lineFeat == nullptr) || (m_baseFeat == nullptr) || (m_basePage == nullptr) ) { - Base::Console().Error("TaskTextLeader - bad parameters (2). Can not proceed.\n"); + Base::Console().Error("TaskLeaderLine - bad parameters (2). Can not proceed.\n"); return; } @@ -128,19 +116,14 @@ TaskTextLeader::TaskTextLeader(int mode, connect(ui->pbTracker, SIGNAL(clicked(bool)), this, SLOT(onTrackerClicked(bool))); - if (m_mode == TEXTMODE) { - connect(ui->pbEditor, SIGNAL(clicked(bool)), - this, SLOT(onEditorClicked(bool))); - } m_trackerMode = QGTracker::TrackerMode::Line; } //ctor for creation -TaskTextLeader::TaskTextLeader(int mode, - TechDraw::DrawView* baseFeat, +TaskLeaderLine::TaskLeaderLine(TechDraw::DrawView* baseFeat, TechDraw::DrawPage* page) : - ui(new Ui_TaskTextLeader), + ui(new Ui_TaskLeaderLine), m_tracker(nullptr), m_lineVP(nullptr), m_baseFeat(baseFeat), @@ -150,16 +133,12 @@ TaskTextLeader::TaskTextLeader(int mode, m_leadLine(nullptr), m_inProgressLock(false), m_qgLine(nullptr), - m_qgText(nullptr), - m_textDialog(nullptr), - m_rte(nullptr), - m_mode(mode), m_pbTrackerState(TRACKERPICK) { if ( (m_basePage == nullptr) || (m_baseFeat == nullptr) ) { //should be caught in CMD caller - Base::Console().Error("TaskTextLeader - bad parameters. Can not proceed.\n"); + Base::Console().Error("TaskLeaderLine - bad parameters. Can not proceed.\n"); return; } @@ -176,44 +155,34 @@ TaskTextLeader::TaskTextLeader(int mode, connect(ui->pbTracker, SIGNAL(clicked(bool)), this, SLOT(onTrackerClicked(bool))); - if (mode == TEXTMODE) { - connect(ui->pbEditor, SIGNAL(clicked(bool)), - this, SLOT(onEditorClicked(bool))); - } m_trackerMode = QGTracker::TrackerMode::Line; } -TaskTextLeader::~TaskTextLeader() +TaskLeaderLine::~TaskLeaderLine() { delete ui; } -void TaskTextLeader::updateTask() +void TaskLeaderLine::updateTask() { // blockUpdate = true; // blockUpdate = false; } -void TaskTextLeader::changeEvent(QEvent *e) +void TaskLeaderLine::changeEvent(QEvent *e) { if (e->type() == QEvent::LanguageChange) { ui->retranslateUi(this); } } -void TaskTextLeader::setUiPrimary() +void TaskLeaderLine::setUiPrimary() { -// Base::Console().Message("TTL::setUiPrimary() - m_mode: %d\n",m_mode); +// Base::Console().Message("TTL::setUiPrimary()\n"); enableVPUi(false); - if (m_mode == TEXTMODE) { - setWindowTitle(QObject::tr("New Text Leader")); - enableTextUi(true); - } else { - setWindowTitle(QObject::tr("New Leader Line")); - enableTextUi(false); - } + setWindowTitle(QObject::tr("New Leader Line")); if (m_baseFeat != nullptr) { std::string baseName = m_baseFeat->getNameInDocument(); @@ -225,31 +194,19 @@ void TaskTextLeader::setUiPrimary() ui->cboxStartSym->setCurrentIndex(aSize); } -void TaskTextLeader::enableTextUi(bool b) -{ - ui->pbEditor->setEnabled(b); - ui->teLeaderText->setEnabled(b); -} - -void TaskTextLeader::enableVPUi(bool b) +void TaskLeaderLine::enableVPUi(bool b) { ui->cpLineColor->setEnabled(b); ui->dsbWeight->setEnabled(b); ui->cboxStyle->setEnabled(b); } -void TaskTextLeader::setUiEdit() +void TaskLeaderLine::setUiEdit() { -// Base::Console().Message("TTL::setUiEdit() - m_mode: %d\n",m_mode); +// Base::Console().Message("TTL::setUiEdit()\n"); enableVPUi(true); - if (m_mode == TEXTMODE) { - setWindowTitle(QObject::tr("Edit Text Leader")); - enableTextUi(true); - } else { - setWindowTitle(QObject::tr("Edit Leader Line")); - enableTextUi(false); - } - + setWindowTitle(QObject::tr("Edit Leader Line")); + if (m_lineFeat != nullptr) { std::string baseName = m_lineFeat->LeaderParent.getValue()->getNameInDocument(); ui->leBaseView->setText(Base::Tools::fromStdString(baseName)); @@ -258,67 +215,21 @@ void TaskTextLeader::setUiEdit() ui->pbTracker->setText(QString::fromUtf8("Edit points")); ui->pbTracker->setEnabled(true); } - + if (m_lineVP != nullptr) { ui->cpLineColor->setColor(m_lineVP->Color.getValue().asValue()); ui->dsbWeight->setValue(m_lineVP->LineWidth.getValue()); ui->cboxStyle->setCurrentIndex(m_lineVP->LineStyle.getValue()); } - - if (m_textFeat != nullptr) { - ui->teLeaderText->setHtml(QString::fromUtf8(m_textFeat->LeaderText.getValue())); - } -} - -void TaskTextLeader::onEditorClicked(bool b) -{ -// Base::Console().Message("TL::onEditorClicked(%d)\n",b); - Q_UNUSED(b); - m_textDialog = new QDialog(0); - QString leadText = ui->teLeaderText->toHtml(); - m_rte = new MRichTextEdit(m_textDialog, leadText); - //m_rte->setTextWidth(m_lineVP->MaxWidth); - QGridLayout* gl = new QGridLayout(m_textDialog); - gl->addWidget(m_rte,0,0,1,1); - m_textDialog->setWindowTitle(QObject::tr("Leader text editor")); - m_textDialog->setMinimumWidth (400); - m_textDialog->setMinimumHeight(400); - - connect(m_rte, SIGNAL(saveText(QString)), - this, SLOT(onSaveAndExit(QString))); - connect(m_rte, SIGNAL(editorFinished(void)), - this, SLOT(onEditorExit(void))); - - m_textDialog->show(); } -void TaskTextLeader::onSaveAndExit(QString qs) -{ - ui->teLeaderText->setHtml(qs); - //dialog clean up should be handled by accept() call in dialog - m_textDialog->accept(); - m_textDialog = nullptr; - m_rte = nullptr; -} - -void TaskTextLeader::onEditorExit(void) -{ - m_textDialog->reject(); - m_textDialog = nullptr; - m_rte = nullptr; -} //****************************************************************************** -void TaskTextLeader::createLeaderFeature(std::vector converted) +void TaskLeaderLine::createLeaderFeature(std::vector converted) { - Base::Console().Message("TTL::createLeaderFeature() - m_mode: %d\n",m_mode); - if (m_mode == TEXTMODE) { - m_leaderName = m_basePage->getDocument()->getUniqueObjectName("DrawTextLeader"); - m_leaderType = "TechDraw::DrawTextLeader"; - } else { - m_leaderName = m_basePage->getDocument()->getUniqueObjectName("DrawLeaderLine"); - m_leaderType = "TechDraw::DrawLeaderLine"; - } +// Base::Console().Message("TTL::createLeaderFeature()\n"); + m_leaderName = m_basePage->getDocument()->getUniqueObjectName("DrawLeaderLine"); + m_leaderType = "TechDraw::DrawLeaderLine"; std::string PageName = m_basePage->getNameInDocument(); @@ -332,18 +243,10 @@ void TaskTextLeader::createLeaderFeature(std::vector converted) App::DocumentObject* obj = m_basePage->getDocument()->getObject(m_leaderName.c_str()); if (obj == nullptr) { - throw Base::RuntimeError("TaskTextLeader - new markup object not found"); + throw Base::RuntimeError("TaskLeaderLine - new markup object not found"); } - if (obj->isDerivedFrom(TechDraw::DrawTextLeader::getClassTypeId())) { - m_lineFeat = static_cast(obj); - m_textFeat = static_cast(obj); - commonFeatureUpdate(converted); - QPointF qTemp = calcTextStartPos(m_lineFeat->getScale()); - Base::Vector3d vTemp(qTemp.x(), qTemp.y()); - m_textFeat->TextPosition.setValue(Rez::appX(vTemp)); - } else if (obj->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId())) { + if (obj->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId())) { m_lineFeat = static_cast(obj); - m_textFeat = nullptr; commonFeatureUpdate(converted); } @@ -352,9 +255,9 @@ void TaskTextLeader::createLeaderFeature(std::vector converted) m_lineFeat->requestPaint(); } -void TaskTextLeader::updateLeaderFeature(std::vector converted) +void TaskLeaderLine::updateLeaderFeature(std::vector converted) { -// Base::Console().Message("TTL::updateLeaderFeature(%d) - m_mode: %d\n",converted.size(),m_mode); +// Base::Console().Message("TTL::updateLeaderFeature(%d)\n",converted.size()); Gui::Command::openCommand("Edit Leader"); commonFeatureUpdate(converted); App::Color ac; @@ -367,29 +270,28 @@ void TaskTextLeader::updateLeaderFeature(std::vector converted) m_lineFeat->requestPaint(); } -void TaskTextLeader::commonFeatureUpdate(std::vector converted) +void TaskLeaderLine::commonFeatureUpdate(std::vector converted) { // Base::Console().Message("TTL::commonFeatureUpdate()\n"); m_lineFeat->setPosition(Rez::appX(m_attachPoint.x),Rez::appX(- m_attachPoint.y), true); if (!converted.empty()) { m_lineFeat->WayPoints.setValues(converted); + if (m_lineFeat->AutoHorizontal.getValue()) { + m_lineFeat->adjustLastSegment(); + } } int start = ui->cboxStartSym->currentIndex() - 1; int end = ui->cboxEndSym->currentIndex() - 1; m_lineFeat->StartSymbol.setValue(start); m_lineFeat->EndSymbol.setValue(end); - if (m_mode == TEXTMODE) { - m_textFeat->LeaderText.setValue(ui->teLeaderText->toHtml().toUtf8()); - } } -void TaskTextLeader::removeFeature(void) +void TaskLeaderLine::removeFeature(void) { // Base::Console().Message("TTL::removeFeature()\n"); if (m_lineFeat != nullptr) { if (m_createMode) { try { - // this doesn't remove the QGMText item?? std::string PageName = m_basePage->getNameInDocument(); Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().%s.removeView(App.activeDocument().%s)", PageName.c_str(),m_lineFeat->getNameInDocument()); @@ -405,62 +307,18 @@ void TaskTextLeader::removeFeature(void) std::vector undos = Gui::Application::Instance->activeDocument()->getUndoVector(); Gui::Application::Instance->activeDocument()->undo(1); } else { - Base::Console().Log("TaskTextLeader: Edit mode - NO command is active\n"); + Base::Console().Log("TaskLeaderLine: Edit mode - NO command is active\n"); } } } } -//we don't know the bounding rect of the text, so we have to calculate a reasonable -//guess at the size of the text block. -QPointF TaskTextLeader::calcTextStartPos(double scale) -{ -// Base::Console().Message("TTL::calcTextStartPos(%.3f) - m_mode: %d\n", scale, m_mode); - double textWidth = 100.0; - double textHeight = 20.0; - double horizGap(20.0); - double tPosX(0.0); - double tPosY(0.0); - - Gui::ViewProvider* vp = QGIView::getViewProvider(m_textFeat); - if (vp != nullptr) { - ViewProviderTextLeader* vpl = dynamic_cast(vp); - if (vpl != nullptr) { - double adjust = 2.0; - double fsize = vpl->Fontsize.getValue(); - textHeight = fsize * adjust; - double width = vpl->MaxWidth.getValue(); - if (width > 0 ) { - textWidth = width; - } - } - } - - if (!m_trackerPoints.empty() ) { - QPointF lastPoint(m_trackerPoints.back().x, m_trackerPoints.back().y); - QPointF firstPoint(m_trackerPoints.front().x, m_trackerPoints.front().y); - QPointF lastOffset = lastPoint; - lastPoint = m_qgParent->mapFromScene(lastPoint) * scale; - firstPoint = m_qgParent->mapFromScene(firstPoint) * scale; - - if (lastPoint.x() < firstPoint.x()) { //last is left of first - tPosX = lastOffset.x() - horizGap - textWidth; //left of last - tPosY = lastOffset.y() - textHeight; - } else { //last is right of first - tPosX = lastOffset.x() + horizGap; //right of last - tPosY = lastOffset.y() - textHeight; - } - } - QPointF result(tPosX, -tPosY); - return result; -} - //********** Tracker routines ******************************************************************* -void TaskTextLeader::onTrackerClicked(bool b) +void TaskLeaderLine::onTrackerClicked(bool b) { Q_UNUSED(b); -// Base::Console().Message("TTL::onTrackerClicked() - m_mode: %d, m_pbTrackerState: %d\n", -// m_mode, m_pbTrackerState); +// Base::Console().Message("TTL::onTrackerClicked() m_pbTrackerState: %d\n", +// m_pbTrackerState); if (m_pbTrackerState == TRACKERCANCEL) { removeTracker(); @@ -486,6 +344,7 @@ void TaskTextLeader::onTrackerClicked(bool b) m_saveContextPolicy = m_mdi->contextMenuPolicy(); m_mdi->setContextMenuPolicy(Qt::PreventContextMenu); m_trackerMode = QGTracker::TrackerMode::Line; + setEditCursor(Qt::CrossCursor); startTracker(); QString msg = tr("Pick a starting point for leader line"); @@ -507,7 +366,7 @@ void TaskTextLeader::onTrackerClicked(bool b) if (qgLead == nullptr) { //tarfu - Base::Console().Error("TaskTextLeader - can't find leader graphic\n"); + Base::Console().Error("TaskLeaderLine - can't find leader graphic\n"); //now what? throw will generate "unknown unhandled exception" } else { m_qgLine = qgLead; @@ -535,6 +394,7 @@ void TaskTextLeader::onTrackerClicked(bool b) m_saveContextPolicy = m_mdi->contextMenuPolicy(); m_mdi->setContextMenuPolicy(Qt::PreventContextMenu); m_trackerMode = QGTracker::TrackerMode::Line; + setEditCursor(Qt::CrossCursor); startTracker(); QString msg = tr("Pick a starting point for leader line"); @@ -548,7 +408,7 @@ void TaskTextLeader::onTrackerClicked(bool b) } //end edit mode } -void TaskTextLeader::startTracker(void) +void TaskLeaderLine::startTracker(void) { // Base::Console().Message("TTL::startTracker()\n"); if (m_trackerMode == QGTracker::TrackerMode::None) { @@ -571,11 +431,11 @@ void TaskTextLeader::startTracker(void) Gui::getMainWindow()->showMessage(msg,3000); } -void TaskTextLeader::onTrackerFinished(std::vector pts, QGIView* qgParent) +void TaskLeaderLine::onTrackerFinished(std::vector pts, QGIView* qgParent) { // Base::Console().Message("TTL::onTrackerFinished()\n"); if (pts.empty()) { - Base::Console().Error("TaskTextLeader - no points available\n"); + Base::Console().Error("TaskLeaderLine - no points available\n"); return; } QGIView* qgiv = dynamic_cast(qgParent); @@ -601,7 +461,7 @@ void TaskTextLeader::onTrackerFinished(std::vector pts, QGIView* qgPare setEditCursor(Qt::ArrowCursor); } -void TaskTextLeader::removeTracker(void) +void TaskLeaderLine::removeTracker(void) { // Base::Console().Message("TTL::removeTracker()\n"); if ( (m_tracker != nullptr) && @@ -612,7 +472,7 @@ void TaskTextLeader::removeTracker(void) } } -void TaskTextLeader::setEditCursor(QCursor c) +void TaskLeaderLine::setEditCursor(QCursor c) { if (m_baseFeat != nullptr) { QGIView* qgivBase = m_view->findQViewForDocObj(m_baseFeat); @@ -621,7 +481,7 @@ void TaskTextLeader::setEditCursor(QCursor c) } //from 1:1 scale scene QPointF to zero origin Vector3d points -void TaskTextLeader::convertTrackerPoints(std::vector pts) +void TaskLeaderLine::convertTrackerPoints(std::vector pts) { // Base::Console().Message("TTL::convertTrackerPoints(%d)\n", pts.size()); m_trackerPoints.clear(); @@ -633,7 +493,7 @@ void TaskTextLeader::convertTrackerPoints(std::vector pts) } //****************************************************************************** -void TaskTextLeader::onPointEditComplete(std::vector pts, QGIView* parent) +void TaskLeaderLine::onPointEditComplete(std::vector pts, QGIView* parent) { // Base::Console().Message("TTL::onPointEditComplete(%d)\n", pts.size()); if (pts.empty()) { @@ -667,7 +527,7 @@ void TaskTextLeader::onPointEditComplete(std::vector pts, QGIView* pare enableTaskButtons(true); } -void TaskTextLeader::abandonEditSession(void) +void TaskLeaderLine::abandonEditSession(void) { if (m_qgLine != nullptr) { m_qgLine->abandonEdit(); @@ -684,20 +544,20 @@ void TaskTextLeader::abandonEditSession(void) setEditCursor(Qt::ArrowCursor); } -void TaskTextLeader::saveButtons(QPushButton* btnOK, +void TaskLeaderLine::saveButtons(QPushButton* btnOK, QPushButton* btnCancel) { m_btnOK = btnOK; m_btnCancel = btnCancel; } -void TaskTextLeader::enableTaskButtons(bool b) +void TaskLeaderLine::enableTaskButtons(bool b) { m_btnOK->setEnabled(b); m_btnCancel->setEnabled(b); } -int TaskTextLeader::getPrefArrowStyle() +int TaskLeaderLine::getPrefArrowStyle() { Base::Reference hGrp = App::GetApplication().GetUserParameter(). GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); @@ -705,12 +565,11 @@ int TaskTextLeader::getPrefArrowStyle() return style; } - //****************************************************************************** -bool TaskTextLeader::accept() +bool TaskLeaderLine::accept() { -// Base::Console().Message("TTL::accept() - m_mode: %d\n", m_mode); +// Base::Console().Message("TTL::accept()\n"); if (m_inProgressLock) { // Base::Console().Message("TTL::accept - edit in progress!!\n"); abandonEditSession(); @@ -733,7 +592,7 @@ bool TaskTextLeader::accept() return true; } -bool TaskTextLeader::reject() +bool TaskLeaderLine::reject() { if (m_inProgressLock) { // Base::Console().Message("TTL::reject - edit in progress!!\n"); @@ -745,7 +604,9 @@ bool TaskTextLeader::reject() Gui::Document* doc = Gui::Application::Instance->getDocument(m_basePage->getDocument()); if (!doc) return false; - m_mdi->setContextMenuPolicy(m_saveContextPolicy); + if (m_mdi != nullptr) { + m_mdi->setContextMenuPolicy(m_saveContextPolicy); + } if (getCreateMode() && (m_lineFeat != nullptr) ) { removeFeature(); @@ -760,49 +621,37 @@ bool TaskTextLeader::reject() } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -TaskDlgTextLeader::TaskDlgTextLeader(int mode, - TechDraw::DrawView* baseFeat, +TaskDlgLeaderLine::TaskDlgLeaderLine(TechDraw::DrawView* baseFeat, TechDraw::DrawPage* page) : TaskDialog() { - widget = new TaskTextLeader(mode,baseFeat,page); - if (mode == TEXTMODE) { - taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-textleader"), - widget->windowTitle(), true, 0); - } else { //if (mode == 1) - taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-mline"), + widget = new TaskLeaderLine(baseFeat,page); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-mline"), widget->windowTitle(), true, 0); - } taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); } -TaskDlgTextLeader::TaskDlgTextLeader(int mode, - TechDrawGui::ViewProviderLeader* leadVP) +TaskDlgLeaderLine::TaskDlgLeaderLine(TechDrawGui::ViewProviderLeader* leadVP) : TaskDialog() { - widget = new TaskTextLeader(mode,leadVP); - if (mode == TEXTMODE) { - taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-textleader"), + widget = new TaskLeaderLine(leadVP); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-mline"), widget->windowTitle(), true, 0); - } else { //if (mode == 1) - taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-mline"), - widget->windowTitle(), true, 0); - } taskbox->groupLayout()->addWidget(widget); Content.push_back(taskbox); } -TaskDlgTextLeader::~TaskDlgTextLeader() +TaskDlgLeaderLine::~TaskDlgLeaderLine() { } -void TaskDlgTextLeader::update() +void TaskDlgLeaderLine::update() { // widget->updateTask(); } -void TaskDlgTextLeader::modifyStandardButtons(QDialogButtonBox* box) +void TaskDlgLeaderLine::modifyStandardButtons(QDialogButtonBox* box) { QPushButton* btnOK = box->button(QDialogButtonBox::Ok); QPushButton* btnCancel = box->button(QDialogButtonBox::Cancel); @@ -810,24 +659,24 @@ void TaskDlgTextLeader::modifyStandardButtons(QDialogButtonBox* box) } //==== calls from the TaskView =============================================================== -void TaskDlgTextLeader::open() +void TaskDlgLeaderLine::open() { } -void TaskDlgTextLeader::clicked(int) +void TaskDlgLeaderLine::clicked(int) { } -bool TaskDlgTextLeader::accept() +bool TaskDlgLeaderLine::accept() { widget->accept(); return true; } -bool TaskDlgTextLeader::reject() +bool TaskDlgLeaderLine::reject() { widget->reject(); return true; } -#include +#include diff --git a/src/Mod/TechDraw/Gui/TaskTextLeader.h b/src/Mod/TechDraw/Gui/TaskLeaderLine.h similarity index 82% rename from src/Mod/TechDraw/Gui/TaskTextLeader.h rename to src/Mod/TechDraw/Gui/TaskLeaderLine.h index 65b33bdb6b49..461fc36827e4 100644 --- a/src/Mod/TechDraw/Gui/TaskTextLeader.h +++ b/src/Mod/TechDraw/Gui/TaskLeaderLine.h @@ -28,7 +28,7 @@ #include #include -#include +#include #include "QGTracker.h" @@ -38,9 +38,7 @@ #define TRACKERCANCEL 2 #define TRACKERCANCELEDIT 3 -class MRichTextEdit; - -class Ui_TaskTextLeader; +class Ui_TaskLeaderLine; namespace App { class DocumentObject; @@ -50,12 +48,9 @@ namespace TechDraw { class DrawPage; class DrawView; -class DrawTextLeader; +class DrawLeaderLine; } -#define TEXTMODE 0 -#define LINEMODE 1 - namespace TechDrawGui { class QGVPage; @@ -65,26 +60,23 @@ class MDIViewPage; class QGTracker; class QGEPath; class QGMText; -class QGITextLeader; +class QGILeaderLine; class ViewProviderLeader; -class ViewProviderTextLeader; -class TaskTextLeader : public QWidget +class TaskLeaderLine : public QWidget { Q_OBJECT public: - TaskTextLeader(int mode, - TechDraw::DrawView* baseFeat, + TaskLeaderLine(TechDraw::DrawView* baseFeat, TechDraw::DrawPage* page); - TaskTextLeader(int mode, - TechDrawGui::ViewProviderLeader* leadVP); - ~TaskTextLeader(); + TaskLeaderLine(TechDrawGui::ViewProviderLeader* leadVP); + ~TaskLeaderLine(); public Q_SLOTS: void onTrackerClicked(bool b); void onTrackerFinished(std::vector pts, QGIView* qgParent); - void onEditorClicked(bool b); +/* void onEditorClicked(bool b);*/ /* void onViewPicked(QPointF pos, QGIView* qgParent);*/ public: @@ -101,8 +93,8 @@ public Q_SLOTS: protected Q_SLOTS: void convertTrackerPoints(std::vector pts); void onPointEditComplete(std::vector pts, QGIView* parent); - void onSaveAndExit(QString); - void onEditorExit(void); +/* void onSaveAndExit(QString);*/ +/* void onEditorExit(void);*/ protected: void changeEvent(QEvent *e); @@ -115,7 +107,7 @@ protected Q_SLOTS: void commonFeatureUpdate(std::vector converted); void removeFeature(void); - QPointF calcTextStartPos(double scale); +/* QPointF calcTextStartPos(double scale);*/ void blockButtons(bool b); void setUiPrimary(void); @@ -128,7 +120,7 @@ protected Q_SLOTS: private: - Ui_TaskTextLeader * ui; + Ui_TaskLeaderLine * ui; bool blockUpdate; QGTracker* m_tracker; @@ -137,10 +129,8 @@ protected Q_SLOTS: QGraphicsScene* m_scene; QGVPage* m_view; ViewProviderLeader* m_lineVP; - ViewProviderTextLeader* m_textVP; TechDraw::DrawView* m_baseFeat; TechDraw::DrawPage* m_basePage; - TechDraw::DrawTextLeader* m_textFeat; TechDraw::DrawLeaderLine* m_lineFeat; std::string m_leaderName; std::string m_leaderType; @@ -152,34 +142,27 @@ protected Q_SLOTS: bool m_createMode; QGEPath* m_leadLine; - QGMText* m_text; QGTracker::TrackerMode m_trackerMode; Qt::ContextMenuPolicy m_saveContextPolicy; bool m_inProgressLock; QGILeaderLine* m_qgLine; - QGITextLeader* m_qgText; QPushButton* m_btnOK; QPushButton* m_btnCancel; - QDialog* m_textDialog; - MRichTextEdit* m_rte; - int m_mode; int m_pbTrackerState; }; -class TaskDlgTextLeader : public Gui::TaskView::TaskDialog +class TaskDlgLeaderLine : public Gui::TaskView::TaskDialog { Q_OBJECT public: - TaskDlgTextLeader(int mode, - TechDraw::DrawView* baseFeat, + TaskDlgLeaderLine(TechDraw::DrawView* baseFeat, TechDraw::DrawPage* page); - TaskDlgTextLeader(int mode, - TechDrawGui::ViewProviderLeader* leadVP); - ~TaskDlgTextLeader(); + TaskDlgLeaderLine(TechDrawGui::ViewProviderLeader* leadVP); + ~TaskDlgLeaderLine(); public: /// is called the TaskView when the dialog is opened @@ -201,7 +184,7 @@ class TaskDlgTextLeader : public Gui::TaskView::TaskDialog protected: private: - TaskTextLeader * widget; + TaskLeaderLine * widget; Gui::TaskView::TaskBox* taskbox; }; diff --git a/src/Mod/TechDraw/Gui/TaskTextLeader.ui b/src/Mod/TechDraw/Gui/TaskLeaderLine.ui similarity index 90% rename from src/Mod/TechDraw/Gui/TaskTextLeader.ui rename to src/Mod/TechDraw/Gui/TaskLeaderLine.ui index 652428e1ba12..26711944f0b5 100644 --- a/src/Mod/TechDraw/Gui/TaskTextLeader.ui +++ b/src/Mod/TechDraw/Gui/TaskLeaderLine.ui @@ -1,13 +1,13 @@ - TechDrawGui::TaskTextLeader - + TechDrawGui::TaskLeaderLine + 0 0 409 - 560 + 405 @@ -23,11 +23,11 @@ - Text Leader + Leader Line - :/icons/actions/techdraw-textleader.svg:/icons/actions/techdraw-textleader.svg + :/icons/actions/techdraw-mline.svg:/icons/actions/techdraw-mline.svg @@ -132,6 +132,9 @@ + + 1 + No Symbol @@ -326,41 +329,23 @@ - - - - Qt::Horizontal - - - - - - - - Leader Text - - - - - - - true - - - Start Editor - - - - - - - + + + Qt::Vertical + + + + 20 + 40 + + + diff --git a/src/Mod/TechDraw/Gui/TaskRichAnno.cpp b/src/Mod/TechDraw/Gui/TaskRichAnno.cpp new file mode 100644 index 000000000000..f29d95dc0995 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskRichAnno.cpp @@ -0,0 +1,560 @@ +/*************************************************************************** + * Copyright (c) 2019 Wandererfan +#endif // #ifndef _PreComp_ + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include "DrawGuiStd.h" +#include "QGVPage.h" +#include "QGIView.h" +#include "QGIPrimPath.h" +#include "MDIViewPage.h" +#include "ViewProviderPage.h" +#include "ViewProviderRichAnno.h" +#include "QGMText.h" +#include "QGIRichAnno.h" +#include "Rez.h" +#include "mrichtextedit.h" +#include "mtextedit.h" + +#include "TaskRichAnno.h" + +using namespace Gui; +using namespace TechDraw; +using namespace TechDrawGui; + +//ctor for edit +TaskRichAnno::TaskRichAnno(TechDrawGui::ViewProviderRichAnno* annoVP) : + ui(new Ui_TaskRichAnno), + m_annoVP(annoVP), + m_baseFeat(nullptr), + m_basePage(nullptr), + m_annoFeat(nullptr), + m_createMode(false), + m_inProgressLock(false), + m_qgAnno(nullptr), + m_textDialog(nullptr), + m_rte(nullptr) +{ + if (m_annoVP == nullptr) { + //should be caught in CMD caller + Base::Console().Error("TaskRichAnno - bad parameters. Can not proceed.\n"); + return; + } + ui->setupUi(this); + + m_annoFeat = m_annoVP->getFeature(); + + //m_baseFeat can be null + App::DocumentObject* obj = m_annoFeat->AnnoParent.getValue(); + if (obj != nullptr) { + if ( obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId()) ) { + m_baseFeat = static_cast(m_annoFeat->AnnoParent.getValue()); + } + } + m_basePage = m_annoFeat->findParentPage(); + if ( m_basePage == nullptr ) { + Base::Console().Error("TaskRichAnno - bad parameters (2). Can not proceed.\n"); + return; + } + + setUiEdit(); +// m_title = QObject::tr("Rich text editor"); + + m_mdi = m_annoVP->getMDIViewPage(); + m_scene = m_mdi->m_scene; + m_view = m_mdi->getQGVPage(); + if (m_baseFeat != nullptr) { + m_qgParent = m_view->findQViewForDocObj(m_baseFeat); + } + + m_saveContextPolicy = m_mdi->contextMenuPolicy(); + + m_attachPoint = Rez::guiX(Base::Vector3d(m_annoFeat->X.getValue(), + -m_annoFeat->Y.getValue(), + 0.0)); + + connect(ui->pbEditor, SIGNAL(clicked(bool)), + this, SLOT(onEditorClicked(bool))); +} + +//ctor for creation +TaskRichAnno::TaskRichAnno(TechDraw::DrawView* baseFeat, + TechDraw::DrawPage* page) : + ui(new Ui_TaskRichAnno), + m_annoVP(nullptr), + m_baseFeat(baseFeat), + m_basePage(page), + m_annoFeat(nullptr), + m_createMode(true), + m_inProgressLock(false), + m_qgAnno(nullptr), + m_textDialog(nullptr), + m_rte(nullptr) +{ + if (m_basePage == nullptr) { + //should be caught in CMD caller + Base::Console().Error("TaskRichAnno - bad parameters. Can not proceed.\n"); + return; + } + + ui->setupUi(this); + m_title = QObject::tr("Rich text creator"); + + Gui::Document* activeGui = Gui::Application::Instance->getDocument(m_basePage->getDocument()); + Gui::ViewProvider* vp = activeGui->getViewProvider(m_basePage); + ViewProviderPage* vpp = static_cast(vp); + m_mdi = vpp->getMDIViewPage(); + m_scene = m_mdi->m_scene; + m_view = m_mdi->getQGVPage(); + if (baseFeat != nullptr) { + m_qgParent = m_view->findQViewForDocObj(baseFeat); + } + + m_saveContextPolicy = m_mdi->contextMenuPolicy(); + + setUiPrimary(); + + connect(ui->pbEditor, SIGNAL(clicked(bool)), + this, SLOT(onEditorClicked(bool))); +} + +TaskRichAnno::~TaskRichAnno() +{ + delete ui; +} + +void TaskRichAnno::updateTask() +{ +// blockUpdate = true; + +// blockUpdate = false; +} + +void TaskRichAnno::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } +} + +void TaskRichAnno::setUiPrimary() +{ +// Base::Console().Message("TRA::setUiPrimary()\n"); + enableVPUi(false); + setWindowTitle(m_title); + + if (m_baseFeat != nullptr) { + std::string baseName = m_baseFeat->getNameInDocument(); + ui->leBaseView->setText(Base::Tools::fromStdString(baseName)); + } +} + +void TaskRichAnno::enableTextUi(bool b) +{ + ui->pbEditor->setEnabled(b); + ui->teAnnoText->setEnabled(b); +} + +void TaskRichAnno::enableVPUi(bool b) +{ + Q_UNUSED(b); +// ui->cpLineColor->setEnabled(b); +// ui->dsbWeight->setEnabled(b); +// ui->cboxStyle->setEnabled(b); +} + +void TaskRichAnno::setUiEdit() +{ +// Base::Console().Message("TRA::setUiEdit()); + enableVPUi(true); + setWindowTitle(m_title); + enableTextUi(true); + + if (m_annoFeat != nullptr) { + std::string baseName("None"); + App::DocumentObject* docObj = m_annoFeat->AnnoParent.getValue(); + if (docObj != nullptr) { + baseName = docObj->getNameInDocument(); + } + ui->leBaseView->setText(Base::Tools::fromStdString(baseName)); + ui->teAnnoText->setHtml(QString::fromUtf8(m_annoFeat->AnnoText.getValue())); + ui->dsbMaxWidth->setValue(m_annoFeat->MaxWidth.getValue()); + ui->cbShowFrame->setChecked(m_annoFeat->ShowFrame.getValue()); + } + + if (m_annoVP != nullptr) { +// ui->cpLineColor->setColor(m_annoVP->Color.getValue().asValue()); +// ui->dsbWeight->setValue(m_annoVP->LineWidth.getValue()); +// ui->cboxStyle->setCurrentIndex(m_annoVP->LineStyle.getValue()); + } +} + +void TaskRichAnno::onEditorClicked(bool b) +{ +// Base::Console().Message("TL::onEditorClicked(%d)\n",b); + Q_UNUSED(b); + m_textDialog = new QDialog(0); + QString leadText = ui->teAnnoText->toHtml(); + m_rte = new MRichTextEdit(m_textDialog, leadText); + //m_rte->setTextWidth(m_annoVP->MaxWidth); + QGridLayout* gl = new QGridLayout(m_textDialog); + gl->addWidget(m_rte,0,0,1,1); + m_textDialog->setWindowTitle(QObject::tr("Rich text editor")); + m_textDialog->setMinimumWidth (400); + m_textDialog->setMinimumHeight(400); + + connect(m_rte, SIGNAL(saveText(QString)), + this, SLOT(onSaveAndExit(QString))); + connect(m_rte, SIGNAL(editorFinished(void)), + this, SLOT(onEditorExit(void))); + +// m_textDialog->setFont(m_annoVP->Font.getValue()); +// m_textDialog->setFontSize(m_annoVP->FontSize.getValue()); + m_textDialog->show(); +} + +void TaskRichAnno::onSaveAndExit(QString qs) +{ + ui->teAnnoText->setHtml(qs); + //dialog clean up should be handled by accept() call in dialog + m_textDialog->accept(); + m_textDialog = nullptr; + m_rte = nullptr; +} + +void TaskRichAnno::onEditorExit(void) +{ + m_textDialog->reject(); + m_textDialog = nullptr; + m_rte = nullptr; +} + +//****************************************************************************** +void TaskRichAnno::createAnnoFeature() +{ +// Base::Console().Message("TRA::createAnnoFeature()"); + std::string annoName = m_basePage->getDocument()->getUniqueObjectName("DrawRichAnno"); + std::string annoType = "TechDraw::DrawRichAnno"; + + std::string PageName = m_basePage->getNameInDocument(); + + Gui::Command::openCommand("Create Leader"); + Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", + annoType.c_str(),annoName.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)", + PageName.c_str(),annoName.c_str()); + + if (m_baseFeat != nullptr) { + Command::doCommand(Command::Doc,"App.activeDocument().%s.AnnoParent = App.activeDocument().%s", + annoName.c_str(),m_baseFeat->getNameInDocument()); + } + App::DocumentObject* obj = m_basePage->getDocument()->getObject(annoName.c_str()); + if (obj == nullptr) { + throw Base::RuntimeError("TaskRichAnno - new RichAnno object not found"); + } + if (obj->isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId())) { + m_annoFeat = static_cast(obj); + commonFeatureUpdate(); + QPointF qTemp = calcTextStartPos(m_annoFeat->getScale()); + Base::Vector3d vTemp(qTemp.x(), qTemp.y()); +// m_annoFeat->TextPosition.setValue(Rez::appX(vTemp)); + m_annoFeat->X.setValue(Rez::appX(vTemp.x)); + m_annoFeat->Y.setValue(Rez::appX(vTemp.y)); + } + + Gui::Command::updateActive(); + Gui::Command::commitCommand(); + m_annoFeat->requestPaint(); +} + +void TaskRichAnno::updateAnnoFeature() +{ +// Base::Console().Message("TRA::updateAnnoFeature()\n"); + Gui::Command::openCommand("Edit Leader"); + commonFeatureUpdate(); +// App::Color ac; +// ac.setValue(ui->cpLineColor->color()); +// m_annoVP->Color.setValue(ac); + + Gui::Command::commitCommand(); + m_annoFeat->requestPaint(); +} + +void TaskRichAnno::commonFeatureUpdate(void) +{ +// Base::Console().Message("TRA::commonFeatureUpdate()\n"); + m_annoFeat->setPosition(Rez::appX(m_attachPoint.x),Rez::appX(- m_attachPoint.y), true); + m_annoFeat->AnnoText.setValue(ui->teAnnoText->toHtml().toUtf8()); + m_annoFeat->MaxWidth.setValue(ui->dsbMaxWidth->value()); + m_annoFeat->ShowFrame.setValue(ui->cbShowFrame->isChecked()); +} + +void TaskRichAnno::removeFeature(void) +{ +// Base::Console().Message("TRA::removeFeature()\n"); + if (m_annoFeat != nullptr) { + if (m_createMode) { + try { + // this doesn't remove the QGMText item?? + std::string PageName = m_basePage->getNameInDocument(); + Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().%s.removeView(App.activeDocument().%s)", + PageName.c_str(),m_annoFeat->getNameInDocument()); + Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().removeObject('%s')", + m_annoFeat->getNameInDocument()); + } + catch (...) { + Base::Console().Warning("TRA::removeFeature - failed to delete feature\n"); + return; + } + } else { + if (Gui::Command::hasPendingCommand()) { + std::vector undos = Gui::Application::Instance->activeDocument()->getUndoVector(); + Gui::Application::Instance->activeDocument()->undo(1); + } else { + Base::Console().Log("TaskRichAnno: Edit mode - NO command is active\n"); + } + } + } +} + +//we don't know the bounding rect of the text, so we have to calculate a reasonable +//guess at the size of the text block. +QPointF TaskRichAnno::calcTextStartPos(double scale) +{ +// Base::Console().Message("TRA::calcTextStartPos(%.3f)\n", scale); + double textWidth = 100.0; + double textHeight = 20.0; + double horizGap(20.0); + double tPosX(0.0); + double tPosY(0.0); + + Gui::ViewProvider* vp = QGIView::getViewProvider(m_annoFeat); + + if (vp != nullptr) { + ViewProviderRichAnno* vpra = dynamic_cast(vp); + if (vpra != nullptr) { + double adjust = 2.0; + double fsize = vpra->Fontsize.getValue(); + textHeight = fsize * adjust; + double width = m_annoFeat->MaxWidth.getValue(); + if (width > 0 ) { + textWidth = width; + } + } + } + + std::vector points; + if (m_baseFeat != nullptr) { + if (m_baseFeat->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId())) { + TechDraw::DrawLeaderLine* dll = dynamic_cast(m_baseFeat); + points = dll->WayPoints.getValues(); + } else { + Base::Console().Log("TRA::calcTextPos - m_baseFeat is not Leader\n"); + QPointF result(0.0,0.0); + return result; + } + } else { + if (m_basePage != nullptr) { + double w = Rez::guiX(m_basePage->getPageWidth() / 2.0); + double h = Rez::guiX(m_basePage->getPageHeight() / 2.0); + QPointF result(w,h); + return result; + } + } + + if (!points.empty()) { + QPointF lastPoint(points.back().x, points.back().y); + QPointF firstPoint(points.front().x, points.front().y); + QPointF lastOffset = lastPoint; + lastPoint = m_qgParent->mapFromScene(lastPoint) * scale; + firstPoint = m_qgParent->mapFromScene(firstPoint) * scale; + + if (lastPoint.x() < firstPoint.x()) { //last is left of first + tPosX = lastOffset.x() - horizGap - textWidth; //left of last + tPosY = lastOffset.y() - textHeight; + } else { //last is right of first + tPosX = lastOffset.x() + horizGap; //right of last + tPosY = lastOffset.y() - textHeight; + } + } + QPointF result(tPosX, -tPosY); + return result; +} + +void TaskRichAnno::saveButtons(QPushButton* btnOK, + QPushButton* btnCancel) +{ + m_btnOK = btnOK; + m_btnCancel = btnCancel; +} + +void TaskRichAnno::enableTaskButtons(bool b) +{ + m_btnOK->setEnabled(b); + m_btnCancel->setEnabled(b); +} + +//****************************************************************************** + +bool TaskRichAnno::accept() +{ +// Base::Console().Message("TRA::accept()\n"); + if (m_inProgressLock) { +// Base::Console().Message("TRA::accept - edit in progress!!\n"); + //TODO: kill MRTE dialog? + return true; + } + + Gui::Document* doc = Gui::Application::Instance->getDocument(m_basePage->getDocument()); + if (!doc) return false; + + if (!getCreateMode()) { + updateAnnoFeature(); + } else { + createAnnoFeature(); + } + m_mdi->setContextMenuPolicy(m_saveContextPolicy); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + + return true; +} + +bool TaskRichAnno::reject() +{ + Base::Console().Message("TRA::reject()\n"); + if (m_inProgressLock) { +// Base::Console().Message("TRA::reject - edit in progress!!\n"); + return false; + } + + if (m_basePage != nullptr) { + Gui::Document* doc = Gui::Application::Instance->getDocument(m_basePage->getDocument()); + if (!doc) { + return false; + } + + Base::Console().Message("TRA::reject() - m_mdi: %X\n", m_mdi); + if (m_mdi != nullptr) { + m_mdi->setContextMenuPolicy(m_saveContextPolicy); + } + if (getCreateMode() && + (m_annoFeat != nullptr) ) { + removeFeature(); + } + } + + //make sure any dangling objects are cleaned up + Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().recompute()"); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + + return false; +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +TaskDlgRichAnno::TaskDlgRichAnno(TechDraw::DrawView* baseFeat, + TechDraw::DrawPage* page) + : TaskDialog() +{ + widget = new TaskRichAnno(baseFeat,page); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-textleader"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskDlgRichAnno::TaskDlgRichAnno(TechDrawGui::ViewProviderRichAnno* leadVP) + : TaskDialog() +{ + widget = new TaskRichAnno(leadVP); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-textleader"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskDlgRichAnno::~TaskDlgRichAnno() +{ +} + +void TaskDlgRichAnno::update() +{ +// widget->updateTask(); +} + +void TaskDlgRichAnno::modifyStandardButtons(QDialogButtonBox* box) +{ + QPushButton* btnOK = box->button(QDialogButtonBox::Ok); + QPushButton* btnCancel = box->button(QDialogButtonBox::Cancel); + widget->saveButtons(btnOK, btnCancel); +} + +//==== calls from the TaskView =============================================================== +void TaskDlgRichAnno::open() +{ +} + +void TaskDlgRichAnno::clicked(int) +{ +} + +bool TaskDlgRichAnno::accept() +{ + widget->accept(); + return true; +} + +bool TaskDlgRichAnno::reject() +{ + widget->reject(); + return true; +} + +#include diff --git a/src/Mod/TechDraw/Gui/TaskRichAnno.h b/src/Mod/TechDraw/Gui/TaskRichAnno.h new file mode 100644 index 000000000000..96ae2d0dc968 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskRichAnno.h @@ -0,0 +1,170 @@ +/*************************************************************************** + * Copyright (c) 2019 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_TASKRICHANNO_H +#define TECHDRAWGUI_TASKRICHANNO_H + +#include +#include +#include +#include + +#include + +class MRichTextEdit; + +class Ui_TaskRichAnno; + +namespace App { +class DocumentObject; +} + +namespace TechDraw +{ +class DrawPage; +class DrawView; +class DrawRichAnno; +} + +namespace TechDrawGui +{ +class QGVPage; +class QGIView; +class QGIPrimPath; +class MDIViewPage; +class QGMText; +class QGIRichAnno; +class ViewProviderRichAnno; + +class TaskRichAnno : public QWidget +{ + Q_OBJECT + +public: + TaskRichAnno(TechDraw::DrawView* baseFeat, + TechDraw::DrawPage* page); + TaskRichAnno(TechDrawGui::ViewProviderRichAnno* leadVP); + ~TaskRichAnno(); + +public Q_SLOTS: + void onEditorClicked(bool b); +/* void onViewPicked(QPointF pos, QGIView* qgParent);*/ + +public: + virtual bool accept(); + virtual bool reject(); + virtual void setCreateMode(bool b) { m_createMode = b; } + virtual bool getCreateMode(void) { return m_createMode; } + void updateTask(); + void saveButtons(QPushButton* btnOK, + QPushButton* btnCancel); + void enableTaskButtons(bool b); + + +protected Q_SLOTS: + void onSaveAndExit(QString); + void onEditorExit(void); + +protected: + void changeEvent(QEvent *e); + + void createAnnoFeature(void); + void updateAnnoFeature(void); + void commonFeatureUpdate(void); + void removeFeature(void); + + QPointF calcTextStartPos(double scale); + + void blockButtons(bool b); + void setUiPrimary(void); + void setUiEdit(void); + void enableTextUi(bool b); + void enableVPUi(bool b); + +private: + Ui_TaskRichAnno * ui; + bool blockUpdate; + + MDIViewPage* m_mdi; + QGraphicsScene* m_scene; + QGVPage* m_view; + ViewProviderRichAnno* m_annoVP; + TechDraw::DrawView* m_baseFeat; + TechDraw::DrawPage* m_basePage; + TechDraw::DrawRichAnno* m_annoFeat; + QGIView* m_qgParent; + std::string m_qgParentName; + + Base::Vector3d m_attachPoint; + + bool m_createMode; + QGMText* m_text; + + Qt::ContextMenuPolicy m_saveContextPolicy; + bool m_inProgressLock; + + QGIRichAnno* m_qgAnno; + QPushButton* m_btnOK; + QPushButton* m_btnCancel; + + QDialog* m_textDialog; + MRichTextEdit* m_rte; + QString m_title; +}; + +class TaskDlgRichAnno : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskDlgRichAnno(TechDraw::DrawView* baseFeat, + TechDraw::DrawPage* page); + TaskDlgRichAnno(TechDrawGui::ViewProviderRichAnno* leadVP); + ~TaskDlgRichAnno(); + +public: + /// is called the TaskView when the dialog is opened + virtual void open(); + /// is called by the framework if an button is clicked which has no accept or reject role + virtual void clicked(int); + /// is called by the framework if the dialog is accepted (Ok) + virtual bool accept(); + /// is called by the framework if the dialog is rejected (Cancel) + virtual bool reject(); + /// is called by the framework if the user presses the help button + virtual void helpRequested() { return;} + virtual bool isAllowedAlterDocument(void) const + { return false; } + void update(); + + void modifyStandardButtons(QDialogButtonBox* box); + +protected: + +private: + TaskRichAnno * widget; + Gui::TaskView::TaskBox* taskbox; +}; + +} //namespace TechDrawGui + +#endif // #ifndef TECHDRAWGUI_TASKRICHANNO_H diff --git a/src/Mod/TechDraw/Gui/TaskRichAnno.ui b/src/Mod/TechDraw/Gui/TaskRichAnno.ui new file mode 100644 index 000000000000..f34c4acebd3e --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskRichAnno.ui @@ -0,0 +1,156 @@ + + + TechDrawGui::TaskRichAnno + + + + 0 + 0 + 409 + 386 + + + + + 0 + 0 + + + + + 250 + 0 + + + + Rich Text Annotation Block + + + + :/icons/actions/techdraw-textleader.svg:/icons/actions/techdraw-textleader.svg + + + + + + + 0 + 0 + + + + QFrame::Box + + + QFrame::Raised + + + + + + + + 0 + + + + + -1.000000000000000 + + + -1.000000000000000 + + + + + + + Max Width + + + + + + + Base Feature + + + + + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::LeftToRight + + + + + + + + + + Show Frame + + + + + + + + + Qt::Horizontal + + + + + + + true + + + Start Rich Text Editor + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp index 7bb070144605..fba922fbf7ec 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp @@ -61,6 +61,7 @@ PROPERTY_SOURCE(TechDrawGui::ViewProviderDrawingView, Gui::ViewProviderDocumentO ViewProviderDrawingView::ViewProviderDrawingView() { +// Base::Console().Message("VPDV::VPDV\n"); sPixmap = "TechDraw_Tree_View"; static const char *group = "Base"; @@ -78,6 +79,7 @@ ViewProviderDrawingView::~ViewProviderDrawingView() void ViewProviderDrawingView::attach(App::DocumentObject *pcFeat) { +// Base::Console().Message("VPDV::attach(%s)\n", pcFeat->getNameInDocument()); ViewProviderDocumentObject::attach(pcFeat); auto bnd = boost::bind(&ViewProviderDrawingView::onGuiRepaint, this, _1); @@ -238,7 +240,6 @@ MDIViewPage* ViewProviderDrawingView::getMDIViewPage() const void ViewProviderDrawingView::onGuiRepaint(const TechDraw::DrawView* dv) { -// Base::Console().Message("VPDV::onGuiRepaint(%s)\n",dv->getNameInDocument()); if (dv == getViewObject()) { if (!dv->isRemoving() && !dv->isRestoring()) { diff --git a/src/Mod/TechDraw/Gui/ViewProviderLeader.cpp b/src/Mod/TechDraw/Gui/ViewProviderLeader.cpp index bd9e00ab1080..75d68c752259 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderLeader.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderLeader.cpp @@ -48,12 +48,12 @@ #include #include -#include +#include #include "MDIViewPage.h" #include "QGVPage.h" #include "QGIView.h" -#include "TaskTextLeader.h" +#include "TaskLeaderLine.h" #include "ViewProviderLeader.h" using namespace TechDrawGui; @@ -92,7 +92,7 @@ bool ViewProviderLeader::setEdit(int ModNum) } // clear the selection (convenience) Gui::Selection().clearSelection(); - Gui::Control().showDialog(new TaskDlgTextLeader(LINEMODE, this)); + Gui::Control().showDialog(new TaskDlgLeaderLine(this)); return true; } else { return ViewProviderDrawingView::setEdit(ModNum); @@ -134,7 +134,27 @@ void ViewProviderLeader::onChanged(const App::Property* p) } } ViewProviderDrawingView::onChanged(p); +} +std::vector ViewProviderLeader::claimChildren(void) const +{ + // Collect any child Document Objects and put them in the right place in the Feature tree + // valid children of a ViewLeader are: + // - Rich Annotations + std::vector temp; + const std::vector &views = getFeature()->getInList(); + try { + for(std::vector::const_iterator it = views.begin(); it != views.end(); ++it) { + if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId())) { + temp.push_back((*it)); + } + } + return temp; + } + catch (...) { + std::vector tmp; + return tmp; + } } TechDraw::DrawLeaderLine* ViewProviderLeader::getViewObject() const @@ -168,109 +188,4 @@ App::Color ViewProviderLeader::getDefLineColor(void) return result; } -//****************************************************************************** -PROPERTY_SOURCE(TechDrawGui::ViewProviderTextLeader, TechDrawGui::ViewProviderLeader) - -ViewProviderTextLeader::ViewProviderTextLeader() -{ - sPixmap = "actions/techdraw-textleader"; - - static const char *group = "Text Format"; - - ADD_PROPERTY_TYPE(Font ,(getDefFont().c_str()),group,App::Prop_None, "The name of the font to use"); - ADD_PROPERTY_TYPE(Fontsize,(getDefFontSize()) ,group,(App::PropertyType)(App::Prop_None), - "Text size in internal units"); - ADD_PROPERTY_TYPE(MaxWidth,(-1) ,group,(App::PropertyType)(App::Prop_None), - "Maximum width of text in mm"); - ADD_PROPERTY_TYPE(ShowFrame,(true) ,group,(App::PropertyType)(App::Prop_None), - "Draw a box around text or not"); -} - -ViewProviderTextLeader::~ViewProviderTextLeader() -{ -} - -void ViewProviderTextLeader::attach(App::DocumentObject *pcFeat) -{ - ViewProviderLeader::attach(pcFeat); -} - -bool ViewProviderTextLeader::setEdit(int ModNum) -{ -// Base::Console().Message("VPTL::setEdit(%d)\n",ModNum); - if (ModNum == ViewProvider::Default ) { - if (Gui::Control().activeDialog()) { //TaskPanel already open! - return false; - } - // clear the selection (convenience) - Gui::Selection().clearSelection(); - Gui::Control().showDialog(new TaskDlgTextLeader(TEXTMODE, this)); - return true; - } else { - return ViewProviderLeader::setEdit(ModNum); - } - return true; -} - -void ViewProviderTextLeader::unsetEdit(int ModNum) -{ - Q_UNUSED(ModNum); - if (ModNum == ViewProvider::Default) { - Gui::Control().closeDialog(); - } - else { - ViewProviderLeader::unsetEdit(ModNum); - } -} - -bool ViewProviderTextLeader::doubleClicked(void) -{ -// Base::Console().Message("VPTL::doubleClicked()\n"); - setEdit(ViewProvider::Default); - return true; -} - -void ViewProviderTextLeader::updateData(const App::Property* p) -{ - ViewProviderLeader::updateData(p); -} - -void ViewProviderTextLeader::onChanged(const App::Property* p) -{ - if ((p == &Font) || - (p == &Fontsize) || - (p == &MaxWidth) || - (p == &ShowFrame)) { - QGIView* qgiv = getQView(); - if (qgiv) { - qgiv->updateView(true); - } - } - ViewProviderLeader::onChanged(p); - -} - -TechDraw::DrawTextLeader* ViewProviderTextLeader::getFeature() const -{ - return dynamic_cast(pcObject); -} - -std::string ViewProviderTextLeader::getDefFont(void) const -{ - Base::Reference hGrp = App::GetApplication().GetUserParameter(). - GetGroup("BaseApp")->GetGroup("Preferences")-> - GetGroup("Mod/TechDraw/Labels"); - std::string result = hGrp->GetASCII("LabelFont", "osifont"); - return result; -} - -double ViewProviderTextLeader::getDefFontSize(void) const -{ - Base::Reference hGrp = App::GetApplication().GetUserParameter(). - GetGroup("BaseApp")->GetGroup("Preferences")-> - GetGroup("Mod/TechDraw/Dimensions"); - double result = hGrp->GetFloat("FontSize", 6.0); - return result; -} - diff --git a/src/Mod/TechDraw/Gui/ViewProviderLeader.h b/src/Mod/TechDraw/Gui/ViewProviderLeader.h index 5953ad61079d..433b6f1e6eba 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderLeader.h +++ b/src/Mod/TechDraw/Gui/ViewProviderLeader.h @@ -32,7 +32,7 @@ #include "ViewProviderDrawingView.h" namespace TechDraw { -class DrawTextLeader; +class DrawRichAnno; class DrawLeaderLine; } @@ -62,6 +62,8 @@ class TechDrawGuiExport ViewProviderLeader : public ViewProviderDrawingView virtual void unsetEdit(int ModNum); virtual bool doubleClicked(void); + std::vector claimChildren(void) const; + virtual TechDraw::DrawLeaderLine* getViewObject() const; TechDraw::DrawLeaderLine* getFeature() const; @@ -70,37 +72,6 @@ class TechDrawGuiExport ViewProviderLeader : public ViewProviderDrawingView App::Color getDefLineColor(void); }; -//****************************************************************************** -class TechDrawGuiExport ViewProviderTextLeader : public ViewProviderLeader -{ - PROPERTY_HEADER(TechDrawGui::ViewProviderTextLeader); - -public: - ViewProviderTextLeader(); - virtual ~ViewProviderTextLeader(); - - App::PropertyFont Font; - App::PropertyLength Fontsize; - App::PropertyFloat MaxWidth; - App::PropertyBool ShowFrame; - - virtual void attach(App::DocumentObject *); - virtual void updateData(const App::Property*); - virtual void onChanged(const App::Property* p); - virtual bool setEdit(int ModNum); - virtual void unsetEdit(int ModNum); - virtual bool doubleClicked(void); - -/* virtual TechDraw::DrawTextLeader* getViewObject() const;*/ - TechDraw::DrawTextLeader* getFeature() const; - -protected: - std::string getDefFont(void) const; - double getDefFontSize(void) const; - -}; - - } // namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp index ee2302ff0897..3bfed29079bb 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp @@ -58,6 +58,7 @@ #include #include #include +#include #include #include @@ -272,12 +273,22 @@ std::vector ViewProviderPage::claimChildren(void) const for(std::vector::const_iterator it = views.begin(); it != views.end(); ++it) { TechDraw::DrawView* featView = dynamic_cast (*it); App::DocumentObject *docObj = *it; + //DrawRichAnno with no parent is child of Page + TechDraw::DrawRichAnno* dra = dynamic_cast (*it); + if (dra != nullptr) { + if (dra->AnnoParent.getValue() == nullptr) { + temp.push_back(*it); + continue; + } + } + // Don't collect if dimension, projection group item, hatch or member of ClipGroup as these should be grouped elsewhere if(docObj->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId()) || docObj->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()) || docObj->isDerivedFrom(TechDraw::DrawHatch::getClassTypeId()) || - docObj->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId()) || - docObj->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId()) || + docObj->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId()) || + docObj->isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId()) || + docObj->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId()) || (featView && featView->isInClip()) ) continue; else diff --git a/src/Mod/TechDraw/Gui/ViewProviderRichAnno.cpp b/src/Mod/TechDraw/Gui/ViewProviderRichAnno.cpp new file mode 100644 index 000000000000..c98d68882a6d --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderRichAnno.cpp @@ -0,0 +1,174 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2019 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_ +#endif + +/// Here the FreeCAD includes sorted by Base,App,Gui...... +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "MDIViewPage.h" +#include "QGVPage.h" +#include "QGIView.h" +#include "TaskRichAnno.h" +#include "ViewProviderRichAnno.h" + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderRichAnno, TechDrawGui::ViewProviderDrawingView) + +//************************************************************************** +// Construction/Destruction + +ViewProviderRichAnno::ViewProviderRichAnno() +{ + sPixmap = "actions/techdraw-textleader"; + + static const char *group = "Text Format"; + + ADD_PROPERTY_TYPE(Color,(getDefLineColor()),group,App::Prop_None,"The color of the Markup"); + ADD_PROPERTY_TYPE(Font ,(getDefFont().c_str()),group,App::Prop_None, "The name of the font to use"); + ADD_PROPERTY_TYPE(Fontsize,(getDefFontSize()) ,group,(App::PropertyType)(App::Prop_None), + "Text size in internal units"); + Color.setStatus(App::Property::ReadOnly,true); + Font.setStatus(App::Property::ReadOnly,true); + Fontsize.setStatus(App::Property::ReadOnly,true); +} + +ViewProviderRichAnno::~ViewProviderRichAnno() +{ +} + +void ViewProviderRichAnno::attach(App::DocumentObject *pcFeat) +{ + ViewProviderDrawingView::attach(pcFeat); +} + +bool ViewProviderRichAnno::setEdit(int ModNum) +{ +// Base::Console().Message("VPRA::setEdit(%d)\n",ModNum); + if (ModNum == ViewProvider::Default ) { + if (Gui::Control().activeDialog()) { //TaskPanel already open! + return false; + } + // clear the selection (convenience) + Gui::Selection().clearSelection(); + Gui::Control().showDialog(new TaskDlgRichAnno(this)); + return true; + } else { + return ViewProviderDrawingView::setEdit(ModNum); + } + return true; +} + +void ViewProviderRichAnno::unsetEdit(int ModNum) +{ + Q_UNUSED(ModNum); + if (ModNum == ViewProvider::Default) { + Gui::Control().closeDialog(); + } + else { + ViewProviderDrawingView::unsetEdit(ModNum); + } +} + +bool ViewProviderRichAnno::doubleClicked(void) +{ +// Base::Console().Message("VPRA::doubleClicked()\n"); + setEdit(ViewProvider::Default); + return true; +} + +void ViewProviderRichAnno::updateData(const App::Property* p) +{ + ViewProviderDrawingView::updateData(p); +} + +void ViewProviderRichAnno::onChanged(const App::Property* p) +{ +// if ((p == &Font) || +// (p == &Fontsize) || +// (p == &Color)) { +// QGIView* qgiv = getQView(); +// if (qgiv) { +// qgiv->updateView(true); +// } +// } + ViewProviderDrawingView::onChanged(p); +} + +TechDraw::DrawRichAnno* ViewProviderRichAnno::getViewObject() const +{ + return dynamic_cast(pcObject); +} + +TechDraw::DrawRichAnno* ViewProviderRichAnno::getFeature() const +{ + return dynamic_cast(pcObject); +} + +App::Color ViewProviderRichAnno::getDefLineColor(void) +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter(). + GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Markups"); + App::Color result; + result.setPackedValue(hGrp->GetUnsigned("Color", 0x00000000)); + return result; +} + +std::string ViewProviderRichAnno::getDefFont(void) +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Labels"); + std::string fontName = hGrp->GetASCII("LabelFont", "osifont"); + return fontName; +} + +double ViewProviderRichAnno::getDefFontSize() +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); + double fontSize = hGrp->GetFloat("FontSize", 5.0); + return fontSize; +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderRichAnno.h b/src/Mod/TechDraw/Gui/ViewProviderRichAnno.h new file mode 100644 index 000000000000..e66552db5ca8 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderRichAnno.h @@ -0,0 +1,78 @@ +/*************************************************************************** + * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2019 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 TECHDRAWGUI_VIEWPROVIDERRICHANNO_H +#define TECHDRAWGUI_VIEWPROVIDERRICHANNO_H + +#include + +#include + +#include "ViewProviderDrawingView.h" + +namespace TechDraw { +class DrawRichAnno; +} + +namespace TechDrawGui { + +class TechDrawGuiExport ViewProviderRichAnno : public ViewProviderDrawingView +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderRichAnno); + +public: + /// constructor + ViewProviderRichAnno(); + /// destructor + virtual ~ViewProviderRichAnno(); + + App::PropertyFont Font; + App::PropertyLength Fontsize; + App::PropertyColor Color; + App::PropertyFloat MaxWidth; + App::PropertyBool ShowFrame; + + virtual void attach(App::DocumentObject *); +/* virtual void setDisplayMode(const char* ModeName);*/ + virtual bool useNewSelectionModel(void) const {return false;} +/* virtual std::vector getDisplayModes(void) const;*/ + virtual void updateData(const App::Property*); + virtual void onChanged(const App::Property* p); + virtual bool setEdit(int ModNum); + virtual void unsetEdit(int ModNum); + virtual bool doubleClicked(void); + + virtual TechDraw::DrawRichAnno* getViewObject() const; + TechDraw::DrawRichAnno* getFeature() const; + +protected: + App::Color getDefLineColor(void); + std::string getDefFont(void); + double getDefFontSize(void); + +}; + +} // namespace TechDrawGui + +#endif // TECHDRAWGUI_VIEWPROVIDERRICHANNO_H diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp b/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp index 72f23e8ff084..63447d9f7c88 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -164,6 +165,7 @@ std::vector ViewProviderViewPart::claimChildren(void) cons // - Leaders // - Hatches // - GeomHatches + // - Leaders std::vector temp; const std::vector &views = getViewPart()->getInList(); try { @@ -188,6 +190,8 @@ std::vector ViewProviderViewPart::claimChildren(void) cons temp.push_back((*it)); } else if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId())) { temp.push_back((*it)); + } else if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId())) { + temp.push_back((*it)); } else if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId())) { temp.push_back((*it)); } diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index 57b1556bc3e7..3d713b6713ae 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -90,7 +90,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_ToggleFrame"; // *decor << "TechDraw_RedrawPage"; *draw << "TechDraw_LeaderLine"; - *draw << "TechDraw_TextLeader"; + *draw << "TechDraw_RichAnno"; return root; } @@ -148,7 +148,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const *decor << "TechDraw_ToggleFrame"; // *decor << "TechDraw_RedrawPage"; *decor << "TechDraw_LeaderLine"; - *decor << "TechDraw_TextLeader"; + *decor << "TechDraw_RichAnno"; return root; } @@ -204,7 +204,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *decor << "TechDraw_ToggleFrame"; // *decor << "TechDraw_RedrawPage"; *decor << "TechDraw_LeaderLine"; - *decor << "TechDraw_TextLeader"; + *decor << "TechDraw_RichAnno"; return root; } diff --git a/src/Mod/TechDraw/Gui/mrichtextedit.cpp b/src/Mod/TechDraw/Gui/mrichtextedit.cpp index 575e1325b948..e56e0c348f59 100644 --- a/src/Mod/TechDraw/Gui/mrichtextedit.cpp +++ b/src/Mod/TechDraw/Gui/mrichtextedit.cpp @@ -113,6 +113,8 @@ MRichTextEdit::MRichTextEdit(QWidget *parent, QString textIn) : QWidget(parent) connect(f_textedit, SIGNAL(copyAvailable(bool)), f_cut, SLOT(setEnabled(bool))); connect(f_textedit, SIGNAL(copyAvailable(bool)), f_copy, SLOT(setEnabled(bool))); +// f_textedit->setLineWrapMode(QTextEdit::FixedColumnWidth); +// f_textedit->setLineWrapColumnOrWidth(????)); #ifndef QT_NO_CLIPBOARD connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(slotClipboardDataChanged())); #endif diff --git a/src/Mod/TechDraw/Gui/mrichtextedit.h b/src/Mod/TechDraw/Gui/mrichtextedit.h index 5a7d99867222..ad8d94556952 100644 --- a/src/Mod/TechDraw/Gui/mrichtextedit.h +++ b/src/Mod/TechDraw/Gui/mrichtextedit.h @@ -40,6 +40,7 @@ class MRichTextEdit : public QWidget, protected Ui::MRichTextEdit { QTextDocument *document() { return f_textedit->document(); } QTextCursor textCursor() const { return f_textedit->textCursor(); } void setTextCursor(const QTextCursor& cursor) { f_textedit->setTextCursor(cursor); } + void setMaxWidth(double w); public slots: void setText(const QString &text);