mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 23:31:32 +08:00
Added global static icon provider to enable registration of custom icons
This commit is contained in:
parent
de645b3cca
commit
3ff154aff1
@ -46,6 +46,7 @@
|
||||
#include "DockWidget.h"
|
||||
#include "DockWidgetTab.h"
|
||||
#include "DockAreaTabBar.h"
|
||||
#include "IconProvider.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@ -101,14 +102,24 @@ struct DockAreaTitleBarPrivate
|
||||
/**
|
||||
* Helper function to set title bar button icons depending on operating
|
||||
* system and to avoid duplicated code. On windows the standard icons
|
||||
* are blurry since Qt 5.11 so we need to do some additional steps
|
||||
* are blurry since Qt 5.11 so we need to do some additional steps.
|
||||
* If the global IconPovider of the dockmanager provides a custom
|
||||
* Icon for the given CustomIconId, the this icon will be used.
|
||||
*/
|
||||
void setTitleBarButtonIcon(tTileBarButton* Button, QStyle::StandardPixmap StandarPixmap)
|
||||
void setTitleBarButtonIcon(tTileBarButton* Button, QStyle::StandardPixmap StandarPixmap,
|
||||
ads::eIcon CustomIconId)
|
||||
{
|
||||
// First we try to use custom icons if available
|
||||
QIcon Icon = CDockManager::iconProvider().customIcon(CustomIconId);
|
||||
if (!Icon.isNull())
|
||||
{
|
||||
Button->setIcon(Icon);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
Button->setIcon(_this->style()->standardIcon(StandarPixmap));
|
||||
#else
|
||||
QIcon Icon;
|
||||
QPixmap normalPixmap = _this->style()->standardPixmap(StandarPixmap, 0, Button);
|
||||
Icon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled);
|
||||
Icon.addPixmap(normalPixmap, QIcon::Normal);
|
||||
@ -136,7 +147,7 @@ void DockAreaTitleBarPrivate::createButtons()
|
||||
TabsMenuButton->setObjectName("tabsMenuButton");
|
||||
TabsMenuButton->setAutoRaise(true);
|
||||
TabsMenuButton->setPopupMode(QToolButton::InstantPopup);
|
||||
setTitleBarButtonIcon(TabsMenuButton, QStyle::SP_TitleBarUnshadeButton);
|
||||
setTitleBarButtonIcon(TabsMenuButton, QStyle::SP_TitleBarUnshadeButton, ads::DockAreaMenuIcon);
|
||||
QMenu* TabsMenu = new QMenu(TabsMenuButton);
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
TabsMenu->setToolTipsVisible(true);
|
||||
@ -159,7 +170,7 @@ void DockAreaTitleBarPrivate::createButtons()
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
UndockButton->setToolTip(QObject::tr("Detach Group"));
|
||||
#endif
|
||||
setTitleBarButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton);
|
||||
setTitleBarButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon);
|
||||
UndockButton->setSizePolicy(ButtonSizePolicy);
|
||||
TopLayout->addWidget(UndockButton, 0);
|
||||
_this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked()));
|
||||
@ -169,7 +180,7 @@ void DockAreaTitleBarPrivate::createButtons()
|
||||
CloseButton = new tTileBarButton();
|
||||
CloseButton->setObjectName("closeButton");
|
||||
CloseButton->setAutoRaise(true);
|
||||
setTitleBarButtonIcon(CloseButton, QStyle::SP_TitleBarCloseButton);
|
||||
setTitleBarButtonIcon(CloseButton, QStyle::SP_TitleBarCloseButton, ads::DockAreaCloseIcon);
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
if (testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
|
||||
{
|
||||
|
@ -52,6 +52,8 @@
|
||||
#include "DockWidget.h"
|
||||
#include "ads_globals.h"
|
||||
#include "DockAreaWidget.h"
|
||||
#include "IconProvider.h"
|
||||
|
||||
|
||||
|
||||
namespace ads
|
||||
@ -788,6 +790,14 @@ void CDockManager::setConfigFlag(eConfigFlag Flag, bool On)
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
CIconProvider& CDockManager::iconProvider()
|
||||
{
|
||||
static CIconProvider Instance;
|
||||
return Instance;
|
||||
}
|
||||
|
||||
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -49,6 +49,7 @@ class CDockAreaTabBar;
|
||||
class CDockWidgetTab;
|
||||
struct DockWidgetTabPrivate;
|
||||
struct DockAreaWidgetPrivate;
|
||||
class CIconProvider;
|
||||
|
||||
/**
|
||||
* The central dock manager that maintains the complete docking system.
|
||||
@ -166,6 +167,13 @@ public:
|
||||
*/
|
||||
static void setConfigFlag(eConfigFlag Flag, bool On = true);
|
||||
|
||||
/**
|
||||
* Returns the global icon provider.
|
||||
* The icon provider enables the use of custom icons in case using
|
||||
* styleheets for icons is not an option.
|
||||
*/
|
||||
static CIconProvider& iconProvider();
|
||||
|
||||
/**
|
||||
* Adds dockwidget into the given area.
|
||||
* If DockAreaWidget is not null, then the area parameter indicates the area
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include "FloatingDockContainer.h"
|
||||
#include "DockOverlay.h"
|
||||
#include "DockManager.h"
|
||||
#include "IconProvider.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@ -161,12 +162,15 @@ void DockWidgetTabPrivate::createLayout()
|
||||
|
||||
CloseButton = createCloseButton();
|
||||
CloseButton->setObjectName("tabCloseButton");
|
||||
// The standard icons do does not look good on high DPI screens
|
||||
QIcon CloseIcon;
|
||||
QPixmap normalPixmap = _this->style()->standardPixmap(QStyle::SP_TitleBarCloseButton, 0, CloseButton);
|
||||
CloseIcon.addPixmap(normalPixmap, QIcon::Normal);
|
||||
CloseIcon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled);
|
||||
CloseButton->setIcon(CloseIcon);
|
||||
QIcon CloseIcon = CDockManager::iconProvider().customIcon(TabCloseIcon);
|
||||
if (CloseIcon.isNull())
|
||||
{
|
||||
// The standard icons do does not look good on high DPI screens
|
||||
QPixmap normalPixmap = _this->style()->standardPixmap(QStyle::SP_TitleBarCloseButton, 0, CloseButton);
|
||||
CloseIcon.addPixmap(normalPixmap, QIcon::Normal);
|
||||
CloseIcon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled);
|
||||
CloseButton->setIcon(CloseIcon);
|
||||
}
|
||||
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
_this->onDockWidgetFeaturesChanged();
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
|
73
src/IconProvider.cpp
Normal file
73
src/IconProvider.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
//============================================================================
|
||||
/// \file IconProvider.cpp
|
||||
/// \author Uwe Kindler
|
||||
/// \date 18.10.2019
|
||||
/// \brief Implementation of CIconProvider
|
||||
//============================================================================
|
||||
|
||||
//============================================================================
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include "IconProvider.h"
|
||||
#include <QVector>
|
||||
|
||||
namespace ads
|
||||
{
|
||||
/**
|
||||
* Private data class (pimpl)
|
||||
*/
|
||||
struct IconProviderPrivate
|
||||
{
|
||||
CIconProvider *_this;
|
||||
QVector<QIcon> UserIcons{IconCount, QIcon()};
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
*/
|
||||
IconProviderPrivate(CIconProvider *_public);
|
||||
};
|
||||
// struct LedArrayPanelPrivate
|
||||
|
||||
//============================================================================
|
||||
IconProviderPrivate::IconProviderPrivate(CIconProvider *_public) :
|
||||
_this(_public)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
CIconProvider::CIconProvider() :
|
||||
d(new IconProviderPrivate(this))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
CIconProvider::~CIconProvider()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QIcon CIconProvider::customIcon(eIcon IconId) const
|
||||
{
|
||||
Q_ASSERT(IconId < d->UserIcons.size());
|
||||
return d->UserIcons[IconId];
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CIconProvider::registerCustomIcon(eIcon IconId, const QIcon &icon)
|
||||
{
|
||||
Q_ASSERT(IconId < d->UserIcons.size());
|
||||
d->UserIcons[IconId] = icon;
|
||||
}
|
||||
|
||||
} // namespace ads
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// EOF IconProvider.cpp
|
61
src/IconProvider.h
Normal file
61
src/IconProvider.h
Normal file
@ -0,0 +1,61 @@
|
||||
#ifndef IconProviderH
|
||||
#define IconProviderH
|
||||
//============================================================================
|
||||
/// \file IconProvider.h
|
||||
/// \author Uwe Kindler
|
||||
/// \date 18.10.2019
|
||||
/// \brief Declaration of CIconProvider
|
||||
//============================================================================
|
||||
|
||||
//============================================================================
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include <QIcon>
|
||||
|
||||
#include "ads_globals.h"
|
||||
|
||||
namespace ads
|
||||
{
|
||||
|
||||
struct IconProviderPrivate;
|
||||
|
||||
/**
|
||||
* This object provides all icons that are required by the advanced docking
|
||||
* system.
|
||||
* The IconProvider enables the user to register custom icons in case using
|
||||
* stylesheets is not an option.
|
||||
*/
|
||||
class ADS_EXPORT CIconProvider
|
||||
{
|
||||
private:
|
||||
IconProviderPrivate* d; ///< private data (pimpl)
|
||||
friend class IconProviderPrivate;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
CIconProvider();
|
||||
|
||||
/**
|
||||
* Virtual Destructor
|
||||
*/
|
||||
virtual ~CIconProvider();
|
||||
|
||||
/**
|
||||
* The function returns a custom icon if one is registered and a null Icon
|
||||
* if no custom icon is registered
|
||||
*/
|
||||
QIcon customIcon(eIcon IconId) const;
|
||||
|
||||
/**
|
||||
* Registers a custom icon for the given IconId
|
||||
*/
|
||||
void registerCustomIcon(eIcon IconId, const QIcon &icon);
|
||||
}; // class IconProvider
|
||||
|
||||
} // namespace ads
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
#endif // IconProviderH
|
@ -96,6 +96,19 @@ enum eDragState
|
||||
DraggingFloatingWidget//!< DraggingFloatingWidget
|
||||
};
|
||||
|
||||
/**
|
||||
* The different icons used in the UI
|
||||
*/
|
||||
enum eIcon
|
||||
{
|
||||
TabCloseIcon, //!< TabCloseIcon
|
||||
DockAreaMenuIcon, //!< DockAreaMenuIcon
|
||||
DockAreaUndockIcon,//!< DockAreaUndockIcon
|
||||
DockAreaCloseIcon, //!< DockAreaCloseIcon
|
||||
|
||||
IconCount, //!< just a delimiter for range checks
|
||||
};
|
||||
|
||||
namespace internal
|
||||
{
|
||||
static const bool RestoreTesting = true;
|
||||
|
@ -40,7 +40,8 @@ HEADERS += \
|
||||
DockOverlay.h \
|
||||
DockSplitter.h \
|
||||
DockAreaTitleBar.h \
|
||||
ElidingLabel.h
|
||||
ElidingLabel.h \
|
||||
IconProvider.h
|
||||
|
||||
|
||||
SOURCES += \
|
||||
@ -55,7 +56,8 @@ SOURCES += \
|
||||
DockOverlay.cpp \
|
||||
DockSplitter.cpp \
|
||||
DockAreaTitleBar.cpp \
|
||||
ElidingLabel.cpp
|
||||
ElidingLabel.cpp \
|
||||
IconProvider.cpp
|
||||
|
||||
|
||||
unix {
|
||||
|
Loading…
Reference in New Issue
Block a user