Skip to content

Commit

Permalink
Merge branch 'master' into feature/tool-bit-poc
Browse files Browse the repository at this point in the history
  • Loading branch information
mlampert committed Dec 5, 2019
2 parents ee937d5 + 85ba410 commit d2683b6
Show file tree
Hide file tree
Showing 10 changed files with 628 additions and 758 deletions.
5 changes: 3 additions & 2 deletions src/Mod/Draft/DraftLayer.py
Expand Up @@ -139,11 +139,11 @@ def __init__(self,vobj):

vobj.OverrideChildren = True
c = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeLineColor",255)
vobj.LineColor = (((c>>24)&0xFF)/255,((c>>16)&0xFF)/255,((c>>8)&0xFF)/255)
vobj.LineColor = (((c>>24)&0xFF)/255.0,((c>>16)&0xFF)/255.0,((c>>8)&0xFF)/255.0)
w = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetInt("DefaultShapeLineWidth",2)
vobj.LineWidth = w
c = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeColor",4294967295)
vobj.ShapeColor = (((c>>24)&0xFF)/255,((c>>16)&0xFF)/255,((c>>8)&0xFF)/255)
vobj.ShapeColor = (((c>>24)&0xFF)/255.0,((c>>16)&0xFF)/255.0,((c>>8)&0xFF)/255.0)
vobj.DrawStyle = "Solid"

vobj.Proxy = self
Expand Down Expand Up @@ -225,6 +225,7 @@ def onChanged(self,vobj,prop):
b.open(QtCore.QIODevice.WriteOnly)
im.save(b,"XPM")
self.icondata = ba.data().decode("latin1")
vobj.signalChangeIcon()

def canDragObject(self,obj):
return True
Expand Down
3 changes: 1 addition & 2 deletions src/Mod/TechDraw/App/DrawRichAnno.cpp
Expand Up @@ -56,7 +56,6 @@ DrawRichAnno::DrawRichAnno(void)
Scale.setStatus(App::Property::Hidden,true);
ScaleType.setStatus(App::Property::Hidden,true);


}

DrawRichAnno::~DrawRichAnno()
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions src/Mod/TechDraw/App/DrawRichAnno.h
Expand Up @@ -42,10 +42,8 @@ class TechDrawExport DrawRichAnno : public TechDraw::DrawView

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);
Expand Down
3 changes: 1 addition & 2 deletions src/Mod/TechDraw/Gui/CommandAnnotate.cpp
Expand Up @@ -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;
}


Expand Down
132 changes: 57 additions & 75 deletions src/Mod/TechDraw/Gui/QGIRichAnno.cpp
Expand Up @@ -66,6 +66,8 @@
#include "QGEPath.h"
#include "QGMText.h"
#include "QGIView.h"
#include "QGCustomText.h"
#include "QGCustomRect.h"

#include "QGIRichAnno.h"

Expand All @@ -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)
Expand All @@ -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<TechDraw::DrawRichAnno*>(getFeature()) );

// 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<TechDraw::DrawRichAnno*>(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::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)
{
Expand All @@ -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();
}
Expand All @@ -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<ViewProviderRichAnno*>(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();

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 <Mod/TechDraw/Gui/moc_QGIRichAnno.cpp>
17 changes: 12 additions & 5 deletions src/Mod/TechDraw/Gui/QGIRichAnno.h
Expand Up @@ -32,6 +32,7 @@
#include <QColor>
#include <QFont>
#include <QPointF>
#include <QPen>

#include <Base/Vector3D.h>
#include "QGILeaderLine.h"
Expand All @@ -47,6 +48,8 @@ class QGIPrimPath;
class QGIArrow;
class QGEPath;
class QGMText;
class QGCustomText;
class QGCustomRect;


//*******************************************************************
Expand Down Expand Up @@ -75,21 +78,25 @@ class TechDrawGuiExport QGIRichAnno : public QGIView
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;
virtual QVariant itemChange( GraphicsItemChange change,
const QVariant &value ) override;

protected:
QGMText* m_text;
/* QGMText* m_text;*/
QGCustomText* m_text;
bool m_hasHover;
QGCustomRect* m_rect;

};

Expand Down

0 comments on commit d2683b6

Please sign in to comment.