42 lines
2.9 KiB
C++
42 lines
2.9 KiB
C++
/* Строка участника: аватар, имя и три действия — звук рации, вызов рации, обычный звонок.
|
||
* GUI-поток, модель принадлежит view. DisplayRole — имя, DecorationRole — аватар,
|
||
* UserRole+1 — подпись, +2 — self, +3 — CHAT_MEMBER_FLAG_*, +4 — storage;
|
||
* MemberListModel::OnlineRole/RadioSpeakingRole определяют доступность и индикацию.
|
||
* Аватар доступен всем, mute — чужим участникам независимо от online, вызовы — online-пирам.
|
||
* Собственная строка показывает состояние рации без кнопок mute/вызова.
|
||
* Сигнал только при LeftButton release в том же действии/строке после press:
|
||
* MouseMove со смещением >=5 по Manhattan или без LeftButton отменяет жест, включая возврат курсора назад. */
|
||
#pragma once
|
||
|
||
#include <QStyledItemDelegate>
|
||
#include <QPersistentModelIndex>
|
||
|
||
class AccountDelegate : public QStyledItemDelegate {
|
||
Q_OBJECT
|
||
public:
|
||
explicit AccountDelegate(QObject *parent = nullptr); // parent владеет по правилам QObject
|
||
|
||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||
const QModelIndex &index) const override;
|
||
QSize sizeHint(const QStyleOptionViewItem &option, // 160 × MemberListModel::kRowHeight, независимо от данных
|
||
const QModelIndex &index) const override;
|
||
bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option,
|
||
const QModelIndex& index) override;
|
||
bool helpEvent(QHelpEvent* event, QAbstractItemView* view, const QStyleOptionViewItem& option,
|
||
const QModelIndex& index) override;
|
||
signals:
|
||
// index заимствует модель; для отложенной работы получатель сохраняет node ID, не QModelIndex через reset.
|
||
void radioCallRequested(const QModelIndex& index);
|
||
void callRequested(const QModelIndex& index);
|
||
void avatarRequested(const QModelIndex& index);
|
||
void radioMuteRequested(const QModelIndex& index);
|
||
private:
|
||
static constexpr int ClickDistance = 5;
|
||
enum class Action { None, Avatar, RadioMute, RadioCall, Call };
|
||
static QRect actionRect(const QRect& row, Action action);
|
||
static Action actionAt(const QPoint& position, const QRect& row, bool self);
|
||
QPersistentModelIndex m_pressedIndex; /* строка, на которой начался клик */
|
||
QPoint m_pressedPosition; // координаты viewport при press
|
||
Action m_pressedAction = Action::None; // ожидаемое действие; сбрасывается при release/отмене жеста
|
||
};
|