mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 23:31:32 +08:00
fix: #13 custom drop area widgets
- adds public function to set widgets - some cleanup changes
This commit is contained in:
parent
180ed31fc4
commit
e04b5c7900
@ -112,6 +112,8 @@ public:
|
||||
*/
|
||||
QList<SectionContent::RefPtr> contents() const;
|
||||
|
||||
QPointer<DropOverlay> dropOverlay() const;
|
||||
|
||||
private:
|
||||
//
|
||||
// Internal Stuff Begins Here
|
||||
|
@ -16,7 +16,7 @@ class DropOverlayCross;
|
||||
* DropOverlay paints a translucent rectangle over another widget. The geometry
|
||||
* of the rectangle is based on the mouse location.
|
||||
*/
|
||||
class DropOverlay : public QFrame
|
||||
class ADS_EXPORT_API DropOverlay : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class DropOverlayCross;
|
||||
@ -28,6 +28,8 @@ public:
|
||||
void setAllowedAreas(DropAreas areas);
|
||||
DropAreas allowedAreas() const;
|
||||
|
||||
void setAreaWidgets(const QHash<DropArea, QWidget*>& widgets);
|
||||
|
||||
DropArea cursorLocation() const;
|
||||
|
||||
DropArea showDropOverlay(QWidget* target);
|
||||
@ -51,7 +53,11 @@ private:
|
||||
DropArea _lastLocation;
|
||||
};
|
||||
|
||||
// DropOverlayCross shows a cross with 5 different drop area possibilities.
|
||||
/*!
|
||||
* DropOverlayCross shows a cross with 5 different drop area possibilities.
|
||||
* I could have handled everything inside DropOverlay, but because of some
|
||||
* styling issues it's better to have a separate class for the cross.
|
||||
*/
|
||||
class DropOverlayCross : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -434,6 +434,11 @@ QList<SectionContent::RefPtr> ContainerWidget::contents() const
|
||||
return sl;
|
||||
}
|
||||
|
||||
QPointer<DropOverlay> ContainerWidget::dropOverlay() const
|
||||
{
|
||||
return _dropOverlay;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE API BEGINS HERE
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
@ -40,7 +40,7 @@ DropOverlay::DropOverlay(QWidget* parent) :
|
||||
l->setSpacing(0);
|
||||
setLayout(l);
|
||||
|
||||
// Cross widget.
|
||||
// Cross with default drop area widgets.
|
||||
QHash<DropArea, QWidget*> areaWidgets;
|
||||
areaWidgets.insert(ADS_NS::TopDropArea, createDropWidget(":/img/split-top.png"));
|
||||
areaWidgets.insert(ADS_NS::RightDropArea, createDropWidget(":/img/split-right.png"));
|
||||
@ -64,8 +64,6 @@ void DropOverlay::setAllowedAreas(DropAreas areas)
|
||||
_allowedAreas = areas;
|
||||
|
||||
_cross->reset();
|
||||
// _cross->move(pos());
|
||||
// _cross->resize(size());
|
||||
}
|
||||
|
||||
DropAreas DropOverlay::allowedAreas() const
|
||||
@ -73,6 +71,11 @@ DropAreas DropOverlay::allowedAreas() const
|
||||
return _allowedAreas;
|
||||
}
|
||||
|
||||
void DropOverlay::setAreaWidgets(const QHash<DropArea, QWidget*>& widgets)
|
||||
{
|
||||
_cross->setAreaWidgets(widgets);
|
||||
}
|
||||
|
||||
DropArea DropOverlay::cursorLocation() const
|
||||
{
|
||||
return _cross->cursorLocation();
|
||||
@ -243,7 +246,7 @@ DropOverlayCross::DropOverlayCross(DropOverlay* overlay) :
|
||||
_widgets()
|
||||
{
|
||||
setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
|
||||
setWindowTitle("DropSplitAreas");
|
||||
setWindowTitle("DropOverlayCross");
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
|
||||
_grid = new QGridLayout();
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <QBoxLayout>
|
||||
|
||||
#include "ads/SectionWidget.h"
|
||||
#include "ads/DropOverlay.h"
|
||||
|
||||
#include "dialogs/SectionContentListWidget.h"
|
||||
|
||||
@ -102,6 +103,18 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
#endif
|
||||
setCentralWidget(_container);
|
||||
|
||||
// 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.
|
||||
// Test #1: Use high-level public API
|
||||
if (true)
|
||||
|
Loading…
Reference in New Issue
Block a user