#include "mainwindow.h" #include "ui_mainwindow.h" #include #include #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; /** * Helper function to create an SVG icon */ static QIcon svgIcon(const QString& File) { // This is a workaround, because in item views SVG icons are not // properly scaled and look blurry or pixelate QIcon SvgIcon(File); SvgIcon.addPixmap(SvgIcon.pixmap(92)); return SvgIcon; } CMainWindow::CMainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::CMainWindow) { ui->setupUi(this); CDockManager::setConfigFlag(CDockManager::OpaqueSplitterResize, true); CDockManager::setConfigFlag(CDockManager::XmlCompressionEnabled, false); CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true); DockManager = new CDockManager(this); // Set central widget QPlainTextEdit* w = new QPlainTextEdit(); w->setPlaceholderText("This is the central editor. Enter your text here."); CDockWidget* CentralDockWidget = new CDockWidget("CentralWidget"); CentralDockWidget->setWidget(w); auto* CentralDockArea = DockManager->setCentralWidget(CentralDockWidget); CentralDockArea->setAllowedAreas(DockWidgetArea::OuterDockAreas); // create other dock widgets 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); ui->menuView->addAction(DataDockWidget->toggleViewAction()); 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); ui->menuView->addAction(TableDockWidget->toggleViewAction()); QTableWidget* propertiesTable = new QTableWidget(); propertiesTable->setColumnCount(3); propertiesTable->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); ui->menuView->addAction(PropertiesDockWidget->toggleViewAction()); createPerspectiveUi(); } CMainWindow::~CMainWindow() { delete ui; } void CMainWindow::createPerspectiveUi() { SavePerspectiveAction = new QAction("Create Perspective", this); SavePerspectiveAction->setIcon(svgIcon(":/adsdemo/images/picture_in_picture.svg")); connect(SavePerspectiveAction, SIGNAL(triggered()), SLOT(savePerspective())); PerspectiveListAction = new QWidgetAction(this); PerspectiveComboBox = new QComboBox(this); PerspectiveComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents); PerspectiveComboBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); connect(PerspectiveComboBox, SIGNAL(activated(const QString&)), DockManager, SLOT(openPerspective(const QString&))); PerspectiveListAction->setDefaultWidget(PerspectiveComboBox); ui->toolBar->addSeparator(); ui->toolBar->addAction(PerspectiveListAction); ui->toolBar->addAction(SavePerspectiveAction); } void CMainWindow::savePerspective() { QString PerspectiveName = QInputDialog::getText(this, "Save Perspective", "Enter unique name:"); if (PerspectiveName.isEmpty()) { return; } DockManager->addPerspective(PerspectiveName); QSignalBlocker Blocker(PerspectiveComboBox); PerspectiveComboBox->clear(); PerspectiveComboBox->addItems(DockManager->perspectiveNames()); PerspectiveComboBox->setCurrentText(PerspectiveName); }