added all files
[ffqwlibrary] / libffqw-1.0 / sources / ffchartlegendcontrolpanel.cpp
1 /*
2           GNU GENERAL PUBLIC LICENSE
3                        Version 3, 29 June 2007
4
5  Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
6  Everyone is permitted to copy and distribute verbatim copies
7  of this license document, but changing it is not allowed.
8
9                             Preamble
10
11   The GNU General Public License is a free, copyleft license for
12 software and other kinds of works.
13
14   The licenses for most software and other practical works are designed
15 to take away your freedom to share and change the works.  By contrast,
16 the GNU General Public License is intended to guarantee your freedom to
17 share and change all versions of a program--to make sure it remains free
18 software for all its users.  We, the Free Software Foundation, use the
19 GNU General Public License for most of our software; it applies also to
20 any other work released this way by its authors.  You can apply it to
21 your programs, too.
22
23   When we speak of free software, we are referring to freedom, not
24 price.  Our General Public Licenses are designed to make sure that you
25 have the freedom to distribute copies of free software (and charge for
26 them if you wish), that you receive source code or can get it if you
27 want it, that you can change the software or use pieces of it in new
28 free programs, and that you know you can do these things.
29
30   To protect your rights, we need to prevent others from denying you
31 these rights or asking you to surrender the rights.  Therefore, you have
32 certain responsibilities if you distribute copies of the software, or if
33 you modify it: responsibilities to respect the freedom of others.
34
35   For example, if you distribute copies of such a program, whether
36 gratis or for a fee, you must pass on to the recipients the same
37 freedoms that you received.  You must make sure that they, too, receive
38 or can get the source code.  And you must show them these terms so they
39 know their rights.
40
41   Developers that use the GNU GPL protect your rights with two steps:
42 (1) assert copyright on the software, and (2) offer you this License
43 giving you legal permission to copy, distribute and/or modify it.
44
45   For the developers' and authors' protection, the GPL clearly explains
46 that there is no warranty for this free software.  For both users' and
47 authors' sake, the GPL requires that modified versions be marked as
48 changed, so that their problems will not be attributed erroneously to
49 authors of previous versions.
50
51   Some devices are designed to deny users access to install or run
52 modified versions of the software inside them, although the manufacturer
53 can do so.  This is fundamentally incompatible with the aim of
54 protecting users' freedom to change the software.  The systematic
55 pattern of such abuse occurs in the area of products for individuals to
56 use, which is precisely where it is most unacceptable.  Therefore, we
57 have designed this version of the GPL to prohibit the practice for those
58 products.  If such problems arise substantially in other domains, we
59 stand ready to extend this provision to those domains in future versions
60 of the GPL, as needed to protect the freedom of users.
61
62   Finally, every program is threatened constantly by software patents.
63 States should not allow patents to restrict development and use of
64 software on general-purpose computers, but in those that do, we wish to
65 avoid the special danger that patents applied to a free program could
66 make it effectively proprietary.  To prevent this, the GPL assures that
67 patents cannot be used to render the program non-free.
68
69   The precise terms and conditions for copying, distribution and
70 modification follow.
71
72 http://www.gnu.org/licenses/gpl-3.0.txt
73 */
74 /**
75  * @file ffchartlegendcontrolpanel.cpp
76  * @brief Contains a necessary class declaration.
77  *
78  * @author ComArch S.A.
79  * @date 2009.08.24
80  * @version 1.0
81  */
82 #include <qdebug.h>
83 #include "ffchartlegendcontrolpanel.h"
84
85 /**
86  * Constructs a FFChartLegendControlPanel with parent.
87  * @param parent QWidget parent
88  */
89 FFChartLegendControlPanel::FFChartLegendControlPanel(QWidget* parent) :
90         FFAbstractWidget(parent)
91 {
92         this->parent = parent;
93         init();
94 }
95
96 /**
97  * A virtual destructor.
98  */
99 FFChartLegendControlPanel::~FFChartLegendControlPanel()
100 {
101         parent = NULL;
102
103 }
104
105 /**
106  * Returns pen_ - pen with line style, line color and line width
107  */
108 QPen FFChartLegendControlPanel::pen()
109 {
110         return pen_;
111 }
112
113 /**
114  * Sets pen_ - pen with line style, line color and line width
115  */
116 void FFChartLegendControlPanel::setPen(QPen pen)
117 {
118         pen_ = pen;
119         colorSelector->setCurrentColor(pen.color());
120         styleSelector->setCurrentLine(pen.style());
121         thicknessSelector->setCurrentLine(pen.width());
122 }
123
124 /**
125  * Initiates all needed fields
126  */
127 void FFChartLegendControlPanel::init()
128 {
129         // sets default values
130         setAutoFillBackground(true);
131
132         backgroundColor = DEFAULT_LEGEND_BACKGROUND_COLOR;
133         backgroundOpacity = DEFAULT_LEGEND_BACKGROUND_OPACITY;
134
135         //Initialize pen_
136         pen_.setWidth(0);
137         pen_.setStyle(Qt::SolidLine);
138         pen_.setColor(Qt::transparent);
139
140         //sets hide button
141         hideButton = new FFAbstractButton(this);
142
143         hideButton->setMargins(0, 0, 5, 5);
144         hideButton->setIconAlignment(Qt::AlignRight);
145         hideButton->setIcon(QIcon(QPixmap(":/standard/combo_colorarrow.svg")));
146
147         //creates selectors
148         colorSelector = new FFColorComboBox(this);
149         thicknessSelector = new FFLineComboBox(this);
150         styleSelector = new FFLineComboBox(this);
151
152         //sets selectors and add needed items
153         QBrush emptyBrush(QColor(20, 80, 0));
154         thicknessSelector->setTitle("Thickness's chooser");
155         thicknessSelector->addItem(QPen(QBrush(qRgb(100, 100, 100)), 1));
156         thicknessSelector->addItem(QPen(QBrush(qRgb(100, 100, 100)), 2));
157         thicknessSelector->addItem(QPen(QBrush(qRgb(100, 100, 100)), 3));
158         thicknessSelector->addItem(QPen(QBrush(qRgb(100, 100, 100)), 4));
159         thicknessSelector->addItem(QPen(QBrush(qRgb(100, 100, 100)), 5));
160         thicknessSelector->addItem(QPen(QBrush(qRgb(100, 100, 100)), 6));
161         thicknessSelector->addItem(QPen(QBrush(qRgb(100, 100, 100)), 7));
162         thicknessSelector->addItem(QPen(QBrush(qRgb(100, 100, 100)), 8));
163         thicknessSelector->addItem(QPen(QBrush(qRgb(100, 100, 100)), 9));
164         thicknessSelector->addItem(QPen(QBrush(qRgb(100, 100, 100)), 10));
165
166         styleSelector->setTitle("Style's chooser");
167         styleSelector->addItem(QPen(QBrush(qRgb(100, 100, 100)),
168                                     6,
169                                     Qt::SolidLine));
170         styleSelector->addItem(QPen(QBrush(qRgb(100, 100, 100)),
171                                     6,
172                                     Qt::DashLine));
173         styleSelector->addItem(QPen(QBrush(qRgb(100, 100, 100)), 6, Qt::DotLine));
174         styleSelector->addItem(QPen(QBrush(qRgb(100, 100, 100)),
175                                     6,
176                                     Qt::DashDotDotLine));
177         styleSelector->addItem(QPen(QBrush(qRgb(100, 100, 100)),
178                                     6,
179                                     Qt::DashDotLine));
180
181         colorSelector->addItem(QColor(125, 125, 125));
182         colorSelector->addItem(QColor(255, 0, 0));
183         colorSelector->addItem(QColor(0, 255, 0));
184         colorSelector->addItem(QColor(0, 0, 255));
185         colorSelector->addItem(QColor(255, 255, 0));
186         colorSelector->addItem(QColor(255, 255, 255));
187         colorSelector->addItem(QColor(0, 255, 255));
188         colorSelector->addItem(QColor(255, 0, 255));
189         colorSelector->addItem(QColor(255, 255, 255));
190         colorSelector->setCols(2);
191
192         //creates and sets layout of controlPanel
193         gLayout = new QGridLayout(this);
194         gLayout->setMargin(0);
195
196         gLayout->addWidget(thicknessSelector, 0, 0);
197         gLayout->addWidget(styleSelector, 1, 0);
198         gLayout->addWidget(colorSelector, 2, 0);
199         gLayout->addWidget(hideButton, 3, 0);
200
201         //empty item added to layout
202         QSpacerItem* horizontalSpacer = new QSpacerItem(1,
203                                                         1,
204                                                         QSizePolicy::Expanding,
205                                                         QSizePolicy::Expanding);
206         gLayout->addItem(horizontalSpacer, 4, 0);
207
208         //connects
209         connect(thicknessSelector,
210                 SIGNAL(activated(QVariant)),
211                 this,
212                 SLOT(thicknessChanged(QVariant)));
213         connect(styleSelector,
214                 SIGNAL(activated(QVariant)),
215                 this,
216                 SLOT(styleChanged(QVariant)));
217         connect(colorSelector,
218                 SIGNAL(activated(QVariant)),
219                 this,
220                 SLOT(colorChanged(QVariant)));
221         connect(hideButton, SIGNAL(clicked()), this, SLOT(hide()));
222 }
223
224 /**
225  * Slot to support sizeChooser and emit signal to legend
226  */
227 void FFChartLegendControlPanel::thicknessChanged(QVariant localPen)
228 {
229         pen_.setWidth(localPen.value<QPen> ().width());
230         emit penChanged(pen_);
231
232 }
233
234 /**
235  * Slot to support styleChooser and emit signal to legend
236  */
237 void FFChartLegendControlPanel::styleChanged(QVariant localPen)
238 {
239         pen_.setStyle(localPen.value<QPen> ().style());
240         emit penChanged(pen_);
241 }
242
243 /**
244  * Slot to support colorChooserand emit signal to legend
245  */
246 void FFChartLegendControlPanel::colorChanged(QVariant localPen)
247 {
248         pen_.setColor(localPen.value<QPen> ().color());
249         emit penChanged(pen_);
250 }
251
252 /**
253  * Slot to support hide feature
254  */
255 void FFChartLegendControlPanel::hide()
256 {
257         QWidget::hide();
258         if(NULL != parent)
259                 parent->parentWidget()->repaint(geometry());
260 }
261
262 /**
263  * Draws FFLegendControlPanel's background
264  * @param event Contains all informations about event.
265  */
266 void FFChartLegendControlPanel::paintEvent(QPaintEvent *event)
267 {
268         Q_UNUSED(event)
269         QPainter paint;
270         paint.begin(this);
271         paint.setOpacity(backgroundOpacity);
272         paint.setBrush(backgroundColor);
273         paint.setPen(Qt::transparent);
274         paint.drawRect(0, 0, width(), height());
275         paint.end();
276 }
277