Removed Q_OBJECT from BoxContent.
This commit is contained in:
parent
b69fcf6048
commit
c369eb13bf
2 changed files with 51 additions and 46 deletions
|
|
@ -18,8 +18,6 @@
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
#include "styles/palette.h"
|
#include "styles/palette.h"
|
||||||
|
|
||||||
#include <QtCore/QTimer>
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
||||||
void BoxContent::setTitle(rpl::producer<QString> title) {
|
void BoxContent::setTitle(rpl::producer<QString> title) {
|
||||||
|
|
@ -48,7 +46,9 @@ void BoxContent::setInner(object_ptr<TWidget> inner) {
|
||||||
setInner(std::move(inner), st::boxScroll);
|
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) {
|
if (inner) {
|
||||||
getDelegate()->setLayerType(true);
|
getDelegate()->setLayerType(true);
|
||||||
_scroll.create(this, st);
|
_scroll.create(this, st);
|
||||||
|
|
@ -90,11 +90,13 @@ void BoxContent::finishScrollCreate() {
|
||||||
updateScrollAreaGeometry();
|
updateScrollAreaGeometry();
|
||||||
_scroll->scrolls(
|
_scroll->scrolls(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
onScroll();
|
updateInnerVisibleTopBottom();
|
||||||
|
updateShadowsVisibility();
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
_scroll->innerResizes(
|
_scroll->innerResizes(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
onInnerResize();
|
updateInnerVisibleTopBottom();
|
||||||
|
updateShadowsVisibility();
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,32 +120,39 @@ void BoxContent::scrollByDraggingDelta(int delta) {
|
||||||
_draggingScrollDelta = _scroll ? delta : 0;
|
_draggingScrollDelta = _scroll ? delta : 0;
|
||||||
if (_draggingScrollDelta) {
|
if (_draggingScrollDelta) {
|
||||||
if (!_draggingScrollTimer) {
|
if (!_draggingScrollTimer) {
|
||||||
_draggingScrollTimer.create(this);
|
_draggingScrollTimer = std::make_unique<base::Timer>([=] {
|
||||||
_draggingScrollTimer->setSingleShot(false);
|
draggingScrollTimerCallback();
|
||||||
connect(_draggingScrollTimer, SIGNAL(timeout()), this, SLOT(onDraggingScrollTimer()));
|
});
|
||||||
}
|
}
|
||||||
_draggingScrollTimer->start(15);
|
_draggingScrollTimer->callEach(15);
|
||||||
} else {
|
} else {
|
||||||
_draggingScrollTimer.destroy();
|
_draggingScrollTimer = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxContent::onDraggingScrollTimer() {
|
void BoxContent::draggingScrollTimerCallback() {
|
||||||
auto delta = (_draggingScrollDelta > 0) ? qMin(_draggingScrollDelta * 3 / 20 + 1, int32(kMaxScrollSpeed)) : qMax(_draggingScrollDelta * 3 / 20 - 1, -int32(kMaxScrollSpeed));
|
const auto delta = (_draggingScrollDelta > 0)
|
||||||
|
? qMin(_draggingScrollDelta * 3 / 20 + 1, int32(kMaxScrollSpeed))
|
||||||
|
: qMax(_draggingScrollDelta * 3 / 20 - 1, -int32(kMaxScrollSpeed));
|
||||||
_scroll->scrollToY(_scroll->scrollTop() + delta);
|
_scroll->scrollToY(_scroll->scrollTop() + delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxContent::updateInnerVisibleTopBottom() {
|
void BoxContent::updateInnerVisibleTopBottom() {
|
||||||
if (auto widget = static_cast<TWidget*>(_scroll ? _scroll->widget() : nullptr)) {
|
const auto widget = static_cast<TWidget*>(_scroll
|
||||||
auto top = _scroll->scrollTop();
|
? _scroll->widget()
|
||||||
|
: nullptr);
|
||||||
|
if (widget) {
|
||||||
|
const auto top = _scroll->scrollTop();
|
||||||
widget->setVisibleTopBottom(top, top + _scroll->height());
|
widget->setVisibleTopBottom(top, top + _scroll->height());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxContent::updateShadowsVisibility() {
|
void BoxContent::updateShadowsVisibility() {
|
||||||
if (!_scroll) return;
|
if (!_scroll) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto top = _scroll->scrollTop();
|
const auto top = _scroll->scrollTop();
|
||||||
_topShadow->toggle(
|
_topShadow->toggle(
|
||||||
(top > 0 || _innerTopSkip > 0),
|
(top > 0 || _innerTopSkip > 0),
|
||||||
anim::type::normal);
|
anim::type::normal);
|
||||||
|
|
@ -152,16 +161,6 @@ void BoxContent::updateShadowsVisibility() {
|
||||||
anim::type::normal);
|
anim::type::normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxContent::onScroll() {
|
|
||||||
updateInnerVisibleTopBottom();
|
|
||||||
updateShadowsVisibility();
|
|
||||||
}
|
|
||||||
|
|
||||||
void BoxContent::onInnerResize() {
|
|
||||||
updateInnerVisibleTopBottom();
|
|
||||||
updateShadowsVisibility();
|
|
||||||
}
|
|
||||||
|
|
||||||
void BoxContent::setDimensionsToContent(
|
void BoxContent::setDimensionsToContent(
|
||||||
int newWidth,
|
int newWidth,
|
||||||
not_null<RpWidget*> content) {
|
not_null<RpWidget*> content) {
|
||||||
|
|
@ -174,7 +173,7 @@ void BoxContent::setDimensionsToContent(
|
||||||
|
|
||||||
void BoxContent::setInnerTopSkip(int innerTopSkip, bool scrollBottomFixed) {
|
void BoxContent::setInnerTopSkip(int innerTopSkip, bool scrollBottomFixed) {
|
||||||
if (_innerTopSkip != innerTopSkip) {
|
if (_innerTopSkip != innerTopSkip) {
|
||||||
auto delta = innerTopSkip - _innerTopSkip;
|
const auto delta = innerTopSkip - _innerTopSkip;
|
||||||
_innerTopSkip = innerTopSkip;
|
_innerTopSkip = innerTopSkip;
|
||||||
if (_scroll && width() > 0) {
|
if (_scroll && width() > 0) {
|
||||||
auto scrollTopWas = _scroll->scrollTop();
|
auto scrollTopWas = _scroll->scrollTop();
|
||||||
|
|
@ -202,13 +201,21 @@ void BoxContent::setInnerVisible(bool scrollAreaVisible) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap BoxContent::grabInnerCache() {
|
QPixmap BoxContent::grabInnerCache() {
|
||||||
auto isTopShadowVisible = !_topShadow->isHidden();
|
const auto isTopShadowVisible = !_topShadow->isHidden();
|
||||||
auto isBottomShadowVisible = !_bottomShadow->isHidden();
|
const auto isBottomShadowVisible = !_bottomShadow->isHidden();
|
||||||
if (isTopShadowVisible) _topShadow->setVisible(false);
|
if (isTopShadowVisible) {
|
||||||
if (isBottomShadowVisible) _bottomShadow->setVisible(false);
|
_topShadow->setVisible(false);
|
||||||
auto result = GrabWidget(this, _scroll->geometry());
|
}
|
||||||
if (isTopShadowVisible) _topShadow->setVisible(true);
|
if (isBottomShadowVisible) {
|
||||||
if (isBottomShadowVisible) _bottomShadow->setVisible(true);
|
_bottomShadow->setVisible(false);
|
||||||
|
}
|
||||||
|
const auto result = GrabWidget(this, _scroll->geometry());
|
||||||
|
if (isTopShadowVisible) {
|
||||||
|
_topShadow->setVisible(true);
|
||||||
|
}
|
||||||
|
if (isBottomShadowVisible) {
|
||||||
|
_bottomShadow->setVisible(true);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -227,8 +234,8 @@ void BoxContent::keyPressEvent(QKeyEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxContent::updateScrollAreaGeometry() {
|
void BoxContent::updateScrollAreaGeometry() {
|
||||||
auto newScrollHeight = height() - _innerTopSkip - _innerBottomSkip;
|
const auto newScrollHeight = height() - _innerTopSkip - _innerBottomSkip;
|
||||||
auto changed = (_scroll->height() != newScrollHeight);
|
const auto changed = (_scroll->height() != newScrollHeight);
|
||||||
_scroll->setGeometryToLeft(0, _innerTopSkip, width(), newScrollHeight);
|
_scroll->setGeometryToLeft(0, _innerTopSkip, width(), newScrollHeight);
|
||||||
_topShadow->entity()->resize(width(), st::lineWidth);
|
_topShadow->entity()->resize(width(), st::lineWidth);
|
||||||
_topShadow->moveToLeft(0, _innerTopSkip);
|
_topShadow->moveToLeft(0, _innerTopSkip);
|
||||||
|
|
@ -239,7 +246,7 @@ void BoxContent::updateScrollAreaGeometry() {
|
||||||
if (changed) {
|
if (changed) {
|
||||||
updateInnerVisibleTopBottom();
|
updateInnerVisibleTopBottom();
|
||||||
|
|
||||||
auto top = _scroll->scrollTop();
|
const auto top = _scroll->scrollTop();
|
||||||
_topShadow->toggle(
|
_topShadow->toggle(
|
||||||
(top > 0 || _innerTopSkip > 0),
|
(top > 0 || _innerTopSkip > 0),
|
||||||
anim::type::instant);
|
anim::type::instant);
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,10 @@
|
||||||
enum class RectPart;
|
enum class RectPart;
|
||||||
using RectParts = base::flags<RectPart>;
|
using RectParts = base::flags<RectPart>;
|
||||||
|
|
||||||
|
namespace base {
|
||||||
|
class Timer;
|
||||||
|
} // namespace base
|
||||||
|
|
||||||
namespace style {
|
namespace style {
|
||||||
struct RoundButton;
|
struct RoundButton;
|
||||||
struct IconButton;
|
struct IconButton;
|
||||||
|
|
@ -97,7 +101,6 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
class BoxContent : public RpWidget {
|
class BoxContent : public RpWidget {
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BoxContent() {
|
BoxContent() {
|
||||||
|
|
@ -211,7 +214,6 @@ public:
|
||||||
|
|
||||||
void scrollByDraggingDelta(int delta);
|
void scrollByDraggingDelta(int delta);
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
void onScrollToY(int top, int bottom = -1);
|
void onScrollToY(int top, int bottom = -1);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -274,12 +276,6 @@ protected:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
void keyPressEvent(QKeyEvent *e) override;
|
void keyPressEvent(QKeyEvent *e) override;
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void onScroll();
|
|
||||||
void onInnerResize();
|
|
||||||
|
|
||||||
void onDraggingScrollTimer();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void finishPrepare();
|
void finishPrepare();
|
||||||
void finishScrollCreate();
|
void finishScrollCreate();
|
||||||
|
|
@ -290,6 +286,8 @@ private:
|
||||||
void updateShadowsVisibility();
|
void updateShadowsVisibility();
|
||||||
object_ptr<TWidget> doTakeInnerWidget();
|
object_ptr<TWidget> doTakeInnerWidget();
|
||||||
|
|
||||||
|
void draggingScrollTimerCallback();
|
||||||
|
|
||||||
BoxContentDelegate *_delegate = nullptr;
|
BoxContentDelegate *_delegate = nullptr;
|
||||||
|
|
||||||
bool _preparing = false;
|
bool _preparing = false;
|
||||||
|
|
@ -301,7 +299,7 @@ private:
|
||||||
object_ptr<FadeShadow> _topShadow = { nullptr };
|
object_ptr<FadeShadow> _topShadow = { nullptr };
|
||||||
object_ptr<FadeShadow> _bottomShadow = { nullptr };
|
object_ptr<FadeShadow> _bottomShadow = { nullptr };
|
||||||
|
|
||||||
object_ptr<QTimer> _draggingScrollTimer = { nullptr };
|
std::unique_ptr<base::Timer> _draggingScrollTimer;
|
||||||
int _draggingScrollDelta = 0;
|
int _draggingScrollDelta = 0;
|
||||||
|
|
||||||
rpl::event_stream<> _boxClosingStream;
|
rpl::event_stream<> _boxClosingStream;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue