Added KDDockWidgets::InitialVisibilityOption::PreserveCurrentTab
So you can insert into a tab group without changing the current
tab, if you want.
(cherry-picked from commit 58b8633e3d)
This commit is contained in:
@@ -128,7 +128,8 @@ Q_ENUM_NS(AddingOption)
|
||||
enum class InitialVisibilityOption
|
||||
{
|
||||
StartVisible = 0, ///< The dock widget is made visible when docked
|
||||
StartHidden ///< Don't show the dock widget when adding it
|
||||
StartHidden, ///< Don't show the dock widget when adding it
|
||||
PreserveCurrentTab ///< When adding as tabbed, don't change the current index
|
||||
};
|
||||
Q_ENUM_NS(InitialVisibilityOption)
|
||||
|
||||
@@ -176,6 +177,11 @@ struct InitialOption
|
||||
return visibility == InitialVisibilityOption::StartHidden;
|
||||
}
|
||||
|
||||
bool preservesCurrentTab() const
|
||||
{
|
||||
return visibility == InitialVisibilityOption::PreserveCurrentTab;
|
||||
}
|
||||
|
||||
int preferredLength(Qt::Orientation o) const
|
||||
{
|
||||
return o == Qt::Horizontal ? preferredSize.width()
|
||||
|
||||
@@ -336,6 +336,14 @@ int DockWidget::tabIndex() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DockWidget::currentTabIndex() const
|
||||
{
|
||||
if (Frame *frame = d->frame())
|
||||
return frame->currentTabIndex();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DockWidget::setIcon(const QIcon &icon, IconPlaces places)
|
||||
{
|
||||
if (places & IconPlace::TitleBar)
|
||||
|
||||
@@ -229,10 +229,17 @@ public:
|
||||
void setAsCurrentTab();
|
||||
|
||||
/**
|
||||
* @brief Returns which tab index this dock widget occupies in the tab widget it's contained in
|
||||
* @brief Returns the tab index this dock widget occupies
|
||||
* Note that dock widgets are almost always tabbed, even if you don't see the tab bar.
|
||||
* A single floating dock widget is still tabbed on a tab widget with a single tab.
|
||||
*/
|
||||
int tabIndex() const;
|
||||
|
||||
/**
|
||||
* @brief Returns the index of the current tab of the tab group this dock widget is in.
|
||||
*/
|
||||
int currentTabIndex() const;
|
||||
|
||||
/**
|
||||
* @brief Sets an icon to show on title bars and tab bars.
|
||||
* @param places Specifies where the icon will be shown (TitleBar, TabBar, ToggleAction, or All)
|
||||
|
||||
@@ -292,6 +292,7 @@ void Frame::insertWidget(DockWidget *dockWidget, int index, InitialOption adding
|
||||
if (m_layoutItem)
|
||||
dockWidget->d->addPlaceholderItem(m_layoutItem);
|
||||
|
||||
const int originalCurrentIndex = currentIndex();
|
||||
insertDockWidget(dockWidget, index);
|
||||
|
||||
if (addingOption.startsHidden()) {
|
||||
@@ -307,6 +308,8 @@ void Frame::insertWidget(DockWidget *dockWidget, int index, InitialOption adding
|
||||
// use that size as the initial suggested size.
|
||||
view()->resize(dockWidget->size());
|
||||
}
|
||||
} else if (addingOption.preservesCurrentTab() && originalCurrentIndex != -1) {
|
||||
setCurrentTabIndex(originalCurrentIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user