Exemplo n.º 1
0
bool ContinuousColorRange::contains(const QVariant &v, bool inclusive) const
{
    QColor clr;
    if( v.type() == QVariant::Double){
        clr =  ColorRangeBase::toColor(v.toULongLong(),defaultColorModel());
    } else
        clr = v.value<QColor>();
    if ( !clr.isValid())
        return false;

    double component1a, component2a, component3a,component4a;
    double component1b, component2b, component3b,component4b;
    double component1c, component2c, component3c,component4c;
    QColor limit1,limit2;

    switch (defaultColorModel()) {
    case ColorRangeBase::cmRGBA :
    case ColorRangeBase::cmGREYSCALE:
        clr.getRgbF(&component1a, &component2a, &component3a);
        _limit1.getRgbF(&component1b, &component2b, &component3b);
        _limit2.getRgbF(&component1c, &component2c, &component3c);
        break;
    case ColorRangeBase::cmHSLA :
        clr.getHslF(&component1a, &component2a, &component3a);
        _limit1.getHslF(&component1b, &component2b, &component3b);
        _limit2.getHslF(&component1c, &component2c, &component3c);
        break;
    case ColorRangeBase::cmCYMKA:
        clr.getCmykF(&component1a, &component2a, &component3a,&component4a);
        limit1 = QColor(_limit1);
        limit2 = QColor(_limit2);
        limit1.getCmykF(&component1b, &component2b, &component3b, &component4b);
        limit2.getCmykF(&component1c, &component2c, &component3c, &component4c);
        break;
    default:
        break;
    }
    switch(defaultColorModel()){
    case ColorRangeBase::cmGREYSCALE:{
        bool isGrey = component1a == component2a && component1a == component3a;
        if (!isGrey)
            return false;
    }
    case ColorRangeBase::cmRGBA :
    case ColorRangeBase::cmHSLA :
        return component1a >= component1b && component1a <= component1c &&
                component2a >= component2b && component2a <= component2c &&
                component3a >= component3b && component3a <= component3c;
    case ColorRangeBase::cmCYMKA:
        return component1a >= component1b && component1a <= component1c &&
                component2a >= component2b && component2a <= component2c &&
                component3a >= component3b && component3a <= component3c &&
                component4a >= component4b && component4a <= component4c;
    default:
        break;

    }
    return false;

}
Exemplo n.º 2
0
QColor tintColor( const QColor & color, qreal tintfactor )
{
    QColor retColor;
    const qreal  nonTindedPart = 1.0 - tintfactor;
    qreal luminance = 0.0;
    qreal sat = 0.0;
    qreal hue = 0.0;
    color.getHslF( &hue, &sat, &luminance );
    luminance = luminance * tintfactor + nonTindedPart;
    retColor.setHslF( hue, sat, luminance );
//     const int tintedColor = 255 * nonTindedPart;
//     retColor.setRed( tintedColor + tintfactor * color.red() );
//     retColor.setGreen( tintedColor + tintfactor * color.green() );
//     retColor.setBlue( tintedColor + tintfactor * color.blue() );
    return retColor;
}
Exemplo n.º 3
0
TagWidget::TagWidget(QWidget *parent) : GroupedLineEdit(parent), m_completer(NULL)
{
	connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(reparse()));
	connect(this, SIGNAL(textChanged()), this, SLOT(reparse()));

	QColor textColor = palette().color(QPalette::Text);
	qreal h, s, l, a;
	textColor.getHslF(&h, &s, &l, &a);
	// I use dark themes
	if (l <= 0.3) { // very dark text. get a brigth background
		addColor(QColor(Qt::red).lighter(120));
		addColor(QColor(Qt::green).lighter(120));
		addColor(QColor(Qt::blue).lighter(120));
	} else if (l <= 0.6) { // moderated dark text. get a somewhat brigth background
		addColor(QColor(Qt::red).lighter(60));
		addColor(QColor(Qt::green).lighter(60));
		addColor(QColor(Qt::blue).lighter(60));
	} else {
		addColor(QColor(Qt::red).darker(120));
		addColor(QColor(Qt::green).darker(120));
		addColor(QColor(Qt::blue).darker(120));
	} // light text. get a dark background.
	setFocusPolicy(Qt::StrongFocus);
}
Exemplo n.º 4
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);
        }
    }
}