Removed Q_OBJECT from ScrollArea.
This commit is contained in:
parent
b64f68dca6
commit
7182fad08a
4 changed files with 60 additions and 52 deletions
|
|
@ -17,6 +17,8 @@
|
||||||
#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) {
|
||||||
|
|
@ -85,8 +87,14 @@ void BoxContent::finishScrollCreate() {
|
||||||
_scroll->show();
|
_scroll->show();
|
||||||
}
|
}
|
||||||
updateScrollAreaGeometry();
|
updateScrollAreaGeometry();
|
||||||
connect(_scroll, SIGNAL(scrolled()), this, SLOT(onScroll()));
|
_scroll->scrolls(
|
||||||
connect(_scroll, SIGNAL(innerResized()), this, SLOT(onInnerResize()));
|
) | rpl::start_with_next([=] {
|
||||||
|
onScroll();
|
||||||
|
}, lifetime());
|
||||||
|
_scroll->innerResizes(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
onInnerResize();
|
||||||
|
}, lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoxContent::scrollToWidget(not_null<QWidget*> widget) {
|
void BoxContent::scrollToWidget(not_null<QWidget*> widget) {
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,10 @@ InnerDropdown::InnerDropdown(
|
||||||
, _roundRect(ImageRoundRadius::Small, _st.bg)
|
, _roundRect(ImageRoundRadius::Small, _st.bg)
|
||||||
, _hideTimer([=] { hideAnimated(); })
|
, _hideTimer([=] { hideAnimated(); })
|
||||||
, _scroll(this, _st.scroll) {
|
, _scroll(this, _st.scroll) {
|
||||||
connect(_scroll, &ScrollArea::scrolled, [=] { scrolled(); });
|
_scroll->scrolls(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
scrolled();
|
||||||
|
}, lifetime());
|
||||||
|
|
||||||
hide();
|
hide();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,11 @@ ScrollBar::ScrollBar(ScrollArea *parent, bool vert, const style::ScrollArea *st)
|
||||||
recountSize();
|
recountSize();
|
||||||
|
|
||||||
connect(_connected, &QAbstractSlider::valueChanged, [=] {
|
connect(_connected, &QAbstractSlider::valueChanged, [=] {
|
||||||
area()->onScrolled();
|
area()->scrolled();
|
||||||
updateBar();
|
updateBar();
|
||||||
});
|
});
|
||||||
connect(_connected, &QAbstractSlider::rangeChanged, [=] {
|
connect(_connected, &QAbstractSlider::rangeChanged, [=] {
|
||||||
area()->onInnerResized();
|
area()->innerResized();
|
||||||
updateBar();
|
updateBar();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -266,7 +266,6 @@ void ScrollBar::mousePressEvent(QMouseEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
area()->setMovingByScrollBar(true);
|
area()->setMovingByScrollBar(true);
|
||||||
area()->scrollStarted();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollBar::mouseReleaseEvent(QMouseEvent *e) {
|
void ScrollBar::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
|
|
@ -274,7 +273,6 @@ void ScrollBar::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
setMoving(false);
|
setMoving(false);
|
||||||
|
|
||||||
area()->setMovingByScrollBar(false);
|
area()->setMovingByScrollBar(false);
|
||||||
area()->scrollFinished();
|
|
||||||
}
|
}
|
||||||
if (!_over) {
|
if (!_over) {
|
||||||
setMouseTracking(false);
|
setMouseTracking(false);
|
||||||
|
|
@ -306,7 +304,7 @@ ScrollArea::ScrollArea(QWidget *parent, const style::ScrollArea &st, bool handle
|
||||||
((data.type == ScrollShadow::Type::Top)
|
((data.type == ScrollShadow::Type::Top)
|
||||||
? _topShadow
|
? _topShadow
|
||||||
: _bottomShadow)->changeVisibility(data.visible);
|
: _bottomShadow)->changeVisibility(data.visible);
|
||||||
}, _lifetime);
|
}, lifetime());
|
||||||
|
|
||||||
_verticalBar->updateBar(true);
|
_verticalBar->updateBar(true);
|
||||||
|
|
||||||
|
|
@ -324,9 +322,8 @@ ScrollArea::ScrollArea(QWidget *parent, const style::ScrollArea &st, bool handle
|
||||||
|
|
||||||
if (_touchEnabled) {
|
if (_touchEnabled) {
|
||||||
viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
|
viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
|
||||||
_touchTimer.setSingleShot(true);
|
_touchTimer.setCallback([=] { _touchRightButton = true; });
|
||||||
connect(&_touchTimer, SIGNAL(timeout()), this, SLOT(onTouchTimer()));
|
_touchScrollTimer.setCallback([=] { touchScrollTimer(); });
|
||||||
connect(&_touchScrollTimer, SIGNAL(timeout()), this, SLOT(onTouchScrollTimer()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -337,7 +334,7 @@ void ScrollArea::touchDeaccelerate(int32 elapsed) {
|
||||||
_touchSpeed.setY((y == 0) ? y : (y > 0) ? qMax(0, y - elapsed) : qMin(0, y + elapsed));
|
_touchSpeed.setY((y == 0) ? y : (y > 0) ? qMax(0, y - elapsed) : qMin(0, y + elapsed));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollArea::onScrolled() {
|
void ScrollArea::scrolled() {
|
||||||
if (const auto inner = widget()) {
|
if (const auto inner = widget()) {
|
||||||
SendPendingMoveResizeEvents(inner);
|
SendPendingMoveResizeEvents(inner);
|
||||||
}
|
}
|
||||||
|
|
@ -369,15 +366,15 @@ void ScrollArea::onScrolled() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (em) {
|
if (em) {
|
||||||
scrolled();
|
_scrolls.fire({});
|
||||||
if (!_movingByScrollBar) {
|
if (!_movingByScrollBar) {
|
||||||
SendSynteticMouseEvent(this, QEvent::MouseMove, Qt::NoButton);
|
SendSynteticMouseEvent(this, QEvent::MouseMove, Qt::NoButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollArea::onInnerResized() {
|
void ScrollArea::innerResized() {
|
||||||
innerResized();
|
_innerResizes.fire({});
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScrollArea::scrollWidth() const {
|
int ScrollArea::scrollWidth() const {
|
||||||
|
|
@ -406,11 +403,7 @@ int ScrollArea::scrollTop() const {
|
||||||
return _verticalValue;
|
return _verticalValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollArea::onTouchTimer() {
|
void ScrollArea::touchScrollTimer() {
|
||||||
_touchRightButton = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScrollArea::onTouchScrollTimer() {
|
|
||||||
auto nowTime = crl::now();
|
auto nowTime = crl::now();
|
||||||
if (_touchScrollState == TouchScrollState::Acceleration && _touchWaitingAcceleration && (nowTime - _touchAccelerationTime) > 40) {
|
if (_touchScrollState == TouchScrollState::Acceleration && _touchWaitingAcceleration && (nowTime - _touchAccelerationTime) > 40) {
|
||||||
_touchScrollState = TouchScrollState::Manual;
|
_touchScrollState = TouchScrollState::Manual;
|
||||||
|
|
@ -423,7 +416,7 @@ void ScrollArea::onTouchScrollTimer() {
|
||||||
if (_touchSpeed.isNull() || !hasScrolled) {
|
if (_touchSpeed.isNull() || !hasScrolled) {
|
||||||
_touchScrollState = TouchScrollState::Manual;
|
_touchScrollState = TouchScrollState::Manual;
|
||||||
_touchScroll = false;
|
_touchScroll = false;
|
||||||
_touchScrollTimer.stop();
|
_touchScrollTimer.cancel();
|
||||||
} else {
|
} else {
|
||||||
_touchTime = nowTime;
|
_touchTime = nowTime;
|
||||||
}
|
}
|
||||||
|
|
@ -518,7 +511,7 @@ void ScrollArea::touchEvent(QTouchEvent *e) {
|
||||||
_touchStart = _touchPos;
|
_touchStart = _touchPos;
|
||||||
} else {
|
} else {
|
||||||
_touchScroll = false;
|
_touchScroll = false;
|
||||||
_touchTimer.start(QApplication::startDragTime());
|
_touchTimer.callOnce(QApplication::startDragTime());
|
||||||
}
|
}
|
||||||
_touchStart = _touchPrevPos = _touchPos;
|
_touchStart = _touchPrevPos = _touchPos;
|
||||||
_touchRightButton = false;
|
_touchRightButton = false;
|
||||||
|
|
@ -527,7 +520,7 @@ void ScrollArea::touchEvent(QTouchEvent *e) {
|
||||||
case QEvent::TouchUpdate: {
|
case QEvent::TouchUpdate: {
|
||||||
if (!_touchPress) return;
|
if (!_touchPress) return;
|
||||||
if (!_touchScroll && (_touchPos - _touchStart).manhattanLength() >= QApplication::startDragDistance()) {
|
if (!_touchScroll && (_touchPos - _touchStart).manhattanLength() >= QApplication::startDragDistance()) {
|
||||||
_touchTimer.stop();
|
_touchTimer.cancel();
|
||||||
_touchScroll = true;
|
_touchScroll = true;
|
||||||
touchUpdateSpeed();
|
touchUpdateSpeed();
|
||||||
}
|
}
|
||||||
|
|
@ -552,7 +545,7 @@ void ScrollArea::touchEvent(QTouchEvent *e) {
|
||||||
if (_touchScrollState == TouchScrollState::Manual) {
|
if (_touchScrollState == TouchScrollState::Manual) {
|
||||||
_touchScrollState = TouchScrollState::Auto;
|
_touchScrollState = TouchScrollState::Auto;
|
||||||
_touchPrevPosValid = false;
|
_touchPrevPosValid = false;
|
||||||
_touchScrollTimer.start(15);
|
_touchScrollTimer.callEach(15);
|
||||||
_touchTime = crl::now();
|
_touchTime = crl::now();
|
||||||
} else if (_touchScrollState == TouchScrollState::Auto) {
|
} else if (_touchScrollState == TouchScrollState::Auto) {
|
||||||
_touchScrollState = TouchScrollState::Manual;
|
_touchScrollState = TouchScrollState::Manual;
|
||||||
|
|
@ -579,7 +572,7 @@ void ScrollArea::touchEvent(QTouchEvent *e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (weak) {
|
if (weak) {
|
||||||
_touchTimer.stop();
|
_touchTimer.cancel();
|
||||||
_touchRightButton = false;
|
_touchRightButton = false;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
@ -588,7 +581,7 @@ void ScrollArea::touchEvent(QTouchEvent *e) {
|
||||||
_touchPress = false;
|
_touchPress = false;
|
||||||
_touchScroll = false;
|
_touchScroll = false;
|
||||||
_touchScrollState = TouchScrollState::Manual;
|
_touchScrollState = TouchScrollState::Manual;
|
||||||
_touchTimer.stop();
|
_touchTimer.cancel();
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -628,12 +621,12 @@ void ScrollArea::resizeEvent(QResizeEvent *e) {
|
||||||
_verticalBar->recountSize();
|
_verticalBar->recountSize();
|
||||||
_topShadow->setGeometry(QRect(0, 0, width(), qAbs(_st.topsh)));
|
_topShadow->setGeometry(QRect(0, 0, width(), qAbs(_st.topsh)));
|
||||||
_bottomShadow->setGeometry(QRect(0, height() - qAbs(_st.bottomsh), width(), qAbs(_st.bottomsh)));
|
_bottomShadow->setGeometry(QRect(0, height() - qAbs(_st.bottomsh), width(), qAbs(_st.bottomsh)));
|
||||||
geometryChanged();
|
_geometryChanged.fire({});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollArea::moveEvent(QMoveEvent *e) {
|
void ScrollArea::moveEvent(QMoveEvent *e) {
|
||||||
QScrollArea::moveEvent(e);
|
QScrollArea::moveEvent(e);
|
||||||
geometryChanged();
|
_geometryChanged.fire({});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollArea::keyPressEvent(QKeyEvent *e) {
|
void ScrollArea::keyPressEvent(QKeyEvent *e) {
|
||||||
|
|
@ -748,4 +741,16 @@ void ScrollArea::setMovingByScrollBar(bool movingByScrollBar) {
|
||||||
_movingByScrollBar = movingByScrollBar;
|
_movingByScrollBar = movingByScrollBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<> ScrollArea::scrolls() const {
|
||||||
|
return _scrolls.events();
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<> ScrollArea::innerResizes() const {
|
||||||
|
return _innerResizes.events();
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<> ScrollArea::geometryChanged() const {
|
||||||
|
return _geometryChanged.events();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@
|
||||||
#include "styles/style_widgets.h"
|
#include "styles/style_widgets.h"
|
||||||
|
|
||||||
#include <QtWidgets/QScrollArea>
|
#include <QtWidgets/QScrollArea>
|
||||||
#include <QtCore/QTimer>
|
|
||||||
#include <QtGui/QtEvents>
|
#include <QtGui/QtEvents>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
@ -127,10 +126,8 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
class ScrollArea : public RpWidgetBase<QScrollArea> {
|
class ScrollArea : public RpWidgetBase<QScrollArea> {
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
using Parent = RpWidgetBase<QScrollArea>;
|
|
||||||
public:
|
public:
|
||||||
|
using Parent = RpWidgetBase<QScrollArea>;
|
||||||
ScrollArea(QWidget *parent, const style::ScrollArea &st = st::defaultScrollArea, bool handleTouch = true);
|
ScrollArea(QWidget *parent, const style::ScrollArea &st = st::defaultScrollArea, bool handleTouch = true);
|
||||||
|
|
||||||
int scrollWidth() const;
|
int scrollWidth() const;
|
||||||
|
|
@ -172,6 +169,15 @@ public:
|
||||||
void scrollTo(ScrollToRequest request);
|
void scrollTo(ScrollToRequest request);
|
||||||
void scrollToWidget(not_null<QWidget*> widget);
|
void scrollToWidget(not_null<QWidget*> widget);
|
||||||
|
|
||||||
|
void scrollToY(int toTop, int toBottom = -1);
|
||||||
|
void disableScroll(bool dis);
|
||||||
|
void scrolled();
|
||||||
|
void innerResized();
|
||||||
|
|
||||||
|
[[nodiscard]] rpl::producer<> scrolls() const;
|
||||||
|
[[nodiscard]] rpl::producer<> innerResizes() const;
|
||||||
|
[[nodiscard]] rpl::producer<> geometryChanged() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *obj, QEvent *e) override;
|
bool eventFilter(QObject *obj, QEvent *e) override;
|
||||||
|
|
||||||
|
|
@ -182,22 +188,6 @@ protected:
|
||||||
void enterEventHook(QEvent *e) override;
|
void enterEventHook(QEvent *e) override;
|
||||||
void leaveEventHook(QEvent *e) override;
|
void leaveEventHook(QEvent *e) override;
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
void scrollToY(int toTop, int toBottom = -1);
|
|
||||||
void disableScroll(bool dis);
|
|
||||||
void onScrolled();
|
|
||||||
void onInnerResized();
|
|
||||||
|
|
||||||
void onTouchTimer();
|
|
||||||
void onTouchScrollTimer();
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void scrolled();
|
|
||||||
void innerResized();
|
|
||||||
void scrollStarted();
|
|
||||||
void scrollFinished();
|
|
||||||
void geometryChanged();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void scrollContentsBy(int dx, int dy) override;
|
void scrollContentsBy(int dx, int dy) override;
|
||||||
|
|
||||||
|
|
@ -207,8 +197,8 @@ private:
|
||||||
|
|
||||||
void setWidget(QWidget *widget);
|
void setWidget(QWidget *widget);
|
||||||
|
|
||||||
|
void touchScrollTimer();
|
||||||
bool touchScroll(const QPoint &delta);
|
bool touchScroll(const QPoint &delta);
|
||||||
|
|
||||||
void touchScrollUpdated(const QPoint &screenPos);
|
void touchScrollUpdated(const QPoint &screenPos);
|
||||||
|
|
||||||
void touchResetSpeed();
|
void touchResetSpeed();
|
||||||
|
|
@ -224,7 +214,7 @@ private:
|
||||||
int _horizontalValue, _verticalValue;
|
int _horizontalValue, _verticalValue;
|
||||||
|
|
||||||
bool _touchEnabled;
|
bool _touchEnabled;
|
||||||
QTimer _touchTimer;
|
base::Timer _touchTimer;
|
||||||
bool _touchScroll = false;
|
bool _touchScroll = false;
|
||||||
bool _touchPress = false;
|
bool _touchPress = false;
|
||||||
bool _touchRightButton = false;
|
bool _touchRightButton = false;
|
||||||
|
|
@ -237,14 +227,16 @@ private:
|
||||||
crl::time _touchSpeedTime = 0;
|
crl::time _touchSpeedTime = 0;
|
||||||
crl::time _touchAccelerationTime = 0;
|
crl::time _touchAccelerationTime = 0;
|
||||||
crl::time _touchTime = 0;
|
crl::time _touchTime = 0;
|
||||||
QTimer _touchScrollTimer;
|
base::Timer _touchScrollTimer;
|
||||||
|
|
||||||
bool _widgetAcceptsTouch = false;
|
bool _widgetAcceptsTouch = false;
|
||||||
|
|
||||||
object_ptr<QWidget> _widget = { nullptr };
|
object_ptr<QWidget> _widget = { nullptr };
|
||||||
|
|
||||||
rpl::event_stream<int> _scrollTopUpdated;
|
rpl::event_stream<int> _scrollTopUpdated;
|
||||||
rpl::lifetime _lifetime;
|
rpl::event_stream<> _scrolls;
|
||||||
|
rpl::event_stream<> _innerResizes;
|
||||||
|
rpl::event_stream<> _geometryChanged;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue