Skip to content

Commit 14f5426

Browse files
Merge branch 'jankrassnigg-master'
2 parents 4a8b5dd + d418d92 commit 14f5426

File tree

5 files changed

+140
-84
lines changed

5 files changed

+140
-84
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ set(ads_INSTALL_INCLUDE
5050
src/ads_globals.h
5151
src/DockAreaTabBar.h
5252
src/DockAreaTitleBar.h
53+
src/DockAreaTitleBar_p.h
5354
src/DockAreaWidget.h
5455
src/DockContainerWidget.h
5556
src/DockManager.h

src/DockAreaTitleBar.cpp

Lines changed: 43 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <QDebug>
4040
#include <QPointer>
4141

42+
#include "DockAreaTitleBar_p.h"
4243
#include "ads_globals.h"
4344
#include "FloatingDockContainer.h"
4445
#include "FloatingDragPreview.h"
@@ -55,8 +56,6 @@
5556

5657
namespace ads
5758
{
58-
using tTitleBarButton = QToolButton;
59-
6059

6160
/**
6261
* Private data class of CDockAreaTitleBar class (pimpl)
@@ -130,86 +129,6 @@ struct DockAreaTitleBarPrivate
130129
IFloatingWidget* makeAreaFloating(const QPoint& Offset, eDragState DragState);
131130
};// struct DockAreaTitleBarPrivate
132131

133-
134-
/**
135-
* Title bar button of a dock area that customizes tTitleBarButton appearance/behaviour
136-
* according to various config flags such as:
137-
* CDockManager::DockAreaHas_xxx_Button - if set to 'false' keeps the button always invisible
138-
* CDockManager::DockAreaHideDisabledButtons - if set to 'true' hides button when it is disabled
139-
*/
140-
class CTitleBarButton : public tTitleBarButton
141-
{
142-
Q_OBJECT
143-
bool Visible = true;
144-
bool HideWhenDisabled = false;
145-
public:
146-
using Super = tTitleBarButton;
147-
CTitleBarButton(bool visible = true, QWidget* parent = nullptr)
148-
: tTitleBarButton(parent),
149-
Visible(visible),
150-
HideWhenDisabled(DockAreaTitleBarPrivate::testConfigFlag(CDockManager::DockAreaHideDisabledButtons))
151-
{}
152-
153-
154-
/**
155-
* Adjust this visibility change request with our internal settings:
156-
*/
157-
virtual void setVisible(bool visible) override
158-
{
159-
// 'visible' can stay 'true' if and only if this button is configured to generaly visible:
160-
visible = visible && this->Visible;
161-
162-
// 'visible' can stay 'true' unless: this button is configured to be invisible when it is disabled and it is currently disabled:
163-
if(visible && HideWhenDisabled)
164-
{
165-
visible = isEnabled();
166-
}
167-
168-
Super::setVisible(visible);
169-
}
170-
171-
protected:
172-
/**
173-
* Handle EnabledChanged signal to set button invisible if the configured
174-
*/
175-
bool event(QEvent *ev) override
176-
{
177-
if(QEvent::EnabledChange == ev->type() && HideWhenDisabled)
178-
{
179-
// force setVisible() call
180-
// Calling setVisible() directly here doesn't work well when button is expected to be shown first time
181-
QMetaObject::invokeMethod(this, "setVisible", Qt::QueuedConnection, Q_ARG(bool, isEnabled()));
182-
}
183-
184-
return Super::event(ev);
185-
}
186-
};
187-
188-
189-
/**
190-
* This spacer widget is here because of the following problem.
191-
* The dock area title bar handles mouse dragging and moving the floating widget.
192-
* The problem is, that if the title bar becomes invisible, i.e. if the dock
193-
* area contains only one single dock widget and the dock area is moved
194-
* into a floating widget, then mouse events are not handled anymore and dragging
195-
* of the floating widget stops.
196-
*/
197-
class CSpacerWidget : public QWidget
198-
{
199-
Q_OBJECT
200-
public:
201-
using Super = QWidget;
202-
CSpacerWidget(QWidget* Parent = 0)
203-
: Super(Parent)
204-
{
205-
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
206-
setStyleSheet("border: none; background: none;");
207-
}
208-
virtual QSize sizeHint() const override {return QSize(0, 0);}
209-
virtual QSize minimumSizeHint() const override {return QSize(0, 0);}
210-
};
211-
212-
213132
//============================================================================
214133
DockAreaTitleBarPrivate::DockAreaTitleBarPrivate(CDockAreaTitleBar* _public) :
215134
_this(_public)
@@ -674,10 +593,50 @@ int CDockAreaTitleBar::indexOf(QWidget *widget) const
674593
return d->Layout->indexOf(widget);
675594
}
676595

596+
//============================================================================
597+
CTitleBarButton::CTitleBarButton(bool visible /*= true*/, QWidget* parent /*= nullptr*/) : tTitleBarButton(parent),
598+
Visible(visible),
599+
HideWhenDisabled(DockAreaTitleBarPrivate::testConfigFlag(CDockManager::DockAreaHideDisabledButtons))
600+
{
677601

678-
} // namespace ads
602+
}
679603

680-
#include "DockAreaTitleBar.moc"
604+
//============================================================================
605+
void CTitleBarButton::setVisible(bool visible)
606+
{
607+
// 'visible' can stay 'true' if and only if this button is configured to generaly visible:
608+
visible = visible && this->Visible;
609+
610+
// 'visible' can stay 'true' unless: this button is configured to be invisible when it is disabled and it is currently disabled:
611+
if (visible && HideWhenDisabled)
612+
{
613+
visible = isEnabled();
614+
}
615+
616+
Super::setVisible(visible);
617+
}
618+
619+
//============================================================================
620+
bool CTitleBarButton::event(QEvent *ev)
621+
{
622+
if (QEvent::EnabledChange == ev->type() && HideWhenDisabled)
623+
{
624+
// force setVisible() call
625+
// Calling setVisible() directly here doesn't work well when button is expected to be shown first time
626+
QMetaObject::invokeMethod(this, "setVisible", Qt::QueuedConnection, Q_ARG(bool, isEnabled()));
627+
}
628+
629+
return Super::event(ev);
630+
}
631+
632+
//============================================================================
633+
CSpacerWidget::CSpacerWidget(QWidget* Parent /*= 0*/) : Super(Parent)
634+
{
635+
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
636+
setStyleSheet("border: none; background: none;");
637+
}
638+
639+
} // namespace ads
681640

682641
//---------------------------------------------------------------------------
683642
// EOF DockAreaTitleBar.cpp

src/DockAreaTitleBar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public slots:
155155
*/
156156
void tabBarClicked(int index);
157157
}; // class name
158+
158159
}
159160
// namespace ads
160161
//-----------------------------------------------------------------------------

src/DockAreaTitleBar_p.h

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#ifndef DockAreaTitleBar_pH
2+
#define DockAreaTitleBar_pH
3+
/*******************************************************************************
4+
** Qt Advanced Docking System
5+
** Copyright (C) 2017 Uwe Kindler
6+
**
7+
** This library is free software; you can redistribute it and/or
8+
** modify it under the terms of the GNU Lesser General Public
9+
** License as published by the Free Software Foundation; either
10+
** version 2.1 of the License, or (at your option) any later version.
11+
**
12+
** This library is distributed in the hope that it will be useful,
13+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
** Lesser General Public License for more details.
16+
**
17+
** You should have received a copy of the GNU Lesser General Public
18+
** License along with this library; If not, see <http://www.gnu.org/licenses/>.
19+
******************************************************************************/
20+
21+
22+
//============================================================================
23+
/// \file DockAreaTitleBar_p.h
24+
/// \author Uwe Kindler
25+
/// \date 12.10.2018
26+
/// \brief Declaration of classes CTitleBarButton and CSpacerWidget
27+
//============================================================================
28+
29+
30+
//============================================================================
31+
// INCLUDES
32+
//============================================================================
33+
#include <QFrame>
34+
#include <QToolButton>
35+
36+
#include "ads_globals.h"
37+
38+
namespace ads
39+
{
40+
using tTitleBarButton = QToolButton;
41+
42+
/**
43+
* Title bar button of a dock area that customizes tTitleBarButton appearance/behaviour
44+
* according to various config flags such as:
45+
* CDockManager::DockAreaHas_xxx_Button - if set to 'false' keeps the button always invisible
46+
* CDockManager::DockAreaHideDisabledButtons - if set to 'true' hides button when it is disabled
47+
*/
48+
class CTitleBarButton : public tTitleBarButton
49+
{
50+
Q_OBJECT
51+
52+
private:
53+
bool Visible = true;
54+
bool HideWhenDisabled = false;
55+
56+
public:
57+
using Super = tTitleBarButton;
58+
CTitleBarButton(bool visible = true, QWidget* parent = nullptr);
59+
60+
/**
61+
* Adjust this visibility change request with our internal settings:
62+
*/
63+
virtual void setVisible(bool visible) override;
64+
65+
protected:
66+
/**
67+
* Handle EnabledChanged signal to set button invisible if the configured
68+
*/
69+
bool event(QEvent *ev) override;
70+
};
71+
72+
73+
/**
74+
* This spacer widget is here because of the following problem.
75+
* The dock area title bar handles mouse dragging and moving the floating widget.
76+
* The problem is, that if the title bar becomes invisible, i.e. if the dock
77+
* area contains only one single dock widget and the dock area is moved
78+
* into a floating widget, then mouse events are not handled anymore and dragging
79+
* of the floating widget stops.
80+
*/
81+
class CSpacerWidget : public QWidget
82+
{
83+
Q_OBJECT
84+
public:
85+
using Super = QWidget;
86+
CSpacerWidget(QWidget* Parent = 0);
87+
virtual QSize sizeHint() const override {return QSize(0, 0);}
88+
virtual QSize minimumSizeHint() const override {return QSize(0, 0);}
89+
};
90+
91+
}
92+
// namespace ads
93+
//-----------------------------------------------------------------------------
94+
#endif // DockAreaTitleBar_pH

src/src.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ HEADERS += \
4141
FloatingDragPreview.h \
4242
DockOverlay.h \
4343
DockSplitter.h \
44+
DockAreaTitleBar_p.h \
4445
DockAreaTitleBar.h \
4546
ElidingLabel.h \
4647
IconProvider.h \

0 commit comments

Comments
 (0)