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>
26 #include <QSignalTransition>
27 #include <QStackedWidget>
28 #include <QStateMachine>
31 #include "panelbase.h"
32 #include "panelcontentstack.h"
33 #include "panelcontextbuttonbar.h"
34 #include "paneltabbar.h"
36 #include "tabbedpanel.h"
38 const int PANEL_CONTEXT_BUTTON_BAR_LEFT_X = 1;
39 const int PANEL_TAB_BAR_TOP_SPACING = 8;
41 TabbedPanel::TabbedPanel(QWidget *parent)
44 m_closeRequestPending(false)
46 qDebug() << __PRETTY_FUNCTION__;
48 const int PANEL_LEFT_X = 0;
49 const int PANEL_TOP_Y = 0;
51 resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH, PANEL_HEIGHT);
52 move(PANEL_CLOSED_X, PANEL_TOP_PADDING);
55 m_panelTabBar = new PanelTabBar(this);
56 m_panelTabBar->move(PANEL_LEFT_X, PANEL_TAB_BAR_TOP_SPACING);
58 connect(m_panelTabBar, SIGNAL(currentChanged(int)),
59 this, SLOT(setCurrentIndex(int)));
61 connect(m_panelTabBar, SIGNAL(sizeChangeRequested()),
62 this, SLOT(calculateMask()));
64 connect(m_panelTabBar, SIGNAL(tabCloseRequested(int)),
65 this, SLOT(closePanel()));
67 connect(this, SIGNAL(panelClosed()),
68 m_panelTabBar, SLOT(deselectTabs()));
71 m_panelBar = new PanelBar(this);
72 m_panelBar->move(PANEL_TAB_BAR_WIDTH, PANEL_TOP_Y);
74 // --- CONTEXT BUTTON BAR ---
75 m_panelContextButtonBar = new PanelContextButtonBar(this);
76 m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X, PANEL_HEIGHT);
78 connect(m_panelContextButtonBar, SIGNAL(barHidden()),
79 this, SLOT(closePanel()));
81 connect(m_panelContextButtonBar, SIGNAL(positionChangeRequested()),
82 this, SLOT(repositionContextButtonBar()));
84 // --- PANEL CONTENT ---
85 m_panelContentStack = new PanelContentStack(this);
86 m_panelContentStack->move(PANEL_TAB_BAR_WIDTH + PANEL_BAR_WIDTH, PANEL_TOP_Y);
88 // --- PANEL ANIMATION ---
89 QStateMachine *panelStateMachine = new QStateMachine(this);
91 m_stateClosed = new QState(panelStateMachine);
92 m_stateOpened = new QState(panelStateMachine);
94 QPropertyAnimation *panelAnimation = new QPropertyAnimation(this, "pos", this);
96 panelStateMachine->setInitialState(m_stateClosed);
98 QSignalTransition *panelTransitionOpen = m_stateClosed->addTransition(this,
99 SIGNAL(toggleState()),
101 panelTransitionOpen->addAnimation(panelAnimation);
103 QSignalTransition *panelTransitionClose = m_stateOpened->addTransition(this,
104 SIGNAL(toggleState()),
106 panelTransitionClose->addAnimation(panelAnimation);
108 connect(panelAnimation, SIGNAL(finished()),
109 this, SLOT(stateChanged()));
111 QPoint closedPosition(PANEL_CLOSED_X, PANEL_TOP_PADDING);
112 m_stateClosed->assignProperty(this, "pos", closedPosition);
114 QPoint openedPosition(PANEL_OPENED_X, PANEL_TOP_PADDING);
115 m_stateOpened->assignProperty(this, "pos", openedPosition);
117 panelStateMachine->start();
120 int TabbedPanel::addTab(QWidget *widget, const QIcon& icon)
122 qDebug() << __PRETTY_FUNCTION__;
124 const int APPEND_INDEX = -1;
126 return insertTab(APPEND_INDEX, widget, icon);
129 void TabbedPanel::calculateMask()
131 qDebug() << __PRETTY_FUNCTION__;
133 QRect panelTabBarRect = m_panelTabBar->rect();
134 QRect panelContextButtonBarRect = m_panelContextButtonBar->rect();
135 int panelContextButtonBarY = height() - panelContextButtonBarRect.height();
138 panelContextButtonBarY = height();
140 QRegion panelTabBarRegion(0, PANEL_TAB_BAR_TOP_SPACING,
141 panelTabBarRect.width(), panelTabBarRect.height());
142 QRegion panelContextButtonBarRegion(0, panelContextButtonBarY,
143 panelContextButtonBarRect.width(),
144 panelContextButtonBarRect.height());
145 QRegion panelContentRegion(panelTabBarRect.right() + 1, 0,
146 PANEL_WIDTH + PANEL_BAR_WIDTH, height());
147 QRegion panelRegion = panelTabBarRegion + panelContentRegion + panelContextButtonBarRegion;
149 setMask(panelRegion);
152 void TabbedPanel::closePanel()
154 qDebug() << __PRETTY_FUNCTION__;
159 if (m_panelContextButtonBar->isBarVisible()) {
160 m_closeRequestPending = true;
161 m_panelContextButtonBar->hideContextButtonBar();
165 } else if (m_closeRequestPending) {
166 m_closeRequestPending = false;
171 int TabbedPanel::insertTab(int index, QWidget *widget, const QIcon& icon)
173 qDebug() << __PRETTY_FUNCTION__;
175 index = m_panelContentStack->insertWidget(index, widget);
176 m_panelTabBar->insertTab(index, icon);
181 void TabbedPanel::openPanel(QWidget *widget)
183 qDebug() << __PRETTY_FUNCTION__;
186 m_panelTabBar->selectTab(m_panelContentStack->indexOf(widget));
187 } else if (!m_open) {
188 if (!m_closeRequestPending) {
195 void TabbedPanel::removeTab(int index)
197 qDebug() << __PRETTY_FUNCTION__;
199 if (QWidget *widget = m_panelContentStack->widget(index)) {
200 m_panelContentStack->removeWidget(widget);
201 m_panelTabBar->removeTab(index);
205 void TabbedPanel::repositionContextButtonBar()
207 qDebug() << __PRETTY_FUNCTION__;
209 m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X, height());
214 void TabbedPanel::resizePanel(const QSize &size)
216 qDebug() << __PRETTY_FUNCTION__;
218 resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH,
219 size.height() - PANEL_TOP_PADDING - PANEL_BOTTOM_PADDING);
222 move(size.width() - PANEL_TAB_BAR_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
224 move(size.width() - PANEL_TAB_BAR_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH, PANEL_TOP_PADDING);
226 m_panelBar->resizeBar(size);
228 m_panelContextButtonBar->move(PANEL_CONTEXT_BUTTON_BAR_LEFT_X, size.height());
230 m_panelContentStack->resizeContentStack(size);
232 QPoint closedPosition(size.width() - PANEL_TAB_BAR_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
233 m_stateClosed->assignProperty(this, "pos", closedPosition);
235 QPoint openedPosition(size.width() - PANEL_TAB_BAR_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH,
237 m_stateOpened->assignProperty(this, "pos", openedPosition);
242 void TabbedPanel::setCurrentIndex(int index)
244 qDebug() << __PRETTY_FUNCTION__;
246 if ((index < m_panelContentStack->count()) && (index >= 0)) {
247 m_panelContentStack->setCurrentIndex(index);
252 m_panelContextButtonBar->setContextButtons(
253 static_cast<PanelBase *>(m_panelContentStack->widget(index))->contextButtons());
255 emit currentChanged(index);
259 void TabbedPanel::stateChanged()
261 qDebug() << __PRETTY_FUNCTION__;
266 m_panelContextButtonBar->showContextButtonBar();