Zoomb button mode is now set to disabled when zoombuttonpanel gets
[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: Zoom buttons catch the mouse press event and it doesn't propagate to zoombuttonpanel
57 void ZoomButtonPanel::mousePressEvent(QMouseEvent *event)
58 {
59     qDebug() << __PRETTY_FUNCTION__;
60
61     if (event->button() == Qt::LeftButton) {
62         m_dragPosition = event->pos();
63         qWarning() << "Press:" << event->pos().x() << event->pos().y()
64                    << "DP:" << m_dragPosition.x() << m_dragPosition.y();
65         event->accept();
66         m_inButtonMode = m_zoomInButton->mode();
67         m_outButtonMode = m_zoomOutButton->mode();
68         m_zoomInButton->setMode(QIcon::Disabled);
69         m_zoomOutButton->setMode(QIcon::Disabled);
70     }
71 }
72
73 void ZoomButtonPanel::mouseMoveEvent(QMouseEvent *event)
74 {
75     qDebug() << __PRETTY_FUNCTION__;
76
77     if (event->buttons() & Qt::LeftButton) {
78         move(mapToParent(event->pos()) - m_dragPosition);
79         qWarning() << "Move:" << event->pos().x() << event->pos().y();
80         setAutoFillBackground(true);
81         event->accept();
82     }
83 }
84
85 void ZoomButtonPanel::mouseReleaseEvent(QMouseEvent *event)
86 {
87     qDebug() << __PRETTY_FUNCTION__;
88
89     setAutoFillBackground(false);
90     event->accept();
91     m_zoomInButton->setMode(m_inButtonMode);
92     m_zoomOutButton->setMode(m_outButtonMode);
93 }
94
95 void ZoomButtonPanel::disableZoomInButton()
96 {
97     qDebug() << __PRETTY_FUNCTION__;
98
99     m_zoomInButton->setMode(QIcon::Disabled);
100 }
101
102 void ZoomButtonPanel::disableZoomOutButton()
103 {
104     qDebug() << __PRETTY_FUNCTION__;
105
106     m_zoomOutButton->setMode(QIcon::Disabled);
107 }
108
109 void ZoomButtonPanel::resetButtons()
110 {
111     qDebug() << __PRETTY_FUNCTION__;
112
113     m_zoomInButton->setMode(QIcon::Normal);
114     m_zoomOutButton->setMode(QIcon::Normal);
115 }