From a2ac1feb6c527abca21568405e50d0935b8709da Mon Sep 17 00:00:00 2001 From: Denes Matetelki Date: Fri, 24 Jun 2011 12:21:20 +0200 Subject: [PATCH] huge refactor: no keys helppage, but a hideable maintoolbar --- graphwidget.cpp | 344 ++++++++++++++++++++------------------ graphwidget.h | 11 +- list-add.svg | 436 ------------------------------------------------ list-remove.svg | 424 ---------------------------------------------- mainwindow.cpp | 53 +++--- mainwindow.h | 15 +- mainwindow.ui | 7 +- node.cpp | 2 +- 8 files changed, 227 insertions(+), 1065 deletions(-) delete mode 100644 list-add.svg delete mode 100644 list-remove.svg diff --git a/graphwidget.cpp b/graphwidget.cpp index 31faf21..307cf82 100644 --- a/graphwidget.cpp +++ b/graphwidget.cpp @@ -225,43 +225,29 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) nodeLostFocus(); return; } + if (m_editingNode) { m_activeNode->keyPressEvent(event); return; } - // certain actions need an active node - if (!m_activeNode && - ( event->key() == Qt::Key_Insert || // add new node - event->key() == Qt::Key_F2 || // edit node - event->key() == Qt::Key_Delete || // delete node - event->key() == Qt::Key_A || // add edge - event->key() == Qt::Key_D || // remove edge - event->key() == Qt::Key_C || // node color - event->key() == Qt::Key_T || // node text color - ( event->modifiers() & Qt::ControlModifier && // moving node - ( event->key() == Qt::Key_Up || - event->key() == Qt::Key_Down || - event->key() == Qt::Key_Left || - event->key() == Qt::Key_Right || - event->key() == Qt::Key_Plus || - event->key() == Qt::Key_Minus )))) - { - m_parent->statusBarMsg(tr("No active node.")); - return; - } - switch (event->key()) { - // move sceve, or move node if modkey is ctrl case Qt::Key_Up: case Qt::Key_Down: case Qt::Key_Left: case Qt::Key_Right: + + if (!m_activeNode) + { + m_parent->statusBarMsg(tr("No active node.")); + return; + } + if (event->modifiers() & Qt::ControlModifier) { - if (event->modifiers() & Qt::AltModifier) + if (event->modifiers() & Qt::MetaModifier) { QList nodeList = m_activeNode->subtree(); foreach(Node *node, nodeList) @@ -288,64 +274,22 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) } break; - // zoom in/out case Qt::Key_Plus: - if (event->modifiers() & Qt::ControlModifier) - { - if (event->modifiers() & Qt::AltModifier) - { - QList nodeList = m_activeNode->subtree(); - foreach(Node *node, nodeList) - node->setScale(qreal(1.2),sceneRect()); - } - else - { - m_activeNode->setScale(qreal(1.2),sceneRect()); - } - } - else - { - scaleView(qreal(1.2)); - } + zoomIn(); break; case Qt::Key_Minus: - if (event->modifiers() & Qt::ControlModifier) - { - if (event->modifiers() & Qt::AltModifier) - { - QList nodeList = m_activeNode->subtree(); - foreach(Node *node, nodeList) - node->setScale(qreal(1 / 1.2),sceneRect()); - } - else - { - m_activeNode->setScale(qreal(1 / 1.2),sceneRect()); - } - } - - else - { - scaleView(1 / qreal(1.2)); - } + zoomOut(); break; // Hint mode: select a node vimperator style case Qt::Key_F: - m_showingNodeNumbers = !m_showingNodeNumbers; - if (!m_showingNodeNumbers) - { - showingAllNodeNumbers(false); - break; - } - m_hintNumber.clear(); - showNodeNumbers(); + hintMode(); break; - // insert new node case Qt::Key_Insert: insertNode(); @@ -389,82 +333,35 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) break; - // edit node case Qt::Key_F2: - setActiveNodeEditable(); + + editNode(); break; - // delete node case Qt::Key_Delete: - { + removeNode(); break; - } - // add edge to active node + case Qt::Key_A: - m_parent->statusBarMsg(tr("Add edge: select destination node.")); - m_edgeAdding = true; + + addEdge(); break; - // add edge to active node case Qt::Key_D: - m_parent->statusBarMsg(tr("Delete edge: select other end-node.")); - m_edgeDeleting = true; + + removeEdge(); break; case Qt::Key_C: - { - QList nodeList; - if (event->modifiers() == Qt::AltModifier) - { - nodeList = m_activeNode->subtree(); - } - else - { - nodeList.push_back(m_activeNode); - } - - QColorDialog dialog(this); - dialog.setWindowTitle(tr("Select node color")); - dialog.setCurrentColor(m_activeNode->color()); - if (dialog.exec()) - { - QColor color = dialog.selectedColor(); - foreach(Node *node, nodeList) - { - node->setColor(color); - foreach (Edge * edge, node->edgesToThis(false)) - edge->setColor(color); - } - } + nodeColor(); break; - } case Qt::Key_T: - { - QList nodeList; - if (event->modifiers() == Qt::AltModifier) - { - nodeList = m_activeNode->subtree(); - } - else - { - nodeList.push_back(m_activeNode); - } - - QColorDialog dialog(this); - dialog.setWindowTitle(tr("Select text color")); - dialog.setCurrentColor(m_activeNode->textColor()); - if (dialog.exec()) - { - QColor color = dialog.selectedColor(); - foreach(Node *node, nodeList) - node->setTextColor(color); - } + nodeTextColor(); break; - } default: QGraphicsView::keyPressEvent(event); @@ -475,29 +372,9 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) void GraphWidget::wheelEvent(QWheelEvent *event) { - if (QApplication::keyboardModifiers() & Qt::ControlModifier) - { - if (!m_activeNode) - { - m_parent->statusBarMsg(tr("No active node.")); - return; - } - if (QApplication::keyboardModifiers() & Qt::AltModifier) - { - foreach(Node *node, m_activeNode->subtree()) - node->setScale(pow((double)1.2, event->delta() / 120.0), - sceneRect()); - } - else - { - m_activeNode->setScale(pow((double)1.2, event->delta() / 120.0), - sceneRect()); - } - } - else - { - scaleView(pow((double)1.2, event->delta() / 240.0)); - } + event->delta() > 0 ? + zoomIn() : + zoomOut(); } void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect) @@ -527,6 +404,60 @@ void GraphWidget::setActiveNode(Node *node) m_activeNode->setActive(); } +void GraphWidget::zoomIn() +{ + if (QApplication::keyboardModifiers() & Qt::ControlModifier) + { + if (!m_activeNode) + { + m_parent->statusBarMsg(tr("No active node.")); + return; + } + + if (QApplication::keyboardModifiers() & Qt::ShiftModifier) + { + QList nodeList = m_activeNode->subtree(); + foreach(Node *node, nodeList) + node->setScale(qreal(1.2),sceneRect()); + } + else + { + m_activeNode->setScale(qreal(1.2),sceneRect()); + } + } + else + { + scaleView(qreal(1.2)); + } +} + +void GraphWidget::zoomOut() +{ + if (QApplication::keyboardModifiers() & Qt::ControlModifier) + { + if (!m_activeNode) + { + m_parent->statusBarMsg(tr("No active node.")); + return; + } + + if (QApplication::keyboardModifiers() & Qt::ShiftModifier) + { + QList nodeList = m_activeNode->subtree(); + foreach(Node *node, nodeList) + node->setScale(qreal(1 / 1.2),sceneRect()); + } + else + { + m_activeNode->setScale(qreal(1 / 1.2),sceneRect()); + } + } + else + { + scaleView(qreal(1 / 1.2)); + } +} + void GraphWidget::insertNode() { if (!m_activeNode) @@ -554,7 +485,7 @@ void GraphWidget::insertNode() addEdge(m_activeNode, node); setActiveNode(node); - setActiveNodeEditable(); + editNode(); contentChanged(); if (m_showingNodeNumbers) @@ -576,7 +507,8 @@ void GraphWidget::removeNode() } QList nodeList; - if (QApplication::keyboardModifiers() & Qt::AltModifier) + if (QApplication::keyboardModifiers() & Qt::ControlModifier && + QApplication::keyboardModifiers() & Qt::ShiftModifier) { nodeList = m_activeNode->subtree(); } @@ -601,6 +533,108 @@ void GraphWidget::removeNode() showNodeNumbers(); } +void GraphWidget::editNode() +{ + if (!m_activeNode) + { + m_parent->statusBarMsg(tr("No active node.")); + return; + } + + m_editingNode = true; + m_activeNode->setEditable(); + m_scene->setFocusItem(m_activeNode); +} + +void GraphWidget::nodeColor() +{ + if (!m_activeNode) + { + m_parent->statusBarMsg(tr("No active node.")); + return; + } + + QList nodeList; + if (QApplication::keyboardModifiers() & Qt::ControlModifier && + QApplication::keyboardModifiers() & Qt::ShiftModifier) + { + nodeList = m_activeNode->subtree(); + } + else + { + nodeList.push_back(m_activeNode); + } + + QColorDialog dialog(this); + dialog.setWindowTitle(tr("Select node color")); + dialog.setCurrentColor(m_activeNode->color()); + if (dialog.exec()) + { + QColor color = dialog.selectedColor(); + foreach(Node *node, nodeList) + { + node->setColor(color); + foreach (Edge * edge, node->edgesToThis(false)) + edge->setColor(color); + } + } +} + +void GraphWidget::nodeTextColor() +{ + if (!m_activeNode) + { + m_parent->statusBarMsg(tr("No active node.")); + return; + } + + QList nodeList; + if (QApplication::keyboardModifiers() & Qt::ControlModifier && + QApplication::keyboardModifiers() & Qt::ShiftModifier) + { + nodeList = m_activeNode->subtree(); + } + else + { + nodeList.push_back(m_activeNode); + } + + QColorDialog dialog(this); + dialog.setWindowTitle(tr("Select text color")); + dialog.setCurrentColor(m_activeNode->textColor()); + if (dialog.exec()) + { + QColor color = dialog.selectedColor(); + foreach(Node *node, nodeList) + node->setTextColor(color); + } +} + +void GraphWidget::addEdge() +{ + m_parent->statusBarMsg(tr("Add edge: select destination node.")); + m_edgeAdding = true; +} + +void GraphWidget::removeEdge() +{ + m_parent->statusBarMsg(tr("Delete edge: select other end-node.")); + m_edgeDeleting = true; +} + +void GraphWidget::hintMode() +{ + m_showingNodeNumbers = !m_showingNodeNumbers; + if (!m_showingNodeNumbers) + { + showingAllNodeNumbers(false); + return; + } + + m_hintNumber.clear(); + showNodeNumbers(); +} + void GraphWidget::showingAllNodeNumbers(const bool &show) { int i =0; @@ -646,13 +680,6 @@ bool GraphWidget::numberStartsWithNumber(const int &number, const int &prefix) return (QString::number(number)).startsWith(QString::number(prefix)); } -void GraphWidget::setActiveNodeEditable() -{ - m_editingNode = true; - m_activeNode->setEditable(); - m_scene->setFocusItem(m_activeNode); -} - void GraphWidget::nodeSelected(Node *node) { showingAllNodeNumbers(false); @@ -680,8 +707,7 @@ void GraphWidget::nodeSelected(Node *node) void GraphWidget::nodeMoved(QGraphicsSceneMouseEvent *event) { QList nodeList; - if (event->modifiers() & Qt::AltModifier && - event->modifiers() & Qt::ControlModifier) + if (event->modifiers() & Qt::MetaModifier) { nodeList = m_activeNode->subtree(); } diff --git a/graphwidget.h b/graphwidget.h index 280b8a9..45ab717 100644 --- a/graphwidget.h +++ b/graphwidget.h @@ -18,10 +18,8 @@ public: GraphWidget(MainWindow *parent = 0); void setActiveNode(Node *node); - void setActiveNodeEditable(); void nodeSelected(Node *node); void nodeMoved(QGraphicsSceneMouseEvent *event); - void nodeLostFocus(); QList edges() const; void contentChanged(const bool &changed = true); @@ -36,8 +34,17 @@ public: public slots: + void zoomIn(); + void zoomOut(); void insertNode(); void removeNode(); + void editNode(); + void nodeColor(); + void nodeTextColor(); + void addEdge(); + void removeEdge(); + void hintMode(); + void nodeLostFocus(); protected: diff --git a/list-add.svg b/list-add.svg deleted file mode 100644 index 6eaed44..0000000 --- a/list-add.svg +++ /dev/null @@ -1,436 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - Add - 2006-01-04 - - - Andreas Nilsson - - - http://tango-project.org - - - add - plus - - - - - - - - - - - - - - - - - - diff --git a/list-remove.svg b/list-remove.svg deleted file mode 100644 index 5f109a0..0000000 --- a/list-remove.svg +++ /dev/null @@ -1,424 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - Remove - 2006-01-04 - - - Andreas Nilsson - - - http://tango-project.org - - - remove - delete - - - - - - - - - - - - - - - - - diff --git a/mainwindow.cpp b/mainwindow.cpp index fd8ebda..57710f7 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -31,8 +31,9 @@ MainWindow::MainWindow(QWidget *parent) : connect(m_ui->actionAbout_QtMindMap, SIGNAL(activated()), this, SLOT(about())); - connect(m_ui->actionKeys, SIGNAL(activated()), - this, SLOT(keys())); + +// connect(m_ui->actionKeys, SIGNAL(activated()), +// this, SLOT(keys())); setCentralWidget(m_graphicsView); @@ -41,32 +42,42 @@ MainWindow::MainWindow(QWidget *parent) : // why can't I do this with qtcreator? /// @bug or a feature? no underline here - m_zoomIn = new QAction(tr("Zoom in (+)"), this); - m_zoomOut = new QAction(tr("Zoom out (+)"), this); - m_addNode = new QAction(tr("Add node (ins)"), this); 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())); + m_editNode = new QAction(tr("Edit node (F2, dubclick)"), this); + connect(m_editNode, SIGNAL(activated()), m_graphicsView, SLOT(editNode())); - m_editNode = new QAction(tr("Edit node (F2)"), this); + /// @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())); m_nodeTextColor = new QAction(tr("Node textcolor (t)"), this); + 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())); m_delEdge = new QAction(tr("Del edge (d)"), this); - m_moveNode = new QAction(tr("Move node (Ctrl cursor)"), this); + 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("Apply on subtree (Alt)"), this); + 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())); + m_zoomOut = new QAction(tr("Zoom out (-, scrolldown)"), this); + 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())); m_hintMode = new QAction(tr("Hint mode (f)"), this); - m_showMainToolbar = new QAction(tr("Main toolbar (Ctrl m)"), this); + 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("Status icons (Ctrl i)"), this); + 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); @@ -81,6 +92,7 @@ MainWindow::MainWindow(QWidget *parent) : m_ui->mainToolBar->addSeparator(); m_ui->mainToolBar->addAction(m_zoomIn); m_ui->mainToolBar->addAction(m_zoomOut); + m_ui->mainToolBar->addAction(m_esc); m_ui->mainToolBar->addAction(m_hintMode); m_ui->mainToolBar->addAction(m_moveNode); m_ui->mainToolBar->addAction(m_subtree); @@ -89,7 +101,8 @@ MainWindow::MainWindow(QWidget *parent) : m_ui->mainToolBar->hide(); - + m_insertIcon = new QAction(tr("Insert icon:"), this); + m_insertIcon->setDisabled(true); m_doIt = new QAction(QIcon(":/applications-system.svg"), "&Do", this); m_doIt->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); @@ -123,6 +136,7 @@ MainWindow::MainWindow(QWidget *parent) : m_maybe->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M)); connect(m_maybe, SIGNAL(activated()), this, SLOT(insertPicture())); + m_ui->statusIcons_toolBar->addAction(m_insertIcon); m_ui->statusIcons_toolBar->addAction(m_doIt); m_ui->statusIcons_toolBar->addAction(m_trash); m_ui->statusIcons_toolBar->addAction(m_info); @@ -434,19 +448,6 @@ void MainWindow::insertPicture() } } -void MainWindow::addNode() { } -void MainWindow::delNode() { } -void MainWindow::editNode() { } -void MainWindow::scaleUpNode() { } -void MainWindow::scaleDownNode() { } -void MainWindow::nodeColor() { } -void MainWindow::nodeTextColor() { } -void MainWindow::addEdge() { } -void MainWindow::delEdge() { } -void MainWindow::zoomIn() { } -void MainWindow::zoomOut() { } -void MainWindow::hintMode() { } - void MainWindow::showMainToolbar(const bool &show) { m_ui->mainToolBar->setVisible(show ? diff --git a/mainwindow.h b/mainwindow.h index 92d3b4a..51460ab 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -36,19 +36,6 @@ public slots: void insertPicture(); - void addNode(); - void delNode(); - void editNode(); - void scaleUpNode(); - void scaleDownNode(); - void nodeColor(); - void nodeTextColor(); - void addEdge(); - void delEdge(); - void zoomIn(); - void zoomOut(); - void hintMode(); - void showMainToolbar(const bool &show = true); void showStatusIconToolbar(const bool &show = true); @@ -77,12 +64,14 @@ private: QAction *m_delEdge; QAction *m_zoomIn; QAction *m_zoomOut; + QAction *m_esc; QAction *m_hintMode; QAction *m_moveNode; QAction *m_subtree; QAction *m_showMainToolbar; QAction *m_showStatusIconToolbar; + QAction *m_insertIcon; QAction *m_doIt; QAction *m_trash; QAction *m_info; diff --git a/mainwindow.ui b/mainwindow.ui index 03aeaa5..f0fea10 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -24,7 +24,7 @@ 0 0 600 - 21 + 23 @@ -45,7 +45,6 @@ &Help - @@ -68,13 +67,13 @@ true - status icons + insert status icons RightToolBarArea - true + false diff --git a/node.cpp b/node.cpp index 8f9c98e..ccfbb60 100644 --- a/node.cpp +++ b/node.cpp @@ -456,7 +456,7 @@ void Node::mousePressEvent(QGraphicsSceneMouseEvent *event) void Node::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { Q_UNUSED(event); - m_graph->setActiveNodeEditable(); + m_graph->editNode(); } void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)