Exemplo n.º 1
0
void KTColorPalette::setColor(const QBrush& brush)
{
	QColor color = brush.color();
	
	if(color.isValid())
	{
		if(m_type == Gradient)
		{
			m_gradientManager->setCurrentColor(color);
		}
		if(m_displayValueColor && m_outlineAndFillColors && m_colorPicker && m_nameColor && m_luminancePicker)
		{
			
			
			m_colorPicker->setCol(color.hue(), color.saturation ());
			if(m_type == Solid)
			{
				m_outlineAndFillColors->setCurrentColor(color);
			}
			m_nameColor->setText(color.name ());
			m_luminancePicker->setCol(color.hue(), color.saturation(), color.value());
			m_containerPalette->setColor( brush );
			m_displayValueColor->setColor(color);
		}
		
	}
	else if(brush.gradient())
	{
		
		QGradient gradient(*brush.gradient());
		changeBrushType(tr("Gradient"));

		m_containerPalette->setColor(gradient);
		m_outlineAndFillColors->setCurrentColor(gradient);
		if( sender () != m_gradientManager )
		{
			m_gradientManager->setGradient(gradient);
		}
		
	}
	emit brushChanged( m_outlineAndFillColors->foreground(),m_outlineAndFillColors->background() );
	
}
Exemplo n.º 2
0
QString HrZones::summarize(int rnum, QVector<double> &time_in_zone) const
{
    assert(rnum < ranges.size());
    const HrZoneRange &range = ranges[rnum];
    if (time_in_zone.size() < range.zones.size()) return "";
    QString summary;
    if(range.lt > 0){
        summary += "<table align=\"center\" width=\"70%\" border=\"0\">";
        summary += "<tr><td align=\"center\">";
        summary += tr("Threshold (bpm): %1").arg(range.lt);
        summary += "</td></tr></table>";
    }
    summary += "<table align=\"center\" width=\"70%\" ";
    summary += "border=\"0\">";
    summary += "<tr>";
    summary += tr("<td align=\"center\">Zone</td>");
    summary += tr("<td align=\"center\">Description</td>");
    summary += tr("<td align=\"center\">Low (bpm)</td>");
    summary += tr("<td align=\"center\">High (bpm)</td>");
    summary += tr("<td align=\"center\">Time</td>");
    summary += tr("<td align=\"center\">%</td>");
    summary += "</tr>";
    QColor color = QApplication::palette().alternateBase().color();
    color = QColor::fromHsv(color.hue(), color.saturation() * 2, color.value());

    double duration = 0;
    foreach(double v, time_in_zone) { duration += v; }

    for (int zone = 0; zone < time_in_zone.size(); ++zone) {
        if (time_in_zone[zone] > 0.0) {
            QString name, desc;
            int lo, hi;
            double trimp;
            zoneInfo(rnum, zone, name, desc, lo, hi, trimp);
            if (zone % 2 == 0)
                summary += "<tr bgcolor='" + color.name() + "'>";
            else
                summary += "<tr>";
            summary += QString("<td align=\"center\">%1</td>").arg(name);
            summary += QString("<td align=\"center\">%1</td>").arg(desc);
            summary += QString("<td align=\"center\">%1</td>").arg(lo);
            if (hi == INT_MAX)
                summary += "<td align=\"center\">MAX</td>";
            else
                summary += QString("<td align=\"center\">%1</td>").arg(hi);
            summary += QString("<td align=\"center\">%1</td>")
                .arg(time_to_string((unsigned) round(time_in_zone[zone])));
            summary += QString("<td align=\"center\">%1</td>")
                .arg((double)time_in_zone[zone]/duration * 100, 0, 'f', 0);
            summary += "</tr>";
        }
    }
    summary += "</table>";
    return summary;
}
Exemplo n.º 3
0
void ColorWheel::setColor(const QColor &color)
{
    if (color == m_currentColor)
    {
        return;
    }
    if (color.hue() != m_currentColor.hue())
    {
        hueChanged(color.hue());
    }

    if (color.saturation() != m_currentColor.saturation() ||
        color.value() != m_currentColor.value() )
    {
        svChanged(color);
    }

    update();
    emit colorSelected(color);
}
Exemplo n.º 4
0
QPixmap
IconLoader::loadPixmap(QString name)
{
    QColor bg = QApplication::palette().window().color();
    if (bg.red() + bg.green() + bg.blue() > 384) { // light background
        QPixmap pmap(QString(":icons/%1").arg(name));
        if (pmap.isNull()) {
            pmap = QPixmap(QString(":icons/%1.png").arg(name));
        }
        return pmap;
    }

    QPixmap pmap(QString(":icons/%1").arg(name));
    if (pmap.isNull()) {
        pmap = QPixmap(QString(":icons/%1_inverse.png").arg(name));
        if (pmap.isNull()) {
            pmap = QPixmap(QString(":icons/%1.png").arg(name));
        }
    }
    if (pmap.isNull()) return pmap;

    for (int i = 0; i < sizeof(autoInvertExceptions)/
                        sizeof(autoInvertExceptions[0]); ++i) {
        if (autoInvertExceptions[i] == name) {
            return pmap;
        }
    }

    // No suitable inverted icon found for black background; try to
    // auto-invert the default one

    QImage img = pmap.toImage().convertToFormat(QImage::Format_ARGB32);

    for (int y = 0; y < img.height(); ++y) {
        for (int x = 0; x < img.width(); ++x) {

            QRgb rgba = img.pixel(x, y);
            QColor colour = QColor
                (qRed(rgba), qGreen(rgba), qBlue(rgba), qAlpha(rgba));

            int alpha = colour.alpha();
            if (colour.saturation() < 5 && colour.alpha() > 10) {
                colour.setHsv(colour.hue(),
                              colour.saturation(),
                              255 - colour.value());
                colour.setAlpha(alpha);
                img.setPixel(x, y, colour.rgba());
            }
        }
    }

    pmap = QPixmap::fromImage(img);
    return pmap;
}
Exemplo n.º 5
0
void ColorWheel::mousePressEvent(QMouseEvent *event)
{
    lastPos = event->pos();
    if(wheelRegion.contains(lastPos)){
        inWheel = true;
        QColor color = posColor(lastPos);
        hueChanged(color.hue());
    }

    mouseDown = true;
}
Exemplo n.º 6
0
void HueSatSelector::setSelectedIndex(QColor c)
{
	if (value != c.value())
	{
		value = c.value();
		for (int i = 0 ; i < 360 ; i++)
			for (int j = 0 ; j < 256 ; j++)
				background.setPixel(i, j, QColor::fromHsv(i, j, value).rgb());
	}
	ColorSelector::setSelectedIndex(QPoint(c.hue(),c.saturation()));
}
Exemplo n.º 7
0
void Group::setColor(const QColor &color)
{
    // Transform from RGB to Hue/Sat
    quint16 hue = color.hue() * 65535 / 360;
    quint8 sat = color.saturation();

    // Transform from RGB to XYZ
    QGenericMatrix<3, 3, qreal> rgb2xyzMatrix;
    rgb2xyzMatrix(0, 0) = 0.412453;    rgb2xyzMatrix(0, 1) = 0.357580;    rgb2xyzMatrix(0, 2) = 0.180423;
    rgb2xyzMatrix(1, 0) = 0.212671;    rgb2xyzMatrix(1, 1) = 0.715160;    rgb2xyzMatrix(1, 2) = 0.072169;
    rgb2xyzMatrix(2, 0) = 0.019334;    rgb2xyzMatrix(2, 1) = 0.119193;    rgb2xyzMatrix(2, 2) = 0.950227;

    QGenericMatrix<1, 3, qreal> rgbMatrix;
    rgbMatrix(0, 0) = 1.0 * color.red() / 255;
    rgbMatrix(1, 0) = 1.0 * color.green() / 255;
    rgbMatrix(2, 0) = 1.0 * color.blue() / 255;

    QGenericMatrix<1, 3, qreal> xyzMatrix = rgb2xyzMatrix * rgbMatrix;

    // transform from XYZ to CIELUV u' and v'
    qreal u = 4*xyzMatrix(0, 0) / (xyzMatrix(0, 0) + 15*xyzMatrix(1, 0) + 3*xyzMatrix(2, 0));
    qreal v = 9*xyzMatrix(1, 0) / (xyzMatrix(0, 0) + 15*xyzMatrix(1, 0) + 3*xyzMatrix(2, 0));

    // Transform from CIELUV to (x,y)
    qreal x = 27*u / (18*u - 48*v + 36);
    qreal y = 12*v / (18*u - 48*v + 36);

    qDebug() << "setting color" << color << x << y;
    if (m_busyStateChangeId == -1) {
        QVariantMap params;

        params.insert("hue", hue);
        params.insert("sat", sat);
        // FIXME: There is a bug in the API that it doesn't report back the set state of "sat"
        // Lets just assume it always succeeds
        m_sat = sat;

//        QVariantList xyList;
//        xyList << x << y;
//        params.insert("xy", xyList);


        params.insert("on", true);
        m_busyStateChangeId = HueBridgeConnection::instance()->put("groups/" + QString::number(m_id) + "/action", params, this, "setStateFinished");
        m_timeout.start();
    } else {
        m_dirtyHue = hue;
        m_hueDirty = true;
        m_dirtySat = sat;
        m_satDirty = true;
//        m_xyDirty = true;
//        m_dirtyXy = QPointF(x, y);
    }
}
Exemplo n.º 8
0
bool QgsColorButton::event( QEvent *e )
{
  if ( e->type() == QEvent::ToolTip )
  {
    QColor c = linkedProjectColor();
    bool isProjectColor = c.isValid();
    if ( !isProjectColor )
      c = mColor;

    QString name = c.name();
    int hue = c.hue();
    int value = c.value();
    int saturation = c.saturation();

    // create very large preview swatch
    int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 23 );
    int height = static_cast< int >( width / 1.61803398875 ); // golden ratio

    int margin = static_cast< int >( height * 0.1 );
    QImage icon = QImage( width + 2 * margin, height + 2 * margin, QImage::Format_ARGB32 );
    icon.fill( Qt::transparent );

    QPainter p;
    p.begin( &icon );

    //start with checkboard pattern
    QBrush checkBrush = QBrush( transparentBackground() );
    p.setPen( Qt::NoPen );
    p.setBrush( checkBrush );
    p.drawRect( margin, margin, width, height );

    //draw color over pattern
    p.setBrush( QBrush( c ) );

    //draw border
    p.setPen( QColor( 197, 197, 197 ) );
    p.drawRect( margin, margin, width, height );
    p.end();

    QByteArray data;
    QBuffer buffer( &data );
    icon.save( &buffer, "PNG", 100 );

    QString info = ( isProjectColor ? QStringLiteral( "<p>%1: %2</p>" ).arg( tr( "Linked color" ), mLinkedColorName ) : QString() )
                   + QStringLiteral( "<b>HEX</b> %1<br>"
                                     "<b>RGB</b> %2<br>"
                                     "<b>HSV</b> %3,%4,%5<p>"
                                     "<img src='data:image/png;base64, %0'>" ).arg( QString( data.toBase64() ), name,
                                         QgsSymbolLayerUtils::encodeColor( c ) )
                   .arg( hue ).arg( saturation ).arg( value );
    setToolTip( info );
  }
  return QToolButton::event( e );
}
Exemplo n.º 9
0
void ContinuousColorRange::add(const QVariant &v)
{
    if ( contains(v))
        return;
    QColor clr = toColor(v, defaultColorModel());
    if ( !clr.isValid())
        return;
    if ( defaultColorModel() == ColorRangeBase::cmRGBA){
        _limit1.setRed(std::min(_limit1.red(), clr.red()));
        _limit1.setGreen(std::min(_limit1.green(), clr.green()));
        _limit1.setBlue(std::min(_limit1.blue(), clr.blue()));
        _limit1.setAlpha(std::min(_limit1.alpha(), clr.alpha()));
        _limit2.setRed(std::max(_limit2.red(), clr.red()));
        _limit2.setGreen(std::max(_limit2.green(), clr.green()));
        _limit2.setBlue(std::max(_limit2.blue(), clr.blue()));
        _limit2.setAlpha(std::max(_limit2.alpha(), clr.alpha()));
    }else if (defaultColorModel() == ColorRangeBase::cmHSLA) {
        _limit1.setHsl(std::min(_limit1.hue(), clr.hue()),
                       std::min(_limit1.saturation(), clr.saturation()),
                       std::min(_limit1.lightness(), clr.lightness()));
        _limit1.setAlpha(std::min(_limit1.alpha(), clr.alpha()));
        _limit2.setHsl(std::max(_limit2.hue(), clr.hue()),
                       std::max(_limit2.saturation(), clr.saturation()),
                       std::max(_limit2.lightness(), clr.lightness()));
        _limit2.setAlpha(std::max(_limit2.alpha(), clr.alpha()));
    }
    else if ( defaultColorModel() == ColorRangeBase::cmCYMKA){
        _limit1.setCmyk(std::min(_limit1.cyan(), clr.cyan()),
                        std::min(_limit1.magenta(), clr.magenta()),
                        std::min(_limit1.yellow(), clr.yellow()),
                        std::min(_limit1.black(), clr.black()));
        _limit1.setAlpha(std::min(_limit1.alpha(), clr.alpha()));
        _limit2.setCmyk(std::max(_limit2.cyan(), clr.cyan()),
                        std::max(_limit2.magenta(), clr.magenta()),
                        std::max(_limit2.yellow(), clr.yellow()),
                        std::max(_limit2.black(), clr.black()));
        _limit2.setAlpha(std::max(_limit2.alpha(), clr.alpha()));

    }

}
Exemplo n.º 10
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();
}
Exemplo n.º 11
0
void QgsColorWidget::setColor( const QColor &color, const bool emitSignals )
{
  if ( color == mCurrentColor )
  {
    return;
  }

  mCurrentColor = color;

  //update recorded hue
  if ( color.hue() >= 0 )
  {
    mExplicitHue = color.hue();
  }

  if ( emitSignals )
  {
    emit colorChanged( mCurrentColor );
  }

  update();
}
Exemplo n.º 12
0
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();
}
Exemplo n.º 13
0
void NQColorWheel::setColor(const QColor &color)
{
    int h = color.hue();
    int s = color.saturation();
    int v = color.value();

    currentColor_.setHsv(h, s, v);

    if (!isVisible()) return;

    initializeSquare(h);

    repaint();
}
Exemplo n.º 14
0
// We try to ensure that the actual color used are within
// reasonalbe bounds while generating the actual baseColor
// from the users request.
void StyleHelper::setBaseColor(const QColor& newcolor) {
  m_requestedBaseColor = newcolor;

  QColor color;
  color.setHsv(newcolor.hue(), newcolor.saturation() * 0.7,
               64 + newcolor.value() / 3);

  if (color.isValid() && color != m_baseColor) {
    m_baseColor = color;
    for (QWidget* w : QApplication::topLevelWidgets()) {
      w->update();
    }
  }
}
Exemplo n.º 15
0
void ColorWheel::mouseMoveEvent(QMouseEvent *event)
{
    QColor color;
    lastPos = event->pos();
    if( !pressDown ) return;
    if(wheelRegion.contains(lastPos) && selectedWheel){
        color = colorPosition(lastPos);
        onHueChanged(color.hue());
    }else if(squareRegion.contains(lastPos) && selected){
        color = colorPosition(lastPos);
        onSVChanged(color);
    }else{
    }
}
Exemplo n.º 16
0
QString Zones::summarize(int rnum, QVector<double> &time_in_zone) const
{
    assert(rnum < ranges.size());
    ZoneRange *range = ranges[rnum];
    assert(time_in_zone.size() == range->zones.size());
    QString summary;
    if(range->cp > 0){
        summary += "<table align=\"center\" width=\"70%\" border=\"0\">";
        summary += "<tr><td align=\"center\">";
        summary += tr("Critical Power: %1").arg(range->cp);
        summary += "</td></tr></table>";
    }
    summary += "<table align=\"center\" width=\"70%\" ";
    summary += "border=\"0\">";
    summary += "<tr>";
    summary += "<td align=\"center\">Zone</td>";
    summary += "<td align=\"center\">Description</td>";
    summary += "<td align=\"center\">Low</td>";
    summary += "<td align=\"center\">High</td>";
    summary += "<td align=\"center\">Time</td>";
    summary += "</tr>";
    QColor color = QApplication::palette().alternateBase().color();
    color = QColor::fromHsv(color.hue(), color.saturation() * 2, color.value());
    for (int zone = 0; zone < time_in_zone.size(); ++zone) {
        if (time_in_zone[zone] > 0.0) {
            QString name, desc;
            int lo, hi;
            zoneInfo(rnum, zone, name, desc, lo, hi);
            if (zone % 2 == 0)
                summary += "<tr bgcolor='" + color.name() + "'>";
            else
                summary += "<tr>";
            summary += QString("<td align=\"center\">%1</td>").arg(name);
            summary += QString("<td align=\"center\">%1</td>").arg(desc);
            summary += QString("<td align=\"center\">%1</td>").arg(lo);
            if (hi == INT_MAX)
                summary += "<td align=\"center\">MAX</td>";
            else
                summary += QString("<td align=\"center\">%1</td>").arg(hi);
            summary += QString("<td align=\"center\">%1</td>")
                .arg(time_to_string((unsigned) round(time_in_zone[zone])));
            summary += "</tr>";
        }
    }
    summary += "</table>";
    return summary;
}
Exemplo n.º 17
0
void ColorModelView::setValue(const QColor &col)
{
    if (col == value_) {
        return;
    }

    if (col.hue() != value_.hue()) {
        // invalidate color model image
        mainImage_ = QPixmap();
    }

    value_ = col;


    update();
    emit valueChanged(col);
}
Exemplo n.º 18
0
void ColorWheel::mousePressEvent(QMouseEvent *event)
{
    QColor color;
    lastPos = event->pos();
    if(wheelRegion.contains(lastPos)){
        selectedWheel = true;
        selected = false;
        color = colorPosition(lastPos);
        onHueChanged(color.hue());
    }else if(squareRegion.contains(lastPos)){
        selectedWheel = false;
        selected = true;
        color = colorPosition(lastPos);
        onSVChanged(color);
    }
    pressDown = true;
}
Exemplo n.º 19
0
void NQColorWheel::mousePressEvent(QMouseEvent *event)
{
    lastPosition_ = event->pos();

    if (regionWheel_.contains(lastPosition_)) {
        insideWheel_ = true;
        insideSquare_ = false;
        QColor color = colorFromPosition(lastPosition_);
        hueChanged(color.hue());
    } else if (regionSquare_.contains(lastPosition_)) {
        insideWheel_ = false;
        insideSquare_ = true;
        QColor color = colorFromPosition(lastPosition_);
        svChanged(color);
    }

    mousePressed_ = true;
}
Exemplo n.º 20
0
void ColorRangeBase::storeColor(const QColor& clr, QDataStream &stream)
{
    switch (defaultColorModel()){
    case ColorRangeBase::cmRGBA:
        stream << clr.red() << clr.green() << clr.blue() << clr.alpha();
        break;
    case ColorRangeBase::cmHSLA:
        stream << clr.hue() << clr.saturation() << clr.lightness() << clr.alpha();
        break;
    case ColorRangeBase::cmCYMKA:
        stream << clr.yellow() << clr.magenta() << clr.cyan() << clr.black();
        break;
    case ColorRangeBase::cmGREYSCALE:
        stream << clr.red();
    default:
        break;
    }
}
Exemplo n.º 21
0
void ColorWheel::mousePressEvent(QMouseEvent *event)
{
    QPoint lastPos = event->pos();
    if (m_squareRegion.contains(lastPos))
    {
        m_isInWheel = false;
        m_isInSquare = true;
        QColor color = pickColor(lastPos);
        svChanged(color);
    }
    else if (m_wheelRegion.contains(lastPos))
    {
        m_isInWheel = true;
        m_isInSquare = false;
        QColor color = pickColor(lastPos);
        hueChanged(color.hue());
    }
}
Exemplo n.º 22
0
void ColorWheel::mousePressEvent(QMouseEvent* e) {
    lastPos_ = e->pos();

    if (wheelRegion_.contains(lastPos_)) {
        inWheel_ = true;
        inSquare_ = false;
        QColor color = posColor(lastPos_);

        if (e->button()==Qt::RightButton) hueChanged(color.hue());
        else setColor(color);
    } else if (squareRegion_.contains(lastPos_)) {
        inWheel_ = false;
        inSquare_ = true;
        QColor color = posColor(lastPos_);
        svChanged(color);
    }

    mouseDown_ = true;
}
Exemplo n.º 23
0
void ColorWheel::mousePressEvent(QMouseEvent *event)
{
    QPoint lastPos = event->pos();
    if (mSquareRect.contains(lastPos))
    {
        mIsInWheel = false;
        mIsInSquare = true;
        QColor color = pickColor(lastPos);
        saturationChanged(color.saturation());
        valueChanged(color.value());

    }
    else if (mWheelRect.contains(lastPos))
    {
        mIsInWheel = true;
        mIsInSquare = false;
        QColor color = pickColor(lastPos);
        hueChanged(color.hue());
    }
}
Exemplo n.º 24
0
		Transformation Transformation::createColor(QString color) {

			Transformation t;

			if (color.toLower() != "random") {
				QColor c(color);
				QColor hsv = c.toHsv();
				t.deltaH = hsv.hue();
				t.scaleAlpha = hsv.alpha()/255.0;
				t.scaleS = hsv.saturation()/255.0;
				t.scaleV = hsv.value()/255.0;
				t.absoluteColor = true;
			} else {
				t.deltaH = 1000;
				t.absoluteColor = true;
			}

			//Debug(QString("Abs Color: %1, %2, %3, %4").arg(t.deltaH).arg(t.scaleS).arg(t.scaleV).arg(t.scaleAlpha));

			return t;
		}
//----------------------------------------------------------------------------
// 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
Exemplo n.º 26
0
void ColorWheel::mouseMoveEvent(QMouseEvent* event)
{
    QPoint lastPos = event->pos();
    if ( event->buttons() == Qt::NoButton )
    {
        return;
    }
    if (m_isInSquare)
    {
        QRect rect = m_squareRegion.boundingRect();

        if ( lastPos.x() < rect.topLeft().x() )
        {
            lastPos.setX( rect.topLeft().x() );
        }
        else if ( lastPos.x() > rect.bottomRight().x() )
        {
            lastPos.setX( rect.bottomRight().x() );
        }

        if ( lastPos.y() < rect.topLeft().y() )
        {
            lastPos.setY( rect.topLeft().y() );
        }
        else if ( lastPos.y() > rect.bottomRight().y() )
        {
            lastPos.setY( rect.bottomRight().y() );
        }

        QColor color = pickColor(lastPos);
        svChanged(color);
    }
    else if (m_wheelRegion.contains(lastPos) && m_isInWheel)
    {
        QColor color = pickColor(lastPos);
        hueChanged(color.hue());
    }
}
Exemplo n.º 27
0
void Widget::ImgEqualization(QImage *srcImg, QImage *rsltImg, unsigned int *CDFMtx)
{
    int i,j;
    unsigned int CDFmin= (~0);
    int color;
    QColor tmpColor;

    for(i=0;i<hisSize;i++){
        if (CDFMtx[i]< CDFmin&&CDFMtx[i] !=0){
            CDFmin=CDFMtx[i];
        }
    }

    for(j=0;j<srcImg->height();j++){
        for(i=0;i<srcImg->width();i++){
            color = (CDFMtx[qGray(srcImg->pixel(i,j))]-CDFmin)*255/(srcImg->width()*srcImg->height()-CDFmin);
            tmpColor = srcImg->pixel(i,j);
            tmpColor.setHsv(tmpColor.hue(),tmpColor.saturation(),color);
            rsltImg->setPixel(i,j,qRgb(tmpColor.red(),tmpColor.green(),tmpColor.blue()));
        }
    }
    ui->toolButton_2->setIcon(QPixmap::fromImage(*rsltImg));
}
Exemplo n.º 28
0
void ColorWheel::mouseMoveEvent(QMouseEvent* event)
{
    QPoint lastPos = event->pos();
    if (event->buttons() == Qt::NoButton)
    {
        return;
    }
    if (mIsInSquare)
    {
        if (lastPos.x() < mSquareRect.topLeft().x())
        {
            lastPos.setX(mSquareRect.topLeft().x());
        }
        else if (lastPos.x() > mSquareRect.bottomRight().x())
        {
            lastPos.setX(mSquareRect.bottomRight().x());
        }

        if (lastPos.y() < mSquareRect.topLeft().y())
        {
            lastPos.setY(mSquareRect.topLeft().y());
        }
        else if (lastPos.y() > mSquareRect.bottomRight().y())
        {
            lastPos.setY(mSquareRect.bottomRight().y());
        }

        QColor color = pickColor(lastPos);
        saturationChanged(color.saturation());
        valueChanged(color.value());
    }
    else if (mWheelRect.contains(lastPos) && mIsInWheel)
    {
        QColor color = pickColor(lastPos);
        hueChanged(color.hue());
    }
}
Exemplo n.º 29
0
void QtGradientStopsControllerPrivate::slotChangeAlpha(const QColor &color)
{
    QtGradientStop *stop = m_model->currentStop();
    if (!stop)
        return;
    m_model->changeStop(stop, color);
    QList<QtGradientStop *> stops = m_model->selectedStops();
    QListIterator<QtGradientStop *> itStop(stops);
    while (itStop.hasNext()) {
        QtGradientStop *s = itStop.next();
        if (s != stop) {
            QColor c = s->color();
            if (m_ui->hsvRadioButton->isChecked()) {
                c.setHsvF(c.hueF(), c.saturationF(), c.valueF(), color.alphaF());
                int hue = c.hue();
                if (hue == 360 || hue == -1)
                    c.setHsvF(0.0, c.saturationF(), c.valueF(), c.alphaF());
            } else {
                c.setRgbF(c.redF(), c.greenF(), c.blueF(), color.alphaF());
            }
            m_model->changeStop(s, c);
        }
    }
}
Exemplo n.º 30
0
void ColorBox::setColor(const QColor& color)
{
	_updating = true;
	_ui->red->setFirstColor(QColor(0, color.green(), color.blue()));
	_ui->red->setLastColor(QColor(255, color.green(), color.blue()));
	_ui->red->setValue(color.red());
	_ui->redbox->setValue(color.red());

	_ui->green->setFirstColor(QColor(color.red(), 0, color.blue()));
	_ui->green->setLastColor(QColor(color.red(), 255, color.blue()));
	_ui->green->setValue(color.green());
	_ui->greenbox->setValue(color.green());

	_ui->blue->setFirstColor(QColor(color.red(), color.green(), 0));
	_ui->blue->setLastColor(QColor(color.red(), color.green(), 255));
	_ui->blue->setValue(color.blue());
	_ui->bluebox->setValue(color.blue());


	_ui->hue->setColorSaturation(color.saturationF());
	_ui->hue->setColorValue(color.valueF());
	_ui->hue->setValue(color.hue());
	_ui->huebox->setValue(color.hue());

	_ui->saturation->setFirstColor(QColor::fromHsv(color.hue(), 0, color.value()));
	_ui->saturation->setLastColor(QColor::fromHsv(color.hue(), 255, color.value()));
	_ui->saturation->setValue(color.saturation());
	_ui->saturationbox->setValue(color.saturation());

	_ui->value->setFirstColor(QColor::fromHsv(color.hue(), color.saturation(), 0));
	_ui->value->setLastColor(QColor::fromHsv(color.hue(), color.saturation(), 255));
	_ui->value->setValue(color.value());
	_ui->valuebox->setValue(color.value());

	_ui->colorwheel->setColor(color);
	_updating = false;
}