コード例 #1
0
ファイル: quiddiards.cpp プロジェクト: silencious/Quiddiards
void Quiddiards::perlin(QImage& image, QColor rgb, float factor){
	QColor hsv(rgb.toHsv());
	qreal value = hsv.valueF();
	const int rows = 64, cols = 64, octave = 7;
	float wNoise[rows][cols], pNoise[rows*octave][cols*octave];
	for (int i = 0; i < rows; i++){
		for (int j = 0; j < cols; j++){
			wNoise[i][j] = randf(factor, 1);
		}
	}
	image = QImage(rows*octave, cols*octave, QImage::Format_RGB32);
	image.fill(hsv);

	float tTable[octave];
	for (int i = 0; i < octave; i++){
		float t = i / float(octave);
		tTable[i] = t*t*t*(t*(6 * t - 15) + 10);
	}
	for (int i = 0; i < rows*octave; i++){
		int y0 = i / octave, y1 = (y0 + 1) % rows;
		for (int j = 0; j < cols*octave; j++){
			int x0 = j / octave, x1 = (x0 + 1) % cols;
			hsv.setHsvF(hsv.hueF(), hsv.saturationF(), value*quadricInter(wNoise[x0][y0], wNoise[x1][y0], wNoise[x0][y1], wNoise[x1][y1], tTable[j%octave], tTable[i%octave]));
			QRgb rgb = hsv.rgb();
			image.setPixel(j, i, hsv.rgb());
		}
	}
}
コード例 #2
0
ファイル: theme.cpp プロジェクト: Stankim/dukto
float Theme::getSaturation(QString color) {

    QColor c;
    c.setNamedColor(color);
    QColor converted = c.toHsv();
    return converted.hsvSaturationF();
}
コード例 #3
0
ファイル: theme.cpp プロジェクト: Stankim/dukto
float Theme::getLightness(QString color) {

    QColor c;
    c.setNamedColor(color);
    QColor converted = c.toHsv();
    return converted.valueF();
}
コード例 #4
0
ファイル: theme.cpp プロジェクト: Stankim/dukto
float Theme::getHue(QString color) {

    QColor c;
    c.setNamedColor(color);
    QColor converted = c.toHsv();
    return converted.hsvHueF();
}
コード例 #5
0
// Make a color darker if it's too bright
QColor make_color_readable(QColor clr)
{
    // Gray
    if (clr.red() == clr.green() && clr.green() == clr.blue()) {
        return QColor("black");
    }
    clr = clr.toHsv();
    int value = MIN(clr.value(), 150);
    int saturation = 255;
    clr.setHsv(clr.hue(), saturation, value, 255);
    return clr.toRgb();
}
コード例 #6
0
ファイル: test.cpp プロジェクト: jpleclerc/Umbrello-ng2
QBrush Test::randomGradientBrush()
{
    QLinearGradient *gradient = new QLinearGradient();
    gradient->setCoordinateMode(QGradient::ObjectBoundingMode);

    int h, s, v;
    h = qrand() % 360;
    s = qrand() % 255;
    v = qrand() % 255;

    QColor colorBottom = QColor::fromHsv(h, s, v);

    colorBottom.toHsv().getHsv(&h, &s, &v);
    int diff = 50;
    if(v + diff <= 255) {
        v += diff;
    }
    else {
        v -= diff;
    }

    diff = 75;
    if(s + diff <= 255) {
        s += diff;
    }
    else {
        s -= diff;
    }
    QColor colorTop = QColor::fromHsv(h, s, v);
    gradient->setColorAt(0, colorTop);
    gradient->setColorAt(1, colorBottom);

    gradient->setStart(0, 0);
    gradient->setFinalStop(0, 1);

    QBrush retval(*gradient);
    delete gradient;
    return retval;
}
コード例 #7
0
ファイル: colorwheel.cpp プロジェクト: chchwy/pencil2d
void ColorWheel::setColor(QColor color)
{
    // this is a UI updating function, never emit any signals
    // and don't call any functions that will emit signals

    color = color.toHsv();

    if (color == mCurrentColor)
    {
        return;
    }

    if (color.hue() == -1) // grayscale color, keep the current hue
    {
        color.setHsv(mCurrentColor.hue(), color.saturation(), color.value(), color.alpha());
    }

    mCurrentColor = color;

    drawSquareImage(color.hue());
    update();
}
コード例 #8
0
//----------------------------------------------------------------------------
// Update Chart
//----------------------------------------------------------------------------
void ReportPieChart::updateChart()
{
    mModel->setRowCount( mDataList.size() );
    if( mDataList.size() > 0 )
    {
        // Sort data items
        switch( mSortType )
        {
        case SORT_BY_BALANCE_DESCENDING:
            qSort( mDataList.begin(), mDataList.end(), pieDataSortByBalanceDescending );
            break;
        case SORT_BY_NAME_ASCENDING:
            qSort( mDataList.begin(), mDataList.end(), pieDataSortByNameAscending );
            break;
        }

        const int colorRange = COLOR_RANGE;
        int step = qMin( MAX_COLOR_STEP, (colorRange / mDataList.size()) );
        QColor baseColor = BASE_COLOR.toHsv();
        int h = baseColor.hue();
        int s = baseColor.saturation();
        int v = baseColor.value();
        for (int i = 0; i < mDataList.size(); ++i)
        {
            QColor secondaryLabelColor = ( mDataList[i].mValue > 0 ) ? QColor(Qt::darkGreen) : QColor(Qt::red);
            QColor nextColor;
            int newH = (h + step*i)%colorRange;
            nextColor.setHsv( newH, s, v );
            QString valueStr = Transaction::getAmountText( mDataList[i].mValue );
            mModel->setData( mModel->index(i,(int)PieView::COLUMN_LABEL), mDataList[i].mName );
            mModel->setData( mModel->index(i,(int)PieView::COLUMN_LABEL), nextColor, Qt::DecorationRole );
            mModel->setData( mModel->index(i,(int)PieView::COLUMN_VALUE), qAbs(mDataList[i].mValue) );
            mModel->setData( mModel->index(i,(int)PieView::COLUMN_SEC_LABEL), valueStr );
            mModel->setData( mModel->index(i,(int)PieView::COLUMN_SEC_LABEL), secondaryLabelColor, Qt::DecorationRole );
        }
    }
    updateViewport();
} // ReportPieChart::updateChart
コード例 #9
0
ファイル: tst_qcolor.cpp プロジェクト: KDE/android-qt
void tst_QColor::toHsvNonDestructive()
{
    QColor aColor = QColor::fromHsvF(0.11, 0.22, 0.33, 0.44);
    QCOMPARE(aColor, aColor.toHsv());
}
コード例 #10
0
QImage GradientLoader::drawGradient(const GradientList& data)
{
    if (data.isEmpty())
    {
        return QImage();
    }

    QPixmap pix(MAX_THUMB_SIZE, MAX_THUMB_SIZE / 2);
    pix.fill(Qt::white);

    QPainter p(&pix);
    p.setPen(QPen(Qt::transparent));
    p.setRenderHint(QPainter::Antialiasing, true);

    QLinearGradient grad(0.0, 0.0, 1.0, 0.0);
    grad.setCoordinateMode(QGradient::StretchToDeviceMode);

    foreach(const GradientData & gradient, data)
    {
        if (gradient.status != GradientData::Ok)
        {
            continue;
        }

        qreal start = gradient.startPoint + 0.01;
        qreal end   = gradient.endPoint;

        // do some basic range checks
        start = qMin(1.0, start);
        start = qMax(0.0, start);
        end   = qMin(1.0, end);
        end   = qMax(0.0, end);

        // check coloring mode
        if (gradient.coloringMode == GradientData::HSVclockwise ||
            gradient.coloringMode == GradientData::HSVcounterClockwise
           )
        {
            const int hue_range = 360;

            bool reverse        = (gradient.coloringMode == GradientData::HSVcounterClockwise);
            qreal stepping      = qAbs(end - start) / (qreal)hue_range;
            qreal pos           = reverse ? start : end;

            QColor col = QColor::fromRgbF(gradient.leftColorRed,
                                          gradient.leftColorGreen,
                                          gradient.leftColorBlue,
                                          gradient.leftColorAlpha);
            QColor hsv        = col.toHsv();
            qreal saturationF = hsv.saturationF();
            qreal valueF      = hsv.valueF();
            qreal alphaF      = hsv.alphaF();

            for (int h = 0.0; h < hue_range; ++h)
            {
                grad.setColorAt(pos, QColor::fromHsvF((qreal)h / hue_range,
                                                      saturationF,
                                                      valueF,
                                                      alphaF));

                if (reverse)
                {
                    pos += stepping;
                }
                else
                {
                    pos -= stepping;
                }
            }
        }
        else
        {
            grad.setColorAt(start, QColor::fromRgbF(gradient.leftColorRed,
                                                    gradient.leftColorGreen,
                                                    gradient.leftColorBlue,
                                                    gradient.leftColorAlpha));

            grad.setColorAt(end, QColor::fromRgbF(gradient.rightColorRed,
                                                  gradient.rightColorGreen,
                                                  gradient.rightColorBlue,
                                                  gradient.rightColorAlpha));
        }
    }

    p.fillRect(pix.rect(), QBrush(grad));
    p.end();

    return pix.toImage();
}
コード例 #11
0
ファイル: gradientline.cpp プロジェクト: CNOT/julia-studio
static inline QColor invertColor(const QColor color)
{
    QColor c = color.toHsv();
    c.setHsv(c.hue(), c.saturation(), 255 - c.value());
    return c;
}
コード例 #12
0
ファイル: colorinspector.cpp プロジェクト: chchwy/pencil2d
void ColorInspector::setColor(QColor newColor)
{
    // this is a UI update function, never emit any signals
    // grab the color from color manager, and then update itself, that's it.

    // compare under the same color spec
    newColor = (isRgbColors) ? newColor.toRgb() : newColor.toHsv();

    if (newColor == mCurrentColor)
    {
        return;
    }

    if(isRgbColors)
    {
        QSignalBlocker b1(ui->red_slider); 
        QSignalBlocker b2(ui->green_slider);
        QSignalBlocker b3(ui->blue_slider);
        QSignalBlocker b4(ui->alpha_slider);

        ui->red_slider->setRgb(newColor);
        ui->green_slider->setRgb(newColor);
        ui->blue_slider->setRgb(newColor);
        ui->alpha_slider->setRgb(newColor);

        QSignalBlocker b5(ui->RedspinBox);
        QSignalBlocker b6(ui->GreenspinBox);
        QSignalBlocker b7(ui->BluespinBox);
        QSignalBlocker b8(ui->AlphaspinBox);

        ui->RedspinBox->setValue(newColor.red());
        ui->GreenspinBox->setValue(newColor.green());
        ui->BluespinBox->setValue(newColor.blue());
        ui->AlphaspinBox->setValue(newColor.alpha());
    }
    else
    {
        QSignalBlocker b1(ui->red_slider);
        QSignalBlocker b2(ui->green_slider);
        QSignalBlocker b3(ui->blue_slider);
        QSignalBlocker b4(ui->alpha_slider);

        ui->red_slider->setHsv(newColor);
        ui->green_slider->setHsv(newColor);
        ui->blue_slider->setHsv(newColor);
        ui->alpha_slider->setHsv(newColor);

        QSignalBlocker b5(ui->RedspinBox);
        QSignalBlocker b6(ui->GreenspinBox);
        QSignalBlocker b7(ui->BluespinBox);
        QSignalBlocker b8(ui->AlphaspinBox);

        ui->RedspinBox->setValue(newColor.hsvHue());
        ui->GreenspinBox->setValue(qRound(newColor.hsvSaturation() / 2.55));
        ui->BluespinBox->setValue(qRound(newColor.value() / 2.55));
        ui->AlphaspinBox->setValue(qRound(newColor.alpha() / 2.55));
    }

    mCurrentColor = newColor;

    QPalette p1 = ui->colorWrapper->palette(), p2 = ui->color->palette();
    p1.setBrush(QPalette::Background, QBrush(QImage(":/background/checkerboard.png")));
    p2.setColor(QPalette::Background, mCurrentColor);
    ui->colorWrapper->setPalette(p1);
    ui->color->setPalette(p2);

    update();
}