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)
:VDrawTool(initData.doc, initData.data, initData.id),
QGraphicsLineItem(parent),
VScaledLine(parent),
firstPoint(initData.firstPoint),
secondPoint(initData.secondPoint),
lineColor(initData.lineColor),
m_isHovered(false),
m_acceptHoverEvents(true)
{
m_isBoldLine = false;
this->m_lineType = initData.typeLine;
//Line
RefreshGeometry();
@ -187,7 +188,7 @@ void VToolLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
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)
{
m_isHovered = true;
m_isBoldLine = true;
setToolTip(MakeToolTip());
QGraphicsLineItem::hoverEnterEvent(event);
VScaledLine::hoverEnterEvent(event);
}
else
{
@ -310,7 +312,8 @@ void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
if (m_acceptHoverEvents && vis.isNull())
{
m_isHovered = false;
QGraphicsLineItem::hoverLeaveEvent(event);
m_isBoldLine = false;
VScaledLine::hoverLeaveEvent(event);
}
}

View File

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

View File

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

View File

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