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 "KChartBackgroundAttributes.h"
21 
22 #include "KChartMath_p.h"
23 
24 #include <QPixmap>
25 
26 #define d d_func()
27 
28 
29 using namespace KChart;
30 
31 class Q_DECL_HIDDEN BackgroundAttributes::Private
32 {
33     friend class KChart::BackgroundAttributes;
34 public:
35     Private();
36 private:
37     bool visible;
38     QBrush brush;
39     BackgroundPixmapMode pixmapMode;
40     QPixmap pixmap;
41 };
42 
Private()43 BackgroundAttributes::Private::Private() :
44     visible( false ),
45     pixmapMode( BackgroundAttributes::BackgroundPixmapModeNone )
46 {
47 }
48 
49 
BackgroundAttributes()50 BackgroundAttributes::BackgroundAttributes()
51     : _d( new Private() )
52 {
53 }
54 
BackgroundAttributes(const BackgroundAttributes & r)55 BackgroundAttributes::BackgroundAttributes( const BackgroundAttributes& r )
56     : _d( new Private( *r.d ) )
57 {
58 }
59 
operator =(const BackgroundAttributes & r)60 BackgroundAttributes & BackgroundAttributes::operator=( const BackgroundAttributes& r )
61 {
62     if ( this == &r )
63         return *this;
64 
65     *d = *r.d;
66 
67     return *this;
68 }
69 
operator ==(const BackgroundAttributes & r) const70 bool BackgroundAttributes::operator==( const BackgroundAttributes& r ) const
71 {
72     return isEqualTo( r );
73 }
74 
75 
isEqualTo(const BackgroundAttributes & other,bool ignorePixmap) const76 bool BackgroundAttributes::isEqualTo(
77         const BackgroundAttributes& other, bool ignorePixmap ) const
78 {
79     /*
80     qDebug() << "BackgroundAttributes::operator==";
81     qDebug() << "isVisible" << (isVisible() == other.isVisible());
82     qDebug() << "brush"     << (brush() == other.brush());
83     qDebug() << "pixmapMode"<< (pixmapMode() == other.pixmapMode());
84     qDebug() << "pixmap"    << (pixmap().serialNumber() == other.pixmap().serialNumber());
85     */
86     return (
87             isVisible()  == other.isVisible() &&
88             brush()      == other.brush() &&
89             pixmapMode() == other.pixmapMode() &&
90             (ignorePixmap ||
91             pixmap().cacheKey() == other.pixmap().cacheKey()) );
92 }
93 
94 
~BackgroundAttributes()95 BackgroundAttributes::~BackgroundAttributes()
96 {
97     delete _d; _d = nullptr;
98 }
99 
100 
101 
102 
setVisible(bool visible)103 void BackgroundAttributes::setVisible( bool visible )
104 {
105     d->visible = visible;
106 }
107 
108 
isVisible() const109 bool BackgroundAttributes::isVisible() const
110 {
111     return d->visible;
112 }
113 
setBrush(const QBrush & brush)114 void BackgroundAttributes::setBrush( const QBrush &brush )
115 {
116     d->brush = brush;
117 }
118 
brush() const119 QBrush BackgroundAttributes::brush() const
120 {
121     return d->brush;
122 }
123 
setPixmapMode(BackgroundPixmapMode mode)124 void BackgroundAttributes::setPixmapMode( BackgroundPixmapMode mode )
125 {
126     d->pixmapMode = mode;
127 }
128 
pixmapMode() const129 BackgroundAttributes::BackgroundPixmapMode BackgroundAttributes::pixmapMode() const
130 {
131     return d->pixmapMode;
132 }
133 
setPixmap(const QPixmap & backPixmap)134 void BackgroundAttributes::setPixmap( const QPixmap &backPixmap )
135 {
136     d->pixmap = backPixmap;
137 }
138 
pixmap() const139 QPixmap BackgroundAttributes::pixmap() const
140 {
141     return d->pixmap;
142 }
143 
144 #if !defined(QT_NO_DEBUG_STREAM)
operator <<(QDebug dbg,const KChart::BackgroundAttributes & ba)145 QDebug operator<<(QDebug dbg, const KChart::BackgroundAttributes& ba)
146 {
147     dbg << "KChart::BackgroundAttributes("
148 	<< "visible="<<ba.isVisible()
149 	<< "brush="<<ba.brush()
150 	<< "pixmapmode="<<ba.pixmapMode()
151 	<< "pixmap="<<ba.pixmap().cacheKey()
152 	<< ")";
153     return dbg;
154 }
155 #endif /* QT_NO_DEBUG_STREAM */
156