Git commit a3c58a129192ee2f152f69548e824d8e83a691cd by Jan Kundr?t. Committed on 01/05/2013 at 17:21. Pushed by jkt into branch 'master'.
GUI: add support for color tinting The idea was suggested by Thomas L?bking, the implementation is shamelessly stolen from Qt5's qtquick1 module (src/declarative/qml/qdeclarativeengine.cpp, the usual Qt licensing). M +24 -0 src/Gui/Util.cpp M +3 -0 src/Gui/Util.h http://commits.kde.org/trojita/a3c58a129192ee2f152f69548e824d8e83a691cd diff --git a/src/Gui/Util.cpp b/src/Gui/Util.cpp index dab9bac..a1ec6de 100644 --- a/src/Gui/Util.cpp +++ b/src/Gui/Util.cpp @@ -68,6 +68,30 @@ QString pkgDataDir() #endif } +/** @short Return the source color tinted with the tintColor + +This is shamelessly stolen from Qt5's qtquick1 module. +*/ +QColor tintColor(const QColor &color, const QColor &tintColor) +{ + QColor finalColor; + int a = tintColor.alpha(); + if (a == 0xff) { + finalColor = tintColor; + } else if (a == 0x00) { + finalColor = color; + } else { + qreal a = tintColor.alphaF(); + qreal inv_a = 1.0 - a; + + finalColor.setRgbF(tintColor.redF() * a + color.redF() * inv_a, + tintColor.greenF() * a + color.greenF() * inv_a, + tintColor.blueF() * a + color.blueF() * inv_a, + a + inv_a * color.alphaF()); + } + return finalColor; +} + } // namespace Util } // namespace Gui diff --git a/src/Gui/Util.h b/src/Gui/Util.h index 56cd3a1..9e68c92 100644 --- a/src/Gui/Util.h +++ b/src/Gui/Util.h @@ -26,6 +26,7 @@ #include <QString> +class QColor; class QWidget; namespace Gui @@ -39,6 +40,8 @@ void centerWidgetOnScreen(QWidget *widget, bool centerOnCursorScreen=true); QString pkgDataDir(); +QColor tintColor(const QColor &color, const QColor &tintColor); + } // namespace Util } // namespace Gui
