本文整理汇总了C++中QRadialGradient::setCoordinateMode方法的典型用法代码示例。如果您正苦于以下问题:C++ QRadialGradient::setCoordinateMode方法的具体用法?C++ QRadialGradient::setCoordinateMode怎么用?C++ QRadialGradient::setCoordinateMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QRadialGradient
的用法示例。
在下文中一共展示了QRadialGradient::setCoordinateMode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EllipseShape
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;
}
示例2: loadComposite
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);
}
示例3: 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 );
//.........这里部分代码省略.........
示例4: 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;
}
示例5: paintEvent
void GroupBoxWidget::paintEvent(QPaintEvent * /*event*/)
{
// skip the rest of the painting if no text
if (m_titleText.isEmpty())
return;
// draw hovering
QPainter p(this);
if (m_hoverValue > 0 && (m_checkValue == 0.0 || m_checkValue == 1.0)) {
QRadialGradient rg = m_checkValue == 1.0 ? QRadialGradient(0.5, 0.2, 0.8) : QRadialGradient(0.5, 1.0, 1.5);
QColor startColor(Qt::white);
startColor.setAlpha((int)(255.0 * m_hoverValue));
rg.setColorAt(0.0, startColor);
rg.setColorAt(1.0, Qt::transparent);
rg.setColorAt(0.0, startColor);
rg.setColorAt(1.0, Qt::transparent);
rg.setCoordinateMode(QGradient::ObjectBoundingMode);
p.fillRect(0, 0, width(), height() - m_checkValue * (height() - 12) , rg);
}
// draw left/right lines
if (m_borderFlags & 0x0001)
p.fillRect(0, 0, 1, height(), QColor(230, 230, 230));
if (m_borderFlags & 0x0002)
p.fillRect(width() - 1, 0, 1, height(), Qt::white);
// precalc text position and move painter
QStyle * ss = m_checkable ? style() : 0;
int indW = ss ? ss->pixelMetric(QStyle::PM_IndicatorWidth, 0, 0) : 0;
int indH = ss ? ss->pixelMetric(QStyle::PM_IndicatorHeight, 0, 0) : 0;
p.save();
p.setFont(m_titleFont);
QFontMetrics metrics(m_titleFont);
QRect textRect = metrics.boundingRect(m_titleText);
// int textHeight = textRect.height();
int dx = 0;
if (m_checkValue < 1.0) {
qreal x1 = -textRect.top() + 2,
x2 = (width() - textRect.width() - indW - 4) / 2;
qreal y1 = height() - 2, //height() + textRect.width()) / 2,
y2 = -textRect.top();
p.translate(x1 + m_checkValue * (x2 - x1), y1 + m_checkValue * (y2 - y1));
p.rotate(m_checkValue * 90 - 90);
} else
p.translate((width() - textRect.width() - indW - 4) / 2, -textRect.top());
// draw checkbox indicator
if (m_checkable && indW && indH) {
QStyleOptionButton opt;
opt.state = QStyle::State_Enabled;
int styleOffset = (textRect.height() - indH) / 2;
opt.rect = QRect(0, -indH + 4 - styleOffset, indW, indH);
dx = indW + 4;
opt.state |= m_checked ? QStyle::State_On : QStyle::State_Off;
if (underMouse())
opt.state |= QStyle::State_MouseOver;
//p.setRenderHints(QPainter::Antialiasing);
style()->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &p, this);
}
// draw text
p.drawText(dx, 0, m_titleText);
p.restore();
}
示例6: 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
//.........这里部分代码省略.........