mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 16:20:06 +00:00
Add q_color_modulate for modulating the color of QIcons
This commit is contained in:
parent
c73698619d
commit
daa5bd24dc
3 changed files with 80 additions and 0 deletions
|
|
@ -357,6 +357,7 @@ set(HDR_UTIL source/scwx/qt/util/color.hpp
|
|||
source/scwx/qt/util/network.hpp
|
||||
source/scwx/qt/util/streams.hpp
|
||||
source/scwx/qt/util/texture_atlas.hpp
|
||||
source/scwx/qt/util/q_color_modulate.hpp
|
||||
source/scwx/qt/util/q_file_buffer.hpp
|
||||
source/scwx/qt/util/q_file_input_stream.hpp
|
||||
source/scwx/qt/util/time.hpp
|
||||
|
|
@ -369,6 +370,7 @@ set(SRC_UTIL source/scwx/qt/util/color.cpp
|
|||
source/scwx/qt/util/maplibre.cpp
|
||||
source/scwx/qt/util/network.cpp
|
||||
source/scwx/qt/util/texture_atlas.cpp
|
||||
source/scwx/qt/util/q_color_modulate.cpp
|
||||
source/scwx/qt/util/q_file_buffer.cpp
|
||||
source/scwx/qt/util/q_file_input_stream.cpp
|
||||
source/scwx/qt/util/time.cpp
|
||||
|
|
|
|||
56
scwx-qt/source/scwx/qt/util/q_color_modulate.cpp
Normal file
56
scwx-qt/source/scwx/qt/util/q_color_modulate.cpp
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#include <scwx/qt/util/q_color_modulate.hpp>
|
||||
|
||||
#include <QColor>
|
||||
#include <QImage>
|
||||
#include <QIcon>
|
||||
#include <QPixmap>
|
||||
#include <QSize>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
void modulateColors_(QImage& image, const QColor& color)
|
||||
{
|
||||
for (int y = 0; y < image.height(); ++y)
|
||||
{
|
||||
QRgb* line = reinterpret_cast<QRgb*>(image.scanLine(y));
|
||||
for (int x = 0; x < image.width(); ++x)
|
||||
{
|
||||
QRgb& rgb = line[x];
|
||||
int red = qRed(rgb) * color.redF();
|
||||
int green = qGreen(rgb) * color.greenF();
|
||||
int blue = qBlue(rgb) * color.blueF();
|
||||
int alpha = qAlpha(rgb) * color.alphaF();
|
||||
|
||||
rgb = qRgba(red, green, blue, alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QImage modulateColors(const QImage& image, const QColor& color)
|
||||
{
|
||||
QImage copy = image.copy();
|
||||
modulateColors_(copy, color);
|
||||
return copy;
|
||||
}
|
||||
|
||||
QPixmap modulateColors(const QPixmap& pixmap, const QColor& color)
|
||||
{
|
||||
QImage image = pixmap.toImage();
|
||||
modulateColors_(image, color);
|
||||
return QPixmap::fromImage(image);
|
||||
}
|
||||
|
||||
QIcon modulateColors(const QIcon& icon, const QSize& size, const QColor& color)
|
||||
{
|
||||
QPixmap pixmap = modulateColors(icon.pixmap(size), color);
|
||||
return QIcon(pixmap);
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
22
scwx-qt/source/scwx/qt/util/q_color_modulate.hpp
Normal file
22
scwx-qt/source/scwx/qt/util/q_color_modulate.hpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <QColor>
|
||||
#include <QImage>
|
||||
#include <QIcon>
|
||||
#include <QPixmap>
|
||||
#include <QSize>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
QImage modulateColors(const QImage& image, const QColor& color);
|
||||
QPixmap modulateColors(const QPixmap& pixmap, const QColor& color);
|
||||
QIcon modulateColors(const QIcon& icon, const QSize& size, const QColor& color);
|
||||
|
||||
} // namespace util
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
Loading…
Add table
Add a link
Reference in a new issue