mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 23:31:32 +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
|
||||
// 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
|
||||
d->DockManager = new CDockManager(this);
|
||||
|
||||
// Uncomment the following line to have the old style where the dock
|
||||
// area close button closes the active tab
|
||||
//CDockManager::setConfigFlags({CDockManager::DockAreaHasCloseButton
|
||||
// CDockManager::setConfigFlags({CDockManager::DockAreaHasCloseButton
|
||||
// | CDockManager::DockAreaCloseButtonClosesTab});
|
||||
connect(d->PerspectiveComboBox, SIGNAL(activated(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
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -123,13 +123,15 @@ public:
|
||||
*/
|
||||
enum eConfigFlag
|
||||
{
|
||||
ActiveTabHasCloseButton = 0x01, //!< 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
|
||||
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
|
||||
OpaqueSplitterResize = 0x08, //!< See QSplitter::setOpaqueResize() documentation
|
||||
XmlAutoFormattingEnabled = 0x10,//!< 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
|
||||
TabCloseButtonIsToolButton = 0x40,//! If enabled the tab close buttons will be QToolButtons instead of QPushButtons - disabled by default
|
||||
ActiveTabHasCloseButton = 0x0001, //!< If this flag is set, the active tab in a tab area has a close button
|
||||
DockAreaHasCloseButton = 0x0002, //!< If the flag is set each dock area has a close button
|
||||
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 = 0x0008, //!< See QSplitter::setOpaqueResize() documentation
|
||||
XmlAutoFormattingEnabled = 0x0010,//!< If enabled, the XML writer automatically adds line-breaks and indentation to empty sections between elements (ignorable whitespace).
|
||||
XmlCompressionEnabled = 0x0020,//!< If enabled, the XML output will be compressed and is not human readable anymore
|
||||
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
|
||||
};
|
||||
Q_DECLARE_FLAGS(ConfigFlags, eConfigFlag)
|
||||
@ -159,6 +161,11 @@ public:
|
||||
*/
|
||||
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.
|
||||
* 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)
|
||||
{
|
||||
if (d->Features == features)
|
||||
{
|
||||
return;
|
||||
}
|
||||
d->Features = features;
|
||||
d->TabWidget->onDockWidgetFeaturesChanged();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidget::setFeature(DockWidgetFeature flag, bool on)
|
||||
{
|
||||
#if QT_VERSION >= 0x050700
|
||||
d->Features.setFlag(flag, on);
|
||||
#else
|
||||
if(on)
|
||||
{
|
||||
d->Features |= flag;
|
||||
}
|
||||
else
|
||||
{
|
||||
d->Features &= ~flag;
|
||||
}
|
||||
#endif
|
||||
auto Features = features();
|
||||
internal::setFlag(Features, flag, on);
|
||||
setFeatures(Features);
|
||||
}
|
||||
|
||||
|
||||
|
@ -167,9 +167,8 @@ void DockWidgetTabPrivate::createLayout()
|
||||
CloseIcon.addPixmap(normalPixmap, QIcon::Normal);
|
||||
CloseIcon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled);
|
||||
CloseButton->setIcon(CloseIcon);
|
||||
|
||||
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
CloseButton->setVisible(false);
|
||||
_this->onDockWidgetFeaturesChanged();
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
CloseButton->setToolTip(QObject::tr("Close Tab"));
|
||||
#endif
|
||||
@ -389,8 +388,10 @@ bool CDockWidgetTab::isActiveTab() const
|
||||
void CDockWidgetTab::setActiveTab(bool active)
|
||||
{
|
||||
bool DockWidgetClosable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetClosable);
|
||||
bool TabHasCloseButton = d->testConfigFlag(CDockManager::ActiveTabHasCloseButton);
|
||||
d->CloseButton->setVisible(active && DockWidgetClosable && TabHasCloseButton);
|
||||
bool ActiveTabHasCloseButton = d->testConfigFlag(CDockManager::ActiveTabHasCloseButton);
|
||||
bool AllTabsHaveCloseButton = d->testConfigFlag(CDockManager::AllTabsHaveCloseButton);
|
||||
bool TabHasCloseButton = (ActiveTabHasCloseButton && active) | AllTabsHaveCloseButton;
|
||||
d->CloseButton->setVisible(DockWidgetClosable && TabHasCloseButton);
|
||||
if (d->IsActiveTab == active)
|
||||
{
|
||||
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
|
||||
|
@ -53,6 +53,8 @@ class ADS_EXPORT CDockWidgetTab : public QFrame
|
||||
private:
|
||||
DockWidgetTabPrivate* d; ///< private data (pimpl)
|
||||
friend struct DockWidgetTabPrivate;
|
||||
friend class CDockWidget;
|
||||
void onDockWidgetFeaturesChanged();
|
||||
|
||||
private slots:
|
||||
void onDetachActionTriggered();
|
||||
@ -125,7 +127,6 @@ public:
|
||||
*/
|
||||
QString text() const;
|
||||
|
||||
|
||||
/**
|
||||
* Sets the tab text
|
||||
*/
|
||||
@ -136,15 +137,14 @@ public:
|
||||
*/
|
||||
bool isClosable() const;
|
||||
|
||||
|
||||
/**
|
||||
* Track event ToolTipChange and set child ToolTip
|
||||
*/
|
||||
virtual bool event(QEvent *e) override;
|
||||
|
||||
public slots:
|
||||
virtual void setVisible(bool visible) override;
|
||||
|
||||
public slots:
|
||||
virtual void setVisible(bool visible) override;
|
||||
|
||||
signals:
|
||||
void activeTabChanged();
|
||||
|
@ -162,6 +162,27 @@ T findParent(const QWidget* w)
|
||||
*/
|
||||
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 ads
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user