2018-02-13 19:00:58 +08:00
/*******************************************************************************
* * Qt Advanced Docking System
* * Copyright ( C ) 2017 Uwe Kindler
* *
* * This library is free software ; you can redistribute it and / or
* * modify it under the terms of the GNU Lesser General Public
* * License as published by the Free Software Foundation ; either
* * version 2.1 of the License , or ( at your option ) any later version .
* *
* * This library is distributed in the hope that it will be useful ,
* * but WITHOUT ANY WARRANTY ; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* * Lesser General Public License for more details .
* *
* * You should have received a copy of the GNU Lesser General Public
* * License along with this library ; If not , see < http : //www.gnu.org/licenses/>.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
//============================================================================
/// \file MainWindow.cpp
/// \author Uwe Kindler
/// \date 13.02.2018
/// \brief Implementation of CMainWindow demo class
//============================================================================
//============================================================================
// INCLUDES
//============================================================================
# include <MainWindow.h>
# include "ui_mainwindow.h"
# include <iostream>
# include <QTime>
# include <QLabel>
# include <QTextEdit>
# include <QCalendarWidget>
# include <QFrame>
# include <QTreeView>
# include <QFileSystemModel>
# include <QBoxLayout>
# include <QSettings>
# include <QDockWidget>
# include <QDebug>
# include <QResizeEvent>
# include <QAction>
# include <QWidgetAction>
# include <QComboBox>
# include <QInputDialog>
2019-11-26 21:40:56 +08:00
# include <QRubberBand>
2019-12-10 21:44:44 +08:00
# include <QPlainTextEdit>
2019-12-11 22:50:13 +08:00
# include <QTableWidget>
2020-01-11 20:53:58 +08:00
# include <QScreen>
# include <QStyle>
2020-01-06 18:42:36 +08:00
# include <QMessageBox>
2020-02-06 07:31:57 +08:00
# include <QMenu>
2020-02-07 21:29:02 +08:00
# include <QToolButton>
2021-01-03 01:06:45 +08:00
# include <QToolBar>
2020-11-21 22:08:30 +08:00
# include <QPointer>
2022-11-15 21:35:52 +08:00
# include <QMap>
# include <QElapsedTimer>
2023-06-30 14:27:51 +08:00
# include <QQuickWidget>
2020-02-07 21:29:02 +08:00
2018-02-13 19:00:58 +08:00
2022-11-15 21:35:52 +08:00
# if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
# include <QRandomGenerator>
# endif
2020-01-11 19:05:44 +08:00
# ifdef Q_OS_WIN
2021-01-03 01:06:45 +08:00
# if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
2020-01-10 15:54:44 +08:00
# include <QAxWidget>
2020-01-11 19:05:44 +08:00
# endif
2021-01-03 01:06:45 +08:00
# endif
2018-02-13 19:00:58 +08:00
# include "DockManager.h"
# include "DockWidget.h"
# include "DockAreaWidget.h"
2020-02-07 21:29:02 +08:00
# include "DockAreaTitleBar.h"
# include "DockAreaTabBar.h"
2019-11-25 22:28:15 +08:00
# include "FloatingDockContainer.h"
2020-02-11 16:31:57 +08:00
# include "DockComponentsFactory.h"
2020-04-14 22:07:00 +08:00
# include "StatusDialog.h"
2021-08-03 20:59:28 +08:00
# include "DockSplitter.h"
2022-11-05 03:14:04 +08:00
# include "ImageViewer.h"
2018-02-13 19:00:58 +08:00
2022-11-15 21:35:52 +08:00
/**
* Returns a random number from 0 to highest - 1
*/
int randomNumberBounded ( int highest )
{
# if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
return QRandomGenerator : : global ( ) - > bounded ( highest ) ;
# else
qsrand ( QTime : : currentTime ( ) . msec ( ) ) ;
return qrand ( ) % highest ;
# endif
}
2019-07-11 21:12:39 +08:00
/**
* Function returns a features string with closable ( c ) , movable ( m ) and floatable ( f )
* features . i . e . The following string is for a not closable but movable and floatable
* widget : c - m + f +
*/
static QString featuresString ( ads : : CDockWidget * DockWidget )
{
auto f = DockWidget - > features ( ) ;
return QString ( " c%1 m%2 f%3 " )
. arg ( f . testFlag ( ads : : CDockWidget : : DockWidgetClosable ) ? " + " : " - " )
. arg ( f . testFlag ( ads : : CDockWidget : : DockWidgetMovable ) ? " + " : " - " )
. arg ( f . testFlag ( ads : : CDockWidget : : DockWidgetFloatable ) ? " + " : " - " ) ;
}
/**
* Appends the string returned by featuresString ( ) to the window title of
* the given DockWidget
*/
static void appendFeaturStringToWindowTitle ( ads : : CDockWidget * DockWidget )
{
DockWidget - > setWindowTitle ( DockWidget - > windowTitle ( )
+ QString ( " (%1) " ) . arg ( featuresString ( DockWidget ) ) ) ;
}
2019-12-10 21:44:44 +08:00
/**
* Helper function to create an SVG icon
*/
static QIcon svgIcon ( const QString & File )
{
2020-02-06 07:31:57 +08:00
// This is a workaround, because in item views SVG icons are not
2020-09-21 14:39:39 +08:00
// properly scaled and look blurry or pixelate
2019-12-10 21:44:44 +08:00
QIcon SvgIcon ( File ) ;
SvgIcon . addPixmap ( SvgIcon . pixmap ( 92 ) ) ;
return SvgIcon ;
}
2019-07-11 21:12:39 +08:00
2020-02-11 16:31:57 +08:00
//============================================================================
class CCustomComponentsFactory : public ads : : CDockComponentsFactory
{
public :
using Super = ads : : CDockComponentsFactory ;
ads : : CDockAreaTitleBar * createDockAreaTitleBar ( ads : : CDockAreaWidget * DockArea ) const override
{
2020-02-11 22:38:49 +08:00
auto TitleBar = new ads : : CDockAreaTitleBar ( DockArea ) ;
2020-02-11 16:31:57 +08:00
auto CustomButton = new QToolButton ( DockArea ) ;
CustomButton - > setToolTip ( QObject : : tr ( " Help " ) ) ;
CustomButton - > setIcon ( svgIcon ( " :/adsdemo/images/help_outline.svg " ) ) ;
CustomButton - > setAutoRaise ( true ) ;
int Index = TitleBar - > indexOf ( TitleBar - > button ( ads : : TitleBarButtonTabsMenu ) ) ;
TitleBar - > insertWidget ( Index + 1 , CustomButton ) ;
return TitleBar ;
}
} ;
2020-03-29 02:32:07 +08:00
//===========================================================================
/**
* Custom QTableWidget with a minimum size hint to test CDockWidget
* setMinimumSizeHintMode ( ) function of CDockWidget
*/
class CMinSizeTableWidget : public QTableWidget
{
public :
using QTableWidget : : QTableWidget ;
virtual QSize minimumSizeHint ( ) const override
{
return QSize ( 300 , 100 ) ;
}
} ;
2020-01-10 15:54:44 +08:00
2018-02-13 19:00:58 +08:00
//============================================================================
/**
* Private data class pimpl
*/
struct MainWindowPrivate
{
CMainWindow * _this ;
Ui : : MainWindow ui ;
2019-01-25 12:05:30 +08:00
QAction * SavePerspectiveAction = nullptr ;
2018-02-13 19:00:58 +08:00
QWidgetAction * PerspectiveListAction = nullptr ;
2019-01-25 12:05:30 +08:00
QComboBox * PerspectiveComboBox = nullptr ;
2018-02-13 19:00:58 +08:00
ads : : CDockManager * DockManager = nullptr ;
2020-07-06 03:48:48 +08:00
ads : : CDockWidget * WindowTitleTestDockWidget = nullptr ;
2020-11-21 22:08:30 +08:00
QPointer < ads : : CDockWidget > LastDockedEditor ;
QPointer < ads : : CDockWidget > LastCreatedFloatingEditor ;
2018-02-13 19:00:58 +08:00
MainWindowPrivate ( CMainWindow * _public ) : _this ( _public ) { }
/**
* Creates the toolbar actions
*/
void createActions ( ) ;
/**
* Fill the dock manager with dock widgets
*/
void createContent ( ) ;
/**
* Saves the dock manager state and the main window geometry
*/
void saveState ( ) ;
/**
* Save the list of perspectives
*/
void savePerspectives ( ) ;
/**
* Restores the dock manager state
*/
void restoreState ( ) ;
/**
* Restore the perspective listo of the dock manager
*/
void restorePerspectives ( ) ;
2020-06-26 17:19:37 +08:00
/**
* Creates a dock widget with a file system tree view
*/
ads : : CDockWidget * createFileSystemTreeDockWidget ( )
{
static int FileSystemCount = 0 ;
QTreeView * w = new QTreeView ( ) ;
w - > setFrameShape ( QFrame : : NoFrame ) ;
QFileSystemModel * m = new QFileSystemModel ( w ) ;
m - > setRootPath ( QDir : : currentPath ( ) ) ;
w - > setModel ( m ) ;
2022-10-28 19:20:27 +08:00
w - > setRootIndex ( m - > index ( QDir : : currentPath ( ) ) ) ;
2020-06-26 17:19:37 +08:00
ads : : CDockWidget * DockWidget = new ads : : CDockWidget ( QString ( " Filesystem %1 " )
. arg ( FileSystemCount + + ) ) ;
DockWidget - > setWidget ( w ) ;
2022-11-07 21:36:19 +08:00
DockWidget - > setIcon ( svgIcon ( " :/adsdemo/images/folder_open.svg " ) ) ;
2020-06-26 17:19:37 +08:00
ui . menuView - > addAction ( DockWidget - > toggleViewAction ( ) ) ;
// We disable focus to test focus highlighting if the dock widget content
// does not support focus
w - > setFocusPolicy ( Qt : : NoFocus ) ;
auto ToolBar = DockWidget - > createDefaultToolBar ( ) ;
ToolBar - > addAction ( ui . actionSaveState ) ;
ToolBar - > addAction ( ui . actionRestoreState ) ;
return DockWidget ;
}
/**
* Create a dock widget with a QCalendarWidget
*/
ads : : CDockWidget * createCalendarDockWidget ( )
{
static int CalendarCount = 0 ;
QCalendarWidget * w = new QCalendarWidget ( ) ;
ads : : CDockWidget * DockWidget = new ads : : CDockWidget ( QString ( " Calendar %1 " ) . arg ( CalendarCount + + ) ) ;
// The following lines are for testing the setWidget() and takeWidget()
// functionality
DockWidget - > setWidget ( w ) ;
DockWidget - > setWidget ( w ) ; // what happens if we set a widget if a widget is already set
DockWidget - > takeWidget ( ) ; // we remove the widget
DockWidget - > setWidget ( w ) ; // and set the widget again - there should be no error
DockWidget - > setToggleViewActionMode ( ads : : CDockWidget : : ActionModeShow ) ;
DockWidget - > setIcon ( svgIcon ( " :/adsdemo/images/date_range.svg " ) ) ;
ui . menuView - > addAction ( DockWidget - > toggleViewAction ( ) ) ;
auto ToolBar = DockWidget - > createDefaultToolBar ( ) ;
ToolBar - > addAction ( ui . actionSaveState ) ;
ToolBar - > addAction ( ui . actionRestoreState ) ;
return DockWidget ;
}
/**
* Create dock widget with a text label
*/
ads : : CDockWidget * createLongTextLabelDockWidget ( )
{
static int LabelCount = 0 ;
QLabel * l = new QLabel ( ) ;
l - > setWordWrap ( true ) ;
l - > setAlignment ( Qt : : AlignTop | Qt : : AlignLeft ) ;
l - > setText ( QString ( " Label %1 %2 - Lorem ipsum dolor sit amet, consectetuer adipiscing elit. "
" Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque "
" penatibus et magnis dis parturient montes, nascetur ridiculus mus. "
" Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. "
" Nulla consequat massa quis enim. Donec pede justo, fringilla vel, "
" aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, "
" imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede "
" mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum "
" semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, "
" porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, "
" dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla "
" ut metus varius laoreet. " )
. arg ( LabelCount )
. arg ( QTime : : currentTime ( ) . toString ( " hh:mm:ss:zzz " ) ) ) ;
ads : : CDockWidget * DockWidget = new ads : : CDockWidget ( QString ( " Label %1 " ) . arg ( LabelCount + + ) ) ;
DockWidget - > setWidget ( l ) ;
2022-11-07 21:36:19 +08:00
DockWidget - > setIcon ( svgIcon ( " :/adsdemo/images/font_download.svg " ) ) ;
2020-06-26 17:19:37 +08:00
ui . menuView - > addAction ( DockWidget - > toggleViewAction ( ) ) ;
return DockWidget ;
}
/**
* Creates as imple editor widget
*/
ads : : CDockWidget * createEditorWidget ( )
{
static int EditorCount = 0 ;
QPlainTextEdit * w = new QPlainTextEdit ( ) ;
w - > setPlaceholderText ( " This is an editor. If you close the editor, it will be "
" deleted. Enter your text here. " ) ;
w - > setStyleSheet ( " border: none " ) ;
ads : : CDockWidget * DockWidget = new ads : : CDockWidget ( QString ( " Editor %1 " ) . arg ( EditorCount + + ) ) ;
DockWidget - > setWidget ( w ) ;
DockWidget - > setIcon ( svgIcon ( " :/adsdemo/images/edit.svg " ) ) ;
DockWidget - > setFeature ( ads : : CDockWidget : : CustomCloseHandling , true ) ;
ui . menuView - > addAction ( DockWidget - > toggleViewAction ( ) ) ;
QMenu * OptionsMenu = new QMenu ( DockWidget ) ;
OptionsMenu - > setTitle ( QObject : : tr ( " Options " ) ) ;
OptionsMenu - > setToolTip ( OptionsMenu - > title ( ) ) ;
OptionsMenu - > setIcon ( svgIcon ( " :/adsdemo/images/custom-menu-button.svg " ) ) ;
auto MenuAction = OptionsMenu - > menuAction ( ) ;
// The object name of the action will be set for the QToolButton that
// is created in the dock area title bar. You can use this name for CSS
// styling
MenuAction - > setObjectName ( " optionsMenu " ) ;
DockWidget - > setTitleBarActions ( { OptionsMenu - > menuAction ( ) } ) ;
auto a = OptionsMenu - > addAction ( QObject : : tr ( " Clear Editor " ) ) ;
w - > connect ( a , SIGNAL ( triggered ( ) ) , SLOT ( clear ( ) ) ) ;
return DockWidget ;
}
2022-11-05 03:14:04 +08:00
/**
* Creates a simply image viewr
*/
ads : : CDockWidget * createImageViewer ( )
{
static int ImageViewerCount = 0 ;
auto w = new CImageViewer ( ) ;
2022-11-15 21:35:52 +08:00
auto ImageIndex = randomNumberBounded ( 4 ) ;
2022-11-07 16:50:28 +08:00
auto FileName = " :adsdemo/images/ads_logo.svg " ;
// Pick a random image from a number of images
switch ( ImageIndex )
{
case 0 : FileName = " :adsdemo/images/ads_tile_blue.svg " ; break ;
2022-11-07 17:15:39 +08:00
case 1 : FileName = " :adsdemo/images/ads_tile_blue_light.svg " ; break ;
2022-11-07 16:50:28 +08:00
case 2 : FileName = " :adsdemo/images/ads_tile_green.svg " ; break ;
case 3 : FileName = " :adsdemo/images/ads_tile_orange.svg " ; break ;
}
auto Result = w - > loadFile ( FileName ) ;
2022-11-05 03:14:04 +08:00
qDebug ( ) < < " loadFile result: " < < Result ;
ads : : CDockWidget * DockWidget = new ads : : CDockWidget ( QString ( " Image Viewer %1 " ) . arg ( ImageViewerCount + + ) ) ;
2022-11-07 21:36:19 +08:00
DockWidget - > setIcon ( svgIcon ( " :/adsdemo/images/photo.svg " ) ) ;
2022-11-05 03:14:04 +08:00
DockWidget - > setWidget ( w , ads : : CDockWidget : : ForceNoScrollArea ) ;
auto ToolBar = DockWidget - > createDefaultToolBar ( ) ;
ToolBar - > addActions ( w - > actions ( ) ) ;
return DockWidget ;
}
2020-06-26 17:19:37 +08:00
/**
* Create a table widget
*/
ads : : CDockWidget * createTableWidget ( )
{
static int TableCount = 0 ;
auto w = new CMinSizeTableWidget ( ) ;
ads : : CDockWidget * DockWidget = new ads : : CDockWidget ( QString ( " Table %1 " ) . arg ( TableCount + + ) ) ;
static int colCount = 5 ;
static int rowCount = 30 ;
w - > setColumnCount ( colCount ) ;
w - > setRowCount ( rowCount ) ;
for ( int col = 0 ; col < colCount ; + + col )
{
w - > setHorizontalHeaderItem ( col , new QTableWidgetItem ( QString ( " Col %1 " ) . arg ( col + 1 ) ) ) ;
for ( int row = 0 ; row < rowCount ; + + row )
{
w - > setItem ( row , col , new QTableWidgetItem ( QString ( " T %1-%2 " ) . arg ( row + 1 ) . arg ( col + 1 ) ) ) ;
}
}
DockWidget - > setWidget ( w ) ;
DockWidget - > setIcon ( svgIcon ( " :/adsdemo/images/grid_on.svg " ) ) ;
DockWidget - > setMinimumSizeHintMode ( ads : : CDockWidget : : MinimumSizeHintFromContent ) ;
auto ToolBar = DockWidget - > createDefaultToolBar ( ) ;
auto Action = ToolBar - > addAction ( svgIcon ( " :/adsdemo/images/fullscreen.svg " ) , " Toggle Fullscreen " ) ;
QObject : : connect ( Action , & QAction : : triggered , [ = ] ( )
{
if ( DockWidget - > isFullScreen ( ) )
{
DockWidget - > showNormal ( ) ;
}
else
{
DockWidget - > showFullScreen ( ) ;
}
} ) ;
ui . menuView - > addAction ( DockWidget - > toggleViewAction ( ) ) ;
return DockWidget ;
}
2023-06-30 14:27:51 +08:00
/**
* Create QQuickWidget for test for OpenGL and QQuick
*/
ads : : CDockWidget * createQQuickWidget ( )
{
QQuickWidget * widget = new QQuickWidget ( ) ;
ads : : CDockWidget * dockWidget = new ads : : CDockWidget ( " Quick " ) ;
dockWidget - > setWidget ( widget ) ;
return dockWidget ;
}
2020-06-26 17:19:37 +08:00
# ifdef Q_OS_WIN
2021-01-03 01:06:45 +08:00
# if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
2020-06-26 17:19:37 +08:00
/**
* Creates an ActiveX widget on windows
*/
ads : : CDockWidget * createActiveXWidget ( QWidget * parent = nullptr )
{
static int ActiveXCount = 0 ;
QAxWidget * w = new QAxWidget ( " {6bf52a52-394a-11d3-b153-00c04f79faa6} " , parent ) ;
ads : : CDockWidget * DockWidget = new ads : : CDockWidget ( QString ( " Active X %1 " ) . arg ( ActiveXCount + + ) ) ;
DockWidget - > setWidget ( w ) ;
ui . menuView - > addAction ( DockWidget - > toggleViewAction ( ) ) ;
return DockWidget ;
}
# endif
2021-01-03 01:06:45 +08:00
# endif
2018-02-13 19:00:58 +08:00
} ;
//============================================================================
void MainWindowPrivate : : createContent ( )
{
// Test container docking
2020-06-26 17:19:37 +08:00
auto DockWidget = createCalendarDockWidget ( ) ;
2018-08-24 19:41:58 +08:00
DockWidget - > setFeature ( ads : : CDockWidget : : DockWidgetClosable , false ) ;
2020-02-02 22:56:31 +08:00
auto SpecialDockArea = DockManager - > addDockWidget ( ads : : LeftDockWidgetArea , DockWidget ) ;
// For this Special Dock Area we want to avoid dropping on the center of it (i.e. we don't want this widget to be ever tabbified):
{
SpecialDockArea - > setAllowedAreas ( ads : : OuterDockAreas ) ;
//SpecialDockArea->setAllowedAreas({ads::LeftDockWidgetArea, ads::RightDockWidgetArea}); // just for testing
}
2020-07-03 20:55:33 +08:00
DockWidget = createLongTextLabelDockWidget ( ) ;
2020-07-06 03:48:48 +08:00
WindowTitleTestDockWidget = DockWidget ;
2020-07-03 20:55:33 +08:00
DockWidget - > setFeature ( ads : : CDockWidget : : DockWidgetFocusable , false ) ;
DockManager - > addDockWidget ( ads : : LeftDockWidgetArea , DockWidget ) ;
2020-06-26 17:19:37 +08:00
auto FileSystemWidget = createFileSystemTreeDockWidget ( ) ;
2020-02-16 21:37:14 +08:00
FileSystemWidget - > setFeature ( ads : : CDockWidget : : DockWidgetFloatable , false ) ;
appendFeaturStringToWindowTitle ( FileSystemWidget ) ;
2018-11-01 05:13:34 +08:00
DockManager - > addDockWidget ( ads : : BottomDockWidgetArea , FileSystemWidget ) ;
2018-09-12 19:52:10 +08:00
2020-06-26 17:19:37 +08:00
FileSystemWidget = createFileSystemTreeDockWidget ( ) ;
2018-08-24 19:41:58 +08:00
FileSystemWidget - > setFeature ( ads : : CDockWidget : : DockWidgetMovable , false ) ;
2019-07-11 21:12:39 +08:00
FileSystemWidget - > setFeature ( ads : : CDockWidget : : DockWidgetFloatable , false ) ;
appendFeaturStringToWindowTitle ( FileSystemWidget ) ;
2020-02-11 16:31:57 +08:00
// Test custom factory - we inject a help button into the title bar
ads : : CDockComponentsFactory : : setFactory ( new CCustomComponentsFactory ( ) ) ;
2018-08-24 19:41:58 +08:00
auto TopDockArea = DockManager - > addDockWidget ( ads : : TopDockWidgetArea , FileSystemWidget ) ;
2020-07-19 04:15:10 +08:00
// Uncomment the next line if you would like to test the
2020-08-18 16:48:35 +08:00
// HideSingleWidgetTitleBar functionality
// TopDockArea->setDockAreaFlag(ads::CDockAreaWidget::HideSingleWidgetTitleBar, true);
2020-02-11 16:31:57 +08:00
ads : : CDockComponentsFactory : : resetDefaultFactory ( ) ;
2020-02-07 21:29:02 +08:00
2020-02-11 03:07:36 +08:00
// We create a calendar widget and clear all flags to prevent the dock area
2020-02-07 21:29:02 +08:00
// from closing
2020-06-26 17:19:37 +08:00
DockWidget = createCalendarDockWidget ( ) ;
2019-01-25 12:05:30 +08:00
DockWidget - > setTabToolTip ( QString ( " Tab ToolTip \n Hodie est dies magna " ) ) ;
2020-02-07 21:29:02 +08:00
auto DockArea = DockManager - > addDockWidget ( ads : : CenterDockWidgetArea , DockWidget , TopDockArea ) ;
2021-08-03 20:59:28 +08:00
// Now we create a action to test resizing of DockArea widget
auto Action = ui . menuTests - > addAction ( QString ( " Resize %1 " ) . arg ( DockWidget - > windowTitle ( ) ) ) ;
QObject : : connect ( Action , & QAction : : triggered , [ DockArea ] ( )
{
// Resizing only works, if the Splitter is visible and has a valid
// sizes
auto Splitter = ads : : internal : : findParent < ads : : CDockSplitter * > ( DockArea ) ;
if ( ! Splitter )
{
return ;
}
// We change the sizes of the splitter that contains the Calendar 1 widget
// to resize the dock widget
int Width = Splitter - > width ( ) ;
Splitter - > setSizes ( { Width * 2 / 3 , Width * 1 / 3 } ) ;
} ) ;
2022-05-10 19:41:19 +08:00
DockWidget - > setWindowTitle ( QString ( " My " + DockWidget - > windowTitle ( ) ) ) ;
2020-02-07 21:29:02 +08:00
// Now we add a custom button to the dock area title bar that will create
// new editor widgets when clicked
auto CustomButton = new QToolButton ( DockArea ) ;
CustomButton - > setToolTip ( QObject : : tr ( " Create Editor " ) ) ;
CustomButton - > setIcon ( svgIcon ( " :/adsdemo/images/plus.svg " ) ) ;
CustomButton - > setAutoRaise ( true ) ;
2020-04-14 04:16:47 +08:00
2020-02-07 21:29:02 +08:00
auto TitleBar = DockArea - > titleBar ( ) ;
int Index = TitleBar - > indexOf ( TitleBar - > tabBar ( ) ) ;
TitleBar - > insertWidget ( Index + 1 , CustomButton ) ;
QObject : : connect ( CustomButton , & QToolButton : : clicked , [ = ] ( )
{
2020-06-26 17:19:37 +08:00
auto DockWidget = createEditorWidget ( ) ;
2020-02-07 21:29:02 +08:00
DockWidget - > setFeature ( ads : : CDockWidget : : DockWidgetDeleteOnClose , true ) ;
DockManager - > addDockWidgetTabToArea ( DockWidget , DockArea ) ;
_this - > connect ( DockWidget , SIGNAL ( closeRequested ( ) ) , SLOT ( onEditorCloseRequested ( ) ) ) ;
} ) ;
2018-02-13 19:00:58 +08:00
// Test dock area docking
2020-06-26 17:19:37 +08:00
auto RighDockArea = DockManager - > addDockWidget ( ads : : RightDockWidgetArea , createLongTextLabelDockWidget ( ) , TopDockArea ) ;
DockManager - > addDockWidget ( ads : : TopDockWidgetArea , createLongTextLabelDockWidget ( ) , RighDockArea ) ;
auto BottomDockArea = DockManager - > addDockWidget ( ads : : BottomDockWidgetArea , createLongTextLabelDockWidget ( ) , RighDockArea ) ;
DockManager - > addDockWidget ( ads : : CenterDockWidgetArea , createLongTextLabelDockWidget ( ) , RighDockArea ) ;
2022-07-29 19:25:14 +08:00
auto LabelDockWidget = createLongTextLabelDockWidget ( ) ;
DockManager - > addDockWidget ( ads : : CenterDockWidgetArea , LabelDockWidget , BottomDockArea ) ;
// Tests CustomCloseHandling without DeleteOnClose
LabelDockWidget - > setFeature ( ads : : CDockWidget : : CustomCloseHandling , true ) ;
QObject : : connect ( LabelDockWidget , & ads : : CDockWidget : : closeRequested , [ LabelDockWidget , this ] ( )
{
int Result = QMessageBox : : question ( _this , " Custom Close Request " ,
" Do you really want to close this dock widget? " ) ;
if ( QMessageBox : : Yes = = Result )
{
LabelDockWidget - > closeDockWidget ( ) ;
}
} ) ;
2019-11-25 22:28:15 +08:00
2021-08-03 20:59:28 +08:00
Action = ui . menuTests - > addAction ( QString ( " Set %1 Floating " ) . arg ( DockWidget - > windowTitle ( ) ) ) ;
2019-11-25 22:59:08 +08:00
DockWidget - > connect ( Action , SIGNAL ( triggered ( ) ) , SLOT ( setFloating ( ) ) ) ;
2020-04-14 04:16:47 +08:00
Action = ui . menuTests - > addAction ( QString ( " Set %1 As Current Tab " ) . arg ( DockWidget - > windowTitle ( ) ) ) ;
DockWidget - > connect ( Action , SIGNAL ( triggered ( ) ) , SLOT ( setAsCurrentTab ( ) ) ) ;
Action = ui . menuTests - > addAction ( QString ( " Raise %1 " ) . arg ( DockWidget - > windowTitle ( ) ) ) ;
DockWidget - > connect ( Action , SIGNAL ( triggered ( ) ) , SLOT ( raise ( ) ) ) ;
2019-11-25 22:59:08 +08:00
2021-12-06 16:42:12 +08:00
// Test hidden floating dock widget
DockWidget = createLongTextLabelDockWidget ( ) ;
DockManager - > addDockWidgetFloating ( DockWidget ) ;
DockWidget - > toggleView ( false ) ;
// Test visible floating dock widget
DockWidget = createCalendarDockWidget ( ) ;
DockManager - > addDockWidgetFloating ( DockWidget ) ;
2022-05-10 19:41:19 +08:00
DockWidget - > setWindowTitle ( QString ( " My " + DockWidget - > windowTitle ( ) ) ) ;
2021-12-06 16:42:12 +08:00
2021-08-03 20:59:28 +08:00
2020-01-11 19:05:44 +08:00
# ifdef Q_OS_WIN
2021-01-03 01:06:45 +08:00
# if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
2023-01-20 18:50:34 +08:00
DockManager - > addDockWidget ( ads : : CenterDockWidgetArea , createActiveXWidget ( ) , RighDockArea ) ;
2021-01-03 01:06:45 +08:00
# endif
2020-01-11 19:05:44 +08:00
# endif
2020-01-10 15:54:44 +08:00
2019-10-01 17:48:53 +08:00
for ( auto DockWidget : DockManager - > dockWidgetsMap ( ) )
{
_this - > connect ( DockWidget , SIGNAL ( viewToggled ( bool ) ) , SLOT ( onViewToggled ( bool ) ) ) ;
2020-01-14 22:58:45 +08:00
_this - > connect ( DockWidget , SIGNAL ( visibilityChanged ( bool ) ) , SLOT ( onViewVisibilityChanged ( bool ) ) ) ;
2019-10-01 17:48:53 +08:00
}
2022-11-05 03:14:04 +08:00
// Create image viewer
DockWidget = createImageViewer ( ) ;
DockManager - > addDockWidget ( ads : : LeftDockWidgetArea , DockWidget ) ;
2023-06-30 14:27:51 +08:00
// Create quick widget
DockWidget = createQQuickWidget ( ) ;
DockWidget - > setFeature ( ads : : CDockWidget : : DockWidgetClosable , true ) ;
DockManager - > addDockWidget ( ads : : LeftDockWidgetArea , DockWidget ) ;
2018-02-13 19:00:58 +08:00
}
//============================================================================
void MainWindowPrivate : : createActions ( )
{
ui . toolBar - > addAction ( ui . actionSaveState ) ;
2019-12-10 21:44:44 +08:00
ui . toolBar - > setToolButtonStyle ( Qt : : ToolButtonTextUnderIcon ) ;
ui . actionSaveState - > setIcon ( svgIcon ( " :/adsdemo/images/save.svg " ) ) ;
2018-02-13 19:00:58 +08:00
ui . toolBar - > addAction ( ui . actionRestoreState ) ;
2019-12-10 21:44:44 +08:00
ui . actionRestoreState - > setIcon ( svgIcon ( " :/adsdemo/images/restore.svg " ) ) ;
2018-02-13 19:00:58 +08:00
2019-12-10 21:44:44 +08:00
SavePerspectiveAction = new QAction ( " Create Perspective " , _this ) ;
SavePerspectiveAction - > setIcon ( svgIcon ( " :/adsdemo/images/picture_in_picture.svg " ) ) ;
2018-02-13 19:00:58 +08:00
_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 ) ;
PerspectiveListAction - > setDefaultWidget ( PerspectiveComboBox ) ;
ui . toolBar - > addSeparator ( ) ;
ui . toolBar - > addAction ( PerspectiveListAction ) ;
ui . toolBar - > addAction ( SavePerspectiveAction ) ;
2019-12-10 21:44:44 +08:00
2020-05-07 22:14:59 +08:00
QAction * a = ui . toolBar - > addAction ( " Create Floating Editor " ) ;
a - > setProperty ( " Floating " , true ) ;
2019-12-10 21:44:44 +08:00
a - > setToolTip ( " Creates floating dynamic dockable editor windows that are deleted on close " ) ;
a - > setIcon ( svgIcon ( " :/adsdemo/images/note_add.svg " ) ) ;
_this - > connect ( a , SIGNAL ( triggered ( ) ) , SLOT ( createEditor ( ) ) ) ;
2020-04-14 04:16:47 +08:00
ui . menuTests - > addAction ( a ) ;
2019-12-11 22:50:13 +08:00
2020-05-07 22:14:59 +08:00
a = ui . toolBar - > addAction ( " Create Docked Editor " ) ;
a - > setProperty ( " Floating " , false ) ;
a - > setToolTip ( " Creates a docked editor windows that are deleted on close " ) ;
a - > setIcon ( svgIcon ( " :/adsdemo/images/docked_editor.svg " ) ) ;
_this - > connect ( a , SIGNAL ( triggered ( ) ) , SLOT ( createEditor ( ) ) ) ;
ui . menuTests - > addAction ( a ) ;
2022-11-14 21:56:06 +08:00
a = ui . toolBar - > addAction ( " Create Editor Tab " ) ;
a - > setProperty ( " Floating " , false ) ;
a - > setToolTip ( " Creates a editor tab and inserts it as second tab into an area " ) ;
a - > setIcon ( svgIcon ( " :/adsdemo/images/tab.svg " ) ) ;
a - > setProperty ( " Tabbed " , true ) ;
_this - > connect ( a , SIGNAL ( triggered ( ) ) , SLOT ( createEditor ( ) ) ) ;
ui . menuTests - > addAction ( a ) ;
2020-05-07 22:14:59 +08:00
a = ui . toolBar - > addAction ( " Create Floating Table " ) ;
2019-12-11 22:50:13 +08:00
a - > setToolTip ( " Creates floating dynamic dockable table with millions of entries " ) ;
a - > setIcon ( svgIcon ( " :/adsdemo/images/grid_on.svg " ) ) ;
_this - > connect ( a , SIGNAL ( triggered ( ) ) , SLOT ( createTable ( ) ) ) ;
2020-04-14 04:16:47 +08:00
ui . menuTests - > addAction ( a ) ;
2020-04-14 22:07:00 +08:00
2022-11-07 15:11:50 +08:00
a = ui . toolBar - > addAction ( " Create Image Viewer " ) ;
auto ToolButton = qobject_cast < QToolButton * > ( ui . toolBar - > widgetForAction ( a ) ) ;
ToolButton - > setPopupMode ( QToolButton : : InstantPopup ) ;
a - > setToolTip ( " Creates floating, docked or pinned image viewer " ) ;
a - > setIcon ( svgIcon ( " :/adsdemo/images/panorama.svg " ) ) ;
ui . menuTests - > addAction ( a ) ;
auto Menu = new QMenu ( ) ;
ToolButton - > setMenu ( Menu ) ;
a = Menu - > addAction ( " Floating Image Viewer " ) ;
_this - > connect ( a , SIGNAL ( triggered ( ) ) , SLOT ( createImageViewer ( ) ) ) ;
a = Menu - > addAction ( " Docked Image Viewer " ) ;
_this - > connect ( a , SIGNAL ( triggered ( ) ) , SLOT ( createImageViewer ( ) ) ) ;
a = Menu - > addAction ( " Pinned Image Viewer " ) ;
_this - > connect ( a , SIGNAL ( triggered ( ) ) , SLOT ( createImageViewer ( ) ) ) ;
2020-04-14 22:07:00 +08:00
ui . menuTests - > addSeparator ( ) ;
a = ui . menuTests - > addAction ( " Show Status Dialog " ) ;
_this - > connect ( a , SIGNAL ( triggered ( ) ) , SLOT ( showStatusDialog ( ) ) ) ;
2020-07-06 03:48:48 +08:00
a = ui . menuTests - > addAction ( " Toggle Label 0 Window Title " ) ;
_this - > connect ( a , SIGNAL ( triggered ( ) ) , SLOT ( toggleDockWidgetWindowTitle ( ) ) ) ;
2020-04-14 22:07:00 +08:00
ui . menuTests - > addSeparator ( ) ;
2022-11-04 20:44:30 +08:00
a = ui . toolBar - > addAction ( " Apply VS Style " ) ;
a - > setToolTip ( " Applies a Visual Studio light style (visual_studio_light.css). " ) ;
a - > setIcon ( svgIcon ( " :/adsdemo/images/color_lens.svg " ) ) ;
QObject : : connect ( a , & QAction : : triggered , _this , & CMainWindow : : applyVsStyle ) ;
2022-11-07 15:11:50 +08:00
ui . menuTests - > addAction ( a ) ;
2018-02-13 19:00:58 +08:00
}
//============================================================================
void MainWindowPrivate : : saveState ( )
{
QSettings Settings ( " Settings.ini " , QSettings : : IniFormat ) ;
Settings . setValue ( " mainWindow/Geometry " , _this - > saveGeometry ( ) ) ;
Settings . setValue ( " mainWindow/State " , _this - > saveState ( ) ) ;
Settings . setValue ( " mainWindow/DockingState " , DockManager - > saveState ( ) ) ;
}
//============================================================================
void MainWindowPrivate : : restoreState ( )
{
2018-10-11 20:15:27 +08:00
QSettings Settings ( " Settings.ini " , QSettings : : IniFormat ) ;
2018-02-13 19:00:58 +08:00
_this - > restoreGeometry ( Settings . value ( " mainWindow/Geometry " ) . toByteArray ( ) ) ;
_this - > restoreState ( Settings . value ( " mainWindow/State " ) . toByteArray ( ) ) ;
2018-10-11 20:15:27 +08:00
DockManager - > restoreState ( Settings . value ( " mainWindow/DockingState " ) . toByteArray ( ) ) ;
2018-02-13 19:00:58 +08:00
}
//============================================================================
void MainWindowPrivate : : savePerspectives ( )
{
QSettings Settings ( " Settings.ini " , QSettings : : IniFormat ) ;
DockManager - > savePerspectives ( Settings ) ;
}
//============================================================================
void MainWindowPrivate : : restorePerspectives ( )
{
QSettings Settings ( " Settings.ini " , QSettings : : IniFormat ) ;
DockManager - > loadPerspectives ( Settings ) ;
PerspectiveComboBox - > clear ( ) ;
PerspectiveComboBox - > addItems ( DockManager - > perspectiveNames ( ) ) ;
}
//============================================================================
CMainWindow : : CMainWindow ( QWidget * parent ) :
QMainWindow ( parent ) ,
d ( new MainWindowPrivate ( this ) )
{
2018-11-08 19:57:25 +08:00
using namespace ads ;
2018-02-13 19:00:58 +08:00
d - > ui . setupUi ( this ) ;
2020-04-27 14:58:50 +08:00
setWindowTitle ( QApplication : : instance ( ) - > applicationName ( ) ) ;
2018-02-13 19:00:58 +08:00
d - > createActions ( ) ;
2019-09-13 03:15:35 +08:00
// uncomment the following line if the tab close button should be
// a QToolButton instead of a QPushButton
2019-09-13 20:19:43 +08:00
// CDockManager::setConfigFlags(CDockManager::configFlags() | CDockManager::TabCloseButtonIsToolButton);
2020-02-16 21:37:14 +08:00
// uncomment the following line if you want to use opaque undocking and
2020-01-11 20:53:58 +08:00
// opaque splitter resizing
2022-11-22 17:25:44 +08:00
//CDockManager::setConfigFlags(CDockManager::DefaultOpaqueConfig);
2019-09-13 03:15:35 +08:00
2020-01-15 17:03:50 +08:00
// uncomment the following line if you want a fixed tab width that does
// not change if the visibility of the close button changes
//CDockManager::setConfigFlag(CDockManager::RetainTabSizeWhenCloseButtonHidden, true);
2020-02-02 23:22:05 +08:00
// uncomment the following line if you don't want close button on DockArea's title bar
//CDockManager::setConfigFlag(CDockManager::DockAreaHasCloseButton, false);
// uncomment the following line if you don't want undock button on DockArea's title bar
//CDockManager::setConfigFlag(CDockManager::DockAreaHasUndockButton, false);
// uncomment the following line if you don't want tabs menu button on DockArea's title bar
//CDockManager::setConfigFlag(CDockManager::DockAreaHasTabsMenuButton, false);
2020-01-15 17:03:50 +08:00
2020-02-05 15:04:27 +08:00
// uncomment the following line if you don't want disabled buttons to appear on DockArea's title bar
//CDockManager::setConfigFlag(CDockManager::DockAreaHideDisabledButtons, true);
2020-02-06 22:21:19 +08:00
// uncomment the following line if you want to show tabs menu button on DockArea's title bar only when there are more than one tab and at least of them has elided title
//CDockManager::setConfigFlag(CDockManager::DockAreaDynamicTabsMenuButtonVisibility, true);
2020-02-11 03:07:36 +08:00
// uncomment the following line if you want floating container to always show application title instead of active dock widget's title
//CDockManager::setConfigFlag(CDockManager::FloatingContainerHasWidgetTitle, false);
// uncomment the following line if you want floating container to show active dock widget's icon instead of always showing application icon
//CDockManager::setConfigFlag(CDockManager::FloatingContainerHasWidgetIcon, true);
2020-04-12 07:05:20 +08:00
// uncomment the following line if you want a central widget in the main dock container (the dock manager) without a titlebar
// If you enable this code, you can test it in the demo with the Calendar 0
// dock widget.
2022-11-02 03:42:52 +08:00
//CDockManager::setConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar, true);
2020-04-12 07:05:20 +08:00
2020-06-10 04:00:46 +08:00
// uncomment the following line to enable focus highlighting of the dock
// widget that has the focus
2022-10-28 21:21:21 +08:00
CDockManager : : setConfigFlag ( CDockManager : : FocusHighlighting , true ) ;
2020-05-23 17:17:31 +08:00
2022-09-22 10:40:11 +08:00
// uncomment if you would like to enable dock widget auto hiding
2023-06-22 20:45:29 +08:00
CDockManager : : setAutoHideConfigFlags ( { CDockManager : : DefaultAutoHideConfig } ) ;
2022-09-22 10:40:11 +08:00
2020-06-14 16:39:07 +08:00
// uncomment if you would like to enable an equal distribution of the
// available size of a splitter to all contained dock widgets
// CDockManager::setConfigFlag(CDockManager::EqualSplitOnInsertion, true);
2021-10-12 02:33:56 +08:00
// uncomment if you would like to close tabs with the middle mouse button, web browser style
// CDockManager::setConfigFlag(CDockManager::MiddleMouseButtonClosesTab, true);
2020-06-14 16:39:07 +08:00
2018-02-13 19:00:58 +08:00
// Now create the dock manager and its content
2018-11-08 19:57:25 +08:00
d - > DockManager = new CDockManager ( this ) ;
2021-01-03 04:05:05 +08:00
# if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
2022-11-19 04:22:44 +08:00
connect ( d - > PerspectiveComboBox , SIGNAL ( activated ( QString ) ) ,
d - > DockManager , SLOT ( openPerspective ( QString ) ) ) ;
2021-01-03 04:05:05 +08:00
# else
2022-11-19 04:22:44 +08:00
connect ( d - > PerspectiveComboBox , SIGNAL ( textActivated ( QString ) ) ,
d - > DockManager , SLOT ( openPerspective ( QString ) ) ) ;
2021-01-03 04:05:05 +08:00
# endif
2018-02-13 19:00:58 +08:00
d - > createContent ( ) ;
2020-01-11 20:53:58 +08:00
// Default window geometry - center on screen
2020-06-14 16:39:07 +08:00
resize ( 1280 , 720 ) ;
2020-01-11 20:53:58 +08:00
setGeometry ( QStyle : : alignedRect (
Qt : : LeftToRight , Qt : : AlignCenter , frameSize ( ) ,
QGuiApplication : : primaryScreen ( ) - > availableGeometry ( )
) ) ;
2018-02-13 19:00:58 +08:00
2019-11-25 22:28:15 +08:00
//d->restoreState();
2018-02-13 19:00:58 +08:00
d - > restorePerspectives ( ) ;
}
//============================================================================
CMainWindow : : ~ CMainWindow ( )
{
delete d ;
}
//============================================================================
void CMainWindow : : closeEvent ( QCloseEvent * event )
{
d - > saveState ( ) ;
2020-07-22 17:28:41 +08:00
// Delete dock manager here to delete all floating widgets. This ensures
// that all top level windows of the dock manager are properly closed
d - > DockManager - > deleteLater ( ) ;
2018-02-13 19:00:58 +08:00
QMainWindow : : closeEvent ( event ) ;
}
//============================================================================
void CMainWindow : : on_actionSaveState_triggered ( bool )
{
qDebug ( ) < < " MainWindow::on_actionSaveState_triggered " ;
d - > saveState ( ) ;
}
//============================================================================
void CMainWindow : : on_actionRestoreState_triggered ( bool )
{
qDebug ( ) < < " MainWindow::on_actionRestoreState_triggered " ;
d - > restoreState ( ) ;
}
//============================================================================
void CMainWindow : : savePerspective ( )
{
QString PerspectiveName = QInputDialog : : getText ( this , " Save Perspective " , " Enter unique name: " ) ;
if ( PerspectiveName . isEmpty ( ) )
{
return ;
}
d - > DockManager - > addPerspective ( PerspectiveName ) ;
QSignalBlocker Blocker ( d - > PerspectiveComboBox ) ;
d - > PerspectiveComboBox - > clear ( ) ;
d - > PerspectiveComboBox - > addItems ( d - > DockManager - > perspectiveNames ( ) ) ;
d - > PerspectiveComboBox - > setCurrentText ( PerspectiveName ) ;
d - > savePerspectives ( ) ;
}
2019-10-01 17:48:53 +08:00
//============================================================================
void CMainWindow : : onViewToggled ( bool Open )
{
2022-11-03 18:34:04 +08:00
Q_UNUSED ( Open ) ;
2019-10-01 17:48:53 +08:00
auto DockWidget = qobject_cast < ads : : CDockWidget * > ( sender ( ) ) ;
if ( ! DockWidget )
{
return ;
}
2022-11-04 19:10:52 +08:00
//qDebug() << DockWidget->objectName() << " viewToggled(" << Open << ")";
2019-10-01 17:48:53 +08:00
}
2019-12-10 21:44:44 +08:00
2020-01-14 22:58:45 +08:00
//============================================================================
void CMainWindow : : onViewVisibilityChanged ( bool Visible )
{
2020-06-06 20:59:03 +08:00
Q_UNUSED ( Visible ) ;
2020-01-14 22:58:45 +08:00
auto DockWidget = qobject_cast < ads : : CDockWidget * > ( sender ( ) ) ;
if ( ! DockWidget )
{
return ;
}
2020-06-04 01:49:57 +08:00
//qDebug() << DockWidget->objectName() << " visibilityChanged(" << Visible << ")";
2020-01-14 22:58:45 +08:00
}
2019-12-10 21:44:44 +08:00
//============================================================================
void CMainWindow : : createEditor ( )
{
2020-05-07 22:14:59 +08:00
QObject * Sender = sender ( ) ;
QVariant vFloating = Sender - > property ( " Floating " ) ;
bool Floating = vFloating . isValid ( ) ? vFloating . toBool ( ) : true ;
2022-11-14 21:56:06 +08:00
QVariant vTabbed = Sender - > property ( " Tabbed " ) ;
bool Tabbed = vTabbed . isValid ( ) ? vTabbed . toBool ( ) : true ;
2020-06-26 17:19:37 +08:00
auto DockWidget = d - > createEditorWidget ( ) ;
2019-12-10 21:44:44 +08:00
DockWidget - > setFeature ( ads : : CDockWidget : : DockWidgetDeleteOnClose , true ) ;
2020-10-14 02:55:09 +08:00
DockWidget - > setFeature ( ads : : CDockWidget : : DockWidgetForceCloseWithArea , true ) ;
2020-01-06 18:42:36 +08:00
connect ( DockWidget , SIGNAL ( closeRequested ( ) ) , SLOT ( onEditorCloseRequested ( ) ) ) ;
2020-05-07 22:14:59 +08:00
if ( Floating )
{
auto FloatingWidget = d - > DockManager - > addDockWidgetFloating ( DockWidget ) ;
FloatingWidget - > move ( QPoint ( 20 , 20 ) ) ;
2020-11-21 22:08:30 +08:00
d - > LastCreatedFloatingEditor = DockWidget ;
d - > LastDockedEditor . clear ( ) ;
2022-11-14 22:10:33 +08:00
return ;
2020-05-07 22:14:59 +08:00
}
2022-11-14 22:10:33 +08:00
ads : : CDockAreaWidget * EditorArea = d - > LastDockedEditor ? d - > LastDockedEditor - > dockAreaWidget ( ) : nullptr ;
if ( EditorArea )
{
if ( Tabbed )
{
// Test inserting the dock widget tab at a given position instead
// of appending it. This function inserts the new dock widget as
// first tab
d - > DockManager - > addDockWidgetTabToArea ( DockWidget , EditorArea , 0 ) ;
}
else
{
d - > DockManager - > setConfigFlag ( ads : : CDockManager : : EqualSplitOnInsertion , true ) ;
d - > DockManager - > addDockWidget ( ads : : RightDockWidgetArea , DockWidget , EditorArea ) ;
}
}
else
{
if ( d - > LastCreatedFloatingEditor )
{
d - > DockManager - > addDockWidget ( ads : : RightDockWidgetArea , DockWidget , d - > LastCreatedFloatingEditor - > dockAreaWidget ( ) ) ;
}
else
{
d - > DockManager - > addDockWidget ( ads : : TopDockWidgetArea , DockWidget ) ;
}
}
d - > LastDockedEditor = DockWidget ;
2020-01-06 18:42:36 +08:00
}
//============================================================================
void CMainWindow : : onEditorCloseRequested ( )
{
auto DockWidget = qobject_cast < ads : : CDockWidget * > ( sender ( ) ) ;
int Result = QMessageBox : : question ( this , " Close Editor " , QString ( " Editor %1 "
" contains unsaved changes? Would you like to close it? " )
. arg ( DockWidget - > windowTitle ( ) ) ) ;
if ( QMessageBox : : Yes = = Result )
{
DockWidget - > closeDockWidget ( ) ;
}
2019-12-10 21:44:44 +08:00
}
2019-12-11 22:50:13 +08:00
2022-11-07 15:19:00 +08:00
//============================================================================
void CMainWindow : : onImageViewerCloseRequested ( )
{
auto DockWidget = qobject_cast < ads : : CDockWidget * > ( sender ( ) ) ;
int Result = QMessageBox : : question ( this , " Close Image Viewer " , QString ( " %1 "
" contains unsaved changes? Would you like to close it? " )
. arg ( DockWidget - > windowTitle ( ) ) ) ;
if ( QMessageBox : : Yes = = Result )
{
DockWidget - > closeDockWidget ( ) ;
}
}
2019-12-11 22:50:13 +08:00
//============================================================================
void CMainWindow : : createTable ( )
{
2020-06-26 17:19:37 +08:00
auto DockWidget = d - > createTableWidget ( ) ;
2019-12-11 22:50:13 +08:00
DockWidget - > setFeature ( ads : : CDockWidget : : DockWidgetDeleteOnClose , true ) ;
auto FloatingWidget = d - > DockManager - > addDockWidgetFloating ( DockWidget ) ;
FloatingWidget - > move ( QPoint ( 40 , 40 ) ) ;
}
2020-04-14 22:07:00 +08:00
//============================================================================
void CMainWindow : : showStatusDialog ( )
{
CStatusDialog Dialog ( d - > DockManager ) ;
Dialog . exec ( ) ;
}
2020-07-06 03:48:48 +08:00
//============================================================================
void CMainWindow : : toggleDockWidgetWindowTitle ( )
{
QString Title = d - > WindowTitleTestDockWidget - > windowTitle ( ) ;
int i = Title . indexOf ( " (Test) " ) ;
if ( - 1 = = i )
{
Title + = " (Test) " ;
}
else
{
Title = Title . left ( i ) ;
}
d - > WindowTitleTestDockWidget - > setWindowTitle ( Title ) ;
}
2022-11-04 20:44:30 +08:00
//============================================================================
void CMainWindow : : applyVsStyle ( )
{
QFile StyleSheetFile ( " :adsdemo/res/visual_studio_light.css " ) ;
StyleSheetFile . open ( QIODevice : : ReadOnly ) ;
QTextStream StyleSheetStream ( & StyleSheetFile ) ;
auto Stylesheet = StyleSheetStream . readAll ( ) ;
StyleSheetFile . close ( ) ;
d - > DockManager - > setStyleSheet ( Stylesheet ) ;
}
2022-11-07 15:11:50 +08:00
//============================================================================
void CMainWindow : : createImageViewer ( )
{
QAction * a = qobject_cast < QAction * > ( sender ( ) ) ;
qDebug ( ) < < " createImageViewer " < < a - > text ( ) ;
auto DockWidget = d - > createImageViewer ( ) ;
DockWidget - > setFeature ( ads : : CDockWidget : : DockWidgetDeleteOnClose , true ) ;
DockWidget - > setFeature ( ads : : CDockWidget : : DockWidgetForceCloseWithArea , true ) ;
DockWidget - > setFeature ( ads : : CDockWidget : : CustomCloseHandling , true ) ;
DockWidget - > resize ( QSize ( 640 , 480 ) ) ;
2022-11-07 15:19:00 +08:00
connect ( DockWidget , & ads : : CDockWidget : : closeRequested , this ,
& CMainWindow : : onImageViewerCloseRequested ) ;
2022-11-07 15:11:50 +08:00
if ( a - > text ( ) . startsWith ( " Floating " ) )
{
auto FloatingWidget = d - > DockManager - > addDockWidgetFloating ( DockWidget ) ;
FloatingWidget - > move ( QPoint ( 20 , 20 ) ) ;
}
else if ( a - > text ( ) . startsWith ( " Docked " ) )
{
d - > DockManager - > addDockWidget ( ads : : RightDockWidgetArea , DockWidget ) ;
}
else if ( a - > text ( ) . startsWith ( " Pinned " ) )
{
d - > DockManager - > addAutoHideDockWidget ( ads : : SideBarLeft , DockWidget ) ;
}
}