Created CFloatingTitleWidget
This commit is contained in:
@@ -6,19 +6,145 @@
|
||||
#include <QSizePolicy>
|
||||
#include <QMouseEvent>
|
||||
#include <QStyle>
|
||||
#include <QLabel>
|
||||
|
||||
#include "ads/SectionTitleWidget.h"
|
||||
#include "ads/SectionContentWidget.h"
|
||||
#include "ads/Internal.h"
|
||||
#include "ads/SectionWidget.h"
|
||||
#include "ads/ContainerWidget.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
ADS_NAMESPACE_BEGIN
|
||||
|
||||
unsigned int FloatingWidget::zOrderCounter = 0;
|
||||
|
||||
|
||||
|
||||
CFloatingTitleWidget::CFloatingTitleWidget(SectionContent::Flags Flags, FloatingWidget* Parent)
|
||||
: QFrame(Parent)
|
||||
{
|
||||
auto Layout = new QHBoxLayout();
|
||||
QLabel* Label = new QLabel(this);
|
||||
Label->setText("Floating Widget");
|
||||
Label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||
Label->setAlignment(Qt::AlignLeft);
|
||||
Layout->addWidget(Label, 1, Qt::AlignLeft | Qt::AlignVCenter);
|
||||
setLayout(Layout);
|
||||
|
||||
if (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);
|
||||
Layout->addWidget(closeButton);
|
||||
connect(closeButton, SIGNAL(clicked(bool)), this, SIGNAL(closeButtonClicked()));
|
||||
Layout->setContentsMargins(6, 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Layout->setContentsMargins(6, 6, 6, 6);
|
||||
}
|
||||
}
|
||||
|
||||
FloatingWidget* CFloatingTitleWidget::floatingWidget() const
|
||||
{
|
||||
return dynamic_cast<FloatingWidget*>(parentWidget());
|
||||
}
|
||||
|
||||
MainContainerWidget* CFloatingTitleWidget::mainContainerWidget() const
|
||||
{
|
||||
return floatingWidget()->mainContainerWidget();
|
||||
}
|
||||
|
||||
|
||||
void CFloatingTitleWidget::mousePressEvent(QMouseEvent* ev)
|
||||
{
|
||||
if (ev->button() == Qt::LeftButton)
|
||||
{
|
||||
ev->accept();
|
||||
//m_DragStartPosition = ev->pos();
|
||||
return;
|
||||
}
|
||||
QFrame::mousePressEvent(ev);
|
||||
}
|
||||
|
||||
|
||||
void CFloatingTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CFloatingTitleWidget::mouseMoveEvent(QMouseEvent* ev)
|
||||
{
|
||||
if (!(ev->buttons() & Qt::LeftButton))
|
||||
{
|
||||
QFrame::mouseMoveEvent(ev);
|
||||
return;
|
||||
}
|
||||
|
||||
QPoint Pos = QCursor::pos();
|
||||
// TODO make a member with the main container widget and assign it on
|
||||
// creation
|
||||
MainContainerWidget* MainContainerWidget = mainContainerWidget();
|
||||
auto Containers = MainContainerWidget->m_Containers;
|
||||
CContainerWidget* TopContainer = nullptr;
|
||||
for (auto ContainerWidget : Containers)
|
||||
{
|
||||
if (!ContainerWidget->isVisible())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (floatingWidget()->containerWidget() == ContainerWidget)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
QPoint MappedPos = ContainerWidget->mapFromGlobal(Pos);
|
||||
if (ContainerWidget->rect().contains(MappedPos))
|
||||
{
|
||||
std::cout << "Container " << ContainerWidget << " contains maousepos" << std::endl;
|
||||
if (!TopContainer || ContainerWidget->isInFrontOf(TopContainer))
|
||||
{
|
||||
TopContainer = ContainerWidget;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (TopContainer)
|
||||
{
|
||||
MainContainerWidget->dropOverlay()->showDropOverlay(TopContainer);
|
||||
MainContainerWidget->dropOverlay()->raise();
|
||||
}
|
||||
else
|
||||
{
|
||||
MainContainerWidget->dropOverlay()->hideDropOverlay();
|
||||
}
|
||||
|
||||
ev->accept();
|
||||
moveFloatingWidget(ev, MainContainerWidget);
|
||||
}
|
||||
|
||||
|
||||
void CFloatingTitleWidget::moveFloatingWidget(QMouseEvent* ev, MainContainerWidget* cw)
|
||||
{
|
||||
const QPoint moveToPos = ev->globalPos() - (m_DragStartPosition + QPoint(ADS_WINDOW_FRAME_BORDER_WIDTH, ADS_WINDOW_FRAME_BORDER_WIDTH));
|
||||
floatingWidget()->move(moveToPos);
|
||||
// cw->moveFloatingWidget(moveToPos);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
FloatingWidget::FloatingWidget(MainContainerWidget* container, SectionContent::RefPtr sc, SectionTitleWidget* titleWidget, SectionContentWidget* contentWidget, QWidget* parent) :
|
||||
QWidget(parent, Qt::CustomizeWindowHint | Qt::Tool),
|
||||
_container(container),
|
||||
m_MainContainerWidget(container),
|
||||
_content(sc),
|
||||
_titleWidget(titleWidget),
|
||||
_contentWidget(contentWidget)
|
||||
@@ -29,24 +155,21 @@ FloatingWidget::FloatingWidget(MainContainerWidget* container, SectionContent::R
|
||||
setLayout(l);
|
||||
|
||||
// Title + Controls
|
||||
_titleLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
_titleLayout->addWidget(titleWidget, 1);
|
||||
l->addLayout(_titleLayout, 0);
|
||||
titleWidget->setActiveTab(false);
|
||||
CFloatingTitleWidget* TitleBar = new CFloatingTitleWidget(sc->flags(), this);
|
||||
l->insertWidget(0, TitleBar);
|
||||
connect(TitleBar, SIGNAL(closeButtonClicked()), this, SLOT(onCloseButtonClicked()));
|
||||
|
||||
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);
|
||||
connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked()));
|
||||
}
|
||||
l->addWidget(contentWidget, 1);
|
||||
contentWidget->show();
|
||||
//l->addWidget(contentWidget, 1);
|
||||
//contentWidget->show();
|
||||
|
||||
m_ContainerWidget = new CContainerWidget(m_MainContainerWidget, this);
|
||||
l->addWidget(m_ContainerWidget, 1);
|
||||
InternalContentData data;
|
||||
data.content = sc;
|
||||
data.contentWidget = contentWidget;
|
||||
data.titleWidget = titleWidget;
|
||||
m_ContainerWidget->dropContent(data, nullptr, CenterDropArea);
|
||||
m_ContainerWidget->show();
|
||||
|
||||
m_zOrderIndex = ++zOrderCounter;
|
||||
}
|
||||
@@ -67,7 +190,7 @@ FloatingWidget::FloatingWidget(SectionWidget* sectionWidget)
|
||||
FloatingWidget::~FloatingWidget()
|
||||
{
|
||||
// maybe we can implement this this via connection to destroyed signal
|
||||
_container->m_Floatings.removeAll(this); // Note: I don't like this here, but we have to remove it from list...
|
||||
m_MainContainerWidget->m_Floatings.removeAll(this); // Note: I don't like this here, but we have to remove it from list...
|
||||
}
|
||||
|
||||
bool FloatingWidget::takeContent(InternalContentData& data)
|
||||
@@ -76,12 +199,12 @@ bool FloatingWidget::takeContent(InternalContentData& data)
|
||||
data.titleWidget = _titleWidget;
|
||||
data.contentWidget = _contentWidget;
|
||||
|
||||
_titleLayout->removeWidget(_titleWidget);
|
||||
_titleWidget->setParent(_container);
|
||||
//_titleLayout->removeWidget(_titleWidget);
|
||||
_titleWidget->setParent(m_MainContainerWidget);
|
||||
_titleWidget = NULL;
|
||||
|
||||
layout()->removeWidget(_contentWidget);
|
||||
_contentWidget->setParent(_container);
|
||||
_contentWidget->setParent(m_MainContainerWidget);
|
||||
_contentWidget = NULL;
|
||||
|
||||
return true;
|
||||
@@ -89,7 +212,7 @@ bool FloatingWidget::takeContent(InternalContentData& data)
|
||||
|
||||
void FloatingWidget::onCloseButtonClicked()
|
||||
{
|
||||
_container->hideSectionContent(_content);
|
||||
m_MainContainerWidget->hideSectionContent(_content);
|
||||
}
|
||||
|
||||
bool FloatingWidget::isDraggingActive() const
|
||||
|
||||
Reference in New Issue
Block a user