本文整理汇总了C++中QColor::lightness方法的典型用法代码示例。如果您正苦于以下问题:C++ QColor::lightness方法的具体用法?C++ QColor::lightness怎么用?C++ QColor::lightness使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QColor
的用法示例。
在下文中一共展示了QColor::lightness方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getDefaultIconColor
QColor getDefaultIconColor(const QColor &color)
{
QColor c = color;
bool menuBackgrounIsLight = c.lightness() > lightThreshold;
c.setHsl(c.hue(),
qMax(0, qMin(255, c.saturation() + (menuBackgrounIsLight ? 30 : 10))),
qMax(0, qMin(255, c.lightness() + (menuBackgrounIsLight ? -140 : 100))));
return c;
}
示例2: isDarkTheme
bool isDarkTheme()
{
QPalette pal = QApplication::palette();
// QPalette::Base is used for the background of the Treeview
QColor color = pal.color(QPalette::Active, QPalette::Base);
return (color.lightness() < 127);
}
示例3: setActiveAppearance
void OverlayAnimator::setActiveAppearance( bool active )
{
QColor color = mEditor->palette().color(QPalette::Base);
if(color.lightness() >= 128)
color = color.darker(60);
else
color = color.lighter(50);
if (active)
color.setAlpha(0);
else
color.setAlpha(mEditor->inactiveFadeAlpha());
mBackgroundAnimation.stop();
if (mEditor->isVisible())
{
mBackgroundAnimation.setDuration(500);
mBackgroundAnimation.setEasingCurve( QEasingCurve::OutCubic );
mBackgroundAnimation.setStartValue( backgroundColor() );
mBackgroundAnimation.setEndValue( color );
mBackgroundAnimation.start();
}
else
{
setBackgroundColor(color);
}
}
示例4: double_thresholding
QImage edge_detector::double_thresholding(const QImage image)
{
QImage destImage = QImage( image);
QColor qc;
int T1 = 16;
int T2 = 12;
int H = image.height();
int W = image.width();
for (int i=0; i<H; i++)
for (int j=0; j<W; j++)
{
qc = ((QColor)image.pixel(j, i));
int lightness = qc.lightness();
int r = qc.red(), g = qc.green(), b = qc.blue();
if (lightness > 200 || lightness < T2)
{
qc.setRgb(0, 0, 0);
}
else if (lightness > T1)
{
qc.setRgb(255, 255, 255);
}
else
{
qc.setRgb(r?255:0, g?255:0, b?255:0);
}
destImage.setPixel( j, i, qc.rgba());
}
return destImage;
}
示例5: saturate
QPixmap ImageFilter::saturate(QImage origin, int delta)
{
QImage newImage(origin.width(), origin.height(), QImage::Format_ARGB32);
QColor oldColor;
QColor newColor;
int h,s,l;
for(int x=0; x < newImage.width(); x++)
{
for(int y=0; y < newImage.height(); y++)
{
oldColor = QColor(origin.pixel(x, y));
newColor = oldColor.toHsl();
h = newColor.hue();
s = newColor.saturation() + delta;
l = newColor.lightness();
//we check if the new value is between 0 and 255
s = qBound(0, s, 255);
newColor.setHsl(h, s, l);
newImage.setPixel(x, y, qRgb(newColor.red(), newColor.green(), newColor.blue()));
}
}
QPixmap processedImage(QPixmap::fromImage(newImage));
return processedImage;
}
示例6: applySaturation
void Alg_DefaultEffects::applySaturation(QImage *image1, QImage *image2, int delta)
{
QColor oldColor;
QColor newColor;
int h, s, l;
for (int x = 0; x < image1->width(); x++)
{
for (int y = 0; y < image1->height(); y++)
{
oldColor = QColor(image1->pixel(x, y));
newColor = oldColor.toHsl();
h = newColor.hue();
s = newColor.saturation()+delta;
l = newColor.lightness();
//we check if the new value is between 0 and 255
s = qBound(0, s, 255);
newColor.setHsl(h, s, l);
image2->setPixel(x, y, qRgb(newColor.red(), newColor.green(), newColor.blue()));
}
}
}
示例7: applyColorFilter
LameImage ImageConverter::applyColorFilter(LameImage image)
{
LameImage newimage(image.size(), LameImage::Format_Indexed8);
newimage.setFrameSize(image.frameWidth(), image.frameHeight());
newimage.setColorTable(_colors[_colorkey]);
for (int y = 0; y < image.height(); y++)
{
for (int x = 0; x < image.width(); x++)
{
QColor color = image.pixel(x, y);
int lightness = color.lightness();
if (color == _transparent)
{
newimage.setPixel(x, y, 2);
}
else
{
if (lightness >= highbreak)
newimage.setPixel(x, y, 1);
else if (lightness <= lowbreak)
newimage.setPixel(x, y, 0);
else
newimage.setPixel(x, y, 3);
}
}
}
return newimage;
}
示例8: get_master_line
/// get strongest line in a quater, if there is no line
/// at all, an empty line (vote == 0) will be given
///
void Rotater::get_master_line(const QImage image, int quater, Form *line)
{
QImage destImage = QImage( image);
int h = m_height, w = m_width;
// deal with 4 quaters of image accordingly
int x_from, x_to, y_from, y_to;
switch(quater)
{
case 1: x_from = 0, x_to = m_width/2, y_from = 0, y_to = m_height/2;
break;
case 2: x_from = m_width/2, x_to = w, y_from = 0, y_to = m_height/2;
break;
case 3: x_from = m_width/2, x_to = w, y_from = m_height/2, y_to = h;
break;
case 4: x_from = 0, x_to = m_width/2, y_from = m_height/2, y_to = h;
break;
}
// voting lines in area of the quater
QColor qc;
m_line_detector->reset();
for (int i=y_from; i<y_to; i++)
{
for (int j=x_from; j<x_to; j++)
{
qc = (QColor)destImage.pixel(j, i);
if (qc.lightness() > 200)
m_line_detector->vote(j, i);
}
}
vector<Form> lines = m_line_detector->get_lines();
int prefered_group = m_sign * ((quater == 1 || quater == 3) ? 1 : -1);
// get the line that has hightest voting in the quater
qreal alpha, min_alpha = 10;
bool alphaOk = false, lineEndOk = false;
int x0, y0, x1, y1;
for (int i=0; i<(int)lines.size(); i++)
{
if (lines.at(i).vote <= line->vote) continue;
m_line_detector->get_line_ends_and_alpha(lines.at(i), &x0, &y0, &x1, &y1, &alpha);
alphaOk = (prefered_group == 1 && fabs(alpha) < 90 - min_alpha) ||
(prefered_group == -1 && fabs(alpha) > min_alpha && fabs(alpha) < 180 - min_alpha);
lineEndOk = (quater == 4 && m_sign > 0 && (y0 == m_height || y1 == m_height)) ||
(quater == 4 && m_sign < 0 && (x0 == 0 || x1 == 0)) ||
(quater == 3 && m_sign > 0 && (x0 == m_width || x1 == m_width)) ||
(quater == 3 && m_sign < 0 && (y0 == m_height || y1 == m_height)) ||
(quater == 2 && m_sign > 0 && (y0 == 0 || y1 == 0)) ||
(quater == 2 && m_sign < 0 && (x0 == m_width || x1 == m_width)) ||
(quater == 1 && m_sign > 0 && (x0 == 0 || x1 == 0)) ||
(quater == 1 && m_sign < 0 && (y0 == 0 || y1 == 0));
if (alphaOk && lineEndOk) *line = lines.at(i);
}
}
示例9: on_colorButton_clicked
void LoadWindow::on_colorButton_clicked()
{
QColor c = QColorDialog::getColor(holder.profile().color());
if (!c.isValid() || (c.isValid() && (c.lightness() > 140 || c.green() > 180))) { // So they can click cancel without their colour disappearing!
return;
}
holder.profile().color() = c;
setColor(c);
}
示例10: on_colorButton_clicked
void TrainerMenu::on_colorButton_clicked()
{
QColor c = QColorDialog::getColor(team().color());
if (c.isValid() && (c.lightness() > 140 || c.green() > 180)) {
return;
}
team().color() = c;
setColor();
}
示例11: add
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()));
}
}
示例12: colorHighlightBg
PlatformStyle::PlatformStyle(const QString& name, bool imagesOnButtons, bool colorizeIcons, bool useExtraSpacing) : name(name),
imagesOnButtons(imagesOnButtons),
colorizeIcons(colorizeIcons),
useExtraSpacing(useExtraSpacing),
singleColor(0, 0, 0),
textColor(0, 0, 0)
{
// Determine icon highlighting color
if (colorizeIcons) {
const QColor colorHighlightBg(QApplication::palette().color(QPalette::Highlight));
const QColor colorHighlightFg(QApplication::palette().color(QPalette::HighlightedText));
const QColor colorText(QApplication::palette().color(QPalette::WindowText));
const int colorTextLightness = colorText.lightness();
QColor colorbase;
if (abs(colorHighlightBg.lightness() - colorTextLightness) < abs(colorHighlightFg.lightness() - colorTextLightness))
colorbase = colorHighlightBg;
else
colorbase = colorHighlightFg;
singleColor = colorbase;
}
// Determine text color
textColor = QColor(QApplication::palette().color(QPalette::WindowText));
}
示例13: eventFilter
bool MainWindow::eventFilter(QObject *obj, QEvent *ev)
{
if(!currentImageSteps->at(*currentStep))
return false;
if(obj == currentImageLabel && ev->type() == QEvent::MouseMove)
{
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(ev);
QPoint pnt = currentImageLabel->mapFromGlobal(mouseEvent->globalPos());
QColor currentPixel = currentImageSteps->at(*currentStep)->pixel(pnt);
statusBar()->showMessage(QString("%[email protected](%2,%3)").arg(currentPixel.lightness()&0xFF).arg(pnt.x()).arg(pnt.y()));
currentRubberBand->setGeometry(QRect(rbOrigin,pnt).normalized());
return true;
}
if(obj == currentImageLabel && ev->type() == QEvent::MouseButtonPress)
{
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(ev);
rbOrigin = currentImageLabel->mapFromGlobal(mouseEvent->globalPos());
currentRubberBand->setGeometry(QRect(rbOrigin,QSize()));
currentRubberBand->show();
}
if(obj == currentImageLabel && ev->type() == QEvent::MouseButtonRelease)
{
currentRubberBand->hide();
*currentImageSteps << new QImage(currentImageSteps->at(*currentStep)->copy(currentRubberBand->geometry()));
*currentStep = currentImageSteps->size()-2;
nextImage();
/*
SparseMatrix* sm = buildModel(img);
QDialog* dlg = new QDialog(this);
QHBoxLayout* mainLayout = new QHBoxLayout(dlg);
QTextEdit *edit = new QTextEdit(this);
edit->setReadOnly(true);
edit->setText(sm->toString());
edit->resize(800,600);
mainLayout->addWidget(edit);
dlg->setLayout(mainLayout);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->resize(800,600);
dlg->show();
delete sm;
*/
}
return false;
}
示例14: setColor
void ColorEditor::setColor(const QColor &c) {
this->c = c;
button->setText(QString("R/G/B/A: %1/%2/%3/%4")
.arg(c.red()).arg(c.green()).arg(c.blue()).arg(c.alpha()));
// Change colors of the button to make it nicer
QColor textColor;
if (c.lightness() > 164) {
textColor = "#000000";
} else {
textColor = "#FFFFFF";
}
QString style = QString("background-color: ") + c.name() +
"; color: " + textColor.name() + ";";
button->setStyleSheet(style);
}
示例15: storeColor
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;
}
}