Fix dimension highlighting problems

Derived all lines from PrimPath
This commit is contained in:
WandererFan 2016-08-03 13:05:25 -04:00 committed by wmayer
parent 5c63c8a957
commit fa57b7a5de
16 changed files with 278 additions and 87 deletions

View File

@ -95,6 +95,7 @@ DrawViewDimension::DrawViewDimension(void)
ADD_PROPERTY_TYPE(Fontsize,(4) ,"Format",(App::PropertyType)(App::Prop_None),"Dimension text size in mm");
ADD_PROPERTY_TYPE(FormatSpec,("%value%") ,"Format",(App::PropertyType)(App::Prop_None),"Dimension Format");
ADD_PROPERTY_TYPE(LineWidth,(0.5) ,"Format",(App::PropertyType)(App::Prop_None),"Dimension line weight");
//ADD_PROPERTY_TYPE(CentreLines,(0) ,"Format",(App::PropertyType)(App::Prop_None),"Arc Dimension Center Mark");
Type.setEnums(TypeEnums); //dimension type: length, radius etc
ADD_PROPERTY(Type,((long)0));
@ -130,6 +131,7 @@ void DrawViewDimension::onChanged(const App::Property* prop)
prop == &Font ||
prop == &Fontsize ||
prop == &FormatSpec ||
//prop == &CentreLines ||
prop == &LineWidth) {
try {
App::DocumentObjectExecReturn *ret = recompute();

View File

@ -56,6 +56,7 @@ public:
App::PropertyFloat Fontsize;
App::PropertyString FormatSpec;
App::PropertyFloat LineWidth;
//App::PropertyBool CentreLines;
//TODO: do we need a property for the actual dimension value? how else to access from Py?
//wf: expose getValue & getFormatedValue

View File

@ -132,6 +132,8 @@ SET(TechDrawGuiView_SRCS
QGIPrimPath.h
QGICMark.cpp
QGICMark.h
QGIDimLines.cpp
QGIDimLines.h
TemplateTextField.cpp
TemplateTextField.h
ZVALUE.h

View File

@ -50,6 +50,9 @@ QGCustomText::QGCustomText()
setAcceptHoverEvents(false);
setFlag(QGraphicsItem::ItemIsSelectable, false);
setFlag(QGraphicsItem::ItemIsMovable, false);
isHighlighted = false;
m_colCurrent = getNormalColor();
}
void QGCustomText::centerAt(QPointF centerPos)
@ -72,6 +75,50 @@ void QGCustomText::centerAt(double cX, double cY)
setPos(newX,newY);
}
QVariant QGCustomText::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == ItemSelectedHasChanged && scene()) {
if(isSelected()) {
setPrettySel();
} else {
setPrettyNormal();
}
}
return QGraphicsTextItem::itemChange(change, value);
}
void QGCustomText::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
if (!isSelected()) {
setPrettyPre();
}
QGraphicsTextItem::hoverEnterEvent(event);
}
void QGCustomText::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
if(!isSelected() && !isHighlighted) {
setPrettyNormal();
}
QGraphicsTextItem::hoverLeaveEvent(event);
}
void QGCustomText::setPrettyNormal() {
m_colCurrent = getNormalColor();
update();
}
void QGCustomText::setPrettyPre() {
m_colCurrent = getPreColor();
update();
}
void QGCustomText::setPrettySel() {
m_colCurrent = getSelectColor();
update();
}
void QGCustomText::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;
@ -102,6 +149,7 @@ void QGCustomText::paint ( QPainter * painter, const QStyleOptionGraphicsItem *
painter->scale(1.0,1.0);
}
setDefaultTextColor(m_colCurrent);
QGraphicsTextItem::paint (painter, &myOption, widget);
}

View File

@ -32,6 +32,8 @@ class QPainter;
class QStyleOptionGraphicsItem;
QT_END_NAMESPACE
#include <Base/Parameter.h>
namespace TechDrawGui
{
@ -44,20 +46,32 @@ public:
enum {Type = QGraphicsItem::UserType + 130};
int type() const { return Type;}
void setHighlighted(bool state);
void setPrettyNormal();
void setPrettyPre();
void setPrettySel();
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
virtual void centerAt(QPointF centerPos);
virtual void centerAt(double cX, double cY);
protected:
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
QColor getNormalColor(void);
QColor getPreColor(void);
QColor getSelectColor(void);
Base::Reference<ParameterGrp> getParmGroup(void);
bool isHighlighted;
QColor m_colCurrent;
private:
};
} // namespace MDIViewPageGui
}
#endif // DRAWINGGUI_QGCUSTOMTEXT_H

View File

@ -42,7 +42,7 @@ using namespace TechDrawGui;
QGICMark::QGICMark(int index) : QGIVertex(index)
{
m_size = 3.0;
m_thick = 0.75;
m_width = 0.75;
draw();
}
void QGICMark::draw(void)
@ -63,8 +63,7 @@ void QGICMark::setSize(float s)
void QGICMark::setThick(float t)
{
m_thick = t;
m_pen.setWidthF(m_thick);
m_width = t;
draw();
}
@ -86,7 +85,5 @@ void QGICMark::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;
m_pen.setWidthF(m_thick);
QGIVertex::paint (painter, &myOption, widget);
}

View File

@ -43,7 +43,7 @@ public:
void draw(void);
float getSize() { return m_size; }
void setSize(float s);
float getThick() { return m_thick; }
float getThick() { return m_width; }
void setThick(float t);
virtual void setPrettyNormal();
@ -53,7 +53,6 @@ protected:
private:
float m_size;
float m_thick;
};
}

View File

@ -0,0 +1,61 @@
/***************************************************************************
* Copyright (c) 2016 WandererFan <wandererfan@gmail.com> *
* *
* 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_
#include <assert.h>
#include <QGraphicsScene>
#include <QMenu>
#include <QMouseEvent>
#include <QGraphicsSceneHoverEvent>
#include <QStyleOptionGraphicsItem>
#include <QPainterPathStroker>
#include <QPainter>
#endif
#include "QGIView.h"
#include "QGIDimLines.h"
using namespace TechDrawGui;
QGIDimLines::QGIDimLines()
{
setCacheMode(QGraphicsItem::NoCache);
setAcceptHoverEvents(false);
setFlag(QGraphicsItem::ItemIsSelectable, false);
setFlag(QGraphicsItem::ItemIsMovable, false);
m_width = 0.5;
}
void QGIDimLines::draw()
{
}
//probably don't need this paint
void QGIDimLines::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;
QGIPrimPath::paint (painter, &myOption, widget);
}

View File

@ -0,0 +1,62 @@
/***************************************************************************
* Copyright (c) 2016 WandererFan <wandererfan@gmail.com> *
* *
* 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 DRAWINGGUI_QGRAPHICSITEMDIMLINES_H
#define DRAWINGGUI_QGRAPHICSITEMDIMLINES_H
# include "QGIPrimPath.h"
QT_BEGIN_NAMESPACE
class QPainter;
class QStyleOptionGraphicsItem;
QT_END_NAMESPACE
namespace TechDrawGui
{
class TechDrawGuiExport QGIDimLines : public QGIPrimPath
{
public:
explicit QGIDimLines();
~QGIDimLines() {}
enum {Type = QGraphicsItem::UserType + 172};
int type() const { return Type;}
public:
void draw();
//void setHighlighted(bool state);
//double getLineWidth() { return m_lineWidth; }
//void setLineWidth(double w);
//QPainterPath shape() const;
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
protected:
//QVariant itemChange(GraphicsItemChange change, const QVariant &value);
private:
};
}
#endif // DRAWINGGUI_QGRAPHICSITEMDIMLINES_H

View File

@ -46,10 +46,10 @@ QGIEdge::QGIEdge(int index) :
projIndex(index),
isCosmetic(false),
isHiddenEdge(false),
isSmoothEdge(false),
strokeWidth(1.0)
isSmoothEdge(false)
{
m_pen.setCosmetic(isCosmetic);
m_width = 1.0;
setCosmetic(isCosmetic);
}
QRectF QGIEdge::boundingRect() const
@ -70,14 +70,11 @@ QPainterPath QGIEdge::shape() const
void QGIEdge::setCosmetic(bool state)
{
isCosmetic = state;
m_pen.setCosmetic(state);
update();
if (state) {
setWidth(0.0);
}
}
void QGIEdge::setStrokeWidth(float width) {
strokeWidth = width;
update();
}
void QGIEdge::setHiddenEdge(bool b) {
isHiddenEdge = b;
@ -118,6 +115,5 @@ void QGIEdge::paint ( QPainter * painter, const QStyleOptionGraphicsItem * optio
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;
m_pen.setWidthF(strokeWidth);
QGIPrimPath::paint (painter, &myOption, widget);
}

View File

@ -44,7 +44,6 @@ public:
int getProjIndex() const { return projIndex; }
void setCosmetic(bool state);
void setStrokeWidth(float width);
void setHiddenEdge(bool b);
bool getHiddenEdge() { return(isHiddenEdge); }
void setSmoothEdge(bool b) { isSmoothEdge = b; }
@ -61,7 +60,6 @@ protected:
Qt::PenStyle getHiddenStyle();
private:
float strokeWidth;
};
}

View File

@ -51,13 +51,14 @@ QGIPrimPath::QGIPrimPath():
setAcceptHoverEvents(true);
isHighlighted = false;
setPrettyNormal();
m_colCurrent = getNormalColor();
m_styleCurrent = Qt::SolidLine;
m_pen.setStyle(m_styleCurrent);
m_pen.setCapStyle(Qt::RoundCap);
m_pen.setWidthF(m_width);
setPrettyNormal();
}
QVariant QGIPrimPath::itemChange(GraphicsItemChange change, const QVariant &value)
@ -120,6 +121,7 @@ void QGIPrimPath::paint ( QPainter * painter, const QStyleOptionGraphicsItem * o
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;
m_pen.setWidthF(m_width);
m_pen.setColor(m_colCurrent);
m_pen.setStyle(m_styleCurrent);
setPen(m_pen);
@ -156,6 +158,11 @@ void QGIPrimPath::setWidth(double w)
m_pen.setWidthF(m_width);
}
void QGIPrimPath::setStyle(Qt::PenStyle s)
{
m_styleCurrent = s;
}
Base::Reference<ParameterGrp> QGIPrimPath::getParmGroup()
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()

View File

@ -53,11 +53,13 @@ public:
virtual void setPrettySel();
virtual void setWidth(double w);
virtual double getWidth() { return m_width;}
Qt::PenStyle getStyle() { return m_styleCurrent; }
void setStyle(Qt::PenStyle s);
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
QColor getNormalColor(void);
QColor getPreColor(void);

View File

@ -55,6 +55,7 @@
#include <Mod/TechDraw/App/Geometry.h>
#include "QGIArrow.h"
#include "QGIDimLines.h"
#include "QGIViewDimension.h"
using namespace TechDrawGui;
@ -82,10 +83,10 @@ QVariant QGIDatumLabel::itemChange(GraphicsItemChange change, const QVariant &va
if (change == ItemSelectedHasChanged && scene()) {
if(isSelected()) {
Q_EMIT selected(true);
setDefaultTextColor(getSelectColor());
setPrettySel();
} else {
Q_EMIT selected(false);
setDefaultTextColor(getNormalColor());
setPrettyNormal();
}
update();
} else if(change == ItemPositionHasChanged && scene()) {
@ -93,7 +94,7 @@ QVariant QGIDatumLabel::itemChange(GraphicsItemChange change, const QVariant &va
Q_EMIT dragging();
}
return QGraphicsItem::itemChange(change, value);
return QGCustomText::itemChange(change, value);
}
void QGIDatumLabel::setPosFromCenter(const double &xCenter, const double &yCenter)
@ -112,8 +113,7 @@ void QGIDatumLabel::setLabelCenter()
void QGIDatumLabel::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_EMIT hover(true);
setDefaultTextColor(getPreColor());
update();
QGCustomText::hoverEnterEvent(event);
}
void QGIDatumLabel::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
@ -123,9 +123,9 @@ void QGIDatumLabel::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Q_EMIT hover(false);
if(!isSelected() && !view->isSelected()) {
setDefaultTextColor(getNormalColor());
update();
setPrettyNormal();
}
QGraphicsTextItem::hoverLeaveEvent(event);
}
void QGIDatumLabel::mouseReleaseEvent( QGraphicsSceneMouseEvent * event)
@ -145,12 +145,15 @@ QGIViewDimension::QGIViewDimension() :
datumLabel = new QGIDatumLabel();
addToGroup(datumLabel);
dimLines = new QGraphicsPathItem();
dimLines = new QGIDimLines();
addToGroup(dimLines);
aHead1 = new QGIArrow();
addToGroup(aHead1);
aHead2 = new QGIArrow();
addToGroup(aHead2);
//centerMark = new QGICMark();
//addToGroup(centerMark);
// connecting the needed slots and signals
QObject::connect(
@ -169,7 +172,7 @@ QGIViewDimension::QGIViewDimension() :
datumLabel, SIGNAL(hover(bool)),
this , SLOT (hover(bool)));
m_pen.setStyle(Qt::SolidLine);
dimLines->setStyle(Qt::SolidLine);
toggleBorder(false);
}
@ -188,6 +191,8 @@ void QGIViewDimension::setViewPartFeature(TechDraw::DrawViewDimension *obj)
datumLabel->setPosFromCenter(x, y);
m_lineWidth = obj->LineWidth.getValue();
updateDim();
draw();
}
@ -224,6 +229,9 @@ void QGIViewDimension::updateView(bool update)
dim->Y.isTouched()) {
datumLabel->setPosFromCenter(datumLabel->X(),datumLabel->Y());
updateDim();
} else if (dim->LineWidth.isTouched()) { //never happens!!
m_lineWidth = dim->LineWidth.getValue();
updateDim();
} else {
updateDim();
}
@ -242,8 +250,9 @@ void QGIViewDimension::updateDim()
font.setPointSizeF(dim->Fontsize.getValue()); //scene units (mm), not points
font.setFamily(QString::fromUtf8(dim->Font.getValue()));
datumLabel->setPlainText(labelText);
datumLabel->setFont(font);
prepareGeometryChange();
datumLabel->setPlainText(labelText);
datumLabel->setPosFromCenter(datumLabel->X(),datumLabel->Y());
}
@ -286,21 +295,11 @@ void QGIViewDimension::draw()
return;
}
m_pen.setWidthF(dim->LineWidth.getValue());
// Crude method of determining state [TODO] improve
if(isSelected()) {
m_pen.setColor(getSelectColor());
} else if (hasHover) {
m_pen.setColor(getPreColor());
} else {
m_pen.setColor(getNormalColor());
}
m_lineWidth = dim->LineWidth.getValue();
QString labelText = datumLabel->toPlainText();
Base::Vector3d lblCenter(datumLabel->X(), datumLabel->Y(), 0);
//we always draw based on Projected geometry.
//const std::vector<App::DocumentObject*> &objects = dim->References2D.getValues();
const std::vector<std::string> &SubNames = dim->References2D.getSubValues();
@ -437,7 +436,7 @@ void QGIViewDimension::draw()
}
dir.Normalize();
norm = Base::Vector3d (-dir.y,dir.x, 0);
norm = Base::Vector3d (-dir.y,dir.x, 0); //normal to dimension direction
// Get magnitude of angle between dir and horizontal
float angle = atan2f(dir.y,dir.x);
@ -455,7 +454,10 @@ void QGIViewDimension::draw()
// is replaced by its projection distStart_
// wf: in this case we can't use one of the Distance? end points as a reference for dim/ext lines. So we use the projection of
// startpoint(distStart) onto dimLine
float normproj12 = (distEnd-distStart).x * norm.x + (distEnd-distStart).y * norm.y;
// m = |proj(A on B)| = dot(A,unit(B)
// m = |proj(dimLine on normal)| = dot(dimLine,normal)
// newstartpt = oldstart + m*normal
float normproj12 = (distEnd-distStart).x * norm.x + (distEnd-distStart).y * norm.y; //dot(dirDimline, normal)
Base::Vector3d distStart_ = distStart + norm * normproj12;
//Base::Vector3d midpos = (distStart_ + distEnd) / 2;
@ -477,21 +479,19 @@ void QGIViewDimension::draw()
Base::Vector3d ext2End = distEnd + norm * (length + offset2 * scaler);
// Calculate the start/end for the Dimension lines
Base::Vector3d dim1Tip = distStart_ + norm * length; //dim line 1 tip
Base::Vector3d dim1Tail = lblCenter - dir * (w / 2 + margin); //dim line 1 tail
//dim1Tip is the position of 1 arrow point (lhs on a horizontal)
//dim2Tail is the position of the other arrow point (rhs)
Base::Vector3d dim1Tip = distStart_ + norm * length;
Base::Vector3d dim1Tail = lblCenter - dir * (w / 2 + margin);
Base::Vector3d dim2Tip = lblCenter + dir * (w / 2 + margin);
Base::Vector3d dim2Tail = distEnd + norm * length;
// Add a small margin
//distStart_ += norm * margin * 0.5;
// distEnd += norm * margin * 0.5;
bool flipTriang = false;
Base::Vector3d del1 = (dim2Tip-dim1Tip);
Base::Vector3d del2 = (dim1Tail-dim1Tip);
float dot1 = del1.x * dir.x + del1.y * dir.y;
float dot2 = del2.x * dir.x + del2.y * dir.y;
Base::Vector3d del1 = (dim2Tip-dim1Tip); //tip2 to tip1? len (dimline1 + label + margins)
Base::Vector3d del2 = (dim1Tail-dim1Tip); //tail1 to tip1? len(dimline1)
float dot1 = del1.x * dir.x + del1.y * dir.y; //dot (del1,dimlinedirection) => ???
float dot2 = del2.x * dir.x + del2.y * dir.y; //dot (del2,dimlinedirection) => ???
//Compare to see if Dimension text is larger than dimension
if (dot1 > (dim2Tail - dim1Tip).Length()) {
@ -522,6 +522,9 @@ void QGIViewDimension::draw()
path.lineTo(ext2End.x, ext2End.y);
//Dimension lines
//line tip goes just a bit too far. overlaps the arrowhead's point
//default arrow length is 5.0
path.moveTo(dim1Tip.x, dim1Tip.y);
path.lineTo(dim1Tail.x, dim1Tail.y);
@ -554,9 +557,6 @@ void QGIViewDimension::draw()
aHead1->setPos(dim1Tip.x, dim1Tip.y);
aHead2->setPos(dim2Tail.x, dim2Tail.y);
//aHead1->setHighlighted(isSelected() || hasHover); //setPrettyxxx??
//aHead2->setHighlighted(isSelected() || hasHover);
} else if(strcmp(dimType, "Diameter") == 0) {
// terminology: Dimension Text, Dimension Line(s), Extension Lines, Arrowheads
// was datumLabel, datum line/parallel line, perpendicular line, arw
@ -572,7 +572,6 @@ void QGIViewDimension::draw()
Base::Console().Log("INFO - qgivd::draw - no geom for projected edge: %d of %d\n",
idx,refObj->getEdgeGeometry().size());
return;
//throw Base::Exception("Edge couldn't be found for diameter dimension");
}
if( (geom->geomType == TechDrawGeometry::CIRCLE) ||
(geom->geomType == TechDrawGeometry::ARCOFCIRCLE) ) {
@ -657,7 +656,6 @@ void QGIViewDimension::draw()
path.moveTo(centre.x - radius, centre.y);
path.lineTo(arrow1Tip.x, arrow1Tip.y + tip);
// Left Arrow
path.moveTo(arrow1Tip.x, arrow1Tip.y); //dimension line, not arrowhead
path.lineTo(dLine1Tail.x, dLine1Tail.y);
@ -665,7 +663,6 @@ void QGIViewDimension::draw()
path.moveTo(centre.x + radius, centre.y);
path.lineTo(arrow2Tip.x, arrow2Tip.y + tip);
// Right arrow
path.moveTo(dLine2Tail.x, dLine2Tail.y);
path.lineTo(arrow2Tip.x, arrow2Tip.y);
@ -746,8 +743,6 @@ void QGIViewDimension::draw()
float arAngle = atan2(dirDimLine.y, dirDimLine.x) * 180 / M_PI;
//aHead1->setHighlighted(isSelected() || hasHover);
//aHead2->setHighlighted(isSelected() || hasHover);
aHead2->show();
if(outerPlacement) {
@ -772,6 +767,11 @@ void QGIViewDimension::draw()
aHead2->setPos(arrow1Tip.x, arrow1Tip.y);
}
// if (dim->CentreLines.getValue()) {
// centreMark->setPos(centre.x,centre.y);
// centerMark->show();
// dim->getViewPart()->addVertex(centre,true);
// }
} else if(strcmp(dimType, "Radius") == 0) {
// preferred terminology: Dimension Text, Dimension Line(s), Extension Lines, Arrowheads
// radius gets 1 dimension line from the dimension text to a point on the curve
@ -903,9 +903,13 @@ void QGIViewDimension::draw()
aHead1->setPos(ar1Pos.x, ar1Pos.y);
aHead1->setRotation(arAngle);
//aHead1->setHighlighted(isSelected() || hasHover);
aHead1->show();
aHead2->hide();
// if (dim->CentreLines.getValue()) {
// centreMark->setPos(curveCenter.x,curveCenter.y);
// centerMark->show();
// dim->getViewPart()->addVertex(curveCenter,true);
// }
} else if(strcmp(dimType, "Angle") == 0) {
// Only use two straight line edeges for angle
if(dim->References2D.getValues().size() == 2 &&
@ -1061,9 +1065,6 @@ void QGIViewDimension::draw()
isOutside = false;
}
// ###############
// Base::Console().Log("<%f, %f, %f>\n", startangle, endangle, labelangle);
QRectF arcRect(p0.x - length, p0.y - length, 2. * length, 2. * length);
path.arcMoveTo(arcRect, endangle * 180 / M_PI);
if(isOutside) {
@ -1111,9 +1112,6 @@ void QGIViewDimension::draw()
aHead2->setRotation(ar2angle);
}
//aHead1->setHighlighted(isSelected() || hasHover);
//aHead2->setHighlighted(isSelected() || hasHover);
// Set the angle of the datum text
Base::Vector3d labelNorm(-labelVec.y, labelVec.x, 0.);
@ -1136,15 +1134,18 @@ void QGIViewDimension::draw()
} //endif Distance/Diameter/Radius/Angle
// redraw the Dimension and the parent View
if (hasHover) {
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();
}
update();
@ -1182,7 +1183,6 @@ void QGIViewDimension::paint ( QPainter * painter, const QStyleOptionGraphicsIte
QPaintDevice* hw = painter->device();
QSvgGenerator* svg = dynamic_cast<QSvgGenerator*>(hw);
double saveWidth = m_pen.widthF();
double arrowSaveWidth = aHead1->getWidth();
if (svg) {
setSvgPens();
@ -1190,23 +1190,22 @@ void QGIViewDimension::paint ( QPainter * painter, const QStyleOptionGraphicsIte
setPens();
}
QGIView::paint (painter, &myOption, widget);
m_pen.setWidthF(saveWidth);
aHead1->setWidth(arrowSaveWidth);
aHead2->setWidth(arrowSaveWidth);
dimLines->setWidth(m_lineWidth);
}
void QGIViewDimension::setSvgPens(void)
{
double svgLineFactor = 3.0; //magic number. should be a setting somewhere.
m_pen.setWidthF(m_pen.widthF()/svgLineFactor);
dimLines->setPen(m_pen);
dimLines->setWidth(m_lineWidth/svgLineFactor);
aHead1->setWidth(aHead1->getWidth()/svgLineFactor);
aHead2->setWidth(aHead2->getWidth()/svgLineFactor);
}
void QGIViewDimension::setPens(void)
{
dimLines->setPen(m_pen);
dimLines->setWidth(m_lineWidth);
}
#include <Mod/TechDraw/Gui/moc_QGIViewDimension.cpp>

View File

@ -43,6 +43,7 @@ class AOC;
namespace TechDrawGui
{
class QGIArrow;
class QGIDimLines;
class QGIDatumLabel : public QGCustomText
{
@ -69,10 +70,10 @@ Q_SIGNALS:
protected:
// Preselection events:
void mouseReleaseEvent( QGraphicsSceneMouseEvent * event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
// Selection detection
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
double posX;
double posY;
@ -113,9 +114,11 @@ protected:
protected:
bool hasHover;
QGIDatumLabel* datumLabel; //dimension text
QGraphicsPathItem* dimLines; //dimension lines + extension lines
QGIDimLines* dimLines; //dimension lines + extension lines
QGIArrow* aHead1;
QGIArrow* aHead2;
//QGICMark* centerMark
double m_lineWidth;
};
} // namespace MDIViewPageGui

View File

@ -258,9 +258,9 @@ void QGIViewPart::updateView(bool update)
for(QList<QGraphicsItem*>::iterator it = items.begin(); it != items.end(); ++it) {
QGIEdge *edge = dynamic_cast<QGIEdge *>(*it);
if(edge && edge->getHiddenEdge()) {
edge->setStrokeWidth(viewPart->HiddenWidth.getValue() * lineScaleFactor);
edge->setWidth(viewPart->HiddenWidth.getValue() * lineScaleFactor);
} else {
edge->setStrokeWidth(viewPart->LineWidth.getValue() * lineScaleFactor);
edge->setWidth(viewPart->LineWidth.getValue() * lineScaleFactor);
}
}
draw();
@ -332,10 +332,10 @@ void QGIViewPart::drawViewPart()
addToGroup(item); //item is at scene(0,0), not group(0,0)
item->setPos(0.0,0.0); //now at group(0,0)
item->setPath(drawPainterPath(*itEdge));
item->setStrokeWidth(lineWidth);
item->setWidth(lineWidth);
item->setZValue(ZVALUE::EDGE);
if(!(*itEdge)->visible) {
item->setStrokeWidth(lineWidthHid);
item->setWidth(lineWidthHid);
item->setHiddenEdge(true);
item->setZValue(ZVALUE::HIDEDGE);
}
@ -359,7 +359,7 @@ void QGIViewPart::drawViewPart()
QGICMark* cmItem = new QGICMark(i);
addToGroup(cmItem);
cmItem->setPos((*vert)->pnt.fX, (*vert)->pnt.fY); //this is in ViewPart coords
cmItem->setThick(0.5 * lineWidth * lineScaleFactor);
cmItem->setThick(0.5 * lineWidth * lineScaleFactor); //need minimum?
cmItem->setSize( cAdjust * lineWidth * vertexScaleFactor);
cmItem->setZValue(ZVALUE::VERTEX);
}