2017-02-25 05:44:02 +08:00
# ifndef DockManagerH
# define DockManagerH
2017-02-27 21:15:20 +08:00
/*******************************************************************************
2017-06-10 04:04:02 +08:00
* * Qt Advanced Docking System
2017-02-27 21:15:20 +08:00
* * Copyright ( C ) 2017 Uwe Kindler
2018-05-06 18:45:46 +08:00
* *
2017-06-10 04:04:02 +08:00
* * 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 .
2018-05-06 18:45:46 +08:00
* *
2017-06-10 04:04:02 +08:00
* * This library is distributed in the hope that it will be useful ,
2017-02-27 21:15:20 +08:00
* * but WITHOUT ANY WARRANTY ; without even the implied warranty of
2017-06-10 04:04:02 +08:00
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* * Lesser General Public License for more details .
2018-05-06 18:45:46 +08:00
* *
2017-06-10 04:04:02 +08:00
* * 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/>.
2017-02-27 21:15:20 +08:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2017-02-25 05:44:02 +08:00
//============================================================================
/// \file DockManager.h
/// \author Uwe Kindler
2017-02-27 01:13:56 +08:00
/// \date 26.02.2017
/// \brief Declaration of CDockManager class
2017-02-25 05:44:02 +08:00
//============================================================================
2017-02-27 21:15:20 +08:00
2017-02-25 05:44:02 +08:00
//============================================================================
// INCLUDES
//============================================================================
2019-11-26 21:40:56 +08:00
# include <ads_globals.h>
# include <DockContainerWidget.h>
# include <DockWidget.h>
# include <FloatingDockContainer.h>
# include <qbytearray.h>
# include <qflags.h>
# include <qlist.h>
# include <qmap.h>
# include <qobjectdefs.h>
# include <qstring.h>
# include <qstringlist.h>
# include <QtGui/qicon.h>
2018-07-17 21:11:49 +08:00
2018-02-13 19:00:58 +08:00
class QSettings ;
2018-09-14 04:19:13 +08:00
class QMenu ;
2018-02-13 19:00:58 +08:00
2017-02-25 05:44:02 +08:00
namespace ads
{
2017-02-27 01:13:56 +08:00
struct DockManagerPrivate ;
2017-03-01 21:09:56 +08:00
class CFloatingDockContainer ;
2018-08-29 14:47:05 +08:00
struct FloatingDockContainerPrivate ;
2017-03-01 23:13:37 +08:00
class CDockContainerWidget ;
2019-11-27 22:50:18 +08:00
class DockContainerWidgetPrivate ;
2017-03-01 23:13:37 +08:00
class CDockOverlay ;
2018-08-29 14:47:05 +08:00
class CDockAreaTabBar ;
class CDockWidgetTab ;
struct DockWidgetTabPrivate ;
struct DockAreaWidgetPrivate ;
2019-10-18 14:31:26 +08:00
class CIconProvider ;
2017-02-25 05:44:02 +08:00
/**
2019-06-26 20:57:14 +08:00
* The central dock manager that maintains the complete docking system .
* With the configuration flags you can globally control the functionality
2019-09-09 22:01:51 +08:00
* of the docking system . The dock manager uses an internal stylesheet to
* style its components like splitters , tabs and buttons . If you want to
* disable this stylesheet because your application uses its own ,
* just call the function for settings the stylesheet with an empty
* string .
* \ code
* DockManager - > setStyleSheet ( " " ) ;
* \ endcode
2017-02-27 01:13:56 +08:00
* */
2018-07-17 21:11:49 +08:00
class ADS_EXPORT CDockManager : public CDockContainerWidget
2017-02-25 05:44:02 +08:00
{
2017-02-27 01:13:56 +08:00
Q_OBJECT
private :
DockManagerPrivate * d ; ///< private data (pimpl)
2018-05-06 18:45:46 +08:00
friend struct DockManagerPrivate ;
2018-08-29 14:47:05 +08:00
friend class CFloatingDockContainer ;
friend struct FloatingDockContainerPrivate ;
friend class CDockContainerWidget ;
2019-11-27 22:50:18 +08:00
friend class DockContainerWidgetPrivate ;
2018-08-29 14:47:05 +08:00
friend class CDockAreaTabBar ;
friend class CDockWidgetTab ;
friend struct DockAreaWidgetPrivate ;
friend struct DockWidgetTabPrivate ;
2019-11-26 21:40:56 +08:00
friend class CFloatingOverlay ;
friend struct FloatingOverlayPrivate ;
2017-03-01 23:13:37 +08:00
2017-02-27 01:13:56 +08:00
protected :
2017-03-01 21:09:56 +08:00
/**
* Registers the given floating widget in the internal list of
* floating widgets
*/
void registerFloatingWidget ( CFloatingDockContainer * FloatingWidget ) ;
2017-03-01 23:13:37 +08:00
/**
* Remove the given floating widget from the list of registered floating
* widgets
*/
void removeFloatingWidget ( CFloatingDockContainer * FloatingWidget ) ;
/**
* Registers the given dock container widget
*/
void registerDockContainer ( CDockContainerWidget * DockContainer ) ;
/**
* Remove dock container from the internal list of registered dock
* containers
*/
void removeDockContainer ( CDockContainerWidget * DockContainer ) ;
/**
* Overlay for containers
*/
CDockOverlay * containerOverlay ( ) const ;
/**
* Overlay for dock areas
*/
CDockOverlay * dockAreaOverlay ( ) const ;
2019-11-25 22:28:15 +08:00
/**
* Show the floating widgets that has been created floating
*/
virtual void showEvent ( QShowEvent * event ) override ;
2018-08-29 14:47:05 +08:00
public :
2019-11-25 22:28:15 +08:00
using Super = CDockContainerWidget ;
2018-09-14 04:19:13 +08:00
enum eViewMenuInsertionOrder
{
MenuSortedByInsertion ,
MenuAlphabeticallySorted
} ;
2018-11-08 19:57:25 +08:00
/**
* These global configuration flags configure some global dock manager
* settings .
*/
enum eConfigFlag
{
2019-09-13 20:19:43 +08:00
ActiveTabHasCloseButton = 0x0001 , //!< If this flag is set, the active tab in a tab area has a close button
DockAreaHasCloseButton = 0x0002 , //!< If the flag is set each dock area has a close button
DockAreaCloseButtonClosesTab = 0x0004 , //!< If the flag is set, the dock area close button closes the active tab, if not set, it closes the complete cock area
OpaqueSplitterResize = 0x0008 , //!< See QSplitter::setOpaqueResize() documentation
XmlAutoFormattingEnabled = 0x0010 , //!< If enabled, the XML writer automatically adds line-breaks and indentation to empty sections between elements (ignorable whitespace).
XmlCompressionEnabled = 0x0020 , //!< If enabled, the XML output will be compressed and is not human readable anymore
TabCloseButtonIsToolButton = 0x0040 , //! If enabled the tab close buttons will be QToolButtons instead of QPushButtons - disabled by default
AllTabsHaveCloseButton = 0x0080 , //!< if this flag is set, then all tabs that are closable show a close button
RetainTabSizeWhenCloseButtonHidden = 0x0100 , //!< if this flag is set, the space for the close button is reserved even if the close button is not visible
2019-11-26 21:40:56 +08:00
OpaqueUndocking = 0x0200 ,
DefaultConfig = ActiveTabHasCloseButton
| DockAreaHasCloseButton
| OpaqueSplitterResize
| XmlCompressionEnabled
| OpaqueUndocking , ///< the default configuration
2018-11-08 19:57:25 +08:00
} ;
Q_DECLARE_FLAGS ( ConfigFlags , eConfigFlag )
2018-08-29 14:47:05 +08:00
/**
* Default Constructor .
* If the given parent is a QMainWindow , the dock manager sets itself as the
2018-11-08 19:57:25 +08:00
* central widget .
* Before you create any dock widgets , you should properly setup the
2019-08-26 13:58:56 +08:00
* configuration flags via setConfigFlags ( ) .
2018-08-29 14:47:05 +08:00
*/
CDockManager ( QWidget * parent = 0 ) ;
/**
* Virtual Destructor
*/
virtual ~ CDockManager ( ) ;
2018-11-08 19:57:25 +08:00
/**
* This function returns the global configuration flags
*/
2019-09-13 03:15:35 +08:00
static ConfigFlags configFlags ( ) ;
2018-11-08 19:57:25 +08:00
/**
* Sets the global configuration flags for the whole docking system .
* Call this function before you create your first dock widget .
*/
2019-09-13 03:15:35 +08:00
static void setConfigFlags ( const ConfigFlags Flags ) ;
2018-11-08 19:57:25 +08:00
2019-09-13 20:19:43 +08:00
/**
* Set a certain config flag
*/
static void setConfigFlag ( eConfigFlag Flag , bool On = true ) ;
2019-10-18 14:31:26 +08:00
/**
* Returns the global icon provider .
* The icon provider enables the use of custom icons in case using
* styleheets for icons is not an option .
*/
static CIconProvider & iconProvider ( ) ;
2017-03-27 16:41:27 +08:00
/**
* Adds dockwidget into the given area .
* If DockAreaWidget is not null , then the area parameter indicates the area
* into the DockAreaWidget . If DockAreaWidget is null , the Dockwidget will
2018-08-29 14:47:05 +08:00
* be dropped into the container . If you would like to add a dock widget
* tabified , then you need to add it to an existing dock area object
* into the CenterDockWidgetArea . The following code shows this :
* \ code
* DockManager - > addDockWidget ( ads : : CenterDockWidgetArea , NewDockWidget ,
* ExisitingDockArea ) ;
* \ endcode
2017-03-27 16:41:27 +08:00
* \ return Returns the dock area widget that contains the new DockWidget
*/
CDockAreaWidget * addDockWidget ( DockWidgetArea area , CDockWidget * Dockwidget ,
CDockAreaWidget * DockAreaWidget = nullptr ) ;
2018-09-07 17:10:14 +08:00
/**
* This function will add the given Dockwidget to the given dock area as
* a new tab .
* If no dock area widget exists for the given area identifier , a new
* dock area widget is created .
*/
CDockAreaWidget * addDockWidgetTab ( DockWidgetArea area ,
CDockWidget * Dockwidget ) ;
/**
* This function will add the given Dockwidget to the given DockAreaWidget
* as a new tab .
*/
CDockAreaWidget * addDockWidgetTabToArea ( CDockWidget * Dockwidget ,
CDockAreaWidget * DockAreaWidget ) ;
2019-11-25 22:28:15 +08:00
/**
* Adds the given DockWidget floating and returns the created
* CFloatingDockContainer instance .
*/
CFloatingDockContainer * addDockWidgetFloating ( CDockWidget * Dockwidget ) ;
2017-03-27 16:41:27 +08:00
/**
* Searches for a registered doc widget with the given ObjectName
* \ return Return the found dock widget or nullptr if a dock widget with the
* given name is not registered
*/
2018-12-02 19:09:31 +08:00
CDockWidget * findDockWidget ( const QString & ObjectName ) const ;
2019-05-15 20:47:58 +08:00
/**
* Remove the given Dock from the dock manager
*/
void removeDockWidget ( CDockWidget * Dockwidget ) ;
2018-12-02 19:09:31 +08:00
/**
* This function returns a readable reference to the internal dock
* widgets map so that it is possible to iterate over all dock widgets
*/
QMap < QString , CDockWidget * > dockWidgetsMap ( ) const ;
2017-03-27 16:41:27 +08:00
2017-03-01 23:13:37 +08:00
/**
* Returns the list of all active and visible dock containers
* Dock containers are the main dock manager and all floating widgets
*/
const QList < CDockContainerWidget * > dockContainers ( ) const ;
/**
* Returns the list of all floating widgets
*/
const QList < CFloatingDockContainer * > floatingWidgets ( ) const ;
2017-03-02 22:49:53 +08:00
/**
* This function always return 0 because the main window is always behind
* any floating widget
*/
virtual unsigned int zOrderIndex ( ) const ;
2017-03-23 22:57:15 +08:00
/**
* Saves the current state of the dockmanger and all its dock widgets
2018-09-14 04:19:13 +08:00
* into the returned QByteArray .
* The XmlMode enables / disables the auto formatting for the XmlStreamWriter .
* If auto formatting is enabled , the output is intended and line wrapped .
* The XmlMode XmlAutoFormattingDisabled is better if you would like to have
* a more compact XML output - i . e . for storage in ini files .
2017-03-23 22:57:15 +08:00
*/
2019-06-26 20:57:14 +08:00
QByteArray saveState ( int version = 0 ) const ;
2017-03-23 22:57:15 +08:00
/**
* Restores the state of this dockmanagers dockwidgets .
* The version number is compared with that stored in state . If they do
* not match , the dockmanager ' s state is left unchanged , and this function
* returns false ; otherwise , the state is restored , and this function
* returns true .
*/
bool restoreState ( const QByteArray & state , int version = 0 ) ;
2018-02-13 19:00:58 +08:00
/**
* Saves the current perspective to the internal list of perspectives .
* A perspective is the current state of the dock manager assigned
* with a certain name . This makes it possible for the user ,
* to switch between different perspectives quickly .
* If a perspective with the given name already exists , then
* it will be overwritten with the new state .
*/
void addPerspective ( const QString & UniquePrespectiveName ) ;
2018-12-02 19:09:31 +08:00
/**
* Removes the perspective with the given name from the list of perspectives
*/
void removePerspective ( const QString & Name ) ;
/**
* Removes the given perspectives from the dock manager
*/
void removePerspectives ( const QStringList & Names ) ;
2018-02-13 19:00:58 +08:00
/**
* Returns the names of all available perspectives
*/
QStringList perspectiveNames ( ) const ;
/**
* Saves the perspectives to the given settings file .
*/
void savePerspectives ( QSettings & Settings ) const ;
/**
* Loads the perspectives from the given settings file
*/
void loadPerspectives ( QSettings & Settings ) ;
2018-09-14 04:19:13 +08:00
/**
* Adds a toggle view action to the the internal view menu .
* You can either manage the insertion of the toggle view actions in your
* application or you can add the actions to the internal view menu and
* then simply insert the menu object into your .
* \ param [ in ] ToggleViewAction The action to insert . If no group is provided
* the action is directly inserted into the menu . If a group
* is provided , the action is inserted into the group and the
* group is inserted into the menu if it is not existing yet .
* \ param [ in ] Group This is the text used for the group menu item
* \ param [ in ] GroupIcon The icon used for grouping the workbenches in the
* view menu . I . e . if there is a workbench for each device
* like for spectrometer devices , it is good to group all these
* workbenches under a menu item
2018-09-26 15:57:36 +08:00
* \ return If Group is not empty , this function returns the GroupAction
* for this group . If the group is empty , the function returns
* the given ToggleViewAction .
2018-09-14 04:19:13 +08:00
*/
2018-09-26 15:57:36 +08:00
QAction * addToggleViewActionToMenu ( QAction * ToggleViewAction ,
2018-09-14 04:19:13 +08:00
const QString & Group = QString ( ) , const QIcon & GroupIcon = QIcon ( ) ) ;
/**
* This function returns the internal view menu .
* To fill the view menu , you can use the addToggleViewActionToMenu ( )
* function .
*/
QMenu * viewMenu ( ) const ;
/**
* Define the insertion order for toggle view menu items .
* The order defines how the actions are added to the view menu .
* The default insertion order is MenuAlphabeticallySorted to make it
* easier for users to find the menu entry for a certain dock widget .
* You need to call this function befor you insert the first menu item
* into the view menu .
*/
void setViewMenuInsertionOrder ( eViewMenuInsertionOrder Order ) ;
2018-10-10 21:15:59 +08:00
/**
* This function returns true between the restoringState ( ) and
* stateRestored ( ) signals .
*/
bool isRestoringState ( ) const ;
2018-11-05 16:58:46 +08:00
/**
* The distance the user needs to move the mouse with the left button
* hold down before a dock widget start floating
*/
static int startDragDistance ( ) ;
2018-02-13 19:00:58 +08:00
public slots :
/**
* Opens the perspective with the given name .
*/
void openPerspective ( const QString & PerspectiveName ) ;
signals :
/**
* This signal is emitted if the list of perspectives changed
*/
void perspectiveListChanged ( ) ;
2018-08-10 20:11:57 +08:00
2018-12-11 22:19:59 +08:00
/**
* This signal is emitted if perspectives have been removed
*/
void perspectivesRemoved ( ) ;
2018-09-27 22:21:14 +08:00
/**
* This signal is emitted , if the restore function is called , just before
* the dock manager starts restoring the state .
* If this function is called , nothing has changed yet
*/
void restoringState ( ) ;
2018-08-10 20:11:57 +08:00
/**
2018-08-24 19:41:58 +08:00
* This signal is emitted if the state changed in restoreState .
* The signal is emitted if the restoreState ( ) function is called or
* if the openPerspective ( ) function is called
2018-08-10 20:11:57 +08:00
*/
2018-09-27 22:21:14 +08:00
void stateRestored ( ) ;
/**
* This signal is emitted , if the dock manager starts opening a
* perspective .
* Opening a perspective may take more than a second if there are
* many complex widgets . The application may use this signal
* to show some progress indicator or to change the mouse cursor
* into a busy cursor .
*/
void openingPerspective ( const QString & PerspectiveName ) ;
/**
* This signal is emitted if the dock manager finished opening a
* perspective
*/
void perspectiveOpened ( const QString & PerspectiveName ) ;
2019-11-23 04:53:17 +08:00
/**
* This signal is emitted , if a new DockArea has been created .
* An application can use this signal to set custom icons or custom
* tooltips for the DockArea buttons .
*/
void dockAreaCreated ( CDockAreaWidget * DockArea ) ;
2017-02-27 01:13:56 +08:00
} ; // class DockManager
2017-02-25 05:44:02 +08:00
} // namespace ads
2017-02-27 01:13:56 +08:00
//-----------------------------------------------------------------------------
2017-02-25 05:44:02 +08:00
# endif // DockManagerH