huge GraphWidget refactor, edd/del edge from maintoolbar without active node bugfix

master
Denes Matetelki 14 years ago
parent bec530fd18
commit ab554f47ec

@ -17,54 +17,64 @@ class GraphWidget : public QGraphicsView
public: public:
GraphWidget(MainWindow *parent = 0); GraphWidget(MainWindow *parent = 0);
void setActiveNode(Node *node); // node reports back it's state change
void nodeSelected(Node *node); void nodeSelected(Node *node);
void nodeMoved(QGraphicsSceneMouseEvent *event); void nodeMoved(QGraphicsSceneMouseEvent *event);
QList<Edge *> edges() const;
// notify MainWindow: a node/edge has changed
void contentChanged(const bool &changed = true); void contentChanged(const bool &changed = true);
// commands from MainWindow
void newScene(); void newScene();
void closeScene(); void closeScene();
bool readContentFromXmlFile(const QString &fileName); bool readContentFromXmlFile(const QString &fileName);
void writeContentToXmlFile(const QString &fileName); void writeContentToXmlFile(const QString &fileName);
void writeContentToPngFile(const QString &fileName); void writeContentToPngFile(const QString &fileName);
void insertPicture(const QString &picture); void insertPicture(const QString &picture);
public slots: public slots:
void zoomIn(); // commands from MainWindow's MainToolBar's actions
void zoomOut();
void insertNode(); void insertNode();
void removeNode(); void removeNode();
void editNode(); void editNode();
void zoomIn();
void zoomOut();
void nodeColor(); void nodeColor();
void nodeTextColor(); void nodeTextColor();
void addEdge(); void addEdge();
void removeEdge(); void removeEdge();
void hintMode();
void nodeLostFocus(); void nodeLostFocus();
void hintMode();
protected: protected:
// key dispathcer of the whole program: long and pedant
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event);
void wheelEvent(QWheelEvent *event); void wheelEvent(QWheelEvent *event);
void drawBackground(QPainter *painter, const QRectF &rect); void drawBackground(QPainter *painter, const QRectF &rect);
private: private:
// zoom in/out of the view
void scaleView(qreal scaleFactor); void scaleView(qreal scaleFactor);
void showNodeNumbers();
void showingAllNodeNumbers(const bool &show = true); // functions on the edges
void showingNodeNumbersBeginWithNumber(const int &number, QList<Edge *> allEdges() const;
const bool &show = true);
bool numberStartsWithNumber(const int &number, const int &prefix);
qreal calculateBiggestAngle(Node *node);
void addEdge(Node *source, Node *destination); void addEdge(Node *source, Node *destination);
void removeEdge(Node* source, Node *destination); void removeEdge(Node* source, Node *destination);
void removeAllNodes();
// functions on nodes
void addFirstNode(); void addFirstNode();
void removeAllNodes();
void setActiveNode(Node *node);
// hint mode's nodenumber handling functions
void showNodeNumbers();
void showingAllNodeNumbers(const bool &show = true);
void showingNodeNumbersBeginWithNumber(const int &prefix,
const bool &show = true);
QList<Node *> m_nodeList; QList<Node *> m_nodeList;
MainWindow *m_parent; MainWindow *m_parent;
@ -80,7 +90,6 @@ private:
QString m_fileName; QString m_fileName;
static const QColor m_paper; static const QColor m_paper;
static const QColor m_gold;
}; };
#endif // GRAPHWIDGET_H #endif // GRAPHWIDGET_H

File diff suppressed because it is too large Load Diff

@ -352,41 +352,68 @@ void MainWindow::setUpMainToolbar()
/// @bug or a feature? no underline here /// @bug or a feature? no underline here
m_addNode = new QAction(tr("Add node (ins)"), this); m_addNode = new QAction(tr("Add node (ins)"), this);
connect(m_addNode, SIGNAL(activated()), m_graphicsView, SLOT(insertNode())); connect(m_addNode, SIGNAL(activated()), m_graphicsView,
SLOT(insertNode()));
m_delNode = new QAction(tr("Del node (del)"), this); m_delNode = new QAction(tr("Del node (del)"), this);
connect(m_delNode, SIGNAL(activated()), m_graphicsView, SLOT(removeNode())); connect(m_delNode, SIGNAL(activated()), m_graphicsView,
SLOT(removeNode()));
m_editNode = new QAction(tr("Edit node (F2, dubclick)"), this); m_editNode = new QAction(tr("Edit node (F2, dubclick)"), this);
connect(m_editNode, SIGNAL(activated()), m_graphicsView, SLOT(editNode())); connect(m_editNode, SIGNAL(activated()), m_graphicsView,
SLOT(editNode()));
/// @todo pass ctrl /// @todo pass ctrl
m_scaleUpNode = new QAction(tr("ScaleUp Node (Ctrl +)"), this); m_scaleUpNode = new QAction(tr("ScaleUp Node (Ctrl +)"), this);
m_scaleDownNode = new QAction(tr("ScaleDown Node (Ctrl -)"), this); m_scaleDownNode = new QAction(tr("ScaleDown Node (Ctrl -)"), this);
m_nodeColor = new QAction(tr("Node color (c)"), this); m_nodeColor = new QAction(tr("Node color (c)"), this);
connect(m_nodeColor, SIGNAL(activated()), m_graphicsView, SLOT(nodeColor())); connect(m_nodeColor, SIGNAL(activated()), m_graphicsView,
SLOT(nodeColor()));
m_nodeTextColor = new QAction(tr("Node textcolor (t)"), this); m_nodeTextColor = new QAction(tr("Node textcolor (t)"), this);
connect(m_nodeTextColor, SIGNAL(activated()), m_graphicsView, SLOT(nodeTextColor())); connect(m_nodeTextColor, SIGNAL(activated()), m_graphicsView,
SLOT(nodeTextColor()));
m_addEdge = new QAction(tr("Add edge (a)"), this); m_addEdge = new QAction(tr("Add edge (a)"), this);
connect(m_addEdge, SIGNAL(activated()), m_graphicsView, SLOT(addEdge())); connect(m_addEdge, SIGNAL(activated()), m_graphicsView,
SLOT(addEdge()));
m_delEdge = new QAction(tr("Del edge (d)"), this); m_delEdge = new QAction(tr("Del edge (d)"), this);
connect(m_delEdge, SIGNAL(activated()), m_graphicsView, SLOT(removeEdge())); connect(m_delEdge, SIGNAL(activated()), m_graphicsView,
SLOT(removeEdge()));
m_moveNode = new QAction(tr("Move node\n(Ctrl cursor, drag)"), this); m_moveNode = new QAction(tr("Move node\n(Ctrl cursor, drag)"), this);
m_moveNode->setDisabled(true); m_moveNode->setDisabled(true);
m_subtree = new QAction(tr("Change on wholesubtree\n(Ctrl shift)"), this); m_subtree = new QAction(tr("Change on wholesubtree\n(Ctrl shift)"), this);
m_subtree->setDisabled(true); m_subtree->setDisabled(true);
m_zoomIn = new QAction(tr("Zoom in (+, scrollup)"), this); m_zoomIn = new QAction(tr("Zoom in (+, scrollup)"), this);
connect(m_zoomIn, SIGNAL(activated()), m_graphicsView, SLOT(zoomIn())); connect(m_zoomIn, SIGNAL(activated()), m_graphicsView,
SLOT(zoomIn()));
m_zoomOut = new QAction(tr("Zoom out (-, scrolldown)"), this); m_zoomOut = new QAction(tr("Zoom out (-, scrolldown)"), this);
connect(m_zoomOut, SIGNAL(activated()), m_graphicsView, SLOT(zoomOut())); connect(m_zoomOut, SIGNAL(activated()), m_graphicsView,
SLOT(zoomOut()));
m_esc = new QAction(tr("Leave editing,\nedge eadd/remove (esc)"), this); m_esc = new QAction(tr("Leave editing,\nedge eadd/remove (esc)"), this);
connect(m_esc, SIGNAL(activated()), m_graphicsView, SLOT(nodeLostFocus())); connect(m_esc, SIGNAL(activated()), m_graphicsView,
SLOT(nodeLostFocus()));
m_hintMode = new QAction(tr("Hint mode (f)"), this); m_hintMode = new QAction(tr("Hint mode (f)"), this);
connect(m_hintMode, SIGNAL(activated()), m_graphicsView, SLOT(hintMode())); connect(m_hintMode, SIGNAL(activated()), m_graphicsView,
SLOT(hintMode()));
m_showMainToolbar = new QAction(tr("Show main toolbar\n(Ctrl m)"), this); m_showMainToolbar = new QAction(tr("Show main toolbar\n(Ctrl m)"), this);
m_showMainToolbar->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M)); m_showMainToolbar->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M));
connect(m_showMainToolbar, SIGNAL(activated()), this, SLOT(showMainToolbar())); connect(m_showMainToolbar, SIGNAL(activated()), this,
m_showStatusIconToolbar = new QAction(tr("Insert status icons\n(Ctrl i)"), this); SLOT(showMainToolbar()));
connect(m_showStatusIconToolbar, SIGNAL(activated()), this, SLOT(showStatusIconToolbar()));
m_showStatusIconToolbar = new QAction(tr("Insert status icons\n(Ctrl i)"),
this);
connect(m_showStatusIconToolbar, SIGNAL(activated()), this,
SLOT(showStatusIconToolbar()));
m_ui->mainToolBar->addAction(m_addNode); m_ui->mainToolBar->addAction(m_addNode);
m_ui->mainToolBar->addAction(m_delNode); m_ui->mainToolBar->addAction(m_delNode);

@ -99,11 +99,13 @@ void Node::setActive(const bool &active)
void Node::setEditable(const bool &editable) void Node::setEditable(const bool &editable)
{ {
setTextInteractionFlags( if (!editable)
editable ? {
Qt::TextEditable : setTextInteractionFlags(Qt::NoTextInteraction);
Qt::NoTextInteraction); return;
}
setTextInteractionFlags(Qt::TextEditable);
QTextCursor c = textCursor(); QTextCursor c = textCursor();
c.setPosition(c.document()->toPlainText().length()); c.setPosition(c.document()->toPlainText().length());
setTextCursor(c); setTextCursor(c);
@ -479,7 +481,10 @@ QPainterPath Node::shape () const
void Node::focusOutEvent(QFocusEvent *event) void Node::focusOutEvent(QFocusEvent *event)
{ {
qDebug() << __PRETTY_FUNCTION__;
Q_UNUSED(event); Q_UNUSED(event);
setEditable(false);
m_graph->nodeLostFocus(); m_graph->nodeLostFocus();
} }

Loading…
Cancel
Save