Fix Vertex hover behaviour

Refactor to reduce duplicate code
Fix Section face color mix on hover
This commit is contained in:
WandererFan
2016-07-06 20:59:05 -04:00
committed by wmayer
parent aee2b622b6
commit f89cdb3cc9
11 changed files with 270 additions and 352 deletions

View File

@@ -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);
}