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;
static unsigned int zOrderCounter;
private:
void dropChildSections(QWidget* Parent);
private slots:
void onActiveTabChanged();
};

View File

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

View File

@ -41,7 +41,7 @@ public:
QRect titleAreaGeometry() 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 InternalContentData& data, bool autoActivate);
bool takeContent(int uid, InternalContentData& data);
@ -54,6 +54,8 @@ public:
virtual bool eventFilter(QObject *watched, QEvent *event);
inline int contentCount() const {return m_ContentWidgets.size();}
protected:
virtual void showEvent(QShowEvent*);
@ -72,9 +74,9 @@ private:
QPointer<CContainerWidget> m_ContainerWidget;
QPointer<MainContainerWidget> m_MainContainerWidget;
QList<SectionContent::RefPtr> _contents;
QList<SectionTitleWidget*> _sectionTitles;
QList<SectionContentWidget*> _sectionContents;
QList<SectionContent::RefPtr> m_Contents;
QList<SectionTitleWidget*> m_TitleWidgets;
QList<SectionContentWidget*> m_ContentWidgets;
QBoxLayout* _topLayout;
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)
{
dropChildSections(FloatingWidget->containerWidget());
InternalContentData data;
FloatingWidget->takeContent(data);
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)
{
if ((e->type() == QEvent::NonClientAreaMouseButtonPress))
@ -248,9 +269,8 @@ bool FloatingWidget::event(QEvent *e)
if (QGuiApplication::mouseButtons() == Qt::LeftButton)
{
std::cout << "FloatingWidget::event Event::NonClientAreaMouseButtonPress" << e->type() << std::endl;
m_DraggingActive = true;
setDraggingActive(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)
@ -285,11 +305,10 @@ bool FloatingWidget::eventFilter(QObject *watched, QEvent *event)
void FloatingWidget::startFloating(const QPoint& Pos)
{
qApp->installEventFilter(this);
setDraggingActive(true);
QPoint TargetPos = QCursor::pos() - Pos;
move(TargetPos);
show();
m_DraggingActive = true;
m_DragStartMousePosition = Pos;
m_DragStartPosition = this->pos();
}
@ -297,8 +316,8 @@ void FloatingWidget::startFloating(const QPoint& Pos)
void FloatingWidget::titleMouseReleaseEvent()
{
qApp->removeEventFilter(this);
m_DraggingActive = false;
setDraggingActive(false);
m_NonCLientDraggingActive = false;
if (!m_DropContainer)
{
return;

View File

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