mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-11-15 21:25:44 +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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index < 0 || index > (d->TabsLayout->count() - 1))
|
if (index < 0 || index > (count() - 1))
|
||||||
{
|
{
|
||||||
qWarning() << Q_FUNC_INFO << "Invalid index" << index;
|
qWarning() << Q_FUNC_INFO << "Invalid index" << index;
|
||||||
return;
|
return;
|
||||||
@ -214,7 +214,7 @@ void CDockAreaTabBar::setCurrentIndex(int index)
|
|||||||
emit currentChanging(index);
|
emit currentChanging(index);
|
||||||
|
|
||||||
// Set active TAB and update all other tabs to be inactive
|
// 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);
|
QLayoutItem* item = d->TabsLayout->itemAt(i);
|
||||||
if (!item->widget())
|
if (!item->widget())
|
||||||
@ -248,7 +248,8 @@ void CDockAreaTabBar::setCurrentIndex(int index)
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
int CDockAreaTabBar::count() const
|
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);
|
d->TabsLayout->insertWidget(Index, Tab);
|
||||||
connect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked()));
|
connect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked()));
|
||||||
|
connect(Tab, SIGNAL(moved()), this, SLOT(onTabMoved()));
|
||||||
d->MenuOutdated = true;
|
d->MenuOutdated = true;
|
||||||
if (Index <= d->CurrentIndex)
|
if (Index <= d->CurrentIndex)
|
||||||
{
|
{
|
||||||
@ -271,6 +273,7 @@ void CDockAreaTabBar::removeTab(CDockWidgetTab* Tab)
|
|||||||
std::cout << "CDockAreaTabBar::removeTab " << std::endl;
|
std::cout << "CDockAreaTabBar::removeTab " << std::endl;
|
||||||
d->TabsLayout->removeWidget(Tab);
|
d->TabsLayout->removeWidget(Tab);
|
||||||
disconnect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked()));
|
disconnect(Tab, SIGNAL(clicked()), this, SLOT(onTabClicked()));
|
||||||
|
disconnect(Tab, SIGNAL(moved()), this, SLOT(onTabMoved()));
|
||||||
d->MenuOutdated = true;
|
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)
|
void CDockAreaTabBar::closeTab(int Index)
|
||||||
{
|
{
|
||||||
if (Index < 0 || Index >= d->TabsLayout->count())
|
if (Index < 0 || Index >= count())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ private:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onTabClicked();
|
void onTabClicked();
|
||||||
|
void onTabMoved();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void wheelEvent(QWheelEvent* Event) override;
|
virtual void wheelEvent(QWheelEvent* Event) override;
|
||||||
|
@ -244,7 +244,7 @@ void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev)
|
|||||||
if (d->isDraggingState(DraggingTab) && d->DockArea)
|
if (d->isDraggingState(DraggingTab) && d->DockArea)
|
||||||
{
|
{
|
||||||
// Find tab under mouse
|
// 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 fromIndex = d->DockArea->index(d->DockWidget);
|
||||||
int toIndex = d->DockArea->indexOfContentByTitlePos(pos, this);
|
int toIndex = d->DockArea->indexOfContentByTitlePos(pos, this);
|
||||||
if (-1 == toIndex)
|
if (-1 == toIndex)
|
||||||
@ -252,7 +252,8 @@ void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev)
|
|||||||
toIndex = d->DockArea->dockWidgetsCount() - 1;
|
toIndex = d->DockArea->dockWidgetsCount() - 1;
|
||||||
}
|
}
|
||||||
qDebug() << "Move tab from " << fromIndex << " to " << toIndex;
|
qDebug() << "Move tab from " << fromIndex << " to " << toIndex;
|
||||||
d->DockArea->reorderDockWidget(fromIndex, toIndex);
|
d->DockArea->reorderDockWidget(fromIndex, toIndex);*/
|
||||||
|
emit moved();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!d->DragStartMousePosition.isNull())
|
if (!d->DragStartMousePosition.isNull())
|
||||||
|
@ -122,6 +122,7 @@ public slots:
|
|||||||
signals:
|
signals:
|
||||||
void activeTabChanged();
|
void activeTabChanged();
|
||||||
void clicked();
|
void clicked();
|
||||||
|
void moved();
|
||||||
}; // class DockWidgetTab
|
}; // class DockWidgetTab
|
||||||
}
|
}
|
||||||
// namespace ads
|
// namespace ads
|
||||||
|
Loading…
Reference in New Issue
Block a user