diff --git a/graphwidget.cpp b/graphwidget.cpp index 2b17f2d..31faf21 100644 --- a/graphwidget.cpp +++ b/graphwidget.cpp @@ -348,9 +348,6 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) // insert new node case Qt::Key_Insert: insertNode(); - contentChanged(); - if (m_showingNodeNumbers) - showNodeNumbers(); break; @@ -400,38 +397,7 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) // delete node case Qt::Key_Delete: { - - if (m_activeNode == m_nodeList.first()) - { - m_parent->statusBarMsg(tr("Base node cannot be deleted.")); - break; - } - - QList nodeList; - if (event->modifiers() == Qt::AltModifier) - { - nodeList = m_activeNode->subtree(); - } - else - { - nodeList.push_back(m_activeNode); - } - - foreach(Node *node, nodeList) - { - if (m_hintNode==node) - m_hintNode=0; - - m_nodeList.removeAll(node); - delete node; - } - - m_activeNode = 0; - contentChanged(); - - if (m_showingNodeNumbers) - showNodeNumbers(); - + removeNode(); break; } // add edge to active node @@ -563,6 +529,12 @@ void GraphWidget::setActiveNode(Node *node) void GraphWidget::insertNode() { + if (!m_activeNode) + { + m_parent->statusBarMsg(tr("No active node.")); + return; + } + double angle(m_activeNode->calculateBiggestAngle()); qreal length(100); @@ -583,6 +555,50 @@ void GraphWidget::insertNode() setActiveNode(node); setActiveNodeEditable(); + + contentChanged(); + if (m_showingNodeNumbers) + showNodeNumbers(); +} + +void GraphWidget::removeNode() +{ + if (!m_activeNode) + { + m_parent->statusBarMsg(tr("No active node.")); + return; + } + + if (m_activeNode == m_nodeList.first()) + { + m_parent->statusBarMsg(tr("Base node cannot be deleted.")); + return; + } + + QList nodeList; + if (QApplication::keyboardModifiers() & Qt::AltModifier) + { + nodeList = m_activeNode->subtree(); + } + else + { + nodeList.push_back(m_activeNode); + } + + foreach(Node *node, nodeList) + { + if (m_hintNode==node) + m_hintNode=0; + + m_nodeList.removeAll(node); + delete node; + } + + m_activeNode = 0; + contentChanged(); + + if (m_showingNodeNumbers) + showNodeNumbers(); } void GraphWidget::showingAllNodeNumbers(const bool &show) diff --git a/graphwidget.h b/graphwidget.h index f8cf443..280b8a9 100644 --- a/graphwidget.h +++ b/graphwidget.h @@ -18,7 +18,6 @@ public: GraphWidget(MainWindow *parent = 0); void setActiveNode(Node *node); - void insertNode(); void setActiveNodeEditable(); void nodeSelected(Node *node); void nodeMoved(QGraphicsSceneMouseEvent *event); @@ -35,6 +34,11 @@ public: void insertPicture(const QString &picture); +public slots: + + void insertNode(); + void removeNode(); + protected: void keyPressEvent(QKeyEvent *event); diff --git a/list-add.svg b/list-add.svg new file mode 100644 index 0000000..6eaed44 --- /dev/null +++ b/list-add.svg @@ -0,0 +1,436 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 new file mode 100644 index 0000000..5f109a0 --- /dev/null +++ b/list-remove.svg @@ -0,0 +1,424 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Remove + 2006-01-04 + + + Andreas Nilsson + + + http://tango-project.org + + + remove + delete + + + + + + + + + + + + + + + + + diff --git a/mainwindow.cpp b/mainwindow.cpp index cefb83c..fd8ebda 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -41,6 +41,56 @@ 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)"), this); + 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); + m_nodeTextColor = new QAction(tr("Node textcolor (t)"), this); + m_addEdge = new QAction(tr("Add edge (a)"), this); + m_delEdge = new QAction(tr("Del edge (d)"), this); + m_moveNode = new QAction(tr("Move node (Ctrl cursor)"), this); + m_moveNode->setDisabled(true); + m_subtree = new QAction(tr("Apply on subtree (Alt)"), this); + m_subtree->setDisabled(true); + + m_hintMode = new QAction(tr("Hint mode (f)"), this); + m_showMainToolbar = new QAction(tr("Main toolbar (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_ui->mainToolBar->addAction(m_addNode); + m_ui->mainToolBar->addAction(m_delNode); + m_ui->mainToolBar->addAction(m_editNode); + m_ui->mainToolBar->addAction(m_scaleUpNode); + m_ui->mainToolBar->addAction(m_scaleDownNode); + m_ui->mainToolBar->addAction(m_nodeColor); + m_ui->mainToolBar->addAction(m_nodeTextColor); + m_ui->mainToolBar->addAction(m_addEdge); + m_ui->mainToolBar->addAction(m_delEdge); + + m_ui->mainToolBar->addSeparator(); + m_ui->mainToolBar->addAction(m_zoomIn); + m_ui->mainToolBar->addAction(m_zoomOut); + m_ui->mainToolBar->addAction(m_hintMode); + m_ui->mainToolBar->addAction(m_moveNode); + m_ui->mainToolBar->addAction(m_subtree); + m_ui->mainToolBar->addAction(m_showMainToolbar); + m_ui->mainToolBar->addAction(m_showStatusIconToolbar); + + m_ui->mainToolBar->hide(); + + + m_doIt = new QAction(QIcon(":/applications-system.svg"), "&Do", this); m_doIt->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); connect(m_doIt, SIGNAL(activated()), this, SLOT(insertPicture())); @@ -57,9 +107,8 @@ MainWindow::MainWindow(QWidget *parent) : m_blocked->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_B)); connect(m_blocked, SIGNAL(activated()), this, SLOT(insertPicture())); - m_question = new QAction(QIcon(":/help-browser.svg"), tr("&What?"), this); - /// @todo come up with some shortcut -// m_question->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_W)); + m_question = new QAction(QIcon(":/help-browser.svg"), tr("&How?"), this); + m_question->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_H)); connect(m_question, SIGNAL(activated()), this, SLOT(insertPicture())); m_postpone = new QAction(QIcon(":/x-office-calendar.svg"), tr("&Postpone"), this); @@ -74,16 +123,16 @@ MainWindow::MainWindow(QWidget *parent) : m_maybe->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M)); connect(m_maybe, SIGNAL(activated()), this, SLOT(insertPicture())); - m_ui->mainToolBar->addAction(m_doIt); - m_ui->mainToolBar->addAction(m_trash); - m_ui->mainToolBar->addAction(m_info); - m_ui->mainToolBar->addAction(m_blocked); - m_ui->mainToolBar->addAction(m_question); - m_ui->mainToolBar->addAction(m_postpone); - m_ui->mainToolBar->addAction(m_delegate); - m_ui->mainToolBar->addAction(m_maybe); - - m_ui->mainToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + m_ui->statusIcons_toolBar->addAction(m_doIt); + m_ui->statusIcons_toolBar->addAction(m_trash); + m_ui->statusIcons_toolBar->addAction(m_info); + m_ui->statusIcons_toolBar->addAction(m_blocked); + m_ui->statusIcons_toolBar->addAction(m_question); + m_ui->statusIcons_toolBar->addAction(m_postpone); + m_ui->statusIcons_toolBar->addAction(m_delegate); + m_ui->statusIcons_toolBar->addAction(m_maybe); + m_ui->statusIcons_toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + m_ui->statusIcons_toolBar->hide(); } MainWindow::~MainWindow() @@ -128,6 +177,8 @@ void MainWindow::newFile() setTitle(m_fileName); m_graphicsView->setFocus(); + + showMainToolbar(); } void MainWindow::openFile(const QString &fileName) @@ -165,6 +216,7 @@ void MainWindow::openFile(const QString &fileName) m_ui->actionClose->setEnabled(true); contentChanged(false); setTitle(m_fileName); + showMainToolbar(); } void MainWindow::saveFile() @@ -238,6 +290,7 @@ bool MainWindow::closeFile() m_contentChanged = false; setTitle(""); m_graphicsView->closeScene(); + showMainToolbar(false); return true; } @@ -381,11 +434,58 @@ 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 ? + !m_ui->mainToolBar->isVisible() : + false); +} + +void MainWindow::showStatusIconToolbar(const bool &show) +{ + m_ui->statusIcons_toolBar->setVisible( + show ? + !m_ui->statusIcons_toolBar->isVisible() : + false); +} + void MainWindow::closeEvent(QCloseEvent * event) { m_contentChanged && !closeFile() ? event->ignore() : event->accept(); } +void MainWindow::keyPressEvent(QKeyEvent *event) +{ + if (event->modifiers() & Qt::ControlModifier) + { + if (event->key() == Qt::Key_M) + { + showMainToolbar(); + return; + } + if (event->key() == Qt::Key_I) + { + showStatusIconToolbar(); + return; + } + } + + QMainWindow::keyPressEvent(event); +} + void MainWindow::setTitle(const QString &title) { if (title.isEmpty()) diff --git a/mainwindow.h b/mainwindow.h index 41f43ec..92d3b4a 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -36,8 +36,26 @@ 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); + + protected: void closeEvent(QCloseEvent * event); + void keyPressEvent(QKeyEvent *event); private: @@ -48,6 +66,23 @@ private: QString m_fileName; bool m_contentChanged; + QAction *m_addNode; + QAction *m_delNode; + QAction *m_editNode; + QAction *m_scaleUpNode; + QAction *m_scaleDownNode; + QAction *m_nodeColor; + QAction *m_nodeTextColor; + QAction *m_addEdge; + QAction *m_delEdge; + QAction *m_zoomIn; + QAction *m_zoomOut; + QAction *m_hintMode; + QAction *m_moveNode; + QAction *m_subtree; + QAction *m_showMainToolbar; + QAction *m_showStatusIconToolbar; + QAction *m_doIt; QAction *m_trash; QAction *m_info; diff --git a/mainwindow.ui b/mainwindow.ui index 710c049..03aeaa5 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 438 - 349 + 600 + 600 @@ -23,7 +23,7 @@ 0 0 - 438 + 600 21 @@ -52,14 +52,31 @@ + + main toolbar + - TopToolBarArea + LeftToolBarArea false + + + true + + + status icons + + + RightToolBarArea + + + true + + true