From 70e614b56165d6b12b7899034f5fdedaf1a01e8c Mon Sep 17 00:00:00 2001 From: mfreiholz Date: Thu, 4 Aug 2016 13:36:55 +0200 Subject: [PATCH] #18 adds flags to disable close functionality --- .../include/ads/SectionContent.h | 11 ++++++++++ .../include/ads/SectionWidget.h | 1 + AdvancedDockingSystem/src/ContainerWidget.cpp | 1 + AdvancedDockingSystem/src/FloatingWidget.cpp | 21 ++++++++++-------- AdvancedDockingSystem/src/SectionContent.cpp | 13 ++++++++++- AdvancedDockingSystem/src/SectionWidget.cpp | 22 +++++++++++-------- AdvancedDockingSystemDemo/src/mainwindow.cpp | 4 ++++ 7 files changed, 54 insertions(+), 19 deletions(-) diff --git a/AdvancedDockingSystem/include/ads/SectionContent.h b/AdvancedDockingSystem/include/ads/SectionContent.h index 8ae0bd0..7161792 100644 --- a/AdvancedDockingSystem/include/ads/SectionContent.h +++ b/AdvancedDockingSystem/include/ads/SectionContent.h @@ -24,6 +24,14 @@ public: typedef QSharedPointer RefPtr; typedef QWeakPointer WeakPtr; + enum Flag + { + None = 0, + Closeable = 1, + AllFlags = Closeable + }; + Q_DECLARE_FLAGS(Flags, Flag) + /*! * Creates new content, associates it to container and takes ownership of * title- and content- widgets. @@ -41,10 +49,12 @@ public: ContainerWidget* containerWidget() const; QWidget* titleWidget() const; QWidget* contentWidget() const; + Flags flags() const; QString visibleTitle() const; QString title() const; void setTitle(const QString& title); + void setFlags(const Flags f); private: const int _uid; @@ -56,6 +66,7 @@ private: // Optional attributes QString _title; + Flags _flags; /* Note: This method could be a problem in static build environment * since it may begin with 0 for every module which uses ADS. diff --git a/AdvancedDockingSystem/include/ads/SectionWidget.h b/AdvancedDockingSystem/include/ads/SectionWidget.h index 22ce9b1..2bdecd5 100644 --- a/AdvancedDockingSystem/include/ads/SectionWidget.h +++ b/AdvancedDockingSystem/include/ads/SectionWidget.h @@ -76,6 +76,7 @@ private: QWidget* _tabsContainerWidget; QBoxLayout* _tabsLayout; QPushButton* _tabsMenuButton; + QPushButton* _closeButton; int _tabsLayoutInitCount; // used for calculations on _tabsLayout modification calls. QStackedLayout *_contentsLayout; diff --git a/AdvancedDockingSystem/src/ContainerWidget.cpp b/AdvancedDockingSystem/src/ContainerWidget.cpp index a7172f5..9036c77 100644 --- a/AdvancedDockingSystem/src/ContainerWidget.cpp +++ b/AdvancedDockingSystem/src/ContainerWidget.cpp @@ -325,6 +325,7 @@ QMenu* ContainerWidget::createContextMenu() const a->setProperty("type", "section"); a->setCheckable(true); a->setChecked(true); + a->setEnabled(sc->flags().testFlag(SectionContent::Closeable)); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) QObject::connect(a, &QAction::toggled, this, &ContainerWidget::onActionToggleSectionContentVisibility); #else diff --git a/AdvancedDockingSystem/src/FloatingWidget.cpp b/AdvancedDockingSystem/src/FloatingWidget.cpp index 1652583..d6a39a5 100644 --- a/AdvancedDockingSystem/src/FloatingWidget.cpp +++ b/AdvancedDockingSystem/src/FloatingWidget.cpp @@ -31,18 +31,21 @@ FloatingWidget::FloatingWidget(ContainerWidget* container, SectionContent::RefPt l->addLayout(_titleLayout, 0); titleWidget->setActiveTab(false); - QPushButton* closeButton = new QPushButton(); - closeButton->setObjectName("closeButton"); - closeButton->setFlat(true); - closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton)); - closeButton->setToolTip(tr("Close")); - closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - _titleLayout->addWidget(closeButton); + if (sc->flags().testFlag(SectionContent::Closeable)) + { + QPushButton* closeButton = new QPushButton(); + closeButton->setObjectName("closeButton"); + closeButton->setFlat(true); + closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton)); + closeButton->setToolTip(tr("Close")); + closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + _titleLayout->addWidget(closeButton); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - QObject::connect(closeButton, &QPushButton::clicked, this, &FloatingWidget::onCloseButtonClicked); + QObject::connect(closeButton, &QPushButton::clicked, this, &FloatingWidget::onCloseButtonClicked); #else - QObject::connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked())); + QObject::connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked())); #endif + } // Content l->addWidget(contentWidget, 1); diff --git a/AdvancedDockingSystem/src/SectionContent.cpp b/AdvancedDockingSystem/src/SectionContent.cpp index d68a75d..d7efb12 100644 --- a/AdvancedDockingSystem/src/SectionContent.cpp +++ b/AdvancedDockingSystem/src/SectionContent.cpp @@ -9,7 +9,8 @@ ADS_NAMESPACE_BEGIN SectionContent::SectionContent() : - _uid(GetNextUid()) + _uid(GetNextUid()), + _flags(AllFlags) { } @@ -78,6 +79,11 @@ QWidget* SectionContent::contentWidget() const return _contentWidget; } +SectionContent::Flags SectionContent::flags() const +{ + return _flags; +} + QString SectionContent::visibleTitle() const { if (_title.isEmpty()) @@ -95,6 +101,11 @@ void SectionContent::setTitle(const QString& title) _title = title; } +void SectionContent::setFlags(const Flags f) +{ + _flags = f; +} + int SectionContent::GetNextUid() { static int NextUid = 0; diff --git a/AdvancedDockingSystem/src/SectionWidget.cpp b/AdvancedDockingSystem/src/SectionWidget.cpp index 057570f..270affd 100644 --- a/AdvancedDockingSystem/src/SectionWidget.cpp +++ b/AdvancedDockingSystem/src/SectionWidget.cpp @@ -74,17 +74,17 @@ SectionWidget::SectionWidget(ContainerWidget* parent) : //QObject::connect(_tabsMenuButton, SIGNAL(clicked()), this, SLOT(onTabsMenuButtonClicked())); #endif - QPushButton* closeButton = new QPushButton(); - closeButton->setObjectName("closeButton"); - closeButton->setFlat(true); - closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton)); - closeButton->setToolTip(tr("Close")); - closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - _topLayout->addWidget(closeButton, 0); + _closeButton = new QPushButton(); + _closeButton->setObjectName("closeButton"); + _closeButton->setFlat(true); + _closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton)); + _closeButton->setToolTip(tr("Close")); + _closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + _topLayout->addWidget(_closeButton, 0); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - QObject::connect(closeButton, &QPushButton::clicked, this, &SectionWidget::onCloseButtonClicked); + QObject::connect(_closeButton, &QPushButton::clicked, this, &SectionWidget::onCloseButtonClicked); #else - QObject::connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked())); + QObject::connect(_closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked())); #endif _tabsLayoutInitCount = _tabsLayout->count(); @@ -349,6 +349,10 @@ void SectionWidget::setCurrentIndex(int index) { stw->setActiveTab(true); _tabsScrollArea->ensureWidgetVisible(stw); + if (stw->_content->flags().testFlag(SectionContent::Closeable)) + _closeButton->setEnabled(true); + else + _closeButton->setEnabled(false); } else stw->setActiveTab(false); diff --git a/AdvancedDockingSystemDemo/src/mainwindow.cpp b/AdvancedDockingSystemDemo/src/mainwindow.cpp index a6fd951..dce502c 100644 --- a/AdvancedDockingSystemDemo/src/mainwindow.cpp +++ b/AdvancedDockingSystemDemo/src/mainwindow.cpp @@ -130,6 +130,10 @@ MainWindow::MainWindow(QWidget *parent) : _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) {