2016-02-03 15:01:26 +08:00
|
|
|
|
2016-02-02 22:01:48 +08:00
|
|
|
#include "ads/FloatingWidget.h"
|
2015-12-09 19:21:38 +08:00
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSizePolicy>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QStyle>
|
|
|
|
|
2016-02-02 22:01:48 +08:00
|
|
|
#include "ads/ContainerWidget.h"
|
|
|
|
#include "ads/SectionTitleWidget.h"
|
|
|
|
#include "ads/SectionContentWidget.h"
|
2015-12-09 19:21:38 +08:00
|
|
|
|
|
|
|
ADS_NAMESPACE_BEGIN
|
|
|
|
|
2016-02-02 20:49:10 +08:00
|
|
|
FloatingWidget::FloatingWidget(ContainerWidget* container, SectionContent::RefPtr sc, SectionTitleWidget* titleWidget, SectionContentWidget* contentWidget, QWidget* parent) :
|
2015-12-09 19:21:38 +08:00
|
|
|
QWidget(parent, Qt::CustomizeWindowHint | Qt::Tool),
|
2016-02-02 20:49:10 +08:00
|
|
|
_container(container),
|
2015-12-09 19:21:38 +08:00
|
|
|
_content(sc),
|
|
|
|
_titleWidget(titleWidget),
|
|
|
|
_contentWidget(contentWidget)
|
|
|
|
{
|
2016-02-03 15:01:26 +08:00
|
|
|
auto l = new QBoxLayout(QBoxLayout::TopToBottom, this);
|
2015-12-09 19:21:38 +08:00
|
|
|
l->setContentsMargins(0, 0, 0, 0);
|
|
|
|
l->setSpacing(0);
|
|
|
|
setLayout(l);
|
|
|
|
|
|
|
|
// Title + Controls
|
2016-02-03 15:01:26 +08:00
|
|
|
_titleLayout = new QBoxLayout(QBoxLayout::LeftToRight, this);
|
2015-12-09 19:21:38 +08:00
|
|
|
_titleLayout->addWidget(titleWidget, 1);
|
2016-02-03 15:01:26 +08:00
|
|
|
l->addLayout(_titleLayout, 0);
|
2015-12-09 19:21:38 +08:00
|
|
|
|
2016-02-03 15:01:26 +08:00
|
|
|
// auto maximizeButton = new QPushButton();
|
|
|
|
// maximizeButton->setObjectName("maximizeButton");
|
|
|
|
// maximizeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarMaxButton));
|
|
|
|
// maximizeButton->setToolTip(tr("Maximize"));
|
|
|
|
// maximizeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
// _titleLayout->addWidget(maximizeButton);
|
2015-12-09 19:21:38 +08:00
|
|
|
|
|
|
|
auto closeButton = new QPushButton();
|
|
|
|
closeButton->setObjectName("closeButton");
|
|
|
|
closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
|
|
|
|
closeButton->setToolTip(tr("Close"));
|
|
|
|
closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
_titleLayout->addWidget(closeButton);
|
|
|
|
QObject::connect(closeButton, &QPushButton::clicked, this, &FloatingWidget::close);
|
|
|
|
|
|
|
|
// Content
|
|
|
|
l->addWidget(contentWidget, 1);
|
|
|
|
contentWidget->show();
|
2016-02-02 20:49:10 +08:00
|
|
|
|
|
|
|
_container->_floatingWidgets.append(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
FloatingWidget::~FloatingWidget()
|
|
|
|
{
|
|
|
|
qDebug() << Q_FUNC_INFO;
|
|
|
|
_container->_floatingWidgets.removeAll(this);
|
2015-12-09 19:21:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
InternalContentData FloatingWidget::takeContent()
|
|
|
|
{
|
|
|
|
InternalContentData data;
|
|
|
|
data.content = _content;
|
|
|
|
data.titleWidget = _titleWidget;
|
|
|
|
data.contentWidget = _contentWidget;
|
|
|
|
|
|
|
|
_titleLayout->removeWidget(_titleWidget);
|
|
|
|
_titleWidget = NULL;
|
|
|
|
|
|
|
|
layout()->removeWidget(_contentWidget);
|
|
|
|
_contentWidget = NULL;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FloatingWidget::closeEvent(QCloseEvent*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ADS_NAMESPACE_END
|