Make message selectable.

No need for manually "Copying".
This commit is contained in:
Black Hat 2018-09-17 08:13:45 +08:00
parent c309f7f3ee
commit d02c3f6e90
6 changed files with 14 additions and 117 deletions

View File

@ -4,7 +4,6 @@ import Qt.labs.settings 1.0
Settings { Settings {
property bool lazyLoad: true property bool lazyLoad: true
property bool richText: true
property bool pressAndHold property bool pressAndHold
property bool rearrangeByActivity property bool rearrangeByActivity

View File

@ -198,13 +198,6 @@ Page {
onCheckedChanged: MSettings.lazyLoad = checked onCheckedChanged: MSettings.lazyLoad = checked
} }
Switch {
text: "Use RichText instead of StyledText"
checked: MSettings.richText
onCheckedChanged: MSettings.richText = checked
}
Switch { Switch {
text: "Use press and hold instead of right click" text: "Use press and hold instead of right click"
checked: MSettings.pressAndHold checked: MSettings.pressAndHold

View File

@ -69,12 +69,23 @@ RowLayout {
} }
} }
AutoLabel { TextEdit {
Layout.fillWidth: true Layout.fillWidth: true
text: display text: (highlighted ? "<style>a{color: white;}</style>" : "") + display
visible: isText visible: isText
coloredBackground: highlighted color: highlighted ? "white": Material.foreground
font.family: "Noto Sans"
font.pointSize: 10
selectByMouse: true
readOnly: true
wrapMode: Label.Wrap
selectionColor: Material.accent
textFormat: Text.RichText
onLinkActivated: Qt.openUrlExternally(link)
} }
Loader { Loader {

View File

@ -9,11 +9,6 @@ Menu {
id: messageContextMenu id: messageContextMenu
MenuItem {
text: "Copy"
onTriggered: matriqueController.copyToClipboard(model.plainText)
}
MenuItem { MenuItem {
text: "View Source" text: "View Source"

View File

@ -31,7 +31,6 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const {
roles[LongOperationRole] = "progressInfo"; roles[LongOperationRole] = "progressInfo";
roles[AnnotationRole] = "annotation"; roles[AnnotationRole] = "annotation";
roles[EventResolvedTypeRole] = "eventResolvedType"; roles[EventResolvedTypeRole] = "eventResolvedType";
roles[PlainTextRole] = "plainText";
roles[UserMarkerRole] = "userMarker"; roles[UserMarkerRole] = "userMarker";
return roles; return roles;
} }
@ -416,105 +415,6 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
tr("Unknown Event")); tr("Unknown Event"));
} }
if (role == PlainTextRole) {
if (evt.isRedacted()) {
auto reason = evt.redactedBecause()->reason();
if (reason.isEmpty()) return tr("Redacted");
return tr("Redacted: %1").arg(evt.redactedBecause()->reason());
}
return visit(
evt,
[this](const RoomMessageEvent& e) {
using namespace MessageEventContent;
if (e.hasFileContent()) {
auto fileCaption = e.content()->fileInfo()->originalName;
if (fileCaption.isEmpty()) fileCaption = e.plainBody();
if (fileCaption.isEmpty()) return tr("a file");
}
return e.plainBody();
},
[this](const RoomMemberEvent& e) {
// FIXME: Rewind to the name that was at the time of this event
QString subjectName = m_currentRoom->roomMembername(e.userId());
// The below code assumes senderName output in AuthorRole
switch (e.membership()) {
case MembershipType::Invite:
if (e.repeatsState())
return tr("reinvited %1 to the room").arg(subjectName);
FALLTHROUGH;
case MembershipType::Join: {
if (e.repeatsState()) return tr("joined the room (repeated)");
if (!e.prevContent() ||
e.membership() != e.prevContent()->membership) {
return e.membership() == MembershipType::Invite
? tr("invited %1 to the room").arg(subjectName)
: tr("joined the room");
}
QString text{};
if (e.displayName() != e.prevContent()->displayName) {
if (e.displayName().isEmpty())
text = tr("cleared their display name");
else
text = tr("changed their display name to %1")
.arg(e.displayName());
}
if (e.avatarUrl() != e.prevContent()->avatarUrl) {
if (!text.isEmpty()) text += " and ";
if (e.avatarUrl().isEmpty())
text += tr("cleared the avatar");
else
text += tr("updated the avatar");
}
return text;
}
case MembershipType::Leave:
if (e.prevContent() &&
e.prevContent()->membership == MembershipType::Ban) {
return (e.senderId() != e.userId())
? tr("unbanned %1").arg(subjectName)
: tr("self-unbanned");
}
return (e.senderId() != e.userId())
? tr("has kicked %1 from the room").arg(subjectName)
: tr("left the room");
case MembershipType::Ban:
return (e.senderId() != e.userId())
? tr("banned %1 from the room").arg(subjectName)
: tr("self-banned from the room");
case MembershipType::Knock:
return tr("knocked");
default:;
}
return tr("made something unknown");
},
[](const RoomAliasesEvent& e) {
return tr("set aliases to: %1").arg(e.aliases().join(", "));
},
[](const RoomCanonicalAliasEvent& e) {
return (e.alias().isEmpty())
? tr("cleared the room main alias")
: tr("set the room main alias to: %1").arg(e.alias());
},
[](const RoomNameEvent& e) {
return (e.name().isEmpty())
? tr("cleared the room name")
: tr("set the room name to: %1").arg(e.name());
},
[](const RoomTopicEvent& e) {
return (e.topic().isEmpty())
? tr("cleared the topic")
: tr("set the topic to: %1").arg(e.topic());
},
[](const RoomAvatarEvent&) { return tr("changed the room avatar"); },
[](const EncryptionEvent&) {
return tr("activated End-to-End Encryption");
},
tr("Unknown Event"));
}
if (role == Qt::ToolTipRole) { if (role == Qt::ToolTipRole) {
return evt.originalJson(); return evt.originalJson();
} }

View File

@ -28,7 +28,6 @@ class MessageEventModel : public QAbstractListModel {
SpecialMarksRole, SpecialMarksRole,
LongOperationRole, LongOperationRole,
AnnotationRole, AnnotationRole,
PlainTextRole,
UserMarkerRole, UserMarkerRole,
// For debugging // For debugging
EventResolvedTypeRole, EventResolvedTypeRole,