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"
28 #include "panelcommon.h"
29 #include "zoombutton.h"
32 ZoomButtonPanel::ZoomButtonPanel(QWidget *parent)
39 qDebug() << __PRETTY_FUNCTION__;
41 m_zoomInButton = new ZoomButton(this, ":/res/images/zoom_in.png");
42 m_zoomOutButton = new ZoomButton(this, ":/res/images/zoom_out.png");
44 m_panelLayout.setMargin(0);
45 m_panelLayout.setSpacing(0);
46 m_panelLayout.setVerticalSpacing(ZOOM_BUTTON_PANEL_BUTTON_SPACING);
47 m_panelLayout.setSizeConstraint(QLayout::SetFixedSize);
49 m_panelLayout.addWidget(m_zoomInButton, 0, 0);
50 m_panelLayout.addWidget(m_zoomOutButton, 1, 0);
52 QSettings settings(DIRECTORY_NAME, FILE_NAME);
53 move(settings.value(ZOOMPANEL_POSITION,
54 QPoint(ZOOM_BUTTON_PANEL_POSITION_X,
55 ZOOM_BUTTON_PANEL_POSITION_Y)).toPoint());
57 QPalette pal = palette();
58 pal.setColor(QPalette::Background, QColor(0, 0, 0, 128));
61 m_dragStartTimer = new QTimer(this);
62 m_dragStartTimer->setSingleShot(true);
63 m_dragStartTimer->setInterval(DRAG_INIT_TIME);
65 m_forceReleaseTimer = new QTimer(this);
66 m_forceReleaseTimer->setSingleShot(true);
67 m_forceReleaseTimer->setInterval(FORCE_RELEASE_TIME);
69 connect(m_zoomInButton, SIGNAL(pressed()),
70 m_dragStartTimer, SLOT(start()));
71 connect(m_zoomInButton, SIGNAL(released()),
72 m_dragStartTimer, SLOT(stop()));
73 connect(m_zoomOutButton, SIGNAL(pressed()),
74 m_dragStartTimer, SLOT(start()));
75 connect(m_zoomOutButton, SIGNAL(released()),
76 m_dragStartTimer, SLOT(stop()));
78 connect(m_dragStartTimer, SIGNAL(timeout()),
79 this, SLOT(timerExpired()));
80 connect(m_forceReleaseTimer, SIGNAL(timeout()),
81 this, SLOT(forceMouseRelease()));
84 void ZoomButtonPanel::mouseMoveEvent(QMouseEvent *event)
86 qDebug() << __PRETTY_FUNCTION__;
89 if (event->buttons() & Qt::LeftButton) {
90 QPoint newLocation = mapToParent(event->pos()) - m_dragPosition;
92 if (newLocation.x() < SIDEBAR_WIDTH)
93 newLocation.rx() = SIDEBAR_WIDTH;
94 else if (newLocation.x() > m_screenSize.width() - width() - SIDEBAR_WIDTH)
95 newLocation.rx() = m_screenSize.width() - width() - SIDEBAR_WIDTH;
97 if (newLocation.y() < 0)
99 else if (newLocation.y() > m_screenSize.height() - height())
100 newLocation.ry() = m_screenSize.height() - height();
105 if(!rect().contains(event->pos()))
106 m_dragStartTimer->stop();
108 QWidget::mouseMoveEvent(event);
111 void ZoomButtonPanel::mousePressEvent(QMouseEvent *event)
113 qDebug() << __PRETTY_FUNCTION__;
115 if (event->button() == Qt::LeftButton) {
116 m_dragPosition = event->pos();
118 m_dragStartTimer->start();
119 QWidget::mousePressEvent(event);
122 void ZoomButtonPanel::mouseReleaseEvent(QMouseEvent *event)
124 qDebug() << __PRETTY_FUNCTION__;
126 m_dragStartTimer->stop();
131 QSettings settings(DIRECTORY_NAME, FILE_NAME);
132 settings.setValue(ZOOMPANEL_POSITION, pos());
134 m_zoomInButton->setDown(false);
135 m_zoomOutButton->setDown(false);
137 QWidget::mouseReleaseEvent(event);
140 const ZoomButton* ZoomButtonPanel::zoomInButton()
142 qDebug() << __PRETTY_FUNCTION__;
144 return m_zoomInButton;
147 const ZoomButton* ZoomButtonPanel::zoomOutButton()
149 qDebug() << __PRETTY_FUNCTION__;
151 return m_zoomOutButton;
154 void ZoomButtonPanel::disableZoomInButton()
156 qDebug() << __PRETTY_FUNCTION__;
158 m_zoomInButton->setMode(QIcon::Disabled);
161 void ZoomButtonPanel::disableZoomOutButton()
163 qDebug() << __PRETTY_FUNCTION__;
165 m_zoomOutButton->setMode(QIcon::Disabled);
168 void ZoomButtonPanel::resetButtons()
170 qDebug() << __PRETTY_FUNCTION__;
172 m_zoomInButton->setMode(QIcon::Normal);
173 m_zoomOutButton->setMode(QIcon::Normal);
176 void ZoomButtonPanel::setDraggable(bool mode, QPoint eventPosition)
178 qDebug() << __PRETTY_FUNCTION__;
180 m_isDraggable = mode;
183 setAutoFillBackground(true);
185 m_zoomInMode = m_zoomInButton->mode();
186 m_zoomOutMode = m_zoomOutButton->mode();
188 m_zoomInButton->setMode(QIcon::Disabled);
189 m_zoomOutButton->setMode(QIcon::Disabled);
191 m_forceReleaseTimer->start();
192 m_dragPosition = eventPosition;
194 setAutoFillBackground(false);
195 if(m_zoomInMode == QIcon::Selected)
196 m_zoomInButton->setMode(QIcon::Normal);
198 m_zoomInButton->setMode(m_zoomInMode);
199 if(m_zoomOutMode == QIcon::Selected)
200 m_zoomOutButton->setMode(QIcon::Normal);
202 m_zoomOutButton->setMode(m_zoomOutMode);
204 m_forceReleaseTimer->stop();
205 m_zoomInButton->setDown(false);
206 m_zoomOutButton->setDown(false);
210 void ZoomButtonPanel::screenResized(const QSize &newSize)
212 qDebug() << __PRETTY_FUNCTION__;
214 m_screenSize = newSize;
216 QPoint resizedPosition = pos();
217 if(resizedPosition.x() > (newSize.width() - rect().width()))
218 resizedPosition.rx() = newSize.width() - rect().width();
219 else if (resizedPosition.x() < SIDEBAR_WIDTH)
220 resizedPosition.rx() = SIDEBAR_WIDTH;
221 if(resizedPosition.y() > (newSize.height() - rect().height()))
222 resizedPosition.ry() = newSize.height() - rect().height();
223 else if (resizedPosition.y() < 0)
224 resizedPosition.ry() = 0;
225 move(resizedPosition);
228 void ZoomButtonPanel::forceMouseRelease()
230 qDebug() << __PRETTY_FUNCTION__;
236 void ZoomButtonPanel::timerExpired()
238 qDebug() << __PRETTY_FUNCTION__;
240 if(m_zoomInButton->isDown())
241 m_dragPosition = m_zoomInButton->eventPosition();
242 if(m_zoomOutButton->isDown())
243 m_dragPosition = m_zoomOutButton->eventPosition();
245 setDraggable(true, m_dragPosition);