Commits

Ivan Andrianov committed b02ef80

Fix

committer: PayableOnDeath <>

Comments (0)

Files changed (5)

-#include <QtCore>
-#include <QtGui>
-#include <QtWebKit>
 #include "mainwindow.h"
 
 int main(int argc, char *argv[])

src/mainwindow.cpp

 #include "mainwindow.h"
+#include "tabwidget.h"
+#include "tabmanager.h"
+
+TabManager * MainWindow::m_tabManager = 0;
+int MainWindow::m_count = 0;
 
 MainWindow::MainWindow(QWidget * parent)
         : QMainWindow(parent)
 {
     setupUi(this);
+
+    m_tabWidget = new TabWidget(m_centralWidget);
+    QVBoxLayout * layout = new QVBoxLayout(m_centralWidget);
+    layout->addWidget(m_tabWidget, 1);
+
+    m_count++;
+    if(m_count == 1)
+    {
+        m_tabManager = new TabManager(m_tabWidget, m_centralWidget);
+    }
+
+    m_tabManager->addTab();
+    m_tabManager->addTab();
+    m_tabManager->addTab();
 }
+
+MainWindow::~MainWindow()
+{
+    m_count--;
+    if(m_count == 0)
+    {
+        m_tabManager->deleteLater();
+    }
+}
+
+TabManager * MainWindow::tabManager()
+{
+    return m_tabManager;
+}
 #ifndef MAINWINDOW_H
 #define MAINWINDOW_H
 
+#include <QtCore>
+#include <QtGui>
+#include <QtWebKit>
 #include "ui_mainwindow.h"
 
+class TabWidget;
+class TabManager;
+
 class MainWindow
         : public QMainWindow
         , private Ui::MainWindow
 
 public:
     MainWindow(QWidget * parent = 0);
+    ~MainWindow();
+
+private:
+    TabWidget * m_tabWidget;
+    static TabManager * m_tabManager;
+    static int m_count;
+    static TabManager * tabManager();
 };
 
 #endif // MAINWINDOW_H

src/tabmanager.cpp

 #include "tabmanager.h"
 #include "tab.h"
 
-TabManager::TabManager(QTabWidget * employee, QObject * parent)
+TabManager::TabManager(QTabWidget * tabWidget, QObject * parent)
         : QObject(parent)
-        , m_employee(employee)
+        , m_tabWidget(tabWidget)
 {
 }
 
 void TabManager::addTab(const QUrl & url)
 {
-    m_employee->addTab(new Tab(url, m_employee), trUtf8("No name"));
+    m_tabWidget->addTab(new Tab(url, m_tabWidget), trUtf8("No name"));
 }
 
 void TabManager::insertTab(int index, const QUrl & url)
 {
-    m_employee->insertTab(index, new Tab(url, m_employee), trUtf8("No name"));
+    m_tabWidget->insertTab(index, new Tab(url, m_tabWidget), trUtf8("No name"));
 }
 
 void TabManager::removeTab(int index)
 {
-    QWidget * tab = m_employee->widget(index);
+    QWidget * tab = m_tabWidget->widget(index);
 
     if(tab)
     {
-        m_employee->removeTab(index);
+        m_tabWidget->removeTab(index);
         tab->deleteLater();
     }
 
-    if(m_employee->count() == 0)
+    if(m_tabWidget->count() == 0)
     {
         addTab();
     }
     Q_OBJECT
 
 public:
-    TabManager(QTabWidget * employee, QObject * parent = 0);
+    TabManager(QTabWidget * tabWidget, QObject * parent = 0);
 
 private:
-    QTabWidget * m_employee;
+    QTabWidget * m_tabWidget;
 
 public slots:
     void addTab(const QUrl & url = QUrl("about:blank"));