mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-01-13 16:42:06 +08:00
Continued refactoring, created private ContainerWidget class
This commit is contained in:
parent
889d9bff5b
commit
3fd20fad16
@ -15,36 +15,13 @@ class QGridLayout;
|
|||||||
#include "ads/SectionContent.h"
|
#include "ads/SectionContent.h"
|
||||||
#include "ads/FloatingWidget.h"
|
#include "ads/FloatingWidget.h"
|
||||||
#include "ads/Serialization.h"
|
#include "ads/Serialization.h"
|
||||||
|
#include "ContainerWidget_p.h"
|
||||||
|
|
||||||
ADS_NAMESPACE_BEGIN
|
ADS_NAMESPACE_BEGIN
|
||||||
class SectionWidget;
|
class SectionWidget;
|
||||||
class DropOverlay;
|
class DropOverlay;
|
||||||
class InternalContentData;
|
class InternalContentData;
|
||||||
|
|
||||||
struct ContainerWidgetPrivate
|
|
||||||
{
|
|
||||||
// Elements inside container.
|
|
||||||
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;
|
|
||||||
|
|
||||||
|
|
||||||
// Layout stuff
|
|
||||||
QGridLayout* mainLayout = nullptr;;
|
|
||||||
Qt::Orientation orientation = Qt::Horizontal;
|
|
||||||
QPointer<QSplitter> splitter; // $mfreiholz: I'd like to remove this variable entirely,
|
|
||||||
// because it changes during user interaction anyway.
|
|
||||||
|
|
||||||
// Drop overlay stuff.
|
|
||||||
QPointer<DropOverlay> dropOverlay;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* ContainerWidget is the main container to provide the docking
|
* ContainerWidget is the main container to provide the docking
|
||||||
@ -130,13 +107,6 @@ public:
|
|||||||
// Advanced Public API
|
// Advanced Public API
|
||||||
// You usually should not need access to this methods
|
// You usually should not need access to this methods
|
||||||
//
|
//
|
||||||
|
|
||||||
// Outer DropAreas
|
|
||||||
QRect outerTopDropRect() const;
|
|
||||||
QRect outerRightDropRect() const;
|
|
||||||
QRect outerBottomDropRect() const;
|
|
||||||
QRect outerLeftDropRect() const;
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief contents
|
* \brief contents
|
||||||
* \return List of known SectionContent for this ContainerWidget.
|
* \return List of known SectionContent for this ContainerWidget.
|
||||||
|
57
AdvancedDockingSystem/include/ads/ContainerWidget_p.h
Normal file
57
AdvancedDockingSystem/include/ads/ContainerWidget_p.h
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#ifndef ContainerWidget_pH
|
||||||
|
#define ContainerWidget_pH
|
||||||
|
//============================================================================
|
||||||
|
/// \file ContainerWidget_p.h
|
||||||
|
/// \author Uwe Kindler
|
||||||
|
/// \date 21.01.2017
|
||||||
|
/// \brief Declaration of
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
// INCLUDES
|
||||||
|
//============================================================================
|
||||||
|
#include <QList>
|
||||||
|
#include <QHash>
|
||||||
|
#include <QPointer>
|
||||||
|
#include <QGridLayout>
|
||||||
|
#include <QSplitter>
|
||||||
|
|
||||||
|
#include "ads/DropOverlay.h"
|
||||||
|
|
||||||
|
namespace ads
|
||||||
|
{
|
||||||
|
|
||||||
|
class SectionWidget;
|
||||||
|
class FloatingWidget;
|
||||||
|
class HiddenSectionItem;
|
||||||
|
|
||||||
|
|
||||||
|
struct ContainerWidgetPrivate
|
||||||
|
{
|
||||||
|
// Elements inside container.
|
||||||
|
QList<SectionWidget*> sections;
|
||||||
|
QList<FloatingWidget*> floatings;
|
||||||
|
QHash<int, HiddenSectionItem> hiddenSectionContents;
|
||||||
|
|
||||||
|
|
||||||
|
// Helper lookup maps, restricted to this container.
|
||||||
|
QHash<int, SectionContent::WeakPtr> SectionContentIdMap;
|
||||||
|
QHash<QString, SectionContent::WeakPtr> SectionContentNameMap;
|
||||||
|
QHash<int, SectionWidget*> SectionWidgetIdMap;
|
||||||
|
|
||||||
|
|
||||||
|
// Layout stuff
|
||||||
|
QGridLayout* mainLayout = nullptr;
|
||||||
|
Qt::Orientation orientation = Qt::Horizontal;
|
||||||
|
QPointer<QSplitter> splitter; // $mfreiholz: I'd like to remove this variable entirely,
|
||||||
|
// because it changes during user interaction anyway.
|
||||||
|
|
||||||
|
// Drop overlay stuff.
|
||||||
|
QPointer<DropOverlay> dropOverlay;
|
||||||
|
QWidget* LeftBorderDropArea;
|
||||||
|
};
|
||||||
|
} // namespace ads
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
#endif // ContainerWidget_pH
|
@ -27,9 +27,6 @@ public:
|
|||||||
|
|
||||||
void setAllowedAreas(DropAreas areas);
|
void setAllowedAreas(DropAreas areas);
|
||||||
DropAreas allowedAreas() const;
|
DropAreas allowedAreas() const;
|
||||||
|
|
||||||
void setAreaWidgets(const QHash<DropArea, QWidget*>& widgets);
|
|
||||||
|
|
||||||
DropArea cursorLocation() const;
|
DropArea cursorLocation() const;
|
||||||
|
|
||||||
DropArea showDropOverlay(QWidget* target);
|
DropArea showDropOverlay(QWidget* target);
|
||||||
@ -51,12 +48,9 @@ protected:
|
|||||||
private:
|
private:
|
||||||
DropAreas _allowedAreas;
|
DropAreas _allowedAreas;
|
||||||
DropOverlayCross* _cross;
|
DropOverlayCross* _cross;
|
||||||
|
|
||||||
bool _fullAreaDrop;
|
|
||||||
QPointer<QWidget> _target;
|
QPointer<QWidget> _target;
|
||||||
QRect _targetRect;
|
QRect _targetRect;
|
||||||
DropArea _lastLocation;
|
DropArea _lastLocation;
|
||||||
QWidget* m_LeftBorderDropArea;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -41,6 +41,10 @@ ContainerWidget::ContainerWidget(QWidget *parent) :
|
|||||||
QFrame(parent),
|
QFrame(parent),
|
||||||
d(new ContainerWidgetPrivate())
|
d(new ContainerWidgetPrivate())
|
||||||
{
|
{
|
||||||
|
d->LeftBorderDropArea = DropOverlay::createDropIndicatorWidget(LeftBorderDropArea);
|
||||||
|
d->LeftBorderDropArea->setVisible(false);
|
||||||
|
d->LeftBorderDropArea->setWindowTitle("LeftBorderDropArea");
|
||||||
|
|
||||||
d->dropOverlay = new DropOverlay(this);
|
d->dropOverlay = new DropOverlay(this);
|
||||||
d->mainLayout = new QGridLayout();
|
d->mainLayout = new QGridLayout();
|
||||||
d->mainLayout->setContentsMargins(4, 4, 4, 4);
|
d->mainLayout->setContentsMargins(4, 4, 4, 4);
|
||||||
@ -64,9 +68,9 @@ ContainerWidget::~ContainerWidget()
|
|||||||
FloatingWidget* fw = d->floatings.takeLast();
|
FloatingWidget* fw = d->floatings.takeLast();
|
||||||
delete fw;
|
delete fw;
|
||||||
}
|
}
|
||||||
d->scLookupMapById.clear();
|
d->SectionContentIdMap.clear();
|
||||||
d->scLookupMapByName.clear();
|
d->SectionContentNameMap.clear();
|
||||||
d->swLookupMapById.clear();
|
d->SectionWidgetIdMap.clear();
|
||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +161,7 @@ bool ContainerWidget::showSectionContent(const SectionContent::RefPtr& sc)
|
|||||||
hsi.data.titleWidget->setVisible(true);
|
hsi.data.titleWidget->setVisible(true);
|
||||||
hsi.data.contentWidget->setVisible(true);
|
hsi.data.contentWidget->setVisible(true);
|
||||||
SectionWidget* sw = nullptr;
|
SectionWidget* sw = nullptr;
|
||||||
if (hsi.preferredSectionId > 0 && (sw = d->swLookupMapById.value(hsi.preferredSectionId)) != nullptr)
|
if (hsi.preferredSectionId > 0 && (sw = d->SectionWidgetIdMap.value(hsi.preferredSectionId)) != nullptr)
|
||||||
{
|
{
|
||||||
sw->addContent(hsi.data, true);
|
sw->addContent(hsi.data, true);
|
||||||
emit sectionContentVisibilityChanged(sc, true);
|
emit sectionContentVisibilityChanged(sc, true);
|
||||||
@ -410,37 +414,10 @@ bool ContainerWidget::restoreState(const QByteArray& data)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<SectionContent::RefPtr> ContainerWidget::contents() const
|
QList<SectionContent::RefPtr> ContainerWidget::contents() const
|
||||||
{
|
{
|
||||||
QList<SectionContent::WeakPtr> wl = d->scLookupMapById.values();
|
QList<SectionContent::WeakPtr> wl = d->SectionContentIdMap.values();
|
||||||
QList<SectionContent::RefPtr> sl;
|
QList<SectionContent::RefPtr> sl;
|
||||||
for (int i = 0; i < wl.count(); ++i)
|
for (int i = 0; i < wl.count(); ++i)
|
||||||
{
|
{
|
||||||
@ -768,7 +745,7 @@ QByteArray ContainerWidget::saveHierarchy() const
|
|||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
iter.next();
|
iter.next();
|
||||||
if (iter.value().preferredSectionId <= 0 || !d->swLookupMapById.contains(iter.value().preferredSectionId))
|
if (iter.value().preferredSectionId <= 0 || !d->SectionWidgetIdMap.contains(iter.value().preferredSectionId))
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
out << cnt;
|
out << cnt;
|
||||||
@ -776,7 +753,7 @@ QByteArray ContainerWidget::saveHierarchy() const
|
|||||||
while (iter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
iter.next();
|
iter.next();
|
||||||
if (iter.value().preferredSectionId <= 0 || !d->swLookupMapById.contains(iter.value().preferredSectionId))
|
if (iter.value().preferredSectionId <= 0 || !d->SectionWidgetIdMap.contains(iter.value().preferredSectionId))
|
||||||
out << iter.value().data.content->uniqueName();
|
out << iter.value().data.content->uniqueName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -941,7 +918,7 @@ bool ContainerWidget::restoreHierarchy(const QByteArray& data)
|
|||||||
QString uname;
|
QString uname;
|
||||||
in >> uname;
|
in >> uname;
|
||||||
|
|
||||||
const SectionContent::RefPtr sc = d->scLookupMapByName.value(uname);
|
const SectionContent::RefPtr sc = d->SectionContentNameMap.value(uname);
|
||||||
if (!sc)
|
if (!sc)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -967,7 +944,7 @@ bool ContainerWidget::restoreHierarchy(const QByteArray& data)
|
|||||||
{
|
{
|
||||||
QString uname;
|
QString uname;
|
||||||
in >> uname;
|
in >> uname;
|
||||||
const SectionContent::RefPtr sc = d->scLookupMapByName.value(uname);
|
const SectionContent::RefPtr sc = d->SectionContentNameMap.value(uname);
|
||||||
if (!sc)
|
if (!sc)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -1006,7 +983,7 @@ bool ContainerWidget::restoreHierarchy(const QByteArray& data)
|
|||||||
contents.append(contentsToHide.at(i));
|
contents.append(contentsToHide.at(i));
|
||||||
|
|
||||||
// Compare restored contents with available contents
|
// Compare restored contents with available contents
|
||||||
const QList<SectionContent::WeakPtr> allContents = d->scLookupMapById.values();
|
const QList<SectionContent::WeakPtr> allContents = d->SectionContentIdMap.values();
|
||||||
for (int i = 0; i < allContents.count(); ++i)
|
for (int i = 0; i < allContents.count(); ++i)
|
||||||
{
|
{
|
||||||
const SectionContent::RefPtr sc = allContents.at(i).toStrongRef();
|
const SectionContent::RefPtr sc = allContents.at(i).toStrongRef();
|
||||||
@ -1078,7 +1055,7 @@ bool ContainerWidget::restoreFloatingWidgets(QDataStream& in, int version, QList
|
|||||||
bool visible = false;
|
bool visible = false;
|
||||||
in >> visible;
|
in >> visible;
|
||||||
|
|
||||||
const SectionContent::RefPtr sc = d->scLookupMapByName.value(uname).toStrongRef();
|
const SectionContent::RefPtr sc = d->SectionContentNameMap.value(uname).toStrongRef();
|
||||||
if (!sc)
|
if (!sc)
|
||||||
{
|
{
|
||||||
qWarning() << "Can not find SectionContent:" << uname;
|
qWarning() << "Can not find SectionContent:" << uname;
|
||||||
@ -1161,7 +1138,7 @@ bool ContainerWidget::restoreSectionWidgets(QDataStream& in, int version, QSplit
|
|||||||
int preferredIndex = -1;
|
int preferredIndex = -1;
|
||||||
in >> preferredIndex;
|
in >> preferredIndex;
|
||||||
|
|
||||||
const SectionContent::RefPtr sc = d->scLookupMapByName.value(uname).toStrongRef();
|
const SectionContent::RefPtr sc = d->SectionContentNameMap.value(uname).toStrongRef();
|
||||||
if (!sc)
|
if (!sc)
|
||||||
{
|
{
|
||||||
qWarning() << "Can not find SectionContent:" << uname;
|
qWarning() << "Can not find SectionContent:" << uname;
|
||||||
@ -1246,7 +1223,7 @@ void ContainerWidget::onActionToggleSectionContentVisibility(bool visible)
|
|||||||
if (!a)
|
if (!a)
|
||||||
return;
|
return;
|
||||||
const int uid = a->property("uid").toInt();
|
const int uid = a->property("uid").toInt();
|
||||||
const SectionContent::RefPtr sc = d->scLookupMapById.value(uid).toStrongRef();
|
const SectionContent::RefPtr sc = d->SectionContentIdMap.value(uid).toStrongRef();
|
||||||
if (sc.isNull())
|
if (sc.isNull())
|
||||||
{
|
{
|
||||||
qCritical() << "Can not find content by ID" << uid;
|
qCritical() << "Can not find content by ID" << uid;
|
||||||
@ -1261,14 +1238,21 @@ void ContainerWidget::onActionToggleSectionContentVisibility(bool visible)
|
|||||||
|
|
||||||
void ContainerWidget::moveFloatingWidget(const QPoint& TargetPos)
|
void ContainerWidget::moveFloatingWidget(const QPoint& TargetPos)
|
||||||
{
|
{
|
||||||
// Mouse is over a SectionWidget
|
// Mouse is over the container widget
|
||||||
SectionWidget* sectionwidget = sectionAt(mapFromGlobal(QCursor::pos()));
|
|
||||||
if (rect().contains(mapFromGlobal(QCursor::pos())))
|
if (rect().contains(mapFromGlobal(QCursor::pos())))
|
||||||
{
|
{
|
||||||
std::cout << "over Container" << std::endl;
|
std::cout << "over Container" << std::endl;
|
||||||
|
d->LeftBorderDropArea->show();
|
||||||
|
d->LeftBorderDropArea->raise();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "-----------------" << std::endl;
|
||||||
|
d->LeftBorderDropArea->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mouse is over a SectionWidget
|
||||||
|
SectionWidget* sectionwidget = sectionAt(mapFromGlobal(QCursor::pos()));
|
||||||
if (sectionwidget)
|
if (sectionwidget)
|
||||||
{
|
{
|
||||||
qInfo() << "over sectionWidget";
|
qInfo() << "over sectionWidget";
|
||||||
@ -1305,6 +1289,10 @@ FloatingWidget* ContainerWidget::startFloating(SectionWidget* sectionwidget, int
|
|||||||
sectionwidget = NULL;
|
sectionwidget = NULL;
|
||||||
}
|
}
|
||||||
deleteEmptySplitter(this);
|
deleteEmptySplitter(this);
|
||||||
|
|
||||||
|
QRect Rect = rect();
|
||||||
|
QPoint Pos(Rect.left(), Rect.center().y());
|
||||||
|
d->LeftBorderDropArea->move(mapToGlobal(Pos));
|
||||||
return fw;
|
return fw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,6 @@ DropOverlay::DropOverlay(QWidget* parent) :
|
|||||||
QFrame(parent),
|
QFrame(parent),
|
||||||
_allowedAreas(InvalidDropArea),
|
_allowedAreas(InvalidDropArea),
|
||||||
_cross(new DropOverlayCross(this)),
|
_cross(new DropOverlayCross(this)),
|
||||||
_fullAreaDrop(false),
|
|
||||||
_lastLocation(InvalidDropArea)
|
_lastLocation(InvalidDropArea)
|
||||||
{
|
{
|
||||||
setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
|
setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
|
||||||
@ -144,10 +143,6 @@ DropOverlay::DropOverlay(QWidget* parent) :
|
|||||||
areaWidgets.insert(ADS_NS::LeftDropArea, createDropIndicatorWidget(LeftDropArea));//createDropWidget(":/img/split-left.png"));
|
areaWidgets.insert(ADS_NS::LeftDropArea, createDropIndicatorWidget(LeftDropArea));//createDropWidget(":/img/split-left.png"));
|
||||||
areaWidgets.insert(ADS_NS::CenterDropArea, createDropIndicatorWidget(CenterDropArea));//createDropWidget(":/img/dock-center.png"));
|
areaWidgets.insert(ADS_NS::CenterDropArea, createDropIndicatorWidget(CenterDropArea));//createDropWidget(":/img/dock-center.png"));
|
||||||
|
|
||||||
m_LeftBorderDropArea = createDropIndicatorWidget(LeftDropArea);
|
|
||||||
m_LeftBorderDropArea->setVisible(false);
|
|
||||||
m_LeftBorderDropArea->setWindowTitle("DropOverlayCross");
|
|
||||||
|
|
||||||
_cross->setAreaWidgets(areaWidgets);
|
_cross->setAreaWidgets(areaWidgets);
|
||||||
_cross->setVisible(false);
|
_cross->setVisible(false);
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
@ -171,10 +166,6 @@ DropAreas DropOverlay::allowedAreas() const
|
|||||||
return _allowedAreas;
|
return _allowedAreas;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DropOverlay::setAreaWidgets(const QHash<DropArea, QWidget*>& widgets)
|
|
||||||
{
|
|
||||||
_cross->setAreaWidgets(widgets);
|
|
||||||
}
|
|
||||||
|
|
||||||
DropArea DropOverlay::cursorLocation() const
|
DropArea DropOverlay::cursorLocation() const
|
||||||
{
|
{
|
||||||
@ -183,8 +174,7 @@ DropArea DropOverlay::cursorLocation() const
|
|||||||
|
|
||||||
DropArea DropOverlay::showDropOverlay(QWidget* target)
|
DropArea DropOverlay::showDropOverlay(QWidget* target)
|
||||||
{
|
{
|
||||||
qInfo() << "DropOverlay::showDropOverlay(QWidget* target)";
|
std::cout << "DropOverlay::showDropOverlay(QWidget* target)" << std::endl;
|
||||||
_fullAreaDrop = true;
|
|
||||||
if (_target == target)
|
if (_target == target)
|
||||||
{
|
{
|
||||||
qInfo() << "_target == target";
|
qInfo() << "_target == target";
|
||||||
@ -199,9 +189,8 @@ DropArea DropOverlay::showDropOverlay(QWidget* target)
|
|||||||
return da;
|
return da;
|
||||||
}
|
}
|
||||||
|
|
||||||
hideDropOverlay();
|
//hideDropOverlay();
|
||||||
qInfo() << "_target != target, hideDropOverlay(), _fullAreaDrop = false";
|
std::cout << "_target != target, hideDropOverlay(), _fullAreaDrop = false" << std::endl;
|
||||||
_fullAreaDrop = false;
|
|
||||||
_target = target;
|
_target = target;
|
||||||
_targetRect = QRect();
|
_targetRect = QRect();
|
||||||
_lastLocation = InvalidDropArea;
|
_lastLocation = InvalidDropArea;
|
||||||
@ -209,9 +198,7 @@ DropArea DropOverlay::showDropOverlay(QWidget* target)
|
|||||||
// Move it over the target.
|
// Move it over the target.
|
||||||
resize(target->size());
|
resize(target->size());
|
||||||
move(target->mapToGlobal(target->rect().topLeft()));
|
move(target->mapToGlobal(target->rect().topLeft()));
|
||||||
|
|
||||||
show();
|
show();
|
||||||
|
|
||||||
return cursorLocation();
|
return cursorLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,8 +209,7 @@ void DropOverlay::showDropOverlay(QWidget* target, const QRect& targetAreaRect)
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hideDropOverlay();
|
//hideDropOverlay();
|
||||||
_fullAreaDrop = true;
|
|
||||||
_target = target;
|
_target = target;
|
||||||
_targetRect = targetAreaRect;
|
_targetRect = targetAreaRect;
|
||||||
_lastLocation = InvalidDropArea;
|
_lastLocation = InvalidDropArea;
|
||||||
@ -231,9 +217,7 @@ void DropOverlay::showDropOverlay(QWidget* target, const QRect& targetAreaRect)
|
|||||||
// Move it over the target's area.
|
// Move it over the target's area.
|
||||||
resize(targetAreaRect.size());
|
resize(targetAreaRect.size());
|
||||||
move(target->mapToGlobal(QPoint(targetAreaRect.x(), targetAreaRect.y())));
|
move(target->mapToGlobal(QPoint(targetAreaRect.x(), targetAreaRect.y())));
|
||||||
|
|
||||||
show();
|
show();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +225,6 @@ void DropOverlay::hideDropOverlay()
|
|||||||
{
|
{
|
||||||
qInfo() << "hideDropOverlay() _fullAreaDrop = false";
|
qInfo() << "hideDropOverlay() _fullAreaDrop = false";
|
||||||
hide();
|
hide();
|
||||||
_fullAreaDrop = false;
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||||
_target.clear();
|
_target.clear();
|
||||||
#else
|
#else
|
||||||
@ -253,9 +236,6 @@ void DropOverlay::hideDropOverlay()
|
|||||||
|
|
||||||
void DropOverlay::paintEvent(QPaintEvent*)
|
void DropOverlay::paintEvent(QPaintEvent*)
|
||||||
{
|
{
|
||||||
QPainter p(this);
|
|
||||||
const QColor areaColor = palette().color(QPalette::Active, QPalette::Highlight);
|
|
||||||
|
|
||||||
// Draw rect based on location
|
// Draw rect based on location
|
||||||
QRect r = rect();
|
QRect r = rect();
|
||||||
const DropArea da = cursorLocation();
|
const DropArea da = cursorLocation();
|
||||||
@ -278,23 +258,13 @@ void DropOverlay::paintEvent(QPaintEvent*)
|
|||||||
r = rect();
|
r = rect();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
r = QRect();
|
return;
|
||||||
}
|
}
|
||||||
if (!r.isNull())
|
QPainter painter(this);
|
||||||
{
|
QColor Color = palette().color(QPalette::Active, QPalette::Highlight);
|
||||||
p.fillRect(r, QBrush(areaColor, Qt::Dense4Pattern));
|
painter.fillRect(r, QBrush(Color, Qt::Dense4Pattern));
|
||||||
p.setBrush(QBrush(areaColor));
|
painter.setBrush(QBrush(Color));
|
||||||
p.drawRect(r);
|
painter.drawRect(r);
|
||||||
}
|
|
||||||
|
|
||||||
// Draw rect over the entire size + border.
|
|
||||||
// auto r = rect();
|
|
||||||
// r.setWidth(r.width() - 1);
|
|
||||||
// r.setHeight(r.height() - 1);
|
|
||||||
|
|
||||||
// p.fillRect(r, QBrush(QColor(0, 100, 255), Qt::Dense4Pattern));
|
|
||||||
// p.setBrush(QBrush(QColor(0, 100, 255)));
|
|
||||||
// p.drawRect(r);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DropOverlay::showEvent(QShowEvent*)
|
void DropOverlay::showEvent(QShowEvent*)
|
||||||
@ -302,15 +272,11 @@ void DropOverlay::showEvent(QShowEvent*)
|
|||||||
_cross->show();
|
_cross->show();
|
||||||
QRect ContainerWidgetRect = parentWidget()->rect();
|
QRect ContainerWidgetRect = parentWidget()->rect();
|
||||||
QPoint Pos(ContainerWidgetRect.left(), ContainerWidgetRect.center().y());
|
QPoint Pos(ContainerWidgetRect.left(), ContainerWidgetRect.center().y());
|
||||||
m_LeftBorderDropArea->move(parentWidget()->mapToGlobal(Pos));
|
|
||||||
m_LeftBorderDropArea->show();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DropOverlay::hideEvent(QHideEvent*)
|
void DropOverlay::hideEvent(QHideEvent*)
|
||||||
{
|
{
|
||||||
_cross->hide();
|
_cross->hide();
|
||||||
m_LeftBorderDropArea->hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DropOverlay::resizeEvent(QResizeEvent* e)
|
void DropOverlay::resizeEvent(QResizeEvent* e)
|
||||||
|
@ -16,8 +16,8 @@ SectionContent::SectionContent() :
|
|||||||
|
|
||||||
SectionContent::RefPtr SectionContent::newSectionContent(const QString& uniqueName, ContainerWidget* container, QWidget* title, QWidget* content)
|
SectionContent::RefPtr SectionContent::newSectionContent(const QString& uniqueName, ContainerWidget* container, QWidget* title, QWidget* content)
|
||||||
{
|
{
|
||||||
auto SectionContentNameMap = container->d->scLookupMapByName;
|
auto SectionContentNameMap = container->d->SectionContentNameMap;
|
||||||
auto SectionContentIdMap = container->d->scLookupMapById;
|
auto SectionContentIdMap = container->d->SectionContentIdMap;
|
||||||
|
|
||||||
if (uniqueName.isEmpty())
|
if (uniqueName.isEmpty())
|
||||||
{
|
{
|
||||||
@ -48,8 +48,8 @@ SectionContent::RefPtr SectionContent::newSectionContent(const QString& uniqueNa
|
|||||||
|
|
||||||
SectionContent::~SectionContent()
|
SectionContent::~SectionContent()
|
||||||
{
|
{
|
||||||
auto SectionContentNameMap = _containerWidget->d->scLookupMapByName;
|
auto SectionContentNameMap = _containerWidget->d->SectionContentNameMap;
|
||||||
auto SectionContentIdMap = _containerWidget->d->scLookupMapById;
|
auto SectionContentIdMap = _containerWidget->d->SectionContentIdMap;
|
||||||
|
|
||||||
if (_containerWidget)
|
if (_containerWidget)
|
||||||
{
|
{
|
||||||
|
@ -97,7 +97,7 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
|
|||||||
// Mouse is over a outer-edge drop area
|
// Mouse is over a outer-edge drop area
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DropArea dropArea = ADS_NS::InvalidDropArea;
|
/*DropArea dropArea = ADS_NS::InvalidDropArea;
|
||||||
if (cw->outerTopDropRect().contains(cw->mapFromGlobal(ev->globalPos())))
|
if (cw->outerTopDropRect().contains(cw->mapFromGlobal(ev->globalPos())))
|
||||||
dropArea = ADS_NS::TopDropArea;
|
dropArea = ADS_NS::TopDropArea;
|
||||||
if (cw->outerRightDropRect().contains(cw->mapFromGlobal(ev->globalPos())))
|
if (cw->outerRightDropRect().contains(cw->mapFromGlobal(ev->globalPos())))
|
||||||
@ -114,7 +114,7 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
|
|||||||
m_FloatingWidget->deleteLater();
|
m_FloatingWidget->deleteLater();
|
||||||
m_FloatingWidget.clear();
|
m_FloatingWidget.clear();
|
||||||
cw->dropContent(data, NULL, dropArea, true);
|
cw->dropContent(data, NULL, dropArea, true);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// End of tab moving, change order now
|
// End of tab moving, change order now
|
||||||
|
@ -93,14 +93,14 @@ SectionWidget::SectionWidget(ContainerWidget* parent) :
|
|||||||
_contentsLayout->setSpacing(0);
|
_contentsLayout->setSpacing(0);
|
||||||
l->addLayout(_contentsLayout, 1);
|
l->addLayout(_contentsLayout, 1);
|
||||||
|
|
||||||
_container->d->swLookupMapById.insert(_uid, this);
|
_container->d->SectionWidgetIdMap.insert(_uid, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionWidget::~SectionWidget()
|
SectionWidget::~SectionWidget()
|
||||||
{
|
{
|
||||||
if (_container)
|
if (_container)
|
||||||
{
|
{
|
||||||
_container->d->swLookupMapById.remove(_uid);
|
_container->d->SectionWidgetIdMap.remove(_uid);
|
||||||
_container->d->sections.removeAll(this); // Note: I don't like this here, but we have to remove it from list...
|
_container->d->sections.removeAll(this); // Note: I don't like this here, but we have to remove it from list...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,66 +90,14 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
// Setup actions.
|
// Setup actions.
|
||||||
QObject::connect(ui->actionContentList, SIGNAL(triggered()), this, SLOT(showSectionContentListDialog()));
|
connect(ui->actionContentList, SIGNAL(triggered()), this, SLOT(showSectionContentListDialog()));
|
||||||
|
|
||||||
// ADS - Create main container (ContainerWidget).
|
// ADS - Create main container (ContainerWidget).
|
||||||
_container = new ADS_NS::ContainerWidget();
|
_container = new ADS_NS::ContainerWidget();
|
||||||
#if QT_VERSION >= 0x050000
|
connect(_container, SIGNAL(activeTabChanged(const SectionContent::RefPtr&, bool)), this, SLOT(onActiveTabChanged(const SectionContent::RefPtr&, bool)));
|
||||||
QObject::connect(_container, &ADS_NS::ContainerWidget::activeTabChanged, this, &MainWindow::onActiveTabChanged);
|
connect(_container, SIGNAL(sectionContentVisibilityChanged(SectionContent::RefPtr,bool)), this, SLOT(onSectionContentVisibilityChanged(SectionContent::RefPtr,bool)));
|
||||||
QObject::connect(_container, &ADS_NS::ContainerWidget::sectionContentVisibilityChanged, this, &MainWindow::onSectionContentVisibilityChanged);
|
|
||||||
#else
|
|
||||||
QObject::connect(_container, SIGNAL(activeTabChanged(const SectionContent::RefPtr&, bool)), this, SLOT(onActiveTabChanged(const SectionContent::RefPtr&, bool)));
|
|
||||||
QObject::connect(_container, SIGNAL(sectionContentVisibilityChanged(SectionContent::RefPtr,bool)), this, SLOT(onSectionContentVisibilityChanged(SectionContent::RefPtr,bool)));
|
|
||||||
#endif
|
|
||||||
setCentralWidget(_container);
|
setCentralWidget(_container);
|
||||||
|
createContent();
|
||||||
// Optional: Use custom drop area widgets.
|
|
||||||
if (false)
|
|
||||||
{
|
|
||||||
QHash<ADS_NS::DropArea, QWidget*> areaWidgets;
|
|
||||||
areaWidgets.insert(ADS_NS::TopDropArea, new QPushButton("TOP"));
|
|
||||||
areaWidgets.insert(ADS_NS::RightDropArea, new QPushButton("RIGHT"));
|
|
||||||
areaWidgets.insert(ADS_NS::BottomDropArea, new QPushButton("BOTTOM"));
|
|
||||||
areaWidgets.insert(ADS_NS::LeftDropArea, new QPushButton("LEFT"));
|
|
||||||
areaWidgets.insert(ADS_NS::CenterDropArea, new QPushButton("CENTER"));
|
|
||||||
_container->dropOverlay()->setAreaWidgets(areaWidgets);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ADS - Adding some contents.
|
|
||||||
if (true)
|
|
||||||
{
|
|
||||||
// Test #1: Use high-level public API
|
|
||||||
ADS_NS::ContainerWidget* cw = _container;
|
|
||||||
ADS_NS::SectionWidget* sw = NULL;
|
|
||||||
|
|
||||||
sw = _container->addSectionContent(createLongTextLabelSC(cw), nullptr, ADS_NS::CenterDropArea);
|
|
||||||
sw = _container->addSectionContent(createCalendarSC(cw), nullptr, ADS_NS::LeftDropArea);
|
|
||||||
sw = _container->addSectionContent(createFileSystemTreeSC(cw), nullptr, ADS_NS::BottomDropArea);
|
|
||||||
|
|
||||||
/*_container->addSectionContent(createCalendarSC(_container));
|
|
||||||
_container->addSectionContent(createLongTextLabelSC(_container));
|
|
||||||
_container->addSectionContent(createLongTextLabelSC(_container));
|
|
||||||
_container->addSectionContent(createLongTextLabelSC(_container));
|
|
||||||
|
|
||||||
ADS_NS::SectionContent::RefPtr sc = createLongTextLabelSC(cw);
|
|
||||||
sc->setFlags(ADS_NS::SectionContent::AllFlags ^ ADS_NS::SectionContent::Closeable);
|
|
||||||
_container->addSectionContent(sc);*/
|
|
||||||
}
|
|
||||||
else if (false)
|
|
||||||
{
|
|
||||||
// Issue #2: If the first drop is not into CenterDropArea, the application crashes.
|
|
||||||
ADS_NS::ContainerWidget* cw = _container;
|
|
||||||
ADS_NS::SectionWidget* sw = NULL;
|
|
||||||
|
|
||||||
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::LeftDropArea);
|
|
||||||
sw = _container->addSectionContent(createCalendarSC(cw), sw, ADS_NS::LeftDropArea);
|
|
||||||
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::CenterDropArea);
|
|
||||||
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::CenterDropArea);
|
|
||||||
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::CenterDropArea);
|
|
||||||
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::RightDropArea);
|
|
||||||
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::BottomDropArea);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default window geometry
|
// Default window geometry
|
||||||
resize(800, 600);
|
resize(800, 600);
|
||||||
restoreGeometry(loadDataHelper("MainWindow"));
|
restoreGeometry(loadDataHelper("MainWindow"));
|
||||||
@ -163,6 +111,42 @@ MainWindow::~MainWindow()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::createContent()
|
||||||
|
{
|
||||||
|
// ADS - Adding some contents.
|
||||||
|
// Test #1: Use high-level public API
|
||||||
|
ADS_NS::ContainerWidget* cw = _container;
|
||||||
|
ADS_NS::SectionWidget* sw = NULL;
|
||||||
|
|
||||||
|
sw = _container->addSectionContent(createLongTextLabelSC(cw), nullptr, ADS_NS::CenterDropArea);
|
||||||
|
sw = _container->addSectionContent(createCalendarSC(cw), nullptr, ADS_NS::LeftDropArea);
|
||||||
|
sw = _container->addSectionContent(createFileSystemTreeSC(cw), nullptr, ADS_NS::BottomDropArea);
|
||||||
|
|
||||||
|
/*_container->addSectionContent(createCalendarSC(_container));
|
||||||
|
_container->addSectionContent(createLongTextLabelSC(_container));
|
||||||
|
_container->addSectionContent(createLongTextLabelSC(_container));
|
||||||
|
_container->addSectionContent(createLongTextLabelSC(_container));
|
||||||
|
|
||||||
|
ADS_NS::SectionContent::RefPtr sc = createLongTextLabelSC(cw);
|
||||||
|
sc->setFlags(ADS_NS::SectionContent::AllFlags ^ ADS_NS::SectionContent::Closeable);
|
||||||
|
_container->addSectionContent(sc);*/
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// Issue #2: If the first drop is not into CenterDropArea, the application crashes.
|
||||||
|
ADS_NS::ContainerWidget* cw = _container;
|
||||||
|
ADS_NS::SectionWidget* sw = NULL;
|
||||||
|
|
||||||
|
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::LeftDropArea);
|
||||||
|
sw = _container->addSectionContent(createCalendarSC(cw), sw, ADS_NS::LeftDropArea);
|
||||||
|
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::CenterDropArea);
|
||||||
|
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::CenterDropArea);
|
||||||
|
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::CenterDropArea);
|
||||||
|
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::RightDropArea);
|
||||||
|
sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ADS_NS::BottomDropArea);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::showSectionContentListDialog()
|
void MainWindow::showSectionContentListDialog()
|
||||||
{
|
{
|
||||||
SectionContentListWidget::Values v;
|
SectionContentListWidget::Values v;
|
||||||
|
@ -38,6 +38,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
ADS_NS::ContainerWidget* _container;
|
ADS_NS::ContainerWidget* _container;
|
||||||
|
void createContent();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
Loading…
Reference in New Issue
Block a user