• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

rocs/VisualEditor

  • sources
  • kde-4.14
  • kdeedu
  • rocs
  • VisualEditor
  • Actions
ZoomAction.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2011 Tomaz Canabrava <tomaz.canabrava@gmail.com>
4  Copyright 2012 Andreas Cord-Landwehr <cola@uni-paderborn.de>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 
22 #include "ZoomAction.h"
23 #include <Scene/GraphScene.h>
24 #include <GraphVisualEditor.h>
25 #include <DocumentManager.h>
26 #include <Document.h>
27 #include <QGraphicsRectItem>
28 #include <QGraphicsView>
29 #include <QDebug>
30 #include <KLocale>
31 #include <QGraphicsSceneWheelEvent>
32 #include <QKeyEvent>
33 
34 ZoomAction::ZoomAction(GraphScene* scene, QObject* parent)
35  : AbstractAction(scene, parent)
36  , _scene(scene)
37  , m_zoomRectItem(0)
38 {
39  setText(i18nc("@action:intoolbar", "Zoom"));
40  setToolTip(i18nc("@info:tooltip", "Zoom the canvas by the wheel, or by dragging."));
41  setIcon(KIcon("page-zoom"));
42  _name = "zoom";
43 }
44 
45 bool ZoomAction::executePress(QPointF pos)
46 {
47  delete m_zoomRectItem;
48  QGraphicsView *view = _scene->views().at(0);
49 
50  m_zoomRectItem = new QGraphicsRectItem(0, 0, 0, 0);
51  QColor color(Qt::green);
52  color.setAlphaF(0.3);
53  m_zoomRectItem->setBrush(QBrush(color));
54  m_zoomRectItem->setPen(QPen(QBrush(Qt::black), 0.1, Qt::SolidLine));
55  m_zoomRectItem->setZValue(9);
56  m_beginZoom = view->mapFromScene(pos);
57 
58  _graphScene->addItem(m_zoomRectItem);
59  return true;
60 }
61 
62 bool ZoomAction::executeMove(QPointF pos)
63 {
64  QGraphicsView *view = _scene->views().at(0);
65  if (!m_zoomRectItem) {
66  return false;
67  }
68 
69  QPoint movePos = view->mapFromScene(pos);
70  qreal left = (m_beginZoom.x() < movePos.x()) ? m_beginZoom.x() : movePos.x();
71  qreal top = (m_beginZoom.y() < movePos.y()) ? m_beginZoom.y() : movePos.y();
72  qreal bottom = (m_beginZoom.y() > movePos.y()) ? m_beginZoom.y() : movePos.y();
73  qreal right = (m_beginZoom.x() > movePos.x()) ? m_beginZoom.x() : movePos.x();
74 
75  QPointF topLeft(view->mapToScene(left, top));
76  QPointF bottomRight(view->mapToScene(right, bottom));
77 
78  m_zoomRectItem->setRect(QRectF(topLeft, bottomRight));
79 
80  return true;
81 }
82 
83 bool ZoomAction::executeRelease(QPointF)
84 {
85  if (!m_zoomRectItem) {
86  return false;
87  }
88  _scene->zoomToRect(m_zoomRectItem->rect());
89  delete m_zoomRectItem;
90  m_zoomRectItem = 0;
91  return true;
92 }
93 
94 bool ZoomAction::executeDoubleClick(QPointF)
95 {
96  zoomReset();
97  return true;
98 }
99 
100 bool ZoomAction::executeKeyRelease(QKeyEvent* keyEvent)
101 {
102  switch (keyEvent->key()) {
103  case Qt::Key_Plus : {
104  _scene->zoomBy(1.25);
105  break;
106  }
107  case Qt::Key_Minus : {
108  _scene->zoomBy(0.8);
109  break;
110  }
111  case Qt::Key_5 : {
112  _scene->resetZoom();
113  break;
114  }
115  }
116  keyEvent->accept();
117  return true;
118 }
119 
120 bool ZoomAction::executeWheelEvent(QGraphicsSceneWheelEvent* wEvent)
121 {
122  if (wEvent->delta() < 0) { // zoom out
123  zoomOut(wEvent->scenePos());
124  } else { // zoom in
125  zoomIn(wEvent->scenePos());
126  }
127  wEvent->accept();
128  return true;
129 }
130 
131 void ZoomAction::zoomInCenter()
132 {
133  _scene->zoomBy(1.25);
134 }
135 
136 void ZoomAction::zoomIn(QPointF zoomCenter)
137 {
138  zoomInCenter();
139  _scene->centerOn(zoomCenter);
140 }
141 
142 void ZoomAction::zoomOutCenter()
143 {
144  _scene->zoomBy(0.8);
145 
146 }
147 
148 void ZoomAction::zoomOut(QPointF zoomCenter)
149 {
150  zoomOutCenter();
151  _scene->centerOn(zoomCenter);
152 }
153 
154 void ZoomAction::zoomReset()
155 {
156  _scene->resetZoom();
157 }
GraphScene::centerOn
void centerOn(const QPointF &pos)
Definition: GraphScene.cpp:331
ZoomAction::zoomIn
void zoomIn(QPointF zoomCenter)
Definition: ZoomAction.cpp:136
ZoomAction::executePress
bool executePress(QPointF pos)
Definition: ZoomAction.cpp:45
QGraphicsSceneWheelEvent
QGraphicsView::mapToScene
QPointF mapToScene(const QPoint &point) const
GraphScene::zoomToRect
void zoomToRect(const QRectF &rect)
Definition: GraphScene.cpp:318
QBrush
QPoint
GraphScene.h
QPoint::x
int x() const
QPoint::y
int y() const
ZoomAction::zoomInCenter
void zoomInCenter()
Definition: ZoomAction.cpp:131
QGraphicsRectItem::setRect
void setRect(const QRectF &rectangle)
AbstractAction
the base class for custom actions. This class provides the basic functionality for all custom actions...
Definition: AbstractAction.h:36
QPointF
GraphVisualEditor.h
QPointF::x
qreal x() const
QPointF::y
qreal y() const
ZoomAction::executeKeyRelease
bool executeKeyRelease(QKeyEvent *keyEvent)
Definition: ZoomAction.cpp:100
GraphScene::resetZoom
void resetZoom()
Definition: GraphScene.cpp:326
GraphScene
Definition: GraphScene.h:38
QObject
ZoomAction::zoomReset
void zoomReset()
Definition: ZoomAction.cpp:154
AbstractAction::_name
QString _name
Definition: AbstractAction.h:90
QGraphicsScene::views
QList< QGraphicsView * > views() const
QGraphicsView::mapFromScene
QPoint mapFromScene(const QPointF &point) const
QColor
ZoomAction.h
QKeyEvent::key
int key() const
QEvent::accept
void accept()
ZoomAction::executeMove
bool executeMove(QPointF pos)
Definition: ZoomAction.cpp:62
QKeyEvent
QAbstractGraphicsShapeItem::setPen
void setPen(const QPen &pen)
QGraphicsRectItem
GraphScene::zoomBy
void zoomBy(qreal scaleFactor)
Definition: GraphScene.cpp:297
AbstractAction::_graphScene
GraphScene * _graphScene
Definition: AbstractAction.h:88
QRectF
QPen
ZoomAction::executeDoubleClick
bool executeDoubleClick(QPointF pos)
Definition: ZoomAction.cpp:94
QColor::setAlphaF
void setAlphaF(qreal alpha)
ZoomAction::executeWheelEvent
bool executeWheelEvent(QGraphicsSceneWheelEvent *wEvent)
Definition: ZoomAction.cpp:120
ZoomAction::zoomOut
void zoomOut(QPointF zoomCenter)
Definition: ZoomAction.cpp:148
QAbstractGraphicsShapeItem::setBrush
void setBrush(const QBrush &brush)
QGraphicsSceneWheelEvent::scenePos
QPointF scenePos() const
QGraphicsScene::addItem
void addItem(QGraphicsItem *item)
QGraphicsSceneWheelEvent::delta
int delta() const
ZoomAction::executeRelease
bool executeRelease(QPointF pos)
Definition: ZoomAction.cpp:83
ZoomAction::ZoomAction
ZoomAction(GraphScene *scene, QObject *parent)
Definition: ZoomAction.cpp:34
QGraphicsItem::setZValue
void setZValue(qreal z)
QGraphicsView
ZoomAction::zoomOutCenter
void zoomOutCenter()
Definition: ZoomAction.cpp:142
QGraphicsRectItem::rect
QRectF rect() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:16:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

rocs/VisualEditor

Skip menu "rocs/VisualEditor"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal