mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-11-15 13:15:43 +08:00
Fixed DockAreaTabBar.cpp to properly count the contained tabs (ignore stretch item)
This commit is contained in:
parent
548dfb363a
commit
7c67d71f68
@ -205,7 +205,7 @@ void CDockAreaTabBar::setCurrentIndex(int index)
|
||||
return;
|
||||
}
|
||||
|
||||
if (index < 0 || index > (d->TabsLayout->count() - 1))
|
||||
if (index < 0 || index > (count() - 1))
|
||||
{
|
||||
qWarning() << Q_FUNC_INFO << "Invalid index" << index;
|
||||
return;
|
||||
@ -214,7 +214,7 @@ void CDockAreaTabBar::setCurrentIndex(int index)
|
||||
emit currentChanging(index);
|
||||
|
||||
// Set active TAB and update all other tabs to be inactive
|
||||
for (int i = 0; i < d->TabsLayout->count(); ++i)
|
||||
for (int i = 0; i < count(); ++i)
|
||||
{
|
||||
QLayoutItem* item = d->TabsLayout->itemAt(i);
|
||||
if (!item->widget())
|
||||
@ -248,7 +248,8 @@ void CDockAreaTabBar::setCurrentIndex(int index)
|
||||
//============================================================================
|
||||
int CDockAreaTabBar::count() const
|
||||
{
|
||||
return d->TabsLayout->count();
|
||||
// The tab bar contains a stretch item as last item
|
||||
return d->TabsLayout->count() - 1;
|
||||
}
|
||||
|
||||
|
||||
@ -257,6 +258,7 @@ void CDockAreaTabBar::insertTab(int Index, CDockWidgetTab* Tab)
|
||||
{
|
||||
d->TabsLayout->insertWidget(Index, Tab);
|
||||
connect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked()));
|
||||
connect(Tab, SIGNAL(moved()), this, SLOT(onTabMoved()));
|
||||
d->MenuOutdated = true;
|
||||
if (Index <= d->CurrentIndex)
|
||||
{
|
||||
@ -271,6 +273,7 @@ void CDockAreaTabBar::removeTab(CDockWidgetTab* Tab)
|
||||
std::cout << "CDockAreaTabBar::removeTab " << std::endl;
|
||||
d->TabsLayout->removeWidget(Tab);
|
||||
disconnect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked()));
|
||||
disconnect(Tab, SIGNAL(moved()), this, SLOT(onTabMoved()));
|
||||
d->MenuOutdated = true;
|
||||
}
|
||||
|
||||
@ -309,10 +312,59 @@ void CDockAreaTabBar::onTabClicked()
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
void CDockAreaTabBar::onTabMoved()
|
||||
{
|
||||
CDockWidgetTab* Tab = qobject_cast<CDockWidgetTab*>(sender());
|
||||
if (!Tab)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Find tab under mouse
|
||||
int fromIndex = d->TabsLayout->indexOf(Tab);
|
||||
std::cout << "d->TabsLayout->count() " << count() << std::endl;
|
||||
for (int i = 0; i < count(); ++i)
|
||||
{
|
||||
CDockWidgetTab* Tab2 = qobject_cast<CDockWidgetTab*>(d->TabsLayout->itemAt(i)->widget());
|
||||
if (Tab2 == Tab || !Tab)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
std::cout << "Tab.left " << Tab->pos().x() << " Tab2.left " << Tab2->pos().x()
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* for (int i = 0; i < d->ContentsLayout->count(); ++i)
|
||||
{
|
||||
auto TabWidget = d->tabWidgetAt(i);
|
||||
if (TabWidget->isVisible() && TabWidget->geometry().contains(p) && (!exclude || TabWidget != exclude))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
std::cout << "CDockAreaTabBar::onTabMoved from " << fromIndex << std::endl;
|
||||
|
||||
/*QPoint pos = d->DockArea->mapFromGlobal(ev->globalPos());
|
||||
int fromIndex = d->DockArea->index(d->DockWidget);
|
||||
int toIndex = d->DockArea->indexOfContentByTitlePos(pos, this);
|
||||
if (-1 == toIndex)
|
||||
{
|
||||
toIndex = d->DockArea->dockWidgetsCount() - 1;
|
||||
}
|
||||
qDebug() << "Move tab from " << fromIndex << " to " << toIndex;
|
||||
d->DockArea->reorderDockWidget(fromIndex, toIndex);*/
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
void CDockAreaTabBar::closeTab(int Index)
|
||||
{
|
||||
if (Index < 0 || Index >= d->TabsLayout->count())
|
||||
if (Index < 0 || Index >= count())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ private:
|
||||
|
||||
private slots:
|
||||
void onTabClicked();
|
||||
void onTabMoved();
|
||||
|
||||
protected:
|
||||
virtual void wheelEvent(QWheelEvent* Event) override;
|
||||
|
@ -244,7 +244,7 @@ void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev)
|
||||
if (d->isDraggingState(DraggingTab) && d->DockArea)
|
||||
{
|
||||
// Find tab under mouse
|
||||
QPoint pos = d->DockArea->mapFromGlobal(ev->globalPos());
|
||||
/*QPoint pos = d->DockArea->mapFromGlobal(ev->globalPos());
|
||||
int fromIndex = d->DockArea->index(d->DockWidget);
|
||||
int toIndex = d->DockArea->indexOfContentByTitlePos(pos, this);
|
||||
if (-1 == toIndex)
|
||||
@ -252,7 +252,8 @@ void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev)
|
||||
toIndex = d->DockArea->dockWidgetsCount() - 1;
|
||||
}
|
||||
qDebug() << "Move tab from " << fromIndex << " to " << toIndex;
|
||||
d->DockArea->reorderDockWidget(fromIndex, toIndex);
|
||||
d->DockArea->reorderDockWidget(fromIndex, toIndex);*/
|
||||
emit moved();
|
||||
}
|
||||
|
||||
if (!d->DragStartMousePosition.isNull())
|
||||
|
@ -122,6 +122,7 @@ public slots:
|
||||
signals:
|
||||
void activeTabChanged();
|
||||
void clicked();
|
||||
void moved();
|
||||
}; // class DockWidgetTab
|
||||
}
|
||||
// namespace ads
|
||||
|
Loading…
Reference in New Issue
Block a user