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 "panelcontextbuttonbar.h"
32 #include "paneltabbar.h"
34 #include "tabbedpanel.h"
36 TabbedPanel::TabbedPanel(QWidget *parent)
40 qDebug() << __PRETTY_FUNCTION__;
42 const int PANEL_LEFT_X = 0;
43 const int PANEL_TOP_Y = 0;
44 const int TAB_BAR_TOP_SPACING = 8;
46 resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH, PANEL_HEIGHT);
47 move(PANEL_CLOSED_X, PANEL_TOP_PADDING);
50 m_panelTabBar = new PanelTabBar(this);
51 m_panelTabBar->move(PANEL_LEFT_X, TAB_BAR_TOP_SPACING);
53 connect(m_panelTabBar, SIGNAL(currentChanged(int)),
54 this, SLOT(setCurrentIndex(int)));
56 connect(m_panelTabBar, SIGNAL(tabCloseRequested(int)),
57 this, SLOT(closePanel()));
59 connect(this, SIGNAL(panelClosed()),
60 m_panelTabBar, SLOT(deselectTabs()));
63 m_panelBar = new PanelBar(this);
64 m_panelBar->move(PANEL_TAB_WIDTH, PANEL_TOP_Y);
66 // --- CONTEXT BUTTON BAR ---
67 m_panelContextButtonBar = new PanelContextButtonBar(this);
68 m_panelContextButtonBar->move(1, 300);
70 // --- PANEL CONTENT ---
71 m_panelContentStack = new PanelContentStack(this);
72 m_panelContentStack->move(PANEL_TAB_WIDTH + PANEL_BAR_WIDTH, PANEL_TOP_Y);
74 // --- PANEL ANIMATION ---
75 m_panelStateMachine = new QStateMachine(this);
77 m_panelStateClosed = new QState(m_panelStateMachine);
78 m_panelStateOpened = new QState(m_panelStateMachine);
80 m_panelAnimation = new QPropertyAnimation(this, "pos", this);
82 m_panelStateMachine->setInitialState(m_panelStateClosed);
84 m_panelTransitionOpen = m_panelStateClosed->addTransition(this, SIGNAL(toggleState()),
86 m_panelTransitionOpen->addAnimation(m_panelAnimation);
88 m_panelTransitionClose = m_panelStateOpened->addTransition(this, SIGNAL(toggleState()),
90 m_panelTransitionClose->addAnimation(m_panelAnimation);
92 connect(m_panelAnimation, SIGNAL(finished()),
93 this, SLOT(stateChanged()));
95 m_panelStateClosed->assignProperty(this, "pos",
96 QPoint(PANEL_CLOSED_X, PANEL_TOP_PADDING));
97 m_panelStateOpened->assignProperty(this, "pos",
98 QPoint(PANEL_OPENED_X, PANEL_TOP_PADDING));
100 m_panelStateMachine->start();
103 int TabbedPanel::addTab(QWidget *widget, const QIcon& icon)
105 qDebug() << __PRETTY_FUNCTION__;
107 const int APPEND_INDEX = -1;
109 return insertTab(APPEND_INDEX, widget, icon);
112 void TabbedPanel::closePanel()
114 qDebug() << __PRETTY_FUNCTION__;
120 int TabbedPanel::insertTab(int index, QWidget *widget, const QIcon& icon)
122 qDebug() << __PRETTY_FUNCTION__;
124 index = m_panelContentStack->insertWidget(index, widget);
125 m_panelTabBar->insertTab(index, icon);
130 void TabbedPanel::removeTab(int index)
132 qDebug() << __PRETTY_FUNCTION__;
134 if (QWidget *widget = m_panelContentStack->widget(index)) {
135 m_panelContentStack->removeWidget(widget);
136 m_panelTabBar->removeTab(index);
140 void TabbedPanel::resizePanel(const QSize &size)
142 qDebug() << __PRETTY_FUNCTION__;
144 resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH,
145 size.height() - PANEL_TOP_PADDING - PANEL_BOTTOM_PADDING);
148 move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
150 move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH, PANEL_TOP_PADDING);
152 m_panelBar->resizeBar(size);
154 m_panelContentStack->resizeContentStack(size);
156 QPoint closedPosition(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
157 m_panelStateClosed->assignProperty(this, "pos", closedPosition);
159 QPoint openedPosition(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH,
161 m_panelStateOpened->assignProperty(this, "pos", openedPosition);
164 void TabbedPanel::showPanel(QWidget *widget)
166 qDebug() << __PRETTY_FUNCTION__;
168 m_panelTabBar->selectTab(m_panelContentStack->indexOf(widget));
171 void TabbedPanel::setCurrentIndex(int index)
173 qDebug() << __PRETTY_FUNCTION__;
175 if ((index < m_panelContentStack->count()) && (index >= 0)) {
176 m_panelContentStack->setCurrentIndex(index);
181 emit currentChanged(index);
185 void TabbedPanel::stateChanged()
187 qDebug() << __PRETTY_FUNCTION__;