2022-09-06 15:35:18 +08:00
# include "mainwindow.h"
# include "ui_mainwindow.h"
# include <QWidgetAction>
# include <QFileSystemModel>
# include <QTableWidget>
# include <QHBoxLayout>
# include <QInputDialog>
# include <QFileDialog>
# include <QSettings>
# include <QPlainTextEdit>
# include <QToolBar>
2022-10-28 14:21:12 +08:00
# include "AutoHideDockContainer.h"
2022-09-06 15:35:18 +08:00
# include "DockAreaWidget.h"
# include "DockAreaTitleBar.h"
using namespace ads ;
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 ) ;
2022-11-01 18:35:07 +08:00
CDockManager : : setAutoHideConfigFlags ( CDockManager : : DefaultAutoHideConfig ) ;
2022-09-06 15:35:18 +08:00
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
QTableWidget * table = new QTableWidget ( ) ;
table - > setColumnCount ( 3 ) ;
table - > setRowCount ( 10 ) ;
CDockWidget * TableDockWidget = new CDockWidget ( " Table 1 " ) ;
2023-06-20 12:03:11 +08:00
//TableDockWidget->setAutoHideTabOrder(1.0); // Uncomment if you would like the table dock widget to always be pinned before the second table dock widget
2022-09-06 15:35:18 +08:00
TableDockWidget - > setWidget ( table ) ;
TableDockWidget - > setMinimumSizeHintMode ( CDockWidget : : MinimumSizeHintFromDockWidget ) ;
TableDockWidget - > setMinimumSize ( 200 , 150 ) ;
2022-11-03 22:28:01 +08:00
const auto autoHideContainer = DockManager - > addAutoHideDockWidget ( SideBarLocation : : SideBarLeft , TableDockWidget ) ;
2022-11-01 18:02:01 +08:00
autoHideContainer - > setSize ( 480 ) ;
2022-09-06 15:35:18 +08:00
ui - > menuView - > addAction ( TableDockWidget - > toggleViewAction ( ) ) ;
table = new QTableWidget ( ) ;
table - > setColumnCount ( 5 ) ;
table - > setRowCount ( 1020 ) ;
TableDockWidget = new CDockWidget ( " Table 2 " ) ;
2023-06-20 12:03:11 +08:00
//TableDockWidget->setAutoHideTabOrder(2.0); // Uncomment if you would like the table dock widget to always be pinned after the first table dock widget
2022-09-06 15:35:18 +08:00
TableDockWidget - > setWidget ( table ) ;
TableDockWidget - > setMinimumSizeHintMode ( CDockWidget : : MinimumSizeHintFromDockWidget ) ;
TableDockWidget - > resize ( 250 , 150 ) ;
TableDockWidget - > setMinimumSize ( 200 , 150 ) ;
2022-11-03 22:28:01 +08:00
DockManager - > addAutoHideDockWidget ( SideBarLocation : : SideBarLeft , TableDockWidget ) ;
2022-09-06 15:35:18 +08:00
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 ) ;
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 ( currentTextChanged ( 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 ) ;
}
//============================================================================
void CMainWindow : : closeEvent ( QCloseEvent * event )
{
// Delete dock manager here to delete all floating widgets. This ensures
// that all top level windows of the dock manager are properly closed
DockManager - > deleteLater ( ) ;
QMainWindow : : closeEvent ( event ) ;
}