- Fixes empty QSplitter bug
- Removes obsolete code
This commit is contained in:
@@ -5,10 +5,21 @@
|
||||
|
||||
#include "ads/ContainerWidget.h"
|
||||
|
||||
const QString DragData::MIMETYPE = QString("qt/ads-dragdata");
|
||||
//const QString DragData::MIMETYPE = QString("qt/ads-dragdata");
|
||||
|
||||
ADS_NAMESPACE_BEGIN
|
||||
|
||||
void deleteEmptySplitter(ContainerWidget* container)
|
||||
{
|
||||
auto splitters = container->findChildren<QSplitter*>();
|
||||
for (auto i = 0; i < splitters.count(); ++i)
|
||||
{
|
||||
auto sp = splitters.at(i);
|
||||
if (sp->count() == 0)
|
||||
delete splitters[i];
|
||||
}
|
||||
}
|
||||
|
||||
ContainerWidget* findParentContainerWidget(QWidget* w)
|
||||
{
|
||||
ContainerWidget* cw = 0;
|
||||
|
||||
@@ -10,12 +10,11 @@ ADS_NAMESPACE_BEGIN
|
||||
|
||||
// Static Helper //////////////////////////////////////////////////////
|
||||
|
||||
static QSplitter* newSplitter(Qt::Orientation orientation = Qt::Horizontal)
|
||||
static QSplitter* newSplitter(Qt::Orientation orientation = Qt::Horizontal, QWidget* parent = 0)
|
||||
{
|
||||
QSplitter* s = new QSplitter();
|
||||
QSplitter* s = new QSplitter(orientation, parent);
|
||||
s->setChildrenCollapsible(false);
|
||||
s->setOpaqueResize(false);
|
||||
s->setOrientation(orientation);
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -105,24 +104,24 @@ void ContainerWidget::dropContent(const InternalContentData& data, SectionWidget
|
||||
return;
|
||||
}
|
||||
|
||||
auto targetSectionSplitter = findParentSplitter(targetSection);
|
||||
QSplitter* targetSectionSplitter = findParentSplitter(targetSection);
|
||||
|
||||
// Drop logic based on area.
|
||||
switch (area)
|
||||
{
|
||||
case TopDropArea:
|
||||
{
|
||||
auto sw = new SectionWidget(this);
|
||||
SectionWidget* sw = new SectionWidget(this);
|
||||
sw->addContent(data, true);
|
||||
if (targetSectionSplitter->orientation() == Qt::Vertical)
|
||||
{
|
||||
auto index = targetSectionSplitter->indexOf(targetSection);
|
||||
const int index = targetSectionSplitter->indexOf(targetSection);
|
||||
targetSectionSplitter->insertWidget(index, sw);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto index = targetSectionSplitter->indexOf(targetSection);
|
||||
auto s = newSplitter(Qt::Vertical);
|
||||
const int index = targetSectionSplitter->indexOf(targetSection);
|
||||
QSplitter* s = newSplitter(Qt::Vertical);
|
||||
s->addWidget(sw);
|
||||
s->addWidget(targetSection);
|
||||
targetSectionSplitter->insertWidget(index, s);
|
||||
@@ -131,17 +130,17 @@ void ContainerWidget::dropContent(const InternalContentData& data, SectionWidget
|
||||
}
|
||||
case RightDropArea:
|
||||
{
|
||||
auto sw = new SectionWidget(this);
|
||||
SectionWidget* sw = new SectionWidget(this);
|
||||
sw->addContent(data, true);
|
||||
if (targetSectionSplitter->orientation() == Qt::Horizontal)
|
||||
{
|
||||
auto index = targetSectionSplitter->indexOf(targetSection);
|
||||
const int index = targetSectionSplitter->indexOf(targetSection);
|
||||
targetSectionSplitter->insertWidget(index + 1, sw);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto index = targetSectionSplitter->indexOf(targetSection);
|
||||
auto s = newSplitter(Qt::Horizontal);
|
||||
const int index = targetSectionSplitter->indexOf(targetSection);
|
||||
QSplitter* s = newSplitter(Qt::Horizontal);
|
||||
s->addWidget(targetSection);
|
||||
s->addWidget(sw);
|
||||
targetSectionSplitter->insertWidget(index, s);
|
||||
@@ -199,9 +198,7 @@ void ContainerWidget::addSection(SectionWidget* section)
|
||||
// Create default splitter.
|
||||
if (!_splitter)
|
||||
{
|
||||
_splitter = new QSplitter(_orientation);
|
||||
_splitter->setChildrenCollapsible(false);
|
||||
_splitter->setOpaqueResize(false);
|
||||
_splitter = newSplitter(_orientation);
|
||||
_mainLayout->addWidget(_splitter, 0, 0);
|
||||
}
|
||||
if (_splitter->indexOf(section) != -1)
|
||||
@@ -221,9 +218,7 @@ void ContainerWidget::splitSections(SectionWidget* s1, SectionWidget* s2, Qt::Or
|
||||
if (currentSplitter)
|
||||
{
|
||||
const int index = currentSplitter->indexOf(s1);
|
||||
auto splitter = new QSplitter(orientation, this);
|
||||
splitter->setChildrenCollapsible(false);
|
||||
splitter->setOpaqueResize(false);
|
||||
QSplitter* splitter = newSplitter(orientation, this);
|
||||
splitter->addWidget(s1);
|
||||
splitter->addWidget(s2);
|
||||
currentSplitter->insertWidget(index, splitter);
|
||||
@@ -317,7 +312,9 @@ QMenu* ContainerWidget::createContextMenu() const
|
||||
{
|
||||
FloatingWidget* fw = _floatingWidgets.at(i);
|
||||
SectionContent::RefPtr c = fw->content();
|
||||
m->addAction(QIcon(), QString("Floating %1").arg(c->uid()));
|
||||
QAction* a = m->addAction(QIcon(), QString("Floating %1").arg(c->uid()));
|
||||
a->setCheckable(true);
|
||||
a->setChecked(fw->isVisible());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
#include "ads/FloatingWidget.h"
|
||||
|
||||
#include <QDebug>
|
||||
@@ -20,21 +21,22 @@ FloatingWidget::FloatingWidget(ContainerWidget* container, SectionContent::RefPt
|
||||
_titleWidget(titleWidget),
|
||||
_contentWidget(contentWidget)
|
||||
{
|
||||
auto l = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
auto l = new QBoxLayout(QBoxLayout::TopToBottom, this);
|
||||
l->setContentsMargins(0, 0, 0, 0);
|
||||
l->setSpacing(0);
|
||||
setLayout(l);
|
||||
|
||||
// Title + Controls
|
||||
_titleLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
_titleLayout = new QBoxLayout(QBoxLayout::LeftToRight, this);
|
||||
_titleLayout->addWidget(titleWidget, 1);
|
||||
l->addLayout(_titleLayout, 0);
|
||||
|
||||
auto maximizeButton = new QPushButton();
|
||||
maximizeButton->setObjectName("maximizeButton");
|
||||
maximizeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarMaxButton));
|
||||
maximizeButton->setToolTip(tr("Maximize"));
|
||||
maximizeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
_titleLayout->addWidget(maximizeButton);
|
||||
// auto maximizeButton = new QPushButton();
|
||||
// maximizeButton->setObjectName("maximizeButton");
|
||||
// maximizeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarMaxButton));
|
||||
// maximizeButton->setToolTip(tr("Maximize"));
|
||||
// maximizeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
// _titleLayout->addWidget(maximizeButton);
|
||||
|
||||
auto closeButton = new QPushButton();
|
||||
closeButton->setObjectName("closeButton");
|
||||
@@ -44,8 +46,6 @@ FloatingWidget::FloatingWidget(ContainerWidget* container, SectionContent::RefPt
|
||||
_titleLayout->addWidget(closeButton);
|
||||
QObject::connect(closeButton, &QPushButton::clicked, this, &FloatingWidget::close);
|
||||
|
||||
l->addLayout(_titleLayout, 0);
|
||||
|
||||
// Content
|
||||
l->addWidget(contentWidget, 1);
|
||||
contentWidget->show();
|
||||
|
||||
@@ -24,21 +24,6 @@
|
||||
|
||||
ADS_NAMESPACE_BEGIN
|
||||
|
||||
static void deleteEmptySplitter(ContainerWidget* container)
|
||||
{
|
||||
auto splitters = container->findChildren<QSplitter*>();
|
||||
for (auto i = 0; i < splitters.count(); ++i)
|
||||
{
|
||||
if (splitters[i]->count() == 0 /*&& container->_splitter != splitters[i]*/)
|
||||
{
|
||||
if (splitters[i] == container->_splitter)
|
||||
continue;
|
||||
qDebug() << "Delete empty QSplitter";
|
||||
delete splitters[i];//splitters[i]->deleteLater();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SectionTitleWidget::SectionTitleWidget(SectionContent::RefPtr content, QWidget* parent) :
|
||||
QFrame(parent),
|
||||
_content(content),
|
||||
|
||||
Reference in New Issue
Block a user