Hardware Design: SIE
Sign in or create your account | Project List | Help
Hardware Design: SIE Git Source Tree
Root/
| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
| 4 | ** All rights reserved. |
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) |
| 6 | ** |
| 7 | ** This file is part of the examples of the Qt Toolkit. |
| 8 | ** |
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 10 | ** Commercial Usage |
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in |
| 12 | ** accordance with the Qt Commercial License Agreement provided with the |
| 13 | ** Software or, alternatively, in accordance with the terms contained in |
| 14 | ** a written agreement between you and Nokia. |
| 15 | ** |
| 16 | ** GNU Lesser General Public License Usage |
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 18 | ** General Public License version 2.1 as published by the Free Software |
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
| 20 | ** packaging of this file. Please review the following information to |
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 23 | ** |
| 24 | ** In addition, as a special exception, Nokia gives you certain additional |
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception |
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 27 | ** |
| 28 | ** GNU General Public License Usage |
| 29 | ** Alternatively, this file may be used under the terms of the GNU |
| 30 | ** General Public License version 3.0 as published by the Free Software |
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the |
| 32 | ** packaging of this file. Please review the following information to |
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be |
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html. |
| 35 | ** |
| 36 | ** If you have questions regarding the use of this file, please contact |
| 37 | ** Nokia at qt-info@nokia.com. |
| 38 | ** $QT_END_LICENSE$ |
| 39 | ** |
| 40 | ****************************************************************************/ |
| 41 | |
| 42 | #include <QtGui> |
| 43 | |
| 44 | #include "lineitem.h" |
| 45 | #include <math.h> |
| 46 | |
| 47 | lineItem::lineItem(QPointF startPoint, QPointF endItem, Arrow *ownerArrow, |
| 48 | int wt, bool movable, QGraphicsItem *parent, QGraphicsScene *scene) |
| 49 | : QGraphicsLineItem(parent, scene) |
| 50 | { |
| 51 | isMovable=movable; |
| 52 | if(isMovable) |
| 53 | { |
| 54 | setFlag(QGraphicsItem::ItemIsMovable, true); |
| 55 | } |
| 56 | |
| 57 | setFlag(QGraphicsItem::ItemIsSelectable, true); |
| 58 | |
| 59 | myColor = Qt::black; |
| 60 | setPen(QPen(myColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); |
| 61 | setLine(QLineF(startPoint,endItem)); |
| 62 | myOwnerArrow = ownerArrow; |
| 63 | pWidth=wt; |
| 64 | moveItem=0; |
| 65 | } |
| 66 | |
| 67 | QRectF lineItem::boundingRect() const |
| 68 | { |
| 69 | qreal extra = (pen().width() + 20) / 2.0; |
| 70 | |
| 71 | return QRectF(line().p1(), QSizeF(line().p2().x() - line().p1().x(), |
| 72 | line().p2().y() - line().p1().y())) |
| 73 | .normalized() |
| 74 | .adjusted(-extra, -extra, extra, extra); |
| 75 | } |
| 76 | |
| 77 | QPainterPath lineItem::shape() const |
| 78 | { |
| 79 | QPainterPath path = QGraphicsLineItem::shape(); |
| 80 | return path; |
| 81 | } |
| 82 | |
| 83 | void lineItem::updatePos() |
| 84 | { |
| 85 | QPointF itemPos = this->line().p1()+QPointF(0.5,0.5); |
| 86 | myOwnerArrow->moveCorner(itemPos,this); |
| 87 | } |
| 88 | |
| 89 | void lineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, |
| 90 | QWidget *) |
| 91 | { |
| 92 | QPen myPen = pen(); |
| 93 | myPen.setColor(myColor); |
| 94 | myPen.setWidth(pWidth); |
| 95 | painter->setPen(myPen); |
| 96 | painter->setBrush(myColor); |
| 97 | |
| 98 | setLine(line()); |
| 99 | painter->drawLine(line()); |
| 100 | |
| 101 | //Drawing arrow selected |
| 102 | if (isSelected()) { |
| 103 | painter->setPen(QPen(Qt::gray, pWidth, Qt::SolidLine)); |
| 104 | QLineF myLine = line(); |
| 105 | painter->drawLine(myLine); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | void lineItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent) |
| 110 | { |
| 111 | if(!isMovable) |
| 112 | { |
| 113 | myOwnerArrow->createCorner(mouseEvent->scenePos(),this); |
| 114 | } |
| 115 | QGraphicsLineItem::mouseDoubleClickEvent(mouseEvent); |
| 116 | } |
| 117 | |
| 118 | |
| 119 | void lineItem::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) |
| 120 | { |
| 121 | QGraphicsLineItem::mousePressEvent(mouseEvent); |
| 122 | } |
| 123 | |
| 124 | void lineItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) |
| 125 | { |
| 126 | if(isMovable) |
| 127 | { |
| 128 | updatePos(); |
| 129 | } |
| 130 | QGraphicsLineItem::mouseMoveEvent(mouseEvent); |
| 131 | } |
| 132 | |
| 133 | void lineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) |
| 134 | { |
| 135 | if(isMovable) |
| 136 | { |
| 137 | updatePos(); |
| 138 | } |
| 139 | QGraphicsLineItem::mouseReleaseEvent(mouseEvent); |
| 140 | } |
| 141 |
Branches:
master
