Spectral/src/messageeventmodel.h

67 lines
1.7 KiB
C
Raw Normal View History

2018-03-05 11:12:13 +00:00
#ifndef MESSAGEEVENTMODEL_H
#define MESSAGEEVENTMODEL_H
#include <QtCore/QAbstractListModel>
#include "room.h"
2018-03-06 11:01:11 +00:00
2018-07-09 02:45:26 +00:00
class MessageEventModel : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(
QMatrixClient::Room* room READ getRoom WRITE setRoom NOTIFY roomChanged)
public:
enum EventRoles {
EventTypeRole = Qt::UserRole + 1,
EventIdRole,
TimeRole,
AboveTimeRole,
2018-07-09 02:45:26 +00:00
SectionRole,
AboveSectionRole,
AuthorRole,
AboveAuthorRole,
ContentRole,
ContentTypeRole,
HighlightRole,
ReadMarkerRole,
SpecialMarksRole,
LongOperationRole,
2018-08-05 16:53:22 +00:00
AnnotationRole,
2018-08-04 20:35:31 +00:00
PlainTextRole,
2018-07-09 02:45:26 +00:00
// For debugging
EventResolvedTypeRole,
};
explicit MessageEventModel(QObject* parent = nullptr);
~MessageEventModel();
QMatrixClient::Room* getRoom() { return m_currentRoom; }
void setRoom(QMatrixClient::Room* room);
2018-08-05 16:53:22 +00:00
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
2018-07-09 02:45:26 +00:00
QHash<int, QByteArray> roleNames() const;
private slots:
void 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:
QMatrixClient::Room* m_currentRoom = nullptr;
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;
void refreshEventRoles(int row, const QVector<int>& roles = {});
void 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