2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Pekka Nissinen - pekka.nissinen@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 #include <QButtonGroup>
25 #include "panelcommon.h"
28 #include "paneltabbar.h"
30 const int APPEND_INDEX = -1;
31 const int NO_ACTIVE_TABS = -1;
33 PanelTabBar::PanelTabBar(QWidget *parent)
35 m_activeTab(NO_ACTIVE_TABS)
37 qDebug() << __PRETTY_FUNCTION__;
39 setFixedWidth(PANEL_TAB_BAR_WIDTH);
41 m_tabButtonGroup = new QButtonGroup(this);
43 connect(m_tabButtonGroup, SIGNAL(buttonPressed(int)),
44 this, SLOT(setCurrentIndex(int)));
47 int PanelTabBar::addTab(const QIcon& icon)
49 qDebug() << __PRETTY_FUNCTION__;
51 return insertTab(APPEND_INDEX, icon);
54 void PanelTabBar::deselectTabs()
56 qDebug() << __PRETTY_FUNCTION__;
58 m_activeTab = NO_ACTIVE_TABS;
60 m_tabButtonGroup->setExclusive(false);
61 m_tabButtonGroup->button(m_tabButtonGroup->checkedId())->setChecked(false);
62 m_tabButtonGroup->setExclusive(true);
65 int PanelTabBar::insertTab(int index, const QIcon& icon)
67 qDebug() << __PRETTY_FUNCTION__;
69 if (index == APPEND_INDEX)
70 m_tabButtonGroup->addButton(new PanelTab(this));
72 m_tabButtonGroup->addButton(new PanelTab(this), index);
74 m_tabButtonGroup->button(index)->setIcon(icon);
81 void PanelTabBar::removeTab(int index)
83 qDebug() << __PRETTY_FUNCTION__;
85 if (QAbstractButton *tab = m_tabButtonGroup->button(index)) {
86 m_tabButtonGroup->removeButton(tab);
93 void PanelTabBar::selectTab(int index)
95 qDebug() << __PRETTY_FUNCTION__;
97 if (!m_tabButtonGroup->button(index)->isChecked())
98 m_tabButtonGroup->button(index)->click();
101 void PanelTabBar::setCurrentIndex(int index)
103 qDebug() << __PRETTY_FUNCTION__;
105 if (m_activeTab == index) {
106 m_activeTab = NO_ACTIVE_TABS;
107 emit tabCloseRequested(index);
110 emit currentChanged(index);
114 void PanelTabBar::setUpTabLayout()
116 qDebug() << __PRETTY_FUNCTION__;
118 const int TAB_BUTTON_STEPPING = 65;
120 QList<QAbstractButton *> tabList = m_tabButtonGroup->buttons();
121 int tabBarHeight = 0;
122 for (int i = 0; i < tabList.size(); i ++) {
123 tabList.at(i)->move(0, i * TAB_BUTTON_STEPPING);
124 tabBarHeight += TAB_BUTTON_STEPPING;
127 setFixedHeight(tabBarHeight);
129 emit sizeChangeRequested();
132 QButtonGroup * PanelTabBar::tabs() const
134 qDebug() << __PRETTY_FUNCTION__;
136 return m_tabButtonGroup;