void Checkbox::paintEvent(QPaintEvent *e) { Painter p(this); float64 over = a_over.current(), checked = a_checked.current(); bool cnone = (over == 0. && checked == 0.), cover = (over == 1. && checked == 0.), cchecked = (checked == 1.); bool cbad = !cnone && !cover && !cchecked; QColor color; if (cbad) { float64 onone = (1. - over) * (1. - checked), oover = over * (1. - checked), ochecked = checked; color.setRedF(_st.checkFg->c.redF() * onone + _st.checkFgOver->c.redF() * oover + _st.checkFgActive->c.redF() * ochecked); color.setGreenF(_st.checkFg->c.greenF() * onone + _st.checkFgOver->c.greenF() * oover + _st.checkFgActive->c.greenF() * ochecked); color.setBlueF(_st.checkFg->c.blueF() * onone + _st.checkFgOver->c.blueF() * oover + _st.checkFgActive->c.blueF() * ochecked); } QRect r(e->rect()); p.setClipRect(r); p.fillRect(r, _st.textBg->b); if (_checkRect.intersects(r)) { p.setRenderHint(QPainter::HighQualityAntialiasing); QPen pen; if (cbad) { pen = QPen(color); } else { pen = (cnone ? _st.checkFg : (cover ? _st.checkFgOver : _st.checkFgActive))->p; color = (cnone ? _st.checkFg : (cover ? _st.checkFgOver : _st.checkFgActive))->c; } pen.setWidth(_st.thickness); p.setPen(pen); if (checked > 0) { color.setRedF(color.redF() * checked + st::white->c.redF() * (1. - checked)); color.setGreenF(color.greenF() * checked + st::white->c.greenF() * (1. - checked)); color.setBlueF(color.blueF() * checked + st::white->c.blueF() * (1. - checked)); p.setBrush(color); } else { p.setBrush(st::white); } p.drawRoundedRect(QRectF(_checkRect).marginsRemoved(QMarginsF(_st.thickness / 2, _st.thickness / 2, _st.thickness / 2, _st.thickness / 2)), st::msgRadius, st::msgRadius); p.setRenderHint(QPainter::HighQualityAntialiasing, false); if (checked > 0) { p.drawSpriteCenter(_checkRect, _st.checkIcon); } } if (_checkRect.contains(r)) return; p.setPen(_st.textFg); p.setFont(_st.font); p.drawTextLeft(_st.textPosition.x(), _st.textPosition.y(), width(), _text, _textWidth); }
QImage DwarfClipboardPng::getTileFromScreen(DFHack::t_screen screen) { QColor foregroundColor = getForegroundColorFromScreen(screen); QColor backgroundColor = getBackgroundColorFromScreen(screen); QImage tile = tileSet->copy((screen.symbol % 16)*tileWidth,int(screen.symbol/16)*tileHeight,tileWidth,tileHeight); QImage resultImage(tileWidth,tileHeight,QImage::Format_ARGB32); for(int x = 0;x< tile.width();x++){ for(int y =0;y<tile.height();y++){ QColor color; color.setRgba(tile.pixel(x,y)); if(color == QColor("#FF00FF")){ // FF00FF is magenta resultImage.setPixel(x,y,backgroundColor.rgb()); } else{ QColor newColor; qreal alpha = color.alphaF(); qreal alpha_diff = 1-alpha; newColor.setRedF((alpha * (color.redF() * foregroundColor.redF() )) + (alpha_diff * backgroundColor.redF())); newColor.setGreenF((alpha * (color.greenF() * foregroundColor.greenF() )) + (alpha_diff * backgroundColor.greenF())); newColor.setBlueF((alpha * (color.blueF() * foregroundColor.blueF() )) + (alpha_diff * backgroundColor.blueF())); resultImage.setPixel(x,y,newColor.rgb()); } } } return(resultImage); }
OPENPSTD_SHARED_EXPORT QColor MultiColorGradient::CalcColor(float value) { auto begin = this->colors.begin(); if (value <= begin->first) { return this->colors.begin()->second; } auto last = this->colors.end(); last--; if (value >= last->first) { return last->second; } std::map<float, QColor>::iterator upperBound = this->colors.upper_bound(value); std::map<float, QColor>::iterator lowerBound = upperBound; lowerBound--; QColor result; result.setRedF(this->LinearInterpolation(lowerBound->first, lowerBound->second.redF(), upperBound->first, upperBound->second.redF(), value)); result.setGreenF( this->LinearInterpolation(lowerBound->first, lowerBound->second.greenF(), upperBound->first, upperBound->second.greenF(), value)); result.setBlueF(this->LinearInterpolation(lowerBound->first, lowerBound->second.blueF(), upperBound->first, upperBound->second.blueF(), value)); result.setAlphaF( this->LinearInterpolation(lowerBound->first, lowerBound->second.alphaF(), upperBound->first, upperBound->second.alphaF(), value)); return result; }
void DColorPicker::paintEvent(QPaintEvent *e) { QPainter pa(this); foreach (const Gradient &gradient, m_gradientList) { int row = gradient.end.x()-gradient.begin.x()+1; int column = gradient.end.y()-gradient.begin.y()+1; for(int i=0; i<row; ++i){ for(int j=0; j<column; ++j){ int top_margin = (height()-m_row*(m_cellSize+m_spacing)-m_spacing)/2; int left_margin = (width()-m_column*(m_cellSize+m_spacing)-m_spacing)/2; QRect rect(left_margin+(j+gradient.begin.y()-1)*(m_cellSize+m_spacing), top_margin+(i+gradient.begin.x()-1)*(m_cellSize+m_spacing), m_cellSize, m_cellSize); QColor c = gradient.startColor.toRgb(); QColor c2 = gradient.endColor.toRgb(); if(row>1&&column>1){ c.setRedF(c.redF()+(c2.redF()-c.redF())*i/(row-1)); c.setGreenF(c.greenF()+(c2.greenF()-c.greenF())*j/(column-1)); c.setBlueF(c.blueF()+(c2.blueF()-c.blueF())*i/(row-1)); }else if(row>1){ c.setRedF(c.redF()+(c2.redF()-c.redF())*i/(row-1)); c.setGreenF(c.greenF()+(c2.greenF()-c.greenF())*i/(row-1)); c.setBlueF(c.blueF()+(c2.blueF()-c.blueF())*i/(row-1)); }else if(column>1){ c.setRedF(c.redF()+(c2.redF()-c.redF())*j/(column-1)); c.setGreenF(c.greenF()+(c2.greenF()-c.greenF())*j/(column-1)); c.setBlueF(c.blueF()+(c2.blueF()-c.blueF())*j/(column-1)); } pa.fillRect(rect, c); if(m_currentColor.isValid()&&c.name() == m_currentColor.name()){ pa.setPen(m_selectedBorderColor); rect.setX(rect.x()-1); rect.setY(rect.y()-1); rect.setWidth(m_cellSize+1); rect.setHeight(m_cellSize+1); pa.drawRect(rect); } } } }
/* see PSColorDef in xkbprint */ bool KeyboardLayoutWidget::parseXkbColorSpec (char* colorspec, QColor& color) { long level; color.setAlphaF(1); if (strcasecmp (colorspec, "black") == 0) { color = Qt::black; } else if (strcasecmp (colorspec, "white") == 0) { color = Qt::white; } else if (strncasecmp (colorspec, "grey", 4) == 0 || strncasecmp (colorspec, "gray", 4) == 0) { level = strtol (colorspec + 4, NULL, 10); color.setRedF(1.0 - level / 100.0); color.setGreenF(1.0 - level / 100.0); color.setBlueF(1.0 - level / 100.0); } else if (strcasecmp (colorspec, "red") == 0) { color = Qt::red; } else if (strcasecmp (colorspec, "green") == 0) { color = Qt::green; } else if (strcasecmp (colorspec, "blue") == 0) { color = Qt::blue; } else if (strncasecmp (colorspec, "red", 3) == 0) { level = strtol (colorspec + 3, NULL, 10); color.setRedF(level / 100.0); color.setGreenF(0); color.setBlueF(0); } else if (strncasecmp (colorspec, "green", 5) == 0) { level = strtol (colorspec + 5, NULL, 10); color.setRedF(0); color.setGreenF(level / 100.0); color.setBlueF(0); } else if (strncasecmp (colorspec, "blue", 4) == 0) { level = strtol (colorspec + 4, NULL, 10); color.setRedF(0); color.setGreenF(0); color.setBlueF(level / 100.0); } else return false; return true; }
QColor ColorRGBToQColor(ColorRGB color) { QColor ret; ret.setRedF(color.r); ret.setGreenF(color.g); ret.setBlueF(color.b); return ret; }
QBrush linearPos(QBrush start, QBrush end, qreal pos) { QColor c; c.setRedF(linearPos(start.color().redF(), end.color().redF(), pos)); c.setGreenF(linearPos(start.color().greenF(), end.color().greenF(), pos)); c.setBlueF(linearPos(start.color().blueF(), end.color().blueF(), pos)); end.setColor(c); return end; }
QColor MediaView::nameDateColor(float64 over) { float64 mover = 1 - over; QColor result; result.setRedF(over * st::medviewNameOverColor->c.redF() + mover * st::medviewNameColor->c.redF()); result.setGreenF(over * st::medviewNameOverColor->c.greenF() + mover * st::medviewNameColor->c.greenF()); result.setBlueF(over * st::medviewNameOverColor->c.blueF() + mover * st::medviewNameColor->c.blueF()); result.setAlphaF(over * st::medviewNameOverColor->c.alphaF() + mover * st::medviewNameColor->c.alphaF()); return result; }
QColor SoRefXipLut::getColorBottom() { if (!fldColorBottom) return QColor(); QColor returnColor; returnColor.setRedF(fldColorBottom->getValue()[0]); returnColor.setGreenF(fldColorBottom->getValue()[1]); returnColor.setBlueF(fldColorBottom->getValue()[2]); return returnColor; }
void ColorPickerForm::makeColor() { QSize size = ui->label_color->size(); QImage img = QImage(size, QImage::Format_ARGB32); int div = size.height() / 6; for (int i = 0; i < size.height(); i++) { QColor col = QColor(0, 0, 0); switch (i / div) { case 0: col.setRedF(1); col.setBlueF(1.0 - (float)(div - (i - div * 0)) / div); break; case 1: col.setBlueF(1); col.setRedF((float)(div - (i - div * 1)) / div); break; case 2: col.setBlueF(1); col.setGreenF(1.0 - (float)(div - (i - div * 2)) / div); break; case 3: col.setGreenF(1); col.setBlueF((float)(div - (i - div * 3)) / div); break; case 4: col.setGreenF(1); col.setRedF(1.0 - (float)(div - (i - div * 4)) / div); break; case 5: col.setRedF(1); col.setGreenF((float)(div - (i - div * 5)) / div); break; } for (int j = 0; j < size.width(); j++) { img.setPixel(j, i, col.rgba()); } } ui->label_color->setPixmap(QPixmap::fromImage(img)); }
QColor SimDomElement::elementToColor(QDomElement element) { QColor color; color.setBlueF(element.attribute("Blue").toFloat()); color.setGreenF(element.attribute("Green").toFloat()); color.setRedF(element.attribute("Red").toFloat()); color.setAlphaF(element.attribute("Alpha").toFloat()); return color; }
QColor ColorLerp(QColor &c1, QColor &c2, float t) { QColor out; out.setRedF(clamp<float>(c1.redF() * (1 - t) + c2.redF() * t, 0.0f, 1.0f)); out.setGreenF( clamp<float>(c1.greenF() * (1 - t) + c2.greenF() * t, 0.0f, 1.0f)); out.setBlueF(clamp<float>(c1.blueF() * (1 - t) + c2.blueF() * t, 0.0f, 1.0f)); out.setAlphaF( clamp<float>(c1.alphaF() * (1 - t) + c2.alphaF() * t, 0.0f, 1.0f)); return out; }
void SourceCodeView::showSourceCode(const QString &absFileName, const int lineNum) { QString fileText = fileHash.value(absFileName); if (fileText.isNull()) { // File not in hash m_currentFileName.clear(); // Assume fileName is relative to directory QFile file(absFileName); if (!file.exists()) { clear(); appendHtml(tr("<i>File %1 not available</i>").arg(absFileName)); return; } if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { clear(); appendHtml(tr("<i>File %1 not readable</i>").arg(absFileName)); return; } const QTextCodec *codec = QTextCodec::codecForName(m_codecName); const QByteArray contents = file.readAll(); fileText = codec ? codec->toUnicode(contents) : QString::fromUtf8(contents); fileHash.insert(absFileName, fileText); } if (m_currentFileName != absFileName) { setPlainText(fileText); m_currentFileName = absFileName; } QTextCursor cursor = textCursor(); cursor.setPosition(document()->findBlockByNumber(lineNum - 1).position()); setTextCursor(cursor); centerCursor(); cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); QTextEdit::ExtraSelection selectedLine; selectedLine.cursor = cursor; // Define custom color for line selection const QColor fg = palette().color(QPalette::Highlight); const QColor bg = palette().color(QPalette::Base); QColor col; const qreal ratio = 0.25; col.setRedF(fg.redF() * ratio + bg.redF() * (1 - ratio)); col.setGreenF(fg.greenF() * ratio + bg.greenF() * (1 - ratio)); col.setBlueF(fg.blueF() * ratio + bg.blueF() * (1 - ratio)); selectedLine.format.setBackground(col); selectedLine.format.setProperty(QTextFormat::FullWidthSelection, true); setExtraSelections(QList<QTextEdit::ExtraSelection>() << selectedLine); }
void CustomColorDialog::spinBoxChanged() { if (m_blockUpdate) return; QColor newColor; newColor.setAlphaF(m_alphaSpinBox->value()); newColor.setRedF(m_rSpinBox->value()); newColor.setGreenF(m_gSpinBox->value()); newColor.setBlueF(m_bSpinBox->value()); setColor(newColor); }
QColor SetMarkedObjectPropertyDlg::gray2PseudoColor(float grayValue) { //将grayValue规范化到0~1之间 if(grayValue < 0.0) { grayValue = 0.0; } if(grayValue > 1.0) { grayValue = 1.0; } QColor pseudoColor; if(grayValue < 0.25) { pseudoColor.setRedF(0.0); pseudoColor.setGreenF(grayValue * 4.0); pseudoColor.setBlueF(1.0); } else if(grayValue < 0.5) { pseudoColor.setRedF(0.0); pseudoColor.setGreenF(1.0); pseudoColor.setBlueF(1.0 - (grayValue - 0.25) * 4.0); } else if(grayValue < 0.75) { pseudoColor.setRedF((grayValue - 0.5) * 4.0); pseudoColor.setGreenF(1.0); pseudoColor.setBlueF(0.0); } else { pseudoColor.setRedF(1.0); pseudoColor.setGreenF(1.0 - (grayValue - 0.75) * 4.0); pseudoColor.setBlueF(0.0); } return pseudoColor; }
MainView::MainView(QWindow *parent) : QQuickView(parent) { /* set the viewer background to transparent */ QColor color; color.setRedF(0.0); color.setGreenF(0.0); color.setBlueF(0.0); color.setAlphaF(0.0); setColor(color); setClearBeforeRendering(true); }
QColor ColorOperations::hsvToRgb(const QColor& hsv) { QColor rgb; rgb.setAlphaF(hsv.alphaF()); if (hsv.blueF() > 0.0) { float hue = hsv.redF()*2.0*M_PI/(60.0*M_PI/180.0); int i = floor(hue); float f = hue-i; float p = hsv.blueF()*(1.0-hsv.greenF()); float q = hsv.blueF()*(1.0-hsv.greenF()*f); float t = hsv.blueF()*(1.0-hsv.greenF()*(1.0-f)); switch (i) { case 0: rgb.setRedF(hsv.blueF()); rgb.setGreenF(t); rgb.setBlueF(p); break; case 1: rgb.setRedF(q); rgb.setGreenF(hsv.blueF()); rgb.setBlueF(p); break; case 2: rgb.setRedF(p); rgb.setGreenF(hsv.blueF()); rgb.setBlueF(t); break; case 3: rgb.setRedF(p); rgb.setGreenF(q); rgb.setBlueF(hsv.blueF()); break; case 4: rgb.setRedF(t); rgb.setGreenF(p); rgb.setBlueF(hsv.blueF()); break; default: rgb.setRedF(hsv.blueF()); rgb.setGreenF(p); rgb.setBlueF(q); break; } } else { rgb.setRedF(hsv.blueF()); rgb.setGreenF(hsv.blueF()); rgb.setBlueF(hsv.blueF()); } return rgb; }
void tst_QColor::setBlue() { QColor c = QColor(Qt::red).toHsv(); c.setBlue(127); QCOMPARE(c.red(), 255); QCOMPARE(c.green(), 0); QCOMPARE(c.blue(), 127); c = QColor(Qt::red).toHsv(); c.setBlueF(0.5); QCOMPARE(c.redF(), qreal(1.0)); QCOMPARE(c.greenF(), qreal(0.0)); QVERIFY(veryFuzzyCompare(c.blueF(), 0.5)); }
// Call named method associated to popup bool GridColourPopup::callMethod(QString methodName, ReturnValue& rv) { bool result = true; if (methodName == "TEST") return true; else if (methodName == "currentColour") { QColor newColor = ui.ColourWidget->currentColour(); double colour[4]; colour[0] = newColor.redF(); colour[1] = newColor.greenF(); colour[2] = newColor.blueF(); colour[3] = newColor.alphaF(); rv.setArray(VTypes::DoubleData, colour, 4); return true; } else if (methodName == "setCurrentColour") { bool success; QColor newColour; newColour.setRedF(rv.asDouble(0, success)); if (success) newColour.setGreenF(rv.asDouble(1, success)); if (success) newColour.setBlueF(rv.asDouble(2, success)); if (success) newColour.setAlphaF(rv.asDouble(3, success)); if (!success) { printf("Failed to get colour information from supplied ReturnValue.\n"); return false; } setCurrentColour(newColour); updateParentButtonIcon(newColour); return true; } else if (methodName == "hideEvent") { updateParentButtonIcon(ui.ColourWidget->currentColour()); return true; } else { printf("No method called '%s' is available in this popup.\n", qPrintable(methodName)); result = false; } return result; }
QColor PhongPixelProcessor::illuminatePixel(quint32 posup, quint32 posdown, quint32 posleft, quint32 posright) { qreal I; qreal Il; int totalChannels = 3; qreal computation[] = {0, 0, 0}; QColor pixelColor; normal_vector.setX(- heightmap[posright] + heightmap[posleft]); normal_vector.setY(- heightmap[posup] + heightmap[posdown]); normal_vector.setZ(8); normal_vector.normalize(); reflection_vector = (2 * pow(QVector3D::dotProduct(normal_vector, light_vector), shiny_exp)) * normal_vector - light_vector; foreach (const Illuminant &illuminant, lightSources) { for (int channel = 0; channel < totalChannels; channel++) { //I = each RGB value Il = illuminant.RGBvalue[channel]; Ia = Ka * Il; Id = Kd * Il * QVector3D::dotProduct(normal_vector, illuminant.lightVector); if (Id < 0) Id = 0; Is = Ks * Il * QVector3D::dotProduct(vision_vector, reflection_vector); if (Is < 0) Is = 0; I = Ia + Id + Is; if (I > 1) I = 1; computation[channel] += I; } } for (int channel = 0; channel < totalChannels; channel++) { if (computation[channel] > 1) computation[channel] = 1; if (computation[channel] < 0) computation[channel] = 0; } pixelColor.setRedF(computation[0]); pixelColor.setGreenF(computation[1]); pixelColor.setBlueF(computation[2]); return pixelColor; }
// Get colour for value v QColor ColourScaleDelta::colour(double value, bool useHSV) const { // Clamp 'v' to range 0.0 - 1.0 to span range of delta double clampv = (value - start_) / delta_; if (clampv < 0.0) clampv = 0.0; else if (clampv > 1.0) clampv = 1.0; QColor col; if (useHSV) { col.setHsvF(startColour_.hue() + deltaColourF_[0] * clampv, startColour_.saturationF() + deltaColourF_[1] * clampv, startColour_.valueF() + deltaColourF_[2] * clampv); } else { col.setRedF(startColour_.redF() + deltaColourF_[0] * clampv); col.setGreenF(startColour_.greenF() + deltaColourF_[1] * clampv); col.setBlueF(startColour_.blueF() + deltaColourF_[2]* clampv); } col.setAlphaF(startColour_.alphaF() + deltaColourF_[3] * clampv); return col; }
void GLWidget::createScene() { QFile democles(":Democles.dae"); m_World= GLC_Factory::instance()->createWorldFromFile(democles); m_ShuttleBoundingBox= m_World.boundingBox(); GLC_StructOccurence* pRoot= m_World.rootOccurence(); QImage texture(QString(":particle.png")); GLC_3DRep pointSprite; const float min= -20000.0f; const float max= 20000.0f; for (int i= 0; i < 300; ++i) { QColor currentColor; currentColor.setRedF(getRandomMinMax(0.4, 1.0)); currentColor.setGreenF(getRandomMinMax(0.4, 0.7)); currentColor.setBlueF(getRandomMinMax(0.4, 1.0)); GLC_Material* pMaterial= GLC_Factory::instance()->createMaterial(texture); pMaterial->setDiffuseColor(currentColor); pointSprite= GLC_Factory::instance()->createPointSprite(getRandomMinMax(5.0f, 10.0f), pMaterial); GLC_StructReference* pStructReference= new GLC_StructReference(new GLC_3DRep(pointSprite)); GLC_StructInstance* pStructInstance= new GLC_StructInstance(pStructReference); GLC_Point3d position(getRandomMinMax(min, max), getRandomMinMax(min, max), getRandomMinMax(min, max)); const double norm= position.length(); if ((norm > max) || (norm < (max / 2))) position.setLength(max); pStructInstance->translate(position); pRoot->addChild(pStructInstance); } }
void SysBtn::paintEvent(QPaintEvent *e) { QPainter p(this); int x = width() - ((_st.size.width() + _st.img.pxWidth()) / 2), y = (height() - _st.img.pxHeight()) / 2; QColor c = a_color.current(); if (_overLevel > 0) { if (_overLevel >= 1) { c = _st.overColor->c; } else { c.setRedF(c.redF() * (1 - _overLevel) + _st.overColor->c.redF() * _overLevel); c.setGreenF(c.greenF() * (1 - _overLevel) + _st.overColor->c.greenF() * _overLevel); c.setBlueF(c.blueF() * (1 - _overLevel) + _st.overColor->c.blueF() * _overLevel); } } p.fillRect(x, y, _st.img.pxWidth(), _st.img.pxHeight(), c); p.drawPixmap(QPoint(x, y), App::sprite(), _st.img); if (!_text.isEmpty()) { p.setFont(st::titleTextButton.font->f); p.setPen(c); p.drawText((_st.size.width() - _st.img.pxWidth()) / 2, st::titleTextButton.textTop + st::titleTextButton.font->ascent, _text); } }
QColor KarbonGradientHelper::colorAt(qreal position, const QGradientStops &stops) { if (! stops.count()) return QColor(); if (stops.count() == 1) return stops.first().second; QGradientStop prevStop(-1.0, QColor()); QGradientStop nextStop(2.0, QColor()); // find framing gradient stops foreach(const QGradientStop & stop, stops) { if (stop.first > prevStop.first && stop.first < position) prevStop = stop; if (stop.first < nextStop.first && stop.first > position) nextStop = stop; } QColor theColor; if (prevStop.first < 0.0) { // new stop is before the first stop theColor = nextStop.second; } else if (nextStop.first > 1.0) { // new stop is after the last stop theColor = prevStop.second; } else { // linear interpolate colors between framing stops QColor prevColor = prevStop.second, nextColor = nextStop.second; qreal colorScale = (position - prevStop.first) / (nextStop.first - prevStop.first); theColor.setRedF(prevColor.redF() + colorScale *(nextColor.redF() - prevColor.redF())); theColor.setGreenF(prevColor.greenF() + colorScale *(nextColor.greenF() - prevColor.greenF())); theColor.setBlueF(prevColor.blueF() + colorScale *(nextColor.blueF() - prevColor.blueF())); theColor.setAlphaF(prevColor.alphaF() + colorScale *(nextColor.alphaF() - prevColor.alphaF())); } return theColor; }
QColor Palette::getColor(double value) const { QMap<unsigned int, QColor>::const_iterator pos = colorMap.begin(); QColor ret; while ((pos != colorMap.end()) && (pos.key() < value)) { pos++; } if ((colorMap.size() == 1) || (pos == colorMap.begin())) { ret = pos.value(); } else if (pos == colorMap.end()) { ret = pos.value(); } else { double factor = (value-(pos-1).key())/((pos.key())-((pos-1).key())); ret.setRedF((1-factor)*(pos-1).value().redF()+(factor)*pos.value().redF()); ret.setGreenF((1-factor)*(pos-1).value().greenF()+(factor)*pos.value().greenF()); ret.setBlueF((1-factor)*(pos-1).value().blueF()+(factor)*pos.value().blueF()); ret.setAlphaF((1-factor)*(pos-1).value().alphaF()+(factor)*pos.value().alphaF()); } return ret; }
void SnapHelperEffect::postPaintScreen() { effects->postPaintScreen(); if (m_timeline.currentValue() != 0.0) { // Display the guide if (effects->isOpenGLCompositing()) { GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); vbo->reset(); vbo->setUseColor(true); ShaderBinder binder(ShaderManager::ColorShader); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); QColor color; color.setRedF(0.5); color.setGreenF(0.5); color.setBlueF(0.5); color.setAlphaF(m_timeline.currentValue() * 0.5); vbo->setColor(color); glLineWidth(4.0); QVector<float> verts; verts.reserve(effects->numScreens() * 24); for (int i = 0; i < effects->numScreens(); ++i) { const QRect& rect = effects->clientArea(ScreenArea, i, 0); int midX = rect.x() + rect.width() / 2; int midY = rect.y() + rect.height() / 2 ; int halfWidth = m_window->width() / 2; int halfHeight = m_window->height() / 2; // Center lines verts << rect.x() + rect.width() / 2 << rect.y(); verts << rect.x() + rect.width() / 2 << rect.y() + rect.height(); verts << rect.x() << rect.y() + rect.height() / 2; verts << rect.x() + rect.width() << rect.y() + rect.height() / 2; // Window outline // The +/- 2 is to prevent line overlap verts << midX - halfWidth + 2 << midY - halfHeight; verts << midX + halfWidth + 2 << midY - halfHeight; verts << midX + halfWidth << midY - halfHeight + 2; verts << midX + halfWidth << midY + halfHeight + 2; verts << midX + halfWidth - 2 << midY + halfHeight; verts << midX - halfWidth - 2 << midY + halfHeight; verts << midX - halfWidth << midY + halfHeight - 2; verts << midX - halfWidth << midY - halfHeight - 2; } vbo->setData(verts.count() / 2, 2, verts.data(), NULL); vbo->render(GL_LINES); glDisable(GL_BLEND); glLineWidth(1.0); } if ( effects->compositingType() == XRenderCompositing ) { #ifdef KWIN_HAVE_XRENDER_COMPOSITING for (int i = 0; i < effects->numScreens(); ++i) { const QRect& rect = effects->clientArea( ScreenArea, i, 0 ); int midX = rect.x() + rect.width() / 2; int midY = rect.y() + rect.height() / 2 ; int halfWidth = m_window->width() / 2; int halfHeight = m_window->height() / 2; xcb_rectangle_t rects[6]; // Center lines rects[0].x = rect.x() + rect.width() / 2 - 2; rects[0].y = rect.y(); rects[0].width = 4; rects[0].height = rect.height(); rects[1].x = rect.x(); rects[1].y = rect.y() + rect.height() / 2 - 2; rects[1].width = rect.width(); rects[1].height = 4; // Window outline // The +/- 4 is to prevent line overlap rects[2].x = midX - halfWidth + 4; rects[2].y = midY - halfHeight; rects[2].width = 2*halfWidth - 4; rects[2].height = 4; rects[3].x = midX + halfWidth - 4; rects[3].y = midY - halfHeight + 4; rects[3].width = 4; rects[3].height = 2*halfHeight - 4; rects[4].x = midX - halfWidth; rects[4].y = midY + halfHeight - 4; rects[4].width = 2*halfWidth - 4; rects[4].height = 4; rects[5].x = midX - halfWidth; rects[5].y = midY - halfHeight; rects[5].width = 4; rects[5].height = 2*halfHeight - 4; xcb_render_fill_rectangles(xcbConnection(), XCB_RENDER_PICT_OP_OVER, effects->xrenderBufferPicture(), preMultiply(QColor(128, 128, 128, m_timeline.currentValue()*128)), 6, rects); } #endif } if (effects->compositingType() == QPainterCompositing) { QPainter *painter = effects->scenePainter(); painter->save(); QColor color; color.setRedF(0.5); color.setGreenF(0.5); color.setBlueF(0.5); color.setAlphaF(m_timeline.currentValue() * 0.5); QPen pen(color); pen.setWidth(4); painter->setPen(pen); painter->setBrush(Qt::NoBrush); for (int i = 0; i < effects->numScreens(); ++i) { const QRect &rect = effects->clientArea(ScreenArea, i, 0); // Center lines painter->drawLine(rect.center().x(), rect.y(), rect.center().x(), rect.y() + rect.height()); painter->drawLine(rect.x(), rect.center().y(), rect.x() + rect.width(), rect.center().y()); // window outline QRect windowRect(rect.center(), m_window->geometry().size()); painter->drawRect(windowRect.translated(-windowRect.width()/2, -windowRect.height()/2)); } painter->restore(); } } else if (m_window && !m_active) { if (m_window->isDeleted()) m_window->unrefWindow(); m_window = NULL; } }
void Radiobutton::paintEvent(QPaintEvent *e) { Painter p(this); float64 over = a_over.current(), checked = a_checked.current(); bool cnone = (over == 0. && checked == 0.), cover = (over == 1. && checked == 0.), cchecked = (checked == 1.); bool cbad = !cnone && !cover && !cchecked; QColor color; if (cbad) { float64 onone = (1. - over) * (1. - checked), oover = over * (1. - checked), ochecked = checked; color.setRedF(_st.checkFg->c.redF() * onone + _st.checkFgOver->c.redF() * oover + _st.checkFgActive->c.redF() * ochecked); color.setGreenF(_st.checkFg->c.greenF() * onone + _st.checkFgOver->c.greenF() * oover + _st.checkFgActive->c.greenF() * ochecked); color.setBlueF(_st.checkFg->c.blueF() * onone + _st.checkFgOver->c.blueF() * oover + _st.checkFgActive->c.blueF() * ochecked); } QRect r(e->rect()); p.setClipRect(r); p.fillRect(r, _st.textBg->b); if (_checkRect.intersects(r)) { p.setRenderHint(QPainter::HighQualityAntialiasing); QPen pen; if (cbad) { pen = QPen(color); } else { pen = (cnone ? _st.checkFg : (cover ? _st.checkFgOver : _st.checkFgActive))->p; } pen.setWidth(_st.thickness); p.setPen(pen); p.setBrush(Qt::NoBrush); //int32 skip = qCeil(_st.thickness / 2); //p.drawEllipse(_checkRect.marginsRemoved(QMargins(skip, skip, skip, skip))); p.drawEllipse(QRectF(_checkRect).marginsRemoved(QMarginsF(_st.thickness / 2, _st.thickness / 2, _st.thickness / 2, _st.thickness / 2))); if (checked > 0) { p.setPen(Qt::NoPen); if (cbad) { p.setBrush(color); } else { p.setBrush(cnone ? _st.checkFg : (cover ? _st.checkFgOver : _st.checkFgActive)); } float64 skip0 = _checkRect.width() / 2., skip1 = _st.checkSkip / 10., checkSkip = skip0 * (1. - checked) + skip1 * checked; p.drawEllipse(QRectF(_checkRect).marginsRemoved(QMarginsF(checkSkip, checkSkip, checkSkip, checkSkip))); //int32 fskip = qFloor(checkSkip), cskip = qCeil(checkSkip); //if (2 * fskip < _checkRect.width()) { // if (fskip != cskip) { // p.setOpacity(float64(cskip) - checkSkip); // p.drawEllipse(_checkRect.marginsRemoved(QMargins(fskip, fskip, fskip, fskip))); // p.setOpacity(1.); // } // if (2 * cskip < _checkRect.width()) { // p.drawEllipse(_checkRect.marginsRemoved(QMargins(cskip, cskip, cskip, cskip))); // } //} } p.setRenderHint(QPainter::HighQualityAntialiasing, false); } if (_checkRect.contains(r)) return; p.setPen(_st.textFg); p.setFont(_st.font); p.drawTextLeft(_st.textPosition.x(), _st.textPosition.y(), width(), _text, _textWidth); }
void KnobGuiParametric::createWidget(QHBoxLayout* layout) { boost::shared_ptr<KnobParametric> knob = _knob.lock(); QObject::connect( knob.get(), SIGNAL(curveChanged(int)), this, SLOT(onCurveChanged(int)) ); boost::shared_ptr<OfxParamOverlayInteract> interact = knob->getCustomInteract(); //layout->parentWidget()->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); treeColumn = new QWidget( layout->parentWidget() ); QVBoxLayout* treeColumnLayout = new QVBoxLayout(treeColumn); treeColumnLayout->setContentsMargins(0, 0, 0, 0); _tree = new QTreeWidget( layout->parentWidget() ); _tree->setSelectionMode(QAbstractItemView::ContiguousSelection); _tree->setColumnCount(1); _tree->header()->close(); if ( hasToolTip() ) { _tree->setToolTip( toolTip() ); } treeColumnLayout->addWidget(_tree); _resetButton = new Button(QString::fromUtf8("Reset"), treeColumn); _resetButton->setToolTip( GuiUtils::convertFromPlainText(tr("Reset the selected curves in the tree to their default shape."), Qt::WhiteSpaceNormal) ); QObject::connect( _resetButton, SIGNAL(clicked()), this, SLOT(resetSelectedCurves()) ); treeColumnLayout->addWidget(_resetButton); layout->addWidget(treeColumn); _curveWidget = new CurveWidget( getGui(), this, boost::shared_ptr<TimeLine>(), layout->parentWidget() ); _curveWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); if (interact) { _curveWidget->setCustomInteract(interact); } if ( hasToolTip() ) { _curveWidget->setToolTip( toolTip() ); } layout->addWidget(_curveWidget); KnobGuiPtr thisShared = shared_from_this(); std::vector<boost::shared_ptr<CurveGui> > visibleCurves; for (int i = 0; i < knob->getDimension(); ++i) { QString curveName = QString::fromUtf8( knob->getDimensionName(i).c_str() ); boost::shared_ptr<KnobCurveGui> curve( new KnobCurveGui(_curveWidget, knob->getParametricCurve(i), thisShared, i, curveName, QColor(255, 255, 255), 1.) ); _curveWidget->addCurveAndSetColor(curve); QColor color; double r, g, b; knob->getCurveColor(i, &r, &g, &b); color.setRedF(r); color.setGreenF(g); color.setBlueF(b); curve->setColor(color); QTreeWidgetItem* item = new QTreeWidgetItem(_tree); item->setText(0, curveName); item->setSelected(true); CurveDescriptor desc; desc.curve = curve; desc.treeItem = item; _curves.push_back(desc); if ( curve->isVisible() ) { visibleCurves.push_back(curve); } } _curveWidget->centerOn(visibleCurves); QObject::connect( _tree, SIGNAL(itemSelectionChanged()), this, SLOT(onItemsSelectionChanged()) ); } // createWidget
QVariant RelationshipView::itemChange(GraphicsItemChange change, const QVariant &value) { if(change==ItemPositionChange) { this->setFlag(QGraphicsItem::ItemIsMovable, false); } else if(change==ItemSelectedHasChanged) { unsigned i, count; QPen pen; QColor color; this->setSelectionOrder(value.toBool()); pos_info_pol->setVisible(value.toBool()); pos_info_txt->setVisible(value.toBool()); obj_selection->setVisible(value.toBool()); this->configurePositionInfo(); for(i=0; i < 3; i++) { if(labels[i]) labels[i]->itemChange(change, value); } //Show tha graphical points if 'value' is true count=graph_points.size(); for(i=0; i < count; i++) graph_points[i]->setVisible(value.toBool()); //Alter the relationship line color when it is selected if(value.toBool()) { QColor cor1=BaseObjectView::getBorderStyle(ParsersAttributes::OBJ_SELECTION).color(), cor2=BaseObjectView::getBorderStyle(ParsersAttributes::RELATIONSHIP).color(); color.setRedF((cor1.redF() + cor2.greenF())/2.0f); color.setGreenF((cor1.greenF() + cor2.greenF())/2.0f); color.setBlueF((cor1.blueF() + cor2.blueF())/2.0f); } else color=BaseObjectView::getBorderStyle(ParsersAttributes::RELATIONSHIP).color(); count=lines.size(); for(i=0; i < count; i++) { pen=lines[i]->pen(); pen.setColor(color); lines[i]->setPen(pen); } //Shows/hides the attribute's selection count=attributes.size(); for(i=0; i < count; i++) attributes[i]->childItems().at(3)->setVisible(value.toBool()); emit s_objectSelected(dynamic_cast<BaseGraphicObject *>(this->getSourceObject()), value.toBool()); } return(value); }
//----------------------------------------------------------- QVariant OGRelacionamento::itemChange(GraphicsItemChange change, const QVariant &value) { //Caso seja uma mudança na posição if(change==ItemPositionChange) { //Força o relacionamento a não ser movimentável this->setFlag(QGraphicsItem::ItemIsMovable, false); } //Caso a mundança no objeto foi a de seleção ou deseleção else if(change==ItemSelectedHasChanged) { unsigned i, qtd; QPen pen; QColor cor; if(value.toBool()) this->ordem_selecao=++ObjetoGrafico::ordem_selecao_global; emit s_objetoSelecionado(dynamic_cast<ObjetoGraficoBase *>(this->obterObjetoOrigem()), value.toBool()); pol_info_pos->setVisible(value.toBool()); txt_info_pos->setVisible(value.toBool()); selecao_obj->setVisible(value.toBool()); this->configurarInfoPosicao(); //Seleciona ou não os rótulos conforme o parâmetro 'value' for(i=0; i < 3; i++) { if(rotulos[i]) rotulos[i]->itemChange(change, value); } //Deixa visível os pontos do relacionamento caso 'value' seja true qtd=pontos_graf.size(); for(i=0; i < qtd; i++) pontos_graf[i]->setVisible(value.toBool()); /* Caso o relacionamento está selecionado (value = true) as linhas do relacionamento tem sua cor alterada para denotar que as mesmas também estão selecionadas */ if(value.toBool()) { QColor cor1=ObjetoGrafico::obterEstiloBorda(AtributosParsers::SELECAO_OBJETO).color(), cor2=ObjetoGrafico::obterEstiloBorda(AtributosParsers::RELACIONAMENTO).color(); cor.setRedF((cor1.redF() + cor2.greenF())/2.0f); cor.setGreenF((cor1.greenF() + cor2.greenF())/2.0f); cor.setBlueF((cor1.blueF() + cor2.blueF())/2.0f); } else cor=ObjetoGrafico::obterEstiloBorda(AtributosParsers::RELACIONAMENTO).color(); //Aplica a cor nas linhas do relacionamento qtd=linhas.size(); for(i=0; i < qtd; i++) { pen=linhas[i]->pen(); pen.setColor(cor); linhas[i]->setPen(pen); } //Exibe/esconde a seleção dos atributos qtd=atributos.size(); for(i=0; i < qtd; i++) atributos[i]->children().at(3)->setVisible(value.toBool()); } return(value); }