Show frequent/recent selected when preview.

This commit is contained in:
John Preston 2024-05-31 17:12:51 +04:00
parent 521c17b76c
commit 1f0acae151
6 changed files with 71 additions and 60 deletions

View File

@ -1562,8 +1562,13 @@ void PeerListContent::handleMouseMove(QPoint globalPosition) {
selectByMouse(globalPosition); selectByMouse(globalPosition);
} }
void PeerListContent::cancelPress() { void PeerListContent::pressLeftToContextMenu(bool shown) {
setPressed(Selected()); if (shown) {
setContexted(_pressed);
setPressed(Selected());
} else {
setContexted(Selected());
}
} }
void PeerListContent::mousePressEvent(QMouseEvent *e) { void PeerListContent::mousePressEvent(QMouseEvent *e) {

View File

@ -347,7 +347,7 @@ public:
virtual void peerListSortRows(Fn<bool(const PeerListRow &a, const PeerListRow &b)> compare) = 0; virtual void peerListSortRows(Fn<bool(const PeerListRow &a, const PeerListRow &b)> compare) = 0;
virtual int peerListPartitionRows(Fn<bool(const PeerListRow &a)> border) = 0; virtual int peerListPartitionRows(Fn<bool(const PeerListRow &a)> border) = 0;
virtual std::shared_ptr<Main::SessionShow> peerListUiShow() = 0; virtual std::shared_ptr<Main::SessionShow> peerListUiShow() = 0;
virtual void peerListCancelPress() = 0; virtual void peerListPressLeftToContextMenu(bool shown) = 0;
template <typename PeerDataRange> template <typename PeerDataRange>
void peerListAddSelectedPeers(PeerDataRange &&range) { void peerListAddSelectedPeers(PeerDataRange &&range) {
@ -662,7 +662,7 @@ public:
void refreshRows(); void refreshRows();
void mouseLeftGeometry(); void mouseLeftGeometry();
void cancelPress(); void pressLeftToContextMenu(bool shown);
void setSearchMode(PeerListSearchMode mode); void setSearchMode(PeerListSearchMode mode);
void changeCheckState( void changeCheckState(
@ -1000,8 +1000,8 @@ public:
not_null<PeerListRow*> row, not_null<PeerListRow*> row,
bool highlightRow, bool highlightRow,
Fn<void(not_null<Ui::PopupMenu*>)> destroyed = nullptr) override; Fn<void(not_null<Ui::PopupMenu*>)> destroyed = nullptr) override;
void peerListCancelPress() override { void peerListPressLeftToContextMenu(bool shown) override {
_content->cancelPress(); _content->pressLeftToContextMenu(shown);
} }
protected: protected:

View File

@ -86,7 +86,9 @@ private:
}; };
class ControllerWithPreviews : public PeerListController { class ControllerWithPreviews
: public PeerListController
, public base::has_weak_ptr {
public: public:
explicit ControllerWithPreviews( explicit ControllerWithPreviews(
not_null<Window::SessionController*> window); not_null<Window::SessionController*> window);
@ -103,9 +105,7 @@ private:
}; };
class RecentsController final class RecentsController final : public ControllerWithPreviews {
: public ControllerWithPreviews
, public base::has_weak_ptr {
public: public:
RecentsController( RecentsController(
not_null<Window::SessionController*> window, not_null<Window::SessionController*> window,
@ -153,9 +153,7 @@ private:
}; };
class MyChannelsController final class MyChannelsController final : public ControllerWithPreviews {
: public ControllerWithPreviews
, public base::has_weak_ptr {
public: public:
explicit MyChannelsController( explicit MyChannelsController(
not_null<Window::SessionController*> window); not_null<Window::SessionController*> window);
@ -188,9 +186,7 @@ private:
}; };
class RecommendationsController final class RecommendationsController final : public ControllerWithPreviews {
: public ControllerWithPreviews
, public base::has_weak_ptr {
public: public:
explicit RecommendationsController( explicit RecommendationsController(
not_null<Window::SessionController*> window); not_null<Window::SessionController*> window);
@ -426,15 +422,17 @@ ControllerWithPreviews::ControllerWithPreviews(
bool ControllerWithPreviews::rowTrackPress(not_null<PeerListRow*> row) { bool ControllerWithPreviews::rowTrackPress(not_null<PeerListRow*> row) {
const auto peer = row->peer(); const auto peer = row->peer();
const auto history = peer->owner().history(peer); const auto history = peer->owner().history(peer);
const auto callback = crl::guard(this, [=](bool shown) {
delegate()->peerListPressLeftToContextMenu(shown);
});
if (base::IsAltPressed()) { if (base::IsAltPressed()) {
_window->showChatPreview({ history, FullMsgId() }); _window->showChatPreview({ history, FullMsgId() }, callback);
delegate()->peerListCancelPress();
return false; return false;
} }
const auto point = delegate()->peerListLastRowMousePosition(); const auto point = delegate()->peerListLastRowMousePosition();
const auto &st = computeListSt().item; const auto &st = computeListSt().item;
if (point && point->x() < st.photoPosition.x() + st.photoSize) { if (point && point->x() < st.photoPosition.x() + st.photoSize) {
_window->scheduleChatPreview({ history, FullMsgId() }); _window->scheduleChatPreview({ history, FullMsgId() }, callback);
return true; return true;
} }
return false; return false;
@ -982,8 +980,8 @@ void Suggestions::setupChats() {
}, _topPeers->lifetime()); }, _topPeers->lifetime());
_topPeers->pressed() | rpl::start_with_next([=](uint64 peerIdRaw) { _topPeers->pressed() | rpl::start_with_next([=](uint64 peerIdRaw) {
handlePressForChatPreview(PeerId(peerIdRaw), [=] { handlePressForChatPreview(PeerId(peerIdRaw), [=](bool shown) {
_topPeers->cancelPress(); _topPeers->pressLeftToContextMenu(shown);
}); });
}, _topPeers->lifetime()); }, _topPeers->lifetime());
@ -1036,12 +1034,8 @@ void Suggestions::setupChats() {
void Suggestions::handlePressForChatPreview( void Suggestions::handlePressForChatPreview(
PeerId id, PeerId id,
Fn<void()> cancelPress) { Fn<void(bool)> callback) {
const auto callback = crl::guard(this, [=](bool shown) { callback = crl::guard(this, callback);
if (shown) {
cancelPress();
}
});
const auto row = RowDescriptor( const auto row = RowDescriptor(
_controller->session().data().history(id), _controller->session().data().history(id),
FullMsgId()); FullMsgId());

View File

@ -122,7 +122,7 @@ private:
void startSlideAnimation(); void startSlideAnimation();
void finishShow(); void finishShow();
void handlePressForChatPreview(PeerId id, Fn<void()> cancelPress); void handlePressForChatPreview(PeerId id, Fn<void(bool)> callback);
const not_null<Window::SessionController*> _controller; const not_null<Window::SessionController*> _controller;

View File

@ -381,14 +381,7 @@ void TopPeersStrip::stripMouseReleaseEvent(QMouseEvent *e) {
_mouseDownPosition = std::nullopt; _mouseDownPosition = std::nullopt;
}); });
const auto pressed = std::exchange(_pressed, -1); const auto pressed = clearPressed();
if (pressed >= 0) {
Assert(pressed < _entries.size());
auto &entry = _entries[pressed];
if (entry.ripple) {
entry.ripple->lastStop();
}
}
if (finishDragging()) { if (finishDragging()) {
return; return;
} }
@ -400,6 +393,18 @@ void TopPeersStrip::stripMouseReleaseEvent(QMouseEvent *e) {
} }
} }
int TopPeersStrip::clearPressed() {
const auto pressed = std::exchange(_pressed, -1);
if (pressed >= 0) {
Assert(pressed < _entries.size());
auto &entry = _entries[pressed];
if (entry.ripple) {
entry.ripple->lastStop();
}
}
return pressed;
}
void TopPeersStrip::updateScrollMax(int newWidth) { void TopPeersStrip::updateScrollMax(int newWidth) {
if (_expandAnimation.animating()) { if (_expandAnimation.animating()) {
return; return;
@ -441,15 +446,13 @@ rpl::producer<> TopPeersStrip::pressCancelled() const {
return _pressCancelled.events(); return _pressCancelled.events();
} }
void TopPeersStrip::cancelPress() { void TopPeersStrip::pressLeftToContextMenu(bool shown) {
const auto pressed = std::exchange(_pressed, -1); if (!shown) {
if (pressed >= 0) { _contexted = -1;
Assert(pressed < _entries.size()); update();
auto &entry = _entries[pressed]; return;
if (entry.ripple) {
entry.ripple->lastStop();
}
} }
_contexted = clearPressed();
if (finishDragging()) { if (finishDragging()) {
return; return;
} }
@ -491,6 +494,9 @@ void TopPeersStrip::removeLocally(uint64 id) {
if (_pressed > index) { if (_pressed > index) {
--_pressed; --_pressed;
} }
if (_contexted > index) {
--_contexted;
}
updateScrollMax(); updateScrollMax();
_count = int(_entries.size()); _count = int(_entries.size());
update(); update();
@ -603,8 +609,17 @@ void TopPeersStrip::apply(const TopPeersList &list) {
} }
auto now = std::vector<Entry>(); auto now = std::vector<Entry>();
auto selectedId = (_selected >= 0) ? _entries[_selected].id : 0; const auto selectedId = (_selected >= 0) ? _entries[_selected].id : 0;
auto pressedId = (_pressed >= 0) ? _entries[_pressed].id : 0; const auto pressedId = (_pressed >= 0) ? _entries[_pressed].id : 0;
const auto contextedId = (_contexted >= 0) ? _entries[_contexted].id : 0;
const auto restoreIndex = [&](uint64 id) {
if (!id) {
return -1;
}
const auto i = ranges::find(_entries, id, &Entry::id);
return (i != end(_entries)) ? int(i - begin(_entries)) : -1;
};
for (const auto &entry : list.entries) { for (const auto &entry : list.entries) {
if (_removed.contains(entry.id)) { if (_removed.contains(entry.id)) {
continue; continue;
@ -627,18 +642,9 @@ void TopPeersStrip::apply(const TopPeersList &list) {
} }
} }
_entries = std::move(now); _entries = std::move(now);
if (selectedId) { _selected = restoreIndex(selectedId);
const auto i = ranges::find(_entries, selectedId, &Entry::id); _pressed = restoreIndex(pressedId);
if (i != end(_entries)) { _contexted = restoreIndex(contextedId);
_selected = int(i - begin(_entries));
}
}
if (pressedId) {
const auto i = ranges::find(_entries, pressedId, &Entry::id);
if (i != end(_entries)) {
_pressed = int(i - begin(_entries));
}
}
updateScrollMax(); updateScrollMax();
unsubscribeUserpics(); unsubscribeUserpics();
_count = int(_entries.size()); _count = int(_entries.size());
@ -736,7 +742,11 @@ void TopPeersStrip::paintStrip(QRect clip) {
auto x = int(base::SafeRound(-shift + from * fsingle + added)); auto x = int(base::SafeRound(-shift + from * fsingle + added));
auto y = row * st.height; auto y = row * st.height;
const auto highlighted = (_pressed >= 0) ? _pressed : _selected; const auto highlighted = (_contexted >= 0)
? _contexted
: (_pressed >= 0)
? _pressed
: _selected;
for (auto i = from; i != till; ++i) { for (auto i = from; i != till; ++i) {
auto &entry = _entries[i]; auto &entry = _entries[i];
const auto selected = (i == highlighted); const auto selected = (i == highlighted);

View File

@ -63,7 +63,7 @@ public:
bool selectByKeyboard(Qt::Key direction); bool selectByKeyboard(Qt::Key direction);
void deselectByKeyboard(); void deselectByKeyboard();
bool chooseRow(); bool chooseRow();
void cancelPress(); void pressLeftToContextMenu(bool shown);
uint64 updateFromParentDrag(QPoint globalPosition); uint64 updateFromParentDrag(QPoint globalPosition);
void dragLeft(); void dragLeft();
@ -105,6 +105,7 @@ private:
[[nodiscard]] QRect innerRounded() const; [[nodiscard]] QRect innerRounded() const;
[[nodiscard]] int scrollLeft() const; [[nodiscard]] int scrollLeft() const;
[[nodiscard]] Layout currentLayout() const; [[nodiscard]] Layout currentLayout() const;
int clearPressed();
void apply(const TopPeersList &list); void apply(const TopPeersList &list);
void apply(Entry &entry, const TopPeersEntry &data); void apply(Entry &entry, const TopPeersEntry &data);
@ -132,6 +133,7 @@ private:
int _selected = -1; int _selected = -1;
int _pressed = -1; int _pressed = -1;
int _contexted = -1;
bool _selectionByKeyboard = false; bool _selectionByKeyboard = false;
bool _hiddenLocally = false; bool _hiddenLocally = false;