Skip to content

Commit 70e614b

Browse files
committed
#18 adds flags to disable close functionality
1 parent 9e27d0b commit 70e614b

File tree

7 files changed

+54
-19
lines changed

7 files changed

+54
-19
lines changed

AdvancedDockingSystem/include/ads/SectionContent.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ class ADS_EXPORT_API SectionContent
2424
typedef QSharedPointer<SectionContent> RefPtr;
2525
typedef QWeakPointer<SectionContent> WeakPtr;
2626

27+
enum Flag
28+
{
29+
None = 0,
30+
Closeable = 1,
31+
AllFlags = Closeable
32+
};
33+
Q_DECLARE_FLAGS(Flags, Flag)
34+
2735
/*!
2836
* Creates new content, associates it to <em>container</em> and takes ownership of
2937
* <em>title</em>- and <em>content</em>- widgets.
@@ -41,10 +49,12 @@ class ADS_EXPORT_API SectionContent
4149
ContainerWidget* containerWidget() const;
4250
QWidget* titleWidget() const;
4351
QWidget* contentWidget() const;
52+
Flags flags() const;
4453

4554
QString visibleTitle() const;
4655
QString title() const;
4756
void setTitle(const QString& title);
57+
void setFlags(const Flags f);
4858

4959
private:
5060
const int _uid;
@@ -56,6 +66,7 @@ class ADS_EXPORT_API SectionContent
5666

5767
// Optional attributes
5868
QString _title;
69+
Flags _flags;
5970

6071
/* Note: This method could be a problem in static build environment
6172
* since it may begin with 0 for every module which uses ADS.

AdvancedDockingSystem/include/ads/SectionWidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ private slots:
7676
QWidget* _tabsContainerWidget;
7777
QBoxLayout* _tabsLayout;
7878
QPushButton* _tabsMenuButton;
79+
QPushButton* _closeButton;
7980
int _tabsLayoutInitCount; // used for calculations on _tabsLayout modification calls.
8081

8182
QStackedLayout *_contentsLayout;

AdvancedDockingSystem/src/ContainerWidget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ QMenu* ContainerWidget::createContextMenu() const
325325
a->setProperty("type", "section");
326326
a->setCheckable(true);
327327
a->setChecked(true);
328+
a->setEnabled(sc->flags().testFlag(SectionContent::Closeable));
328329
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
329330
QObject::connect(a, &QAction::toggled, this, &ContainerWidget::onActionToggleSectionContentVisibility);
330331
#else

AdvancedDockingSystem/src/FloatingWidget.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,21 @@ FloatingWidget::FloatingWidget(ContainerWidget* container, SectionContent::RefPt
3131
l->addLayout(_titleLayout, 0);
3232
titleWidget->setActiveTab(false);
3333

34-
QPushButton* closeButton = new QPushButton();
35-
closeButton->setObjectName("closeButton");
36-
closeButton->setFlat(true);
37-
closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
38-
closeButton->setToolTip(tr("Close"));
39-
closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
40-
_titleLayout->addWidget(closeButton);
34+
if (sc->flags().testFlag(SectionContent::Closeable))
35+
{
36+
QPushButton* closeButton = new QPushButton();
37+
closeButton->setObjectName("closeButton");
38+
closeButton->setFlat(true);
39+
closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
40+
closeButton->setToolTip(tr("Close"));
41+
closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
42+
_titleLayout->addWidget(closeButton);
4143
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
42-
QObject::connect(closeButton, &QPushButton::clicked, this, &FloatingWidget::onCloseButtonClicked);
44+
QObject::connect(closeButton, &QPushButton::clicked, this, &FloatingWidget::onCloseButtonClicked);
4345
#else
44-
QObject::connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked()));
46+
QObject::connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked()));
4547
#endif
48+
}
4649

4750
// Content
4851
l->addWidget(contentWidget, 1);

AdvancedDockingSystem/src/SectionContent.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
ADS_NAMESPACE_BEGIN
1010

1111
SectionContent::SectionContent() :
12-
_uid(GetNextUid())
12+
_uid(GetNextUid()),
13+
_flags(AllFlags)
1314
{
1415
}
1516

@@ -78,6 +79,11 @@ QWidget* SectionContent::contentWidget() const
7879
return _contentWidget;
7980
}
8081

82+
SectionContent::Flags SectionContent::flags() const
83+
{
84+
return _flags;
85+
}
86+
8187
QString SectionContent::visibleTitle() const
8288
{
8389
if (_title.isEmpty())
@@ -95,6 +101,11 @@ void SectionContent::setTitle(const QString& title)
95101
_title = title;
96102
}
97103

104+
void SectionContent::setFlags(const Flags f)
105+
{
106+
_flags = f;
107+
}
108+
98109
int SectionContent::GetNextUid()
99110
{
100111
static int NextUid = 0;

AdvancedDockingSystem/src/SectionWidget.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ SectionWidget::SectionWidget(ContainerWidget* parent) :
7474
//QObject::connect(_tabsMenuButton, SIGNAL(clicked()), this, SLOT(onTabsMenuButtonClicked()));
7575
#endif
7676

77-
QPushButton* closeButton = new QPushButton();
78-
closeButton->setObjectName("closeButton");
79-
closeButton->setFlat(true);
80-
closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
81-
closeButton->setToolTip(tr("Close"));
82-
closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
83-
_topLayout->addWidget(closeButton, 0);
77+
_closeButton = new QPushButton();
78+
_closeButton->setObjectName("closeButton");
79+
_closeButton->setFlat(true);
80+
_closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
81+
_closeButton->setToolTip(tr("Close"));
82+
_closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
83+
_topLayout->addWidget(_closeButton, 0);
8484
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
85-
QObject::connect(closeButton, &QPushButton::clicked, this, &SectionWidget::onCloseButtonClicked);
85+
QObject::connect(_closeButton, &QPushButton::clicked, this, &SectionWidget::onCloseButtonClicked);
8686
#else
87-
QObject::connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked()));
87+
QObject::connect(_closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked()));
8888
#endif
8989

9090
_tabsLayoutInitCount = _tabsLayout->count();
@@ -349,6 +349,10 @@ void SectionWidget::setCurrentIndex(int index)
349349
{
350350
stw->setActiveTab(true);
351351
_tabsScrollArea->ensureWidgetVisible(stw);
352+
if (stw->_content->flags().testFlag(SectionContent::Closeable))
353+
_closeButton->setEnabled(true);
354+
else
355+
_closeButton->setEnabled(false);
352356
}
353357
else
354358
stw->setActiveTab(false);

AdvancedDockingSystemDemo/src/mainwindow.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ MainWindow::MainWindow(QWidget *parent) :
130130
_container->addSectionContent(createLongTextLabelSC(_container));
131131
_container->addSectionContent(createLongTextLabelSC(_container));
132132
_container->addSectionContent(createLongTextLabelSC(_container));
133+
134+
ADS_NS::SectionContent::RefPtr sc = createLongTextLabelSC(cw);
135+
sc->setFlags(ADS_NS::SectionContent::AllFlags ^ ADS_NS::SectionContent::Closeable);
136+
_container->addSectionContent(sc);
133137
}
134138
else if (false)
135139
{

0 commit comments

Comments
 (0)