• <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)
            該函數(shù)第一個參數(shù)為箭頭起點(diǎn),rect為箭頭指向的矩形框,該函數(shù)會自動計(jì)算箭頭終點(diǎn)和箭頭相關(guān)參數(shù)
            該代碼經(jīng)過測試 - 完全可以使用
            參考:
            http://www.cnblogs.com/liulun/p/3833006.html
            posted on 2015-12-15 13:10 ccsdu2009 閱讀(9864) 評論(0)  編輯 收藏 引用 所屬分類: QT編程
             
            中文字幕无码精品亚洲资源网久久| 狠狠久久亚洲欧美专区| 久久99精品久久久久久水蜜桃| 久久er国产精品免费观看8| 久久精品国产精品亚洲人人| 久久天天躁夜夜躁狠狠| 国产999精品久久久久久| 99久久精品免费看国产一区二区三区| 久久精品国产亚洲AV高清热| 久久久91人妻无码精品蜜桃HD| 久久99热这里只有精品66| 欧美伊香蕉久久综合类网站| 中文字幕无码精品亚洲资源网久久| 99精品久久久久久久婷婷| 欧美国产成人久久精品| 久久久久亚洲AV成人网| 久久不见久久见免费视频7| 亚洲?V乱码久久精品蜜桃| 94久久国产乱子伦精品免费| 久久九九兔免费精品6| 久久国产香蕉一区精品| 精品国产一区二区三区久久| 色婷婷久久综合中文久久蜜桃av| 亚洲国产成人久久一区WWW| 久久精品国产99国产电影网| 久久精品国产亚洲精品2020| 伊色综合久久之综合久久| 久久久精品久久久久久 | 热久久国产欧美一区二区精品| 久久久久久无码Av成人影院| 精品熟女少妇AV免费久久| 欧美麻豆久久久久久中文| 久久久久综合中文字幕| 国产精品免费看久久久香蕉 | 国内精品久久久久影院网站| 99麻豆久久久国产精品免费| 久久久久人妻一区精品色 | 久久天堂AV综合合色蜜桃网| 77777亚洲午夜久久多人| 亚洲乱码日产精品a级毛片久久| 久久这里有精品视频|