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 "panelbase.h"
31 #include "panelcontentstack.h"
32 #include "panelcontextbuttonbar.h"
33 #include "paneltabbar.h"
35 #include "tabbedpanel.h"
37 const int PANEL_CONTEXT_BUTTON_BAR_LEFT_X = 1;
39 TabbedPanel::TabbedPanel(QWidget *parent)
42 m_closeRequestPending(false)
44 qDebug() << __PRETTY_FUNCTION__;
46 const int PANEL_LEFT_X = 0;
47 const int PANEL_TOP_Y = 0;
48 const int PANEL_TAB_BAR_TOP_SPACING = 8;
50 resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH, PANEL_HEIGHT);
51 move(PANEL_CLOSED_X, PANEL_TOP_PADDING);
54 m_panelTabBar = new PanelTabBar(this);
55 m_panelTabBar->move(PANEL_LEFT_X, PANEL_TAB_BAR_TOP_SPACING);
57 connect(m_panelTabBar, SIGNAL(currentChanged(int)),
58 this, SLOT(setCurrentIndex(int)));
60 connect(m_panelTabBar, SIGNAL(tabCloseRequested(int)),
61 this, SLOT(closePanel()));
63 connect(this, SIGNAL(panelClosed()),
64 m_panelTabBar, SLOT(deselectTabs()));
67 m_panelBar = new PanelBar(this);
68 m_panelBar->move(PANEL_TAB_WIDTH, PANEL_TOP_Y);
70 // --- CONTEXT BUTTON BAR ---
71 m_panelContextButtonBar = new PanelContextButtonBar(this);
72 m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X, PANEL_HEIGHT);
74 connect(m_panelContextButtonBar, SIGNAL(barHidden()),
75 this, SLOT(closePanel()));
77 connect(m_panelContextButtonBar, SIGNAL(positionChangeRequested()),
78 this, SLOT(repositionContextButtonBar()));
80 // --- PANEL CONTENT ---
81 m_panelContentStack = new PanelContentStack(this);
82 m_panelContentStack->move(PANEL_TAB_WIDTH + PANEL_BAR_WIDTH, PANEL_TOP_Y);
84 // --- PANEL ANIMATION ---
85 QStateMachine *panelStateMachine = new QStateMachine(this);
87 m_stateClosed = new QState(panelStateMachine);
88 m_stateOpened = new QState(panelStateMachine);
90 QPropertyAnimation *panelAnimation = new QPropertyAnimation(this, "pos", this);
92 panelStateMachine->setInitialState(m_stateClosed);
94 QSignalTransition *panelTransitionOpen = m_stateClosed->addTransition(this,
95 SIGNAL(toggleState()),
97 panelTransitionOpen->addAnimation(panelAnimation);
99 QSignalTransition *panelTransitionClose = m_stateOpened->addTransition(this,
100 SIGNAL(toggleState()),
102 panelTransitionClose->addAnimation(panelAnimation);
104 connect(panelAnimation, SIGNAL(finished()),
105 this, SLOT(stateChanged()));
107 QPoint closedPosition(PANEL_CLOSED_X, PANEL_TOP_PADDING);
108 m_stateClosed->assignProperty(this, "pos", closedPosition);
110 QPoint openedPosition(PANEL_OPENED_X, PANEL_TOP_PADDING);
111 m_stateOpened->assignProperty(this, "pos", openedPosition);
113 panelStateMachine->start();
116 int TabbedPanel::addTab(QWidget *widget, const QIcon& icon)
118 qDebug() << __PRETTY_FUNCTION__;
120 const int APPEND_INDEX = -1;
122 return insertTab(APPEND_INDEX, widget, icon);
125 void TabbedPanel::closePanel()
127 qDebug() << __PRETTY_FUNCTION__;
132 if (m_panelContextButtonBar->isBarVisible()) {
133 m_closeRequestPending = true;
134 m_panelContextButtonBar->hideContextButtonBar();
138 } else if (m_closeRequestPending) {
139 m_closeRequestPending = false;
144 int TabbedPanel::insertTab(int index, QWidget *widget, const QIcon& icon)
146 qDebug() << __PRETTY_FUNCTION__;
148 index = m_panelContentStack->insertWidget(index, widget);
149 m_panelTabBar->insertTab(index, icon);
154 void TabbedPanel::openPanel(QWidget *widget)
156 qDebug() << __PRETTY_FUNCTION__;
159 m_panelTabBar->selectTab(m_panelContentStack->indexOf(widget));
160 } else if (!m_open) {
161 if (!m_closeRequestPending) {
168 void TabbedPanel::removeTab(int index)
170 qDebug() << __PRETTY_FUNCTION__;
172 if (QWidget *widget = m_panelContentStack->widget(index)) {
173 m_panelContentStack->removeWidget(widget);
174 m_panelTabBar->removeTab(index);
178 void TabbedPanel::repositionContextButtonBar()
180 qDebug() << __PRETTY_FUNCTION__;
182 m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X, height());
185 void TabbedPanel::resizePanel(const QSize &size)
187 qDebug() << __PRETTY_FUNCTION__;
189 resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH,
190 size.height() - PANEL_TOP_PADDING - PANEL_BOTTOM_PADDING);
193 move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
195 move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH, PANEL_TOP_PADDING);
197 m_panelBar->resizeBar(size);
199 m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X, size.height());
201 m_panelContentStack->resizeContentStack(size);
203 QPoint closedPosition(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
204 m_stateClosed->assignProperty(this, "pos", closedPosition);
206 QPoint openedPosition(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH,
208 m_stateOpened->assignProperty(this, "pos", openedPosition);
211 void TabbedPanel::setCurrentIndex(int index)
213 qDebug() << __PRETTY_FUNCTION__;
215 if ((index < m_panelContentStack->count()) && (index >= 0)) {
216 m_panelContentStack->setCurrentIndex(index);
221 m_panelContextButtonBar->setContextButtons(
222 static_cast<PanelBase *>(m_panelContentStack->widget(index))->contextButtons());
224 emit currentChanged(index);
228 void TabbedPanel::stateChanged()
230 qDebug() << __PRETTY_FUNCTION__;
233 m_panelContextButtonBar->showContextButtonBar();