[TD]make detail highlight interactive
- drag detail highlight to change detail anchor point - change detail reference position using HighlightAdjust property
This commit is contained in:
@@ -106,8 +106,7 @@ short DrawViewDetail::mustExecute() const
|
||||
TechDraw::DrawView::mustExecute();
|
||||
}
|
||||
|
||||
if (AnchorPoint.isTouched() || Radius.isTouched() || BaseView.isTouched()
|
||||
|| Reference.isTouched()) {
|
||||
if (AnchorPoint.isTouched() || Radius.isTouched() || BaseView.isTouched()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -125,13 +124,6 @@ void DrawViewDetail::onChanged(const App::Property* prop)
|
||||
std::string lblText = "Detail " + std::string(Reference.getValue());
|
||||
Label.setValue(lblText);
|
||||
}
|
||||
if (prop == &Reference || prop == &Radius || prop == &BaseView) {
|
||||
requestPaint();
|
||||
}
|
||||
if (prop == &AnchorPoint) {
|
||||
// to see AnchorPoint changes repainting is not enough, we must recompute
|
||||
recomputeFeature(true);
|
||||
}
|
||||
|
||||
DrawViewPart::onChanged(prop);
|
||||
}
|
||||
@@ -159,13 +151,6 @@ App::DocumentObjectExecReturn* DrawViewDetail::execute()
|
||||
if (dvp->isDerivedFrom(TechDraw::DrawViewSection::getClassTypeId())) {
|
||||
dvs = static_cast<TechDraw::DrawViewSection*>(dvp);
|
||||
}
|
||||
// TopoDS_Shape shape;
|
||||
// shape = dvs->getCutShape();
|
||||
// }
|
||||
// else {
|
||||
// //getSourceShapeFused will complain if called on section
|
||||
// shape = dvp->getSourceShapeFused();
|
||||
// }
|
||||
|
||||
if (shape.IsNull()) {
|
||||
return DrawView::execute();
|
||||
|
||||
@@ -40,7 +40,8 @@ using namespace TechDraw;
|
||||
QGIDecoration::QGIDecoration() :
|
||||
m_colCurrent(Qt::black),
|
||||
m_styleCurrent(Qt::SolidLine),
|
||||
m_brushCurrent(Qt::SolidPattern)
|
||||
m_brushCurrent(Qt::SolidPattern),
|
||||
m_dragState(DECORNODRAG)
|
||||
{
|
||||
setCacheMode(QGraphicsItem::NoCache);
|
||||
setAcceptHoverEvents(false);
|
||||
@@ -118,4 +119,34 @@ void QGIDecoration::makeMark(Base::Vector3d v)
|
||||
makeMark(v.x, v.y);
|
||||
}
|
||||
|
||||
void QGIDecoration::mousePressEvent(QGraphicsSceneMouseEvent * event)
|
||||
{
|
||||
// Base::Console().Message("QGID::mousePressEvent() - %s\n", getViewName());
|
||||
m_dragState = DECORDRAGSTARTED;
|
||||
|
||||
QGraphicsItem::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void QGIDecoration::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
|
||||
{
|
||||
if (m_dragState == DECORDRAGSTARTED) {
|
||||
m_dragState = DECORDRAGGING;
|
||||
}
|
||||
QGraphicsItem::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
void QGIDecoration::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
|
||||
{
|
||||
// Base::Console().Message("QGID::mouseReleaseEvent() - %s\n", getViewName());
|
||||
if (m_dragState == DECORDRAGGING) {
|
||||
onDragFinished();
|
||||
}
|
||||
m_dragState = DECORNODRAG;
|
||||
|
||||
QGraphicsItem::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void QGIDecoration::onDragFinished()
|
||||
{
|
||||
//override this
|
||||
}
|
||||
|
||||
@@ -43,17 +43,31 @@ QT_END_NAMESPACE
|
||||
namespace TechDrawGui
|
||||
{
|
||||
|
||||
#define DECORNODRAG 0
|
||||
#define DECORDRAGSTARTED 1
|
||||
#define DECORDRAGGING 2
|
||||
|
||||
class TechDrawGuiExport QGIDecoration : public QGraphicsItemGroup
|
||||
{
|
||||
public:
|
||||
explicit QGIDecoration(void);
|
||||
~QGIDecoration() {}
|
||||
enum {Type = QGraphicsItem::UserType + 173};
|
||||
int type() const { return Type;}
|
||||
int type() const override { return Type;}
|
||||
|
||||
virtual QRectF boundingRect() const;
|
||||
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = nullptr );
|
||||
QRectF boundingRect() const override;
|
||||
void paint(QPainter * painter,
|
||||
const QStyleOptionGraphicsItem * option,
|
||||
QWidget * widget = nullptr ) override;
|
||||
virtual void draw();
|
||||
|
||||
// Mouse handling
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
|
||||
virtual void onDragFinished();
|
||||
|
||||
void setWidth(double w);
|
||||
double getWidth() { return m_width; }
|
||||
void setStyle(Qt::PenStyle s);
|
||||
@@ -78,6 +92,8 @@ protected:
|
||||
Qt::PenStyle m_styleCurrent;
|
||||
Qt::BrushStyle m_brushCurrent;
|
||||
|
||||
int m_dragState;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
@@ -31,14 +31,15 @@
|
||||
|
||||
#include "QGIHighlight.h"
|
||||
#include "PreferencesGui.h"
|
||||
#include "QGIView.h"
|
||||
#include "QGIViewPart.h"
|
||||
#include "Rez.h"
|
||||
|
||||
|
||||
using namespace TechDrawGui;
|
||||
using namespace TechDraw;
|
||||
|
||||
QGIHighlight::QGIHighlight()
|
||||
QGIHighlight::QGIHighlight() :
|
||||
m_referenceAngle(0.0)
|
||||
{
|
||||
m_refSize = 0.0;
|
||||
setInteractive(false);
|
||||
@@ -63,6 +64,17 @@ QGIHighlight::~QGIHighlight()
|
||||
|
||||
}
|
||||
|
||||
void QGIHighlight::onDragFinished()
|
||||
{
|
||||
// Base::Console().Message("QGIH::onDragFinished - pos: %s\n",
|
||||
// DrawUtil::formatVector(pos()).c_str());
|
||||
QGraphicsItem* parent = parentItem();
|
||||
auto qgivp = dynamic_cast<QGIViewPart*>(parent);
|
||||
if (qgivp) {
|
||||
qgivp->highlightMoved(this, pos());
|
||||
}
|
||||
}
|
||||
|
||||
void QGIHighlight::draw()
|
||||
{
|
||||
prepareGeometryChange();
|
||||
@@ -93,9 +105,31 @@ void QGIHighlight::makeReference()
|
||||
m_refFont .setPixelSize(fontSize);
|
||||
m_reference->setFont(m_refFont);
|
||||
m_reference->setPlainText(m_refText);
|
||||
double fudge = Rez::guiX(1.0);
|
||||
QPointF newPos(m_end.x() + fudge, m_start.y() - m_refSize - fudge);
|
||||
m_reference->setPos(newPos);
|
||||
|
||||
double vertOffset = 0.0;
|
||||
if (m_referenceAngle >= 0.0 &&
|
||||
m_referenceAngle <= 180.0) {
|
||||
//above the X axis
|
||||
//referenceText is positioned by top-left, need to adjust upwards by text height
|
||||
vertOffset = m_reference->boundingRect().height();
|
||||
} else {
|
||||
//below X axis. need to adjust upwards a bit because there is blank space above text
|
||||
vertOffset = m_reference->tightBoundingAdjust().y();
|
||||
}
|
||||
|
||||
double horizOffset = 0.0;
|
||||
if (m_referenceAngle > 90.0 &&
|
||||
m_referenceAngle < 270.0) {
|
||||
//to left of Y axis
|
||||
horizOffset = -m_reference->boundingRect().width();
|
||||
}
|
||||
QRectF r(m_start, m_end);
|
||||
double radius = r.width() / 2.0;
|
||||
QPointF center = r.center();
|
||||
double angleRad = m_referenceAngle * M_PI / 180.0;
|
||||
double posX = center.x() + cos(angleRad) * radius + horizOffset;
|
||||
double posY = center.y() - sin(angleRad) * radius - vertOffset;
|
||||
m_reference->setPos(posX, posY);
|
||||
|
||||
double highRot = rotation();
|
||||
if (!TechDraw::DrawUtil::fpCompare(highRot, 0.0)) {
|
||||
|
||||
@@ -48,20 +48,22 @@ public:
|
||||
enum {Type = QGraphicsItem::UserType + 176};
|
||||
int type() const override { return Type;}
|
||||
|
||||
virtual void paint(QPainter * painter,
|
||||
const QStyleOptionGraphicsItem * option,
|
||||
QWidget * widget = nullptr ) override;
|
||||
void paint(QPainter * painter,
|
||||
const QStyleOptionGraphicsItem * option,
|
||||
QWidget * widget = nullptr ) override;
|
||||
|
||||
void setBounds(double x1, double y1, double x2, double y2);
|
||||
void setReference(const char* sym);
|
||||
void setFont(QFont f, double fsize);
|
||||
virtual void draw() override;
|
||||
void setInteractive(bool state);
|
||||
void setFeatureName(std::string name) { m_featureName = name; }
|
||||
std::string getFeatureName() { return m_featureName; }
|
||||
void setReferenceAngle(double angle) { m_referenceAngle = angle; }
|
||||
|
||||
void onDragFinished() override;
|
||||
|
||||
protected:
|
||||
/* virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;*/
|
||||
/* virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) override;*/
|
||||
/* virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;*/
|
||||
QColor getHighlightColor();
|
||||
Qt::PenStyle getHighlightStyle();
|
||||
void makeHighlight();
|
||||
@@ -69,8 +71,6 @@ protected:
|
||||
void setTools();
|
||||
int getHoleStyle(void);
|
||||
|
||||
/* bool m_dragging;*/
|
||||
|
||||
private:
|
||||
QString m_refText;
|
||||
QGraphicsEllipseItem* m_circle;
|
||||
@@ -81,6 +81,8 @@ private:
|
||||
double m_refSize;
|
||||
QPointF m_start;
|
||||
QPointF m_end;
|
||||
std::string m_featureName;
|
||||
double m_referenceAngle;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -974,18 +974,26 @@ void QGIViewPart::drawHighlight(TechDraw::DrawViewDetail* viewDetail, bool b)
|
||||
}
|
||||
|
||||
auto vp = static_cast<ViewProviderViewPart*>(getViewProvider(getViewObject()));
|
||||
if (!vp)
|
||||
if (!vp) {
|
||||
return;
|
||||
|
||||
}
|
||||
auto vpDetail = static_cast<ViewProviderViewPart*>(getViewProvider(viewDetail));
|
||||
if (!vpDetail) {
|
||||
return;
|
||||
}
|
||||
if (b) {
|
||||
// double fontSize = getPrefFontSize();
|
||||
double fontSize = Preferences::labelFontSizeMM();
|
||||
QGIHighlight* highlight = new QGIHighlight();
|
||||
addToGroup(highlight);
|
||||
highlight->setPos(0.0, 0.0);//sb setPos(center.x, center.y)?
|
||||
scene()->addItem(highlight);
|
||||
highlight->setReference(viewDetail->Reference.getValue());
|
||||
highlight->setStyle((Qt::PenStyle)vp->HighlightLineStyle.getValue());
|
||||
highlight->setColor(vp->HighlightLineColor.getValue().asValue<QColor>());
|
||||
highlight->setFeatureName(viewDetail->getNameInDocument());
|
||||
highlight->setInteractive(true);
|
||||
|
||||
addToGroup(highlight);
|
||||
highlight->setPos(0.0, 0.0);//sb setPos(center.x, center.y)?
|
||||
|
||||
Base::Vector3d center = viewDetail->AnchorPoint.getValue() * viewPart->getScale();
|
||||
double rotationRad = viewPart->Rotation.getValue() * M_PI / 180.0;
|
||||
@@ -997,17 +1005,32 @@ void QGIViewPart::drawHighlight(TechDraw::DrawViewDetail* viewDetail, bool b)
|
||||
highlight->setWidth(Rez::guiX(vp->IsoWidth.getValue()));
|
||||
highlight->setFont(getFont(), fontSize);
|
||||
highlight->setZValue(ZVALUE::HIGHLIGHT);
|
||||
highlight->setReferenceAngle(vpDetail->HighlightAdjust.getValue());
|
||||
|
||||
//handle conversion of apparent X,Y to rotated
|
||||
QPointF rotCenter = highlight->mapFromParent(transformOriginPoint());
|
||||
highlight->setTransformOriginPoint(rotCenter);
|
||||
|
||||
double rotation = viewPart->Rotation.getValue() + vp->HighlightAdjust.getValue();
|
||||
double rotation = viewPart->Rotation.getValue();
|
||||
highlight->setRotation(rotation);
|
||||
highlight->draw();
|
||||
}
|
||||
}
|
||||
|
||||
void QGIViewPart::highlightMoved(QGIHighlight* highlight, QPointF newPos)
|
||||
{
|
||||
std::string highlightName = highlight->getFeatureName();
|
||||
App::Document* doc = getViewObject()->getDocument();
|
||||
App::DocumentObject* docObj = doc->getObject(highlightName.c_str());
|
||||
auto detail = dynamic_cast<DrawViewDetail*>(docObj);
|
||||
auto oldAnchor = detail->AnchorPoint.getValue();
|
||||
if (detail) {
|
||||
Base::Vector3d delta = Rez::appX(DrawUtil::toVector3d(newPos)) / getViewObject()->getScale();
|
||||
delta = DrawUtil::invertY(delta);
|
||||
detail->AnchorPoint.setValue(oldAnchor + delta);
|
||||
}
|
||||
}
|
||||
|
||||
void QGIViewPart::drawMatting()
|
||||
{
|
||||
auto viewPart(dynamic_cast<TechDraw::DrawViewPart*>(getViewObject()));
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
#include <Mod/TechDraw/TechDrawGlobal.h>
|
||||
|
||||
#include <Mod/TechDraw/App/Geometry.h>
|
||||
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
|
||||
@@ -38,12 +40,14 @@ class DrawHatch;
|
||||
class DrawGeomHatch;
|
||||
class DrawViewDetail;
|
||||
class DrawView;
|
||||
|
||||
}
|
||||
|
||||
namespace TechDrawGui
|
||||
{
|
||||
class QGIFace;
|
||||
class QGIEdge;
|
||||
class QGIHighlight;
|
||||
|
||||
class TechDrawGuiExport QGIViewPart : public QGIView
|
||||
{
|
||||
@@ -76,6 +80,7 @@ public:
|
||||
void draw() override;
|
||||
void rotateView() override;
|
||||
|
||||
virtual void highlightMoved(QGIHighlight* highlight, QPointF newPos);
|
||||
|
||||
static QPainterPath geomToPainterPath(TechDraw::BaseGeomPtr baseGeom, double rotation = 0.0);
|
||||
/// Helper for pathArc()
|
||||
|
||||
@@ -132,6 +132,16 @@ ViewProviderViewPart::~ViewProviderViewPart()
|
||||
|
||||
void ViewProviderViewPart::onChanged(const App::Property* prop)
|
||||
{
|
||||
if (getViewPart()->isDerivedFrom(TechDraw::DrawViewDetail::getClassTypeId()) &&
|
||||
prop == &(HighlightAdjust)) {
|
||||
auto detail = static_cast<DrawViewDetail*>(getViewPart());
|
||||
auto baseDvp = dynamic_cast<DrawViewPart*>(detail->BaseView.getValue());
|
||||
if (baseDvp) {
|
||||
baseDvp->requestPaint();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (prop == &(LineWidth) ||
|
||||
prop == &(HiddenWidth) ||
|
||||
prop == &(IsoWidth) ||
|
||||
|
||||
Reference in New Issue
Block a user