mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-04-01 02:42:39 +08:00
Added functions to insert custom dock area title bar widgets
This commit is contained in:
parent
d10d59a8e2
commit
efb9b879dd
@ -170,6 +170,7 @@ void CDockAreaTabBar::setCurrentIndex(int index)
|
|||||||
emit currentChanging(index);
|
emit currentChanging(index);
|
||||||
d->CurrentIndex = index;
|
d->CurrentIndex = index;
|
||||||
d->updateTabs();
|
d->updateTabs();
|
||||||
|
updateGeometry();
|
||||||
emit currentChanged(index);
|
emit currentChanged(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ struct DockAreaTitleBarPrivate
|
|||||||
QPointer<tTitleBarButton> TabsMenuButton;
|
QPointer<tTitleBarButton> TabsMenuButton;
|
||||||
QPointer<tTitleBarButton> UndockButton;
|
QPointer<tTitleBarButton> UndockButton;
|
||||||
QPointer<tTitleBarButton> CloseButton;
|
QPointer<tTitleBarButton> CloseButton;
|
||||||
QBoxLayout* TopLayout;
|
QBoxLayout* Layout;
|
||||||
CDockAreaWidget* DockArea;
|
CDockAreaWidget* DockArea;
|
||||||
CDockAreaTabBar* TabBar;
|
CDockAreaTabBar* TabBar;
|
||||||
bool MenuOutdated = true;
|
bool MenuOutdated = true;
|
||||||
@ -212,7 +212,7 @@ void DockAreaTitleBarPrivate::createButtons()
|
|||||||
TabsMenuButton->setMenu(TabsMenu);
|
TabsMenuButton->setMenu(TabsMenu);
|
||||||
internal::setToolTip(TabsMenuButton, QObject::tr("List all tabs"));
|
internal::setToolTip(TabsMenuButton, QObject::tr("List all tabs"));
|
||||||
TabsMenuButton->setSizePolicy(ButtonSizePolicy);
|
TabsMenuButton->setSizePolicy(ButtonSizePolicy);
|
||||||
TopLayout->addWidget(TabsMenuButton, 0);
|
Layout->addWidget(TabsMenuButton, 0);
|
||||||
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
|
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
|
||||||
SLOT(onTabsMenuActionTriggered(QAction*)));
|
SLOT(onTabsMenuActionTriggered(QAction*)));
|
||||||
|
|
||||||
@ -223,7 +223,7 @@ void DockAreaTitleBarPrivate::createButtons()
|
|||||||
internal::setToolTip(UndockButton, QObject::tr("Detach Group"));
|
internal::setToolTip(UndockButton, QObject::tr("Detach Group"));
|
||||||
internal::setButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon);
|
internal::setButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon);
|
||||||
UndockButton->setSizePolicy(ButtonSizePolicy);
|
UndockButton->setSizePolicy(ButtonSizePolicy);
|
||||||
TopLayout->addWidget(UndockButton, 0);
|
Layout->addWidget(UndockButton, 0);
|
||||||
_this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked()));
|
_this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked()));
|
||||||
|
|
||||||
// Close button
|
// Close button
|
||||||
@ -241,7 +241,7 @@ void DockAreaTitleBarPrivate::createButtons()
|
|||||||
}
|
}
|
||||||
CloseButton->setSizePolicy(ButtonSizePolicy);
|
CloseButton->setSizePolicy(ButtonSizePolicy);
|
||||||
CloseButton->setIconSize(QSize(16, 16));
|
CloseButton->setIconSize(QSize(16, 16));
|
||||||
TopLayout->addWidget(CloseButton, 0);
|
Layout->addWidget(CloseButton, 0);
|
||||||
_this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked()));
|
_this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +250,8 @@ void DockAreaTitleBarPrivate::createButtons()
|
|||||||
void DockAreaTitleBarPrivate::createTabBar()
|
void DockAreaTitleBarPrivate::createTabBar()
|
||||||
{
|
{
|
||||||
TabBar = new CDockAreaTabBar(DockArea);
|
TabBar = new CDockAreaTabBar(DockArea);
|
||||||
TopLayout->addWidget(TabBar);
|
TabBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
||||||
|
Layout->addWidget(TabBar);
|
||||||
_this->connect(TabBar, SIGNAL(tabClosed(int)), SLOT(markTabsMenuOutdated()));
|
_this->connect(TabBar, SIGNAL(tabClosed(int)), SLOT(markTabsMenuOutdated()));
|
||||||
_this->connect(TabBar, SIGNAL(tabOpened(int)), SLOT(markTabsMenuOutdated()));
|
_this->connect(TabBar, SIGNAL(tabOpened(int)), SLOT(markTabsMenuOutdated()));
|
||||||
_this->connect(TabBar, SIGNAL(tabInserted(int)), SLOT(markTabsMenuOutdated()));
|
_this->connect(TabBar, SIGNAL(tabInserted(int)), SLOT(markTabsMenuOutdated()));
|
||||||
@ -314,18 +315,16 @@ CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) :
|
|||||||
d->DockArea = parent;
|
d->DockArea = parent;
|
||||||
|
|
||||||
setObjectName("dockAreaTitleBar");
|
setObjectName("dockAreaTitleBar");
|
||||||
d->TopLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
d->Layout = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||||
d->TopLayout->setContentsMargins(0, 0, 0, 0);
|
d->Layout->setContentsMargins(0, 0, 0, 0);
|
||||||
d->TopLayout->setSpacing(0);
|
d->Layout->setSpacing(0);
|
||||||
setLayout(d->TopLayout);
|
setLayout(d->Layout);
|
||||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||||
|
|
||||||
d->createTabBar();
|
d->createTabBar();
|
||||||
d->TabBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
|
||||||
auto horizontalSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
auto horizontalSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||||
d->TopLayout->addSpacerItem(horizontalSpacer);
|
d->Layout->addSpacerItem(horizontalSpacer);
|
||||||
d->createButtons();
|
d->createButtons();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -449,7 +448,7 @@ void CDockAreaTitleBar::updateDockWidgetActionsButtons()
|
|||||||
{
|
{
|
||||||
for (auto Button : d->DockWidgetActionsButtons)
|
for (auto Button : d->DockWidgetActionsButtons)
|
||||||
{
|
{
|
||||||
d->TopLayout->removeWidget(Button);
|
d->Layout->removeWidget(Button);
|
||||||
delete Button;
|
delete Button;
|
||||||
}
|
}
|
||||||
d->DockWidgetActionsButtons.clear();
|
d->DockWidgetActionsButtons.clear();
|
||||||
@ -469,7 +468,7 @@ void CDockAreaTitleBar::updateDockWidgetActionsButtons()
|
|||||||
Button->setAutoRaise(true);
|
Button->setAutoRaise(true);
|
||||||
Button->setPopupMode(QToolButton::InstantPopup);
|
Button->setPopupMode(QToolButton::InstantPopup);
|
||||||
Button->setObjectName(Action->objectName());
|
Button->setObjectName(Action->objectName());
|
||||||
d->TopLayout->insertWidget(InsertIndex++, Button, 0);
|
d->Layout->insertWidget(InsertIndex++, Button, 0);
|
||||||
d->DockWidgetActionsButtons.append(Button);
|
d->DockWidgetActionsButtons.append(Button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -634,6 +633,20 @@ void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
void CDockAreaTitleBar::insertWidget(int index, QWidget *widget)
|
||||||
|
{
|
||||||
|
d->Layout->insertWidget(index, widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
int CDockAreaTitleBar::indexOf(QWidget *widget) const
|
||||||
|
{
|
||||||
|
return d->Layout->indexOf(widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace ads
|
} // namespace ads
|
||||||
|
|
||||||
#include "DockAreaTitleBar.moc"
|
#include "DockAreaTitleBar.moc"
|
||||||
|
@ -98,6 +98,7 @@ public slots:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
using Super = QFrame;
|
using Super = QFrame;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
*/
|
*/
|
||||||
@ -129,6 +130,23 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void setVisible(bool Visible) override;
|
virtual void setVisible(bool Visible) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts a custom widget at position index into this title bar.
|
||||||
|
* If index is negative, the widget is added at the end.
|
||||||
|
* You can use this function to insert custom widgets into the title bar.
|
||||||
|
*/
|
||||||
|
void insertWidget(int index, QWidget *widget);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches for widget widget in this title bar.
|
||||||
|
* You can use this function, to get the position of the default
|
||||||
|
* widget in the tile bar.
|
||||||
|
* \code
|
||||||
|
* int tabBarIndex = TitleBar->indexOf(TitleBar->tabBar());
|
||||||
|
* int closeButtonIndex = TitleBar->indexOf(TitleBar->button(TitleBarButtonClose));
|
||||||
|
* \endcode
|
||||||
|
*/
|
||||||
|
int indexOf(QWidget *widget) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
|
@ -92,8 +92,3 @@ QScrollArea#dockWidgetScrollArea
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ads--CDockAreaTitleBar
|
|
||||||
{
|
|
||||||
background: red;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user