mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 07:21:32 +08:00
Do some refactoring for public api logic
This commit is contained in:
parent
9b09ae2fa6
commit
2d1a3b8665
@ -15,11 +15,13 @@ class QMenu;
|
||||
#include "ads/FloatingWidget.h"
|
||||
|
||||
ADS_NAMESPACE_BEGIN
|
||||
|
||||
class InternalContentData;
|
||||
|
||||
// ContainerWidget is the main container to provide the docking
|
||||
// functionality. It manages mulitple Sections and all possible areas.
|
||||
|
||||
/*!
|
||||
* ContainerWidget is the main container to provide the docking
|
||||
* functionality. It manages mulitple Sections and all possible areas.
|
||||
*/
|
||||
class ContainerWidget : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -27,6 +29,8 @@ class ContainerWidget : public QFrame
|
||||
|
||||
friend class SectionWidget;
|
||||
friend class FloatingWidget;
|
||||
friend class SectionTitleWidget;
|
||||
friend class SectionContentWidget;
|
||||
|
||||
public:
|
||||
explicit ContainerWidget(QWidget *parent = NULL);
|
||||
@ -48,7 +52,7 @@ public:
|
||||
|
||||
/*!
|
||||
* Creates a QMenu based on available SectionContents.
|
||||
* The ownership is needs to be handled by the caller.
|
||||
* The caller is responsible to delete the menu.
|
||||
*/
|
||||
QMenu* createContextMenu() const;
|
||||
|
||||
@ -65,30 +69,27 @@ public:
|
||||
bool restoreState(const QByteArray& data);
|
||||
|
||||
//
|
||||
// Internal Stuff Begins Here
|
||||
// Advanced Public API
|
||||
// You usually should not need access to this methods
|
||||
//
|
||||
|
||||
// splitSections splits "section1" and "section2" with given "orientation".
|
||||
// The "section2" element is moved to the "section1" element.
|
||||
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);
|
||||
SectionWidget* sectionAt(const QPoint& pos) const;
|
||||
|
||||
// Drop areas for the ContainerWidget
|
||||
// Outer DropAreas
|
||||
QRect outerTopDropRect() const;
|
||||
QRect outerRightDropRect() const;
|
||||
QRect outerBottomDropRect() const;
|
||||
QRect outerLeftDropRect() const;
|
||||
|
||||
private:
|
||||
//
|
||||
// Internal Stuff Begins Here
|
||||
//
|
||||
|
||||
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);
|
||||
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:
|
||||
@ -97,7 +98,7 @@ private slots:
|
||||
signals:
|
||||
void orientationChanged();
|
||||
|
||||
public:
|
||||
private:
|
||||
// Existing sections.
|
||||
// SectionWidgets are always visible.
|
||||
QList<SectionWidget*> _sections;
|
||||
|
@ -1,6 +1,9 @@
|
||||
#ifndef ADS_INTERNAL_HEADER
|
||||
#define ADS_INTERNAL_HEADER
|
||||
|
||||
#include <QSharedPointer>
|
||||
#include <QWeakPointer>
|
||||
|
||||
#include "ads/API.h"
|
||||
#include "ads/SectionContent.h"
|
||||
|
||||
@ -13,6 +16,9 @@ class SectionContentWidget;
|
||||
class InternalContentData
|
||||
{
|
||||
public:
|
||||
typedef QSharedPointer<InternalContentData> RefPtr;
|
||||
typedef QWeakPointer<InternalContentData> WeakPtr;
|
||||
|
||||
InternalContentData();
|
||||
~InternalContentData();
|
||||
|
||||
|
@ -216,29 +216,38 @@ bool ContainerWidget::restoreState(const QByteArray& data)
|
||||
return success;
|
||||
}
|
||||
|
||||
QRect ContainerWidget::outerTopDropRect() const
|
||||
{
|
||||
QRect r = rect();
|
||||
int h = r.height() / 100 * 5;
|
||||
return QRect(r.left(), r.top(), r.width(), h);
|
||||
}
|
||||
|
||||
QRect ContainerWidget::outerRightDropRect() const
|
||||
{
|
||||
QRect r = rect();
|
||||
int w = r.width() / 100 * 5;
|
||||
return QRect(r.right() - w, r.top(), w, r.height());
|
||||
}
|
||||
|
||||
QRect ContainerWidget::outerBottomDropRect() const
|
||||
{
|
||||
QRect r = rect();
|
||||
int h = r.height() / 100 * 5;
|
||||
return QRect(r.left(), r.bottom() - h, r.width(), h);
|
||||
}
|
||||
|
||||
QRect ContainerWidget::outerLeftDropRect() const
|
||||
{
|
||||
QRect r = rect();
|
||||
int w = r.width() / 100 * 5;
|
||||
return QRect(r.left(), r.top(), w, r.height());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE API BEGINS HERE
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ContainerWidget::splitSections(SectionWidget* s1, SectionWidget* s2, Qt::Orientation orientation)
|
||||
{
|
||||
addSection(s1);
|
||||
|
||||
if (!s2)
|
||||
s2 = new SectionWidget(this);
|
||||
addSection(s2);
|
||||
|
||||
QSplitter* currentSplitter = findParentSplitter(s1);
|
||||
if (currentSplitter)
|
||||
{
|
||||
const int index = currentSplitter->indexOf(s1);
|
||||
QSplitter* splitter = newSplitter(orientation, this);
|
||||
splitter->addWidget(s1);
|
||||
splitter->addWidget(s2);
|
||||
currentSplitter->insertWidget(index, splitter);
|
||||
}
|
||||
}
|
||||
|
||||
SectionWidget* ContainerWidget::dropContent(const InternalContentData& data, SectionWidget* targetSection, DropArea area, bool autoActive)
|
||||
{
|
||||
SectionWidget* ret = NULL;
|
||||
@ -393,34 +402,6 @@ SectionWidget* ContainerWidget::sectionAt(const QPoint& pos) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
QRect ContainerWidget::outerTopDropRect() const
|
||||
{
|
||||
QRect r = rect();
|
||||
int h = r.height() / 100 * 5;
|
||||
return QRect(r.left(), r.top(), r.width(), h);
|
||||
}
|
||||
|
||||
QRect ContainerWidget::outerRightDropRect() const
|
||||
{
|
||||
QRect r = rect();
|
||||
int w = r.width() / 100 * 5;
|
||||
return QRect(r.right() - w, r.top(), w, r.height());
|
||||
}
|
||||
|
||||
QRect ContainerWidget::outerBottomDropRect() const
|
||||
{
|
||||
QRect r = rect();
|
||||
int h = r.height() / 100 * 5;
|
||||
return QRect(r.left(), r.bottom() - h, r.width(), h);
|
||||
}
|
||||
|
||||
QRect ContainerWidget::outerLeftDropRect() const
|
||||
{
|
||||
QRect r = rect();
|
||||
int w = r.width() / 100 * 5;
|
||||
return QRect(r.left(), r.top(), w, r.height());
|
||||
}
|
||||
|
||||
SectionWidget* ContainerWidget::dropContentOuterHelper(QLayout* l, const InternalContentData& data, Qt::Orientation orientation, bool append)
|
||||
{
|
||||
ContainerWidget* cw = this;
|
||||
|
Loading…
Reference in New Issue
Block a user