Merged with latest master
[situare] / src / ui / zoombuttonpanel.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Pekka Nissinen - pekka.nissinen@ixonos.com
6
7    Situare is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License
9    version 2 as published by the Free Software Foundation.
10
11    Situare is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with Situare; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19    USA.
20 */
21
22 #include <QDebug>
23 #include <QPainter>
24
25 #include "zoombuttonpanel.h"
26 #include "panelcommon.h"
27
28 ZoomButtonPanel::ZoomButtonPanel(QWidget *parent, int x, int y)
29     : QWidget(parent),
30       m_zoomInButton(0),
31       m_zoomOutButton(0),
32       m_panelLayout(this),
33       m_x(x),
34       m_y(y)
35 {
36     qDebug() << __PRETTY_FUNCTION__;
37
38     m_zoomInButton = new ImageButton(this, ":/res/images/zoom_in.png");
39     m_zoomOutButton = new ImageButton(this, ":/res/images/zoom_out.png");
40
41     m_panelLayout.setMargin(0);
42     m_panelLayout.setSpacing(0);
43     m_panelLayout.setVerticalSpacing(ZOOM_BUTTON_PANEL_BUTTON_SPACING);
44     m_panelLayout.setSizeConstraint(QLayout::SetFixedSize);
45
46     m_panelLayout.addWidget(m_zoomInButton, 0, 0);
47     m_panelLayout.addWidget(m_zoomOutButton, 1, 0);
48
49     move(m_x, m_y);
50
51     QPalette pal = palette();
52     pal.setColor(QPalette::Background, QColor(0, 0, 0, 128));
53     setPalette(pal);
54 }
55
56 // BUG: long mouse press before dragging causes panel to not be centered
57 // on the cursor. Cause: Long press does not appear to be mousePressEvent o_O
58 void ZoomButtonPanel::mousePressEvent(QMouseEvent *event)
59 {
60     qDebug() << __PRETTY_FUNCTION__;
61     if (event->button() == Qt::LeftButton) {
62
63         dragPosition = event->pos();
64         qWarning() << "EvPos:" << event->pos().x() << event->pos().y() << "DP:" << dragPosition.x() << dragPosition.y();
65         event->accept();
66     }
67 }
68
69 void ZoomButtonPanel::mouseMoveEvent(QMouseEvent *event)
70 {
71     qDebug() << __PRETTY_FUNCTION__;
72     if (event->buttons() & Qt::LeftButton) {
73         move(mapToParent(event->pos()) - dragPosition);
74 //        move(event->pos() - dragPosition);
75         qWarning() << "EvPos2:" << event->pos().x() << event->pos().y();
76         setAutoFillBackground(true);
77         event->accept();
78     }
79 }
80
81 void ZoomButtonPanel::mouseReleaseEvent(QMouseEvent *event)
82 {
83     qDebug() << __PRETTY_FUNCTION__;
84     setAutoFillBackground(false);
85     event->accept();
86 }
87
88 void ZoomButtonPanel::disableZoomInButton()
89 {
90     qDebug() << __PRETTY_FUNCTION__;
91
92     m_zoomInButton->setMode(QIcon::Disabled);
93 }
94
95 void ZoomButtonPanel::disableZoomOutButton()
96 {
97     qDebug() << __PRETTY_FUNCTION__;
98
99     m_zoomOutButton->setMode(QIcon::Disabled);
100 }
101
102 void ZoomButtonPanel::resetButtons()
103 {
104     qDebug() << __PRETTY_FUNCTION__;
105
106     m_zoomInButton->setMode(QIcon::Normal);
107     m_zoomOutButton->setMode(QIcon::Normal);
108 }