Commits

Ivan Andrianov committed 12f3b01

Added initial tabs support

committer: PayableOnDeath <>

  • Participants
  • Parent commits 4761f36

Comments (0)

Files changed (11)

+#include "tab.h"
+#include "toolbar.h"
+#include "webview.h"
+
+Tab::Tab(const QUrl & url, QWidget * parent)
+        : QWidget(parent)
+{
+    m_toolBar = new ToolBar(url, this);
+    m_webView = new WebView(url, this);
+    QVBoxLayout * layout = new QVBoxLayout(this);
+    layout->addWidget(m_toolBar, 0);
+    layout->addWidget(m_webView, 1);
+}
+#ifndef TAB_H
+#define TAB_H
+
+#include <QtCore>
+#include <QtGui>
+#include <QtWebKit>
+
+class ToolBar;
+class WebView;
+
+class Tab
+        : public QWidget
+{
+    Q_OBJECT
+
+public:
+    Tab(const QUrl & url, QWidget * parent = 0);
+
+private:
+    ToolBar * m_toolBar;
+    WebView * m_webView;
+};
+
+#endif // TAB_H

src/tabmanager.cpp

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

src/tabwidget.cpp

+#include "tabwidget.h"
+
+TabWidget::TabWidget(QWidget * parent)
+        : QTabWidget(parent)
+{
+    setMovable(true);
+}
+#ifndef TABWIDGET_H
+#define TABWIDGET_H
+
+#include <QtCore>
+#include <QtGui>
+#include <QtWebKit>
+
+class TabWidget
+        : public QTabWidget
+{
+    Q_OBJECT
+
+public:
+    TabWidget(QWidget * parent = 0);
+};
+
+#endif // TABWIDGET_H
+#include "toolbar.h"
+
+ToolBar::ToolBar(const QUrl & url, QWidget * parent)
+        : QToolBar(parent)
+{
+}
+#ifndef TOOLBAR_H
+#define TOOLBAR_H
+
+#include <QtCore>
+#include <QtGui>
+#include <QtWebKit>
+
+class ToolBar
+        : public QToolBar
+{
+    Q_OBJECT
+
+public:
+    ToolBar(const QUrl & url, QWidget * parent = 0);
+};
+
+#endif // TOOLBAR_H
+#include "webview.h"
+
+WebView::WebView(const QUrl & url, QWidget * parent)
+        : QWebView(parent)
+{
+    load(url);
+}
+#ifndef WEBVIEW_H
+#define WEBVIEW_H
+
+#include <QtCore>
+#include <QtGui>
+#include <QtWebKit>
+
+class WebView
+        : public QWebView
+{
+    Q_OBJECT
+
+public:
+    WebView(const QUrl & url, QWidget * parent = 0);
+};
+
+#endif // WEBVIEW_H
 TARGET = surfer
 TEMPLATE = app
 SOURCES += src/main.cpp \
-    src/mainwindow.cpp
-HEADERS += src/mainwindow.h
+    src/mainwindow.cpp \
+    src/webview.cpp \
+    src/toolbar.cpp \
+    src/tabwidget.cpp \
+    src/tabmanager.cpp \
+    src/tab.cpp
+HEADERS += src/mainwindow.h \
+    src/webview.h \
+    src/toolbar.h \
+    src/tabwidget.h \
+    src/tabmanager.h \
+    src/tab.h
 FORMS += src/mainwindow.ui