mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 07:21:32 +08:00
Implemented support for adding dock widgets to DockContainerWidget
This commit is contained in:
parent
94a6f5e2f1
commit
4a0c176327
@ -124,31 +124,9 @@ void CContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget,
|
||||
}
|
||||
|
||||
|
||||
void CContainerWidget::dropChildSections(QWidget* Parent)
|
||||
{
|
||||
auto Sections = Parent->findChildren<SectionWidget*>(QString(), Qt::FindDirectChildrenOnly);
|
||||
auto Splitters = Parent->findChildren<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
|
||||
|
||||
std::cout << "-----------------------" << std::endl;
|
||||
std::cout << "Sections " << Sections.size() << std::endl;
|
||||
std::cout << "Splitters " << Splitters.size() << std::endl;
|
||||
|
||||
for (auto Section : Sections)
|
||||
{
|
||||
// drop section
|
||||
}
|
||||
|
||||
for (auto Splitter : Splitters)
|
||||
{
|
||||
dropChildSections(Splitter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CContainerWidget::dropIntoContainer(FloatingWidget* FloatingWidget, DropArea area)
|
||||
{
|
||||
dropChildSections(FloatingWidget->containerWidget());
|
||||
|
||||
CContainerWidget* FloatingContainer = FloatingWidget->containerWidget();
|
||||
QSplitter* FloatingMainSplitter = FloatingContainer->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
|
||||
|
||||
|
@ -116,9 +116,6 @@ protected:
|
||||
unsigned int m_zOrderIndex = 0;
|
||||
static unsigned int zOrderCounter;
|
||||
|
||||
private:
|
||||
void dropChildSections(QWidget* Parent);
|
||||
|
||||
private slots:
|
||||
void onActiveTabChanged();
|
||||
};
|
||||
|
@ -10,7 +10,10 @@
|
||||
//============================================================================
|
||||
#include "DockAreaWidget.h"
|
||||
|
||||
#include <QStackedLayout>
|
||||
|
||||
#include "DockContainerWidget.h"
|
||||
#include "DockWidget.h"
|
||||
|
||||
namespace ads
|
||||
{
|
||||
@ -20,6 +23,7 @@ namespace ads
|
||||
struct DockAreaWidgetPrivate
|
||||
{
|
||||
CDockAreaWidget* _this;
|
||||
QStackedLayout* StackedLayout;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@ -40,7 +44,11 @@ CDockAreaWidget::CDockAreaWidget(CDockManager* DockManager, CDockContainerWidget
|
||||
QFrame(parent),
|
||||
d(new DockAreaWidgetPrivate(this))
|
||||
{
|
||||
|
||||
setStyleSheet("background: yellow;");
|
||||
d->StackedLayout = new QStackedLayout();
|
||||
d->StackedLayout->setContentsMargins(0, 0, 0, 0);
|
||||
d->StackedLayout->setSpacing(0);
|
||||
setLayout(d->StackedLayout);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
@ -66,6 +74,13 @@ CDockContainerWidget* CDockAreaWidget::dockContainerWidget() const
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaWidget::addDockWidget(CDockWidget* DockWidget)
|
||||
{
|
||||
d->StackedLayout->addWidget(DockWidget);
|
||||
}
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -17,6 +17,7 @@ namespace ads
|
||||
struct DockAreaWidgetPrivate;
|
||||
class CDockManager;
|
||||
class CDockContainerWidget;
|
||||
class CDockWidget;
|
||||
|
||||
/**
|
||||
* DockAreaWidget manages multiple instances of DckWidgets.
|
||||
@ -46,6 +47,12 @@ public:
|
||||
* if there is no
|
||||
*/
|
||||
CDockContainerWidget* dockContainerWidget() const;
|
||||
|
||||
/**
|
||||
* Add a new dock widget to dock area.
|
||||
* All dockwidgets in the dock area tabified in a stacked layout with tabs
|
||||
*/
|
||||
void addDockWidget(CDockWidget* DockWidget);
|
||||
}; // class DockAreaWidget
|
||||
}
|
||||
// namespace ads
|
||||
|
@ -13,14 +13,31 @@
|
||||
#include <QEvent>
|
||||
#include <QList>
|
||||
#include <QGridLayout>
|
||||
#include <QSplitter>
|
||||
|
||||
#include "DockManager.h"
|
||||
#include "DockAreaWidget.h"
|
||||
#include "ads_globals.h"
|
||||
|
||||
namespace ads
|
||||
{
|
||||
static unsigned int zOrderCounter = 0;
|
||||
|
||||
/**
|
||||
* Helper function to ease insertion of dock area into splitter
|
||||
*/
|
||||
static void inserDockAreaIntoSplitter(QSplitter* Splitter, QWidget* widget, bool Append)
|
||||
{
|
||||
if (Append)
|
||||
{
|
||||
Splitter->addWidget(widget);
|
||||
}
|
||||
else
|
||||
{
|
||||
Splitter->insertWidget(0, widget);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Private data class of CDockContainerWidget class (pimpl)
|
||||
*/
|
||||
@ -40,12 +57,23 @@ struct DockContainerWidgetPrivate
|
||||
/**
|
||||
* Create a new dock area widget and adds it to the list of doc areas
|
||||
*/
|
||||
CDockAreaWidget* newDockAreaWidget()
|
||||
CDockAreaWidget* newDockArea()
|
||||
{
|
||||
auto DockAreaWidget = new CDockAreaWidget(DockManager, _this);
|
||||
DockAreas.append(DockAreaWidget);
|
||||
return DockAreaWidget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds dock widget to container
|
||||
*/
|
||||
void dockWidgetIntoContainer(DockWidgetArea area, CDockWidget* Dockwidget);
|
||||
|
||||
/**
|
||||
* Adds dock widget to a existing DockWidgetArea
|
||||
*/
|
||||
void dockWidgetIntoDockArea(DockWidgetArea area, CDockWidget* Dockwidget,
|
||||
CDockAreaWidget* DockAreaWidget);
|
||||
}; // struct DockContainerWidgetPrivate
|
||||
|
||||
|
||||
@ -56,11 +84,72 @@ DockContainerWidgetPrivate::DockContainerWidgetPrivate(CDockContainerWidget* _pu
|
||||
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetArea area,
|
||||
CDockWidget* Dockwidget)
|
||||
{
|
||||
CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this);
|
||||
NewDockArea->addDockWidget(Dockwidget);
|
||||
auto InsertParam = internal::dockAreaInsertParameters(area);
|
||||
|
||||
if (DockAreas.isEmpty())
|
||||
{
|
||||
Layout->addWidget(NewDockArea, 0, 0);
|
||||
}
|
||||
else if (DockAreas.count() == 1)
|
||||
{
|
||||
QSplitter* Splitter = internal::newSplitter(InsertParam.first);
|
||||
auto DockArea = dynamic_cast<CDockAreaWidget*>(Layout->itemAtPosition(0, 0)->widget());
|
||||
Layout->replaceWidget(DockArea, Splitter);
|
||||
Splitter->addWidget(DockArea);
|
||||
inserDockAreaIntoSplitter(Splitter, NewDockArea, InsertParam.second);
|
||||
}
|
||||
else
|
||||
{
|
||||
QSplitter* Splitter = _this->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
|
||||
if (Splitter->orientation() == InsertParam.first)
|
||||
{
|
||||
inserDockAreaIntoSplitter(Splitter, NewDockArea, InsertParam.second);
|
||||
}
|
||||
else
|
||||
{
|
||||
QSplitter* NewSplitter = internal::newSplitter(InsertParam.first);
|
||||
if (InsertParam.second)
|
||||
{
|
||||
QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter);
|
||||
NewSplitter->addWidget(Splitter);
|
||||
NewSplitter->addWidget(NewDockArea);
|
||||
delete li;
|
||||
}
|
||||
else
|
||||
{
|
||||
NewSplitter->addWidget(NewDockArea);
|
||||
QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter);
|
||||
NewSplitter->addWidget(Splitter);
|
||||
delete li;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DockAreas.append(NewDockArea);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetArea area,
|
||||
CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockContainerWidget::CDockContainerWidget(CDockManager* DockManager, QWidget *parent) :
|
||||
QFrame(parent),
|
||||
d(new DockContainerWidgetPrivate(this))
|
||||
{
|
||||
setStyleSheet("background: green;");
|
||||
d->DockManager = DockManager;
|
||||
|
||||
d->Layout = new QGridLayout();
|
||||
@ -80,9 +169,13 @@ CDockContainerWidget::~CDockContainerWidget()
|
||||
void CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget,
|
||||
CDockAreaWidget* DockAreaWidget)
|
||||
{
|
||||
if (d->DockAreas.isEmpty())
|
||||
if (DockAreaWidget)
|
||||
{
|
||||
|
||||
d->dockWidgetIntoDockArea(area, Dockwidget, DockAreaWidget);
|
||||
}
|
||||
else
|
||||
{
|
||||
d->dockWidgetIntoContainer(area, Dockwidget);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
|
||||
//============================================================================
|
||||
/// \file DockManager.cpp
|
||||
/// \author Uwe Kindler
|
||||
/// \date 23.02.2017
|
||||
/// \brief Implementation of CDockManager
|
||||
/// \date 26.02.2017
|
||||
/// \brief Implementation of CDockManager class
|
||||
//============================================================================
|
||||
|
||||
//============================================================================
|
||||
@ -10,9 +11,49 @@
|
||||
//============================================================================
|
||||
#include "DockManager.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
namespace ads
|
||||
{
|
||||
/**
|
||||
* Private data class of CDockManager class (pimpl)
|
||||
*/
|
||||
struct DockManagerPrivate
|
||||
{
|
||||
CDockManager* _this;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
*/
|
||||
DockManagerPrivate(CDockManager* _public);
|
||||
};
|
||||
// struct DockManagerPrivate
|
||||
|
||||
//============================================================================
|
||||
DockManagerPrivate::DockManagerPrivate(CDockManager* _public) :
|
||||
_this(_public)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockManager::CDockManager(QWidget *parent) :
|
||||
CDockContainerWidget(this, parent),
|
||||
d(new DockManagerPrivate(this))
|
||||
{
|
||||
QMainWindow* MainWindow = dynamic_cast<QMainWindow*>(parent);
|
||||
if (MainWindow)
|
||||
{
|
||||
MainWindow->setCentralWidget(this);
|
||||
}
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
CDockManager::~CDockManager()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -3,8 +3,8 @@
|
||||
//============================================================================
|
||||
/// \file DockManager.h
|
||||
/// \author Uwe Kindler
|
||||
/// \date 23.02.2017
|
||||
/// \brief Declaration of CDockManager
|
||||
/// \date 26.02.2017
|
||||
/// \brief Declaration of CDockManager class
|
||||
//============================================================================
|
||||
|
||||
//============================================================================
|
||||
@ -14,15 +14,31 @@
|
||||
|
||||
namespace ads
|
||||
{
|
||||
struct DockManagerPrivate;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
* The central dock manager that maintains the complete docking system
|
||||
**/
|
||||
class CDockManager : public CDockContainerWidget
|
||||
{
|
||||
};
|
||||
Q_OBJECT
|
||||
private:
|
||||
DockManagerPrivate* d; ///< private data (pimpl)
|
||||
friend class DockManagerPrivate;
|
||||
protected:
|
||||
public:
|
||||
/**
|
||||
* Default Constructor.
|
||||
* If the given parent is a QMainWindow, the dck manager sets itself as the
|
||||
* central widget
|
||||
*/
|
||||
CDockManager(QWidget* parent = 0);
|
||||
|
||||
/**
|
||||
* Virtual Destructor
|
||||
*/
|
||||
virtual ~CDockManager();
|
||||
}; // class DockManager
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
#endif // DockManagerH
|
||||
|
@ -1,8 +1,9 @@
|
||||
|
||||
//============================================================================
|
||||
/// \file DockWidget.cpp
|
||||
/// \author Uwe Kindler
|
||||
/// \date 23.02.2017
|
||||
/// \brief Implementation of CDockWidget
|
||||
/// \date 26.02.2017
|
||||
/// \brief Implementation of CDockWidget class
|
||||
//============================================================================
|
||||
|
||||
//============================================================================
|
||||
@ -10,9 +11,72 @@
|
||||
//============================================================================
|
||||
#include "DockWidget.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
|
||||
namespace ads
|
||||
{
|
||||
/**
|
||||
* Private data class of CDockWidget class (pimpl)
|
||||
*/
|
||||
struct DockWidgetPrivate
|
||||
{
|
||||
CDockWidget* _this;
|
||||
QBoxLayout* Layout;
|
||||
QWidget* Widget = nullptr;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
*/
|
||||
DockWidgetPrivate(CDockWidget* _public);
|
||||
};
|
||||
// struct DockWidgetPrivate
|
||||
|
||||
//============================================================================
|
||||
DockWidgetPrivate::DockWidgetPrivate(CDockWidget* _public) :
|
||||
_this(_public)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
|
||||
QFrame(parent),
|
||||
d(new DockWidgetPrivate(this))
|
||||
{
|
||||
d->Layout = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
d->Layout->setContentsMargins(0, 0, 0, 0);
|
||||
d->Layout->setSpacing(0);
|
||||
setLayout(d->Layout);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
CDockWidget::~CDockWidget()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidget::setWidget(QWidget* widget)
|
||||
{
|
||||
if (d->Widget)
|
||||
{
|
||||
d->Layout->replaceWidget(d->Widget, widget);
|
||||
}
|
||||
else
|
||||
{
|
||||
d->Layout->addWidget(widget);
|
||||
}
|
||||
|
||||
d->Widget = widget;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QWidget* CDockWidget::widget() const
|
||||
{
|
||||
return d->Widget;
|
||||
}
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -3,8 +3,8 @@
|
||||
//============================================================================
|
||||
/// \file DockWidget.h
|
||||
/// \author Uwe Kindler
|
||||
/// \date 23.02.2017
|
||||
/// \brief Declaration of CDockWidget
|
||||
/// \date 26.02.2017
|
||||
/// \brief Declaration of CDockWidget class
|
||||
//============================================================================
|
||||
|
||||
//============================================================================
|
||||
@ -14,16 +14,42 @@
|
||||
|
||||
namespace ads
|
||||
{
|
||||
struct DockWidgetPrivate;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* The QDockWidget class provides a widget that can be docked inside a
|
||||
* CDockManager or floated as a top-level window on the desktop.
|
||||
*/
|
||||
class CDockWidget : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
};
|
||||
private:
|
||||
DockWidgetPrivate* d; ///< private data (pimpl)
|
||||
friend class DockWidgetPrivate;
|
||||
protected:
|
||||
public:
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
CDockWidget(const QString &title, QWidget* parent = 0);
|
||||
|
||||
} // namespace ads
|
||||
/**
|
||||
* Virtual Destructor
|
||||
*/
|
||||
virtual ~CDockWidget();
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
/**
|
||||
* Sets the widget for the dock widget to widget.
|
||||
*/
|
||||
void setWidget(QWidget* widget);
|
||||
|
||||
/**
|
||||
* Returns the widget for the dock widget. This function returns zero if
|
||||
* the widget has not been set.
|
||||
*/
|
||||
QWidget* widget() const;
|
||||
}; // class DockWidget
|
||||
}
|
||||
// namespace ads
|
||||
//-----------------------------------------------------------------------------
|
||||
#endif // DockWidgetH
|
||||
|
@ -12,11 +12,14 @@
|
||||
#include <QSplitter>
|
||||
#include <QVariant>
|
||||
|
||||
#include "ads_globals.h"
|
||||
|
||||
namespace ads
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
//============================================================================
|
||||
QSplitter* newSplitter(Qt::Orientation orientation, QWidget* parent)
|
||||
{
|
||||
QSplitter* s = new QSplitter(orientation, parent);
|
||||
@ -26,6 +29,22 @@ QSplitter* newSplitter(Qt::Orientation orientation, QWidget* parent)
|
||||
return s;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
QPair<Qt::Orientation, bool> dockAreaInsertParameters(DockWidgetArea Area)
|
||||
{
|
||||
switch (Area)
|
||||
{
|
||||
case TopDockWidgetArea: return QPair<Qt::Orientation, bool>(Qt::Vertical, false);
|
||||
case RightDockWidgetArea: return QPair<Qt::Orientation, bool>(Qt::Horizontal, true);
|
||||
case CenterDockWidgetArea:
|
||||
case BottomDockWidgetArea: return QPair<Qt::Orientation, bool>(Qt::Vertical, true);
|
||||
case LeftDockWidgetArea: return QPair<Qt::Orientation, bool>(Qt::Horizontal, false);
|
||||
default: QPair<Qt::Orientation, bool>(Qt::Vertical, false);
|
||||
} // switch (Area)
|
||||
|
||||
return QPair<Qt::Orientation, bool>(Qt::Vertical, false);
|
||||
}
|
||||
|
||||
|
||||
} // namespace internal
|
||||
} // namespace ads
|
||||
|
@ -11,6 +11,8 @@
|
||||
//============================================================================
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include <QPair>
|
||||
|
||||
class QSplitter;
|
||||
|
||||
namespace ads
|
||||
@ -24,8 +26,8 @@ enum DockWidgetArea
|
||||
BottomDockWidgetArea = 0x08,
|
||||
CenterDockWidgetArea = 0x10,
|
||||
|
||||
OuterAreas = TopDockWidgetArea | LeftDockWidgetArea | RightDockWidgetArea | BottomDockWidgetArea,
|
||||
AllAreas = OuterAreas | CenterDockWidgetArea
|
||||
OuterDockAreas = TopDockWidgetArea | LeftDockWidgetArea | RightDockWidgetArea | BottomDockWidgetArea,
|
||||
AllDockAreas = OuterDockAreas | CenterDockWidgetArea
|
||||
};
|
||||
Q_DECLARE_FLAGS(DockWidgetAreas, DockWidgetArea)
|
||||
|
||||
@ -34,7 +36,12 @@ namespace internal
|
||||
/**
|
||||
* Helper function to create new splitter widgets
|
||||
*/
|
||||
QSplitter* newSplitter(Qt::Orientation orientation, QWidget* parent);
|
||||
QSplitter* newSplitter(Qt::Orientation orientation, QWidget* parent = 0);
|
||||
|
||||
/**
|
||||
* Returns the insertion parameters for the given dock area
|
||||
*/
|
||||
QPair<Qt::Orientation, bool> dockAreaInsertParameters(DockWidgetArea Area);
|
||||
} // namespace internal
|
||||
} // namespace ads
|
||||
|
||||
|
20
AdvancedDockingSystem/src/v2/v2.pri
Normal file
20
AdvancedDockingSystem/src/v2/v2.pri
Normal file
@ -0,0 +1,20 @@
|
||||
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
|
||||
|
||||
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/ads_globals.cpp \
|
||||
$$PWD/DockAreaWidget.cpp \
|
||||
$$PWD/DockContainerWidget.cpp \
|
||||
$$PWD/DockManager.cpp \
|
||||
$$PWD/DockWidget.cpp \
|
||||
$$PWD/DockWidgetTitleBar.cpp \
|
||||
$$PWD/FloatingDockContainer.cpp
|
@ -19,7 +19,6 @@ public:
|
||||
virtual ~MainWindow();
|
||||
|
||||
public slots:
|
||||
void showSectionContentListDialog();
|
||||
|
||||
private slots:
|
||||
void onActiveTabChanged(const ads::SectionContent::RefPtr& sc, bool active);
|
||||
|
@ -0,0 +1,40 @@
|
||||
include($$(cetoni_repository)/build/qt/qtprojectsettings/common.pri)
|
||||
|
||||
TARGET = AdvancedDockingSystemDemo_v2
|
||||
|
||||
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
|
||||
|
||||
|
||||
HEADERS += \
|
||||
src/mainwindow.h
|
||||
|
||||
FORMS += \
|
||||
src/mainwindow.ui
|
||||
|
||||
|
||||
# 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 \
|
||||
$$PWD/../AdvancedDockingSystem/src/v2
|
||||
|
||||
DEPENDPATH += $$PWD/../AdvancedDockingSystem/src \
|
||||
$$PWD/../AdvancedDockingSystem/src/v2
|
@ -0,0 +1,90 @@
|
||||
#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;
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
#ifndef ADS_SECTIONCONTENTMODEL_H
|
||||
#define ADS_SECTIONCONTENTMODEL_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QAbstractTableModel>
|
||||
#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<int, QString> _headers;
|
||||
|
||||
ads::CMainContainerWidget* _cw;
|
||||
QList<ads::SectionContent::RefPtr> _contents;
|
||||
};
|
||||
|
||||
#endif
|
@ -0,0 +1,38 @@
|
||||
#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());
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
#ifndef SECTIONCONTENTLISTWIDGET
|
||||
#define SECTIONCONTENTLISTWIDGET
|
||||
|
||||
#include <QDialog>
|
||||
#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
|
@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SectionContentListWidgetForm</class>
|
||||
<widget class="QWidget" name="SectionContentListWidgetForm">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>522</width>
|
||||
<height>258</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QTableView" name="tableView">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="deleteButton">
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
28
AdvancedDockingSystemDemo_v2/src/main.cpp
Normal file
28
AdvancedDockingSystemDemo_v2/src/main.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
#include <QApplication>
|
||||
|
||||
#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();
|
||||
}
|
91
AdvancedDockingSystemDemo_v2/src/mainwindow.cpp
Normal file
91
AdvancedDockingSystemDemo_v2/src/mainwindow.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <QTime>
|
||||
#include <QLabel>
|
||||
#include <QTextEdit>
|
||||
#include <QCalendarWidget>
|
||||
#include <QFrame>
|
||||
#include <QTreeView>
|
||||
#include <QFileSystemModel>
|
||||
#include <QBoxLayout>
|
||||
|
||||
#include "DockManager.h"
|
||||
#include "DockWidget.h"
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int CONTENT_COUNT = 0;
|
||||
|
||||
static ads::CDockWidget* createLongTextLabelDockWidget(ads::CDockManager* DockManager)
|
||||
{
|
||||
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."));
|
||||
|
||||
ads::CDockWidget* DockWidget = new ads::CDockWidget("DockWidget1");
|
||||
DockWidget->setWidget(l);
|
||||
return DockWidget;
|
||||
}
|
||||
|
||||
static ads::CDockWidget* createCalendarDockWidget(ads::CDockManager* DockManager)
|
||||
{
|
||||
QCalendarWidget* w = new QCalendarWidget();
|
||||
ads::CDockWidget* DockWidget = new ads::CDockWidget("DockWidget1");
|
||||
DockWidget->setWidget(w);
|
||||
return DockWidget;
|
||||
}
|
||||
|
||||
static ads::CDockWidget* createFileSystemTreeDockWidget(ads::CDockManager* DockManager)
|
||||
{
|
||||
QTreeView* w = new QTreeView();
|
||||
w->setFrameShape(QFrame::NoFrame);
|
||||
QFileSystemModel* m = new QFileSystemModel(w);
|
||||
m->setRootPath(QDir::currentPath());
|
||||
w->setModel(m);
|
||||
ads::CDockWidget* DockWidget = new ads::CDockWidget("DockWidget1");
|
||||
DockWidget->setWidget(w);
|
||||
return DockWidget;
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
m_DockManager = new ads::CDockManager(this);
|
||||
createContent();
|
||||
// Default window geometry
|
||||
resize(800, 600);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::createContent()
|
||||
{
|
||||
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, createCalendarDockWidget(m_DockManager));
|
||||
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(m_DockManager));
|
||||
m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(m_DockManager));
|
||||
m_DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(m_DockManager));
|
||||
}
|
||||
|
||||
|
25
AdvancedDockingSystemDemo_v2/src/mainwindow.h
Normal file
25
AdvancedDockingSystemDemo_v2/src/mainwindow.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include "DockManager.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
virtual ~MainWindow();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
ads::CDockManager* m_DockManager;
|
||||
void createContent();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
79
AdvancedDockingSystemDemo_v2/src/mainwindow.ui
Normal file
79
AdvancedDockingSystemDemo_v2/src/mainwindow.ui
Normal file
@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget"/>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
</property>
|
||||
<addaction name="actionExit"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuView">
|
||||
<property name="title">
|
||||
<string>View</string>
|
||||
</property>
|
||||
<addaction name="actionContentList"/>
|
||||
<addaction name="actionDemo_2"/>
|
||||
<addaction name="actionDemo_3"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuAbout">
|
||||
<property name="title">
|
||||
<string>About</string>
|
||||
</property>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuView"/>
|
||||
<addaction name="menuAbout"/>
|
||||
</widget>
|
||||
<action name="actionAddSectionContent">
|
||||
<property name="text">
|
||||
<string>Add SectionContent</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionContentList">
|
||||
<property name="text">
|
||||
<string>Contents...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionDemo_2">
|
||||
<property name="text">
|
||||
<string>Demo 2</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionDemo_3">
|
||||
<property name="text">
|
||||
<string>Demo 3</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExit">
|
||||
<property name="text">
|
||||
<string>Exit</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue
Block a user