SVN commit 1017939 by tcanabrava: cute node grouth - shrink from the wheel M +1 -0 Actions/AddNode.cpp M +1 -1 Actions/MoveNode.cpp M +13 -1 Core/node.cpp M +5 -1 Core/node.h M +23 -10 GraphicsItem/NodeItem.cpp M +4 -0 GraphicsItem/NodeItem.h M +6 -3 Interface/GraphPropertiesWidget.cpp M +35 -6 Interface/GraphScene.cpp M +1 -1 Interface/GraphScene.h --- trunk/playground/edu/Rocs/src/Actions/AddNode.cpp #1017938:1017939 @@ -52,6 +52,7 @@ Node *n = _graph -> addNode(i18n("untitled")); n ->setX(pos.x()); n -> setY(pos.y()); + n -> setZ(1); Graph *g = qobject_cast(n->parent()); g->calcRelativeCenter(); --- trunk/playground/edu/Rocs/src/Actions/MoveNode.cpp #1017938:1017939 @@ -69,7 +69,7 @@ } } else { - _node -> setPos(pos.x(), pos.y()); + _node -> setPos(pos.x(), pos.y(), _node->z()); } } --- trunk/playground/edu/Rocs/src/Core/node.cpp #1017938:1017939 @@ -27,6 +27,7 @@ setColor("#FF0000"); setX(0); setY(0); + setZ(0); setBegin(false); setEnd(false); } @@ -173,15 +174,26 @@ _y = y; emit posChanged(); } -void Node::setPos(qreal x, qreal y) { + +void Node::setZ(qreal z) { + _z = z; + emit posChanged(); +} + +void Node::setPos(qreal x, qreal y, qreal z) { _x = x; _y = y; + _z = z; emit posChanged(); kDebug() << "Updating"; } qreal Node::y() const { return _y; } + +qreal Node::z() const { + return _z; +} void Node::setColor(const QString& s) { _color = s; } --- trunk/playground/edu/Rocs/src/Core/node.h #1017938:1017939 @@ -40,6 +40,7 @@ Q_OBJECT Q_PROPERTY(qreal x READ x WRITE setX); Q_PROPERTY(qreal y READ y WRITE setY); + Q_PROPERTY(qreal z READ z WRITE setZ); Q_PROPERTY(QString name READ name WRITE setName); Q_PROPERTY(QString color READ color WRITE setColor); Q_PROPERTY(bool begin READ begin WRITE setBegin); @@ -73,9 +74,11 @@ void setX(qreal x); void setY(qreal y); - void setPos(qreal x, qreal y); + void setZ(qreal z); + void setPos(qreal x, qreal y, qreal z = 1); qreal x() const; qreal y() const; + qreal z() const; void setColor(const QString& s); const QString& color() const; void setName(const QString& s); @@ -108,6 +111,7 @@ //! fixed properties qreal _x; qreal _y; + qreal _z; QString _name; QString _color; bool _begin; --- trunk/playground/edu/Rocs/src/GraphicsItem/NodeItem.cpp #1017938:1017939 @@ -45,6 +45,7 @@ connect(_node, SIGNAL(posChanged()), this, SLOT(updatePos())); QPointF pos( _node -> x() ,_node->y() ); setPos( pos ); + _oldZ = node->z(); setZValue(1); setFlag(ItemIsSelectable); connect (_node, SIGNAL(removed()), this, SLOT(deleteItem())); @@ -87,29 +88,40 @@ } QRectF NodeItem::boundingRect() const { + qreal z = _node->z(); + if(isDownSizing) { + return QRectF(-12 * _oldZ, -12 * _oldZ, 25 * _oldZ, 25 * _oldZ); + } if ( _node && _node->begin() ){ - return QRectF(-52, -12 , 65, 25); + return QRectF(-52 * z, -12 * z , 65 * z, 25 * z); } if ( _removingBeginFlag ){ - return QRectF(-52, -12 , 65, 25); + return QRectF(-52 * z, -12 * z , 65 * z, 25 * z); } - return QRectF(-12, -12 , 25, 25); + return QRectF(-12 * z, -12 * z , 25 * z, 25 * z); } QPainterPath NodeItem::shape() const { QPainterPath path; - path.addEllipse(-10, -10, 20, 20); + qreal z = _node->z(); + path.addEllipse(-10 * z, -10 * z, 20 * z, 20 * z); return path; } void NodeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) { + qreal z = _node->z(); + if(z > _oldZ) _oldZ = z; + if(isDownSizing) { + QBrush brush(Qt::white); + painter->setBrush(brush); + painter->drawRect(QRectF(-11 * z, -11 * z, 24 * z, 24 * z)); + } if (_node){ _color = _node->color(); } - if (isSelected()) { QPen pen(Qt::black, 1, Qt::DotLine); painter->setBrush(QBrush()); painter->setPen(pen); - painter->drawRect(QRectF(-11 , -11 , 24 , 24 )); + painter->drawRect(QRectF(-11 * z , -11 * z , 24 * z , 24 * z )); } @@ -120,14 +132,15 @@ painter->drawLine(-20, 10, 0, 0); } else if (_removingBeginFlag) _removingBeginFlag = false; + painter->setPen(Qt::NoPen); _color.setAlphaF(_opacity); painter->setBrush( _color.dark(240) ); - painter->drawEllipse(-7, -7, 20, 20); - QRadialGradient gradient(-3, -3, 10); + painter->drawEllipse(-7 * z, -7 * z, 20 * z, 20 * z); + QRadialGradient gradient(-3 * z, -3 * z, 10 * z); if (option->state & QStyle::State_Sunken) { gradient.setColorAt(0, _color.light(240)); @@ -139,12 +152,12 @@ painter->setBrush(gradient); painter->setPen(QPen(_color, 2)); - painter->drawEllipse(-10, -10, 20, 20); + painter->drawEllipse(-10 * z, -10 * z, 20 * z, 20 * z); if(_node && _node->end() ){ QColor c(Qt::black); c.setAlphaF(_opacity); painter->setPen(c); - painter->drawEllipse(-7, -7, 15, 15); + painter->drawEllipse(-7 * z, -7 * z, 15 * z, 15 * z); } } --- trunk/playground/edu/Rocs/src/GraphicsItem/NodeItem.h #1017938:1017939 @@ -36,6 +36,9 @@ class NodeItem : public QObject, public QGraphicsItem { Q_OBJECT public: + + bool isDownSizing; + bool isUpSizing; /*! default constructor \param node the Node that this item will interact to. \param parent the QGraphicsITem that this Item belongs to. */ @@ -91,6 +94,7 @@ private: Node *_node; + qreal _oldZ; qreal _opacity; bool _removingBeginFlag; QTimeLine *_timeLine; --- trunk/playground/edu/Rocs/src/Interface/GraphPropertiesWidget.cpp #1017938:1017939 @@ -43,8 +43,11 @@ _graphEdgeColor->setColor(_graph->edgeDefaultColor()); _graphNodeColor->setColor(_graph->nodeDefaultColor()); _graphAutomate->setChecked(_graph->automate()); - _graphAutomate->setChecked( _graph->directed()); + _graphAutomate->setChecked(_graph->directed()); + _activateGraph->setChecked(true); + _editWidget->setVisible(_activateGraph->isChecked()); + } void GraphPropertiesWidget::on__graphAutomate_clicked(bool b){ @@ -60,7 +63,7 @@ } void GraphPropertiesWidget::on__graphName_textChanged(QString n){ - + _activateGraph->setText(_graphName->text()); } void GraphPropertiesWidget::on__graphNodeColorApplyNow_clicked(){ @@ -77,4 +80,4 @@ void GraphPropertiesWidget::on__graphDelete_clicked(){ -} \ No newline at end of file +} --- trunk/playground/edu/Rocs/src/Interface/GraphScene.cpp #1017938:1017939 @@ -31,6 +31,7 @@ #include #include #include +#include "node.h" #include "graph.h" GraphScene::GraphScene(QObject *parent) : QGraphicsScene(parent) { @@ -103,23 +104,51 @@ return edgeItem; } +void GraphScene::wheelEvent(QGraphicsSceneWheelEvent *wheelEvent) { + NodeItem *nitem = qgraphicsitem_cast(itemAt(wheelEvent->scenePos())); + if (!nitem) return; + Node *movableNode = nitem->node(); + int numDegrees = wheelEvent->delta(); + if(wheelEvent->orientation() == Qt::Vertical) { + if(numDegrees > 0) + { + nitem->isUpSizing = 1; + movableNode->setZ(movableNode->z()+0.25); + nitem->update(); + nitem->isUpSizing = 0; + } + else if(movableNode->z() > 0.5) + { + nitem->isDownSizing = 1; + movableNode->setZ(movableNode->z()-0.25); + nitem->update(); + nitem->isDownSizing = 0; + } + } + } + void GraphScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) { _action->executeMove(mouseEvent->scenePos()); } void GraphScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) { + if(mouseEvent->button() == 4) + { + NodeItem *nitem = qgraphicsitem_cast(itemAt(mouseEvent->scenePos())); + if (!nitem) return; + Node *movableNode = nitem->node(); + nitem->isDownSizing = 1; + movableNode->setZ(1); + nitem->update(); + nitem->isDownSizing = 0; + } _action->executePress(mouseEvent->scenePos()); - } void GraphScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) { - _action->executeRelease(mouseEvent->scenePos()); + _action->executeRelease(mouseEvent->scenePos()); } -void GraphScene::wheelEvent(QGraphicsSceneWheelEvent *) { - -} - void GraphScene::keyPressEvent(QKeyEvent *) { } --- trunk/playground/edu/Rocs/src/Interface/GraphScene.h #1017938:1017939 @@ -9,7 +9,7 @@ * version 2 of the License, or (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * MERCHANTABILITY or FITNGraphScene::ESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * You should have received a copy of the GNU Library General Public License * along with this program; see the file COPYING. If not, write to