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:
GraphWidget(MainWindow *parent = 0);
void setActiveNode(Node *node);
// node reports back it's state change
void nodeSelected(Node *node);
void nodeMoved(QGraphicsSceneMouseEvent *event);
QList<Edge *> edges() const;
// notify MainWindow: a node/edge has changed
void contentChanged(const bool &changed = true);
// commands from MainWindow
void newScene();
void closeScene();
bool readContentFromXmlFile(const QString &fileName);
void writeContentToXmlFile(const QString &fileName);
void writeContentToPngFile(const QString &fileName);
void insertPicture(const QString &picture);
public slots:
void zoomIn();
void zoomOut();
// commands from MainWindow's MainToolBar's actions
void insertNode();
void removeNode();
void editNode();
void zoomIn();
void zoomOut();
void nodeColor();
void nodeTextColor();
void addEdge();
void removeEdge();
void hintMode();
void nodeLostFocus();
void hintMode();
protected:
// key dispathcer of the whole program: long and pedant
void keyPressEvent(QKeyEvent *event);
void wheelEvent(QWheelEvent *event);
void drawBackground(QPainter *painter, const QRectF &rect);
private:
// zoom in/out of the view
void scaleView(qreal scaleFactor);
void showNodeNumbers();
void showingAllNodeNumbers(const bool &show = true);
void showingNodeNumbersBeginWithNumber(const int &number,
const bool &show = true);
bool numberStartsWithNumber(const int &number, const int &prefix);
qreal calculateBiggestAngle(Node *node);
// functions on the edges
QList<Edge *> allEdges() const;
void addEdge(Node *source, Node *destination);
void removeEdge(Node* source, Node *destination);
void removeAllNodes();
// functions on nodes
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;
MainWindow *m_parent;
@ -80,7 +90,6 @@ private:
QString m_fileName;
static const QColor m_paper;
static const QColor m_gold;
};
#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
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);
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);
connect(m_editNode, SIGNAL(activated()), m_graphicsView, SLOT(editNode()));
connect(m_editNode, SIGNAL(activated()), m_graphicsView,
SLOT(editNode()));
/// @todo pass ctrl
m_scaleUpNode = new QAction(tr("ScaleUp Node (Ctrl +)"), this);
m_scaleDownNode = new QAction(tr("ScaleDown Node (Ctrl -)"), 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);
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);
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);
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->setDisabled(true);
m_subtree = new QAction(tr("Change on wholesubtree\n(Ctrl shift)"), this);
m_subtree->setDisabled(true);
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);
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);
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);
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->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M));
connect(m_showMainToolbar, SIGNAL(activated()), this, SLOT(showMainToolbar()));
m_showStatusIconToolbar = new QAction(tr("Insert status icons\n(Ctrl i)"), this);
connect(m_showStatusIconToolbar, SIGNAL(activated()), this, SLOT(showStatusIconToolbar()));
connect(m_showMainToolbar, SIGNAL(activated()), this,
SLOT(showMainToolbar()));
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_delNode);

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

Loading…
Cancel
Save