Fix overlap of dimension selection area

This commit is contained in:
wandererfan
2019-06-07 20:13:57 -04:00
committed by WandererFan
parent 5deca3b667
commit 4816755f42
5 changed files with 187 additions and 95 deletions

View File

@@ -32,6 +32,10 @@
#include <QPainter>
#endif
#include <App/Application.h>
#include <Base/Parameter.h>
#include <Base/Console.h>
#include "QGIDimLines.h"
using namespace TechDrawGui;
@@ -50,19 +54,36 @@ void QGIDimLines::draw()
{
}
QRectF QGIDimLines::boundingRect() const
QPainterPath QGIDimLines::shape() const
{
return shape().boundingRect().adjusted(-2, -2, 2, 2); //room for 0.5 line widths? needs Rez::guiX??
// return childrenBoundingRect().adjusted(-2,-2,2,2);
QPainterPath outline;
QPainterPathStroker stroker;
stroker.setWidth(getEdgeFuzz());
outline = stroker.createStroke(path());
return outline;
}
double QGIDimLines::getEdgeFuzz(void) const
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->
GetGroup("Preferences")->GetGroup("Mod/TechDraw/General");
double result = hGrp->GetFloat("EdgeFuzz",10.0);
return result;
}
QRectF QGIDimLines::boundingRect() const
{
return shape().controlPointRect().adjusted(-3, -3, 3, 3);
}
//probably don't need this paint
void QGIDimLines::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;
// painter->drawRect(boundingRect()); //good for debugging
// painter->drawRect(boundingRect()); //good for debugging
// painter->drawPath(shape()); //good for debugging
QGIPrimPath::paint (painter, &myOption, widget);
}

View File

@@ -41,7 +41,8 @@ public:
enum {Type = QGraphicsItem::UserType + 175};
int type() const { return Type;}
QRectF boundingRect() const;
virtual QRectF boundingRect() const override;
virtual QPainterPath shape() const override;
public:
void draw();
@@ -53,6 +54,7 @@ public:
protected:
//QVariant itemChange(GraphicsItemChange change, const QVariant &value);
double getEdgeFuzz(void) const;
private:

View File

@@ -52,10 +52,8 @@
#include "ZVALUE.h"
#include "DrawGuiUtil.h"
#include "QGVPage.h"
#include "QGCustomBorder.h"
#include "QGCustomLabel.h"
#include "QGCustomBorder.h"
#include "QGCustomLabel.h"
#include "QGCustomText.h"
#include "QGICaption.h"
#include "QGCustomClip.h"

View File

@@ -56,6 +56,13 @@
#include "Rez.h"
#include "ZVALUE.h"
#include "QGCustomLabel.h"
#include "QGCustomBorder.h"
#include "QGCustomText.h"
#include "QGICaption.h"
#include "QGCustomImage.h"
#include "QGIArrow.h"
#include "QGIDimLines.h"
#include "QGIViewDimension.h"
@@ -90,6 +97,7 @@ QGIDatumLabel::QGIDatumLabel()
m_tolText->setParentItem(this);
m_ctrl = false;
hasHover = false;
}
QVariant QGIDatumLabel::itemChange(GraphicsItemChange change, const QVariant &value)
@@ -141,6 +149,7 @@ void QGIDatumLabel::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
void QGIDatumLabel::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_EMIT hover(true);
hasHover = true;
if (!isSelected()) {
setPrettyPre();
}
@@ -154,6 +163,7 @@ void QGIDatumLabel::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Q_UNUSED(view);
Q_EMIT hover(false);
hasHover = false;
if (!isSelected()) {
setPrettyNormal();
}
@@ -303,6 +313,9 @@ QGIViewDimension::QGIViewDimension() :
{
setHandlesChildEvents(false);
setFlag(QGraphicsItem::ItemIsMovable, false);
setFlag(QGraphicsItem::ItemIsSelectable, false);
// setAcceptHoverEvents(true);
setAcceptHoverEvents(false);
setCacheMode(QGraphicsItem::NoCache);
datumLabel = new QGIDatumLabel();
@@ -344,12 +357,63 @@ QGIViewDimension::QGIViewDimension() :
dimLines->setStyle(Qt::SolidLine);
// toggleBorder(false);
setZValue(ZVALUE::DIMENSION); //note: this won't paint dimensions over another View if it stacks
//above this Dimension's parent view. need Layers?
setZValue(ZVALUE::DIMENSION); //note: this won't paint dimensions over another View if it stacks
//above this Dimension's parent view. need Layers?
m_label->hide();
m_border->hide();
m_caption->hide();
m_lock->hide();
setPrettyNormal();
}
QVariant QGIViewDimension::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == ItemSelectedHasChanged && scene()) {
if(isSelected()) {
setSelected(false);
datumLabel->setSelected(true);
} else {
datumLabel->setSelected(false);
}
draw();
}
return QGIView::itemChange(change, value);
}
void QGIViewDimension::select(bool state)
{
// Base::Console().Message("QGIVD::select(%d)\n", state);
if (state) {
setPrettySel();
} else {
setPrettyNormal();
}
draw();
}
//surrogate for hover enter (true), hover leave (false) events
void QGIViewDimension::hover(bool state)
{
hasHover = state;
if (state) {
if (datumLabel->isSelected()) {
setPrettySel();
} else {
setPrettyPre(); //have hover, not selected -> preselect
}
} else {
if (datumLabel->isSelected()) {
setPrettySel();
} else {
setPrettyNormal();
}
}
draw();
}
void QGIViewDimension::setViewPartFeature(TechDraw::DrawViewDimension *obj)
{
@@ -368,18 +432,6 @@ void QGIViewDimension::setViewPartFeature(TechDraw::DrawViewDimension *obj)
draw();
}
void QGIViewDimension::select(bool state)
{
setSelected(state);
draw();
}
void QGIViewDimension::hover(bool state)
{
hasHover = state;
draw();
}
void QGIViewDimension::updateView(bool update)
{
Q_UNUSED(update);
@@ -472,7 +524,7 @@ void QGIViewDimension::datumLabelDragFinished()
void QGIViewDimension::draw()
{
if (!isVisible()) { //should this be controlled by parent ViewPart?
if (!isVisible()) {
return;
}
@@ -1135,7 +1187,7 @@ void QGIViewDimension::draw()
float bbX = datumLabel->boundingRect().width();
float bbY = datumLabel->boundingRect().height();
datumLabel->setTransformOriginPoint(bbX / 2, bbY /2);
datumLabel->setRotation(0.0); //label is always right side up & horizontal
datumLabel->setRotation(0.0); //label is always right side up & horizontal
//if inside the arc (len(DimLine < radius)) arrow goes from center to edge away from label
//if outside the arc arrow kinks, then goes to edge nearest label
@@ -1418,20 +1470,15 @@ void QGIViewDimension::draw()
} //endif Distance/Diameter/Radius/Angle
// redraw the Dimension and the parent View
if (hasHover && !isSelected()) {
aHead1->setPrettyPre();
aHead2->setPrettyPre();
dimLines->setPrettyPre();
} else if (isSelected()) {
aHead1->setPrettySel();
aHead2->setPrettySel();
dimLines->setPrettySel();
} else {
aHead1->setPrettyNormal();
aHead2->setPrettyNormal();
dimLines->setPrettyNormal();
}
//this is already handled in select() and hover()
// // redraw the Dimension and the parent View
// if (datumLabel->hasHover && !datumLabel->isSelected()) {
// setPrettyPre();
// } else if (datumLabel->isSelected()) {
// setPrettySel();
// } else {
// setPrettyNormal();
// }
update();
if (parentItem()) {
@@ -1442,59 +1489,6 @@ void QGIViewDimension::draw()
}
}
void QGIViewDimension::drawBorder(void)
{
//Dimensions have no border!
// Base::Console().Message("TRACE - QGIViewDimension::drawBorder - doing nothing!\n");
}
QVariant QGIViewDimension::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == ItemSelectedHasChanged && scene()) {
if(isSelected()) {
datumLabel->setSelected(true);
} else {
datumLabel->setSelected(false);
}
draw();
}
return QGIView::itemChange(change, value);
}
void QGIViewDimension::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;
QPaintDevice* hw = painter->device();
QSvgGenerator* svg = dynamic_cast<QSvgGenerator*>(hw);
setPens();
//double arrowSaveWidth = aHead1->getWidth();
if (svg) {
setSvgPens();
} else {
setPens();
}
// painter->drawRect(boundingRect()); //good for debugging
QGIView::paint (painter, &myOption, widget);
setPens();
}
void QGIViewDimension::setSvgPens(void)
{
double svgLineFactor = 3.0; //magic number. should be a setting somewhere.
dimLines->setWidth(m_lineWidth/svgLineFactor);
aHead1->setWidth(aHead1->getWidth()/svgLineFactor);
aHead2->setWidth(aHead2->getWidth()/svgLineFactor);
}
void QGIViewDimension::setPens(void)
{
dimLines->setWidth(m_lineWidth);
aHead1->setWidth(m_lineWidth);
aHead2->setWidth(m_lineWidth);
}
QColor QGIViewDimension::getNormalColor()
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
@@ -1569,6 +1563,33 @@ Base::Vector3d QGIViewDimension::findIsoExt(Base::Vector3d dir)
return dirExt;
}
void QGIViewDimension::setPrettyPre(void)
{
aHead1->setPrettyPre();
aHead2->setPrettyPre();
dimLines->setPrettyPre();
}
void QGIViewDimension::setPrettySel(void)
{
aHead1->setPrettySel();
aHead2->setPrettySel();
dimLines->setPrettySel();
}
void QGIViewDimension::setPrettyNormal(void)
{
aHead1->setPrettyNormal();
aHead2->setPrettyNormal();
dimLines->setPrettyNormal();
}
void QGIViewDimension::drawBorder(void)
{
//Dimensions have no border!
// Base::Console().Message("TRACE - QGIViewDimension::drawBorder - doing nothing!\n");
}
const double QGIViewDimension::TextOffsetFudge = 2.0;
double QGIViewDimension::getDefaultTextHorizontalOffset(bool toLeft) const
@@ -1592,9 +1613,53 @@ double QGIViewDimension::getDefaultTextVerticalOffset() const
return textMult*Rez::guiX(vp->Fontsize.getValue()) + TextOffsetFudge;
}
//frame, border, caption are never shown in QGIVD, so shouldn't be in bRect
QRectF QGIViewDimension::boundingRect() const
{
return childrenBoundingRect().adjusted(-3,-3,3,3);
QRectF labelRect = mapFromItem(datumLabel, datumLabel->boundingRect()).boundingRect();
QRectF linesRect = mapFromItem(dimLines, dimLines->boundingRect()).boundingRect();
QRectF aHead1Rect = mapFromItem(aHead1, aHead1->boundingRect()).boundingRect();
QRectF aHead2Rect = mapFromItem(aHead2, aHead2->boundingRect()).boundingRect();
QRectF result(labelRect);
result = result.united(linesRect);
result = result.united(aHead1Rect);
result = result.united(aHead2Rect);
return result;
}
void QGIViewDimension::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;
QPaintDevice* hw = painter->device();
QSvgGenerator* svg = dynamic_cast<QSvgGenerator*>(hw);
setPens();
//double arrowSaveWidth = aHead1->getWidth();
if (svg) {
setSvgPens();
} else {
setPens();
}
// painter->drawRect(boundingRect()); //good for debugging
// QGIView::paint (painter, &myOption, widget);
QGraphicsItemGroup::paint(painter, &myOption, widget);
setPens();
}
void QGIViewDimension::setSvgPens(void)
{
double svgLineFactor = 3.0; //magic number. should be a setting somewhere.
dimLines->setWidth(m_lineWidth/svgLineFactor);
aHead1->setWidth(aHead1->getWidth()/svgLineFactor);
aHead2->setWidth(aHead2->getWidth()/svgLineFactor);
}
void QGIViewDimension::setPens(void)
{
dimLines->setWidth(m_lineWidth);
aHead1->setWidth(m_lineWidth);
aHead2->setWidth(m_lineWidth);
}

View File

@@ -89,6 +89,8 @@ public:
void setTolText(QGCustomText* newTol) { m_tolText = newTol; }
double getTolAdjust(void);
bool hasHover;
Q_SIGNALS:
void dragging(bool);
@@ -112,7 +114,7 @@ protected:
double posX;
double posY;
private:
};
@@ -130,7 +132,7 @@ public:
void setViewPartFeature(TechDraw::DrawViewDimension *obj);
int type() const override { return Type;}
QRectF boundingRect() const;
virtual QRectF boundingRect() const override;
virtual void paint( QPainter * painter,
const QStyleOptionGraphicsItem * option,
QWidget * widget = 0 ) override;
@@ -139,6 +141,10 @@ public:
virtual void updateView(bool update = false) override;
virtual QColor getNormalColor(void) override;
QString getLabelText(void);
void setPrettyPre(void);
void setPrettySel(void);
void setPrettyNormal(void);
public Q_SLOTS:
void datumLabelDragged(bool ctrl);