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)
40 m_activeTab(-1) ///< @todo magic
42 qDebug() << __PRETTY_FUNCTION__;
44 ///< @todo Do not use this, REMOVE ALL OCCURENCES!
45 this->resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH, PANEL_HEIGHT);
46 this->move(PANEL_CLOSED_X, PANEL_TOP_PADDING);
49 m_panelWidgetStack = new QStackedWidget(this);
51 m_tabButtonGroup = new QButtonGroup(this);
53 connect(m_tabButtonGroup, SIGNAL(buttonPressed(int)),
54 this, SLOT(setActiveTab(int)));
57 m_panelBar = new PanelBar(this);
58 m_panelBar->move(PANEL_TAB_WIDTH, 0);
60 // --- PANEL CONTENT ---
61 m_panelContent = new PanelContent(this);
62 m_panelContent->setContentWidget(m_panelWidgetStack);
63 m_panelContent->move(PANEL_TAB_WIDTH + PANEL_BAR_WIDTH, 0);
65 // --- PANEL ANIMATION ---
66 m_panelStateMachine = new QStateMachine(this);
68 m_panelStateClosed = new QState(m_panelStateMachine);
69 m_panelStateOpened = new QState(m_panelStateMachine);
71 m_panelAnimation = new QPropertyAnimation(this, "pos", this);
73 m_panelStateMachine->setInitialState(m_panelStateClosed);
75 m_panelTransitionOpen = m_panelStateClosed->addTransition(this, SIGNAL(toggleState()),
77 m_panelTransitionOpen->addAnimation(m_panelAnimation);
79 m_panelTransitionClose = m_panelStateOpened->addTransition(this, SIGNAL(toggleState()),
81 m_panelTransitionClose->addAnimation(m_panelAnimation);
83 connect(m_panelAnimation, SIGNAL(finished()),
84 this, SLOT(stateChanged()));
86 m_panelStateClosed->assignProperty(this, "pos",
87 QPoint(PANEL_CLOSED_X, PANEL_TOP_PADDING));
88 m_panelStateOpened->assignProperty(this, "pos",
89 QPoint(PANEL_OPENED_X, PANEL_TOP_PADDING));
91 m_panelStateMachine->start();
94 int TabbedPanel::addTab(QWidget *widget, const QIcon& icon)
96 qDebug() << __PRETTY_FUNCTION__;
99 return insertTab(-1, widget, icon);
102 int TabbedPanel::insertTab(int index, QWidget *widget, const QIcon& icon)
104 qDebug() << __PRETTY_FUNCTION__;
106 ///< @todo callers responsibility to call with right parameters
111 int verticalStartPoint = 8;
113 index = m_panelWidgetStack->insertWidget(index, widget);
114 m_tabButtonGroup->addButton(new PanelTab(this), index);
115 m_tabButtonGroup->button(index)->setIcon(icon);
117 ///< @todo [BEGIN]: Purkkaa (to be removed ASAP!!!)
119 verticalStartPoint += 65 * index;
121 m_tabButtonGroup->button(index)->move(0, verticalStartPoint);
127 void TabbedPanel::removeTab(int index)
129 qDebug() << __PRETTY_FUNCTION__;
131 if(QWidget *widget = m_panelWidgetStack->widget(index)) {
132 m_panelWidgetStack->removeWidget(widget);
134 QAbstractButton *tab = m_tabButtonGroup->button(index);
135 m_tabButtonGroup->removeButton(tab);
140 ///< @todo sort alphabetically (other methods too)
141 void TabbedPanel::closePanel()
143 qDebug() << __PRETTY_FUNCTION__;
149 void TabbedPanel::openPanel()
151 qDebug() << __PRETTY_FUNCTION__;
157 void TabbedPanel::resizePanel(const QSize &size)
159 qDebug() << __PRETTY_FUNCTION__;
161 this->resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH,
162 size.height() - PANEL_TOP_PADDING - PANEL_BOTTOM_PADDING);
165 this->move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
168 this->move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH,
172 m_panelBar->resizeBar(size);
174 m_panelContent->resizePanelContent(size);
177 m_panelStateClosed->assignProperty(this, "pos",
178 QPoint(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING));
179 m_panelStateOpened->assignProperty(this, "pos",
180 QPoint(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH,
184 void TabbedPanel::setActiveTab(int index)
186 qDebug() << __PRETTY_FUNCTION__;
189 ///< @todo short comments?
190 if(m_activeTab == -1) {
192 m_panelWidgetStack->setCurrentIndex(index);
195 } else if(m_activeTab == index) {
200 m_panelWidgetStack->setCurrentIndex(index);
205 void TabbedPanel::stateChanged()
207 qDebug() << __PRETTY_FUNCTION__;
215 m_tabButtonGroup->setExclusive(false);
216 m_tabButtonGroup->button(m_tabButtonGroup->checkedId())->setChecked(false);
217 m_tabButtonGroup->setExclusive(true);