Skip to content

Commit

Permalink
Merge pull request mfreiholz#20 from yozka/feature_2
Browse files Browse the repository at this point in the history
set tooltip for titlebar and menu
  • Loading branch information
githubuser0xFFFF committed Jan 25, 2019
2 parents 4dde545 + 0c3ef64 commit e352ce5
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 17 deletions.
3 changes: 2 additions & 1 deletion demo/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ struct MainWindowPrivate
Ui::MainWindow ui;
QAction* SavePerspectiveAction = nullptr;
QWidgetAction* PerspectiveListAction = nullptr;
QComboBox* PerspectiveComboBox = nullptr;;
QComboBox* PerspectiveComboBox = nullptr;
ads::CDockManager* DockManager = nullptr;

MainWindowPrivate(CMainWindow* _public) : _this(_public) {}
Expand Down Expand Up @@ -188,6 +188,7 @@ void MainWindowPrivate::createContent()
auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
DockWidget = createCalendarDockWidget(ViewMenu);
DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false);
DockWidget->setTabToolTip(QString("Tab ToolTip\nHodie est dies magna"));
DockManager->addDockWidget(ads::CenterDockWidgetArea, DockWidget, TopDockArea);

// Test dock area docking
Expand Down
13 changes: 13 additions & 0 deletions src/DockAreaTitleBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,14 @@ void DockAreaTitleBarPrivate::createButtons()
TabsMenuButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarUnshadeButton));

QMenu* TabsMenu = new QMenu(TabsMenuButton);
#ifndef QT_NO_TOOLTIP
TabsMenu->setToolTipsVisible(true);
#endif
_this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow()));
TabsMenuButton->setMenu(TabsMenu);
#ifndef QT_NO_TOOLTIP
TabsMenuButton->setToolTip(QObject::tr("List all tabs"));
#endif
TabsMenuButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
TopLayout->addWidget(TabsMenuButton, 0);
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
Expand All @@ -131,7 +136,9 @@ void DockAreaTitleBarPrivate::createButtons()
UndockButton = new tTileBarButton();
UndockButton->setObjectName("undockButton");
UndockButton->setAutoRaise(true);
#ifndef QT_NO_TOOLTIP
UndockButton->setToolTip(QObject::tr("Detach Group"));
#endif
UndockButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarNormalButton));
UndockButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
TopLayout->addWidget(UndockButton, 0);
Expand All @@ -148,6 +155,7 @@ void DockAreaTitleBarPrivate::createButtons()
CloseIcon.addPixmap(disabledPixmap, QIcon::Disabled);

CloseButton->setIcon(CloseIcon);
#ifndef QT_NO_TOOLTIP
if (testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
{
CloseButton->setToolTip(QObject::tr("Close Active Tab"));
Expand All @@ -156,6 +164,7 @@ void DockAreaTitleBarPrivate::createButtons()
{
CloseButton->setToolTip(QObject::tr("Close Group"));
}
#endif
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
TopLayout->addWidget(CloseButton, 0);
_this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked()));
Expand Down Expand Up @@ -240,6 +249,9 @@ void CDockAreaTitleBar::onTabsMenuAboutToShow()
}
auto Tab = d->TabBar->tab(i);
QAction* Action = menu->addAction(Tab->icon(), Tab->text());
#ifndef QT_NO_TOOLTIP
Action->setToolTip(Tab->toolTip());
#endif
Action->setData(i);
}

Expand Down Expand Up @@ -312,6 +324,7 @@ QAbstractButton* CDockAreaTitleBar::button(TitleBarButton which) const
void CDockAreaTitleBar::setVisible(bool Visible)
{
Super::setVisible(Visible);
markTabsMenuOutdated();
}


Expand Down
6 changes: 5 additions & 1 deletion src/DockAreaTitleBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ class CDockAreaTitleBar : public QFrame
friend struct DockAreaTitleBarPrivate;

private slots:
void markTabsMenuOutdated();
void onTabsMenuAboutToShow();
void onCloseButtonClicked();
void onUndockButtonClicked();
void onTabsMenuActionTriggered(QAction* Action);
void onCurrentTabChanged(int Index);
void showContextMenu(const QPoint& pos);

public slots:
void markTabsMenuOutdated();


public:
using Super = QFrame;
/**
Expand Down Expand Up @@ -88,6 +91,7 @@ private slots:
*/
virtual void setVisible(bool Visible) override;


signals:
/**
* This signal is emitted if a tab in the tab bar is clicked by the user
Expand Down
26 changes: 20 additions & 6 deletions src/DockAreaWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ using DockAreaLayout = CDockAreaLayout;
*/
struct DockAreaWidgetPrivate
{
CDockAreaWidget* _this;
QBoxLayout* Layout;
DockAreaLayout* ContentsLayout;
CDockAreaTitleBar* TitleBar;
CDockManager* DockManager = nullptr;
CDockAreaWidget* _this = nullptr;
QBoxLayout* Layout = nullptr;
DockAreaLayout* ContentsLayout = nullptr;
CDockAreaTitleBar* TitleBar = nullptr;
CDockManager* DockManager = nullptr;
bool UpdateCloseButton = false;

/**
Expand Down Expand Up @@ -680,10 +680,24 @@ void CDockAreaWidget::updateTitleBarVisibility()
return;
}

d->TitleBar->setVisible(!Container->isFloating() || !Container->hasTopLevelDockWidget());
if (d->TitleBar)
{
d->TitleBar->setVisible(!Container->isFloating() || !Container->hasTopLevelDockWidget());
}
}


//============================================================================
void CDockAreaWidget::markTitleBarMenuOutdated()
{
if (d->TitleBar)
{
d->TitleBar->markTabsMenuOutdated();
}
}



//============================================================================
void CDockAreaWidget::saveState(QXmlStreamWriter& s) const
{
Expand Down
6 changes: 6 additions & 0 deletions src/DockAreaWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ private slots:
*/
void internalSetCurrentDockWidget(CDockWidget* DockWidget);


/**
* Marks tabs menu to update
*/
void markTitleBarMenuOutdated();

protected slots:
void toggleView(bool Open);

Expand Down
30 changes: 27 additions & 3 deletions src/DockWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ namespace ads
*/
struct DockWidgetPrivate
{
CDockWidget* _this;
QBoxLayout* Layout;
CDockWidget* _this = nullptr;
QBoxLayout* Layout = nullptr;
QWidget* Widget = nullptr;
CDockWidgetTab* TabWidget = nullptr;
CDockWidget::DockWidgetFeatures Features = CDockWidget::AllDockWidgetFeatures;
Expand Down Expand Up @@ -516,12 +516,36 @@ bool CDockWidget::event(QEvent *e)
{
d->ToggleViewAction->setText(title);
}
if (d->DockArea)
{
d->DockArea->markTitleBarMenuOutdated();//update tabs menu
}
emit titleChanged(title);
}
return QFrame::event(e);
return Super::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->markTitleBarMenuOutdated();//update tabs menu
}
}
#endif


//============================================================================
void CDockWidget::setIcon(const QIcon& Icon)
{
Expand Down
10 changes: 10 additions & 0 deletions src/DockWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ private slots:
void toggleViewInternal(bool Open);

public:
using Super = QFrame;

enum DockWidgetFeature
{
DockWidgetClosable = 0x01,
Expand Down Expand Up @@ -385,6 +387,14 @@ private slots:
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 -----------------------------------------------
/**
* Emits titleChanged signal if title change event occurs
Expand Down
34 changes: 28 additions & 6 deletions src/DockWidgetTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ void DockWidgetTabPrivate::createLayout()
CloseButton->setIcon(CloseIcon);
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
CloseButton->setVisible(false);
#ifndef QT_NO_TOOLTIP
CloseButton->setToolTip(QObject::tr("Close Tab"));
#endif
_this->connect(CloseButton, SIGNAL(clicked()), SIGNAL(closeRequested()));

QFontMetrics fm(TitleLabel->font());
Expand Down Expand Up @@ -264,7 +266,7 @@ void CDockWidgetTab::mousePressEvent(QMouseEvent* ev)
emit clicked();
return;
}
QFrame::mousePressEvent(ev);
Super::mousePressEvent(ev);
}


Expand All @@ -280,7 +282,7 @@ void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev)

d->DragStartMousePosition = QPoint();
d->DragState = DraggingInactive;
QFrame::mouseReleaseEvent(ev);
Super::mouseReleaseEvent(ev);
}


Expand All @@ -290,15 +292,15 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
if (!(ev->buttons() & Qt::LeftButton) || d->isDraggingState(DraggingInactive))
{
d->DragState = DraggingInactive;
QFrame::mouseMoveEvent(ev);
Super::mouseMoveEvent(ev);
return;
}

// move floating window
if (d->isDraggingState(DraggingFloatingWidget))
{
d->FloatingWidget->moveFloating();
QFrame::mouseMoveEvent(ev);
Super::mouseMoveEvent(ev);
return;
}

Expand Down Expand Up @@ -338,7 +340,7 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
return;
}

QFrame::mouseMoveEvent(ev);
Super::mouseMoveEvent(ev);
}


Expand Down Expand Up @@ -422,7 +424,9 @@ void CDockWidgetTab::setIcon(const QIcon& Icon)
d->IconLabel = new QLabel();
d->IconLabel->setAlignment(Qt::AlignVCenter);
d->IconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
#ifndef QT_NO_TOOLTIP
d->IconLabel->setToolTip(d->TitleLabel->toolTip());
#endif
Layout->insertWidget(0, d->IconLabel, Qt::AlignVCenter);
Layout->insertSpacing(1, qRound(1.5 * Layout->contentsMargins().left() / 2.0));
}
Expand Down Expand Up @@ -504,7 +508,25 @@ void CDockWidgetTab::onDetachActionTriggered()
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 Super::event(e);
}




} // namespace ads
//---------------------------------------------------------------------------
// EOF DockWidgetTab.cpp
6 changes: 6 additions & 0 deletions src/DockWidgetTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ private slots:
*/
bool isClosable() const;


/**
* Track event ToolTipChange and set child ToolTip
*/
virtual bool event(QEvent *e) override;

public slots:

virtual void setVisible(bool visible) override;
Expand Down
4 changes: 4 additions & 0 deletions src/ElidingLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ CElidingLabel::CElidingLabel(const QString& text, QWidget* parent, Qt::WindowFla
d(new ElidingLabelPrivate(this))
{
d->Text = text;
#ifndef QT_NO_TOOLTIP
setToolTip(text);
#endif
}


Expand Down Expand Up @@ -183,7 +185,9 @@ void CElidingLabel::setText(const QString &text)
else
{
d->Text = text;
#ifndef QT_NO_TOOLTIP
setToolTip( text );
#endif
d->elideText(this->size().width());
}
}
Expand Down

0 comments on commit e352ce5

Please sign in to comment.