本文整理汇总了C++中QColor::hslHue方法的典型用法代码示例。如果您正苦于以下问题:C++ QColor::hslHue方法的具体用法?C++ QColor::hslHue怎么用?C++ QColor::hslHue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QColor
的用法示例。
在下文中一共展示了QColor::hslHue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: achromaticHslHue
void tst_QColor::achromaticHslHue()
{
QColor color = Qt::black;
QColor hsl = color.toHsl();
QCOMPARE(hsl.hslHue(), -1);
}
示例2: sendColour
bool LIFXLightClient::sendColour()
{
LIFXPacket *packet = new LIFXPacket(LIFX_SET_LIGHT_COLOR);
memcpy(packet->header.target_mac_address, m_addressraw, sizeof(packet->header.target_mac_address));
LIFXSetLightColorPayload *payload = (LIFXSetLightColorPayload*)packet->payloaddata;
if(payload != NULL)
{
QColor color = QColor::fromRgb(red, green, blue);
//color.getHsl( *payload->hue, *payload->saturation, *payload->brightness);
payload->stream = 0;
payload->hue = color.hslHue() *275;
payload->saturation = color.hslSaturation()*257;
payload->brightness = color.lightness()*655.35;
payload->kelvin = kelvin;
payload->fade_time = fadetime;
((LIFXGatewayClient*)gatewayclient)->SendPacket(packet);
return true;
}
return false;
}
示例3: 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();
}
示例4: 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);
}
}
//.........这里部分代码省略.........
示例5: colorToString
QString colorToString(const QColor &color, ColorFormat format)
{
QString ret;
QString prefix;
QString colorComponents;
if (format == ColorFormat::QCssRgbUCharFormat) {
prefix = QLatin1String("rgb(");
colorComponents = QString::number(color.red()) + QLatin1String(", ")
+ QString::number(color.green()) + QLatin1String(", ")
+ QString::number(color.blue());
qreal alpha = color.alphaF();
if (alpha < 1.0) {
prefix.insert(3, QLatin1Char('a'));
colorComponents += QLatin1String(", ") + colorDoubleToQString(color.alphaF());
}
}
if (format == ColorFormat::QCssRgbPercentFormat) {
int rP = qRound(color.redF() * 100);
int gP = qRound(color.greenF() * 100);
int bP = qRound(color.blueF() * 100);
prefix = QLatin1String("rgb(");
colorComponents = QString::number(rP) + QChar::fromLatin1('%') + QLatin1String(", ")
+ QString::number(gP) + QChar::fromLatin1('%') + QLatin1String(", ")
+ QString::number(bP) + QChar::fromLatin1('%');
qreal alpha = color.alphaF();
if (alpha < 1.0) {
prefix.insert(3, QLatin1Char('a'));
colorComponents += QLatin1String(", ") + colorDoubleToQString(alpha);
}
}
else if (format == ColorFormat::QssHsvFormat) {
prefix = QLatin1String("hsv(");
colorComponents = QString::number(color.hsvHue()) + QLatin1String(", ")
+ QString::number(color.hsvSaturation()) + QLatin1String(", ")
+ QString::number(color.value());
int aP = qRound(color.alphaF() * 100);
if (aP < 100) {
prefix.insert(3, QLatin1Char('a'));
colorComponents += QLatin1String(", ") + colorDoubleToQString(aP);
}
}
else if (format == ColorFormat::CssHslFormat) {
prefix = QLatin1String("hsl(");
int sP = qRound(color.hslSaturationF() * 100);
int lP = qRound(color.lightnessF() * 100);
colorComponents = QString::number(color.hslHue()) + QLatin1String(", ")
+ QString::number(sP) + QChar::fromLatin1('%') + QLatin1String(", ")
+ QString::number(lP) + QChar::fromLatin1('%');
qreal alpha = color.alphaF();
if (alpha < 1.0) {
prefix.insert(3, QLatin1Char('a'));
colorComponents += QLatin1String(", ") + colorDoubleToQString(color.alphaF());
}
}
else if (format == ColorFormat::QmlRgbaFormat) {
prefix = QLatin1String("Qt.rgba(");
colorComponents = colorDoubleToQString(color.redF()) + QLatin1String(", ")
+ colorDoubleToQString(color.greenF()) + QLatin1String(", ")
+ colorDoubleToQString(color.blueF()) + QLatin1String(", ")
+ colorDoubleToQString(color.alphaF());
}
else if (format == ColorFormat::QmlHslaFormat) {
prefix = QLatin1String("Qt.hsla(");
colorComponents = colorDoubleToQString(color.hueF()) + QLatin1String(", ")
+ colorDoubleToQString(color.saturationF()) + QLatin1String(", ")
+ colorDoubleToQString(color.lightnessF()) + QLatin1String(", ")
+ colorDoubleToQString(color.alphaF());
}
else if (format == ColorFormat::GlslFormat) {
prefix = QLatin1String("vec");
colorComponents = colorDoubleToQString(color.redF()) + QLatin1String(", ")
+ colorDoubleToQString(color.greenF()) + QLatin1String(", ")
+ colorDoubleToQString(color.blueF());
qreal alpha = color.alphaF();
if (alpha < 1.0) {
prefix.append(QLatin1Char('4'));
colorComponents += QLatin1String(", ") + colorDoubleToQString(color.alphaF());
} else {
prefix.append(QLatin1Char('3'));
}
prefix.append(QLatin1Char('('));
}
else if (format == ColorFormat::HexFormat) {
prefix = QLatin1String("#");
int alpha = color.alpha();
//.........这里部分代码省略.........