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

107 lines
3.2 KiB
C
Raw Normal View History

2015-12-09 19:21:38 +08:00
#ifndef ADS_CONTAINERWIDGET_H
#define ADS_CONTAINERWIDGET_H
#include <QPointer>
2015-12-09 19:21:38 +08:00
#include <QFrame>
#include <QGridLayout>
#include <QPoint>
#include <QList>
class QSplitter;
class QMenu;
2015-12-09 19:21:38 +08:00
#include "ads/API.h"
#include "ads/SectionContent.h"
#include "ads/SectionWidget.h"
#include "ads/FloatingWidget.h"
2015-12-09 19:21:38 +08:00
ADS_NAMESPACE_BEGIN
class InternalContentData;
2015-12-09 19:21:38 +08:00
// ContainerWidget is the main container to provide the docking
// functionality. It manages mulitple Sections and all possible areas.
class ContainerWidget : public QFrame
{
Q_OBJECT
Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
friend class SectionWidget;
friend class FloatingWidget;
2015-12-09 19:21:38 +08:00
public:
explicit ContainerWidget(QWidget *parent = NULL);
//
// 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);
/*!
* Creates a QMenu based on available SectionContents.
* The ownership is needs to be handled by the caller.
*/
QMenu* createContextMenu() const;
2015-12-09 19:21:38 +08:00
//
// Internal Stuff Begins Here
//
// splitSections splits "section1" and "section2" with given "orientation".
// The "section2" element is moved to the "section1" element.
2015-12-09 19:21:38 +08:00
void splitSections(SectionWidget* section1, SectionWidget* section2, Qt::Orientation orientation = Qt::Horizontal);
SectionWidget* dropContent(const InternalContentData& data, SectionWidget* targetSection, DropArea area, bool autoActive = true);
void addSection(SectionWidget* section);
2015-12-09 19:21:38 +08:00
SectionWidget* sectionAt(const QPoint& pos) const;
// Drop areas for the ContainerWidget
QRect outerTopDropRect() const;
QRect outerRightDropRect() const;
QRect outerBottomDropRect() const;
QRect outerLeftDropRect() const;
// Geometry and state serialization
QByteArray saveState() const;
bool restoreState(const QByteArray& data);
private:
void saveGeometryWalk(QDataStream& out, QWidget* widget) const;
bool restoreGeometryWalk(QDataStream& in, QSplitter* currentSplitter = NULL);
// takeContent searches all section-widgets and floating-widgets for "sc" and takes
// the ownership of it and passes it to "data" object.
bool takeContent(const SectionContent::RefPtr& sc, InternalContentData& data);
private slots:
void onActionToggleSectionContentVisibility(bool visible);
2015-12-09 19:21:38 +08:00
signals:
void orientationChanged();
public:
// Existing sections.
// SectionWidgets are always visible.
QList<SectionWidget*> _sections;
// All currently active Floatingwidgets.
QList<FloatingWidget*> _floatingWidgets;
// Layout stuff
QGridLayout* _mainLayout;
Qt::Orientation _orientation;
QPointer<QSplitter> _splitter;
2015-12-09 19:21:38 +08:00
};
ADS_NAMESPACE_END
2016-02-12 14:15:10 +08:00
#endif