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)
43 qDebug() << __PRETTY_FUNCTION__;
45 const int PANEL_LEFT_X = 0;
46 const int PANEL_TOP_Y = 0;
47 const int PANEL_TAB_BAR_TOP_SPACING = 8;
49 resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH, PANEL_HEIGHT);
50 move(PANEL_CLOSED_X, PANEL_TOP_PADDING);
53 m_panelTabBar = new PanelTabBar(this);
54 m_panelTabBar->move(PANEL_LEFT_X, PANEL_TAB_BAR_TOP_SPACING);
56 connect(m_panelTabBar, SIGNAL(currentChanged(int)),
57 this, SLOT(setCurrentIndex(int)));
59 connect(m_panelTabBar, SIGNAL(tabCloseRequested(int)),
60 this, SLOT(closePanel()));
62 connect(this, SIGNAL(panelClosed()),
63 m_panelTabBar, SLOT(deselectTabs()));
66 m_panelBar = new PanelBar(this);
67 m_panelBar->move(PANEL_TAB_WIDTH, PANEL_TOP_Y);
69 // --- CONTEXT BUTTON BAR ---
70 m_panelContextButtonBar = new PanelContextButtonBar(this);
71 m_panelContextButtonBar->setVisible(false);
72 m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X,
73 PANEL_HEIGHT - m_panelContextButtonBar->height());
75 connect(m_panelContextButtonBar, SIGNAL(positionChangeRequested()),
76 this, SLOT(repositionContextButtonBar()));
78 // --- PANEL CONTENT ---
79 m_panelContentStack = new PanelContentStack(this);
80 m_panelContentStack->move(PANEL_TAB_WIDTH + PANEL_BAR_WIDTH, PANEL_TOP_Y);
82 // --- PANEL ANIMATION ---
83 m_panelStateMachine = new QStateMachine(this);
85 m_panelStateClosed = new QState(m_panelStateMachine);
86 m_panelStateOpened = new QState(m_panelStateMachine);
88 m_panelAnimation = new QPropertyAnimation(this, "pos", this);
90 m_panelStateMachine->setInitialState(m_panelStateClosed);
92 m_panelTransitionOpen = m_panelStateClosed->addTransition(this, SIGNAL(toggleState()),
94 m_panelTransitionOpen->addAnimation(m_panelAnimation);
96 m_panelTransitionClose = m_panelStateOpened->addTransition(this, SIGNAL(toggleState()),
98 m_panelTransitionClose->addAnimation(m_panelAnimation);
100 connect(m_panelAnimation, SIGNAL(finished()),
101 this, SLOT(stateChanged()));
103 m_panelStateClosed->assignProperty(this, "pos",
104 QPoint(PANEL_CLOSED_X, PANEL_TOP_PADDING));
105 m_panelStateOpened->assignProperty(this, "pos",
106 QPoint(PANEL_OPENED_X, PANEL_TOP_PADDING));
108 m_panelStateMachine->start();
111 int TabbedPanel::addTab(QWidget *widget, const QIcon& icon)
113 qDebug() << __PRETTY_FUNCTION__;
115 const int APPEND_INDEX = -1;
117 return insertTab(APPEND_INDEX, widget, icon);
120 void TabbedPanel::closePanel()
122 qDebug() << __PRETTY_FUNCTION__;
128 int TabbedPanel::insertTab(int index, QWidget *widget, const QIcon& icon)
130 qDebug() << __PRETTY_FUNCTION__;
132 index = m_panelContentStack->insertWidget(index, widget);
133 m_panelTabBar->insertTab(index, icon);
138 void TabbedPanel::removeTab(int index)
140 qDebug() << __PRETTY_FUNCTION__;
142 if (QWidget *widget = m_panelContentStack->widget(index)) {
143 m_panelContentStack->removeWidget(widget);
144 m_panelTabBar->removeTab(index);
148 void TabbedPanel::repositionContextButtonBar()
150 qDebug() << __PRETTY_FUNCTION__;
152 m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X,
153 height() - m_panelContextButtonBar->height());
156 void TabbedPanel::resizePanel(const QSize &size)
158 qDebug() << __PRETTY_FUNCTION__;
160 resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH,
161 size.height() - PANEL_TOP_PADDING - PANEL_BOTTOM_PADDING);
164 move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
166 move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH, PANEL_TOP_PADDING);
168 m_panelBar->resizeBar(size);
170 m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X,
171 size.height() - m_panelContextButtonBar->height());
173 m_panelContentStack->resizeContentStack(size);
175 QPoint closedPosition(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
176 m_panelStateClosed->assignProperty(this, "pos", closedPosition);
178 QPoint openedPosition(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH,
180 m_panelStateOpened->assignProperty(this, "pos", openedPosition);
183 void TabbedPanel::setCurrentIndex(int index)
185 qDebug() << __PRETTY_FUNCTION__;
187 if ((index < m_panelContentStack->count()) && (index >= 0)) {
188 m_panelContentStack->setCurrentIndex(index);
193 m_panelContextButtonBar->setContextButtons(
194 static_cast<PanelBase *>(m_panelContentStack->widget(index))->contextButtons());
196 emit currentChanged(index);
200 void TabbedPanel::showPanel(QWidget *widget)
202 qDebug() << __PRETTY_FUNCTION__;
204 m_panelTabBar->selectTab(m_panelContentStack->indexOf(widget));
207 void TabbedPanel::stateChanged()
209 qDebug() << __PRETTY_FUNCTION__;
213 m_panelContextButtonBar->setVisible(true);
217 m_panelContextButtonBar->setVisible(false);