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);
90 connect(this, SIGNAL(listItemSelectionChanged(bool)),
91 m_itemContextButtonBar, SLOT(onListItemSelectionChanged(bool)));
93 // --- PANEL CONTENT ---
94 m_panelContentStack = new PanelContentStack(this);
95 m_panelContentStack->move(PANEL_TAB_BAR_WIDTH + PANEL_BAR_WIDTH, PANEL_TOP_Y);
96 m_panelContentStack->stackUnder(m_itemContextButtonBar);
98 // --- PANEL ANIMATION ---
99 QStateMachine *panelStateMachine = new QStateMachine(this);
101 m_stateClosed = new QState(panelStateMachine);
102 m_stateOpened = new QState(panelStateMachine);
104 QPropertyAnimation *panelAnimation = new QPropertyAnimation(this, "pos", this);
106 panelStateMachine->setInitialState(m_stateClosed);
108 QSignalTransition *panelTransitionOpen = m_stateClosed->addTransition(this,
109 SIGNAL(toggleState()),
111 panelTransitionOpen->addAnimation(panelAnimation);
113 QSignalTransition *panelTransitionClose = m_stateOpened->addTransition(this,
114 SIGNAL(toggleState()),
116 panelTransitionClose->addAnimation(panelAnimation);
118 connect(panelAnimation, SIGNAL(finished()),
119 this, SLOT(stateChanged()));
121 QPoint closedPosition(PANEL_CLOSED_X, PANEL_TOP_PADDING);
122 m_stateClosed->assignProperty(this, "pos", closedPosition);
124 QPoint openedPosition(PANEL_OPENED_X, PANEL_TOP_PADDING);
125 m_stateOpened->assignProperty(this, "pos", openedPosition);
127 panelStateMachine->start();
130 int TabbedPanel::addTab(QWidget *widget, const QIcon& icon)
132 qDebug() << __PRETTY_FUNCTION__;
134 const int APPEND_INDEX = -1;
136 return insertTab(APPEND_INDEX, widget, icon);
139 void TabbedPanel::calculateMask()
141 qDebug() << __PRETTY_FUNCTION__;
143 QRect panelTabBarRect = m_panelTabBar->rect();
144 QRect panelContextButtonBarRect = m_panelContextButtonBar->rect();
145 int panelContextButtonBarY = height() - panelContextButtonBarRect.height();
148 panelContextButtonBarY = height();
150 QRegion panelTabBarRegion(0, PANEL_TAB_BAR_TOP_SPACING,
151 panelTabBarRect.width(), panelTabBarRect.height());
152 QRegion panelContextButtonBarRegion(0, panelContextButtonBarY,
153 panelContextButtonBarRect.width(),
154 panelContextButtonBarRect.height());
155 QRegion panelContentRegion(panelTabBarRect.right() + 1, 0,
156 PANEL_WIDTH + PANEL_BAR_WIDTH, height());
157 QRegion panelRegion = panelTabBarRegion + panelContentRegion + panelContextButtonBarRegion;
159 setMask(panelRegion);
162 void TabbedPanel::closePanel()
164 qDebug() << __PRETTY_FUNCTION__;
169 if (m_panelContextButtonBar->isBarVisible()) {
170 m_closeRequestPending = true;
171 m_panelContextButtonBar->hideContextButtonBar();
175 } else if (m_closeRequestPending) {
176 m_closeRequestPending = false;
181 int TabbedPanel::insertTab(int index, QWidget *widget, const QIcon& icon)
183 qDebug() << __PRETTY_FUNCTION__;
185 index = m_panelContentStack->insertWidget(index, widget);
186 m_panelTabBar->insertTab(index, icon);
191 void TabbedPanel::openPanel(QWidget *widget)
193 qDebug() << __PRETTY_FUNCTION__;
196 m_panelTabBar->selectTab(m_panelContentStack->indexOf(widget));
197 } else if (!m_open) {
198 if (!m_closeRequestPending) {
205 void TabbedPanel::removeTab(int index)
207 qDebug() << __PRETTY_FUNCTION__;
209 if (QWidget *widget = m_panelContentStack->widget(index)) {
210 m_panelContentStack->removeWidget(widget);
211 m_panelTabBar->removeTab(index);
215 void TabbedPanel::repositionContextButtonBar()
217 qDebug() << __PRETTY_FUNCTION__;
219 m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X, height());
224 void TabbedPanel::resizePanel(const QSize &size)
226 qDebug() << __PRETTY_FUNCTION__;
228 resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH,
229 size.height() - PANEL_TOP_PADDING - PANEL_BOTTOM_PADDING);
232 move(size.width() - PANEL_TAB_BAR_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
234 move(size.width() - PANEL_TAB_BAR_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH, PANEL_TOP_PADDING);
236 m_panelBar->resizeBar(size);
238 m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X, size.height());
240 m_panelContentStack->resizeContentStack(size);
242 QPoint closedPosition(size.width() - PANEL_TAB_BAR_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
243 m_stateClosed->assignProperty(this, "pos", closedPosition);
245 QPoint openedPosition(size.width() - PANEL_TAB_BAR_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH,
247 m_stateOpened->assignProperty(this, "pos", openedPosition);
252 void TabbedPanel::setCurrentIndex(int index)
254 qDebug() << __PRETTY_FUNCTION__;
256 if ((index < m_panelContentStack->count()) && (index >= 0)) {
257 m_panelContentStack->setCurrentIndex(index);
262 m_panelContextButtonBar->setContextButtons(
263 static_cast<PanelBase *>(m_panelContentStack->widget(index))->genericPanelButtons());
265 QWidget *itemContextButtons = static_cast<PanelBase *>(m_panelContentStack->widget(index))->itemButtons();
266 m_itemContextButtonBar->setContextButtons(itemContextButtons);
268 emit currentChanged(index);
272 void TabbedPanel::setTabsEnabled(const QList<int> &tabIndexes, bool enabled)
274 qDebug() << __PRETTY_FUNCTION__;
276 QButtonGroup *tabs = m_panelTabBar->tabs();
278 foreach (int tabIndex, tabIndexes) {
279 QAbstractButton *tabButton = tabs->button(tabIndex);
282 if (tabButton->isChecked())
285 tabButton->setEnabled(enabled);
290 void TabbedPanel::stateChanged()
292 qDebug() << __PRETTY_FUNCTION__;
297 m_panelContextButtonBar->showContextButtonBar();