custom buttons
[colorflood] / colorflood / src / colorbuttons.cpp
1 /*
2   Copyright 2010 Serge Ziryukin <ftrvxmtrx@gmail.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation; version 2 of the License.
7
8   This program is distributed in the hope that it will be useful,
9   but WITHOUT ANY WARRANTY; without even the implied warranty of
10   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   GNU General Public License for more details.
12 */
13
14 #include <QBrush>
15 #include <QPainter>
16 #include <QPixmap>
17 #include <QPushButton>
18 #include <QGridLayout>
19 #include "colorbuttons.hpp"
20 #include "colorscheme.hpp"
21 #include "colorbutton.hpp"
22
23 ColorButtons::ColorButtons (QWidget *parent)
24     : QGroupBox(parent)
25 {
26     Q_ASSERT(parent);
27
28     const QVector<QBrush> &scheme = ColorScheme::instance().getScheme();
29     QGridLayout *layout = new QGridLayout;
30
31     for (int i = 0; i < scheme.size(); i++)
32     {
33         ColorButton *button = new ColorButton(this, i);
34         layout->addWidget(button, (i - (i % 3)) / 3, i % 3);
35         group.addButton(button, i);
36     }
37
38     QObject::connect(&group,
39                      SIGNAL(buttonClicked(int)),
40                      this,
41                      SIGNAL(flood(int)));
42
43     setLayout(layout);
44 }