Code cleanup.

square-messages
Black Hat 2018-12-15 22:29:51 +08:00
parent 076c501605
commit df045a786f
12 changed files with 129 additions and 145 deletions

View File

@ -3,6 +3,7 @@ import QtQuick.Controls 2.4
import QtQuick.Layouts 1.3
import QtQuick.Controls.Material 2.4
import QtGraphicalEffects 1.0
import Qt.labs.platform 1.0 as Platform
import Spectral 0.1
import Spectral.Setting 0.1
@ -14,13 +15,15 @@ ColumnLayout {
readonly property bool avatarVisible: !sentByMe && (aboveAuthor !== author || aboveSection !== section || aboveEventType === "state" || aboveEventType === "emote" || aboveEventType === "other")
readonly property bool sentByMe: author === currentRoom.localUser
signal saveFileAs()
signal openExternally()
property bool openOnFinished: false
readonly property bool downloaded: progressInfo && progressInfo.completed
id: root
spacing: 0
onDownloadedChanged: if (downloaded && openOnFinished) openSavedFile()
Label {
Layout.leftMargin: 48
@ -72,7 +75,6 @@ ColumnLayout {
id: img
source: "image://mxc/" + (content.thumbnail_url ? content.thumbnail_url : content.url)
sourceSize.width: Math.min(256, messageListView.width)
layer.enabled: true
layer.effect: OpacityMask {
@ -88,13 +90,65 @@ ColumnLayout {
id: messageMouseArea
onSecondaryClicked: {
messageContextMenu.root = root
messageContextMenu.model = model
messageContextMenu.selectedText = ""
messageContextMenu.popup()
onSecondaryClicked: messageContextMenu.popup()
Menu {
id: messageContextMenu
MenuItem {
text: "View Source"
onTriggered: {
sourceDialog.sourceText = toolTip
sourceDialog.open()
}
}
MenuItem {
text: "Open Externally"
onTriggered: downloadAndOpen()
}
MenuItem {
text: "Save As"
onTriggered: saveFileAs()
}
MenuItem {
text: "Reply"
onTriggered: {
roomPanelInput.replyUser = author
roomPanelInput.replyEventID = eventId
roomPanelInput.replyContent = message
roomPanelInput.isReply = true
roomPanelInput.focus()
}
}
MenuItem {
text: "Redact"
onTriggered: currentRoom.redactEvent(eventId)
}
}
}
}
}
function saveFileAs() { currentRoom.saveFileAs(eventId) }
function downloadAndOpen()
{
if (downloaded) openSavedFile()
else
{
openOnFinished = true
currentRoom.downloadFile(eventId, Platform.StandardPaths.writableLocation(Platform.StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_") + (message || ".tmp"))
}
}
function openSavedFile()
{
if (Qt.openUrlExternally(progressInfo.localPath)) return;
if (Qt.openUrlExternally(progressInfo.localDir)) return;
}
}

View File

@ -80,11 +80,37 @@ ColumnLayout {
id: messageMouseArea
onSecondaryClicked: {
messageContextMenu.root = root
messageContextMenu.model = model
messageContextMenu.selectedText = contentLabel.selectedText
messageContextMenu.popup()
onSecondaryClicked: messageContextMenu.popup()
Menu {
readonly property string selectedText: contentLabel.selectedText
id: messageContextMenu
MenuItem {
text: "View Source"
onTriggered: {
sourceDialog.sourceText = toolTip
sourceDialog.open()
}
}
MenuItem {
text: "Reply"
onTriggered: {
roomPanelInput.replyUser = author
roomPanelInput.replyEventID = eventId
roomPanelInput.replyContent = messageContextMenu.selectedText || message
roomPanelInput.isReply = true
roomPanelInput.focus()
}
}
MenuItem {
text: "Redact"
onTriggered: currentRoom.redactEvent(eventId)
}
}
}
}

View File

@ -2,9 +2,4 @@ pragma Singleton
import QtQuick 2.12
import QtQuick.Controls 2.4
Item {
property alias font: materialLabel.font
Label {
id: materialLabel
}
}
Label {}

View File

@ -1,54 +0,0 @@
import QtQuick 2.12
import QtQuick.Controls 2.4
Menu {
property var root: null
property var model: null
property string selectedText
readonly property bool isFile: model && (model.eventType === "video" || model.eventType === "audio" || model.eventType === "file" || model.eventType === "image")
id: messageContextMenu
MenuItem {
text: "View Source"
onTriggered: {
sourceDialog.sourceText = model.toolTip
sourceDialog.open()
}
}
MenuItem {
visible: isFile
height: visible ? undefined : 0
text: "Open Externally"
onTriggered: root.openExternally()
}
MenuItem {
visible: isFile
height: visible ? undefined : 0
text: "Save As"
onTriggered: root.saveFileAs()
}
MenuItem {
height: visible ? undefined : 0
text: "Reply"
onTriggered: {
roomPanelInput.replyUser = model.author
roomPanelInput.replyEventID = model.eventId
roomPanelInput.replyContent = selectedText != "" ? selectedText : model.message
roomPanelInput.isReply = true
roomPanelInput.focus()
}
}
MenuItem {
visible: model && model.author === currentRoom.localUser
height: visible ? undefined : 0
text: "Redact"
onTriggered: currentRoom.redactEvent(model.eventId)
}
}

View File

@ -1,35 +0,0 @@
import QtQuick 2.12
import QtQuick.Controls 2.4
import Spectral 0.1
Menu {
property var model: null
id: roomListMenu
MenuItem {
text: "Favourite"
checkable: true
checked: model && model.category === RoomType.Favorite
onTriggered: model.category === RoomType.Favorite ? model.currentRoom.removeTag("m.favourite") : model.currentRoom.addTag("m.favourite", 1.0)
}
MenuItem {
text: "Deprioritize"
checkable: true
checked: model && model.category === RoomType.Deprioritized
onTriggered: model.category === RoomType.Deprioritized ? model.currentRoom.removeTag("m.lowpriority") : model.currentRoom.addTag("m.lowpriority", 1.0)
}
MenuSeparator {}
MenuItem {
text: "Mark as Read"
onTriggered: model.currentRoom.markAllMessagesAsRead()
}
MenuItem {
text: "Leave Room"
onTriggered: model.currentRoom.forget()
}
}

View File

@ -1,3 +0,0 @@
module Spectral.Menu
MessageContextMenu 2.0 MessageContextMenu.qml
RoomContextMenu 2.0 RoomContextMenu.qml

View File

@ -5,7 +5,6 @@ import QtQuick.Layouts 1.3
import QtQuick.Controls.Material 2.4
import Spectral.Component 2.0
import Spectral.Menu 2.0
import Spectral.Effect 2.0
import Spectral 0.1
@ -489,11 +488,8 @@ Rectangle {
stepSize: 25
snapMode: Slider.SnapAlways
ToolTip {
Material.foreground: "white"
visible: parent.pressed
text: parent.value
}
ToolTip.visible: pressed
ToolTip.text: value
onMoved: controller.setDpi(value)
}
@ -804,10 +800,7 @@ Rectangle {
RippleEffect {
anchors.fill: parent
onSecondaryClicked: {
roomContextMenu.model = model
roomContextMenu.popup()
}
onSecondaryClicked: roomContextMenu.popup()
onPrimaryClicked: {
if (category === RoomType.Invited) {
inviteDialog.currentRoom = currentRoom
@ -823,6 +816,36 @@ Rectangle {
}
}
}
Menu {
id: roomContextMenu
MenuItem {
text: "Favourite"
checkable: true
checked: category === RoomType.Favorite
onTriggered: category === RoomType.Favorite ? currentRoom.removeTag("m.favourite") : currentRoom.addTag("m.favourite", 1.0)
}
MenuItem {
text: "Deprioritize"
checkable: true
checked: category === RoomType.Deprioritized
onTriggered: category === RoomType.Deprioritized ? currentRoom.removeTag("m.lowpriority") : currentRoom.addTag("m.lowpriority", 1.0)
}
MenuSeparator {}
MenuItem {
text: "Mark as Read"
onTriggered: currentRoom.markAllMessagesAsRead()
}
MenuItem {
text: "Leave Room"
onTriggered: currentRoom.forget()
}
}
}
section.property: "display"
@ -837,10 +860,6 @@ Rectangle {
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
}
RoomContextMenu {
id: roomContextMenu
}
}
}

View File

@ -7,7 +7,6 @@ import Qt.labs.qmlmodels 1.0
import Spectral.Component 2.0
import Spectral.Component.Emoji 2.0
import Spectral.Component.Timeline 2.0
import Spectral.Menu 2.0
import Spectral.Effect 2.0
import Spectral 0.1
@ -266,10 +265,6 @@ Item {
onClicked: messageListView.positionViewAtBeginning()
}
MessageContextMenu {
id: messageContextMenu
}
Popup {
property string sourceText

View File

@ -251,13 +251,8 @@ Control {
onTriggered: currentRoom.sendTypingNotification(true)
}
ToolTip {
visible: currentRoom
&& currentRoom.hasUsersTyping
text: currentRoom ? currentRoom.usersTyping : ""
Material.foreground: "white"
}
ToolTip.visible: currentRoom && currentRoom.hasUsersTyping
ToolTip.text: currentRoom ? currentRoom.usersTyping : ""
Keys.onReturnPressed: {
if (event.modifiers & Qt.ShiftModifier) {

View File

@ -26,9 +26,6 @@ ApplicationWindow {
visible: true
title: qsTr("Spectral")
Material.foreground: MSettings.darkTheme ? "#FFFFFF" : "#1D333E"
Material.background: MSettings.darkTheme ? "#303030" : "#FFFFFF"
Platform.SystemTrayIcon {
visible: MSettings.showTray
iconSource: "qrc:/assets/img/icon.png"
@ -132,7 +129,6 @@ ApplicationWindow {
ToolTip {
id: loginButtonTooltip
Material.foreground: "white"
}
}

View File

@ -10,6 +10,5 @@ Theme=Light
Variant=Dense
Primary=#344955
Accent=#673AB7
Foreground=#1D333E
Background=#FFFFFF
Font/Family="Roboto,Noto Sans,Noto Color Emoji"

View File

@ -14,9 +14,6 @@
<file>imports/Spectral/Component/qmldir</file>
<file>imports/Spectral/Effect/ElevationEffect.qml</file>
<file>imports/Spectral/Effect/qmldir</file>
<file>imports/Spectral/Menu/MessageContextMenu.qml</file>
<file>imports/Spectral/Menu/qmldir</file>
<file>imports/Spectral/Menu/RoomContextMenu.qml</file>
<file>imports/Spectral/Page/qmldir</file>
<file>assets/font/material.ttf</file>
<file>assets/img/icon.icns</file>