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>
32 #include "listitemcontextbuttonbar.h"
34 #include "panelbase.h"
35 #include "panelcontentstack.h"
36 #include "panelcontextbuttonbar.h"
37 #include "paneltabbar.h"
39 #include "tabbedpanel.h"
41 const int PANEL_CONTEXT_BUTTON_BAR_LEFT_X = 1;
42 const int PANEL_TAB_BAR_TOP_SPACING = 8;
44 TabbedPanel::TabbedPanel(QWidget *parent)
47 m_closeRequestPending(false)
49 qDebug() << __PRETTY_FUNCTION__;
51 const int PANEL_LEFT_X = 0;
52 const int PANEL_TOP_Y = 0;
54 resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH, PANEL_HEIGHT);
55 move(PANEL_CLOSED_X, PANEL_TOP_PADDING);
58 m_panelTabBar = new PanelTabBar(this);
59 m_panelTabBar->move(PANEL_LEFT_X, PANEL_TAB_BAR_TOP_SPACING);
61 connect(m_panelTabBar, SIGNAL(currentChanged(int)),
62 this, SLOT(setCurrentIndex(int)));
64 connect(m_panelTabBar, SIGNAL(sizeChangeRequested()),
65 this, SLOT(calculateMask()));
67 connect(m_panelTabBar, SIGNAL(tabCloseRequested(int)),
68 this, SLOT(closePanel()));
70 connect(this, SIGNAL(panelClosed()),
71 m_panelTabBar, SLOT(deselectTabs()));
74 m_panelBar = new PanelBar(this);
75 m_panelBar->move(PANEL_TAB_BAR_WIDTH, PANEL_TOP_Y);
77 // --- GENERIC PANEL CONTEXT BUTTON BAR ---
78 m_panelContextButtonBar = new PanelContextButtonBar(this);
79 m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X, PANEL_HEIGHT);
81 connect(m_panelContextButtonBar, SIGNAL(barHidden()),
82 this, SLOT(closePanel()));
84 connect(m_panelContextButtonBar, SIGNAL(positionChangeRequested()),
85 this, SLOT(repositionContextButtonBar()));
87 // --- LIST ITEM RELATED CONTEXT BUTTONS BAR ---
88 m_itemContextButtonBar = new ListItemContextButtonBar(this);
89 m_itemContextButtonBar->hide();
91 connect(this, SIGNAL(listItemSelectionChanged(bool)),
92 m_itemContextButtonBar, SLOT(onListItemSelectionChanged(bool)));
94 // --- PANEL CONTENT ---
95 m_panelContentStack = new PanelContentStack(this);
96 m_panelContentStack->move(PANEL_TAB_BAR_WIDTH + PANEL_BAR_WIDTH, PANEL_TOP_Y);
97 m_panelContentStack->stackUnder(m_itemContextButtonBar);
99 // --- PANEL ANIMATION ---
100 QStateMachine *panelStateMachine = new QStateMachine(this);
102 m_stateClosed = new QState(panelStateMachine);
103 m_stateOpened = new QState(panelStateMachine);
105 QPropertyAnimation *panelAnimation = new QPropertyAnimation(this, "pos", this);
107 panelStateMachine->setInitialState(m_stateClosed);
109 QSignalTransition *panelTransitionOpen = m_stateClosed->addTransition(this,
110 SIGNAL(toggleState()),
112 panelTransitionOpen->addAnimation(panelAnimation);
114 QSignalTransition *panelTransitionClose = m_stateOpened->addTransition(this,
115 SIGNAL(toggleState()),
117 panelTransitionClose->addAnimation(panelAnimation);
119 connect(panelAnimation, SIGNAL(finished()),
120 this, SLOT(stateChanged()));
122 QPoint closedPosition(PANEL_CLOSED_X, PANEL_TOP_PADDING);
123 m_stateClosed->assignProperty(this, "pos", closedPosition);
125 QPoint openedPosition(PANEL_OPENED_X, PANEL_TOP_PADDING);
126 m_stateOpened->assignProperty(this, "pos", openedPosition);
128 panelStateMachine->start();
131 int TabbedPanel::addTab(QWidget *widget, const QIcon& icon)
133 qDebug() << __PRETTY_FUNCTION__;
135 const int APPEND_INDEX = -1;
137 return insertTab(APPEND_INDEX, widget, icon);
140 void TabbedPanel::calculateMask()
142 qDebug() << __PRETTY_FUNCTION__;
144 QRect panelTabBarRect = m_panelTabBar->rect();
145 QRect panelContextButtonBarRect = m_panelContextButtonBar->rect();
146 int panelContextButtonBarY = height() - panelContextButtonBarRect.height();
149 panelContextButtonBarY = height();
151 QRegion panelTabBarRegion(0, PANEL_TAB_BAR_TOP_SPACING,
152 panelTabBarRect.width(), panelTabBarRect.height());
153 QRegion panelContextButtonBarRegion(0, panelContextButtonBarY,
154 panelContextButtonBarRect.width(),
155 panelContextButtonBarRect.height());
156 QRegion panelContentRegion(panelTabBarRect.right() + 1, 0,
157 PANEL_WIDTH + PANEL_BAR_WIDTH, height());
158 QRegion panelRegion = panelTabBarRegion + panelContentRegion + panelContextButtonBarRegion;
160 setMask(panelRegion);
163 void TabbedPanel::closePanel()
165 qDebug() << __PRETTY_FUNCTION__;
170 if (m_panelContextButtonBar->isBarVisible()) {
171 m_closeRequestPending = true;
172 m_panelContextButtonBar->hideContextButtonBar();
176 } else if (m_closeRequestPending) {
177 m_closeRequestPending = false;
182 int TabbedPanel::insertTab(int index, QWidget *widget, const QIcon& icon)
184 qDebug() << __PRETTY_FUNCTION__;
186 index = m_panelContentStack->insertWidget(index, widget);
187 m_panelTabBar->insertTab(index, icon);
192 void TabbedPanel::openPanel(QWidget *widget)
194 qDebug() << __PRETTY_FUNCTION__;
197 m_panelTabBar->selectTab(m_panelContentStack->indexOf(widget));
198 } else if (!m_open) {
199 if (!m_closeRequestPending) {
206 void TabbedPanel::removeTab(int index)
208 qDebug() << __PRETTY_FUNCTION__;
210 if (QWidget *widget = m_panelContentStack->widget(index)) {
211 m_panelContentStack->removeWidget(widget);
212 m_panelTabBar->removeTab(index);
216 void TabbedPanel::repositionContextButtonBar()
218 qDebug() << __PRETTY_FUNCTION__;
220 m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X, height());
225 void TabbedPanel::resizePanel(const QSize &size)
227 qDebug() << __PRETTY_FUNCTION__;
229 resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH,
230 size.height() - PANEL_TOP_PADDING - PANEL_BOTTOM_PADDING);
233 move(size.width() - PANEL_TAB_BAR_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
235 move(size.width() - PANEL_TAB_BAR_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH, PANEL_TOP_PADDING);
237 m_panelBar->resizeBar(size);
239 m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X, size.height());
241 m_panelContentStack->resizeContentStack(size);
243 QPoint closedPosition(size.width() - PANEL_TAB_BAR_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
244 m_stateClosed->assignProperty(this, "pos", closedPosition);
246 QPoint openedPosition(size.width() - PANEL_TAB_BAR_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH,
248 m_stateOpened->assignProperty(this, "pos", openedPosition);
253 void TabbedPanel::setCurrentIndex(int index)
255 qDebug() << __PRETTY_FUNCTION__;
257 if ((index < m_panelContentStack->count()) && (index >= 0)) {
258 m_panelContentStack->setCurrentIndex(index);
263 m_panelContextButtonBar->setContextButtons(
264 static_cast<PanelBase *>(m_panelContentStack->widget(index))->genericPanelButtons());
266 QWidget *itemContextButtons = static_cast<PanelBase *>(m_panelContentStack->widget(index))->itemButtons();
267 m_itemContextButtonBar->setContextButtons(itemContextButtons);
269 emit currentChanged(index);
273 void TabbedPanel::setTabsEnabled(const QList<int> &tabIndexes, bool enabled)
275 qDebug() << __PRETTY_FUNCTION__;
277 QButtonGroup *tabs = m_panelTabBar->tabs();
279 foreach (int tabIndex, tabIndexes) {
280 QAbstractButton *tabButton = tabs->button(tabIndex);
283 if (tabButton->isChecked())
286 tabButton->setEnabled(enabled);
291 void TabbedPanel::stateChanged()
293 qDebug() << __PRETTY_FUNCTION__;
298 m_panelContextButtonBar->showContextButtonBar();