"View source" dialog.

This commit is contained in:
Black Hat 2018-09-11 13:14:56 +08:00
parent 63c7601942
commit 421316aa00
11 changed files with 102 additions and 27 deletions

View File

@ -15,7 +15,15 @@ Control {
AutoMouseArea { AutoMouseArea {
anchors.fill: parent anchors.fill: parent
onSecondaryClicked: Qt.createComponent("qrc:/qml/menu/MessageContextMenu.qml").createObject(this) onSecondaryClicked: {
messageContextMenu.row = messageRow
messageContextMenu.plainText = plainText
messageContextMenu.toolTip = toolTip
messageContextMenu.eventId = eventId
messageContextMenu.eventType = eventType
messageContextMenu.canRedact = sentByMe
messageContextMenu.popup()
}
} }
background: Rectangle { color: colored ? Material.accent : highlighted ? Material.primary : backgroundColor } background: Rectangle { color: colored ? Material.accent : highlighted ? Material.primary : backgroundColor }

View File

@ -110,7 +110,7 @@ Drawer {
room: roomDrawer.room room: roomDrawer.room
} }
delegate: ItemDelegate { delegate: SwipeDelegate {
width: parent.width width: parent.width
height: 48 height: 48
@ -134,6 +134,25 @@ Drawer {
text: name text: name
} }
} }
swipe.right: Rectangle {
width: parent.height
height: parent.height
anchors.right: parent.right
color: Material.accent
MaterialIcon {
anchors.fill: parent
icon: "\ue8fb"
color: "white"
}
SwipeDelegate.onClicked: room.kickMember(userId)
}
onClicked: inputField.insert(inputField.cursorPosition, name)
} }
ScrollBar.vertical: ScrollBar {} ScrollBar.vertical: ScrollBar {}

View File

@ -7,7 +7,7 @@ import "qrc:/js/util.js" as Util
ItemDelegate { ItemDelegate {
property var page property var page
readonly property bool selected: stackView.currentItem === page property bool selected: stackView.currentItem === page
property color highlightColor: Material.accent property color highlightColor: Material.accent
Rectangle { Rectangle {

View File

@ -1,13 +1,13 @@
import QtQuick 2.9 import QtQuick 2.9
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import QtQuick.Controls.Material 2.2 import QtQuick.Controls.Material 2.2
import QtGraphicalEffects 1.0 import QtGraphicalEffects 1.0
import Matrique 0.1 import Matrique 0.1
import Matrique.Settings 0.1 import Matrique.Settings 0.1
import "../component" import "qrc:/qml/component"
import "qrc:/qml/menu"
import "qrc:/js/md.js" as Markdown import "qrc:/js/md.js" as Markdown
import "qrc:/js/util.js" as Util import "qrc:/js/util.js" as Util
@ -225,6 +225,36 @@ Item {
Behavior on opacity { NumberAnimation { duration: 200 } } Behavior on opacity { NumberAnimation { duration: 200 } }
} }
MessageContextMenu { id: messageContextMenu }
Dialog {
property string sourceText
x: (window.width - width) / 2
y: (window.height - height) / 2
width: 480
id: sourceDialog
parent: ApplicationWindow.overlay
modal: true
standardButtons: Dialog.Ok
padding: 16
title: "View Source"
contentItem: ScrollView {
TextArea {
readOnly: true
selectByMouse: true
text: sourceDialog.sourceText
}
}
}
} }
ScrollBar { ScrollBar {

View File

@ -8,7 +8,8 @@ import Matrique 0.1
import SortFilterProxyModel 0.2 import SortFilterProxyModel 0.2
import Matrique.Settings 0.1 import Matrique.Settings 0.1
import "../component" import "qrc:/qml/component"
import "qrc:/qml/menu"
import "qrc:/js/util.js" as Util import "qrc:/js/util.js" as Util
Item { Item {
@ -114,7 +115,10 @@ Item {
hoverEnabled: MSettings.miniMode hoverEnabled: MSettings.miniMode
onSecondaryClicked: Qt.createComponent("qrc:/qml/menu/RoomContextMenu.qml").createObject(this) onSecondaryClicked: {
roomContextMenu.room = currentRoom
roomContextMenu.popup()
}
onPrimaryClicked: category === RoomType.Invited ? inviteDialog.open() : enteredRoom = currentRoom onPrimaryClicked: category === RoomType.Invited ? inviteDialog.open() : enteredRoom = currentRoom
ToolTip.visible: MSettings.miniMode && containsMouse ToolTip.visible: MSettings.miniMode && containsMouse
@ -198,6 +202,8 @@ Item {
horizontalAlignment: MSettings.miniMode ? Text.AlignHCenter : undefined horizontalAlignment: MSettings.miniMode ? Text.AlignHCenter : undefined
} }
RoomContextMenu { id: roomContextMenu }
Dialog { Dialog {
id: inviteDialog id: inviteDialog
parent: ApplicationWindow.overlay parent: ApplicationWindow.overlay

View File

@ -123,6 +123,8 @@ ApplicationWindow {
width: parent.width width: parent.width
height: width height: width
selected: stackView.currentItem === page && currentConnection === connection
ImageItem { ImageItem {
anchors.fill: parent anchors.fill: parent
anchors.margins: 12 anchors.margins: 12

View File

@ -2,6 +2,13 @@ import QtQuick 2.9
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
Menu { Menu {
property var row
property bool canRedact
property string eventType
property string plainText
property string toolTip
property string eventId
readonly property bool isFile: eventType === "video" || eventType === "audio" || eventType === "file" || eventType === "image" readonly property bool isFile: eventType === "video" || eventType === "audio" || eventType === "file" || eventType === "image"
id: messageContextMenu id: messageContextMenu
@ -12,32 +19,32 @@ Menu {
onTriggered: matriqueController.copyToClipboard(plainText) onTriggered: matriqueController.copyToClipboard(plainText)
} }
MenuItem { MenuItem {
text: "Copy Source" text: "View Source"
onTriggered: matriqueController.copyToClipboard(toolTip) onTriggered: {
sourceDialog.sourceText = toolTip
sourceDialog.open()
}
} }
MenuItem { MenuItem {
visible: isFile visible: isFile
height: visible ? undefined : 0 height: visible ? undefined : 0
text: "Open Externally" text: "Open Externally"
onTriggered: messageRow.openExternally() onTriggered: row.openExternally()
} }
MenuItem { MenuItem {
visible: isFile visible: isFile
height: visible ? undefined : 0 height: visible ? undefined : 0
text: "Save As" text: "Save As"
onTriggered: messageRow.saveFileAs() onTriggered: row.saveFileAs()
} }
MenuItem { MenuItem {
visible: sentByMe visible: canRedact
height: visible ? undefined : 0 height: visible ? undefined : 0
text: "Redact" text: "Redact"
onTriggered: currentRoom.redactEvent(eventId) onTriggered: currentRoom.redactEvent(eventId)
} }
Component.onCompleted: popup()
onClosed: messageContextMenu.destroy()
} }

View File

@ -2,34 +2,33 @@ import QtQuick 2.9
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
Menu { Menu {
property var room: null
id: roomListMenu id: roomListMenu
MenuItem { MenuItem {
text: "Favourite" text: "Favourite"
checkable: true checkable: true
checked: currentRoom && currentRoom.isFavourite checked: room && room.isFavourite
onTriggered: currentRoom.isFavourite ? currentRoom.removeTag("m.favourite") : currentRoom.addTag("m.favourite", "1") onTriggered: room.isFavourite ? room.removeTag("m.favourite") : room.addTag("m.favourite", "1")
} }
MenuItem { MenuItem {
text: "Deprioritize" text: "Deprioritize"
checkable: true checkable: true
checked: currentRoom && currentRoom.isLowPriority checked: room && room.isLowPriority
onTriggered: currentRoom.isLowPriority ? currentRoom.removeTag("m.lowpriority") : currentRoom.addTag("m.lowpriority", "1") onTriggered: room.isLowPriority ? room.removeTag("m.lowpriority") : room.addTag("m.lowpriority", "1")
} }
MenuSeparator {} MenuSeparator {}
MenuItem { MenuItem {
text: "Mark as Read" text: "Mark as Read"
onTriggered: currentRoom.markAllMessagesAsRead() onTriggered: room.markAllMessagesAsRead()
} }
MenuItem { MenuItem {
text: "Leave Room" text: "Leave Room"
onTriggered: currentRoom.forget() onTriggered: room.forget()
} }
Component.onCompleted: popup()
onClosed: roomListMenu.destroy()
} }

View File

@ -373,7 +373,7 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
: tr("self-unbanned"); : tr("self-unbanned");
} }
return (e.senderId() != e.userId()) return (e.senderId() != e.userId())
? tr("has put %1 out of the room").arg(subjectName) ? tr("has kicked %1 from the room").arg(subjectName)
: tr("left the room"); : tr("left the room");
case MembershipType::Ban: case MembershipType::Ban:
return (e.senderId() != e.userId()) return (e.senderId() != e.userId())
@ -472,7 +472,7 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
: tr("self-unbanned"); : tr("self-unbanned");
} }
return (e.senderId() != e.userId()) return (e.senderId() != e.userId())
? tr("has put %1 out of the room").arg(subjectName) ? tr("has kicked %1 from the room").arg(subjectName)
: tr("left the room"); : tr("left the room");
case MembershipType::Ban: case MembershipType::Ban:
return (e.senderId() != e.userId()) return (e.senderId() != e.userId())

View File

@ -67,6 +67,9 @@ QVariant UserListModel::data(const QModelIndex& index, int role) const {
if (role == NameRole) { if (role == NameRole) {
return user->displayname(m_currentRoom); return user->displayname(m_currentRoom);
} }
if (role == UserIDRole) {
return user->id();
}
if (role == AvatarRole) { if (role == AvatarRole) {
if (!user->avatarUrl(m_currentRoom).isEmpty()) if (!user->avatarUrl(m_currentRoom).isEmpty())
return user->avatar(64, m_currentRoom); return user->avatar(64, m_currentRoom);
@ -126,6 +129,7 @@ int UserListModel::findUserPos(const QString& username) const {
QHash<int, QByteArray> UserListModel::roleNames() const { QHash<int, QByteArray> UserListModel::roleNames() const {
QHash<int, QByteArray> roles; QHash<int, QByteArray> roles;
roles[NameRole] = "name"; roles[NameRole] = "name";
roles[UserIDRole] = "userId";
roles[AvatarRole] = "avatar"; roles[AvatarRole] = "avatar";
return roles; return roles;
} }

View File

@ -17,7 +17,7 @@ class UserListModel : public QAbstractListModel {
Q_PROPERTY( Q_PROPERTY(
QMatrixClient::Room* room READ room WRITE setRoom NOTIFY roomChanged) QMatrixClient::Room* room READ room WRITE setRoom NOTIFY roomChanged)
public: public:
enum EventRoles { NameRole = Qt::UserRole + 1, AvatarRole }; enum EventRoles { NameRole = Qt::UserRole + 1, UserIDRole, AvatarRole };
using User = QMatrixClient::User; using User = QMatrixClient::User;