00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <QtGui>
00023
00024 #include "groupnode.h"
00025 #include <QGraphicsSceneDragDropEvent>
00026 #include "itemnode.h"
00027
00028
00029 GroupNode::GroupNode(QGraphicsItem * parent, QGraphicsScene * scene): Node(parent, scene)
00030 {
00031 myTextColor = Qt::darkGreen;
00032 myOutlineColor = Qt::darkBlue;
00033 myBackgroundColor = Qt::white;
00034
00035 setFlags(ItemIsMovable | ItemIsSelectable);
00036
00037 type = "Group";
00038 name = type;
00039 }
00040
00041 GroupNode::~GroupNode()
00042 {
00043 foreach (Link *link, getLinks())
00044 delete link;
00045
00046 foreach (QGraphicsItem *child, children())
00047 delete child;
00048 }
00049
00050 void GroupNode::addNode(Node *node)
00051 {
00052
00053 node->setParentItem(this);
00054
00055
00056 node->scale(SUBSCALE, SUBSCALE);
00057
00058
00059 node->setPos(node->pos() * SUBSCALE);
00060 }
00061
00062 void GroupNode::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * )
00063 {
00064 QPen pen(myOutlineColor);
00065 if (option->state & QStyle::State_Selected) {
00066 pen.setStyle(Qt::DotLine);
00067 pen.setWidth(2);
00068 }
00069 painter->setPen(pen);
00070 painter->setBrush(myBackgroundColor);
00071
00072 QRectF rect = outlineRect();
00073 painter->drawRoundRect(rect.adjusted(0.0, 12.0, 0.0, .0), roundness(rect.width()),
00074 roundness(rect.height()));
00075
00076 painter->setPen(myTextColor);
00077 painter->drawText(QPointF((int)rect.left(), (int)rect.top() + 10), myText);
00078
00079
00080 painter->drawEllipse((int)rect.right() - 10, (int)rect.bottom() - 10, 8, 8);
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 }
00092
00093
00094 QPointF GroupNode::scenePointPos(int ) const
00095 {
00096
00097
00098
00099
00100
00101 return this->scenePos();
00102 }
00103
00104 QPointF GroupNode::scenePointPos(QString, bool) const
00105 {
00106 return this->scenePos();
00107 }
00108
00109 int GroupNode::propPoint(QString, bool) const
00110 {
00111 return 0;
00112 }
00113
00114 int GroupNode::numProps() const
00115 {
00116 return 0;
00117 }
00118
00119 void GroupNode::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
00120 {
00121 QRectF rect = outlineRect();
00122 QPointF click = mapFromScene(event->scenePos());
00123
00124 if ((click.x() > rect.right() - 10) && (click.y() > rect.bottom() - 10)) {
00125
00126
00127 }
00128 else {
00129 QString text = QInputDialog::getText(event->widget(),
00130 tr("Edit Text"), tr("Enter new text:"),
00131 QLineEdit::Normal, myText);
00132 if (!text.isEmpty())
00133 setText(text);
00134 }
00135 }
00136
00137 QVariant GroupNode::itemChange(GraphicsItemChange change,
00138 const QVariant &value)
00139 {
00140 if (change == ItemPositionHasChanged)
00141 updateLinksPos();
00142
00143 return QGraphicsItem::itemChange(change, value);
00144 }
00145
00146 void GroupNode::updateLinksPos()
00147 {
00148 foreach (Link *link, getLinks())
00149 link->trackNodes();
00150
00151 foreach (QGraphicsItem *child, children()) {
00152 Node *nodeChild = dynamic_cast<Node *>(child);
00153 if (nodeChild)
00154 nodeChild->updateLinksPos();
00155 }
00156 }
00157
00158 QRectF GroupNode::outlineRect() const
00159 {
00160 const int Padding = 8;
00161 QFontMetricsF metrics = qApp->font();
00162 QRectF rect = metrics.boundingRect(myText);
00163 rect.adjust(-Padding, -Padding, +Padding, +Padding);
00164 rect.translate(-rect.center());
00165
00166 QRectF childRect = childrenBoundingRect();
00167
00168
00169
00170 return (childRect).adjusted(-20.0, -17.0, 20.0, 5.0);
00171 }
00172
00173 int GroupNode::roundness(double size) const
00174 {
00175 const int Diameter = 12;
00176 return 100 * Diameter / int(size);
00177 }
00178
00179 int GroupNode::pointAt(QPointF ) const
00180 {
00181 return -1;
00182 }
00183
00184 QString GroupNode::propName(int ) const
00185 {
00186 return QString();
00187 }
00188