#include <KColorButton>
#include <KLocalizedString>
+static QColor stringToColor(QString strColor)
+{
+ bool ok = false;
+ QColor color("black");
+ int intval = 0;
+
+ if (strColor.startsWith("0x")) {
+ // Format must be 0xRRGGBBAA
+ intval = strColor.toUInt(&ok, 16);
+ color.setRgb( ( intval >> 24 ) & 0xff, // r
+ ( intval >> 16 ) & 0xff, // g
+ ( intval >> 8 ) & 0xff, // b
+ ( intval ) & 0xff ); // a
+ } else if (strColor.startsWith("#") && strColor.length() == 9) {
+ // Format must be #AARRGGBB
+ strColor = strColor.replace('#', "0x");
+ intval = strColor.toUInt(&ok, 16);
+ color.setRgb( ( intval >> 16 ) & 0xff, // r
+ ( intval >> 8 ) & 0xff, // g
+ ( intval ) & 0xff, // b
+ ( intval >> 24 ) & 0xff ); // a
+ } else if (strColor.startsWith("#") && strColor.length() == 7) {
+ // Format must be #RRGGBB
+ strColor = strColor.replace('#', "0x");
+ intval = strColor.toUInt(&ok, 16);
+ color.setRgb( ( intval >> 16 ) & 0xff, // r
+ ( intval >> 8 ) & 0xff, // g
+ ( intval ) & 0xff, // b
+ 0xff ); // a
+ }
+
+ return color;
+}
+
+static QString colorToString(QColor color, bool alpha)
+{
+ QString colorStr;
+ QTextStream stream(&colorStr);
+ stream << "#";
+ stream.setIntegerBase(16);
+ stream.setFieldWidth(2);
+ stream.setFieldAlignment(QTextStream::AlignRight);
+ stream.setPadChar('0');
+ if(alpha)
+ {
+ stream << color.alpha();
+ }
+ stream << color.red() << color.green() << color.blue();
-ChooseColorWidget::ChooseColorWidget(QString text, QColor color, QWidget *parent) :
+ return colorStr;
+}
+
+ChooseColorWidget::ChooseColorWidget(QString text, QString color, QWidget *parent) :
QWidget(parent)
{
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setSpacing(0);
QLabel *label = new QLabel(text, this);
- m_button = new KColorButton(color, this);
+ m_button = new KColorButton(stringToColor(color), this);
m_button->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
ColorPickerWidget *picker = new ColorPickerWidget(this);
connect(m_button, SIGNAL(changed(QColor)), this, SIGNAL(modified()));
}
-QColor ChooseColorWidget::getColor()
+QString ChooseColorWidget::getColor()
+{
+ return colorToString(m_button->color(), m_button->isAlphaChannelEnabled());
+}
+
+void ChooseColorWidget::setAlphaChannelEnabled(bool enabled)
{
- return m_button->color();
+ m_button->setAlphaChannelEnabled(enabled);
}
void ChooseColorWidget::setColor(QColor color)