|
| 1 | +#include "mainwindow.h" |
| 2 | +#include "droppableitem.h" |
| 3 | + |
| 4 | +#include "ui_mainwindow.h" |
| 5 | + |
| 6 | +#include <QWidgetAction> |
| 7 | +#include <QFileSystemModel> |
| 8 | +#include <QTableWidget> |
| 9 | +#include <QHBoxLayout> |
| 10 | +#include <QInputDialog> |
| 11 | +#include <QFileDialog> |
| 12 | +#include <QSettings> |
| 13 | +#include <QPlainTextEdit> |
| 14 | +#include <QToolBar> |
| 15 | + |
| 16 | +#include "AutoHideDockContainer.h" |
| 17 | +#include "DockAreaWidget.h" |
| 18 | +#include "DockAreaTitleBar.h" |
| 19 | + |
| 20 | +using namespace ads; |
| 21 | + |
| 22 | +CMainWindow::CMainWindow(QWidget *parent) |
| 23 | + : QMainWindow(parent) |
| 24 | + , ui(new Ui::CMainWindow) |
| 25 | +{ |
| 26 | + ui->setupUi(this); |
| 27 | + CDockManager::setConfigFlag(CDockManager::OpaqueSplitterResize, true); |
| 28 | + CDockManager::setConfigFlag(CDockManager::XmlCompressionEnabled, false); |
| 29 | + CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true); |
| 30 | + CDockManager::setAutoHideConfigFlags(CDockManager::DefaultAutoHideConfig); |
| 31 | + CDockManager::setAutoHideConfigFlag(CDockManager::AutoHideOpenOnDragHover, true); |
| 32 | + DockManager = new CDockManager(this); |
| 33 | + |
| 34 | + // Set central widget |
| 35 | + QPlainTextEdit* w = new QPlainTextEdit(); |
| 36 | + w->setPlaceholderText("This is the central editor. Enter your text here."); |
| 37 | + CDockWidget* CentralDockWidget = new CDockWidget("CentralWidget"); |
| 38 | + CentralDockWidget->setWidget(w); |
| 39 | + auto* CentralDockArea = DockManager->setCentralWidget(CentralDockWidget); |
| 40 | + CentralDockArea->setAllowedAreas(DockWidgetArea::OuterDockAreas); |
| 41 | + |
| 42 | + DroppableItem* droppableItem = new DroppableItem("Drop text here."); |
| 43 | + CDockWidget* dropDockWidget = new CDockWidget("Tab"); |
| 44 | + dropDockWidget->setWidget(droppableItem); |
| 45 | + dropDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget); |
| 46 | + dropDockWidget->setMinimumSize(200,150); |
| 47 | + dropDockWidget->setAcceptDrops(true); |
| 48 | + const auto autoHideContainer = DockManager->addAutoHideDockWidget(SideBarLocation::SideBarLeft, dropDockWidget); |
| 49 | + autoHideContainer->setSize(480); |
| 50 | + autoHideContainer->setAcceptDrops(true); |
| 51 | + ui->menuView->addAction(dropDockWidget->toggleViewAction()); |
| 52 | + |
| 53 | + QTableWidget* propertiesTable = new QTableWidget(); |
| 54 | + propertiesTable->setColumnCount(3); |
| 55 | + propertiesTable->setRowCount(10); |
| 56 | + CDockWidget* PropertiesDockWidget = new CDockWidget("Properties"); |
| 57 | + PropertiesDockWidget->setWidget(propertiesTable); |
| 58 | + PropertiesDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget); |
| 59 | + PropertiesDockWidget->resize(250, 150); |
| 60 | + PropertiesDockWidget->setMinimumSize(200,150); |
| 61 | + DockManager->addDockWidget(DockWidgetArea::RightDockWidgetArea, PropertiesDockWidget, CentralDockArea); |
| 62 | + ui->menuView->addAction(PropertiesDockWidget->toggleViewAction()); |
| 63 | + |
| 64 | + createPerspectiveUi(); |
| 65 | +} |
| 66 | + |
| 67 | +CMainWindow::~CMainWindow() |
| 68 | +{ |
| 69 | + delete ui; |
| 70 | +} |
| 71 | + |
| 72 | + |
| 73 | +void CMainWindow::createPerspectiveUi() |
| 74 | +{ |
| 75 | + SavePerspectiveAction = new QAction("Create Perspective", this); |
| 76 | + connect(SavePerspectiveAction, SIGNAL(triggered()), SLOT(savePerspective())); |
| 77 | + PerspectiveListAction = new QWidgetAction(this); |
| 78 | + PerspectiveComboBox = new QComboBox(this); |
| 79 | + PerspectiveComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents); |
| 80 | + PerspectiveComboBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
| 81 | + connect(PerspectiveComboBox, SIGNAL(currentTextChanged(const QString&)), |
| 82 | + DockManager, SLOT(openPerspective(const QString&))); |
| 83 | + PerspectiveListAction->setDefaultWidget(PerspectiveComboBox); |
| 84 | + ui->toolBar->addSeparator(); |
| 85 | + ui->toolBar->addAction(PerspectiveListAction); |
| 86 | + ui->toolBar->addAction(SavePerspectiveAction); |
| 87 | +} |
| 88 | + |
| 89 | + |
| 90 | +void CMainWindow::savePerspective() |
| 91 | +{ |
| 92 | + QString PerspectiveName = QInputDialog::getText(this, "Save Perspective", "Enter unique name:"); |
| 93 | + if (PerspectiveName.isEmpty()) |
| 94 | + { |
| 95 | + return; |
| 96 | + } |
| 97 | + |
| 98 | + DockManager->addPerspective(PerspectiveName); |
| 99 | + QSignalBlocker Blocker(PerspectiveComboBox); |
| 100 | + PerspectiveComboBox->clear(); |
| 101 | + PerspectiveComboBox->addItems(DockManager->perspectiveNames()); |
| 102 | + PerspectiveComboBox->setCurrentText(PerspectiveName); |
| 103 | +} |
| 104 | + |
| 105 | + |
| 106 | +//============================================================================ |
| 107 | +void CMainWindow::closeEvent(QCloseEvent* event) |
| 108 | +{ |
| 109 | + // Delete dock manager here to delete all floating widgets. This ensures |
| 110 | + // that all top level windows of the dock manager are properly closed |
| 111 | + DockManager->deleteLater(); |
| 112 | + QMainWindow::closeEvent(event); |
| 113 | +} |
| 114 | + |
| 115 | + |
| 116 | + |
0 commit comments