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, int x, int y)
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_zoomInButton->setObjectName("ZoomInButton");
45 m_zoomOutButton->setObjectName("ZoomOutButton");
46 m_panelLayout.setMargin(0);
47 m_panelLayout.setSpacing(0);
48 m_panelLayout.setVerticalSpacing(ZOOM_BUTTON_PANEL_BUTTON_SPACING);
49 m_panelLayout.setSizeConstraint(QLayout::SetFixedSize);
51 m_panelLayout.addWidget(m_zoomInButton, 0, 0);
52 m_panelLayout.addWidget(m_zoomOutButton, 1, 0);
56 QPalette pal = palette();
57 pal.setColor(QPalette::Background, QColor(0, 0, 0, 128));
60 m_eventBlocker = new QWidget(this);
61 m_eventBlocker->setAttribute(Qt::WA_TransparentForMouseEvents, true);
62 m_eventBlocker->resize(size().width(),
63 m_zoomInButton->size().height() * 2 + ZOOM_BUTTON_PANEL_BUTTON_SPACING);
65 m_dragStartTimer = new QTimer(this);
66 m_dragStartTimer->setSingleShot(true);
67 m_dragStartTimer->setInterval(DRAG_INIT_TIME);
69 connect(m_zoomInButton, SIGNAL(pressEvent()),
70 m_dragStartTimer, SLOT(start()));
71 connect(m_zoomInButton, SIGNAL(releaseEvent()),
72 m_dragStartTimer, SLOT(stop()));
73 connect(m_zoomOutButton, SIGNAL(pressEvent()),
74 m_dragStartTimer, SLOT(start()));
75 connect(m_zoomOutButton, SIGNAL(releaseEvent()),
76 m_dragStartTimer, SLOT(stop()));
78 connect(m_zoomInButton, SIGNAL(eventPosition(QPoint)),
79 this, SLOT(setDragPosition(QPoint)));
80 connect(m_zoomOutButton, SIGNAL(eventPosition(QPoint)),
81 this, SLOT(setDragPosition(QPoint)));
83 connect(m_dragStartTimer, SIGNAL(timeout()),
84 this, SLOT(timerExpired()));
88 void ZoomButtonPanel::mouseMoveEvent(QMouseEvent *event)
90 qDebug() << __PRETTY_FUNCTION__;
93 if (event->buttons() & Qt::LeftButton) {
94 QPoint newLocation = mapToParent(event->pos()) - m_dragPosition;
96 if (newLocation.x() < SIDEBAR_WIDTH)
97 newLocation.rx() = SIDEBAR_WIDTH;
98 else if (newLocation.x() > m_screenSize.width() - m_eventBlocker->width())
99 newLocation.rx() = m_screenSize.width() - m_eventBlocker->width();
101 if (newLocation.y() < 0)
102 newLocation.ry() = 0;
103 else if (newLocation.y() > m_screenSize.height() - m_eventBlocker->height())
104 newLocation.ry() = m_screenSize.height() - m_eventBlocker->height();
111 m_dragPosition = event->pos();
116 void ZoomButtonPanel::mousePressEvent(QMouseEvent *event)
118 qDebug() << __PRETTY_FUNCTION__;
120 if (event->button() == Qt::LeftButton) {
121 m_dragPosition = event->pos();
124 m_dragStartTimer->start();
127 void ZoomButtonPanel::mouseReleaseEvent(QMouseEvent *event)
131 QSettings settings(DIRECTORY_NAME, FILE_NAME);
132 settings.setValue(ZOOMPANEL_POSITION, pos());
134 m_dragStartTimer->stop();
137 const ImageButton* ZoomButtonPanel::zoomInButton()
139 qDebug() << __PRETTY_FUNCTION__;
141 return m_zoomInButton;
144 const ImageButton* ZoomButtonPanel::zoomOutButton()
146 qDebug() << __PRETTY_FUNCTION__;
148 return m_zoomOutButton;
151 void ZoomButtonPanel::disableZoomInButton()
153 qDebug() << __PRETTY_FUNCTION__;
155 m_zoomInButton->setMode(QIcon::Disabled);
158 void ZoomButtonPanel::disableZoomOutButton()
160 qDebug() << __PRETTY_FUNCTION__;
162 m_zoomOutButton->setMode(QIcon::Disabled);
165 void ZoomButtonPanel::resetButtons()
167 qDebug() << __PRETTY_FUNCTION__;
169 m_zoomInButton->setMode(QIcon::Normal);
170 m_zoomOutButton->setMode(QIcon::Normal);
173 void ZoomButtonPanel::setDraggable(bool mode, QPoint eventPosition)
176 m_eventBlocker->setAttribute(Qt::WA_TransparentForMouseEvents, false);
177 m_isDraggable = mode;
178 setAutoFillBackground(true);
180 m_zoomInMode = m_zoomInButton->mode();
181 m_zoomOutMode = m_zoomOutButton->mode();
183 m_zoomInButton->setMode(QIcon::Disabled);
184 m_zoomOutButton->setMode(QIcon::Disabled);
186 m_dragPosition = eventPosition;
189 m_eventBlocker->setAttribute(Qt::WA_TransparentForMouseEvents, true);
190 m_isDraggable = mode;
191 setAutoFillBackground(false);
192 if(m_zoomInMode == QIcon::Selected)
193 m_zoomInButton->setMode(QIcon::Normal);
195 m_zoomInButton->setMode(m_zoomInMode);
196 if(m_zoomOutMode == QIcon::Selected)
197 m_zoomOutButton->setMode(QIcon::Normal);
199 m_zoomOutButton->setMode(m_zoomOutMode);
201 m_zoomInButton->setDown(false);
202 m_zoomOutButton->setDown(false);
206 void ZoomButtonPanel::screenResized(const QSize &size)
211 void ZoomButtonPanel::setDragPosition(QPoint eventPosition)
213 m_dragPosition = eventPosition;
216 void ZoomButtonPanel::timerExpired()
218 setDraggable(true, m_dragPosition);