mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-01-24 05:22:06 +08:00
Added support for componentsFactory per dock manager
This commit is contained in:
parent
7245dced84
commit
1bec4234c3
@ -470,12 +470,12 @@ void MainWindowPrivate::createContent()
|
||||
appendFeaturStringToWindowTitle(FileSystemWidget);
|
||||
|
||||
// Test custom factory - we inject a help button into the title bar
|
||||
ads::CDockComponentsFactory::setFactory(new CCustomComponentsFactory());
|
||||
DockManager->setComponentsFactory(new CCustomComponentsFactory());
|
||||
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
|
||||
// Uncomment the next line if you would like to test the
|
||||
// HideSingleWidgetTitleBar functionality
|
||||
// TopDockArea->setDockAreaFlag(ads::CDockAreaWidget::HideSingleWidgetTitleBar, true);
|
||||
ads::CDockComponentsFactory::resetDefaultFactory();
|
||||
DockManager->setComponentsFactory(ads::CDockComponentsFactory::factory());
|
||||
|
||||
// We create a calendar widget and clear all flags to prevent the dock area
|
||||
// from closing
|
||||
|
@ -124,6 +124,21 @@ struct AutoHideDockContainerPrivate
|
||||
*/
|
||||
AutoHideDockContainerPrivate(CAutoHideDockContainer *_public);
|
||||
|
||||
/**
|
||||
* Convenience function to ease access to dock manager components factory
|
||||
*/
|
||||
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const
|
||||
{
|
||||
if (!DockWidget || !DockWidget->dockManager())
|
||||
{
|
||||
return CDockComponentsFactory::factory();
|
||||
}
|
||||
else
|
||||
{
|
||||
return DockWidget->dockManager()->componentsFactory();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to get a dock widget area
|
||||
*/
|
||||
@ -199,7 +214,7 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget, SideBarL
|
||||
{
|
||||
hide(); // auto hide dock container is initially always hidden
|
||||
d->SideTabBarArea = area;
|
||||
d->SideTab = componentsFactory()->createDockWidgetSideTab(nullptr);
|
||||
d->SideTab = d->componentsFactory()->createDockWidgetSideTab(nullptr);
|
||||
connect(d->SideTab, &CAutoHideTab::pressed, this, &CAutoHideDockContainer::toggleCollapseState);
|
||||
d->DockArea = new CDockAreaWidget(DockWidget->dockManager(), parent);
|
||||
d->DockArea->setObjectName("autoHideDockArea");
|
||||
|
@ -114,6 +114,14 @@ struct DockAreaTitleBarPrivate
|
||||
return DockArea->dockManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function for access to dock manager components factory
|
||||
*/
|
||||
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const
|
||||
{
|
||||
return dockManager()->componentsFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given config flag is set
|
||||
* Convenience function to ease config flag testing
|
||||
|
@ -269,6 +269,14 @@ struct DockAreaWidgetPrivate
|
||||
*/
|
||||
DockAreaWidgetPrivate(CDockAreaWidget* _public);
|
||||
|
||||
/**
|
||||
* Convencience function to ease components factory access
|
||||
*/
|
||||
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const
|
||||
{
|
||||
return DockManager->componentsFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the layout for top area with tabs and close button
|
||||
*/
|
||||
|
@ -21,7 +21,8 @@
|
||||
|
||||
namespace ads
|
||||
{
|
||||
static std::unique_ptr<CDockComponentsFactory> DefaultFactory(new CDockComponentsFactory());
|
||||
|
||||
static QSharedPointer<ads::CDockComponentsFactory> DefaultFactory;
|
||||
|
||||
|
||||
//============================================================================
|
||||
@ -52,9 +53,13 @@ CDockAreaTitleBar* CDockComponentsFactory::createDockAreaTitleBar(CDockAreaWidge
|
||||
|
||||
|
||||
//============================================================================
|
||||
const CDockComponentsFactory* CDockComponentsFactory::factory()
|
||||
QSharedPointer<ads::CDockComponentsFactory> CDockComponentsFactory::factory()
|
||||
{
|
||||
return DefaultFactory.get();
|
||||
if (!DefaultFactory)
|
||||
{
|
||||
DefaultFactory.reset(new CDockComponentsFactory());
|
||||
}
|
||||
return DefaultFactory;
|
||||
}
|
||||
|
||||
|
||||
@ -70,6 +75,7 @@ void CDockComponentsFactory::resetDefaultFactory()
|
||||
{
|
||||
DefaultFactory.reset(new CDockComponentsFactory());
|
||||
}
|
||||
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -66,9 +66,11 @@ public:
|
||||
virtual CDockAreaTitleBar* createDockAreaTitleBar(CDockAreaWidget* DockArea) const;
|
||||
|
||||
/**
|
||||
* Returns the default components factory
|
||||
* This returns the default dock components factory instance.
|
||||
* If no components factory is assigned to a specifc dock manager, this
|
||||
* global factory instance will be used.
|
||||
*/
|
||||
static const CDockComponentsFactory* factory();
|
||||
static QSharedPointer<ads::CDockComponentsFactory> factory();
|
||||
|
||||
/**
|
||||
* Sets a new default factory for creation of GUI elements.
|
||||
@ -82,15 +84,6 @@ public:
|
||||
static void resetDefaultFactory();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Convenience function to ease factory instance access
|
||||
*/
|
||||
inline const CDockComponentsFactory* componentsFactory()
|
||||
{
|
||||
return CDockComponentsFactory::factory();
|
||||
}
|
||||
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -60,6 +60,8 @@
|
||||
#include "DockAreaTitleBar.h"
|
||||
#include "DockFocusController.h"
|
||||
#include "DockSplitter.h"
|
||||
#include "DockComponentsFactory.h"
|
||||
|
||||
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
||||
#include "linux/FloatingWidgetTitleBar.h"
|
||||
@ -125,6 +127,7 @@ struct DockManagerPrivate
|
||||
QSize ToolBarIconSizeDocked = QSize(16, 16);
|
||||
QSize ToolBarIconSizeFloating = QSize(24, 24);
|
||||
CDockWidget::DockWidgetFeatures LockedDockWidgetFeatures;
|
||||
QSharedPointer<ads::CDockComponentsFactory> ComponentFactory {ads::CDockComponentsFactory::factory()};
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@ -581,6 +584,28 @@ CDockManager::~CDockManager()
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QSharedPointer<ads::CDockComponentsFactory> CDockManager::componentsFactory() const
|
||||
{
|
||||
return d->ComponentFactory;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockManager::setComponentsFactory(ads::CDockComponentsFactory* factory)
|
||||
{
|
||||
setComponentsFactory(QSharedPointer<ads::CDockComponentsFactory>(factory));
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockManager::setComponentsFactory(QSharedPointer<ads::CDockComponentsFactory> factory)
|
||||
{
|
||||
d->ComponentFactory = factory;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
||||
bool CDockManager::eventFilter(QObject *obj, QEvent *e)
|
||||
|
@ -290,6 +290,24 @@ public:
|
||||
*/
|
||||
virtual ~CDockManager() override;
|
||||
|
||||
/**
|
||||
* Returns the dock manager specific factory for creating components of
|
||||
* fock widgets
|
||||
*/
|
||||
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const;
|
||||
|
||||
/**
|
||||
* Sets a custom factory for creating components of dock widgets.
|
||||
* The pointer is stored internally into a shared pointer so you should not
|
||||
* delete the given factory object as long as it is used by the dock manager.
|
||||
*/
|
||||
void setComponentsFactory(ads::CDockComponentsFactory* Factory);
|
||||
|
||||
/**
|
||||
* Sets a custom factory for creating components of dock widgets.
|
||||
*/
|
||||
void setComponentsFactory(QSharedPointer<ads::CDockComponentsFactory>);
|
||||
|
||||
/**
|
||||
* This function returns the global configuration flags
|
||||
*/
|
||||
|
@ -102,6 +102,14 @@ struct DockWidgetPrivate
|
||||
*/
|
||||
DockWidgetPrivate(CDockWidget* _public);
|
||||
|
||||
/**
|
||||
* Convenience function to ease components factory access
|
||||
*/
|
||||
QSharedPointer<ads::CDockComponentsFactory> componentsFactory() const
|
||||
{
|
||||
return DockManager ? DockManager->componentsFactory() : CDockComponentsFactory::factory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show dock widget
|
||||
*/
|
||||
@ -358,9 +366,17 @@ void DockWidgetPrivate::setToolBarStyleFromDockManager()
|
||||
|
||||
//============================================================================
|
||||
CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
|
||||
QFrame(parent),
|
||||
d(new DockWidgetPrivate(this))
|
||||
CDockWidget(nullptr, title, parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockWidget::CDockWidget(CDockManager *manager, const QString &title, QWidget* parent)
|
||||
: QFrame(parent),
|
||||
d(new DockWidgetPrivate(this))
|
||||
{
|
||||
d->DockManager = manager;
|
||||
d->Layout = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
d->Layout->setContentsMargins(0, 0, 0, 0);
|
||||
d->Layout->setSpacing(0);
|
||||
@ -368,7 +384,7 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
|
||||
setWindowTitle(title);
|
||||
setObjectName(title);
|
||||
|
||||
d->TabWidget = componentsFactory()->createDockWidgetTab(this);
|
||||
d->TabWidget = d->componentsFactory()->createDockWidgetTab(this);
|
||||
|
||||
d->ToggleViewAction = new QAction(title, this);
|
||||
d->ToggleViewAction->setCheckable(true);
|
||||
@ -382,6 +398,7 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CDockWidget::~CDockWidget()
|
||||
{
|
||||
|
@ -256,8 +256,18 @@ public:
|
||||
* during runtime, you need to set a unique object name explicitly
|
||||
* by calling setObjectName() after construction.
|
||||
* Use the layoutFlags to configure the layout of the dock widget.
|
||||
* \note If you would like to use custom TabWidget implementations, you need
|
||||
* to use the constructor with the CDockManager argument.
|
||||
*/
|
||||
CDockWidget(const QString &title, QWidget* parent = nullptr);
|
||||
explicit CDockWidget(const QString &title, QWidget* parent = nullptr);
|
||||
|
||||
/**
|
||||
* Creates a dock widget and assigns the dock manager that manages this
|
||||
* widget.
|
||||
* This allows the dock widget to use the componentsFactory() of the dock
|
||||
* manager in the constructot to create its components.
|
||||
*/
|
||||
CDockWidget(CDockManager *manager, const QString &title, QWidget* parent = nullptr);
|
||||
|
||||
/**
|
||||
* Virtual Destructor
|
||||
|
Loading…
Reference in New Issue
Block a user