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,
24 #include <QMouseEvent>
28 #include "zoombuttonpanel.h"
31 #include "panelcommon.h"
32 #include "zoombutton.h"
34 const int ROUNDING_RADIUS = 9; ///< Roundness of the background edges
36 ZoomButtonPanel::ZoomButtonPanel(QWidget *parent)
43 qDebug() << __PRETTY_FUNCTION__;
45 m_zoomInButton = new ZoomButton(":/res/images/zoom_in.png", this);
46 m_zoomOutButton = new ZoomButton(":/res/images/zoom_out.png", this);
48 m_panelLayout.setMargin(0);
49 m_panelLayout.setSpacing(0);
50 m_panelLayout.setVerticalSpacing(ZOOM_BUTTON_PANEL_BUTTON_SPACING);
51 m_panelLayout.setSizeConstraint(QLayout::SetFixedSize);
53 m_panelLayout.addWidget(m_zoomInButton, 0, 0);
54 m_panelLayout.addWidget(m_zoomOutButton, 1, 0);
56 QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
57 QPoint savedLocation = settings.value(ZOOMPANEL_POSITION,
58 QPoint(ZOOM_BUTTON_PANEL_POSITION_X,
59 ZOOM_BUTTON_PANEL_POSITION_Y)).toPoint();
61 if(savedLocation.x() > DEFAULT_SCREEN_WIDTH || savedLocation.y() > DEFAULT_SCREEN_HEIGHT) {
62 savedLocation.rx() = ZOOM_BUTTON_PANEL_POSITION_X;
63 savedLocation.ry() = ZOOM_BUTTON_PANEL_POSITION_Y;
68 m_dragStartTimer = new QTimer(this);
69 m_dragStartTimer->setSingleShot(true);
70 m_dragStartTimer->setInterval(DRAG_INIT_TIME);
72 m_forceReleaseTimer = new QTimer(this);
73 m_forceReleaseTimer->setSingleShot(true);
74 m_forceReleaseTimer->setInterval(FORCE_RELEASE_TIME);
76 connect(m_zoomInButton, SIGNAL(pressed()),
77 m_dragStartTimer, SLOT(start()));
78 connect(m_zoomInButton, SIGNAL(released()),
79 m_dragStartTimer, SLOT(stop()));
80 connect(m_zoomOutButton, SIGNAL(pressed()),
81 m_dragStartTimer, SLOT(start()));
82 connect(m_zoomOutButton, SIGNAL(released()),
83 m_dragStartTimer, SLOT(stop()));
85 connect(m_dragStartTimer, SIGNAL(timeout()),
86 this, SLOT(timerExpired()));
87 connect(m_forceReleaseTimer, SIGNAL(timeout()),
88 this, SLOT(forceMouseRelease()));
91 void ZoomButtonPanel::mouseMoveEvent(QMouseEvent *event)
93 qDebug() << __PRETTY_FUNCTION__;
96 if (event->buttons() & Qt::LeftButton) {
97 QPoint newLocation = mapToParent(event->pos()) - m_dragPosition;
99 if (newLocation.x() < 0)
100 newLocation.rx() = 0;
101 else if (newLocation.x() > m_screenSize.width() - width() - PANEL_BAR_WIDTH)
102 newLocation.rx() = m_screenSize.width() - width() - PANEL_BAR_WIDTH;
104 if (newLocation.y() < 0)
105 newLocation.ry() = 0;
106 else if (newLocation.y() > m_screenSize.height() - height())
107 newLocation.ry() = m_screenSize.height() - height();
112 if(!rect().contains(event->pos()))
113 m_dragStartTimer->stop();
117 void ZoomButtonPanel::mousePressEvent(QMouseEvent *event)
119 qDebug() << __PRETTY_FUNCTION__;
121 if (event->button() == Qt::LeftButton)
122 m_dragPosition = event->pos();
124 m_dragStartTimer->start();
127 void ZoomButtonPanel::mouseReleaseEvent(QMouseEvent *event)
129 qDebug() << __PRETTY_FUNCTION__;
131 m_dragStartTimer->stop();
137 QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
138 settings.setValue(ZOOMPANEL_POSITION, pos());
142 m_zoomInButton->setDown(false);
143 m_zoomOutButton->setDown(false);
147 void ZoomButtonPanel::paintEvent(QPaintEvent *event)
149 qDebug() << __PRETTY_FUNCTION__;
153 QPainter painter(this);
156 QPainterPath backgroundPath;
157 backgroundPath.addRoundedRect(this->rect(), ROUNDING_RADIUS, ROUNDING_RADIUS);
158 painter.setRenderHint(QPainter::Antialiasing);
159 painter.fillPath(backgroundPath, QBrush(Qt::Dense4Pattern));
163 const ZoomButton* ZoomButtonPanel::zoomInButton() const
165 qDebug() << __PRETTY_FUNCTION__;
167 return m_zoomInButton;
170 const ZoomButton* ZoomButtonPanel::zoomOutButton() const
172 qDebug() << __PRETTY_FUNCTION__;
174 return m_zoomOutButton;
177 void ZoomButtonPanel::disableZoomInButton()
179 qDebug() << __PRETTY_FUNCTION__;
181 m_zoomInButton->setEnabled(false);
184 void ZoomButtonPanel::disableZoomOutButton()
186 qDebug() << __PRETTY_FUNCTION__;
188 m_zoomOutButton->setEnabled(false);
191 void ZoomButtonPanel::resetButtons()
193 qDebug() << __PRETTY_FUNCTION__;
195 m_zoomInButton->setEnabled(true);
196 m_zoomOutButton->setEnabled(true);
199 void ZoomButtonPanel::setDraggable(bool mode, QPoint eventPosition)
201 qDebug() << __PRETTY_FUNCTION__;
203 m_isDraggable = mode;
206 emit draggingModeTriggered();
208 m_zoomInMode = m_zoomInButton->isEnabled();
209 m_zoomOutMode = m_zoomOutButton->isEnabled();
211 m_zoomInButton->setEnabled(false);
212 m_zoomOutButton->setEnabled(false);
216 m_forceReleaseTimer->start();
217 m_dragPosition = eventPosition;
219 m_zoomInButton->setEnabled(m_zoomInMode);
220 m_zoomOutButton->setEnabled(m_zoomOutMode);
224 m_forceReleaseTimer->stop();
226 m_zoomInButton->setDown(false);
227 m_zoomOutButton->setDown(false);
232 void ZoomButtonPanel::screenResized(const QSize &newSize)
234 qDebug() << __PRETTY_FUNCTION__;
239 if(m_screenSize.height() < 0)
240 oldHeight = DEFAULT_NON_FULLSCREEN_HEIGHT;
242 oldHeight = m_screenSize.height();
244 if(m_screenSize.width() < 0)
245 oldWidth = DEFAULT_SCREEN_WIDTH;
247 oldWidth = m_screenSize.width();
249 m_screenSize = newSize;
251 QPoint resizedPosition = pos();
253 if(resizedPosition.x() < 0)
254 resizedPosition.rx() = 0;
255 else if(resizedPosition.x() > (newSize.width() - rect().width()))
256 resizedPosition.rx() = newSize.width() - rect().width();
258 if(resizedPosition.y() < 0)
259 resizedPosition.ry() = 0;
260 else if(resizedPosition.y() > (newSize.height() - rect().height()))
261 resizedPosition.ry() = newSize.height() - rect().height();
263 if((pos().y() + rect().center().y()) > (oldHeight / 2))
264 resizedPosition.ry() = newSize.height() - (oldHeight - pos().y());
266 if((pos().x() + rect().center().x()) > (oldWidth / 2))
267 resizedPosition.rx() = newSize.width() - (oldWidth - pos().x());
269 move(resizedPosition);
272 void ZoomButtonPanel::forceMouseRelease()
274 qDebug() << __PRETTY_FUNCTION__;
280 void ZoomButtonPanel::timerExpired()
282 qDebug() << __PRETTY_FUNCTION__;
284 if(m_zoomInButton->isDown())
285 m_dragPosition = m_zoomInButton->eventPosition();
287 if(m_zoomOutButton->isDown())
288 m_dragPosition = m_zoomOutButton->eventPosition();
290 setDraggable(true, m_dragPosition);