From cbb9a378984c50baddc9997240fa67a186b954ae Mon Sep 17 00:00:00 2001 From: Serge Ziryukin Date: Tue, 13 Apr 2010 10:26:43 +0300 Subject: [PATCH] simple and stupid color buttons --- colorflood/src/colorbuttons.cpp | 50 +++++++++++++++++++++++++++++++++++++++ colorflood/src/colorbuttons.hpp | 34 ++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 colorflood/src/colorbuttons.cpp create mode 100644 colorflood/src/colorbuttons.hpp diff --git a/colorflood/src/colorbuttons.cpp b/colorflood/src/colorbuttons.cpp new file mode 100644 index 0000000..d8275f6 --- /dev/null +++ b/colorflood/src/colorbuttons.cpp @@ -0,0 +1,50 @@ +/* + Copyright 2010 Serge Ziryukin + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +*/ + +#include +#include +#include +#include +#include +#include "colorbuttons.hpp" +#include "colorscheme.hpp" + +ColorButtons::ColorButtons (QWidget *parent) + : QGroupBox(parent) +{ + Q_ASSERT(parent); + + const QVector &scheme = ColorScheme::instance().getScheme(); + QVBoxLayout *layout = new QVBoxLayout; + + for (int i = 0; i < scheme.size(); i++) + { + QPixmap pixmap(64, 64); + QPainter painter; + painter.begin(&pixmap); + painter.fillRect(pixmap.rect(), scheme.at(i)); + painter.end(); + + QPushButton *button = new QPushButton(pixmap, "", this); + button->setFixedSize(48, 48); + layout->addWidget(button); + group.addButton(button, i); + } + + QObject::connect(&group, + SIGNAL(buttonClicked(int)), + this, + SIGNAL(flood(int))); + + setLayout(layout); +} diff --git a/colorflood/src/colorbuttons.hpp b/colorflood/src/colorbuttons.hpp new file mode 100644 index 0000000..5d837c3 --- /dev/null +++ b/colorflood/src/colorbuttons.hpp @@ -0,0 +1,34 @@ +/* + Copyright 2010 Serge Ziryukin + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +*/ + +#ifndef _COLORBUTTONS_HPP +#define _COLORBUTTONS_HPP + +#include +#include + +class ColorButtons : public QGroupBox +{ + Q_OBJECT; + +public: + ColorButtons (QWidget *parent); + +signals: + void flood (int colorIndex); + +private: + QButtonGroup group; +}; + +#endif // !_COLORBUTTONS_HPP -- 1.7.9.5