mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-21 18:50:47 +03:00
Add basic sections and button placeholders to qml timeline
This commit is contained in:
parent
699fd7b38e
commit
2dd636456c
6 changed files with 132 additions and 6 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -52,6 +52,9 @@ ui_*.h
|
|||
*.qmlproject.user
|
||||
*.qmlproject.user.*
|
||||
|
||||
# Vim
|
||||
*.swp
|
||||
|
||||
#####=== CMake ===#####
|
||||
|
||||
CMakeCache.txt
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import QtQuick 2.1
|
||||
import QtQuick 2.5
|
||||
import QtQuick.Controls 2.5
|
||||
import QtQuick.Layouts 1.5
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
|
@ -17,9 +19,89 @@ Rectangle {
|
|||
id: chat
|
||||
|
||||
model: timelineManager.timeline
|
||||
delegate: Text {
|
||||
height: contentHeight
|
||||
text: model.userId
|
||||
delegate: RowLayout {
|
||||
width: chat.width
|
||||
Text {
|
||||
Layout.fillWidth: true
|
||||
height: contentHeight
|
||||
text: model.userName
|
||||
}
|
||||
|
||||
Button {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
id: replyButton
|
||||
flat: true
|
||||
height: replyButtonImg.contentHeight
|
||||
width: replyButtonImg.contentWidth
|
||||
ToolTip.visible: hovered
|
||||
ToolTip.text: qsTr("Reply")
|
||||
Image {
|
||||
id: replyButtonImg
|
||||
// Workaround, can't get icon.source working for now...
|
||||
anchors.fill: parent
|
||||
source: "qrc:/icons/icons/ui/mail-reply.png"
|
||||
}
|
||||
}
|
||||
Button {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
id: optionsButton
|
||||
flat: true
|
||||
height: optionsButtonImg.contentHeight
|
||||
width: optionsButtonImg.contentWidth
|
||||
ToolTip.visible: hovered
|
||||
ToolTip.text: qsTr("Options")
|
||||
Image {
|
||||
id: optionsButtonImg
|
||||
// Workaround, can't get icon.source working for now...
|
||||
anchors.fill: parent
|
||||
source: "qrc:/icons/icons/ui/vertical-ellipsis.png"
|
||||
}
|
||||
|
||||
onClicked: contextMenu.open()
|
||||
|
||||
Menu {
|
||||
y: optionsButton.height
|
||||
id: contextMenu
|
||||
|
||||
MenuItem {
|
||||
text: "Read receipts"
|
||||
}
|
||||
MenuItem {
|
||||
text: "Mark as read"
|
||||
}
|
||||
MenuItem {
|
||||
text: "View raw message"
|
||||
}
|
||||
MenuItem {
|
||||
text: "Redact message"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
text: model.timestamp.toLocaleTimeString("HH:mm")
|
||||
}
|
||||
}
|
||||
|
||||
section {
|
||||
property: "section"
|
||||
delegate: Column {
|
||||
width: parent.width
|
||||
Label {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
visible: section.includes(" ")
|
||||
text: Qt.formatDate(new Date(Number(section.split(" ")[1])))
|
||||
height: contentHeight * 1.2
|
||||
width: contentWidth * 1.2
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
background: Rectangle {
|
||||
radius: parent.height / 2
|
||||
color: "black"
|
||||
}
|
||||
}
|
||||
Text { text: section.split(" ")[0] }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -22,6 +22,13 @@ senderId(const T &event)
|
|||
{
|
||||
return QString::fromStdString(event.sender);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
QDateTime
|
||||
eventTimestamp(const T &event)
|
||||
{
|
||||
return QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
|
||||
}
|
||||
}
|
||||
|
||||
TimelineModel::TimelineModel(QString room_id, QObject *parent)
|
||||
|
@ -36,6 +43,7 @@ QHash<int, QByteArray>
|
|||
TimelineModel::roleNames() const
|
||||
{
|
||||
return {
|
||||
{Section, "section"},
|
||||
{Type, "type"},
|
||||
{Body, "body"},
|
||||
{FormattedBody, "formattedBody"},
|
||||
|
@ -55,16 +63,49 @@ TimelineModel::rowCount(const QModelIndex &parent) const
|
|||
QVariant
|
||||
TimelineModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
nhlog::ui()->info("data");
|
||||
if (index.row() < 0 && index.row() >= (int)eventOrder.size())
|
||||
return QVariant();
|
||||
|
||||
QString id = eventOrder[index.row()];
|
||||
|
||||
switch (role) {
|
||||
case Section: {
|
||||
QDateTime date = boost::apply_visitor(
|
||||
[](const auto &e) -> QDateTime { return eventTimestamp(e); }, events.value(id));
|
||||
date.setTime(QTime());
|
||||
|
||||
QString userId = boost::apply_visitor(
|
||||
[](const auto &e) -> QString { return senderId(e); }, events.value(id));
|
||||
|
||||
for (int r = index.row() - 1; r > 0; r--) {
|
||||
QDateTime prevDate = boost::apply_visitor(
|
||||
[](const auto &e) -> QDateTime { return eventTimestamp(e); },
|
||||
events.value(eventOrder[r]));
|
||||
prevDate.setTime(QTime());
|
||||
if (prevDate != date)
|
||||
return QString("%2 %1").arg(date.toMSecsSinceEpoch()).arg(userId);
|
||||
|
||||
QString prevUserId =
|
||||
boost::apply_visitor([](const auto &e) -> QString { return senderId(e); },
|
||||
events.value(eventOrder[r]));
|
||||
if (userId != prevUserId)
|
||||
break;
|
||||
}
|
||||
|
||||
return QString("%1").arg(userId);
|
||||
}
|
||||
case UserId:
|
||||
return QVariant(boost::apply_visitor(
|
||||
[](const auto &e) -> QString { return senderId(e); }, events.value(id)));
|
||||
case UserName:
|
||||
return QVariant(Cache::displayName(
|
||||
room_id_,
|
||||
boost::apply_visitor([](const auto &e) -> QString { return senderId(e); },
|
||||
events.value(id))));
|
||||
|
||||
case Timestamp:
|
||||
return QVariant(boost::apply_visitor(
|
||||
[](const auto &e) -> QDateTime { return eventTimestamp(e); }, events.value(id)));
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ public:
|
|||
|
||||
enum Roles
|
||||
{
|
||||
Section,
|
||||
Type,
|
||||
Body,
|
||||
FormattedBody,
|
||||
|
|
|
@ -34,7 +34,6 @@ public:
|
|||
|
||||
Q_INVOKABLE TimelineModel *activeTimeline() const
|
||||
{
|
||||
nhlog::ui()->info("aaaa");
|
||||
return timeline_;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue