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 "KChartAbstractThreeDAttributes.h"
21 #include "KChartAbstractThreeDAttributes_p.h"
22 
23 #include "KChartMath_p.h"
24 
25 #include <QDebug>
26 #include <QBrush>
27 
28 #define d d_func()
29 
30 
31 using namespace KChart;
32 
33 
Private()34 AbstractThreeDAttributes::Private::Private()
35     : enabled( false ),
36       depth( 20 ),
37       threeDBrushEnabled( false )
38 {
39 }
40 
41 
AbstractThreeDAttributes()42 AbstractThreeDAttributes::AbstractThreeDAttributes()
43     : _d( new Private() )
44 {
45 }
46 
AbstractThreeDAttributes(const AbstractThreeDAttributes & r)47 AbstractThreeDAttributes::AbstractThreeDAttributes( const AbstractThreeDAttributes& r )
48     : _d( new Private( *r.d ) )
49 {
50 }
51 
operator =(const AbstractThreeDAttributes & r)52 AbstractThreeDAttributes& AbstractThreeDAttributes::operator= ( const AbstractThreeDAttributes& r )
53 {
54     if ( this == &r )
55         return *this;
56 
57     *d = *r.d;
58 
59     return *this;
60 }
61 
~AbstractThreeDAttributes()62 AbstractThreeDAttributes::~AbstractThreeDAttributes()
63 {
64     delete _d; _d = nullptr;
65 }
66 
67 
operator ==(const AbstractThreeDAttributes & r) const68 bool AbstractThreeDAttributes::operator==( const AbstractThreeDAttributes& r ) const
69 {
70     return isEnabled() == r.isEnabled() &&
71         depth() == r.depth() &&
72         isThreeDBrushEnabled() == r.isThreeDBrushEnabled();
73 }
74 
75 
init()76 void AbstractThreeDAttributes::init( )
77 {
78 
79 }
80 
setEnabled(bool enabled)81 void AbstractThreeDAttributes::setEnabled( bool enabled )
82 {
83     d->enabled = enabled;
84 }
85 
isEnabled() const86 bool AbstractThreeDAttributes::isEnabled() const
87 {
88     return d->enabled;
89 }
90 
setDepth(qreal depth)91 void AbstractThreeDAttributes::setDepth( qreal depth )
92 {
93     d->depth = depth;
94 }
95 
96 
depth() const97 qreal AbstractThreeDAttributes::depth() const
98 {
99     return d->depth;
100 }
101 
102 
validDepth() const103 qreal AbstractThreeDAttributes::validDepth() const
104 {
105     return isEnabled() ? d->depth : 0.0;
106 }
107 
isThreeDBrushEnabled() const108 bool AbstractThreeDAttributes::isThreeDBrushEnabled() const
109 {
110     return d->threeDBrushEnabled;
111 }
112 
setThreeDBrushEnabled(bool enabled)113 void AbstractThreeDAttributes::setThreeDBrushEnabled( bool enabled )
114 {
115     d->threeDBrushEnabled = enabled;
116 }
117 
threeDBrush(const QBrush & brush,const QRectF & rect) const118 QBrush AbstractThreeDAttributes::threeDBrush( const QBrush& brush, const QRectF& rect ) const
119 {
120     if ( isThreeDBrushEnabled() ) {
121         QLinearGradient gr(rect.topLeft(), rect.bottomRight());
122         gr.setColorAt(0.0, brush.color());
123         gr.setColorAt(0.5, brush.color().lighter(180));
124         gr.setColorAt(1.0, brush.color());
125         return QBrush(gr);
126     }
127     return brush;
128 }
129 
130 #if !defined(QT_NO_DEBUG_STREAM)
operator <<(QDebug dbg,const KChart::AbstractThreeDAttributes & a)131 QDebug operator<<(QDebug dbg, const KChart::AbstractThreeDAttributes& a)
132 {
133     dbg << "enabled="<<a.isEnabled()
134         << "depth="<<a.depth();
135     return dbg;
136 }
137 #endif /* QT_NO_DEBUG_STREAM */
138