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>
29 #include "panelcontent.h"
33 #include "tabbedpanel.h"
35 TabbedPanel::TabbedPanel(QWidget *parent)
40 qDebug() << __PRETTY_FUNCTION__;
42 this->resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH, PANEL_HEIGHT);
43 this->move(PANEL_CLOSED_X, PANEL_TOP_PADDING);
46 m_panelWidgetStack = new QStackedWidget(this);
48 m_tabButtonGroup = new QButtonGroup(this);
50 connect(m_tabButtonGroup, SIGNAL(buttonPressed(int)),
51 this, SLOT(setActiveTab(int)));
54 m_panelBar = new PanelBar(this);
55 m_panelBar->move(PANEL_TAB_WIDTH, 0);
57 // --- PANEL CONTENT ---
58 m_panelContent = new PanelContent(this);
59 m_panelContent->setContentWidget(m_panelWidgetStack);
60 m_panelContent->move(PANEL_TAB_WIDTH + PANEL_BAR_WIDTH, 0);
62 // --- PANEL ANIMATION ---
63 m_panelStateMachine = new QStateMachine(this);
65 m_panelStateClosed = new QState(m_panelStateMachine);
66 m_panelStateOpened = new QState(m_panelStateMachine);
68 m_panelAnimation = new QPropertyAnimation(this, "pos", this);
70 m_panelStateMachine->setInitialState(m_panelStateClosed);
72 m_panelTransitionOpen = m_panelStateClosed->addTransition(this, SIGNAL(toggleState()),
74 m_panelTransitionOpen->addAnimation(m_panelAnimation);
76 m_panelTransitionClose = m_panelStateOpened->addTransition(this, SIGNAL(toggleState()),
78 m_panelTransitionClose->addAnimation(m_panelAnimation);
80 connect(m_panelAnimation, SIGNAL(finished()),
81 this, SLOT(stateChanged()));
83 m_panelStateClosed->assignProperty(this, "pos",
84 QPoint(PANEL_CLOSED_X, PANEL_TOP_PADDING));
85 m_panelStateOpened->assignProperty(this, "pos",
86 QPoint(PANEL_OPENED_X, PANEL_TOP_PADDING));
88 m_panelStateMachine->start();
91 int TabbedPanel::addTab(QWidget *widget, const QIcon& icon)
93 qDebug() << __PRETTY_FUNCTION__;
95 return insertTab(-1, widget, icon);
98 int TabbedPanel::insertTab(int index, QWidget *widget, const QIcon& icon)
100 qDebug() << __PRETTY_FUNCTION__;
105 int verticalStartPoint = 8;
107 index = m_panelWidgetStack->insertWidget(index, widget);
108 m_tabButtonGroup->addButton(new PanelTab(this), index);
109 m_tabButtonGroup->button(index)->setIcon(icon);
111 // [BEGIN]: Purkkaa (to be removed ASAP!!!)
113 verticalStartPoint += 65 * index;
115 m_tabButtonGroup->button(index)->move(0, verticalStartPoint);
121 void TabbedPanel::removeTab(int index)
123 qDebug() << __PRETTY_FUNCTION__;
125 if(QWidget *widget = m_panelWidgetStack->widget(index)) {
126 m_panelWidgetStack->removeWidget(widget);
128 QAbstractButton *tab = m_tabButtonGroup->button(index);
129 m_tabButtonGroup->removeButton(tab);
134 void TabbedPanel::closePanel()
136 qDebug() << __PRETTY_FUNCTION__;
142 void TabbedPanel::openPanel()
144 qDebug() << __PRETTY_FUNCTION__;
150 void TabbedPanel::setActiveTab(int index)
152 qDebug() << __PRETTY_FUNCTION__;
154 if(m_activeTab == -1) {
156 m_panelWidgetStack->setCurrentIndex(index);
158 } else if(m_activeTab == index) {
163 m_panelWidgetStack->setCurrentIndex(index);
167 void TabbedPanel::resizePanel(const QSize &size)
169 qDebug() << __PRETTY_FUNCTION__;
171 this->resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH,
172 size.height() - PANEL_TOP_PADDING - PANEL_BOTTOM_PADDING);
175 this->move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
177 this->move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH,
180 m_panelBar->resizeBar(size);
182 m_panelContent->resizePanelContent(size);
184 m_panelStateClosed->assignProperty(this, "pos",
185 QPoint(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING));
186 m_panelStateOpened->assignProperty(this, "pos",
187 QPoint(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH,
191 void TabbedPanel::stateChanged()
193 qDebug() << __PRETTY_FUNCTION__;
201 m_tabButtonGroup->setExclusive(false);
202 m_tabButtonGroup->button(m_tabButtonGroup->checkedId())->setChecked(false);
203 m_tabButtonGroup->setExclusive(true);