WaitingDialog::WaitingDialog(QWidget *parent) : QDialog(parent), ui(new Ui::WaitingDialog) { ui->setupUi(this); m_rot = 0; QGraphicsScene* scene = new QGraphicsScene(); ui->graphicsView->setScene(scene); QRect rect(0,0,50,50); m_startPoint = QPoint(0,ui->graphicsView->rect().size().height()/2); m_endPoint = QPoint(ui->graphicsView->rect().size().width(),ui->graphicsView->rect().size().height()/2); QRadialGradient rg = QRadialGradient(10,10,45.0); QColor mcol(Qt::blue); mcol.setAlpha(255); rg.setColorAt(0.0,Qt::white); mcol.setBlue(mcol.blue()-15); rg.setColorAt(0.5,mcol); mcol.setBlue(mcol.blue()+15); rg.setColorAt(1.0,mcol); QPen pen(mcol); QPixmap pm(rect.size()+QSize(1,1)); pm.fill(Qt::transparent); QPainter p(&pm); p.setBackgroundMode(Qt::TransparentMode); p.setBrush(rg); p.setPen(pen); p.drawEllipse(rect); m_ellipse = new MyItem(pm); m_ellipse->setPos(m_startPoint); ui->graphicsView->scene()->addItem(m_ellipse); m_anim = new QPropertyAnimation(m_ellipse,"pos"); connect(m_anim,SIGNAL(finished()),this,SLOT(animFinished())); m_anim->setEasingCurve(QEasingCurve::OutBounce); m_anim->setStartValue(m_startPoint); m_anim->setEndValue(m_endPoint); m_anim->setDuration(2000); m_anim->setLoopCount(1); m_anim->start(); m_timer = new QTimer(this); connect(m_timer,SIGNAL(timeout()),this,SLOT(timeout())); m_timer->setInterval(100); #if defined(Q_OS_SYMBIAN) this->showMaximized(); #else this->show(); #endif m_timer->start(); }
void PreviewWidget::drawShadow(QPainter &painter, QRectF rect) { // Shadow width int width = qBound(4, int(qMax(rect.height(), rect.width())) / 100, 7); painter.save(); painter.setClipRect(rect.adjusted(0, 0, width, width)); QColor lightColor = this->palette().color(QPalette::Background); QColor darkColor = lightColor.darker(160); QRectF shadowRect = rect.adjusted(0, 0, width, width); QLinearGradient lg; lg.setColorAt(0.0, darkColor); lg.setColorAt(1.0, lightColor); QRadialGradient rg; rg.setColorAt(0, darkColor); rg.setColorAt(1, lightColor); rg.setRadius(width); // Right lg.setStart(QPointF(rect.right(), rect.center().y())); lg.setFinalStop(QPointF(shadowRect.right(), rect.center().y())); painter.fillRect(rect.right(), rect.top() + width, width, rect.height() - width, lg); // Bottom lg.setStart(rect.center().x(), rect.bottom()); lg.setFinalStop(rect.center().x(), rect.bottom() + width); painter.fillRect(rect.left() + width, rect.bottom(), rect.width() - width, width, lg); //TopRight QPointF p; p = rect.bottomRight(); rg.setCenter(p); rg.setFocalPoint(p); painter.fillRect(rect.right(), rect.bottom(), width, width, rg); // BottomRight p = rect.topRight(); p.ry() += width; rg.setCenter(p); rg.setFocalPoint(p); painter.fillRect(rect.right(), rect.top(), width, width, rg); //BottomLeft p = rect.bottomLeft(); p.rx() += width; rg.setCenter(p); rg.setFocalPoint(p); painter.fillRect(rect.left(), rect.bottom(), width, width, rg); painter.restore(); }
void DashBar::repaint(QPainter &painter){ float v; float min = qMin(value1,value2); float max = qMax(value1,value2); int size = orientation == Qt::Horizontal? width-10 : height-10; QRadialGradient gradient; QPen pen(Qt::black); pen.setWidth(1); painter.save(); painter.setRenderHint(QPainter::Antialiasing); painter.translate(x,y); gradient = QRadialGradient(QPointF(0,0), qSqrt(width*width+height*height)*2, QPointF(0,0)); gradient.setColorAt(0, QColor(224,224,224)); gradient.setColorAt(1, QColor(28,28,28)); painter.setPen(pen); painter.setBrush(QBrush(gradient)); painter.drawRect(0,0,width, height); gradient = QRadialGradient(QPointF(width,height), qSqrt(width*width+height*height)*2, QPointF(width,height)); gradient.setColorAt(0, QColor(88,88,88)); gradient.setColorAt(1, QColor(28,28,28)); painter.setPen(pen); painter.setBrush(QBrush(gradient)); painter.drawRect(5,5,width-10,height-10); painter.setBrush(Qt::white); painter.setPen(Qt::white); if(value>max)value = max; if(value<min)value = min; v = (max-value)/(max-min)*size; for(int i=0; i<size; i+=4){ if(i>size*0.4f){ painter.setPen(i>=v || isSelected? Qt::green : QColor(Qt::green).darker()); }else if(i>=size*0.1f && i<=size*0.4f){ painter.setPen(i>=v || isSelected? Qt::yellow : QColor(Qt::yellow).darker()); }else{ painter.setPen(i>=v || isSelected? Qt::red : QColor(Qt::red).darker()); } if(orientation == Qt::Horizontal){ //Orizzontale painter.drawLine(width-6-i,6,width-6-i,height-6); //Linee verticali }else{ painter.drawLine(6,6+i,width-6,6+i); } } painter.restore(); }
void BrushEngine::paint(const QPointF& point, float pressure) { QPainter painter(eraser > 50 ? canvasItem->getPixmap() : canvasBuffer->getPixmap()); painter.setRenderHint(QPainter::Antialiasing, true); painter.setPen(Qt::NoPen); if (eraser > 50) { painter.setCompositionMode(QPainter::CompositionMode_DestinationOut); } color.setAlpha(qRound(255 * flow / 100.0)); QColor pressureColor = color; pressureColor.setAlpha(qRound(color.alpha() * pressure)); QColor alphaColor = color; alphaColor.setAlpha(0); QRadialGradient radialGradient; radialGradient.setRadius(size / 2.0); radialGradient.setColorAt(0, pressureColor); radialGradient.setColorAt(1, alphaColor); radialGradient.setColorAt(hardness / 100.0, pressureColor); painter.setBrush(QBrush(radialGradient)); if (startPoint.isNull()) { startPoint = QPointF(point); lastPoint = QPointF(point); topleft = QPoint(0, 0); bottomright = QPoint(canvasBuffer->getPixmap()->width(), canvasBuffer->getPixmap()->height()); paintDab(point, painter); } else { qreal length = qSqrt(qPow(lastPoint.x() - point.x(), 2) + qPow(lastPoint.y() - point.y(), 2)); qreal delta = size * spacing / 2.0 / 100.0; if (length >= delta) { int dabs = qRound(length / delta); qreal angle = qAtan2(point.x() - lastPoint.x(), point.y() - lastPoint.y()); qreal deltaX = delta * qSin(angle); qreal deltaY = delta * qCos(angle); QPointF betweenPoint; for (int i = 1; i <= dabs; i++) { qreal x = lastPoint.x() + deltaX * i + (10000 - qrand() % 20000) / 10000.0 * size * jitter / 100; qreal y = lastPoint.y() + deltaY * i + (10000 - qrand() % 20000) / 10000.0 * size * jitter / 100; betweenPoint = QPointF(x, y); paintDab(betweenPoint, painter); } lastPoint = betweenPoint; } } }
KoShape * KoEllipseShapeFactory::createDefaultShape() const { KoEllipseShape * ellipse = new KoEllipseShape(); ellipse->setBorder( new KoLineBorder( 1.0 ) ); ellipse->setShapeId( KoPathShapeId ); QRadialGradient * gradient = new QRadialGradient( QPointF(50,50), 50.0, QPointF(25,25) ); gradient->setColorAt( 0.0, Qt::white ); gradient->setColorAt( 1.0, Qt::green ); ellipse->setBackground( new KoGradientBackground( gradient ) ); return ellipse; }
KoShape *EllipseShapeFactory::createDefaultShape(KoDocumentResourceManager *) const { EllipseShape *ellipse = new EllipseShape(); ellipse->setStroke(new KoShapeStroke(1.0)); ellipse->setShapeId(KoPathShapeId); QRadialGradient *gradient = new QRadialGradient(QPointF(0.5,0.5), 0.5, QPointF(0.25,0.25)); gradient->setCoordinateMode(QGradient::ObjectBoundingMode); gradient->setColorAt(0.0, Qt::white); gradient->setColorAt(1.0, Qt::green); ellipse->setBackground(new KoGradientBackground(gradient)); return ellipse; }
KoStopGradient * KoStopGradient::fromQGradient(QGradient * gradient) { if (! gradient) return 0; KoStopGradient * newGradient = new KoStopGradient(""); newGradient->setType(gradient->type()); newGradient->setSpread(gradient->spread()); switch (gradient->type()) { case QGradient::LinearGradient: { QLinearGradient * g = static_cast<QLinearGradient*>(gradient); newGradient->m_start = g->start(); newGradient->m_stop = g->finalStop(); newGradient->m_focalPoint = g->start(); break; } case QGradient::RadialGradient: { QRadialGradient * g = static_cast<QRadialGradient*>(gradient); newGradient->m_start = g->center(); newGradient->m_stop = g->center() + QPointF(g->radius(), 0); newGradient->m_focalPoint = g->focalPoint(); break; } case QGradient::ConicalGradient: { QConicalGradient * g = static_cast<QConicalGradient*>(gradient); qreal radian = g->angle() * M_PI / 180.0; newGradient->m_start = g->center(); newGradient->m_stop = QPointF(100.0 * cos(radian), 100.0 * sin(radian)); newGradient->m_focalPoint = g->center(); break; } default: delete newGradient; return 0; } Q_FOREACH (const QGradientStop & stop, gradient->stops()) { KoColor color(newGradient->colorSpace()); color.fromQColor(stop.second); newGradient->m_stops.append(KoGradientStop(stop.first, color)); } return newGradient; }
void EditorMagnifierItem::updateMask() { QRectF current = getRect(); QSize box = QSize( current.width(), current.width() ); // reupdate our mask if (m_imgMask.size() != box) { int radius = box.width() / 2; int ring = radius - 10; m_imgMask = QPixmap(box); m_imgMask.fill(Qt::transparent); QRadialGradient g; g.setCenter(radius, radius); g.setFocalPoint(radius, radius); g.setRadius(radius); g.setColorAt( 1.0, QColor(255, 255, 255, 0) ); g.setColorAt( 0.5, QColor(128, 128, 128, 255) ); QPainter mask(&m_imgMask); mask.setRenderHint(QPainter::Antialiasing); mask.setCompositionMode(QPainter::CompositionMode_Source); mask.setBrush(g); mask.setPen(Qt::NoPen); mask.drawRect( m_imgMask.rect() ); mask.setBrush( QColor(Qt::transparent) ); mask.drawEllipse(g.center(), ring, ring); mask.end(); } }
static PyObject *meth_QRadialGradient_center(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { QRadialGradient *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QRadialGradient, &sipCpp)) { QPointF *sipRes; Py_BEGIN_ALLOW_THREADS sipRes = new QPointF(sipCpp->center()); Py_END_ALLOW_THREADS return sipConvertFromNewType(sipRes,sipType_QPointF,NULL); } }
int MailTreeDelegate::DrawMessageActionIcons (QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index, int height) const { if (Mode_ != MailListMode::Normal) return 0; if (option.state & QStyle::State_MouseOver) return 0; const auto& actionsVar = index.data (MailModel::MailRole::MessageActions); if (actionsVar.isNull ()) return 0; auto actionInfos = actionsVar.value<QList<MessageListActionInfo>> (); if (actionInfos.isEmpty ()) return 0; std::reverse (actionInfos.begin (), actionInfos.end ()); if (ActionsHintsBalls_) height -= Padding * 2; painter->save (); painter->setRenderHint (QPainter::Antialiasing); painter->setPen (Qt::NoPen); auto rect = option.rect; rect.setLeft (rect.right () - height - Padding); rect.setSize ({ height, height }); rect.moveTop (rect.top () + Padding); for (const auto& item : actionInfos) { if (item.Flags_ & MessageListActionFlag::AlwaysPresent) continue; if (ActionsHintsBalls_) { QRadialGradient gradient; gradient.setCoordinateMode (QGradient::ObjectBoundingMode); gradient.setFocalPoint ({ 0.3, 0.3 }); gradient.setCenter ({ 0.5, 0.5 }); gradient.setRadius (0.5); gradient.setColorAt (0, item.ReprColor_.lighter (200)); gradient.setColorAt (1, item.ReprColor_.darker (120)); painter->setBrush (gradient); painter->drawEllipse (rect); } else item.Icon_.paint (painter, rect); rect.moveLeft (rect.left () - height - Padding); } painter->restore (); return option.rect.right () - rect.right (); }
static QGradient loadGradient(const QDomElement &elem) { if (elem.tagName() != QLatin1String("gradientData")) return QLinearGradient(); const QGradient::Type type = stringToGradientType(elem.attribute(QLatin1String("type"))); const QGradient::Spread spread = stringToGradientSpread(elem.attribute(QLatin1String("spread"))); const QGradient::CoordinateMode mode = stringToGradientCoordinateMode(elem.attribute(QLatin1String("coordinateMode"))); QGradient gradient = QLinearGradient(); if (type == QGradient::LinearGradient) { QLinearGradient g; g.setStart(elem.attribute(QLatin1String("startX")).toDouble(), elem.attribute(QLatin1String("startY")).toDouble()); g.setFinalStop(elem.attribute(QLatin1String("endX")).toDouble(), elem.attribute(QLatin1String("endY")).toDouble()); gradient = g; } else if (type == QGradient::RadialGradient) { QRadialGradient g; g.setCenter(elem.attribute(QLatin1String("centerX")).toDouble(), elem.attribute(QLatin1String("centerY")).toDouble()); g.setFocalPoint(elem.attribute(QLatin1String("focalX")).toDouble(), elem.attribute(QLatin1String("focalY")).toDouble()); g.setRadius(elem.attribute(QLatin1String("radius")).toDouble()); gradient = g; } else if (type == QGradient::ConicalGradient) { QConicalGradient g; g.setCenter(elem.attribute(QLatin1String("centerX")).toDouble(), elem.attribute(QLatin1String("centerY")).toDouble()); g.setAngle(elem.attribute(QLatin1String("angle")).toDouble()); gradient = g; } QDomElement stopElem = elem.firstChildElement(); while (!stopElem.isNull()) { QGradientStop stop = loadGradientStop(stopElem); gradient.setColorAt(stop.first, stop.second); stopElem = stopElem.nextSiblingElement(); } gradient.setSpread(spread); gradient.setCoordinateMode(mode); return gradient; }
void StyleLoader::loadComposite(QRadialGradient& value) { int coordinateMode; int spread; QPointF center; QPointF focal; double radius; QGradientStops stopPoints; load("coordinateMode", coordinateMode); load("spread", spread); load("centerPoint", center); load("focalPoint", focal); load("radius", radius); load("stopPoints", stopPoints); value = QRadialGradient(center, radius, focal); value.setSpread((QGradient::Spread) spread); value.setCoordinateMode((QGradient::CoordinateMode) coordinateMode); value.setStops(stopPoints); }
void RadialVolumeWidgetPrivate::paintBackground() // QGradient is soooo sloooow { QPainter p(&bg); p.setRenderHint(QPainter::Antialiasing, true); int r = spectrum.radius(); QPoint c = spectrum.center().toPoint(); p.setBrush(spectrum); p.setPen(QPen(Qt::NoPen)); p.drawEllipse(c.x()-r, c.y()-r, 2*r, 2*r); // Gradient background p.setBrush(QBrush()); // Do not fill //p.setPen(QPen(QColor(255, 255, 255, 160), 0, Qt::DashLine)); for (int i=0; i<n_levels; i++) { int l_r = r*levels[i]; p.setPen(QPen(QColor(255, 255, 255, 255-(180*(i+1))/n_levels), 1, Qt::DashLine)); p.drawEllipse(c.x()-l_r, c.y()-l_r, 2*l_r, 2*l_r); } }
void BitmapImage::drawRect(QRectF rectangle, QPen pen, QBrush brush, QPainter::CompositionMode cm, bool antialiasing) { int width = pen.width(); setCompositionModeBounds(rectangle.adjusted(-width, -width, width, width).toRect(), true, cm); if (brush.style() == Qt::RadialGradientPattern) { QRadialGradient* gradient = (QRadialGradient*)brush.gradient(); gradient->setCenter(gradient->center() - mBounds.topLeft()); gradient->setFocalPoint(gradient->focalPoint() - mBounds.topLeft()); } if (!image()->isNull()) { QPainter painter(image()); painter.setCompositionMode(cm); painter.setRenderHint(QPainter::Antialiasing, antialiasing); painter.setPen(pen); painter.setBrush(brush); painter.drawRect(rectangle.translated(-mBounds.topLeft())); painter.end(); } modification(); }
void ConvertDialogTest::convert_filter_gradient() { EffectsScrollArea *effectsScrollArea = convertDialog->effectsScrollArea; QGroupBox *filterGroupBox = effectsScrollArea->filterGroupBox; filterGroupBox->setChecked(true); QRadioButton *filterGradientRadioButton = effectsScrollArea->filterGradientRadioButton; filterGradientRadioButton->setChecked(true); QRadialGradient gradient = QRadialGradient(QPoint(1, 2), 2.5); gradient.setColorAt(0.0, Qt::green); gradient.setColorAt(1.0, Qt::red); BrushFrame *filterBrushFrame = effectsScrollArea->filterBrushFrame; filterBrushFrame->setBrush(gradient); convertDialog->convert(); SharedInformation *sharedInfo = convertDialog->sharedInfo; EffectsConfiguration conf = sharedInfo->effectsConfiguration(); QCOMPARE(conf.getFilterType(), int(Gradient)); QCOMPARE(conf.getFilterBrush(), QBrush(gradient)); }
void BitmapImage::drawEllipse( QRectF rectangle, QPen pen, QBrush brush, QPainter::CompositionMode cm, bool antialiasing) { int width = pen.width(); extend( rectangle.adjusted(-width,-width,width,width).toRect() ); if (brush.style() == Qt::RadialGradientPattern) { QRadialGradient* gradient = (QRadialGradient*)brush.gradient(); gradient->setCenter( gradient->center() - topLeft() ); gradient->setFocalPoint( gradient->focalPoint() - topLeft() ); } if (mImage != NULL && !mImage->isNull() ) { QPainter painter(mImage); painter.setCompositionMode(cm); painter.setRenderHint(QPainter::Antialiasing, antialiasing); painter.setPen(pen); painter.setBrush(brush); //if (brush == Qt::NoBrush) painter.drawEllipse( rectangle.translated(-topLeft()) ); painter.end(); } }
void Point::paint ( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * /*widget*/ ) { QRadialGradient gradient ( 0.0, 0.0, _radius ); // If we are selected, use a lighter color. if ( option->state & QStyle::State_Sunken ) { gradient.setColorAt ( 0, QColor ( Qt::yellow ).light ( 120 ) ); gradient.setColorAt ( 1, QColor ( Qt::darkYellow ).light ( 120 ) ); painter->setPen ( QPen ( Qt::red, 0 ) ); } else { gradient.setColorAt ( 0, Qt::yellow ); gradient.setColorAt ( 1, Qt::darkYellow ); painter->setPen ( QPen ( Qt::black, 0 ) ); } painter->setBrush ( gradient ); const double diameter ( _radius * 2 ); painter->drawEllipse ( -_radius, -_radius, diameter, diameter); }
void Highlight::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QColor pen_color = pen.color(); painter->setPen(pen); if(time < total_time ){ //don't want to keep adding them past animation length int expected_num_rings = (int)ceil(frequency * time); if( expected_num_rings > rings.length()){ rings.append(time); } //velocity= 200.0 - (time*total_time*2.0);//pretty cool //velocity= 200.0*(1.0-done_ratio);//pretty cool, about the same //frequency = 3.0*(1.0-done_ratio);//pretty cool for(int i=0; i<rings.length(); i++){ //qreal dist = diameter + ( velocity * (time - rings.at(i))); qreal t = (time - rings.at(i)); qreal dist = diameter + ( velocity * t ) + (0.5 * -5.0 * t*t); //qDebug() << "dist:" << dist << " outerDiameter:" << outerDiameter; QRectF s(x()-dist/2.0, y()-dist/2.0,dist,dist); QRectF r = mapRectFromScene(x()-dist/2.0, y()-dist/2.0,dist,dist); pen.setWidth(20.0+50.0* dist/outerDiameter); QRadialGradient radialGrad; radialGrad.setCenter(r.center()); radialGrad.setFocalPoint(r.center()); radialGrad.setCenterRadius(r.width()/2.0+pen.widthF()/2.0); radialGrad.setFocalRadius(r.width()/2.0-pen.widthF()/2.0); /* not entirely sure I get it, but I think focal radius * needs to be either the center of the pen or its inner edge * while center radius is the outer edge. */ QColor green(0,255,0,255); QColor yellow(255,255,0,255); /* pen_color.setAlphaF(1.0-(dist/outerDiameter)); //surface waves don't inverse square */ green.setAlphaF(1.0-(dist/outerDiameter)); yellow.setAlphaF((1.0-(dist/outerDiameter))); radialGrad.setColorAt(.0, yellow ); radialGrad.setColorAt( .5, green ); radialGrad.setColorAt(1, yellow ); brush = QBrush(radialGrad); pen.setBrush(brush); painter->setPen(pen); painter->drawEllipse(r); } } }
void BoxStyle::unoptimizedPaint(QPainter* painter, int xOffset, int yOffset, int contentBoxWidth, int contentBoxHeight) const { qreal x = xOffset; qreal y = yOffset; int outlineWidth = outline_.style()!=Qt::NoPen ? outline_.width() : 0; // Move the figure when using antialiasing. The outline will start at a pixel boundary. This makes it sharper. if ( painter->testRenderHint(QPainter::Antialiasing) || painter->testRenderHint(QPainter::HighQualityAntialiasing) ) if ( outline().style() != Qt::NoPen) { x = xOffset + outlineWidth/2.0; y = yOffset + outlineWidth/2.0; } // Draw shadow if ( shadow() != Qt::NoBrush ) { painter->setPen(Qt::NoPen); painter->setBrush(shadow()); painter->drawPath(getRectanglePath(xOffset + xShadowOffset(), yOffset + yShadowOffset(), contentBoxWidth, contentBoxHeight)); } // Draw box. painter->setPen(outline()); // Set the brush and fix the gradient if needed. if ( background().style() == Qt::LinearGradientPattern && background().gradient()->coordinateMode() == QGradient::LogicalMode ) { QLinearGradient g = *(static_cast<const QLinearGradient*> (background().gradient())); g.setStart(x + g.start().x(), y + g.start().y()); g.setFinalStop(x + g.finalStop().x(), y + g.finalStop().y()); painter->setBrush(g); } else if ( background().style() == Qt::RadialGradientPattern && background().gradient()->coordinateMode() == QGradient::LogicalMode ) { QRadialGradient g = *(static_cast<const QRadialGradient*> (background().gradient())); g.setCenter(x + g.center().x(), y + g.center().y()); g.setFocalPoint(x + g.focalPoint().x(), y + g.focalPoint().y()); painter->setBrush(g); } else { painter->setBrush(background()); } painter->drawPath(getRectanglePath(x, y, contentBoxWidth - outlineWidth, contentBoxHeight - outlineWidth)); }
QRadialGradient* getRadialGradient(const CLRadialGradient* radial, const CLBoundingBox* bounds, const CLRenderResolver* resolver) { double cx = bounds->getPosition().getX() + radial->getCenterX().getAbsoluteValue() + radial->getCenterX().getRelativeValue() / 100.0 * bounds->getDimensions().getWidth(); double cy = bounds->getPosition().getY() + radial->getCenterY().getAbsoluteValue() + radial->getCenterY().getRelativeValue() / 100.0 * bounds->getDimensions().getHeight(); double fx = bounds->getPosition().getX() + radial->getFocalPointX().getAbsoluteValue() + radial->getFocalPointX().getRelativeValue() / 100.0 * bounds->getDimensions().getWidth(); double fy = bounds->getPosition().getY() + radial->getFocalPointY().getAbsoluteValue() + radial->getFocalPointY().getRelativeValue() / 100.0 * bounds->getDimensions().getHeight(); double r = radial->getRadius().getAbsoluteValue() + radial->getRadius().getRelativeValue() / 100.0 * bounds->getDimensions().getWidth(); QRadialGradient* result = new QRadialGradient(cx, cy, r, fx, fy); switch (radial->getSpreadMethod()) { case CLGradientBase::REFLECT: result->setSpread(QGradient::ReflectSpread); break; case CLGradientBase::REPEAT: result->setSpread(QGradient::RepeatSpread); break; case CLGradientBase::PAD: result->setSpread(QGradient::PadSpread); break; default: break; } for (size_t i = 0; i < radial->getNumGradientStops(); ++i) { const CLGradientStop* stop = radial->getGradientStop(i); result->setColorAt(stop->getOffset().getAbsoluteValue() + stop->getOffset().getRelativeValue() / 100.0, getColor(stop->getStopColor(), resolver)); } return result; }
//! //! Paints the graphics item into a graphics view. //! //! \param painter The object to use for painting. //! \param option Style options for painting the graphics item. //! \param widget The widget into which to paint the graphics item. //! void PinGraphicsItem::paint ( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget /* = 0 */ ) { const QColor penColor (30, 30, 30); QRadialGradient radialGradient (rect().center(), 5); radialGradient.setColorAt(1, m_color.darker(200)); radialGradient.setColorAt(0, m_color); // set the brush QBrush brush; if (isEnabled()) if (m_hovered && m_clicked) radialGradient.setColorAt(0.5, m_color.lighter(100)); else if (m_hovered || m_clicked) radialGradient.setColorAt(0.5, m_color.lighter(100)); else radialGradient.setColorAt(0.5, m_color.darker(150)); else brush = Qt::NoBrush; // paint the pin brush = QBrush(radialGradient); painter->setRenderHint(QPainter::Antialiasing); painter->setPen(QPen(QBrush(penColor), 1)); painter->setBrush(brush); painter->drawEllipse(rect().center(), 5, 5); // check if the parameter the pin represents is a parameter group //if (m_abstractParameter && m_abstractParameter->isGroup()) { // painter->setPen(QPen(penColor)); // painter->setBrush(QBrush(QColor(Qt::black))); // painter->setRenderHint(QPainter::Antialiasing); // if (m_abstractParameter->getName().isEmpty()) { // // draw two dots for parameter roots // painter->drawEllipse(rect().center() + QPointF(-2, 0.5), 1, 1); // painter->drawEllipse(rect().center() + QPointF(2, 0.5), 1, 1); // } else // // draw one dot for other parameter groups // painter->drawEllipse(rect().center(), 1, 1); //} if (m_isGroup) { painter->setPen(QPen(penColor)); painter->setBrush(QBrush(QColor(Qt::black))); painter->setRenderHint(QPainter::Antialiasing); if (m_isRootGroup) { // draw two dots for parameter roots painter->drawEllipse(rect().center() + QPointF(-2, 0.5), 1, 1); painter->drawEllipse(rect().center() + QPointF(2, 0.5), 1, 1); } else // draw one dot for other parameter groups painter->drawEllipse(rect().center(), 1, 1); } }
SpaceObjectSun::SpaceObjectSun(int x, int y) : SpaceObject(x, y, SO_TYPE_SUN) { mPixmap->fill(Qt::transparent); QPainter p(mPixmap); QRadialGradient rd; rd.setCenter(40, 40); rd.setRadius(40); rd.setFocalPoint(40, 40); rd.setColorAt(0, QColor(0xFF, 0xFF, 0xDD, 0xFF)); rd.setColorAt(0.45, QColor(0xFF, 0xFF, 0xDD, 0xFF)); rd.setColorAt(0.55, QColor(0xFF, 0xFF, 0x33, 0xFF)); rd.setColorAt(0.6, QColor("#FF9900")); rd.setColorAt(1, QColor( 0, 0, 0, 0x00 )); p.setPen(Qt::NoPen); p.setBrush( rd ); p.drawEllipse(0, 0, 80, 80); }
void PainterWidget::updateBrush() { QRadialGradient g; g.setCenter(brush_size/2, brush_size/2); g.setFocalPoint(brush_size/2, brush_size/2); g.setRadius(brush_size/2); g.setColorAt(1.0, Qt::black); g.setColorAt(0, QColor(100,100,100)); QImage mask(brush_size, brush_size,QImage::Format_RGB32); mask.fill(qRgb(0,0,0)); QPainter painter2(&mask); painter2.fillRect(mask.rect(), g); painter2.end(); soft_brush = QImage(brush_size, brush_size,QImage::Format_RGB32); soft_brush.fill(brush_color.rgb()); soft_brush.setAlphaChannel(mask); }
void LedIndicator::paintEvent(QPaintEvent *event) { qreal realSize = qMin(width(), height()); QRadialGradient gradient; QPainter painter(this); QPen pen(Qt::black); pen.setWidth(1); painter.setRenderHint(QPainter::Antialiasing); painter.translate(width()/2, height()/2); painter.scale(realSize/scaledSize, realSize/scaledSize); gradient = QRadialGradient (QPointF(-500,-500), 1500, QPointF(-500,-500)); gradient.setColorAt(0, QColor(224,224,224)); gradient.setColorAt(1, QColor(28,28,28)); painter.setPen(pen); painter.setBrush(QBrush(gradient)); painter.drawEllipse(QPointF(0,0), 500, 500); gradient = QRadialGradient (QPointF(500,500), 1500, QPointF(500,500)); gradient.setColorAt(0, QColor(224,224,224)); gradient.setColorAt(1, QColor(28,28,28)); painter.setPen(pen); painter.setBrush(QBrush(gradient)); painter.drawEllipse(QPointF(0,0), 450, 450); painter.setPen(pen); if( isDown() ) { gradient = QRadialGradient (QPointF(-500,-500), 1500, QPointF(-500,-500)); gradient.setColorAt(0, onColor1); gradient.setColorAt(1, onColor2); } else { gradient = QRadialGradient (QPointF(500,500), 1500, QPointF(500,500)); gradient.setColorAt(0, offColor1); gradient.setColorAt(1, offColor2); } painter.setBrush(gradient); painter.drawEllipse(QPointF(0,0), 400, 400); }
void LightMaps::paintEvent(QPaintEvent *event) { QPainter p; p.begin(this); m_normalMap->render(&p, event->rect()); p.setPen(Qt::black); p.drawText(rect(), Qt::AlignBottom | Qt::TextWordWrap, "Map data CCBYSA 2009 OpenStreetMap.org contributors"); p.end(); if (zoomed) { int dim = qMin(width(), height()); int magnifierSize = qMin(MAX_MAGNIFIER, dim * 2 / 3); int radius = magnifierSize / 2; int ring = radius - 15; QSize box = QSize(magnifierSize, magnifierSize); // reupdate our mask if (maskPixmap.size() != box) { maskPixmap = QPixmap(box); maskPixmap.fill(Qt::transparent); QRadialGradient g; g.setCenter(radius, radius); g.setFocalPoint(radius, radius); g.setRadius(radius); g.setColorAt(1.0, QColor(255, 255, 255, 0)); g.setColorAt(0.5, QColor(128, 128, 128, 255)); QPainter mask(&maskPixmap); mask.setRenderHint(QPainter::Antialiasing); mask.setCompositionMode(QPainter::CompositionMode_Source); mask.setBrush(g); mask.setPen(Qt::NoPen); mask.drawRect(maskPixmap.rect()); mask.setBrush(QColor(Qt::transparent)); mask.drawEllipse(g.center(), ring, ring); mask.end(); } QPoint center = dragPos - QPoint(0, radius); center = center + QPoint(0, radius / 2); QPoint corner = center - QPoint(radius, radius); QPoint xy = center * 2 - QPoint(radius, radius); // only set the dimension to the magnified portion if (zoomPixmap.size() != box) { zoomPixmap = QPixmap(box); zoomPixmap.fill(Qt::lightGray); } if (true) { QPainter p(&zoomPixmap); p.translate(-xy); m_largeMap->render(&p, QRect(xy, box)); p.end(); } QPainterPath clipPath; clipPath.addEllipse(center, ring, ring); QPainter p(this); p.setRenderHint(QPainter::Antialiasing); p.setClipPath(clipPath); p.drawPixmap(corner, zoomPixmap); p.setClipping(false); p.drawPixmap(corner, maskPixmap); p.setPen(Qt::gray); p.drawPath(clipPath); } if (invert) { QPainter p(this); p.setCompositionMode(QPainter::CompositionMode_Difference); p.fillRect(event->rect(), Qt::white); p.end(); } }
void Mask::mask_slot(){ int countSel = gsri->countSelected(); GObjectInterface *iObj, *endObj=gsri->selected(gsri->countSelected()-1);//создаём контейнер с выделенными рамкой объектами qreal k_h, k_w, width_iObj, width_endObj = endObj->boundingRect().width(), height_iObj, height_endObj = endObj->boundingRect().height(); QBrush endObjBrush = endObj->brush(); if(endObjBrush.style() == Qt::RadialGradientPattern || endObjBrush.style() == Qt::ConicalGradientPattern || endObjBrush.style() == Qt::LinearGradientPattern){ for (int i=0; i<countSel-1; i++){ iObj = gsri->selected(i); QBrush inters = iObj->brush(); qreal iObjAlpha = inters.color().alphaF(); QGradient qg = *endObjBrush.gradient(); height_iObj = iObj->boundingRect().height(); width_iObj = iObj->boundingRect().width(); k_h = height_endObj/height_iObj;//считаем коэффициенты пропорциональности фигур для умножения--> k_w = width_endObj/width_iObj;//-->на точки градиента(чтобы градиенты не зависели от размеров фигур). int d_x = iObj->boundingRect().x() - endObj->boundingRect().x();//вычисляем расстояния между левыми краями фигур int d_y = iObj->boundingRect().y() - endObj->boundingRect().y(); qreal k_shift_x = ( d_x / width_endObj) * k_w,//вычисляем коэффициенты сдвига градиента по ширине--> k_shift_y = (d_y / height_endObj) * k_h;//--> и по высотке QGradientStops grStops(qg.stops());//копируем точки/цвета задаваемого градиента. QColor BrushColor = inters.gradient()->stops()[0].second; for(int j=0; j<grStops.count(); j++){ grStops[j].second.setRgbF( BrushColor.redF(), BrushColor.greenF(), BrushColor.blueF(), grStops[j].second.alphaF()*iObjAlpha); } if(qg.type() == QGradient::LinearGradient){ QLinearGradient qlg = *static_cast<const QLinearGradient *>(endObjBrush.gradient()); QLinearGradient qlgLinear(qlg.start().x() * k_w - k_shift_x, qlg.start().y() * k_h - k_shift_y, qlg.finalStop().x() * k_w - k_shift_x, qlg.finalStop().y() * k_h - k_shift_y); qlgLinear.setStops(grStops); iObj->setBrush(qlgLinear); } if(qg.type() == QGradient::RadialGradient){ for(int j=0; j<grStops.count(); j++) grStops[j].first *= k_w; QRadialGradient qlg = *static_cast<const QRadialGradient *>(endObjBrush.gradient()); QRadialGradient qlgRadial(QPointF(qlg.center().x()*k_w - k_shift_x, qlg.center().y()*k_h - k_shift_y), qlg.radius(), QPointF(qlg.focalPoint().x()*k_w - k_shift_x, qlg.focalPoint().y()*k_h - k_shift_y), qlg.focalRadius()); qlgRadial.setStops(grStops); iObj->setBrush(qlgRadial); } if(qg.type() == QGradient::ConicalGradient){ QConicalGradient qlg = *static_cast<const QConicalGradient *>(endObjBrush.gradient()); QConicalGradient qlgConical(QPointF(qlg.center().x()*k_w - k_shift_x, qlg.center().y()*k_h - k_shift_y), qlg.angle()); qlgConical.setStops(grStops); iObj->setBrush(qlgConical); } } endObj->setVisible(false); } else{ QMessageBox m; m.setText(tr("upper figure does not contain a gradient")); m.exec(); } gsri->reset(); }
void AbstractDiagram::paintMarker( QPainter* painter, const MarkerAttributes& markerAttributes, const QBrush& brush, const QPen& pen, const QPointF& pos, const QSizeF& maSize ) { const QPen oldPen( painter->pen() ); // Pen is used to paint 4Pixels - 1 Pixel - Ring and FastCross types. // make sure to use the brush color - see above in those cases. const bool isFourPixels = (markerAttributes.markerStyle() == MarkerAttributes::Marker4Pixels); if( isFourPixels || (markerAttributes.markerStyle() == MarkerAttributes::Marker1Pixel) ){ // for high-performance point charts with tiny point markers: painter->setPen( PrintingParameters::scalePen( QPen( brush.color().light() ) ) ); if( isFourPixels ){ const qreal x = pos.x(); const qreal y = pos.y(); painter->drawLine( QPointF(x-1.0,y-1.0), QPointF(x+1.0,y-1.0) ); painter->drawLine( QPointF(x-1.0,y), QPointF(x+1.0,y) ); painter->drawLine( QPointF(x-1.0,y+1.0), QPointF(x+1.0,y+1.0) ); } painter->drawPoint( pos ); }else{ const PainterSaver painterSaver( painter ); // we only a solid line surrounding the markers QPen painterPen( pen ); painterPen.setStyle( Qt::SolidLine ); painter->setPen( PrintingParameters::scalePen( painterPen ) ); painter->setBrush( brush ); painter->setRenderHint ( QPainter::Antialiasing ); painter->translate( pos ); switch ( markerAttributes.markerStyle() ) { case MarkerAttributes::MarkerCircle: { if ( markerAttributes.threeD() ) { QRadialGradient grad; grad.setCoordinateMode( QGradient::ObjectBoundingMode ); QColor drawColor = brush.color(); grad.setCenter( 0.5, 0.5 ); grad.setRadius( 1.0 ); grad.setFocalPoint( 0.35, 0.35 ); grad.setColorAt( 0.00, drawColor.lighter( 150 ) ); grad.setColorAt( 0.20, drawColor ); grad.setColorAt( 0.50, drawColor.darker( 150 ) ); grad.setColorAt( 0.75, drawColor.darker( 200 ) ); grad.setColorAt( 0.95, drawColor.darker( 250 ) ); grad.setColorAt( 1.00, drawColor.darker( 200 ) ); QBrush newBrush( grad ); newBrush.setMatrix( brush.matrix() ); painter->setBrush( newBrush ); } painter->drawEllipse( QRectF( 0 - maSize.height()/2, 0 - maSize.width()/2, maSize.height(), maSize.width()) ); } break; case MarkerAttributes::MarkerSquare: { QRectF rect( 0 - maSize.width()/2, 0 - maSize.height()/2, maSize.width(), maSize.height() ); painter->drawRect( rect ); break; } case MarkerAttributes::MarkerDiamond: { QVector <QPointF > diamondPoints; QPointF top, left, bottom, right; top = QPointF( 0, 0 - maSize.height()/2 ); left = QPointF( 0 - maSize.width()/2, 0 ); bottom = QPointF( 0, maSize.height()/2 ); right = QPointF( maSize.width()/2, 0 ); diamondPoints << top << left << bottom << right; painter->drawPolygon( diamondPoints ); break; } // both handled on top of the method: case MarkerAttributes::Marker1Pixel: case MarkerAttributes::Marker4Pixels: break; case MarkerAttributes::MarkerRing: { painter->setPen( PrintingParameters::scalePen( QPen( brush.color() ) ) ); painter->setBrush( Qt::NoBrush ); painter->drawEllipse( QRectF( 0 - maSize.height()/2, 0 - maSize.width()/2, maSize.height(), maSize.width()) ); break; } case MarkerAttributes::MarkerCross: { // Note: Markers can have outline, // so just drawing two rects is NOT the solution here! const qreal w02 = maSize.width() * 0.2; const qreal w05 = maSize.width() * 0.5; const qreal h02 = maSize.height()* 0.2; const qreal h05 = maSize.height()* 0.5; QVector <QPointF > crossPoints; QPointF p[12]; p[ 0] = QPointF( -w02, -h05 ); p[ 1] = QPointF( w02, -h05 ); p[ 2] = QPointF( w02, -h02 ); p[ 3] = QPointF( w05, -h02 ); p[ 4] = QPointF( w05, h02 ); p[ 5] = QPointF( w02, h02 ); p[ 6] = QPointF( w02, h05 ); p[ 7] = QPointF( -w02, h05 ); p[ 8] = QPointF( -w02, h02 ); p[ 9] = QPointF( -w05, h02 ); p[10] = QPointF( -w05, -h02 ); p[11] = QPointF( -w02, -h02 ); for( int i=0; i<12; ++i ) crossPoints << p[i]; crossPoints << p[0]; painter->drawPolygon( crossPoints ); break; } case MarkerAttributes::MarkerFastCross: { QPointF left, right, top, bottom; left = QPointF( -maSize.width()/2, 0 ); right = QPointF( maSize.width()/2, 0 ); top = QPointF( 0, -maSize.height()/2 ); bottom= QPointF( 0, maSize.height()/2 ); painter->setPen( PrintingParameters::scalePen( QPen( brush.color() ) ) ); painter->drawLine( left, right ); painter->drawLine( top, bottom ); break; } case MarkerAttributes::NoMarker: break; default: Q_ASSERT_X ( false, "paintMarkers()", "Type item does not match a defined Marker Type." ); } } painter->setPen( oldPen ); }
QBrush XMLParseBase::parseGradient(const QDomElement &element) { QBrush brush; QString gradientStart = element.attribute("start", ""); QString gradientEnd = element.attribute("end", ""); int gradientAlpha = element.attribute("alpha", "255").toInt(); QString direction = element.attribute("direction", "vertical"); QGradientStops stops; if (!gradientStart.isEmpty()) { QColor startColor = QColor(gradientStart); startColor.setAlpha(gradientAlpha); QGradientStop stop(0.0, startColor); stops.append(stop); } for (QDomNode child = element.firstChild(); !child.isNull(); child = child.nextSibling()) { QDomElement childElem = child.toElement(); if (childElem.tagName() == "stop") { float position = childElem.attribute("position", "0").toFloat(); QString color = childElem.attribute("color", ""); int alpha = childElem.attribute("alpha", "-1").toInt(); if (alpha < 0) alpha = gradientAlpha; QColor stopColor = QColor(color); stopColor.setAlpha(alpha); QGradientStop stop((position / 100), stopColor); stops.append(stop); } } if (!gradientEnd.isEmpty()) { QColor endColor = QColor(gradientEnd); endColor.setAlpha(gradientAlpha); QGradientStop stop(1.0, endColor); stops.append(stop); } if (direction == "radial") { QRadialGradient gradient; gradient.setCoordinateMode(QGradient::ObjectBoundingMode); float x1 = 0.5, y1 = 0.5, radius = 0.5; gradient.setCenter(x1,y1); gradient.setFocalPoint(x1,y1); gradient.setRadius(radius); gradient.setStops(stops); brush = QBrush(gradient); } else // Linear { QLinearGradient gradient; gradient.setCoordinateMode(QGradient::ObjectBoundingMode); float x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0; if (direction == "vertical") { x1 = 0.5; x2 = 0.5; y1 = 0.0; y2 = 1.0; } else if (direction == "diagonal") { x1 = 0.0; x2 = 1.0; y1 = 0.0; y2 = 1.0; } else // Horizontal { x1 = 0.0; x2 = 1.0; y1 = 0.5; y2 = 0.5; } gradient.setStart(x1, y1); gradient.setFinalStop(x2, y2); gradient.setStops(stops); brush = QBrush(gradient); } return brush; }
void transferGradientPosition(const QGradient * srcGradient, QGradient * dstGradient) { // first check if gradients have the same type if (srcGradient->type() == dstGradient->type()) { switch (srcGradient->type()) { case QGradient::LinearGradient: { const QLinearGradient * src = static_cast<const QLinearGradient*>(srcGradient); QLinearGradient * dst = static_cast<QLinearGradient*>(dstGradient); dst->setStart(src->start()); dst->setFinalStop(src->finalStop()); break; } case QGradient::RadialGradient: { const QRadialGradient * src = static_cast<const QRadialGradient*>(srcGradient); QRadialGradient * dst = static_cast<QRadialGradient*>(dstGradient); dst->setCenter(src->center()); dst->setRadius(src->radius()); dst->setFocalPoint(src->focalPoint()); break; } case QGradient::ConicalGradient: { const QConicalGradient * src = static_cast<const QConicalGradient*>(srcGradient); QConicalGradient * dst = static_cast<QConicalGradient*>(dstGradient); dst->setCenter(src->center()); dst->setAngle(src->angle()); break; } default: return; } return; } // try to preserve gradient positions as best as possible QPointF start, stop; switch (srcGradient->type()) { case QGradient::LinearGradient: { const QLinearGradient * g = static_cast<const QLinearGradient*>(srcGradient); start = g->start(); stop = g->finalStop(); break; } case QGradient::RadialGradient: { const QRadialGradient * g = static_cast<const QRadialGradient*>(srcGradient); start = g->center(); stop = QPointF(g->radius(), 0.0); break; } case QGradient::ConicalGradient: { const QConicalGradient * g = static_cast<const QConicalGradient*>(srcGradient); start = g->center(); qreal radAngle = g->angle() * M_PI / 180.0; stop = QPointF(50.0 * cos(radAngle), 50.*sin(radAngle)); break; } default: start = QPointF(0.0, 0.0); stop = QPointF(50.0, 50.0); } switch (dstGradient->type()) { case QGradient::LinearGradient: { QLinearGradient * g = static_cast<QLinearGradient*>(dstGradient); g->setStart(start); g->setFinalStop(stop); break; } case QGradient::RadialGradient: { QRadialGradient * g = static_cast<QRadialGradient*>(dstGradient); QPointF diff = stop - start; qreal radius = sqrt(diff.x() * diff.x() + diff.y() * diff.y()); g->setCenter(start); g->setFocalPoint(start); g->setRadius(radius); break; } case QGradient::ConicalGradient: { QConicalGradient * g = static_cast<QConicalGradient*>(dstGradient); QPointF diff = stop - start; qreal angle = atan2(diff.y(), diff.x()); if (angle < 0.0) angle += 2 * M_PI; g->setCenter(start); g->setAngle(angle*180 / M_PI); break; } default: return; } }
void tst_QBrush::testQRadialGradientSetters() { QRadialGradient rg; QCOMPARE(rg.radius(), qreal(1.0)); QCOMPARE(rg.center(), QPointF(0, 0)); QCOMPARE(rg.focalPoint(), QPointF(0, 0)); rg.setRadius(100); QCOMPARE(rg.radius(), qreal(100.0)); rg.setCenter(101, 102); QCOMPARE(rg.center(), QPointF(101, 102)); rg.setCenter(QPointF(201, 202)); QCOMPARE(rg.center(), QPointF(201, 202)); rg.setFocalPoint(103, 104); QCOMPARE(rg.focalPoint(), QPointF(103, 104)); rg.setFocalPoint(QPointF(203, 204)); QCOMPARE(rg.focalPoint(), QPointF(203, 204)); }