Modified existing classes to use the new PanelTabBar class and its methods
authorPekka Nissinen <pekka.nissinen@ixonos.com>
Mon, 16 Aug 2010 06:51:22 +0000 (09:51 +0300)
committerPekka Nissinen <pekka.nissinen@ixonos.com>
Mon, 16 Aug 2010 06:51:22 +0000 (09:51 +0300)
src/ui/mainwindow.cpp
src/ui/tabbedpanel.cpp
src/ui/tabbedpanel.h

index f8fc16a..31927a6 100644 (file)
@@ -322,7 +322,7 @@ void MainWindow::buildPanels()
     m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
     m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
 
-    connect(m_tabbedPanel, SIGNAL(tabChanged()),
+    connect(m_tabbedPanel, SIGNAL(panelClosed()),
             m_friendsListPanel, SLOT(clearFriendListFilter()));
 
     connect(m_mapView, SIGNAL(viewResized(QSize)),
index ec2aff2..2321ceb 100644 (file)
@@ -20,7 +20,6 @@
     USA.
 */
 
-#include <QButtonGroup>
 #include <QDebug>
 #include <QPropertyAnimation>
 #include <QSignalTransition>
 
 #include "panelbar.h"
 #include "panelcontent.h"
-#include "paneltab.h"
-#include "userinfo.h"
+#include "paneltabbar.h"
 
 #include "tabbedpanel.h"
 
 TabbedPanel::TabbedPanel(QWidget *parent)
     : QWidget(parent),
-      m_isOpen(false),
-      m_activeTab(-1)
+      m_isOpen(false)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -47,10 +44,16 @@ TabbedPanel::TabbedPanel(QWidget *parent)
     // --- TABS ---
     m_panelWidgetStack = new QStackedWidget(this);
 
-    m_tabButtonGroup = new QButtonGroup(this);
+    m_panelTabBar = new PanelTabBar(this);
 
-    connect(m_tabButtonGroup, SIGNAL(buttonPressed(int)),
-            this, SLOT(setActiveTab(int)));
+    connect(m_panelTabBar, SIGNAL(currentChanged(int)),
+            this, SLOT(showTab(int)));
+
+    connect(m_panelTabBar, SIGNAL(tabCloseRequested(int)),
+             this, SLOT(closePanel()));
+
+    connect(this, SIGNAL(panelClosed()),
+            m_panelTabBar, SLOT(deselectTabs()));
 
     // --- BAR ---
     m_panelBar = new PanelBar(this);
@@ -104,18 +107,8 @@ int TabbedPanel::insertTab(int index, QWidget *widget, const QIcon& icon)
     if(!widget)
         return -1;
 
-    int verticalStartPoint = 8;
-
     index = m_panelWidgetStack->insertWidget(index, widget);
-    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
+    m_panelTabBar->insertTab(index, icon);
 
     return index;
 }
@@ -126,10 +119,7 @@ void TabbedPanel::removeTab(int index)
 
     if(QWidget *widget = m_panelWidgetStack->widget(index)) {
         m_panelWidgetStack->removeWidget(widget);
-
-        QAbstractButton *tab = m_tabButtonGroup->button(index);
-        m_tabButtonGroup->removeButton(tab);
-        delete tab;
+        m_panelTabBar->removeTab(index);
     }
 }
 
@@ -149,6 +139,17 @@ void TabbedPanel::openPanel()
         emit toggleState();
 }
 
+void TabbedPanel::showTab(int index)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (index < m_panelWidgetStack->count() && index >= 0) {
+        m_panelWidgetStack->setCurrentIndex(index);
+        openPanel();
+        emit currentChanged(index);
+    }
+}
+
 void TabbedPanel::resizePanel(const QSize &size)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -173,25 +174,6 @@ void TabbedPanel::resizePanel(const QSize &size)
                                PANEL_TOP_PADDING));
 }
 
-void TabbedPanel::setActiveTab(int index)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    if(m_activeTab == -1) {
-        m_activeTab = index;
-        m_panelWidgetStack->setCurrentIndex(index);
-        emit tabChanged();
-        emit toggleState();
-    } else if(m_activeTab == index) {
-        m_activeTab = -1;
-        emit toggleState();
-    } else {
-        m_activeTab = index;
-        m_panelWidgetStack->setCurrentIndex(index);
-        emit tabChanged();
-    }
-}
-
 void TabbedPanel::stateChanged()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -201,11 +183,6 @@ void TabbedPanel::stateChanged()
         emit panelOpened();
     } else {
         m_isOpen = false;
-
-        m_tabButtonGroup->setExclusive(false);
-        m_tabButtonGroup->button(m_tabButtonGroup->checkedId())->setChecked(false);
-        m_tabButtonGroup->setExclusive(true);
-
         emit panelClosed();
     }
 }
index 91c03a5..5c9398a 100644 (file)
@@ -20,7 +20,6 @@
     USA.
 */
 
-
 #ifndef TABBEDPANEL_H
 #define TABBEDPANEL_H
 
 
 #include "panelcommon.h"
 
-class QButtonGroup;
-class QMouseEvent;
-class QPaintEvent;
-class QPixmap;
 class QPropertyAnimation;
-class QRect;
 class QSignalTransition;
 class QStackedWidget;
 class QState;
@@ -41,14 +35,13 @@ class QStateMachine;
 
 class PanelBar;
 class PanelContent;
+class PanelTabBar;
 
 /**
  * @brief Class for tabbed panels
  *
  * @author Kaj Wallin - kaj.wallin (at) ixonos.com
  * @author Pekka Nissinen - pekka.nissinen@ixonos.com
- *
- * @class TabbedPanel tabbedpanel.h "ui/tabbedpanel.h"
  */
 class TabbedPanel : public QWidget
 {
@@ -98,8 +91,6 @@ public:
      * Removes a tab and its widget from the panel at index position. The widget itself is not
      * deleted.
      *
-     * @todo: Fix tab drawing order
-     *
      * @param index Index of the tab
      */
     void removeTab(int index);
@@ -122,14 +113,14 @@ public slots:
      */
     void resizePanel(const QSize &size);
 
-private slots:
     /**
-     * @brief Sets the tab at given index active
+     * @brief Shows the tab at given index active
      *
      * @param index Index of the tab
      */
-    void setActiveTab(int index);
+    void showTab(int index);
 
+private slots:
     /**
      * @brief Internal slot used to track statemachine state
      */
@@ -140,6 +131,11 @@ private slots:
  ******************************************************************************/
 signals:
     /**
+     * @brief This signal is emitted whenever the current page index changes
+     */
+    void currentChanged(int index);
+
+    /**
      * @brief Signal that is sent when panel is closed
      *
      * @sa openPanel
@@ -156,12 +152,7 @@ signals:
     void panelOpened();
 
     /**
-     * @brief Signal that is sent when user has clicked another tab active
-     */
-    void tabChanged();
-
-    /**
-     * @brief Signal that is sent to state machine when state must be changed
+     * @brief Signal that is sent to state machine when panel state must be changed
      *
      * @sa openPanel
      * @sa closePanel
@@ -174,10 +165,6 @@ signals:
 private:
     bool m_isOpen;      ///< Boolean used to track the current state of the statemachine
 
-    int m_activeTab;    ///< Index of a active tab
-
-    QButtonGroup *m_tabButtonGroup; ///< Button groub for tab buttons
-
     QPropertyAnimation *m_panelAnimation;       ///< Animation for panel state changes
 
     QSignalTransition *m_panelTransitionClose;  ///< Transition signal for closing the panel
@@ -192,6 +179,7 @@ private:
 
     PanelBar *m_panelBar;                       ///< Widget for panel bar
     PanelContent *m_panelContent;               ///< Widget for panel content
+    PanelTabBar *m_panelTabBar;                 ///< Widget for panel tab bar
 };
 
 #endif // TABBEDPANEL_H