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,
24 #include <QPropertyAnimation>
25 #include <QSignalTransition>
26 #include <QStackedWidget>
27 #include <QStateMachine>
30 #include "panelcontent.h"
31 #include "paneltabbar.h"
33 #include "tabbedpanel.h"
35 TabbedPanel::TabbedPanel(QWidget *parent)
39 qDebug() << __PRETTY_FUNCTION__;
41 ///< @todo Do not use this, REMOVE ALL OCCURENCES IN ALL FILES!
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_panelTabBar = new PanelTabBar(this);
50 connect(m_panelTabBar, SIGNAL(currentChanged(int)),
51 this, SLOT(setCurrentIndex(int)));
53 connect(m_panelTabBar, SIGNAL(tabCloseRequested(int)),
54 this, SLOT(closePanel()));
56 connect(this, SIGNAL(panelClosed()),
57 m_panelTabBar, SLOT(deselectTabs()));
60 m_panelBar = new PanelBar(this);
61 m_panelBar->move(PANEL_TAB_WIDTH, 0);
63 // --- PANEL CONTENT ---
64 m_panelContent = new PanelContent(this);
65 m_panelContent->setContentWidget(m_panelWidgetStack);
66 m_panelContent->move(PANEL_TAB_WIDTH + PANEL_BAR_WIDTH, 0);
68 // --- PANEL ANIMATION ---
69 m_panelStateMachine = new QStateMachine(this);
71 m_panelStateClosed = new QState(m_panelStateMachine);
72 m_panelStateOpened = new QState(m_panelStateMachine);
74 m_panelAnimation = new QPropertyAnimation(this, "pos", this);
76 m_panelStateMachine->setInitialState(m_panelStateClosed);
78 m_panelTransitionOpen = m_panelStateClosed->addTransition(this, SIGNAL(toggleState()),
80 m_panelTransitionOpen->addAnimation(m_panelAnimation);
82 m_panelTransitionClose = m_panelStateOpened->addTransition(this, SIGNAL(toggleState()),
84 m_panelTransitionClose->addAnimation(m_panelAnimation);
86 connect(m_panelAnimation, SIGNAL(finished()),
87 this, SLOT(stateChanged()));
89 m_panelStateClosed->assignProperty(this, "pos",
90 QPoint(PANEL_CLOSED_X, PANEL_TOP_PADDING));
91 m_panelStateOpened->assignProperty(this, "pos",
92 QPoint(PANEL_OPENED_X, PANEL_TOP_PADDING));
94 m_panelStateMachine->start();
97 int TabbedPanel::addTab(QWidget *widget, const QIcon& icon)
99 qDebug() << __PRETTY_FUNCTION__;
102 return insertTab(-1, widget, icon);
105 int TabbedPanel::insertTab(int index, QWidget *widget, const QIcon& icon)
107 qDebug() << __PRETTY_FUNCTION__;
109 ///< @todo callers responsibility to call with right parameters
113 index = m_panelWidgetStack->insertWidget(index, widget);
114 m_panelTabBar->insertTab(index, icon);
119 void TabbedPanel::removeTab(int index)
121 qDebug() << __PRETTY_FUNCTION__;
123 if(QWidget *widget = m_panelWidgetStack->widget(index)) {
124 m_panelWidgetStack->removeWidget(widget);
125 m_panelTabBar->removeTab(index);
129 ///< @todo sort alphabetically (other methods too)
130 void TabbedPanel::closePanel()
132 qDebug() << __PRETTY_FUNCTION__;
138 void TabbedPanel::showPanel(QWidget *widget)
140 qDebug() << __PRETTY_FUNCTION__;
142 m_panelTabBar->selectTab(m_panelWidgetStack->indexOf(widget));
145 void TabbedPanel::setCurrentIndex(int index)
147 qDebug() << __PRETTY_FUNCTION__;
149 ///< @todo if ((first) && (second)) {
150 if (index < m_panelWidgetStack->count() && index >= 0) {
151 m_panelWidgetStack->setCurrentIndex(index);
156 emit currentChanged(index);
160 void TabbedPanel::resizePanel(const QSize &size)
162 qDebug() << __PRETTY_FUNCTION__;
164 this->resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH,
165 size.height() - PANEL_TOP_PADDING - PANEL_BOTTOM_PADDING);
168 this->move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
170 this->move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH,
174 m_panelBar->resizeBar(size);
176 m_panelContent->resizePanelContent(size);
179 m_panelStateClosed->assignProperty(this, "pos",
180 QPoint(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING));
181 m_panelStateOpened->assignProperty(this, "pos",
182 QPoint(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH,
186 void TabbedPanel::stateChanged()
188 qDebug() << __PRETTY_FUNCTION__;