本文整理汇总了C++中QColor::hslHueF方法的典型用法代码示例。如果您正苦于以下问题:C++ QColor::hslHueF方法的具体用法?C++ QColor::hslHueF怎么用?C++ QColor::hslHueF使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QColor
的用法示例。
在下文中一共展示了QColor::hslHueF方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: plotMouseMove
void QgsGradientColorRampDialog::plotMouseMove( QPointF point )
{
QColor newColor = mStopEditor->selectedStop().color;
if ( mCurrentPlotColorComponent == 0 )
newColor = QColor::fromHslF( qBound( qreal( 0.0 ), point.y(), qreal( 1.0 ) ), newColor.hslSaturationF(), newColor.lightnessF(), newColor.alphaF() );
else if ( mCurrentPlotColorComponent == 1 )
newColor = QColor::fromHslF( newColor.hslHueF(), newColor.hslSaturationF(), qBound( qreal( 0.0 ), point.y(), qreal( 1.0 ) ), newColor.alphaF() );
else if ( mCurrentPlotColorComponent == 2 )
newColor = QColor::fromHslF( newColor.hslHueF(), qBound( qreal( 0.0 ), point.y(), qreal( 1.0 ) ), newColor.lightnessF(), newColor.alphaF() );
else if ( mCurrentPlotColorComponent == 3 )
newColor = QColor::fromHslF( newColor.hslHueF(), newColor.hslSaturationF(), newColor.lightnessF(), qBound( qreal( 0.0 ), point.y(), qreal( 1.0 ) ) );
mStopEditor->setSelectedStopDetails( newColor, qBound( qreal( 0.0 ), point.x(), qreal( 1.0 ) ) );
}
示例2: darkShade
static QColor darkShade(QColor c)
{
qreal contrast = 0.7; // taken from kcolorscheme for the dark shade
qreal darkAmount;
if (c.lightnessF() < 0.006)
{
/* too dark */
darkAmount = 0.02 + 0.40 * contrast;
}
else if (c.lightnessF() > 0.93)
{
/* too bright */
darkAmount = -0.06 - 0.60 * contrast;
}
else
{
darkAmount = (-c.lightnessF()) * (0.55 + contrast * 0.35);
}
qreal v = c.lightnessF() + darkAmount;
v = v > 0.0 ? (v < 1.0 ? v : 1.0) : 0.0;
c.setHsvF(c.hslHueF(), c.hslSaturationF(), v);
return c;
}
示例3: addMarkersForColor
void QgsGradientColorRampDialog::addMarkersForColor( double x, const QColor &color, bool isSelected )
{
if ( mPlotHueCheckbox->isChecked() )
addPlotMarker( x, color.hslHueF(), color, isSelected && mCurrentPlotColorComponent == 0 );
if ( mPlotLightnessCheckbox->isChecked() )
addPlotMarker( x, color.lightnessF(), color, isSelected && mCurrentPlotColorComponent == 1 );
if ( mPlotSaturationCheckbox->isChecked() )
addPlotMarker( x, color.hslSaturationF(), color, isSelected && mCurrentPlotColorComponent == 2 );
if ( mPlotAlphaCheckbox->isChecked() )
addPlotMarker( x, color.alphaF(), color, isSelected && mCurrentPlotColorComponent == 3 );
}
示例4: tintImage
// Tints an image with tintColor, while preserving alpha and lightness
void StyleHelper::tintImage(QImage &img, const QColor &tintColor)
{
QPainter p(&img);
p.setCompositionMode(QPainter::CompositionMode_Screen);
for (int x = 0; x < img.width(); ++x) {
for (int y = 0; y < img.height(); ++y) {
QRgb rgbColor = img.pixel(x, y);
int alpha = qAlpha(rgbColor);
QColor c = QColor(rgbColor);
if (alpha > 0) {
c.toHsl();
qreal l = c.lightnessF();
QColor newColor = QColor::fromHslF(tintColor.hslHueF(), tintColor.hslSaturationF(), l);
newColor.setAlpha(alpha);
img.setPixel(x, y, newColor.rgba());
}
}
}
}
示例5: setHsl
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);
}
}
//.........这里部分代码省略.........
示例6: plotMousePress
void QgsGradientColorRampDialog::plotMousePress( QPointF point )
{
//find closest part
double minDist = 1;
mCurrentPlotColorComponent = -1;
mCurrentPlotMarkerIndex = -1;
// first color
for ( int i = 0; i < mRamp.count(); ++i )
{
QColor currentCol;
double currentOff = 0.0;
if ( i == 0 )
{
currentOff = 0.0;
currentCol = mRamp.color1();
}
else if ( i == mRamp.count() - 1 )
{
currentOff = 1.0;
currentCol = mRamp.color2();
}
else
{
currentOff = mRamp.stops().at( i - 1 ).offset;
currentCol = mRamp.stops().at( i - 1 ).color;
}
double currentDist;
if ( mPlotHueCheckbox->isChecked() )
{
currentDist = std::pow( point.x() - currentOff, 2.0 ) + std::pow( point.y() - currentCol.hslHueF(), 2.0 );
if ( currentDist < minDist )
{
minDist = currentDist;
mCurrentPlotColorComponent = 0;
mCurrentPlotMarkerIndex = i;
}
}
if ( mPlotLightnessCheckbox->isChecked() )
{
currentDist = std::pow( point.x() - currentOff, 2.0 ) + std::pow( point.y() - currentCol.lightnessF(), 2.0 );
if ( currentDist < minDist )
{
minDist = currentDist;
mCurrentPlotColorComponent = 1;
mCurrentPlotMarkerIndex = i;
}
}
if ( mPlotSaturationCheckbox->isChecked() )
{
currentDist = std::pow( point.x() - currentOff, 2.0 ) + std::pow( point.y() - currentCol.hslSaturationF(), 2.0 );
if ( currentDist < minDist )
{
minDist = currentDist;
mCurrentPlotColorComponent = 2;
mCurrentPlotMarkerIndex = i;
}
}
if ( mPlotAlphaCheckbox->isChecked() )
{
currentDist = std::pow( point.x() - currentOff, 2.0 ) + std::pow( point.y() - currentCol.alphaF(), 2.0 );
if ( currentDist < minDist )
{
minDist = currentDist;;
mCurrentPlotColorComponent = 3;
mCurrentPlotMarkerIndex = i;
}
}
}
// watch out - selected stop index may differ if stops in editor are out of order!!!
if ( mCurrentPlotMarkerIndex >= 0 )
mStopEditor->selectStop( mCurrentPlotMarkerIndex );
}