Continued refactoring, created private ContainerWidget class
This commit is contained in:
@@ -41,6 +41,10 @@ ContainerWidget::ContainerWidget(QWidget *parent) :
|
||||
QFrame(parent),
|
||||
d(new ContainerWidgetPrivate())
|
||||
{
|
||||
d->LeftBorderDropArea = DropOverlay::createDropIndicatorWidget(LeftBorderDropArea);
|
||||
d->LeftBorderDropArea->setVisible(false);
|
||||
d->LeftBorderDropArea->setWindowTitle("LeftBorderDropArea");
|
||||
|
||||
d->dropOverlay = new DropOverlay(this);
|
||||
d->mainLayout = new QGridLayout();
|
||||
d->mainLayout->setContentsMargins(4, 4, 4, 4);
|
||||
@@ -64,9 +68,9 @@ ContainerWidget::~ContainerWidget()
|
||||
FloatingWidget* fw = d->floatings.takeLast();
|
||||
delete fw;
|
||||
}
|
||||
d->scLookupMapById.clear();
|
||||
d->scLookupMapByName.clear();
|
||||
d->swLookupMapById.clear();
|
||||
d->SectionContentIdMap.clear();
|
||||
d->SectionContentNameMap.clear();
|
||||
d->SectionWidgetIdMap.clear();
|
||||
delete d;
|
||||
}
|
||||
|
||||
@@ -157,7 +161,7 @@ bool ContainerWidget::showSectionContent(const SectionContent::RefPtr& sc)
|
||||
hsi.data.titleWidget->setVisible(true);
|
||||
hsi.data.contentWidget->setVisible(true);
|
||||
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);
|
||||
emit sectionContentVisibilityChanged(sc, true);
|
||||
@@ -410,37 +414,10 @@ bool ContainerWidget::restoreState(const QByteArray& data)
|
||||
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::WeakPtr> wl = d->scLookupMapById.values();
|
||||
QList<SectionContent::WeakPtr> wl = d->SectionContentIdMap.values();
|
||||
QList<SectionContent::RefPtr> sl;
|
||||
for (int i = 0; i < wl.count(); ++i)
|
||||
{
|
||||
@@ -768,7 +745,7 @@ QByteArray ContainerWidget::saveHierarchy() const
|
||||
while (iter.hasNext())
|
||||
{
|
||||
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++;
|
||||
}
|
||||
out << cnt;
|
||||
@@ -776,7 +753,7 @@ QByteArray ContainerWidget::saveHierarchy() const
|
||||
while (iter.hasNext())
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -941,7 +918,7 @@ bool ContainerWidget::restoreHierarchy(const QByteArray& data)
|
||||
QString uname;
|
||||
in >> uname;
|
||||
|
||||
const SectionContent::RefPtr sc = d->scLookupMapByName.value(uname);
|
||||
const SectionContent::RefPtr sc = d->SectionContentNameMap.value(uname);
|
||||
if (!sc)
|
||||
continue;
|
||||
|
||||
@@ -967,7 +944,7 @@ bool ContainerWidget::restoreHierarchy(const QByteArray& data)
|
||||
{
|
||||
QString uname;
|
||||
in >> uname;
|
||||
const SectionContent::RefPtr sc = d->scLookupMapByName.value(uname);
|
||||
const SectionContent::RefPtr sc = d->SectionContentNameMap.value(uname);
|
||||
if (!sc)
|
||||
continue;
|
||||
|
||||
@@ -1006,7 +983,7 @@ bool ContainerWidget::restoreHierarchy(const QByteArray& data)
|
||||
contents.append(contentsToHide.at(i));
|
||||
|
||||
// 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)
|
||||
{
|
||||
const SectionContent::RefPtr sc = allContents.at(i).toStrongRef();
|
||||
@@ -1078,7 +1055,7 @@ bool ContainerWidget::restoreFloatingWidgets(QDataStream& in, int version, QList
|
||||
bool visible = false;
|
||||
in >> visible;
|
||||
|
||||
const SectionContent::RefPtr sc = d->scLookupMapByName.value(uname).toStrongRef();
|
||||
const SectionContent::RefPtr sc = d->SectionContentNameMap.value(uname).toStrongRef();
|
||||
if (!sc)
|
||||
{
|
||||
qWarning() << "Can not find SectionContent:" << uname;
|
||||
@@ -1161,7 +1138,7 @@ bool ContainerWidget::restoreSectionWidgets(QDataStream& in, int version, QSplit
|
||||
int preferredIndex = -1;
|
||||
in >> preferredIndex;
|
||||
|
||||
const SectionContent::RefPtr sc = d->scLookupMapByName.value(uname).toStrongRef();
|
||||
const SectionContent::RefPtr sc = d->SectionContentNameMap.value(uname).toStrongRef();
|
||||
if (!sc)
|
||||
{
|
||||
qWarning() << "Can not find SectionContent:" << uname;
|
||||
@@ -1246,7 +1223,7 @@ void ContainerWidget::onActionToggleSectionContentVisibility(bool visible)
|
||||
if (!a)
|
||||
return;
|
||||
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())
|
||||
{
|
||||
qCritical() << "Can not find content by ID" << uid;
|
||||
@@ -1261,14 +1238,21 @@ void ContainerWidget::onActionToggleSectionContentVisibility(bool visible)
|
||||
|
||||
void ContainerWidget::moveFloatingWidget(const QPoint& TargetPos)
|
||||
{
|
||||
// Mouse is over a SectionWidget
|
||||
SectionWidget* sectionwidget = sectionAt(mapFromGlobal(QCursor::pos()));
|
||||
// Mouse is over the container widget
|
||||
if (rect().contains(mapFromGlobal(QCursor::pos())))
|
||||
{
|
||||
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)
|
||||
{
|
||||
qInfo() << "over sectionWidget";
|
||||
@@ -1305,6 +1289,10 @@ FloatingWidget* ContainerWidget::startFloating(SectionWidget* sectionwidget, int
|
||||
sectionwidget = NULL;
|
||||
}
|
||||
deleteEmptySplitter(this);
|
||||
|
||||
QRect Rect = rect();
|
||||
QPoint Pos(Rect.left(), Rect.center().y());
|
||||
d->LeftBorderDropArea->move(mapToGlobal(Pos));
|
||||
return fw;
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,6 @@ DropOverlay::DropOverlay(QWidget* parent) :
|
||||
QFrame(parent),
|
||||
_allowedAreas(InvalidDropArea),
|
||||
_cross(new DropOverlayCross(this)),
|
||||
_fullAreaDrop(false),
|
||||
_lastLocation(InvalidDropArea)
|
||||
{
|
||||
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::CenterDropArea, createDropIndicatorWidget(CenterDropArea));//createDropWidget(":/img/dock-center.png"));
|
||||
|
||||
m_LeftBorderDropArea = createDropIndicatorWidget(LeftDropArea);
|
||||
m_LeftBorderDropArea->setVisible(false);
|
||||
m_LeftBorderDropArea->setWindowTitle("DropOverlayCross");
|
||||
|
||||
_cross->setAreaWidgets(areaWidgets);
|
||||
_cross->setVisible(false);
|
||||
setVisible(false);
|
||||
@@ -171,10 +166,6 @@ DropAreas DropOverlay::allowedAreas() const
|
||||
return _allowedAreas;
|
||||
}
|
||||
|
||||
void DropOverlay::setAreaWidgets(const QHash<DropArea, QWidget*>& widgets)
|
||||
{
|
||||
_cross->setAreaWidgets(widgets);
|
||||
}
|
||||
|
||||
DropArea DropOverlay::cursorLocation() const
|
||||
{
|
||||
@@ -183,8 +174,7 @@ DropArea DropOverlay::cursorLocation() const
|
||||
|
||||
DropArea DropOverlay::showDropOverlay(QWidget* target)
|
||||
{
|
||||
qInfo() << "DropOverlay::showDropOverlay(QWidget* target)";
|
||||
_fullAreaDrop = true;
|
||||
std::cout << "DropOverlay::showDropOverlay(QWidget* target)" << std::endl;
|
||||
if (_target == target)
|
||||
{
|
||||
qInfo() << "_target == target";
|
||||
@@ -199,9 +189,8 @@ DropArea DropOverlay::showDropOverlay(QWidget* target)
|
||||
return da;
|
||||
}
|
||||
|
||||
hideDropOverlay();
|
||||
qInfo() << "_target != target, hideDropOverlay(), _fullAreaDrop = false";
|
||||
_fullAreaDrop = false;
|
||||
//hideDropOverlay();
|
||||
std::cout << "_target != target, hideDropOverlay(), _fullAreaDrop = false" << std::endl;
|
||||
_target = target;
|
||||
_targetRect = QRect();
|
||||
_lastLocation = InvalidDropArea;
|
||||
@@ -209,9 +198,7 @@ DropArea DropOverlay::showDropOverlay(QWidget* target)
|
||||
// Move it over the target.
|
||||
resize(target->size());
|
||||
move(target->mapToGlobal(target->rect().topLeft()));
|
||||
|
||||
show();
|
||||
|
||||
return cursorLocation();
|
||||
}
|
||||
|
||||
@@ -222,8 +209,7 @@ void DropOverlay::showDropOverlay(QWidget* target, const QRect& targetAreaRect)
|
||||
{
|
||||
return;
|
||||
}
|
||||
hideDropOverlay();
|
||||
_fullAreaDrop = true;
|
||||
//hideDropOverlay();
|
||||
_target = target;
|
||||
_targetRect = targetAreaRect;
|
||||
_lastLocation = InvalidDropArea;
|
||||
@@ -231,9 +217,7 @@ void DropOverlay::showDropOverlay(QWidget* target, const QRect& targetAreaRect)
|
||||
// Move it over the target's area.
|
||||
resize(targetAreaRect.size());
|
||||
move(target->mapToGlobal(QPoint(targetAreaRect.x(), targetAreaRect.y())));
|
||||
|
||||
show();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -241,7 +225,6 @@ void DropOverlay::hideDropOverlay()
|
||||
{
|
||||
qInfo() << "hideDropOverlay() _fullAreaDrop = false";
|
||||
hide();
|
||||
_fullAreaDrop = false;
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
_target.clear();
|
||||
#else
|
||||
@@ -253,9 +236,6 @@ void DropOverlay::hideDropOverlay()
|
||||
|
||||
void DropOverlay::paintEvent(QPaintEvent*)
|
||||
{
|
||||
QPainter p(this);
|
||||
const QColor areaColor = palette().color(QPalette::Active, QPalette::Highlight);
|
||||
|
||||
// Draw rect based on location
|
||||
QRect r = rect();
|
||||
const DropArea da = cursorLocation();
|
||||
@@ -278,23 +258,13 @@ void DropOverlay::paintEvent(QPaintEvent*)
|
||||
r = rect();
|
||||
break;
|
||||
default:
|
||||
r = QRect();
|
||||
return;
|
||||
}
|
||||
if (!r.isNull())
|
||||
{
|
||||
p.fillRect(r, QBrush(areaColor, Qt::Dense4Pattern));
|
||||
p.setBrush(QBrush(areaColor));
|
||||
p.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);
|
||||
QPainter painter(this);
|
||||
QColor Color = palette().color(QPalette::Active, QPalette::Highlight);
|
||||
painter.fillRect(r, QBrush(Color, Qt::Dense4Pattern));
|
||||
painter.setBrush(QBrush(Color));
|
||||
painter.drawRect(r);
|
||||
}
|
||||
|
||||
void DropOverlay::showEvent(QShowEvent*)
|
||||
@@ -302,15 +272,11 @@ void DropOverlay::showEvent(QShowEvent*)
|
||||
_cross->show();
|
||||
QRect ContainerWidgetRect = parentWidget()->rect();
|
||||
QPoint Pos(ContainerWidgetRect.left(), ContainerWidgetRect.center().y());
|
||||
m_LeftBorderDropArea->move(parentWidget()->mapToGlobal(Pos));
|
||||
m_LeftBorderDropArea->show();
|
||||
|
||||
}
|
||||
|
||||
void DropOverlay::hideEvent(QHideEvent*)
|
||||
{
|
||||
_cross->hide();
|
||||
m_LeftBorderDropArea->hide();
|
||||
}
|
||||
|
||||
void DropOverlay::resizeEvent(QResizeEvent* e)
|
||||
|
||||
@@ -16,8 +16,8 @@ SectionContent::SectionContent() :
|
||||
|
||||
SectionContent::RefPtr SectionContent::newSectionContent(const QString& uniqueName, ContainerWidget* container, QWidget* title, QWidget* content)
|
||||
{
|
||||
auto SectionContentNameMap = container->d->scLookupMapByName;
|
||||
auto SectionContentIdMap = container->d->scLookupMapById;
|
||||
auto SectionContentNameMap = container->d->SectionContentNameMap;
|
||||
auto SectionContentIdMap = container->d->SectionContentIdMap;
|
||||
|
||||
if (uniqueName.isEmpty())
|
||||
{
|
||||
@@ -48,8 +48,8 @@ SectionContent::RefPtr SectionContent::newSectionContent(const QString& uniqueNa
|
||||
|
||||
SectionContent::~SectionContent()
|
||||
{
|
||||
auto SectionContentNameMap = _containerWidget->d->scLookupMapByName;
|
||||
auto SectionContentIdMap = _containerWidget->d->scLookupMapById;
|
||||
auto SectionContentNameMap = _containerWidget->d->SectionContentNameMap;
|
||||
auto SectionContentIdMap = _containerWidget->d->SectionContentIdMap;
|
||||
|
||||
if (_containerWidget)
|
||||
{
|
||||
|
||||
@@ -97,7 +97,7 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
|
||||
// Mouse is over a outer-edge drop area
|
||||
else
|
||||
{
|
||||
DropArea dropArea = ADS_NS::InvalidDropArea;
|
||||
/*DropArea dropArea = ADS_NS::InvalidDropArea;
|
||||
if (cw->outerTopDropRect().contains(cw->mapFromGlobal(ev->globalPos())))
|
||||
dropArea = ADS_NS::TopDropArea;
|
||||
if (cw->outerRightDropRect().contains(cw->mapFromGlobal(ev->globalPos())))
|
||||
@@ -114,7 +114,7 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
|
||||
m_FloatingWidget->deleteLater();
|
||||
m_FloatingWidget.clear();
|
||||
cw->dropContent(data, NULL, dropArea, true);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
// End of tab moving, change order now
|
||||
|
||||
@@ -93,14 +93,14 @@ SectionWidget::SectionWidget(ContainerWidget* parent) :
|
||||
_contentsLayout->setSpacing(0);
|
||||
l->addLayout(_contentsLayout, 1);
|
||||
|
||||
_container->d->swLookupMapById.insert(_uid, this);
|
||||
_container->d->SectionWidgetIdMap.insert(_uid, this);
|
||||
}
|
||||
|
||||
SectionWidget::~SectionWidget()
|
||||
{
|
||||
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...
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user