Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
zoomButton.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50 //== INCLUDES =================================================================
51 #include <QPixmap>
52 #include <QGraphicsItem>
53 #include <QGraphicsSceneMouseEvent>
54
55 #include <OpenFlipper/common/GlobalOptions.hh>
56
57 #include "zoomButton.hh"
58 #include "graphicsScene.hh"
59
60 //== NAMESPACES ===============================================================
61 namespace VSI {
62
63 //=============================================================================
64 //
65 // CLASS VSI::ZoomButton - IMPLEMENTATION
66 //
67 //=============================================================================
68
70 ZoomButton::ZoomButton (GraphicsScene *_scene, QGraphicsItem *_parent, Type _type) :
71 QGraphicsPixmapItem (_parent),
72 scene_ (_scene),
73 type_ (_type)
74 {
75
76 // Load icon depending on type
77 switch (type_)
78 {
79 case In:
80 setPixmap (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"zoom-in.png");
81 break;
82 case Out:
83 setPixmap (OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"zoom-out.png");
84 break;
85 }
86
87 setOpacity (0.4);
88
89 setAcceptHoverEvents (true);
90
91 connect (&timer_, SIGNAL (timeout ()), this, SLOT (timeout ()));
92 }
93
94 //------------------------------------------------------------------------------
95
97 ZoomButton::~ZoomButton ()
98 {
99 }
100
101 //------------------------------------------------------------------------------
102
103 // make the widget opaque if the mouse is over it
104 void ZoomButton::hoverEnterEvent (QGraphicsSceneHoverEvent * /*_event*/)
105 {
106 setOpacity (1.0);
107 }
108
109 //------------------------------------------------------------------------------
110
111 // make the widget transparent if the mouse leaves it
112 void ZoomButton::hoverLeaveEvent (QGraphicsSceneHoverEvent * /*_event*/)
113 {
114 setOpacity (0.4);
115 }
116
117 //------------------------------------------------------------------------------
118
119 // zoom the scene on mouse press
120 void ZoomButton::mousePressEvent (QGraphicsSceneMouseEvent *_event)
121 {
122 _event->accept ();
123
124 switch (type_)
125 {
126 case In:
127 scene_->scaleElements (1.25);
128 break;
129 case Out:
130 scene_->scaleElements (0.8);
131 break;
132 }
133
134 QRectF rect = scene_->sceneRect ();
135 pos_ = QPointF (rect.x () + (rect.width () / 2.0), rect.y () + (rect.height () / 2.0));
136
137 // start timer for zooming during the mouse is pressed
138 timer_.start (500);
139 }
140
141 //------------------------------------------------------------------------------
142
143 // stop zooming on release
144 void ZoomButton::mouseReleaseEvent (QGraphicsSceneMouseEvent *_event)
145 {
146 _event->accept ();
147 timer_.stop ();
148 }
149
150 //------------------------------------------------------------------------------
151
152 // zoom on mouse wheel
153 void ZoomButton::wheelEvent (QGraphicsSceneWheelEvent *_event)
154 {
155 _event->accept ();
156
157 qreal delta;
158
159 if (_event->delta () > 0)
160 delta = 1.25;
161 else
162 delta = 0.8;
163
164 scene_->scaleElements (delta);
165 }
166
167 //------------------------------------------------------------------------------
168
169 // zoom the scene on timeout
170 void ZoomButton::timeout ()
171 {
172 switch (type_)
173 {
174 case In:
175 scene_->scaleElements (1.25, pos_);
176 break;
177 case Out:
178 scene_->scaleElements (0.8, pos_);
179 break;
180 }
181 }
182
183 //------------------------------------------------------------------------------
184
186 void ZoomButton::activate (QPointF _pos)
187 {
188 pos_ = _pos;
189 setOpacity (1.0);
190 if (!timer_.isActive ())
191 timer_.start (500);
192 }
193
194 //------------------------------------------------------------------------------
195
197 void ZoomButton::deactivate ()
198 {
199 setOpacity (0.4);
200 timer_.stop ();
201 }
202
203 //------------------------------------------------------------------------------
204
206 void ZoomButton::setGeometry (const QRectF &_rect)
207 {
208 QGraphicsPixmapItem::setPos (_rect.topLeft ());
209 QGraphicsLayoutItem::setGeometry (_rect);
210 }
211
212 //------------------------------------------------------------------------------
213
214 // size information for layouting
215 QSizeF ZoomButton::sizeHint (Qt::SizeHint _which, const QSizeF &/*_constraint*/) const
216 {
217 QSizeF sh;
218 switch (_which) {
219 case Qt::MinimumSize:
220 case Qt::PreferredSize:
221 case Qt::MaximumSize:
222 sh = QSizeF (pixmap ().width (), pixmap ().height ());
223 break;
224 default:
225 break;
226 }
227
228 return sh;
229 }
230
231 //------------------------------------------------------------------------------
232 }
VSI
Definition: baseWidget.cc:78
VSI::ZoomButton::setGeometry
virtual void setGeometry(const QRectF &_rect)
Sets the geometry.
Definition: zoomButton.cc:206
VSI::GraphicsScene::scaleElements
void scaleElements(qreal _delta)
Scale all elements with scaling center in the center of the scene.
Definition: graphicsScene.cc:286
VSI::ZoomButton::deactivate
void deactivate()
Stop the timer.
Definition: zoomButton.cc:197
VSI::ZoomButton::~ZoomButton
~ZoomButton()
Destructor.
Definition: zoomButton.cc:97
VSI::ZoomButton::activate
void activate(QPointF _pos)
Activates the timer for zoom with center at _pos (will be called if an element is moved above) ...
Definition: zoomButton.cc:186
VSI::GraphicsScene
Definition: graphicsScene.hh:86
GlobalOptions.hh
VSI::ZoomButton::Type
Type
Zoom type.
Definition: zoomButton.hh:74
VSI::ZoomButton::ZoomButton
ZoomButton(GraphicsScene *_scene, QGraphicsItem *_parent, Type _type)
Constructor.
Definition: zoomButton.cc:70