Skip to content

Commit 6cb1f33

Browse files
ToolTip from titlebar and menu
1 parent 1ad6cae commit 6cb1f33

File tree

7 files changed

+89
-9
lines changed

7 files changed

+89
-9
lines changed

src/DockAreaTitleBar.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,14 @@ void DockAreaTitleBarPrivate::createButtons()
119119
TabsMenuButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarUnshadeButton));
120120

121121
QMenu* TabsMenu = new QMenu(TabsMenuButton);
122+
#ifndef QT_NO_TOOLTIP
123+
TabsMenu->setToolTipsVisible(true);
124+
#endif
122125
_this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow()));
123126
TabsMenuButton->setMenu(TabsMenu);
127+
#ifndef QT_NO_TOOLTIP
124128
TabsMenuButton->setToolTip(QObject::tr("List all tabs"));
129+
#endif
125130
TabsMenuButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
126131
TopLayout->addWidget(TabsMenuButton, 0);
127132
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
@@ -131,7 +136,9 @@ void DockAreaTitleBarPrivate::createButtons()
131136
UndockButton = new tTileBarButton();
132137
UndockButton->setObjectName("undockButton");
133138
UndockButton->setAutoRaise(true);
139+
#ifndef QT_NO_TOOLTIP
134140
UndockButton->setToolTip(QObject::tr("Detach Group"));
141+
#endif
135142
UndockButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarNormalButton));
136143
UndockButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
137144
TopLayout->addWidget(UndockButton, 0);
@@ -148,6 +155,7 @@ void DockAreaTitleBarPrivate::createButtons()
148155
CloseIcon.addPixmap(disabledPixmap, QIcon::Disabled);
149156

150157
CloseButton->setIcon(CloseIcon);
158+
#ifndef QT_NO_TOOLTIP
151159
if (testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
152160
{
153161
CloseButton->setToolTip(QObject::tr("Close Active Tab"));
@@ -156,6 +164,7 @@ void DockAreaTitleBarPrivate::createButtons()
156164
{
157165
CloseButton->setToolTip(QObject::tr("Close Group"));
158166
}
167+
#endif
159168
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
160169
TopLayout->addWidget(CloseButton, 0);
161170
_this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked()));
@@ -240,6 +249,9 @@ void CDockAreaTitleBar::onTabsMenuAboutToShow()
240249
}
241250
auto Tab = d->TabBar->tab(i);
242251
QAction* Action = menu->addAction(Tab->icon(), Tab->text());
252+
#ifndef QT_NO_TOOLTIP
253+
Action->setToolTip(Tab->toolTip());
254+
#endif
243255
Action->setData(i);
244256
}
245257

@@ -312,6 +324,7 @@ QAbstractButton* CDockAreaTitleBar::button(TitleBarButton which) const
312324
void CDockAreaTitleBar::setVisible(bool Visible)
313325
{
314326
Super::setVisible(Visible);
327+
markTabsMenuOutdated();
315328
}
316329

317330

src/DockAreaWidget.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,11 @@ using DockAreaLayout = CDockAreaLayout;
236236
*/
237237
struct DockAreaWidgetPrivate
238238
{
239-
CDockAreaWidget* _this;
240-
QBoxLayout* Layout;
241-
DockAreaLayout* ContentsLayout;
242-
CDockAreaTitleBar* TitleBar;
243-
CDockManager* DockManager = nullptr;
239+
CDockAreaWidget* _this = nullptr;
240+
QBoxLayout* Layout = nullptr;
241+
DockAreaLayout* ContentsLayout = nullptr;
242+
CDockAreaTitleBar* TitleBar = nullptr;
243+
CDockManager* DockManager = nullptr;
244244
bool UpdateCloseButton = false;
245245

246246
/**
@@ -680,7 +680,10 @@ void CDockAreaWidget::updateTitleBarVisibility()
680680
return;
681681
}
682682

683-
d->TitleBar->setVisible(!Container->isFloating() || !Container->hasTopLevelDockWidget());
683+
if (d->TitleBar)
684+
{
685+
d->TitleBar->setVisible(!Container->isFloating() || !Container->hasTopLevelDockWidget());
686+
}
684687
}
685688

686689

src/DockWidget.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ namespace ads
5858
*/
5959
struct DockWidgetPrivate
6060
{
61-
CDockWidget* _this;
62-
QBoxLayout* Layout;
61+
CDockWidget* _this = nullptr;
62+
QBoxLayout* Layout = nullptr;
6363
QWidget* Widget = nullptr;
6464
CDockWidgetTab* TabWidget = nullptr;
6565
CDockWidget::DockWidgetFeatures Features = CDockWidget::AllDockWidgetFeatures;
@@ -516,12 +516,36 @@ bool CDockWidget::event(QEvent *e)
516516
{
517517
d->ToggleViewAction->setText(title);
518518
}
519+
if (d->DockArea)
520+
{
521+
d->DockArea->updateTitleBarVisibility();//update tabs menu
522+
}
519523
emit titleChanged(title);
520524
}
521525
return QFrame::event(e);
522526
}
523527

524528

529+
#ifndef QT_NO_TOOLTIP
530+
//============================================================================
531+
void CDockWidget::setTabToolTip(const QString &text)
532+
{
533+
if (d->TabWidget)
534+
{
535+
d->TabWidget->setToolTip(text);
536+
}
537+
if (d->ToggleViewAction)
538+
{
539+
d->ToggleViewAction->setToolTip(text);
540+
}
541+
if (d->DockArea)
542+
{
543+
d->DockArea->updateTitleBarVisibility();//update tabs menu
544+
}
545+
}
546+
#endif
547+
548+
525549
//============================================================================
526550
void CDockWidget::setIcon(const QIcon& Icon)
527551
{

src/DockWidget.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,14 @@ private slots:
385385
QSize toolBarIconSize(eState State) const;
386386

387387

388+
#ifndef QT_NO_TOOLTIP
389+
/**
390+
* This is function sets text tooltip for title bar widget
391+
* and tooltip for toggle view action
392+
*/
393+
void setTabToolTip(const QString &text);
394+
#endif
395+
388396
public: // reimplements QFrame -----------------------------------------------
389397
/**
390398
* Emits titleChanged signal if title change event occurs

src/DockWidgetTab.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ void DockWidgetTabPrivate::createLayout()
153153
CloseButton->setIcon(CloseIcon);
154154
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
155155
CloseButton->setVisible(false);
156+
#ifndef QT_NO_TOOLTIP
156157
CloseButton->setToolTip(QObject::tr("Close Tab"));
158+
#endif
157159
_this->connect(CloseButton, SIGNAL(clicked()), SIGNAL(closeRequested()));
158160

159161
QFontMetrics fm(TitleLabel->font());
@@ -422,7 +424,9 @@ void CDockWidgetTab::setIcon(const QIcon& Icon)
422424
d->IconLabel = new QLabel();
423425
d->IconLabel->setAlignment(Qt::AlignVCenter);
424426
d->IconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
427+
#ifndef QT_NO_TOOLTIP
425428
d->IconLabel->setToolTip(d->TitleLabel->toolTip());
429+
#endif
426430
Layout->insertWidget(0, d->IconLabel, Qt::AlignVCenter);
427431
Layout->insertSpacing(1, qRound(1.5 * Layout->contentsMargins().left() / 2.0));
428432
}
@@ -504,7 +508,25 @@ void CDockWidgetTab::onDetachActionTriggered()
504508
d->startFloating(DraggingInactive);
505509
}
506510

507-
} // namespace ads
508511

512+
513+
514+
//============================================================================
515+
bool CDockWidgetTab::event(QEvent *e)
516+
{
517+
#ifndef QT_NO_TOOLTIP
518+
if (e->type() == QEvent::ToolTipChange)
519+
{
520+
const auto text = toolTip();
521+
d->TitleLabel->setToolTip(text);
522+
}
523+
#endif
524+
return QFrame::event(e);
525+
}
526+
527+
528+
529+
530+
} // namespace ads
509531
//---------------------------------------------------------------------------
510532
// EOF DockWidgetTab.cpp

src/DockWidgetTab.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ private slots:
136136
*/
137137
bool isClosable() const;
138138

139+
140+
/**
141+
* Emits tooltipChanged
142+
*/
143+
virtual bool event(QEvent *e) override;
144+
139145
public slots:
140146

141147
virtual void setVisible(bool visible) override;

src/ElidingLabel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ CElidingLabel::CElidingLabel(const QString& text, QWidget* parent, Qt::WindowFla
8888
d(new ElidingLabelPrivate(this))
8989
{
9090
d->Text = text;
91+
#ifndef QT_NO_TOOLTIP
9192
setToolTip(text);
93+
#endif
9294
}
9395

9496

@@ -183,7 +185,9 @@ void CElidingLabel::setText(const QString &text)
183185
else
184186
{
185187
d->Text = text;
188+
#ifndef QT_NO_TOOLTIP
186189
setToolTip( text );
190+
#endif
187191
d->elideText(this->size().width());
188192
}
189193
}

0 commit comments

Comments
 (0)