#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 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
* <em>title</em>- and <em>content</em>- 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.

View File

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

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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)
{