X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fchoosecolorwidget.cpp;h=d842a0a30d587612e0ccdbea40360db3e90c2eaa;hb=c1ad9ec174e137d76b6bb92430d2798db27f07d7;hp=36eb893b945419769e79e637cade375fa7fd3761;hpb=7d708fd156c646b36c91cffaed60e5cf777f95d9;p=kdenlive diff --git a/src/choosecolorwidget.cpp b/src/choosecolorwidget.cpp index 36eb893b..d842a0a3 100644 --- a/src/choosecolorwidget.cpp +++ b/src/choosecolorwidget.cpp @@ -27,36 +27,42 @@ #include #include #include +#include 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 + if (strColor.length() == 10) { + // 0xRRGGBBAA + intval = strColor.toUInt(&ok, 16); + color.setRgb( ( intval >> 24 ) & 0xff, // r + ( intval >> 16 ) & 0xff, // g + ( intval >> 8 ) & 0xff, // b + ( intval ) & 0xff ); // a + } else { + // 0xRRGGBB, 0xRGB + color.setNamedColor(strColor.replace(0, 2, "#")); + } + } else { + if (strColor.length() == 9) { + // #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.length() == 8) { + // 0xRRGGBB + strColor = strColor.replace('#', "0x"); + color.setNamedColor(strColor); + } else { + // #RRGGBB, #RGB + color.setNamedColor(strColor); + } } return color; @@ -66,21 +72,24 @@ static QString colorToString(QColor color, bool alpha) { QString colorStr; QTextStream stream(&colorStr); - stream << "#"; + stream << "0x"; stream.setIntegerBase(16); stream.setFieldWidth(2); stream.setFieldAlignment(QTextStream::AlignRight); stream.setPadChar('0'); + stream << color.red() << color.green() << color.blue(); if(alpha) { stream << color.alpha(); } - stream << color.red() << color.green() << color.blue(); - + else { + // MLT always wants 0xRRGGBBAA format + stream << "ff"; + } return colorStr; } -ChooseColorWidget::ChooseColorWidget(QString text, QString color, QWidget *parent) : +ChooseColorWidget::ChooseColorWidget(QString text, QString color, bool alphaEnabled, QWidget *parent) : QWidget(parent) { QHBoxLayout *layout = new QHBoxLayout(this); @@ -95,6 +104,9 @@ ChooseColorWidget::ChooseColorWidget(QString text, QString color, QWidget *paren rightSideLayout->setSpacing(0); m_button = new KColorButton(stringToColor(color), rightSide); +#if KDE_IS_VERSION(4,5,0) + if (alphaEnabled) m_button->setAlphaChannelEnabled(alphaEnabled); +#endif // m_button->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); ColorPickerWidget *picker = new ColorPickerWidget(rightSide); @@ -105,6 +117,7 @@ ChooseColorWidget::ChooseColorWidget(QString text, QString color, QWidget *paren connect(picker, SIGNAL(colorPicked(QColor)), this, SLOT(setColor(QColor))); connect(picker, SIGNAL(displayMessage(const QString&, int)), this, SIGNAL(displayMessage(const QString&, int))); + connect(picker, SIGNAL(disableCurrentFilter(bool)), this, SIGNAL(disableCurrentFilter(bool))); connect(m_button, SIGNAL(changed(QColor)), this, SIGNAL(modified())); } @@ -117,13 +130,6 @@ QString ChooseColorWidget::getColor() return colorToString(m_button->color(), alphaChannel); } -void ChooseColorWidget::setAlphaChannelEnabled(bool enabled) -{ -#if KDE_IS_VERSION(4,5,0) - m_button->setAlphaChannelEnabled(enabled); -#endif -} - void ChooseColorWidget::setColor(QColor color) { m_button->setColor(color);