Skip to content

Commit

Permalink
Added spacer widget to handle mouse events properly in CDockAreaTitle…
Browse files Browse the repository at this point in the history
…Bar, added missing updateGeometry calls to CDockAreaTabBar
  • Loading branch information
githubuser0xFFFF committed Feb 7, 2020
1 parent c4872c6 commit 8113bf6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/DockAreaTabBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,15 @@ bool CDockAreaTabBar::eventFilter(QObject *watched, QEvent *event)
switch (event->type())
{
case QEvent::Hide:
emit tabClosed(d->TabsLayout->indexOf(Tab)); break;
emit tabClosed(d->TabsLayout->indexOf(Tab));
updateGeometry();
break;

case QEvent::Show:
emit tabOpened(d->TabsLayout->indexOf(Tab)); break;
emit tabOpened(d->TabsLayout->indexOf(Tab));
updateGeometry();
break;

default:
break;
}
Expand Down
27 changes: 25 additions & 2 deletions src/DockAreaTitleBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,30 @@ class CTitleBarButton : public tTitleBarButton
};


/**
* This spacer widget is here because of the following problem.
* The dock area title bar handles mouse dragging and moving the floating widget.
* The problem is, that if the title bar becomes invisible, i.e. if the dock
* area contains only one single dock widget and the dock area is moved
* into a floating widget, then mouse events are not handled anymore and dragging
* of the floating widget stops.
*/
class CSpacerWidget : public QWidget
{
Q_OBJECT
public:
using Super = QWidget;
CSpacerWidget(QWidget* Parent = 0)
: Super(Parent)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
setStyleSheet("border: none; background: none;");
}
virtual QSize sizeHint() const override {return QSize(0, 0);}
virtual QSize minimumSizeHint() const override {return QSize(0, 0);}
};


//============================================================================
DockAreaTitleBarPrivate::DockAreaTitleBarPrivate(CDockAreaTitleBar* _public) :
_this(_public)
Expand Down Expand Up @@ -322,8 +346,7 @@ CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) :
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);

d->createTabBar();
auto horizontalSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
d->Layout->addSpacerItem(horizontalSpacer);
d->Layout->addWidget(new CSpacerWidget(this));
d->createButtons();
}

Expand Down

0 comments on commit 8113bf6

Please sign in to comment.