Fixed some bugs in tabbar handling

This commit is contained in:
Uwe Kindler 2018-10-12 11:51:35 +02:00
parent ceebda7431
commit 9c95e34df5
4 changed files with 32 additions and 2 deletions

View File

@ -265,6 +265,7 @@ void CDockAreaTabBar::insertTab(int Index, CDockWidgetTab* Tab)
d->TabsLayout->insertWidget(Index, Tab); d->TabsLayout->insertWidget(Index, Tab);
connect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked())); connect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked()));
connect(Tab, SIGNAL(moved(const QPoint&)), this, SLOT(onTabWidgetMoved(const QPoint&))); connect(Tab, SIGNAL(moved(const QPoint&)), this, SLOT(onTabWidgetMoved(const QPoint&)));
Tab->installEventFilter(this);
d->MenuOutdated = true; d->MenuOutdated = true;
if (Index <= d->CurrentIndex) if (Index <= d->CurrentIndex)
{ {
@ -321,6 +322,7 @@ void CDockAreaTabBar::removeTab(CDockWidgetTab* Tab)
d->TabsLayout->removeWidget(Tab); d->TabsLayout->removeWidget(Tab);
Tab->disconnect(this); Tab->disconnect(this);
Tab->removeEventFilter(this);
d->MenuOutdated = true; d->MenuOutdated = true;
qDebug() << "NewCurrentIndex " << NewCurrentIndex; qDebug() << "NewCurrentIndex " << NewCurrentIndex;
if (NewCurrentIndex != d->CurrentIndex) if (NewCurrentIndex != d->CurrentIndex)
@ -448,6 +450,26 @@ void CDockAreaTabBar::closeTab(int Index)
} }
emit tabCloseRequested(Index); emit tabCloseRequested(Index);
} }
//===========================================================================
bool CDockAreaTabBar::eventFilter(QObject *watched, QEvent *event)
{
bool Result = Super::eventFilter(watched, event);
if (event->type() != QEvent::Hide)
{
return Result;
}
CDockWidgetTab* Tab = qobject_cast<CDockWidgetTab*>(watched);
if (!Tab)
{
return Result;
}
qDebug() << "Hide event for tab " << Tab->text();
return Result;
}
} // namespace ads } // namespace ads
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -63,6 +63,7 @@ protected:
void startFloating(const QPoint& Pos); void startFloating(const QPoint& Pos);
public: public:
using Super = QScrollArea;
/** /**
* Default Constructor * Default Constructor
*/ */
@ -105,6 +106,11 @@ public:
*/ */
CDockWidgetTab* tab(int Index) const; CDockWidgetTab* tab(int Index) const;
/**
* Filters the tab widget events
*/
virtual bool eventFilter(QObject *watched, QEvent *event) override;
public slots: public slots:
/** /**
* This property sets the index of the tab bar's visible tab * This property sets the index of the tab bar's visible tab

View File

@ -187,9 +187,10 @@ public:
{ {
LayoutItem->widget()->setParent(0); LayoutItem->widget()->setParent(0);
} }
m_CurrentWidget = nullptr;
m_CurrentIndex = -1;
} }
m_Widgets.removeOne(Widget); m_Widgets.removeOne(Widget);
//setCurrentIndex(0);
} }
QWidget* currentWidget() const QWidget* currentWidget() const
@ -379,7 +380,7 @@ void DockAreaWidgetPrivate::createTabBar()
TabBar = new CDockAreaTabBar(_this); TabBar = new CDockAreaTabBar(_this);
TopLayout->addWidget(TabBar, 1); TopLayout->addWidget(TabBar, 1);
_this->connect(TabBar, SIGNAL(tabBarClicked(int)), SLOT(setCurrentIndex(int))); _this->connect(TabBar, SIGNAL(currentChanged(int)), SLOT(setCurrentIndex(int)));
_this->connect(TabBar, SIGNAL(tabMoved(int, int)), SLOT(reorderDockWidget(int, int))); _this->connect(TabBar, SIGNAL(tabMoved(int, int)), SLOT(reorderDockWidget(int, int)));
TabsMenuButton = new QPushButton(); TabsMenuButton = new QPushButton();

View File

@ -132,6 +132,7 @@ void DockWidgetPrivate::showDockWidget()
{ {
DockArea->show(); DockArea->show();
DockArea->setCurrentDockWidget(_this); DockArea->setCurrentDockWidget(_this);
TabWidget->show();
QSplitter* Splitter = internal::findParent<QSplitter*>(_this); QSplitter* Splitter = internal::findParent<QSplitter*>(_this);
while (Splitter && !Splitter->isVisible()) while (Splitter && !Splitter->isVisible())
{ {