Removed unused PanelSideBar classes and added new PanelTab classes for tabbed panels
[situare] / src / ui / paneltab.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 <QMouseEvent>
24 #include <QPainter>
25 #include <QRect>
26
27 #include "paneltab.h"
28
29 const int TAB_WIDTH = 66;
30 const int TAB_WIDTH_ACTIVE = 74;
31 const int TAB_HEIGHT = 66;
32
33 PanelTab::PanelTab(QWidget *parent)
34     : QToolButton(parent),
35       m_tabActive(false),
36       m_tabSelected(false)
37 {
38     qDebug() << __PRETTY_FUNCTION__;
39
40     m_tabPixmaps[0].load(":/res/images/tab_inactive.png");
41     m_tabPixmaps[1].load(":/res/images/tab_inactive2.png");
42     m_tabPixmaps[2].load(":/res/images/tab_active.png");
43
44 //    m_tabRect.setRect(TAB_WIDTH_ACTIVE - TAB_WIDTH, 0, TAB_WIDTH, TAB_HEIGHT);
45
46     setCheckable(true);
47
48     setFixedSize(TAB_WIDTH_ACTIVE, TAB_HEIGHT);
49 }
50
51 void PanelTab::mouseMoveEvent(QMouseEvent *event)
52 {
53 //    qDebug() << __PRETTY_FUNCTION__;
54
55     if(m_tabSelected) {
56         if(!rect().contains(event->pos()))
57             setDown(false);
58         else
59             setDown(true);
60     }
61 }
62
63 void PanelTab::mousePressEvent(QMouseEvent *event)
64 {
65 //    qDebug() << __PRETTY_FUNCTION__;
66
67     if(event->button() == Qt::LeftButton) {
68         setDown(true);
69         m_tabSelected = true;
70     }
71 }
72
73 void PanelTab::mouseReleaseEvent(QMouseEvent *event)
74 {
75 //    qDebug() << __PRETTY_FUNCTION__;
76
77     if(this->rect().contains(event->pos())) {
78 //        emit QAbstractButton::clicked();
79 //        emit clicked();
80         click();
81
82 //        if(m_tabActive) {
83         if(isChecked()) {
84 //            m_tabActive = false;
85             setChecked(false);
86 //            m_tabRect.setRect(TAB_WIDTH_ACTIVE - TAB_WIDTH, 0, TAB_WIDTH, TAB_HEIGHT);
87         } else {
88 //            m_tabActive = true;
89             setChecked(true);
90 //            m_tabRect.setRect(0, 0, TAB_WIDTH_ACTIVE, TAB_HEIGHT);
91         }
92     }
93
94     setDown(false);
95     m_tabSelected = false;
96 }
97
98 void PanelTab::paintEvent(QPaintEvent *)
99 {
100 //    qDebug() << __PRETTY_FUNCTION__;
101
102     QPainter painter(this);
103
104     if(isChecked()) {
105         m_tabRect.setRect(0, 0, TAB_WIDTH_ACTIVE, TAB_HEIGHT);
106         painter.drawPixmap(m_tabRect, m_tabPixmaps[2]);
107     } else {
108         m_tabRect.setRect(TAB_WIDTH_ACTIVE - TAB_WIDTH, 0, TAB_WIDTH, TAB_HEIGHT);
109         painter.drawPixmap(m_tabRect, m_tabPixmaps[0]);
110     }
111
112     if(isDown())
113         icon().paint(&painter, m_tabRect, Qt::AlignCenter, QIcon::Selected);
114     else if(isChecked())
115         icon().paint(&painter, m_tabRect, Qt::AlignCenter, QIcon::Normal);
116     else
117         icon().paint(&painter, m_tabRect, Qt::AlignCenter, QIcon::Disabled);
118 }
119
120 void PanelTab::setActive(bool state)
121 {
122     qDebug() << __PRETTY_FUNCTION__;
123
124     if(state)
125 //        m_tabActive = true;
126         setChecked(true);
127     else
128 //        m_tabActive = false;
129         setChecked(false);
130 }