mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-01-24 13:32:06 +08:00
ToolTip from titlebar and menu
This commit is contained in:
parent
1ad6caeb8a
commit
6cb1f33451
@ -119,9 +119,14 @@ void DockAreaTitleBarPrivate::createButtons()
|
|||||||
TabsMenuButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarUnshadeButton));
|
TabsMenuButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarUnshadeButton));
|
||||||
|
|
||||||
QMenu* TabsMenu = new QMenu(TabsMenuButton);
|
QMenu* TabsMenu = new QMenu(TabsMenuButton);
|
||||||
|
#ifndef QT_NO_TOOLTIP
|
||||||
|
TabsMenu->setToolTipsVisible(true);
|
||||||
|
#endif
|
||||||
_this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow()));
|
_this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow()));
|
||||||
TabsMenuButton->setMenu(TabsMenu);
|
TabsMenuButton->setMenu(TabsMenu);
|
||||||
|
#ifndef QT_NO_TOOLTIP
|
||||||
TabsMenuButton->setToolTip(QObject::tr("List all tabs"));
|
TabsMenuButton->setToolTip(QObject::tr("List all tabs"));
|
||||||
|
#endif
|
||||||
TabsMenuButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
TabsMenuButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||||
TopLayout->addWidget(TabsMenuButton, 0);
|
TopLayout->addWidget(TabsMenuButton, 0);
|
||||||
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
|
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
|
||||||
@ -131,7 +136,9 @@ void DockAreaTitleBarPrivate::createButtons()
|
|||||||
UndockButton = new tTileBarButton();
|
UndockButton = new tTileBarButton();
|
||||||
UndockButton->setObjectName("undockButton");
|
UndockButton->setObjectName("undockButton");
|
||||||
UndockButton->setAutoRaise(true);
|
UndockButton->setAutoRaise(true);
|
||||||
|
#ifndef QT_NO_TOOLTIP
|
||||||
UndockButton->setToolTip(QObject::tr("Detach Group"));
|
UndockButton->setToolTip(QObject::tr("Detach Group"));
|
||||||
|
#endif
|
||||||
UndockButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarNormalButton));
|
UndockButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarNormalButton));
|
||||||
UndockButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
UndockButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||||
TopLayout->addWidget(UndockButton, 0);
|
TopLayout->addWidget(UndockButton, 0);
|
||||||
@ -148,6 +155,7 @@ void DockAreaTitleBarPrivate::createButtons()
|
|||||||
CloseIcon.addPixmap(disabledPixmap, QIcon::Disabled);
|
CloseIcon.addPixmap(disabledPixmap, QIcon::Disabled);
|
||||||
|
|
||||||
CloseButton->setIcon(CloseIcon);
|
CloseButton->setIcon(CloseIcon);
|
||||||
|
#ifndef QT_NO_TOOLTIP
|
||||||
if (testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
|
if (testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
|
||||||
{
|
{
|
||||||
CloseButton->setToolTip(QObject::tr("Close Active Tab"));
|
CloseButton->setToolTip(QObject::tr("Close Active Tab"));
|
||||||
@ -156,6 +164,7 @@ void DockAreaTitleBarPrivate::createButtons()
|
|||||||
{
|
{
|
||||||
CloseButton->setToolTip(QObject::tr("Close Group"));
|
CloseButton->setToolTip(QObject::tr("Close Group"));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||||
TopLayout->addWidget(CloseButton, 0);
|
TopLayout->addWidget(CloseButton, 0);
|
||||||
_this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked()));
|
_this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked()));
|
||||||
@ -240,6 +249,9 @@ void CDockAreaTitleBar::onTabsMenuAboutToShow()
|
|||||||
}
|
}
|
||||||
auto Tab = d->TabBar->tab(i);
|
auto Tab = d->TabBar->tab(i);
|
||||||
QAction* Action = menu->addAction(Tab->icon(), Tab->text());
|
QAction* Action = menu->addAction(Tab->icon(), Tab->text());
|
||||||
|
#ifndef QT_NO_TOOLTIP
|
||||||
|
Action->setToolTip(Tab->toolTip());
|
||||||
|
#endif
|
||||||
Action->setData(i);
|
Action->setData(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,6 +324,7 @@ QAbstractButton* CDockAreaTitleBar::button(TitleBarButton which) const
|
|||||||
void CDockAreaTitleBar::setVisible(bool Visible)
|
void CDockAreaTitleBar::setVisible(bool Visible)
|
||||||
{
|
{
|
||||||
Super::setVisible(Visible);
|
Super::setVisible(Visible);
|
||||||
|
markTabsMenuOutdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -236,11 +236,11 @@ using DockAreaLayout = CDockAreaLayout;
|
|||||||
*/
|
*/
|
||||||
struct DockAreaWidgetPrivate
|
struct DockAreaWidgetPrivate
|
||||||
{
|
{
|
||||||
CDockAreaWidget* _this;
|
CDockAreaWidget* _this = nullptr;
|
||||||
QBoxLayout* Layout;
|
QBoxLayout* Layout = nullptr;
|
||||||
DockAreaLayout* ContentsLayout;
|
DockAreaLayout* ContentsLayout = nullptr;
|
||||||
CDockAreaTitleBar* TitleBar;
|
CDockAreaTitleBar* TitleBar = nullptr;
|
||||||
CDockManager* DockManager = nullptr;
|
CDockManager* DockManager = nullptr;
|
||||||
bool UpdateCloseButton = false;
|
bool UpdateCloseButton = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -680,7 +680,10 @@ void CDockAreaWidget::updateTitleBarVisibility()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->TitleBar->setVisible(!Container->isFloating() || !Container->hasTopLevelDockWidget());
|
if (d->TitleBar)
|
||||||
|
{
|
||||||
|
d->TitleBar->setVisible(!Container->isFloating() || !Container->hasTopLevelDockWidget());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,8 +58,8 @@ namespace ads
|
|||||||
*/
|
*/
|
||||||
struct DockWidgetPrivate
|
struct DockWidgetPrivate
|
||||||
{
|
{
|
||||||
CDockWidget* _this;
|
CDockWidget* _this = nullptr;
|
||||||
QBoxLayout* Layout;
|
QBoxLayout* Layout = nullptr;
|
||||||
QWidget* Widget = nullptr;
|
QWidget* Widget = nullptr;
|
||||||
CDockWidgetTab* TabWidget = nullptr;
|
CDockWidgetTab* TabWidget = nullptr;
|
||||||
CDockWidget::DockWidgetFeatures Features = CDockWidget::AllDockWidgetFeatures;
|
CDockWidget::DockWidgetFeatures Features = CDockWidget::AllDockWidgetFeatures;
|
||||||
@ -516,12 +516,36 @@ bool CDockWidget::event(QEvent *e)
|
|||||||
{
|
{
|
||||||
d->ToggleViewAction->setText(title);
|
d->ToggleViewAction->setText(title);
|
||||||
}
|
}
|
||||||
|
if (d->DockArea)
|
||||||
|
{
|
||||||
|
d->DockArea->updateTitleBarVisibility();//update tabs menu
|
||||||
|
}
|
||||||
emit titleChanged(title);
|
emit titleChanged(title);
|
||||||
}
|
}
|
||||||
return QFrame::event(e);
|
return QFrame::event(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef QT_NO_TOOLTIP
|
||||||
|
//============================================================================
|
||||||
|
void CDockWidget::setTabToolTip(const QString &text)
|
||||||
|
{
|
||||||
|
if (d->TabWidget)
|
||||||
|
{
|
||||||
|
d->TabWidget->setToolTip(text);
|
||||||
|
}
|
||||||
|
if (d->ToggleViewAction)
|
||||||
|
{
|
||||||
|
d->ToggleViewAction->setToolTip(text);
|
||||||
|
}
|
||||||
|
if (d->DockArea)
|
||||||
|
{
|
||||||
|
d->DockArea->updateTitleBarVisibility();//update tabs menu
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
void CDockWidget::setIcon(const QIcon& Icon)
|
void CDockWidget::setIcon(const QIcon& Icon)
|
||||||
{
|
{
|
||||||
|
@ -385,6 +385,14 @@ public:
|
|||||||
QSize toolBarIconSize(eState State) const;
|
QSize toolBarIconSize(eState State) const;
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef QT_NO_TOOLTIP
|
||||||
|
/**
|
||||||
|
* This is function sets text tooltip for title bar widget
|
||||||
|
* and tooltip for toggle view action
|
||||||
|
*/
|
||||||
|
void setTabToolTip(const QString &text);
|
||||||
|
#endif
|
||||||
|
|
||||||
public: // reimplements QFrame -----------------------------------------------
|
public: // reimplements QFrame -----------------------------------------------
|
||||||
/**
|
/**
|
||||||
* Emits titleChanged signal if title change event occurs
|
* Emits titleChanged signal if title change event occurs
|
||||||
|
@ -153,7 +153,9 @@ void DockWidgetTabPrivate::createLayout()
|
|||||||
CloseButton->setIcon(CloseIcon);
|
CloseButton->setIcon(CloseIcon);
|
||||||
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||||
CloseButton->setVisible(false);
|
CloseButton->setVisible(false);
|
||||||
|
#ifndef QT_NO_TOOLTIP
|
||||||
CloseButton->setToolTip(QObject::tr("Close Tab"));
|
CloseButton->setToolTip(QObject::tr("Close Tab"));
|
||||||
|
#endif
|
||||||
_this->connect(CloseButton, SIGNAL(clicked()), SIGNAL(closeRequested()));
|
_this->connect(CloseButton, SIGNAL(clicked()), SIGNAL(closeRequested()));
|
||||||
|
|
||||||
QFontMetrics fm(TitleLabel->font());
|
QFontMetrics fm(TitleLabel->font());
|
||||||
@ -422,7 +424,9 @@ void CDockWidgetTab::setIcon(const QIcon& Icon)
|
|||||||
d->IconLabel = new QLabel();
|
d->IconLabel = new QLabel();
|
||||||
d->IconLabel->setAlignment(Qt::AlignVCenter);
|
d->IconLabel->setAlignment(Qt::AlignVCenter);
|
||||||
d->IconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
d->IconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||||
|
#ifndef QT_NO_TOOLTIP
|
||||||
d->IconLabel->setToolTip(d->TitleLabel->toolTip());
|
d->IconLabel->setToolTip(d->TitleLabel->toolTip());
|
||||||
|
#endif
|
||||||
Layout->insertWidget(0, d->IconLabel, Qt::AlignVCenter);
|
Layout->insertWidget(0, d->IconLabel, Qt::AlignVCenter);
|
||||||
Layout->insertSpacing(1, qRound(1.5 * Layout->contentsMargins().left() / 2.0));
|
Layout->insertSpacing(1, qRound(1.5 * Layout->contentsMargins().left() / 2.0));
|
||||||
}
|
}
|
||||||
@ -504,7 +508,25 @@ void CDockWidgetTab::onDetachActionTriggered()
|
|||||||
d->startFloating(DraggingInactive);
|
d->startFloating(DraggingInactive);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ads
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
bool CDockWidgetTab::event(QEvent *e)
|
||||||
|
{
|
||||||
|
#ifndef QT_NO_TOOLTIP
|
||||||
|
if (e->type() == QEvent::ToolTipChange)
|
||||||
|
{
|
||||||
|
const auto text = toolTip();
|
||||||
|
d->TitleLabel->setToolTip(text);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return QFrame::event(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace ads
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
// EOF DockWidgetTab.cpp
|
// EOF DockWidgetTab.cpp
|
||||||
|
@ -136,6 +136,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool isClosable() const;
|
bool isClosable() const;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emits tooltipChanged
|
||||||
|
*/
|
||||||
|
virtual bool event(QEvent *e) override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
virtual void setVisible(bool visible) override;
|
virtual void setVisible(bool visible) override;
|
||||||
|
@ -88,7 +88,9 @@ CElidingLabel::CElidingLabel(const QString& text, QWidget* parent, Qt::WindowFla
|
|||||||
d(new ElidingLabelPrivate(this))
|
d(new ElidingLabelPrivate(this))
|
||||||
{
|
{
|
||||||
d->Text = text;
|
d->Text = text;
|
||||||
|
#ifndef QT_NO_TOOLTIP
|
||||||
setToolTip(text);
|
setToolTip(text);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -183,7 +185,9 @@ void CElidingLabel::setText(const QString &text)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
d->Text = text;
|
d->Text = text;
|
||||||
|
#ifndef QT_NO_TOOLTIP
|
||||||
setToolTip( text );
|
setToolTip( text );
|
||||||
|
#endif
|
||||||
d->elideText(this->size().width());
|
d->elideText(this->size().width());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user