Removed Q_OBJECT from BoxContent.

This commit is contained in:
23rd 2022-02-23 04:07:24 +03:00
parent b69fcf6048
commit c369eb13bf
2 changed files with 51 additions and 46 deletions

View file

@ -18,8 +18,6 @@
#include "styles/style_layers.h"
#include "styles/palette.h"
#include <QtCore/QTimer>
namespace Ui {
void BoxContent::setTitle(rpl::producer<QString> title) {
@ -48,7 +46,9 @@ void BoxContent::setInner(object_ptr<TWidget> inner) {
setInner(std::move(inner), st::boxScroll);
}
void BoxContent::setInner(object_ptr<TWidget> inner, const style::ScrollArea &st) {
void BoxContent::setInner(
object_ptr<TWidget> inner,
const style::ScrollArea &st) {
if (inner) {
getDelegate()->setLayerType(true);
_scroll.create(this, st);
@ -90,11 +90,13 @@ void BoxContent::finishScrollCreate() {
updateScrollAreaGeometry();
_scroll->scrolls(
) | rpl::start_with_next([=] {
onScroll();
updateInnerVisibleTopBottom();
updateShadowsVisibility();
}, lifetime());
_scroll->innerResizes(
) | rpl::start_with_next([=] {
onInnerResize();
updateInnerVisibleTopBottom();
updateShadowsVisibility();
}, lifetime());
}
@ -118,32 +120,39 @@ void BoxContent::scrollByDraggingDelta(int delta) {
_draggingScrollDelta = _scroll ? delta : 0;
if (_draggingScrollDelta) {
if (!_draggingScrollTimer) {
_draggingScrollTimer.create(this);
_draggingScrollTimer->setSingleShot(false);
connect(_draggingScrollTimer, SIGNAL(timeout()), this, SLOT(onDraggingScrollTimer()));
_draggingScrollTimer = std::make_unique<base::Timer>([=] {
draggingScrollTimerCallback();
});
}
_draggingScrollTimer->start(15);
_draggingScrollTimer->callEach(15);
} else {
_draggingScrollTimer.destroy();
_draggingScrollTimer = nullptr;
}
}
void BoxContent::onDraggingScrollTimer() {
auto delta = (_draggingScrollDelta > 0) ? qMin(_draggingScrollDelta * 3 / 20 + 1, int32(kMaxScrollSpeed)) : qMax(_draggingScrollDelta * 3 / 20 - 1, -int32(kMaxScrollSpeed));
void BoxContent::draggingScrollTimerCallback() {
const auto delta = (_draggingScrollDelta > 0)
? qMin(_draggingScrollDelta * 3 / 20 + 1, int32(kMaxScrollSpeed))
: qMax(_draggingScrollDelta * 3 / 20 - 1, -int32(kMaxScrollSpeed));
_scroll->scrollToY(_scroll->scrollTop() + delta);
}
void BoxContent::updateInnerVisibleTopBottom() {
if (auto widget = static_cast<TWidget*>(_scroll ? _scroll->widget() : nullptr)) {
auto top = _scroll->scrollTop();
const auto widget = static_cast<TWidget*>(_scroll
? _scroll->widget()
: nullptr);
if (widget) {
const auto top = _scroll->scrollTop();
widget->setVisibleTopBottom(top, top + _scroll->height());
}
}
void BoxContent::updateShadowsVisibility() {
if (!_scroll) return;
if (!_scroll) {
return;
}
auto top = _scroll->scrollTop();
const auto top = _scroll->scrollTop();
_topShadow->toggle(
(top > 0 || _innerTopSkip > 0),
anim::type::normal);
@ -152,16 +161,6 @@ void BoxContent::updateShadowsVisibility() {
anim::type::normal);
}
void BoxContent::onScroll() {
updateInnerVisibleTopBottom();
updateShadowsVisibility();
}
void BoxContent::onInnerResize() {
updateInnerVisibleTopBottom();
updateShadowsVisibility();
}
void BoxContent::setDimensionsToContent(
int newWidth,
not_null<RpWidget*> content) {
@ -174,7 +173,7 @@ void BoxContent::setDimensionsToContent(
void BoxContent::setInnerTopSkip(int innerTopSkip, bool scrollBottomFixed) {
if (_innerTopSkip != innerTopSkip) {
auto delta = innerTopSkip - _innerTopSkip;
const auto delta = innerTopSkip - _innerTopSkip;
_innerTopSkip = innerTopSkip;
if (_scroll && width() > 0) {
auto scrollTopWas = _scroll->scrollTop();
@ -202,13 +201,21 @@ void BoxContent::setInnerVisible(bool scrollAreaVisible) {
}
QPixmap BoxContent::grabInnerCache() {
auto isTopShadowVisible = !_topShadow->isHidden();
auto isBottomShadowVisible = !_bottomShadow->isHidden();
if (isTopShadowVisible) _topShadow->setVisible(false);
if (isBottomShadowVisible) _bottomShadow->setVisible(false);
auto result = GrabWidget(this, _scroll->geometry());
if (isTopShadowVisible) _topShadow->setVisible(true);
if (isBottomShadowVisible) _bottomShadow->setVisible(true);
const auto isTopShadowVisible = !_topShadow->isHidden();
const auto isBottomShadowVisible = !_bottomShadow->isHidden();
if (isTopShadowVisible) {
_topShadow->setVisible(false);
}
if (isBottomShadowVisible) {
_bottomShadow->setVisible(false);
}
const auto result = GrabWidget(this, _scroll->geometry());
if (isTopShadowVisible) {
_topShadow->setVisible(true);
}
if (isBottomShadowVisible) {
_bottomShadow->setVisible(true);
}
return result;
}
@ -227,8 +234,8 @@ void BoxContent::keyPressEvent(QKeyEvent *e) {
}
void BoxContent::updateScrollAreaGeometry() {
auto newScrollHeight = height() - _innerTopSkip - _innerBottomSkip;
auto changed = (_scroll->height() != newScrollHeight);
const auto newScrollHeight = height() - _innerTopSkip - _innerBottomSkip;
const auto changed = (_scroll->height() != newScrollHeight);
_scroll->setGeometryToLeft(0, _innerTopSkip, width(), newScrollHeight);
_topShadow->entity()->resize(width(), st::lineWidth);
_topShadow->moveToLeft(0, _innerTopSkip);
@ -239,7 +246,7 @@ void BoxContent::updateScrollAreaGeometry() {
if (changed) {
updateInnerVisibleTopBottom();
auto top = _scroll->scrollTop();
const auto top = _scroll->scrollTop();
_topShadow->toggle(
(top > 0 || _innerTopSkip > 0),
anim::type::instant);

View file

@ -18,6 +18,10 @@
enum class RectPart;
using RectParts = base::flags<RectPart>;
namespace base {
class Timer;
} // namespace base
namespace style {
struct RoundButton;
struct IconButton;
@ -97,7 +101,6 @@ public:
};
class BoxContent : public RpWidget {
Q_OBJECT
public:
BoxContent() {
@ -211,7 +214,6 @@ public:
void scrollByDraggingDelta(int delta);
public Q_SLOTS:
void onScrollToY(int top, int bottom = -1);
protected:
@ -274,12 +276,6 @@ protected:
void paintEvent(QPaintEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
private Q_SLOTS:
void onScroll();
void onInnerResize();
void onDraggingScrollTimer();
private:
void finishPrepare();
void finishScrollCreate();
@ -290,6 +286,8 @@ private:
void updateShadowsVisibility();
object_ptr<TWidget> doTakeInnerWidget();
void draggingScrollTimerCallback();
BoxContentDelegate *_delegate = nullptr;
bool _preparing = false;
@ -301,7 +299,7 @@ private:
object_ptr<FadeShadow> _topShadow = { nullptr };
object_ptr<FadeShadow> _bottomShadow = { nullptr };
object_ptr<QTimer> _draggingScrollTimer = { nullptr };
std::unique_ptr<base::Timer> _draggingScrollTimer;
int _draggingScrollDelta = 0;
rpl::event_stream<> _boxClosingStream;