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>
27 #include "paneltabbar.h"
29 const int APPEND_INDEX = -1;
30 const int NO_ACTIVE_TABS = -1;
32 PanelTabBar::PanelTabBar(QWidget *parent)
34 m_activeTab(NO_ACTIVE_TABS)
36 qDebug() << __PRETTY_FUNCTION__;
38 m_tabButtonGroup = new QButtonGroup(this);
40 connect(m_tabButtonGroup, SIGNAL(buttonPressed(int)),
41 this, SLOT(setCurrentIndex(int)));
44 int PanelTabBar::addTab(const QIcon& icon)
46 qDebug() << __PRETTY_FUNCTION__;
48 return insertTab(APPEND_INDEX, icon);
51 void PanelTabBar::deselectTabs()
53 qDebug() << __PRETTY_FUNCTION__;
55 m_tabButtonGroup->setExclusive(false);
56 m_tabButtonGroup->button(m_tabButtonGroup->checkedId())->setChecked(false);
57 m_tabButtonGroup->setExclusive(true);
60 int PanelTabBar::insertTab(int index, const QIcon& icon)
62 qDebug() << __PRETTY_FUNCTION__;
64 if (index == APPEND_INDEX)
65 m_tabButtonGroup->addButton(new PanelTab(this));
67 m_tabButtonGroup->addButton(new PanelTab(this), index);
69 m_tabButtonGroup->button(index)->setIcon(icon);
76 void PanelTabBar::removeTab(int index)
78 qDebug() << __PRETTY_FUNCTION__;
80 if (QAbstractButton *tab = m_tabButtonGroup->button(index)) {
81 m_tabButtonGroup->removeButton(tab);
88 void PanelTabBar::selectTab(int index)
90 qDebug() << __PRETTY_FUNCTION__;
92 if (!m_tabButtonGroup->button(index)->isChecked())
93 m_tabButtonGroup->button(index)->click();
96 void PanelTabBar::setCurrentIndex(int index)
98 qDebug() << __PRETTY_FUNCTION__;
100 if (m_activeTab == index) {
101 m_activeTab = NO_ACTIVE_TABS;
102 emit tabCloseRequested(index);
105 emit currentChanged(index);
109 void PanelTabBar::setUpTabLayout()
111 qDebug() << __PRETTY_FUNCTION__;
113 const int TAB_BUTTON_STEPPING = 65;
115 QList<QAbstractButton *> tabList = m_tabButtonGroup->buttons();
117 for (int i = 0; i < tabList.size(); i ++) {
118 tabList.at(i)->move(0, i * TAB_BUTTON_STEPPING);