Merge branch 'new_panels' of https://vcs.maemo.org/git/situare into new_panels
authorSami Rämö <sami.ramo@ixonos.com>
Mon, 16 Aug 2010 09:02:59 +0000 (12:02 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Mon, 16 Aug 2010 12:16:57 +0000 (15:16 +0300)
 - Reviewed by Sami Rämö

Conflicts:
src/ui/panelbar.cpp
src/ui/paneltab.h
src/ui/tabbedpanel.cpp

src/ui/mainwindow.cpp
src/ui/panelbar.cpp
src/ui/panelcontent.h
src/ui/paneltab.cpp
src/ui/paneltab.h
src/ui/paneltabbar.cpp [new file with mode: 0644]
src/ui/paneltabbar.h [new file with mode: 0644]
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 9a426b1..1bfbfaf 100644 (file)
@@ -28,9 +28,9 @@
 
 #include "panelcommon.h"
 
-///< @todo requires clean-up
+///< @todo requires clean-up, there is some commented code
 
-PanelBar::PanelBar(QWidget *parent) //, Side side)
+PanelBar::PanelBar(QWidget *parent)
     : QWidget(parent)
 {
     qDebug() << __PRETTY_FUNCTION__;
index 839f64a..74fabd3 100644 (file)
@@ -44,7 +44,7 @@ public:
     /**
      * @brief Constructor
      *
-     * @param parent
+     * @param parent Parent
      */
     PanelContent(QWidget *parent = 0);
 
index bb5ab31..9d393c7 100644 (file)
@@ -43,8 +43,6 @@ PanelTab::PanelTab(QWidget *parent)
     m_tabPixmaps[1].load(":/res/images/tab_inactive2.png");
     m_tabPixmaps[2].load(":/res/images/tab_active.png");
 
-//    m_tabRect.setRect(TAB_WIDTH_ACTIVE - TAB_WIDTH, 0, TAB_WIDTH, TAB_HEIGHT);
-
     setCheckable(true);
 
     setFixedSize(TAB_WIDTH_ACTIVE, TAB_HEIGHT);
@@ -81,13 +79,10 @@ void PanelTab::mouseReleaseEvent(QMouseEvent *event)
     if(this->rect().contains(event->pos())) {
         click();
 
-        if(isChecked()) {
+        if(isChecked())
             setChecked(false);
-//            m_tabRect.setRect(TAB_WIDTH_ACTIVE - TAB_WIDTH, 0, TAB_WIDTH, TAB_HEIGHT);
-        } else {
+        else
             setChecked(true);
-//            m_tabRect.setRect(0, 0, TAB_WIDTH_ACTIVE, TAB_HEIGHT);
-        }
     }
 
     setDown(false);
index fe0c7f4..f4fe610 100644 (file)
 
 class QMouseEvent;
 
-///< @todo Many missing comments
+/**
+ * @brief Class for tab button
+ *
+ * @author Pekka Nissinen - pekka.nissinen@ixonos.com
+ */
 class PanelTab : public QToolButton
 {
     Q_OBJECT
@@ -35,7 +39,7 @@ public:
     /**
      * @brief Constructor
      *
-     * @param parent
+     * @param parent Parent
      */
     PanelTab(QWidget *parent = 0);
 
@@ -64,6 +68,7 @@ protected:
      */
     void mouseReleaseEvent(QMouseEvent *event);
 
+///< @todo parameter name missing (also in .cpp)
     /**
      * @brief Draws the tab button
      *
@@ -75,19 +80,22 @@ protected:
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
 public:
+    /**
+     * @brief This slot is used to change tab button state
+     */
     void setActive(bool state);
 
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    bool m_tabActive;
-    bool m_tabSelected;
+    bool m_tabActive;   ///< Boolean used to track whether the tab button is active or not
+    bool m_tabSelected; ///< Boolean used to track whether the tab button is selected or not
 
     ///< @todo magic, replace with enum?
-    QPixmap m_tabPixmaps[3];
+    QPixmap m_tabPixmaps[3];    ///< Pixmap table for tab button images
 
-    QRect m_tabRect;
+    QRect m_tabRect;            ///< Rect for the tab button
 };
 
 #endif // PANELTAB_H
diff --git a/src/ui/paneltabbar.cpp b/src/ui/paneltabbar.cpp
new file mode 100644 (file)
index 0000000..99c2776
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+    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 == index) {
+        m_activeTab = -1;
+        emit tabCloseRequested(index);
+    } else {
+        m_activeTab = index;
+        emit currentChanged(index);
+    }
+}
diff --git a/src/ui/paneltabbar.h b/src/ui/paneltabbar.h
new file mode 100644 (file)
index 0000000..3c2d4cf
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+    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 Sets the tab at current index active
+     *
+     * @param index Index of the tab
+     */
+    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
index a35d9aa..f534a86 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) ///< @todo magic
+      m_isOpen(false)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    ///< @todo Do not use this, REMOVE ALL OCCURENCES!
+    ///< @todo Do not use this, REMOVE ALL OCCURENCES IN ALL FILES!
     this->resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH, PANEL_HEIGHT);
     this->move(PANEL_CLOSED_X, PANEL_TOP_PADDING);
 
     // --- 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);
@@ -107,19 +110,8 @@ int TabbedPanel::insertTab(int index, QWidget *widget, const QIcon& icon)
     if(!widget)
         return -1;
 
-    ///< @todo magic
-    int verticalStartPoint = 8;
-
     index = m_panelWidgetStack->insertWidget(index, widget);
-    m_tabButtonGroup->addButton(new PanelTab(this), index);
-    m_tabButtonGroup->button(index)->setIcon(icon);
-
-    ///< @todo [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;
 }
@@ -130,10 +122,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);
     }
 }
 
@@ -154,6 +143,18 @@ void TabbedPanel::openPanel()
         emit toggleState();
 }
 
+void TabbedPanel::showTab(int index)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+///< @todo if ((first) && (second)) {
+    if (index < m_panelWidgetStack->count() && index >= 0) {
+        m_panelWidgetStack->setCurrentIndex(index);
+        openPanel();
+        emit currentChanged(index);
+    }
+}
+
 void TabbedPanel::resizePanel(const QSize &size)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -161,10 +162,9 @@ void TabbedPanel::resizePanel(const QSize &size)
     this->resize(PANEL_BAR_TABBED_WIDTH + PANEL_WIDTH,
                  size.height() - PANEL_TOP_PADDING - PANEL_BOTTOM_PADDING);
 
-    if(!m_isOpen) {
+    if (!m_isOpen) {
         this->move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH, PANEL_TOP_PADDING);
-    }
-    else {
+    } else {
         this->move(size.width() - PANEL_TAB_WIDTH - PANEL_BAR_WIDTH - PANEL_WIDTH,
                    PANEL_TOP_PADDING);
     }
@@ -181,27 +181,6 @@ void TabbedPanel::resizePanel(const QSize &size)
                                PANEL_TOP_PADDING));
 }
 
-void TabbedPanel::setActiveTab(int index)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    ///< @todo magic
-    ///< @todo short comments?
-    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__;
@@ -211,11 +190,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 06ab708..a54332c 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,6 +35,7 @@ class QStateMachine;
 
 class PanelBar;
 class PanelContent;
+class PanelTabBar;
 
 /**
  * @brief Class for tabbed panels
@@ -97,8 +92,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);
@@ -121,14 +114,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
      */
@@ -139,6 +132,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
@@ -155,12 +153,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
@@ -173,10 +166,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
@@ -191,6 +180,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