• <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 閱讀(9864) 評論(0)  編輯 收藏 引用 所屬分類: QT編程
             
            国产亚洲色婷婷久久99精品91| 久久人做人爽一区二区三区| 久久99国产精品久久99| 久久成人影院精品777| 国产激情久久久久影院老熟女免费| 国产成人精品综合久久久| 香蕉久久夜色精品国产2020| 精品免费tv久久久久久久| 久久久久亚洲爆乳少妇无| 伊人久久大香线蕉亚洲五月天| 国产免费久久精品99久久| 欧美精品福利视频一区二区三区久久久精品| 久久九九兔免费精品6| 免费观看久久精彩视频| 久久久久久精品免费免费自慰| 久久国产高潮流白浆免费观看| 久久久中文字幕日本| 国产V综合V亚洲欧美久久 | 伊人久久大香线蕉AV一区二区| 激情伊人五月天久久综合| 国内精品免费久久影院| 久久久久女人精品毛片| 国产香蕉久久精品综合网| 中文精品久久久久国产网址| 久久99精品久久久久久动态图| 久久成人国产精品免费软件| 国产精品狼人久久久久影院| 国产精品无码久久综合 | 久久er99热精品一区二区| 亚洲精品无码久久久| 丰满少妇人妻久久久久久4| 亚洲va国产va天堂va久久| 久久久久亚洲av综合波多野结衣| 国产精品午夜久久| 99久久精品免费国产大片| 88久久精品无码一区二区毛片 | 日本高清无卡码一区二区久久| 精品久久久久久国产91| 久久久久久a亚洲欧洲aⅴ| 88久久精品无码一区二区毛片| 青青青青久久精品国产h|