Qt-Advanced-Docking-System/AdvancedDockingSystem/include/ads/ContainerWidget.h

159 lines
5.0 KiB
C
Raw Normal View History

2015-12-09 19:21:38 +08:00
#ifndef ADS_CONTAINERWIDGET_H
#define ADS_CONTAINERWIDGET_H
#include <QList>
2016-02-26 19:48:10 +08:00
#include <QHash>
#include <QPointer>
2015-12-09 19:21:38 +08:00
#include <QFrame>
class QPoint;
2015-12-09 19:21:38 +08:00
class QSplitter;
class QMenu;
class QGridLayout;
2015-12-09 19:21:38 +08:00
#include "ads/API.h"
#include "ads/Internal.h"
#include "ads/SectionContent.h"
#include "ads/FloatingWidget.h"
2015-12-09 19:21:38 +08:00
ADS_NAMESPACE_BEGIN
class SectionWidget;
class InternalContentData;
/*!
* ContainerWidget is the main container to provide the docking
* functionality. It manages multiple sections with all possible areas.
*/
class ADS_EXPORT_API ContainerWidget : public QFrame
2015-12-09 19:21:38 +08:00
{
Q_OBJECT
Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
friend class SectionContent;
2015-12-09 19:21:38 +08:00
friend class SectionWidget;
friend class FloatingWidget;
friend class SectionTitleWidget;
friend class SectionContentWidget;
2015-12-09 19:21:38 +08:00
public:
explicit ContainerWidget(QWidget *parent = NULL);
virtual ~ContainerWidget();
2015-12-09 19:21:38 +08:00
//
// Public API
//
2015-12-09 19:21:38 +08:00
Qt::Orientation orientation() const;
void setOrientation(Qt::Orientation orientation);
/*!
* Adds the section-content <em>sc</em> to this container-widget into the section-widget <em>sw</em>.
* If <em>sw</em> is not NULL, the <em>area</em> is used to indicate how the content should be arranged.
* Returns a pointer to the SectionWidget of the added SectionContent. Do not use it for anything else than adding more
* SectionContent elements with this method.
*/
SectionWidget* addSectionContent(const SectionContent::RefPtr& sc, SectionWidget* sw = NULL, DropArea area = CenterDropArea);
/*!
* Shows the specific SectionContent in UI.
* Independed of the current state, whether it is used inside a section or is floating.
*/
bool showSectionContent(const SectionContent::RefPtr& sc);
/*!
* Closes the specified SectionContent from UI.
* Independed of the current state, whether it is used inside a section or is floating.
*/
bool hideSectionContent(const SectionContent::RefPtr& sc);
/*!
* Selects the specific SectionContent as current, if it is part of a SectionWidget.
* If SC is floating, it does nothing (or should we show it?)
*/
bool raiseSectionContent(const SectionContent::RefPtr& sc);
/*!
* Creates a QMenu based on available SectionContents.
* The caller is responsible to delete the menu.
*/
QMenu* createContextMenu() const;
2015-12-09 19:21:38 +08:00
/*!
* Serializes the current state of contents and returns it as a plain byte array.
* \see restoreState(const QByteArray&)
*/
QByteArray saveState() const;
/*!
* Deserilizes the state of contents from <em>data</em>, which was written with <em>saveState()</em>.
* \see saveState()
*/
bool restoreState(const QByteArray& data);
//
// Advanced Public API
// You usually should not need access to this methods
//
// Outer DropAreas
2015-12-09 19:21:38 +08:00
QRect outerTopDropRect() const;
QRect outerRightDropRect() const;
QRect outerBottomDropRect() const;
QRect outerLeftDropRect() const;
private:
//
// Internal Stuff Begins Here
//
SectionWidget* newSectionWidget();
SectionWidget* dropContent(const InternalContentData& data, SectionWidget* targetSection, DropArea area, bool autoActive = true);
void addSection(SectionWidget* section);
SectionWidget* sectionAt(const QPoint& pos) const;
SectionWidget* dropContentOuterHelper(QLayout* l, const InternalContentData& data, Qt::Orientation orientation, bool append);
// Serialization
void saveFloatingWidgets(QDataStream& out) const;
void saveSectionWidgets(QDataStream& out, QWidget* widget) const;
bool restoreFloatingWidgets(QDataStream& in, int version, QList<FloatingWidget*>& floatings);
bool restoreSectionWidgets(QDataStream& in, int version, QSplitter* currentSplitter, QList<SectionWidget*>& sections, QList<SectionContent::RefPtr>& contentsToHide);
bool takeContent(const SectionContent::RefPtr& sc, InternalContentData& data);
private slots:
void onActiveTabChanged();
void onActionToggleSectionContentVisibility(bool visible);
2015-12-09 19:21:38 +08:00
signals:
void orientationChanged();
/*!
* Emits whenever the "isActiveTab" state of a SectionContent changes.
* Whenever the users sets another tab as active, this signal gets invoked
* for the old tab and the new active tab (the order is unspecified).
*/
void activeTabChanged(const SectionContent::RefPtr& sc, bool active);
private:
// Elements inside container.
2015-12-09 19:21:38 +08:00
QList<SectionWidget*> _sections;
QList<FloatingWidget*> _floatings;
QHash<int, HiddenSectionItem> _hiddenSectionContents;
// Helper lookup maps, restricted to this container.
QHash<int, SectionContent::WeakPtr> _scLookupMapById;
QHash<QString, SectionContent::WeakPtr> _scLookupMapByName;
QHash<int, SectionWidget*> _swLookupMapById;
2015-12-09 19:21:38 +08:00
// Layout stuff
QGridLayout* _mainLayout;
Qt::Orientation _orientation;
QPointer<QSplitter> _splitter; // $mfreiholz: I'd like to remove this variable entirely,
// because it changes during user interaction anyway.
2015-12-09 19:21:38 +08:00
};
ADS_NAMESPACE_END
2016-02-12 14:15:10 +08:00
#endif