Separated the tab section into a new class PanelTabBar
authorPekka Nissinen <pekka.nissinen@ixonos.com>
Mon, 16 Aug 2010 06:29:58 +0000 (09:29 +0300)
committerPekka Nissinen <pekka.nissinen@ixonos.com>
Mon, 16 Aug 2010 06:29:58 +0000 (09:29 +0300)
src/ui/paneltabbar.cpp [new file with mode: 0644]
src/ui/paneltabbar.h [new file with mode: 0644]

diff --git a/src/ui/paneltabbar.cpp b/src/ui/paneltabbar.cpp
new file mode 100644 (file)
index 0000000..7f7b313
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+    Situare - A location system for Facebook
+    Copyright (C) 2010  Ixonos Plc. Authors:
+
+        Pekka Nissinen - pekka.nissinen@ixonos.com
+
+    Situare is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    version 2 as published by the Free Software Foundation.
+
+    Situare is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Situare; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+    USA.
+*/
+
+#include <QDebug>
+#include <QButtonGroup>
+
+#include "paneltab.h"
+
+#include "paneltabbar.h"
+
+PanelTabBar::PanelTabBar(QWidget *parent)
+    : QWidget(parent),
+      m_activeTab(-1)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_tabButtonGroup = new QButtonGroup(this);
+
+    connect(m_tabButtonGroup, SIGNAL(buttonPressed(int)),
+                this, SLOT(setCurrentIndex(int)));
+}
+
+int PanelTabBar::addTab(const QIcon& icon)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return insertTab(-1, icon);
+}
+
+void PanelTabBar::deselectTabs()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_tabButtonGroup->setExclusive(false);
+    m_tabButtonGroup->button(m_tabButtonGroup->checkedId())->setChecked(false);
+    m_tabButtonGroup->setExclusive(true);
+}
+
+int PanelTabBar::insertTab(int index, const QIcon& icon)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    int verticalStartPoint = 8;
+
+    m_tabButtonGroup->addButton(new PanelTab(this), index);
+    m_tabButtonGroup->button(index)->setIcon(icon);
+
+    // [BEGIN]: Purkkaa (to be removed ASAP!!!)
+    if(index > 0)
+        verticalStartPoint += 65 * index;
+
+    m_tabButtonGroup->button(index)->move(0, verticalStartPoint);
+    // [END]: Purkkaa
+
+    return index;
+}
+
+void PanelTabBar::removeTab(int index)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if(QAbstractButton *tab = m_tabButtonGroup->button(index)) {
+        m_tabButtonGroup->removeButton(tab);
+        delete tab;
+    }
+}
+
+void PanelTabBar::setCurrentIndex(int index)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if(m_activeTab == -1) {
+        m_activeTab = index;
+//        m_panelWidgetStack->setCurrentIndex(index);
+        emit currentChanged(index);
+//        emit toggleState();
+    } else if(m_activeTab == index) {
+        m_activeTab = -1;
+        emit tabCloseRequested(index);
+//        emit toggleState();
+    } else {
+        m_activeTab = index;
+//        m_panelWidgetStack->setCurrentIndex(index);
+        emit currentChanged(index);
+    }
+}
diff --git a/src/ui/paneltabbar.h b/src/ui/paneltabbar.h
new file mode 100644 (file)
index 0000000..8c71b56
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+    Situare - A location system for Facebook
+    Copyright (C) 2010  Ixonos Plc. Authors:
+
+        Pekka Nissinen - pekka.nissinen@ixonos.com
+
+    Situare is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    version 2 as published by the Free Software Foundation.
+
+    Situare is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Situare; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+    USA.
+*/
+
+#ifndef PANELTABBAR_H
+#define PANELTABBAR_H
+
+#include <QWidget>
+
+class QButtonGroup;
+
+/**
+ * @brief Class for tab bar
+ *
+ * @author Pekka Nissinen - pekka.nissinen@ixonos.com
+ */
+class PanelTabBar : public QWidget
+{
+    Q_OBJECT
+
+public:
+    /**
+     * @brief Constructor
+     *
+     * @param parent Parent
+     */
+    PanelTabBar(QWidget *parent = 0);
+
+/*******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
+public:
+    /**
+     * @brief Adds a tab
+     *
+     * Adds a tab with icon and returns the index of the inserted tab
+     *
+     * @param icon Icon of the tab
+     */
+    int addTab(const QIcon& icon);
+
+    /**
+     * @brief Inserts a tab
+     *
+     * Inserts a tab with icon at the specified index and returns the index of the inserted tab.
+     * If index is out of range, the tab is appended.
+     *
+     * @param index Index of the tab
+     * @param icon Icon of the tab
+     */
+    int insertTab(int index, const QIcon& icon);
+
+    /**
+     * @brief Removes a tab
+     *
+     * Removes a tab at index position
+     *
+     * @todo: Fix tab drawing order
+     *
+     * @param index Index of the tab
+     */
+    void removeTab(int index);
+
+public slots:
+    /**
+     * @brief This slot is used to clear tab selections
+     */
+    void deselectTabs();
+
+    /**
+     * @brief Internal slot used to track statemachine state
+     */
+    void setCurrentIndex(int index);
+
+/*******************************************************************************
+ * SIGNALS
+ ******************************************************************************/
+signals:
+    /**
+     * @brief This signal is emitted whenever the current tab index changes
+     */
+    void currentChanged(int index);
+
+    /**
+     * @brief This signal is emitted whenever user wants to close a tab
+     */
+    void tabCloseRequested(int index);
+
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
+private:
+    int m_activeTab;    ///< Index of a active tab
+
+    QButtonGroup *m_tabButtonGroup; ///< Button groub for tab buttons
+};
+
+#endif // PANELTABBAR_H