diff --git a/include/graphwidget.h b/include/graphwidget.h index 86c8ff0..f442750 100644 --- a/include/graphwidget.h +++ b/include/graphwidget.h @@ -39,6 +39,8 @@ public slots: void editNode(); void zoomIn(); void zoomOut(); + void scaleUp(); + void scaleDown(); void nodeColor(); void nodeTextColor(); void addEdge(); diff --git a/src/graphwidget.cpp b/src/graphwidget.cpp index eba92ec..f71c525 100644 --- a/src/graphwidget.cpp +++ b/src/graphwidget.cpp @@ -364,57 +364,53 @@ void GraphWidget::editNode() void GraphWidget::zoomIn() { - if (QApplication::keyboardModifiers() & Qt::ControlModifier) + scaleView(qreal(1.2)); +} + +void GraphWidget::zoomOut() +{ + scaleView(qreal(1 / 1.2)); +} + +void GraphWidget::scaleUp() +{ + if (!m_activeNode) { - if (!m_activeNode) - { - m_parent->statusBarMsg(tr("No active node.")); - return; - } + m_parent->statusBarMsg(tr("No active node.")); + return; + } - // Scale up just the active Node or it's subtree too? - 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()); - } + // Scale up just the active Node or it's subtree too? + if (QApplication::keyboardModifiers() & Qt::ShiftModifier) + { + QList nodeList = m_activeNode->subtree(); + foreach(Node *node, nodeList) + node->setScale(qreal(1.2),sceneRect()); } - else // zoom in the view + else { - scaleView(qreal(1.2)); + m_activeNode->setScale(qreal(1.2),sceneRect()); } } -void GraphWidget::zoomOut() +void GraphWidget::scaleDown() { - if (QApplication::keyboardModifiers() & Qt::ControlModifier) + if (!m_activeNode) { - if (!m_activeNode) - { - m_parent->statusBarMsg(tr("No active node.")); - return; - } + m_parent->statusBarMsg(tr("No active node.")); + return; + } - // Scale down just the active Node or it's subtree too? - 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()); - } + // Scale down just the active Node or it's subtree too? + if (QApplication::keyboardModifiers() & Qt::ShiftModifier) + { + QList nodeList = m_activeNode->subtree(); + foreach(Node *node, nodeList) + node->setScale(qreal(1 / 1.2),sceneRect()); } - else // zoom out of the view + else { - scaleView(qreal(1 / 1.2)); + m_activeNode->setScale(qreal(1 / 1.2),sceneRect()); } } @@ -619,12 +615,17 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) case Qt::Key_Plus: - zoomIn(); + event->modifiers() & Qt::ControlModifier ? + scaleUp() : + zoomIn(); + break; case Qt::Key_Minus: - zoomOut(); + event->modifiers() & Qt::ControlModifier ? + scaleDown() : + zoomOut(); break; // Hint mode: select a Node vimperator-style. @@ -713,9 +714,13 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) void GraphWidget::wheelEvent(QWheelEvent *event) { - event->delta() > 0 ? - zoomIn() : - zoomOut(); + event->modifiers() & Qt::ControlModifier ? + (event->delta() > 0 ? + scaleUp() : + scaleDown()) : + (event->delta() > 0 ? + zoomIn() : + zoomOut()); } void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fefdc46..c63fd7c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -319,9 +319,12 @@ void MainWindow::setUpMainToolbar() connect(m_editNode, SIGNAL(activated()), m_graphicsView, SLOT(editNode())); - /// @todo pass ctrl m_scaleUpNode = new QAction(tr("ScaleUp Node (Ctrl +)"), this); + connect(m_scaleUpNode, SIGNAL(activated()), m_graphicsView, + SLOT(scaleUp())); m_scaleDownNode = new QAction(tr("ScaleDown Node (Ctrl -)"), this); + connect(m_scaleDownNode, SIGNAL(activated()), m_graphicsView, + SLOT(scaleDown())); m_nodeColor = new QAction(tr("Node color (c)"), this); connect(m_nodeColor, SIGNAL(activated()), m_graphicsView,