Preparing dropping of section widgets with multiple sections

This commit is contained in:
Uwe Kindler 2017-02-12 19:59:29 +01:00
parent df97d17844
commit 025bedfb65
6 changed files with 117 additions and 40 deletions

View File

@ -99,6 +99,9 @@ protected:
unsigned int m_zOrderIndex = 0; unsigned int m_zOrderIndex = 0;
static unsigned int zOrderCounter; static unsigned int zOrderCounter;
private:
void dropChildSections(QWidget* Parent);
private slots: private slots:
void onActiveTabChanged(); void onActiveTabChanged();
}; };

View File

@ -90,6 +90,8 @@ private slots:
void onCloseButtonClicked(); void onCloseButtonClicked();
private: private:
void setDraggingActive(bool Active);
MainContainerWidget* m_MainContainerWidget; MainContainerWidget* m_MainContainerWidget;
SectionContent::RefPtr _content; SectionContent::RefPtr _content;
SectionTitleWidget* _titleWidget; SectionTitleWidget* _titleWidget;

View File

@ -41,7 +41,7 @@ public:
QRect titleAreaGeometry() const; QRect titleAreaGeometry() const;
QRect contentAreaGeometry() const; QRect contentAreaGeometry() const;
const QList<SectionContent::RefPtr>& contents() const { return _contents; } const QList<SectionContent::RefPtr>& contents() const { return m_Contents; }
void addContent(const SectionContent::RefPtr& c); void addContent(const SectionContent::RefPtr& c);
void addContent(const InternalContentData& data, bool autoActivate); void addContent(const InternalContentData& data, bool autoActivate);
bool takeContent(int uid, InternalContentData& data); bool takeContent(int uid, InternalContentData& data);
@ -54,6 +54,8 @@ public:
virtual bool eventFilter(QObject *watched, QEvent *event); virtual bool eventFilter(QObject *watched, QEvent *event);
inline int contentCount() const {return m_ContentWidgets.size();}
protected: protected:
virtual void showEvent(QShowEvent*); virtual void showEvent(QShowEvent*);
@ -72,9 +74,9 @@ private:
QPointer<CContainerWidget> m_ContainerWidget; QPointer<CContainerWidget> m_ContainerWidget;
QPointer<MainContainerWidget> m_MainContainerWidget; QPointer<MainContainerWidget> m_MainContainerWidget;
QList<SectionContent::RefPtr> _contents; QList<SectionContent::RefPtr> m_Contents;
QList<SectionTitleWidget*> _sectionTitles; QList<SectionTitleWidget*> m_TitleWidgets;
QList<SectionContentWidget*> _sectionContents; QList<SectionContentWidget*> m_ContentWidgets;
QBoxLayout* _topLayout; QBoxLayout* _topLayout;
QScrollArea* _tabsScrollArea; QScrollArea* _tabsScrollArea;

View File

@ -109,9 +109,60 @@ void CContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget,
} }
} }
/*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::dropChildSections(QWidget* Parent)
{
auto Sections = Parent->findChildren<SectionWidget*>(QString(), Qt::FindDirectChildrenOnly);
auto Splitters = Parent->findChildren<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
std::cout << "-----------------------" << std::endl;
std::cout << "Sections " << Sections.size() << std::endl;
std::cout << "Splitters " << Splitters.size() << std::endl;
for (auto Section : Sections)
{
// drop section
}
for (auto Splitter : Splitters)
{
dropChildSections(Splitter);
}
}
void CContainerWidget::dropIntoContainer(FloatingWidget* FloatingWidget, DropArea area) void CContainerWidget::dropIntoContainer(FloatingWidget* FloatingWidget, DropArea area)
{ {
dropChildSections(FloatingWidget->containerWidget());
InternalContentData data; InternalContentData data;
FloatingWidget->takeContent(data); FloatingWidget->takeContent(data);
FloatingWidget->deleteLater(); FloatingWidget->deleteLater();

View File

@ -241,6 +241,27 @@ void FloatingWidget::moveEvent(QMoveEvent *event)
} }
void FloatingWidget::setDraggingActive(bool Active)
{
if (m_DraggingActive == Active)
{
return;
}
m_DraggingActive = Active;
if (Active)
{
std::cout << "FloatingWidget:: InstallEventFilter" << std::endl;
qApp->installEventFilter(this);
}
else
{
std::cout << "FloatingWidget:: RemoveEventFilter" << std::endl;
qApp->removeEventFilter(this);
}
}
bool FloatingWidget::event(QEvent *e) bool FloatingWidget::event(QEvent *e)
{ {
if ((e->type() == QEvent::NonClientAreaMouseButtonPress)) if ((e->type() == QEvent::NonClientAreaMouseButtonPress))
@ -248,9 +269,8 @@ bool FloatingWidget::event(QEvent *e)
if (QGuiApplication::mouseButtons() == Qt::LeftButton) if (QGuiApplication::mouseButtons() == Qt::LeftButton)
{ {
std::cout << "FloatingWidget::event Event::NonClientAreaMouseButtonPress" << e->type() << std::endl; std::cout << "FloatingWidget::event Event::NonClientAreaMouseButtonPress" << e->type() << std::endl;
m_DraggingActive = true; setDraggingActive(true);
m_NonCLientDraggingActive = true; 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)
@ -285,11 +305,10 @@ bool FloatingWidget::eventFilter(QObject *watched, QEvent *event)
void FloatingWidget::startFloating(const QPoint& Pos) void FloatingWidget::startFloating(const QPoint& Pos)
{ {
qApp->installEventFilter(this); setDraggingActive(true);
QPoint TargetPos = QCursor::pos() - Pos; QPoint TargetPos = QCursor::pos() - Pos;
move(TargetPos); move(TargetPos);
show(); show();
m_DraggingActive = true;
m_DragStartMousePosition = Pos; m_DragStartMousePosition = Pos;
m_DragStartPosition = this->pos(); m_DragStartPosition = this->pos();
} }
@ -297,8 +316,8 @@ void FloatingWidget::startFloating(const QPoint& Pos)
void FloatingWidget::titleMouseReleaseEvent() void FloatingWidget::titleMouseReleaseEvent()
{ {
qApp->removeEventFilter(this); setDraggingActive(false);
m_DraggingActive = false; m_NonCLientDraggingActive = false;
if (!m_DropContainer) if (!m_DropContainer)
{ {
return; return;

View File

@ -135,19 +135,19 @@ QRect SectionWidget::contentAreaGeometry() const
void SectionWidget::addContent(const SectionContent::RefPtr& c) void SectionWidget::addContent(const SectionContent::RefPtr& c)
{ {
_contents.append(c); m_Contents.append(c);
SectionTitleWidget* title = new SectionTitleWidget(c, NULL); SectionTitleWidget* title = new SectionTitleWidget(c, NULL);
_sectionTitles.append(title); m_TitleWidgets.append(title);
_tabsLayout->insertWidget(_tabsLayout->count() - _tabsLayoutInitCount, title); _tabsLayout->insertWidget(_tabsLayout->count() - _tabsLayoutInitCount, title);
QObject::connect(title, SIGNAL(clicked()), this, SLOT(onSectionTitleClicked())); QObject::connect(title, SIGNAL(clicked()), this, SLOT(onSectionTitleClicked()));
SectionContentWidget* content = new SectionContentWidget(c, NULL); SectionContentWidget* content = new SectionContentWidget(c, NULL);
_sectionContents.append(content); m_ContentWidgets.append(content);
_contentsLayout->addWidget(content); _contentsLayout->addWidget(content);
// Active first TAB. // Active first TAB.
if (_contents.size() == 1) if (m_Contents.size() == 1)
setCurrentIndex(0); setCurrentIndex(0);
// Switch to newest. // Switch to newest.
// else // else
@ -158,26 +158,26 @@ void SectionWidget::addContent(const SectionContent::RefPtr& c)
void SectionWidget::addContent(const InternalContentData& data, bool autoActivate) void SectionWidget::addContent(const InternalContentData& data, bool autoActivate)
{ {
_contents.append(data.content); m_Contents.append(data.content);
// Add title-widget to tab-bar // Add title-widget to tab-bar
// #FIX: Make it visible, since it is possible that it was hidden previously. // #FIX: Make it visible, since it is possible that it was hidden previously.
_sectionTitles.append(data.titleWidget); m_TitleWidgets.append(data.titleWidget);
_tabsLayout->insertWidget(_tabsLayout->count() - _tabsLayoutInitCount, data.titleWidget); _tabsLayout->insertWidget(_tabsLayout->count() - _tabsLayoutInitCount, data.titleWidget);
data.titleWidget->setVisible(true); data.titleWidget->setVisible(true);
QObject::connect(data.titleWidget, SIGNAL(clicked()), this, SLOT(onSectionTitleClicked())); QObject::connect(data.titleWidget, SIGNAL(clicked()), this, SLOT(onSectionTitleClicked()));
// Add content-widget to stack. // Add content-widget to stack.
// Visibility is managed by QStackedWidget. // Visibility is managed by QStackedWidget.
_sectionContents.append(data.contentWidget); m_ContentWidgets.append(data.contentWidget);
_contentsLayout->addWidget(data.contentWidget); _contentsLayout->addWidget(data.contentWidget);
// Activate first TAB. // Activate first TAB.
if (_contents.size() == 1) if (m_Contents.size() == 1)
setCurrentIndex(0); setCurrentIndex(0);
// Switch to just added TAB. // Switch to just added TAB.
else if (autoActivate) else if (autoActivate)
setCurrentIndex(_contents.count() - 1); setCurrentIndex(m_Contents.count() - 1);
// Mark it as inactive tab. // Mark it as inactive tab.
else else
data.titleWidget->setActiveTab(false); // or: setCurrentIndex(currentIndex()) data.titleWidget->setActiveTab(false); // or: setCurrentIndex(currentIndex())
@ -190,19 +190,19 @@ bool SectionWidget::takeContent(int uid, InternalContentData& data)
// Find SectionContent. // Find SectionContent.
SectionContent::RefPtr sc; SectionContent::RefPtr sc;
int index = -1; int index = -1;
for (int i = 0; i < _contents.count(); i++) for (int i = 0; i < m_Contents.count(); i++)
{ {
if (_contents[i]->uid() != uid) if (m_Contents[i]->uid() != uid)
continue; continue;
index = i; index = i;
sc = _contents.takeAt(i); sc = m_Contents.takeAt(i);
break; break;
} }
if (!sc) if (!sc)
return false; return false;
// Title wrapper widget (TAB) // Title wrapper widget (TAB)
SectionTitleWidget* title = _sectionTitles.takeAt(index); SectionTitleWidget* title = m_TitleWidgets.takeAt(index);
if (title) if (title)
{ {
_tabsLayout->removeWidget(title); _tabsLayout->removeWidget(title);
@ -211,7 +211,7 @@ bool SectionWidget::takeContent(int uid, InternalContentData& data)
} }
// Content wrapper widget (CONTENT) // Content wrapper widget (CONTENT)
SectionContentWidget* content = _sectionContents.takeAt(index); SectionContentWidget* content = m_ContentWidgets.takeAt(index);
if (content) if (content)
{ {
_contentsLayout->removeWidget(content); _contentsLayout->removeWidget(content);
@ -220,7 +220,7 @@ bool SectionWidget::takeContent(int uid, InternalContentData& data)
} }
// Select the previous tab as activeTab. // Select the previous tab as activeTab.
if (_contents.size() > 0 && title->isActiveTab()) if (m_Contents.size() > 0 && title->isActiveTab())
{ {
if (index > 0) if (index > 0)
setCurrentIndex(index - 1); setCurrentIndex(index - 1);
@ -238,14 +238,14 @@ bool SectionWidget::takeContent(int uid, InternalContentData& data)
int SectionWidget::indexOfContent(const SectionContent::RefPtr& c) const int SectionWidget::indexOfContent(const SectionContent::RefPtr& c) const
{ {
return _contents.indexOf(c); return m_Contents.indexOf(c);
} }
int SectionWidget::indexOfContentByUid(int uid) const int SectionWidget::indexOfContentByUid(int uid) const
{ {
for (int i = 0; i < _contents.count(); ++i) for (int i = 0; i < m_Contents.count(); ++i)
{ {
if (_contents[i]->uid() == uid) if (m_Contents[i]->uid() == uid)
return i; return i;
} }
return -1; return -1;
@ -254,9 +254,9 @@ int SectionWidget::indexOfContentByUid(int uid) const
int SectionWidget::indexOfContentByTitlePos(const QPoint& p, QWidget* exclude) const int SectionWidget::indexOfContentByTitlePos(const QPoint& p, QWidget* exclude) const
{ {
int index = -1; int index = -1;
for (int i = 0; i < _sectionTitles.size(); ++i) for (int i = 0; i < m_TitleWidgets.size(); ++i)
{ {
if (_sectionTitles[i]->geometry().contains(p) && (exclude == NULL || _sectionTitles[i] != exclude)) if (m_TitleWidgets[i]->geometry().contains(p) && (exclude == NULL || m_TitleWidgets[i] != exclude))
{ {
index = i; index = i;
break; break;
@ -272,16 +272,16 @@ int SectionWidget::currentIndex() const
void SectionWidget::moveContent(int from, int to) void SectionWidget::moveContent(int from, int to)
{ {
if (from >= _contents.size() || from < 0 || to >= _contents.size() || to < 0 || from == to) if (from >= m_Contents.size() || from < 0 || to >= m_Contents.size() || to < 0 || from == to)
{ {
qDebug() << "Invalid index for tab movement" << from << to; qDebug() << "Invalid index for tab movement" << from << to;
_tabsLayout->update(); _tabsLayout->update();
return; return;
} }
_contents.move(from, to); m_Contents.move(from, to);
_sectionTitles.move(from, to); m_TitleWidgets.move(from, to);
_sectionContents.move(from, to); m_ContentWidgets.move(from, to);
QLayoutItem* liFrom = NULL; QLayoutItem* liFrom = NULL;
liFrom = _tabsLayout->takeAt(from); liFrom = _tabsLayout->takeAt(from);
@ -302,12 +302,12 @@ void SectionWidget::moveContent(int from, int to)
void SectionWidget::showEvent(QShowEvent*) void SectionWidget::showEvent(QShowEvent*)
{ {
_tabsScrollArea->ensureWidgetVisible(_sectionTitles.at(currentIndex())); _tabsScrollArea->ensureWidgetVisible(m_TitleWidgets.at(currentIndex()));
} }
void SectionWidget::setCurrentIndex(int index) void SectionWidget::setCurrentIndex(int index)
{ {
if (index < 0 || index > _contents.count() - 1) if (index < 0 || index > m_Contents.count() - 1)
{ {
qWarning() << Q_FUNC_INFO << "Invalid index" << index; qWarning() << Q_FUNC_INFO << "Invalid index" << index;
return; return;
@ -354,9 +354,9 @@ void SectionWidget::onSectionTitleClicked()
void SectionWidget::onCloseButtonClicked() void SectionWidget::onCloseButtonClicked()
{ {
const int index = currentIndex(); const int index = currentIndex();
if (index < 0 || index > _contents.size() - 1) if (index < 0 || index > m_Contents.size() - 1)
return; return;
SectionContent::RefPtr sc = _contents.at(index); SectionContent::RefPtr sc = m_Contents.at(index);
if (sc.isNull()) if (sc.isNull())
return; return;
m_MainContainerWidget->hideSectionContent(sc); m_MainContainerWidget->hideSectionContent(sc);
@ -377,9 +377,9 @@ void SectionWidget::onTabsMenuActionTriggered(bool)
void SectionWidget::updateTabsMenu() void SectionWidget::updateTabsMenu()
{ {
QMenu* m = new QMenu(); QMenu* m = new QMenu();
for (int i = 0; i < _contents.count(); ++i) for (int i = 0; i < m_Contents.count(); ++i)
{ {
const SectionContent::RefPtr& sc = _contents.at(i); const SectionContent::RefPtr& sc = m_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());
QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(onTabsMenuActionTriggered(bool))); QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(onTabsMenuActionTriggered(bool)));