mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Support chat preview on touchscreens.
This commit is contained in:
parent
40fbd415ef
commit
4df5372dab
5 changed files with 67 additions and 1 deletions
|
@ -1316,6 +1316,9 @@ void InnerWidget::paintSearchInTopic(
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerWidget::mouseMoveEvent(QMouseEvent *e) {
|
void InnerWidget::mouseMoveEvent(QMouseEvent *e) {
|
||||||
|
if (_chatPreviewTouchGlobal) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const auto globalPosition = e->globalPos();
|
const auto globalPosition = e->globalPos();
|
||||||
if (!_lastMousePosition) {
|
if (!_lastMousePosition) {
|
||||||
_lastMousePosition = globalPosition;
|
_lastMousePosition = globalPosition;
|
||||||
|
@ -1333,6 +1336,8 @@ void InnerWidget::mouseMoveEvent(QMouseEvent *e) {
|
||||||
void InnerWidget::cancelChatPreview() {
|
void InnerWidget::cancelChatPreview() {
|
||||||
_chatPreviewTimer.cancel();
|
_chatPreviewTimer.cancel();
|
||||||
_chatPreviewWillBeFor = {};
|
_chatPreviewWillBeFor = {};
|
||||||
|
_chatPreviewTouchLocal = {};
|
||||||
|
_chatPreviewTouchGlobal = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerWidget::clearIrrelevantState() {
|
void InnerWidget::clearIrrelevantState() {
|
||||||
|
@ -2396,10 +2401,14 @@ void InnerWidget::fillArchiveSearchMenu(not_null<Ui::PopupMenu*> menu) {
|
||||||
|
|
||||||
void InnerWidget::showChatPreview(bool onlyUserpic) {
|
void InnerWidget::showChatPreview(bool onlyUserpic) {
|
||||||
const auto key = base::take(_chatPreviewWillBeFor);
|
const auto key = base::take(_chatPreviewWillBeFor);
|
||||||
|
const auto touchGlobal = base::take(_chatPreviewTouchGlobal);
|
||||||
cancelChatPreview();
|
cancelChatPreview();
|
||||||
if (!pressShowsPreview(onlyUserpic) || key != computeChatPreviewRow()) {
|
if (!pressShowsPreview(onlyUserpic) || key != computeChatPreviewRow()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (onlyUserpic && touchGlobal) {
|
||||||
|
_touchCancelRequests.fire({});
|
||||||
|
}
|
||||||
ClickHandler::unpressed();
|
ClickHandler::unpressed();
|
||||||
mousePressReleased(QCursor::pos(), Qt::NoButton, Qt::NoModifier);
|
mousePressReleased(QCursor::pos(), Qt::NoButton, Qt::NoModifier);
|
||||||
|
|
||||||
|
@ -2538,6 +2547,41 @@ void InnerWidget::parentGeometryChanged() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InnerWidget::processTouchEvent(not_null<QTouchEvent*> e) {
|
||||||
|
const auto point = e->touchPoints().empty()
|
||||||
|
? std::optional<QPoint>()
|
||||||
|
: e->touchPoints().front().screenPos().toPoint();
|
||||||
|
switch (e->type()) {
|
||||||
|
case QEvent::TouchBegin: {
|
||||||
|
if (!point) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
selectByMouse(*point);
|
||||||
|
const auto onlyUserpic = true;
|
||||||
|
if (pressShowsPreview(onlyUserpic)) {
|
||||||
|
_chatPreviewTouchGlobal = point;
|
||||||
|
_chatPreviewWillBeFor = computeChatPreviewRow();
|
||||||
|
_chatPreviewTimer.callOnce(kChatPreviewDelay);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case QEvent::TouchUpdate: {
|
||||||
|
if (!_chatPreviewTouchGlobal || !point) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto delta = (*_chatPreviewTouchGlobal - *point);
|
||||||
|
if (delta.manhattanLength() > _st->photoSize) {
|
||||||
|
cancelChatPreview();
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case QEvent::TouchEnd:
|
||||||
|
case QEvent::TouchCancel: if (_chatPreviewTouchGlobal) {
|
||||||
|
cancelChatPreview();
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void InnerWidget::applySearchState(SearchState state) {
|
void InnerWidget::applySearchState(SearchState state) {
|
||||||
if (_searchState == state) {
|
if (_searchState == state) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -174,6 +174,11 @@ public:
|
||||||
|
|
||||||
void parentGeometryChanged();
|
void parentGeometryChanged();
|
||||||
|
|
||||||
|
void processTouchEvent(not_null<QTouchEvent*> e);
|
||||||
|
[[nodiscard]] rpl::producer<> touchCancelRequests() const {
|
||||||
|
return _touchCancelRequests.events();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void visibleTopBottomUpdated(
|
void visibleTopBottomUpdated(
|
||||||
int visibleTop,
|
int visibleTop,
|
||||||
|
@ -520,6 +525,9 @@ private:
|
||||||
base::Timer _chatPreviewTimer;
|
base::Timer _chatPreviewTimer;
|
||||||
Key _chatPreviewWillBeFor;
|
Key _chatPreviewWillBeFor;
|
||||||
Key _chatPreviewKey;
|
Key _chatPreviewKey;
|
||||||
|
std::optional<QPoint> _chatPreviewTouchLocal;
|
||||||
|
std::optional<QPoint> _chatPreviewTouchGlobal;
|
||||||
|
rpl::event_stream<> _touchCancelRequests;
|
||||||
|
|
||||||
rpl::variable<ChildListShown> _childListShown;
|
rpl::variable<ChildListShown> _childListShown;
|
||||||
float64 _narrowRatio = 0.;
|
float64 _narrowRatio = 0.;
|
||||||
|
|
|
@ -473,6 +473,7 @@ Widget::Widget(
|
||||||
updateSearchFromVisibility(true);
|
updateSearchFromVisibility(true);
|
||||||
setupSupportMode();
|
setupSupportMode();
|
||||||
setupScrollUpButton();
|
setupScrollUpButton();
|
||||||
|
setupTouchChatPreview();
|
||||||
|
|
||||||
const auto overscrollBg = [=] {
|
const auto overscrollBg = [=] {
|
||||||
return anim::color(
|
return anim::color(
|
||||||
|
@ -655,6 +656,18 @@ void Widget::setupScrollUpButton() {
|
||||||
updateScrollUpVisibility();
|
updateScrollUpVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Widget::setupTouchChatPreview() {
|
||||||
|
_scroll->setCustomTouchProcess([=](not_null<QTouchEvent*> e) {
|
||||||
|
_inner->processTouchEvent(e);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
_inner->touchCancelRequests() | rpl::start_with_next([=] {
|
||||||
|
QTouchEvent ev(QEvent::TouchCancel);
|
||||||
|
ev.setTimestamp(crl::now());
|
||||||
|
QGuiApplication::sendEvent(_scroll, &ev);
|
||||||
|
}, _inner->lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
void Widget::setupMoreChatsBar() {
|
void Widget::setupMoreChatsBar() {
|
||||||
if (_layout == Layout::Child) {
|
if (_layout == Layout::Child) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -179,6 +179,7 @@ private:
|
||||||
[[nodiscard]] const std::vector<Data::ReactionId> &searchInTags() const;
|
[[nodiscard]] const std::vector<Data::ReactionId> &searchInTags() const;
|
||||||
|
|
||||||
void setupSupportMode();
|
void setupSupportMode();
|
||||||
|
void setupTouchChatPreview();
|
||||||
void setupConnectingWidget();
|
void setupConnectingWidget();
|
||||||
void setupMainMenuToggle();
|
void setupMainMenuToggle();
|
||||||
void setupMoreChatsBar();
|
void setupMoreChatsBar();
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 495ea0af50da469fb30769ac2d78251e4279a746
|
Subproject commit 33aac93b160d4cd30119c8859de722e28512902b
|
Loading…
Add table
Reference in a new issue