mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-09-05 00:46:08 +00:00
Support chat preview on touchscreens.
This commit is contained in:
@@ -1316,6 +1316,9 @@ void InnerWidget::paintSearchInTopic(
|
||||
}
|
||||
|
||||
void InnerWidget::mouseMoveEvent(QMouseEvent *e) {
|
||||
if (_chatPreviewTouchGlobal) {
|
||||
return;
|
||||
}
|
||||
const auto globalPosition = e->globalPos();
|
||||
if (!_lastMousePosition) {
|
||||
_lastMousePosition = globalPosition;
|
||||
@@ -1333,6 +1336,8 @@ void InnerWidget::mouseMoveEvent(QMouseEvent *e) {
|
||||
void InnerWidget::cancelChatPreview() {
|
||||
_chatPreviewTimer.cancel();
|
||||
_chatPreviewWillBeFor = {};
|
||||
_chatPreviewTouchLocal = {};
|
||||
_chatPreviewTouchGlobal = {};
|
||||
}
|
||||
|
||||
void InnerWidget::clearIrrelevantState() {
|
||||
@@ -2396,10 +2401,14 @@ void InnerWidget::fillArchiveSearchMenu(not_null<Ui::PopupMenu*> menu) {
|
||||
|
||||
void InnerWidget::showChatPreview(bool onlyUserpic) {
|
||||
const auto key = base::take(_chatPreviewWillBeFor);
|
||||
const auto touchGlobal = base::take(_chatPreviewTouchGlobal);
|
||||
cancelChatPreview();
|
||||
if (!pressShowsPreview(onlyUserpic) || key != computeChatPreviewRow()) {
|
||||
return;
|
||||
}
|
||||
if (onlyUserpic && touchGlobal) {
|
||||
_touchCancelRequests.fire({});
|
||||
}
|
||||
ClickHandler::unpressed();
|
||||
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) {
|
||||
if (_searchState == state) {
|
||||
return;
|
||||
|
Reference in New Issue
Block a user