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_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);
54 QPalette pal = palette();
55 pal.setColor(QPalette::Background, QColor(0, 0, 0, 128));
58 m_eventBlocker = new QWidget(this);
59 m_eventBlocker->setAttribute(Qt::WA_TransparentForMouseEvents, true);
60 m_eventBlocker->resize(size().width(),
61 m_zoomInButton->size().height() * 2 + ZOOM_BUTTON_PANEL_BUTTON_SPACING);
63 connect(m_zoomInButton, SIGNAL(startDragMode(bool, QPoint)),
64 this, SLOT(setDraggable(bool, QPoint)));
65 connect(m_zoomOutButton, SIGNAL(startDragMode(bool, QPoint)),
66 this, SLOT(setDraggable(bool, QPoint)));
68 m_dragStartTimer = new QTimer(this);
69 m_dragStartTimer->setSingleShot(true);
70 connect(m_dragStartTimer, SIGNAL(timeout()),
71 this, SLOT(timerExpired()));
74 void ZoomButtonPanel::mouseMoveEvent(QMouseEvent *event)
76 qDebug() << __PRETTY_FUNCTION__;
79 if (event->buttons() & Qt::LeftButton) {
80 QPoint newLocation = mapToParent(event->pos()) - m_dragPosition;
81 if (newLocation.x() < SIDEBAR_WIDTH) {
82 newLocation.rx() = SIDEBAR_WIDTH;
84 else if (newLocation.x() > m_screenSize.width()
85 - m_eventBlocker->width()){
86 newLocation.rx() = m_screenSize.width() - m_eventBlocker->width();
88 if (newLocation.y() < 0){
91 else if (newLocation.y() > m_screenSize.height() - m_eventBlocker->height()) {
92 newLocation.ry() = m_screenSize.height() - m_eventBlocker->height();
100 void ZoomButtonPanel::mousePressEvent(QMouseEvent *event)
102 qDebug() << __PRETTY_FUNCTION__;
104 if (event->button() == Qt::LeftButton) {
105 m_dragPosition = event->pos();
108 m_dragStartTimer->start(DRAG_INIT_TIME);
111 void ZoomButtonPanel::mouseReleaseEvent(QMouseEvent *event)
115 QSettings settings(DIRECTORY_NAME, FILE_NAME);
116 settings.setValue(ZOOMPANEL_POSITION, pos());
120 const ImageButton* ZoomButtonPanel::zoomInButton()
122 qDebug() << __PRETTY_FUNCTION__;
124 return m_zoomInButton;
127 const ImageButton* ZoomButtonPanel::zoomOutButton()
129 qDebug() << __PRETTY_FUNCTION__;
131 return m_zoomOutButton;
134 void ZoomButtonPanel::disableZoomInButton()
136 qDebug() << __PRETTY_FUNCTION__;
138 m_zoomInButton->setMode(QIcon::Disabled);
141 void ZoomButtonPanel::disableZoomOutButton()
143 qDebug() << __PRETTY_FUNCTION__;
145 m_zoomOutButton->setMode(QIcon::Disabled);
148 void ZoomButtonPanel::resetButtons()
150 qDebug() << __PRETTY_FUNCTION__;
152 m_zoomInButton->setMode(QIcon::Normal);
153 m_zoomOutButton->setMode(QIcon::Normal);
156 void ZoomButtonPanel::setDraggable(bool mode, QPoint eventPosition)
159 m_eventBlocker->setAttribute(Qt::WA_TransparentForMouseEvents, false);
160 m_isDraggable = mode;
161 setAutoFillBackground(true);
162 m_zoomInMode = m_zoomInButton->mode();
163 m_zoomOutMode = m_zoomOutButton->mode();
164 m_zoomInButton->setMode(QIcon::Disabled);
165 m_zoomOutButton->setMode(QIcon::Disabled);
167 m_dragPosition = eventPosition;
170 m_eventBlocker->setAttribute(Qt::WA_TransparentForMouseEvents, true);
171 m_isDraggable = mode;
172 setAutoFillBackground(false);
173 m_zoomInButton->setMode(m_zoomInMode);
174 m_zoomOutButton->setMode(m_zoomOutMode);
179 void ZoomButtonPanel::screenResized(const QSize &size)
184 void ZoomButtonPanel::timerExpired()
186 setDraggable(true, m_dragPosition);