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,7 +364,15 @@ 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)
{ {
@ -384,15 +392,8 @@ void GraphWidget::zoomIn()
m_activeNode->setScale(qreal(1.2),sceneRect()); m_activeNode->setScale(qreal(1.2),sceneRect());
} }
} }
else // zoom in the view
{
scaleView(qreal(1.2));
}
}
void GraphWidget::zoomOut() void GraphWidget::scaleDown()
{
if (QApplication::keyboardModifiers() & Qt::ControlModifier)
{ {
if (!m_activeNode) if (!m_activeNode)
{ {
@ -412,11 +413,6 @@ void GraphWidget::zoomOut()
m_activeNode->setScale(qreal(1 / 1.2),sceneRect()); m_activeNode->setScale(qreal(1 / 1.2),sceneRect());
} }
} }
else // zoom out of the view
{
scaleView(qreal(1 / 1.2));
}
}
void GraphWidget::nodeColor() void GraphWidget::nodeColor()
{ {
@ -619,11 +615,16 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
case Qt::Key_Plus: case Qt::Key_Plus:
event->modifiers() & Qt::ControlModifier ?
scaleUp() :
zoomIn(); zoomIn();
break; break;
case Qt::Key_Minus: case Qt::Key_Minus:
event->modifiers() & Qt::ControlModifier ?
scaleDown() :
zoomOut(); zoomOut();
break; break;
@ -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 ?
(event->delta() > 0 ?
scaleUp() :
scaleDown()) :
(event->delta() > 0 ?
zoomIn() : zoomIn() :
zoomOut(); 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