2017-03-23 17:23:53 +08:00
|
|
|
#ifndef DockAreaWidgetH
|
|
|
|
#define DockAreaWidgetH
|
|
|
|
/*******************************************************************************
|
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 DockAreaWidget.h
|
|
|
|
/// \author Uwe Kindler
|
|
|
|
/// \date 24.02.2017
|
|
|
|
/// \brief Declaration of CDockAreaWidget class
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// INCLUDES
|
|
|
|
//============================================================================
|
|
|
|
#include <QFrame>
|
|
|
|
|
2018-07-17 21:11:49 +08:00
|
|
|
#include "ads_globals.h"
|
2018-10-12 21:18:05 +08:00
|
|
|
#include "DockWidget.h"
|
2018-07-17 21:11:49 +08:00
|
|
|
|
2017-12-30 01:18:16 +08:00
|
|
|
class QXmlStreamWriter;
|
2018-11-04 03:51:02 +08:00
|
|
|
class QAbstractButton;
|
2017-12-30 01:18:16 +08:00
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
namespace ads
|
|
|
|
{
|
|
|
|
struct DockAreaWidgetPrivate;
|
|
|
|
class CDockManager;
|
|
|
|
class CDockContainerWidget;
|
2018-08-29 14:47:05 +08:00
|
|
|
struct DockContainerWidgetPrivate;
|
2017-03-23 17:23:53 +08:00
|
|
|
|
2017-03-24 17:18:25 +08:00
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
/**
|
2018-08-24 20:04:21 +08:00
|
|
|
* DockAreaWidget manages multiple instances of DockWidgets.
|
2017-03-23 17:23:53 +08:00
|
|
|
* It displays a title tab, which is clickable and will switch to
|
|
|
|
* the contents associated to the title when clicked.
|
|
|
|
*/
|
2018-07-17 21:11:49 +08:00
|
|
|
class ADS_EXPORT CDockAreaWidget : public QFrame
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private:
|
|
|
|
DockAreaWidgetPrivate* d; ///< private data (pimpl)
|
2018-05-06 18:45:46 +08:00
|
|
|
friend struct DockAreaWidgetPrivate;
|
2018-08-29 14:47:05 +08:00
|
|
|
friend class CDockContainerWidget;
|
|
|
|
friend class DockContainerWidgetPrivate;
|
|
|
|
friend class CDockWidgetTab;
|
2018-09-07 17:10:14 +08:00
|
|
|
friend struct DockWidgetPrivate;
|
|
|
|
friend class CDockWidget;
|
2018-11-01 15:52:14 +08:00
|
|
|
friend struct DockManagerPrivate;
|
2017-03-23 17:23:53 +08:00
|
|
|
|
|
|
|
private slots:
|
2018-10-12 20:51:57 +08:00
|
|
|
void onTabCloseRequested(int Index);
|
2017-03-23 17:23:53 +08:00
|
|
|
|
2018-10-12 15:17:14 +08:00
|
|
|
/**
|
|
|
|
* Reorder the index position of DockWidget at fromIndx to toIndex
|
|
|
|
* if a tab in the tabbar is dragged from one index to another one
|
|
|
|
*/
|
|
|
|
void reorderDockWidget(int fromIndex, int toIndex);
|
|
|
|
|
2018-08-29 14:47:05 +08:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Inserts a dock widget into dock area.
|
|
|
|
* All dockwidgets in the dock area tabified in a stacked layout with tabs.
|
|
|
|
* The index indicates the index of the new dockwidget in the tabbar and
|
|
|
|
* in the stacked layout. If the Activate parameter is true, the new
|
|
|
|
* DockWidget will be the active one in the stacked layout
|
|
|
|
*/
|
|
|
|
void insertDockWidget(int index, CDockWidget* DockWidget, bool Activate = true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new dock widget to dock area.
|
|
|
|
* All dockwidgets in the dock area tabified in a stacked layout with tabs
|
|
|
|
*/
|
|
|
|
void addDockWidget(CDockWidget* DockWidget);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the given dock widget from the dock area
|
|
|
|
*/
|
|
|
|
void removeDockWidget(CDockWidget* DockWidget);
|
|
|
|
|
2018-09-07 17:10:14 +08:00
|
|
|
/**
|
|
|
|
* Called from dock widget if it is opened or closed
|
|
|
|
*/
|
|
|
|
void toggleDockWidgetView(CDockWidget* DockWidget, bool Open);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a helper function to get the next open dock widget to activate
|
|
|
|
* if the given DockWidget will be closed or removed.
|
|
|
|
* The function returns the next widget that should be activated or
|
|
|
|
* nullptr in case there are no more open widgets in this area.
|
|
|
|
*/
|
|
|
|
CDockWidget* nextOpenDockWidget(CDockWidget* DockWidget) const;
|
2018-08-29 14:47:05 +08:00
|
|
|
|
2018-09-07 18:38:11 +08:00
|
|
|
/**
|
|
|
|
* Returns the index of the given DockWidget in the internal layout
|
|
|
|
*/
|
|
|
|
int index(CDockWidget* DockWidget);
|
|
|
|
|
2018-09-14 14:46:10 +08:00
|
|
|
/**
|
|
|
|
* Call this function, if you already know, that the dock does not
|
|
|
|
* contain any visible content (any open dock widgets).
|
|
|
|
*/
|
|
|
|
void hideAreaWithNoVisibleContent();
|
|
|
|
|
2018-09-26 15:57:36 +08:00
|
|
|
/**
|
|
|
|
* Updates the dock area layout and components visibility
|
|
|
|
*/
|
|
|
|
void updateTabBarVisibility();
|
|
|
|
|
2018-11-01 15:52:14 +08:00
|
|
|
/**
|
|
|
|
* This is the internal private function for setting the current widget.
|
|
|
|
* This function is called by the public setCurrentDockWidget() function
|
|
|
|
* and by the dock manager when restoring the state
|
|
|
|
*/
|
|
|
|
void internalSetCurrentDockWidget(CDockWidget* DockWidget);
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
public:
|
2018-10-15 14:29:30 +08:00
|
|
|
using Super = QFrame;
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
/**
|
|
|
|
* Default Constructor
|
|
|
|
*/
|
|
|
|
CDockAreaWidget(CDockManager* DockManager, CDockContainerWidget* parent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Virtual Destructor
|
|
|
|
*/
|
|
|
|
virtual ~CDockAreaWidget();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the dock manager object this dock area belongs to
|
|
|
|
*/
|
|
|
|
CDockManager* dockManager() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the dock container widget this dock area widget belongs to or 0
|
|
|
|
* if there is no
|
|
|
|
*/
|
|
|
|
CDockContainerWidget* dockContainer() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the rectangle of the title area
|
|
|
|
*/
|
2018-10-12 20:51:57 +08:00
|
|
|
QRect titleBarGeometry() const;
|
2017-03-23 17:23:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the rectangle of the content
|
|
|
|
*/
|
|
|
|
QRect contentAreaGeometry() const;
|
|
|
|
|
2018-09-14 14:46:10 +08:00
|
|
|
/**
|
|
|
|
* Returns the number of dock widgets in this area
|
|
|
|
*/
|
|
|
|
int dockWidgetsCount() const;
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
/**
|
|
|
|
* Returns a list of all dock widgets in this dock area.
|
|
|
|
* This list contains open and closed dock widgets.
|
|
|
|
*/
|
|
|
|
QList<CDockWidget*> dockWidgets() const;
|
|
|
|
|
|
|
|
/**
|
2018-09-14 14:46:10 +08:00
|
|
|
* Returns the number of dock widgets in this area
|
2017-03-23 17:23:53 +08:00
|
|
|
*/
|
2018-09-14 14:46:10 +08:00
|
|
|
int openDockWidgetsCount() const;
|
2017-03-23 17:23:53 +08:00
|
|
|
|
|
|
|
/**
|
2018-09-14 14:46:10 +08:00
|
|
|
* Returns a list of dock widgets that are not closed
|
2017-03-23 17:23:53 +08:00
|
|
|
*/
|
2018-09-14 14:46:10 +08:00
|
|
|
QList<CDockWidget*> openedDockWidgets() const;
|
2017-03-23 17:23:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a dock widget by its index
|
|
|
|
*/
|
|
|
|
CDockWidget* dockWidget(int Index) const;
|
|
|
|
|
|
|
|
/**
|
2018-11-04 03:51:02 +08:00
|
|
|
* Returns the index of the current active dock widget or -1 if there
|
|
|
|
* are is no active dock widget (ie.e if all dock widgets are closed)
|
2017-03-23 17:23:53 +08:00
|
|
|
*/
|
|
|
|
int currentIndex() const;
|
|
|
|
|
|
|
|
/**
|
2018-11-04 03:51:02 +08:00
|
|
|
* Returns the current active dock widget or a nullptr if there is no
|
|
|
|
* active dock widget (i.e. if all dock widgets are closed)
|
2017-03-23 17:23:53 +08:00
|
|
|
*/
|
|
|
|
CDockWidget* currentDockWidget() const;
|
|
|
|
|
|
|
|
/**
|
2018-08-29 14:47:05 +08:00
|
|
|
* Shows the tab with the given dock widget
|
2017-03-23 17:23:53 +08:00
|
|
|
*/
|
|
|
|
void setCurrentDockWidget(CDockWidget* DockWidget);
|
|
|
|
|
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
|
|
|
|
2018-10-12 21:18:05 +08:00
|
|
|
/**
|
|
|
|
* This functions returns the dock widget features of all dock widget in
|
|
|
|
* this area.
|
|
|
|
* A bitwise and is used to combine the flags of all dock widgets. That
|
|
|
|
* means, if only dock widget does not support a certain flag, the whole
|
|
|
|
* dock are does not support the flag.
|
|
|
|
*/
|
|
|
|
CDockWidget::DockWidgetFeatures features() const;
|
|
|
|
|
2018-11-04 03:51:02 +08:00
|
|
|
/**
|
|
|
|
* Returns the title bar button corresponding to the given title bar
|
|
|
|
* button identifier
|
|
|
|
*/
|
|
|
|
QAbstractButton* titleBarButton(TitleBarButton which) const;
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
public slots:
|
|
|
|
/**
|
2018-09-07 17:10:14 +08:00
|
|
|
* This activates the tab for the given tab index.
|
|
|
|
* If the dock widget for the given tab is not visible, the this function
|
|
|
|
* call will make it visible.
|
2017-03-23 17:23:53 +08:00
|
|
|
*/
|
|
|
|
void setCurrentIndex(int index);
|
|
|
|
|
2018-10-15 14:29:30 +08:00
|
|
|
/**
|
2018-11-01 14:53:54 +08:00
|
|
|
* This property controls whether the dock area is open or closed.
|
|
|
|
* The toogleViewAction triggers this slot.
|
2018-10-15 14:29:30 +08:00
|
|
|
*/
|
2018-11-01 14:53:54 +08:00
|
|
|
void toggleView(bool Open);
|
2018-10-15 14:29:30 +08:00
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
signals:
|
|
|
|
/**
|
|
|
|
* This signal is emitted when user clicks on a tab at an index.
|
|
|
|
*/
|
|
|
|
void tabBarClicked(int index);
|
|
|
|
|
2018-08-10 19:46:57 +08:00
|
|
|
/**
|
|
|
|
* This signal is emitted when the tab bar's current tab is about to be changed. The new
|
|
|
|
* current has the given index, or -1 if there isn't a new one.
|
|
|
|
* @param index
|
|
|
|
*/
|
|
|
|
void currentChanging(int index);
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
/**
|
|
|
|
* This signal is emitted when the tab bar's current tab changes. The new
|
|
|
|
* current has the given index, or -1 if there isn't a new one
|
|
|
|
* @param index
|
|
|
|
*/
|
|
|
|
void currentChanged(int index);
|
2018-11-01 14:53:54 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This signal is emitted if the visibility of this dock area is toggled
|
|
|
|
* via toggle view function
|
|
|
|
*/
|
|
|
|
void viewToggled(bool Open);
|
2017-03-23 17:23:53 +08:00
|
|
|
}; // class DockAreaWidget
|
|
|
|
}
|
|
|
|
// namespace ads
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
#endif // DockAreaWidgetH
|