mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-11-15 13:15:43 +08:00
Disable tabs menu button when only single tab exists in a Dock area (#111)
This commit is contained in:
parent
72496ebd48
commit
474dd13855
@ -283,7 +283,6 @@ struct MainWindowPrivate
|
||||
void restorePerspectives();
|
||||
};
|
||||
|
||||
|
||||
//============================================================================
|
||||
void MainWindowPrivate::createContent()
|
||||
{
|
||||
@ -453,6 +452,9 @@ CMainWindow::CMainWindow(QWidget *parent) :
|
||||
// uncomment the following line if you don't want disabled buttons to appear on DockArea's title bar
|
||||
//CDockManager::setConfigFlag(CDockManager::DockAreaHideDisabledButtons, true);
|
||||
|
||||
// uncomment the following line if you want to show tabs menu button on DockArea's title bar only when there are more than one tab and at least of them has elided title
|
||||
//CDockManager::setConfigFlag(CDockManager::DockAreaDynamicTabsMenuButtonVisibility, true);
|
||||
|
||||
// Now create the dock manager and its content
|
||||
d->DockManager = new CDockManager(this);
|
||||
|
||||
|
@ -343,6 +343,7 @@ void CDockAreaTabBar::insertTab(int Index, CDockWidgetTab* Tab)
|
||||
connect(Tab, SIGNAL(closeRequested()), this, SLOT(onTabCloseRequested()));
|
||||
connect(Tab, SIGNAL(closeOtherTabsRequested()), this, SLOT(onCloseOtherTabsRequested()));
|
||||
connect(Tab, SIGNAL(moved(const QPoint&)), this, SLOT(onTabWidgetMoved(const QPoint&)));
|
||||
connect(Tab, SIGNAL(elidedChanged(bool)), this, SIGNAL(elidedChanged(bool)));
|
||||
Tab->installEventFilter(this);
|
||||
emit tabInserted(Index);
|
||||
if (Index <= d->CurrentIndex || d->CurrentIndex == -1)
|
||||
@ -562,7 +563,6 @@ void CDockAreaTabBar::onTabWidgetMoved(const QPoint& GlobalPos)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
void CDockAreaTabBar::closeTab(int Index)
|
||||
{
|
||||
|
@ -239,6 +239,11 @@ signals:
|
||||
* This signal is emitted if a tab has been inserted
|
||||
*/
|
||||
void tabInserted(int index);
|
||||
|
||||
/**
|
||||
* This signal is emitted when a tab title elide state has been changed
|
||||
*/
|
||||
void elidedChanged(bool elided);
|
||||
}; // class CDockAreaTabBar
|
||||
} // namespace ads
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -151,10 +151,11 @@ protected:
|
||||
if(QEvent::EnabledChange == ev->type() && HideWhenDisabled)
|
||||
{
|
||||
// force setVisible() call
|
||||
setVisible(isEnabled());
|
||||
// Calling setVisible() directly here doesn't work well when button is expected to be shown first time
|
||||
QMetaObject::invokeMethod(this, "setVisible", Qt::QueuedConnection, Q_ARG(bool, isEnabled()));
|
||||
}
|
||||
|
||||
return Super::event(ev);;
|
||||
return Super::event(ev);
|
||||
}
|
||||
};
|
||||
|
||||
@ -232,6 +233,7 @@ void DockAreaTitleBarPrivate::createTabBar()
|
||||
_this->connect(TabBar, SIGNAL(tabMoved(int, int)), SLOT(markTabsMenuOutdated()));
|
||||
_this->connect(TabBar, SIGNAL(currentChanged(int)), SLOT(onCurrentTabChanged(int)));
|
||||
_this->connect(TabBar, SIGNAL(tabBarClicked(int)), SIGNAL(tabBarClicked(int)));
|
||||
_this->connect(TabBar, SIGNAL(elidedChanged(bool)), SLOT(markTabsMenuOutdated()));
|
||||
|
||||
TabBar->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
_this->connect(TabBar, SIGNAL(customContextMenuRequested(const QPoint&)),
|
||||
@ -286,14 +288,31 @@ CDockAreaTabBar* CDockAreaTitleBar::tabBar() const
|
||||
return d->TabBar;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTitleBar::markTabsMenuOutdated()
|
||||
{
|
||||
if(DockAreaTitleBarPrivate::testConfigFlag(CDockManager::DockAreaDynamicTabsMenuButtonVisibility))
|
||||
{
|
||||
bool hasElidedTabTitle = false;
|
||||
for (int i = 0; i < d->TabBar->count(); ++i)
|
||||
{
|
||||
if (!d->TabBar->isTabOpen(i))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
CDockWidgetTab* Tab = d->TabBar->tab(i);
|
||||
if(Tab->isTitleElided())
|
||||
{
|
||||
hasElidedTabTitle = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
bool visible = (hasElidedTabTitle && (d->TabBar->count() > 1));
|
||||
QMetaObject::invokeMethod(d->TabsMenuButton, "setVisible", Qt::QueuedConnection, Q_ARG(bool, visible));
|
||||
}
|
||||
d->MenuOutdated = true;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTitleBar::onTabsMenuAboutToShow()
|
||||
{
|
||||
|
@ -145,7 +145,7 @@ public:
|
||||
{
|
||||
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
|
||||
DockAreaCloseButtonClosesTab = 0x0004,//!< If the flag is set, the dock area close button closes the active tab, if not set, it closes the complete dock 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
|
||||
@ -160,6 +160,7 @@ public:
|
||||
DockAreaHasUndockButton = 0x4000, //!< If the flag is set each dock area has an undock button
|
||||
DockAreaHasTabsMenuButton = 0x8000, //!< If the flag is set each dock area has a tabs menu button
|
||||
DockAreaHideDisabledButtons = 0x10000, //!< If the flag is set disabled dock area buttons will not appear on the tollbar at all (enabling them will bring them back)
|
||||
DockAreaDynamicTabsMenuButtonVisibility = 0x20000, //!< If the flag is set dock area will disable a tabs menu button when there is only one tab in the area
|
||||
|
||||
|
||||
DefaultDockAreaButtons = DockAreaHasCloseButton
|
||||
|
@ -170,6 +170,8 @@ void DockWidgetTabPrivate::createLayout()
|
||||
TitleLabel->setText(DockWidget->windowTitle());
|
||||
TitleLabel->setObjectName("dockWidgetTabLabel");
|
||||
TitleLabel->setAlignment(Qt::AlignCenter);
|
||||
_this->connect(TitleLabel, SIGNAL(elidedChanged(bool)), SIGNAL(elidedChanged(bool)));
|
||||
|
||||
|
||||
CloseButton = createCloseButton();
|
||||
CloseButton->setObjectName("tabCloseButton");
|
||||
@ -556,6 +558,11 @@ void CDockWidgetTab::setText(const QString& title)
|
||||
d->TitleLabel->setText(title);
|
||||
}
|
||||
|
||||
bool CDockWidgetTab::isTitleElided() const
|
||||
{
|
||||
return d->TitleLabel->isElided();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//============================================================================
|
||||
|
@ -132,6 +132,11 @@ public:
|
||||
*/
|
||||
void setText(const QString& title);
|
||||
|
||||
/**
|
||||
* Returns true if text is elided on the tab's title
|
||||
*/
|
||||
bool isTitleElided() const;
|
||||
|
||||
/**
|
||||
* This function returns true if the assigned dock widget is closable
|
||||
*/
|
||||
@ -152,6 +157,7 @@ signals:
|
||||
void closeRequested();
|
||||
void closeOtherTabsRequested();
|
||||
void moved(const QPoint& GlobalPos);
|
||||
void elidedChanged(bool elided);
|
||||
}; // class DockWidgetTab
|
||||
}
|
||||
// namespace ads
|
||||
|
@ -41,6 +41,7 @@ struct ElidingLabelPrivate
|
||||
CElidingLabel* _this;
|
||||
Qt::TextElideMode ElideMode = Qt::ElideNone;
|
||||
QString Text;
|
||||
bool IsElided = false;
|
||||
|
||||
ElidingLabelPrivate(CElidingLabel* _public) : _this(_public) {}
|
||||
|
||||
@ -69,6 +70,12 @@ void ElidingLabelPrivate::elideText(int Width)
|
||||
{
|
||||
str = Text.at(0);
|
||||
}
|
||||
bool WasElided = IsElided;
|
||||
IsElided = str != Text;
|
||||
if(IsElided != WasElided)
|
||||
{
|
||||
emit _this->elidedChanged(IsElided);
|
||||
}
|
||||
_this->QLabel::setText(str);
|
||||
}
|
||||
|
||||
@ -113,6 +120,12 @@ void CElidingLabel::setElideMode(Qt::TextElideMode mode)
|
||||
d->elideText(size().width());
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
bool CElidingLabel::isElided() const
|
||||
{
|
||||
return d->IsElided;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CElidingLabel::mouseReleaseEvent(QMouseEvent* event)
|
||||
|
@ -73,6 +73,10 @@ public:
|
||||
*/
|
||||
void setElideMode(Qt::TextElideMode mode);
|
||||
|
||||
/**
|
||||
* This function indicates whether the text on this label is currently elided
|
||||
*/
|
||||
bool isElided() const;
|
||||
|
||||
public: // reimplements QLabel ----------------------------------------------
|
||||
virtual QSize minimumSizeHint() const override;
|
||||
@ -91,6 +95,11 @@ signals:
|
||||
* This signal is emitted if the user does a double click on the label
|
||||
*/
|
||||
void doubleClicked();
|
||||
|
||||
/**
|
||||
* This signal is emitted when isElided() state of this label is changed
|
||||
*/
|
||||
void elidedChanged(bool elided);
|
||||
}; //class CElidingLabel
|
||||
|
||||
} // namespace QtLabb
|
||||
|
Loading…
Reference in New Issue
Block a user