2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

Add context menu support to info members list.

This commit is contained in:
John Preston
2017-10-22 20:06:57 +03:00
parent 856ca22aad
commit fb46c33d7f
15 changed files with 366 additions and 76 deletions

View File

@@ -29,6 +29,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "ui/widgets/multi_select.h"
#include "ui/widgets/labels.h"
#include "ui/widgets/scroll_area.h"
#include "ui/widgets/popup_menu.h"
#include "ui/effects/round_checkbox.h"
#include "ui/effects/ripple_animation.h"
#include "ui/wrap/slide_wrap.h"
@@ -863,7 +864,10 @@ void PeerListContent::leaveEventHook(QEvent *e) {
}
void PeerListContent::mouseMoveEvent(QMouseEvent *e) {
auto position = e->globalPos();
handleMouseMove(e->globalPos());
}
void PeerListContent::handleMouseMove(QPoint position) {
if (_mouseSelection || _lastMousePosition != position) {
_lastMousePosition = position;
_mouseSelection = true;
@@ -872,6 +876,7 @@ void PeerListContent::mouseMoveEvent(QMouseEvent *e) {
}
void PeerListContent::mousePressEvent(QMouseEvent *e) {
_pressButton = e->button();
_mouseSelection = true;
_lastMousePosition = e->globalPos();
updateSelection();
@@ -896,12 +901,16 @@ void PeerListContent::mousePressEvent(QMouseEvent *e) {
}
void PeerListContent::mouseReleaseEvent(QMouseEvent *e) {
mousePressReleased(e->button());
}
void PeerListContent::mousePressReleased(Qt::MouseButton button) {
updateRow(_pressed.index);
updateRow(_selected.index);
auto pressed = _pressed;
setPressed(Selected());
if (e->button() == Qt::LeftButton && pressed == _selected) {
if (button == Qt::LeftButton && pressed == _selected) {
if (auto row = getRow(pressed.index)) {
if (pressed.action) {
_controller->rowActionClicked(row);
@@ -912,6 +921,41 @@ void PeerListContent::mouseReleaseEvent(QMouseEvent *e) {
}
}
void PeerListContent::contextMenuEvent(QContextMenuEvent *e) {
if (_menu) {
_menu->deleteLater();
_menu = nullptr;
}
if (_context.index.value >= 0) {
updateRow(_context.index);
_context = Selected();
}
if (e->reason() == QContextMenuEvent::Mouse) {
handleMouseMove(e->globalPos());
}
_context = _selected;
if (_pressButton != Qt::LeftButton) {
mousePressReleased(_pressButton);
}
if (auto row = getRow(_context.index)) {
_menu = _controller->rowContextMenu(row);
if (_menu) {
_menu->setDestroyedCallback(base::lambda_guarded(
this,
[this] {
updateRow(_context.index);
_context = Selected();
handleMouseMove(QCursor::pos());
}));
_menu->popup(e->globalPos());
e->accept();
}
}
}
void PeerListContent::setPressed(Selected pressed) {
if (auto row = getRow(_pressed.index)) {
row->stopLastRipple();
@@ -933,7 +977,11 @@ TimeMs PeerListContent::paintRow(Painter &p, TimeMs ms, RowIndex index) {
auto peer = row->peer();
auto user = peer->asUser();
auto active = (_pressed.index.value >= 0) ? _pressed : _selected;
auto active = (_context.index.value >= 0)
? _context
: (_pressed.index.value >= 0)
? _pressed
: _selected;
auto selected = (active.index == index);
auto actionSelected = (selected && active.action);

View File

@@ -39,6 +39,7 @@ template <typename Widget>
class SlideWrap;
class FlatLabel;
struct ScrollToRequest;
class PopupMenu;
} // namespace Ui
namespace Notify {
@@ -238,8 +239,8 @@ public:
virtual void peerListScrollToTop() = 0;
virtual int peerListFullRowsCount() = 0;
virtual PeerListRow *peerListFindRow(PeerListRowId id) = 0;
virtual void peerListSortRows(base::lambda<bool(PeerListRow &a, PeerListRow &b)> compare) = 0;
virtual int peerListPartitionRows(base::lambda<bool(PeerListRow &a)> border) = 0;
virtual void peerListSortRows(base::lambda<bool(const PeerListRow &a, const PeerListRow &b)> compare) = 0;
virtual int peerListPartitionRows(base::lambda<bool(const PeerListRow &a)> border) = 0;
template <typename PeerDataRange>
void peerListAddSelectedRows(PeerDataRange &&range) {
@@ -306,6 +307,10 @@ public:
}
virtual void itemDeselectedHook(not_null<PeerData*> peer) {
}
virtual Ui::PopupMenu *rowContextMenu(
not_null<PeerListRow*> row) {
return nullptr;
}
bool isSearchLoading() const {
return _searchController ? _searchController->isLoading() : false;
}
@@ -429,6 +434,7 @@ protected:
void mouseMoveEvent(QMouseEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void contextMenuEvent(QContextMenuEvent *e) override;
private:
void refreshIndices();
@@ -505,6 +511,8 @@ private:
int labelHeight() const;
void clearSearchRows();
void handleMouseMove(QPoint position);
void mousePressReleased(Qt::MouseButton button);
const style::PeerList &_st;
not_null<PeerListController*> _controller;
@@ -516,7 +524,9 @@ private:
Selected _selected;
Selected _pressed;
Selected _context;
bool _mouseSelection = false;
Qt::MouseButton _pressButton = Qt::LeftButton;
rpl::event_stream<Ui::ScrollToRequest> _scrollToRequests;
@@ -540,6 +550,7 @@ private:
std::vector<std::unique_ptr<PeerListRow>> _searchRows;
base::Timer _repaintByStatus;
QPointer<Ui::PopupMenu> _menu;
};
@@ -615,7 +626,7 @@ public:
_content->setSearchMode(mode);
}
void peerListSortRows(
base::lambda<bool(PeerListRow &a, PeerListRow &b)> compare) override {
base::lambda<bool(const PeerListRow &a, const PeerListRow &b)> compare) override {
_content->reorderRows([compare = std::move(compare)](
auto &&begin,
auto &&end) {
@@ -625,7 +636,7 @@ public:
});
}
int peerListPartitionRows(
base::lambda<bool(PeerListRow &a)> border) override {
base::lambda<bool(const PeerListRow &a)> border) override {
auto result = 0;
_content->reorderRows([border = std::move(border), &result](
auto &&begin,

View File

@@ -243,8 +243,8 @@ void ChatsListBoxController::rebuildRows() {
added += appendList(App::main()->contactsNoDialogsList());
if (!wasEmpty && added > 0) {
// Place dialogs list before contactsNoDialogs list.
delegate()->peerListPartitionRows([](PeerListRow &a) {
auto history = static_cast<Row&>(a).history();
delegate()->peerListPartitionRows([](const PeerListRow &a) {
auto history = static_cast<const Row&>(a).history();
return history->inChatList(Dialogs::Mode::All);
});
}