Fix Vertex hover behaviour
Refactor to reduce duplicate code Fix Section face color mix on hover
This commit is contained in:
parent
dd5b461e35
commit
8d859c91e1
|
@ -128,6 +128,8 @@ SET(TechDrawGuiView_SRCS
|
|||
QGIViewSpreadsheet.h
|
||||
QGIViewClip.cpp
|
||||
QGIViewClip.h
|
||||
QGIPrimPath.cpp
|
||||
QGIPrimPath.h
|
||||
TemplateTextField.cpp
|
||||
TemplateTextField.h
|
||||
ZVALUE.h
|
||||
|
|
|
@ -45,40 +45,25 @@ using namespace TechDrawGui;
|
|||
QGIEdge::QGIEdge(int index) :
|
||||
projIndex(index)
|
||||
{
|
||||
setCacheMode(QGraphicsItem::NoCache);
|
||||
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
setFlag(QGraphicsItem::ItemIsMovable, false);
|
||||
setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true);
|
||||
setFlag(QGraphicsItem::ItemSendsGeometryChanges,true);
|
||||
setAcceptHoverEvents(true);
|
||||
|
||||
strokeWidth = 1.;
|
||||
|
||||
isCosmetic = false;
|
||||
m_pen.setCosmetic(isCosmetic);
|
||||
isHighlighted = false;
|
||||
isHiddenEdge = false;
|
||||
isSmoothEdge = false;
|
||||
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
|
||||
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors");
|
||||
App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("NormalColor", 0x00000000));
|
||||
m_colNormal = fcColor.asValue<QColor>();
|
||||
m_defNormal = m_colNormal;
|
||||
fcColor.setPackedValue(hGrp->GetUnsigned("SelectColor", 0x0000FF00));
|
||||
m_colSel = fcColor.asValue<QColor>();
|
||||
fcColor.setPackedValue(hGrp->GetUnsigned("PreSelectColor", 0x00080800));
|
||||
m_colPre = fcColor.asValue<QColor>();
|
||||
App::Color fcColor;
|
||||
fcColor.setPackedValue(hGrp->GetUnsigned("HiddenColor", 0x08080800));
|
||||
m_colHid = fcColor.asValue<QColor>();
|
||||
|
||||
hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw");
|
||||
m_styleHid = static_cast<Qt::PenStyle> (hGrp->GetInt("HiddenLine",2));
|
||||
|
||||
m_pen.setStyle(Qt::SolidLine);
|
||||
m_pen.setCapStyle(Qt::RoundCap);
|
||||
|
||||
setPrettyNormal();
|
||||
//m_pen.setStyle(Qt::SolidLine);
|
||||
//m_pen.setCapStyle(Qt::RoundCap);
|
||||
}
|
||||
|
||||
QRectF QGIEdge::boundingRect() const
|
||||
|
@ -96,68 +81,13 @@ QPainterPath QGIEdge::shape() const
|
|||
}
|
||||
|
||||
|
||||
QVariant QGIEdge::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
if (change == ItemSelectedHasChanged && scene()) {
|
||||
if(isSelected()) {
|
||||
setPrettySel();
|
||||
} else {
|
||||
setPrettyNormal();
|
||||
}
|
||||
}
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
void QGIEdge::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
if (!isSelected()) {
|
||||
setPrettyPre();
|
||||
}
|
||||
QGraphicsPathItem::hoverEnterEvent(event);
|
||||
}
|
||||
|
||||
void QGIEdge::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
QGIView *view = dynamic_cast<QGIView *> (parentItem()); //this is temp for debug??
|
||||
assert(view != 0);
|
||||
if(!isSelected() && !isHighlighted) {
|
||||
setPrettyNormal();
|
||||
}
|
||||
QGraphicsPathItem::hoverLeaveEvent(event);
|
||||
}
|
||||
|
||||
void QGIEdge::setCosmetic(bool state)
|
||||
{
|
||||
isCosmetic = state;
|
||||
m_pen.setCosmetic(state);
|
||||
update();
|
||||
}
|
||||
|
||||
// obs?
|
||||
void QGIEdge::setHighlighted(bool b)
|
||||
{
|
||||
isHighlighted = b;
|
||||
if(isHighlighted) {
|
||||
setPrettySel();
|
||||
} else {
|
||||
setPrettyNormal();
|
||||
}
|
||||
}
|
||||
|
||||
void QGIEdge::setPrettyNormal() {
|
||||
m_colCurrent = m_colNormal;
|
||||
update();
|
||||
}
|
||||
|
||||
void QGIEdge::setPrettyPre() {
|
||||
m_colCurrent = m_colPre;
|
||||
update();
|
||||
}
|
||||
|
||||
void QGIEdge::setPrettySel() {
|
||||
m_colCurrent = m_colSel;
|
||||
update();
|
||||
}
|
||||
|
||||
void QGIEdge::setStrokeWidth(float width) {
|
||||
strokeWidth = width;
|
||||
update();
|
||||
|
@ -180,7 +110,5 @@ void QGIEdge::paint ( QPainter * painter, const QStyleOptionGraphicsItem * optio
|
|||
myOption.state &= ~QStyle::State_Selected;
|
||||
|
||||
m_pen.setWidthF(strokeWidth);
|
||||
m_pen.setColor(m_colCurrent);
|
||||
setPen(m_pen);
|
||||
QGraphicsPathItem::paint (painter, &myOption, widget);
|
||||
QGIPrimPath::paint (painter, &myOption, widget);
|
||||
}
|
||||
|
|
|
@ -23,12 +23,7 @@
|
|||
#ifndef DRAWINGGUI_QGRAPHICSITEMEDGE_H
|
||||
#define DRAWINGGUI_QGRAPHICSITEMEDGE_H
|
||||
|
||||
# include <QGraphicsItem>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QPainter;
|
||||
class QStyleOptionGraphicsItem;
|
||||
QT_END_NAMESPACE
|
||||
#include "QGIPrimPath.h"
|
||||
|
||||
namespace TechDrawGeometry {
|
||||
class BaseGeom;
|
||||
|
@ -37,7 +32,7 @@ class BaseGeom;
|
|||
namespace TechDrawGui
|
||||
{
|
||||
|
||||
class TechDrawGuiExport QGIEdge : public QGraphicsPathItem
|
||||
class TechDrawGuiExport QGIEdge : public QGIPrimPath
|
||||
{
|
||||
public:
|
||||
explicit QGIEdge(int index);
|
||||
|
@ -52,41 +47,27 @@ public:
|
|||
|
||||
int getProjIndex() const { return projIndex; }
|
||||
|
||||
void setHighlighted(bool state);
|
||||
void setCosmetic(bool state);
|
||||
void setStrokeWidth(float width);
|
||||
void setPrettyNormal();
|
||||
void setPrettyPre();
|
||||
void setPrettySel();
|
||||
void setHiddenEdge(bool b);
|
||||
bool getHiddenEdge() { return(isHiddenEdge); }
|
||||
void setSmoothEdge(bool b) { isSmoothEdge = b; }
|
||||
bool getSmoothEdge() { return(isSmoothEdge); }
|
||||
|
||||
protected:
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
|
||||
int projIndex; //index of edge in Projection. must exist.
|
||||
|
||||
bool isHighlighted;
|
||||
bool isCosmetic;
|
||||
bool isHiddenEdge;
|
||||
bool isSmoothEdge;
|
||||
|
||||
private:
|
||||
float strokeWidth;
|
||||
QPen m_pen;
|
||||
QColor m_colCurrent;
|
||||
QColor m_colNormal;
|
||||
QColor m_colPre;
|
||||
QColor m_colSel;
|
||||
QColor m_colHid;
|
||||
QColor m_defNormal;
|
||||
Qt::PenStyle m_styleHid;
|
||||
};
|
||||
|
||||
} // namespace MDIViewPageGui
|
||||
}
|
||||
|
||||
#endif // DRAWINGGUI_QGRAPHICSITEMEDGE_H
|
||||
|
|
|
@ -56,40 +56,15 @@ QGIFace::QGIFace(int index) :
|
|||
m_styleDef(Qt::SolidPattern),
|
||||
m_styleSelect(Qt::SolidPattern)
|
||||
{
|
||||
setCacheMode(QGraphicsItem::NoCache);
|
||||
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
setFlag(QGraphicsItem::ItemIsMovable, false);
|
||||
setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true);
|
||||
setFlag(QGraphicsItem::ItemSendsGeometryChanges,true);
|
||||
setFlag(QGraphicsItem::ItemClipsChildrenToShape,true);
|
||||
//setFiltersChildEvents(true);
|
||||
setAcceptHoverEvents(true);
|
||||
|
||||
isHighlighted = false;
|
||||
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
|
||||
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors");
|
||||
App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("NormalColor", 0x00000000));
|
||||
m_colNormal = fcColor.asValue<QColor>();
|
||||
fcColor.setPackedValue(hGrp->GetUnsigned("SelectColor", 0x0000FF00));
|
||||
m_colSel = fcColor.asValue<QColor>();
|
||||
fcColor.setPackedValue(hGrp->GetUnsigned("PreSelectColor", 0x00080800));
|
||||
m_colPre = fcColor.asValue<QColor>();
|
||||
|
||||
m_pen.setCosmetic(true);
|
||||
m_pen.setColor(m_colNormal);
|
||||
|
||||
m_brushDef.setColor(m_colDefFill);
|
||||
m_brushDef.setStyle(m_styleDef);
|
||||
m_brushNormal = m_brushDef;
|
||||
m_brushCurrent = m_brushNormal;
|
||||
m_styleNormal = m_styleDef;
|
||||
m_colNormalFill = m_colDefFill;
|
||||
setPrettyNormal();
|
||||
|
||||
m_brushPre.setColor(m_colPre);
|
||||
m_brushPre.setStyle(m_styleSelect);
|
||||
m_brushSel.setColor(m_colSel);
|
||||
m_brushSel.setStyle(m_styleSelect);
|
||||
|
||||
m_svg = new QGCustomSvg();
|
||||
|
||||
m_rect = new QGCustomRect();
|
||||
|
@ -103,85 +78,37 @@ QGIFace::~QGIFace()
|
|||
//nothing to do. every item is a child of QGIFace & will get removed/deleted when QGIF is deleted
|
||||
}
|
||||
|
||||
QVariant QGIFace::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
if (change == ItemSelectedHasChanged && scene()) {
|
||||
if(isSelected()) { //this is only QtGui Selected, not FC selected?
|
||||
setPrettySel();
|
||||
} else {
|
||||
setPrettyNormal();
|
||||
}
|
||||
}
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
void QGIFace::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
if (!isSelected() && !isHighlighted) {
|
||||
setPrettyPre();
|
||||
}
|
||||
QGraphicsPathItem::hoverEnterEvent(event);
|
||||
}
|
||||
|
||||
void QGIFace::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
if (!isSelected()) {
|
||||
setPrettyNormal();
|
||||
}
|
||||
QGraphicsPathItem::hoverLeaveEvent(event);
|
||||
}
|
||||
|
||||
void QGIFace::mousePressEvent(QGraphicsSceneMouseEvent * event)
|
||||
{
|
||||
QGraphicsItem::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void QGIFace::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
|
||||
{
|
||||
QGraphicsItem::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void QGIFace::setPrettyNormal() {
|
||||
m_colCurrent = m_colNormal;
|
||||
m_brushCurrent = m_brushNormal;
|
||||
update();
|
||||
m_fillStyle = m_styleNormal;
|
||||
m_fillColor = m_colNormalFill;
|
||||
QGIPrimPath::setPrettyNormal();
|
||||
}
|
||||
|
||||
void QGIFace::setPrettyPre() {
|
||||
m_colCurrent = m_colPre;
|
||||
m_brushCurrent = m_brushPre;
|
||||
update();
|
||||
m_fillStyle = m_styleSelect;
|
||||
m_fillColor = m_colPre;
|
||||
QGIPrimPath::setPrettyPre();
|
||||
}
|
||||
|
||||
void QGIFace::setPrettySel() {
|
||||
m_colCurrent = m_colSel;
|
||||
m_brushCurrent = m_brushSel;
|
||||
update();
|
||||
}
|
||||
|
||||
void QGIFace::setHighlighted(bool b)
|
||||
{
|
||||
isHighlighted = b;
|
||||
if(isHighlighted && isSelected()) {
|
||||
setPrettySel();
|
||||
} else if (isHighlighted) {
|
||||
setPrettyPre();
|
||||
} else {
|
||||
setPrettyNormal();
|
||||
}
|
||||
m_fillStyle = m_styleSelect;
|
||||
m_fillColor = m_colSel;
|
||||
QGIPrimPath::setPrettySel();
|
||||
}
|
||||
|
||||
void QGIFace::setFill(QColor c, Qt::BrushStyle s) {
|
||||
//m_colNormalFill = c;
|
||||
//m_styleNormal = s;
|
||||
m_brushNormal.setColor(c);
|
||||
m_brushNormal.setStyle(s);
|
||||
m_colNormalFill = c;
|
||||
m_styleNormal = s;
|
||||
}
|
||||
|
||||
void QGIFace::setFill(QBrush b) {
|
||||
m_colNormalFill = b.color();
|
||||
//m_styleCurr = b.style();
|
||||
m_brushNormal = b;
|
||||
m_styleNormal = b.style();
|
||||
}
|
||||
|
||||
void QGIFace::resetFill() {
|
||||
m_colNormalFill = m_colDefFill;
|
||||
m_styleNormal = m_styleDef;
|
||||
}
|
||||
|
||||
void QGIFace::setHatch(std::string fileSpec)
|
||||
|
@ -211,7 +138,7 @@ void QGIFace::setPath(const QPainterPath & path)
|
|||
|
||||
void QGIFace::buildHatch()
|
||||
{
|
||||
m_brushNormal.setStyle(Qt::NoBrush );
|
||||
m_styleNormal = Qt::NoBrush;
|
||||
double w = boundingRect().width();
|
||||
double h = boundingRect().height();
|
||||
QRectF r = boundingRect();
|
||||
|
@ -222,7 +149,6 @@ void QGIFace::buildHatch()
|
|||
h = nh * SVGSIZEW;
|
||||
m_rect->setRect(0.,0.,w,-h);
|
||||
m_rect->centerAt(fCenter);
|
||||
//QPointF rPos = m_rect->pos();
|
||||
r = m_rect->rect();
|
||||
QByteArray before,after;
|
||||
before.append(QString::fromStdString(SVGCOLPREFIX + SVGCOLDEFAULT));
|
||||
|
@ -232,7 +158,6 @@ void QGIFace::buildHatch()
|
|||
for (int ih = 0; ih < int(nh); ih++) {
|
||||
QGCustomSvg* tile = new QGCustomSvg();
|
||||
if (tile->load(&colorXML)) {
|
||||
//if (tile->load(&m_svgXML)) {
|
||||
tile->setParentItem(m_rect);
|
||||
tile->setPos(iw*SVGSIZEW,-h + ih*SVGSIZEH);
|
||||
}
|
||||
|
@ -248,15 +173,6 @@ void QGIFace::setHatchColor(std::string c)
|
|||
m_svgCol = c;
|
||||
}
|
||||
|
||||
void QGIFace::resetFill() {
|
||||
m_colNormalFill = m_colDefFill;
|
||||
//m_styleCurr = m_styleDef;
|
||||
m_styleNormal = m_styleDef;
|
||||
m_brushNormal.setColor(m_colDefFill);
|
||||
m_brushNormal.setStyle(m_styleDef);
|
||||
m_brushCurrent = m_brushNormal;
|
||||
}
|
||||
|
||||
QRectF QGIFace::boundingRect() const
|
||||
{
|
||||
return shape().controlPointRect();
|
||||
|
@ -271,10 +187,8 @@ void QGIFace::paint ( QPainter * painter, const QStyleOptionGraphicsItem * optio
|
|||
QStyleOptionGraphicsItem myOption(*option);
|
||||
myOption.state &= ~QStyle::State_Selected;
|
||||
|
||||
m_pen.setColor(m_colCurrent);
|
||||
setPen(m_pen);
|
||||
//m_brush.setStyle(m_styleCurr);
|
||||
//m_brush.setColor(m_colCurrFill);
|
||||
setBrush(m_brushCurrent);
|
||||
QGraphicsPathItem::paint (painter, &myOption, widget);
|
||||
m_brush.setStyle(m_fillStyle);
|
||||
m_brush.setColor(m_fillColor);
|
||||
setBrush(m_brush);
|
||||
QGIPrimPath::paint (painter, &myOption, widget);
|
||||
}
|
||||
|
|
|
@ -28,14 +28,10 @@
|
|||
#include <QSvgRenderer>
|
||||
#include <QByteArray>
|
||||
|
||||
#include "QGIPrimPath.h"
|
||||
#include "QGCustomSvg.h"
|
||||
#include "QGCustomRect.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QPainter;
|
||||
class QStyleOptionGraphicsItem;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace TechDrawGeometry {
|
||||
class BaseGeom;
|
||||
}
|
||||
|
@ -48,7 +44,7 @@ namespace TechDrawGui
|
|||
const std::string SVGCOLPREFIX = "stroke:";
|
||||
const std::string SVGCOLDEFAULT = "#000000";
|
||||
|
||||
class QGIFace : public QGraphicsPathItem
|
||||
class QGIFace : public QGIPrimPath
|
||||
{
|
||||
public:
|
||||
explicit QGIFace(int index = -1);
|
||||
|
@ -63,7 +59,6 @@ public:
|
|||
public:
|
||||
int getProjIndex() const { return projIndex; }
|
||||
|
||||
void setHighlighted(bool state);
|
||||
void setPrettyNormal();
|
||||
void setPrettyPre();
|
||||
void setPrettySel();
|
||||
|
@ -75,46 +70,26 @@ public:
|
|||
void buildHatch(void);
|
||||
void setHatchColor(std::string c);
|
||||
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
|
||||
|
||||
protected:
|
||||
// Preselection events:
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||
// Selection detection
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent * event);
|
||||
bool load(QByteArray *svgBytes);
|
||||
|
||||
protected:
|
||||
int projIndex; //index of face in Projection. -1 for SectionFace.
|
||||
bool isHighlighted;
|
||||
QGCustomRect *m_rect;
|
||||
QGCustomSvg *m_svg;
|
||||
QByteArray m_svgXML;
|
||||
std::string m_svgCol;
|
||||
|
||||
private:
|
||||
QPen m_pen;
|
||||
QBrush m_brush;
|
||||
QColor m_colNormal;
|
||||
QColor m_colPre;
|
||||
QColor m_colSel;
|
||||
QColor m_colCurrent;
|
||||
QColor m_defNormal; //pen default normal color
|
||||
Qt::BrushStyle m_fillStyle; //current fill style
|
||||
QColor m_fillColor; //current fill color
|
||||
|
||||
QColor m_colDefFill; //"no color"
|
||||
QColor m_colCurrFill; //current color
|
||||
QColor m_colNormalFill;
|
||||
Qt::BrushStyle m_styleDef; //default Normal fill fill style
|
||||
Qt::BrushStyle m_styleCurr; //current fill style
|
||||
Qt::BrushStyle m_styleNormal; //Normal fill style
|
||||
QColor m_colDefFill; //"no color" default normal fill color
|
||||
QColor m_colNormalFill; //current Normal fill color
|
||||
Qt::BrushStyle m_styleDef; //default Normal fill style
|
||||
Qt::BrushStyle m_styleNormal; //current Normal fill style
|
||||
Qt::BrushStyle m_styleSelect; //Select/preSelect fill style
|
||||
QBrush m_brushNormal;
|
||||
QBrush m_brushPre;
|
||||
QBrush m_brushSel;
|
||||
QBrush m_brushDef;
|
||||
QBrush m_brushCurrent;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
133
src/Mod/TechDraw/Gui/QGIPrimPath.cpp
Normal file
133
src/Mod/TechDraw/Gui/QGIPrimPath.cpp
Normal file
|
@ -0,0 +1,133 @@
|
|||
/***************************************************************************
|
||||
* 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 <QGraphicsSceneHoverEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QPainterPathStroker>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
|
||||
#include "QGIPrimPath.h"
|
||||
#include "QGIView.h"
|
||||
|
||||
using namespace TechDrawGui;
|
||||
|
||||
QGIPrimPath::QGIPrimPath()
|
||||
{
|
||||
setCacheMode(QGraphicsItem::NoCache);
|
||||
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
setFlag(QGraphicsItem::ItemIsMovable, false);
|
||||
setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true);
|
||||
setFlag(QGraphicsItem::ItemSendsGeometryChanges,true);
|
||||
setAcceptHoverEvents(true);
|
||||
|
||||
isHighlighted = false;
|
||||
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
|
||||
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors");
|
||||
App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("NormalColor", 0x00000000));
|
||||
m_colNormal = fcColor.asValue<QColor>();
|
||||
fcColor.setPackedValue(hGrp->GetUnsigned("SelectColor", 0x0000FF00));
|
||||
m_colSel = fcColor.asValue<QColor>();
|
||||
fcColor.setPackedValue(hGrp->GetUnsigned("PreSelectColor", 0x00080800));
|
||||
m_colPre = fcColor.asValue<QColor>();
|
||||
|
||||
setPrettyNormal();
|
||||
|
||||
m_pen.setColor(m_colNormal);
|
||||
m_pen.setStyle(Qt::SolidLine);
|
||||
m_pen.setCapStyle(Qt::RoundCap);
|
||||
}
|
||||
|
||||
QVariant QGIPrimPath::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
if (change == ItemSelectedHasChanged && scene()) {
|
||||
if(isSelected()) {
|
||||
setPrettySel();
|
||||
} else {
|
||||
setPrettyNormal();
|
||||
}
|
||||
}
|
||||
return QGraphicsPathItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
void QGIPrimPath::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
if (!isSelected()) {
|
||||
setPrettyPre();
|
||||
}
|
||||
QGraphicsPathItem::hoverEnterEvent(event);
|
||||
}
|
||||
|
||||
void QGIPrimPath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
QGIView *view = dynamic_cast<QGIView *> (parentItem()); //this is temp for debug??
|
||||
assert(view != 0);
|
||||
if(!isSelected() && !isHighlighted) {
|
||||
setPrettyNormal();
|
||||
}
|
||||
QGraphicsPathItem::hoverLeaveEvent(event);
|
||||
}
|
||||
|
||||
void QGIPrimPath::setHighlighted(bool b)
|
||||
{
|
||||
isHighlighted = b;
|
||||
if(isHighlighted) {
|
||||
setPrettySel();
|
||||
} else {
|
||||
setPrettyNormal();
|
||||
}
|
||||
}
|
||||
|
||||
void QGIPrimPath::setPrettyNormal() {
|
||||
m_colCurrent = m_colNormal;
|
||||
update();
|
||||
}
|
||||
|
||||
void QGIPrimPath::setPrettyPre() {
|
||||
m_colCurrent = m_colPre;
|
||||
update();
|
||||
}
|
||||
|
||||
void QGIPrimPath::setPrettySel() {
|
||||
m_colCurrent = m_colSel;
|
||||
update();
|
||||
}
|
||||
|
||||
void QGIPrimPath::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
|
||||
QStyleOptionGraphicsItem myOption(*option);
|
||||
myOption.state &= ~QStyle::State_Selected;
|
||||
|
||||
m_pen.setColor(m_colCurrent);
|
||||
setPen(m_pen);
|
||||
QGraphicsPathItem::paint (painter, &myOption, widget);
|
||||
}
|
74
src/Mod/TechDraw/Gui/QGIPrimPath.h
Normal file
74
src/Mod/TechDraw/Gui/QGIPrimPath.h
Normal file
|
@ -0,0 +1,74 @@
|
|||
/***************************************************************************
|
||||
* 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_QGIPRIMPATH_H
|
||||
#define DRAWINGGUI_QGIPRIMPATH_H
|
||||
|
||||
# include <QGraphicsItem>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QPainter;
|
||||
class QStyleOptionGraphicsItem;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace TechDrawGeometry {
|
||||
class BaseGeom;
|
||||
}
|
||||
|
||||
namespace TechDrawGui
|
||||
{
|
||||
|
||||
class TechDrawGuiExport QGIPrimPath : public QGraphicsPathItem
|
||||
{
|
||||
public:
|
||||
explicit QGIPrimPath();
|
||||
~QGIPrimPath() {}
|
||||
|
||||
enum {Type = QGraphicsItem::UserType + 170};
|
||||
|
||||
int type() const { return Type;}
|
||||
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
|
||||
|
||||
void setHighlighted(bool state);
|
||||
virtual void setPrettyNormal();
|
||||
virtual void setPrettyPre();
|
||||
virtual void setPrettySel();
|
||||
|
||||
protected:
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
|
||||
bool isHighlighted;
|
||||
QPen m_pen;
|
||||
QColor m_colCurrent;
|
||||
QColor m_colNormal;
|
||||
QColor m_colPre;
|
||||
QColor m_colSel;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
} // namespace MDIViewPageGui
|
||||
|
||||
#endif // DRAWINGGUI_QGIPRIMPATH_H
|
|
@ -30,91 +30,31 @@
|
|||
#include <QStyleOptionGraphicsItem>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Material.h>
|
||||
//#include <App/Application.h>
|
||||
//#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
//#include <Base/Parameter.h>
|
||||
|
||||
#include "QGIView.h"
|
||||
#include "QGIVertex.h"
|
||||
|
||||
using namespace TechDrawGui;
|
||||
|
||||
QGIVertex::QGIVertex(int index) :
|
||||
QGIVertex::QGIVertex(int index) :
|
||||
projIndex(index),
|
||||
m_radius(2),
|
||||
m_fill(Qt::SolidPattern)
|
||||
{
|
||||
setCacheMode(QGraphicsItem::NoCache);
|
||||
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true);
|
||||
setFlag(QGraphicsItem::ItemSendsGeometryChanges,true);
|
||||
setAcceptHoverEvents(true);
|
||||
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
|
||||
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors");
|
||||
App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("NormalColor", 0x00000000));
|
||||
m_colNormal = fcColor.asValue<QColor>();
|
||||
fcColor.setPackedValue(hGrp->GetUnsigned("SelectColor", 0x0000FF00));
|
||||
m_colSel = fcColor.asValue<QColor>();
|
||||
fcColor.setPackedValue(hGrp->GetUnsigned("PreSelectColor", 0x00080800));
|
||||
m_colPre = fcColor.asValue<QColor>();
|
||||
|
||||
m_brush.setStyle(m_fill);
|
||||
setPrettyNormal();
|
||||
|
||||
setRadius(m_radius);
|
||||
}
|
||||
|
||||
QVariant QGIVertex::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
void QGIVertex::setRadius(float r)
|
||||
{
|
||||
if (change == ItemSelectedHasChanged && scene()) {
|
||||
if(isSelected()) {
|
||||
setPrettySel();
|
||||
} else {
|
||||
setPrettyNormal();
|
||||
}
|
||||
}
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
void QGIVertex::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
setPrettyPre();
|
||||
}
|
||||
|
||||
void QGIVertex::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
QGIView *view = dynamic_cast<QGIView *> (parentItem());
|
||||
assert(view != 0);
|
||||
|
||||
if(!isSelected() && !isHighlighted) {
|
||||
setPrettyNormal();
|
||||
}
|
||||
}
|
||||
|
||||
void QGIVertex::setHighlighted(bool b)
|
||||
{
|
||||
isHighlighted = b;
|
||||
if(isHighlighted) {
|
||||
setPrettySel();
|
||||
} else {
|
||||
setPrettyNormal();
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void QGIVertex::setPrettyNormal() {
|
||||
m_colCurrent = m_colNormal;
|
||||
update();
|
||||
}
|
||||
|
||||
void QGIVertex::setPrettyPre() {
|
||||
m_colCurrent = m_colPre;
|
||||
update();
|
||||
}
|
||||
|
||||
void QGIVertex::setPrettySel() {
|
||||
m_colCurrent = m_colSel;
|
||||
update();
|
||||
m_radius = r;
|
||||
QPainterPath p;
|
||||
p.addEllipse(-r/2.0, -r/2.0, r, r);
|
||||
setPath(p);
|
||||
}
|
||||
|
||||
void QGIVertex::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
|
@ -122,13 +62,9 @@ void QGIVertex::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|||
QStyleOptionGraphicsItem myOption(*option);
|
||||
myOption.state &= ~QStyle::State_Selected;
|
||||
|
||||
m_pen.setColor(m_colCurrent);
|
||||
setPen(m_pen);
|
||||
m_brush.setColor(m_colCurrent);
|
||||
m_brush.setStyle(m_fill);
|
||||
setBrush(m_brush);
|
||||
setRect(-m_radius,-m_radius,2.*m_radius,2.*m_radius);
|
||||
QGraphicsEllipseItem::paint (painter, &myOption, widget);
|
||||
//setRect(-m_radius,-m_radius,2.*m_radius,2.*m_radius);
|
||||
QGIPrimPath::paint (painter, &myOption, widget);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,12 +23,7 @@
|
|||
#ifndef DRAWINGGUI_QGRAPHICSITEMVERTEX_H
|
||||
#define DRAWINGGUI_QGRAPHICSITEMVERTEX_H
|
||||
|
||||
# include <QGraphicsItem>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QPainter;
|
||||
class QStyleOptionGraphicsItem;
|
||||
QT_END_NAMESPACE
|
||||
# include "QGIPrimPath.h"
|
||||
|
||||
namespace TechDrawGeometry {
|
||||
class BaseGeom;
|
||||
|
@ -37,7 +32,7 @@ class BaseGeom;
|
|||
namespace TechDrawGui
|
||||
{
|
||||
|
||||
class TechDrawGuiExport QGIVertex : public QGraphicsEllipseItem
|
||||
class TechDrawGuiExport QGIVertex : public QGIPrimPath
|
||||
{
|
||||
public:
|
||||
explicit QGIVertex(int index);
|
||||
|
@ -50,35 +45,19 @@ public:
|
|||
int getProjIndex() const { return projIndex; }
|
||||
|
||||
float getRadius() { return m_radius; }
|
||||
void setRadius(float r) { m_radius = r; }
|
||||
void setRadius(float r);
|
||||
Qt::BrushStyle getFill() { return m_fill; }
|
||||
void setFill(Qt::BrushStyle f) { m_fill = f; }
|
||||
|
||||
void setHighlighted(bool isHighlighted);
|
||||
void setPrettyNormal();
|
||||
void setPrettyPre();
|
||||
void setPrettySel();
|
||||
|
||||
protected:
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
|
||||
int projIndex; //index of vertex in Projection. must exist.
|
||||
|
||||
bool isHighlighted;
|
||||
int projIndex;
|
||||
|
||||
private:
|
||||
QPen m_pen;
|
||||
QBrush m_brush;
|
||||
QColor m_colCurrent;
|
||||
QColor m_colNormal;
|
||||
QColor m_colPre;
|
||||
QColor m_colSel;
|
||||
float m_radius;
|
||||
QBrush m_brush;
|
||||
Qt::BrushStyle m_fill;
|
||||
};
|
||||
|
||||
} // namespace MDIViewPageGui
|
||||
}
|
||||
|
||||
#endif // DRAWINGGUI_QGRAPHICSITEMVERTEX_H
|
||||
|
|
|
@ -325,8 +325,6 @@ void QGIViewPart::drawViewPart()
|
|||
}
|
||||
}
|
||||
newFace->setZValue(ZVALUE::FACE);
|
||||
newFace->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
newFace->setAcceptHoverEvents(true);
|
||||
newFace->setPrettyNormal();
|
||||
}
|
||||
#endif //#if MOD_TECHDRAW_HANDLE_FACES
|
||||
|
@ -357,8 +355,6 @@ void QGIViewPart::drawViewPart()
|
|||
item->setPath(drawPainterPath(*itEdge));
|
||||
item->setStrokeWidth(lineWidth);
|
||||
item->setZValue(ZVALUE::EDGE);
|
||||
item->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
item->setAcceptHoverEvents(true);
|
||||
if(!(*itEdge)->visible) {
|
||||
item->setStrokeWidth(lineWidthHid);
|
||||
item->setHiddenEdge(true);
|
||||
|
|
|
@ -74,7 +74,8 @@ void QGIViewSection::drawSectionFace()
|
|||
return;
|
||||
}
|
||||
std::vector<TechDrawGeometry::Face *>::iterator fit = sectionFaces.begin();
|
||||
QColor faceColor(0,0,255,40); //temp. sb preference or property.
|
||||
//QColor faceColor(0,0,255,40); //temp. sb preference or property. transparency allows bleed through/colour mix.
|
||||
QColor faceColor(170,170,255); //temp. sb preference or property.
|
||||
for(; fit != sectionFaces.end(); fit++) {
|
||||
QGIFace* newFace = drawFace(*fit,-1); //TODO: do we need to know which sectionFace this QGIFace came from?
|
||||
newFace->setZValue(ZVALUE::SECTIONFACE);
|
||||
|
@ -82,7 +83,6 @@ void QGIViewSection::drawSectionFace()
|
|||
newFace->setPrettyNormal();
|
||||
newFace->setAcceptHoverEvents(false);
|
||||
newFace->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
||||
newFace->setAcceptHoverEvents(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user