#18 adds flags to disable close functionality

This commit is contained in:
mfreiholz 2016-08-04 13:36:55 +02:00
parent 9e27d0b224
commit 70e614b561
7 changed files with 54 additions and 19 deletions

View File

@ -24,6 +24,14 @@ public:
typedef QSharedPointer<SectionContent> RefPtr; typedef QSharedPointer<SectionContent> RefPtr;
typedef QWeakPointer<SectionContent> WeakPtr; typedef QWeakPointer<SectionContent> WeakPtr;
enum Flag
{
None = 0,
Closeable = 1,
AllFlags = Closeable
};
Q_DECLARE_FLAGS(Flags, Flag)
/*! /*!
* Creates new content, associates it to <em>container</em> and takes ownership of * Creates new content, associates it to <em>container</em> and takes ownership of
* <em>title</em>- and <em>content</em>- widgets. * <em>title</em>- and <em>content</em>- widgets.
@ -41,10 +49,12 @@ public:
ContainerWidget* containerWidget() const; ContainerWidget* containerWidget() const;
QWidget* titleWidget() const; QWidget* titleWidget() const;
QWidget* contentWidget() const; QWidget* contentWidget() const;
Flags flags() const;
QString visibleTitle() const; QString visibleTitle() const;
QString title() const; QString title() const;
void setTitle(const QString& title); void setTitle(const QString& title);
void setFlags(const Flags f);
private: private:
const int _uid; const int _uid;
@ -56,6 +66,7 @@ private:
// Optional attributes // Optional attributes
QString _title; QString _title;
Flags _flags;
/* Note: This method could be a problem in static build environment /* Note: This method could be a problem in static build environment
* since it may begin with 0 for every module which uses ADS. * since it may begin with 0 for every module which uses ADS.

View File

@ -76,6 +76,7 @@ private:
QWidget* _tabsContainerWidget; QWidget* _tabsContainerWidget;
QBoxLayout* _tabsLayout; QBoxLayout* _tabsLayout;
QPushButton* _tabsMenuButton; QPushButton* _tabsMenuButton;
QPushButton* _closeButton;
int _tabsLayoutInitCount; // used for calculations on _tabsLayout modification calls. int _tabsLayoutInitCount; // used for calculations on _tabsLayout modification calls.
QStackedLayout *_contentsLayout; QStackedLayout *_contentsLayout;

View File

@ -325,6 +325,7 @@ QMenu* ContainerWidget::createContextMenu() const
a->setProperty("type", "section"); a->setProperty("type", "section");
a->setCheckable(true); a->setCheckable(true);
a->setChecked(true); a->setChecked(true);
a->setEnabled(sc->flags().testFlag(SectionContent::Closeable));
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QObject::connect(a, &QAction::toggled, this, &ContainerWidget::onActionToggleSectionContentVisibility); QObject::connect(a, &QAction::toggled, this, &ContainerWidget::onActionToggleSectionContentVisibility);
#else #else

View File

@ -31,18 +31,21 @@ FloatingWidget::FloatingWidget(ContainerWidget* container, SectionContent::RefPt
l->addLayout(_titleLayout, 0); l->addLayout(_titleLayout, 0);
titleWidget->setActiveTab(false); titleWidget->setActiveTab(false);
QPushButton* closeButton = new QPushButton(); if (sc->flags().testFlag(SectionContent::Closeable))
closeButton->setObjectName("closeButton"); {
closeButton->setFlat(true); QPushButton* closeButton = new QPushButton();
closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton)); closeButton->setObjectName("closeButton");
closeButton->setToolTip(tr("Close")); closeButton->setFlat(true);
closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
_titleLayout->addWidget(closeButton); closeButton->setToolTip(tr("Close"));
closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
_titleLayout->addWidget(closeButton);
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) #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 #else
QObject::connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked())); QObject::connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked()));
#endif #endif
}
// Content // Content
l->addWidget(contentWidget, 1); l->addWidget(contentWidget, 1);

View File

@ -9,7 +9,8 @@
ADS_NAMESPACE_BEGIN ADS_NAMESPACE_BEGIN
SectionContent::SectionContent() : SectionContent::SectionContent() :
_uid(GetNextUid()) _uid(GetNextUid()),
_flags(AllFlags)
{ {
} }
@ -78,6 +79,11 @@ QWidget* SectionContent::contentWidget() const
return _contentWidget; return _contentWidget;
} }
SectionContent::Flags SectionContent::flags() const
{
return _flags;
}
QString SectionContent::visibleTitle() const QString SectionContent::visibleTitle() const
{ {
if (_title.isEmpty()) if (_title.isEmpty())
@ -95,6 +101,11 @@ void SectionContent::setTitle(const QString& title)
_title = title; _title = title;
} }
void SectionContent::setFlags(const Flags f)
{
_flags = f;
}
int SectionContent::GetNextUid() int SectionContent::GetNextUid()
{ {
static int NextUid = 0; static int NextUid = 0;

View File

@ -74,17 +74,17 @@ SectionWidget::SectionWidget(ContainerWidget* parent) :
//QObject::connect(_tabsMenuButton, SIGNAL(clicked()), this, SLOT(onTabsMenuButtonClicked())); //QObject::connect(_tabsMenuButton, SIGNAL(clicked()), this, SLOT(onTabsMenuButtonClicked()));
#endif #endif
QPushButton* closeButton = new QPushButton(); _closeButton = new QPushButton();
closeButton->setObjectName("closeButton"); _closeButton->setObjectName("closeButton");
closeButton->setFlat(true); _closeButton->setFlat(true);
closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton)); _closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
closeButton->setToolTip(tr("Close")); _closeButton->setToolTip(tr("Close"));
closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); _closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
_topLayout->addWidget(closeButton, 0); _topLayout->addWidget(_closeButton, 0);
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 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 #else
QObject::connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked())); QObject::connect(_closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked()));
#endif #endif
_tabsLayoutInitCount = _tabsLayout->count(); _tabsLayoutInitCount = _tabsLayout->count();
@ -349,6 +349,10 @@ void SectionWidget::setCurrentIndex(int index)
{ {
stw->setActiveTab(true); stw->setActiveTab(true);
_tabsScrollArea->ensureWidgetVisible(stw); _tabsScrollArea->ensureWidgetVisible(stw);
if (stw->_content->flags().testFlag(SectionContent::Closeable))
_closeButton->setEnabled(true);
else
_closeButton->setEnabled(false);
} }
else else
stw->setActiveTab(false); stw->setActiveTab(false);

View File

@ -130,6 +130,10 @@ MainWindow::MainWindow(QWidget *parent) :
_container->addSectionContent(createLongTextLabelSC(_container)); _container->addSectionContent(createLongTextLabelSC(_container));
_container->addSectionContent(createLongTextLabelSC(_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) else if (false)
{ {