当前位置: 首页>>代码示例>>C++>>正文


C++ QPainterPath类代码示例

本文整理汇总了C++中QPainterPath的典型用法代码示例。如果您正苦于以下问题:C++ QPainterPath类的具体用法?C++ QPainterPath怎么用?C++ QPainterPath使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QPainterPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: QPixmap

void ArthurFrame::paintEvent(QPaintEvent *e)
{
#ifdef Q_WS_QWS
    static QPixmap *static_image = 0;
#else
    static QImage *static_image = 0;
#endif
    QPainter painter;
    if (preferImage()
#ifdef QT_OPENGL_SUPPORT
        && !m_use_opengl
#endif
        ) {
        if (!static_image || static_image->size() != size()) {
            delete static_image;
#ifdef Q_WS_QWS
            static_image = new QPixmap(size());
#else
            static_image = new QImage(size(), QImage::Format_RGB32);
#endif
        }
        painter.begin(static_image);

        int o = 10;

        QBrush bg = palette().brush(QPalette::Background);
        painter.fillRect(0, 0, o, o, bg);
        painter.fillRect(width() - o, 0, o, o, bg);
        painter.fillRect(0, height() - o, o, o, bg);
        painter.fillRect(width() - o, height() - o, o, o, bg);
    } else {
#ifdef QT_OPENGL_SUPPORT
        if (m_use_opengl) {
            painter.begin(glw);
            painter.fillRect(QRectF(0, 0, glw->width(), glw->height()), palette().color(backgroundRole()));
        } else {
            painter.begin(this);
        }
#else
        painter.begin(this);
#endif
    }

    painter.setClipRect(e->rect());

    painter.setRenderHint(QPainter::Antialiasing);

    QPainterPath clipPath;

    QRect r = rect();
    qreal left = r.x() + 1;
    qreal top = r.y() + 1;
    qreal right = r.right();
    qreal bottom = r.bottom();
    qreal radius2 = 8 * 2;

    clipPath.moveTo(right - radius2, top);
    clipPath.arcTo(right - radius2, top, radius2, radius2, 90, -90);
    clipPath.arcTo(right - radius2, bottom - radius2, radius2, radius2, 0, -90);
    clipPath.arcTo(left, bottom - radius2, radius2, radius2, 270, -90);
    clipPath.arcTo(left, top, radius2, radius2, 180, -90);
    clipPath.closeSubpath();

    painter.save();
    painter.setClipPath(clipPath, Qt::IntersectClip);

    painter.drawTiledPixmap(rect(), m_tile);

    // client painting

    paint(&painter);

    painter.restore();

    painter.save();
    if (m_show_doc)
        paintDescription(&painter);
    painter.restore();

    int level = 180;
    painter.setPen(QPen(QColor(level, level, level), 2));
    painter.setBrush(Qt::NoBrush);
    painter.drawPath(clipPath);

    if (preferImage()
#ifdef QT_OPENGL_SUPPORT
        && !m_use_opengl
#endif
        ) {
        painter.end();
        painter.begin(this);
#ifdef Q_WS_QWS
        painter.drawPixmap(e->rect(), *static_image, e->rect());
#else
        painter.drawImage(e->rect(), *static_image, e->rect());
#endif
    }

#ifdef QT_OPENGL_SUPPORT
    if (m_use_opengl && (inherits("PathDeformRenderer") || inherits("PathStrokeRenderer") || inherits("CompositionRenderer") || m_show_doc))
//.........这里部分代码省略.........
开发者ID:Afreeca,项目名称:qt,代码行数:101,代码来源:arthurwidgets.cpp

示例2: getPathStroke

FloatRect RenderPath::strokeBBox() const
{
    QPainterPath outline = getPathStroke(*(path().platformPath()), this, style());
    return outline.boundingRect();
}
开发者ID:KDE,项目名称:khtml,代码行数:5,代码来源:RenderPathQt.cpp

示例3: CreateTornEdge

// algorithm from Greenshot - http://getgreenshot.org/
static QPixmap CreateTornEdge(const QPixmap& sourceImage, int toothHeight, int horizontalToothRange, int verticalToothRange)
{
    QPixmap returnImage( sourceImage.width(), sourceImage.height() );
    returnImage.fill (Qt::transparent);
    QPainterPath path;

    int horizontalRegions = (int)(sourceImage.width() / horizontalToothRange);
    int verticalRegions = (int)(sourceImage.height() / verticalToothRange);

    // Start
    QPointF previousEndingPoint = QPointF( horizontalToothRange, MiscFunctions::random(1, toothHeight) );
    QPointF newEndingPoint;

    // Top
    path.moveTo(previousEndingPoint);
    for (int i = 0; i < horizontalRegions; i++)
    {
        int x = (int)previousEndingPoint.x() + horizontalToothRange;
        int y = MiscFunctions::random(1, toothHeight);
        newEndingPoint = QPointF(x, y);

        //path.lineTo(previousEndingPoint, newEndingPoint);
        path.lineTo(newEndingPoint);
        previousEndingPoint = newEndingPoint;
    }

    // Right
    for (int i = 0; i < verticalRegions; i++)
    {
        int x = sourceImage.width() - MiscFunctions::random(1, toothHeight);
        int y = (int)previousEndingPoint.y() + verticalToothRange;
        newEndingPoint = QPointF(x, y);
        path.lineTo(newEndingPoint);
        previousEndingPoint = newEndingPoint;
    }

    //       Bottom
    for (int i = 0; i < horizontalRegions; i++)
    {
        int x = (int)previousEndingPoint.x() - horizontalToothRange;
        int y = sourceImage.height() - MiscFunctions::random(1, toothHeight);
        newEndingPoint = QPointF(x, y);
        path.lineTo(newEndingPoint);
        previousEndingPoint = newEndingPoint;
    }

    // Left
    for (int i = 0; i < verticalRegions; i++)
    {
        int x = MiscFunctions::random(1, toothHeight);
        int y = (int)previousEndingPoint.y() - verticalToothRange;
        newEndingPoint = QPointF(x, y);
        path.lineTo(newEndingPoint);
        previousEndingPoint = newEndingPoint;
    }
    path.closeSubpath();

    QPainter painter(&returnImage);
    painter.setPen(Qt::NoPen);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setClipPath(path);
    painter.drawPixmap(0,0,sourceImage);

    return drawShadowedPixmap(returnImage);
}
开发者ID:shinsterneck,项目名称:hotshots,代码行数:66,代码来源:PostEffect.cpp

示例4: qPow

/*!
   Draw the rose

   \param painter Painter
   \param palette Palette
   \param center Center of the rose
   \param radius Radius of the rose
   \param north Position pointing to north
   \param width Width of the rose
   \param numThorns Number of thorns
   \param numThornLevels Number of thorn levels
   \param shrinkFactor Factor to shrink the thorns with each level
*/
void QwtSimpleCompassRose::drawRose(
    QPainter *painter,
    const QPalette &palette,
    const QPointF &center, double radius, double north, double width,
    int numThorns, int numThornLevels, double shrinkFactor )
{
    if ( numThorns < 4 )
        numThorns = 4;

    if ( numThorns % 4 )
        numThorns += 4 - numThorns % 4;

    if ( numThornLevels <= 0 )
        numThornLevels = numThorns / 4;

    if ( shrinkFactor >= 1.0 )
        shrinkFactor = 1.0;

    if ( shrinkFactor <= 0.5 )
        shrinkFactor = 0.5;

    painter->save();

    painter->setPen( Qt::NoPen );

    for ( int j = 1; j <= numThornLevels; j++ )
    {
        double step =  qPow( 2.0, j ) * M_PI / numThorns;
        if ( step > M_PI_2 )
            break;

        double r = radius;
        for ( int k = 0; k < 3; k++ )
        {
            if ( j + k < numThornLevels )
                r *= shrinkFactor;
        }

        double leafWidth = r * width;
        if ( 2.0 * M_PI / step > 32 )
            leafWidth = 16;

        const double origin = qwtRadians( north );
        for ( double angle = origin;
            angle < 2.0 * M_PI + origin; angle += step )
        {
            const QPointF p = qwtPolar2Pos( center, r, angle );
            const QPointF p1 = qwtPolar2Pos( center, leafWidth, angle + M_PI_2 );
            const QPointF p2 = qwtPolar2Pos( center, leafWidth, angle - M_PI_2 );
            const QPointF p3 = qwtPolar2Pos( center, r, angle + step / 2.0 );
            const QPointF p4 = qwtPolar2Pos( center, r, angle - step / 2.0 );

            QPainterPath darkPath;
            darkPath.moveTo( center );
            darkPath.lineTo( p );
            darkPath.lineTo( qwtIntersection( center, p3, p1, p ) );

            painter->setBrush( palette.brush( QPalette::Dark ) );
            painter->drawPath( darkPath );

            QPainterPath lightPath;
            lightPath.moveTo( center );
            lightPath.lineTo( p );
            lightPath.lineTo( qwtIntersection( center, p4, p2, p ) );

            painter->setBrush( palette.brush( QPalette::Light ) );
            painter->drawPath( lightPath );
        }
    }
    painter->restore();
}
开发者ID:CaptainFalco,项目名称:OpenPilot,代码行数:84,代码来源:qwt_compass_rose.cpp

示例5: position

/*!
    Sets the points of the array to those describing an ellipse with
    size, width \a w by height \a h, and position (\a x, \a y).

    The returned array has sufficient resolution for use as pixels.
*/
void Q3PointArray::makeEllipse(int x, int y, int w, int h)
{
    QPainterPath path;
    path.addEllipse(x, y, w, h);
    *this = path.toSubpathPolygons().at(0).toPolygon();
}
开发者ID:stephaneAG,项目名称:PengPod700,代码行数:12,代码来源:q3pointarray.cpp

示例6: shape

QPainterPath MapObjectItem::shape() const
{
    QPainterPath path = mMapDocument->renderer()->interactionShape(mObject);
    path.translate(-pos());
    return path;
}
开发者ID:bjorn,项目名称:tiled,代码行数:6,代码来源:mapobjectitem.cpp

示例7: shape

QPainterPath Node::shape() const {
    QPainterPath    path;
    path.addEllipse(boundingRect());
    return (path);
}
开发者ID:danylo-bilyk,项目名称:trucks,代码行数:5,代码来源:node.cpp

示例8: Q_UNUSED

void SearchButton::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainterPath myPath;

    int radius = (height() / 5) * 2;
    QRect circle(height() / 3 - 1, height() / 4, radius, radius);
    myPath.addEllipse(circle);

    myPath.arcMoveTo(circle, 300);
    QPointF c = myPath.currentPosition();
    int diff = height() / 7;
    myPath.lineTo(qMin(width() - 2, (int)c.x() + diff), c.y() + diff);

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setPen(QPen(Qt::darkGray, 2));
    painter.drawPath(myPath);

    if (m_menu) {
        QPainterPath dropPath;
        dropPath.arcMoveTo(circle, 320);
        QPointF c = dropPath.currentPosition();
        c = QPointF(c.x() + 3.5, c.y() + 0.5);
        dropPath.moveTo(c);
        dropPath.lineTo(c.x() + 4, c.y());
        dropPath.lineTo(c.x() + 2, c.y() + 2);
        dropPath.closeSubpath();
        painter.setPen(Qt::darkGray);
        painter.setBrush(Qt::darkGray);
        painter.setRenderHint(QPainter::Antialiasing, false);
        painter.drawPath(dropPath);
    }
    painter.end();
}
开发者ID:aktokaji,项目名称:boxtest,代码行数:35,代码来源:searchlineedit.cpp

示例9: QImage

    QImage *createArrowBackground(const QMatrix &matrix) const
    {
        QRect scaledRect;
        scaledRect = matrix.mapRect(QRect(0, 0, this->logicalSize.width(), this->logicalSize.height()));

        QImage *image = new QImage(scaledRect.width(), scaledRect.height(), QImage::Format_ARGB32_Premultiplied);
        image->fill(QColor(0, 0, 0, 0).rgba());
        QPainter painter(image);
        painter.setRenderHint(QPainter::SmoothPixmapTransform);
        painter.setRenderHint(QPainter::Antialiasing);
        painter.setPen(Qt::NoPen);

        if (Colors::useEightBitPalette){
            painter.setPen(QColor(120, 120, 120));
            if (this->pressed)
                painter.setBrush(QColor(60, 60, 60));
            else if (this->highlighted)
                painter.setBrush(QColor(100, 100, 100));
            else
                painter.setBrush(QColor(80, 80, 80));
        }
        else {
            QLinearGradient outlinebrush(0, 0, 0, scaledRect.height());
            QLinearGradient brush(0, 0, 0, scaledRect.height());

            brush.setSpread(QLinearGradient::PadSpread);
            QColor highlight(255, 255, 255, 70);
            QColor shadow(0, 0, 0, 70);
            QColor sunken(220, 220, 220, 30);
            QColor normal1 = QColor(200, 170, 160, 50);
            QColor normal2 = QColor(50, 10, 0, 50);

           if (pressed) {
               outlinebrush.setColorAt(0.0f, shadow);
               outlinebrush.setColorAt(1.0f, highlight);
               brush.setColorAt(0.0f, sunken);
               painter.setPen(Qt::NoPen);
           } else {
               outlinebrush.setColorAt(1.0f, shadow);
               outlinebrush.setColorAt(0.0f, highlight);
               brush.setColorAt(0.0f, normal1);
               if (!this->highlighted)
                   brush.setColorAt(1.0f, normal2);
               painter.setPen(QPen(outlinebrush, 1));
           }
           painter.setBrush(brush);
        }

        painter.drawRect(0, 0, scaledRect.width(), scaledRect.height());

        float xOff = scaledRect.width() / 2;
        float yOff = scaledRect.height() / 2;
        float sizex = 3.0f * matrix.m11();
        float sizey = 1.5f * matrix.m22();
        if (this->type == TextButton::UP)
            sizey *= -1;
        QPainterPath path;
        path.moveTo(xOff, yOff + (5 * sizey));
        path.lineTo(xOff - (4 * sizex), yOff - (3 * sizey));
        path.lineTo(xOff + (4 * sizex), yOff - (3 * sizey));
        path.lineTo(xOff, yOff + (5 * sizey));
        painter.drawPath(path);

        return image;
    }
开发者ID:e1z0,项目名称:openvpn_client,代码行数:65,代码来源:textbutton.cpp

示例10: Q_ASSERT

/*!
    \internal
    This function returns the items in ascending order.
*/
void QGraphicsSceneIndexPrivate::recursive_items_helper(QGraphicsItem *item, QRectF exposeRect,
                                                        QGraphicsSceneIndexIntersector *intersector,
                                                        QList<QGraphicsItem *> *items,
                                                        const QTransform &viewTransform,
                                                        Qt::ItemSelectionMode mode,
                                                        qreal parentOpacity) const
{
    Q_ASSERT(item);
    if (!item->d_ptr->visible)
        return;

    const qreal opacity = item->d_ptr->combineOpacityFromParent(parentOpacity);
    const bool itemIsFullyTransparent = QGraphicsItemPrivate::isOpacityNull(opacity);
    const bool itemHasChildren = !item->d_ptr->children.isEmpty();
    if (itemIsFullyTransparent && (!itemHasChildren || item->d_ptr->childrenCombineOpacity()))
        return;

    // Update the item's scene transform if dirty.
    const bool itemIsUntransformable = item->d_ptr->itemIsUntransformable();
    const bool wasDirtyParentSceneTransform = item->d_ptr->dirtySceneTransform && !itemIsUntransformable;
    if (wasDirtyParentSceneTransform) {
        item->d_ptr->updateSceneTransformFromParent();
        Q_ASSERT(!item->d_ptr->dirtySceneTransform);
    }

    const bool itemClipsChildrenToShape = (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape);
    bool processItem = !itemIsFullyTransparent;
    if (processItem) {
        processItem = intersector->intersect(item, exposeRect, mode, viewTransform);
        if (!processItem && (!itemHasChildren || itemClipsChildrenToShape)) {
            if (wasDirtyParentSceneTransform)
                item->d_ptr->invalidateChildrenSceneTransform();
            return;
        }
    } // else we know for sure this item has children we must process.

    int i = 0;
    if (itemHasChildren) {
        // Sort children.
        item->d_ptr->ensureSortedChildren();

        // Clip to shape.
        if (itemClipsChildrenToShape && !itemIsUntransformable) {
            QPainterPath mappedShape = item->d_ptr->sceneTransformTranslateOnly
                                     ? item->shape().translated(item->d_ptr->sceneTransform.dx(),
                                                                item->d_ptr->sceneTransform.dy())
                                     : item->d_ptr->sceneTransform.map(item->shape());
            exposeRect &= mappedShape.controlPointRect();
        }

        // Process children behind
        for (i = 0; i < item->d_ptr->children.size(); ++i) {
            QGraphicsItem *child = item->d_ptr->children.at(i);
            if (wasDirtyParentSceneTransform)
                child->d_ptr->dirtySceneTransform = 1;
            if (!(child->d_ptr->flags & QGraphicsItem::ItemStacksBehindParent))
                break;
            if (itemIsFullyTransparent && !(child->d_ptr->flags & QGraphicsItem::ItemIgnoresParentOpacity))
                continue;
            recursive_items_helper(child, exposeRect, intersector, items, viewTransform,
                                   mode, opacity);
        }
    }

    // Process item
    if (processItem)
        items->append(item);

    // Process children in front
    if (itemHasChildren) {
        for (; i < item->d_ptr->children.size(); ++i) {
            QGraphicsItem *child = item->d_ptr->children.at(i);
            if (wasDirtyParentSceneTransform)
                child->d_ptr->dirtySceneTransform = 1;
            if (itemIsFullyTransparent && !(child->d_ptr->flags & QGraphicsItem::ItemIgnoresParentOpacity))
                continue;
            recursive_items_helper(child, exposeRect, intersector, items, viewTransform,
                                   mode, opacity);
        }
    }
}
开发者ID:fluxer,项目名称:katie,代码行数:85,代码来源:qgraphicssceneindex.cpp

示例11: shape

QPainterPath Player::shape() const
{
    QPainterPath path;
    path.addRect(-(getWidth()/2),-(getHeight()/2),getWidth(),getHeight());
    return path;
}
开发者ID:Batyan,项目名称:Eliminator,代码行数:6,代码来源:player.cpp

示例12: clear

void DiagramScene::setValues(QMap<QString, QVector<QPointF> > values)
{
    if(!values.keys().size())
    {
        mouseline=0;
        clear();
        return;
    }

    if(!values[values.keys().at(0)].size())
    {
        mouseline=0;
        clear();
        return;
    }

    bool dirty = true;
    int searchiteration=0;
    while(dirty && searchiteration<1000)
    {
        searchiteration++;
        mouseline=0;
        clear();

        for(int index=0; index < value.size(); index++)
            delete value[value.keys().at(index)];

        value.clear();
        minvaluex=0.0;
        maxvaluex=0.0;
        minvaluey=0.0;
        maxvaluey=0.0;

        if(!yscale)
            yscale=1;

        data=values;

        if(!values.size())
            return;

        for(int index=0; index < values.size(); index++)
        {
            QPen pen(QColor(((index+1)*948)%200+50,((index+1)*123)%200+50,((index+1)*11)%200+50));
            QPainterPath tmppath;
            QVector<QPointF> result = values[values.keys().at(index)];
            value[data.keys().at(index)] = new QMap<qreal,qreal>();

            for(int pointindex=0; pointindex < result.size(); pointindex++)
            {
                qreal x = (qreal)(result[pointindex].x());
                qreal y = (qreal)(result[pointindex].y());


                (*value[data.keys().at(index)])[x]=y;

                if(!pointindex && !index)
                {
                    minvaluex=x;
                    maxvaluex=x;
                    minvaluey=(double)y/(double)yscale;
                    maxvaluey=(double)y/(double)yscale;
                }

                if(!pointindex)
                    tmppath.moveTo(x*prec,(-y/yscale)*prec);
                else
                    tmppath.lineTo(x*prec,(-y/yscale)*prec);

                if(x > maxvaluex)
                    maxvaluex=(double)x;
                if(x < minvaluex)
                    minvaluex=(double)x;
                if((double)y/yscale > maxvaluey)
                    maxvaluey=(double)y/yscale;
                if((double)y/yscale < minvaluey)
                    minvaluey=(double)y/yscale;
            }

            addPath(tmppath,pen);
        }

        dirty = false;
        qreal maxyvalue = maxvaluey-minvaluey;

        if(maxvaluey==minvaluey)
            maxyvalue = qAbs(maxvaluey);

        qreal LOWY = 20.0;
        qreal UPPERY = 80.0;

        if(maxyvalue < LOWY || maxyvalue > UPPERY)
        {
            yscale *=maxyvalue/((double)(UPPERY-LOWY)/2.0 + LOWY);
            dirty = true;
        }
    }
    showGrid();

    qreal w , h;
//.........这里部分代码省略.........
开发者ID:iut-ibk,项目名称:Calimero,代码行数:101,代码来源:diagramscene.cpp

示例13: gradient


//.........这里部分代码省略.........
            painter->drawPolygon(points,4);
        }
        p = GetPoint(palpha);
        q = GetQuater(palpha);
        if (q ==1 || q==4)
        {
            QPointF points[4] =
            {
                QPointF(p.x(),p.y()),
                QPointF(p.x(),p.y()+pW),
                QPointF(cX+cW/2,cY+cH/2+pW),
                QPointF(cX+cW/2,cY+cH/2)
            };
            gradient_side.setColorAt(1,pieces[0].rgbColor);
            painter->setBrush(gradient_side);
            painter->drawPolygon(points,4);
        }

        for (int i=0;i<pieces.size();i++)
        {
          gradient.setColorAt(0.5,pieces[i].rgbColor);
          painter->setBrush(gradient);
          pdegree = 3.6*pieces[i].pPerc;
          painter->drawPie(cX,cY,cW,cH,palpha*16,pdegree*16);

          double a_ = Angle360(palpha);
          int q_ = GetQuater(palpha);

          palpha += pdegree;

          double a = Angle360(palpha);
          int q = GetQuater(palpha);

          QPainterPath path;
          p = GetPoint(palpha);

          if((q == 3 || q == 4) && (q_ == 3 || q_ == 4))
          {
              // 1)
              if (a>a_)
              {
                  QPointF p_old = GetPoint(palpha-pdegree);
                  path.moveTo(p_old.x()-1,p_old.y());
                  path.arcTo(cX,cY,cW,cH,palpha-pdegree,pdegree);
                  path.lineTo(p.x(),p.y()+pW);
                  path.arcTo(cX,cY+pW,cW,cH,palpha,-pdegree);
              }
              // 2)
              else
              {
                  path.moveTo(cX,cY+cH/2);
                  path.arcTo(cX,cY,cW,cH,180,Angle360(palpha)-180);
                  path.lineTo(p.x(),p.y()+pW);
                  path.arcTo(cX,cY+pW,cW,cH,Angle360(palpha),-Angle360(palpha)+180);
                  path.lineTo(cX,cY+cH/2);

                  path.moveTo(p.x(),p.y());
                  path.arcTo(cX,cY,cW,cH,palpha-pdegree,360-Angle360(palpha-pdegree));
                  path.lineTo(cX+cW,cY+cH/2+pW);
                  path.arcTo(cX,cY+pW,cW,cH,0,-360+Angle360(palpha-pdegree));
              }

          }
          // 3)
          else if((q == 3 || q == 4) && (q_ == 1 || q_ == 2) && a>a_ )
          {
开发者ID:sreyw,项目名称:cs340project,代码行数:67,代码来源:nightcharts.cpp

示例14: shape

//! [2]
QPainterPath Arrow::shape() const
{
    QPainterPath path = QGraphicsLineItem::shape();
    path.addPolygon(arrowHead);
    return path;
}
开发者ID:Afreeca,项目名称:qt,代码行数:7,代码来源:arrow.cpp

示例15: draw_unified_arrow

void TracePainter::draw_unified_arrow(int x1, int y1, int x2, int y2, QPainter * painter,
                        bool always_straight, bool start_arrowhead)
{
  // The length of the from the tip of the arrow to the point
    // where line starts.
    const int arrowhead_length = 16;

    QPainterPath arrow;
    arrow.moveTo(x1, y1);

    // Determine the angle of the straight line.
    double a1 = x2 - x1;
    double a2 = y2 - y1;
    double b1 = 1;
    double b2 = 0;

    double straight_length = sqrt(a1 * a1 + a2 * a2);

    double dot_product = a1 * b1 + a2 * b2;
    double cosine = dot_product / (sqrt(pow(a1, 2) + pow(a2, 2)) * sqrt(b1 + b2));
    double angle = acos(cosine);
    if (y1 < y2)
    {
        angle = -angle;
    }
    double straight_angle = angle * 180 / M_PI;

    double limit = 10;

    double angle_to_vertical;
    if (fabs(straight_angle) < 90)
    {
        angle_to_vertical = fabs(straight_angle);
    }
    else if (straight_angle > 0)
    {
        angle_to_vertical = 180 - straight_angle;
    }
    else
    {
        angle_to_vertical = 180 -(-straight_angle);
    }

    double angle_delta = 0;
    if (!always_straight)
    {
        if (angle_to_vertical > limit)
        {
            angle_delta = 30 * (angle_to_vertical - limit)/90;
        }
    }
    double start_angle = straight_angle > 0
    ? straight_angle - angle_delta :
    straight_angle + angle_delta;


    QMatrix m1;
    m1.translate(x1, y1);
    m1.rotate(-start_angle);

    double end_angle = straight_angle > 0
        ? (straight_angle + 180 + angle_delta) :
        (straight_angle + 180 - angle_delta);

    QMatrix m2;
    m2.reset();
    m2.translate(x2, y2);
    m2.rotate(-end_angle);

    arrow.cubicTo(m1.map(QPointF(straight_length/2, 0)),
                  m2.map(QPointF(straight_length/2, 0)),
                  m2.map(QPointF(arrowhead_length, 0)));

    painter->save();
    painter->setBrush(Qt::NoBrush);
    painter->drawPath(arrow);
    painter->restore();


    QPolygon arrowhead(4);
    arrowhead.setPoint(0, 0, 0);
    arrowhead.setPoint(1, arrowhead_length/3, -arrowhead_length*5/4);
    arrowhead.setPoint(2, 0, -arrowhead_length);
    arrowhead.setPoint(3, -arrowhead_length/3, -arrowhead_length*5/4);

    painter->save();

    painter->translate(x2, y2);
    painter->rotate(-90);
    painter->rotate(-end_angle);
    painter->rotate(180);
    painter->setPen(Qt::NoPen);
    painter->drawPolygon(arrowhead);

    painter->restore();

    if (start_arrowhead)
    {
        painter->save();
        painter->translate(x1, y1);
//.........这里部分代码省略.........
开发者ID:cojuer,项目名称:vis4,代码行数:101,代码来源:trace_painter.cpp


注:本文中的QPainterPath类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。