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 zoomIn();
void zoomOut();
void scaleUp();
void scaleDown();
void nodeColor();
void nodeTextColor();
void addEdge();

@ -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 <Node *> 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 <Node *> 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 <Node *> 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 <Node *> 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)

@ -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,

Loading…
Cancel
Save