[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/edu/Rocs/src/Interface
From:       Tomaz Martins dos Santos Canabrava <tomaz.canabrava () gmail ! com>
Date:       2009-05-22 13:18:19
Message-ID: 1242998299.508099.15275.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 971437 by tcanabrava:

Speed up fixes
Fixed crash where selecting a node was actually selecting the background.
fixed the node-related properties modifications from the ui
fixed a few inconsistencies on drawing things on canvas.
more consistent use of the automate support.

 M  +49 -25    SUI_GraphPropertiesWidget.cpp  
 M  +5 -3      SUI_GraphPropertiesWidget.h  
 M  +5 -1      SUI_GraphScene.cpp  
 M  +4 -1      SUI_MainWindow.cpp  
 M  +1 -1      SUI_MainWindow.h  
 M  +7 -2      action_AddNode.cpp  
 M  +20 -3     action_MoveNode.cpp  
 M  +4 -4      action_Select.cpp  


--- trunk/playground/edu/Rocs/src/Interface/SUI_GraphPropertiesWidget.cpp \
#971436:971437 @@ -23,6 +23,7 @@
 #include <KDebug>
 #include <QGraphicsItem>
 #include "graph.h"
+#include "graphDocument.h"
 #include "node.h"
 #include "edge.h"
 #include "SUI_MainWindow.h"
@@ -30,42 +31,57 @@
 #include "graphicsitem_Node.h"
 #include "graphicsitem_OrientedEdge.h"
 
-GraphPropertiesWidget::GraphPropertiesWidget ( QWidget* parent )
+GraphPropertiesWidget::GraphPropertiesWidget ( MainWindow* parent )
         : QWidget ( parent ) {
 
     setupUi(this);
     unsetAll();
     _model = new GraphPropertiesModel();
     _tableView->setModel(_model);
+    _mainWindow = parent;
+    
+  connect(_nodeName,  SIGNAL(textChanged(QString)), this, \
SLOT(nodeNameChanged(QString)) ); +  connect(_nodeColor, SIGNAL(activated(QColor)),   \
this, SLOT(nodeColorChanged(QColor)) ); +  connect(_nodeEnd,   SIGNAL(toggled(bool)), \
this, SLOT(nodeEndChanged(bool))     ); +  connect(_nodeBegin, SIGNAL(toggled(bool)), \
this, SLOT(nodeBeginChanged(bool))   ); +  connect(_nodeX,     \
SIGNAL(valueChanged(int)),    this, SLOT(nodeXChanged(int))        ); +  \
connect(_nodeY,     SIGNAL(valueChanged(int)),    this, SLOT(nodeYChanged(int))       \
); +  connect(_nodeValue, SIGNAL(textChanged(QString)), this, SLOT( \
nodeValueChanged(QString))); +  connect(_edgeColor, SIGNAL(activated(QColor)),    \
this, SLOT(edgeColorChanged(QColor)) ); +  connect(_edgeName, \
SIGNAL(textChanged(QString)),  this, SLOT(edgeNameChanged(QString))); +  \
connect(_edgeValue, SIGNAL(textChanged(QString)), this, \
SLOT(edgeValueChanged(QString)));  }
 
 void GraphPropertiesWidget::setDataSource(QGraphicsItem *o) {
-    kDebug() << "Entrou no setDataSource";
+   if (GraphDocument *g = _mainWindow->activeDocument()){
+ 
+      _nodeX->setRange(0,g->width());
+      _nodeY->setRange(0, g->height());
+    }
+
     QObject *obj = 0;
     unsetAll();
     if ( o == 0){
-	MainWindow *mWindow = qobject_cast<MainWindow*>( parent() );
-	if (Graph *g = mWindow->graph()){
-	  obj = g;
-	  setGraph(g);
-	  _graphicsItem = 0;
-	}
+      if (Graph *g = _mainWindow->graph()){
+	 obj = g;
+	 setGraph(g);
+	 _graphicsItem = 0;
+      }
     }
     else if( NodeItem *nodeItem = qgraphicsitem_cast<NodeItem*>(o) ){
-      kDebug() << "O No Foi Selecionado Corretamente.";
+      _graphicsItem = nodeItem;      
       obj = nodeItem->node();
       setNode(nodeItem->node());
-      _graphicsItem = nodeItem;
     }
     else if( EdgeItem *edgeItem = qgraphicsitem_cast<EdgeItem*>(o)){
+      _graphicsItem = edgeItem;
       obj = edgeItem->edge();
       setEdge(edgeItem->edge());
-      _graphicsItem = edgeItem;
     }
     else if ( OrientedEdgeItem *edgeItem = \
qgraphicsitem_cast<OrientedEdgeItem*>(o)){ +      _graphicsItem = edgeItem;
       obj = edgeItem->edge();
       setEdge(edgeItem->edge());
-      _graphicsItem = edgeItem;
     } 
     _model->setDataSource(obj);
 }
@@ -77,7 +93,10 @@
 }
 
 void GraphPropertiesWidget::setNode(Node *n){
+   kDebug() << "Node Setted!";
   _node = n;
+  kDebug() << n->name() << n->color().toAscii() << n->end() << n->begin() << n->x() \
<< n->y() << n->value();  +  
   _nodePAnel->show();
   _nodeName->setText(_node->name());
   _nodeColor->setColor(_node->color());
@@ -87,14 +106,6 @@
   _nodeX->setValue(_node->x());
   _nodeY->setValue(_node->y());
   
-  connect(_nodeName,  SIGNAL(textChanged(QString)),    this, \
                SLOT(nodeNameChanged(QString)) );
-  connect(_nodeColor, SIGNAL(currentIndexChanged(int)),this, \
                SLOT(nodeColorChanged())       );
-  connect(_nodeEnd,   SIGNAL(toggled(bool)),           this, \
                SLOT(nodeEndChanged(bool))     );
-  connect(_nodeBegin, SIGNAL(toggled(bool)),           this, \
                SLOT(nodeBeginChanged(bool))   );
-  connect(_nodeX,     SIGNAL(valueChanged(int)),       this, SLOT(nodeXChanged(int)) \
                );
-  connect(_nodeY,     SIGNAL(valueChanged(int)),       this, SLOT(nodeYChanged(int)) \
                );
-  
-  
 }
 
 void GraphPropertiesWidget::setEdge(Edge *e){
@@ -128,9 +139,9 @@
   _graphicsItem->update();
 }
 
-void GraphPropertiesWidget::nodeColorChanged(){
+void GraphPropertiesWidget::nodeColorChanged(QColor c){
   if (!_node) return;
-  _node->setColor(_nodeColor->color().name());
+  _node->setColor(c.name());
   _graphicsItem->update();
 }
 void GraphPropertiesWidget::nodeEndChanged(bool b){
@@ -145,11 +156,24 @@
 }
 void GraphPropertiesWidget::nodeXChanged(int x){
   if (!_node) return;
-  _node->setX(x);
-  _graphicsItem->update();
+  if (NodeItem *n = qgraphicsitem_cast<NodeItem*>(_graphicsItem)){
+    n->updatePos(QPointF(x, _node->y()));
+    _graphicsItem->update();
+  }
+  
+  kDebug() << "x updated";
 }
 void GraphPropertiesWidget::nodeYChanged(int y){
   if (!_node) return;
-  _node->setY(y);
+  if (NodeItem *n = qgraphicsitem_cast<NodeItem*>(_graphicsItem)){
+    n->updatePos(QPointF(_node->x(), y));
+    _graphicsItem->update();
+  }
+  kDebug() << "y updated";
+}
+
+void GraphPropertiesWidget::nodeValueChanged(QString s){
+  if (!_node) return;
+  _node->setValue(s);
   _graphicsItem->update();
 }
\ No newline at end of file
--- trunk/playground/edu/Rocs/src/Interface/SUI_GraphPropertiesWidget.h \
#971436:971437 @@ -29,30 +29,32 @@
 class Node;
 class Edge;
 
+
 /*! \brief Properties Area, not used yet. */
 class MainWindow;
 class GraphPropertiesWidget : public QWidget, public Ui::GraphPropertiesWidget
 {
     Q_OBJECT
 public:
-    GraphPropertiesWidget ( QWidget* parent = 0 );
+    GraphPropertiesWidget ( MainWindow* parent = 0 );
 public slots:
     void setDataSource(QGraphicsItem *o);
     
 private slots:
   void nodeNameChanged(QString s);
-  void nodeColorChanged();
+  void nodeColorChanged(QColor c);
   void nodeEndChanged(bool b);
   void nodeBeginChanged(bool b);
   void nodeXChanged(int x);
   void nodeYChanged(int y);
-
+  void nodeValueChanged(QString s);
 private:
     GraphPropertiesModel *_model;
     Graph *_graph;
     Node *_node;
     Edge *_edge;
     QGraphicsItem *_graphicsItem;
+    MainWindow *_mainWindow;
     
     void setGraph(Graph *g);
     void setNode(Node *n);
--- trunk/playground/edu/Rocs/src/Interface/SUI_GraphScene.cpp #971436:971437
@@ -36,7 +36,11 @@
     }
 
     setSceneRect(QRectF(0,0, gd->width(), gd->height() ));
-    addRect(0,0, gd->width(), gd->height());
+    QGraphicsRectItem *n = new QGraphicsRectItem(0,0, gd->width(), gd->height());
+    n->setFlag(QGraphicsItem::ItemIsSelectable, false);
+    n->setZValue(-1);
+    addItem(n);
+    
     int size = _graphDocument->size();
 
     for (int i = 0; i < size; i++) {
--- trunk/playground/edu/Rocs/src/Interface/SUI_MainWindow.cpp #971436:971437
@@ -110,6 +110,9 @@
 void MainWindow::setupModels() {
     _documentModel = new GraphDocumentModel( &_documents );
 }
+
+GraphDocument *MainWindow::activeDocument() const{ return _activeGraphDocument; }
+
 void MainWindow::setupWidgets() {
 
     _leftTabBar = new KMultiTabBar(KMultiTabBar::Left, this);
@@ -210,7 +213,7 @@
 
     _OpenedFiles = new OpenedFilesWidget ( _documentModel, toolBox );
     _PaletteBar	= new PaletteBarWidget	( toolBox );
-    _GraphProperties = new GraphPropertiesWidget( toolBox );
+    _GraphProperties = new GraphPropertiesWidget( this );
 
     QStackedWidget *toolsStack = new QStackedWidget();
 
--- trunk/playground/edu/Rocs/src/Interface/SUI_MainWindow.h #971436:971437
@@ -63,7 +63,7 @@
     Graph *graph() const;
     GraphScene *scene() const;
     void debug(const QString& s);
-
+    GraphDocument *activeDocument() const;
 private: // Methods
     void setupModels();	// setup all the models to be used on the views.
     void setupWidgets(); // Setup all the widgets.
--- trunk/playground/edu/Rocs/src/Interface/action_AddNode.cpp #971436:971437
@@ -24,7 +24,7 @@
 #include "graphicsitem_Node.h"
 #include "node.h"
 #include <KLocale>
-
+#include "graphDocument.h"
 #include <KDebug>
 
 AddNodeAction::AddNodeAction(GraphScene *scene, QObject *parent)
@@ -43,7 +43,12 @@
         kDebug() << "Error, Graph == 0";
         return;
     }
-
+    
+    if (pos.x() < 0) return;
+    else if (pos.y() < 0) return;
+    else if (pos.x() > _graphDocument->width()) return;
+    else if (pos.y() > _graphDocument->height()) return;
+    
     Node *n = _graph -> addNode(i18n("untitled"));
     n ->setX(pos.x());
     n -> setY(pos.y());
--- trunk/playground/edu/Rocs/src/Interface/action_MoveNode.cpp #971436:971437
@@ -22,6 +22,7 @@
 #include "SUI_GraphScene.h"
 #include "graph.h"
 #include "node.h"
+#include "graphDocument.h"
 #include "graphicsitem_Node.h"
 #include <KLocale>
 #include <QGraphicsView>
@@ -57,16 +58,32 @@
     if ( ! _movableNode ) {
         return;
     }
-    _movableNode -> updatePos( pos );
+    if ((pos.x() < 0) || (pos.x() > _graphDocument->width())){
+      if (( pos.y() > 0) && (pos.y() < _graphDocument->height())){
+	_movableNode -> updatePos( QPointF(_node->x(), pos.y()) );
+      }
+    }
+    else if ((pos.y() < 0) || (pos.y() > _graphDocument->height())){
+      if (( pos.x() > 0) && (pos.x() < _graphDocument->width())){
+	_movableNode -> updatePos( QPointF(pos.x(),_node->y() ));
+      }
+    }
+   else{
+      _movableNode -> updatePos( pos );
+    }
 }
 
 void MoveNodeAction::executeRelease(QPointF pos) {
     if ( !_movableNode ) {
         return;
     }
-
     _view->setRenderHint(QPainter::Antialiasing, true);
-    _movableNode -> updatePos( pos );
+    if ((pos.x() < 0) || (pos.y() < 0) || (pos.x() > _graphDocument->width())|| \
(pos.y() > _graphDocument->height())){ +      _movableNode -> updatePos( \
QPointF(_node->x(), _node->y()) ); +    }
+    else{
+      _movableNode -> updatePos( pos );
+    }
     _movableNode = 0;
 }
 
--- trunk/playground/edu/Rocs/src/Interface/action_Select.cpp #971436:971437
@@ -55,25 +55,25 @@
 }
 
 void SelectAction::executeRelease(QPointF pos) {
-    if ( !_graph ) return;
     if ( _selectionRect == 0) return;
-    
+    if ( !_graph ) return;    
     _graphScene->removeItem(_selectionRect);
     
     delete _selectionRect;
     _selectionRect = 0;
     
     QList<QGraphicsItem*> currentSelection = _graphScene->selectedItems();
-    kDebug() << "Number of selected Items: " << currentSelection.size();
     foreach(QGraphicsItem *i, currentSelection) {
         i->setSelected(false);
         i->update();
     }
     
     if (pos == _p1){
+      kDebug() << "Selecionando um item apenas.";
       singleSelect(pos);
     }
     else{
+      kDebug() << "Selecionando um monte de items";
       multiSelect(pos);
     }
     
@@ -89,7 +89,7 @@
 
 void SelectAction::singleSelect(QPointF pos){
     QGraphicsItem * item = _graphScene->itemAt(pos);
-    if ( ! item ) {
+    if ( !qgraphicsitem_cast<NodeItem*>(item) && \
!qgraphicsitem_cast<EdgeItem*>(item) && \
!qgraphicsitem_cast<OrientedEdgeItem*>(item)){  emit ItemSelectedChanged(0);
         return;
     }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic