Show CColorButton.h syntax highlighted
#ifndef CCOLORBUTTON_H_
#define CCOLORBUTTON_H_
#include <QtGui/QPushButton>
#include <QtGui/QColor>
#include <QtGui/QColorDialog>
namespace osgDesigner
{
class CColorButton: public QPushButton
{
//Q_OBJECT
public:
CColorButton(QWidget * parent = 0 )
: QPushButton(parent)
{
_color.setRgbF(1.0,1.0,1.0,1.0);
// updatePalette();
}
virtual ~CColorButton() {}
#define nbPix 6
virtual void paintEvent(QPaintEvent *)
{
QPainter painter(this);
QBrush brush(_color);
QPixmap pm(2*nbPix, 2*nbPix);
QPainter pmp(&pm);
pmp.fillRect(0, 0, nbPix, nbPix, Qt::lightGray);
pmp.fillRect(nbPix, nbPix, nbPix, nbPix, Qt::lightGray);
pmp.fillRect(0, nbPix, nbPix, nbPix, Qt::darkGray);
pmp.fillRect(nbPix, 0, nbPix, nbPix, Qt::darkGray);
pmp.end();
painter.save();
painter.setBackgroundMode(Qt::OpaqueMode);
painter.setBackground(QBrush(pm));
painter.restore();
painter.fillRect(0, 0, width(), height(), brush);
}
virtual void nextCheckState()
{
bool flag = false;
QRgb colorRgba = QColorDialog::getRgba(_color.rgba(), &flag, this);
if (flag)
{
_color.setRgba(colorRgba);
//updatePalette();
}
}
private:
// void updatePalette()
// {
// QPixmap pm(2*nbPix, 2*nbPix);
// QPainter pmp(&pm);
// pmp.fillRect(0, 0, nbPix, nbPix, Qt::lightGray);
// pmp.fillRect(nbPix, nbPix, nbPix, nbPix, Qt::lightGray);
// pmp.fillRect(0, nbPix, nbPix, nbPix, Qt::darkGray);
// pmp.fillRect(nbPix, 0, nbPix, nbPix, Qt::darkGray);
// pmp.end();
// QPalette pal = palette();
//
// if (backgroundRole() == QPalette::Button)
// {
// pal.setBrush(backgroundRole(), QBrush(pm));
// setAutoFillBackground(true);
// }
// else
// {
// pal.setColor(QPalette::Button, _color);
// }
// setPalette(pal);
// }
QColor _color;
};
}
#endif // ** __CCOLORBUTTON_H__ ** //
See more files for this project here