1 | /**************************************************************************** |
2 | ** Copyright (C) 2001-2010 Klaralvdalens Datakonsult AB. All rights reserved. |
3 | ** |
4 | ** This file is part of the KD Chart library. |
5 | ** |
6 | ** Licensees holding valid commercial KD Chart licenses may use this file in |
7 | ** accordance with the KD Chart Commercial License Agreement provided with |
8 | ** the Software. |
9 | ** |
10 | ** |
11 | ** This file may be distributed and/or modified under the terms of the |
12 | ** GNU General Public License version 2 and version 3 as published by the |
13 | ** Free Software Foundation and appearing in the file LICENSE.GPL included. |
14 | ** |
15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
17 | ** |
18 | ** Contact info@kdab.com if any conditions of this licensing are not |
19 | ** clear to you. |
20 | ** |
21 | **********************************************************************/ |
22 | |
23 | #ifndef __KDCHART_PALETTE_H__ |
24 | #define __KDCHART_PALETTE_H__ |
25 | |
26 | #include <QObject> |
27 | #include <QBrush> |
28 | #include "KDChartGlobal.h" |
29 | |
30 | namespace KDChart { |
31 | |
32 | /** |
33 | * \brief A Palette is a set of brushes (or colors) to be used |
34 | * for painting data sets. |
35 | * |
36 | * The palette class encapsulates a colletion of brushes, which in |
37 | * the simplest case are colors, to be used for painting a series of |
38 | * data sets. When asked for the m-th color, a palette of size n will |
39 | * wrap around and thus cycle through the available colors. |
40 | * |
41 | * Three builtin palettes are provided for convenience, one with a default |
42 | * set of colors, one with a subdued color selection, one with rainbow |
43 | * colors. |
44 | * |
45 | * When a palette changes, it emits a changed() signal. Hook up to it, if |
46 | * you want to repaint when the color selection changes. |
47 | */ |
48 | |
49 | class KDCHART_EXPORT Palette: public QObject |
50 | { |
51 | Q_OBJECT |
52 | public: |
53 | explicit Palette( QObject *parent = 0 ); |
54 | Palette( const Palette& ); |
55 | Palette &operator= ( const Palette & ); |
56 | |
57 | ~Palette(); |
58 | |
59 | /** Provide access to the three builtin palettes, one with standard bright |
60 | * colors, one with more subdued colors, and one with rainbow colors. */ |
61 | static const Palette& defaultPalette(); |
62 | static const Palette& subduedPalette(); |
63 | static const Palette& rainbowPalette(); |
64 | |
65 | /** @return whether this represents a valid palette. For a palette to be |
66 | * valid it needs to have at least one brush associated. */ |
67 | bool isValid() const; |
68 | |
69 | /** @return the number of brushed in the palette. */ |
70 | int size() const; |
71 | |
72 | /** Adds \a brush to the palette. If no \a position is specified, the |
73 | * brush is appended. |
74 | */ |
75 | void addBrush( const QBrush & brush, int position = -1 ); |
76 | |
77 | /** |
78 | * Query the palette for a brush at the specified position. If the |
79 | * position exceeds the size of the palette, it wraps around. |
80 | */ |
81 | QBrush getBrush( int position ) const; |
82 | |
83 | /** Remove the brush at position \a position, if there is one. */ |
84 | void removeBrush( int position ); |
85 | |
86 | Q_SIGNALS: |
87 | /** Emitted whenever the palette changes. Views listen to this and |
88 | * repaing. */ |
89 | void changed(); |
90 | |
91 | private: |
92 | KDCHART_DECLARE_PRIVATE_BASE_VALUE( Palette ) |
93 | }; |
94 | |
95 | } |
96 | KDCHART_DECLARE_SWAP_SPECIALISATION( KDChart::Palette ) |
97 | #endif |
98 | |