1 /*
2  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB.  All rights reserved.
3  *
4  * This file is part of the KD Chart library.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #include "KChartValueTrackerAttributes.h"
21 #include "KChartMath_p.h"
22 
23 #include <QPen>
24 #include <QSizeF>
25 #include <QBrush>
26 
27 #define d d_func()
28 
29 using namespace KChart;
30 
31 class Q_DECL_HIDDEN ValueTrackerAttributes::Private
32 {
33     friend class ValueTrackerAttributes;
34     public:
35         Private();
36     private:
37         QPen linePen;
38         QPen markerPen;
39         QBrush markerBrush;
40         QBrush arrowBrush;
41         QSizeF markerSize;
42         bool enabled;
43         QBrush areaBrush;
44         Qt::Orientations orientations;
45 };
46 
Private()47 ValueTrackerAttributes::Private::Private()
48     : linePen( QPen( QColor( 80, 80, 80, 200 ) ) ),
49       markerSize( QSizeF( 6.0, 6.0 ) ),
50       enabled( false ),
51       areaBrush( QBrush() ),
52       orientations(Qt::Vertical|Qt::Horizontal)
53 {
54     markerPen = linePen;
55     arrowBrush = linePen.color();
56 }
57 
58 
ValueTrackerAttributes()59 ValueTrackerAttributes::ValueTrackerAttributes()
60     : _d( new Private() )
61 {
62 }
63 
ValueTrackerAttributes(const ValueTrackerAttributes & r)64 ValueTrackerAttributes::ValueTrackerAttributes( const ValueTrackerAttributes& r )
65     : _d( new Private( *r.d ) )
66 {
67 }
68 
operator =(const ValueTrackerAttributes & r)69 ValueTrackerAttributes & ValueTrackerAttributes::operator=( const ValueTrackerAttributes& r )
70 {
71     if ( this == &r )
72         return *this;
73 
74     *d = *r.d;
75 
76     return *this;
77 }
78 
~ValueTrackerAttributes()79 ValueTrackerAttributes::~ValueTrackerAttributes()
80 {
81     delete _d; _d = nullptr;
82 }
83 
84 
operator ==(const ValueTrackerAttributes & r) const85 bool ValueTrackerAttributes::operator==( const ValueTrackerAttributes& r ) const
86 {
87     return ( linePen() == r.linePen() &&
88              markerPen() == r.markerPen() &&
89              markerBrush() == r.markerBrush() &&
90              arrowBrush() == r.arrowBrush() &&
91              areaBrush() == r.areaBrush() &&
92              markerSize() == r.markerSize() &&
93              isEnabled() == r.isEnabled() );
94 }
95 
setPen(const QPen & pen)96 void ValueTrackerAttributes::setPen( const QPen& pen )
97 {
98     d->linePen = pen;
99     d->markerPen = pen;
100     d->markerBrush = QBrush();
101     d->arrowBrush = pen.color();
102 }
103 
pen() const104 QPen ValueTrackerAttributes::pen() const
105 {
106     return d->linePen;
107 }
108 
setLinePen(const QPen & pen)109 void ValueTrackerAttributes::setLinePen( const QPen &pen )
110 {
111     d->linePen = pen;
112 }
113 
linePen() const114 QPen ValueTrackerAttributes::linePen() const
115 {
116     return d->linePen;
117 }
118 
setMarkerPen(const QPen & pen)119 void ValueTrackerAttributes::setMarkerPen( const QPen &pen )
120 {
121     d->markerPen = pen;
122 }
123 
markerPen() const124 QPen ValueTrackerAttributes::markerPen() const
125 {
126     return d->markerPen;
127 }
128 
setMarkerBrush(const QBrush & brush)129 void ValueTrackerAttributes::setMarkerBrush( const QBrush &brush )
130 {
131     d->markerBrush = brush;
132 }
133 
markerBrush() const134 QBrush ValueTrackerAttributes::markerBrush() const
135 {
136     return d->markerBrush;
137 }
138 
setArrowBrush(const QBrush & brush)139 void ValueTrackerAttributes::setArrowBrush( const QBrush &brush )
140 {
141     d->arrowBrush = brush;
142 }
143 
arrowBrush() const144 QBrush ValueTrackerAttributes::arrowBrush() const
145 {
146     return d->arrowBrush;
147 }
148 
setAreaBrush(const QBrush & brush)149 void ValueTrackerAttributes::setAreaBrush( const QBrush& brush )
150 {
151     d->areaBrush = brush;
152 }
153 
areaBrush() const154 QBrush ValueTrackerAttributes::areaBrush() const
155 {
156     return d->areaBrush;
157 }
158 
setMarkerSize(const QSizeF & size)159 void ValueTrackerAttributes::setMarkerSize( const QSizeF& size )
160 {
161     d->markerSize = size;
162 }
163 
markerSize() const164 QSizeF ValueTrackerAttributes::markerSize() const
165 {
166     return d->markerSize;
167 }
168 
orientations() const169 Qt::Orientations ValueTrackerAttributes::orientations() const
170 {
171     return d->orientations;
172 }
173 
setOrientations(Qt::Orientations orientations)174 void ValueTrackerAttributes::setOrientations( Qt::Orientations orientations )
175 {
176     d->orientations = orientations;
177 }
178 
setEnabled(bool enabled)179 void ValueTrackerAttributes::setEnabled( bool enabled )
180 {
181     d->enabled = enabled;
182 }
183 
isEnabled() const184 bool ValueTrackerAttributes::isEnabled() const
185 {
186     return d->enabled;
187 }
188 
189 #if !defined(QT_NO_DEBUG_STREAM)
operator <<(QDebug dbg,const KChart::ValueTrackerAttributes & va)190 QDebug operator<<(QDebug dbg, const KChart::ValueTrackerAttributes& va)
191 {
192     dbg << "KChart::ValueTrackerAttributes("
193         << "linePen="<<va.linePen()
194         << "markerPen="<<va.markerPen()
195         << "markerBrush="<<va.markerBrush()
196         << "arrowBrush="<<va.arrowBrush()
197         << "markerSize="<<va.markerSize()
198         << "enabled="<<va.isEnabled()
199         << ")";
200     return dbg;
201 }
202 #endif /* QT_NO_DEBUG_STREAM */
203