diff --git a/AdvancedDockingSystem/AdvancedDockingSystem.pri b/AdvancedDockingSystem/AdvancedDockingSystem.pri deleted file mode 100644 index 99a8091..0000000 --- a/AdvancedDockingSystem/AdvancedDockingSystem.pri +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/AdvancedDockingSystem/AdvancedDockingSystem.pro b/AdvancedDockingSystem/AdvancedDockingSystem.pro deleted file mode 100644 index b62a1d9..0000000 --- a/AdvancedDockingSystem/AdvancedDockingSystem.pro +++ /dev/null @@ -1,62 +0,0 @@ -include($$(cetoni_repository)/build/qt/qtprojectsettings/shared_library.pri) -include(src/v2/v2.pri) - -TARGET = $$qtLibraryTarget(AdvancedDockingSystem) -TEMPLATE = lib -#VERSION = 1.0.0 - -CONFIG += adsBuildShared - -QT += core gui -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -greaterThan(QT_MAJOR_VERSION, 4): DEFINES += ADS_NAMESPACE_ENABLED - -adsBuildShared { - CONFIG += shared - DEFINES += ADS_EXPORT -} -!adsBuildShared { - CONFIG += staticlib -} - -INCLUDEPATH += $$PWD/include - -windows { - # MinGW - *-g++* { - QMAKE_CXXFLAGS += -std=c++11 - QMAKE_CXXFLAGS += -Wall -Wextra -pedantic - } - # MSVC - *-msvc* { - } -} - -RESOURCES += \ - res/ads.qrc - -SOURCES += \ - $$PWD/src/API.cpp \ - $$PWD/src/MainContainerWidget.cpp \ - $$PWD/src/SectionWidget.cpp \ - $$PWD/src/SectionContent.cpp \ - $$PWD/src/SectionTitleWidget.cpp \ - $$PWD/src/SectionContentWidget.cpp \ - $$PWD/src/DropOverlay.cpp \ - $$PWD/src/FloatingWidget.cpp \ - $$PWD/src/Internal.cpp \ - $$PWD/src/Serialization.cpp \ - $$PWD/src/ContainerWidget.cpp - -HEADERS += \ - $$PWD/src/API.h \ - $$PWD/src/MainContainerWidget.h \ - $$PWD/src/SectionWidget.h \ - $$PWD/src/SectionContent.h \ - $$PWD/src/SectionTitleWidget.h \ - $$PWD/src/SectionContentWidget.h \ - $$PWD/src/DropOverlay.h \ - $$PWD/src/FloatingWidget.h \ - $$PWD/src/Internal.h \ - $$PWD/src/Serialization.h \ - $$PWD/src/ContainerWidget.h diff --git a/AdvancedDockingSystem/src/API.cpp b/AdvancedDockingSystem/src/API.cpp deleted file mode 100644 index 51d6bda..0000000 --- a/AdvancedDockingSystem/src/API.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ - - -#include "MainContainerWidget.h" -#include "API.h" - -#include -#include -#include -#include - -#include "SectionWidget.h" - -namespace ads -{ - -static bool splitterContainsSectionWidget(QSplitter* splitter) -{ - for (int i = 0; i < splitter->count(); ++i) - { - QWidget* w = splitter->widget(i); - QSplitter* sp = qobject_cast(w); - SectionWidget* sw = NULL; - if (sp && splitterContainsSectionWidget(sp)) - return true; - else if ((sw = qobject_cast(w)) != NULL) - return true; - } - return false; -} - -void deleteEmptySplitter(CMainContainerWidget* container) -{ - bool doAgain = false; - do - { - doAgain = false; - QList splitters = container->findChildren(); - for (int i = 0; i < splitters.count(); ++i) - { - QSplitter* sp = splitters.at(i); - if (!sp->property("ads-splitter").toBool()) - continue; - if (sp->count() > 0 && splitterContainsSectionWidget(sp)) - continue; - delete splitters[i]; - doAgain = true; - break; - } - } - while (doAgain); -} - - -QSplitter* findParentSplitter(QWidget* w) -{ - QSplitter* splitter = 0; - QWidget* parentWidget = w; - do - { - if ((splitter = dynamic_cast(parentWidget)) != 0) - { - break; - } - parentWidget = parentWidget->parentWidget(); - } - while (parentWidget); - return splitter; -} - - -QSplitter* findImmediateSplitter(QWidget* w) -{ - QLayout* l = w->layout(); - if (!l || l->count() <= 0) - { - return nullptr; - } - - QSplitter* sp = nullptr; - for (int i = 0; i < l->count(); ++i) - { - QLayoutItem* li = l->itemAt(0); - if (!li->widget()) - { - continue; - } - if ((sp = dynamic_cast(li->widget())) != nullptr) - { - break; - } - } - return sp; -} - -} // namespace ads diff --git a/AdvancedDockingSystem/src/API.h b/AdvancedDockingSystem/src/API.h deleted file mode 100644 index 2f867f6..0000000 --- a/AdvancedDockingSystem/src/API.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef ADS_API_H -#define ADS_API_H -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ - -#include -class QWidget; -class QSplitter; - -// DLL Export API -#ifdef _WIN32 - #if defined(ADS_IMPORT) - #define ADS_EXPORT_API - #elif defined(ADS_EXPORT) - #define ADS_EXPORT_API __declspec(dllexport) - #else - #define ADS_EXPORT_API __declspec(dllimport) - #endif -#else - #define ADS_EXPORT_API -#endif - - -// Beautiful C++ stuff. -#define ADS_Expects(cond) -#define ADS_Ensures(cond) - -// Indicates whether ADS should include animations. -//#define ADS_ANIMATIONS_ENABLED 1 -//#define ADS_ANIMATION_DURATION 150 - -namespace ads -{ -class CMainContainerWidget; -class SectionWidget; - -enum DropArea -{ - InvalidDropArea = 0, - TopDropArea = 1, - RightDropArea = 2, - BottomDropArea = 4, - LeftDropArea = 8, - CenterDropArea = 16, - - OuterAreas = TopDropArea | RightDropArea | BottomDropArea | LeftDropArea, - AllAreas = OuterAreas | CenterDropArea -}; -Q_DECLARE_FLAGS(DropAreas, DropArea) - -void deleteEmptySplitter(CMainContainerWidget* container); -QSplitter* findParentSplitter(QWidget* w); -QSplitter* findImmediateSplitter(QWidget* w); - -} // namespace ads -#endif diff --git a/AdvancedDockingSystem/src/ContainerWidget.cpp b/AdvancedDockingSystem/src/ContainerWidget.cpp deleted file mode 100644 index 22076ac..0000000 --- a/AdvancedDockingSystem/src/ContainerWidget.cpp +++ /dev/null @@ -1,560 +0,0 @@ -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ - - -//============================================================================ -// INCLUDES -//============================================================================ -#include "MainContainerWidget.h" -#include "SectionContentWidget.h" -#include "ContainerWidget.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "Internal.h" -#include "SectionWidget.h" -#include "SectionTitleWidget.h" -#include "DropOverlay.h" -#include "Serialization.h" - -namespace ads -{ -unsigned int CContainerWidget::zOrderCounter = 0; - -//============================================================================ -CContainerWidget::CContainerWidget(CMainContainerWidget* MainContainer, QWidget *parent) - : QFrame(parent), - m_MainContainerWidget(MainContainer) -{ - m_MainLayout = new QGridLayout(); - m_MainLayout->setContentsMargins(0, 1, 0, 0); - m_MainLayout->setSpacing(0); - setLayout(m_MainLayout); -} - - -//============================================================================ -CContainerWidget::~CContainerWidget() -{ - std::cout << "CContainerWidget::~CContainerWidget()" << std::endl; - m_MainContainerWidget->m_Containers.removeAll(this); -} - - -bool CContainerWidget::event(QEvent *e) -{ - bool Result = QWidget::event(e); - if (e->type() == QEvent::WindowActivate) - { - m_zOrderIndex = ++zOrderCounter; - } - else if (e->type() == QEvent::Show && !m_zOrderIndex) - { - m_zOrderIndex = ++zOrderCounter; - } - - return Result; -} - - -unsigned int CContainerWidget::zOrderIndex() const -{ - return m_zOrderIndex; -} - -void CContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget, - const QPoint& TargetPos) -{ - SectionWidget* sectionWidget = sectionWidgetAt(TargetPos); - DropArea dropArea = InvalidDropArea; - if (sectionWidget) - { - auto dropOverlay = m_MainContainerWidget->sectionDropOverlay(); - dropOverlay->setAllowedAreas(AllAreas); - dropArea = dropOverlay->showDropOverlay(sectionWidget); - if (dropArea != InvalidDropArea) - { - std::cout << "Section Drop Content: " << dropArea << std::endl; - /*InternalContentData data; - FloatingWidget->takeContent(data); - FloatingWidget->deleteLater(); - dropContent(data, sectionWidget, dropArea, true);*/ - dropIntoSection(FloatingWidget, sectionWidget, dropArea); - } - } - - // mouse is over container - if (InvalidDropArea == dropArea) - { - dropArea = m_MainContainerWidget->dropOverlay()->dropAreaUnderCursor(); - std::cout << "Container Drop Content: " << dropArea << std::endl; - if (dropArea != InvalidDropArea) - { - // drop content - dropIntoContainer(FloatingWidget, dropArea); - } - } -} - - - -void CContainerWidget::dropIntoContainer(FloatingWidget* FloatingWidget, DropArea area) -{ - CContainerWidget* FloatingContainer = FloatingWidget->containerWidget(); - QSplitter* FloatingMainSplitter = FloatingContainer->findChild(QString(), Qt::FindDirectChildrenOnly); - - //QSplitter* oldsp = findImmediateSplitter(this); - // We use findChild here instead of findImmediateSplitter because I do not - // know what the advantage of the findImmediateSplitter function is - QSplitter* OldSplitter = this->findChild(QString(), Qt::FindDirectChildrenOnly); - //auto SectionWidgets = FloatingMainSplitter->findChildren(QString(), Qt::FindDirectChildrenOnly); - QList SectionWidgets; - for (int i = 0; i < FloatingMainSplitter->count(); ++i) - { - SectionWidgets.append(static_cast(FloatingMainSplitter->widget(i))); - } - - std::cout << "SectionWIdget[0] " << SectionWidgets[0] << " FloatingSplitter index 0" - << FloatingMainSplitter->widget(0) << std::endl; - //std::cout<< "oldsp " << oldsp << " oldsp2 " << oldsp2 << std::endl; - - Qt::Orientation orientation; - bool append; - - switch (area) - { - case TopDropArea: orientation = Qt::Vertical; append = false; break; - case RightDropArea: orientation = Qt::Horizontal; append = true; break; - case CenterDropArea: - case BottomDropArea: orientation = Qt::Vertical; append = true; break; - case LeftDropArea: orientation = Qt::Horizontal; append = false; break; - } - - auto l = m_MainLayout; - - if (!OldSplitter) - { - std::cout << "Create new splitter" << std::endl; - // we have no splitter yet - let us create one - QSplitter* sp = CMainContainerWidget::newSplitter(FloatingMainSplitter->orientation()); - if (l->count() > 0) - { - qWarning() << "Still items in layout. This should never happen."; - QLayoutItem* li = l->takeAt(0); - delete li; - } - l->addWidget(sp); - for (auto SectionWidget : SectionWidgets) - { - sp->addWidget(SectionWidget); - } - } - else if ((FloatingMainSplitter->orientation() == orientation || FloatingMainSplitter->count() == 1) && - (OldSplitter->count() == 1 || OldSplitter->orientation() == orientation)) - { - OldSplitter->setOrientation(orientation); - std::cout << "Splitter with right orientation" << std::endl; - // we have a splitter with only one item or with the right orientation so - // we can make it match the orientation of the floating splitter - for (int i = 0; i < SectionWidgets.count(); ++i) - { - if (append) - { - OldSplitter->addWidget(SectionWidgets[i]); - } - else - { - OldSplitter->insertWidget(i, SectionWidgets[i]); - } - } - } - else - { - std::cout << "Splitter with wrong orientation" << std::endl; - // we have a splitter but with the wrong orientation - QSplitter* sp = CMainContainerWidget::newSplitter(orientation); - if (append) - { - QLayoutItem* li = l->replaceWidget(OldSplitter, sp); - sp->addWidget(OldSplitter); - sp->addWidget(FloatingMainSplitter); - delete li; - } - else - { - sp->addWidget(FloatingMainSplitter); - QLayoutItem* li = l->replaceWidget(OldSplitter, sp); - sp->addWidget(OldSplitter); - delete li; - } - } - - m_Sections.append(SectionWidgets); - FloatingWidget->deleteLater(); -} - - -void CContainerWidget::dropIntoSection(FloatingWidget* FloatingWidget, - SectionWidget* targetSection, DropArea area) -{ - CContainerWidget* FloatingContainer = FloatingWidget->containerWidget(); - QSplitter* FloatingMainSplitter = FloatingContainer->findChild(QString(), - Qt::FindDirectChildrenOnly); - QList SectionWidgets; - for (int i = 0; i < FloatingMainSplitter->count(); ++i) - { - SectionWidgets.append(static_cast(FloatingMainSplitter->widget(i))); - } - - Qt::Orientation Orientation; - int InsertIndexOffset; - switch (area) - { - case TopDropArea: Orientation = Qt::Vertical; InsertIndexOffset = 0;break; - case RightDropArea: Orientation = Qt::Horizontal; InsertIndexOffset = 1;break; - case BottomDropArea: Orientation = Qt::Vertical; InsertIndexOffset = 1;break; - case LeftDropArea: Orientation = Qt::Horizontal; InsertIndexOffset = 0;break; - - case CenterDropArea: - { - QList SectionWidgets = FloatingContainer->findChildren(QString(), Qt::FindChildrenRecursively); - for (auto SectionWidget : SectionWidgets) - { - std::cout << "dropping into section CenterDropArea " << SectionWidget->contentCount() << std::endl; - while (SectionWidget->contentCount()) - { - InternalContentData data; - if (!SectionWidget->takeContentAt(0, data)) - { - qWarning() << "THIS SHOULD NOT HAPPEN!! " << 0; - return; - } - targetSection->addContent(data, false); - } - } - FloatingWidget->deleteLater(); - } - return; - - default: - break; - } - - QSplitter* targetSectionSplitter = findParentSplitter(targetSection); - std::cout << "target->orientaton " << targetSectionSplitter->orientation() - << " orien " << Orientation << std::endl; - int index = targetSectionSplitter->indexOf(targetSection); - std::cout << "targetSectionSplitter->indexOf(targetSection) " << index << std::endl; - if (targetSectionSplitter->orientation() == Orientation) - { - std::cout << "targetSectionSplitter->orientation() == Orientation" << std::endl; - if (FloatingMainSplitter->orientation() == Orientation || FloatingMainSplitter->count() == 1) - { - std::cout << "FloatingMainSplitter->orientation() == Orientation || FloatingMainSplitter->count() == 1" << std::endl; - for (int i = 0; i < SectionWidgets.count(); ++i) - { - targetSectionSplitter->insertWidget(index + InsertIndexOffset, SectionWidgets[i]); - } - } - else - { - targetSectionSplitter->insertWidget(index + InsertIndexOffset, FloatingMainSplitter); - } - } - else - { - std::cout << "targetSectionSplitter->orientation() != Orientation" << std::endl; - QSplitter* s = CMainContainerWidget::newSplitter(Orientation); - if (FloatingMainSplitter->orientation() == Orientation || FloatingMainSplitter->count() == 1) - { - std::cout << "FloatingMainSplitter->orientation() == Orientation || FloatingMainSplitter->count() == 1" << std::endl; - for (int i = 0; i < SectionWidgets.count(); ++i) - { - s->addWidget(SectionWidgets[i]); - } - } - else - { - s->addWidget(FloatingMainSplitter); - } - - if (!InsertIndexOffset) - { - s->addWidget(targetSection); - } - else - { - s->insertWidget(0, targetSection); - } - targetSectionSplitter->insertWidget(index, s); - } - FloatingWidget->deleteLater(); - m_Sections.append(SectionWidgets); -} - - - -SectionWidget* CContainerWidget::sectionWidgetAt(const QPoint& pos) const -{ - std::cout << "CContainerWidget::sectionWidgetAt m_Sections count " - << m_Sections.count() << std::endl; - for (const auto& SectionWidget : m_Sections) - { - if (SectionWidget->rect().contains(SectionWidget->mapFromGlobal(pos))) - { - return SectionWidget; - } - } - - return 0; -} - - -bool CContainerWidget::isInFrontOf(CContainerWidget* Other) const -{ - return this->zOrderIndex() > Other->zOrderIndex(); -} - -SectionWidget* CContainerWidget::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* CContainerWidget::newSectionWidget() -{ - SectionWidget* sw = new SectionWidget(m_MainContainerWidget, this); - m_Sections.append(sw); - return sw; -} - -void CContainerWidget::addSectionWidget(SectionWidget* section) -{ - ADS_Expects(section != NULL); - - if (section->containerWidget()) - { - section->containerWidget()->takeSection(section); - } - - // Create default splitter. - if (!m_Splitter) - { - m_Splitter = CMainContainerWidget::newSplitter(m_Orientation); - m_MainLayout->addWidget(m_Splitter, 0, 0); - } - if (m_Splitter->indexOf(section) != -1) - { - qWarning() << Q_FUNC_INFO << QString("Section has already been added"); - return; - } - m_Splitter->addWidget(section); - m_Sections.append(section); -} - - -void CContainerWidget::takeSection(SectionWidget* Widget) -{ - m_Sections.removeAll(Widget); -} - -SectionWidget* CContainerWidget::dropContentOuterHelper(QLayout* l, const InternalContentData& data, Qt::Orientation orientation, bool append) -{ - ADS_Expects(l != NULL); - - SectionWidget* sw = newSectionWidget(); - sw->addContent(data, true); - - QSplitter* oldsp = findImmediateSplitter(this); - if (!oldsp) - { - QSplitter* sp = CMainContainerWidget::newSplitter(orientation); - if (l->count() > 0) - { - qWarning() << "Still items in layout. This should never happen."; - QLayoutItem* li = l->takeAt(0); - delete li; - } - l->addWidget(sp); - sp->addWidget(sw); - } - else if (oldsp->orientation() == orientation - || oldsp->count() == 1) - { - oldsp->setOrientation(orientation); - if (append) - oldsp->addWidget(sw); - else - oldsp->insertWidget(0, sw); - } - else - { - QSplitter* sp = CMainContainerWidget::newSplitter(orientation); - if (append) - { - QLayoutItem* li = l->replaceWidget(oldsp, sp); - sp->addWidget(oldsp); - sp->addWidget(sw); - delete li; - } - else - { - sp->addWidget(sw); - QLayoutItem* li = l->replaceWidget(oldsp, sp); - sp->addWidget(oldsp); - delete li; - } - } - return sw; -} - -SectionWidget* CContainerWidget::insertNewSectionWidget( - const InternalContentData& data, SectionWidget* targetSection, SectionWidget* ret, - Qt::Orientation Orientation, int InsertIndexOffset) -{ - QSplitter* targetSectionSplitter = findParentSplitter(targetSection); - SectionWidget* sw = newSectionWidget(); - sw->addContent(data, true); - if (targetSectionSplitter->orientation() == Orientation) - { - const int index = targetSectionSplitter->indexOf(targetSection); - targetSectionSplitter->insertWidget(index + InsertIndexOffset, sw); - } - else - { - const int index = targetSectionSplitter->indexOf(targetSection); - QSplitter* s = CMainContainerWidget::newSplitter(Orientation); - s->addWidget(sw); - s->addWidget(targetSection); - targetSectionSplitter->insertWidget(index, s); - } - ret = sw; - return ret; -} - -SectionWidget* CContainerWidget::addSectionContent(const SectionContent::RefPtr& sc, SectionWidget* sw, DropArea area) -{ - ADS_Expects(!sc.isNull()); - - // Drop it based on "area" - InternalContentData data; - data.content = sc; - data.titleWidget = new SectionTitleWidget(sc, NULL); - data.contentWidget = new CSectionContentWidget(sc, NULL); - - connect(data.titleWidget, SIGNAL(activeTabChanged()), this, SLOT(onActiveTabChanged())); - return dropContent(data, sw, area, false); -} - - -void dumpChildSplitters(QWidget* Widget) -{ - QSplitter* ParentSplitter = dynamic_cast(Widget); - auto Sections = Widget->findChildren(QString(), Qt::FindDirectChildrenOnly); - auto Splitters = Widget->findChildren(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(sender()); - if (stw) - { - emit activeTabChanged(stw->m_Content, stw->isActiveTab()); - } -} -} // namespace ads - -//--------------------------------------------------------------------------- -// EOF ContainerWidget.cpp diff --git a/AdvancedDockingSystem/src/ContainerWidget.h b/AdvancedDockingSystem/src/ContainerWidget.h deleted file mode 100644 index 96f784c..0000000 --- a/AdvancedDockingSystem/src/ContainerWidget.h +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef ContainerWidgetH -#define ContainerWidgetH -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ - -//============================================================================ -// INCLUDES -//============================================================================ -#include - -#include "API.h" -#include "Internal.h" -#include "SectionContent.h" -#include "FloatingWidget.h" -#include "Serialization.h" -#include "DropOverlay.h" - -namespace ads -{ -class SectionWidget; -class DropOverlay; -class InternalContentData; -class CMainContainerWidget; - -/** - * @brief - */ -class CContainerWidget : public QFrame -{ - Q_OBJECT - - friend class SectionContent; - friend class SectionWidget; - friend class FloatingWidget; - friend class SectionTitleWidget; - friend class ContainerWidgetPrivate; - -public: - explicit CContainerWidget(CMainContainerWidget* MainContainerWidget, QWidget *parent = nullptr); - virtual ~CContainerWidget(); - - /** - * Returns the current zOrderIndex - */ - virtual unsigned int zOrderIndex() const; - - void dropFloatingWidget(FloatingWidget* FloatingWidget, - const QPoint& TargetPos); - - SectionWidget* sectionWidgetAt(const QPoint& GlobalPos) const; - - /** - * This function returns true if this container widgets z order index is - * higher than the index of the container widget given in Other parameter - */ - bool isInFrontOf(CContainerWidget* Other) const; - - SectionWidget* dropContent(const InternalContentData& data, SectionWidget* targetSection, DropArea area, bool autoActive = true); - - /*! - * Adds the section-content sc to this container-widget into the section-widget sw. - * If sw is not NULL, the area is used to indicate how the content should be arranged. - * Returns a pointer to the SectionWidget of the added SectionContent. Do not use it for anything else than adding more - * SectionContent elements with this method. - */ - SectionWidget* addSectionContent(const SectionContent::RefPtr& sc, SectionWidget* sw = NULL, DropArea area = CenterDropArea); - - void dumpLayout(); - - CMainContainerWidget* mainContainerWidget() const {return m_MainContainerWidget;} - - void addSectionWidget(SectionWidget* section); - - void takeSection(SectionWidget* Widget); - -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: - void dropIntoContainer(FloatingWidget* FloatingWidget, DropArea area); - void dropIntoSection(FloatingWidget* FloatingWidget, SectionWidget* targetSection, DropArea area); - virtual bool event(QEvent *e) override; - SectionWidget* newSectionWidget(); - SectionWidget* dropContentOuterHelper(QLayout* l, const InternalContentData& data, Qt::Orientation orientation, bool append); - SectionWidget* insertNewSectionWidget(const InternalContentData& data, - SectionWidget* targetSection, SectionWidget* ret, Qt::Orientation Orientation, int InsertIndexOffset); - - QList m_Sections; - // Layout stuff - QGridLayout* m_MainLayout = nullptr; - Qt::Orientation m_Orientation = Qt::Horizontal; - QPointer m_Splitter; // $mfreiholz: I'd like to remove this variable entirely, - // because it changes during user interaction anyway. - - CMainContainerWidget* m_MainContainerWidget = 0; - unsigned int m_zOrderIndex = 0; - static unsigned int zOrderCounter; - -private slots: - void onActiveTabChanged(); -}; - -} // namespace ads - -//--------------------------------------------------------------------------- -#endif // ContainerWidgetH diff --git a/AdvancedDockingSystem/src/DropOverlay.cpp b/AdvancedDockingSystem/src/DropOverlay.cpp deleted file mode 100644 index ea52837..0000000 --- a/AdvancedDockingSystem/src/DropOverlay.cpp +++ /dev/null @@ -1,461 +0,0 @@ -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ - -#include "DropOverlay.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace ads -{ - -// Helper ///////////////////////////////////////////////////////////// - -static QPixmap createDropIndicatorPixmap(const QPalette& pal, const QSizeF& size, DropArea dropArea) -{ - const QColor borderColor = pal.color(QPalette::Active, QPalette::Highlight); - const QColor backgroundColor = pal.color(QPalette::Active, QPalette::Base); - const QColor areaBackgroundColor = pal.color(QPalette::Active, QPalette::Highlight).lighter(150); - - QPixmap pm(size.width(), size.height()); - pm.fill(QColor(0, 0, 0, 0)); - - QPainter p(&pm); - QPen pen = p.pen(); - QRectF baseRect(pm.rect()); - - // Fill - p.fillRect(baseRect, backgroundColor); - - // Drop area rect. - p.save(); - QRectF areaRect; - QLineF areaLine; - QLinearGradient gradient; - switch (dropArea) - { - case TopDropArea: - areaRect = QRectF(baseRect.x(), baseRect.y(), baseRect.width(), baseRect.height() * .5f); - areaLine = QLineF(areaRect.bottomLeft(), areaRect.bottomRight()); - gradient.setStart(areaRect.topLeft()); - gradient.setFinalStop(areaRect.bottomLeft()); - break; - case RightDropArea: - areaRect = QRectF(baseRect.width() * .5f, baseRect.y(), baseRect.width() * .5f, baseRect.height()); - areaLine = QLineF(areaRect.topLeft(), areaRect.bottomLeft()); - gradient.setStart(areaRect.topLeft()); - gradient.setFinalStop(areaRect.topRight()); - break; - case BottomDropArea: - areaRect = QRectF(baseRect.x(), baseRect.height() * .5f, baseRect.width(), baseRect.height() * .5f); - areaLine = QLineF(areaRect.topLeft(), areaRect.topRight()); - gradient.setStart(areaRect.topLeft()); - gradient.setFinalStop(areaRect.bottomLeft()); - break; - case LeftDropArea: - areaRect = QRectF(baseRect.x(), baseRect.y(), baseRect.width() * .5f, baseRect.height()); - areaLine = QLineF(areaRect.topRight(), areaRect.bottomRight()); - gradient.setStart(areaRect.topLeft()); - gradient.setFinalStop(areaRect.topRight()); - break; - default: - break; - } - if (areaRect.isValid()) - { - gradient.setColorAt(0.f, areaBackgroundColor); - gradient.setColorAt(1.f, areaBackgroundColor.lighter(120)); - p.fillRect(areaRect, gradient); - - pen = p.pen(); - pen.setColor(borderColor); - pen.setStyle(Qt::DashLine); - p.setPen(pen); - p.drawLine(areaLine); - } - p.restore(); - - p.save(); - pen = p.pen(); - pen.setColor(borderColor); - pen.setWidth(1); - - p.setPen(pen); - p.drawRect(baseRect.adjusted(0, 0, -pen.width(), -pen.width())); - p.restore(); - return pm; -} - -QWidget* DropOverlay::createDropIndicatorWidget(DropArea dropArea) -{ - QLabel* l = new QLabel(); - l->setObjectName("DropAreaLabel"); - - const qreal metric = static_cast(l->fontMetrics().height()) * 2.f; - const QSizeF size(metric, metric); - - l->setPixmap(createDropIndicatorPixmap(l->palette(), size, dropArea)); - l->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint); - l->setAttribute(Qt::WA_TranslucentBackground); - return l; -} - -/////////////////////////////////////////////////////////////////////// - -DropOverlay::DropOverlay(QWidget* parent, eMode Mode) : - QFrame(parent), - _allowedAreas(InvalidDropArea), - _cross(new DropOverlayCross(this)), - _lastLocation(InvalidDropArea) -{ - setWindowFlags(Qt::Tool | Qt::FramelessWindowHint); - setWindowOpacity(0.2); - setWindowTitle("DropOverlay"); - setAttribute(Qt::WA_NoSystemBackground); - setAttribute(Qt::WA_TranslucentBackground); - - QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom); - l->setSpacing(0); - setLayout(l); - - _cross->setupOverlayCross(Mode); - _cross->setVisible(false); - setVisible(false); -} - -DropOverlay::~DropOverlay() -{ -} - -void DropOverlay::setAllowedAreas(DropAreas areas) -{ - if (areas == _allowedAreas) - return; - _allowedAreas = areas; - - _cross->reset(); -} - -DropAreas DropOverlay::allowedAreas() const -{ - return _allowedAreas; -} - - -DropArea DropOverlay::dropAreaUnderCursor() const -{ - return _cross->cursorLocation(); -} - -DropArea DropOverlay::showDropOverlay(QWidget* target) -{ - //std::cout << "DropOverlay::showDropOverlay(QWidget* target)" << std::endl; - if (_target == target) - { - qInfo() << "_target == target"; - // Hint: We could update geometry of overlay here. - DropArea da = dropAreaUnderCursor(); - if (da != _lastLocation) - { - qInfo() << "repaint()"; - repaint(); - _lastLocation = da; - } - return da; - } - - _target = target; - _targetRect = QRect(); - _lastLocation = InvalidDropArea; - - // Move it over the target. - resize(target->size()); - move(target->mapToGlobal(target->rect().topLeft())); - show(); - return dropAreaUnderCursor(); -} - -void DropOverlay::showDropOverlay(QWidget* target, const QRect& targetAreaRect) -{ - qInfo() << "DropOverlay::showDropOverlay(QWidget* target, const QRect& targetAreaRect)"; - if (_target == target && _targetRect == targetAreaRect) - { - return; - } - //hideDropOverlay(); - _target = target; - _targetRect = targetAreaRect; - _lastLocation = InvalidDropArea; - - // Move it over the target's area. - resize(targetAreaRect.size()); - move(target->mapToGlobal(QPoint(targetAreaRect.x(), targetAreaRect.y()))); - show(); - return; -} - -void DropOverlay::hideDropOverlay() -{ - qInfo() << "hideDropOverlay() _fullAreaDrop = false"; - hide(); -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - _target.clear(); -#else - _target = 0; -#endif - _targetRect = QRect(); - _lastLocation = InvalidDropArea; -} - -void DropOverlay::paintEvent(QPaintEvent*) -{ - // Draw rect based on location - QRect r = rect(); - const DropArea da = dropAreaUnderCursor(); - std::cout << "CursorLocation: " << dropAreaUnderCursor() << std::endl; - switch (da) - { - case TopDropArea: r.setHeight(r.height() / 2); break; - case RightDropArea: r.setX(r.width() / 2); break; - case BottomDropArea: r.setY(r.height() / 2); break; - case LeftDropArea: r.setWidth(r.width() / 2); break; - case CenterDropArea: r = rect();break; - default: return; - } - QPainter painter(this); - QColor Color = palette().color(QPalette::Active, QPalette::Highlight); - painter.fillRect(r, QBrush(Color, Qt::Dense4Pattern)); - painter.setBrush(QBrush(Color)); - painter.drawRect(r); -} - -void DropOverlay::showEvent(QShowEvent*) -{ - _cross->show(); - QWidget* w = parentWidget() ? parentWidget() : _target.data(); - QRect WidgetRect = w->rect(); - QPoint Pos(WidgetRect.left(), WidgetRect.center().y()); -} - -void DropOverlay::hideEvent(QHideEvent*) -{ - _cross->hide(); -} - -void DropOverlay::resizeEvent(QResizeEvent* e) -{ - qInfo() << "DropOverlay::resizeEvent" << e->size(); - _cross->resize(e->size()); -} - -void DropOverlay::moveEvent(QMoveEvent* e) -{ - qInfo() << "DropOverlay::moveEvent" << e->pos(); - _cross->move(e->pos()); -} - -static int areaAlignment(const DropArea area) -{ - switch (area) - { - case TopDropArea: return (int) Qt::AlignHCenter | Qt::AlignBottom; - case RightDropArea: return (int) Qt::AlignLeft | Qt::AlignVCenter; - case BottomDropArea: return (int) Qt::AlignHCenter | Qt::AlignTop; - case LeftDropArea: return (int) Qt::AlignRight | Qt::AlignVCenter; - case CenterDropArea: return (int) Qt::AlignCenter; - default: return Qt::AlignCenter; - } -} - - -QPoint DropOverlayCross::areaGridPosition(const DropArea area) -{ - if (DropOverlay::ModeSectionOverlay == m_Mode) - { - switch (area) - { - case TopDropArea: return QPoint(1, 2); - case RightDropArea: return QPoint(2, 3); - case BottomDropArea: return QPoint(3, 2); - case LeftDropArea: return QPoint(2, 1); - case CenterDropArea: return QPoint(2, 2); - default: return QPoint(); - } - } - else - { - switch (area) - { - case TopDropArea: return QPoint(0, 2); - case RightDropArea: return QPoint(2, 4); - case BottomDropArea: return QPoint(4, 2); - case LeftDropArea: return QPoint(2, 0); - case CenterDropArea: return QPoint(2, 2); - default: return QPoint(); - } - } -} - - -DropOverlayCross::DropOverlayCross(DropOverlay* overlay) : - QWidget(overlay->parentWidget()), - m_DropOverlay(overlay) -{ - setWindowFlags(Qt::Tool | Qt::FramelessWindowHint); - setWindowTitle("DropOverlayCross"); - setAttribute(Qt::WA_TranslucentBackground); - - m_GridLayout = new QGridLayout(); - m_GridLayout->setSpacing(6); - setLayout(m_GridLayout); -} - -DropOverlayCross::~DropOverlayCross() -{ -} - - -void DropOverlayCross::setupOverlayCross(DropOverlay::eMode Mode) -{ - m_Mode = Mode; - - QHash areaWidgets; - areaWidgets.insert(TopDropArea, DropOverlay::createDropIndicatorWidget(TopDropArea)); - areaWidgets.insert(RightDropArea, DropOverlay::createDropIndicatorWidget(RightDropArea)); - areaWidgets.insert(BottomDropArea, DropOverlay::createDropIndicatorWidget(BottomDropArea)); - areaWidgets.insert(LeftDropArea, DropOverlay::createDropIndicatorWidget(LeftDropArea)); - areaWidgets.insert(CenterDropArea, DropOverlay::createDropIndicatorWidget(CenterDropArea)); - - setAreaWidgets(areaWidgets); -} - - -void DropOverlayCross::setAreaWidgets(const QHash& widgets) -{ - // Delete old widgets. - QMutableHashIterator i(m_DropIndicatorWidgets); - while (i.hasNext()) - { - i.next(); - QWidget* widget = i.value(); - m_GridLayout->removeWidget(widget); - delete widget; - i.remove(); - } - - // Insert new widgets into grid. - m_DropIndicatorWidgets = widgets; - QHashIterator i2(m_DropIndicatorWidgets); - while (i2.hasNext()) - { - i2.next(); - const DropArea area = i2.key(); - QWidget* widget = i2.value(); - QPoint p = areaGridPosition(area); - m_GridLayout->addWidget(widget, p.x(), p.y(), (Qt::Alignment) areaAlignment(area)); - } - - if (DropOverlay::ModeSectionOverlay == m_Mode) - { - m_GridLayout->setContentsMargins(0, 0, 0, 0); - m_GridLayout->setRowStretch(0, 1); - m_GridLayout->setRowStretch(1, 0); - m_GridLayout->setRowStretch(2, 0); - m_GridLayout->setRowStretch(3, 0); - m_GridLayout->setRowStretch(4, 1); - - m_GridLayout->setColumnStretch(0, 1); - m_GridLayout->setColumnStretch(1, 0); - m_GridLayout->setColumnStretch(2, 0); - m_GridLayout->setColumnStretch(3, 0); - m_GridLayout->setColumnStretch(4, 1); - } - else - { - m_GridLayout->setContentsMargins(4, 4, 4, 4); - m_GridLayout->setRowStretch(0, 0); - m_GridLayout->setRowStretch(1, 1); - m_GridLayout->setRowStretch(2, 1); - m_GridLayout->setRowStretch(3, 1); - m_GridLayout->setRowStretch(4, 0); - - m_GridLayout->setColumnStretch(0, 0); - m_GridLayout->setColumnStretch(1, 1); - m_GridLayout->setColumnStretch(2, 1); - m_GridLayout->setColumnStretch(3, 1); - m_GridLayout->setColumnStretch(4, 0); - } - reset(); -} - -DropArea DropOverlayCross::cursorLocation() const -{ - const QPoint pos = mapFromGlobal(QCursor::pos()); - QHashIterator i(m_DropIndicatorWidgets); - while (i.hasNext()) - { - i.next(); - if (m_DropOverlay->allowedAreas().testFlag(i.key()) - && i.value() - && i.value()->isVisible() - && i.value()->geometry().contains(pos)) - { - return i.key(); - } - } - return InvalidDropArea; -} - -void DropOverlayCross::showEvent(QShowEvent*) -{ - resize(m_DropOverlay->size()); - move(m_DropOverlay->pos()); -} - -void DropOverlayCross::reset() -{ - QList allAreas; - allAreas << TopDropArea << RightDropArea - << BottomDropArea << LeftDropArea << CenterDropArea; - const DropAreas allowedAreas = m_DropOverlay->allowedAreas(); - - // Update visibility of area widgets based on allowedAreas. - for (int i = 0; i < allAreas.count(); ++i) - { - QPoint p = areaGridPosition(allAreas.at(i)); - QLayoutItem* item = m_GridLayout->itemAtPosition(p.x(), p.y()); - QWidget* w = nullptr; - if (item && (w = item->widget()) != nullptr) - { - w->setVisible(allowedAreas.testFlag(allAreas.at(i))); - } - } -} - -} // namespace ads diff --git a/AdvancedDockingSystem/src/DropOverlay.h b/AdvancedDockingSystem/src/DropOverlay.h deleted file mode 100644 index 9c4cd85..0000000 --- a/AdvancedDockingSystem/src/DropOverlay.h +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef DROP_OVERLAY_H -#define DROP_OVERLAY_H -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ -#include -#include -#include -#include -class QGridLayout; - -#include "API.h" - -namespace ads -{ -class DropOverlayCross; - -/*! - * DropOverlay paints a translucent rectangle over another widget. The geometry - * of the rectangle is based on the mouse location. - */ -class ADS_EXPORT_API DropOverlay : public QFrame -{ - Q_OBJECT - friend class DropOverlayCross; - -public: - enum eMode - { - ModeSectionOverlay, - ModeContainerOverlay - }; - - DropOverlay(QWidget* parent, eMode Mode = ModeSectionOverlay); - virtual ~DropOverlay(); - - void setAllowedAreas(DropAreas areas); - - /** - * Returns flags with all allowed drop areas - */ - DropAreas allowedAreas() const; - - /** - * Returns the drop area under the current cursor location - */ - DropArea dropAreaUnderCursor() const; - - DropArea showDropOverlay(QWidget* target); - void showDropOverlay(QWidget* target, const QRect& targetAreaRect); - void hideDropOverlay(); - - /** - * Creates a drop indicator widget for the given drop area - */ - static QWidget* createDropIndicatorWidget(DropArea dropArea); - -protected: - virtual void paintEvent(QPaintEvent *e); - virtual void showEvent(QShowEvent* e); - virtual void hideEvent(QHideEvent* e); - virtual void resizeEvent(QResizeEvent* e); - virtual void moveEvent(QMoveEvent* e); - -private: - DropAreas _allowedAreas; - DropOverlayCross* _cross; - QPointer _target; - QRect _targetRect; - DropArea _lastLocation; -}; - -/*! - * DropOverlayCross shows a cross with 5 different drop area possibilities. - * I could have handled everything inside DropOverlay, but because of some - * styling issues it's better to have a separate class for the cross. - */ -class DropOverlayCross : public QWidget -{ - Q_OBJECT - friend class DropOverlay; - -public: - DropOverlayCross(DropOverlay* overlay); - virtual ~DropOverlayCross(); - - DropArea cursorLocation() const; - void setupOverlayCross(DropOverlay::eMode Mode); - -protected: - virtual void showEvent(QShowEvent* e); - void setAreaWidgets(const QHash& widgets); - -private: - void reset(); - QPoint areaGridPosition(const DropArea area); - -private: - DropOverlay::eMode m_Mode = DropOverlay::ModeSectionOverlay; - DropOverlay* m_DropOverlay; - QHash m_DropIndicatorWidgets; - QGridLayout* m_GridLayout; -}; - -} // namespace ads -#endif diff --git a/AdvancedDockingSystem/src/FloatingWidget.cpp b/AdvancedDockingSystem/src/FloatingWidget.cpp deleted file mode 100644 index 31a5e5c..0000000 --- a/AdvancedDockingSystem/src/FloatingWidget.cpp +++ /dev/null @@ -1,422 +0,0 @@ -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ - -#include "FloatingWidget.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "SectionTitleWidget.h" -#include "Internal.h" -#include "SectionWidget.h" -#include "ContainerWidget.h" -#include "MainContainerWidget.h" -#include "SectionContentWidget.h" - -#include - -namespace ads -{ - -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); - Layout->setSpacing(0); - setLayout(Layout); - - if (Flags.testFlag(SectionContent::Maximizable)) - { - QPushButton* Button = new QPushButton(); - Button->setObjectName("maximizeButton"); - Button->setFlat(true); - Button->setIcon(style()->standardIcon(QStyle::SP_TitleBarMaxButton)); - Button->setToolTip(tr("Close")); - Button->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); - Layout->addWidget(Button); - connect(Button, SIGNAL(clicked(bool)), this, SLOT(onMaximizeButtonClicked())); - } - - 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("Maximize")); - closeButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); - Layout->addWidget(closeButton); - connect(closeButton, SIGNAL(clicked(bool)), this, SIGNAL(closeButtonClicked())); - } - - if (Flags == 0) - { - Layout->setContentsMargins(6, 6, 6, 6); - } - else - { - Layout->setContentsMargins(6, 0, 0, 0); - } -} - -FloatingWidget* CFloatingTitleWidget::floatingWidget() const -{ - return dynamic_cast(parentWidget()); -} - -CMainContainerWidget* CFloatingTitleWidget::mainContainerWidget() const -{ - return floatingWidget()->mainContainerWidget(); -} - - -void CFloatingTitleWidget::mousePressEvent(QMouseEvent* ev) -{ - if (ev->button() == Qt::LeftButton) - { - ev->accept(); - m_DragStartPosition = floatingWidget()->pos(); - m_DragStartMousePosition = ev->globalPos(); - return; - } - QFrame::mousePressEvent(ev); -} - - -void CFloatingTitleWidget::mouseReleaseEvent(QMouseEvent* ev) -{ - -} - - -void CFloatingTitleWidget::mouseMoveEvent(QMouseEvent* ev) -{ - if (!(ev->buttons() & Qt::LeftButton)) - { - QFrame::mouseMoveEvent(ev); - return; - } - - floatingWidget()->updateDropOverlays(ev->globalPos()); - ev->accept(); - moveFloatingWidget(ev); -} - - -void CFloatingTitleWidget::moveFloatingWidget(QMouseEvent* ev) -{ - const QPoint DragDistance = ev->globalPos() - m_DragStartMousePosition; - const QPoint moveToPos = m_DragStartPosition + DragDistance; - floatingWidget()->move(moveToPos); -} - - -void CFloatingTitleWidget::onMaximizeButtonClicked() -{ - if (floatingWidget()->isMaximized()) - { - floatingWidget()->showNormal(); - } - else - { - floatingWidget()->showMaximized(); - } -} - - - - -FloatingWidget::FloatingWidget(CMainContainerWidget* MainContainer, SectionContent::RefPtr sc, SectionTitleWidget* titleWidget, CSectionContentWidget* contentWidget, QWidget* parent) : - QWidget(MainContainer, Qt::Window), - m_MainContainerWidget(MainContainer) -{ - QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom); - l->setContentsMargins(0, 0, 0, 0); - l->setSpacing(0); - setLayout(l); - m_ContainerWidget = new CContainerWidget(m_MainContainerWidget, this); - m_MainContainerWidget->m_Containers.append(m_ContainerWidget); - 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; - m_MainContainerWidget->m_Floatings.append(this); -} - - -FloatingWidget::FloatingWidget(CMainContainerWidget* MainContainer, SectionWidget* sectionWidget) - : QWidget(MainContainer, Qt::Window), - m_MainContainerWidget(MainContainer) -{ - QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom); - l->setContentsMargins(0, 0, 0, 0); - l->setSpacing(0); - setLayout(l); - - m_ContainerWidget = new CContainerWidget(m_MainContainerWidget, this); - m_MainContainerWidget->m_Containers.append(m_ContainerWidget); - l->addWidget(m_ContainerWidget, 1); - - m_ContainerWidget->addSectionWidget(sectionWidget); - m_ContainerWidget->show(); - m_zOrderIndex = ++zOrderCounter; - m_MainContainerWidget->m_Floatings.append(this); -} - - -FloatingWidget::~FloatingWidget() -{ - std::cout << "FloatingWidget::~FloatingWidget" << std::endl; - m_MainContainerWidget->m_Floatings.removeAll(this); -} - -bool FloatingWidget::takeContent(InternalContentData& data) -{ - // TODO remove takeContent function - /*data.content = _content; - data.titleWidget = _titleWidget; - data.contentWidget = _contentWidget; - - //_titleLayout->removeWidget(_titleWidget); - _titleWidget->setParent(m_MainContainerWidget); - _titleWidget = NULL; - - layout()->removeWidget(_contentWidget); - _contentWidget->setParent(m_MainContainerWidget); - _contentWidget = NULL;*/ - - return true; -} - -void FloatingWidget::onCloseButtonClicked() -{ - //m_MainContainerWidget->hideSectionContent(_content); -} - - -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); - } -} - -void FloatingWidget::changeEvent(QEvent *event) -{ - QWidget::changeEvent(event); - if (event->type() == QEvent::ActivationChange && isActiveWindow()) - { - std::cout << "FloatingWidget::changeEvent QEvent::ActivationChange " << std::endl; - m_zOrderIndex = ++zOrderCounter; - return; - } -} - - -void FloatingWidget::moveEvent(QMoveEvent *event) -{ - QWidget::moveEvent(event); - if (m_DraggingActive && qApp->mouseButtons().testFlag(Qt::LeftButton)) - { - //std::cout << "Dragging" << std::endl; - updateDropOverlays(QCursor::pos()); - } -} - -bool FloatingWidget::event(QEvent *e) -{ - if ((e->type() == QEvent::NonClientAreaMouseButtonPress)) - { - if (QGuiApplication::mouseButtons() == Qt::LeftButton) - { - std::cout << "FloatingWidget::event Event::NonClientAreaMouseButtonPress" << e->type() << std::endl; - setDraggingActive(true); - } - } - else if (e->type() == QEvent::NonClientAreaMouseButtonDblClick) - { - std::cout << "FloatingWidget::event QEvent::NonClientAreaMouseButtonDblClick" << std::endl; - setDraggingActive(false); - } - else if ((e->type() == QEvent::NonClientAreaMouseButtonRelease) && m_DraggingActive) - { - std::cout << "FloatingWidget::event QEvent::NonClientAreaMouseButtonRelease" << std::endl; - titleMouseReleaseEvent(); - } - return QWidget::event(e); -} - - -bool FloatingWidget::eventFilter(QObject *watched, QEvent *event) -{ - if (event->type() == QEvent::MouseButtonRelease) - { - std::cout << "FloatingWidget::eventFilter QEvent::MouseButtonRelease" << std::endl; - titleMouseReleaseEvent(); - } - else if (event->type() == QEvent::MouseMove) - { - if (m_DraggingActive) - { - QMouseEvent* MouseEvent = dynamic_cast(event); - int BorderSize = (frameSize().width() - size().width()) / 2; - const QPoint moveToPos = QCursor::pos() - m_DragStartMousePosition - QPoint(BorderSize, 0); - move(moveToPos); - return true; - } - } - return false; -} - - -void FloatingWidget::startFloating(const QPoint& Pos) -{ - setDraggingActive(true); - QPoint TargetPos = QCursor::pos() - Pos; - move(TargetPos); - show(); - m_DragStartMousePosition = Pos; - m_DragStartPosition = this->pos(); -} - - -void FloatingWidget::titleMouseReleaseEvent() -{ - setDraggingActive(false); - if (!m_DropContainer) - { - return; - } - - std::cout << "Dropped" << std::endl; - CMainContainerWidget* MainContainerWidget = mainContainerWidget(); - m_DropContainer->dropFloatingWidget(this, QCursor::pos()); - MainContainerWidget->dropOverlay()->hideDropOverlay(); - MainContainerWidget->sectionDropOverlay()->hideDropOverlay(); -} - - -unsigned int FloatingWidget::zOrderIndex() const -{ - return m_zOrderIndex; -} - - -void FloatingWidget::updateDropOverlays(const QPoint& GlobalPos) -{ - if (!isVisible()) - { - return; - } - CMainContainerWidget* MainContainerWidget = mainContainerWidget(); - auto Containers = MainContainerWidget->m_Containers; - CContainerWidget* TopContainer = nullptr; - for (auto ContainerWidget : Containers) - { - if (!ContainerWidget->isVisible()) - { - continue; - } - - if (containerWidget() == ContainerWidget) - { - continue; - } - - QPoint MappedPos = ContainerWidget->mapFromGlobal(GlobalPos); - if (ContainerWidget->rect().contains(MappedPos)) - { - std::cout << "Container " << ContainerWidget << " contains mousepos" << std::endl; - if (!TopContainer || ContainerWidget->isInFrontOf(TopContainer)) - { - TopContainer = ContainerWidget; - } - } - } - - 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(AllAreas); - SectionDropOverlay->showDropOverlay(sectionwidget); - } - else - { - SectionDropOverlay->hideDropOverlay(); - } - - - if (TopContainer) - { - ContainerDropOverlay->showDropOverlay(TopContainer); - ContainerDropOverlay->raise(); - } - else - { - ContainerDropOverlay->hideDropOverlay(); - } -} - -} // namespace ads diff --git a/AdvancedDockingSystem/src/FloatingWidget.h b/AdvancedDockingSystem/src/FloatingWidget.h deleted file mode 100644 index d49d4f8..0000000 --- a/AdvancedDockingSystem/src/FloatingWidget.h +++ /dev/null @@ -1,116 +0,0 @@ -#ifndef FLOATINGWIDGET_H -#define FLOATINGWIDGET_H -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ -#include -#include -class QBoxLayout; - -#include "API.h" -#include "SectionContent.h" - -namespace ads -{ - -class CMainContainerWidget; -class SectionTitleWidget; -class CSectionContentWidget; -class InternalContentData; -class SectionWidget; -class CContainerWidget; -class FloatingWidget; - -class CFloatingTitleWidget : public QFrame -{ - Q_OBJECT -private: - QPoint m_DragStartPosition; - QPoint m_DragStartMousePosition; - FloatingWidget* floatingWidget() const; - CMainContainerWidget* mainContainerWidget() const; - void moveFloatingWidget(QMouseEvent* ev); - -private slots: - void onMaximizeButtonClicked(); - -protected: - virtual void mousePressEvent(QMouseEvent* ev); - virtual void mouseReleaseEvent(QMouseEvent* ev); - virtual void mouseMoveEvent(QMouseEvent* ev); - -public: - CFloatingTitleWidget(SectionContent::Flags Flags, FloatingWidget* Parent); - -signals: - void closeButtonClicked(); -}; - - -// FloatingWidget holds and displays SectionContent as a floating window. -// It can be resized, moved and dropped back into a SectionWidget. -class FloatingWidget : public QWidget -{ - Q_OBJECT - - friend class CMainContainerWidget; - friend class CFloatingTitleWidget; - -public: - FloatingWidget(CMainContainerWidget* container, SectionContent::RefPtr sc, SectionTitleWidget* titleWidget, CSectionContentWidget* contentWidget, QWidget* parent = NULL); - FloatingWidget(CMainContainerWidget* container, SectionWidget* sectionWidget); - virtual ~FloatingWidget(); - - /** - * Returns the current zOrderIndex - */ - unsigned int zOrderIndex() const; - - CContainerWidget* containerWidget() const {return m_ContainerWidget;} - CMainContainerWidget* mainContainerWidget() const {return m_MainContainerWidget;} - -public://private: - bool takeContent(InternalContentData& data); - - void startFloating(const QPoint& Pos); - -protected: - virtual void changeEvent(QEvent *event) override; - virtual void moveEvent(QMoveEvent *event) override; - virtual bool event(QEvent *e); - void titleMouseReleaseEvent(); - virtual bool eventFilter(QObject *watched, QEvent *event) override; - void updateDropOverlays(const QPoint& GlobalPos); - -private slots: - void onCloseButtonClicked(); - -private: - void setDraggingActive(bool Active); - - CMainContainerWidget* m_MainContainerWidget; - CContainerWidget* m_ContainerWidget; - CContainerWidget* m_DropContainer; - bool m_DraggingActive = false; - unsigned int m_zOrderIndex = 0; - QPoint m_DragStartPosition; - QPoint m_DragStartMousePosition; - static unsigned int zOrderCounter; -}; - -} // namespace ads -#endif diff --git a/AdvancedDockingSystem/src/Internal.cpp b/AdvancedDockingSystem/src/Internal.cpp deleted file mode 100644 index a9c42d1..0000000 --- a/AdvancedDockingSystem/src/Internal.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ - -#include "Internal.h" - -namespace ads -{ - -InternalContentData::InternalContentData() : - titleWidget(NULL), - contentWidget(NULL) -{ -} - -InternalContentData::~InternalContentData() -{ -} - -} // namespace ads diff --git a/AdvancedDockingSystem/src/Internal.h b/AdvancedDockingSystem/src/Internal.h deleted file mode 100644 index fd6ef55..0000000 --- a/AdvancedDockingSystem/src/Internal.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef ADS_INTERNAL_HEADER -#define ADS_INTERNAL_HEADER -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ -#include -#include - -#include "API.h" - -namespace ads -{ -class SectionContent; -class SectionTitleWidget; -class CSectionContentWidget; - - -class InternalContentData -{ -public: - typedef QSharedPointer RefPtr; - typedef QWeakPointer WeakPtr; - - InternalContentData(); - ~InternalContentData(); - - QSharedPointer content; - SectionTitleWidget* titleWidget; - CSectionContentWidget* contentWidget; -}; - - -class HiddenSectionItem -{ -public: - HiddenSectionItem() : - preferredSectionId(-1), - preferredSectionIndex(-1) - {} - - int preferredSectionId; - int preferredSectionIndex; - InternalContentData data; -}; - - -} // namespace ads -#endif diff --git a/AdvancedDockingSystem/src/MainContainerWidget.cpp b/AdvancedDockingSystem/src/MainContainerWidget.cpp deleted file mode 100644 index 067c52b..0000000 --- a/AdvancedDockingSystem/src/MainContainerWidget.cpp +++ /dev/null @@ -1,1029 +0,0 @@ -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ - -#include "SectionContentWidget.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Internal.h" -#include "SectionWidget.h" -#include "SectionTitleWidget.h" -#include "DropOverlay.h" -#include "Serialization.h" - -#include -#include "MainContainerWidget.h" - -namespace ads -{ - - -QSplitter* CMainContainerWidget::newSplitter(Qt::Orientation orientation, QWidget* parent) -{ - QSplitter* s = new QSplitter(orientation, parent); - s->setProperty("ads-splitter", QVariant(true)); - s->setChildrenCollapsible(false); - s->setOpaqueResize(false); - return s; -} - - -CMainContainerWidget::CMainContainerWidget(QWidget *parent) : - CContainerWidget(this, parent) -{ - m_SectionDropOverlay = new DropOverlay(this, DropOverlay::ModeSectionOverlay); - m_ContainerDropOverlay = new DropOverlay(this, DropOverlay::ModeContainerOverlay); - m_ContainerDropOverlay->setAttribute(Qt::WA_TransparentForMouseEvents); - m_ContainerDropOverlay->setWindowFlags(m_ContainerDropOverlay->windowFlags() | Qt::WindowTransparentForInput); - m_Containers.append(this); -} - -CMainContainerWidget::~CMainContainerWidget() -{ - // Note: It's required to delete in 2 steps - // Remove from list, and then delete. - // Because the destrcutor of objects wants to modify the current - // iterating list as well... :-/ - while (!m_Sections.isEmpty()) - { - SectionWidget* sw = m_Sections.takeLast(); - delete sw; - } - while (!m_Floatings.isEmpty()) - { - FloatingWidget* fw = m_Floatings.takeLast(); - delete fw; - } - m_SectionContentIdMap.clear(); - m_SectionContentNameMap.clear(); - m_SectionWidgetIdMap.clear(); -} - - -bool CMainContainerWidget::removeSectionContent(const SectionContent::RefPtr& sc) -{ - ADS_Expects(!sc.isNull()); - - // Hide the content. - // The hideSectionContent() automatically deletes no longer required SectionWidget objects. - if (!hideSectionContent(sc)) - return false; - - // Begin of ugly work arround. - // TODO The hideSectionContent() method should take care of deleting FloatingWidgets and SectionWidgets, - // but only cares about SectionWidgets right now. So we need to check whether it was a FloatingWidget - // and delete it. - bool found = false; - for (int i = 0; i < m_Floatings.count(); ++i) - { - FloatingWidget* fw = m_Floatings.at(i); - InternalContentData data; - if (!(found = fw->takeContent(data))) - continue; - m_Floatings.removeAll(fw); - delete fw; - delete data.titleWidget; - delete data.contentWidget; - break; - } // End of ugly work arround. - - // Get from hidden contents and delete associated internal stuff. - if (!m_HiddenSectionContents.contains(sc->uid())) - { - qFatal("Something went wrong... The content should have been there :-/"); - return false; - } - - // Delete internal objects. - HiddenSectionItem hsi = m_HiddenSectionContents.take(sc->uid()); - delete hsi.data.titleWidget; - delete hsi.data.contentWidget; - - // Hide the custom widgets of SectionContent. - // ... should we? ... - - return true; -} - -bool CMainContainerWidget::showSectionContent(const SectionContent::RefPtr& sc) -{ - ADS_Expects(!sc.isNull()); - - // Search SC in floatings - for (int i = 0; i < m_Floatings.count(); ++i) - { - FloatingWidget* fw = m_Floatings.at(i); - /*const bool found = fw->content()->uid() == sc->uid(); - if (!found) - continue;*/ - fw->setVisible(true); - //fw->_titleWidget->setVisible(true); - //fw->_contentWidget->setVisible(true); - emit sectionContentVisibilityChanged(sc, true); - return true; - } - - // Search SC in hidden sections - // Try to show them in the last position, otherwise simply append - // it to the first section (or create a new section?) - if (m_HiddenSectionContents.contains(sc->uid())) - { - const HiddenSectionItem hsi = m_HiddenSectionContents.take(sc->uid()); - hsi.data.titleWidget->setVisible(true); - hsi.data.contentWidget->setVisible(true); - SectionWidget* sw = nullptr; - if (hsi.preferredSectionId > 0 && (sw = m_SectionWidgetIdMap.value(hsi.preferredSectionId)) != nullptr) - { - sw->addContent(hsi.data, true); - emit sectionContentVisibilityChanged(sc, true); - return true; - } - else if (m_Sections.size() > 0 && (sw = m_Sections.first()) != NULL) - { - sw->addContent(hsi.data, true); - emit sectionContentVisibilityChanged(sc, true); - return true; - } - else - { - sw = newSectionWidget(); - addSectionWidget(sw); - sw->addContent(hsi.data, true); - emit sectionContentVisibilityChanged(sc, true); - return true; - } - } - - // Already visible? - // TODO - qWarning("Unable to show SectionContent, don't know where 8-/ (already visible?)"); - return false; -} - -bool CMainContainerWidget::hideSectionContent(const SectionContent::RefPtr& sc) -{ - ADS_Expects(!sc.isNull()); - - // Search SC in floatings - // We can simply hide floatings, nothing else required. - for (int i = 0; i < m_Floatings.count(); ++i) - { - /*const bool found = m_Floatings.at(i)->content()->uid() == sc->uid(); - if (!found) - continue;*/ - m_Floatings.at(i)->setVisible(false); - emit sectionContentVisibilityChanged(sc, false); - return true; - } - - // Search SC in sections - // It's required to remove the SC from SW completely and hold it in a - // separate list as long as a "showSectionContent" gets called for the SC again. - // In case that the SW does not have any other SCs, we need to delete it. - for (int i = 0; i < m_Sections.count(); ++i) - { - SectionWidget* sw = m_Sections.at(i); - const bool found = sw->indexOfContent(sc) >= 0; - if (!found) - continue; - - HiddenSectionItem hsi; - hsi.preferredSectionId = sw->uid(); - hsi.preferredSectionIndex = sw->indexOfContent(sc); - if (!sw->takeContent(sc->uid(), hsi.data)) - return false; - - hsi.data.titleWidget->setVisible(false); - hsi.data.contentWidget->setVisible(false); - m_HiddenSectionContents.insert(sc->uid(), hsi); - - if (sw->contents().isEmpty()) - { - delete sw; - sw = NULL; - deleteEmptySplitter(this); - } - emit sectionContentVisibilityChanged(sc, false); - return true; - } - - // Search SC in hidden elements - // The content may already be hidden - if (m_HiddenSectionContents.contains(sc->uid())) - return true; - - qFatal("Unable to hide SectionContent, don't know this one 8-/"); - return false; -} - -bool CMainContainerWidget::raiseSectionContent(const SectionContent::RefPtr& sc) -{ - ADS_Expects(!sc.isNull()); - - // Search SC in sections - for (int i = 0; i < m_Sections.count(); ++i) - { - SectionWidget* sw = m_Sections.at(i); - int index = sw->indexOfContent(sc); - if (index < 0) - continue; - sw->setCurrentIndex(index); - return true; - } - - // Search SC in floatings - for (int i = 0; i < m_Floatings.size(); ++i) - { - FloatingWidget* fw = m_Floatings.at(i); - /*if (fw->content()->uid() != sc->uid()) - continue;*/ - fw->setVisible(true); - fw->raise(); - return true; - } - - // Search SC in hidden - if (m_HiddenSectionContents.contains(sc->uid())) - return showSectionContent(sc); - - qFatal("Unable to hide SectionContent, don't know this one 8-/"); - return false; -} - -bool CMainContainerWidget::isSectionContentVisible(const SectionContent::RefPtr& sc) -{ - ADS_Expects(!sc.isNull()); - - // Search SC in floatings - for (int i = 0; i < m_Floatings.count(); ++i) - { - /*const bool found = m_Floatings.at(i)->content()->uid() == sc->uid(); - if (!found) - continue;*/ - return m_Floatings.at(i)->isVisible(); - } - - // Search SC in sections - for (int i = 0; i < m_Sections.count(); ++i) - { - SectionWidget* sw = m_Sections.at(i); - const int index = sw->indexOfContent(sc); - if (index < 0) - continue; - return true; - } - - // Search SC in hidden - if (m_HiddenSectionContents.contains(sc->uid())) - return false; - - qWarning() << "SectionContent is not a part of this ContainerWidget:" << sc->uniqueName(); - return false; -} - -QMenu* CMainContainerWidget::createContextMenu() const -{ - // Fill map with actions (sorted by key!) - QMap actions; - - // Visible contents of sections - for (int i = 0; i < m_Sections.size(); ++i) - { - const SectionWidget* sw = m_Sections.at(i); - const QList& contents = sw->contents(); - foreach (const SectionContent::RefPtr& sc, contents) - { - QAction* a = new QAction(QIcon(), sc->visibleTitle(), NULL); - a->setObjectName(QString("ads-action-sc-%1").arg(QString::number(sc->uid()))); - a->setProperty("uid", sc->uid()); - a->setProperty("type", "section"); - a->setCheckable(true); - a->setChecked(true); - a->setEnabled(sc->flags().testFlag(SectionContent::Closeable)); - connect(a, SIGNAL(toggled(bool)), this, SLOT(onActionToggleSectionContentVisibility(bool))); - actions.insert(a->text(), a); - } - } - - // Hidden contents of sections - QHashIterator hiddenIter(m_HiddenSectionContents); - while (hiddenIter.hasNext()) - { - hiddenIter.next(); - const SectionContent::RefPtr sc = hiddenIter.value().data.content; - - QAction* a = new QAction(QIcon(), sc->visibleTitle(), NULL); - a->setObjectName(QString("ads-action-sc-%1").arg(QString::number(sc->uid()))); - a->setProperty("uid", sc->uid()); - a->setProperty("type", "section"); - a->setCheckable(true); - a->setChecked(false); - connect(a, SIGNAL(toggled(bool)), this, SLOT(onActionToggleSectionContentVisibility(bool))); - actions.insert(a->text(), a); - } - - // Floating contents - for (int i = 0; i < m_Floatings.size(); ++i) - { - /*const FloatingWidget* fw = m_Floatings.at(i); - const SectionContent::RefPtr sc = fw->content(); - - QAction* a = new QAction(QIcon(), sc->visibleTitle(), NULL); - a->setObjectName(QString("ads-action-sc-%1").arg(QString::number(sc->uid()))); - a->setProperty("uid", sc->uid()); - a->setProperty("type", "floating"); - a->setCheckable(true); - a->setChecked(fw->isVisible()); - connect(a, SIGNAL(toggled(bool)), this, SLOT(onActionToggleSectionContentVisibility(bool))); - actions.insert(a->text(), a);*/ - } - - // Create menu from "actions" - QMenu* m = new QMenu(NULL); - m->addActions(actions.values()); - return m; -} - -QByteArray CMainContainerWidget::saveState() const -{ - InMemoryWriter writer; - - // Hierarchy data. - const QByteArray hierarchyData = saveHierarchy(); - if (!hierarchyData.isEmpty()) - { - writer.write(ET_Hierarchy, hierarchyData); - } - - // SectionIndex data. - SectionIndexData sid; - if (saveSectionIndex(sid)) - { - writer.write(sid); - } - - if (writer.offsetsCount() == 0) - return QByteArray(); - return writer.toByteArray(); -} - -bool CMainContainerWidget::restoreState(const QByteArray& data) -{ - if (data.isEmpty()) - return false; - - InMemoryReader reader(data); - if (!reader.initReadHeader()) - return false; - - // Basic hierarchy data. - QByteArray hierarchyData; - if (reader.read(ET_Hierarchy, hierarchyData)) - { - restoreHierarchy(hierarchyData); - } - return true; -} - - -QList CMainContainerWidget::contents() const -{ - QList wl = m_SectionContentIdMap.values(); - QList sl; - for (int i = 0; i < wl.count(); ++i) - { - const SectionContent::RefPtr sc = wl.at(i).toStrongRef(); - if (sc) - sl.append(sc); - } - return sl; -} - -QPointer CMainContainerWidget::sectionDropOverlay() const -{ - return m_SectionDropOverlay; -} - - -QPointer CMainContainerWidget::dropOverlay() const -{ - return m_ContainerDropOverlay; -} - -/////////////////////////////////////////////////////////////////////// -// PRIVATE API BEGINS HERE -/////////////////////////////////////////////////////////////////////// - -QByteArray CMainContainerWidget::saveHierarchy() const -{ - /* - # Data Format - - quint32 Magic - quint32 Version - - int Number of floating widgets - LOOP Floating widgets - QString Unique name of content - QByteArray Geometry of floating widget - bool Visibility - - int Number of layout items (Valid values: 0, 1) - IF 0 - int Number of hidden contents - LOOP Contents - QString Unique name of content - ELSEIF 1 - ... todo ... - ENDIF - */ - QByteArray ba; - QDataStream out(&ba, QIODevice::WriteOnly); - out.setVersion(QDataStream::Qt_4_5); - out << (quint32) 0x00001337; // Magic - out << (quint32) 1; // Version - - // Save state of floating contents - saveFloatingWidgets(out); - - // Save state of sections and contents - if (m_MainLayout->count() <= 0 || m_Sections.isEmpty()) - { - // Looks like the user has hidden all contents and no more sections - // are available. We can simply write a list of all hidden contents. - out << 0; // Mode - - out << m_HiddenSectionContents.count(); - QHashIterator iter(m_HiddenSectionContents); - while (iter.hasNext()) - { - iter.next(); - out << iter.value().data.content->uniqueName(); - } - } - else if (m_MainLayout->count() == 1) - { - out << 1; // Mode - - // There should only be one! - QLayoutItem* li = m_MainLayout->itemAt(0); - if (!li->widget()) - qFatal("Not a widget in mainLayout, this shouldn't happen."); - - // Save sections beginning with the first QSplitter (li->widget()). - saveSectionWidgets(out, li->widget()); - - // Safe state of hidden contents, which doesn't have an section association - // or the section association points to a no longer existing section. - QHashIterator iter(m_HiddenSectionContents); - int cnt = 0; - while (iter.hasNext()) - { - iter.next(); - if (iter.value().preferredSectionId <= 0 || !m_SectionWidgetIdMap.contains(iter.value().preferredSectionId)) - cnt++; - } - out << cnt; - iter.toFront(); - while (iter.hasNext()) - { - iter.next(); - if (iter.value().preferredSectionId <= 0 || !m_SectionWidgetIdMap.contains(iter.value().preferredSectionId)) - out << iter.value().data.content->uniqueName(); - } - } - else - { - // More? Oh oh.. something is wrong :-/ - out << -1; - qWarning() << "Oh noooz.. Something went wrong. There are too many items in mainLayout."; - } - return ba; -} - -void CMainContainerWidget::saveFloatingWidgets(QDataStream& out) const -{ - out << m_Floatings.count(); - for (int i = 0; i < m_Floatings.count(); ++i) - { - FloatingWidget* fw = m_Floatings.at(i); - /*out << fw->content()->uniqueName();*/ - out << fw->saveGeometry(); - out << fw->isVisible(); - } -} - -void CMainContainerWidget::saveSectionWidgets(QDataStream& out, QWidget* widget) const -{ - QSplitter* sp = NULL; - SectionWidget* sw = NULL; - - if (!widget) - { - out << 0; - } - else if ((sp = dynamic_cast(widget)) != NULL) - { - out << 1; // Type = QSplitter - out << ((sp->orientation() == Qt::Horizontal) ? (int) 1 : (int) 2); - out << sp->count(); - out << sp->sizes(); - for (int i = 0; i < sp->count(); ++i) - { - saveSectionWidgets(out, sp->widget(i)); - } - } - else if ((sw = dynamic_cast(widget)) != NULL) - { - // Format (version 1) - // int Object type (SectionWidget=2) - // int Current active index - // int Number of contents (visible + hidden) - // LOOP Contents of section (last int) - // QString Unique name of SectionContent - // bool Visibility - // int Preferred index - - const QList& contents = sw->contents(); - QList hiddenContents; - - QHashIterator iter(m_HiddenSectionContents); - while (iter.hasNext()) - { - iter.next(); - const HiddenSectionItem& hsi = iter.value(); - if (hsi.preferredSectionId != sw->uid()) - continue; - hiddenContents.append(hsi); - } - - out << 2; // Type = SectionWidget - out << sw->currentIndex(); - out << contents.count() + hiddenContents.count(); - - for (int i = 0; i < contents.count(); ++i) - { - out << contents[i]->uniqueName(); // Unique name - out << (bool) true; // Visiblity - out << i; // Index - } - for (int i = 0; i < hiddenContents.count(); ++i) - { - out << hiddenContents.at(i).data.content->uniqueName(); - out << (bool) false; - out << hiddenContents.at(i).preferredSectionIndex; - } - } -} - -bool CMainContainerWidget::saveSectionIndex(SectionIndexData& sid) const -{ - if (m_Sections.count() <= 0) - return false; - - sid.sectionsCount = m_Sections.count(); - for (int i = 0; i < sid.sectionsCount; ++i) - { - SectionEntity se; - se.x = mapFromGlobal(m_Sections[i]->parentWidget()->mapToGlobal(m_Sections[i]->pos())).x(); - se.y = mapFromGlobal(m_Sections[i]->parentWidget()->mapToGlobal(m_Sections[i]->pos())).y(); - se.width = m_Sections[i]->geometry().width(); - se.height = m_Sections[i]->geometry().height(); - se.currentIndex = m_Sections[i]->currentIndex(); - se.sectionContentsCount = m_Sections[i]->contents().count(); - foreach (const SectionContent::RefPtr& sc, m_Sections[i]->contents()) - { - SectionContentEntity sce; - sce.uniqueName = sc->uniqueName(); - sce.visible = true; - sce.preferredIndex = m_Sections[i]->indexOfContent(sc); - se.sectionContents.append(sce); // std::move()? - } - sid.sections.append(se); // std::move()? - } - return true; -} - -bool CMainContainerWidget::restoreHierarchy(const QByteArray& data) -{ - QDataStream in(data); - in.setVersion(QDataStream::Qt_4_5); - - quint32 magic = 0; - in >> magic; - if (magic != 0x00001337) - return false; - - quint32 version = 0; - in >> version; - if (version != 1) - return false; - - QList oldFloatings = m_Floatings; - QList oldSections = m_Sections; - - // Restore floating widgets - QList floatings; - bool success = restoreFloatingWidgets(in, version, floatings); - if (!success) - { - qWarning() << "Could not restore floatings completely"; - } - - // Restore splitters, sections and contents - QList sections; - QList contentsToHide; - - int mode = 0; - in >> mode; - if (mode == 0) - { - // List of hidden contents. There are no sections at all. - int cnt = 0; - in >> cnt; - - if(cnt > 0) - { - // Create dummy section, required to call hideSectionContent() later. - SectionWidget* sw = new SectionWidget(this, this); - sections.append(sw); - - for (int i = 0; i < cnt; ++i) - { - QString uname; - in >> uname; - - const SectionContent::RefPtr sc = m_SectionContentNameMap.value(uname); - if (!sc) - continue; - - InternalContentData data; - if (!takeContent(sc, data)) - qFatal("This should never happen!!!"); - - sw->addContent(data, false); - contentsToHide.append(sc); - } - } - } - else if (mode == 1) - { - success = restoreSectionWidgets(in, version, NULL, sections, contentsToHide); - if (!success) - qWarning() << "Could not restore sections completely"; - - // Restore lonely hidden contents - int cnt = 0; - in >> cnt; - for (int i = 0; i < cnt; ++i) - { - QString uname; - in >> uname; - const SectionContent::RefPtr sc = m_SectionContentNameMap.value(uname); - if (!sc) - continue; - - InternalContentData data; - if (!takeContent(sc, data)) - { - qWarning("This should never happen! Looks like a bug during serialization, since the content is already being used in SWs."); - continue; - } - - SectionWidget* sw = NULL; - if (sections.size() <= 0) - qFatal("This should never happen, because above a section should have been created."); - else - sw = sections.first(); - - sw->addContent(data, false); - contentsToHide.append(sc); - } - } - - // Handle SectionContent which is not mentioned by deserialized data. - // What shall we do with it? For now: Simply drop them into the first SectionWidget. - if (true) - { - QList leftContents; - - // Collect all contents which has been restored - QList contents; - /*for (int i = 0; i < floatings.count(); ++i) - contents.append(floatings.at(i)->content());*/ - for (int i = 0; i < sections.count(); ++i) - for (int j = 0; j < sections.at(i)->contents().count(); ++j) - contents.append(sections.at(i)->contents().at(j)); - for (int i = 0; i < contentsToHide.count(); ++i) - contents.append(contentsToHide.at(i)); - - // Compare restored contents with available contents - const QList allContents = m_SectionContentIdMap.values(); - for (int i = 0; i < allContents.count(); ++i) - { - const SectionContent::RefPtr sc = allContents.at(i).toStrongRef(); - if (sc.isNull() || sc->containerWidget() != this) - continue; - if (contents.contains(sc)) - continue; - leftContents.append(sc); - } - - // What should we do with a drunken sailor.. what should.. erm.. - // What should we do with the left-contents? - // Lets add them to the first found SW or create one, if no SW is available. - for (int i = 0; i < leftContents.count(); ++i) - { - const SectionContent::RefPtr sc = leftContents.at(i); - SectionWidget* sw = NULL; - - if (sections.isEmpty()) - { - sw = new SectionWidget(this, this); - sections.append(sw); - addSectionWidget(sw); - } - else - sw = sections.first(); - - InternalContentData data; - if (!takeContent(sc, data)) - sw->addContent(sc); - else - sw->addContent(data, false); - } - } - - m_Floatings = floatings; - m_Sections = sections; - - // Delete old objects - QLayoutItem* old = m_MainLayout->takeAt(0); - m_MainLayout->addWidget(m_Splitter); - delete old; - qDeleteAll(oldFloatings); - qDeleteAll(oldSections); - - // Hide all as "hidden" marked contents - for (int i = 0; i < contentsToHide.count(); ++i) - hideSectionContent(contentsToHide.at(i)); - - deleteEmptySplitter(this); - return success; -} - -bool CMainContainerWidget::restoreFloatingWidgets(QDataStream& in, int version, QList& floatings) -{ - Q_UNUSED(version) - - int fwCount = 0; - in >> fwCount; - if (fwCount <= 0) - return true; - - for (int i = 0; i < fwCount; ++i) - { - QString uname; - in >> uname; - QByteArray geom; - in >> geom; - bool visible = false; - in >> visible; - - const SectionContent::RefPtr sc = m_SectionContentNameMap.value(uname).toStrongRef(); - if (!sc) - { - qWarning() << "Can not find SectionContent:" << uname; - continue; - } - - InternalContentData data; - if (!this->takeContent(sc, data)) - continue; - - FloatingWidget* fw = new FloatingWidget(this, sc, data.titleWidget, data.contentWidget, this); - fw->restoreGeometry(geom); - fw->setVisible(visible); - if (visible) - { - //fw->_titleWidget->setVisible(visible); - //fw->_contentWidget->setVisible(visible); - } - floatings.append(fw); - //data.titleWidget->m_FloatingWidget = fw; // $mfreiholz: Don't look at it :-< It's more than ugly... - } - return true; -} - -bool CMainContainerWidget::restoreSectionWidgets(QDataStream& in, int version, QSplitter* currentSplitter, QList& sections, QList& contentsToHide) -{ - if (in.atEnd()) - return true; - - int type; - in >> type; - - // Splitter - if (type == 1) - { - int orientation, count; - QList sizes; - in >> orientation >> count >> sizes; - - QSplitter* sp = newSplitter((Qt::Orientation) orientation); - for (int i = 0; i < count; ++i) - { - if (!restoreSectionWidgets(in, version, sp, sections, contentsToHide)) - return false; - } - if (sp->count() <= 0) - { - delete sp; - sp = NULL; - } - else if (sp) - { - sp->setSizes(sizes); - - if (!currentSplitter) - m_Splitter = sp; - else - currentSplitter->addWidget(sp); - } - } - // Section - else if (type == 2) - { - if (!currentSplitter) - { - qWarning() << "Missing splitter object for section"; - return false; - } - - int currentIndex, count; - in >> currentIndex >> count; - - SectionWidget* sw = new SectionWidget(this, this); - for (int i = 0; i < count; ++i) - { - QString uname; - in >> uname; - bool visible = false; - in >> visible; - int preferredIndex = -1; - in >> preferredIndex; - - const SectionContent::RefPtr sc = m_SectionContentNameMap.value(uname).toStrongRef(); - if (!sc) - { - qWarning() << "Can not find SectionContent:" << uname; - continue; - } - - InternalContentData data; - if (!takeContent(sc, data)) - { - qCritical() << "Can not find InternalContentData of SC, this should never happen!" << sc->uid() << sc->uniqueName(); - sw->addContent(sc); - } - else - sw->addContent(data, false); - - if (!visible) - contentsToHide.append(sc); - } - if (sw->contents().isEmpty()) - { - delete sw; - sw = NULL; - } - else if (sw) - { - sw->setCurrentIndex(currentIndex); - currentSplitter->addWidget(sw); - sections.append(sw); - } - } - // Unknown - else - { - qWarning() << "Unknown object type during restore"; - } - - return true; -} - -bool CMainContainerWidget::takeContent(const SectionContent::RefPtr& sc, InternalContentData& data) -{ - ADS_Expects(!sc.isNull()); - - // Search in sections - bool found = false; - for (int i = 0; i < m_Sections.count() && !found; ++i) - { - found = m_Sections.at(i)->takeContent(sc->uid(), data); - } - - // Search in floating widgets - for (int i = 0; i < m_Floatings.count() && !found; ++i) - { - /*found = m_Floatings.at(i)->content()->uid() == sc->uid(); - if (found) - m_Floatings.at(i)->takeContent(data);*/ - } - - // Search in hidden items - if (!found && m_HiddenSectionContents.contains(sc->uid())) - { - const HiddenSectionItem hsi = m_HiddenSectionContents.take(sc->uid()); - data = hsi.data; - found = true; - } - - return found; -} - - -void CMainContainerWidget::onActionToggleSectionContentVisibility(bool visible) -{ - QAction* a = qobject_cast(sender()); - if (!a) - return; - const int uid = a->property("uid").toInt(); - const SectionContent::RefPtr sc = m_SectionContentIdMap.value(uid).toStrongRef(); - if (sc.isNull()) - { - qCritical() << "Can not find content by ID" << uid; - return; - } - if (visible) - showSectionContent(sc); - else - hideSectionContent(sc); -} - - -void CMainContainerWidget::hideContainerOverlay() -{ - m_ContainerDropOverlay->hideDropOverlay(); -} - - -void CMainContainerWidget::moveFloatingWidget(const QPoint& TargetPos) -{ - QPoint MousePos = mapFromGlobal(QCursor::pos()); - - // Mouse is over the container widget - if (rect().contains(MousePos)) - { - //std::cout << "over Container" << std::endl; - m_ContainerDropOverlay->showDropOverlay(this); - m_ContainerDropOverlay->raise(); - } - else - { - std::cout << "-----------------" << std::endl; - m_ContainerDropOverlay->hideDropOverlay(); - } - - // Mouse is over a SectionWidget - SectionWidget* sectionwidget = sectionWidgetAt(MousePos); - if (sectionwidget) - { - //qInfo() << "over sectionWidget"; - m_SectionDropOverlay->setAllowedAreas(AllAreas); - m_SectionDropOverlay->showDropOverlay(sectionwidget); - } - else - { - m_SectionDropOverlay->hideDropOverlay(); - } -} - - -} // namespace ads diff --git a/AdvancedDockingSystem/src/MainContainerWidget.h b/AdvancedDockingSystem/src/MainContainerWidget.h deleted file mode 100644 index de38284..0000000 --- a/AdvancedDockingSystem/src/MainContainerWidget.h +++ /dev/null @@ -1,189 +0,0 @@ -#ifndef ADS_CONTAINERWIDGET_H -#define ADS_CONTAINERWIDGET_H -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ -#include -#include -#include -#include -#include -#include - -class QPoint; -class QMenu; - -#include "API.h" -#include "Internal.h" -#include "SectionContent.h" -#include "FloatingWidget.h" -#include "Serialization.h" -#include "DropOverlay.h" -#include "ContainerWidget.h" - -namespace ads -{ -class SectionWidget; -class DropOverlay; -class InternalContentData; -class CSectionContentWidget; - - - -/*! - * ContainerWidget is the main container to provide the docking - * functionality. It manages multiple sections with all possible areas. - */ -class ADS_EXPORT_API CMainContainerWidget : public CContainerWidget -{ - Q_OBJECT - - friend class SectionContent; - friend class SectionWidget; - friend class FloatingWidget; - friend class SectionTitleWidget; - friend class ContainerWidgetPrivate; - friend class CFloatingTitleWidget; - friend class CContainerWidget; - friend class CSectionContentWidget; - -public: - explicit CMainContainerWidget(QWidget *parent = nullptr); - virtual ~CMainContainerWidget(); - - // - // Public API - // - - /*! - * Completely removes the sc from this ContainerWidget. - * This container will no longer hold a reference to the content. - * The content can be safely deleted. - */ - bool removeSectionContent(const SectionContent::RefPtr& sc); - - /*! - * Shows the specific SectionContent in UI. - * Independed of the current state, whether it is used inside a section or is floating. - */ - bool showSectionContent(const SectionContent::RefPtr& sc); - - /*! - * Closes the specified SectionContent from UI. - * Independed of the current state, whether it is used inside a section or is floating. - */ - bool hideSectionContent(const SectionContent::RefPtr& sc); - - /*! - * Selects the specific SectionContent as current, if it is part of a SectionWidget. - * If SC is floating, it does nothing (or should we show it?) - */ - bool raiseSectionContent(const SectionContent::RefPtr& sc); - - /*! - * Indicates whether the SectionContent sc is visible. - */ - bool isSectionContentVisible(const SectionContent::RefPtr& sc); - - /*! - * Creates a QMenu based on available SectionContents. - * The caller is responsible to delete the menu. - */ - QMenu* createContextMenu() const; - - /*! - * Serializes the current state of contents and returns it as a plain byte array. - * \see restoreState(const QByteArray&) - */ - QByteArray saveState() const; - - /*! - * Deserilizes the state of contents from data, which was written with saveState(). - * \see saveState() - */ - bool restoreState(const QByteArray& data); - - // - // Advanced Public API - // You usually should not need access to this methods - // - /*! - * \brief contents - * \return List of known SectionContent for this ContainerWidget. - */ - QList contents() const; - - /** - * Access function for the section drop overlay - */ - QPointer sectionDropOverlay() const; - - QPointer dropOverlay() const; - - static QSplitter* newSplitter(Qt::Orientation orientation = Qt::Horizontal, QWidget* parent = 0); - - virtual unsigned int zOrderIndex() const {return 0;} - -private: - // Serialization - QByteArray saveHierarchy() const; - void saveFloatingWidgets(QDataStream& out) const; - void saveSectionWidgets(QDataStream& out, QWidget* widget) const; - - bool saveSectionIndex(SectionIndexData &sid) const; - - bool restoreHierarchy(const QByteArray& data); - bool restoreFloatingWidgets(QDataStream& in, int version, QList& floatings); - bool restoreSectionWidgets(QDataStream& in, int version, QSplitter* currentSplitter, QList& sections, QList& contentsToHide); - - bool takeContent(const SectionContent::RefPtr& sc, InternalContentData& data); - void hideContainerOverlay(); - void moveFloatingWidget(const QPoint& TargetPos); - -private slots: - void onActionToggleSectionContentVisibility(bool visible); - -signals: - void orientationChanged(); - - /*! - * Emits whenever the visibility of a SectionContent changes. - * \see showSectionContent(), hideSectionContent() - * \since 0.2 - */ - void sectionContentVisibilityChanged(const SectionContent::RefPtr& sc, bool visible); - -private: - QList m_Floatings; - QList m_Containers; - QHash m_HiddenSectionContents; - - // Helper lookup maps, restricted to this container. - QHash m_SectionContentIdMap; - QHash m_SectionContentNameMap; - QHash m_SectionWidgetIdMap; - - QHash m_SectionContentWidgetIdMap; - QHash m_SectionContentWidgetNameMap; - - QPointer m_ContainerDropOverlay; - QPointer m_SectionDropOverlay; -}; - - -} // namespace ads -#endif diff --git a/AdvancedDockingSystem/src/SectionContent.cpp b/AdvancedDockingSystem/src/SectionContent.cpp deleted file mode 100644 index eaa2518..0000000 --- a/AdvancedDockingSystem/src/SectionContent.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ - -#include "MainContainerWidget.h" -#include "SectionContent.h" - -#include -#include - -#include "Internal.h" - -namespace ads -{ - -SectionContent::SectionContent() : - _uid(GetNextUid()), - _flags(AllFlags) -{ -} - -SectionContent::RefPtr SectionContent::newSectionContent(const QString& uniqueName, CMainContainerWidget* container, QWidget* title, QWidget* content) -{ - auto SectionContentNameMap = container->m_SectionContentNameMap; - auto SectionContentIdMap = container->m_SectionContentIdMap; - - if (uniqueName.isEmpty()) - { - qFatal("Can not create SectionContent with empty uniqueName"); - return RefPtr(); - } - else if (SectionContentNameMap.contains(uniqueName)) - { - qFatal("Can not create SectionContent with already used uniqueName"); - return RefPtr(); - } - else if (!container || !title || !content) - { - qFatal("Can not create SectionContent with NULL values"); - return RefPtr(); - } - - QSharedPointer sc(new SectionContent()); - sc->_uniqueName = uniqueName; - sc->m_MainContainerWidget = container; - sc->m_TitleWidgetContent = title; - sc->m_ContentWidget = content; - - SectionContentIdMap.insert(sc->uid(), sc); - SectionContentNameMap.insert(sc->uniqueName(), sc); - return sc; -} - -SectionContent::~SectionContent() -{ - auto SectionContentNameMap = m_MainContainerWidget->m_SectionContentNameMap; - auto SectionContentIdMap = m_MainContainerWidget->m_SectionContentIdMap; - - if (m_MainContainerWidget) - { - SectionContentIdMap.remove(_uid); - SectionContentNameMap.remove(_uniqueName); - } - delete m_TitleWidgetContent; - delete m_ContentWidget; -} - -int SectionContent::uid() const -{ - return _uid; -} - -QString SectionContent::uniqueName() const -{ - return _uniqueName; -} - -CMainContainerWidget* SectionContent::containerWidget() const -{ - return m_MainContainerWidget; -} - -QWidget* SectionContent::titleWidgetContent() const -{ - return m_TitleWidgetContent; -} - -QWidget* SectionContent::contentWidget() const -{ - return m_ContentWidget; -} - -SectionContent::Flags SectionContent::flags() const -{ - return _flags; -} - -QString SectionContent::visibleTitle() const -{ - if (_title.isEmpty()) - return _uniqueName; - return _title; -} - -QString SectionContent::title() const -{ - return _title; -} - -void SectionContent::setTitle(const QString& title) -{ - _title = title; -} - -void SectionContent::setFlags(const Flags f) -{ - _flags = f; -} - -int SectionContent::GetNextUid() -{ - static int NextUid = 0; - return ++NextUid; -} - -} // namespace ads diff --git a/AdvancedDockingSystem/src/SectionContent.h b/AdvancedDockingSystem/src/SectionContent.h deleted file mode 100644 index 90ff68c..0000000 --- a/AdvancedDockingSystem/src/SectionContent.h +++ /dev/null @@ -1,99 +0,0 @@ -#ifndef SECTIONCONTENT_H -#define SECTIONCONTENT_H -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ -#include -#include -#include - - -class QWidget; - -#include "API.h" - -namespace ads -{ - -class CMainContainerWidget; - -class ADS_EXPORT_API SectionContent -{ - friend class CMainContainerWidget; - -private: - SectionContent(); - SectionContent(const SectionContent&); - SectionContent& operator=(const SectionContent&); - -public: - typedef QSharedPointer RefPtr; - typedef QWeakPointer WeakPtr; - - enum Flag - { - None = 0, - Closeable = 1, - Maximizable = 2, - AllFlags = Closeable | Maximizable - }; - Q_DECLARE_FLAGS(Flags, Flag) - - /*! - * Creates new content, associates it to container and takes ownership of - * title- and content- widgets. - * \param uniqueName An unique identifier across the entire process. - * \param container The parent ContainerWidget in which this content will be active. - * \param title The widget to use as title. - * \param content The widget to use as content. - * \return May return a invalid ref-pointer in case of invalid parameters. - */ - static RefPtr newSectionContent(const QString& uniqueName, CMainContainerWidget* container, QWidget* title, QWidget* content); - - virtual ~SectionContent(); - int uid() const; - QString uniqueName() const; - CMainContainerWidget* containerWidget() const; - QWidget* titleWidgetContent() const; - QWidget* contentWidget() const; - Flags flags() const; - - QString visibleTitle() const; - QString title() const; - void setTitle(const QString& title); - void setFlags(const Flags f); - -private: - const int _uid; - QString _uniqueName; - - QPointer m_MainContainerWidget; - QPointer m_TitleWidgetContent; - QPointer m_ContentWidget; - - // Optional attributes - QString _title; - Flags _flags; - - /* Note: This method could be a problem in static build environment - * since it may begin with 0 for every module which uses ADS. - */ - static int GetNextUid(); -}; - -} // namespace ads -#endif diff --git a/AdvancedDockingSystem/src/SectionContentWidget.cpp b/AdvancedDockingSystem/src/SectionContentWidget.cpp deleted file mode 100644 index b374982..0000000 --- a/AdvancedDockingSystem/src/SectionContentWidget.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ - -#include "MainContainerWidget.h" -#include -#include "SectionContentWidget.h" -#include "SectionTitleWidget.h" - -namespace ads -{ -struct SectionContentWidgetPrivate -{ - CSectionContentWidget* _this; - int Uid; - QString UniqueName; - QPointer MainContainerWidget; - QPointer TitleWidgetContent; - QPointer ContentWidget; - // Optional attributes - QString Title; - CSectionContentWidget::Flags Flags = CSectionContentWidget::AllFlags; - - - - /* Note: This method could be a problem in static build environment - * since it may begin with 0 for every module which uses ADS. - */ - static int GetNextUid() - { - static int NextUid = 0; - return ++NextUid; - } - - - SectionContentWidgetPrivate(CSectionContentWidget* _public) - : _this(_public), - Uid(GetNextUid()) - { - - } -}; - - -CSectionContentWidget::CSectionContentWidget(SectionContent::RefPtr c, QWidget* parent) : - QFrame(parent), - d(new SectionContentWidgetPrivate(this)), - _content(c) -{ - QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom); - l->setContentsMargins(0, 0, 0, 0); - l->setSpacing(0); - l->addWidget(_content->contentWidget()); - setLayout(l); -} - - -CSectionContentWidget* CSectionContentWidget::newSectionContent(const QString& uniqueName, - CMainContainerWidget* container, QWidget* title, QWidget* content) -{ - auto SectionContentNameMap = container->m_SectionContentNameMap; - auto SectionContentIdMap = container->m_SectionContentIdMap; - - if (uniqueName.isEmpty()) - { - qFatal("Can not create SectionContent with empty uniqueName"); - return nullptr; - } - else if (SectionContentNameMap.contains(uniqueName)) - { - qFatal("Can not create SectionContent with already used uniqueName"); - return nullptr; - } - else if (!container || !title || !content) - { - qFatal("Can not create SectionContent with NULL values"); - return nullptr; - } - - CSectionContentWidget* sc(new CSectionContentWidget()); - sc->d->UniqueName = uniqueName; - sc->d->MainContainerWidget = container; - sc->d->TitleWidgetContent = title; - sc->d->ContentWidget = content; - - container->m_SectionContentWidgetIdMap.insert(sc->uid(), sc); - container->m_SectionContentWidgetNameMap.insert(sc->uniqueName(), sc); - return sc; -} - -CSectionContentWidget::~CSectionContentWidget() -{ - layout()->removeWidget(_content->contentWidget()); - delete d; -} - - -int CSectionContentWidget::uid() const -{ - return d->Uid; -} - - -QString CSectionContentWidget::uniqueName() const -{ - return d->UniqueName; -} - - -CMainContainerWidget* CSectionContentWidget::containerWidget() const -{ - return d->MainContainerWidget; -} - -QWidget* CSectionContentWidget::titleWidgetContent() const -{ - return d->TitleWidgetContent.data(); -} - - -QWidget* CSectionContentWidget::contentWidget() const -{ - return d->ContentWidget; -} - -CSectionContentWidget::Flags CSectionContentWidget::flags() const -{ - return d->Flags; -} - - -QString CSectionContentWidget::visibleTitle() const -{ - return d->Title.isEmpty() ? d->UniqueName : d->Title; -} - - -QString CSectionContentWidget::title() const -{ - return d->Title; -} - -void CSectionContentWidget::setTitle(const QString& title) -{ - d->Title = title; -} - -void CSectionContentWidget::setFlags(const Flags f) -{ - d->Flags = f; -} - -} // namespace ads diff --git a/AdvancedDockingSystem/src/SectionContentWidget.h b/AdvancedDockingSystem/src/SectionContentWidget.h deleted file mode 100644 index 4796b1a..0000000 --- a/AdvancedDockingSystem/src/SectionContentWidget.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef SECTION_CONTENT_WIDGET_H -#define SECTION_CONTENT_WIDGET_H -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ -#include - -#include "API.h" -#include "SectionContent.h" - -namespace ads -{ -class CMainContainerWidget; -class SectionWidget; -class SectionTitleWidget; - - -struct SectionContentWidgetPrivate; - - -class CSectionContentWidget : public QFrame -{ - Q_OBJECT -private: - SectionContentWidgetPrivate* d; - friend class SectionContentWidgetPrivate; - friend class CMainContainerWidget; - -public: - enum Flag - { - None = 0, - Closeable = 1, - Maximizable = 2, - AllFlags = Closeable | Maximizable - }; - Q_DECLARE_FLAGS(Flags, Flag) - - CSectionContentWidget(SectionContent::RefPtr c = SectionContent::RefPtr(), QWidget* parent = 0); - virtual ~CSectionContentWidget(); - - /*! - * Creates new content, associates it to container and takes ownership of - * title- and content- widgets. - * \param uniqueName An unique identifier across the entire process. - * \param container The parent ContainerWidget in which this content will be active. - * \param title The widget to use as title. - * \param content The widget to use as content. - * \return May return a invalid ref-pointer in case of invalid parameters. - */ - static CSectionContentWidget* newSectionContent(const QString& uniqueName, - CMainContainerWidget* container, QWidget* title, QWidget* content); - - int uid() const; - QString uniqueName() const; - CMainContainerWidget* containerWidget() const; - QWidget* titleWidgetContent() const; - QWidget* contentWidget() const; - Flags flags() const; - - QString visibleTitle() const; - QString title() const; - void setTitle(const QString& title); - void setFlags(const Flags f); - -private: - SectionContent::RefPtr _content; -}; - -} // namespace ads -#endif diff --git a/AdvancedDockingSystem/src/SectionTitleWidget.cpp b/AdvancedDockingSystem/src/SectionTitleWidget.cpp deleted file mode 100644 index 3a9eb64..0000000 --- a/AdvancedDockingSystem/src/SectionTitleWidget.cpp +++ /dev/null @@ -1,290 +0,0 @@ -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ - -#include "MainContainerWidget.h" -#include "SectionTitleWidget.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "Internal.h" -#include "DropOverlay.h" -#include "SectionContent.h" -#include "SectionWidget.h" -#include "FloatingWidget.h" -#include - -namespace ads -{ - -SectionTitleWidget::SectionTitleWidget(SectionContent::RefPtr content, QWidget* parent) : - QFrame(parent), - m_Content(content), - m_TabMoving(false), - m_IsActiveTab(false) -{ - QBoxLayout* l = new QBoxLayout(QBoxLayout::LeftToRight); - l->setContentsMargins(0, 0, 0, 0); - l->setSpacing(0); - l->addWidget(content->titleWidgetContent()); - setLayout(l); -} - - -SectionTitleWidget::~SectionTitleWidget() -{ - layout()->removeWidget(m_Content->titleWidgetContent()); -} - -bool SectionTitleWidget::isActiveTab() const -{ - return m_IsActiveTab; -} - -void SectionTitleWidget::setActiveTab(bool active) -{ - if (active != m_IsActiveTab) - { - m_IsActiveTab = active; - - style()->unpolish(this); - style()->polish(this); - update(); - - emit activeTabChanged(); - } -} - -void SectionTitleWidget::mousePressEvent(QMouseEvent* ev) -{ - if (ev->button() == Qt::LeftButton) - { - ev->accept(); - m_DragStartMousePosition = ev->pos(); - m_DragStartGlobalMousePosition = ev->globalPos(); - m_DragStartPosition = mapToGlobal(this->pos()); - return; - } - QFrame::mousePressEvent(ev); -} - - -CContainerWidget* findParentContainerWidget(QWidget* w) -{ - CContainerWidget* cw = 0; - QWidget* next = w; - do - { - if ((cw = dynamic_cast(next)) != 0) - { - break; - } - next = next->parentWidget(); - } - while (next); - return cw; -} - -SectionWidget* findParentSectionWidget(class QWidget* w) -{ - SectionWidget* cw = 0; - QWidget* next = w; - do - { - if ((cw = dynamic_cast(next)) != 0) - { - break; - } - next = next->parentWidget(); - } - while (next); - return cw; -} - -void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev) -{ - SectionWidget* section = nullptr; - CContainerWidget* cw = findParentContainerWidget(this); - CMainContainerWidget* mcw = cw->mainContainerWidget(); - std::cout << "SectionTitleWidget::mouseReleaseEvent" << std::endl; - - //m_FloatingWidget.clear(); - // End of tab moving, change order now - if (m_TabMoving && (section = findParentSectionWidget(this)) != nullptr) - { - // Find tab under mouse - QPoint pos = ev->globalPos(); - pos = section->mapFromGlobal(pos); - int fromIndex = section->indexOfContent(m_Content); - int toIndex = section->indexOfContentByTitlePos(pos, this); - qInfo() << "fromIndex: " << fromIndex << " toIndex: " << toIndex; - if (-1 == toIndex) - { - toIndex = section->indexOfContent(section->contents().last()); - } - section->moveContent(fromIndex, toIndex); - } - - if (!m_DragStartMousePosition.isNull()) - { - emit clicked(); - } - - // Reset - m_DragStartMousePosition = QPoint(); - m_TabMoving = false; - mcw->m_SectionDropOverlay->hideDropOverlay(); - mcw->hideContainerOverlay(); - QFrame::mouseReleaseEvent(ev); -} - - -void SectionTitleWidget::startFloating(QMouseEvent* ev, CMainContainerWidget* cw, SectionWidget* sectionwidget) -{ - std::cout << "SectionTitleWidget::startFloating" << std::endl; - - FloatingWidget* fw; - if (sectionwidget->contentCount() > 1) - { - // If section widget has multiple tabs, we take only one tab - InternalContentData data; - if (!sectionwidget->takeContent(m_Content->uid(), data)) - { - qWarning() << "THIS SHOULD NOT HAPPEN!!" << m_Content->uid(); - return; - } - fw = new FloatingWidget(cw, data.content, data.titleWidget, data.contentWidget, cw); - } - else - { - // If section widget has only one content widget, we can move the complete - // section widget into floating widget - QSplitter* splitter = findParentSplitter(sectionwidget); - fw = new FloatingWidget(cw, sectionwidget); - if (splitter && splitter->count() == 1) - { - // if splitter contains only one section widget, then we can - // remove the splitter and replace it with the section widget - std::cout << "splitter->count() == 1" << std::endl; - SectionWidget* sectionwidget = dynamic_cast(splitter->widget(0)); - QSplitter* parentSplitter = dynamic_cast(splitter->parentWidget()); - if (parentSplitter) - { - sectionwidget->setParent(0); - int index = parentSplitter->indexOf(splitter); - splitter->setParent(0); - parentSplitter->insertWidget(index, sectionwidget); - delete splitter; - std::cout << "Index of splitter " << index << std::endl; - } - } - } - - 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(); -} - - -void SectionTitleWidget::moveTab(QMouseEvent* ev) -{ - ev->accept(); - int left, top, right, bottom; - getContentsMargins(&left, &top, &right, &bottom); - QPoint moveToPos = mapToParent(ev->pos()) - m_DragStartMousePosition; - moveToPos.setY(0/* + top*/); - move(moveToPos); -} - - -void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev) -{ - std::cout << "SectionTitleWidget::mouseMoveEvent" << std::endl; - if (!(ev->buttons() & Qt::LeftButton)) - { - QFrame::mouseMoveEvent(ev); - return; - } - - // TODO make a member with the main container widget and assign it on - // creation - CMainContainerWidget* MainContainerWidget = findParentContainerWidget(this)->mainContainerWidget(); - ev->accept(); - - - SectionWidget* sectionwidget = findParentSectionWidget(this); - if (!sectionwidget) - { - QFrame::mouseMoveEvent(ev); - return; - } - - // move tab - if (m_TabMoving) - { - moveTab(ev); - } - - // leave if dragging is not active - if (m_DragStartMousePosition.isNull()) - { - QFrame::mouseMoveEvent(ev); - return; - } - - // Begin to drag/float the SectionContent. - if (!sectionwidget->titleAreaGeometry().contains(sectionwidget->mapFromGlobal(ev->globalPos()))) - { - startFloating(ev, MainContainerWidget, sectionwidget); - return; - } - // Begin to drag title inside the title area to switch its position inside the SectionWidget. - else if ((ev->pos() - m_DragStartMousePosition).manhattanLength() >= QApplication::startDragDistance() // Wait a few pixels before start moving - && sectionwidget->titleAreaGeometry().contains(sectionwidget->mapFromGlobal(ev->globalPos()))) - { - m_TabMoving = true; - //raise(); // Raise current title-widget above other tabs - return; - } - QFrame::mouseMoveEvent(ev); -} - -} // namespace ads diff --git a/AdvancedDockingSystem/src/SectionTitleWidget.h b/AdvancedDockingSystem/src/SectionTitleWidget.h deleted file mode 100644 index 870bb96..0000000 --- a/AdvancedDockingSystem/src/SectionTitleWidget.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef SECTION_TITLE_WIDGET_H -#define SECTION_TITLE_WIDGET_H -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ -#include -#include -#include - -#include "API.h" -#include "SectionContent.h" - -class QPushButton; - -namespace ads -{ - -class CMainContainerWidget; -class SectionWidget; -class FloatingWidget; - -class SectionTitleWidget : public QFrame -{ - Q_OBJECT - Q_PROPERTY(bool activeTab READ isActiveTab WRITE setActiveTab NOTIFY activeTabChanged) - - friend class CMainContainerWidget; - friend class SectionWidget; - friend class CContainerWidget; - - SectionContent::RefPtr m_Content; - - // Drag & Drop (Floating) - QPoint m_DragStartMousePosition; - QPoint m_DragStartGlobalMousePosition; - QPoint m_DragStartPosition; - - // Drag & Drop (Title/Tabs) - bool m_TabMoving; - - // Property values - bool m_IsActiveTab; - -public: - SectionTitleWidget(SectionContent::RefPtr content, QWidget* parent); - virtual ~SectionTitleWidget(); - - bool isActiveTab() const; - void setActiveTab(bool active); - -protected: - virtual void mousePressEvent(QMouseEvent* ev); - virtual void mouseReleaseEvent(QMouseEvent* ev); - virtual void mouseMoveEvent(QMouseEvent* ev); - -private: - void startFloating(QMouseEvent* ev, CMainContainerWidget* cw, SectionWidget* sectionwidget); - void moveTab(QMouseEvent* ev); - -signals: - void activeTabChanged(); - void clicked(); -}; - -} // namepsace ads -#endif diff --git a/AdvancedDockingSystem/src/SectionWidget.cpp b/AdvancedDockingSystem/src/SectionWidget.cpp deleted file mode 100644 index d829438..0000000 --- a/AdvancedDockingSystem/src/SectionWidget.cpp +++ /dev/null @@ -1,495 +0,0 @@ -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ - -#include "SectionWidget.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "Internal.h" -#include "DropOverlay.h" -#include "SectionContent.h" -#include "SectionTitleWidget.h" -#include "SectionContentWidget.h" -#include "FloatingWidget.h" -#include "MainContainerWidget.h" - -namespace ads -{ - -SectionWidget::SectionWidget(CMainContainerWidget* MainContainer, CContainerWidget* parent) : - QFrame(parent), - _uid(GetNextUid()), - m_MainContainerWidget(MainContainer), - _tabsLayout(NULL), - _tabsLayoutInitCount(0), - _contentsLayout(NULL), - _mousePressTitleWidget(NULL) -{ - QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom); - l->setContentsMargins(0, 0, 0, 0); - l->setSpacing(0); - setLayout(l); - - /* top area with tabs and close button */ - _topLayout = new QBoxLayout(QBoxLayout::LeftToRight); - _topLayout->setContentsMargins(0, 0, 0, 0); - _topLayout->setSpacing(0); - l->addLayout(_topLayout); - - _tabsScrollArea = new SectionWidgetTabsScrollArea(this); - _topLayout->addWidget(_tabsScrollArea, 1); - - _tabsContainerWidget = new QWidget(); - _tabsContainerWidget->setObjectName("tabsContainerWidget"); - _tabsScrollArea->setWidget(_tabsContainerWidget); - - _tabsLayout = new QBoxLayout(QBoxLayout::LeftToRight); - _tabsLayout->setContentsMargins(0, 0, 0, 0); - _tabsLayout->setSpacing(0); - _tabsLayout->addStretch(1); - _tabsContainerWidget->setLayout(_tabsLayout); - - _tabsMenuButton = new QPushButton(); - _tabsMenuButton->setObjectName("tabsMenuButton"); - _tabsMenuButton->setFlat(true); - _tabsMenuButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarUnshadeButton)); - _tabsMenuButton->setMaximumWidth(_tabsMenuButton->iconSize().width()); - _topLayout->addWidget(_tabsMenuButton, 0); -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - //QObject::connect(_tabsMenuButton, &QPushButton::clicked, this, &SectionWidget::onTabsMenuButtonClicked); -#else - //QObject::connect(_tabsMenuButton, SIGNAL(clicked()), this, SLOT(onTabsMenuButtonClicked())); -#endif - - _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); - _topLayout->addWidget(_closeButton, 0); - connect(_closeButton, SIGNAL(clicked(bool)), this, SLOT(onCloseButtonClicked())); - - _tabsLayoutInitCount = _tabsLayout->count(); - - /* central area with contents */ - - _contentsLayout = new QStackedLayout(); - _contentsLayout->setContentsMargins(0, 0, 0, 0); - _contentsLayout->setSpacing(0); - l->addLayout(_contentsLayout, 1); - - m_MainContainerWidget->m_SectionWidgetIdMap.insert(_uid, this); -} - -SectionWidget::~SectionWidget() -{ - if (m_MainContainerWidget) - { - m_MainContainerWidget->m_SectionWidgetIdMap.remove(_uid); - m_MainContainerWidget->m_Sections.removeAll(this); // Note: I don't like this here, but we have to remove it from list... - } - - // Delete empty QSplitter. - QSplitter* splitter = findParentSplitter(this); - if (splitter && splitter->count() == 0) - { - splitter->deleteLater(); - } - - std::cout << "SectionWidget::~SectionWidget()" << std::endl; -} - -int SectionWidget::uid() const -{ - return _uid; -} - -CContainerWidget* SectionWidget::containerWidget() const -{ - QWidget* Parent = parentWidget(); - while (Parent) - { - CContainerWidget* Container = dynamic_cast(Parent); - if (Container) - { - return Container; - } - Parent = Parent->parentWidget(); - } - - return 0; -} - -QRect SectionWidget::titleAreaGeometry() const -{ - return _topLayout->geometry(); -} - -QRect SectionWidget::contentAreaGeometry() const -{ - return _contentsLayout->geometry(); -} - -void SectionWidget::addContent(const SectionContent::RefPtr& c) -{ - m_Contents.append(c); - - SectionTitleWidget* title = new SectionTitleWidget(c, NULL); - m_TitleWidgets.append(title); - _tabsLayout->insertWidget(_tabsLayout->count() - _tabsLayoutInitCount, title); - QObject::connect(title, SIGNAL(clicked()), this, SLOT(onSectionTitleClicked())); - - CSectionContentWidget* content = new CSectionContentWidget(c, NULL); - m_ContentWidgets.append(content); - _contentsLayout->addWidget(content); - - // Active first TAB. - if (m_Contents.size() == 1) - setCurrentIndex(0); - // Switch to newest. -// else -// setCurrentIndex(_contentsLayout->count() - 1); - - updateTabsMenu(); -} - -void SectionWidget::addContent(const InternalContentData& data, bool autoActivate) -{ - m_Contents.append(data.content); - - // Add title-widget to tab-bar - // #FIX: Make it visible, since it is possible that it was hidden previously. - 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. - m_ContentWidgets.append(data.contentWidget); - _contentsLayout->addWidget(data.contentWidget); - - // Activate first TAB. - if (m_Contents.size() == 1) - setCurrentIndex(0); - // Switch to just added TAB. - else if (autoActivate) - setCurrentIndex(m_Contents.count() - 1); - // Mark it as inactive tab. - else - data.titleWidget->setActiveTab(false); // or: setCurrentIndex(currentIndex()) - - updateTabsMenu(); -} - -bool SectionWidget::takeContent(int uid, InternalContentData& data) -{ - for (int i = 0; i < m_Contents.count(); i++) - { - if (m_Contents[i]->uid() != uid) - { - continue; - } - return takeContentAt(i, data); - } - - return false; -} - -bool SectionWidget::takeContentAt(int index, InternalContentData& data) -{ - SectionContent::RefPtr sc = m_Contents.takeAt(index); - if (!sc) - return false; - - // Title wrapper widget (TAB) - SectionTitleWidget* title = m_TitleWidgets.takeAt(index); - if (title) - { - _tabsLayout->removeWidget(title); - title->disconnect(this); - title->setParent(m_MainContainerWidget); - } - - // Content wrapper widget (CONTENT) - CSectionContentWidget* content = m_ContentWidgets.takeAt(index); - if (content) - { - _contentsLayout->removeWidget(content); - content->disconnect(this); - content->setParent(m_MainContainerWidget); - } - - // Select the previous tab as activeTab. - if (m_Contents.size() > 0 && title->isActiveTab()) - { - if (index > 0) - setCurrentIndex(index - 1); - else - setCurrentIndex(0); - } - - updateTabsMenu(); - - data.content = sc; - data.titleWidget = title; - data.contentWidget = content; - return !data.content.isNull(); -} - - -int SectionWidget::indexOfContent(const SectionContent::RefPtr& c) const -{ - return m_Contents.indexOf(c); -} - -int SectionWidget::indexOfContentByUid(int uid) const -{ - for (int i = 0; i < m_Contents.count(); ++i) - { - if (m_Contents[i]->uid() == uid) - return i; - } - return -1; -} - -int SectionWidget::indexOfContentByTitlePos(const QPoint& p, QWidget* exclude) const -{ - int index = -1; - for (int i = 0; i < m_TitleWidgets.size(); ++i) - { - if (m_TitleWidgets[i]->geometry().contains(p) && (exclude == NULL || m_TitleWidgets[i] != exclude)) - { - index = i; - break; - } - } - return index; -} - -int SectionWidget::currentIndex() const -{ - return _contentsLayout->currentIndex(); -} - -void SectionWidget::moveContent(int from, int 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; - } - - m_Contents.move(from, to); - m_TitleWidgets.move(from, to); - m_ContentWidgets.move(from, to); - - QLayoutItem* liFrom = NULL; - liFrom = _tabsLayout->takeAt(from); - _tabsLayout->insertItem(to, liFrom); - liFrom = _contentsLayout->takeAt(from); - _contentsLayout->insertWidget(to, liFrom->widget()); - delete liFrom; - - updateTabsMenu(); -} - -void SectionWidget::showEvent(QShowEvent*) -{ - _tabsScrollArea->ensureWidgetVisible(m_TitleWidgets.at(currentIndex())); -} - -void SectionWidget::setCurrentIndex(int index) -{ - if (index < 0 || index > m_Contents.count() - 1) - { - qWarning() << Q_FUNC_INFO << "Invalid index" << index; - return; - } - - // Set active TAB - for (int i = 0; i < _tabsLayout->count(); ++i) - { - QLayoutItem* item = _tabsLayout->itemAt(i); - if (item->widget()) - { - SectionTitleWidget* stw = dynamic_cast(item->widget()); - if (stw) - { - if (i == index) - { - stw->setActiveTab(true); - _tabsScrollArea->ensureWidgetVisible(stw); - if (stw->m_Content->flags().testFlag(SectionContent::Closeable)) - _closeButton->setEnabled(true); - else - _closeButton->setEnabled(false); - } - else - stw->setActiveTab(false); - } - } - } - - // Set active CONTENT - _contentsLayout->setCurrentIndex(index); -} - -void SectionWidget::onSectionTitleClicked() -{ - SectionTitleWidget* stw = qobject_cast(sender()); - if (stw) - { - int index = _tabsLayout->indexOf(stw); - setCurrentIndex(index); - } -} - -void SectionWidget::onCloseButtonClicked() -{ - const int index = currentIndex(); - if (index < 0 || index > m_Contents.size() - 1) - return; - SectionContent::RefPtr sc = m_Contents.at(index); - if (sc.isNull()) - return; - m_MainContainerWidget->hideSectionContent(sc); -} - -void SectionWidget::onTabsMenuActionTriggered(bool) -{ - QAction* a = qobject_cast(sender()); - if (a) - { - const int uid = a->data().toInt(); - const int index = indexOfContentByUid(uid); - if (index >= 0) - setCurrentIndex(index); - } -} - -void SectionWidget::updateTabsMenu() -{ - QMenu* m = new QMenu(); - for (int i = 0; i < m_Contents.count(); ++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))); - } - QMenu* old = _tabsMenuButton->menu(); - _tabsMenuButton->setMenu(m); - delete old; -} - -int SectionWidget::GetNextUid() -{ - static int NextUid = 0; - return ++NextUid; -} - - -/*****************************************************************************/ - -SectionWidgetTabsScrollArea::SectionWidgetTabsScrollArea(SectionWidget*, - QWidget* parent) : - QScrollArea(parent) -{ - /* Important: QSizePolicy::Ignored makes the QScrollArea behaves - like a QLabel and automatically fits into the layout. */ - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored); - setFrameStyle(QFrame::NoFrame); - setWidgetResizable(true); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); -} - -SectionWidgetTabsScrollArea::~SectionWidgetTabsScrollArea() -{ -} - -void SectionWidgetTabsScrollArea::wheelEvent(QWheelEvent* e) -{ - e->accept(); - const int direction = e->angleDelta().y(); - if (direction < 0) - horizontalScrollBar()->setValue(horizontalScrollBar()->value() + 20); - else - horizontalScrollBar()->setValue(horizontalScrollBar()->value() - 20); -} - - -void SectionWidgetTabsScrollArea::mousePressEvent(QMouseEvent* ev) -{ - qInfo() << "mousePressEvent " << ev->type(); - if (ev->button() == Qt::LeftButton) - { - ev->accept(); - _dragStartPos = ev->pos(); - return; - } - QScrollArea::mousePressEvent(ev); -} - -void SectionWidgetTabsScrollArea::mouseMoveEvent(QMouseEvent* ev) -{ - /*if (_fw) - { - return; - } - - ContainerWidget* cw = findParentContainerWidget(this); - SectionWidget* sectionWidget = findParentSectionWidget(this); - - qInfo() << "mousePressEvent " << ev->type(); - ev->accept(); - - _fw = new FloatingWidget(sectionWidget); - _fw->resize(sectionWidget->size()); - cw->_floatings.append(_fw); // Note: I don't like this... - - const QPoint moveToPos = ev->globalPos() - (_dragStartPos + QPoint(ADS_WINDOW_FRAME_BORDER_WIDTH, ADS_WINDOW_FRAME_BORDER_WIDTH)); - _fw->move(moveToPos); - _fw->show(); - - //delete sectionWidget; - deleteEmptySplitter(cw);*/ - QScrollArea::mouseMoveEvent(ev); - return; -} - -} // namespace ads diff --git a/AdvancedDockingSystem/src/SectionWidget.h b/AdvancedDockingSystem/src/SectionWidget.h deleted file mode 100644 index e4ce51f..0000000 --- a/AdvancedDockingSystem/src/SectionWidget.h +++ /dev/null @@ -1,130 +0,0 @@ -#ifndef SECTION_WIDGET_H -#define SECTION_WIDGET_H -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ -#include -#include -#include -#include -#include - -class QBoxLayout; -class QStackedLayout; -class QPushButton; -class QMenu; - -#include "API.h" -#include "Internal.h" -#include "SectionContent.h" -#include "FloatingWidget.h" - -namespace ads -{ - -class CMainContainerWidget; -class SectionTitleWidget; -class CSectionContentWidget; - -// SectionWidget manages multiple instances of SectionContent. -// It displays a title TAB, which is clickable and will switch to -// the contents associated to the title when clicked. -class ADS_EXPORT_API SectionWidget : public QFrame -{ - Q_OBJECT - friend class CMainContainerWidget; - friend class CContainerWidget; - - explicit SectionWidget(CMainContainerWidget* MainContainer, CContainerWidget* parent); - -public: - virtual ~SectionWidget(); - - int uid() const; - CContainerWidget* containerWidget() const; - - QRect titleAreaGeometry() const; - QRect contentAreaGeometry() const; - - const QList& contents() const { return m_Contents; } - void addContent(const SectionContent::RefPtr& c); - void addContent(const InternalContentData& data, bool autoActivate); - bool takeContent(int uid, InternalContentData& data); - bool takeContentAt(int Index, InternalContentData& data); - int indexOfContent(const SectionContent::RefPtr& c) const; - int indexOfContentByUid(int uid) const; - int indexOfContentByTitlePos(const QPoint& pos, QWidget* exclude = NULL) const; - - int currentIndex() const; - void moveContent(int from, int to); - - inline int contentCount() const {return m_ContentWidgets.size();} - -protected: - virtual void showEvent(QShowEvent*); - -public slots: - void setCurrentIndex(int index); - -private slots: - void onSectionTitleClicked(); - void onCloseButtonClicked(); - void onTabsMenuActionTriggered(bool); - void updateTabsMenu(); - - -private: - const int _uid; - QPointer m_MainContainerWidget; - QList m_Contents; - QList m_TitleWidgets; - QList m_ContentWidgets; - - QBoxLayout* _topLayout; - QScrollArea* _tabsScrollArea; - QWidget* _tabsContainerWidget; - QBoxLayout* _tabsLayout; - QPushButton* _tabsMenuButton; - QPushButton* _closeButton; - int _tabsLayoutInitCount; // used for calculations on _tabsLayout modification calls. - - QStackedLayout *_contentsLayout; - - QPoint _mousePressPoint; - SectionContent::RefPtr _mousePressContent; - SectionTitleWidget* _mousePressTitleWidget; - - static int GetNextUid(); -}; - -/* Custom scrollable implementation for tabs */ -class SectionWidgetTabsScrollArea : public QScrollArea -{ -public: - SectionWidgetTabsScrollArea(SectionWidget* sectionWidget, QWidget* parent = NULL); - virtual ~SectionWidgetTabsScrollArea(); - -protected: - QPoint _dragStartPos; - QPointer _fw; - virtual void wheelEvent(QWheelEvent*); - virtual void mousePressEvent(QMouseEvent* ev); - virtual void mouseMoveEvent(QMouseEvent* ev); -}; - -} // namespace ads -#endif diff --git a/AdvancedDockingSystem/src/Serialization.cpp b/AdvancedDockingSystem/src/Serialization.cpp deleted file mode 100644 index 6d300e4..0000000 --- a/AdvancedDockingSystem/src/Serialization.cpp +++ /dev/null @@ -1,459 +0,0 @@ -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ - -#include "Serialization.h" - -#include - -namespace ads -{ - -/* - \namespace ads::serialization - - Serialization of ContainerWidget - -------------------------------- - - # Data Format Header - - quint32 Magic - quint32 Major Version - quint32 Minor Version - - # Offsets of available contents - - qint32 Number of offset headers - LOOP - qint32 Type (e.g. Hierachy, SectionIndex) - qint64 Offset - qint64 Length - - # Type: Hierachy - # Used to recreate the GUI geometry and state. - - int Number of floating widgets - LOOP Floating widgets - QString Unique name of content - QByteArray Geometry of floating widget - bool Visibility - - int Number of layout items (Valid values: 0, 1) - IF 0 - int Number of hidden contents - LOOP Contents - QString Unique name of content - ELSEIF 1 - ... todo ... - ENDIF - - # Type: SectionIndex - # Can be used for quick lookups on details for SectionWidgets. - # It includes sizes and its contents. - - qint32 Number of section-widgets - LOOP - qint32 Width - qint32 Height - qint32 Current active tab index - qint32 Number of contents - LOOP - QString Unique name of content - bool Visibility - qint32 Preferred tab index - -*/ - -/////////////////////////////////////////////////////////////////////////////// - -qint32 HeaderEntity::MAGIC = 0x00001337; -qint32 HeaderEntity::MAJOR_VERSION = 2; -qint32 HeaderEntity::MINOR_VERSION = 0; - -HeaderEntity::HeaderEntity() : - magic(0), majorVersion(0), minorVersion(0) -{ -} - -QDataStream& operator<<(QDataStream& out, const HeaderEntity& data) -{ - out << data.magic; - out << data.majorVersion; - out << data.minorVersion; - return out; -} - -QDataStream& operator>>(QDataStream& in, HeaderEntity& data) -{ - in >> data.magic; - in >> data.majorVersion; - in >> data.minorVersion; - return in; -} - -/////////////////////////////////////////////////////////////////////////////// - -OffsetsHeaderEntity::OffsetsHeaderEntity() : - entriesCount(0) -{ -} - -QDataStream& operator<<(QDataStream& out, const OffsetsHeaderEntity& data) -{ - out << data.entriesCount; - for (int i = 0; i < data.entriesCount; ++i) - { - out << data.entries.at(i); - } - return out; -} - -QDataStream& operator>>(QDataStream& in, OffsetsHeaderEntity& data) -{ - in >> data.entriesCount; - for (int i = 0; i < data.entriesCount; ++i) - { - OffsetsHeaderEntryEntity entry; - in >> entry; - data.entries.append(entry); - } - return in; -} - -/////////////////////////////////////////////////////////////////////////////// - -OffsetsHeaderEntryEntity::OffsetsHeaderEntryEntity() : - type(ET_Unknown), offset(0), contentSize(0) -{ -} - -QDataStream& operator<<(QDataStream& out, const OffsetsHeaderEntryEntity& data) -{ - out << data.type; - out << data.offset; - out << data.contentSize; - return out; -} - -QDataStream& operator>>(QDataStream& in, OffsetsHeaderEntryEntity& data) -{ - in >> data.type; - in >> data.offset; - in >> data.contentSize; - return in; -} - -/////////////////////////////////////////////////////////////////////////////// - -SectionEntity::SectionEntity() : - x(0), y(0), width(0), height(0), currentIndex(0), sectionContentsCount(0) -{ -} - -QDataStream& operator<<(QDataStream& out, const SectionEntity& data) -{ - out << data.x; - out << data.y; - out << data.width; - out << data.height; - out << data.currentIndex; - out << data.sectionContentsCount; - for (int i = 0; i < data.sectionContentsCount; ++i) - { - out << data.sectionContents.at(i); - } - return out; -} - -QDataStream& operator>>(QDataStream& in, SectionEntity& data) -{ - in >> data.x; - in >> data.y; - in >> data.width; - in >> data.height; - in >> data.currentIndex; - in >> data.sectionContentsCount; - for (int i = 0; i < data.sectionContentsCount; ++i) - { - SectionContentEntity sc; - in >> sc; - data.sectionContents.append(sc); - } - return in; -} - -/////////////////////////////////////////////////////////////////////////////// - -SectionContentEntity::SectionContentEntity() : - visible(false), preferredIndex(0) -{ -} - -QDataStream& operator<<(QDataStream& out, const SectionContentEntity& data) -{ - out << data.uniqueName; - out << data.visible; - out << data.preferredIndex; - return out; -} - -QDataStream& operator>>(QDataStream& in, SectionContentEntity& data) -{ - in >> data.uniqueName; - in >> data.visible; - in >> data.preferredIndex; - return in; -} - -/////////////////////////////////////////////////////////////////////////////// - -FloatingContentEntity::FloatingContentEntity() : - xpos(0), ypos(0), width(0), height(0), visible(false) -{ -} - -QDataStream& operator<<(QDataStream& out, const FloatingContentEntity& data) -{ - out << data.uniqueName; - out << data.xpos; - out << data.ypos; - out << data.width; - out << data.height; - out << data.visible; - return out; -} - -QDataStream& operator>>(QDataStream& in, FloatingContentEntity& data) -{ - in >> data.uniqueName; - in >> data.xpos; - in >> data.ypos; - in >> data.width; - in >> data.height; - in >> data.visible; - return in; -} - -/////////////////////////////////////////////////////////////////////////////// - -HierarchyData::HierarchyData() -{ -} - -QDataStream& operator<<(QDataStream& out, const HierarchyData& data) -{ - out << data.data; - return out; -} - -QDataStream& operator>>(QDataStream& in, HierarchyData& data) -{ - in >> data.data; - return in; -} - -/////////////////////////////////////////////////////////////////////////////// - -SectionIndexData::SectionIndexData() : - sectionsCount(0) -{ -} - -QDataStream& operator<<(QDataStream& out, const SectionIndexData& data) -{ - out << data.sectionsCount; - for (int i = 0; i < data.sectionsCount; ++i) - { - out << data.sections.at(i); - } - return out; -} - -QDataStream& operator>>(QDataStream& in, SectionIndexData& data) -{ - in >> data.sectionsCount; - for (int i = 0; i < data.sectionsCount; ++i) - { - SectionEntity s; - in >> s; - data.sections.append(s); - } - return in; -} - -/////////////////////////////////////////////////////////////////////////////// - -InMemoryWriter::InMemoryWriter() -{ - _contentBuffer.open(QIODevice::ReadWrite); -} - -bool InMemoryWriter::write(qint32 entryType, const QByteArray& data) -{ - OffsetsHeaderEntryEntity entry; - entry.type = entryType; - entry.offset = _contentBuffer.pos(); // Relative offset! - entry.contentSize = data.size(); - - _contentBuffer.write(data); - - _offsetsHeader.entries.append(entry); - _offsetsHeader.entriesCount += 1; - - return true; -} - -bool InMemoryWriter::write(const SectionIndexData& data) -{ - OffsetsHeaderEntryEntity entry; - entry.type = ET_SectionIndex; - entry.offset = _contentBuffer.pos(); // Relative offset! - - QDataStream out(&_contentBuffer); - out.setVersion(QDataStream::Qt_4_5); - out << data; - - entry.contentSize = _contentBuffer.size() - entry.offset; - - _offsetsHeader.entries.append(entry); - _offsetsHeader.entriesCount += 1; - - return true; -} - -QByteArray InMemoryWriter::toByteArray() const -{ - QByteArray data; - QDataStream out(&data, QIODevice::ReadWrite); - out.setVersion(QDataStream::Qt_4_5); - - // Basic format header. - HeaderEntity header; - header.magic = HeaderEntity::MAGIC; - header.majorVersion = HeaderEntity::MAJOR_VERSION; - header.minorVersion = HeaderEntity::MINOR_VERSION; - out << header; - - // Offsets-Header - // - Save begin pos - // - Write OffsetsHeader - // - Convert relative- to absolute-offsets - // - Seek back to begin-pos and write OffsetsHeader again. - // Use a copy of OffsetsHeader to keep the _offsetsHeader relative. - const qint64 posOffsetHeaders = out.device()->pos(); - OffsetsHeaderEntity offsetsHeader = _offsetsHeader; - out << offsetsHeader; - - // Now we know the size of the entire header. - // We can update the relative- to absolute-offsets now. - const qint64 allHeaderSize = out.device()->pos(); - for (int i = 0; i < offsetsHeader.entriesCount; ++i) - { - offsetsHeader.entries[i].offset += allHeaderSize; // Absolute offset! - } - - // Seek back and write again with absolute offsets. - // TODO Thats not nice, but it works... - out.device()->seek(posOffsetHeaders); - out << offsetsHeader; - - // Write contents. - out.writeRawData(_contentBuffer.data().constData(), _contentBuffer.size()); - - return data; -} - -/////////////////////////////////////////////////////////////////////////////// - -InMemoryReader::InMemoryReader(const QByteArray& data) : - _data(data) -{ -} - -bool InMemoryReader::initReadHeader() -{ - QDataStream in(_data); - in.setVersion(QDataStream::Qt_4_5); - - // Basic format header. - HeaderEntity header; - in >> header; - if (header.magic != HeaderEntity::MAGIC) - { - qWarning() << QString("invalid format (magic=%1)").arg(header.magic); - return false; - } - if (header.majorVersion != HeaderEntity::MAJOR_VERSION) - { - qWarning() << QString("format is too new (major=%1; minor=%2)") - .arg(header.majorVersion).arg(header.minorVersion); - return false; - } - - // OffsetsHeader. - in >> _offsetsHeader; - - return !in.atEnd(); -} - -bool InMemoryReader::read(qint32 entryType, QByteArray& data) -{ - // Find offset for "type". - int index = -1; - for (int i = 0; i < _offsetsHeader.entriesCount; ++i) - { - if (_offsetsHeader.entries.at(i).type == entryType) - { - index = i; - break; - } - } - if (index < 0) - return false; - else if (_offsetsHeader.entries.at(index).offset == 0) - return false; - - const OffsetsHeaderEntryEntity& entry = _offsetsHeader.entries.at(index); - - QDataStream in(_data); - in.setVersion(QDataStream::Qt_4_5); - in.device()->seek(entry.offset); - - char* buff = new char[entry.contentSize]; - in.readRawData(buff, entry.contentSize); - data.append(buff, entry.contentSize); - delete[] buff; - - return true; -} - -bool InMemoryReader::read(SectionIndexData& sid) -{ - QByteArray sidData; - if (!read(ET_SectionIndex, sidData) || sidData.isEmpty()) - return false; - - QDataStream in(sidData); - in.setVersion(QDataStream::Qt_4_5); - in >> sid; - - return in.atEnd(); -} - -/////////////////////////////////////////////////////////////////////////////// - -} // namespace ads diff --git a/AdvancedDockingSystem/src/Serialization.h b/AdvancedDockingSystem/src/Serialization.h deleted file mode 100644 index 62b776c..0000000 --- a/AdvancedDockingSystem/src/Serialization.h +++ /dev/null @@ -1,182 +0,0 @@ -#ifndef ADS_SERIALIZATION_H -#define ADS_SERIALIZATION_H -/******************************************************************************* -** QtAdcancedDockingSystem -** Copyright (C) 2017 Uwe Kindler -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -******************************************************************************/ -#include -#include -#include -#include -#include - -#include "API.h" - -namespace ads -{ - -enum EntryType -{ - ET_Unknown = 0x00000000, - ET_Hierarchy = 0x00000001, - ET_SectionIndex = 0x00000002, - - // Begin of custom entry types (e.g. CustomType + 42) - ET_Custom = 0x0000ffff -}; - -class ADS_EXPORT_API HeaderEntity -{ -public: - static qint32 MAGIC; - static qint32 MAJOR_VERSION; - static qint32 MINOR_VERSION; - - HeaderEntity(); - qint32 magic; - qint32 majorVersion; - qint32 minorVersion; -}; -QDataStream& operator<<(QDataStream& out, const HeaderEntity& data); -QDataStream& operator>>(QDataStream& in, HeaderEntity& data); - - -class ADS_EXPORT_API OffsetsHeaderEntity -{ -public: - OffsetsHeaderEntity(); - - qint64 entriesCount; - QList entries; -}; -QDataStream& operator<<(QDataStream& out, const OffsetsHeaderEntity& data); -QDataStream& operator>>(QDataStream& in, OffsetsHeaderEntity& data); - - -class ADS_EXPORT_API OffsetsHeaderEntryEntity -{ -public: - OffsetsHeaderEntryEntity(); - qint32 type; - qint64 offset; - qint64 contentSize; -}; -QDataStream& operator<<(QDataStream& out, const OffsetsHeaderEntryEntity& data); -QDataStream& operator>>(QDataStream& in, OffsetsHeaderEntryEntity& data); - - -class ADS_EXPORT_API SectionEntity -{ -public: - SectionEntity(); - qint32 x; - qint32 y; - qint32 width; - qint32 height; - qint32 currentIndex; - qint32 sectionContentsCount; - QList sectionContents; -}; -QDataStream& operator<<(QDataStream& out, const SectionEntity& data); -QDataStream& operator>>(QDataStream& in, SectionEntity& data); - - -class ADS_EXPORT_API SectionContentEntity -{ -public: - SectionContentEntity(); - QString uniqueName; - bool visible; - qint32 preferredIndex; -}; -QDataStream& operator<<(QDataStream& out, const SectionContentEntity& data); -QDataStream& operator>>(QDataStream& in, SectionContentEntity& data); - - -class ADS_EXPORT_API FloatingContentEntity -{ -public: - FloatingContentEntity(); - QString uniqueName; - qint32 xpos; - qint32 ypos; - qint32 width; - qint32 height; - bool visible; -}; -QDataStream& operator<<(QDataStream& out, const FloatingContentEntity& data); -QDataStream& operator>>(QDataStream& in, FloatingContentEntity& data); - - -// Type: OffsetHeaderEntry::Hierarchy -class ADS_EXPORT_API HierarchyData -{ -public: - HierarchyData(); - QByteArray data; -}; -QDataStream& operator<<(QDataStream& out, const HierarchyData& data); -QDataStream& operator>>(QDataStream& in, HierarchyData& data); - - -// Type: OffsetHeaderEntry::SectionIndex -class ADS_EXPORT_API SectionIndexData -{ -public: - SectionIndexData(); - qint32 sectionsCount; - QList sections; -}; -QDataStream& operator<<(QDataStream& out, const SectionIndexData& data); -QDataStream& operator>>(QDataStream& in, SectionIndexData& data); - - -/*! - * \brief The InMemoryWriter class writes into a QByteArray. - */ -class ADS_EXPORT_API InMemoryWriter -{ -public: - InMemoryWriter(); - bool write(qint32 entryType, const QByteArray& data); - bool write(const SectionIndexData& data); - QByteArray toByteArray() const; - qint32 offsetsCount() const { return _offsetsHeader.entriesCount; } - -private: - QBuffer _contentBuffer; - OffsetsHeaderEntity _offsetsHeader; -}; - -/*! - * \brief The InMemoryReader class - */ -class ADS_EXPORT_API InMemoryReader -{ -public: - InMemoryReader(const QByteArray& data); - bool initReadHeader(); - bool read(qint32 entryType, QByteArray &data); - bool read(SectionIndexData& sid); - qint32 offsetsCount() const { return _offsetsHeader.entriesCount; } - -private: - QByteArray _data; - OffsetsHeaderEntity _offsetsHeader; -}; - -} // namespace ads -#endif diff --git a/AdvancedDockingSystem/src/v2/v2.pri b/AdvancedDockingSystem/src/v2/v2.pri deleted file mode 100644 index faffff3..0000000 --- a/AdvancedDockingSystem/src/v2/v2.pri +++ /dev/null @@ -1,22 +0,0 @@ -DEPENDPATH *= $$PWD -HEADERS += \ - $$PWD/ads_globals.h \ - $$PWD/DockAreaWidget.h \ - $$PWD/DockContainerWidget.h \ - $$PWD/DockManager.h \ - $$PWD/DockWidget.h \ - $$PWD/DockWidgetTitleBar.h \ - $$PWD/FloatingDockContainer.h \ - $$PWD/DockOverlay.h - - - -SOURCES += \ - $$PWD/ads_globals.cpp \ - $$PWD/DockAreaWidget.cpp \ - $$PWD/DockContainerWidget.cpp \ - $$PWD/DockManager.cpp \ - $$PWD/DockWidget.cpp \ - $$PWD/DockWidgetTitleBar.cpp \ - $$PWD/FloatingDockContainer.cpp \ - $$PWD/DockOverlay.cpp \ No newline at end of file diff --git a/AdvancedDockingSystemDemo/AdvancedDockingSystemDemo.pro b/AdvancedDockingSystemDemo/AdvancedDockingSystemDemo.pro deleted file mode 100644 index 90c532b..0000000 --- a/AdvancedDockingSystemDemo/AdvancedDockingSystemDemo.pro +++ /dev/null @@ -1,57 +0,0 @@ -include($$(cetoni_repository)/build/qt/qtprojectsettings/common.pri) - -TARGET = AdvancedDockingSystemDemo - -QT += core gui -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -greaterThan(QT_MAJOR_VERSION, 4): DEFINES += ADS_NAMESPACE_ENABLED - -windows { - # MinGW - *-g++* { - QMAKE_CXXFLAGS += -std=c++11 - } - # MSVC - *-msvc* { - } -} - -SOURCES += \ - src/main.cpp \ - src/mainwindow.cpp \ - src/icontitlewidget.cpp \ - src/dialogs/SectionContentListModel.cpp \ - src/dialogs/SectionContentListWidget.cpp - -HEADERS += \ - src/mainwindow.h \ - src/icontitlewidget.h \ - src/dialogs/SectionContentListModel.h \ - src/dialogs/SectionContentListWidget.h - -FORMS += \ - src/mainwindow.ui \ - src/dialogs/SectionContentListWidget.ui - - -# Dependency: AdvancedDockingSystem (staticlib) -#win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../AdvancedDockingSystem/release/ -lAdvancedDockingSystem -#else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../AdvancedDockingSystem/debug/ -lAdvancedDockingSystem -#else:unix: LIBS += -L$$OUT_PWD/../AdvancedDockingSystem/ -lAdvancedDockingSystem - -#INCLUDEPATH += $$PWD/../AdvancedDockingSystem/include -#DEPENDPATH += $$PWD/../AdvancedDockingSystem/include - -#win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../AdvancedDockingSystem/release/libAdvancedDockingSystem.a -#else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../AdvancedDockingSystem/debug/libAdvancedDockingSystem.a -#else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../AdvancedDockingSystem/release/AdvancedDockingSystem.lib -#else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../AdvancedDockingSystem/debug/AdvancedDockingSystem.lib -#else:unix: PRE_TARGETDEPS += $$OUT_PWD/../AdvancedDockingSystem/libAdvancedDockingSystem.a - -# Dependency: AdvancedDockingSystem (shared) -win32:CONFIG(release, debug|release): LIBS += -l$$qtLinkLibrary(AdvancedDockingSystem) -else:win32:CONFIG(debug, debug|release): LIBS += -l$$qtLinkLibrary(AdvancedDockingSystem) -else:unix: LIBS += -L$$OUT_PWD/../AdvancedDockingSystem/ -lAdvancedDockingSystem - -INCLUDEPATH += $$PWD/../AdvancedDockingSystem/src -DEPENDPATH += $$PWD/../AdvancedDockingSystem/src diff --git a/AdvancedDockingSystemDemo/src/dialogs/SectionContentListModel.cpp b/AdvancedDockingSystemDemo/src/dialogs/SectionContentListModel.cpp deleted file mode 100644 index ccfff64..0000000 --- a/AdvancedDockingSystemDemo/src/dialogs/SectionContentListModel.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "SectionContentListModel.h" - -SectionContentListModel::SectionContentListModel(QObject* parent) : - QAbstractTableModel(parent) -{ - _headers.insert(UidColumn, "UID"); - _headers.insert(UniqueNameColumn, "Unique Name"); - _headers.insert(TitleColumn, "Title"); - _headers.insert(VisibleColumn, "Visible"); -} - -SectionContentListModel::~SectionContentListModel() -{ -} - -void SectionContentListModel::init(ads::CMainContainerWidget* cw) -{ - beginResetModel(); - _cw = cw; - _contents = _cw->contents(); - endResetModel(); -} - -int SectionContentListModel::columnCount(const QModelIndex& parent) const -{ - Q_UNUSED(parent) - return _headers.count(); -} - -QVariant SectionContentListModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) - return _headers.value(section); - return QVariant(); -} - -int SectionContentListModel::rowCount(const QModelIndex& parent) const -{ - Q_UNUSED(parent) - return _contents.count(); -} - -QVariant SectionContentListModel::data(const QModelIndex& index, int role) const -{ - if (!index.isValid() || index.row() > rowCount(index) - 1) - return QVariant(); - - const ads::SectionContent::RefPtr sc = _contents.at(index.row()); - if (sc.isNull()) - return QVariant(); - - switch (role) - { - case Qt::DisplayRole: - { - switch (index.column()) - { - case UidColumn: - return sc->uid(); - case UniqueNameColumn: - return sc->uniqueName(); - case TitleColumn: - return sc->title(); - case VisibleColumn: - return _cw->isSectionContentVisible(sc); - } - } - } - return QVariant(); -} - -bool SectionContentListModel::removeRows(int row, int count, const QModelIndex& parent) -{ - if (row > rowCount(parent) - 1) - return false; - - const int first = row; - const int last = row + count - 1; - beginRemoveRows(parent, first, last); - - for (int i = last; i >= first; --i) - { - const ads::SectionContent::RefPtr sc = _contents.at(i); - _cw->removeSectionContent(sc); - _contents.removeAt(i); - } - - endRemoveRows(); - return true; -} diff --git a/AdvancedDockingSystemDemo/src/dialogs/SectionContentListModel.h b/AdvancedDockingSystemDemo/src/dialogs/SectionContentListModel.h deleted file mode 100644 index b0aad42..0000000 --- a/AdvancedDockingSystemDemo/src/dialogs/SectionContentListModel.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef ADS_SECTIONCONTENTMODEL_H -#define ADS_SECTIONCONTENTMODEL_H - -#include -#include -#include -#include -#include "../../../AdvancedDockingSystem/src/SectionContent.h" -#include "MainContainerWidget.h" -#include "API.h" -namespace ads {class CMainContainerWidget;} - - -class SectionContentListModel : public QAbstractTableModel -{ - Q_OBJECT - -public: - enum Column - { - UidColumn, - UniqueNameColumn, - TitleColumn, - VisibleColumn - }; - - SectionContentListModel(QObject* parent); - virtual ~SectionContentListModel(); - void init(ads::CMainContainerWidget* cw); - - virtual int columnCount(const QModelIndex &parent) const; - virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; - - virtual int rowCount(const QModelIndex &parent) const; - virtual QVariant data(const QModelIndex &index, int role) const; - - virtual bool removeRows(int row, int count, const QModelIndex &parent); - -private: - QHash _headers; - - ads::CMainContainerWidget* _cw; - QList _contents; -}; - -#endif diff --git a/AdvancedDockingSystemDemo/src/dialogs/SectionContentListWidget.cpp b/AdvancedDockingSystemDemo/src/dialogs/SectionContentListWidget.cpp deleted file mode 100644 index 26a3b46..0000000 --- a/AdvancedDockingSystemDemo/src/dialogs/SectionContentListWidget.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "SectionContentListWidget.h" -#include "SectionContentListModel.h" - - -SectionContentListWidget::SectionContentListWidget(QWidget* parent) : - QDialog(parent) -{ - _ui.setupUi(this); - connect(_ui.deleteButton, SIGNAL(clicked(bool)), this, SLOT(onDeleteButtonClicked())); -} - -void SectionContentListWidget::setValues(const SectionContentListWidget::Values& v) -{ - _v = v; - - // Reset - QAbstractItemModel* m = _ui.tableView->model(); - if (m) - { - _ui.tableView->setModel(NULL); - delete m; - m = NULL; - } - - // Fill. - SectionContentListModel* sclm = new SectionContentListModel(this); - sclm->init(_v.cw); - _ui.tableView->setModel(sclm); -} - -void SectionContentListWidget::onDeleteButtonClicked() -{ - const QModelIndex mi = _ui.tableView->currentIndex(); - if (!mi.isValid()) - return; - - _ui.tableView->model()->removeRows(mi.row(), 1, mi.parent()); -} diff --git a/AdvancedDockingSystemDemo/src/dialogs/SectionContentListWidget.h b/AdvancedDockingSystemDemo/src/dialogs/SectionContentListWidget.h deleted file mode 100644 index 255081d..0000000 --- a/AdvancedDockingSystemDemo/src/dialogs/SectionContentListWidget.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef SECTIONCONTENTLISTWIDGET -#define SECTIONCONTENTLISTWIDGET - -#include -#include "../../../AdvancedDockingSystem/src/SectionContent.h" -#include "MainContainerWidget.h" -#include "ui_SectionContentListWidget.h" - -#include "API.h" - -class SectionContentListWidget : public QDialog -{ - Q_OBJECT - -public: - class Values - { - public: - ads::CMainContainerWidget* cw; - }; - - SectionContentListWidget(QWidget* parent); - void setValues(const Values& v); - -private slots: - void onDeleteButtonClicked(); - -private: - Ui::SectionContentListWidgetForm _ui; - Values _v; -}; - -#endif diff --git a/AdvancedDockingSystemDemo/src/dialogs/SectionContentListWidget.ui b/AdvancedDockingSystemDemo/src/dialogs/SectionContentListWidget.ui deleted file mode 100644 index 1f25ed3..0000000 --- a/AdvancedDockingSystemDemo/src/dialogs/SectionContentListWidget.ui +++ /dev/null @@ -1,61 +0,0 @@ - - - SectionContentListWidgetForm - - - - 0 - 0 - 522 - 258 - - - - Form - - - - - - QAbstractItemView::NoEditTriggers - - - true - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - - - - - - - Delete - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - diff --git a/AdvancedDockingSystemDemo/src/icontitlewidget.cpp b/AdvancedDockingSystemDemo/src/icontitlewidget.cpp deleted file mode 100644 index a2db3af..0000000 --- a/AdvancedDockingSystemDemo/src/icontitlewidget.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "icontitlewidget.h" - -#include -#include -#include -#include -#include - -IconTitleWidget::IconTitleWidget(const QIcon& icon, const QString& title, QWidget *parent) : - QFrame(parent) -{ - QBoxLayout* l = new QBoxLayout(QBoxLayout::LeftToRight); - l->setContentsMargins(0, 0, 0, 0); - setLayout(l); - - _iconLabel = new QLabel(); - _iconLabel->setAlignment(Qt::AlignVCenter); - l->addWidget(_iconLabel, Qt::AlignVCenter); - - _titleLabel = new QLabel(); - l->addWidget(_titleLabel, 1); - - setIcon(icon); - setTitle(title); -} - -void IconTitleWidget::setIcon(const QIcon& icon) -{ - if (icon.isNull()) - { - _iconLabel->setPixmap(QPixmap()); - _iconLabel->setVisible(false); - } - else - { - _iconLabel->setPixmap(icon.pixmap(16, 16)); - _iconLabel->setVisible(true); - } -} - -void IconTitleWidget::setTitle(const QString& title) -{ - if (title.isEmpty()) - { - _titleLabel->setText(QString()); - _titleLabel->setVisible(false); - } - else - { - _titleLabel->setText(title); - _titleLabel->setVisible(true); - } -} - -void IconTitleWidget::polishUpdate() -{ - QList widgets; - widgets.append(_iconLabel); - widgets.append(_titleLabel); - foreach (QWidget* w, widgets) - { - w->style()->unpolish(w); - w->style()->polish(w); - w->update(); - } -} diff --git a/AdvancedDockingSystemDemo/src/icontitlewidget.h b/AdvancedDockingSystemDemo/src/icontitlewidget.h deleted file mode 100644 index 35bb982..0000000 --- a/AdvancedDockingSystemDemo/src/icontitlewidget.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef ICONTITLEWIDGET_H -#define ICONTITLEWIDGET_H - -#include -class QIcon; -class QString; -class QLabel; - -class IconTitleWidget : public QFrame -{ - Q_OBJECT - -public: - explicit IconTitleWidget(const QIcon& icon, const QString& title, QWidget *parent = 0); - -public slots: - void setIcon(const QIcon& icon); - void setTitle(const QString& title); - void polishUpdate(); - -public: - QLabel* _iconLabel; - QLabel* _titleLabel; -}; - -#endif // ICONTITLEWIDGET_H diff --git a/AdvancedDockingSystemDemo/src/main.cpp b/AdvancedDockingSystemDemo/src/main.cpp deleted file mode 100644 index 620f65e..0000000 --- a/AdvancedDockingSystemDemo/src/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include - -#include "mainwindow.h" - -static void initStyleSheet(QApplication& a) -{ - //Q_INIT_RESOURCE(ads); // If static linked. - QFile f(":ads/stylesheets/default-windows.css"); - if (f.open(QFile::ReadOnly)) - { - const QByteArray ba = f.readAll(); - f.close(); - a.setStyleSheet(QString(ba)); - } -} - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - a.setQuitOnLastWindowClosed(true); - initStyleSheet(a); - - MainWindow mw; - mw.show(); - return a.exec(); -} diff --git a/AdvancedDockingSystemDemo/src/mainwindow.cpp b/AdvancedDockingSystemDemo/src/mainwindow.cpp deleted file mode 100644 index 109c088..0000000 --- a/AdvancedDockingSystemDemo/src/mainwindow.cpp +++ /dev/null @@ -1,195 +0,0 @@ -#include "mainwindow.h" -#include "ui_mainwindow.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "SectionWidget.h" -#include "DropOverlay.h" - -#include "dialogs/SectionContentListWidget.h" - -#include "icontitlewidget.h" - -/////////////////////////////////////////////////////////////////////// - -static int CONTENT_COUNT = 0; - -static ads::SectionContent::RefPtr createLongTextLabelSC(ads::CMainContainerWidget* container) -{ - QWidget* w = new QWidget(); - QBoxLayout* bl = new QBoxLayout(QBoxLayout::TopToBottom); - w->setLayout(bl); - - QLabel* l = new QLabel(); - l->setWordWrap(true); - l->setAlignment(Qt::AlignTop | Qt::AlignLeft); - l->setText(QString("Lorem Ipsum ist ein einfacher Demo-Text für die Print- und Schriftindustrie. Lorem Ipsum ist in der Industrie bereits der Standard Demo-Text seit 1500, als ein unbekannter Schriftsteller eine Hand voll Wörter nahm und diese durcheinander warf um ein Musterbuch zu erstellen. Es hat nicht nur 5 Jahrhunderte überlebt, sondern auch in Spruch in die elektronische Schriftbearbeitung geschafft (bemerke, nahezu unverändert). Bekannt wurde es 1960, mit dem erscheinen von Letrase, welches Passagen von Lorem Ipsum enhielt, so wie Desktop Software wie Aldus PageMaker - ebenfalls mit Lorem Ipsum.")); - bl->addWidget(l); - - const int index = ++CONTENT_COUNT; - ads::SectionContent::RefPtr sc = ads::SectionContent::newSectionContent(QString("uname-%1").arg(index), container, new IconTitleWidget(QIcon(), QString("Label %1").arg(index)), w); - sc->setTitle("Ein Label " + QString::number(index)); - return sc; -} - -static ads::SectionContent::RefPtr createCalendarSC(ads::CMainContainerWidget* container) -{ - QCalendarWidget* w = new QCalendarWidget(); - - const int index = ++CONTENT_COUNT; - return ads::SectionContent::newSectionContent(QString("uname-%1").arg(index), container, new IconTitleWidget(QIcon(), QString("Calendar %1").arg(index)), w); -} - -static ads::SectionContent::RefPtr createFileSystemTreeSC(ads::CMainContainerWidget* container) -{ - QTreeView* w = new QTreeView(); - w->setFrameShape(QFrame::NoFrame); - // QFileSystemModel* m = new QFileSystemModel(w); - // m->setRootPath(QDir::currentPath()); - // w->setModel(m); - - const int index = ++CONTENT_COUNT; - return ads::SectionContent::newSectionContent(QString("uname-%1").arg(index), container, new IconTitleWidget(QIcon(), QString("Filesystem %1").arg(index)), w); -} - -static void storeDataHelper(const QString& fname, const QByteArray& ba) -{ - QFile f(fname + QString(".dat")); - if (f.open(QFile::WriteOnly)) - { - f.write(ba); - f.close(); - } -} - -static QByteArray loadDataHelper(const QString& fname) -{ - QFile f(fname + QString(".dat")); - if (f.open(QFile::ReadOnly)) - { - QByteArray ba = f.readAll(); - f.close(); - return ba; - } - return QByteArray(); -} - -/////////////////////////////////////////////////////////////////////// - -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow) -{ - ui->setupUi(this); - - // Setup actions. - connect(ui->actionContentList, SIGNAL(triggered()), this, SLOT(showSectionContentListDialog())); - - // ADS - Create main container (ContainerWidget). - _container = new ads::CMainContainerWidget(); - connect(_container, SIGNAL(activeTabChanged(const SectionContent::RefPtr&, bool)), this, SLOT(onActiveTabChanged(const SectionContent::RefPtr&, bool))); - connect(_container, SIGNAL(sectionContentVisibilityChanged(SectionContent::RefPtr,bool)), this, SLOT(onSectionContentVisibilityChanged(SectionContent::RefPtr,bool))); - setCentralWidget(_container); - createContent(); - // Default window geometry - resize(800, 600); - restoreGeometry(loadDataHelper("MainWindow")); - - // ADS - Restore geometries and states of contents. - //_container->restoreState(loadDataHelper("ContainerWidget")); - _container->dumpLayout(); -} - -MainWindow::~MainWindow() -{ - delete ui; -} - - -void MainWindow::createContent() -{ - // ADS - Adding some contents. - // Test #1: Use high-level public API - ads::CMainContainerWidget* cw = _container; - ads::SectionWidget* sw = nullptr; - - sw = _container->addSectionContent(createLongTextLabelSC(cw), nullptr, ads::CenterDropArea); - sw = _container->addSectionContent(createCalendarSC(cw), nullptr, ads::LeftDropArea); - sw = _container->addSectionContent(createFileSystemTreeSC(cw), nullptr, ads::BottomDropArea); - sw = _container->addSectionContent(createCalendarSC(cw), nullptr, ads::BottomDropArea); - - /*_container->addSectionContent(createCalendarSC(_container)); - _container->addSectionContent(createLongTextLabelSC(_container)); - _container->addSectionContent(createLongTextLabelSC(_container)); - _container->addSectionContent(createLongTextLabelSC(_container)); - - ads::SectionContent::RefPtr sc = createLongTextLabelSC(cw); - sc->setFlags(ads::SectionContent::AllFlags ^ ads::SectionContent::Closeable); - _container->addSectionContent(sc);*/ - -#if 0 - // Issue #2: If the first drop is not into CenterDropArea, the application crashes. - ads::CMainContainerWidget* cw = _container; - ads::SectionWidget* sw = NULL; - - sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ads::LeftDropArea); - sw = _container->addSectionContent(createCalendarSC(cw), sw, ads::LeftDropArea); - sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ads::CenterDropArea); - sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ads::CenterDropArea); - sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ads::CenterDropArea); - sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ads::RightDropArea); - sw = _container->addSectionContent(createLongTextLabelSC(cw), sw, ads::BottomDropArea); -#endif -} - -void MainWindow::showSectionContentListDialog() -{ - SectionContentListWidget::Values v; - v.cw = _container; - - SectionContentListWidget w(this); - w.setValues(v); - w.exec(); -} - -void MainWindow::onActiveTabChanged(const ads::SectionContent::RefPtr& sc, bool active) -{ - Q_UNUSED(active); - IconTitleWidget* itw = dynamic_cast(sc->titleWidgetContent()); - if (itw) - { - itw->polishUpdate(); - } -} - -void MainWindow::onSectionContentVisibilityChanged(const ads::SectionContent::RefPtr& sc, bool visible) -{ - qDebug() << Q_FUNC_INFO << sc->uniqueName() << visible; -} - -void MainWindow::onActionAddSectionContentTriggered() -{ - return; -} - -void MainWindow::contextMenuEvent(QContextMenuEvent* e) -{ - Q_UNUSED(e); - QMenu* m = _container->createContextMenu(); - m->exec(QCursor::pos()); - delete m; -} - -void MainWindow::closeEvent(QCloseEvent* e) -{ - Q_UNUSED(e); - storeDataHelper("MainWindow", saveGeometry()); - storeDataHelper("ContainerWidget", _container->saveState()); -} diff --git a/AdvancedDockingSystemDemo/src/mainwindow.h b/AdvancedDockingSystemDemo/src/mainwindow.h deleted file mode 100644 index bda08c3..0000000 --- a/AdvancedDockingSystemDemo/src/mainwindow.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include -#include "../../AdvancedDockingSystem/src/MainContainerWidget.h" -#include "../../AdvancedDockingSystem/src/SectionContent.h" -#include "API.h" - -namespace Ui { -class MainWindow; -} - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit MainWindow(QWidget *parent = 0); - virtual ~MainWindow(); - -public slots: - -private slots: - void onActiveTabChanged(const ads::SectionContent::RefPtr& sc, bool active); - void onSectionContentVisibilityChanged(const ads::SectionContent::RefPtr& sc, bool visible); - void onActionAddSectionContentTriggered(); - -protected: - virtual void contextMenuEvent(QContextMenuEvent* e); - virtual void closeEvent(QCloseEvent* e); - -private: - Ui::MainWindow *ui; - ads::CMainContainerWidget* _container; - void createContent(); -}; - -#endif // MAINWINDOW_H diff --git a/AdvancedDockingSystemDemo/src/mainwindow.ui b/AdvancedDockingSystemDemo/src/mainwindow.ui deleted file mode 100644 index cce9b48..0000000 --- a/AdvancedDockingSystemDemo/src/mainwindow.ui +++ /dev/null @@ -1,79 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 400 - 300 - - - - MainWindow - - - - - - - 0 - 0 - 400 - 21 - - - - - File - - - - - - View - - - - - - - - About - - - - - - - - - Add SectionContent - - - - - Contents... - - - - - Demo 2 - - - - - Demo 3 - - - - - Exit - - - - - - - diff --git a/AdvancedDockingSystemDemo_v2/src/dialogs/SectionContentListModel.cpp b/AdvancedDockingSystemDemo_v2/src/dialogs/SectionContentListModel.cpp deleted file mode 100644 index 4f4941c..0000000 --- a/AdvancedDockingSystemDemo_v2/src/dialogs/SectionContentListModel.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "SectionContentListModel.h" - -SectionContentListModel::SectionContentListModel(QObject* parent) : - QAbstractTableModel(parent) -{ - _headers.insert(UidColumn, "UID"); - _headers.insert(UniqueNameColumn, "Unique Name"); - _headers.insert(TitleColumn, "Title"); - _headers.insert(VisibleColumn, "Visible"); -} - -SectionContentListModel::~SectionContentListModel() -{ -} - -void SectionContentListModel::init(ads::CMainContainerWidget* cw) -{ - beginResetModel(); - _cw = cw; - _contents = _cw->contents(); - endResetModel(); -} - -int SectionContentListModel::columnCount(const QModelIndex& parent) const -{ - Q_UNUSED(parent) - return _headers.count(); -} - -QVariant SectionContentListModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) - return _headers.value(section); - return QVariant(); -} - -int SectionContentListModel::rowCount(const QModelIndex& parent) const -{ - Q_UNUSED(parent) - return _contents.count(); -} - -QVariant SectionContentListModel::data(const QModelIndex& index, int role) const -{ - if (!index.isValid() || index.row() > rowCount(index) - 1) - return QVariant(); - - const ads::SectionContent::RefPtr sc = _contents.at(index.row()); - if (sc.isNull()) - return QVariant(); - - switch (role) - { - case Qt::DisplayRole: - { - switch (index.column()) - { - case UidColumn: - return sc->uid(); - case UniqueNameColumn: - return sc->uniqueName(); - case TitleColumn: - return sc->title(); - case VisibleColumn: - return _cw->isSectionContentVisible(sc); - } - } - } - return QVariant(); -} - -bool SectionContentListModel::removeRows(int row, int count, const QModelIndex& parent) -{ - if (row > rowCount(parent) - 1) - return false; - - const int first = row; - const int last = row + count - 1; - beginRemoveRows(parent, first, last); - - for (int i = last; i >= first; --i) - { - const ads::SectionContent::RefPtr sc = _contents.at(i); - _cw->removeSectionContent(sc); - _contents.removeAt(i); - } - - endRemoveRows(); - return true; -} diff --git a/AdvancedDockingSystemDemo_v2/src/dialogs/SectionContentListModel.h b/AdvancedDockingSystemDemo_v2/src/dialogs/SectionContentListModel.h deleted file mode 100644 index b066302..0000000 --- a/AdvancedDockingSystemDemo_v2/src/dialogs/SectionContentListModel.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef ADS_SECTIONCONTENTMODEL_H -#define ADS_SECTIONCONTENTMODEL_H - -#include -#include -#include -#include -#include "../../../AdvancedDockingSystem/src/SectionContent.h" -#include "MainContainerWidget.h" -#include "API.h" -namespace ads {class CMainContainerWidget;} - - -class SectionContentListModel : public QAbstractTableModel -{ - Q_OBJECT - -public: - enum Column - { - UidColumn, - UniqueNameColumn, - TitleColumn, - VisibleColumn - }; - - SectionContentListModel(QObject* parent); - virtual ~SectionContentListModel(); - void init(ads::CMainContainerWidget* cw); - - virtual int columnCount(const QModelIndex &parent) const; - virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; - - virtual int rowCount(const QModelIndex &parent) const; - virtual QVariant data(const QModelIndex &index, int role) const; - - virtual bool removeRows(int row, int count, const QModelIndex &parent); - -private: - QHash _headers; - - ads::CMainContainerWidget* _cw; - QList _contents; -}; - -#endif diff --git a/AdvancedDockingSystemDemo_v2/src/dialogs/SectionContentListWidget.cpp b/AdvancedDockingSystemDemo_v2/src/dialogs/SectionContentListWidget.cpp deleted file mode 100644 index a4b060e..0000000 --- a/AdvancedDockingSystemDemo_v2/src/dialogs/SectionContentListWidget.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "SectionContentListWidget.h" -#include "SectionContentListModel.h" - - -SectionContentListWidget::SectionContentListWidget(QWidget* parent) : - QDialog(parent) -{ - _ui.setupUi(this); - connect(_ui.deleteButton, SIGNAL(clicked(bool)), this, SLOT(onDeleteButtonClicked())); -} - -void SectionContentListWidget::setValues(const SectionContentListWidget::Values& v) -{ - _v = v; - - // Reset - QAbstractItemModel* m = _ui.tableView->model(); - if (m) - { - _ui.tableView->setModel(NULL); - delete m; - m = NULL; - } - - // Fill. - SectionContentListModel* sclm = new SectionContentListModel(this); - sclm->init(_v.cw); - _ui.tableView->setModel(sclm); -} - -void SectionContentListWidget::onDeleteButtonClicked() -{ - const QModelIndex mi = _ui.tableView->currentIndex(); - if (!mi.isValid()) - return; - - _ui.tableView->model()->removeRows(mi.row(), 1, mi.parent()); -} diff --git a/AdvancedDockingSystemDemo_v2/src/dialogs/SectionContentListWidget.h b/AdvancedDockingSystemDemo_v2/src/dialogs/SectionContentListWidget.h deleted file mode 100644 index 08653b8..0000000 --- a/AdvancedDockingSystemDemo_v2/src/dialogs/SectionContentListWidget.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef SECTIONCONTENTLISTWIDGET -#define SECTIONCONTENTLISTWIDGET - -#include -#include "../../../AdvancedDockingSystem/src/SectionContent.h" -#include "MainContainerWidget.h" -#include "ui_SectionContentListWidget.h" - -#include "API.h" - -class SectionContentListWidget : public QDialog -{ - Q_OBJECT - -public: - class Values - { - public: - ads::CMainContainerWidget* cw; - }; - - SectionContentListWidget(QWidget* parent); - void setValues(const Values& v); - -private slots: - void onDeleteButtonClicked(); - -private: - Ui::SectionContentListWidgetForm _ui; - Values _v; -}; - -#endif diff --git a/AdvancedDockingSystemDemo_v2/src/dialogs/SectionContentListWidget.ui b/AdvancedDockingSystemDemo_v2/src/dialogs/SectionContentListWidget.ui deleted file mode 100644 index e14ed87..0000000 --- a/AdvancedDockingSystemDemo_v2/src/dialogs/SectionContentListWidget.ui +++ /dev/null @@ -1,61 +0,0 @@ - - - SectionContentListWidgetForm - - - - 0 - 0 - 522 - 258 - - - - Form - - - - - - QAbstractItemView::NoEditTriggers - - - true - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - - - - - - - Delete - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - diff --git a/AdvancedDockingSystemUnitTests/AdvancedDockingSystemUnitTests.pri b/AdvancedDockingSystemUnitTests/AdvancedDockingSystemUnitTests.pri deleted file mode 100644 index 028a5de..0000000 --- a/AdvancedDockingSystemUnitTests/AdvancedDockingSystemUnitTests.pri +++ /dev/null @@ -1,7 +0,0 @@ - -HEADERS += \ - $$PWD/src/TestCore.h - -SOURCES += \ - $$PWD/src/main.cpp \ - $$PWD/src/TestCore.cpp diff --git a/AdvancedDockingSystemUnitTests/AdvancedDockingSystemUnitTests.pro b/AdvancedDockingSystemUnitTests/AdvancedDockingSystemUnitTests.pro deleted file mode 100644 index 0b45c67..0000000 --- a/AdvancedDockingSystemUnitTests/AdvancedDockingSystemUnitTests.pro +++ /dev/null @@ -1,16 +0,0 @@ -include($$(cetoni_repository)/build/qt/qtprojectsettings/common.pri) - -TARGET = AdvancedDockingSystemUnitTests - -QT += core gui testlib -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -greaterThan(QT_MAJOR_VERSION, 4): DEFINES += ADS_NAMESPACE_ENABLED -DEFINES += ADS_IMPORT - -INCLUDEPATH += $$PWD/src - -INCLUDEPATH += $$PWD/../AdvancedDockingSystem/include -DEPENDPATH += $$PWD/../AdvancedDockingSystem/include - -include(AdvancedDockingSystemUnitTests.pri) -include(../AdvancedDockingSystem/AdvancedDockingSystem.pri) diff --git a/AdvancedDockingSystemUnitTests/src/TestCore.cpp b/AdvancedDockingSystemUnitTests/src/TestCore.cpp deleted file mode 100644 index 597615c..0000000 --- a/AdvancedDockingSystemUnitTests/src/TestCore.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "TestCore.h" - -#include "ads/API.h" -#include "ads/Serialization.h" - -void TestCore::serialization() -{ - QList datas; - datas.append(QByteArray("Custom Data Here!!!")); - datas.append(QByteArray("Even More...")); - datas.append(QByteArray("lalalaalalalalalalal").toBase64()); - - // WRITE some data. - ADS_NS_SER::InMemoryWriter writer; - for (int i = 0; i < datas.count(); ++i) - { - QVERIFY(writer.write(ADS_NS_SER::ET_Custom + i, datas.at(i))); - } - - // Type: SectionIndexData - ADS_NS_SER::SectionIndexData sid; - for (int i = 0; i < 1; ++i) - { - ADS_NS_SER::SectionEntity se; - se.x = i; - se.y = i; - se.width = 100 + i; - se.height = 100 + i; - se.currentIndex = i; - - for (int j = 0; j < 1; ++j) - { - ADS_NS_SER::SectionContentEntity sce; - sce.uniqueName = QString("uname-%1-%2").arg(i).arg(j); - sce.preferredIndex = 8; - sce.visible = true; - se.sectionContents.append(sce); - se.sectionContentsCount += 1; - } - - sid.sections.append(se); - sid.sectionsCount += 1; - } - QVERIFY(writer.write(sid)); - - QVERIFY(writer.offsetsCount() == datas.count() + 1); - const QByteArray writtenData = writer.toByteArray(); - QVERIFY(writtenData.size() > 0); - - // READ and validate written data. - ADS_NS_SER::InMemoryReader reader(writtenData); - QVERIFY(reader.initReadHeader()); - QVERIFY(reader.offsetsCount() == datas.count() + 1); - for (int i = 0; i < datas.count(); ++i) - { - QByteArray readData; - QVERIFY(reader.read(ADS_NS_SER::ET_Custom + i, readData)); - QVERIFY(readData == datas.at(i)); - } - - // Type: SectionIndexData - ADS_NS_SER::SectionIndexData sidRead; - QVERIFY(reader.read(sidRead)); - - // TODO compare sidRead with sid -} - -QTEST_MAIN(TestCore) \ No newline at end of file diff --git a/AdvancedDockingSystemUnitTests/src/TestCore.h b/AdvancedDockingSystemUnitTests/src/TestCore.h deleted file mode 100644 index fbe11d1..0000000 --- a/AdvancedDockingSystemUnitTests/src/TestCore.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef TEST_CORE_H -#define TEST_CORE_H - -#include - -class TestCore : public QObject -{ - Q_OBJECT - -private slots: - void serialization(); -}; - -#endif \ No newline at end of file diff --git a/AdvancedDockingSystemUnitTests/src/main.cpp b/AdvancedDockingSystemUnitTests/src/main.cpp deleted file mode 100644 index 815c5e8..0000000 --- a/AdvancedDockingSystemUnitTests/src/main.cpp +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/ads.pro b/ads.pro new file mode 100644 index 0000000..1ddf582 --- /dev/null +++ b/ads.pro @@ -0,0 +1,5 @@ +TEMPLATE = subdirs + +SUBDIRS = \ + src \ + demo diff --git a/build.pro b/build.pro deleted file mode 100644 index c58974c..0000000 --- a/build.pro +++ /dev/null @@ -1,7 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS = \ - AdvancedDockingSystem \ - AdvancedDockingSystemDemo \ - AdvancedDockingSystemDemo_v2 \ - AdvancedDockingSystemUnitTests diff --git a/AdvancedDockingSystemDemo_v2/AdvancedDockingSystemDemo_v2.pro b/demo/demo.pro similarity index 54% rename from AdvancedDockingSystemDemo_v2/AdvancedDockingSystemDemo_v2.pro rename to demo/demo.pro index abcf835..bee1e47 100644 --- a/AdvancedDockingSystemDemo_v2/AdvancedDockingSystemDemo_v2.pro +++ b/demo/demo.pro @@ -1,10 +1,9 @@ include($$(cetoni_repository)/build/qt/qtprojectsettings/common.pri) -TARGET = AdvancedDockingSystemDemo_v2 +TARGET = AdvancedDockingSystemDemo -QT += core gui -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -greaterThan(QT_MAJOR_VERSION, 4): DEFINES += ADS_NAMESPACE_ENABLED +QT += core gui widgets +DEFINES += ADS_NAMESPACE_ENABLED windows { # MinGW @@ -17,15 +16,15 @@ windows { } SOURCES += \ - src/main.cpp \ - src/mainwindow.cpp + main.cpp \ + mainwindow.cpp HEADERS += \ - src/mainwindow.h + mainwindow.h FORMS += \ - src/mainwindow.ui + mainwindow.ui # Dependency: AdvancedDockingSystem (shared) @@ -33,8 +32,6 @@ win32:CONFIG(release, debug|release): LIBS += -l$$qtLinkLibrary(AdvancedDockingS else:win32:CONFIG(debug, debug|release): LIBS += -l$$qtLinkLibrary(AdvancedDockingSystem) else:unix: LIBS += -L$$OUT_PWD/../AdvancedDockingSystem/ -lAdvancedDockingSystem -INCLUDEPATH += $$PWD/../AdvancedDockingSystem/src \ - $$PWD/../AdvancedDockingSystem/src/v2 +INCLUDEPATH += ../src -DEPENDPATH += $$PWD/../AdvancedDockingSystem/src \ - $$PWD/../AdvancedDockingSystem/src/v2 +DEPENDPATH += ../src diff --git a/AdvancedDockingSystemDemo_v2/src/main.cpp b/demo/main.cpp similarity index 91% rename from AdvancedDockingSystemDemo_v2/src/main.cpp rename to demo/main.cpp index 488b2e0..82a073c 100644 --- a/AdvancedDockingSystemDemo_v2/src/main.cpp +++ b/demo/main.cpp @@ -6,7 +6,6 @@ static void initStyleSheet(QApplication& a) { - //Q_INIT_RESOURCE(ads); // If static linked. QFile f(":ads/stylesheets/default-windows2.css"); if (f.open(QFile::ReadOnly)) { diff --git a/AdvancedDockingSystemDemo_v2/src/mainwindow.cpp b/demo/mainwindow.cpp similarity index 99% rename from AdvancedDockingSystemDemo_v2/src/mainwindow.cpp rename to demo/mainwindow.cpp index bc5d670..71171e2 100644 --- a/AdvancedDockingSystemDemo_v2/src/mainwindow.cpp +++ b/demo/mainwindow.cpp @@ -1,4 +1,5 @@ #include "mainwindow.h" + #include "ui_mainwindow.h" #include diff --git a/AdvancedDockingSystemDemo_v2/src/mainwindow.h b/demo/mainwindow.h similarity index 100% rename from AdvancedDockingSystemDemo_v2/src/mainwindow.h rename to demo/mainwindow.h diff --git a/AdvancedDockingSystemDemo_v2/src/mainwindow.ui b/demo/mainwindow.ui similarity index 100% rename from AdvancedDockingSystemDemo_v2/src/mainwindow.ui rename to demo/mainwindow.ui diff --git a/AdvancedDockingSystem/src/v2/DockAreaWidget.cpp b/src/DockAreaWidget.cpp similarity index 99% rename from AdvancedDockingSystem/src/v2/DockAreaWidget.cpp rename to src/DockAreaWidget.cpp index e588efe..6eb6a96 100644 --- a/AdvancedDockingSystem/src/v2/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -542,6 +542,7 @@ void CDockAreaWidget::setCurrentIndex(int index) } d->ContentsLayout->setCurrentIndex(index); + emit currentChanged(index); } diff --git a/AdvancedDockingSystem/src/v2/DockAreaWidget.h b/src/DockAreaWidget.h similarity index 93% rename from AdvancedDockingSystem/src/v2/DockAreaWidget.h rename to src/DockAreaWidget.h index e1212bc..a458ef8 100644 --- a/AdvancedDockingSystem/src/v2/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -159,6 +159,19 @@ public slots: * Updates the dock area layout and components visibility */ void updateDockArea(); + +signals: + /** + * This signal is emitted when user clicks on a tab at an index. + */ + void tabBarClicked(int index); + + /** + * This signal is emitted when the tab bar's current tab changes. The new + * current has the given index, or -1 if there isn't a new one + * @param index + */ + void currentChanged(int index); }; // class DockAreaWidget } // namespace ads diff --git a/AdvancedDockingSystem/src/v2/DockContainerWidget.cpp b/src/DockContainerWidget.cpp similarity index 100% rename from AdvancedDockingSystem/src/v2/DockContainerWidget.cpp rename to src/DockContainerWidget.cpp diff --git a/AdvancedDockingSystem/src/v2/DockContainerWidget.h b/src/DockContainerWidget.h similarity index 100% rename from AdvancedDockingSystem/src/v2/DockContainerWidget.h rename to src/DockContainerWidget.h diff --git a/AdvancedDockingSystem/src/v2/DockManager.cpp b/src/DockManager.cpp similarity index 100% rename from AdvancedDockingSystem/src/v2/DockManager.cpp rename to src/DockManager.cpp diff --git a/AdvancedDockingSystem/src/v2/DockManager.h b/src/DockManager.h similarity index 100% rename from AdvancedDockingSystem/src/v2/DockManager.h rename to src/DockManager.h diff --git a/AdvancedDockingSystem/src/v2/DockOverlay.cpp b/src/DockOverlay.cpp similarity index 100% rename from AdvancedDockingSystem/src/v2/DockOverlay.cpp rename to src/DockOverlay.cpp diff --git a/AdvancedDockingSystem/src/v2/DockOverlay.h b/src/DockOverlay.h similarity index 100% rename from AdvancedDockingSystem/src/v2/DockOverlay.h rename to src/DockOverlay.h diff --git a/AdvancedDockingSystem/src/v2/DockWidget.cpp b/src/DockWidget.cpp similarity index 100% rename from AdvancedDockingSystem/src/v2/DockWidget.cpp rename to src/DockWidget.cpp diff --git a/AdvancedDockingSystem/src/v2/DockWidget.h b/src/DockWidget.h similarity index 100% rename from AdvancedDockingSystem/src/v2/DockWidget.h rename to src/DockWidget.h diff --git a/AdvancedDockingSystem/src/v2/DockWidgetTitleBar.cpp b/src/DockWidgetTitleBar.cpp similarity index 99% rename from AdvancedDockingSystem/src/v2/DockWidgetTitleBar.cpp rename to src/DockWidgetTitleBar.cpp index e4559a6..f4a773a 100644 --- a/AdvancedDockingSystem/src/v2/DockWidgetTitleBar.cpp +++ b/src/DockWidgetTitleBar.cpp @@ -117,6 +117,7 @@ struct DockWidgetTitleBarPrivate }; // struct DockWidgetTitleBarPrivate + //============================================================================ DockWidgetTitleBarPrivate::DockWidgetTitleBarPrivate(CDockWidgetTitleBar* _public) : _this(_public) diff --git a/AdvancedDockingSystem/src/v2/DockWidgetTitleBar.h b/src/DockWidgetTitleBar.h similarity index 100% rename from AdvancedDockingSystem/src/v2/DockWidgetTitleBar.h rename to src/DockWidgetTitleBar.h diff --git a/AdvancedDockingSystem/src/v2/FloatingDockContainer.cpp b/src/FloatingDockContainer.cpp similarity index 100% rename from AdvancedDockingSystem/src/v2/FloatingDockContainer.cpp rename to src/FloatingDockContainer.cpp diff --git a/AdvancedDockingSystem/src/v2/FloatingDockContainer.h b/src/FloatingDockContainer.h similarity index 100% rename from AdvancedDockingSystem/src/v2/FloatingDockContainer.h rename to src/FloatingDockContainer.h diff --git a/AdvancedDockingSystem/res/ads.qrc b/src/ads.qrc similarity index 97% rename from AdvancedDockingSystem/res/ads.qrc rename to src/ads.qrc index 32ef0d3..dcf3ae7 100644 --- a/AdvancedDockingSystem/res/ads.qrc +++ b/src/ads.qrc @@ -1,8 +1,8 @@ - - - stylesheets/default-windows.css - stylesheets/vendor-partsolutions.css - stylesheets/modern-windows.css - stylesheets/default-windows2.css - - + + + stylesheets/default-windows.css + stylesheets/vendor-partsolutions.css + stylesheets/modern-windows.css + stylesheets/default-windows2.css + + diff --git a/AdvancedDockingSystem/src/v2/ads_globals.cpp b/src/ads_globals.cpp similarity index 100% rename from AdvancedDockingSystem/src/v2/ads_globals.cpp rename to src/ads_globals.cpp diff --git a/AdvancedDockingSystem/src/v2/ads_globals.h b/src/ads_globals.h similarity index 100% rename from AdvancedDockingSystem/src/v2/ads_globals.h rename to src/ads_globals.h diff --git a/src/src.pro b/src/src.pro new file mode 100644 index 0000000..bf98889 --- /dev/null +++ b/src/src.pro @@ -0,0 +1,54 @@ +include($$(cetoni_repository)/build/qt/qtprojectsettings/shared_library.pri) +include(src/v2/v2.pri) + +TARGET = $$qtLibraryTarget(AdvancedDockingSystem) +TEMPLATE = lib +#VERSION = 1.0.0 + +CONFIG += adsBuildShared + +QT += core gui widgets +DEFINES += ADS_NAMESPACE_ENABLED + +adsBuildShared { + CONFIG += shared + DEFINES += ADS_EXPORT +} +!adsBuildShared { + CONFIG += staticlib +} + +windows { + # MinGW + *-g++* { + QMAKE_CXXFLAGS += -std=c++11 + QMAKE_CXXFLAGS += -Wall -Wextra -pedantic + } + # MSVC + *-msvc* { + } +} + +RESOURCES += ads.qrc + +HEADERS += \ + ads_globals.h \ + DockAreaWidget.h \ + DockContainerWidget.h \ + DockManager.h \ + DockWidget.h \ + DockWidgetTitleBar.h \ + FloatingDockContainer.h \ + DockOverlay.h + + + +SOURCES += \ + ads_globals.cpp \ + DockAreaWidget.cpp \ + DockContainerWidget.cpp \ + DockManager.cpp \ + DockWidget.cpp \ + DockWidgetTitleBar.cpp \ + FloatingDockContainer.cpp \ + DockOverlay.cpp diff --git a/AdvancedDockingSystem/res/stylesheets/default-windows.css b/src/stylesheets/default-windows.css similarity index 95% rename from AdvancedDockingSystem/res/stylesheets/default-windows.css rename to src/stylesheets/default-windows.css index a0e00ba..6fb505b 100644 --- a/AdvancedDockingSystem/res/stylesheets/default-windows.css +++ b/src/stylesheets/default-windows.css @@ -1,77 +1,77 @@ -/* - * Default style sheet on Windows Platforms - * Note: Always use CSS-classes with and without "ads--" namespace to support Qt4 & Qt5 - */ - -ads--ContainerWidget, -ContainerWidget -{ - background: palette(dark); -} - -ads--ContainerWidget QSplitter::handle, -ContainerWidget QSplitter::handle -{ - background: palette(dark); -} - -ads--SectionWidget, -SectionWidget -{ - background: palette(window); - border: 1px solid palette(light); -} - -ads--SectionWidget #tabsMenuButton::menu-indicator, -SectionWidget #tabsMenuButton::menu-indicator -{ - image: none; -} - -ads--SectionTitleWidget, -SectionTitleWidget -{ - background: palette(window); - border-color: palette(light); - border-style: solid; - border-width: 0 1px 0 0; - padding: 0 9px; -} - -ads--SectionTitleWidget[activeTab="true"], -SectionTitleWidget[activeTab="true"] -{ -/* background: palette(light);*/ -/* background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(255, 255, 255, 255), stop:1 rgba(240, 240, 240, 255));*/ - background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:0.5, stop:0 palette(window), stop:1 palette(light)); -} - -ads--SectionContentWidget, -SectionContentWidget -{ - background: palette(light); - border-color: palette(light); - border-style: solid; - border-width: 1px 0 0 0; -} - -/* Special: QLabels inside SectionTitleWidget -*/ -ads--SectionTitleWidget QLabel, -SectionTitleWidget QLabel -{ - color: palette(dark); -} -ads--SectionTitleWidget[activeTab="true"] QLabel, -SectionTitleWidget[activeTab="true"] QLabel -{ - color: palette(foreground); -} - -/* Special: QLabels inside SectionTitleWidget, which is floating -*/ -ads--FloatingWidget ads--SectionTitleWidget QLabel, -FloatingWidget SectionTitleWidget QLabel -{ - color: palette(foreground); -} +/* + * Default style sheet on Windows Platforms + * Note: Always use CSS-classes with and without "ads--" namespace to support Qt4 & Qt5 + */ + +ads--ContainerWidget, +ContainerWidget +{ + background: palette(dark); +} + +ads--ContainerWidget QSplitter::handle, +ContainerWidget QSplitter::handle +{ + background: palette(dark); +} + +ads--SectionWidget, +SectionWidget +{ + background: palette(window); + border: 1px solid palette(light); +} + +ads--SectionWidget #tabsMenuButton::menu-indicator, +SectionWidget #tabsMenuButton::menu-indicator +{ + image: none; +} + +ads--SectionTitleWidget, +SectionTitleWidget +{ + background: palette(window); + border-color: palette(light); + border-style: solid; + border-width: 0 1px 0 0; + padding: 0 9px; +} + +ads--SectionTitleWidget[activeTab="true"], +SectionTitleWidget[activeTab="true"] +{ +/* background: palette(light);*/ +/* background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(255, 255, 255, 255), stop:1 rgba(240, 240, 240, 255));*/ + background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:0.5, stop:0 palette(window), stop:1 palette(light)); +} + +ads--SectionContentWidget, +SectionContentWidget +{ + background: palette(light); + border-color: palette(light); + border-style: solid; + border-width: 1px 0 0 0; +} + +/* Special: QLabels inside SectionTitleWidget +*/ +ads--SectionTitleWidget QLabel, +SectionTitleWidget QLabel +{ + color: palette(dark); +} +ads--SectionTitleWidget[activeTab="true"] QLabel, +SectionTitleWidget[activeTab="true"] QLabel +{ + color: palette(foreground); +} + +/* Special: QLabels inside SectionTitleWidget, which is floating +*/ +ads--FloatingWidget ads--SectionTitleWidget QLabel, +FloatingWidget SectionTitleWidget QLabel +{ + color: palette(foreground); +} diff --git a/AdvancedDockingSystem/res/stylesheets/default-windows2.css b/src/stylesheets/default-windows2.css similarity index 100% rename from AdvancedDockingSystem/res/stylesheets/default-windows2.css rename to src/stylesheets/default-windows2.css diff --git a/AdvancedDockingSystem/res/stylesheets/modern-windows.css b/src/stylesheets/modern-windows.css similarity index 95% rename from AdvancedDockingSystem/res/stylesheets/modern-windows.css rename to src/stylesheets/modern-windows.css index 7bb5773..64d683c 100644 --- a/AdvancedDockingSystem/res/stylesheets/modern-windows.css +++ b/src/stylesheets/modern-windows.css @@ -1,35 +1,35 @@ -QSplitter::handle { - background: palette(light); -} - -ads--ContainerWidget, ContainerWidget { - background: palette(light); -} - -ads--SectionWidget, SectionWidget { - background: palette(light); -} - -ads--SectionTitleWidget, SectionTitleWidget { - background: #ffffff; -} -ads--SectionTitleWidget QLabel, SectionTitleWidget QLabel { - color: #000000; -} - -ads--SectionTitleWidget[activeTab="true"], SectionTitleWidget[activeTab="true"] { - background: #000000; - border-right: 1px solid #000000; - padding: 9px; -} -ads--SectionTitleWidget[activeTab="true"] QLabel, SectionTitleWidget[activeTab="true"] QLabel { - color: #ffffff; -} - -ads--SectionContentWidget, SectionContentWidget { - border: 1px solid #000000; -} - -QAbstractItemView { - border: 0; +QSplitter::handle { + background: palette(light); +} + +ads--ContainerWidget, ContainerWidget { + background: palette(light); +} + +ads--SectionWidget, SectionWidget { + background: palette(light); +} + +ads--SectionTitleWidget, SectionTitleWidget { + background: #ffffff; +} +ads--SectionTitleWidget QLabel, SectionTitleWidget QLabel { + color: #000000; +} + +ads--SectionTitleWidget[activeTab="true"], SectionTitleWidget[activeTab="true"] { + background: #000000; + border-right: 1px solid #000000; + padding: 9px; +} +ads--SectionTitleWidget[activeTab="true"] QLabel, SectionTitleWidget[activeTab="true"] QLabel { + color: #ffffff; +} + +ads--SectionContentWidget, SectionContentWidget { + border: 1px solid #000000; +} + +QAbstractItemView { + border: 0; } \ No newline at end of file diff --git a/AdvancedDockingSystem/res/stylesheets/vendor-partsolutions.css b/src/stylesheets/vendor-partsolutions.css similarity index 95% rename from AdvancedDockingSystem/res/stylesheets/vendor-partsolutions.css rename to src/stylesheets/vendor-partsolutions.css index ee7ed2a..d73bbae 100644 --- a/AdvancedDockingSystem/res/stylesheets/vendor-partsolutions.css +++ b/src/stylesheets/vendor-partsolutions.css @@ -1,63 +1,63 @@ -/* - * Style sheet used by CADENAS PARTsolutions product line - * Requires Qt4 compatibility - */ - -QSplitter::handle:vertical { - image: url(:/img/splitter-horizontal.png); -} - -QSplitter::handle:horizontal { - image: url(:/img/splitter-vertical.png); -} - -ads--ContainerWidget, ContainerWidget { - background: #9ab6ca; - border: 0; -} - -ads--SectionWidget, SectionWidget { - background: #7c9eb3; - border-color: #ffffff; - border-style: solid; - border-width: 1px; -} - -ads--SectionTitleWidget, SectionTitleWidget { - background: #7c9eb3; - border-right: 1px solid #E7F3F8; - padding: 6px 6px; -} - -ads--SectionTitleWidget[activeTab="true"], SectionTitleWidget[activeTab="true"] { - background: #E7F3F8; - border: 1px solid #E7F3F8; -} - -ads--SectionWidget QPushButton#closeButton, SectionWidget QPushButton#closeButton, -ads--FloatingWidget QPushButton#closeButton, FloatingWidget QPushButton#closeButton { - background: #ff0000; - border: 1px solid red; -} - -ads--SectionContentWidget, SectionContentWidget { - background: #ffffff; - border: 0px solid #E7F3F8; -} - -/* Special */ - -IconTitleWidget { - padding: 0; - margin: 0; -} - -ads--SectionTitleWidget QLabel, SectionTitleWidget QLabel { - color: #ffffff; - background: #7c9eb3; -} - -ads--SectionTitleWidget[activeTab="true"] QLabel, SectionTitleWidget[activeTab="true"] QLabel { - color: #000000; - background: #E7F3F8; +/* + * Style sheet used by CADENAS PARTsolutions product line + * Requires Qt4 compatibility + */ + +QSplitter::handle:vertical { + image: url(:/img/splitter-horizontal.png); +} + +QSplitter::handle:horizontal { + image: url(:/img/splitter-vertical.png); +} + +ads--ContainerWidget, ContainerWidget { + background: #9ab6ca; + border: 0; +} + +ads--SectionWidget, SectionWidget { + background: #7c9eb3; + border-color: #ffffff; + border-style: solid; + border-width: 1px; +} + +ads--SectionTitleWidget, SectionTitleWidget { + background: #7c9eb3; + border-right: 1px solid #E7F3F8; + padding: 6px 6px; +} + +ads--SectionTitleWidget[activeTab="true"], SectionTitleWidget[activeTab="true"] { + background: #E7F3F8; + border: 1px solid #E7F3F8; +} + +ads--SectionWidget QPushButton#closeButton, SectionWidget QPushButton#closeButton, +ads--FloatingWidget QPushButton#closeButton, FloatingWidget QPushButton#closeButton { + background: #ff0000; + border: 1px solid red; +} + +ads--SectionContentWidget, SectionContentWidget { + background: #ffffff; + border: 0px solid #E7F3F8; +} + +/* Special */ + +IconTitleWidget { + padding: 0; + margin: 0; +} + +ads--SectionTitleWidget QLabel, SectionTitleWidget QLabel { + color: #ffffff; + background: #7c9eb3; +} + +ads--SectionTitleWidget[activeTab="true"] QLabel, SectionTitleWidget[activeTab="true"] QLabel { + color: #000000; + background: #E7F3F8; } \ No newline at end of file