File indexing completed on 2024-05-12 04:20:30

0001 /*
0002  * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
0003  *
0004  * This file is part of the KD Chart library.
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #include "KChartAbstractThreeDAttributes.h"
0010 #include "KChartAbstractThreeDAttributes_p.h"
0011 
0012 #include "KChartMath_p.h"
0013 
0014 #include <QDebug>
0015 #include <QBrush>
0016 
0017 #define d d_func()
0018 
0019 
0020 using namespace KChart;
0021 
0022 
0023 AbstractThreeDAttributes::Private::Private()
0024     : enabled( false ),
0025       depth( 20 ),
0026       threeDBrushEnabled( false )
0027 {
0028 }
0029 
0030 AbstractThreeDAttributes::Private::~Private() = default;
0031 
0032 
0033 AbstractThreeDAttributes::AbstractThreeDAttributes()
0034     : _d( new Private() )
0035 {
0036 }
0037 
0038 AbstractThreeDAttributes::AbstractThreeDAttributes( const AbstractThreeDAttributes& r )
0039     : _d( new Private( *r.d ) )
0040 {
0041 }
0042 
0043 AbstractThreeDAttributes& AbstractThreeDAttributes::operator= ( const AbstractThreeDAttributes& r )
0044 {
0045     if ( this == &r )
0046         return *this;
0047 
0048     *d = *r.d;
0049 
0050     return *this;
0051 }
0052 
0053 AbstractThreeDAttributes::~AbstractThreeDAttributes()
0054 {
0055     delete _d; _d = nullptr;
0056 }
0057 
0058 
0059 bool AbstractThreeDAttributes::operator==( const AbstractThreeDAttributes& r ) const
0060 {
0061     return isEnabled() == r.isEnabled() &&
0062         depth() == r.depth() && 
0063         isThreeDBrushEnabled() == r.isThreeDBrushEnabled();
0064 }
0065 
0066 
0067 void AbstractThreeDAttributes::init( )
0068 {
0069 
0070 }
0071 
0072 void AbstractThreeDAttributes::setEnabled( bool enabled )
0073 {
0074     d->enabled = enabled;
0075 }
0076 
0077 bool AbstractThreeDAttributes::isEnabled() const
0078 {
0079     return d->enabled;
0080 }
0081 
0082 void AbstractThreeDAttributes::setDepth( qreal depth )
0083 {
0084     d->depth = depth;
0085 }
0086 
0087 
0088 qreal AbstractThreeDAttributes::depth() const
0089 {
0090     return d->depth;
0091 }
0092 
0093 
0094 qreal AbstractThreeDAttributes::validDepth() const
0095 {
0096     return isEnabled() ? d->depth : 0.0;
0097 }
0098 
0099 bool AbstractThreeDAttributes::isThreeDBrushEnabled() const
0100 {
0101     return d->threeDBrushEnabled;
0102 }
0103 
0104 void AbstractThreeDAttributes::setThreeDBrushEnabled( bool enabled )
0105 {
0106     d->threeDBrushEnabled = enabled;
0107 }
0108 
0109 QBrush AbstractThreeDAttributes::threeDBrush( const QBrush& brush, const QRectF& rect ) const
0110 {
0111     if ( isThreeDBrushEnabled() ) {
0112         QLinearGradient gr(rect.topLeft(), rect.bottomRight());
0113         gr.setColorAt(0.0, brush.color());
0114         gr.setColorAt(0.5, brush.color().lighter(180));
0115         gr.setColorAt(1.0, brush.color());
0116         return QBrush(gr);
0117     }
0118     return brush;
0119 }
0120 
0121 #if !defined(QT_NO_DEBUG_STREAM)
0122 QDebug operator<<(QDebug dbg, const KChart::AbstractThreeDAttributes& a)
0123 {
0124     dbg << "enabled="<<a.isEnabled()
0125         << "depth="<<a.depth();
0126     return dbg;
0127 }
0128 #endif /* QT_NO_DEBUG_STREAM */