summaryrefslogtreecommitdiff
path: root/ui/qt/color_utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ui/qt/color_utils.cpp')
-rw-r--r--ui/qt/color_utils.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/ui/qt/color_utils.cpp b/ui/qt/color_utils.cpp
index 0603a26b98..4210d29734 100644
--- a/ui/qt/color_utils.cpp
+++ b/ui/qt/color_utils.cpp
@@ -60,6 +60,26 @@ QColor ColorUtils::fromColorT(color_t color)
return fromColorT(&color);
}
+QRgb ColorUtils::alphaBlend(const QColor &color1, const QColor &color2, qreal alpha)
+{
+ alpha = qBound(0.0, alpha, 1.0);
+
+ int r1 = color1.red() * alpha;
+ int g1 = color1.green() * alpha;
+ int b1 = color1.blue() * alpha;
+ int r2 = color2.red() * (1 - alpha);
+ int g2 = color2.green() * (1 - alpha);
+ int b2 = color2.blue() * (1 - alpha);
+
+ QColor alpha_color(r1 + r2, g1 + g2, b1 + b2);
+ return alpha_color.rgb();
+}
+
+QRgb ColorUtils::alphaBlend(const QBrush &brush1, const QBrush &brush2, qreal alpha)
+{
+ return alphaBlend(brush1.color(), brush2.color(), alpha);
+}
+
/*
* Editor modelines
*