mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-26 08:01:32 +08:00
Created CFloatingTitleWidget
This commit is contained in:
parent
7f5e393cfb
commit
0716020ab4
@ -24,6 +24,7 @@ namespace ads
|
|||||||
class SectionWidget;
|
class SectionWidget;
|
||||||
class DropOverlay;
|
class DropOverlay;
|
||||||
class InternalContentData;
|
class InternalContentData;
|
||||||
|
class MainContainerWidget;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
@ -39,19 +40,54 @@ class CContainerWidget : public QFrame
|
|||||||
friend class ContainerWidgetPrivate;
|
friend class ContainerWidgetPrivate;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CContainerWidget(QWidget *parent = nullptr);
|
explicit CContainerWidget(MainContainerWidget* MainContainerWidget, QWidget *parent = nullptr);
|
||||||
virtual ~CContainerWidget();
|
virtual ~CContainerWidget();
|
||||||
|
|
||||||
|
void moveFloatingWidget(const QPoint& TargetPos);
|
||||||
|
/**
|
||||||
|
* Returns the current zOrderIndex
|
||||||
|
*/
|
||||||
|
unsigned int zOrderIndex() const;
|
||||||
|
|
||||||
|
void dropFloatingWidget(FloatingWidget* FloatingWidget,
|
||||||
|
const QPoint& TargetPos);
|
||||||
|
|
||||||
|
SectionWidget* sectionWidgetAt(const QPoint& pos) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function returns true if this container widgets z order index is
|
||||||
|
* higher than the index of the container widget given in Other parameter
|
||||||
|
*/
|
||||||
|
bool isInFrontOf(CContainerWidget* Other) const;
|
||||||
|
|
||||||
|
SectionWidget* dropContent(const InternalContentData& data, SectionWidget* targetSection, DropArea area, bool autoActive = true);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* 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);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual bool event(QEvent *e) override;
|
||||||
|
SectionWidget* newSectionWidget();
|
||||||
|
void addSectionWidget(SectionWidget* section);
|
||||||
|
SectionWidget* dropContentOuterHelper(QLayout* l, const InternalContentData& data, Qt::Orientation orientation, bool append);
|
||||||
|
SectionWidget* insertNewSectionWidget(const InternalContentData& data,
|
||||||
|
SectionWidget* targetSection, SectionWidget* ret, Qt::Orientation Orientation, int InsertIndexOffset);
|
||||||
|
|
||||||
|
QList<SectionWidget*> m_Sections;
|
||||||
// Layout stuff
|
// Layout stuff
|
||||||
QGridLayout* m_MainLayout = nullptr;
|
QGridLayout* m_MainLayout = nullptr;
|
||||||
Qt::Orientation m_Orientation = Qt::Horizontal;
|
Qt::Orientation m_Orientation = Qt::Horizontal;
|
||||||
QPointer<QSplitter> m_Splitter; // $mfreiholz: I'd like to remove this variable entirely,
|
QPointer<QSplitter> m_Splitter; // $mfreiholz: I'd like to remove this variable entirely,
|
||||||
// because it changes during user interaction anyway.
|
// because it changes during user interaction anyway.
|
||||||
|
|
||||||
// Drop overlay stuff.
|
MainContainerWidget* m_MainContainerWidget = 0;
|
||||||
QPointer<DropOverlay> m_SectionDropOverlay;
|
unsigned int m_zOrderIndex = 0;
|
||||||
QPointer<DropOverlay> m_ContainerDropOverlay;
|
static unsigned int zOrderCounter;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ads
|
} // namespace ads
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define FLOATINGWIDGET_H
|
#define FLOATINGWIDGET_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QFrame>
|
||||||
class QBoxLayout;
|
class QBoxLayout;
|
||||||
|
|
||||||
#include "ads/API.h"
|
#include "ads/API.h"
|
||||||
@ -13,6 +14,30 @@ class SectionTitleWidget;
|
|||||||
class SectionContentWidget;
|
class SectionContentWidget;
|
||||||
class InternalContentData;
|
class InternalContentData;
|
||||||
class SectionWidget;
|
class SectionWidget;
|
||||||
|
class CContainerWidget;
|
||||||
|
class FloatingWidget;
|
||||||
|
|
||||||
|
class CFloatingTitleWidget : public QFrame
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
QPoint m_DragStartPosition;
|
||||||
|
FloatingWidget* floatingWidget() const;
|
||||||
|
MainContainerWidget* mainContainerWidget() const;
|
||||||
|
void moveFloatingWidget(QMouseEvent* ev, MainContainerWidget* MainContainer);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void mousePressEvent(QMouseEvent* ev);
|
||||||
|
virtual void mouseReleaseEvent(QMouseEvent* ev);
|
||||||
|
virtual void mouseMoveEvent(QMouseEvent* ev);
|
||||||
|
|
||||||
|
public:
|
||||||
|
CFloatingTitleWidget(SectionContent::Flags Flags, FloatingWidget* Parent);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void closeButtonClicked();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// FloatingWidget holds and displays SectionContent as a floating window.
|
// FloatingWidget holds and displays SectionContent as a floating window.
|
||||||
// It can be resized, moved and dropped back into a SectionWidget.
|
// It can be resized, moved and dropped back into a SectionWidget.
|
||||||
@ -40,6 +65,9 @@ public:
|
|||||||
*/
|
*/
|
||||||
unsigned int zOrderIndex() const;
|
unsigned int zOrderIndex() const;
|
||||||
|
|
||||||
|
CContainerWidget* containerWidget() const {return m_ContainerWidget;}
|
||||||
|
MainContainerWidget* mainContainerWidget() const {return m_MainContainerWidget;}
|
||||||
|
|
||||||
public://private:
|
public://private:
|
||||||
bool takeContent(InternalContentData& data);
|
bool takeContent(InternalContentData& data);
|
||||||
|
|
||||||
@ -50,12 +78,13 @@ private slots:
|
|||||||
void onCloseButtonClicked();
|
void onCloseButtonClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MainContainerWidget* _container;
|
MainContainerWidget* m_MainContainerWidget;
|
||||||
SectionContent::RefPtr _content;
|
SectionContent::RefPtr _content;
|
||||||
SectionTitleWidget* _titleWidget;
|
SectionTitleWidget* _titleWidget;
|
||||||
SectionContentWidget* _contentWidget;
|
SectionContentWidget* _contentWidget;
|
||||||
|
CContainerWidget* m_ContainerWidget;
|
||||||
|
|
||||||
QBoxLayout* _titleLayout;
|
//QBoxLayout* _titleLayout;
|
||||||
unsigned int m_zOrderIndex = 0;
|
unsigned int m_zOrderIndex = 0;
|
||||||
static unsigned int zOrderCounter;
|
static unsigned int zOrderCounter;
|
||||||
};
|
};
|
||||||
|
@ -39,6 +39,7 @@ class ADS_EXPORT_API MainContainerWidget : public CContainerWidget
|
|||||||
friend class FloatingWidget;
|
friend class FloatingWidget;
|
||||||
friend class SectionTitleWidget;
|
friend class SectionTitleWidget;
|
||||||
friend class ContainerWidgetPrivate;
|
friend class ContainerWidgetPrivate;
|
||||||
|
friend class CFloatingTitleWidget;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainContainerWidget(QWidget *parent = nullptr);
|
explicit MainContainerWidget(QWidget *parent = nullptr);
|
||||||
@ -119,6 +120,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
QPointer<DropOverlay> sectionDropOverlay() const;
|
QPointer<DropOverlay> sectionDropOverlay() const;
|
||||||
|
|
||||||
|
QPointer<DropOverlay> dropOverlay() const;
|
||||||
|
|
||||||
|
static QSplitter* newSplitter(Qt::Orientation orientation = Qt::Horizontal, QWidget* parent = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters the events of the floating widgets
|
* Filters the events of the floating widgets
|
||||||
*/
|
*/
|
||||||
@ -128,12 +133,8 @@ private:
|
|||||||
//
|
//
|
||||||
// Internal Stuff Begins Here
|
// Internal Stuff Begins Here
|
||||||
//
|
//
|
||||||
|
|
||||||
SectionWidget* newSectionWidget();
|
|
||||||
SectionWidget* dropContent(const InternalContentData& data, SectionWidget* targetSection, DropArea area, bool autoActive = true);
|
SectionWidget* dropContent(const InternalContentData& data, SectionWidget* targetSection, DropArea area, bool autoActive = true);
|
||||||
void addSectionWidget(SectionWidget* section);
|
|
||||||
SectionWidget* sectionWidgetAt(const QPoint& pos) const;
|
SectionWidget* sectionWidgetAt(const QPoint& pos) const;
|
||||||
SectionWidget* dropContentOuterHelper(QLayout* l, const InternalContentData& data, Qt::Orientation orientation, bool append);
|
|
||||||
|
|
||||||
// Serialization
|
// Serialization
|
||||||
QByteArray saveHierarchy() const;
|
QByteArray saveHierarchy() const;
|
||||||
@ -149,8 +150,6 @@ private:
|
|||||||
bool takeContent(const SectionContent::RefPtr& sc, InternalContentData& data);
|
bool takeContent(const SectionContent::RefPtr& sc, InternalContentData& data);
|
||||||
FloatingWidget* startFloating(SectionWidget* sectionwidget, int ContentUid, const QPoint& TargetPos);
|
FloatingWidget* startFloating(SectionWidget* sectionwidget, int ContentUid, const QPoint& TargetPos);
|
||||||
void hideContainerOverlay();
|
void hideContainerOverlay();
|
||||||
SectionWidget* insertNewSectionWidget(const InternalContentData& data,
|
|
||||||
SectionWidget* targetSection, SectionWidget* ret, Qt::Orientation Orientation, int InsertIndexOffset);
|
|
||||||
void moveFloatingWidget(const QPoint& TargetPos);
|
void moveFloatingWidget(const QPoint& TargetPos);
|
||||||
void dropFloatingWidget(FloatingWidget* FloatingWidget, const QPoint& TargetPos);
|
void dropFloatingWidget(FloatingWidget* FloatingWidget, const QPoint& TargetPos);
|
||||||
|
|
||||||
@ -178,13 +177,16 @@ signals:
|
|||||||
private:
|
private:
|
||||||
QList<SectionWidget*> m_Sections;
|
QList<SectionWidget*> m_Sections;
|
||||||
QList<FloatingWidget*> m_Floatings;
|
QList<FloatingWidget*> m_Floatings;
|
||||||
|
QList<CContainerWidget*> m_Containers;
|
||||||
QHash<int, HiddenSectionItem> m_HiddenSectionContents;
|
QHash<int, HiddenSectionItem> m_HiddenSectionContents;
|
||||||
|
|
||||||
|
|
||||||
// Helper lookup maps, restricted to this container.
|
// Helper lookup maps, restricted to this container.
|
||||||
QHash<int, SectionContent::WeakPtr> m_SectionContentIdMap;
|
QHash<int, SectionContent::WeakPtr> m_SectionContentIdMap;
|
||||||
QHash<QString, SectionContent::WeakPtr> m_SectionContentNameMap;
|
QHash<QString, SectionContent::WeakPtr> m_SectionContentNameMap;
|
||||||
QHash<int, SectionWidget*> m_SectionWidgetIdMap;
|
QHash<int, SectionWidget*> m_SectionWidgetIdMap;
|
||||||
|
|
||||||
|
QPointer<DropOverlay> m_ContainerDropOverlay;
|
||||||
|
QPointer<DropOverlay> m_SectionDropOverlay;
|
||||||
};
|
};
|
||||||
|
|
||||||
ADS_NAMESPACE_END
|
ADS_NAMESPACE_END
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
#include "ads/API.h"
|
#include "ads/API.h"
|
||||||
#include "ads/SectionContent.h"
|
#include "ads/SectionContent.h"
|
||||||
|
|
||||||
|
class QPushButton;
|
||||||
|
|
||||||
ADS_NAMESPACE_BEGIN
|
ADS_NAMESPACE_BEGIN
|
||||||
class MainContainerWidget;
|
class MainContainerWidget;
|
||||||
class SectionWidget;
|
class SectionWidget;
|
||||||
|
@ -28,14 +28,15 @@ class ADS_EXPORT_API SectionWidget : public QFrame
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
friend class MainContainerWidget;
|
friend class MainContainerWidget;
|
||||||
|
friend class CContainerWidget;
|
||||||
|
|
||||||
explicit SectionWidget(MainContainerWidget* parent);
|
explicit SectionWidget(MainContainerWidget* MainContainer, CContainerWidget* parent);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~SectionWidget();
|
virtual ~SectionWidget();
|
||||||
|
|
||||||
int uid() const;
|
int uid() const;
|
||||||
MainContainerWidget* containerWidget() const;
|
CContainerWidget* containerWidget() const;
|
||||||
|
|
||||||
QRect titleAreaGeometry() const;
|
QRect titleAreaGeometry() const;
|
||||||
QRect contentAreaGeometry() const;
|
QRect contentAreaGeometry() const;
|
||||||
@ -69,7 +70,8 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
const int _uid;
|
const int _uid;
|
||||||
|
|
||||||
QPointer<MainContainerWidget> _container;
|
QPointer<CContainerWidget> m_ContainerWidget;
|
||||||
|
QPointer<MainContainerWidget> m_MainContainerWidget;
|
||||||
QList<SectionContent::RefPtr> _contents;
|
QList<SectionContent::RefPtr> _contents;
|
||||||
QList<SectionTitleWidget*> _sectionTitles;
|
QList<SectionTitleWidget*> _sectionTitles;
|
||||||
QList<SectionContentWidget*> _sectionContents;
|
QList<SectionContentWidget*> _sectionContents;
|
||||||
|
@ -22,24 +22,25 @@
|
|||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "ads/Internal.h"
|
#include "ads/Internal.h"
|
||||||
#include "ads/SectionWidget.h"
|
#include "ads/SectionWidget.h"
|
||||||
#include "ads/SectionTitleWidget.h"
|
#include "ads/SectionTitleWidget.h"
|
||||||
#include "ads/SectionContentWidget.h"
|
#include "ads/SectionContentWidget.h"
|
||||||
#include "ads/DropOverlay.h"
|
#include "ads/DropOverlay.h"
|
||||||
#include "ads/Serialization.h"
|
#include "ads/Serialization.h"
|
||||||
|
#include "ads/MainContainerWidget.h"
|
||||||
|
|
||||||
namespace ads
|
namespace ads
|
||||||
{
|
{
|
||||||
//============================================================================
|
unsigned int CContainerWidget::zOrderCounter = 0;
|
||||||
CContainerWidget::CContainerWidget(QWidget *parent)
|
|
||||||
: QFrame(parent)
|
|
||||||
{
|
|
||||||
m_SectionDropOverlay = new DropOverlay(this, DropOverlay::ModeSectionOverlay);
|
|
||||||
m_ContainerDropOverlay = new DropOverlay(this, DropOverlay::ModeContainerOverlay);
|
|
||||||
m_ContainerDropOverlay->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
||||||
m_ContainerDropOverlay->setWindowFlags(m_ContainerDropOverlay->windowFlags() | Qt::WindowTransparentForInput);
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
CContainerWidget::CContainerWidget(MainContainerWidget* MainContainer, QWidget *parent)
|
||||||
|
: QFrame(parent),
|
||||||
|
m_MainContainerWidget(MainContainer)
|
||||||
|
{
|
||||||
m_MainLayout = new QGridLayout();
|
m_MainLayout = new QGridLayout();
|
||||||
m_MainLayout->setContentsMargins(0, 1, 0, 0);
|
m_MainLayout->setContentsMargins(0, 1, 0, 0);
|
||||||
m_MainLayout->setSpacing(0);
|
m_MainLayout->setSpacing(0);
|
||||||
@ -50,7 +51,250 @@ CContainerWidget::CContainerWidget(QWidget *parent)
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
CContainerWidget::~CContainerWidget()
|
CContainerWidget::~CContainerWidget()
|
||||||
{
|
{
|
||||||
|
std::cout << "CContainerWidget::~CContainerWidget()" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool CContainerWidget::event(QEvent *e)
|
||||||
|
{
|
||||||
|
bool Result = QWidget::event(e);
|
||||||
|
if (e->type() == QEvent::WindowActivate)
|
||||||
|
{
|
||||||
|
m_zOrderIndex = ++zOrderCounter;
|
||||||
|
}
|
||||||
|
else if (e->type() == QEvent::Show && !m_zOrderIndex)
|
||||||
|
{
|
||||||
|
m_zOrderIndex = ++zOrderCounter;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int CContainerWidget::zOrderIndex() const
|
||||||
|
{
|
||||||
|
return m_zOrderIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget,
|
||||||
|
const QPoint& TargetPos)
|
||||||
|
{
|
||||||
|
if (!FloatingWidget->isDraggingActive())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPoint MousePos = mapFromGlobal(TargetPos);
|
||||||
|
SectionWidget* sectionWidget = sectionWidgetAt(MousePos);
|
||||||
|
DropArea dropArea = InvalidDropArea;
|
||||||
|
if (sectionWidget)
|
||||||
|
{
|
||||||
|
//m_SectionDropOverlay->setAllowedAreas(ADS_NS::AllAreas);
|
||||||
|
//dropArea = m_SectionDropOverlay->showDropOverlay(sectionWidget);
|
||||||
|
if (dropArea != InvalidDropArea)
|
||||||
|
{
|
||||||
|
InternalContentData data;
|
||||||
|
FloatingWidget->takeContent(data);
|
||||||
|
FloatingWidget->deleteLater();
|
||||||
|
//dropContent(data, sectionWidget, dropArea, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mouse is over container
|
||||||
|
if (InvalidDropArea == dropArea)
|
||||||
|
{
|
||||||
|
//dropArea = m_ContainerDropOverlay->dropAreaUnderCursor();
|
||||||
|
std::cout << "Cursor location: " << dropArea << std::endl;
|
||||||
|
if (dropArea != InvalidDropArea)
|
||||||
|
{
|
||||||
|
InternalContentData data;
|
||||||
|
FloatingWidget->takeContent(data);
|
||||||
|
FloatingWidget->deleteLater();
|
||||||
|
//dropContent(data, nullptr, dropArea, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SectionWidget* CContainerWidget::sectionWidgetAt(const QPoint& pos) const
|
||||||
|
{
|
||||||
|
const QPoint gpos = mapToGlobal(pos);
|
||||||
|
for (int i = 0; i < m_Sections.size(); ++i)
|
||||||
|
{
|
||||||
|
SectionWidget* sw = m_Sections[i];
|
||||||
|
if (sw->rect().contains(sw->mapFromGlobal(gpos)))
|
||||||
|
{
|
||||||
|
return sw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool CContainerWidget::isInFrontOf(CContainerWidget* Other) const
|
||||||
|
{
|
||||||
|
return this->m_zOrderIndex > Other->m_zOrderIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
SectionWidget* CContainerWidget::dropContent(const InternalContentData& data, SectionWidget* targetSectionWidget, DropArea area, bool autoActive)
|
||||||
|
{
|
||||||
|
ADS_Expects(targetSection != NULL);
|
||||||
|
|
||||||
|
SectionWidget* section_widget = nullptr;
|
||||||
|
|
||||||
|
// If no sections exists yet, create a default one and always drop into it.
|
||||||
|
if (m_Sections.isEmpty())
|
||||||
|
{
|
||||||
|
targetSectionWidget = newSectionWidget();
|
||||||
|
addSectionWidget(targetSectionWidget);
|
||||||
|
area = CenterDropArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drop on outer area
|
||||||
|
if (!targetSectionWidget)
|
||||||
|
{
|
||||||
|
switch (area)
|
||||||
|
{
|
||||||
|
case TopDropArea:return dropContentOuterHelper(m_MainLayout, data, Qt::Vertical, false);
|
||||||
|
case RightDropArea: return dropContentOuterHelper(m_MainLayout, data, Qt::Horizontal, true);
|
||||||
|
case CenterDropArea:
|
||||||
|
case BottomDropArea:return dropContentOuterHelper(m_MainLayout, data, Qt::Vertical, true);
|
||||||
|
case LeftDropArea: return dropContentOuterHelper(m_MainLayout, data, Qt::Horizontal, false);
|
||||||
|
default:
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return section_widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drop logic based on area.
|
||||||
|
switch (area)
|
||||||
|
{
|
||||||
|
case TopDropArea:return insertNewSectionWidget(data, targetSectionWidget, section_widget, Qt::Vertical, 0);
|
||||||
|
case RightDropArea: return insertNewSectionWidget(data, targetSectionWidget, section_widget, Qt::Horizontal, 1);
|
||||||
|
case BottomDropArea: return insertNewSectionWidget(data, targetSectionWidget, section_widget, Qt::Vertical, 1);
|
||||||
|
case LeftDropArea: return insertNewSectionWidget(data, targetSectionWidget, section_widget, Qt::Horizontal, 0);
|
||||||
|
case CenterDropArea:
|
||||||
|
targetSectionWidget->addContent(data, autoActive);
|
||||||
|
return targetSectionWidget;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return section_widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SectionWidget* CContainerWidget::newSectionWidget()
|
||||||
|
{
|
||||||
|
SectionWidget* sw = new SectionWidget(m_MainContainerWidget, this);
|
||||||
|
m_Sections.append(sw);
|
||||||
|
return sw;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CContainerWidget::addSectionWidget(SectionWidget* section)
|
||||||
|
{
|
||||||
|
ADS_Expects(section != NULL);
|
||||||
|
|
||||||
|
// Create default splitter.
|
||||||
|
if (!m_Splitter)
|
||||||
|
{
|
||||||
|
m_Splitter = MainContainerWidget::newSplitter(m_Orientation);
|
||||||
|
m_MainLayout->addWidget(m_Splitter, 0, 0);
|
||||||
|
}
|
||||||
|
if (m_Splitter->indexOf(section) != -1)
|
||||||
|
{
|
||||||
|
qWarning() << Q_FUNC_INFO << QString("Section has already been added");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_Splitter->addWidget(section);
|
||||||
|
}
|
||||||
|
|
||||||
|
SectionWidget* CContainerWidget::dropContentOuterHelper(QLayout* l, const InternalContentData& data, Qt::Orientation orientation, bool append)
|
||||||
|
{
|
||||||
|
ADS_Expects(l != NULL);
|
||||||
|
|
||||||
|
SectionWidget* sw = newSectionWidget();
|
||||||
|
sw->addContent(data, true);
|
||||||
|
|
||||||
|
QSplitter* oldsp = findImmediateSplitter(this);
|
||||||
|
if (!oldsp)
|
||||||
|
{
|
||||||
|
QSplitter* sp = MainContainerWidget::newSplitter(orientation);
|
||||||
|
if (l->count() > 0)
|
||||||
|
{
|
||||||
|
qWarning() << "Still items in layout. This should never happen.";
|
||||||
|
QLayoutItem* li = l->takeAt(0);
|
||||||
|
delete li;
|
||||||
|
}
|
||||||
|
l->addWidget(sp);
|
||||||
|
sp->addWidget(sw);
|
||||||
|
}
|
||||||
|
else if (oldsp->orientation() == orientation
|
||||||
|
|| oldsp->count() == 1)
|
||||||
|
{
|
||||||
|
oldsp->setOrientation(orientation);
|
||||||
|
if (append)
|
||||||
|
oldsp->addWidget(sw);
|
||||||
|
else
|
||||||
|
oldsp->insertWidget(0, sw);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QSplitter* sp = MainContainerWidget::newSplitter(orientation);
|
||||||
|
if (append)
|
||||||
|
{
|
||||||
|
QLayoutItem* li = l->replaceWidget(oldsp, sp);
|
||||||
|
sp->addWidget(oldsp);
|
||||||
|
sp->addWidget(sw);
|
||||||
|
delete li;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sp->addWidget(sw);
|
||||||
|
QLayoutItem* li = l->replaceWidget(oldsp, sp);
|
||||||
|
sp->addWidget(oldsp);
|
||||||
|
delete li;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sw;
|
||||||
|
}
|
||||||
|
|
||||||
|
SectionWidget* CContainerWidget::insertNewSectionWidget(
|
||||||
|
const InternalContentData& data, SectionWidget* targetSection, SectionWidget* ret,
|
||||||
|
Qt::Orientation Orientation, int InsertIndexOffset)
|
||||||
|
{
|
||||||
|
QSplitter* targetSectionSplitter = findParentSplitter(targetSection);
|
||||||
|
SectionWidget* sw = newSectionWidget();
|
||||||
|
sw->addContent(data, true);
|
||||||
|
if (targetSectionSplitter->orientation() == Orientation)
|
||||||
|
{
|
||||||
|
const int index = targetSectionSplitter->indexOf(targetSection);
|
||||||
|
targetSectionSplitter->insertWidget(index + InsertIndexOffset, sw);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const int index = targetSectionSplitter->indexOf(targetSection);
|
||||||
|
QSplitter* s = MainContainerWidget::newSplitter(Orientation);
|
||||||
|
s->addWidget(sw);
|
||||||
|
s->addWidget(targetSection);
|
||||||
|
targetSectionSplitter->insertWidget(index, s);
|
||||||
|
}
|
||||||
|
ret = sw;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
SectionWidget* CContainerWidget::addSectionContent(const SectionContent::RefPtr& sc, SectionWidget* sw, DropArea area)
|
||||||
|
{
|
||||||
|
ADS_Expects(!sc.isNull());
|
||||||
|
|
||||||
|
// Drop it based on "area"
|
||||||
|
InternalContentData data;
|
||||||
|
data.content = sc;
|
||||||
|
data.titleWidget = new SectionTitleWidget(sc, NULL);
|
||||||
|
data.contentWidget = new SectionContentWidget(sc, NULL);
|
||||||
|
|
||||||
|
//connect(data.titleWidget, SIGNAL(activeTabChanged()), this, SLOT(onActiveTabChanged()));
|
||||||
|
return dropContent(data, sw, area, false);
|
||||||
}
|
}
|
||||||
} // namespace ads
|
} // namespace ads
|
||||||
|
|
||||||
|
@ -252,8 +252,9 @@ void DropOverlay::paintEvent(QPaintEvent*)
|
|||||||
void DropOverlay::showEvent(QShowEvent*)
|
void DropOverlay::showEvent(QShowEvent*)
|
||||||
{
|
{
|
||||||
_cross->show();
|
_cross->show();
|
||||||
QRect ContainerWidgetRect = parentWidget()->rect();
|
QWidget* w = parentWidget() ? parentWidget() : _target.data();
|
||||||
QPoint Pos(ContainerWidgetRect.left(), ContainerWidgetRect.center().y());
|
QRect WidgetRect = w->rect();
|
||||||
|
QPoint Pos(WidgetRect.left(), WidgetRect.center().y());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DropOverlay::hideEvent(QHideEvent*)
|
void DropOverlay::hideEvent(QHideEvent*)
|
||||||
|
@ -6,19 +6,145 @@
|
|||||||
#include <QSizePolicy>
|
#include <QSizePolicy>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
#include "ads/SectionTitleWidget.h"
|
#include "ads/SectionTitleWidget.h"
|
||||||
#include "ads/SectionContentWidget.h"
|
#include "ads/SectionContentWidget.h"
|
||||||
#include "ads/Internal.h"
|
#include "ads/Internal.h"
|
||||||
#include "ads/SectionWidget.h"
|
#include "ads/SectionWidget.h"
|
||||||
|
#include "ads/ContainerWidget.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
ADS_NAMESPACE_BEGIN
|
ADS_NAMESPACE_BEGIN
|
||||||
|
|
||||||
unsigned int FloatingWidget::zOrderCounter = 0;
|
unsigned int FloatingWidget::zOrderCounter = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CFloatingTitleWidget::CFloatingTitleWidget(SectionContent::Flags Flags, FloatingWidget* Parent)
|
||||||
|
: QFrame(Parent)
|
||||||
|
{
|
||||||
|
auto Layout = new QHBoxLayout();
|
||||||
|
QLabel* Label = new QLabel(this);
|
||||||
|
Label->setText("Floating Widget");
|
||||||
|
Label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||||
|
Label->setAlignment(Qt::AlignLeft);
|
||||||
|
Layout->addWidget(Label, 1, Qt::AlignLeft | Qt::AlignVCenter);
|
||||||
|
setLayout(Layout);
|
||||||
|
|
||||||
|
if (Flags.testFlag(SectionContent::Closeable))
|
||||||
|
{
|
||||||
|
QPushButton* closeButton = new QPushButton();
|
||||||
|
closeButton->setObjectName("closeButton");
|
||||||
|
closeButton->setFlat(true);
|
||||||
|
closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
|
||||||
|
closeButton->setToolTip(tr("Close"));
|
||||||
|
closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
Layout->addWidget(closeButton);
|
||||||
|
connect(closeButton, SIGNAL(clicked(bool)), this, SIGNAL(closeButtonClicked()));
|
||||||
|
Layout->setContentsMargins(6, 0, 0, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Layout->setContentsMargins(6, 6, 6, 6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FloatingWidget* CFloatingTitleWidget::floatingWidget() const
|
||||||
|
{
|
||||||
|
return dynamic_cast<FloatingWidget*>(parentWidget());
|
||||||
|
}
|
||||||
|
|
||||||
|
MainContainerWidget* CFloatingTitleWidget::mainContainerWidget() const
|
||||||
|
{
|
||||||
|
return floatingWidget()->mainContainerWidget();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CFloatingTitleWidget::mousePressEvent(QMouseEvent* ev)
|
||||||
|
{
|
||||||
|
if (ev->button() == Qt::LeftButton)
|
||||||
|
{
|
||||||
|
ev->accept();
|
||||||
|
//m_DragStartPosition = ev->pos();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QFrame::mousePressEvent(ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CFloatingTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CFloatingTitleWidget::mouseMoveEvent(QMouseEvent* ev)
|
||||||
|
{
|
||||||
|
if (!(ev->buttons() & Qt::LeftButton))
|
||||||
|
{
|
||||||
|
QFrame::mouseMoveEvent(ev);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPoint Pos = QCursor::pos();
|
||||||
|
// TODO make a member with the main container widget and assign it on
|
||||||
|
// creation
|
||||||
|
MainContainerWidget* MainContainerWidget = mainContainerWidget();
|
||||||
|
auto Containers = MainContainerWidget->m_Containers;
|
||||||
|
CContainerWidget* TopContainer = nullptr;
|
||||||
|
for (auto ContainerWidget : Containers)
|
||||||
|
{
|
||||||
|
if (!ContainerWidget->isVisible())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (floatingWidget()->containerWidget() == ContainerWidget)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPoint MappedPos = ContainerWidget->mapFromGlobal(Pos);
|
||||||
|
if (ContainerWidget->rect().contains(MappedPos))
|
||||||
|
{
|
||||||
|
std::cout << "Container " << ContainerWidget << " contains maousepos" << std::endl;
|
||||||
|
if (!TopContainer || ContainerWidget->isInFrontOf(TopContainer))
|
||||||
|
{
|
||||||
|
TopContainer = ContainerWidget;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TopContainer)
|
||||||
|
{
|
||||||
|
MainContainerWidget->dropOverlay()->showDropOverlay(TopContainer);
|
||||||
|
MainContainerWidget->dropOverlay()->raise();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MainContainerWidget->dropOverlay()->hideDropOverlay();
|
||||||
|
}
|
||||||
|
|
||||||
|
ev->accept();
|
||||||
|
moveFloatingWidget(ev, MainContainerWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CFloatingTitleWidget::moveFloatingWidget(QMouseEvent* ev, MainContainerWidget* cw)
|
||||||
|
{
|
||||||
|
const QPoint moveToPos = ev->globalPos() - (m_DragStartPosition + QPoint(ADS_WINDOW_FRAME_BORDER_WIDTH, ADS_WINDOW_FRAME_BORDER_WIDTH));
|
||||||
|
floatingWidget()->move(moveToPos);
|
||||||
|
// cw->moveFloatingWidget(moveToPos);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FloatingWidget::FloatingWidget(MainContainerWidget* container, SectionContent::RefPtr sc, SectionTitleWidget* titleWidget, SectionContentWidget* contentWidget, QWidget* parent) :
|
FloatingWidget::FloatingWidget(MainContainerWidget* container, SectionContent::RefPtr sc, SectionTitleWidget* titleWidget, SectionContentWidget* contentWidget, QWidget* parent) :
|
||||||
QWidget(parent, Qt::CustomizeWindowHint | Qt::Tool),
|
QWidget(parent, Qt::CustomizeWindowHint | Qt::Tool),
|
||||||
_container(container),
|
m_MainContainerWidget(container),
|
||||||
_content(sc),
|
_content(sc),
|
||||||
_titleWidget(titleWidget),
|
_titleWidget(titleWidget),
|
||||||
_contentWidget(contentWidget)
|
_contentWidget(contentWidget)
|
||||||
@ -29,24 +155,21 @@ FloatingWidget::FloatingWidget(MainContainerWidget* container, SectionContent::R
|
|||||||
setLayout(l);
|
setLayout(l);
|
||||||
|
|
||||||
// Title + Controls
|
// Title + Controls
|
||||||
_titleLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
CFloatingTitleWidget* TitleBar = new CFloatingTitleWidget(sc->flags(), this);
|
||||||
_titleLayout->addWidget(titleWidget, 1);
|
l->insertWidget(0, TitleBar);
|
||||||
l->addLayout(_titleLayout, 0);
|
connect(TitleBar, SIGNAL(closeButtonClicked()), this, SLOT(onCloseButtonClicked()));
|
||||||
titleWidget->setActiveTab(false);
|
|
||||||
|
|
||||||
if (sc->flags().testFlag(SectionContent::Closeable))
|
//l->addWidget(contentWidget, 1);
|
||||||
{
|
//contentWidget->show();
|
||||||
QPushButton* closeButton = new QPushButton();
|
|
||||||
closeButton->setObjectName("closeButton");
|
m_ContainerWidget = new CContainerWidget(m_MainContainerWidget, this);
|
||||||
closeButton->setFlat(true);
|
l->addWidget(m_ContainerWidget, 1);
|
||||||
closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
|
InternalContentData data;
|
||||||
closeButton->setToolTip(tr("Close"));
|
data.content = sc;
|
||||||
closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
data.contentWidget = contentWidget;
|
||||||
_titleLayout->addWidget(closeButton);
|
data.titleWidget = titleWidget;
|
||||||
connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked()));
|
m_ContainerWidget->dropContent(data, nullptr, CenterDropArea);
|
||||||
}
|
m_ContainerWidget->show();
|
||||||
l->addWidget(contentWidget, 1);
|
|
||||||
contentWidget->show();
|
|
||||||
|
|
||||||
m_zOrderIndex = ++zOrderCounter;
|
m_zOrderIndex = ++zOrderCounter;
|
||||||
}
|
}
|
||||||
@ -67,7 +190,7 @@ FloatingWidget::FloatingWidget(SectionWidget* sectionWidget)
|
|||||||
FloatingWidget::~FloatingWidget()
|
FloatingWidget::~FloatingWidget()
|
||||||
{
|
{
|
||||||
// maybe we can implement this this via connection to destroyed signal
|
// maybe we can implement this this via connection to destroyed signal
|
||||||
_container->m_Floatings.removeAll(this); // Note: I don't like this here, but we have to remove it from list...
|
m_MainContainerWidget->m_Floatings.removeAll(this); // Note: I don't like this here, but we have to remove it from list...
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FloatingWidget::takeContent(InternalContentData& data)
|
bool FloatingWidget::takeContent(InternalContentData& data)
|
||||||
@ -76,12 +199,12 @@ bool FloatingWidget::takeContent(InternalContentData& data)
|
|||||||
data.titleWidget = _titleWidget;
|
data.titleWidget = _titleWidget;
|
||||||
data.contentWidget = _contentWidget;
|
data.contentWidget = _contentWidget;
|
||||||
|
|
||||||
_titleLayout->removeWidget(_titleWidget);
|
//_titleLayout->removeWidget(_titleWidget);
|
||||||
_titleWidget->setParent(_container);
|
_titleWidget->setParent(m_MainContainerWidget);
|
||||||
_titleWidget = NULL;
|
_titleWidget = NULL;
|
||||||
|
|
||||||
layout()->removeWidget(_contentWidget);
|
layout()->removeWidget(_contentWidget);
|
||||||
_contentWidget->setParent(_container);
|
_contentWidget->setParent(m_MainContainerWidget);
|
||||||
_contentWidget = NULL;
|
_contentWidget = NULL;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -89,7 +212,7 @@ bool FloatingWidget::takeContent(InternalContentData& data)
|
|||||||
|
|
||||||
void FloatingWidget::onCloseButtonClicked()
|
void FloatingWidget::onCloseButtonClicked()
|
||||||
{
|
{
|
||||||
_container->hideSectionContent(_content);
|
m_MainContainerWidget->hideSectionContent(_content);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FloatingWidget::isDraggingActive() const
|
bool FloatingWidget::isDraggingActive() const
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
ADS_NAMESPACE_BEGIN
|
ADS_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
|
||||||
static QSplitter* newSplitter(Qt::Orientation orientation = Qt::Horizontal, QWidget* parent = 0)
|
QSplitter* MainContainerWidget::newSplitter(Qt::Orientation orientation, QWidget* parent)
|
||||||
{
|
{
|
||||||
QSplitter* s = new QSplitter(orientation, parent);
|
QSplitter* s = new QSplitter(orientation, parent);
|
||||||
s->setProperty("ads-splitter", QVariant(true));
|
s->setProperty("ads-splitter", QVariant(true));
|
||||||
@ -35,9 +35,14 @@ static QSplitter* newSplitter(Qt::Orientation orientation = Qt::Horizontal, QWid
|
|||||||
|
|
||||||
|
|
||||||
MainContainerWidget::MainContainerWidget(QWidget *parent) :
|
MainContainerWidget::MainContainerWidget(QWidget *parent) :
|
||||||
CContainerWidget(parent)
|
CContainerWidget(this, parent)
|
||||||
{
|
{
|
||||||
|
m_SectionDropOverlay = new DropOverlay(this, DropOverlay::ModeSectionOverlay);
|
||||||
|
|
||||||
|
m_ContainerDropOverlay = new DropOverlay(this, DropOverlay::ModeContainerOverlay);
|
||||||
|
m_ContainerDropOverlay->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
|
m_ContainerDropOverlay->setWindowFlags(m_ContainerDropOverlay->windowFlags() | Qt::WindowTransparentForInput);
|
||||||
|
m_Containers.append(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainContainerWidget::~MainContainerWidget()
|
MainContainerWidget::~MainContainerWidget()
|
||||||
@ -420,41 +425,16 @@ QPointer<DropOverlay> MainContainerWidget::sectionDropOverlay() const
|
|||||||
return m_SectionDropOverlay;
|
return m_SectionDropOverlay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QPointer<DropOverlay> MainContainerWidget::dropOverlay() const
|
||||||
|
{
|
||||||
|
return m_ContainerDropOverlay;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
// PRIVATE API BEGINS HERE
|
// PRIVATE API BEGINS HERE
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
SectionWidget* MainContainerWidget::newSectionWidget()
|
|
||||||
{
|
|
||||||
SectionWidget* sw = new SectionWidget(this);
|
|
||||||
m_Sections.append(sw);
|
|
||||||
return sw;
|
|
||||||
}
|
|
||||||
|
|
||||||
SectionWidget* MainContainerWidget::insertNewSectionWidget(
|
|
||||||
const InternalContentData& data, SectionWidget* targetSection, SectionWidget* ret,
|
|
||||||
Qt::Orientation Orientation, int InsertIndexOffset)
|
|
||||||
{
|
|
||||||
QSplitter* targetSectionSplitter = findParentSplitter(targetSection);
|
|
||||||
SectionWidget* sw = newSectionWidget();
|
|
||||||
sw->addContent(data, true);
|
|
||||||
if (targetSectionSplitter->orientation() == Orientation)
|
|
||||||
{
|
|
||||||
const int index = targetSectionSplitter->indexOf(targetSection);
|
|
||||||
targetSectionSplitter->insertWidget(index + InsertIndexOffset, sw);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const int index = targetSectionSplitter->indexOf(targetSection);
|
|
||||||
QSplitter* s = newSplitter(Orientation);
|
|
||||||
s->addWidget(sw);
|
|
||||||
s->addWidget(targetSection);
|
|
||||||
targetSectionSplitter->insertWidget(index, s);
|
|
||||||
}
|
|
||||||
ret = sw;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
SectionWidget* MainContainerWidget::dropContent(const InternalContentData& data, SectionWidget* targetSectionWidget, DropArea area, bool autoActive)
|
SectionWidget* MainContainerWidget::dropContent(const InternalContentData& data, SectionWidget* targetSectionWidget, DropArea area, bool autoActive)
|
||||||
{
|
{
|
||||||
ADS_Expects(targetSection != NULL);
|
ADS_Expects(targetSection != NULL);
|
||||||
@ -502,23 +482,6 @@ SectionWidget* MainContainerWidget::dropContent(const InternalContentData& data,
|
|||||||
return section_widget;
|
return section_widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainContainerWidget::addSectionWidget(SectionWidget* section)
|
|
||||||
{
|
|
||||||
ADS_Expects(section != NULL);
|
|
||||||
|
|
||||||
// Create default splitter.
|
|
||||||
if (!m_Splitter)
|
|
||||||
{
|
|
||||||
m_Splitter = newSplitter(m_Orientation);
|
|
||||||
m_MainLayout->addWidget(m_Splitter, 0, 0);
|
|
||||||
}
|
|
||||||
if (m_Splitter->indexOf(section) != -1)
|
|
||||||
{
|
|
||||||
qWarning() << Q_FUNC_INFO << QString("Section has already been added");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_Splitter->addWidget(section);
|
|
||||||
}
|
|
||||||
|
|
||||||
SectionWidget* MainContainerWidget::sectionWidgetAt(const QPoint& pos) const
|
SectionWidget* MainContainerWidget::sectionWidgetAt(const QPoint& pos) const
|
||||||
{
|
{
|
||||||
@ -534,73 +497,7 @@ SectionWidget* MainContainerWidget::sectionWidgetAt(const QPoint& pos) const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionWidget* MainContainerWidget::dropContentOuterHelper(QLayout* l, const InternalContentData& data, Qt::Orientation orientation, bool append)
|
|
||||||
{
|
|
||||||
ADS_Expects(l != NULL);
|
|
||||||
|
|
||||||
SectionWidget* sw = newSectionWidget();
|
|
||||||
sw->addContent(data, true);
|
|
||||||
|
|
||||||
QSplitter* oldsp = findImmediateSplitter(this);
|
|
||||||
if (!oldsp)
|
|
||||||
{
|
|
||||||
QSplitter* sp = newSplitter(orientation);
|
|
||||||
if (l->count() > 0)
|
|
||||||
{
|
|
||||||
qWarning() << "Still items in layout. This should never happen.";
|
|
||||||
QLayoutItem* li = l->takeAt(0);
|
|
||||||
delete li;
|
|
||||||
}
|
|
||||||
l->addWidget(sp);
|
|
||||||
sp->addWidget(sw);
|
|
||||||
}
|
|
||||||
else if (oldsp->orientation() == orientation
|
|
||||||
|| oldsp->count() == 1)
|
|
||||||
{
|
|
||||||
oldsp->setOrientation(orientation);
|
|
||||||
if (append)
|
|
||||||
oldsp->addWidget(sw);
|
|
||||||
else
|
|
||||||
oldsp->insertWidget(0, sw);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QSplitter* sp = newSplitter(orientation);
|
|
||||||
if (append)
|
|
||||||
{
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
|
|
||||||
QLayoutItem* li = l->replaceWidget(oldsp, sp);
|
|
||||||
sp->addWidget(oldsp);
|
|
||||||
sp->addWidget(sw);
|
|
||||||
delete li;
|
|
||||||
#else
|
|
||||||
int index = l->indexOf(oldsp);
|
|
||||||
QLayoutItem* li = l->takeAt(index);
|
|
||||||
l->addWidget(sp);
|
|
||||||
sp->addWidget(oldsp);
|
|
||||||
sp->addWidget(sw);
|
|
||||||
delete li;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
|
|
||||||
sp->addWidget(sw);
|
|
||||||
QLayoutItem* li = l->replaceWidget(oldsp, sp);
|
|
||||||
sp->addWidget(oldsp);
|
|
||||||
delete li;
|
|
||||||
#else
|
|
||||||
sp->addWidget(sw);
|
|
||||||
int index = l->indexOf(oldsp);
|
|
||||||
QLayoutItem* li = l->takeAt(index);
|
|
||||||
l->addWidget(sp);
|
|
||||||
sp->addWidget(oldsp);
|
|
||||||
delete li;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sw;
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray MainContainerWidget::saveHierarchy() const
|
QByteArray MainContainerWidget::saveHierarchy() const
|
||||||
{
|
{
|
||||||
@ -833,7 +730,7 @@ bool MainContainerWidget::restoreHierarchy(const QByteArray& data)
|
|||||||
if(cnt > 0)
|
if(cnt > 0)
|
||||||
{
|
{
|
||||||
// Create dummy section, required to call hideSectionContent() later.
|
// Create dummy section, required to call hideSectionContent() later.
|
||||||
SectionWidget* sw = new SectionWidget(this);
|
SectionWidget* sw = new SectionWidget(this, this);
|
||||||
sections.append(sw);
|
sections.append(sw);
|
||||||
|
|
||||||
for (int i = 0; i < cnt; ++i)
|
for (int i = 0; i < cnt; ++i)
|
||||||
@ -927,7 +824,7 @@ bool MainContainerWidget::restoreHierarchy(const QByteArray& data)
|
|||||||
|
|
||||||
if (sections.isEmpty())
|
if (sections.isEmpty())
|
||||||
{
|
{
|
||||||
sw = new SectionWidget(this);
|
sw = new SectionWidget(this, this);
|
||||||
sections.append(sw);
|
sections.append(sw);
|
||||||
addSectionWidget(sw);
|
addSectionWidget(sw);
|
||||||
}
|
}
|
||||||
@ -1051,7 +948,7 @@ bool MainContainerWidget::restoreSectionWidgets(QDataStream& in, int version, QS
|
|||||||
int currentIndex, count;
|
int currentIndex, count;
|
||||||
in >> currentIndex >> count;
|
in >> currentIndex >> count;
|
||||||
|
|
||||||
SectionWidget* sw = new SectionWidget(this);
|
SectionWidget* sw = new SectionWidget(this, this);
|
||||||
for (int i = 0; i < count; ++i)
|
for (int i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
QString uname;
|
QString uname;
|
||||||
@ -1178,6 +1075,7 @@ FloatingWidget* MainContainerWidget::startFloating(SectionWidget* sectionwidget,
|
|||||||
FloatingWidget* fw = new FloatingWidget(this, data.content, data.titleWidget, data.contentWidget, this);
|
FloatingWidget* fw = new FloatingWidget(this, data.content, data.titleWidget, data.contentWidget, this);
|
||||||
fw->resize(sectionwidget->size());
|
fw->resize(sectionwidget->size());
|
||||||
m_Floatings.append(fw);
|
m_Floatings.append(fw);
|
||||||
|
m_Containers.append(fw->containerWidget());
|
||||||
fw->move(TargetPos);
|
fw->move(TargetPos);
|
||||||
fw->show();
|
fw->show();
|
||||||
fw->setObjectName("FloatingWidget");
|
fw->setObjectName("FloatingWidget");
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <QCursor>
|
#include <QCursor>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
#ifdef ADS_ANIMATIONS_ENABLED
|
#ifdef ADS_ANIMATIONS_ENABLED
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
@ -37,9 +38,9 @@ SectionTitleWidget::SectionTitleWidget(SectionContent::RefPtr content, QWidget*
|
|||||||
l->setSpacing(0);
|
l->setSpacing(0);
|
||||||
l->addWidget(content->titleWidget());
|
l->addWidget(content->titleWidget());
|
||||||
setLayout(l);
|
setLayout(l);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SectionTitleWidget::~SectionTitleWidget()
|
SectionTitleWidget::~SectionTitleWidget()
|
||||||
{
|
{
|
||||||
layout()->removeWidget(m_Content->titleWidget());
|
layout()->removeWidget(m_Content->titleWidget());
|
||||||
@ -118,8 +119,7 @@ void SectionTitleWidget::moveFloatingWidget(QMouseEvent* ev, MainContainerWidget
|
|||||||
{
|
{
|
||||||
const QPoint moveToPos = ev->globalPos() - (m_DragStartPosition + QPoint(ADS_WINDOW_FRAME_BORDER_WIDTH, ADS_WINDOW_FRAME_BORDER_WIDTH));
|
const QPoint moveToPos = ev->globalPos() - (m_DragStartPosition + QPoint(ADS_WINDOW_FRAME_BORDER_WIDTH, ADS_WINDOW_FRAME_BORDER_WIDTH));
|
||||||
m_FloatingWidget->move(moveToPos);
|
m_FloatingWidget->move(moveToPos);
|
||||||
cw->moveFloatingWidget(moveToPos);
|
// cw->moveFloatingWidget(moveToPos);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,24 +156,42 @@ void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QPoint Pos = QCursor::pos();
|
QPoint Pos = QCursor::pos();
|
||||||
MainContainerWidget* cw = findParentContainerWidget(this);
|
// TODO make a member with the main container widget and assign it on
|
||||||
auto Floatings = cw->m_Floatings;
|
// creation
|
||||||
FloatingWidget* TopWidget = nullptr;
|
MainContainerWidget* MainContainerWidget = findParentContainerWidget(this);
|
||||||
for (auto widget : Floatings)
|
auto Containers = MainContainerWidget->m_Containers;
|
||||||
|
CContainerWidget* TopContainer = nullptr;
|
||||||
|
for (auto ContainerWidget : Containers)
|
||||||
{
|
{
|
||||||
if ((widget != m_FloatingWidget.data()) && widget->geometry().contains(Pos))
|
if (!ContainerWidget->isVisible())
|
||||||
{
|
{
|
||||||
if (!TopWidget || widget->zOrderIndex() > TopWidget->zOrderIndex())
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_FloatingWidget || (m_FloatingWidget->containerWidget() == ContainerWidget))
|
||||||
{
|
{
|
||||||
TopWidget = widget;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPoint MappedPos = ContainerWidget->mapFromGlobal(Pos);
|
||||||
|
if (ContainerWidget->rect().contains(MappedPos))
|
||||||
|
{
|
||||||
|
std::cout << "Container " << ContainerWidget << " contains maousepos" << std::endl;
|
||||||
|
if (!TopContainer || ContainerWidget->isInFrontOf(TopContainer))
|
||||||
|
{
|
||||||
|
TopContainer = ContainerWidget;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TopWidget)
|
if (TopContainer)
|
||||||
{
|
{
|
||||||
std::cout << "TopWidget " << std::hex << (int)TopWidget << std::dec
|
MainContainerWidget->dropOverlay()->showDropOverlay(TopContainer);
|
||||||
<< " Z: " << TopWidget->zOrderIndex() << std::endl;
|
MainContainerWidget->dropOverlay()->raise();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MainContainerWidget->dropOverlay()->hideDropOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
ev->accept();
|
ev->accept();
|
||||||
@ -181,7 +199,7 @@ void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev)
|
|||||||
// Move already existing FloatingWidget
|
// Move already existing FloatingWidget
|
||||||
if (isDraggingFloatingWidget())
|
if (isDraggingFloatingWidget())
|
||||||
{
|
{
|
||||||
moveFloatingWidget(ev, cw);
|
moveFloatingWidget(ev, MainContainerWidget);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,7 +227,7 @@ void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev)
|
|||||||
// Begin to drag/float the SectionContent.
|
// Begin to drag/float the SectionContent.
|
||||||
if (!sectionwidget->titleAreaGeometry().contains(sectionwidget->mapFromGlobal(ev->globalPos())))
|
if (!sectionwidget->titleAreaGeometry().contains(sectionwidget->mapFromGlobal(ev->globalPos())))
|
||||||
{
|
{
|
||||||
startFloating(ev, cw, sectionwidget);
|
startFloating(ev, MainContainerWidget, sectionwidget);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Begin to drag title inside the title area to switch its position inside the SectionWidget.
|
// Begin to drag title inside the title area to switch its position inside the SectionWidget.
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
#include <QTabBar>
|
||||||
|
|
||||||
#if defined(ADS_ANIMATIONS_ENABLED)
|
#if defined(ADS_ANIMATIONS_ENABLED)
|
||||||
#include <QGraphicsDropShadowEffect>
|
#include <QGraphicsDropShadowEffect>
|
||||||
@ -29,10 +30,11 @@
|
|||||||
|
|
||||||
ADS_NAMESPACE_BEGIN
|
ADS_NAMESPACE_BEGIN
|
||||||
|
|
||||||
SectionWidget::SectionWidget(MainContainerWidget* parent) :
|
SectionWidget::SectionWidget(MainContainerWidget* MainContainer, CContainerWidget* parent) :
|
||||||
QFrame(parent),
|
QFrame(parent),
|
||||||
_uid(GetNextUid()),
|
_uid(GetNextUid()),
|
||||||
_container(parent),
|
m_ContainerWidget(parent),
|
||||||
|
m_MainContainerWidget(MainContainer),
|
||||||
_tabsLayout(NULL),
|
_tabsLayout(NULL),
|
||||||
_tabsLayoutInitCount(0),
|
_tabsLayoutInitCount(0),
|
||||||
_contentsLayout(NULL),
|
_contentsLayout(NULL),
|
||||||
@ -44,7 +46,6 @@ SectionWidget::SectionWidget(MainContainerWidget* parent) :
|
|||||||
setLayout(l);
|
setLayout(l);
|
||||||
|
|
||||||
/* top area with tabs and close button */
|
/* top area with tabs and close button */
|
||||||
|
|
||||||
_topLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
_topLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||||
_topLayout->setContentsMargins(0, 0, 0, 0);
|
_topLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
_topLayout->setSpacing(0);
|
_topLayout->setSpacing(0);
|
||||||
@ -93,15 +94,15 @@ SectionWidget::SectionWidget(MainContainerWidget* parent) :
|
|||||||
_contentsLayout->setSpacing(0);
|
_contentsLayout->setSpacing(0);
|
||||||
l->addLayout(_contentsLayout, 1);
|
l->addLayout(_contentsLayout, 1);
|
||||||
|
|
||||||
_container->m_SectionWidgetIdMap.insert(_uid, this);
|
m_MainContainerWidget->m_SectionWidgetIdMap.insert(_uid, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionWidget::~SectionWidget()
|
SectionWidget::~SectionWidget()
|
||||||
{
|
{
|
||||||
if (_container)
|
if (m_MainContainerWidget)
|
||||||
{
|
{
|
||||||
_container->m_SectionWidgetIdMap.remove(_uid);
|
m_MainContainerWidget->m_SectionWidgetIdMap.remove(_uid);
|
||||||
_container->m_Sections.removeAll(this); // Note: I don't like this here, but we have to remove it from list...
|
m_MainContainerWidget->m_Sections.removeAll(this); // Note: I don't like this here, but we have to remove it from list...
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete empty QSplitter.
|
// Delete empty QSplitter.
|
||||||
@ -117,9 +118,9 @@ int SectionWidget::uid() const
|
|||||||
return _uid;
|
return _uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
MainContainerWidget* SectionWidget::containerWidget() const
|
CContainerWidget* SectionWidget::containerWidget() const
|
||||||
{
|
{
|
||||||
return _container;
|
return m_ContainerWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect SectionWidget::titleAreaGeometry() const
|
QRect SectionWidget::titleAreaGeometry() const
|
||||||
@ -139,11 +140,7 @@ void SectionWidget::addContent(const SectionContent::RefPtr& c)
|
|||||||
SectionTitleWidget* title = new SectionTitleWidget(c, NULL);
|
SectionTitleWidget* title = new SectionTitleWidget(c, NULL);
|
||||||
_sectionTitles.append(title);
|
_sectionTitles.append(title);
|
||||||
_tabsLayout->insertWidget(_tabsLayout->count() - _tabsLayoutInitCount, title);
|
_tabsLayout->insertWidget(_tabsLayout->count() - _tabsLayoutInitCount, title);
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
|
||||||
QObject::connect(title, &SectionTitleWidget::clicked, this, &SectionWidget::onSectionTitleClicked);
|
|
||||||
#else
|
|
||||||
QObject::connect(title, SIGNAL(clicked()), this, SLOT(onSectionTitleClicked()));
|
QObject::connect(title, SIGNAL(clicked()), this, SLOT(onSectionTitleClicked()));
|
||||||
#endif
|
|
||||||
|
|
||||||
SectionContentWidget* content = new SectionContentWidget(c, NULL);
|
SectionContentWidget* content = new SectionContentWidget(c, NULL);
|
||||||
_sectionContents.append(content);
|
_sectionContents.append(content);
|
||||||
@ -168,11 +165,7 @@ void SectionWidget::addContent(const InternalContentData& data, bool autoActivat
|
|||||||
_sectionTitles.append(data.titleWidget);
|
_sectionTitles.append(data.titleWidget);
|
||||||
_tabsLayout->insertWidget(_tabsLayout->count() - _tabsLayoutInitCount, data.titleWidget);
|
_tabsLayout->insertWidget(_tabsLayout->count() - _tabsLayoutInitCount, data.titleWidget);
|
||||||
data.titleWidget->setVisible(true);
|
data.titleWidget->setVisible(true);
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
|
||||||
QObject::connect(data.titleWidget, &SectionTitleWidget::clicked, this, &SectionWidget::onSectionTitleClicked);
|
|
||||||
#else
|
|
||||||
QObject::connect(data.titleWidget, SIGNAL(clicked()), this, SLOT(onSectionTitleClicked()));
|
QObject::connect(data.titleWidget, SIGNAL(clicked()), this, SLOT(onSectionTitleClicked()));
|
||||||
#endif
|
|
||||||
|
|
||||||
// Add content-widget to stack.
|
// Add content-widget to stack.
|
||||||
// Visibility is managed by QStackedWidget.
|
// Visibility is managed by QStackedWidget.
|
||||||
@ -217,7 +210,7 @@ bool SectionWidget::takeContent(int uid, InternalContentData& data)
|
|||||||
title->setAttribute(Qt::WA_WState_Created, false); /* fix: floating rubberband #16 */
|
title->setAttribute(Qt::WA_WState_Created, false); /* fix: floating rubberband #16 */
|
||||||
#endif
|
#endif
|
||||||
title->disconnect(this);
|
title->disconnect(this);
|
||||||
title->setParent(_container);
|
title->setParent(m_MainContainerWidget);
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||||
title->setAttribute(Qt::WA_WState_Created, true); /* fix: floating rubberband #16 */
|
title->setAttribute(Qt::WA_WState_Created, true); /* fix: floating rubberband #16 */
|
||||||
#endif
|
#endif
|
||||||
@ -229,7 +222,7 @@ bool SectionWidget::takeContent(int uid, InternalContentData& data)
|
|||||||
{
|
{
|
||||||
_contentsLayout->removeWidget(content);
|
_contentsLayout->removeWidget(content);
|
||||||
content->disconnect(this);
|
content->disconnect(this);
|
||||||
content->setParent(_container);
|
content->setParent(m_MainContainerWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select the previous tab as activeTab.
|
// Select the previous tab as activeTab.
|
||||||
@ -372,7 +365,7 @@ void SectionWidget::onCloseButtonClicked()
|
|||||||
SectionContent::RefPtr sc = _contents.at(index);
|
SectionContent::RefPtr sc = _contents.at(index);
|
||||||
if (sc.isNull())
|
if (sc.isNull())
|
||||||
return;
|
return;
|
||||||
_container->hideSectionContent(sc);
|
m_MainContainerWidget->hideSectionContent(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SectionWidget::onTabsMenuActionTriggered(bool)
|
void SectionWidget::onTabsMenuActionTriggered(bool)
|
||||||
|
@ -14,7 +14,8 @@ IconTitleWidget::IconTitleWidget(const QIcon& icon, const QString& title, QWidge
|
|||||||
setLayout(l);
|
setLayout(l);
|
||||||
|
|
||||||
_iconLabel = new QLabel();
|
_iconLabel = new QLabel();
|
||||||
l->addWidget(_iconLabel);
|
_iconLabel->setAlignment(Qt::AlignVCenter);
|
||||||
|
l->addWidget(_iconLabel, Qt::AlignVCenter);
|
||||||
|
|
||||||
_titleLabel = new QLabel();
|
_titleLabel = new QLabel();
|
||||||
l->addWidget(_titleLabel, 1);
|
l->addWidget(_titleLabel, 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user