graphwidget's zoomIn/Out has been splitted to zoomIn/Out and scaleUp/Down so they can be called separately (cannot modify the modifier keys when calling them)

master
Denes Matetelki 14 years ago
parent a63518fb3c
commit 8843d20ac2

@ -39,6 +39,8 @@ public slots:
void editNode(); void editNode();
void zoomIn(); void zoomIn();
void zoomOut(); void zoomOut();
void scaleUp();
void scaleDown();
void nodeColor(); void nodeColor();
void nodeTextColor(); void nodeTextColor();
void addEdge(); void addEdge();

@ -364,57 +364,53 @@ void GraphWidget::editNode()
void GraphWidget::zoomIn() 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? // Scale up just the active Node or it's subtree too?
if (QApplication::keyboardModifiers() & Qt::ShiftModifier) if (QApplication::keyboardModifiers() & Qt::ShiftModifier)
{ {
QList <Node *> nodeList = m_activeNode->subtree(); QList <Node *> nodeList = m_activeNode->subtree();
foreach(Node *node, nodeList) foreach(Node *node, nodeList)
node->setScale(qreal(1.2),sceneRect()); node->setScale(qreal(1.2),sceneRect());
}
else
{
m_activeNode->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? // Scale down just the active Node or it's subtree too?
if (QApplication::keyboardModifiers() & Qt::ShiftModifier) if (QApplication::keyboardModifiers() & Qt::ShiftModifier)
{ {
QList <Node *> nodeList = m_activeNode->subtree(); QList <Node *> nodeList = m_activeNode->subtree();
foreach(Node *node, nodeList) foreach(Node *node, nodeList)
node->setScale(qreal(1 / 1.2),sceneRect()); node->setScale(qreal(1 / 1.2),sceneRect());
}
else
{
m_activeNode->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: case Qt::Key_Plus:
zoomIn(); event->modifiers() & Qt::ControlModifier ?
scaleUp() :
zoomIn();
break; break;
case Qt::Key_Minus: case Qt::Key_Minus:
zoomOut(); event->modifiers() & Qt::ControlModifier ?
scaleDown() :
zoomOut();
break; break;
// Hint mode: select a Node vimperator-style. // Hint mode: select a Node vimperator-style.
@ -713,9 +714,13 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
void GraphWidget::wheelEvent(QWheelEvent *event) void GraphWidget::wheelEvent(QWheelEvent *event)
{ {
event->delta() > 0 ? event->modifiers() & Qt::ControlModifier ?
zoomIn() : (event->delta() > 0 ?
zoomOut(); scaleUp() :
scaleDown()) :
(event->delta() > 0 ?
zoomIn() :
zoomOut());
} }
void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect) void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect)

@ -319,9 +319,12 @@ void MainWindow::setUpMainToolbar()
connect(m_editNode, SIGNAL(activated()), m_graphicsView, connect(m_editNode, SIGNAL(activated()), m_graphicsView,
SLOT(editNode())); SLOT(editNode()));
/// @todo pass ctrl
m_scaleUpNode = new QAction(tr("ScaleUp Node (Ctrl +)"), this); 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); 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); m_nodeColor = new QAction(tr("Node color (c)"), this);
connect(m_nodeColor, SIGNAL(activated()), m_graphicsView, connect(m_nodeColor, SIGNAL(activated()), m_graphicsView,

Loading…
Cancel
Save