本文整理汇总了C++中QColor::setHsl方法的典型用法代码示例。如果您正苦于以下问题:C++ QColor::setHsl方法的具体用法?C++ QColor::setHsl怎么用?C++ QColor::setHsl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QColor
的用法示例。
在下文中一共展示了QColor::setHsl方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toColor
QColor ColorRangeBase::toColor(const QVariant &v, ColorRangeBase::ColorModel colormodel)
{
if ( v.type() == QVariant::Color)
return QColor(v.value<QColor>());
else if ( v.type() == QVariant::String){
QRegExp separ("[(]|,|[)]");
QStringList parts = (v.toString()).split(separ);
if(parts.last().isEmpty())
parts.removeLast();
QColor clr;
bool ok1,ok2,ok3,ok4,ok5 =true;
if ( parts.size() >= 5){
double component1 = parts[1].toDouble(&ok1);
double component2 = parts[2].toDouble(&ok2);
double component3 = parts[3].toDouble(&ok3);
double component4 = parts[4].toDouble(&ok4);
double component5 = parts.size()== 6 ? parts[5].toDouble(&ok5) : rUNDEF;
if(! (ok1 && ok2 && ok3 && ok4 && ok5))
return QColor();
bool isFractional = component1 <= 1 && component2 <= 1 && component3 <= 1 && component4 <= 1;
if ( parts[0].toLower() == "rgba"){
if ( isFractional){
clr.setRgbF(component1,component2, component3);
clr.setAlphaF(component4);
}
else{
clr.setRgb(component1,component2, component3);
clr.setAlpha(component4);
}
}else if ( parts[0].toLower() == "hsla"){
if ( isFractional){
clr.setHslF(component1,component2, component3);
clr.setAlphaF(component4);
}
else{
clr.setHsl(component1,component2, component3);
clr.setAlpha(component4);
}
} else if ( parts[0].toLower() == "cmyka" && parts.size() == 6){
if ( isFractional){
clr.setCmykF(component1,component2, component3, component4);
clr.setAlphaF(component5);
}
else{
clr.setCmyk(component1,component2, component3, component4);
clr.setAlpha(component5);
}
}
return clr;
}
} else if( v.type() == QVariant::ULongLong){
return ColorRangeBase::toColor(v.toULongLong(),colormodel);
} else if( v.type() == QVariant::Double){
return ColorRangeBase::toColor(v.toULongLong(),colormodel);
}
return QColor();
}
示例2: applySaturation
void Alg_DefaultEffects::applySaturation(QImage *image1, QImage *image2, int delta)
{
QColor oldColor;
QColor newColor;
int h, s, l;
for (int x = 0; x < image1->width(); x++)
{
for (int y = 0; y < image1->height(); y++)
{
oldColor = QColor(image1->pixel(x, y));
newColor = oldColor.toHsl();
h = newColor.hue();
s = newColor.saturation()+delta;
l = newColor.lightness();
//we check if the new value is between 0 and 255
s = qBound(0, s, 255);
newColor.setHsl(h, s, l);
image2->setPixel(x, y, qRgb(newColor.red(), newColor.green(), newColor.blue()));
}
}
}
示例3: do_color_preprocessing_by_type
QColor color_selector::do_color_preprocessing_by_type (QColor color, color_single_selector_type type)
{
switch (type)
{
case color_single_selector_type::HSL_HUE:
color.setHsl (0, 255, 128, 255); // In this case we need basically the same palette for every color (rainbow)
break;
case color_single_selector_type::HSV_HUE:
color.setHsv (0, 255, 255, 255);
break;
case color_single_selector_type::HSL_LIGHTNESS:
case color_single_selector_type::HSL_SATURATION:
return change_param_by_type (color, 255, color_single_selector_type::HSL_ALPHA);
case color_single_selector_type::HSV_SATURATION:
case color_single_selector_type::HSV_VALUE:
return change_param_by_type (color, 255, color_single_selector_type::HSV_ALPHA);
case color_single_selector_type::CMYK_CYAN:
case color_single_selector_type::CMYK_MAGENTA:
case color_single_selector_type::CMYK_YELLOW:
case color_single_selector_type::CMYK_BLACK:
return change_param_by_type (color, 255, color_single_selector_type::CMYK_ALPHA);
case color_single_selector_type::RGB_RED:
case color_single_selector_type::RGB_GREEN:
case color_single_selector_type::RGB_BLUE:
return change_param_by_type (color, 255, color_single_selector_type::RGB_ALPHA);
case color_single_selector_type::RGB_ALPHA:
case color_single_selector_type::HSL_ALPHA:
case color_single_selector_type::HSV_ALPHA:
case color_single_selector_type::CMYK_ALPHA:
break;
}
return color;
}
示例4: saturate
QPixmap ImageFilter::saturate(QImage origin, int delta)
{
QImage newImage(origin.width(), origin.height(), QImage::Format_ARGB32);
QColor oldColor;
QColor newColor;
int h,s,l;
for(int x=0; x < newImage.width(); x++)
{
for(int y=0; y < newImage.height(); y++)
{
oldColor = QColor(origin.pixel(x, y));
newColor = oldColor.toHsl();
h = newColor.hue();
s = newColor.saturation() + delta;
l = newColor.lightness();
//we check if the new value is between 0 and 255
s = qBound(0, s, 255);
newColor.setHsl(h, s, l);
newImage.setPixel(x, y, qRgb(newColor.red(), newColor.green(), newColor.blue()));
}
}
QPixmap processedImage(QPixmap::fromImage(newImage));
return processedImage;
}
示例5: getDefaultIconColor
QColor getDefaultIconColor(const QColor &color)
{
QColor c = color;
bool menuBackgrounIsLight = c.lightness() > lightThreshold;
c.setHsl(c.hue(),
qMax(0, qMin(255, c.saturation() + (menuBackgrounIsLight ? 30 : 10))),
qMax(0, qMin(255, c.lightness() + (menuBackgrounIsLight ? -140 : 100))));
return c;
}
示例6:
DivePercentageItem::DivePercentageItem(int i)
{
QPen pen;
QColor color;
color.setHsl(100 + 10 * i, 200, 100);
pen.setBrush(QBrush(color));
pen.setCosmetic(true);
pen.setWidth(1);
setPen(pen);
settingsChanged();
}
示例7: handlePaletteCase
bool RasterCoverageConnector::handlePaletteCase(Size<> &rastersize, RasterCoverage* raster) {
auto layerHandle = gdal()->getRasterBand(_handle->handle(), 1);
auto paletteHandle = gdal()->getColorPalette(layerHandle);
ColorPalette *palette = new ColorPalette();
if (!paletteHandle)
return false;
int count = gdal()->getColorPaletteSize(paletteHandle);
if ( count == 0)
return false;
ColorRangeBase::ColorModel model;
GDALPaletteInterp colorType = gdal()->getPaletteColorInterpretation(paletteHandle);
for(int i = 0; i < count; ++i) {
GDALColorEntry *entry = gdal()->getColorPaletteEntry(paletteHandle, i);
if ( !entry)
continue;
QColor clr;
switch ( colorType){
case GPI_RGB:
clr.setRgb(entry->c1, entry->c2, entry->c3);
model = ColorRangeBase::cmRGBA;
break;
case GPI_HLS:
clr.setHsl(entry->c1, entry->c2, entry->c3); break;
model = ColorRangeBase::cmHSLA;
break;
case GPI_CMYK:
clr.setCmyk(entry->c1, entry->c2, entry->c3, entry->c4);
model = ColorRangeBase::cmCYMKA;
break;
case GPI_Gray:
clr.setRgb(entry->c1, entry->c1, entry->c1);
model = ColorRangeBase::cmGREYSCALE;
}
clr.setAlpha(entry->c4);
palette->add(new ColorItem(clr));
}
palette->defaultColorModel(model);
_typeSize = 1;
_gdalValueType = gdal()->rasterDataType(layerHandle);
raster->datadefRef() = DataDefinition(IDomain("colorpalette"), reinterpret_cast<Range *>(palette));
return true;
}
示例8: draw
/**
* Draws a rappresentation of the sensor with the painter
*/
void GroundSensor::draw(QPainter& p)
{
p.save();
p.setPen(Qt::transparent);
QColor color = QColor(255,255,255,255);
color.setHsl(0,0,255);
//color.setAlphaF(0.2);
smReal pointDimX = paddingX/5;
smReal pointDimY = paddingY/5;
for (int x=0; x<cols; x++) {
for (int y=0; y<rows; y++) {
smReal weight = matrix[matrixPosition(x,y)];
color.setHsv(0,weight,255);
p.setBrush(color);
QPointF center = realWorldPosition(x,y);
p.drawEllipse(center,pointDimX,pointDimY);
}
}
p.restore();
}
示例9: loadColor
void ColorRangeBase::loadColor(QColor& clr, QDataStream &stream){
int c1, c2, c3, c4;
stream >> c1 >> c2 >> c3 >> c4;
switch (defaultColorModel()){
case ColorRangeBase::cmRGBA:
clr.setRgb(c1,c2,c3);
clr.setAlpha(c4);
break;
case ColorRangeBase::cmHSLA:
clr.setHsl(c1,c2,c3);
clr.setAlpha(c4);
break;
case ColorRangeBase::cmCYMKA:
clr.setCmyk(c1,c2,c3, c4);
break;
case ColorRangeBase::cmGREYSCALE:
stream << clr.red();
default:
break;
}
}
示例10: setIcons
void FlatButton::setIcons(const QIcon& _icon, const QIcon& _checkedIcon, const QIcon& _hoverIcon)
{
m_icon = _icon;
ImageHelper::setIconColor(m_icon, ICON_SIZE, palette().text().color());
m_checkedIcon = _checkedIcon;
if (!m_checkedIcon.isNull()) {
m_checkedIconHighlight = false;
ImageHelper::setIconColor(m_checkedIcon, ICON_SIZE, palette().text().color());
} else {
m_checkedIconHighlight = true;
m_checkedIcon = _icon;
QColor highlightColor = palette().highlight().color();
#ifdef Q_OS_MAC
highlightColor.setHsl(highlightColor.hslHue(), highlightColor.hslSaturation(),
highlightColor.lightness() - 50);
#endif
ImageHelper::setIconColor(m_checkedIcon, ICON_SIZE, highlightColor);
}
m_hoverIcon = _hoverIcon;
aboutUpdateIcon();
}
示例11: setHsl
void tst_QColor::setHsl()
{
QColor color;
for (int A = 0; A <= USHRT_MAX; ++A) {
{
// 0-255
int a = A >> 8;
color.setHsl(0, 0, 0, a);
QCOMPARE(color.alpha(), a);
int h, s, l, a2;
color.getHsv(&h, &s, &l, &a2);
QCOMPARE(a2, a);
}
{
// 0.0-1.0
qreal a = A / qreal(USHRT_MAX);
color.setHslF(0.0, 0.0, 0.0, a);
QCOMPARE(color.alphaF(), a);
qreal h, s, l, a2;
color.getHslF(&h, &s, &l, &a2);
QCOMPARE(a2, a);
}
}
for (int H = 0; H < 36000; ++H) {
{
// 0-255
int h = H / 100;
color.setHsl(h, 0, 0, 0);
QCOMPARE(color.hslHue(), h);
int h2, s, l, a;
color.getHsl(&h2, &s, &l, &a);
QCOMPARE(h2, h);
}
{
// 0.0-1.0
qreal h = H / 36000.0;
color.setHslF(h, 0.0, 0.0, 0.0);
QCOMPARE(color.hslHueF(), h);
qreal h2, s, l, a;
color.getHslF(&h2, &s, &l, &a);
QCOMPARE(h2, h);
}
}
for (int S = 0; S <= USHRT_MAX; ++S) {
{
// 0-255
int s = S >> 8;
color.setHsl(0, s, 0, 0);
QCOMPARE(color.hslSaturation(), s);
int h, s2, l, a;
color.getHsl(&h, &s2, &l, &a);
QCOMPARE(s2, s);
}
{
// 0.0-1.0
qreal s = S / qreal(USHRT_MAX);
color.setHslF(0.0, s, 0.0, 0.0);
QCOMPARE(color.hslSaturationF(), s);
qreal h, s2, l, a;
color.getHslF(&h, &s2, &l, &a);
QCOMPARE(s2, s);
}
}
for (int L = 0; L <= USHRT_MAX; ++L) {
{
// 0-255
int l = L >> 8;
color.setHsl(0, 0, l, 0);
QCOMPARE(color.lightness(), l);
int h, s, l2, a;
color.getHsl(&h, &s, &l2, &a);
QCOMPARE(l2, l);
}
{
// 0.0-1.0
qreal l = L / qreal(USHRT_MAX);
color.setHslF(0.0, 0.0, l, 0.0);
QCOMPARE(color.lightnessF(), l);
qreal h, s, l2, a;
color.getHslF(&h, &s, &l2, &a);
QCOMPARE(l2, l);
}
}
//.........这里部分代码省略.........
示例12: change_param_by_type
QColor color_selector::change_param_by_type (QColor color, int value, color_single_selector_type type)
{
int h = 0, s, v, l, r, g, b, a, c, m, y, k;
switch (type)
{
case color_single_selector_type::HSV_SATURATION:
case color_single_selector_type::HSV_HUE:
case color_single_selector_type::HSV_VALUE:
case color_single_selector_type::HSV_ALPHA:
color.getHsv (&h, &s, &v, &a);
break;
case color_single_selector_type::HSL_HUE:
case color_single_selector_type::HSL_SATURATION:
case color_single_selector_type::HSL_LIGHTNESS:
case color_single_selector_type::HSL_ALPHA:
color.getHsl (&h, &s, &l, &a);
break;
case color_single_selector_type::RGB_RED:
case color_single_selector_type::RGB_GREEN:
case color_single_selector_type::RGB_BLUE:
case color_single_selector_type::RGB_ALPHA:
color.getRgb (&r, &g, &b, &a);
break;
case color_single_selector_type::CMYK_CYAN:
case color_single_selector_type::CMYK_MAGENTA:
case color_single_selector_type::CMYK_YELLOW:
case color_single_selector_type::CMYK_BLACK:
case color_single_selector_type::CMYK_ALPHA:
color.getCmyk (&c, &m, &y, &k, &a);
break;
}
if (value < 0)
value = 0;
if (value > get_param_maximum_by_type (type))
value = get_param_maximum_by_type (type);
if (h < 0)
h = 0;
switch (type)
{
case color_single_selector_type::HSL_HUE:
color.setHsl (value, s, l, a);
break;
case color_single_selector_type::HSV_HUE:
color.setHsv (value, s, v, a);
break;
case color_single_selector_type::HSL_LIGHTNESS:
color.setHsl (h, s, value, a);
break;
case color_single_selector_type::HSL_SATURATION:
color.setHsl (h, value, l, a);
break;
case color_single_selector_type::HSV_SATURATION:
color.setHsv (h, value, v, a);
break;
case color_single_selector_type::HSV_VALUE:
color.setHsv (h, s, value, a);
break;
case color_single_selector_type::RGB_RED:
color.setRgb (value, g, b, a);
break;
case color_single_selector_type::RGB_GREEN:
color.setRgb (r, value, b, a);
break;
case color_single_selector_type::RGB_BLUE:
color.setRgb (r, g, value, a);
break;
case color_single_selector_type::RGB_ALPHA:
color.setRgb (r, g, b, value);
break;
case color_single_selector_type::CMYK_CYAN:
color.setCmyk (value, m, y, k, a);
break;
case color_single_selector_type::CMYK_MAGENTA:
color.setCmyk (c, value, y, k, a);
break;
case color_single_selector_type::CMYK_YELLOW:
color.setCmyk (c, m, value, k, a);
break;
case color_single_selector_type::CMYK_BLACK:
color.setCmyk (c, m, y, value, a);
break;
case color_single_selector_type::HSL_ALPHA:
color.setHsl (h, s, l, value);
break;
case color_single_selector_type::HSV_ALPHA:
color.setHsv (h, s, v, value);
break;
case color_single_selector_type::CMYK_ALPHA:
color.setCmyk (c, m, y, k, value);
break;
}
return color;
}
示例13: parseColor
QColor parseColor(ColorFormat format, const QRegularExpressionMatch &match)
{
QColor ret;
if (format == ColorFormat::QCssRgbUCharFormat) {
int r = match.captured(1).toInt();
int g = match.captured(2).toInt();
int b = match.captured(3).toInt();
ret.setRgb(r, g, b);
QString possibleAlpha = match.captured(4);
if (!possibleAlpha.isNull()) {
qreal a = possibleAlpha.toDouble();
ret.setAlphaF(a);
}
}
if (format == ColorFormat::QCssRgbPercentFormat) {
qreal r = match.captured(1).remove(QChar::fromLatin1('%')).toDouble() / 100;
qreal g = match.captured(2).remove(QChar::fromLatin1('%')).toDouble() / 100;
qreal b = match.captured(3).remove(QChar::fromLatin1('%')).toDouble() / 100;
ret.setRgbF(r, g, b);
QString possibleAlpha = match.captured(4);
if (!possibleAlpha.isNull()) {
qreal a = possibleAlpha.toDouble();
ret.setAlphaF(a);
}
}
else if (format == ColorFormat::QssHsvFormat) {
int h = match.captured(1).toInt();
int s = match.captured(2).toInt();
int v = match.captured(3).toInt();
ret.setHsv(h, s, v);
QString possibleAlpha = match.captured(4);
if (!possibleAlpha.isNull()) {
qreal a = possibleAlpha.remove(QChar::fromLatin1('%')).toDouble() / 100;
ret.setAlphaF(a);
}
}
else if (format == ColorFormat::CssHslFormat) {
int h = match.captured(1).toInt();
int s = match.captured(2).remove(QChar::fromLatin1('%')).toInt() * 255 / 100;
int l = match.captured(3).remove(QChar::fromLatin1('%')).toInt() * 255 / 100;
ret.setHsl(h, s, l);
QString possibleAlpha = match.captured(4);
if (!possibleAlpha.isNull()) {
qreal a = possibleAlpha.toDouble();
ret.setAlphaF(a);
}
}
else if (format == ColorFormat::QmlRgbaFormat) {
qreal r = match.captured(1).toDouble();
qreal g = match.captured(2).toDouble();
qreal b = match.captured(3).toDouble();
qreal a = match.captured(4).toDouble();
ret.setRgbF(r, g, b, a);
}
else if (format == ColorFormat::QmlHslaFormat) {
qreal h = match.captured(1).toDouble();
qreal s = match.captured(2).toDouble();
qreal l = match.captured(3).toDouble();
qreal a = match.captured(4).toDouble();
ret.setHslF(h, s, l, a);
}
else if (format == ColorFormat::GlslFormat) {
qreal r = match.captured(1).toDouble();
qreal g = match.captured(2).toDouble();
qreal b = match.captured(3).toDouble();
ret.setRgbF(r, g, b);
QString possibleAlpha = match.captured(4);
if (!possibleAlpha.isNull()) {
qreal a = possibleAlpha.toDouble();
ret.setAlphaF(a);
}
}
else if (format == ColorFormat::HexFormat) {
ret.setNamedColor(match.captured());
}
Q_ASSERT_X(ret.isValid(), Q_FUNC_INFO, "The color cannot be invalid.");
return ret;
}
示例14: filterImage
//.........这里部分代码省略.........
result.setPixel(x, y, qRgba(r, g, b, qAlpha(pixel)));
}
}
}
} else if (filter == tr("Làm ấm")) {
// Nếu filter là "Làm ấm" thì bật QInputDialog lên cho người dùng
// nhập vào giá trị, giá trị này trong khoảng 1 đến 255
bool ok; // Kiểm tra giá trị nhập
int delta = QInputDialog::getInt(parent, tr("Lầm ấm"),
tr("Nhập mức độ ấm:"),
10, 1, 255, 1, &ok);
// Hình sẽ trong ấm hơn nếu ta tăng độ vàng của ảnh, và màu vàng được
// tổng hợp từ màu đỏ và xanh lục trong kênh màu RGB
if (ok) {
int r, g, b;
for (int x = 0; x < original.width(); x++) {
for (int y = 0; y < original.height(); y++) {
int pixel = original.pixel(x, y);
r = qRed(pixel) + delta;
g = qGreen(pixel) + delta;
b = qBlue(pixel);
//Ta kiểm tra các giá trị mới trong khoảng cho phép.
r = qBound(0, r, 255);
g = qBound(0, g, 255);
result.setPixel(x, y, qRgba(r, g, b, qAlpha(pixel)));
}
}
}
} else if (filter == tr("Làm mát...")) {
// Nếu filter là "Làm mát" thì bật QInputDialog lên cho người dùng
// nhập vào giá trị, giá trị này trong khoảng 1 đến 255
bool ok; // Kiểm tra giá trị nhập
int delta = QInputDialog::getInt(parent, tr("Lầm mát"),
tr("Nhập mức độ mát:"),
10, 1, 256, 1, &ok);
// Hình sẽ có cảm giác mát hơn khi ta tăng giá trị kênh màu xanh lam
if (ok) {
int r, g, b;
for (int x = 0; x < original.width(); x++) {
for (int y = 0; y < original.height(); y++) {
int pixel = original.pixel(x, y);
r = qRed(pixel);
g = qGreen(pixel);
b = qBlue(pixel) + delta;
//Ta kiểm tra giá trị mới trong khoảng cho phép.
b = qBound(0, b, 255);
result.setPixel(x, y, qRgba(r, g, b, qAlpha(pixel)));
}
}
}
} else if (filter == tr("Độ bão hòa")) {
// Nếu filter là "Độ bão hòa" thì bật QInputDialog lên cho người dùng
// nhập vào giá trị, giá trị này trong khoảng -255 đến 255
bool ok; // Kiểm tra giá trị nhập vào
int delta = QInputDialog::getInt(parent, tr("Độ bão hòa"),
tr("Nhập độ bão hòa:"),
10, -255, 255, 1, &ok);
QColor newClolor;
QColor oldColor;
int h, s, l;
// Ta chuyển hình về kênh màu HSL rồi sau đó tăng hoặc giảm kênh
// saturation để tăng hoặc giảm độ bão hòa sau đó lại chuyển ảnh về RGB
if (ok) {
for (int y = 0; y < original.height(); ++y) {
for (int x = 0; x < original.width(); ++x) {
oldColor = QColor(original.pixel(x, y));
newClolor = oldColor.toHsl();
h = newClolor.hue();
s = newClolor.saturation() + delta;
l = newClolor.lightness();
// Ta kiểm tra giá trị mới trong khoảng cho phép
s = qBound(0, s, 255);
newClolor.setHsl(h, s, l);
result.setPixel(x, y, qRgba(newClolor.red(),
newClolor.green(),
newClolor.blue(),
newClolor.alpha()));
}
}
}
}
return result;
}