Commit 82c66ae3 authored by Pierre Kraemer's avatar Pierre Kraemer

add missing files

parent f17551a4
#ifndef _COLORCOMBOBOX_H
#define _COLORCOMBOBOX_H
#include <QComboBox>
class QColor;
class QWidget;
class ColorComboBox : public QComboBox
{
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor USER true)
public:
QColor color() const;
void setColor(QColor c);
public:
ColorComboBox(QWidget *widget = 0);
private:
void populateList();
public slots:
void slotHighlight(int index);
};
#endif
#include <QtGui>
#include "colorComboBox.h"
ColorComboBox::ColorComboBox(QWidget *widget) : QComboBox(widget)
{
//connect( this, SIGNAL(highlighted(int)), this, SLOT(slotHighlight(int)) );
populateList();
}
QColor ColorComboBox::color() const
{
return qvariant_cast<QColor>(itemData(currentIndex(), Qt::DecorationRole));
}
void ColorComboBox::setColor(QColor color)
{
setCurrentIndex(findData(color, int(Qt::DecorationRole)));
}
void ColorComboBox::populateList()
{
//QStringList colorNames = QColor::colorNames();
QStringList colorNames;
colorNames <<
"red" <<
"green" <<
"blue" <<
"cyan "<<
"magenta" <<
"yellow" <<
"gray" <<
"white" <<
"black";
for (int i = 0; i < colorNames.size(); ++i)
{
QColor color(colorNames[i]);
insertItem(i, colorNames[i]);
setItemData(i, color, Qt::DecorationRole);
}
}
void ColorComboBox::slotHighlight(int index)
{
const QStringList colorNames = QColor::colorNames();
QColor color(colorNames.at(index));
QPalette palette = this->palette();
palette.setColor(QPalette::Highlight, color);
setPalette(palette);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment