Spectral/src/messageeventmodel.h

85 lines
2.0 KiB
C
Raw Normal View History

2018-03-05 11:12:13 +00:00
#ifndef MESSAGEEVENTMODEL_H
#define MESSAGEEVENTMODEL_H
#include "room.h"
2018-11-22 00:01:07 +00:00
#include "spectralroom.h"
2018-03-06 11:01:11 +00:00
#include <QtCore/QAbstractListModel>
2018-07-09 02:45:26 +00:00
class MessageEventModel : public QAbstractListModel {
Q_OBJECT
2019-05-02 06:20:04 +00:00
Q_PROPERTY(SpectralRoom* room READ room WRITE setRoom NOTIFY roomChanged)
2018-07-09 02:45:26 +00:00
public:
enum EventRoles {
EventTypeRole = Qt::UserRole + 1,
2018-09-17 03:58:02 +00:00
MessageRole,
2018-07-09 02:45:26 +00:00
EventIdRole,
TimeRole,
SectionRole,
AuthorRole,
ContentRole,
ContentTypeRole,
HighlightRole,
ReadMarkerRole,
SpecialMarksRole,
LongOperationRole,
2018-08-05 16:53:22 +00:00
AnnotationRole,
2018-09-13 05:05:51 +00:00
UserMarkerRole,
2019-05-09 13:18:04 +00:00
// For reply
2018-11-27 00:09:45 +00:00
ReplyEventIdRole,
ReplyAuthorRole,
ReplyDisplayRole,
2019-05-09 13:18:04 +00:00
ShowAuthorRole,
ShowSectionRole,
2019-05-09 13:18:04 +00:00
BubbleShapeRole,
2018-07-09 02:45:26 +00:00
// For debugging
EventResolvedTypeRole,
};
2019-05-09 13:18:04 +00:00
enum BubbleShapes {
NoShape = 0,
BeginShape,
MiddleShape,
EndShape,
};
2018-07-09 02:45:26 +00:00
explicit MessageEventModel(QObject* parent = nullptr);
~MessageEventModel();
2019-05-02 06:20:04 +00:00
SpectralRoom* room() { return m_currentRoom; }
void setRoom(SpectralRoom* room);
2018-07-09 02:45:26 +00:00
2018-08-05 16:53:22 +00:00
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
2018-08-06 12:13:51 +00:00
QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const override;
2018-09-13 05:05:51 +00:00
QHash<int, QByteArray> roleNames() const override;
2018-07-09 02:45:26 +00:00
2018-10-22 01:48:37 +00:00
Q_INVOKABLE int eventIDToIndex(const QString& eventID);
2018-07-09 02:45:26 +00:00
private slots:
int refreshEvent(const QString& eventId);
2018-08-05 16:53:22 +00:00
void refreshRow(int row);
2018-07-09 02:45:26 +00:00
private:
SpectralRoom* m_currentRoom = nullptr;
2018-07-09 02:45:26 +00:00
QString lastReadEventId;
2018-08-05 16:53:22 +00:00
int rowBelowInserted = -1;
bool movingEvent = 0;
2018-07-09 02:45:26 +00:00
2018-08-05 16:53:22 +00:00
int timelineBaseIndex() const;
QDateTime makeMessageTimestamp(
const QMatrixClient::Room::rev_iter_t& baseIt) const;
2018-08-05 16:53:22 +00:00
QString renderDate(QDateTime timestamp) const;
2018-08-06 12:13:51 +00:00
2018-11-22 00:01:07 +00:00
void refreshLastUserEvents(int baseRow);
2018-08-05 16:53:22 +00:00
void refreshEventRoles(int row, const QVector<int>& roles = {});
int refreshEventRoles(const QString& eventId, const QVector<int>& roles = {});
2018-07-09 02:45:26 +00:00
signals:
void roomChanged();
2018-03-05 11:12:13 +00:00
};
2018-07-09 02:45:26 +00:00
#endif // MESSAGEEVENTMODEL_H