2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Pekka Nissinen - pekka.nissinen@ixonos.com
6 Kaj Wallin - kaj.wallin@ixonos.com
8 Situare is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 version 2 as published by the Free Software Foundation.
12 Situare is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Situare; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
27 #include "zoombuttonpanel.h"
30 #include "panelcommon.h"
31 #include "zoombutton.h"
33 const int ROUNDING_RADIUS = 9; ///< Roundness of the background edges
35 ZoomButtonPanel::ZoomButtonPanel(QWidget *parent)
42 qDebug() << __PRETTY_FUNCTION__;
44 m_zoomInButton = new ZoomButton(this, ":/res/images/zoom_in.png");
45 m_zoomOutButton = new ZoomButton(this, ":/res/images/zoom_out.png");
47 m_panelLayout.setMargin(0);
48 m_panelLayout.setSpacing(0);
49 m_panelLayout.setVerticalSpacing(ZOOM_BUTTON_PANEL_BUTTON_SPACING);
50 m_panelLayout.setSizeConstraint(QLayout::SetFixedSize);
52 m_panelLayout.addWidget(m_zoomInButton, 0, 0);
53 m_panelLayout.addWidget(m_zoomOutButton, 1, 0);
55 QSettings settings(DIRECTORY_NAME, FILE_NAME);
56 QPoint savedLocation = settings.value(ZOOMPANEL_POSITION,
57 QPoint(ZOOM_BUTTON_PANEL_POSITION_X,
58 ZOOM_BUTTON_PANEL_POSITION_Y)).toPoint();
60 if(savedLocation.x() > DEFAULT_SCREEN_WIDTH || savedLocation.y() > DEFAULT_SCREEN_HEIGHT) {
61 savedLocation.rx() = ZOOM_BUTTON_PANEL_POSITION_X;
62 savedLocation.ry() = ZOOM_BUTTON_PANEL_POSITION_Y;
67 m_dragStartTimer = new QTimer(this);
68 m_dragStartTimer->setSingleShot(true);
69 m_dragStartTimer->setInterval(DRAG_INIT_TIME);
71 m_forceReleaseTimer = new QTimer(this);
72 m_forceReleaseTimer->setSingleShot(true);
73 m_forceReleaseTimer->setInterval(FORCE_RELEASE_TIME);
75 connect(m_zoomInButton, SIGNAL(pressed()),
76 m_dragStartTimer, SLOT(start()));
77 connect(m_zoomInButton, SIGNAL(released()),
78 m_dragStartTimer, SLOT(stop()));
79 connect(m_zoomOutButton, SIGNAL(pressed()),
80 m_dragStartTimer, SLOT(start()));
81 connect(m_zoomOutButton, SIGNAL(released()),
82 m_dragStartTimer, SLOT(stop()));
84 connect(m_dragStartTimer, SIGNAL(timeout()),
85 this, SLOT(timerExpired()));
86 connect(m_forceReleaseTimer, SIGNAL(timeout()),
87 this, SLOT(forceMouseRelease()));
90 void ZoomButtonPanel::mouseMoveEvent(QMouseEvent *event)
92 qDebug() << __PRETTY_FUNCTION__;
95 if (event->buttons() & Qt::LeftButton) {
96 QPoint newLocation = mapToParent(event->pos()) - m_dragPosition;
98 if (newLocation.x() < 0)
100 else if (newLocation.x() > m_screenSize.width() - width() - PANEL_BAR_WIDTH)
101 newLocation.rx() = m_screenSize.width() - width() - PANEL_BAR_WIDTH;
103 if (newLocation.y() < 0)
104 newLocation.ry() = 0;
105 else if (newLocation.y() > m_screenSize.height() - height())
106 newLocation.ry() = m_screenSize.height() - height();
111 if(!rect().contains(event->pos()))
112 m_dragStartTimer->stop();
116 void ZoomButtonPanel::mousePressEvent(QMouseEvent *event)
118 qDebug() << __PRETTY_FUNCTION__;
120 if (event->button() == Qt::LeftButton)
121 m_dragPosition = event->pos();
123 m_dragStartTimer->start();
126 void ZoomButtonPanel::mouseReleaseEvent(QMouseEvent *event)
128 qDebug() << __PRETTY_FUNCTION__;
130 m_dragStartTimer->stop();
136 QSettings settings(DIRECTORY_NAME, FILE_NAME);
137 settings.setValue(ZOOMPANEL_POSITION, pos());
141 m_zoomInButton->setDown(false);
142 m_zoomOutButton->setDown(false);
146 void ZoomButtonPanel::paintEvent(QPaintEvent *event)
148 qDebug() << __PRETTY_FUNCTION__;
152 QPainter painter(this);
155 QPainterPath backgroundPath;
156 backgroundPath.addRoundedRect(this->rect(), ROUNDING_RADIUS, ROUNDING_RADIUS);
157 painter.setRenderHint(QPainter::Antialiasing);
158 painter.fillPath(backgroundPath, QBrush(Qt::Dense4Pattern));
162 const ZoomButton* ZoomButtonPanel::zoomInButton()
164 qDebug() << __PRETTY_FUNCTION__;
166 return m_zoomInButton;
169 const ZoomButton* ZoomButtonPanel::zoomOutButton()
171 qDebug() << __PRETTY_FUNCTION__;
173 return m_zoomOutButton;
176 void ZoomButtonPanel::disableZoomInButton()
178 qDebug() << __PRETTY_FUNCTION__;
180 m_zoomInButton->setMode(QIcon::Disabled);
183 void ZoomButtonPanel::disableZoomOutButton()
185 qDebug() << __PRETTY_FUNCTION__;
187 m_zoomOutButton->setMode(QIcon::Disabled);
190 void ZoomButtonPanel::resetButtons()
192 qDebug() << __PRETTY_FUNCTION__;
194 m_zoomInButton->setMode(QIcon::Normal);
195 m_zoomOutButton->setMode(QIcon::Normal);
198 void ZoomButtonPanel::setDraggable(bool mode, QPoint eventPosition)
200 qDebug() << __PRETTY_FUNCTION__;
202 m_isDraggable = mode;
205 emit draggingModeTriggered();
207 m_zoomInMode = m_zoomInButton->mode();
208 m_zoomOutMode = m_zoomOutButton->mode();
209 m_zoomInButton->setMode(QIcon::Disabled);
210 m_zoomOutButton->setMode(QIcon::Disabled);
214 m_forceReleaseTimer->start();
215 m_dragPosition = eventPosition;
217 if(m_zoomInMode == QIcon::Selected)
218 m_zoomInButton->setMode(QIcon::Normal);
220 m_zoomInButton->setMode(m_zoomInMode);
222 if(m_zoomOutMode == QIcon::Selected)
223 m_zoomOutButton->setMode(QIcon::Normal);
225 m_zoomOutButton->setMode(m_zoomOutMode);
229 m_forceReleaseTimer->stop();
230 m_zoomInButton->setDown(false);
231 m_zoomOutButton->setDown(false);
236 void ZoomButtonPanel::screenResized(const QSize &newSize)
238 qDebug() << __PRETTY_FUNCTION__;
243 if(m_screenSize.height() < 0)
244 oldHeight = DEFAULT_NON_FULLSCREEN_HEIGHT;
246 oldHeight = m_screenSize.height();
248 if(m_screenSize.width() < 0)
249 oldWidth = DEFAULT_SCREEN_WIDTH;
251 oldWidth = m_screenSize.width();
253 m_screenSize = newSize;
255 QPoint resizedPosition = pos();
257 if(resizedPosition.x() < 0)
258 resizedPosition.rx() = 0;
259 else if(resizedPosition.x() > (newSize.width() - rect().width()))
260 resizedPosition.rx() = newSize.width() - rect().width();
262 if(resizedPosition.y() < 0)
263 resizedPosition.ry() = 0;
264 else if(resizedPosition.y() > (newSize.height() - rect().height()))
265 resizedPosition.ry() = newSize.height() - rect().height();
267 if((pos().y() + rect().center().y()) > (oldHeight / 2))
268 resizedPosition.ry() = newSize.height() - (oldHeight - pos().y());
270 if((pos().x() + rect().center().x()) > (oldWidth / 2))
271 resizedPosition.rx() = newSize.width() - (oldWidth - pos().x());
273 move(resizedPosition);
276 void ZoomButtonPanel::forceMouseRelease()
278 qDebug() << __PRETTY_FUNCTION__;
284 void ZoomButtonPanel::timerExpired()
286 qDebug() << __PRETTY_FUNCTION__;
288 if(m_zoomInButton->isDown())
289 m_dragPosition = m_zoomInButton->eventPosition();
291 if(m_zoomOutButton->isDown())
292 m_dragPosition = m_zoomOutButton->eventPosition();
294 setDraggable(true, m_dragPosition);