From 3fd20fad16a6706812da43906d036484e7d9bde0 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Sat, 21 Jan 2017 22:22:20 +0100 Subject: [PATCH] Continued refactoring, created private ContainerWidget class --- .../include/ads/ContainerWidget.h | 32 +------ .../include/ads/ContainerWidget_p.h | 57 +++++++++++ .../include/ads/DropOverlay.h | 6 -- AdvancedDockingSystem/src/ContainerWidget.cpp | 74 ++++++-------- AdvancedDockingSystem/src/DropOverlay.cpp | 54 ++--------- AdvancedDockingSystem/src/SectionContent.cpp | 8 +- .../src/SectionTitleWidget.cpp | 4 +- AdvancedDockingSystem/src/SectionWidget.cpp | 4 +- AdvancedDockingSystemDemo/src/mainwindow.cpp | 96 ++++++++----------- AdvancedDockingSystemDemo/src/mainwindow.h | 1 + 10 files changed, 148 insertions(+), 188 deletions(-) create mode 100644 AdvancedDockingSystem/include/ads/ContainerWidget_p.h diff --git a/AdvancedDockingSystem/include/ads/ContainerWidget.h b/AdvancedDockingSystem/include/ads/ContainerWidget.h index d9b60c2..c73e124 100644 --- a/AdvancedDockingSystem/include/ads/ContainerWidget.h +++ b/AdvancedDockingSystem/include/ads/ContainerWidget.h @@ -15,36 +15,13 @@ class QGridLayout; #include "ads/SectionContent.h" #include "ads/FloatingWidget.h" #include "ads/Serialization.h" +#include "ContainerWidget_p.h" ADS_NAMESPACE_BEGIN class SectionWidget; class DropOverlay; class InternalContentData; -struct ContainerWidgetPrivate -{ - // Elements inside container. - QList sections; - QList floatings; - QHash hiddenSectionContents; - - - // Helper lookup maps, restricted to this container. - QHash scLookupMapById; - QHash scLookupMapByName; - QHash swLookupMapById; - - - // Layout stuff - QGridLayout* mainLayout = nullptr;; - Qt::Orientation orientation = Qt::Horizontal; - QPointer splitter; // $mfreiholz: I'd like to remove this variable entirely, - // because it changes during user interaction anyway. - - // Drop overlay stuff. - QPointer dropOverlay; -}; - /*! * ContainerWidget is the main container to provide the docking @@ -130,13 +107,6 @@ public: // Advanced Public API // 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 * \return List of known SectionContent for this ContainerWidget. diff --git a/AdvancedDockingSystem/include/ads/ContainerWidget_p.h b/AdvancedDockingSystem/include/ads/ContainerWidget_p.h new file mode 100644 index 0000000..21b0eeb --- /dev/null +++ b/AdvancedDockingSystem/include/ads/ContainerWidget_p.h @@ -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 +#include +#include +#include +#include + +#include "ads/DropOverlay.h" + +namespace ads +{ + +class SectionWidget; +class FloatingWidget; +class HiddenSectionItem; + + +struct ContainerWidgetPrivate +{ + // Elements inside container. + QList sections; + QList floatings; + QHash hiddenSectionContents; + + + // Helper lookup maps, restricted to this container. + QHash SectionContentIdMap; + QHash SectionContentNameMap; + QHash SectionWidgetIdMap; + + + // Layout stuff + QGridLayout* mainLayout = nullptr; + Qt::Orientation orientation = Qt::Horizontal; + QPointer splitter; // $mfreiholz: I'd like to remove this variable entirely, + // because it changes during user interaction anyway. + + // Drop overlay stuff. + QPointer dropOverlay; + QWidget* LeftBorderDropArea; +}; +} // namespace ads + +//--------------------------------------------------------------------------- +#endif // ContainerWidget_pH diff --git a/AdvancedDockingSystem/include/ads/DropOverlay.h b/AdvancedDockingSystem/include/ads/DropOverlay.h index 0bb8ae5..3240231 100644 --- a/AdvancedDockingSystem/include/ads/DropOverlay.h +++ b/AdvancedDockingSystem/include/ads/DropOverlay.h @@ -27,9 +27,6 @@ public: void setAllowedAreas(DropAreas areas); DropAreas allowedAreas() const; - - void setAreaWidgets(const QHash& widgets); - DropArea cursorLocation() const; DropArea showDropOverlay(QWidget* target); @@ -51,12 +48,9 @@ protected: private: DropAreas _allowedAreas; DropOverlayCross* _cross; - - bool _fullAreaDrop; QPointer _target; QRect _targetRect; DropArea _lastLocation; - QWidget* m_LeftBorderDropArea; }; /*! diff --git a/AdvancedDockingSystem/src/ContainerWidget.cpp b/AdvancedDockingSystem/src/ContainerWidget.cpp index ad5bfe8..30aaa5b 100644 --- a/AdvancedDockingSystem/src/ContainerWidget.cpp +++ b/AdvancedDockingSystem/src/ContainerWidget.cpp @@ -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 ContainerWidget::contents() const { - QList wl = d->scLookupMapById.values(); + QList wl = d->SectionContentIdMap.values(); QList 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 allContents = d->scLookupMapById.values(); + const QList 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; } diff --git a/AdvancedDockingSystem/src/DropOverlay.cpp b/AdvancedDockingSystem/src/DropOverlay.cpp index 0222f9c..48dc19f 100644 --- a/AdvancedDockingSystem/src/DropOverlay.cpp +++ b/AdvancedDockingSystem/src/DropOverlay.cpp @@ -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& 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) diff --git a/AdvancedDockingSystem/src/SectionContent.cpp b/AdvancedDockingSystem/src/SectionContent.cpp index 95024aa..dbc8625 100644 --- a/AdvancedDockingSystem/src/SectionContent.cpp +++ b/AdvancedDockingSystem/src/SectionContent.cpp @@ -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) { diff --git a/AdvancedDockingSystem/src/SectionTitleWidget.cpp b/AdvancedDockingSystem/src/SectionTitleWidget.cpp index 025cb96..3e1bae3 100644 --- a/AdvancedDockingSystem/src/SectionTitleWidget.cpp +++ b/AdvancedDockingSystem/src/SectionTitleWidget.cpp @@ -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 diff --git a/AdvancedDockingSystem/src/SectionWidget.cpp b/AdvancedDockingSystem/src/SectionWidget.cpp index a7dd643..a64b02f 100644 --- a/AdvancedDockingSystem/src/SectionWidget.cpp +++ b/AdvancedDockingSystem/src/SectionWidget.cpp @@ -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... } diff --git a/AdvancedDockingSystemDemo/src/mainwindow.cpp b/AdvancedDockingSystemDemo/src/mainwindow.cpp index a0de4d4..bd39410 100644 --- a/AdvancedDockingSystemDemo/src/mainwindow.cpp +++ b/AdvancedDockingSystemDemo/src/mainwindow.cpp @@ -90,66 +90,14 @@ MainWindow::MainWindow(QWidget *parent) : ui->setupUi(this); // Setup actions. - QObject::connect(ui->actionContentList, SIGNAL(triggered()), this, SLOT(showSectionContentListDialog())); + connect(ui->actionContentList, SIGNAL(triggered()), this, SLOT(showSectionContentListDialog())); // ADS - Create main container (ContainerWidget). _container = new ADS_NS::ContainerWidget(); -#if QT_VERSION >= 0x050000 - QObject::connect(_container, &ADS_NS::ContainerWidget::activeTabChanged, this, &MainWindow::onActiveTabChanged); - 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 + connect(_container, SIGNAL(activeTabChanged(const SectionContent::RefPtr&, bool)), this, SLOT(onActiveTabChanged(const SectionContent::RefPtr&, bool))); + connect(_container, SIGNAL(sectionContentVisibilityChanged(SectionContent::RefPtr,bool)), this, SLOT(onSectionContentVisibilityChanged(SectionContent::RefPtr,bool))); setCentralWidget(_container); - - // Optional: Use custom drop area widgets. - if (false) - { - QHash 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); - } - + createContent(); // Default window geometry resize(800, 600); restoreGeometry(loadDataHelper("MainWindow")); @@ -163,6 +111,42 @@ MainWindow::~MainWindow() 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() { SectionContentListWidget::Values v; diff --git a/AdvancedDockingSystemDemo/src/mainwindow.h b/AdvancedDockingSystemDemo/src/mainwindow.h index 3548e84..4891481 100644 --- a/AdvancedDockingSystemDemo/src/mainwindow.h +++ b/AdvancedDockingSystemDemo/src/mainwindow.h @@ -38,6 +38,7 @@ protected: private: Ui::MainWindow *ui; ADS_NS::ContainerWidget* _container; + void createContent(); }; #endif // MAINWINDOW_H