Show chat preview on Alt+Click.

This commit is contained in:
John Preston 2024-05-03 18:30:14 +04:00
parent aee62c7591
commit cd7cfcdf2f
2 changed files with 22 additions and 12 deletions

View file

@ -159,7 +159,7 @@ InnerWidget::InnerWidget(
+ st::defaultDialogRow.padding.left()) + st::defaultDialogRow.padding.left())
, _cancelSearchInChat(this, st::dialogsCancelSearchInPeer) , _cancelSearchInChat(this, st::dialogsCancelSearchInPeer)
, _cancelSearchFromUser(this, st::dialogsCancelSearchInPeer) , _cancelSearchFromUser(this, st::dialogsCancelSearchInPeer)
, _chatPreviewTimer([=] { showChatPreview(); }) , _chatPreviewTimer([=] { showChatPreview(true); })
, _childListShown(std::move(childListShown)) { , _childListShown(std::move(childListShown)) {
setAttribute(Qt::WA_OpaquePaintEvent, true); setAttribute(Qt::WA_OpaquePaintEvent, true);
@ -1435,6 +1435,18 @@ void InnerWidget::mousePressEvent(QMouseEvent *e) {
setFilteredPressed(_filteredSelected, _selectedTopicJump); setFilteredPressed(_filteredSelected, _selectedTopicJump);
setPeerSearchPressed(_peerSearchSelected); setPeerSearchPressed(_peerSearchSelected);
setSearchedPressed(_searchedSelected); setSearchedPressed(_searchedSelected);
const auto alt = (e->modifiers() & Qt::AltModifier);
const auto onlyUserpic = !alt;
if (pressShowsPreview(onlyUserpic)) {
_chatPreviewWillBeFor = computeChosenRow().key;
if (alt) {
showChatPreview(onlyUserpic);
return;
}
_chatPreviewTimer.callOnce(kChatPreviewDelay);
}
if (base::in_range(_collapsedSelected, 0, _collapsedRows.size())) { if (base::in_range(_collapsedSelected, 0, _collapsedRows.size())) {
auto row = &_collapsedRows[_collapsedSelected]->row; auto row = &_collapsedRows[_collapsedSelected]->row;
row->addRipple(e->pos(), QSize(width(), st::dialogsImportantBarHeight), [this, index = _collapsedSelected] { row->addRipple(e->pos(), QSize(width(), st::dialogsImportantBarHeight), [this, index = _collapsedSelected] {
@ -1503,10 +1515,8 @@ void InnerWidget::mousePressEvent(QMouseEvent *e) {
row->repaint()); row->repaint());
} }
ClickHandler::pressed(); ClickHandler::pressed();
if (pressShowsPreview()) { if (anim::Disabled()
_chatPreviewWillBeFor = computeChosenRow().key; && !_chatPreviewTimer.isActive()
_chatPreviewTimer.callOnce(kChatPreviewDelay);
} else if (anim::Disabled()
&& (!_pressed || !_pressed->entry()->isPinnedDialog(_filterId))) { && (!_pressed || !_pressed->entry()->isPinnedDialog(_filterId))) {
mousePressReleased(e->globalPos(), e->button(), e->modifiers()); mousePressReleased(e->globalPos(), e->button(), e->modifiers());
} }
@ -2306,10 +2316,10 @@ void InnerWidget::fillArchiveSearchMenu(not_null<Ui::PopupMenu*> menu) {
}); });
} }
void InnerWidget::showChatPreview() { void InnerWidget::showChatPreview(bool onlyUserpic) {
const auto key = base::take(_chatPreviewWillBeFor); const auto key = base::take(_chatPreviewWillBeFor);
cancelChatPreview(); cancelChatPreview();
if (!pressShowsPreview() || key != computeChosenRow().key) { if (!pressShowsPreview(onlyUserpic) || key != computeChosenRow().key) {
return; return;
} }
ClickHandler::unpressed(); ClickHandler::unpressed();
@ -3558,15 +3568,15 @@ bool InnerWidget::isUserpicPress() const {
&& (width() > _narrowWidth); && (width() > _narrowWidth);
} }
bool InnerWidget::pressShowsPreview() const { bool InnerWidget::pressShowsPreview(bool onlyUserpic) const {
if (!isUserpicPress()) { if (onlyUserpic && !isUserpicPress()) {
return false; return false;
} }
const auto key = computeChosenRow().key; const auto key = computeChosenRow().key;
if (const auto history = key.history()) { if (const auto history = key.history()) {
return !history->peer->isForum(); return !history->peer->isForum();
} }
return key.topic() != nullptr;; return key.topic() != nullptr;
} }
bool InnerWidget::chooseRow( bool InnerWidget::chooseRow(

View file

@ -123,9 +123,9 @@ public:
void resizeEmptyLabel(); void resizeEmptyLabel();
[[nodiscard]] bool isUserpicPress() const; [[nodiscard]] bool isUserpicPress() const;
[[nodiscard]] bool pressShowsPreview() const; [[nodiscard]] bool pressShowsPreview(bool onlyUserpic) const;
void cancelChatPreview(); void cancelChatPreview();
void showChatPreview(); void showChatPreview(bool onlyUserpic);
bool chooseRow( bool chooseRow(
Qt::KeyboardModifiers modifiers = {}, Qt::KeyboardModifiers modifiers = {},
MsgId pressedTopicRootId = {}); MsgId pressedTopicRootId = {});