#include <QApplication>
#include <QMainWindow>
#include <QDockWidget>
#include <QHBoxLayout>
#include <QTabWidget>
#include <QTabBar>


QDockWidget* addOnePanel(QMainWindow*   mainWindow,
                         const QString& uiTitle,
                         QWidget*       in_widget) {
    auto dockWidget = new QDockWidget(uiTitle, mainWindow);
    dockWidget->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable |
                            QDockWidget::DockWidgetFloatable);
    dockWidget->setWidget(in_widget);
    dockWidget->setAllowedAreas(Qt::RightDockWidgetArea | Qt::LeftDockWidgetArea);
    mainWindow->addDockWidget(Qt::RightDockWidgetArea, dockWidget);
    return dockWidget;
};

class Editor : public QWidget
{
public:
    Editor(QWidget* parent)
        : QWidget(parent) {
        auto layout = new QHBoxLayout;
        layout->setContentsMargins(0, 0, 0, 0);
        setLayout(layout);
    }

    QSize sizeHint() const {
        return QSize(300, 600);
    }
};

class TabWidget : public QTabWidget
{
public:
    void setTabBar(QTabBar* tb) {
        QTabWidget::setTabBar(tb);
    }
};

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    auto tabWidget = new TabWidget();
    auto tabBar = new QTabBar(tabWidget);
    tabWidget->setTabBar(tabBar);

    QMainWindow mw;
    mw.setDockOptions(QMainWindow::GroupedDragging);
    mw.setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North);
    mw.setCentralWidget(tabWidget);

    Editor editor(&mw);

    QDockWidget *dockWidget1 = addOnePanel(&mw, "Dock1", &editor);
    QDockWidget *dockWidget2 = addOnePanel(&mw, "Dock2", &editor);

    mw.setCentralWidget(tabWidget);
    mw.tabifyDockWidget(dockWidget1, dockWidget2);

    mw.show();

    return a.exec();
}

#include "main.moc"
