示例#1
0
void QwtPainter::drawColoredArc(QPainter *painter, const QRect &rect,
    int peak, int arc, int interval, const QColor &c1, const QColor &c2)
{
    int h1, s1, v1;
    int h2, s2, v2;

#if QT_VERSION < 0x040000
    c1.hsv(&h1, &s1, &v1);
    c2.hsv(&h2, &s2, &v2);
#else
    c1.getHsv(&h1, &s1, &v1);
    c2.getHsv(&h2, &s2, &v2);
#endif

    arc /= 2;
    for ( int angle = -arc; angle < arc; angle += interval)
    {
        double ratio;
        if ( angle >= 0 )
            ratio = 1.0 - angle / double(arc);
        else
            ratio = 1.0 + angle / double(arc);


        QColor c;
        c.setHsv( h1 + qRound(ratio * (h2 - h1)),
            s1 + qRound(ratio * (s2 - s1)),
            v1 + qRound(ratio * (v2 - v1)) );

        painter->setPen(QPen(c, painter->pen().width()));
        painter->drawArc(rect, (peak + angle) * 16, interval * 16);
    }
}
示例#2
0
bool KstColorSequence::colorsTooClose(const QColor& color, const QColor& badColor) {
  double r1, h1, f1, x1, y1, z1;
  double r2, h2, f2, x2, y2, z2;
  double dc;
  int sugH, sugS, sugV;
  int badH, badS, badV;

  // make sure that the new color is not close to badColor.
  // to do this imagine HSV as defining a cone.
  // The distance from the point of the cone is R = V / 255
  // Angle of rotational symetry is Theta = H * 2PI/360
  // The 2nd angle is phi = S*(PI/4)/255
  // a color is acceptable if |C1-C2|>dcMin

  color.getHsv(sugH,sugS,sugV);
  badColor.getHsv(badH, badS, badV);

  r1 = badV/255.0;
  h1 = badH*M_PI/180.0;
  f1 = badS*M_PI/4.0/255.0;
  x1 = r1*sin( h1 )*sin( f1 );
  y1 = r1*cos( h1 )*sin( f1 );
  z1 = r1*cos( f1 );
  r2 = sugV/255.0;
  h2 = sugH*M_PI/180.0;
  f2 = sugS*M_PI/4.0/255.0;
  x2 = r2*sin( h2 )*sin( f2 );
  y2 = r2*cos( h2 )*sin( f2 );
  z2 = r2*cos( f2 );
  dc = sqrt( ( x1-x2 )*( x1-x2 ) + ( y1-y2 )*( y1-y2 ) + ( z1-z2 )*( z1-z2 ) );

  return dc < 0.3;
}
bool KonqCombo::hasSufficientContrast(const QColor &c1, const QColor &c2)
{
    // Taken from khtml/misc/helper.cc
#define HUE_DISTANCE 40
#define CONTRAST_DISTANCE 10

    int h1, s1, v1, h2, s2, v2;
    int hdist = -CONTRAST_DISTANCE;
    c1.getHsv(&h1,&s1,&v1);
    c2.getHsv(&h2,&s2,&v2);
    if(h1!=-1 && h2!=-1) { // grey values have no hue
        hdist = qAbs(h1-h2);
        if (hdist > 180) hdist = 360-hdist;
        if (hdist < HUE_DISTANCE) {
            hdist -= HUE_DISTANCE;
            // see if they are high key or low key colours
            bool hk1 = h1>=45 && h1<=225;
            bool hk2 = h2>=45 && h2<=225;
            if (hk1 && hk2)
                hdist = (5*hdist)/3;
            else if (!hk1 && !hk2)
                hdist = (7*hdist)/4;
        }
        hdist = qMin(hdist, HUE_DISTANCE*2);
    }
    return hdist + (qAbs(s1-s2)*128)/(160+qMin(s1,s2)) + qAbs(v1-v2) > CONTRAST_DISTANCE;
}
示例#4
0
文件: helper.cpp 项目: KDE/khtml
/** checks whether the given colors have enough contrast
 * @returns @p true if contrast is ok.
 */
bool khtml::hasSufficientContrast(const QColor &c1, const QColor &c2)
{
// New version from Germain Garand, better suited for contrast measurement
#if 1

#define HUE_DISTANCE 40
#define CONTRAST_DISTANCE 10

    int h1, s1, v1, h2, s2, v2;
    int hdist = -CONTRAST_DISTANCE;
    c1.getHsv(&h1, &s1, &v1);
    c2.getHsv(&h2, &s2, &v2);
    if (h1 != -1 && h2 != -1) { // grey values have no hue
        hdist = qAbs(h1 - h2);
        if (hdist > 180) {
            hdist = 360 - hdist;
        }
        if (hdist < HUE_DISTANCE) {
            hdist -= HUE_DISTANCE;
            // see if they are high key or low key colours
            bool hk1 = h1 >= 45 && h1 <= 225;
            bool hk2 = h2 >= 45 && h2 <= 225;
            if (hk1 && hk2) {
                hdist = (5 * hdist) / 3;
            } else if (!hk1 && !hk2) {
                hdist = (7 * hdist) / 4;
            }
        }
        hdist = qMin(hdist, HUE_DISTANCE * 2);
    }
    return hdist + (qAbs(s1 - s2) * 128) / (160 + qMin(s1, s2)) + qAbs(v1 - v2) > CONTRAST_DISTANCE;

#undef CONTRAST_DISTANCE
#undef HUE_DISTANCE

#else   // orginal fast but primitive version by me (LS)

// ### arbitrary value, to be adapted if necessary (LS)
#define CONTRAST_DISTANCE 32

    if (qAbs(c1.Qt::red() - c2.Qt::red()) > CONTRAST_DISTANCE) {
        return true;
    }
    if (qAbs(c1.Qt::green() - c2.Qt::green()) > CONTRAST_DISTANCE) {
        return true;
    }
    if (qAbs(c1.Qt::blue() - c2.Qt::blue()) > CONTRAST_DISTANCE) {
        return true;
    }

    return false;

#undef CONTRAST_DISTANCE

#endif
}
示例#5
0
文件: qpalette.cpp 项目: fluxer/katie
static void qt_palette_from_color(QPalette &pal, const QColor & button)
{
    QColor bg = button,
           btn = button,
           fg, base;
    int h, s, v;
    bg.getHsv(&h, &s, &v);
    if(v > 128) {
        fg   = Qt::black;
        base = Qt::white;
    } else {
        fg   = Qt::white;
        base = Qt::black;
    }
    //inactive and active are the same..
    pal.setColorGroup(QPalette::Active, QBrush(fg), QBrush(btn), QBrush(btn.lighter(150)),
                      QBrush(btn.darker()), QBrush(btn.darker(150)), QBrush(fg), QBrush(Qt::white),
                      QBrush(base), QBrush(bg));
    pal.setColorGroup(QPalette::Inactive, QBrush(fg), QBrush(btn), QBrush(btn.lighter(150)),
                      QBrush(btn.darker()), QBrush(btn.darker(150)), QBrush(fg), QBrush(Qt::white),
                      QBrush(base), QBrush(bg));
    pal.setColorGroup(QPalette::Disabled, QBrush(btn.darker()), QBrush(btn), QBrush(btn.lighter(150)),
                      QBrush(btn.darker()), QBrush(btn.darker(150)), QBrush(btn.darker()),
                      QBrush(Qt::white), QBrush(bg), QBrush(bg));
}
示例#6
0
/*!
  Draw a dotted round circle, if !isReadOnly()

  \param painter Painter
*/
void QwtDial::drawFocusIndicator( QPainter *painter ) const
{
    if ( !isReadOnly() )
    {
        QRectF focusRect = innerRect();

        const int margin = 2;
        focusRect.adjust( margin, margin, -margin, -margin );

        QColor color = palette().color( QPalette::Base );
        if ( color.isValid() )
        {
            const QColor gray( Qt::gray );

            int h, s, v;
            color.getHsv( &h, &s, &v );
            color = ( v > 128 ) ? gray.dark( 120 ) : gray.light( 120 );
        }
        else
            color = Qt::darkGray;

        painter->save();
        painter->setBrush( Qt::NoBrush );
        painter->setPen( QPen( color, 0, Qt::DotLine ) );
        painter->drawEllipse( focusRect );
        painter->restore();
    }
}
示例#7
0
void QgsColorWidget::alterColor( QColor& color, const QgsColorWidget::ColorComponent component, const int newValue ) const
{
  int h, s, v, a;
  color.getHsv( &h, &s, &v, &a );

  //clip value to sensible range
  int clippedValue = qMin( qMax( 0, newValue ), componentRange( component ) );

  switch ( component )
  {
    case QgsColorWidget::Red:
      color.setRed( clippedValue );
      return;
    case QgsColorWidget::Green:
      color.setGreen( clippedValue );
      return;
    case QgsColorWidget::Blue:
      color.setBlue( clippedValue );
      return;
    case QgsColorWidget::Hue:
      color.setHsv( clippedValue, s, v, a );
      return;
    case QgsColorWidget::Saturation:
      color.setHsv( h, clippedValue, v, a );
      return;
    case QgsColorWidget::Value:
      color.setHsv( h, s, clippedValue, a );
      return;
    case QgsColorWidget::Alpha:
      color.setAlpha( clippedValue );
      return;
    default:
      return;
  }
}
示例#8
0
void RDPushButton::setFlashColor(QColor color)
{
  int h=0;
  int s=0;
  int v=0;

  flash_color=color;  
  flash_palette=QPalette(QColor(flash_color),backgroundColor());

  color.getHsv(&h,&s,&v);
  if((h>180)&&(h<300)) {
    v=255;
  }
  else {
    if(v<168) {
      v=255;
    }
    else {
      v=0;
    }
  }
  s=0;
  color.setHsv(h,s,v);
  flash_palette.setColor(QPalette::Active,QColorGroup::ButtonText,color);
  flash_palette.setColor(QPalette::Inactive,QColorGroup::ButtonText,color);
}
示例#9
0
/*!
    Constructs a palette from a \a button color and a \a window.
    The other colors are automatically calculated, based on these
    colors.
*/
QPalette::QPalette(const QColor &button, const QColor &window)
{
    init();
    int h, s, v;
    window.getHsv(&h, &s, &v);

    const QBrush windowBrush = QBrush(window);
    const QBrush whiteBrush = QBrush(Qt::white);
    const QBrush blackBrush = QBrush(Qt::black);
    const QBrush baseBrush = v > 128 ? whiteBrush : blackBrush;
    const QBrush foregroundBrush = v > 128 ? blackBrush : whiteBrush;
    const QBrush disabledForeground = QBrush(Qt::darkGray);

    const QBrush buttonBrush = QBrush(button);
    const QBrush buttonBrushDark = QBrush(button.darker());
    const QBrush buttonBrushDark150 = QBrush(button.darker(150));
    const QBrush buttonBrushLight150 = QBrush(button.lighter(150));

    //inactive and active are identical
    setColorGroup(Inactive, foregroundBrush, buttonBrush, buttonBrushLight150, buttonBrushDark,
                  buttonBrushDark150, foregroundBrush, whiteBrush, baseBrush,
                  windowBrush);
    setColorGroup(Active, foregroundBrush, buttonBrush, buttonBrushLight150, buttonBrushDark,
                  buttonBrushDark150, foregroundBrush, whiteBrush, baseBrush,
                  windowBrush);
    setColorGroup(Disabled, disabledForeground, buttonBrush, buttonBrushLight150,
                  buttonBrushDark, buttonBrushDark150, disabledForeground,
                  whiteBrush, baseBrush, windowBrush);
}
void CFocusFrameStyle::drawPrimitive(PrimitiveElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget) const
{
	if (element == QStyle::PE_FrameFocusRect) {
		if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(option)) {
			QColor bg = fropt->backgroundColor;
			QPen oldPen = painter->pen();
			QPen newPen;
			if (bg.isValid()) {
				int h, s, v;
				bg.getHsv(&h, &s, &v);
				if (v >= 128)
					newPen.setColor(Qt::black);
				else
					newPen.setColor(Qt::white);
			} else {
				newPen.setColor(option->palette.foreground().color());
			}
			newPen.setWidth(0);
			newPen.setStyle(Qt::DotLine);
			painter->setPen(newPen);
			QRect focusRect = option->rect /*.adjusted(1, 1, -1, -1) */;
			painter->drawRect(focusRect.adjusted(0, 0, -1, -1)); //draw pen inclusive
			painter->setPen(oldPen);
		}
	} else
		QApplication::style()->drawPrimitive(element, option, painter, widget);
}
示例#11
0
void KApplication::applyColors(ColorSchema cs)
{
    QPalette pal = QApplication::palette();

    switch (cs) {
            case DarkBlue:
               {
                  const QColor bg(32, 32, 82);
                  const QColor bgAlt(57, 64, 98);

                  pal.setColor(QPalette::Text, Qt::white);
                  pal.setColor(QPalette::Base, bg);
                  pal.setColor(QPalette::Foreground, 0xd7d7ef);
                  pal.setColor(QPalette::Background, bgAlt);

                  pal.setColor(QPalette::Button, bgAlt);
                  pal.setColor(QPalette::ButtonText, 0xd7d7ef);

                  pal.setColor(QPalette::Highlight, Qt::white);
                  pal.setColor(QPalette::HighlightedText, bg);
                  int h, s, v;
                  bgAlt.getHsv(&h, &s, &v);
                  pal.setColor(QPalette::Midlight, QColor(h, s/3, (int)(v * 1.2)));
               }
            break;
    }

    applyPalette(pal);
}
示例#12
0
文件: qpalette.cpp 项目: fluxer/katie
/*!
    Constructs a palette from a \a button color and a \a window.
    The other colors are automatically calculated, based on these
    colors.
*/
QPalette::QPalette(const QColor &button, const QColor &window)
{
    init();
    QColor bg = window, btn = button, fg, base, disfg;
    int h, s, v;
    bg.getHsv(&h, &s, &v);
    if(v > 128) {
        fg   = Qt::black;
        base = Qt::white;
        disfg = Qt::darkGray;
    } else {
        fg   = Qt::white;
        base = Qt::black;
        disfg = Qt::darkGray;
    }
    //inactive and active are identical
    setColorGroup(Inactive, QBrush(fg), QBrush(btn), QBrush(btn.lighter(150)), QBrush(btn.darker()),
                  QBrush(btn.darker(150)), QBrush(fg), QBrush(Qt::white), QBrush(base),
                  QBrush(bg));
    setColorGroup(Active, QBrush(fg), QBrush(btn), QBrush(btn.lighter(150)), QBrush(btn.darker()),
                  QBrush(btn.darker(150)), QBrush(fg), QBrush(Qt::white), QBrush(base),
                  QBrush(bg));
    setColorGroup(Disabled, QBrush(disfg), QBrush(btn), QBrush(btn.lighter(150)),
                  QBrush(btn.darker()), QBrush(btn.darker(150)), QBrush(disfg),
                  QBrush(Qt::white), QBrush(base), QBrush(bg));
}
示例#13
0
void KHueSaturationSelector::drawPalette( QPixmap *pixmap )
{
    int xSize = contentsRect().width(), ySize = contentsRect().height();
    QImage image( QSize( xSize, ySize ), QImage::Format_RGB32 );
    QColor col;
    int h, s;
    uint *p;

    col.setHsv( hue(), saturation(), colorValue() );

    int _h, _s, _v, _r, _g, _b;
    col.getHsv( &_h, &_s, &_v );
    col.getRgb( &_r, &_g, &_b );

	for ( s = ySize-1; s >= 0; s-- )
	{
        p = ( uint * ) image.scanLine( ySize - s - 1 );
		for( h = 0; h < xSize; h++ )
		{
            switch ( chooserMode() ) {
            case ChooserClassic:
            default:
                col.setHsv( 359 * h / ( xSize - 1 ), 255 * s / ( ( ySize == 1 ) ? 1 : ySize - 1 ), 192 );
                break;
            case ChooserHue:
                col.setHsv( _h, 255 * h / ( xSize - 1 ), 255 * s / ( ( ySize == 1 ) ? 1 : ySize - 1 ) );
                break;
            case ChooserSaturation:
                col.setHsv( 359 * h / ( xSize - 1 ), _s, 255 * s / ( ( ySize == 1 ) ? 1 : ySize - 1 ) );
                break;
            case ChooserValue:
                col.setHsv( 359 * h / ( xSize - 1 ), 255 * s / ( ( ySize == 1 ) ? 1 : ySize - 1 ), _v );
                break;
            case ChooserRed:
                col.setRgb( _r, 255 * h / ( xSize - 1 ), 255 * s / ( ( ySize == 1 ) ? 1 : ySize - 1 ) );
                break;
            case ChooserGreen:
                col.setRgb( 255 * h / ( xSize - 1 ), _g, 255 * s / ( ( ySize == 1 ) ? 1 : ySize - 1 ) );
                break;
            case ChooserBlue:
                col.setRgb( 255 * s / ( ( ySize == 1 ) ? 1 : ySize - 1 ), 255 * h / ( xSize - 1 ), _b );
                break;
            }

            *p = col.rgb();
            p++;
        }
    }

    /*
    if ( pixmap->depth() <= 8 )
    {
        const QVector<QColor> standardPalette = kdeui_standardPalette();
        KImageEffect::dither( image, standardPalette.data(), standardPalette.size() );
    }
    */
    *pixmap = QPixmap::fromImage( image );
}
示例#14
0
文件: MiscQt.cpp 项目: beauby/pigale
QColor OppCol(QColor & col)
// to draw text on vertices
  {int hue,sat,val;
  col.getHsv(&hue,&sat,&val);
  val = (val <= 192) ? 255 : 0;
  QColor col1;
  col1.setHsv((hue+180)%360,sat/2,val); 
  return col1;
  }
示例#15
0
void KColorCombo2::drawColorRect(QPainter &painter, int x, int y, const QColor &color, bool isDefault, int width, int height)
{
	// Fill:
	if (color.isValid())
		painter.fillRect(x /*+ 1*/, y /*+ 1*/, width /*- 2*/, height /*- 2*/, color);
	else {
		// If it's an invalid color, it's for the "Other..." entry: draw a rainbow.
		// If it wasn't for the "Other..." entry, the programmer made a fault, so (s)he will be informed about that visually.
		for (int i = 0; i < width-2; ++i) {
			int hue = i * 360 / (width-2);
			for (int j = 0; j < height-2; ++j) {
				int saturation = 255 - (j * 255 / (height-2));
				painter.setPen( QColor(hue, saturation, /*value=*/255, QColor::Hsv) );
				painter.drawPoint(x + i + 1, y + j + 1);
			}
		}
	}

	// Stroke:
	int dontCare, value;
	color.getHsv(/*hue:*/dontCare, /*saturation:*/dontCare, value);
	QColor stroke = (color.isValid() ? color.dark(125) : palette().color(QPalette::Text));
	painter.setPen(/*color);//*/stroke);
	painter.drawLine(x + 1,         y,              x + width - 2, y);
	painter.drawLine(x,             y + 1,          x,             y + height - 2);
	painter.drawLine(x + 1,         y + height - 1, x + width - 2, y + height - 1);
	painter.drawLine(x + width - 1, y + 1,          x + width - 1, y + height - 2);

	// Round corners:
	QColor antialiasing;
	if (color.isValid()) {
		antialiasing = Tool_mixColors(color, stroke);
		painter.setPen(antialiasing);
		painter.drawPoint(x + 1,         y + 1);
		painter.drawPoint(x + 1,         y + height - 2);
		painter.drawPoint(x + width - 2, y + height - 2);
		painter.drawPoint(x + width - 2, y + 1);
	} else {
		// The two top corners:
		antialiasing = Tool_mixColors(Qt::red, stroke);
		painter.setPen(antialiasing);
		painter.drawPoint(x + 1,         y + 1);
		painter.drawPoint(x + width - 2, y + 1);
		// The two bottom ones:
		antialiasing = Tool_mixColors(Qt::white, stroke);
		painter.setPen(antialiasing);
		painter.drawPoint(x + 1,         y + height - 2);
		painter.drawPoint(x + width - 2, y + height - 2);
	}

	// Mark default color:
	if (isDefault) {
		painter.setPen(stroke);
		painter.drawLine(x + 1, y + height - 2, x + width - 2, y + 1);
	}
}
示例#16
0
文件: MiscQt.cpp 项目: beauby/pigale
QColor Desaturate(QColor & col)
  {int hue,sat,val;
  col.getHsv(&hue,&sat,&val);
  int val0 = 192;
  val = val0 +(int)(val*((double)(255.-val0)/255.));
  QColor col1;
  col1.setHsv(hue,sat/4,val); 
  //col.setHsv((hue+180)%360,sat/4,val); 
  return col1;
  }
示例#17
0
void msl::colorChanged(const QColor & color)
{
	//Get RGB values of the current color
	int r, g, b, h, s, v;

	color.getRgb(&r, &g, &b);
	color.getHsv(&h, &s, &v);

	updateLEDs();
}
示例#18
0
void KColorDialog::KColorDialogPrivate::setHsvEdit(const QColor &col)
{
    if (bEditHsv) return;
    int h, s, v;
    col.getHsv(&h, &s, &v);

    hedit->setValue(h);
    sedit->setValue(s);
    vedit->setValue(v);
}
示例#19
0
void
Style::drawHeaderSection(const QStyleOption *option, QPainter *painter, const QWidget*) const
{
    OPT_SUNKEN OPT_HOVER
    const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option);
    const bool sorting = header && (header->sortIndicator != QStyleOptionHeader::None);

    Qt::Orientation o = Qt::Vertical; int s = RECT.height();
    if (header && header->orientation == Qt::Vertical)
    {
        o = Qt::Horizontal;
        s = RECT.width();
    }

    QColor c =  sorting ? COLOR(config.view.sortingHeader_role[Bg]) : COLOR(config.view.header_role[Bg]);

    if (Colors::value(c) < 50)
        { int h,s,v,a; c.getHsv(&h, &s, &v, &a); c.setHsv(h, s, 50, a); }

    if (appType == GTK)
        sunken = option->state & State_HasFocus;
    if (sunken)
    {
        const QPixmap &sunk = Gradients::pix(c, s, o, Gradients::Sunken);
        painter->drawTiledPixmap(RECT, sunk);
        return;
    }

    const Gradients::Type gt = sorting ? config.view.sortingHeaderGradient : config.view.headerGradient;

    if (hover)
        c = Colors::mid(c, sorting ? CCOLOR(view.sortingHeader, Fg) : CCOLOR(view.header, Fg),8,1);

    if (gt == Gradients::None)
        painter->fillRect(RECT, c);
    else
        painter->drawTiledPixmap(RECT, Gradients::pix(c, s, o, gt));

    if (o == Qt::Vertical)
    {
        if (!header || header->section < QStyleOptionHeader::End)
        {
            QRect r = RECT; r.setLeft(r.right() - F(1));
            painter->drawTiledPixmap(r, Gradients::pix(CCOLOR(view.header, Bg), s, o, Gradients::Sunken));
        }
        if (Colors::value(CCOLOR(view.header, Bg)) > 90) // not on dark elements - looks just stupid...
        {
            SAVE_PEN
            painter->setPen(Colors::mid(FCOLOR(Base), Qt::black, 6, 1));
            painter->drawLine(RECT.bottomLeft(), RECT.bottomRight());
            RESTORE_PEN
        }
    }
示例#20
0
/*! \internal

    Given the color \a col, this function determines the point in the
    equilateral triangle defined with (pa, pb, pc) that displays this
    color. The function assumes the color at pa has a hue equal to the
    hue of \a col, and that pb is black and pc is white.

    In this certain type of triangle, we observe that saturation grows
    from the black-color edge towards the black-white edge. The value
    grows from the black corner towards the white-color edge. Using
    the intersection of the saturation and value points on the three
    edges, we are able to determine the point with the same saturation
    and value as \a col.
*/
QPointF QtColorTriangle::pointFromColor(const QColor &col) const
{
    // Simplifications for the corner cases.
    if (col == Qt::black)
	return pb;
    else if (col == Qt::white)
	return pc;

    // Find the x and y slopes
    double ab_deltax = pb.x() - pa.x();
    double ab_deltay = pb.y() - pa.y();
    double bc_deltax = pc.x() - pb.x();
    double bc_deltay = pc.y() - pb.y();
    double ac_deltax = pc.x() - pa.x();
    double ac_deltay = pc.y() - pa.y();

    // Extract the h,s,v values of col.
    int hue,sat,val;
    col.getHsv(&hue, &sat, &val);

    // Find the line that passes through the triangle where the value
    // is equal to our color's value.
    double p1 = pa.x() + (ab_deltax * (double) (255 - val)) / 255.0;
    double q1 = pa.y() + (ab_deltay * (double) (255 - val)) / 255.0;
    double p2 = pb.x() + (bc_deltax * (double) val) / 255.0;
    double q2 = pb.y() + (bc_deltay * (double) val) / 255.0;

    // Find the line that passes through the triangle where the
    // saturation is equal to our color's value.
    double p3 = pa.x() + (ac_deltax * (double) (255 - sat)) / 255.0;
    double q3 = pa.y() + (ac_deltay * (double) (255 - sat)) / 255.0;
    double p4 = pb.x();
    double q4 = pb.y();

    // Find the intersection between these lines.
	double x = 0;
	double y = 0;
	if (p1 != p2) {
		double a = (q2 - q1) / (p2 - p1);
		double c = (q4 - q3) / (p4 - p3);
		double b = q1 - a * p1;
		double d = q3 - c * p3;

		x = (d - b) / (a - c);
		y = a * x + b;
	}
	else {
		x = p1;
		y = q3 + (x - p3) * (q4 - q3) / (p4 - p3);
	}
	
    return QPointF(x, y);
}
示例#21
0
QColor KODayMatrix::getShadedColor( const QColor &color ) const
{
  QColor shaded;
  int h = 0;
  int s = 0;
  int v = 0;
  color.getHsv( &h, &s, &v );
  s = s / 4;
  v = 192 + v / 4;
  shaded.setHsv( h, s, v );

  return shaded;
}
示例#22
0
文件: tray.cpp 项目: mfuchs/kget-gsoc
void Tray::paintIcon( int mergePixels, bool force )
{
    // skip redrawing the same pixmap
    static int mergePixelsCache = 0;
    if ( mergePixels == mergePixelsCache && !force )
         return;
    mergePixelsCache = mergePixels;

    if ( mergePixels < 0 )
        return blendOverlay( baseIcon );

    // make up the grayed icon
    if ( !grayedIcon )
    {
        QImage tmpTrayIcon = baseIcon->toImage();
        KIconEffect::semiTransparent( tmpTrayIcon );
        grayedIcon = new QPixmap( QPixmap::fromImage( tmpTrayIcon ) );
    }
    if ( mergePixels == 0 )
        return blendOverlay( grayedIcon );

    // make up the alternate icon (use hilight color but more saturated)
    if ( !alternateIcon )
    {
        QImage tmpTrayIcon = baseIcon->toImage();
        // eros: this looks cool with dark red blue or green but sucks with
        // other colors (such as kde default's pale pink..). maybe the effect
        // or the blended color has to be changed..
        QLabel label; //just a hack to get the palette
        QColor saturatedColor = label.palette().color(QPalette::Active, QPalette::Highlight);
        int hue, sat, value;
        saturatedColor.getHsv( &hue, &sat, &value );
        saturatedColor.setHsv( hue, (sat + 510) / 3, value );
        KIconEffect::colorize( tmpTrayIcon, saturatedColor/* Qt::blue */, 0.9 );
        alternateIcon = new QPixmap( QPixmap::fromImage( tmpTrayIcon ) );
    }
    if ( mergePixels >= alternateIcon->height() )
        return blendOverlay( alternateIcon );

    // mix [ grayed <-> colored ] icons
    QPixmap tmpTrayPixmap( *alternateIcon );
    QPainter paint;
    paint.begin( &tmpTrayPixmap );
    paint.drawPixmap( 0, 0, *grayedIcon, 0, 0,
        alternateIcon->width(), alternateIcon->height() - mergePixels );
    paint.end();

    blendOverlay( &tmpTrayPixmap );
}
/**
 * This code is inspired from code found in a Paint.net plugin:
 * http://paintdotnet.forumer.com/viewtopic.php?f=27&t=26193&p=205954&hilit=red+eye#p205954
 */
inline qreal computeRedEyeAlpha(const QColor& src)
{
    int hue, sat, value;
    src.getHsv(&hue, &sat, &value);

    qreal axs = 1.0;
    if (hue > 259) {
        static const Ramp ramp(30, 35, 0., 1.);
        axs = ramp(sat);
    } else {
        const Ramp ramp(hue * 2 + 29, hue * 2 + 40, 0., 1.);
        axs = ramp(sat);
    }

    return qBound(0., double(src.alphaF()) * axs, 1.);
}
示例#24
0
void
amaroK::TrayIcon::paintIcon( int mergePixels, bool force )
{
    // skip redrawing the same pixmap
    static int mergePixelsCache = 0;
    if ( mergePixels == mergePixelsCache && !force )
         return;
    mergePixelsCache = mergePixels;

    if ( mergePixels < 0 )
        return blendOverlay( baseIcon );

    // make up the grayed icon
    if ( grayedIcon.isNull() )
    {
        QImage tmpTrayIcon = baseIcon.convertToImage();
        KIconEffect::semiTransparent( tmpTrayIcon );
        grayedIcon = tmpTrayIcon;
    }
    if ( mergePixels == 0 )
        return blendOverlay( grayedIcon );

    // make up the alternate icon (use hilight color but more saturated)
    if ( alternateIcon.isNull() )
    {
        QImage tmpTrayIcon = baseIcon.convertToImage();
        // eros: this looks cool with dark red blue or green but sucks with
        // other colors (such as kde default's pale pink..). maybe the effect
        // or the blended color has to be changed..
        QColor saturatedColor = palette().active().highlight();
        int hue, sat, value;
        saturatedColor.getHsv( &hue, &sat, &value );
        saturatedColor.setHsv( hue, sat > 200 ? 200 : sat, value < 100 ? 100 : value );
        KIconEffect::colorize( tmpTrayIcon, saturatedColor/* Qt::blue */, 0.9 );
        alternateIcon = tmpTrayIcon;
    }
    if ( mergePixels >= alternateIcon.height() )
        return blendOverlay( alternateIcon );

    // mix [ grayed <-> colored ] icons
    QPixmap tmpTrayPixmap = alternateIcon;
    copyBlt( &tmpTrayPixmap, 0,0, &grayedIcon, 0,0,
            alternateIcon.width(), alternateIcon.height() - mergePixels );
    blendOverlay( tmpTrayPixmap );
}
示例#25
0
static QPalette createPalette(const QColor &windowColor,
                              const QColor &highlightColor)
{
    int hue, sat, windowValue;
    windowColor.getHsv(&hue, &sat, &windowValue);

    auto fromValue = [=](int value) {
        return QColor::fromHsv(hue, sat, qMin(255, qMax(0, value)));
    };

    const bool isLight = windowValue > 128;
    const int baseValue = isLight ? windowValue + 48 : windowValue - 24;

    const int lightTextValue = qMin(255, baseValue + 192);
    const int darkTextValue = qMax(0, baseValue - 192);
    const int lightTextDisabledValue = (baseValue + lightTextValue) / 2;
    const int darkTextDisabledValue = (baseValue + darkTextValue) / 2;

    const QColor lightText = fromValue(lightTextValue);
    const QColor darkText = fromValue(darkTextValue);
    const QColor lightDisabledText = fromValue(lightTextDisabledValue);
    const QColor darkDisabledText = fromValue(darkTextDisabledValue);

    QPalette palette(fromValue(windowValue));
    palette.setColor(QPalette::Base, fromValue(baseValue));
    palette.setColor(QPalette::AlternateBase, fromValue(baseValue - 10));
    palette.setColor(QPalette::Window, fromValue(windowValue));
    palette.setColor(QPalette::WindowText, isLight ? darkText : lightText);
    palette.setColor(QPalette::ButtonText, isLight ? darkText : lightText);
    palette.setColor(QPalette::Text, isLight ? darkText : lightText);
    palette.setColor(QPalette::Light, QColor(255, 255, 255, 55));
    palette.setColor(QPalette::Dark, fromValue(windowValue - 55));

    palette.setColor(QPalette::Disabled, QPalette::WindowText, isLight ? darkDisabledText : lightDisabledText);
    palette.setColor(QPalette::Disabled, QPalette::ButtonText, isLight ? darkDisabledText : lightDisabledText);
    palette.setColor(QPalette::Disabled, QPalette::Text, isLight ? darkDisabledText : lightDisabledText);

    bool highlightIsDark = qGray(highlightColor.rgb()) < 120;
    palette.setColor(QPalette::Highlight, highlightColor);
    palette.setColor(QPalette::HighlightedText, highlightIsDark ? Qt::white : Qt::black);

    return palette;
}
示例#26
0
文件: rdconf.cpp 项目: WMTH/rivendell
QColor RDGetTextColor(const QColor &background_color)
{
  int h,s,v;
  QColor color=background_color;

  background_color.getHsv(&h,&s,&v);
  if(v<128) {
    color=Qt::white;
  }
  else {
    if((h>210)&&(h<270)&&(s>128)) {  // Special case for blue
      color=Qt::white;
    }
    else {
      color=Qt::black;
    }
  }

  return color;
}
示例#27
0
/**
 * Color triangle has been used, update sliders to match
 */
void ColorDialog::updateTriangle(const QColor& color)
{
	if(!updating_) {
		updating_ = true;
		ui_->red->setValue(color.red());
		ui_->green->setValue(color.green());
		ui_->blue->setValue(color.blue());

		int h,s,v;
		color.getHsv(&h,&s,&v);
		if(h==-1)
			h = validhue_;
		ui_->hue->setValue(h);
		ui_->saturation->setValue(s);
		ui_->value->setValue(v);
		updateCurrent(color);
		ui_->txtHex->setText(color.name());

		updating_ = false;
	}
}
示例#28
0
/*!
  Draw a dotted round circle, if !isReadOnly()

  \param painter Painter
*/
void QwtDial::drawFocusIndicator(QPainter *painter) const
{
    if ( !isReadOnly() )
    {
        QRect focusRect = contentsRect();

        const int margin = 2;
        focusRect.setRect( 
            focusRect.x() + margin,
            focusRect.y() + margin,
            focusRect.width() - 2 * margin,
            focusRect.height() - 2 * margin);

#if QT_VERSION < 0x040000
        QColor color = colorGroup().color(QColorGroup::Base);
#else
        QColor color = palette().color(QPalette::Base);
#endif
        if (color.isValid())
        {
            const QColor gray(Qt::gray);

            int h, s, v;
#if QT_VERSION < 0x040000
            color.hsv(&h, &s, &v);
#else
            color.getHsv(&h, &s, &v);
#endif
            color = (v > 128) ? gray.dark(120) : gray.light(120);
        }
        else
            color = Qt::darkGray;

        painter->save();
        painter->setBrush(Qt::NoBrush);
        painter->setPen(QPen(color, 0, Qt::DotLine));
        painter->drawEllipse(focusRect);
        painter->restore();
    }
}
示例#29
0
/**
 * RGB sliders have been used, update HSV to match
 */
void ColorDialog::updateRgb()
{
	if(!updating_) {
		QColor col = color();
		int h,s,v;
		col.getHsv(&h,&s,&v);
		if(h==-1)
			h = validhue_;
		else
			validhue_ = h;
		updating_ = true;
		ui_->hue->setValue(h);
		ui_->saturation->setValue(s);
		ui_->value->setValue(v);
		ui_->colorTriangle->setColor(col);
		updateBars();

		ui_->txtHex->setText(col.name());
		updateCurrent(col);
		updating_ = false;
	}
}
示例#30
0
void
AudioVUMeter::paintEvent(QPaintEvent */* e */)
{
    //###
    // See note in VUMeter.cpp explaining the width/height - 1 issue
    int w = width() - 1;
    int h = height() - 1;
    QPainter paint(this);

    // we'll try giving the area between the border and the actual meter the
    // same tint as the faders, for consistency of appearance

    // first, we'll fill the whole background rect with a 40% alpha version of
    // the border color
    QColor fill = palette().mid().color();
    int H = 0;
    int S = 0;
    int V = 0;
    int A = 0;
    fill.getHsv(&H, &S, &V, &A);
    A = 40;
    fill = QColor::fromHsv(H, S, V, A);
    paint.fillRect(0, 0, w, h, fill);
    
    // now we draw the border outline around it
    paint.setPen(palette().mid().color());
    paint.drawRect(0, 0, w, h);

    paint.setPen(palette().background().color());
    paint.setBrush(palette().background());
    paint.drawRect(1, 1, w - 2, m_yoff / 2 - 1);
    paint.drawRect(1, 1, m_xoff / 2 - 1, h - 2);
    paint.drawRect(w - m_xoff / 2 - 1, 1, m_xoff / 2, h - 2);
    paint.drawRect(1, h - m_yoff / 2 - 1, w - 2, m_yoff / 2);
    paint.end();

//  m_meter->paintEvent(e);
}