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 "panelcontentstack.h"
31 #include "paneltabbar.h"
33 #include "tabbedpanel.h"
35 TabbedPanel::TabbedPanel(QWidget *parent)
39 qDebug() << __PRETTY_FUNCTION__;
41 const int PANEL_LEFT_X = 0;
42 const int PANEL_TOP_Y = 0;
43 const int TAB_BAR_TOP_SPACING = 8;
45 resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH, PANEL_HEIGHT);
46 move(PANEL_CLOSED_X, PANEL_TOP_PADDING);
49 m_panelTabBar = new PanelTabBar(this);
50 m_panelTabBar->move(PANEL_LEFT_X, TAB_BAR_TOP_SPACING);
52 connect(m_panelTabBar, SIGNAL(currentChanged(int)),
53 this, SLOT(setCurrentIndex(int)));
55 connect(m_panelTabBar, SIGNAL(tabCloseRequested(int)),
56 this, SLOT(closePanel()));
58 connect(this, SIGNAL(panelClosed()),
59 m_panelTabBar, SLOT(deselectTabs()));
62 m_panelBar = new PanelBar(this);
63 m_panelBar->move(PANEL_TAB_WIDTH, PANEL_TOP_Y);
65 // --- PANEL CONTENT ---
66 m_panelContentStack = new PanelContentStack(this);
67 m_panelContentStack->move(PANEL_TAB_WIDTH + PANEL_BAR_WIDTH, PANEL_TOP_Y);
69 // --- PANEL ANIMATION ---
70 m_panelStateMachine = new QStateMachine(this);
72 m_panelStateClosed = new QState(m_panelStateMachine);
73 m_panelStateOpened = new QState(m_panelStateMachine);
75 m_panelAnimation = new QPropertyAnimation(this, "pos", this);
77 m_panelStateMachine->setInitialState(m_panelStateClosed);
79 m_panelTransitionOpen = m_panelStateClosed->addTransition(this, SIGNAL(toggleState()),
81 m_panelTransitionOpen->addAnimation(m_panelAnimation);
83 m_panelTransitionClose = m_panelStateOpened->addTransition(this, SIGNAL(toggleState()),
85 m_panelTransitionClose->addAnimation(m_panelAnimation);
87 connect(m_panelAnimation, SIGNAL(finished()),
88 this, SLOT(stateChanged()));
90 m_panelStateClosed->assignProperty(this, "pos",
91 QPoint(PANEL_CLOSED_X, PANEL_TOP_PADDING));
92 m_panelStateOpened->assignProperty(this, "pos",
93 QPoint(PANEL_OPENED_X, PANEL_TOP_PADDING));
95 m_panelStateMachine->start();
98 int TabbedPanel::addTab(QWidget *widget, const QIcon& icon)
100 qDebug() << __PRETTY_FUNCTION__;
102 const int APPEND_INDEX = -1;
104 return insertTab(APPEND_INDEX, widget, icon);
107 void TabbedPanel::closePanel()
109 qDebug() << __PRETTY_FUNCTION__;
115 int TabbedPanel::insertTab(int index, QWidget *widget, const QIcon& icon)
117 qDebug() << __PRETTY_FUNCTION__;
119 index = m_panelContentStack->insertWidget(index, widget);
120 m_panelTabBar->insertTab(index, icon);
125 void TabbedPanel::removeTab(int index)
127 qDebug() << __PRETTY_FUNCTION__;
129 if (QWidget *widget = m_panelContentStack->widget(index)) {
130 m_panelContentStack->removeWidget(widget);
131 m_panelTabBar->removeTab(index);
135 void TabbedPanel::resizePanel(const QSize &size)
137 qDebug() << __PRETTY_FUNCTION__;
139 resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH,
140 size.height() - PANEL_TOP_PADDING - PANEL_BOTTOM_PADDING);
143 move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
145 move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH, PANEL_TOP_PADDING);
147 m_panelBar->resizeBar(size);
149 m_panelContentStack->resizeContentStack(size);
151 QPoint closedPosition(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
152 m_panelStateClosed->assignProperty(this, "pos", closedPosition);
154 QPoint openedPosition(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH,
156 m_panelStateOpened->assignProperty(this, "pos", openedPosition);
159 void TabbedPanel::showPanel(QWidget *widget)
161 qDebug() << __PRETTY_FUNCTION__;
163 m_panelTabBar->selectTab(m_panelContentStack->indexOf(widget));
166 void TabbedPanel::setCurrentIndex(int index)
168 qDebug() << __PRETTY_FUNCTION__;
170 if ((index < m_panelContentStack->count()) && (index >= 0)) {
171 m_panelContentStack->setCurrentIndex(index);
176 emit currentChanged(index);
180 void TabbedPanel::stateChanged()
182 qDebug() << __PRETTY_FUNCTION__;