diff options
author | Mateusz Łukasik <mati75@linuxmint.pl> | 2016-11-21 11:29:50 +0100 |
---|---|---|
committer | Mateusz Łukasik <mati75@linuxmint.pl> | 2016-11-21 11:29:50 +0100 |
commit | 634cd2063f449c5d38046de88a395af77e2c9ea5 (patch) | |
tree | 55abc0118d6d82d019969471ac01076924abaa8e /src/colorutils.cpp | |
parent | 392e79606ccba0695027b63ed872c4b0a491cd8b (diff) |
New upstream version 16.11.0~ds0
Diffstat (limited to 'src/colorutils.cpp')
-rw-r--r-- | src/colorutils.cpp | 62 |
1 files changed, 48 insertions, 14 deletions
diff --git a/src/colorutils.cpp b/src/colorutils.cpp index 2f5cdc9..a417556 100644 --- a/src/colorutils.cpp +++ b/src/colorutils.cpp @@ -18,37 +18,71 @@ #include "colorutils.h" #include <QWidget> +#include <QDebug> -QString ColorUtils::colorToRRGGBBAA(unsigned int color) { +#if 0 +QString ColorUtils::colorToRGB(unsigned int color) { QColor c; - c.setRgb( color ); + c.setRgb(color); + return colorToRGB(c); +} - QString s; - return s.sprintf("%02x%02x%02x00", c.red(), c.green(), c.blue() ); +QString ColorUtils::colorToRRGGBBAA(unsigned int color) { + QColor c; + c.setRgb(color); + return colorToRRGGBBAA(c); } QString ColorUtils::colorToRRGGBB(unsigned int color) { QColor c; - c.setRgb( color ); - - QString s; - return s.sprintf("%02x%02x%02x", c.red(), c.green(), c.blue() ); + c.setRgb(color); + return colorToRRGGBB(c); } -QString ColorUtils::colorToRGB(unsigned int color) { +QString ColorUtils::colorToAABBGGRR(unsigned int color) { QColor c; - c.setRgb( color ); + c.setRgb(color); + return colorToAABBGGRR(c); +} +#endif +QString ColorUtils::colorToRGB(QColor c) { QString s; return s.sprintf("0x%02x%02x%02x", c.blue(), c.green(), c.red() ); } -QString ColorUtils::colorToAABBGGRR(unsigned int color) { - QColor c; - c.setRgb( color ); +QString ColorUtils::colorToRRGGBBAA(QColor c) { + QString s; + return s.sprintf("%02x%02x%02x%02x", c.red(), c.green(), c.blue(), c.alpha()); +} + +QString ColorUtils::colorToRRGGBB(QColor c) { + QString s; + return s.sprintf("%02x%02x%02x", c.red(), c.green(), c.blue()); +} + +QString ColorUtils::colorToAABBGGRR(QColor c) { + QString s; + return s.sprintf("%02x%02x%02x%02x", 255 - c.alpha(), c.blue(), c.green(), c.red() ); +} +QString ColorUtils::colorToAARRGGBB(QColor c) { QString s; - return s.sprintf("00%02x%02x%02x", c.blue(), c.green(), c.red() ); + return s.sprintf("%02x%02x%02x%02x", c.alpha(), c.red(), c.green(), c.blue()); +} + +QColor ColorUtils::AARRGGBBToColor(const QString & s) { + QRegExp rx("([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})"); + if (rx.indexIn(s) > -1 && rx.captureCount() == 4) { + qDebug() << "ColorUtils::AARRGGBBToColor:" << rx.cap(1) << rx.cap(2) << rx.cap(3) << rx.cap(4); + uint alpha = rx.cap(1).toUInt(0, 16); + uint red = rx.cap(2).toUInt(0, 16); + uint green = rx.cap(3).toUInt(0, 16); + uint blue = rx.cap(4).toUInt(0, 16); + QColor c(red, green, blue, alpha); + return c; + } + return QColor(); } #ifdef CHANGE_WIDGET_COLOR |