本文整理汇总了C++中QPainterPath::translate方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainterPath::translate方法的具体用法?C++ QPainterPath::translate怎么用?C++ QPainterPath::translate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainterPath
的用法示例。
在下文中一共展示了QPainterPath::translate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateTextPath
void ArcItem::updateTextPath() {
QPainterPath path;
if((_endItem && _startItem->collidesWithItem(_endItem)) ||
(!_endItem && _startItem->contains(_end)))
return;
QPointF start(0,0),
point = _end - pos();
//The arrow line and reverse liune
QLineF line(start, point);
QLineF revline(point, start);
//Make some text
if(this->weight() != 1){
QFont font;
font.setPointSizeF(6);
path.addText(QPointF(0,0), font, QString::number(this->weight()));
//Move it into some reasonable position
path.translate(-path.boundingRect().width()/2, -3);
QTransform rotation;
qreal angle = line.angle();
if(angle > 90 && angle < 270)
angle = 180 - angle;
else
angle = 360 - angle;
rotation.rotate(angle);
path = rotation.map(path);
path.translate(point/2);
}
_cachedTextPath = path;
}
示例2: draw
void ChordLine::draw(QPainter* painter) const
{
qreal _spatium = spatium();
if (this->isStraight()) {
painter->scale(_spatium, _spatium);
painter->setPen(QPen(curColor(), .15, Qt::SolidLine));
painter->setBrush(Qt::NoBrush);
QPainterPath pathOffset = path;
float offset = 0.5;
if (_chordLineType == ChordLineType::FALL)
pathOffset.translate(offset, -offset);
else if (_chordLineType == ChordLineType::DOIT)
pathOffset.translate(offset, offset);
else if (_chordLineType == ChordLineType::SCOOP)
pathOffset.translate(-offset, offset);
else if (_chordLineType == ChordLineType::PLOP)
pathOffset.translate(-offset, -offset);
painter->drawPath(pathOffset);
painter->scale(1.0/_spatium, 1.0/_spatium);
}
else {
painter->scale(_spatium, _spatium);
painter->setPen(QPen(curColor(), .15, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter->setBrush(Qt::NoBrush);
painter->drawPath(path);
painter->scale(1.0/_spatium, 1.0/_spatium);
}
}
示例3: metrics
PlainTextItem(QString text, QFont font, double width, double height, QBrush brush, QColor outlineColor, double outline, int align, int lineSpacing)
{
m_boundingRect = QRectF(0, 0, width, height);
m_brush = brush;
m_outline = outline;
m_pen = QPen(outlineColor);
m_pen.setWidthF(outline);
QFontMetrics metrics(font);
lineSpacing += metrics.lineSpacing();
// Calculate line width
QStringList lines = text.split('\n');
double linePos = metrics.ascent();
foreach(const QString &line, lines)
{
QPainterPath linePath;
linePath.addText(0, linePos, font, line);
linePos += lineSpacing;
if ( align == Qt::AlignHCenter )
{
double offset = (width - metrics.width(line)) / 2;
linePath.translate(offset, 0);
} else if ( align == Qt::AlignRight ) {
double offset = (width - metrics.width(line));
linePath.translate(offset, 0);
}
m_path = m_path.united(linePath);
}
示例4: paintMeshElToBeHigh
void EditorArea::paintMeshElToBeHigh(QPainter &painter)
{
qreal radius = size2screen(8);
float fontSize = size2screen(12);
qreal width = radius * 2;
qreal height = radius * 2;
QPainterPath path;
QPainterPath text;
QPainterPath circle;
path.arcTo(QRectF(-radius, -radius, width, height), 0, 360);
text.addText(-radius / 2.0, radius / 2.0, QFont("Arial", fontSize), meshElsType.value(meshElToBeHigh));
circle.arcTo(QRectF(-radius * 3 / 2, -radius * 3 / 2, width * 3 / 2, height * 3 / 2), 0, 360);
path.translate(meshElsPos.value(meshElToBeHigh));
text.translate(meshElsPos.value(meshElToBeHigh));
circle.translate(meshElsPos.value(meshElToBeHigh));
painter.setPen(Qt::NoPen);
painter.setBrush(Qt::magenta);
painter.drawPath(circle);
painter.setBrush(Qt::darkCyan);
painter.drawPath(path);
painter.setPen(Qt::yellow);
painter.setBrush(Qt::yellow);
painter.drawPath(text);
}
示例5: updateShadow
void MyTextItem::updateShadow()
{
QString text = toPlainText();
if (text.isEmpty()) {
m_shadow = QImage();
return;
}
QFontMetrics metrics(font());
//ADJUST TO CURRENT SETTING
int lineSpacing = data(TitleDocument::LineSpacing).toInt() + metrics.lineSpacing();
QPainterPath path;
// Calculate line width
QStringList lines = text.split('\n');
double linePos = metrics.ascent();
QRectF bounding = boundingRect();
foreach(const QString &line, lines)
{
QPainterPath linePath;
linePath.addText(0, linePos, font(), line);
linePos += lineSpacing;
if ( m_alignment == Qt::AlignHCenter ) {
double offset = (bounding.width() - metrics.width(line)) / 2;
linePath.translate(offset, 0);
} else if ( m_alignment == Qt::AlignRight ) {
double offset = (bounding.width() - metrics.width(line));
linePath.translate(offset, 0);
}
path.addPath(linePath);
}
示例6: path
QPainterPath LineBand::path()
{
//move the path so it accounts for the position of the selectionband
QPainterPath temppath = mIntersectionPath;
temppath.translate(getTopLeft());
return temppath;
}
示例7: drawArrow
void MapView::drawArrow(QPainter &painter, const QPoint &p)
{
QPainterPath path;
path.moveTo(0, 0);
path.lineTo(1, 0);
path.lineTo(7, 15);
path.lineTo(0, 10);
path.lineTo(-7, 15);
path.lineTo(0, 0);
path.translate(p);
path.translate(0, 2);
painter.fillPath(path, QBrush(Qt::yellow));
}
示例8: createArrow
static QPainterPath createArrow()
{
const qreal arrowHeadPos = 10;
const qreal arrowHeadLength = 4;
const qreal arrowHeadWidth = 4;
const qreal arcWidth = 2;
const qreal outerArcSize = arrowHeadPos + arcWidth - arrowHeadLength;
const qreal innerArcSize = arrowHeadPos - arcWidth - arrowHeadLength;
QPainterPath path;
path.moveTo(arrowHeadPos, 0);
path.lineTo(arrowHeadPos + arrowHeadWidth, arrowHeadLength);
path.lineTo(arrowHeadPos + arcWidth, arrowHeadLength);
path.arcTo(QRectF(arrowHeadLength - outerArcSize,
arrowHeadLength - outerArcSize,
outerArcSize * 2,
outerArcSize * 2),
0, -90);
path.lineTo(arrowHeadLength, arrowHeadPos + arrowHeadWidth);
path.lineTo(0, arrowHeadPos);
path.lineTo(arrowHeadLength, arrowHeadPos - arrowHeadWidth);
path.lineTo(arrowHeadLength, arrowHeadPos - arcWidth);
path.arcTo(QRectF(arrowHeadLength - innerArcSize,
arrowHeadLength - innerArcSize,
innerArcSize * 2,
innerArcSize * 2),
-90, 90);
path.lineTo(arrowHeadPos - arrowHeadWidth, arrowHeadLength);
path.closeSubpath();
path.translate(-3, -3);
return path;
}
示例9: updateShapeCache
void TopologyNode::updateShapeCache()
{
QPainterPath shapePath;
QString imagePath;
#ifdef PLUGIN_TARGET
if(mNodeFlags & NF_ISCENTRALROUTER)
{
Q_ASSERT (m_paintStrategy);
imagePath = m_paintStrategy->getImageName();
}
else
#endif
{
#ifdef POWERLINE_REVISION
if(m_isPowerLine)
{
imagePath = GENIE2_RES("map/devices/PowerLineNormal.png");
}
else
#endif
{
imagePath = getDeviceTypeImagePath(m_deviceType,DTIR_NORMAL);
}
}
QPixmap pixDetecter(imagePath);
shapePath.addRegion(QRegion(pixDetecter.mask()));
shapePath.translate(-pixDetecter.width() / 2,-pixDetecter.height() / 2);
m_shapePath = shapePath;
}
示例10: RefreshCurve
/**
* @brief RefreshCurve refresh curve on scene.
* @param curve curve.
* @param curveId curve id.
*/
void VToolCutSpline::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition,
PathDirection direction)
{
const QSharedPointer<VSpline> spl = VAbstractTool::data.GeometricObject<VSpline>(curveId);
QPainterPath path;
path.addPath(spl->GetPath(direction));
path.setFillRule( Qt::WindingFill );
if (curvePosition == SimpleCurvePoint::FirstPoint)
{
path.translate(-spl->GetP1().toQPointF().x(), -spl->GetP1().toQPointF().y());
}
else
{
path.translate(-spl->GetP4().toQPointF().x(), -spl->GetP4().toQPointF().y());
}
curve->setPath(path);
}
示例11: paintEvent
void ToolButton::paintEvent(QPaintEvent *) {
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
p.setPen(Qt::black);
p.setBrush(_flashBackground != Qt::lightGray
? _flashBackground
: _mousePressPoint.isNull()
? (_mouseCurrentlyOver ? Qt::darkGray : Qt::lightGray)
: Qt::white);
p.drawRoundedRect(rect(), 20, 20, Qt::RelativeSize);
if (_tool) {
p.drawPixmap(2, 2, _tool->icon()
.pixmap(iconSize(), _currentlyTriggerable
? QIcon::Normal : QIcon::Disabled));
}
if (!_keyLabel.isNull()) {
QPainterPath pp;
QFont font = this->font();
//QFont font("Sans");
//font.setPointSize(10);
pp.addText(QPointF(0, 0), font, _keyLabel);
pp.translate(width()-2-pp.boundingRect().width()-pp.boundingRect().x(),
height()-2-pp.boundingRect().height()-pp.boundingRect().y());
p.setRenderHint(QPainter::Antialiasing);
// LATER parametrize outline and main letter colors
p.setBrush(Qt::white);
p.setPen(Qt::white);
p.drawPath(pp);
p.setBrush(Qt::darkBlue);
p.setPen(Qt::transparent);
p.drawPath(pp);
}
// LATER use icon rather than text as target indicator
QString targetIndicator("?");
switch (_targetType) {
case TargetManager::PrimaryTarget:
targetIndicator = QString();
break;
case TargetManager::PreviousPrimaryTarget:
targetIndicator = "p";
break;
case TargetManager::MouseOverTarget:
targetIndicator = "o";
break;
}
if (!targetIndicator.isEmpty()) {
QFont font = this->font();
//font.setPointSize(10);
p.setFont(font);
p.setPen(Qt::black);
QFontMetrics fm(font);
p.drawText(QRectF(2, height()-2-fm.height(), width()-4, fm.maxWidth()),
Qt::AlignLeft, targetIndicator);
}
p.end();
}
示例12: paintNodes
void EditorArea::paintNodes(QPainter &painter)
{
bool firstTime = true;
qreal radius = size2screen(6);
qreal width = radius * 2;
qreal height = radius * 2;
QVector<int> nodesIds = workspace->getNodesIds();
for (int i=0; i < nodesIds.size(); i++) {
QPointF screenXY = graph2screen(workspace->getNodePosition(nodesIds[i]));
if (workspace->getNodeMov(nodesIds[i])) {
painter.setPen(Qt::NoPen);
} else {
painter.setPen(QPen(Qt::darkRed, size2screen(3), Qt::SolidLine,
Qt::RoundCap, Qt::RoundJoin));
}
QPainterPath path;
path.arcTo(QRectF(-radius, -radius, width, height), 0, 360);
path.translate(screenXY);
painter.drawPath(path);
QPainterPath mousePath;
mousePath.arcTo(QRectF(-5, -5, 10, 10), 0, 360);
mousePath.translate(mouseCurrentPos);
if (path.intersects(mousePath)) {
if (firstTime) {
firstTime = false;
hitElements.clear();
}
QPoint temp(1, nodesIds[i]);
hitElements.append(temp);
}
}
}
示例13: brushOutline
QPainterPath KisChalkPaintOpSettings::brushOutline(const QPointF& pos, KisPaintOpSettings::OutlineMode mode, qreal scale, qreal rotation) const
{
Q_UNUSED(scale);
Q_UNUSED(rotation);
QPainterPath path;
if (mode == CursorIsOutline){
qreal size = getInt(CHALK_RADIUS) * 2 + 1;
QRectF rc(0, 0, size, size);
rc.translate(-rc.center());
path.addEllipse(rc);
path.translate(pos);
}
return path;
}
示例14: translate
void tst_QPainterPath::translate()
{
QPainterPath path;
// Path with no elements.
QCOMPARE(path.currentPosition(), QPointF());
path.translate(50.5, 50.5);
QCOMPARE(path.currentPosition(), QPointF());
QCOMPARE(path.translated(50.5, 50.5).currentPosition(), QPointF());
// path.isEmpty(), but we have one MoveTo element that should be translated.
path.moveTo(50, 50);
QCOMPARE(path.currentPosition(), QPointF(50, 50));
path.translate(99.9, 99.9);
QCOMPARE(path.currentPosition(), QPointF(149.9, 149.9));
path.translate(-99.9, -99.9);
QCOMPARE(path.currentPosition(), QPointF(50, 50));
QCOMPARE(path.translated(-50, -50).currentPosition(), QPointF(0, 0));
// Complex path.
QRegion shape(100, 100, 300, 200, QRegion::Ellipse);
shape -= QRect(225, 175, 50, 50);
QPainterPath complexPath;
complexPath.addRegion(shape);
QVector<QPointF> untranslatedElements;
for (int i = 0; i < complexPath.elementCount(); ++i)
untranslatedElements.append(QPointF(complexPath.elementAt(i)));
const QPainterPath untranslatedComplexPath(complexPath);
const QPointF offset(100, 100);
complexPath.translate(offset);
for (int i = 0; i < complexPath.elementCount(); ++i)
QCOMPARE(QPointF(complexPath.elementAt(i)) - offset, untranslatedElements.at(i));
QCOMPARE(complexPath.translated(-offset), untranslatedComplexPath);
}
示例15: shape
QPainterPath MapObjectItem::shape() const
{
QPainterPath path = mMapDocument->renderer()->shape(mObject);
#if QT_VERSION >= 0x040600
path.translate(-pos());
#else
const QPointF p = pos();
const int elementCount = path.elementCount();
for (int i = 0; i < elementCount; i++) {
const QPainterPath::Element &element = path.elementAt(i);
path.setElementPositionAt(i, element.x - p.x(), element.y - p.y());
}
#endif
return path;
}