• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            Cpper
            C/C++高級工程師 Android高級軟件工程師 IT集成工程師 音頻工程師 熟悉c,c++,java,c#,py,js,asp等多種語言 程序猿
            代碼如下:
            class ArrowItem : public QGraphicsItem
            {
            public:
                
            const static float LINE_WIDTH;
                
            const static float ARROW_SIZE;
            public:
                ArrowItem(QGraphicsItem
            * parent = 0);
                
            ~ArrowItem();
                
            void setData(const QPointF& from,const QRectF& rect);
            public:
                QRectF boundingRect()
            const;
                
            void paint(QPainter* painter,const QStyleOptionGraphicsItem* style,QWidget* widget);
            private:
                QPointF computeTo(
            const QPointF& from,const QRectF& to);
            private:
                
            bool mValid;
                QPointF mFrom;
                QPointF mTo;
                QPointF mP1;
                QPointF mP2;
                QRectF  mRect;
            };

            const float ArrowItem::LINE_WIDTH = 1.5f;
            const float ArrowItem::ARROW_SIZE = 8.0f;

            ArrowItem::ArrowItem(QGraphicsItem
            * parent):
            QGraphicsItem(parent),
            mValid(
            false)
            {
            }

            ArrowItem::
            ~ArrowItem()
            {
            }

            QPointF ArrowItem::computeTo(
            const QPointF& from,const QRectF& to)
            {
                QPointF center(to.center());
                QPointF top(center.x(),to.top());
                QPointF right(to.right(),center.y());
                QPointF bottom(center.x(),to.bottom());
                QPointF left(to.left(),center.y());

                
            //left
                if(from.x() < to.left())
                {
                    
            if(from.y() < to.top())
                    {
                        QLineF line1(from,top);
                        QLineF line2(from,left);
                        
            return line1.length() > line2.length() ? left : top;
                    }
                    
            else if(from.y() > to.bottom())
                    {
                        QLineF line1(from,left);
                        QLineF line2(from,bottom);
                        
            return line1.length() > line2.length() ? bottom : left;
                    }
                    
            return left;
                }
                
            //right
                if(from.x() > to.right())
                {
                    
            if(from.y() < to.top())
                    {
                        QLineF line1(from,top);
                        QLineF line2(from,right);
                        
            return line1.length() > line2.length() ? right : top;
                    }
                    
            else if(from.y() > to.bottom())
                    {
                        QLineF line1(from,bottom);
                        QLineF line2(from,right);
                        
            return line1.length() > line2.length() ? right : bottom;
                    }
                    
            return right;
                }

                
            if(from.y() < to.top())
                    
            return top;
                
            else if(from.y() > to.bottom())
                    
            return bottom;

                Q_ASSERT(
            0);
                
            return QPointF();
            }

            void ArrowItem::setData(const QPointF& from,const QRectF& rect)
            {
                mValid 
            = true;
                mFrom 
            = from;
                mRect 
            = rect;

                
            if(rect.contains(from))
                {
                    mValid 
            = false;
                    
            return;
                }

                mTo 
            = computeTo(mFrom,mRect);

                QLineF line(mFrom,mTo);
                qreal angle 
            = ::acos(line.dx()/line.length());

                
            if(line.dy() >= 0)
                    angle 
            = 3.14159*2 - angle;

                mP1 
            = mTo + QPointF(sin(angle-PI/3)*ARROW_SIZE,cos(angle-PI/3)*ARROW_SIZE);
                mP2 
            = mTo + QPointF(sin(angle-PI+PI/3)*ARROW_SIZE,cos(angle-PI+PI/3)*ARROW_SIZE);
            }

            QRectF ArrowItem::boundingRect()
            const
            {
                qreal extra 
            = (LINE_WIDTH + ARROW_SIZE)/2.0;
                QRectF rect
            = QRectF(mFrom,QSizeF(mTo.x()-mFrom.x(),mTo.y()-mFrom.y())).normalized().
                    adjusted(
            -extra,-extra,extra,extra);
                
            return rect;
            }

            void ArrowItem::paint(QPainter* painter,const QStyleOptionGraphicsItem* style,QWidget* widget)
            {
                
            if(!mValid)
                    
            return;
                painter
            ->setRenderHint(QPainter::Antialiasing);
                QPen p(QColor::fromRgb(
            79,136,187));
                painter
            ->setBrush(QBrush(p.color()));
                p.setWidthF(LINE_WIDTH);
                painter
            ->setPen(p);
                painter
            ->drawLine(mFrom,mTo);
                painter
            ->drawPolygon(QPolygonF()<<mTo<<mP1<<mP2);
            }

            void ArrowItem::setData(const QPointF& from,const QRectF& rect)
            該函數第一個參數為箭頭起點,rect為箭頭指向的矩形框,該函數會自動計算箭頭終點和箭頭相關參數
            該代碼經過測試 - 完全可以使用
            參考:
            http://www.cnblogs.com/liulun/p/3833006.html
            posted on 2015-12-15 13:10 ccsdu2009 閱讀(9881) 評論(0)  編輯 收藏 引用 所屬分類: QT編程
             
            国产精品美女久久久免费| 亚洲欧洲日产国码无码久久99| 久久亚洲国产欧洲精品一| 久久久久av无码免费网| 亚洲精品乱码久久久久久蜜桃图片 | 2020久久精品国产免费| 91久久香蕉国产熟女线看| 国产精品99久久久精品无码| 久久青青草原精品国产不卡| 色诱久久久久综合网ywww| 国产V亚洲V天堂无码久久久| 精品久久久久久国产牛牛app| 久久av无码专区亚洲av桃花岛| 亚洲精品美女久久久久99小说| 久久精品国产亚洲av麻豆色欲| 久久精品视频网| 亚洲国产成人精品91久久久 | 久久涩综合| 国产一区二区三区久久精品| 久久99久久成人免费播放| 久久一日本道色综合久久| 亚洲欧美一级久久精品| 久久se精品一区精品二区| 亚洲精品蜜桃久久久久久| 久久黄视频| 久久精品国产精品亚洲精品 | 国产精品久久婷婷六月丁香| 情人伊人久久综合亚洲| 久久久久亚洲精品天堂| 久久精品中文字幕无码绿巨人| 四虎久久影院| 亚洲国产成人久久精品影视| 九九精品99久久久香蕉| 亚洲国产精品无码久久一区二区 | 国产美女久久精品香蕉69| AV无码久久久久不卡蜜桃| 久久久久久伊人高潮影院| 97久久国产综合精品女不卡| 日批日出水久久亚洲精品tv| 欧美色综合久久久久久| 久久久久亚洲精品无码网址|