本文整理汇总了C++中QPainterPath::setElementPositionAt方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainterPath::setElementPositionAt方法的具体用法?C++ QPainterPath::setElementPositionAt怎么用?C++ QPainterPath::setElementPositionAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainterPath
的用法示例。
在下文中一共展示了QPainterPath::setElementPositionAt方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lensDeform
QPainterPath PathDeformRenderer::lensDeform(const QPainterPath &source, const QPointF &offset)
{
QPainterPath path;
path.addPath(source);
qreal flip = m_intensity / qreal(100);
for (int i=0; i<path.elementCount(); ++i) {
const QPainterPath::Element &e = path.elementAt(i);
qreal x = e.x + offset.x();
qreal y = e.y + offset.y();
qreal dx = x - m_pos.x();
qreal dy = y - m_pos.y();
qreal len = m_radius - qSqrt(dx * dx + dy * dy);
if (len > 0) {
path.setElementPositionAt(i,
x + flip * dx * len / m_radius,
y + flip * dy * len / m_radius);
} else {
path.setElementPositionAt(i, x, y);
}
}
return path;
}
示例2: AddTrackingVertex
TrackActivities ViewInteractionItemDrawer::AddTrackingVertex(
const QPointF &src, bool force)
{
QPainterPath p = _vitem->path();
QList<QPolygonF> ps = p.toSubpathPolygons();
Q_ASSERT(ps.size() <= 1);
Q_ASSERT(_vitem->_feature != nullptr);
Q_ASSERT(_vitem->_feature->paths().size() == 1);
_vitem->ClearTempItems();
TrackActivities ret;
int n = _vitem->_feature->get_geometry(0).size();
if (n == 0) {
ret = TryTrackingMulti(src);
if (force && ret.is_tracked()) {
_vitem->add_temp_vertex(ret.closest()._vpos);
}
} else {
Q_ASSERT(p.elementCount() == n || p.elementCount() == n + 1);
if (p.elementCount() == n) {
p.lineTo(src);
} else {
ret = TryTrackingMulti(src);
if (force && ret.is_tracked()) {
p.setElementPositionAt(n, ret.closest()._vpos.x(), ret.closest()._vpos.y());
_vitem->add_temp_vertex(ret.closest()._vpos);
} else {
p.setElementPositionAt(n, src.x(), src.y());
}
}
}
_vitem->setPath(p);
return force ? ret : TrackActivities();
}
示例3: moved
bool Editor::moved( const QPoint& pos )
{
if ( plot() == NULL )
return false;
const QwtScaleMap xMap = plot()->canvasMap( d_editedItem->xAxis() );
const QwtScaleMap yMap = plot()->canvasMap( d_editedItem->yAxis() );
const QPointF p1 = QwtScaleMap::invTransform( xMap, yMap, d_currentPos );
const QPointF p2 = QwtScaleMap::invTransform( xMap, yMap, pos );
#if QT_VERSION >= 0x040600
const QPainterPath shape = d_editedItem->shape().translated( p2 - p1 );
#else
const double dx = p2.x() - p1.x();
const double dy = p2.y() - p1.y();
QPainterPath shape = d_editedItem->shape();
for ( int i = 0; i < shape.elementCount(); i++ )
{
const QPainterPath::Element &el = shape.elementAt( i );
shape.setElementPositionAt( i, el.x + dx, el.y + dy );
}
#endif
d_editedItem->setShape( shape );
d_currentPos = pos;
return true;
}
示例4: qwtRevertPath
static inline void qwtRevertPath( QPainterPath &path )
{
if ( path.elementCount() == 4 )
{
QPainterPath::Element el0 = path.elementAt(0);
QPainterPath::Element el3 = path.elementAt(3);
path.setElementPositionAt( 0, el3.x, el3.y );
path.setElementPositionAt( 3, el0.x, el0.y );
}
}
示例5: 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;
}
示例6: moveHandleTo
//reDraw lineitem by shift mode
QRectF QLineItem::moveHandleTo(int iDragHandle, QPointF qpLocal, QRectF &qrcBondingRect)
{
QRectF qrcRect = QRectF();
qpLocal = mapFromScene(qpLocal);
QPointF actPos = qpLocal;
int iHandleIdx = iDragHandle - 1;
if (bShiftMode)//shift mode 对齐模式
{
QPointF startPos;
int iStartIndex = 0;
if(iHandleIdx == 0)//终点
{
iStartIndex = 0;
}
startPos = path().elementAt(iStartIndex);
double ang = atan2(qpLocal.y()-startPos.y(),qpLocal.x()-startPos.x())*6/PI;
qDebug() << "ang = " << ang;
if (ang >(-1) && ang < 1)
{
actPos = QPointF(qpLocal.x(),startPos.y());
}
else if (ang >2 && ang <4)
{
actPos = QPointF(startPos.x(),qpLocal.y());
}
else if ((ang >5 && ang <6) || (ang <-5 && ang >-6))
{
actPos = QPointF(qpLocal.x(),startPos.y());
}
else if (ang >-4 && ang <-2)
{
actPos = QPointF(startPos.x(),qpLocal.y());
}
}
QPainterPath path = this->path();
path.setElementPositionAt(iHandleIdx, actPos.x(), actPos.y());
this->setPath(path);
return qrcRect;
}
示例7: setElementPositionAt
void tst_QPainterPath::setElementPositionAt()
{
QPainterPath path(QPointF(42., 42.));
QCOMPARE(path.elementCount(), 1);
QVERIFY(path.elementAt(0).type == QPainterPath::MoveToElement);
QCOMPARE(path.elementAt(0).x, qreal(42.));
QCOMPARE(path.elementAt(0).y, qreal(42.));
QPainterPath copy = path;
copy.setElementPositionAt(0, qreal(0), qreal(0));
QCOMPARE(copy.elementCount(), 1);
QVERIFY(copy.elementAt(0).type == QPainterPath::MoveToElement);
QCOMPARE(copy.elementAt(0).x, qreal(0));
QCOMPARE(copy.elementAt(0).y, qreal(0));
QCOMPARE(path.elementCount(), 1);
QVERIFY(path.elementAt(0).type == QPainterPath::MoveToElement);
QCOMPARE(path.elementAt(0).x, qreal(42.));
QCOMPARE(path.elementAt(0).y, qreal(42.));
}
示例8: adjust_coords
void geoGraphicsMultilineItem::adjust_coords(int nNewLevel)
{
if (vi() && nNewLevel != level())
{
/** Since the map is zooming from level() to current level,
* the map size zoom ratio can be calculated using pow below.
* We can get new coord for current zoom level by multiplicative.
*/
double ratio = pow(2.0,(nNewLevel - level()));
QPainterPath p = this->path();
int sz = p.elementCount();
for (int i=0;i<sz;++i)
{
QPainterPath::Element pt = p.elementAt(i);
pt.x *= ratio;
pt.y *= ratio;
p.setElementPositionAt(i,pt.x,pt.y);
}
this->setPath(p);
}
}
示例9: paintContent
//.........这里部分代码省略.........
.arg( m_axisY.unit() );
painter->drawText( contentRect().toRect(), Qt::AlignBottom | Qt::AlignCenter, intervalStr );
// draw elevation profile
painter->setPen( QColor( Qt::black ) );
bool const highRes = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::HighResolution;
QPen pen = painter->pen();
pen.setWidth( highRes ? 2 : 1 );
painter->setPen( pen );
QLinearGradient fillGradient( 0, 0, 0, m_eleGraphHeight );
QColor startColor = Oxygen::forestGreen4;
QColor endColor = Oxygen::hotOrange4;
startColor.setAlpha( 200 );
endColor.setAlpha( 32 );
fillGradient.setColorAt( 0.0, startColor );
fillGradient.setColorAt( 1.0, endColor );
QBrush brush = QBrush( fillGradient );
painter->setBrush( brush );
QPoint oldPos;
oldPos.setX( m_leftGraphMargin );
oldPos.setY( ( m_axisY.minValue() - m_axisY.minValue() )
* m_eleGraphHeight / ( m_axisY.range() / m_shrinkFactorY ) );
oldPos.setY( m_eleGraphHeight - oldPos.y() );
QPainterPath path;
path.moveTo( oldPos.x(), m_eleGraphHeight );
path.lineTo( oldPos.x(), oldPos.y() );
const int start = m_zoomToViewport ? m_firstVisiblePoint : 0;
const int end = m_zoomToViewport ? m_lastVisiblePoint : m_eleData.size() - 1;
for ( int i = start; i <= end; ++i ) {
QPoint newPos;
if ( i == start ) {
// make sure the plot always starts at the y-axis
newPos.setX( 0 );
} else {
newPos.setX( ( m_eleData.value(i).x() - m_axisX.minValue() ) * m_eleGraphWidth / m_axisX.range() );
}
newPos.rx() += m_leftGraphMargin;
if ( newPos.x() != oldPos.x() || newPos.y() != oldPos.y() ) {
newPos.setY( ( m_eleData.value(i).y() - m_axisY.minValue() )
* m_eleGraphHeight / ( m_axisY.range() * m_shrinkFactorY ) );
newPos.setY( m_eleGraphHeight - newPos.y() );
path.lineTo( newPos.x(), newPos.y() );
oldPos = newPos;
}
}
path.lineTo( oldPos.x(), m_eleGraphHeight );
// fill
painter->setPen( QPen( Qt::NoPen ) );
painter->drawPath( path );
// contour
// "remove" the first and last path element first, they are only used to fill down to the bottom
painter->setBrush( QBrush( Qt::NoBrush ) );
path.setElementPositionAt( 0, path.elementAt( 1 ).x, path.elementAt( 1 ).y );
path.setElementPositionAt( path.elementCount()-1,
path.elementAt( path.elementCount()-2 ).x,
path.elementAt( path.elementCount()-2 ).y );
painter->setPen( pen );
painter->drawPath( path );
pen.setWidth( 1 );
painter->setPen( pen );
// draw interactive cursor
const GeoDataCoordinates currentPoint = m_markerPlacemark->coordinate();
if ( currentPoint.isValid() ) {
painter->setPen( QColor( Qt::white ) );
painter->drawLine( m_leftGraphMargin + m_cursorPositionX, 0,
m_leftGraphMargin + m_cursorPositionX, m_eleGraphHeight );
qreal xpos = m_axisX.minValue() + ( m_cursorPositionX / m_eleGraphWidth ) * m_axisX.range();
qreal ypos = m_eleGraphHeight - ( ( currentPoint.altitude() - m_axisY.minValue() ) / ( qMax<qreal>( 1.0, m_axisY.range() ) * m_shrinkFactorY ) ) * m_eleGraphHeight;
painter->drawLine( m_leftGraphMargin + m_cursorPositionX - 5, ypos,
m_leftGraphMargin + m_cursorPositionX + 5, ypos );
intervalStr.setNum( xpos * m_axisX.scale(), 'f', 2 );
intervalStr += ' ' + m_axisX.unit();
int currentStringBegin = m_leftGraphMargin + m_cursorPositionX
- QFontMetricsF( font() ).width( intervalStr ) / 2;
painter->drawText( currentStringBegin, contentSize().height() - 1.5 * m_fontHeight, intervalStr );
intervalStr.setNum( currentPoint.altitude(), 'f', 1 );
intervalStr += ' ' + m_axisY.unit();
if ( m_cursorPositionX + QFontMetricsF( font() ).width( intervalStr ) + m_leftGraphMargin
< m_eleGraphWidth ) {
currentStringBegin = ( m_leftGraphMargin + m_cursorPositionX + 5 + 2 );
} else {
currentStringBegin = m_leftGraphMargin + m_cursorPositionX - 5
- QFontMetricsF( font() ).width( intervalStr ) * 1.5;
}
// Make sure the text still fits into the window
while ( ypos < m_fontHeight ) {
ypos++;
}
painter->drawText( currentStringBegin, ypos + m_fontHeight / 2, intervalStr );
}
painter->restore();
}