mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-25 07:31:33 +08:00
Added support for new configuration flag RetainTabSizeWhenCloseButtonHidden
This commit is contained in:
parent
b776fc24a6
commit
0c5ef5e158
@ -301,14 +301,18 @@ CMainWindow::CMainWindow(QWidget *parent) :
|
|||||||
|
|
||||||
// uncomment the following line if the tab close button should be
|
// uncomment the following line if the tab close button should be
|
||||||
// a QToolButton instead of a QPushButton
|
// a QToolButton instead of a QPushButton
|
||||||
//CDockManager::setConfigFlags(CDockManager::configFlags() | CDockManager::TabCloseButtonIsToolButton);
|
// CDockManager::setConfigFlags(CDockManager::configFlags() | CDockManager::TabCloseButtonIsToolButton);
|
||||||
|
|
||||||
|
// uncomment the following line if you wand a fixed tab width that does
|
||||||
|
// not change if the visibility of the close button changes
|
||||||
|
// CDockManager::setConfigFlag(CDockManager::RetainTabSizeWhenCloseButtonHidden, true);
|
||||||
|
|
||||||
// Now create the dock manager and its content
|
// Now create the dock manager and its content
|
||||||
d->DockManager = new CDockManager(this);
|
d->DockManager = new CDockManager(this);
|
||||||
|
|
||||||
// Uncomment the following line to have the old style where the dock
|
// Uncomment the following line to have the old style where the dock
|
||||||
// area close button closes the active tab
|
// area close button closes the active tab
|
||||||
//CDockManager::setConfigFlags({CDockManager::DockAreaHasCloseButton
|
// CDockManager::setConfigFlags({CDockManager::DockAreaHasCloseButton
|
||||||
// | CDockManager::DockAreaCloseButtonClosesTab});
|
// | CDockManager::DockAreaCloseButtonClosesTab});
|
||||||
connect(d->PerspectiveComboBox, SIGNAL(activated(const QString&)),
|
connect(d->PerspectiveComboBox, SIGNAL(activated(const QString&)),
|
||||||
d->DockManager, SLOT(openPerspective(const QString&)));
|
d->DockManager, SLOT(openPerspective(const QString&)));
|
||||||
|
@ -778,6 +778,13 @@ void CDockManager::setConfigFlags(const ConfigFlags Flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
void CDockManager::setConfigFlag(eConfigFlag Flag, bool On)
|
||||||
|
{
|
||||||
|
internal::setFlag(StaticConfigFlags, Flag, On);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace ads
|
} // namespace ads
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -123,13 +123,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
enum eConfigFlag
|
enum eConfigFlag
|
||||||
{
|
{
|
||||||
ActiveTabHasCloseButton = 0x01, //!< If this flag is set, the active tab in a tab area has a close button
|
ActiveTabHasCloseButton = 0x0001, //!< If this flag is set, the active tab in a tab area has a close button
|
||||||
DockAreaHasCloseButton = 0x02, //!< If the flag is set each dock area has a close button
|
DockAreaHasCloseButton = 0x0002, //!< If the flag is set each dock area has a close button
|
||||||
DockAreaCloseButtonClosesTab = 0x04,//!< If the flag is set, the dock area close button closes the active tab, if not set, it closes the complete cock area
|
DockAreaCloseButtonClosesTab = 0x0004,//!< If the flag is set, the dock area close button closes the active tab, if not set, it closes the complete cock area
|
||||||
OpaqueSplitterResize = 0x08, //!< See QSplitter::setOpaqueResize() documentation
|
OpaqueSplitterResize = 0x0008, //!< See QSplitter::setOpaqueResize() documentation
|
||||||
XmlAutoFormattingEnabled = 0x10,//!< If enabled, the XML writer automatically adds line-breaks and indentation to empty sections between elements (ignorable whitespace).
|
XmlAutoFormattingEnabled = 0x0010,//!< If enabled, the XML writer automatically adds line-breaks and indentation to empty sections between elements (ignorable whitespace).
|
||||||
XmlCompressionEnabled = 0x20,//!< If enabled, the XML output will be compressed and is not human readable anymore
|
XmlCompressionEnabled = 0x0020,//!< If enabled, the XML output will be compressed and is not human readable anymore
|
||||||
TabCloseButtonIsToolButton = 0x40,//! If enabled the tab close buttons will be QToolButtons instead of QPushButtons - disabled by default
|
TabCloseButtonIsToolButton = 0x0040,//! If enabled the tab close buttons will be QToolButtons instead of QPushButtons - disabled by default
|
||||||
|
AllTabsHaveCloseButton = 0x0080, //!< if this flag is set, then all tabs that are closable show a close button
|
||||||
|
RetainTabSizeWhenCloseButtonHidden = 0x0100, //!< if this flag is set, the space for the close button is reserved even if the close button is not visible
|
||||||
DefaultConfig = ActiveTabHasCloseButton | DockAreaHasCloseButton | OpaqueSplitterResize | XmlCompressionEnabled, ///< the default configuration
|
DefaultConfig = ActiveTabHasCloseButton | DockAreaHasCloseButton | OpaqueSplitterResize | XmlCompressionEnabled, ///< the default configuration
|
||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(ConfigFlags, eConfigFlag)
|
Q_DECLARE_FLAGS(ConfigFlags, eConfigFlag)
|
||||||
@ -159,6 +161,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
static void setConfigFlags(const ConfigFlags Flags);
|
static void setConfigFlags(const ConfigFlags Flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a certain config flag
|
||||||
|
*/
|
||||||
|
static void setConfigFlag(eConfigFlag Flag, bool On = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds dockwidget into the given area.
|
* Adds dockwidget into the given area.
|
||||||
* If DockAreaWidget is not null, then the area parameter indicates the area
|
* If DockAreaWidget is not null, then the area parameter indicates the area
|
||||||
|
@ -289,25 +289,21 @@ CDockWidgetTab* CDockWidget::tabWidget() const
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
void CDockWidget::setFeatures(DockWidgetFeatures features)
|
void CDockWidget::setFeatures(DockWidgetFeatures features)
|
||||||
{
|
{
|
||||||
|
if (d->Features == features)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
d->Features = features;
|
d->Features = features;
|
||||||
|
d->TabWidget->onDockWidgetFeaturesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
void CDockWidget::setFeature(DockWidgetFeature flag, bool on)
|
void CDockWidget::setFeature(DockWidgetFeature flag, bool on)
|
||||||
{
|
{
|
||||||
#if QT_VERSION >= 0x050700
|
auto Features = features();
|
||||||
d->Features.setFlag(flag, on);
|
internal::setFlag(Features, flag, on);
|
||||||
#else
|
setFeatures(Features);
|
||||||
if(on)
|
|
||||||
{
|
|
||||||
d->Features |= flag;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
d->Features &= ~flag;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -167,9 +167,8 @@ void DockWidgetTabPrivate::createLayout()
|
|||||||
CloseIcon.addPixmap(normalPixmap, QIcon::Normal);
|
CloseIcon.addPixmap(normalPixmap, QIcon::Normal);
|
||||||
CloseIcon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled);
|
CloseIcon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled);
|
||||||
CloseButton->setIcon(CloseIcon);
|
CloseButton->setIcon(CloseIcon);
|
||||||
|
|
||||||
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||||
CloseButton->setVisible(false);
|
_this->onDockWidgetFeaturesChanged();
|
||||||
#ifndef QT_NO_TOOLTIP
|
#ifndef QT_NO_TOOLTIP
|
||||||
CloseButton->setToolTip(QObject::tr("Close Tab"));
|
CloseButton->setToolTip(QObject::tr("Close Tab"));
|
||||||
#endif
|
#endif
|
||||||
@ -389,8 +388,10 @@ bool CDockWidgetTab::isActiveTab() const
|
|||||||
void CDockWidgetTab::setActiveTab(bool active)
|
void CDockWidgetTab::setActiveTab(bool active)
|
||||||
{
|
{
|
||||||
bool DockWidgetClosable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetClosable);
|
bool DockWidgetClosable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetClosable);
|
||||||
bool TabHasCloseButton = d->testConfigFlag(CDockManager::ActiveTabHasCloseButton);
|
bool ActiveTabHasCloseButton = d->testConfigFlag(CDockManager::ActiveTabHasCloseButton);
|
||||||
d->CloseButton->setVisible(active && DockWidgetClosable && TabHasCloseButton);
|
bool AllTabsHaveCloseButton = d->testConfigFlag(CDockManager::AllTabsHaveCloseButton);
|
||||||
|
bool TabHasCloseButton = (ActiveTabHasCloseButton && active) | AllTabsHaveCloseButton;
|
||||||
|
d->CloseButton->setVisible(DockWidgetClosable && TabHasCloseButton);
|
||||||
if (d->IsActiveTab == active)
|
if (d->IsActiveTab == active)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -546,6 +547,17 @@ bool CDockWidgetTab::event(QEvent *e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
void CDockWidgetTab::onDockWidgetFeaturesChanged()
|
||||||
|
{
|
||||||
|
auto Features = d->DockWidget->features();
|
||||||
|
auto SizePolicy = d->CloseButton->sizePolicy();
|
||||||
|
SizePolicy.setRetainSizeWhenHidden(Features.testFlag(CDockWidget::DockWidgetClosable)
|
||||||
|
&& d->testConfigFlag(CDockManager::RetainTabSizeWhenCloseButtonHidden));
|
||||||
|
d->CloseButton->setSizePolicy(SizePolicy);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace ads
|
} // namespace ads
|
||||||
|
@ -53,6 +53,8 @@ class ADS_EXPORT CDockWidgetTab : public QFrame
|
|||||||
private:
|
private:
|
||||||
DockWidgetTabPrivate* d; ///< private data (pimpl)
|
DockWidgetTabPrivate* d; ///< private data (pimpl)
|
||||||
friend struct DockWidgetTabPrivate;
|
friend struct DockWidgetTabPrivate;
|
||||||
|
friend class CDockWidget;
|
||||||
|
void onDockWidgetFeaturesChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDetachActionTriggered();
|
void onDetachActionTriggered();
|
||||||
@ -125,7 +127,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
QString text() const;
|
QString text() const;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the tab text
|
* Sets the tab text
|
||||||
*/
|
*/
|
||||||
@ -136,16 +137,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool isClosable() const;
|
bool isClosable() const;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Track event ToolTipChange and set child ToolTip
|
* Track event ToolTipChange and set child ToolTip
|
||||||
*/
|
*/
|
||||||
virtual bool event(QEvent *e) override;
|
virtual bool event(QEvent *e) override;
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void setVisible(bool visible) override;
|
virtual void setVisible(bool visible) override;
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void activeTabChanged();
|
void activeTabChanged();
|
||||||
void clicked();
|
void clicked();
|
||||||
|
@ -162,6 +162,27 @@ T findParent(const QWidget* w)
|
|||||||
*/
|
*/
|
||||||
QPixmap createTransparentPixmap(const QPixmap& Source, qreal Opacity);
|
QPixmap createTransparentPixmap(const QPixmap& Source, qreal Opacity);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function for settings flags in a QFlags instance.
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
void setFlag(T& Flags, typename T::enum_type flag, bool on = true)
|
||||||
|
{
|
||||||
|
#if QT_VERSION >= 0x050700
|
||||||
|
Flags.setFlag(flag, on);
|
||||||
|
#else
|
||||||
|
if(on)
|
||||||
|
{
|
||||||
|
d->Features |= flag;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
d->Features &= ~flag;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace ads
|
} // namespace ads
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user