Skip to content

Commit

Permalink
Fixed #653 - DisablingTabTextEliding not letting DockAreaDynamicTabsM…
Browse files Browse the repository at this point in the history
…enuButtonVisibility to function and program crashes
  • Loading branch information
githubuser0xFFFF committed Jul 8, 2024
1 parent 1c41cbf commit cea1327
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/DockAreaTabBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,13 @@ int CDockAreaTabBar::tabInsertIndexAt(const QPoint& Pos) const
}
}


//===========================================================================
bool CDockAreaTabBar::areTabsOverflowing() const
{
return d->TabsContainerWidget->width() > width();
}

} // namespace ads


Expand Down
6 changes: 6 additions & 0 deletions src/DockAreaTabBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ private Q_SLOTS:
*/
virtual QSize sizeHint() const override;

/**
* This function returns true, if the tabs need more space than the size
* of the tab bar.
*/
bool areTabsOverflowing() const;

public Q_SLOTS:
/**
* This property sets the index of the tab bar's visible tab
Expand Down
47 changes: 34 additions & 13 deletions src/DockAreaTitleBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,27 +377,48 @@ CDockAreaTabBar* CDockAreaTitleBar::tabBar() const
return d->TabBar;
}


//============================================================================
void CDockAreaTitleBar::resizeEvent(QResizeEvent *event)
{
Super::resizeEvent(event);
if (CDockManager::testConfigFlag(CDockManager::DockAreaDynamicTabsMenuButtonVisibility)
&& CDockManager::testConfigFlag(CDockManager::DisableTabTextEliding))
{
markTabsMenuOutdated();
}
}


//============================================================================
void CDockAreaTitleBar::markTabsMenuOutdated()
{
if(DockAreaTitleBarPrivate::testConfigFlag(CDockManager::DockAreaDynamicTabsMenuButtonVisibility))
if (CDockManager::testConfigFlag(CDockManager::DockAreaDynamicTabsMenuButtonVisibility))
{
bool hasElidedTabTitle = false;
for (int i = 0; i < d->TabBar->count(); ++i)
bool TabsMenuButtonVisible = false;
if (CDockManager::testConfigFlag(CDockManager::DisableTabTextEliding))
{
if (!d->TabBar->isTabOpen(i))
{
continue;
}
CDockWidgetTab* Tab = d->TabBar->tab(i);
if(Tab->isTitleElided())
TabsMenuButtonVisible = d->TabBar->areTabsOverflowing();
}
else
{
bool hasElidedTabTitle = false;
for (int i = 0; i < d->TabBar->count(); ++i)
{
hasElidedTabTitle = true;
break;
if (!d->TabBar->isTabOpen(i))
{
continue;
}
CDockWidgetTab* Tab = d->TabBar->tab(i);
if(Tab->isTitleElided())
{
hasElidedTabTitle = true;
break;
}
}
TabsMenuButtonVisible = (hasElidedTabTitle && (d->TabBar->count() > 1));
}
bool visible = (hasElidedTabTitle && (d->TabBar->count() > 1));
QMetaObject::invokeMethod(d->TabsMenuButton, "setVisible", Qt::QueuedConnection, Q_ARG(bool, visible));
QMetaObject::invokeMethod(d->TabsMenuButton, "setVisible", Qt::QueuedConnection, Q_ARG(bool, TabsMenuButtonVisible));
}
d->MenuOutdated = true;
}
Expand Down
5 changes: 5 additions & 0 deletions src/DockAreaTitleBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ private Q_SLOTS:
*/
virtual void contextMenuEvent(QContextMenuEvent *event) override;

/**
* Handle resize events
*/
virtual void resizeEvent(QResizeEvent *event) override;

public Q_SLOTS:
/**
* Call this slot to tell the title bar that it should update the tabs menu
Expand Down

0 comments on commit cea1327

Please sign in to comment.