예제 #1
0
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;
}
예제 #2
0
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();
}
예제 #3
0
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);
        }
    }
}