本文整理汇总了C++中QRadialGradient::setFocalPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ QRadialGradient::setFocalPoint方法的具体用法?C++ QRadialGradient::setFocalPoint怎么用?C++ QRadialGradient::setFocalPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QRadialGradient
的用法示例。
在下文中一共展示了QRadialGradient::setFocalPoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateMask
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();
}
}
示例2: paint
void dot::paint ( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
{
Q_UNUSED ( widget );
painter->setPen ( Qt::NoPen );
painter->setBrush ( Qt::darkGray );
painter->drawEllipse ( -1, -1, 5, 5 );
QRadialGradient gradient ( -3, -3, 10 );
if( this->isSelected() )
{
if ( option->state & QStyle::State_Sunken )
{
gradient.setCenter ( 3, 3 );
gradient.setFocalPoint ( 3, 3 );
gradient.setColorAt ( 1, QColor ( Qt::green ).light ( 100 ) );
gradient.setColorAt ( 0, QColor ( Qt::darkGreen ).light ( 100 ) );
}
else
{
gradient.setColorAt ( 0, Qt::green );
gradient.setColorAt ( 1, Qt::darkGreen );
}
}
else
{
if ( option->state & QStyle::State_Sunken )
{
gradient.setCenter ( 3, 3 );
gradient.setFocalPoint ( 3, 3 );
gradient.setColorAt ( 1, QColor ( Qt::yellow ).light ( 100 ) );
gradient.setColorAt ( 0, QColor ( Qt::darkYellow ).light ( 100 ) );
}
else
{
gradient.setColorAt ( 0, Qt::yellow );
gradient.setColorAt ( 1, Qt::darkYellow );
}
}
painter->setBrush ( gradient );
painter->setPen ( QPen ( Qt::black, 0 ) );
painter->drawEllipse ( -2, -2, 6, 6 );
painter->scale ( 1.0,-1.0 );
painter->setFont(QFont("Arial", 14));
painter->drawText(0,10,message);
}
示例3: unoptimizedPaint
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));
}
示例4: paint
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);
}
}
}
示例5: updateBrush
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);
}
示例6: loadGradient
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;
}
示例7: drawEllipse
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();
}
}
示例8: drawRect
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();
}
示例9: p
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);
}
示例10: paintEvent
//.........这里部分代码省略.........
}
//窗口的高度。
int height = this->mBallMap.height() ;
if (width != this->mBallMap.width()) {
//qLogx()<< "change to width:" << width ;
//需要改变图象大小。宽度
this->mBallMap = QImage(width , this->mBallMap.height() , QImage::Format_ARGB32_Premultiplied);
//this->mBallMap = this->mBallMap.scaledToWidth( width ) ;
//this->resize(width,height);
this->setFixedWidth( width );
}
if (this->mBallBit.size() != (width/(this->mBallRadius*2)) * (height/(this->mBallRadius*2))) {
height = (this->mBallRadius*2) * (this->mBallBit.size())/((width/(this->mBallRadius*2)));
if (height % (this->mBallRadius*2) != 0 ) {
height = ( 1+ (height / (this->mBallRadius*2)) ) * ( this->mBallRadius * 2);
} else {
height = ( height / (this->mBallRadius*2) ) * ( this->mBallRadius * 2);
}
//qLogx()<< "change to height: " << height ;
//需要改变图象大小。高度。
//this->mBallMap = this->mBallMap.scaledToHeight( (this->mCurrentLength / (this->mBlockSize))/((width/(this->mBallRadius*2)) ) * ( this->mBallRadius*2 ));
this->mBallMap = QImage(width, height, QImage::Format_ARGB32_Premultiplied);
//this->mBallMap = this->mBallMap.scaledToHeight(height);
//this->resize(width,height);
this->setFixedHeight(height); //设置本窗口构件的大小,使得外层的滚动构件能适当的添加或者删除滚动条。
}
// ball ball 48 0 // 0 true 600 0
// qLogx()<<__FUNCTION__<<this->mBallBit.size()<<this->mBallMap.isNull()<<width<<height;
if (this->mBallMap.isNull()) {
/*
if not check, show this error:
QPainter::begin: Paint device returned engine == 0, type: 3
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::setBrush: Painter not active
QPainter::drawRects: Painter not active
QPainter::setBrush: Painter not active
QPainter::setBrush: Painter not actiev
*/
// this->mBallMap = QImage(mp->width(), mp->height(), QImage::Format_ARGB32_Premultiplied);
return;
}
QPainter imgp(&this->mBallMap) ;
imgp.setRenderHint(QPainter::Antialiasing, true);
imgp.setBrush(brush) ;
imgp.drawRect(0, 0, this->mBallMap.width(), this->mBallMap.height());
//更改前景颜色。
brush.setColor(QColor(0,255,0));
imgp.setBrush(brush);
//////////
QRadialGradient radgrad ; //梯度法
imgp.setBrush(radgrad) ;
int row = 0 , col = 0 ; //当前行,列
int mrow , mcol ; //最大行,列
int srow , scol ; //当前球块所在行,列。
mcol = width / (this->mBallRadius*2) ;
mrow = this->mBallBit.size() % mcol == 0 ?
(this->mBallBit.size() / mcol) : (this->mBallBit.size() / mcol + 1);
int mtb = this->mBallBit.size(); //所有球的个数。
// qLogx()<<"rows:"<<mrow<<"cols:"<<mcol;
for (int row = 0; row < mrow; row++) {
int sballno;
for (int col=0; col < mcol ; col ++) {
int bx, by, bw, bh;
sballno = row * mcol + col; //本球块在整个文件块中的序号。
if (sballno >= this->mBallBit.size()) {
break;
}
if (this->mBallBit.testBit(sballno) == false) {
continue;
}
bx = col * this->mBallRadius * 2; //本求块的右上角X值。
by = row * this->mBallRadius * 2; //本求块的右上角Y值。
//qLogx()<<"x,y,w"<<bx<<by<<(this->mBallRadius*2);
radgrad.setCenter(bx+this->mBallRadius, by + this->mBallRadius); //梯度参数设置
radgrad.setRadius(this->mBallRadius * 2 );
radgrad.setFocalPoint(bx+this->mBallRadius/2,by+this->mBallRadius/2);
radgrad.setColorAt(0.0,QColor(255,255,255));
radgrad.setColorAt(0.5,QColor(0,255,0));
radgrad.setColorAt(1.0,QColor(0,0,0));
imgp.setBrush(radgrad);
imgp.drawEllipse(bx,by,this->mBallRadius*2 , this->mBallRadius*2);
}
}
//输出到屏幕。
QPainter scrp(this);
scrp.drawImage(0, 0, this->mBallMap);
}
示例11: paintMarker
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 );
//.........这里部分代码省略.........
示例12: parseGradient
bool SvgParser::parseGradient(const KoXmlElement &e, const KoXmlElement &referencedBy)
{
// IMPROVEMENTS:
// - Store the parsed colorstops in some sort of a cache so they don't need to be parsed again.
// - A gradient inherits attributes it does not have from the referencing gradient.
// - Gradients with no color stops have no fill or stroke.
// - Gradients with one color stop have a solid color.
SvgGraphicsContext *gc = m_context.currentGC();
if (!gc)
return false;
SvgGradientHelper gradhelper;
if (e.hasAttribute("xlink:href")) {
QString href = e.attribute("xlink:href").mid(1);
if (! href.isEmpty()) {
// copy the referenced gradient if found
SvgGradientHelper *pGrad = findGradient(href);
if (pGrad)
gradhelper = *pGrad;
} else {
//gc->fillType = SvgGraphicsContext::None; // <--- TODO Fill OR Stroke are none
return false;
}
}
// Use the gradient that is referencing, or if there isn't one, the original gradient.
KoXmlElement b;
if (!referencedBy.isNull())
b = referencedBy;
else
b = e;
QString gradientId = b.attribute("id");
if (! gradientId.isEmpty()) {
// check if we have this gradient already parsed
// copy existing gradient if it exists
if (m_gradients.find(gradientId) != m_gradients.end())
gradhelper.copyGradient(m_gradients[ gradientId ].gradient());
}
if (b.attribute("gradientUnits") == "userSpaceOnUse")
gradhelper.setGradientUnits(SvgGradientHelper::UserSpaceOnUse);
// parse color prop
QColor c = gc->currentColor;
if (!b.attribute("color").isEmpty()) {
m_context.styleParser().parseColor(c, b.attribute("color"));
} else {
// try style attr
QString style = b.attribute("style").simplified();
const QStringList substyles = style.split(';', QString::SkipEmptyParts);
for (QStringList::ConstIterator it = substyles.begin(); it != substyles.end(); ++it) {
QStringList substyle = it->split(':');
QString command = substyle[0].trimmed();
QString params = substyle[1].trimmed();
if (command == "color")
m_context.styleParser().parseColor(c, params);
}
}
gc->currentColor = c;
if (b.tagName() == "linearGradient") {
QLinearGradient *g = new QLinearGradient();
if (gradhelper.gradientUnits() == SvgGradientHelper::ObjectBoundingBox) {
g->setCoordinateMode(QGradient::ObjectBoundingMode);
g->setStart(QPointF(SvgUtil::fromPercentage(b.attribute("x1", "0%")),
SvgUtil::fromPercentage(b.attribute("y1", "0%"))));
g->setFinalStop(QPointF(SvgUtil::fromPercentage(b.attribute("x2", "100%")),
SvgUtil::fromPercentage(b.attribute("y2", "0%"))));
} else {
g->setStart(QPointF(SvgUtil::fromUserSpace(b.attribute("x1").toDouble()),
SvgUtil::fromUserSpace(b.attribute("y1").toDouble())));
g->setFinalStop(QPointF(SvgUtil::fromUserSpace(b.attribute("x2").toDouble()),
SvgUtil::fromUserSpace(b.attribute("y2").toDouble())));
}
// preserve color stops
if (gradhelper.gradient())
g->setStops(gradhelper.gradient()->stops());
gradhelper.setGradient(g);
} else if (b.tagName() == "radialGradient") {
QRadialGradient *g = new QRadialGradient();
if (gradhelper.gradientUnits() == SvgGradientHelper::ObjectBoundingBox) {
g->setCoordinateMode(QGradient::ObjectBoundingMode);
g->setCenter(QPointF(SvgUtil::fromPercentage(b.attribute("cx", "50%")),
SvgUtil::fromPercentage(b.attribute("cy", "50%"))));
g->setRadius(SvgUtil::fromPercentage(b.attribute("r", "50%")));
g->setFocalPoint(QPointF(SvgUtil::fromPercentage(b.attribute("fx", "50%")),
SvgUtil::fromPercentage(b.attribute("fy", "50%"))));
} else {
g->setCenter(QPointF(SvgUtil::fromUserSpace(b.attribute("cx").toDouble()),
SvgUtil::fromUserSpace(b.attribute("cy").toDouble())));
g->setFocalPoint(QPointF(SvgUtil::fromUserSpace(b.attribute("fx").toDouble()),
SvgUtil::fromUserSpace(b.attribute("fy").toDouble())));
g->setRadius(SvgUtil::fromUserSpace(b.attribute("r").toDouble()));
}
// preserve color stops
//.........这里部分代码省略.........
示例13: parseGradient
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;
}
示例14: transferGradientPosition
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;
}
}
示例15: generateFuzzyRect
QPixmap ThumbBarDock::generateFuzzyRect(const QSize& size, const QColor& color, int radius)
{
QPixmap pix(size);
pix.fill(Qt::transparent);
QPainter painter(&pix);
painter.setRenderHint(QPainter::Antialiasing, true);
// Draw corners ----------------------------------
QRadialGradient gradient;
gradient.setColorAt(1, Qt::transparent);
gradient.setColorAt(0, color);
gradient.setRadius(radius);
QPoint center;
// Top Left
center = QPoint(radius, radius);
gradient.setCenter(center);
gradient.setFocalPoint(center);
painter.fillRect(0, 0, radius, radius, gradient);
// Top right
center = QPoint(size.width() - radius, radius);
gradient.setCenter(center);
gradient.setFocalPoint(center);
painter.fillRect(center.x(), 0, radius, radius, gradient);
// Bottom left
center = QPoint(radius, size.height() - radius);
gradient.setCenter(center);
gradient.setFocalPoint(center);
painter.fillRect(0, center.y(), radius, radius, gradient);
// Bottom right
center = QPoint(size.width() - radius, size.height() - radius);
gradient.setCenter(center);
gradient.setFocalPoint(center);
painter.fillRect(center.x(), center.y(), radius, radius, gradient);
// Draw borders ----------------------------------
QLinearGradient linearGradient;
linearGradient.setColorAt(1, Qt::transparent);
linearGradient.setColorAt(0, color);
// Top
linearGradient.setStart(0, radius);
linearGradient.setFinalStop(0, 0);
painter.fillRect(radius, 0, size.width() - 2*radius, radius, linearGradient);
// Bottom
linearGradient.setStart(0, size.height() - radius);
linearGradient.setFinalStop(0, size.height());
painter.fillRect(radius, int(linearGradient.start().y()), size.width() - 2*radius, radius, linearGradient);
// Left
linearGradient.setStart(radius, 0);
linearGradient.setFinalStop(0, 0);
painter.fillRect(0, radius, radius, size.height() - 2*radius, linearGradient);
// Right
linearGradient.setStart(size.width() - radius, 0);
linearGradient.setFinalStop(size.width(), 0);
painter.fillRect(int(linearGradient.start().x()), radius, radius, size.height() - 2*radius, linearGradient);
return pix;
}