2017-03-23 17:23:53 +08:00
|
|
|
#ifndef DockWidgetH
|
|
|
|
#define DockWidgetH
|
|
|
|
/*******************************************************************************
|
2017-06-10 04:04:02 +08:00
|
|
|
** Qt Advanced Docking System
|
2017-03-23 17:23:53 +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-03-23 17:23:53 +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-03-23 17:23:53 +08:00
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
/// \file DockWidget.h
|
|
|
|
/// \author Uwe Kindler
|
|
|
|
/// \date 26.02.2017
|
|
|
|
/// \brief Declaration of CDockWidget class
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// INCLUDES
|
|
|
|
//============================================================================
|
|
|
|
#include <QFrame>
|
|
|
|
|
2018-07-17 21:11:49 +08:00
|
|
|
#include "ads_globals.h"
|
|
|
|
|
2017-12-30 01:18:16 +08:00
|
|
|
class QXmlStreamWriter;
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
namespace ads
|
|
|
|
{
|
|
|
|
struct DockWidgetPrivate;
|
2018-08-24 19:41:58 +08:00
|
|
|
class CDockWidgetTab;
|
2017-03-23 17:23:53 +08:00
|
|
|
class CDockManager;
|
|
|
|
class CDockContainerWidget;
|
|
|
|
class CDockAreaWidget;
|
2017-03-29 04:38:47 +08:00
|
|
|
struct DockContainerWidgetPrivate;
|
2017-03-23 17:23:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The QDockWidget class provides a widget that can be docked inside a
|
|
|
|
* CDockManager or floated as a top-level window on the desktop.
|
|
|
|
*/
|
2018-07-17 21:11:49 +08:00
|
|
|
class ADS_EXPORT CDockWidget : public QFrame
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private:
|
|
|
|
DockWidgetPrivate* d; ///< private data (pimpl)
|
2018-05-06 18:45:46 +08:00
|
|
|
friend struct DockWidgetPrivate;
|
2017-03-23 17:23:53 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class CDockContainerWidget;
|
|
|
|
friend class CDockAreaWidget;
|
|
|
|
friend class CFloatingDockContainer;
|
2017-03-28 16:57:03 +08:00
|
|
|
friend class CDockManager;
|
2018-05-06 18:45:46 +08:00
|
|
|
friend struct DockContainerWidgetPrivate;
|
2017-03-23 17:23:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Assigns the dock manager that manages this dock widget
|
|
|
|
*/
|
|
|
|
void setDockManager(CDockManager* DockManager);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If this dock widget is inserted into a dock area, the dock area will
|
|
|
|
* be registered on this widget via this function. If a dock widget is
|
|
|
|
* removed from a dock area, this function will be called with nullptr
|
|
|
|
* value.
|
|
|
|
*/
|
|
|
|
void setDockArea(CDockAreaWidget* DockArea);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function changes the toggle view action without emitting any
|
|
|
|
* signal
|
|
|
|
*/
|
|
|
|
void setToggleViewActionChecked(bool Checked);
|
|
|
|
|
2017-03-23 22:57:15 +08:00
|
|
|
/**
|
|
|
|
* Saves the state into the given stream
|
|
|
|
*/
|
2017-12-30 01:18:16 +08:00
|
|
|
void saveState(QXmlStreamWriter& Stream) const;
|
2017-03-23 22:57:15 +08:00
|
|
|
|
2017-03-28 16:57:03 +08:00
|
|
|
/**
|
|
|
|
* This is a helper function for the dock manager to flag this widget
|
|
|
|
* as unassigned.
|
|
|
|
* When calling the restore function, it may happen, that the saved state
|
|
|
|
* contains less dock widgets then currently available. All widgets whose
|
|
|
|
* data is not contained in the saved state, are flagged as unassigned
|
|
|
|
* after the restore process. If the user shows an unassigned dock widget,
|
|
|
|
* a floating widget will be created to take up the dock widget.
|
|
|
|
*/
|
|
|
|
void flagAsUnassigned();
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
public:
|
|
|
|
enum DockWidgetFeature
|
|
|
|
{
|
|
|
|
DockWidgetClosable = 0x01,
|
|
|
|
DockWidgetMovable = 0x02,
|
|
|
|
DockWidgetFloatable = 0x04,
|
|
|
|
AllDockWidgetFeatures = DockWidgetClosable | DockWidgetMovable | DockWidgetFloatable,
|
|
|
|
NoDockWidgetFeatures = 0x00
|
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(DockWidgetFeatures, DockWidgetFeature)
|
|
|
|
|
|
|
|
|
|
|
|
enum eState
|
|
|
|
{
|
|
|
|
StateHidden,
|
|
|
|
StateDocked,
|
|
|
|
StateFloating
|
|
|
|
};
|
|
|
|
|
2018-01-02 15:01:23 +08:00
|
|
|
/**
|
|
|
|
* This mode configures the behavior of the toggle view action.
|
|
|
|
* If the mode if ActionModeToggle, then the toggle view action is
|
|
|
|
* a checkable action to show / hide the dock widget. If the mode
|
|
|
|
* is ActionModeShow, then the action is not checkable an it will
|
|
|
|
* always show the dock widget if clicked. If the mode is ActionModeShow,
|
|
|
|
* the user can only close the DockWidget with the close button.
|
|
|
|
*/
|
|
|
|
enum eToggleViewActionMode
|
|
|
|
{
|
|
|
|
ActionModeToggle,//!< ActionModeToggle
|
|
|
|
ActionModeShow //!< ActionModeShow
|
|
|
|
};
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
/**
|
|
|
|
* Default Constructor
|
|
|
|
*/
|
|
|
|
CDockWidget(const QString &title, QWidget* parent = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Virtual Destructor
|
|
|
|
*/
|
|
|
|
virtual ~CDockWidget();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the widget for the dock widget to widget.
|
|
|
|
*/
|
|
|
|
void setWidget(QWidget* widget);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the widget for the dock widget. This function returns zero if
|
|
|
|
* the widget has not been set.
|
|
|
|
*/
|
|
|
|
QWidget* widget() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the title bar widget of this dock widget
|
|
|
|
*/
|
2018-08-24 19:41:58 +08:00
|
|
|
CDockWidgetTab* titleBar() const;
|
2017-03-23 17:23:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets, whether the dock widget is movable, closable, and floatable.
|
|
|
|
*/
|
|
|
|
void setFeatures(DockWidgetFeatures features);
|
|
|
|
|
2018-08-24 19:41:58 +08:00
|
|
|
/**
|
|
|
|
* Sets the feature flag for this dock widget if on is true; otherwise
|
|
|
|
* clears the flag.
|
|
|
|
*/
|
|
|
|
void setFeature(DockWidgetFeature flag, bool on);
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
/**
|
|
|
|
* This property holds whether the dock widget is movable, closable, and
|
|
|
|
* floatable.
|
|
|
|
* By default, this property is set to a combination of DockWidgetClosable,
|
|
|
|
* DockWidgetMovable and DockWidgetFloatable.
|
|
|
|
*/
|
|
|
|
DockWidgetFeatures features() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the dock manager that manages the dock widget or 0 if the widget
|
|
|
|
* has not been assigned to any dock manager yet
|
|
|
|
*/
|
|
|
|
CDockManager* dockManager() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the dock container widget this dock area widget belongs to or 0
|
|
|
|
* if this dock widget has nt been docked yet
|
|
|
|
*/
|
|
|
|
CDockContainerWidget* dockContainer() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the dock area widget this dock widget belongs to or 0
|
|
|
|
* if this dock widget has not been docked yet
|
|
|
|
*/
|
|
|
|
CDockAreaWidget* dockAreaWidget() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This property holds whether the dock widget is floating.
|
|
|
|
*/
|
|
|
|
bool isFloating() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true, if this dock widget is closed.
|
|
|
|
*/
|
|
|
|
bool isClosed() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a checkable action that can be used to show or close this dock widget.
|
|
|
|
* The action's text is set to the dock widget's window title.
|
|
|
|
*/
|
|
|
|
QAction* toggleViewAction() const;
|
|
|
|
|
2017-03-28 16:57:03 +08:00
|
|
|
/**
|
2018-01-02 15:01:23 +08:00
|
|
|
* Configures the behavior of the toggle view action.
|
|
|
|
* \see eToggleViewActionMode for a detailed description
|
|
|
|
*/
|
|
|
|
void setToggleViewActionMode(eToggleViewActionMode Mode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emits titleChanged signal if title change event occurs
|
2017-03-28 16:57:03 +08:00
|
|
|
*/
|
|
|
|
virtual bool event(QEvent *e) override;
|
|
|
|
|
2018-01-02 15:01:23 +08:00
|
|
|
/**
|
|
|
|
* Sets the dock widget icon that is shown in tabs and in toggle view
|
|
|
|
* actions
|
|
|
|
*/
|
|
|
|
void setIcon(const QIcon& Icon);
|
|
|
|
|
2018-08-27 21:40:01 +08:00
|
|
|
/**
|
|
|
|
* Returns tzhe icon that has been assigned to the dock widget
|
|
|
|
*/
|
|
|
|
QIcon icon() const;
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
public slots:
|
|
|
|
/**
|
|
|
|
* This property controls whether the dock widget is open or closed.
|
|
|
|
* The toogleViewAction triggers this slot
|
|
|
|
*/
|
2018-01-02 15:01:23 +08:00
|
|
|
void toggleView(bool Open = true);
|
2017-03-23 17:23:53 +08:00
|
|
|
|
|
|
|
signals:
|
|
|
|
/**
|
|
|
|
* This signal is emitted if the dock widget is opened or closed
|
|
|
|
*/
|
|
|
|
void viewToggled(bool Open);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This signal is emitted if the dock widget is closed
|
|
|
|
*/
|
|
|
|
void closed();
|
2017-03-28 16:57:03 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This signal is emitted if the window title of this dock widget
|
|
|
|
* changed
|
|
|
|
*/
|
|
|
|
void titleChanged(const QString& Title);
|
2017-03-23 17:23:53 +08:00
|
|
|
}; // class DockWidget
|
|
|
|
}
|
|
|
|
// namespace ads
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
#endif // DockWidgetH
|