Skip to content

Commit a9965bf

Browse files
committed
Moved CTitleBarButton and CSpacerWidget declaration into DockAreaTitleBar.h
This gets rid of the need to MOC DockAreaTitleBar.h and DockAreaTitleBar.cpp and it means that DockAreaTitleBar.cpp does not need to #include "DockAreaTitleBar.moc" anymore, which is a file that is generated by the build system and therefore may be named differently when using a custom build system.
1 parent aa7976d commit a9965bf

File tree

2 files changed

+94
-84
lines changed

2 files changed

+94
-84
lines changed

src/DockAreaTitleBar.cpp

Lines changed: 42 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@
5555

5656
namespace ads
5757
{
58-
using tTitleBarButton = QToolButton;
59-
6058

6159
/**
6260
* Private data class of CDockAreaTitleBar class (pimpl)
@@ -130,86 +128,6 @@ struct DockAreaTitleBarPrivate
130128
IFloatingWidget* makeAreaFloating(const QPoint& Offset, eDragState DragState);
131129
};// struct DockAreaTitleBarPrivate
132130

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-
213131
//============================================================================
214132
DockAreaTitleBarPrivate::DockAreaTitleBarPrivate(CDockAreaTitleBar* _public) :
215133
_this(_public)
@@ -674,10 +592,50 @@ int CDockAreaTitleBar::indexOf(QWidget *widget) const
674592
return d->Layout->indexOf(widget);
675593
}
676594

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

678-
} // namespace ads
601+
}
679602

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

682640
//---------------------------------------------------------------------------
683641
// EOF DockAreaTitleBar.cpp

src/DockAreaTitleBar.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
// INCLUDES
3232
//============================================================================
3333
#include <QFrame>
34+
#include <QToolButton>
3435

3536
#include "ads_globals.h"
3637

@@ -155,6 +156,57 @@ public slots:
155156
*/
156157
void tabBarClicked(int index);
157158
}; // class name
159+
160+
using tTitleBarButton = QToolButton;
161+
162+
/**
163+
* Title bar button of a dock area that customizes tTitleBarButton appearance/behaviour
164+
* according to various config flags such as:
165+
* CDockManager::DockAreaHas_xxx_Button - if set to 'false' keeps the button always invisible
166+
* CDockManager::DockAreaHideDisabledButtons - if set to 'true' hides button when it is disabled
167+
*/
168+
class CTitleBarButton : public tTitleBarButton
169+
{
170+
Q_OBJECT
171+
172+
bool Visible = true;
173+
bool HideWhenDisabled = false;
174+
175+
public:
176+
using Super = tTitleBarButton;
177+
CTitleBarButton(bool visible = true, QWidget* parent = nullptr);
178+
179+
/**
180+
* Adjust this visibility change request with our internal settings:
181+
*/
182+
virtual void setVisible(bool visible) override;
183+
184+
protected:
185+
/**
186+
* Handle EnabledChanged signal to set button invisible if the configured
187+
*/
188+
bool event(QEvent *ev) override;
189+
};
190+
191+
192+
/**
193+
* This spacer widget is here because of the following problem.
194+
* The dock area title bar handles mouse dragging and moving the floating widget.
195+
* The problem is, that if the title bar becomes invisible, i.e. if the dock
196+
* area contains only one single dock widget and the dock area is moved
197+
* into a floating widget, then mouse events are not handled anymore and dragging
198+
* of the floating widget stops.
199+
*/
200+
class CSpacerWidget : public QWidget
201+
{
202+
Q_OBJECT
203+
public:
204+
using Super = QWidget;
205+
CSpacerWidget(QWidget* Parent = 0);
206+
virtual QSize sizeHint() const override {return QSize(0, 0);}
207+
virtual QSize minimumSizeHint() const override {return QSize(0, 0);}
208+
};
209+
158210
}
159211
// namespace ads
160212
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)