From 120a52c143a9efbcb41d2bf109e82728becf7d6c Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 5 Jan 2021 21:09:05 +0400 Subject: [PATCH] Add traits for customizing RpWidgetWrap instances. --- ui/rp_widget.cpp | 6 ++++-- ui/rp_widget.h | 16 ++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ui/rp_widget.cpp b/ui/rp_widget.cpp index 8646c92..16f8919 100644 --- a/ui/rp_widget.cpp +++ b/ui/rp_widget.cpp @@ -160,8 +160,10 @@ bool RpWidgetMethods::handleEvent(QEvent *event) { return eventHook(event); } -RpWidgetMethods::Initer::Initer(QWidget *parent) { - parent->setGeometry(0, 0, 0, 0); +RpWidgetMethods::Initer::Initer(QWidget *parent, bool setZeroGeometry) { + if (setZeroGeometry) { + parent->setGeometry(0, 0, 0, 0); + } } void RpWidgetMethods::visibilityChangedHook(bool wasVisible, bool nowVisible) { diff --git a/ui/rp_widget.h b/ui/rp_widget.h index 8cffbe5..f6ce3c2 100644 --- a/ui/rp_widget.h +++ b/ui/rp_widget.h @@ -243,7 +243,7 @@ using RpWidgetParent = std::conditional_t< TWidget, TWidgetHelper>; -template +template class RpWidgetWrap; class RpWidgetMethods { @@ -281,7 +281,7 @@ protected: virtual bool eventHook(QEvent *event) = 0; private: - template + template friend class RpWidgetWrap; struct EventStreams { @@ -292,7 +292,7 @@ private: rpl::event_stream<> alive; }; struct Initer { - Initer(QWidget *parent); + Initer(QWidget *parent, bool setZeroGeometry); }; virtual void callSetVisible(bool visible) = 0; @@ -310,11 +310,15 @@ private: }; -template +struct RpWidgetDefaultTraits { + static constexpr bool kSetZeroGeometry = true; +}; + +template class RpWidgetWrap : public RpWidgetParent , public RpWidgetMethods { - using Self = RpWidgetWrap; + using Self = RpWidgetWrap; using Parent = RpWidgetParent; public: @@ -362,7 +366,7 @@ private: return this->isHidden(); } - Initer _initer = { this }; + Initer _initer = { this, Traits::kSetZeroGeometry }; };