Fixed movement of witget on start of floating

This commit is contained in:
Uwe Kindler 2017-02-11 22:05:23 +01:00
parent 2bf1a51627
commit df97d17844
10 changed files with 223 additions and 217 deletions

View File

@ -43,7 +43,6 @@ public:
explicit CContainerWidget(MainContainerWidget* MainContainerWidget, QWidget *parent = nullptr); explicit CContainerWidget(MainContainerWidget* MainContainerWidget, QWidget *parent = nullptr);
virtual ~CContainerWidget(); virtual ~CContainerWidget();
void moveFloatingWidget(const QPoint& TargetPos);
/** /**
* Returns the current zOrderIndex * Returns the current zOrderIndex
*/ */
@ -52,7 +51,7 @@ public:
void dropFloatingWidget(FloatingWidget* FloatingWidget, void dropFloatingWidget(FloatingWidget* FloatingWidget,
const QPoint& TargetPos); const QPoint& TargetPos);
SectionWidget* sectionWidgetAt(const QPoint& pos) const; SectionWidget* sectionWidgetAt(const QPoint& GlobalPos) const;
/** /**
* This function returns true if this container widgets z order index is * This function returns true if this container widgets z order index is
@ -70,7 +69,18 @@ public:
*/ */
SectionWidget* addSectionContent(const SectionContent::RefPtr& sc, SectionWidget* sw = NULL, DropArea area = CenterDropArea); SectionWidget* addSectionContent(const SectionContent::RefPtr& sc, SectionWidget* sw = NULL, DropArea area = CenterDropArea);
void dumpLayout();
signals:
/*!
* Emits whenever the "isActiveTab" state of a SectionContent changes.
* Whenever the users sets another tab as active, this signal gets invoked
* for the old tab and the new active tab (the order is unspecified).
*/
void activeTabChanged(const SectionContent::RefPtr& sc, bool active);
protected: protected:
void dropIntoContainer(FloatingWidget* FloatingWidget, DropArea area);
virtual bool event(QEvent *e) override; virtual bool event(QEvent *e) override;
SectionWidget* newSectionWidget(); SectionWidget* newSectionWidget();
void addSectionWidget(SectionWidget* section); void addSectionWidget(SectionWidget* section);
@ -88,6 +98,9 @@ protected:
MainContainerWidget* m_MainContainerWidget = 0; MainContainerWidget* m_MainContainerWidget = 0;
unsigned int m_zOrderIndex = 0; unsigned int m_zOrderIndex = 0;
static unsigned int zOrderCounter; static unsigned int zOrderCounter;
private slots:
void onActiveTabChanged();
}; };
} // namespace ads } // namespace ads

View File

@ -76,6 +76,8 @@ public:
public://private: public://private:
bool takeContent(InternalContentData& data); bool takeContent(InternalContentData& data);
void startFloating(const QPoint& Pos);
protected: protected:
virtual void changeEvent(QEvent *event) override; virtual void changeEvent(QEvent *event) override;
virtual void moveEvent(QMoveEvent *event) override; virtual void moveEvent(QMoveEvent *event) override;
@ -95,7 +97,10 @@ private:
CContainerWidget* m_ContainerWidget; CContainerWidget* m_ContainerWidget;
CContainerWidget* m_DropContainer; CContainerWidget* m_DropContainer;
bool m_DraggingActive = false; bool m_DraggingActive = false;
bool m_NonCLientDraggingActive = false;
unsigned int m_zOrderIndex = 0; unsigned int m_zOrderIndex = 0;
QPoint m_DragStartPosition;
QPoint m_DragStartMousePosition;
static unsigned int zOrderCounter; static unsigned int zOrderCounter;
}; };

View File

@ -125,18 +125,7 @@ public:
static QSplitter* newSplitter(Qt::Orientation orientation = Qt::Horizontal, QWidget* parent = 0); static QSplitter* newSplitter(Qt::Orientation orientation = Qt::Horizontal, QWidget* parent = 0);
/**
* Filters the events of the floating widgets
*/
virtual bool event(QEvent *e) override;
private: private:
//
// Internal Stuff Begins Here
//
SectionWidget* dropContent(const InternalContentData& data, SectionWidget* targetSection, DropArea area, bool autoActive = true);
SectionWidget* sectionWidgetAt(const QPoint& pos) const;
// Serialization // Serialization
QByteArray saveHierarchy() const; QByteArray saveHierarchy() const;
void saveFloatingWidgets(QDataStream& out) const; void saveFloatingWidgets(QDataStream& out) const;
@ -149,24 +138,15 @@ private:
bool restoreSectionWidgets(QDataStream& in, int version, QSplitter* currentSplitter, QList<SectionWidget*>& sections, QList<SectionContent::RefPtr>& contentsToHide); bool restoreSectionWidgets(QDataStream& in, int version, QSplitter* currentSplitter, QList<SectionWidget*>& sections, QList<SectionContent::RefPtr>& contentsToHide);
bool takeContent(const SectionContent::RefPtr& sc, InternalContentData& data); bool takeContent(const SectionContent::RefPtr& sc, InternalContentData& data);
FloatingWidget* startFloating(SectionWidget* sectionwidget, int ContentUid, const QPoint& TargetPos);
void hideContainerOverlay(); void hideContainerOverlay();
void moveFloatingWidget(const QPoint& TargetPos); void moveFloatingWidget(const QPoint& TargetPos);
private slots: private slots:
void onActiveTabChanged();
void onActionToggleSectionContentVisibility(bool visible); void onActionToggleSectionContentVisibility(bool visible);
signals: signals:
void orientationChanged(); void orientationChanged();
/*!
* Emits whenever the "isActiveTab" state of a SectionContent changes.
* Whenever the users sets another tab as active, this signal gets invoked
* for the old tab and the new active tab (the order is unspecified).
*/
void activeTabChanged(const SectionContent::RefPtr& sc, bool active);
/*! /*!
* Emits whenever the visibility of a SectionContent changes. * Emits whenever the visibility of a SectionContent changes.
* \see showSectionContent(), hideSectionContent() * \see showSectionContent(), hideSectionContent()

View File

@ -22,11 +22,14 @@ class SectionTitleWidget : public QFrame
friend class MainContainerWidget; friend class MainContainerWidget;
friend class SectionWidget; friend class SectionWidget;
friend class CContainerWidget;
SectionContent::RefPtr m_Content; SectionContent::RefPtr m_Content;
// Drag & Drop (Floating) // Drag & Drop (Floating)
QPointer<FloatingWidget> m_FloatingWidget; QPointer<FloatingWidget> m_FloatingWidget;
QPoint m_DragStartMousePosition;
QPoint m_DragStartGlobalMousePosition;
QPoint m_DragStartPosition; QPoint m_DragStartPosition;
// Drag & Drop (Title/Tabs) // Drag & Drop (Title/Tabs)
@ -48,6 +51,8 @@ public:
*/ */
bool isDraggingFloatingWidget() const; bool isDraggingFloatingWidget() const;
virtual bool event(QEvent *e);
protected: protected:
virtual void mousePressEvent(QMouseEvent* ev); virtual void mousePressEvent(QMouseEvent* ev);
virtual void mouseReleaseEvent(QMouseEvent* ev); virtual void mouseReleaseEvent(QMouseEvent* ev);

View File

@ -80,8 +80,7 @@ unsigned int CContainerWidget::zOrderIndex() const
void CContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget, void CContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget,
const QPoint& TargetPos) const QPoint& TargetPos)
{ {
QPoint MousePos = mapFromGlobal(TargetPos); SectionWidget* sectionWidget = sectionWidgetAt(TargetPos);
SectionWidget* sectionWidget = sectionWidgetAt(MousePos);
DropArea dropArea = InvalidDropArea; DropArea dropArea = InvalidDropArea;
if (sectionWidget) if (sectionWidget)
{ {
@ -90,6 +89,7 @@ void CContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget,
dropArea = dropOverlay->showDropOverlay(sectionWidget); dropArea = dropOverlay->showDropOverlay(sectionWidget);
if (dropArea != InvalidDropArea) if (dropArea != InvalidDropArea)
{ {
std::cout << "Section Drop Content: " << dropArea << std::endl;
InternalContentData data; InternalContentData data;
FloatingWidget->takeContent(data); FloatingWidget->takeContent(data);
FloatingWidget->deleteLater(); FloatingWidget->deleteLater();
@ -101,29 +101,34 @@ void CContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget,
if (InvalidDropArea == dropArea) if (InvalidDropArea == dropArea)
{ {
dropArea = m_MainContainerWidget->dropOverlay()->dropAreaUnderCursor(); dropArea = m_MainContainerWidget->dropOverlay()->dropAreaUnderCursor();
std::cout << "Drop Content: " << dropArea << std::endl; std::cout << "Container Drop Content: " << dropArea << std::endl;
if (dropArea != InvalidDropArea) if (dropArea != InvalidDropArea)
{
dropIntoContainer(FloatingWidget, dropArea);
}
}
}
void CContainerWidget::dropIntoContainer(FloatingWidget* FloatingWidget, DropArea area)
{ {
InternalContentData data; InternalContentData data;
FloatingWidget->takeContent(data); FloatingWidget->takeContent(data);
FloatingWidget->deleteLater(); FloatingWidget->deleteLater();
dropContent(data, nullptr, dropArea, true); dropContent(data, nullptr, area, true);
}
}
} }
SectionWidget* CContainerWidget::sectionWidgetAt(const QPoint& pos) const SectionWidget* CContainerWidget::sectionWidgetAt(const QPoint& pos) const
{ {
const QPoint gpos = mapToGlobal(pos); for (const auto& SectionWidget : m_Sections)
for (int i = 0; i < m_Sections.size(); ++i)
{ {
SectionWidget* sw = m_Sections[i]; if (SectionWidget->rect().contains(SectionWidget->mapFromGlobal(pos)))
if (sw->rect().contains(sw->mapFromGlobal(gpos)))
{ {
return sw; return SectionWidget;
} }
} }
return 0; return 0;
} }
@ -290,9 +295,49 @@ SectionWidget* CContainerWidget::addSectionContent(const SectionContent::RefPtr&
data.titleWidget = new SectionTitleWidget(sc, NULL); data.titleWidget = new SectionTitleWidget(sc, NULL);
data.contentWidget = new SectionContentWidget(sc, NULL); data.contentWidget = new SectionContentWidget(sc, NULL);
//connect(data.titleWidget, SIGNAL(activeTabChanged()), this, SLOT(onActiveTabChanged())); connect(data.titleWidget, SIGNAL(activeTabChanged()), this, SLOT(onActiveTabChanged()));
return dropContent(data, sw, area, false); return dropContent(data, sw, area, false);
} }
void dumpChildSplitters(QWidget* Widget)
{
QSplitter* ParentSplitter = dynamic_cast<QSplitter*>(Widget);
auto Sections = Widget->findChildren<SectionWidget*>(QString(), Qt::FindDirectChildrenOnly);
auto Splitters = Widget->findChildren<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
std::cout << "-----------------------" << std::endl;
std::cout << "Sections " << Sections.size() << std::endl;
std::cout << "Splitters " << Splitters.size() << std::endl;
for (const auto& Splitter : Splitters)
{
if (ParentSplitter)
{
std::cout << "Orientation " << Splitter->orientation() << " index " << ParentSplitter->indexOf(Splitter) << std::endl;
}
else
{
std::cout << "Orientation " << Splitter->orientation() << std::endl;
}
dumpChildSplitters(Splitter);
}
}
void CContainerWidget::dumpLayout()
{
dumpChildSplitters(this);
}
void CContainerWidget::onActiveTabChanged()
{
SectionTitleWidget* stw = qobject_cast<SectionTitleWidget*>(sender());
if (stw)
{
emit activeTabChanged(stw->m_Content, stw->isActiveTab());
}
}
} // namespace ads } // namespace ads
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -219,6 +219,7 @@ void FloatingWidget::changeEvent(QEvent *event)
QWidget::changeEvent(event); QWidget::changeEvent(event);
if (event->type() != QEvent::ActivationChange) if (event->type() != QEvent::ActivationChange)
{ {
std::cout << "FloatingWidget::changeEvent QEvent::ActivationChange " << std::endl;
return; return;
} }
@ -242,25 +243,21 @@ void FloatingWidget::moveEvent(QMoveEvent *event)
bool FloatingWidget::event(QEvent *e) bool FloatingWidget::event(QEvent *e)
{ {
//std::cout << "FloatingWidget::event " << e->type() << std::endl;
if ((e->type() == QEvent::NonClientAreaMouseButtonPress)) if ((e->type() == QEvent::NonClientAreaMouseButtonPress))
{ {
if (QGuiApplication::mouseButtons() == Qt::LeftButton) if (QGuiApplication::mouseButtons() == Qt::LeftButton)
{ {
std::cout << "FloatingWidget::event Event::NonClientAreaMouseButtonPress" << e->type() << std::endl;
m_DraggingActive = true; m_DraggingActive = true;
qApp->installEventFilter(this); m_NonCLientDraggingActive = true;
qApp->installEventFilter(this); // install to remove mouse events if widget is behind drop overlay
} }
} }
else if ((e->type() == QEvent::NonClientAreaMouseButtonRelease) && m_DraggingActive) else if ((e->type() == QEvent::NonClientAreaMouseButtonRelease) && m_DraggingActive)
{ {
std::cout << "FloatingWidget::event QEvent::NonClientAreaMouseButtonRelease" << e->type() << std::endl;
titleMouseReleaseEvent(); titleMouseReleaseEvent();
} }
else if (e->type() == QEvent::WindowActivate)
{
m_DraggingActive = true;
qApp->installEventFilter(this);
std::cout << "QEvent::WindowActivate MouseButtons " << QGuiApplication::mouseButtons() << std::endl;
}
return QWidget::event(e); return QWidget::event(e);
} }
@ -271,10 +268,33 @@ bool FloatingWidget::eventFilter(QObject *watched, QEvent *event)
{ {
titleMouseReleaseEvent(); titleMouseReleaseEvent();
} }
else if (event->type() == QEvent::MouseMove)
{
if (m_DraggingActive)
{
QMouseEvent* MouseEvent = dynamic_cast<QMouseEvent*>(event);
int BorderSize = (frameSize().width() - size().width()) / 2;
const QPoint moveToPos = QCursor::pos() - m_DragStartMousePosition - QPoint(BorderSize, 0);
move(moveToPos);
return true;
}
}
return false; return false;
} }
void FloatingWidget::startFloating(const QPoint& Pos)
{
qApp->installEventFilter(this);
QPoint TargetPos = QCursor::pos() - Pos;
move(TargetPos);
show();
m_DraggingActive = true;
m_DragStartMousePosition = Pos;
m_DragStartPosition = this->pos();
}
void FloatingWidget::titleMouseReleaseEvent() void FloatingWidget::titleMouseReleaseEvent()
{ {
qApp->removeEventFilter(this); qApp->removeEventFilter(this);
@ -286,7 +306,6 @@ void FloatingWidget::titleMouseReleaseEvent()
std::cout << "Dropped" << std::endl; std::cout << "Dropped" << std::endl;
MainContainerWidget* MainContainerWidget = mainContainerWidget(); MainContainerWidget* MainContainerWidget = mainContainerWidget();
//MainContainerWidget->dropFloatingWidget(this, QCursor::pos());
m_DropContainer->dropFloatingWidget(this, QCursor::pos()); m_DropContainer->dropFloatingWidget(this, QCursor::pos());
MainContainerWidget->dropOverlay()->hideDropOverlay(); MainContainerWidget->dropOverlay()->hideDropOverlay();
MainContainerWidget->sectionDropOverlay()->hideDropOverlay(); MainContainerWidget->sectionDropOverlay()->hideDropOverlay();
@ -328,6 +347,31 @@ void FloatingWidget::updateDropOverlays(const QPoint& GlobalPos)
} }
m_DropContainer = TopContainer; m_DropContainer = TopContainer;
DropOverlay* ContainerDropOverlay = MainContainerWidget->dropOverlay();
DropOverlay* SectionDropOverlay = MainContainerWidget->sectionDropOverlay();
if (!TopContainer)
{
ContainerDropOverlay->hideDropOverlay();
SectionDropOverlay->hideDropOverlay();
return;
}
ContainerDropOverlay->showDropOverlay(TopContainer);
ContainerDropOverlay->raise();
SectionWidget* sectionwidget = TopContainer->sectionWidgetAt(GlobalPos);
if (sectionwidget)
{
SectionDropOverlay->setAllowedAreas(ADS_NS::AllAreas);
SectionDropOverlay->showDropOverlay(sectionwidget);
}
else
{
SectionDropOverlay->hideDropOverlay();
}
if (TopContainer) if (TopContainer)
{ {
MainContainerWidget->dropOverlay()->showDropOverlay(TopContainer); MainContainerWidget->dropOverlay()->showDropOverlay(TopContainer);

View File

@ -435,70 +435,6 @@ QPointer<DropOverlay> MainContainerWidget::dropOverlay() const
// PRIVATE API BEGINS HERE // PRIVATE API BEGINS HERE
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
SectionWidget* MainContainerWidget::dropContent(const InternalContentData& data, SectionWidget* targetSectionWidget, DropArea area, bool autoActive)
{
ADS_Expects(targetSection != NULL);
SectionWidget* section_widget = nullptr;
// If no sections exists yet, create a default one and always drop into it.
if (m_Sections.isEmpty())
{
targetSectionWidget = newSectionWidget();
addSectionWidget(targetSectionWidget);
area = CenterDropArea;
}
// Drop on outer area
if (!targetSectionWidget)
{
switch (area)
{
case TopDropArea:return dropContentOuterHelper(m_MainLayout, data, Qt::Vertical, false);
case RightDropArea: return dropContentOuterHelper(m_MainLayout, data, Qt::Horizontal, true);
case CenterDropArea:
case BottomDropArea:return dropContentOuterHelper(m_MainLayout, data, Qt::Vertical, true);
case LeftDropArea: return dropContentOuterHelper(m_MainLayout, data, Qt::Horizontal, false);
default:
return nullptr;
}
return section_widget;
}
// Drop logic based on area.
switch (area)
{
case TopDropArea:return insertNewSectionWidget(data, targetSectionWidget, section_widget, Qt::Vertical, 0);
case RightDropArea: return insertNewSectionWidget(data, targetSectionWidget, section_widget, Qt::Horizontal, 1);
case BottomDropArea: return insertNewSectionWidget(data, targetSectionWidget, section_widget, Qt::Vertical, 1);
case LeftDropArea: return insertNewSectionWidget(data, targetSectionWidget, section_widget, Qt::Horizontal, 0);
case CenterDropArea:
targetSectionWidget->addContent(data, autoActive);
return targetSectionWidget;
default:
break;
}
return section_widget;
}
SectionWidget* MainContainerWidget::sectionWidgetAt(const QPoint& pos) const
{
const QPoint gpos = mapToGlobal(pos);
for (int i = 0; i < m_Sections.size(); ++i)
{
SectionWidget* sw = m_Sections[i];
if (sw->rect().contains(sw->mapFromGlobal(gpos)))
{
return sw;
}
}
return 0;
}
QByteArray MainContainerWidget::saveHierarchy() const QByteArray MainContainerWidget::saveHierarchy() const
{ {
/* /*
@ -1028,14 +964,6 @@ bool MainContainerWidget::takeContent(const SectionContent::RefPtr& sc, Internal
return found; return found;
} }
void MainContainerWidget::onActiveTabChanged()
{
SectionTitleWidget* stw = qobject_cast<SectionTitleWidget*>(sender());
if (stw)
{
emit activeTabChanged(stw->m_Content, stw->isActiveTab());
}
}
void MainContainerWidget::onActionToggleSectionContentVisibility(bool visible) void MainContainerWidget::onActionToggleSectionContentVisibility(bool visible)
{ {
@ -1062,43 +990,6 @@ void MainContainerWidget::hideContainerOverlay()
} }
FloatingWidget* MainContainerWidget::startFloating(SectionWidget* sectionwidget, int ContentUid, const QPoint& TargetPos)
{
// Create floating widget.
InternalContentData data;
if (!sectionwidget->takeContent(ContentUid, data))
{
qWarning() << "THIS SHOULD NOT HAPPEN!!" << ContentUid;
return 0;
}
FloatingWidget* fw = new FloatingWidget(this, data.content, data.titleWidget, data.contentWidget, this);
fw->resize(sectionwidget->size());
fw->move(TargetPos);
fw->show();
fw->setObjectName("FloatingWidget");
// Delete old section, if it is empty now.
if (sectionwidget->contents().isEmpty())
{
delete sectionwidget;
sectionwidget = NULL;
}
deleteEmptySplitter(this);
m_ContainerDropOverlay->setAllowedAreas(OuterAreas);
m_ContainerDropOverlay->showDropOverlay(this);
m_ContainerDropOverlay->raise();
return fw;
}
bool MainContainerWidget::event(QEvent *e)
{
//std::cout << "ContainerWidget::event " << e->type() << std::endl;
return QFrame::event(e);
}
void MainContainerWidget::moveFloatingWidget(const QPoint& TargetPos) void MainContainerWidget::moveFloatingWidget(const QPoint& TargetPos)
{ {
QPoint MousePos = mapFromGlobal(QCursor::pos()); QPoint MousePos = mapFromGlobal(QCursor::pos());

View File

@ -11,6 +11,8 @@
#include <QSplitter> #include <QSplitter>
#include <QPushButton> #include <QPushButton>
#include <iostream>
#ifdef ADS_ANIMATIONS_ENABLED #ifdef ADS_ANIMATIONS_ENABLED
#include <QPropertyAnimation> #include <QPropertyAnimation>
#include <QParallelAnimationGroup> #include <QParallelAnimationGroup>
@ -70,7 +72,9 @@ void SectionTitleWidget::mousePressEvent(QMouseEvent* ev)
if (ev->button() == Qt::LeftButton) if (ev->button() == Qt::LeftButton)
{ {
ev->accept(); ev->accept();
m_DragStartPosition = ev->pos(); m_DragStartMousePosition = ev->pos();
m_DragStartGlobalMousePosition = ev->globalPos();
m_DragStartPosition = mapToGlobal(this->pos());
return; return;
} }
QFrame::mousePressEvent(ev); QFrame::mousePressEvent(ev);
@ -80,13 +84,11 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
{ {
SectionWidget* section = nullptr; SectionWidget* section = nullptr;
MainContainerWidget* cw = findParentContainerWidget(this); MainContainerWidget* cw = findParentContainerWidget(this);
std::cout << "SectionTitleWidget::mouseReleaseEvent" << std::endl;
if (isDraggingFloatingWidget() && cw->rect().contains(cw->mapFromGlobal(ev->globalPos()))) m_FloatingWidget.clear();
{
cw->dropFloatingWidget(m_FloatingWidget, ev->globalPos());
}
// End of tab moving, change order now // End of tab moving, change order now
else if (m_TabMoving && (section = findParentSectionWidget(this)) != nullptr) if (m_TabMoving && (section = findParentSectionWidget(this)) != nullptr)
{ {
// Find tab under mouse // Find tab under mouse
QPoint pos = ev->globalPos(); QPoint pos = ev->globalPos();
@ -101,13 +103,13 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
section->moveContent(fromIndex, toIndex); section->moveContent(fromIndex, toIndex);
} }
if (!m_DragStartPosition.isNull()) if (!m_DragStartMousePosition.isNull())
{ {
emit clicked(); emit clicked();
} }
// Reset // Reset
m_DragStartPosition = QPoint(); m_DragStartMousePosition = QPoint();
m_TabMoving = false; m_TabMoving = false;
cw->m_SectionDropOverlay->hideDropOverlay(); cw->m_SectionDropOverlay->hideDropOverlay();
cw->hideContainerOverlay(); cw->hideContainerOverlay();
@ -117,26 +119,84 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
void SectionTitleWidget::moveFloatingWidget(QMouseEvent* ev, MainContainerWidget* cw) void SectionTitleWidget::moveFloatingWidget(QMouseEvent* ev, MainContainerWidget* cw)
{ {
const QPoint moveToPos = ev->globalPos() - (m_DragStartPosition + QPoint(ADS_WINDOW_FRAME_BORDER_WIDTH, ADS_WINDOW_FRAME_BORDER_WIDTH)); std::cout << "SectionTitleWidget::moveFloatingWidget" << std::endl;
m_FloatingWidget->move(moveToPos); /*const QPoint DragDistance = ev->globalPos() - m_DragStartGlobalMousePosition;
// cw->moveFloatingWidget(moveToPos); const QPoint moveToGlobalPos = m_DragStartPosition + DragDistance;
m_FloatingWidget->move(moveToGlobalPos);*/
const QPoint moveToPos = ev->globalPos() - m_DragStartMousePosition;
m_FloatingWidget->move(moveToPos);
} }
void SectionTitleWidget::startFloating(QMouseEvent* ev, MainContainerWidget* cw, SectionWidget* sectionwidget) void SectionTitleWidget::startFloating(QMouseEvent* ev, MainContainerWidget* cw, SectionWidget* sectionwidget)
{ {
QPoint moveToPos = ev->globalPos() - (m_DragStartPosition + QPoint(ADS_WINDOW_FRAME_BORDER_WIDTH, ADS_WINDOW_FRAME_BORDER_WIDTH)); std::cout << "SectionTitleWidget::startFloating" << std::endl;
m_FloatingWidget = cw->startFloating(sectionwidget, m_Content->uid(), moveToPos); QPoint moveToPos = ev->globalPos() - m_DragStartMousePosition;
InternalContentData data;
if (!sectionwidget->takeContent(m_Content->uid(), data))
{
qWarning() << "THIS SHOULD NOT HAPPEN!!" << m_Content->uid();
return;
} }
FloatingWidget* fw = new FloatingWidget(cw, data.content, data.titleWidget, data.contentWidget, cw);
fw->resize(sectionwidget->size());
fw->setObjectName("FloatingWidget");
fw->startFloating(m_DragStartMousePosition);
// Delete old section, if it is empty now.
if (sectionwidget->contents().isEmpty())
{
delete sectionwidget;
sectionwidget = NULL;
}
deleteEmptySplitter(cw);
DropOverlay* ContainerDropOverlay = cw->dropOverlay();
ContainerDropOverlay->setAllowedAreas(OuterAreas);
ContainerDropOverlay->showDropOverlay(this);
ContainerDropOverlay->raise();
}
/*
FloatingWidget* MainContainerWidget::startFloating(SectionWidget* sectionwidget, int ContentUid, const QPoint& TargetPos)
{
// Create floating widget.
InternalContentData data;
if (!sectionwidget->takeContent(ContentUid, data))
{
qWarning() << "THIS SHOULD NOT HAPPEN!!" << ContentUid;
return 0;
}
FloatingWidget* fw = new FloatingWidget(this, data.content, data.titleWidget, data.contentWidget, this);
fw->resize(sectionwidget->size());
fw->setObjectName("FloatingWidget");
fw->startFloating(TargetPos);
// Delete old section, if it is empty now.
if (sectionwidget->contents().isEmpty())
{
delete sectionwidget;
sectionwidget = NULL;
}
deleteEmptySplitter(this);
m_ContainerDropOverlay->setAllowedAreas(OuterAreas);
m_ContainerDropOverlay->showDropOverlay(this);
m_ContainerDropOverlay->raise();
return fw;
}*/
void SectionTitleWidget::moveTab(QMouseEvent* ev) void SectionTitleWidget::moveTab(QMouseEvent* ev)
{ {
ev->accept(); ev->accept();
int left, top, right, bottom; int left, top, right, bottom;
getContentsMargins(&left, &top, &right, &bottom); getContentsMargins(&left, &top, &right, &bottom);
QPoint moveToPos = mapToParent(ev->pos()) - m_DragStartPosition; QPoint moveToPos = mapToParent(ev->pos()) - m_DragStartMousePosition;
moveToPos.setY(0/* + top*/); moveToPos.setY(0/* + top*/);
move(moveToPos); move(moveToPos);
} }
@ -144,62 +204,28 @@ void SectionTitleWidget::moveTab(QMouseEvent* ev)
bool SectionTitleWidget::isDraggingFloatingWidget() const bool SectionTitleWidget::isDraggingFloatingWidget() const
{ {
return m_FloatingWidget != nullptr; return !m_FloatingWidget.isNull();
} }
void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev) void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev)
{ {
std::cout << "SectionTitleWidget::mouseMoveEvent" << std::endl;
if (!(ev->buttons() & Qt::LeftButton)) if (!(ev->buttons() & Qt::LeftButton))
{ {
QFrame::mouseMoveEvent(ev); QFrame::mouseMoveEvent(ev);
return; return;
} }
QPoint Pos = QCursor::pos();
// TODO make a member with the main container widget and assign it on // TODO make a member with the main container widget and assign it on
// creation // creation
MainContainerWidget* MainContainerWidget = findParentContainerWidget(this); MainContainerWidget* MainContainerWidget = findParentContainerWidget(this);
auto Containers = MainContainerWidget->m_Containers;
CContainerWidget* TopContainer = nullptr;
for (auto ContainerWidget : Containers)
{
if (!ContainerWidget->isVisible())
{
continue;
}
if (!m_FloatingWidget || (m_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(); ev->accept();
// Move already existing FloatingWidget // Move already existing FloatingWidget
if (isDraggingFloatingWidget()) if (isDraggingFloatingWidget())
{ {
moveFloatingWidget(ev, MainContainerWidget); std::cout << "SectionTitleWidget isDraggingFloatingWidget()" << std::endl;
//moveFloatingWidget(ev, MainContainerWidget);
return; return;
} }
@ -218,7 +244,7 @@ void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev)
} }
// leave if dragging is not active // leave if dragging is not active
if (m_DragStartPosition.isNull()) if (m_DragStartMousePosition.isNull())
{ {
QFrame::mouseMoveEvent(ev); QFrame::mouseMoveEvent(ev);
return; return;
@ -231,7 +257,7 @@ void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev)
return; return;
} }
// Begin to drag title inside the title area to switch its position inside the SectionWidget. // Begin to drag title inside the title area to switch its position inside the SectionWidget.
else if ((ev->pos() - m_DragStartPosition).manhattanLength() >= QApplication::startDragDistance() // Wait a few pixels before start moving else if ((ev->pos() - m_DragStartMousePosition).manhattanLength() >= QApplication::startDragDistance() // Wait a few pixels before start moving
&& sectionwidget->titleAreaGeometry().contains(sectionwidget->mapFromGlobal(ev->globalPos()))) && sectionwidget->titleAreaGeometry().contains(sectionwidget->mapFromGlobal(ev->globalPos())))
{ {
m_TabMoving = true; m_TabMoving = true;
@ -241,4 +267,10 @@ void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev)
QFrame::mouseMoveEvent(ev); QFrame::mouseMoveEvent(ev);
} }
bool SectionTitleWidget::event(QEvent *e)
{
return QFrame::event(e);
}
ADS_NAMESPACE_END ADS_NAMESPACE_END

View File

@ -206,14 +206,8 @@ bool SectionWidget::takeContent(int uid, InternalContentData& data)
if (title) if (title)
{ {
_tabsLayout->removeWidget(title); _tabsLayout->removeWidget(title);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
title->setAttribute(Qt::WA_WState_Created, false); /* fix: floating rubberband #16 */
#endif
title->disconnect(this); title->disconnect(this);
title->setParent(m_MainContainerWidget); title->setParent(m_MainContainerWidget);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
title->setAttribute(Qt::WA_WState_Created, true); /* fix: floating rubberband #16 */
#endif
} }
// Content wrapper widget (CONTENT) // Content wrapper widget (CONTENT)
@ -388,11 +382,7 @@ void SectionWidget::updateTabsMenu()
const SectionContent::RefPtr& sc = _contents.at(i); const SectionContent::RefPtr& sc = _contents.at(i);
QAction* a = m->addAction(QIcon(), sc->visibleTitle()); QAction* a = m->addAction(QIcon(), sc->visibleTitle());
a->setData(sc->uid()); a->setData(sc->uid());
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QObject::connect(a, &QAction::triggered, this, &SectionWidget::onTabsMenuActionTriggered);
#else
QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(onTabsMenuActionTriggered(bool))); QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(onTabsMenuActionTriggered(bool)));
#endif
} }
QMenu* old = _tabsMenuButton->menu(); QMenu* old = _tabsMenuButton->menu();
_tabsMenuButton->setMenu(m); _tabsMenuButton->setMenu(m);

View File

@ -104,6 +104,7 @@ MainWindow::MainWindow(QWidget *parent) :
// ADS - Restore geometries and states of contents. // ADS - Restore geometries and states of contents.
//_container->restoreState(loadDataHelper("ContainerWidget")); //_container->restoreState(loadDataHelper("ContainerWidget"));
_container->dumpLayout();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()