Fix bug with pen width.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-02-06 20:08:50 +02:00
parent 6c438f92e0
commit 6e50832578
4 changed files with 15 additions and 11 deletions

View File

@ -62,13 +62,14 @@ template <class T> class QSharedPointer;
*/ */
VToolLine::VToolLine(const VToolLineInitData &initData, QGraphicsItem *parent) VToolLine::VToolLine(const VToolLineInitData &initData, QGraphicsItem *parent)
:VDrawTool(initData.doc, initData.data, initData.id), :VDrawTool(initData.doc, initData.data, initData.id),
QGraphicsLineItem(parent), VScaledLine(parent),
firstPoint(initData.firstPoint), firstPoint(initData.firstPoint),
secondPoint(initData.secondPoint), secondPoint(initData.secondPoint),
lineColor(initData.lineColor), lineColor(initData.lineColor),
m_isHovered(false), m_isHovered(false),
m_acceptHoverEvents(true) m_acceptHoverEvents(true)
{ {
m_isBoldLine = false;
this->m_lineType = initData.typeLine; this->m_lineType = initData.typeLine;
//Line //Line
RefreshGeometry(); RefreshGeometry();
@ -187,7 +188,7 @@ void VToolLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
setPen(QPen(CorrectColor(this, lineColor), width, LineStyleToPenStyle(m_lineType))); setPen(QPen(CorrectColor(this, lineColor), width, LineStyleToPenStyle(m_lineType)));
PaintWithFixItemHighlightSelected<QGraphicsLineItem>(this, painter, option, widget); PaintWithFixItemHighlightSelected<VScaledLine>(this, painter, option, widget);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -291,8 +292,9 @@ void VToolLine::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
if (m_acceptHoverEvents) if (m_acceptHoverEvents)
{ {
m_isHovered = true; m_isHovered = true;
m_isBoldLine = true;
setToolTip(MakeToolTip()); setToolTip(MakeToolTip());
QGraphicsLineItem::hoverEnterEvent(event); VScaledLine::hoverEnterEvent(event);
} }
else else
{ {
@ -310,7 +312,8 @@ void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
if (m_acceptHoverEvents && vis.isNull()) if (m_acceptHoverEvents && vis.isNull())
{ {
m_isHovered = false; m_isHovered = false;
QGraphicsLineItem::hoverLeaveEvent(event); m_isBoldLine = false;
VScaledLine::hoverLeaveEvent(event);
} }
} }

View File

@ -31,8 +31,6 @@
#include <qcompilerdetection.h> #include <qcompilerdetection.h>
#include <QDomElement> #include <QDomElement>
#include <QGraphicsItem>
#include <QGraphicsLineItem>
#include <QMetaObject> #include <QMetaObject>
#include <QObject> #include <QObject>
#include <QString> #include <QString>
@ -42,6 +40,7 @@
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "vdrawtool.h" #include "vdrawtool.h"
#include "../vwidgets/scalesceneitems.h"
template <class T> class QSharedPointer; template <class T> class QSharedPointer;
@ -64,7 +63,7 @@ struct VToolLineInitData : VAbstractToolInitData
/** /**
* @brief The VToolLine class tool for creation line. * @brief The VToolLine class tool for creation line.
*/ */
class VToolLine: public VDrawTool, public QGraphicsLineItem class VToolLine: public VDrawTool, public VScaledLine
{ {
Q_OBJECT Q_OBJECT
public: public:

View File

@ -48,8 +48,9 @@ VScaledLine::VScaledLine(const QLineF &line, QGraphicsItem *parent)
void VScaledLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void VScaledLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
QPen lPen = pen(); QPen lPen = pen();
lPen.setWidthF(ScaleWidth(m_isBoldLine ? qApp->Settings()->WidthMainLine() : qApp->Settings()->WidthHairLine(), const qreal width = ScaleWidth(m_isBoldLine ? qApp->Settings()->WidthMainLine() : qApp->Settings()->WidthHairLine(),
SceneScale(scene()))); SceneScale(scene()));
lPen.setWidthF(qRound(width*100.)/100.);
setPen(lPen); setPen(lPen);
PaintWithFixItemHighlightSelected<QGraphicsLineItem>(this, painter, option, widget); PaintWithFixItemHighlightSelected<QGraphicsLineItem>(this, painter, option, widget);

View File

@ -49,10 +49,11 @@ public:
bool IsBoldLine() const; bool IsBoldLine() const;
void SetBoldLine(bool bold); void SetBoldLine(bool bold);
protected:
bool m_isBoldLine;
private: private:
Q_DISABLE_COPY(VScaledLine) Q_DISABLE_COPY(VScaledLine)
bool m_isBoldLine;
}; };
class VScaledEllipse : public QGraphicsEllipseItem class VScaledEllipse : public QGraphicsEllipseItem