2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Kaj Wallin - kaj.wallin@ixonos.com
6 Pekka Nissinen - pekka.nissinen@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,
23 #include <QButtonGroup>
25 #include <QPropertyAnimation>
26 #include <QSignalTransition>
27 #include <QStackedWidget>
28 #include <QStateMachine>
31 #include "panelcontent.h"
35 #include "tabbedpanel.h"
37 TabbedPanel::TabbedPanel(QWidget *parent)
42 qDebug() << __PRETTY_FUNCTION__;
44 this->resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH, PANEL_HEIGHT);
45 this->move(PANEL_CLOSED_X, PANEL_TOP_PADDING);
48 m_panelWidgetStack = new QStackedWidget(this);
50 m_tabButtonGroup = new QButtonGroup(this);
52 connect(m_tabButtonGroup, SIGNAL(buttonPressed(int)),
53 this, SLOT(setActiveTab(int)));
56 m_panelBar = new PanelBar(this);
57 m_panelBar->move(PANEL_TAB_WIDTH, 0);
59 // --- PANEL CONTENT ---
60 m_panelContent = new PanelContent(this);
61 m_panelContent->setContentWidget(m_panelWidgetStack);
62 m_panelContent->move(PANEL_TAB_WIDTH + PANEL_BAR_WIDTH, 0);
64 // --- PANEL ANIMATION ---
65 m_panelStateMachine = new QStateMachine(this);
67 m_panelStateClosed = new QState(m_panelStateMachine);
68 m_panelStateOpened = new QState(m_panelStateMachine);
70 m_panelAnimation = new QPropertyAnimation(this, "pos", this);
72 m_panelStateMachine->setInitialState(m_panelStateClosed);
74 m_panelTransitionOpen = m_panelStateClosed->addTransition(this, SIGNAL(toggleState()),
76 m_panelTransitionOpen->addAnimation(m_panelAnimation);
78 m_panelTransitionClose = m_panelStateOpened->addTransition(this, SIGNAL(toggleState()),
80 m_panelTransitionClose->addAnimation(m_panelAnimation);
82 connect(m_panelAnimation, SIGNAL(finished()),
83 this, SLOT(stateChanged()));
85 m_panelStateClosed->assignProperty(this, "pos",
86 QPoint(PANEL_CLOSED_X, PANEL_TOP_PADDING));
87 m_panelStateOpened->assignProperty(this, "pos",
88 QPoint(PANEL_OPENED_X, PANEL_TOP_PADDING));
90 m_panelStateMachine->start();
93 int TabbedPanel::addTab(QWidget *widget, const QIcon& icon)
95 qDebug() << __PRETTY_FUNCTION__;
97 return insertTab(-1, widget, icon);
100 int TabbedPanel::insertTab(int index, QWidget *widget, const QIcon& icon)
102 qDebug() << __PRETTY_FUNCTION__;
107 int verticalStartPoint = 8;
109 index = m_panelWidgetStack->insertWidget(index, widget);
110 m_tabButtonGroup->addButton(new PanelTab(this), index);
111 m_tabButtonGroup->button(index)->setIcon(icon);
113 // [BEGIN]: Purkkaa (to be removed ASAP!!!)
115 verticalStartPoint += 65 * index;
117 m_tabButtonGroup->button(index)->move(0, verticalStartPoint);
123 void TabbedPanel::removeTab(int index)
125 qDebug() << __PRETTY_FUNCTION__;
127 if(QWidget *widget = m_panelWidgetStack->widget(index)) {
128 m_panelWidgetStack->removeWidget(widget);
130 QAbstractButton *tab = m_tabButtonGroup->button(index);
131 m_tabButtonGroup->removeButton(tab);
136 void TabbedPanel::closePanel()
138 qDebug() << __PRETTY_FUNCTION__;
144 void TabbedPanel::openPanel()
146 qDebug() << __PRETTY_FUNCTION__;
152 void TabbedPanel::resizePanel(const QSize &size)
154 qDebug() << __PRETTY_FUNCTION__;
156 this->resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH,
157 size.height() - PANEL_TOP_PADDING - PANEL_BOTTOM_PADDING);
160 this->move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
162 this->move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH,
165 m_panelBar->resizeBar(size);
167 m_panelContent->resizePanelContent(size);
169 m_panelStateClosed->assignProperty(this, "pos",
170 QPoint(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING));
171 m_panelStateOpened->assignProperty(this, "pos",
172 QPoint(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH,
176 void TabbedPanel::setActiveTab(int index)
178 qDebug() << __PRETTY_FUNCTION__;
180 if(m_activeTab == -1) {
182 m_panelWidgetStack->setCurrentIndex(index);
185 } else if(m_activeTab == index) {
190 m_panelWidgetStack->setCurrentIndex(index);
195 void TabbedPanel::stateChanged()
197 qDebug() << __PRETTY_FUNCTION__;
205 m_tabButtonGroup->setExclusive(false);
206 m_tabButtonGroup->button(m_tabButtonGroup->checkedId())->setChecked(false);
207 m_tabButtonGroup->setExclusive(true);