2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-09-02 23:45:44 +00:00

Empty preview widget on long userpic press.

This commit is contained in:
John Preston
2024-05-02 19:39:36 +04:00
parent ef2aa05197
commit 4427ae4306
6 changed files with 234 additions and 7 deletions

View File

@@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "dialogs/dialogs_widget.h"
#include "dialogs/dialogs_search_from_controllers.h"
#include "dialogs/dialogs_search_tags.h"
#include "history/view/history_view_chat_preview.h"
#include "history/view/history_view_context_menu.h"
#include "history/history.h"
#include "history/history_item.h"
@@ -80,6 +81,7 @@ namespace {
constexpr auto kHashtagResultsLimit = 5;
constexpr auto kStartReorderThreshold = 30;
constexpr auto kChatPreviewDelay = crl::time(1000);
int FixedOnTopDialogsCount(not_null<Dialogs::IndexedList*> list) {
auto result = 0;
@@ -157,6 +159,7 @@ InnerWidget::InnerWidget(
+ st::defaultDialogRow.padding.left())
, _cancelSearchInChat(this, st::dialogsCancelSearchInPeer)
, _cancelSearchFromUser(this, st::dialogsCancelSearchInPeer)
, _chatPreviewTimer([=] { showChatPreview(); })
, _childListShown(std::move(childListShown)) {
setAttribute(Qt::WA_OpaquePaintEvent, true);
@@ -651,6 +654,8 @@ void InnerWidget::paintEvent(QPaintEvent *e) {
context.active = active;
context.selected = _menuRow.key
? (row->key() == _menuRow.key)
: _chatPreviewKey
? (row->key() == _chatPreviewKey)
: selected;
context.topicJumpSelected = selected
&& _selectedTopicJump
@@ -1268,6 +1273,14 @@ void InnerWidget::mouseMoveEvent(QMouseEvent *e) {
return;
}
selectByMouse(globalPosition);
if (!isUserpicPress()) {
cancelChatPreview();
}
}
void InnerWidget::cancelChatPreview() {
_chatPreviewTimer.cancel();
_chatPreviewWillBeFor = {};
}
void InnerWidget::clearIrrelevantState() {
@@ -1490,11 +1503,15 @@ void InnerWidget::mousePressEvent(QMouseEvent *e) {
row->repaint());
}
ClickHandler::pressed();
if (anim::Disabled()
if (pressShowsPreview()) {
_chatPreviewWillBeFor = computeChosenRow().key;
_chatPreviewTimer.callOnce(kChatPreviewDelay);
} else if (anim::Disabled()
&& (!_pressed || !_pressed->entry()->isPinnedDialog(_filterId))) {
mousePressReleased(e->globalPos(), e->button(), e->modifiers());
}
}
const std::vector<Key> &InnerWidget::pinnedChatsOrder() const {
const auto owner = &session().data();
return _savedSublists
@@ -1513,6 +1530,7 @@ void InnerWidget::checkReorderPinnedStart(QPoint localPosition) {
< style::ConvertScale(kStartReorderThreshold)) {
return;
}
cancelChatPreview();
_dragging = _pressed;
if (updateReorderIndexGetCount() < 2) {
_dragging = nullptr;
@@ -2288,6 +2306,33 @@ void InnerWidget::fillArchiveSearchMenu(not_null<Ui::PopupMenu*> menu) {
});
}
void InnerWidget::showChatPreview() {
const auto key = base::take(_chatPreviewWillBeFor);
cancelChatPreview();
if (!pressShowsPreview() || key != computeChosenRow().key) {
return;
}
ClickHandler::unpressed();
mousePressReleased(QCursor::pos(), Qt::NoButton, Qt::NoModifier);
_chatPreviewKey = key;
_menu = HistoryView::MakeChatPreview(this, key.entry());
if (!_menu) {
return;
}
QObject::connect(_menu.get(), &QObject::destroyed, [=] {
if (_chatPreviewKey) {
updateDialogRow(RowDescriptor(base::take(_chatPreviewKey), {}));
}
const auto globalPosition = QCursor::pos();
if (rect().contains(mapFromGlobal(globalPosition))) {
setMouseTracking(true);
selectByMouse(globalPosition);
}
});
_menu->popup(_lastMousePosition.value_or(QCursor::pos()));
}
void InnerWidget::contextMenuEvent(QContextMenuEvent *e) {
_menu = nullptr;
@@ -2316,7 +2361,9 @@ void InnerWidget::contextMenuEvent(QContextMenuEvent *e) {
}
return RowDescriptor();
}();
if (!row.key) return;
if (!row.key) {
return;
}
_menuRow = row;
if (_pressButton != Qt::LeftButton) {
@@ -2555,6 +2602,12 @@ void InnerWidget::trackSearchResultsHistory(not_null<History*> history) {
refresh();
clearMouseSelection(true);
}
if (_chatPreviewWillBeFor.topic() == topic) {
_chatPreviewWillBeFor = {};
}
if (_chatPreviewKey.topic() == topic) {
_chatPreviewKey = {};
}
}, _searchResultsLifetime);
}
}
@@ -3499,6 +3552,23 @@ ChosenRow InnerWidget::computeChosenRow() const {
return ChosenRow();
}
bool InnerWidget::isUserpicPress() const {
return (_lastRowLocalMouseX >= 0)
&& (_lastRowLocalMouseX < _st->nameLeft)
&& (width() > _narrowWidth);
}
bool InnerWidget::pressShowsPreview() const {
if (!isUserpicPress()) {
return false;
}
const auto key = computeChosenRow().key;
if (const auto history = key.history()) {
return !history->peer->isForum();
}
return key.topic() != nullptr;;
}
bool InnerWidget::chooseRow(
Qt::KeyboardModifiers modifiers,
MsgId pressedTopicRootId) {
@@ -3511,9 +3581,7 @@ bool InnerWidget::chooseRow(
ChosenRow row,
Qt::KeyboardModifiers modifiers) {
row.newWindow = (modifiers & Qt::ControlModifier);
row.userpicClick = (_lastRowLocalMouseX >= 0)
&& (_lastRowLocalMouseX < _st->nameLeft)
&& (width() > _narrowWidth);
row.userpicClick = isUserpicPress();
return row;
};
auto chosen = modifyChosenRow(computeChosenRow(), modifiers);