1 /************************************************************************
2 **
3 ** @file
4 ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5 ** @date 21 6, 2017
6 **
7 ** @brief
8 ** @copyright
9 ** This source code is part of the Valentina project, a pattern making
10 ** program, whose allow create and modeling patterns of clothing.
11 ** Copyright (C) 2017 Valentina project
12 ** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
13 **
14 ** Valentina is free software: you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License as published by
16 ** the Free Software Foundation, either version 3 of the License, or
17 ** (at your option) any later version.
18 **
19 ** Valentina is distributed in the hope that it will be useful,
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ** GNU General Public License for more details.
23 **
24 ** You should have received a copy of the GNU General Public License
25 ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
26 **
27 *************************************************************************/
28
29 #include "scalesceneitems.h"
30 #include "global.h"
31 #include "../vmisc/vabstractapplication.h"
32
33 #include <QPen>
34
35 //---------------------------------------------------------------------------------------------------------------------
VScaledLine(QGraphicsItem * parent)36 VScaledLine::VScaledLine(QGraphicsItem *parent)
37 : QGraphicsLineItem(parent),
38 m_isBoldLine(true)
39 {}
40
41 //---------------------------------------------------------------------------------------------------------------------
VScaledLine(const QLineF & line,QGraphicsItem * parent)42 VScaledLine::VScaledLine(const QLineF &line, QGraphicsItem *parent)
43 : QGraphicsLineItem(line, parent),
44 m_isBoldLine(true)
45 {}
46
47 //---------------------------------------------------------------------------------------------------------------------
paint(QPainter * painter,const QStyleOptionGraphicsItem * option,QWidget * widget)48 void VScaledLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
49 {
50 QPen lPen = pen();
51 const qreal width = ScaleWidth(m_isBoldLine ? VAbstractApplication::VApp()->Settings()->WidthMainLine()
52 : VAbstractApplication::VApp()->Settings()->WidthHairLine(),
53 SceneScale(scene()));
54 lPen.setWidthF(qRound(width*100.)/100.);
55 setPen(lPen);
56
57 PaintWithFixItemHighlightSelected<QGraphicsLineItem>(this, painter, option, widget);
58 }
59
60 //---------------------------------------------------------------------------------------------------------------------
IsBoldLine() const61 bool VScaledLine::IsBoldLine() const
62 {
63 return m_isBoldLine;
64 }
65
66 //---------------------------------------------------------------------------------------------------------------------
SetBoldLine(bool bold)67 void VScaledLine::SetBoldLine(bool bold)
68 {
69 m_isBoldLine = bold;
70 }
71
72 //---------------------------------------------------------------------------------------------------------------------
VScaledEllipse(QGraphicsItem * parent)73 VScaledEllipse::VScaledEllipse(QGraphicsItem *parent)
74 : QGraphicsEllipseItem(parent)
75 {}
76
77 //---------------------------------------------------------------------------------------------------------------------
paint(QPainter * painter,const QStyleOptionGraphicsItem * option,QWidget * widget)78 void VScaledEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
79 {
80 const qreal scale = SceneScale(scene());
81 const qreal width = ScaleWidth(VAbstractApplication::VApp()->Settings()->WidthMainLine(), scale);
82
83 QPen visPen = pen();
84 visPen.setWidthF(width);
85
86 setPen(visPen);
87 ScaleCircleSize(this, scale);
88
89 PaintWithFixItemHighlightSelected<QGraphicsEllipseItem>(this, painter, option, widget);
90 }
91