本文整理汇总了C++中QColor::getHsv方法的典型用法代码示例。如果您正苦于以下问题:C++ QColor::getHsv方法的具体用法?C++ QColor::getHsv怎么用?C++ QColor::getHsv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QColor
的用法示例。
在下文中一共展示了QColor::getHsv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawColoredArc
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: hasSufficientContrast
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;
}
示例3: hasSufficientContrast
/** 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
}
示例4: qt_palette_from_color
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));
}
示例5: drawFocusIndicator
/*!
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();
}
}
示例6: alterColor
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;
}
}
示例7: setFlashColor
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);
}
示例8: init
/*!
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);
}
示例9: drawPrimitive
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);
}
示例10: applyColors
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);
}
示例11: init
/*!
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));
}
示例12: drawPalette
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 );
}
示例13: OppCol
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;
}
示例14: QColor
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);
}
}
示例15: Desaturate
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;
}