#include "mainwindow.h" #include "ui_mainwindow.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include "DockAreaWidget.h" #include "DockAreaTitleBar.h" #include "DockAreaTabBar.h" #include "FloatingDockContainer.h" #include "DockComponentsFactory.h" using namespace ads; const QString CMainWindow::kTableTopLayout = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "344 272 " "" "" "" "" "" "" "" "258 758 258 " "" "" "" "" "52 621 52 " "" "" ""; const QString CMainWindow::kTableBottomLayout = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "258 758 258 " "" "" "" "" "" "" "" "621 52 52 " "" "" ""; CMainWindow::CMainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::CMainWindow) { ui->setupUi(this); CDockManager::setConfigFlag(CDockManager::OpaqueSplitterResize, true); CDockManager::setConfigFlag(CDockManager::XmlCompressionEnabled, false); DockManager = new CDockManager(this); QCalendarWidget* calendar = new QCalendarWidget(); CDockWidget* CentralDockWidget = new CDockWidget("CentralWidget"); CentralDockWidget->setWidget(calendar); auto* CentralDockArea = DockManager->setCentralWidget(CentralDockWidget); CentralDockArea->setAllowedAreas(DockWidgetArea::OuterDockAreas); QTreeView* fileTree = new QTreeView(); fileTree->setFrameShape(QFrame::NoFrame); QFileSystemModel* fileModel = new QFileSystemModel(fileTree); fileModel->setRootPath(QDir::currentPath()); fileTree->setModel(fileModel); CDockWidget* DataDockWidget = new CDockWidget("File system"); DataDockWidget->setWidget(fileTree); DataDockWidget->resize(150, 250); DataDockWidget->setMinimumSize(100, 250); auto* fileArea = DockManager->addDockWidget(DockWidgetArea::LeftDockWidgetArea, DataDockWidget, CentralDockArea); QTableWidget* table = new QTableWidget(); table->setColumnCount(3); table->setRowCount(10); CDockWidget* TableDockWidget = new CDockWidget("Table"); TableDockWidget->setWidget(table); TableDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget); TableDockWidget->resize(250, 150); TableDockWidget->setMinimumSize(200,150); DockManager->addDockWidget(DockWidgetArea::BottomDockWidgetArea, TableDockWidget, fileArea); QTableWidget* propertiesTable = new QTableWidget(); table->setColumnCount(3); table->setRowCount(10); CDockWidget* PropertiesDockWidget = new CDockWidget("Properties"); PropertiesDockWidget->setWidget(propertiesTable); PropertiesDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget); PropertiesDockWidget->resize(250, 150); PropertiesDockWidget->setMinimumSize(200,150); DockManager->addDockWidget(DockWidgetArea::RightDockWidgetArea, PropertiesDockWidget, CentralDockArea); QWidget* timeLineWidget = new QWidget(); QHBoxLayout* timelineLayout = new QHBoxLayout(timeLineWidget); QRadioButton* radioDockTop = new QRadioButton("Top", timeLineWidget); QRadioButton* radioDockBottom = new QRadioButton("Bottom", timeLineWidget); radioDockTop->setChecked(true); timelineLayout->addWidget(new QLabel("Test Widget.")); timelineLayout->addStretch(1); timelineLayout->addWidget(new QLabel("Apply predefined perspective: ", this)); timelineLayout->addWidget(radioDockTop); timelineLayout->addWidget(radioDockBottom); TimelineDockWidget = new CDockWidget("Timeline"); TimelineDockWidget->setWidget(timeLineWidget); TimelineDockWidget->setFeature(CDockWidget::DockWidgetClosable, false); TimelineDockWidget->setFeature(CDockWidget::DockWidgetMovable, false); TimelineDockWidget->setFeature(CDockWidget::DockWidgetFloatable, false); TimelineDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget); TimelineDockWidget->setMinimumSize(QSize(50, 50)); auto *TimelineDockArea = DockManager->addDockWidget(DockWidgetArea::TopDockWidgetArea, TimelineDockWidget); TimelineDockArea->setDockAreaFlag(CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true); TimelineDockArea->setAllowedAreas(DockWidgetArea::OuterDockAreas); connect(radioDockTop, &QRadioButton::toggled, [this](bool checked){ bool ok = true; if(!checked) { ok = DockManager->restoreState(kTableBottomLayout.toUtf8()); } else { ok = DockManager->restoreState(kTableTopLayout.toUtf8()); } if(!ok) { QMessageBox msgBox; msgBox.setText("Failed to apply perspective!"); msgBox.exec(); } }); QWidget* statusWidget = new QWidget(); QHBoxLayout* statusLayout = new QHBoxLayout(statusWidget); statusLayout->setSpacing(10); statusLayout->addWidget(new QLabel("Status Bar")); QPushButton* OpenPerspectiveButton = new QPushButton("Open Perspective", statusWidget); connect(OpenPerspectiveButton, &QPushButton::clicked, [this](){ QString PerspectiveName = QFileDialog::getOpenFileName(this, "Open Perspective", "", "Perspective files (*.xml)"); if (PerspectiveName.isEmpty()) { return; } QFile stateFile(PerspectiveName); stateFile.open(QIODevice::ReadOnly); QByteArray state = stateFile.readAll(); stateFile.close(); if(!DockManager->restoreState(state)) { QMessageBox msgBox; msgBox.setText("Failed to apply perspective " + stateFile.fileName()); msgBox.exec(); } }); QPushButton* SavePerspectiveButton = new QPushButton("Create Perspective", statusWidget); connect(SavePerspectiveButton, &QPushButton::clicked, [this](){ QString PerspectiveName = QInputDialog::getText(this, "Save Perspective", "Enter unique name:"); if (PerspectiveName.isEmpty()) { return; } QByteArray state = DockManager->saveState(); QFile stateFile(PerspectiveName + ".xml"); stateFile.open(QIODevice::WriteOnly); stateFile.write(state); stateFile.close(); }); statusLayout->addWidget(OpenPerspectiveButton); statusLayout->addWidget(SavePerspectiveButton); statusLayout->addStretch(1); CDockWidget* StatusDockWidget = new CDockWidget("Status"); StatusDockWidget->setWidget(statusWidget); StatusDockWidget->setFeature(CDockWidget::DockWidgetClosable, false); StatusDockWidget->setFeature(CDockWidget::DockWidgetMovable, false); StatusDockWidget->setFeature(CDockWidget::DockWidgetFloatable, false); StatusDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget); StatusDockWidget->setMinimumSize(QSize(50, 50)); StatusDockArea = DockManager->addDockWidget(DockWidgetArea::BottomDockWidgetArea, StatusDockWidget); StatusDockArea->setAllowedAreas(DockWidgetArea::OuterDockAreas); StatusDockArea->setDockAreaFlag(ads::CDockAreaWidget::eDockAreaFlag::HideSingleWidgetTitleBar, true); } CMainWindow::~CMainWindow() { delete ui; }