本文整理汇总了C++中QBrush::transform方法的典型用法代码示例。如果您正苦于以下问题:C++ QBrush::transform方法的具体用法?C++ QBrush::transform怎么用?C++ QBrush::transform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBrush
的用法示例。
在下文中一共展示了QBrush::transform方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveOdfGradientStyle
QString KoOdfGraphicStyles::saveOdfGradientStyle(KoGenStyles &mainStyles, const QBrush &brush)
{
KoGenStyle gradientStyle;
if (brush.style() == Qt::RadialGradientPattern) {
const QRadialGradient *gradient = static_cast<const QRadialGradient*>(brush.gradient());
gradientStyle = KoGenStyle(KoGenStyle::RadialGradientStyle /*no family name*/);
gradientStyle.addAttributePercent("svg:cx", gradient->center().x() * 100);
gradientStyle.addAttributePercent("svg:cy", gradient->center().y() * 100);
gradientStyle.addAttributePercent("svg:r", gradient->radius() * 100);
gradientStyle.addAttributePercent("svg:fx", gradient->focalPoint().x() * 100);
gradientStyle.addAttributePercent("svg:fy", gradient->focalPoint().y() * 100);
} else if (brush.style() == Qt::LinearGradientPattern) {
const QLinearGradient *gradient = static_cast<const QLinearGradient*>(brush.gradient());
gradientStyle = KoGenStyle(KoGenStyle::LinearGradientStyle /*no family name*/);
gradientStyle.addAttributePercent("svg:x1", gradient->start().x() * 100);
gradientStyle.addAttributePercent("svg:y1", gradient->start().y() * 100);
gradientStyle.addAttributePercent("svg:x2", gradient->finalStop().x() * 100);
gradientStyle.addAttributePercent("svg:y2", gradient->finalStop().y() * 100);
} else if (brush.style() == Qt::ConicalGradientPattern) {
const QConicalGradient * gradient = static_cast<const QConicalGradient*>(brush.gradient());
gradientStyle = KoGenStyle(KoGenStyle::ConicalGradientStyle /*no family name*/);
gradientStyle.addAttributePercent("svg:cx", gradient->center().x() * 100);
gradientStyle.addAttributePercent("svg:cy", gradient->center().y() * 100);
gradientStyle.addAttribute("draw:angle", QString("%1").arg(gradient->angle()));
}
const QGradient * gradient = brush.gradient();
if (gradient->spread() == QGradient::RepeatSpread)
gradientStyle.addAttribute("svg:spreadMethod", "repeat");
else if (gradient->spread() == QGradient::ReflectSpread)
gradientStyle.addAttribute("svg:spreadMethod", "reflect");
else
gradientStyle.addAttribute("svg:spreadMethod", "pad");
if (! brush.transform().isIdentity()) {
gradientStyle.addAttribute("svg:gradientTransform", saveTransformation(brush.transform()));
}
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
KoXmlWriter elementWriter(&buffer); // TODO pass indentation level
// save stops
QGradientStops stops = gradient->stops();
Q_FOREACH (const QGradientStop & stop, stops) {
elementWriter.startElement("svg:stop");
elementWriter.addAttribute("svg:offset", QString("%1").arg(stop.first));
elementWriter.addAttribute("svg:stop-color", stop.second.name());
if (stop.second.alphaF() < 1.0)
elementWriter.addAttribute("svg:stop-opacity", QString("%1").arg(stop.second.alphaF()));
elementWriter.endElement();
}
示例2: stroke
void QEmulationPaintEngine::stroke(const QVectorPath &path, const QPen &pen)
{
QPainterState *s = state();
if (s->bgMode == Qt::OpaqueMode && pen.style() > Qt::SolidLine) {
QPen bgPen = pen;
bgPen.setBrush(s->bgBrush);
bgPen.setStyle(Qt::SolidLine);
real_engine->stroke(path, bgPen);
}
QBrush brush = pen.brush();
QPen copy = pen;
Qt::BrushStyle style = qbrush_style(brush);
if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) {
const QGradient *g = brush.gradient();
if (g->coordinateMode() > QGradient::LogicalMode) {
if (g->coordinateMode() == QGradient::StretchToDeviceMode) {
QTransform mat = brush.transform();
mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height());
brush.setTransform(mat);
copy.setBrush(brush);
real_engine->stroke(path, copy);
return;
} else if (g->coordinateMode() == QGradient::ObjectBoundingMode) {
QTransform mat = brush.transform();
QRectF r = path.controlPointRect();
mat.translate(r.x(), r.y());
mat.scale(r.width(), r.height());
brush.setTransform(mat);
copy.setBrush(brush);
real_engine->stroke(path, copy);
return;
}
}
}
real_engine->stroke(path, pen);
}
示例3: fill
void QEmulationPaintEngine::fill(const QVectorPath &path, const QBrush &brush)
{
QPainterState *s = state();
if (s->bgMode == Qt::OpaqueMode) {
Qt::BrushStyle style = brush.style();
if (style >= Qt::Dense1Pattern && style <= Qt::DiagCrossPattern)
real_engine->fill(path, s->bgBrush);
}
Qt::BrushStyle style = qbrush_style(brush);
if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) {
const QGradient *g = brush.gradient();
if (g->coordinateMode() > QGradient::LogicalMode) {
if (g->coordinateMode() == QGradient::StretchToDeviceMode) {
QBrush copy = brush;
QTransform mat = copy.transform();
mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height());
copy.setTransform(mat);
real_engine->fill(path, copy);
return;
} else if (g->coordinateMode() == QGradient::ObjectBoundingMode) {
QBrush copy = brush;
QTransform mat = copy.transform();
QRectF r = path.controlPointRect();
mat.translate(r.x(), r.y());
mat.scale(r.width(), r.height());
copy.setTransform(mat);
real_engine->fill(path, copy);
return;
}
}
}
real_engine->fill(path, brush);
}
示例4: loadStyle
bool KGradientBackground::loadStyle(KOdfLoadingContext &context, const QSizeF &shapeSize)
{
Q_D(KGradientBackground);
KOdfStyleStack &styleStack = context.styleStack();
if (! styleStack.hasProperty(KOdfXmlNS::draw, "fill"))
return false;
QString fillStyle = styleStack.property(KOdfXmlNS::draw, "fill");
if (fillStyle == "gradient") {
QBrush brush = KOdf::loadOdfGradientStyle(styleStack, context.stylesReader(), shapeSize);
const QGradient * gradient = brush.gradient();
if (gradient) {
d->gradient = KFlake::cloneGradient(gradient);
d->matrix = brush.transform();
return true;
}
}
return false;
}
示例5: stroke
//.........这里部分代码省略.........
d->activeStroker->lineTo(path.points()[0], path.points()[1]);
} else {
d->activeStroker->moveTo(points[0], points[1]);
points += 2;
while (points < lastPoint) {
d->activeStroker->lineTo(points[0], points[1]);
points += 2;
}
if (path.hasImplicitClose())
d->activeStroker->lineTo(path.points()[0], path.points()[1]);
}
d->activeStroker->end();
if (!d->strokeHandler->types.size()) // an empty path...
return;
QVectorPath strokePath(d->strokeHandler->pts.data(),
d->strokeHandler->types.size(),
d->strokeHandler->types.data(),
flags);
fill(strokePath, pen.brush());
} else {
// For cosmetic pens we need a bit of trickery... We to process xform the input points
if (state()->matrix.type() >= QTransform::TxProject) {
QPainterPath painterPath = state()->matrix.map(path.convertToPainterPath());
d->activeStroker->strokePath(painterPath, d->strokeHandler, QTransform());
} else {
d->activeStroker->setCurveThresholdFromTransform(QTransform());
d->activeStroker->begin(d->strokeHandler);
if (types) {
while (points < lastPoint) {
switch (*types) {
case QPainterPath::MoveToElement: {
QPointF pt = (*(QPointF *) points) * state()->matrix;
d->activeStroker->moveTo(pt.x(), pt.y());
points += 2;
++types;
break;
}
case QPainterPath::LineToElement: {
QPointF pt = (*(QPointF *) points) * state()->matrix;
d->activeStroker->lineTo(pt.x(), pt.y());
points += 2;
++types;
break;
}
case QPainterPath::CurveToElement: {
QPointF c1 = ((QPointF *) points)[0] * state()->matrix;
QPointF c2 = ((QPointF *) points)[1] * state()->matrix;
QPointF e = ((QPointF *) points)[2] * state()->matrix;
d->activeStroker->cubicTo(c1.x(), c1.y(), c2.x(), c2.y(), e.x(), e.y());
points += 6;
types += 3;
flags |= QVectorPath::CurvedShapeMask;
break;
}
default:
break;
}
}
if (path.hasImplicitClose()) {
QPointF pt = * ((QPointF *) path.points()) * state()->matrix;
d->activeStroker->lineTo(pt.x(), pt.y());
}
} else {
QPointF p = ((QPointF *)points)[0] * state()->matrix;
d->activeStroker->moveTo(p.x(), p.y());
points += 2;
while (points < lastPoint) {
QPointF p = ((QPointF *)points)[0] * state()->matrix;
d->activeStroker->lineTo(p.x(), p.y());
points += 2;
}
if (path.hasImplicitClose())
d->activeStroker->lineTo(p.x(), p.y());
}
d->activeStroker->end();
}
QVectorPath strokePath(d->strokeHandler->pts.data(),
d->strokeHandler->types.size(),
d->strokeHandler->types.data(),
flags);
QTransform xform = state()->matrix;
state()->matrix = QTransform();
transformChanged();
QBrush brush = pen.brush();
if (qbrush_style(brush) != Qt::SolidPattern)
brush.setTransform(brush.transform() * xform);
fill(strokePath, brush);
state()->matrix = xform;
transformChanged();
}
}
示例6: fillRect
void QBlitterPaintEngine::fillRect(const QRectF &rect, const QBrush &brush)
{
if (rect.size().isEmpty())
return;
Q_D(QBlitterPaintEngine);
if (qbrush_style(brush) == Qt::SolidPattern
&& d->caps.canBlitterAlphaFillRect()) {
d->fillRect(rect, qbrush_color(brush), true);
} else if (qbrush_style(brush) == Qt::SolidPattern
&& qbrush_color(brush).alpha() == 0xff
&& d->caps.canBlitterFillRect()) {
d->fillRect(rect, qbrush_color(brush), false);
} else if ((brush.style() == Qt::TexturePattern) &&
(brush.transform().type() <= QTransform::TxTranslate) &&
((d->caps.canBlitterDrawPixmapOpacity(brush.texture())) ||
(d->caps.canBlitterDrawPixmap(rect, brush.texture(), rect)))) {
bool rectIsFilled = false;
QRectF transformedRect = state()->matrix.mapRect(rect);
qreal x = transformedRect.x();
qreal y = transformedRect.y();
QPixmap pm = brush.texture();
d->unlock();
int srcX = int(rect.x() - state()->brushOrigin.x() - brush.transform().dx()) % pm.width();
if (srcX < 0)
srcX = pm.width() + srcX;
const int startX = srcX;
int srcY = int(rect.y() - state()->brushOrigin.y() - brush.transform().dy()) % pm.height();
if (srcY < 0)
srcY = pm.height() + srcY;
while (!rectIsFilled) {
qreal blitWidth = (pm.width() ) - srcX;
qreal blitHeight = (pm.height() ) - srcY;
if (x + blitWidth > transformedRect.right())
blitWidth = transformedRect.right() -x;
if (y + blitHeight > transformedRect.bottom())
blitHeight = transformedRect.bottom() - y;
const QClipData *clipData = d->clip();
if (clipData->hasRectClip) {
QRect targetRect = QRect(x, y, blitWidth, blitHeight).intersected(clipData->clipRect);
if (targetRect.isValid()) {
int tmpSrcX = srcX + (targetRect.x() - x);
int tmpSrcY = srcY + (targetRect.y() - y);
QRect srcRect(tmpSrcX, tmpSrcY, targetRect.width(), targetRect.height());
d->pmData->blittable()->drawPixmap(targetRect, pm, srcRect);
}
} else if (clipData->hasRegionClip) {
QVector<QRect> clipRects = clipData->clipRegion.rects();
QRect unclippedTargetRect(x, y, blitWidth, blitHeight);
QRegion intersectedRects = clipData->clipRegion.intersected(unclippedTargetRect);
for (int i = 0; i < intersectedRects.rects().size(); ++i) {
QRect targetRect = intersectedRects.rects().at(i);
if (!targetRect.isValid() || targetRect.isEmpty())
continue;
int tmpSrcX = srcX + (targetRect.x() - x);
int tmpSrcY = srcY + (targetRect.y() - y);
QRect srcRect(tmpSrcX, tmpSrcY, targetRect.width(), targetRect.height());
d->pmData->blittable()->drawPixmap(targetRect, pm, srcRect);
}
}
x+=blitWidth;
if (qFuzzyCompare(x, transformedRect.right())) {
x = transformedRect.x();
srcX = startX;
srcY = 0;
y += blitHeight;
if (qFuzzyCompare(y, transformedRect.bottom()))
rectIsFilled = true;
} else
srcX = 0;
}
} else {
d->lock();
d->pmData->markRasterOverlay(rect);
QRasterPaintEngine::fillRect(rect, brush);
}
}
示例7: switch
//.........这里部分代码省略.........
case Qt::SolidPattern:
{
ComPtr<ID2D1SolidColorBrush> solid;
hr = dc()->CreateSolidColorBrush(to_d2d_color_f(newBrush.color()), &solid);
if (FAILED(hr)) {
qWarning("%s: Could not create solid color brush: %#x", __FUNCTION__, hr);
break;
}
hr = solid.As(&result);
if (FAILED(hr))
qWarning("%s: Could not convert solid color brush: %#x", __FUNCTION__, hr);
}
break;
case Qt::Dense1Pattern:
case Qt::Dense2Pattern:
case Qt::Dense3Pattern:
case Qt::Dense4Pattern:
case Qt::Dense5Pattern:
case Qt::Dense6Pattern:
case Qt::Dense7Pattern:
case Qt::HorPattern:
case Qt::VerPattern:
case Qt::CrossPattern:
case Qt::BDiagPattern:
case Qt::FDiagPattern:
case Qt::DiagCrossPattern:
{
ComPtr<ID2D1BitmapBrush1> bitmapBrush;
D2D1_BITMAP_BRUSH_PROPERTIES1 bitmapBrushProperties = {
D2D1_EXTEND_MODE_WRAP,
D2D1_EXTEND_MODE_WRAP,
interpolationMode()
};
QImage brushImg = qt_imageForBrush(newBrush.style(), false);
brushImg.setColor(0, newBrush.color().rgba());
brushImg.setColor(1, qRgba(0, 0, 0, 0));
QWindowsDirect2DBitmap bitmap;
bool success = bitmap.fromImage(brushImg, Qt::AutoColor);
if (!success) {
qWarning("%s: Could not create Direct2D bitmap from Qt pattern brush image", __FUNCTION__);
break;
}
hr = dc()->CreateBitmapBrush(bitmap.bitmap(),
bitmapBrushProperties,
&bitmapBrush);
if (FAILED(hr)) {
qWarning("%s: Could not create Direct2D bitmap brush for Qt pattern brush: %#x", __FUNCTION__, hr);
break;
}
hr = bitmapBrush.As(&result);
if (FAILED(hr))
qWarning("%s: Could not convert Direct2D bitmap brush for Qt pattern brush: %#x", __FUNCTION__, hr);
}
break;
case Qt::LinearGradientPattern:
case Qt::RadialGradientPattern:
case Qt::ConicalGradientPattern:
*needsEmulation = true;
break;
case Qt::TexturePattern:
{
ComPtr<ID2D1BitmapBrush1> bitmapBrush;
D2D1_BITMAP_BRUSH_PROPERTIES1 bitmapBrushProperties = {
D2D1_EXTEND_MODE_WRAP,
D2D1_EXTEND_MODE_WRAP,
interpolationMode()
};
QWindowsDirect2DPlatformPixmap *pp = static_cast<QWindowsDirect2DPlatformPixmap *>(newBrush.texture().handle());
QWindowsDirect2DBitmap *bitmap = pp->bitmap();
hr = dc()->CreateBitmapBrush(bitmap->bitmap(),
bitmapBrushProperties,
&bitmapBrush);
if (FAILED(hr)) {
qWarning("%s: Could not create texture brush: %#x", __FUNCTION__, hr);
break;
}
hr = bitmapBrush.As(&result);
if (FAILED(hr))
qWarning("%s: Could not convert texture brush: %#x", __FUNCTION__, hr);
}
break;
}
if (result && !newBrush.transform().isIdentity())
result->SetTransform(to_d2d_matrix_3x2_f(newBrush.transform()));
return result;
}