Skip to content

Commit

Permalink
Fix dimension highlighting problems
Browse files Browse the repository at this point in the history
Derived all lines from PrimPath
  • Loading branch information
WandererFan authored and wwmayer committed Aug 16, 2016
1 parent 5c63c8a commit fa57b7a
Show file tree
Hide file tree
Showing 16 changed files with 278 additions and 87 deletions.
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/App/DrawViewDimension.cpp
Expand Up @@ -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));
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/App/DrawViewDimension.h
Expand Up @@ -56,6 +56,7 @@ class TechDrawExport DrawViewDimension : public TechDraw::DrawView
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
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/Gui/CMakeLists.txt
Expand Up @@ -132,6 +132,8 @@ SET(TechDrawGuiView_SRCS
QGIPrimPath.h
QGICMark.cpp
QGICMark.h
QGIDimLines.cpp
QGIDimLines.h
TemplateTextField.cpp
TemplateTextField.h
ZVALUE.h
Expand Down
48 changes: 48 additions & 0 deletions src/Mod/TechDraw/Gui/QGCustomText.cpp
Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
16 changes: 15 additions & 1 deletion src/Mod/TechDraw/Gui/QGCustomText.h
Expand Up @@ -32,6 +32,8 @@ class QPainter;
class QStyleOptionGraphicsItem;
QT_END_NAMESPACE

#include <Base/Parameter.h>

namespace TechDrawGui
{

Expand All @@ -44,20 +46,32 @@ class TechDrawGuiExport QGCustomText : public QGraphicsTextItem
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
7 changes: 2 additions & 5 deletions src/Mod/TechDraw/Gui/QGICMark.cpp
Expand Up @@ -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)
Expand All @@ -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();
}

Expand All @@ -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);
}
3 changes: 1 addition & 2 deletions src/Mod/TechDraw/Gui/QGICMark.h
Expand Up @@ -43,7 +43,7 @@ class TechDrawGuiExport QGICMark : public QGIVertex
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();

Expand All @@ -53,7 +53,6 @@ class TechDrawGuiExport QGICMark : public QGIVertex

private:
float m_size;
float m_thick;
};

}
Expand Down
61 changes: 61 additions & 0 deletions src/Mod/TechDraw/Gui/QGIDimLines.cpp
@@ -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);
}
62 changes: 62 additions & 0 deletions src/Mod/TechDraw/Gui/QGIDimLines.h
@@ -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
16 changes: 6 additions & 10 deletions src/Mod/TechDraw/Gui/QGIEdge.cpp
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
2 changes: 0 additions & 2 deletions src/Mod/TechDraw/Gui/QGIEdge.h
Expand Up @@ -44,7 +44,6 @@ class TechDrawGuiExport QGIEdge : public QGIPrimPath
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; }
Expand All @@ -61,7 +60,6 @@ class TechDrawGuiExport QGIEdge : public QGIPrimPath
Qt::PenStyle getHiddenStyle();

private:
float strokeWidth;
};

}
Expand Down

0 comments on commit fa57b7a

Please sign in to comment.