Skip to content

Commit 442be1c

Browse files
githubuser0xFFFFjonjenssen
authored andcommitted
Fixed issue githubuser0xFFFF#524: Sometimes sidebar visibility state is incorrect
1 parent 349c297 commit 442be1c

File tree

3 files changed

+63
-27
lines changed

3 files changed

+63
-27
lines changed

demo/MainWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
734734
CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true);
735735

736736
// uncomment if you would like to enable dock widget auto hiding
737-
CDockManager::setAutoHideConfigFlags({CDockManager::DefaultAutoHideConfig | CDockManager::AutoHideCloseButtonCollapsesDock});
737+
CDockManager::setAutoHideConfigFlags({CDockManager::DefaultAutoHideConfig});
738738

739739
// uncomment if you would like to enable an equal distribution of the
740740
// available size of a splitter to all contained dock widgets

src/AutoHideSideBar.cpp

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -127,27 +127,6 @@ void AutoHideSideBarPrivate::handleViewportEvent(QEvent* e)
127127
}
128128
break;
129129

130-
case QEvent::Resize:
131-
if (_this->tabCount())
132-
{
133-
auto ev = static_cast<QResizeEvent*>(e);
134-
auto Tab = _this->tabAt(0);
135-
int Size = isHorizontal() ? ev->size().height() : ev->size().width();
136-
int TabSize = isHorizontal() ? Tab->size().height() : Tab->size().width();
137-
// If the size of the side bar is less than the size of the first tab
138-
// then there are no visible tabs in this side bar. This check will
139-
// fail if someone will force a very big border via CSS!!
140-
if (Size < TabSize)
141-
{
142-
_this->hide();
143-
}
144-
}
145-
else
146-
{
147-
_this->hide();
148-
}
149-
break;
150-
151130
default:
152131
break;
153132
}
@@ -288,20 +267,33 @@ void CAutoHideSideBar::removeTab(CAutoHideTab* SideTab)
288267
//============================================================================
289268
bool CAutoHideSideBar::eventFilter(QObject *watched, QEvent *event)
290269
{
291-
if (event->type() != QEvent::ShowToParent)
270+
auto Tab = qobject_cast<CAutoHideTab*>(watched);
271+
if (!Tab)
292272
{
293273
return false;
294274
}
295275

296-
// As soon as on tab is shown, we need to show the side tab bar
297-
auto Tab = qobject_cast<CAutoHideTab*>(watched);
298-
if (Tab)
276+
switch (event->type())
299277
{
300-
show();
278+
case QEvent::ShowToParent:
279+
show();
280+
break;
281+
282+
case QEvent::Hide:
283+
if (!hasVisibleTabs())
284+
{
285+
hide();
286+
}
287+
break;
288+
289+
default:
290+
break;
301291
}
292+
302293
return false;
303294
}
304295

296+
305297
//============================================================================
306298
Qt::Orientation CAutoHideSideBar::orientation() const
307299
{
@@ -323,6 +315,37 @@ int CAutoHideSideBar::tabCount() const
323315
}
324316

325317

318+
//============================================================================
319+
int CAutoHideSideBar::visibleTabCount() const
320+
{
321+
int count = 0;
322+
for (auto i = 0; i < tabCount(); i++)
323+
{
324+
if (tabAt(i)->isVisible())
325+
{
326+
count++;
327+
}
328+
}
329+
330+
return count;
331+
}
332+
333+
334+
//============================================================================
335+
bool CAutoHideSideBar::hasVisibleTabs() const
336+
{
337+
for (auto i = 0; i < tabCount(); i++)
338+
{
339+
if (tabAt(i)->isVisible())
340+
{
341+
return true;
342+
}
343+
}
344+
345+
return false;
346+
}
347+
348+
326349
//============================================================================
327350
SideBarLocation CAutoHideSideBar::sideBarLocation() const
328351
{

src/AutoHideSideBar.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ class ADS_EXPORT CAutoHideSideBar : public QScrollArea
134134
*/
135135
int tabCount() const;
136136

137+
/**
138+
* Returns the number of visible tabs
139+
*/
140+
int visibleTabCount() const;
141+
142+
/**
143+
* Returns true, if the sidebar contains visible tabs.
144+
* The function returns as soon as it finds the first visible tab.
145+
* That means, if you just want to find out if theee are visible tabs
146+
* then this function is quicker than visibleTabCount()
147+
*/
148+
bool hasVisibleTabs() const;
149+
137150
/**
138151
* Getter for side tab bar area property
139152
*/

0 commit comments

Comments
 (0)