Removed a few constants from panelcommon.h (that really weren't common at all) and...
[situare] / src / ui / paneltabbar.cpp
index 4decac6..e21d63f 100644 (file)
 
 #include "paneltabbar.h"
 
+const int NO_ACTIVE_TABS = -1;
+
 PanelTabBar::PanelTabBar(QWidget *parent)
     : QWidget(parent),
-      m_activeTab(-1) ///< @todo magic
+      m_activeTab(NO_ACTIVE_TABS)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -60,19 +62,10 @@ int PanelTabBar::insertTab(int index, const QIcon& icon)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    const int TAB_BAR_TOP_SPACING = 8;
-
-    int verticalStartPoint = TAB_BAR_TOP_SPACING;
-
     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
+    setUpTabLayout();
 
     return index;
 }
@@ -84,6 +77,8 @@ void PanelTabBar::removeTab(int index)
     if (QAbstractButton *tab = m_tabButtonGroup->button(index)) {
         m_tabButtonGroup->removeButton(tab);
         delete tab;
+
+        setUpTabLayout();
     }
 }
 
@@ -100,11 +95,23 @@ void PanelTabBar::setCurrentIndex(int index)
     qDebug() << __PRETTY_FUNCTION__;
 
     if (m_activeTab == index) {
-        ///< @todo magic
-        m_activeTab = -1;
+        m_activeTab = NO_ACTIVE_TABS;
         emit tabCloseRequested(index);
     } else {
         m_activeTab = index;
         emit currentChanged(index);
     }
 }
+
+void PanelTabBar::setUpTabLayout()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    const int TAB_BUTTON_STEPPING = 65;
+
+    QList<QAbstractButton *> tabList = m_tabButtonGroup->buttons();
+
+    for (int i = 0; i < tabList.size(); i ++) {
+        tabList.at(i)->move(0, i * TAB_BUTTON_STEPPING);
+    }
+}