diff --git a/src/Mod/TechDraw/App/DrawRichAnno.cpp b/src/Mod/TechDraw/App/DrawRichAnno.cpp index 377031572b..95f3cde049 100644 --- a/src/Mod/TechDraw/App/DrawRichAnno.cpp +++ b/src/Mod/TechDraw/App/DrawRichAnno.cpp @@ -56,7 +56,6 @@ DrawRichAnno::DrawRichAnno(void) Scale.setStatus(App::Property::Hidden,true); ScaleType.setStatus(App::Property::Hidden,true); - } DrawRichAnno::~DrawRichAnno() @@ -87,7 +86,7 @@ short DrawRichAnno::mustExecute() const App::DocumentObjectExecReturn *DrawRichAnno::execute(void) { -// Base::Console().Message("DRA::execute()\n"); +// Base::Console().Message("DRA::execute() - @ (%.3f, %.3f)\n", X.getValue(), Y.getValue()); if (!keepUpdated()) { return App::DocumentObject::StdReturn; } diff --git a/src/Mod/TechDraw/App/DrawRichAnno.h b/src/Mod/TechDraw/App/DrawRichAnno.h index 7e59902f58..179797296c 100644 --- a/src/Mod/TechDraw/App/DrawRichAnno.h +++ b/src/Mod/TechDraw/App/DrawRichAnno.h @@ -42,10 +42,8 @@ public: 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); diff --git a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp index 895a9cc0a7..217c7b2242 100644 --- a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp +++ b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp @@ -192,8 +192,7 @@ void CmdTechDrawRichTextAnnotation::activated(int iMsg) bool CmdTechDrawRichTextAnnotation::isActive(void) { bool havePage = DrawGuiUtil::needPage(this); - bool haveView = DrawGuiUtil::needView(this, false); - return (havePage && haveView); + return havePage; } diff --git a/src/Mod/TechDraw/Gui/QGIRichAnno.cpp b/src/Mod/TechDraw/Gui/QGIRichAnno.cpp index 47e31314c0..7cd18ae006 100644 --- a/src/Mod/TechDraw/Gui/QGIRichAnno.cpp +++ b/src/Mod/TechDraw/Gui/QGIRichAnno.cpp @@ -66,6 +66,8 @@ #include "QGEPath.h" #include "QGMText.h" #include "QGIView.h" +#include "QGCustomText.h" +#include "QGCustomRect.h" #include "QGIRichAnno.h" @@ -79,38 +81,30 @@ QGIRichAnno::QGIRichAnno(QGraphicsItem* myParent, { setHandlesChildEvents(false); setAcceptHoverEvents(false); - setFlag(QGraphicsItem::ItemIsSelectable, false); //we actually select & drag m_text - setFlag(QGraphicsItem::ItemIsMovable, false); + setFlag(QGraphicsItem::ItemIsSelectable, true); + setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges,true); if (myParent != nullptr) { setParentItem(myParent); } + setViewFeature(anno); - m_text = new QGMText(); + m_text = new QGCustomText(); m_text->setTextInteractionFlags(Qt::NoTextInteraction); addToGroup(m_text); m_text->setZValue(ZVALUE::DIMENSION); + m_text->centerAt(0.0, 0.0); + m_rect = new QGCustomRect(); + addToGroup(m_rect); + m_rect->setZValue(ZVALUE::DIMENSION - 1); + m_rect->centerAt(0.0, 0.0); + setZValue(ZVALUE::DIMENSION); - QObject::connect( - m_text, SIGNAL(dragging()), - this , SLOT (textDragging()) - ); - QObject::connect( - 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 QGIRichAnno::itemChange(GraphicsItemChange change, const QVariant &value) @@ -123,52 +117,17 @@ QVariant QGIRichAnno::itemChange(GraphicsItemChange change, const QVariant &valu return QGIView::itemChange(change, value); } -void QGIRichAnno::textDragging(void) -{ -// Base::Console().Message("QGIRA::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()) ); +//void QGIRichAnno::select(bool state) +//{ +// setSelected(state); +// draw(); +//} -// if( lead == nullptr ) { -// return; -// } - -// double x = Rez::appX(m_text->x()), -// y = Rez::appX(m_text->y()); -// Base::Vector3d tPos(x,-y,0.0); -// Gui::Command::openCommand("Drag Text"); -// lead->TextPosition.setValue(tPos); -// Gui::Command::commitCommand(); -// draw(); -} - -void QGIRichAnno::textDragFinished(void) -{ -// Base::Console().Message("QGIRA::textDragFinished()\n"); - auto anno( dynamic_cast(getFeature()) ); - - if( anno == nullptr ) { - return; - } - - double x = Rez::appX(m_text->x()) / getScale(); - double y = - Rez::appX(m_text->y()) / getScale(); - anno->X.setValue(x); - anno->Y.setValue(y); -} - -void QGIRichAnno::select(bool state) -{ - setSelected(state); - draw(); -} - -void QGIRichAnno::hover(bool state) -{ - m_hasHover = state; - draw(); -} +//void QGIRichAnno::hover(bool state) +//{ +// m_hasHover = state; +// draw(); +//} void QGIRichAnno::updateView(bool update) { @@ -184,6 +143,13 @@ void QGIRichAnno::updateView(bool update) if ( vp == nullptr ) { return; } + if (annoFeat->X.isTouched() || + annoFeat->Y.isTouched()) { + float x = Rez::guiX(annoFeat->X.getValue()); + float y = Rez::guiX(annoFeat->Y.getValue()); + m_text->centerAt(x, -y); + m_rect->centerAt(x, -y); + } draw(); } @@ -197,23 +163,25 @@ void QGIRichAnno::drawBorder() void QGIRichAnno::draw() { -// Base::Console().Log("QGITL::draw() - %s\n",getFeature()->getNameInDocument()); +// Base::Console().Log("QGIRA::draw() - %s - parent: %X\n",getFeature()->getNameInDocument(), parentItem()); if (!isVisible()) { - Base::Console().Log("QGITL::draw - not visible\n"); +// Base::Console().Message("QGIRA::draw - not visible\n"); return; } TechDraw::DrawRichAnno* annoFeat = getFeature(); if((!annoFeat) ) { - Base::Console().Log("QGITL::draw - no feature\n"); +// Base::Console().Message("QGIRA::draw - no feature\n"); return; } auto vp = static_cast(getViewProvider(getFeature())); if ( vp == nullptr ) { - Base::Console().Log("QGITL::draw - no viewprovider\n"); +// Base::Console().Message("QGIRA::draw - no viewprovider\n"); return; } +// double appX = Rez::guiX(annoFeat->X.getValue()); +// double appY = Rez::guiX(annoFeat->Y.getValue()); QGIView::draw(); @@ -257,14 +225,20 @@ void QGIRichAnno::setTextItem() m_text->setHtml(outHtml); m_text->setTextWidth(Rez::guiX(annoFeat->MaxWidth.getValue())); - m_text->showBox(annoFeat->ShowFrame.getValue()); - double scale = getScale(); - 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); +// m_text->showBox(annoFeat->ShowFrame.getValue()); + if (annoFeat->ShowFrame.getValue()) { + QRectF r = m_text->boundingRect().adjusted(1,1,-1,-1); + m_rect->setPen(rectPen()); + m_rect->setBrush(Qt::NoBrush); + m_rect->setRect(r); + m_rect->show(); + } else { + m_rect->hide(); + } + + m_text->centerAt(0.0, 0.0); + m_rect->centerAt(0.0, 0.0); } //void QGIRichAnno::drawBorder() @@ -301,4 +275,12 @@ void QGIRichAnno::paint ( QPainter * painter, const QStyleOptionGraphicsItem * o QGIView::paint (painter, &myOption, widget); } +QPen QGIRichAnno::rectPen() const +{ + QPen pen(Qt::SolidLine); + pen.setWidthF(1.0); + return pen; +} + + #include diff --git a/src/Mod/TechDraw/Gui/QGIRichAnno.h b/src/Mod/TechDraw/Gui/QGIRichAnno.h index 38991fc9c8..fc2b0f20ba 100644 --- a/src/Mod/TechDraw/Gui/QGIRichAnno.h +++ b/src/Mod/TechDraw/Gui/QGIRichAnno.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include "QGILeaderLine.h" @@ -47,6 +48,8 @@ class QGIPrimPath; class QGIArrow; class QGEPath; class QGMText; +class QGCustomText; +class QGCustomRect; //******************************************************************* @@ -75,12 +78,14 @@ public: void setTextItem(void); virtual TechDraw::DrawRichAnno* getFeature(void); + QPen rectPen() const; + public Q_SLOTS: - void textDragging(void); - void textDragFinished(void); - void hover(bool state); - void select(bool state); +/* void textDragging(void);*/ +/* void textDragFinished(void);*/ +/* void hover(bool state);*/ +/* void select(bool state);*/ protected: virtual void draw() override; @@ -88,8 +93,10 @@ protected: const QVariant &value ) override; protected: - QGMText* m_text; +/* QGMText* m_text;*/ + QGCustomText* m_text; bool m_hasHover; + QGCustomRect* m_rect; }; diff --git a/src/Mod/TechDraw/Gui/TaskRichAnno.cpp b/src/Mod/TechDraw/Gui/TaskRichAnno.cpp index 93f8e700e6..602abc7515 100644 --- a/src/Mod/TechDraw/Gui/TaskRichAnno.cpp +++ b/src/Mod/TechDraw/Gui/TaskRichAnno.cpp @@ -145,6 +145,7 @@ TaskRichAnno::TaskRichAnno(TechDraw::DrawView* baseFeat, return; } + ui->setupUi(this); m_title = QObject::tr("Rich text creator"); @@ -278,7 +279,7 @@ void TaskRichAnno::createAnnoFeature() std::string PageName = m_basePage->getNameInDocument(); - Gui::Command::openCommand("Create Leader"); + Gui::Command::openCommand("Create Anno"); 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)", @@ -309,7 +310,7 @@ void TaskRichAnno::createAnnoFeature() void TaskRichAnno::updateAnnoFeature() { // Base::Console().Message("TRA::updateAnnoFeature()\n"); - Gui::Command::openCommand("Edit Leader"); + Gui::Command::openCommand("Edit Anno"); commonFeatureUpdate(); Gui::Command::commitCommand(); @@ -375,16 +376,19 @@ QPointF TaskRichAnno::calcTextStartPos(double scale) TechDraw::DrawLeaderLine* dll = dynamic_cast(m_baseFeat); points = dll->WayPoints.getValues(); } else { - Base::Console().Log("TRA::calcTextPos - m_baseFeat is not Leader\n"); +// Base::Console().Message("TRA::calcTextPos - m_baseFeat is not Leader\n"); QPointF result(0.0,0.0); return result; } } else { +// Base::Console().Message("TRA::calcStartPos - no m_baseFeat\n"); 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; + } else { + Base::Console().Message("TRA::calcStartPos - no m_basePage\n"); } }