forked from mirror/nheko
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
156 lines
4.9 KiB
156 lines
4.9 KiB
8 years ago
|
/*
|
||
|
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation, either version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
8 years ago
|
#pragma once
|
||
8 years ago
|
|
||
7 years ago
|
#include <QDateTime>
|
||
8 years ago
|
#include <QHBoxLayout>
|
||
|
#include <QLabel>
|
||
7 years ago
|
#include <QPainter>
|
||
|
#include <QStyle>
|
||
|
#include <QStyleOption>
|
||
8 years ago
|
|
||
7 years ago
|
#include "AvatarProvider.h"
|
||
7 years ago
|
#include "Emote.h"
|
||
7 years ago
|
#include "File.h"
|
||
8 years ago
|
#include "Image.h"
|
||
|
#include "MessageEvent.h"
|
||
|
#include "Notice.h"
|
||
7 years ago
|
#include "RoomInfoListItem.h"
|
||
8 years ago
|
#include "Text.h"
|
||
7 years ago
|
#include "TimelineViewManager.h"
|
||
8 years ago
|
|
||
7 years ago
|
class ImageItem;
|
||
7 years ago
|
class FileItem;
|
||
7 years ago
|
class Avatar;
|
||
|
|
||
8 years ago
|
namespace events = matrix::events;
|
||
7 years ago
|
namespace msgs = matrix::events::messages;
|
||
8 years ago
|
|
||
8 years ago
|
class TimelineItem : public QWidget
|
||
8 years ago
|
{
|
||
7 years ago
|
Q_OBJECT
|
||
8 years ago
|
public:
|
||
7 years ago
|
TimelineItem(const events::MessageEvent<msgs::Notice> &e,
|
||
|
bool with_sender,
|
||
|
QWidget *parent = 0);
|
||
|
TimelineItem(const events::MessageEvent<msgs::Text> &e,
|
||
|
bool with_sender,
|
||
|
QWidget *parent = 0);
|
||
7 years ago
|
TimelineItem(const events::MessageEvent<msgs::Emote> &e,
|
||
|
bool with_sender,
|
||
|
QWidget *parent = 0);
|
||
8 years ago
|
|
||
7 years ago
|
// For local messages.
|
||
7 years ago
|
// m.text & m.emote
|
||
7 years ago
|
TimelineItem(events::MessageEventType ty,
|
||
|
const QString &userid,
|
||
|
QString body,
|
||
|
bool withSender,
|
||
|
QWidget *parent = 0);
|
||
7 years ago
|
// m.image
|
||
|
TimelineItem(ImageItem *item, const QString &userid, bool withSender, QWidget *parent = 0);
|
||
7 years ago
|
TimelineItem(FileItem *item, const QString &userid, bool withSender, QWidget *parent = 0);
|
||
8 years ago
|
|
||
7 years ago
|
TimelineItem(ImageItem *img,
|
||
|
const events::MessageEvent<msgs::Image> &e,
|
||
|
bool with_sender,
|
||
|
QWidget *parent);
|
||
7 years ago
|
TimelineItem(FileItem *file,
|
||
|
const events::MessageEvent<msgs::File> &e,
|
||
|
bool with_sender,
|
||
|
QWidget *parent);
|
||
8 years ago
|
|
||
7 years ago
|
void setUserAvatar(const QImage &pixmap);
|
||
7 years ago
|
DescInfo descriptionMessage() const { return descriptionMsg_; }
|
||
|
QString eventId() const { return event_id_; }
|
||
8 years ago
|
|
||
7 years ago
|
~TimelineItem();
|
||
8 years ago
|
|
||
7 years ago
|
protected:
|
||
|
void paintEvent(QPaintEvent *event) override;
|
||
|
|
||
8 years ago
|
private:
|
||
7 years ago
|
void init();
|
||
8 years ago
|
|
||
7 years ago
|
template<class Widget>
|
||
|
void setupLocalWidgetLayout(Widget *widget,
|
||
|
const QString &userid,
|
||
|
const QString &msgDescription,
|
||
|
bool withSender);
|
||
|
|
||
7 years ago
|
void generateBody(const QString &body);
|
||
|
void generateBody(const QString &userid, const QString &body);
|
||
|
void generateTimestamp(const QDateTime &time);
|
||
|
QString descriptiveTime(const QDateTime &then);
|
||
8 years ago
|
|
||
7 years ago
|
void setupAvatarLayout(const QString &userName);
|
||
|
void setupSimpleLayout();
|
||
8 years ago
|
|
||
7 years ago
|
QString replaceEmoji(const QString &body);
|
||
7 years ago
|
QString event_id_;
|
||
8 years ago
|
|
||
7 years ago
|
DescInfo descriptionMsg_;
|
||
7 years ago
|
|
||
7 years ago
|
QHBoxLayout *topLayout_;
|
||
|
QVBoxLayout *sideLayout_; // Avatar or Timestamp
|
||
|
QVBoxLayout *mainLayout_; // Header & Message body
|
||
8 years ago
|
|
||
7 years ago
|
QHBoxLayout *headerLayout_; // Username (&) Timestamp
|
||
8 years ago
|
|
||
7 years ago
|
Avatar *userAvatar_;
|
||
8 years ago
|
|
||
7 years ago
|
QFont font_;
|
||
7 years ago
|
|
||
7 years ago
|
QLabel *timestamp_;
|
||
|
QLabel *userName_;
|
||
|
QLabel *body_;
|
||
8 years ago
|
};
|
||
7 years ago
|
|
||
|
template<class Widget>
|
||
|
void
|
||
|
TimelineItem::setupLocalWidgetLayout(Widget *widget,
|
||
|
const QString &userid,
|
||
|
const QString &msgDescription,
|
||
|
bool withSender)
|
||
|
{
|
||
|
auto displayName = TimelineViewManager::displayName(userid);
|
||
|
auto timestamp = QDateTime::currentDateTime();
|
||
|
|
||
|
descriptionMsg_ = {
|
||
|
"You", userid, QString(" %1").arg(msgDescription), descriptiveTime(timestamp)};
|
||
|
|
||
|
generateTimestamp(timestamp);
|
||
|
|
||
|
auto widgetLayout = new QHBoxLayout();
|
||
|
widgetLayout->setContentsMargins(0, 5, 0, 0);
|
||
|
widgetLayout->addWidget(widget);
|
||
|
widgetLayout->addStretch(1);
|
||
|
|
||
|
if (withSender) {
|
||
|
generateBody(displayName, "");
|
||
|
setupAvatarLayout(displayName);
|
||
|
mainLayout_->addLayout(headerLayout_);
|
||
|
|
||
|
AvatarProvider::resolve(userid, this);
|
||
|
} else {
|
||
|
setupSimpleLayout();
|
||
|
}
|
||
|
|
||
|
mainLayout_->addLayout(widgetLayout);
|
||
|
}
|