1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#ifndef COLORFRAME_H_
#define COLORFRAME_H_
#include <QFrame>
#include <QColorDialog>
/*
*A simple widget that displays a color and allows the
* user to choose a new one with a QColorDialog
*/
class Colorframe : public QFrame
{
Q_OBJECT
public:
Colorframe(QWidget * parent, Qt::WindowFlags flags = 0) : QFrame(parent, flags){}
virtual void mousePressEvent ( QMouseEvent *)
{
QPalette palette = Colorframe::palette();
QColor temp = palette.color(QPalette::Normal, QPalette::Window);
temp = QColorDialog::getColor(temp);
if (temp.isValid()){
setColor(temp);
update();
}
}
QColor getColor(){return Colorframe::palette().color(QPalette::Normal, QPalette::Window);}
public slots:
void setColor(QColor c)
{
QPalette palette = Colorframe::palette();
palette.setColor(QPalette::Normal, QPalette::Window, c);
palette.setColor(QPalette::Disabled, QPalette::Window, c);
palette.setColor(QPalette::Inactive, QPalette::Window, c);
setPalette(palette);
update();
emit colorChanged(c);
}
signals:
void colorChanged(QColor c);
};
#endif /*COLORFRAME_H_*/
|