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,
23 #include <QAbstractButton>
24 #include <QButtonGroup>
26 #include <QPropertyAnimation>
28 #include <QSignalTransition>
29 #include <QStackedWidget>
30 #include <QStateMachine>
33 #include "panelbase.h"
34 #include "panelcontentstack.h"
35 #include "panelcontextbuttonbar.h"
36 #include "paneltabbar.h"
38 #include "tabbedpanel.h"
40 const int PANEL_CONTEXT_BUTTON_BAR_LEFT_X = 1;
41 const int PANEL_TAB_BAR_TOP_SPACING = 8;
43 TabbedPanel::TabbedPanel(QWidget *parent)
46 m_closeRequestPending(false)
48 qDebug() << __PRETTY_FUNCTION__;
50 const int PANEL_LEFT_X = 0;
51 const int PANEL_TOP_Y = 0;
53 resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH, PANEL_HEIGHT);
54 move(PANEL_CLOSED_X, PANEL_TOP_PADDING);
57 m_panelTabBar = new PanelTabBar(this);
58 m_panelTabBar->move(PANEL_LEFT_X, PANEL_TAB_BAR_TOP_SPACING);
60 connect(m_panelTabBar, SIGNAL(currentChanged(int)),
61 this, SLOT(setCurrentIndex(int)));
63 connect(m_panelTabBar, SIGNAL(sizeChangeRequested()),
64 this, SLOT(calculateMask()));
66 connect(m_panelTabBar, SIGNAL(tabCloseRequested(int)),
67 this, SLOT(closePanel()));
69 connect(this, SIGNAL(panelClosed()),
70 m_panelTabBar, SLOT(deselectTabs()));
73 m_panelBar = new PanelBar(this);
74 m_panelBar->move(PANEL_TAB_BAR_WIDTH, PANEL_TOP_Y);
76 // --- CONTEXT BUTTON BAR ---
77 m_panelContextButtonBar = new PanelContextButtonBar(this);
78 m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X, PANEL_HEIGHT);
80 connect(m_panelContextButtonBar, SIGNAL(barHidden()),
81 this, SLOT(closePanel()));
83 connect(m_panelContextButtonBar, SIGNAL(positionChangeRequested()),
84 this, SLOT(repositionContextButtonBar()));
86 // --- PANEL CONTENT ---
87 m_panelContentStack = new PanelContentStack(this);
88 m_panelContentStack->move(PANEL_TAB_BAR_WIDTH + PANEL_BAR_WIDTH, PANEL_TOP_Y);
90 // --- PANEL ANIMATION ---
91 QStateMachine *panelStateMachine = new QStateMachine(this);
93 m_stateClosed = new QState(panelStateMachine);
94 m_stateOpened = new QState(panelStateMachine);
96 QPropertyAnimation *panelAnimation = new QPropertyAnimation(this, "pos", this);
98 panelStateMachine->setInitialState(m_stateClosed);
100 QSignalTransition *panelTransitionOpen = m_stateClosed->addTransition(this,
101 SIGNAL(toggleState()),
103 panelTransitionOpen->addAnimation(panelAnimation);
105 QSignalTransition *panelTransitionClose = m_stateOpened->addTransition(this,
106 SIGNAL(toggleState()),
108 panelTransitionClose->addAnimation(panelAnimation);
110 connect(panelAnimation, SIGNAL(finished()),
111 this, SLOT(stateChanged()));
113 QPoint closedPosition(PANEL_CLOSED_X, PANEL_TOP_PADDING);
114 m_stateClosed->assignProperty(this, "pos", closedPosition);
116 QPoint openedPosition(PANEL_OPENED_X, PANEL_TOP_PADDING);
117 m_stateOpened->assignProperty(this, "pos", openedPosition);
119 panelStateMachine->start();
122 int TabbedPanel::addTab(QWidget *widget, const QIcon& icon)
124 qDebug() << __PRETTY_FUNCTION__;
126 const int APPEND_INDEX = -1;
128 return insertTab(APPEND_INDEX, widget, icon);
131 void TabbedPanel::calculateMask()
133 qDebug() << __PRETTY_FUNCTION__;
135 QRect panelTabBarRect = m_panelTabBar->rect();
136 QRect panelContextButtonBarRect = m_panelContextButtonBar->rect();
137 int panelContextButtonBarY = height() - panelContextButtonBarRect.height();
140 panelContextButtonBarY = height();
142 QRegion panelTabBarRegion(0, PANEL_TAB_BAR_TOP_SPACING,
143 panelTabBarRect.width(), panelTabBarRect.height());
144 QRegion panelContextButtonBarRegion(0, panelContextButtonBarY,
145 panelContextButtonBarRect.width(),
146 panelContextButtonBarRect.height());
147 QRegion panelContentRegion(panelTabBarRect.right() + 1, 0,
148 PANEL_WIDTH + PANEL_BAR_WIDTH, height());
149 QRegion panelRegion = panelTabBarRegion + panelContentRegion + panelContextButtonBarRegion;
151 setMask(panelRegion);
154 void TabbedPanel::closePanel()
156 qDebug() << __PRETTY_FUNCTION__;
161 if (m_panelContextButtonBar->isBarVisible()) {
162 m_closeRequestPending = true;
163 m_panelContextButtonBar->hideContextButtonBar();
167 } else if (m_closeRequestPending) {
168 m_closeRequestPending = false;
173 int TabbedPanel::insertTab(int index, QWidget *widget, const QIcon& icon)
175 qDebug() << __PRETTY_FUNCTION__;
177 index = m_panelContentStack->insertWidget(index, widget);
178 m_panelTabBar->insertTab(index, icon);
183 void TabbedPanel::openPanel(QWidget *widget)
185 qDebug() << __PRETTY_FUNCTION__;
188 m_panelTabBar->selectTab(m_panelContentStack->indexOf(widget));
189 } else if (!m_open) {
190 if (!m_closeRequestPending) {
197 void TabbedPanel::removeTab(int index)
199 qDebug() << __PRETTY_FUNCTION__;
201 if (QWidget *widget = m_panelContentStack->widget(index)) {
202 m_panelContentStack->removeWidget(widget);
203 m_panelTabBar->removeTab(index);
207 void TabbedPanel::repositionContextButtonBar()
209 qDebug() << __PRETTY_FUNCTION__;
211 m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X, height());
216 void TabbedPanel::resizePanel(const QSize &size)
218 qDebug() << __PRETTY_FUNCTION__;
220 resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH,
221 size.height() - PANEL_TOP_PADDING - PANEL_BOTTOM_PADDING);
224 move(size.width() - PANEL_TAB_BAR_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
226 move(size.width() - PANEL_TAB_BAR_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH, PANEL_TOP_PADDING);
228 m_panelBar->resizeBar(size);
230 m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X, size.height());
232 m_panelContentStack->resizeContentStack(size);
234 QPoint closedPosition(size.width() - PANEL_TAB_BAR_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
235 m_stateClosed->assignProperty(this, "pos", closedPosition);
237 QPoint openedPosition(size.width() - PANEL_TAB_BAR_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH,
239 m_stateOpened->assignProperty(this, "pos", openedPosition);
244 void TabbedPanel::setCurrentIndex(int index)
246 qDebug() << __PRETTY_FUNCTION__;
248 if ((index < m_panelContentStack->count()) && (index >= 0)) {
249 m_panelContentStack->setCurrentIndex(index);
254 m_panelContextButtonBar->setContextButtons(
255 static_cast<PanelBase *>(m_panelContentStack->widget(index))->contextButtons());
257 emit currentChanged(index);
261 void TabbedPanel::setTabsEnabled(const QList<int> &tabIndexes, bool enabled)
263 qDebug() << __PRETTY_FUNCTION__;
265 QButtonGroup *tabs = m_panelTabBar->tabs();
267 foreach (int tabIndex, tabIndexes) {
269 QAbstractButton *tabButton = tabs->button(tabIndex);
272 tabButton->setEnabled(enabled);
276 void TabbedPanel::stateChanged()
278 qDebug() << __PRETTY_FUNCTION__;
283 m_panelContextButtonBar->showContextButtonBar();