d8275f6b6f341688d9de9a4271b67b3491dcda8c
[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 <QVBoxLayout>
19 #include "colorbuttons.hpp"
20 #include "colorscheme.hpp"
21
22 ColorButtons::ColorButtons (QWidget *parent)
23     : QGroupBox(parent)
24 {
25     Q_ASSERT(parent);
26
27     const QVector<QBrush> &scheme = ColorScheme::instance().getScheme();
28     QVBoxLayout *layout = new QVBoxLayout;
29
30     for (int i = 0; i < scheme.size(); i++)
31     {
32         QPixmap pixmap(64, 64);
33         QPainter painter;
34         painter.begin(&pixmap);
35         painter.fillRect(pixmap.rect(), scheme.at(i));
36         painter.end();
37
38         QPushButton *button = new QPushButton(pixmap, "", this);
39         button->setFixedSize(48, 48);
40         layout->addWidget(button);
41         group.addButton(button, i);
42     }
43
44     QObject::connect(&group,
45                      SIGNAL(buttonClicked(int)),
46                      this,
47                      SIGNAL(flood(int)));
48
49     setLayout(layout);
50 }