diff --git a/src/chatbar/ChatBarCore.qml b/src/chatbar/ChatBarCore.qml index a15af0195..f6e4f1cea 100644 --- a/src/chatbar/ChatBarCore.qml +++ b/src/chatbar/ChatBarCore.qml @@ -72,12 +72,12 @@ QQC2.Control { visible: NeoChatConfig.sendMessageWith === 1 } RowLayout { - spacing: 0 QQC2.ScrollView { id: chatScrollView Layout.fillWidth: true Layout.maximumHeight: Kirigami.Units.gridUnit * 8 + contentWidth: availableWidth clip: true ColumnLayout { diff --git a/src/messagecontent/FileComponent.qml b/src/messagecontent/FileComponent.qml index 965426171..02bfc9b9d 100644 --- a/src/messagecontent/FileComponent.qml +++ b/src/messagecontent/FileComponent.qml @@ -36,6 +36,11 @@ ColumnLayout { */ required property var fileTransferInfo + /** + * @brief Whether the component should be editable. + */ + required property bool editable + /** * @brief Whether the media has been downloaded. */ @@ -66,6 +71,7 @@ ColumnLayout { spacing: Kirigami.Units.largeSpacing RowLayout { + Layout.fillWidth: true spacing: Kirigami.Units.largeSpacing states: [ @@ -137,6 +143,7 @@ ColumnLayout { QQC2.Button { id: openButton + visible: !root.editable icon.name: "document-open" onClicked: { root.autoOpenFile = true; @@ -150,6 +157,7 @@ ColumnLayout { QQC2.Button { id: downloadButton + visible: !root.editable icon.name: "download" onClicked: root.saveFileAs() @@ -158,6 +166,18 @@ ColumnLayout { QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay } + QQC2.Button { + id: cancelButton + visible: root.editable + display: QQC2.AbstractButton.IconOnly + text: i18nc("@action:button", "Remove attachment") + icon.name: "dialog-close" + onClicked: root.Message.contentModel?.removeAttachment() + QQC2.ToolTip.text: text + QQC2.ToolTip.visible: hovered + QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay + } + Component { id: fileDialog diff --git a/src/messagecontent/models/chatbarmessagecontentmodel.cpp b/src/messagecontent/models/chatbarmessagecontentmodel.cpp index e901fc4d2..adfb291ab 100644 --- a/src/messagecontent/models/chatbarmessagecontentmodel.cpp +++ b/src/messagecontent/models/chatbarmessagecontentmodel.cpp @@ -144,6 +144,10 @@ void ChatBarMessageContentModel::initializeFromCache() } endResetModel(); + if (currentCache->attachmentPath().length() > 0) { + addAttachment(QUrl(currentCache->attachmentPath())); + } + m_currentFocusComponent = QPersistentModelIndex(index(rowCount() - 1)); Q_EMIT focusRowChanged(); } @@ -365,12 +369,16 @@ void ChatBarMessageContentModel::addAttachment(const QUrl &path) clearModel(); initializeModel(plainText); + QFileInfo fileInfo(path.isLocalFile() ? path.toLocalFile() : path.toString()); + auto mime = QMimeDatabase().mimeTypeForUrl(path); auto it = insertComponent(m_components.first().type == MessageComponentType::Reply ? 1 : 0, MessageComponentType::typeForPath(path), { {"filename"_L1, path.fileName()}, {"source"_L1, path}, {"animated"_L1, false}, + {"mimeIcon"_L1, mime.name()}, + {"size"_L1, fileInfo.size()}, }); it->display = path.fileName(); Q_EMIT dataChanged(index(std::distance(m_components.begin(), it)), index(std::distance(m_components.begin(), it)), {DisplayRole}); @@ -662,6 +670,9 @@ std::optional ChatBarMessageContentModel::getReplyEventId() void ChatBarMessageContentModel::clearModel() { + const auto hadAttachment = + hasComponentType({MessageComponentType::File, MessageComponentType::Audio, MessageComponentType::Image, MessageComponentType::Video}); + beginResetModel(); for (const auto &component : m_components) { if (const auto textItem = textItemForComponent(component)) { @@ -671,6 +682,10 @@ void ChatBarMessageContentModel::clearModel() } m_components.clear(); endResetModel(); + + if (hadAttachment) { + Q_EMIT hasAttachmentChanged(); + } } #include "moc_chatbarmessagecontentmodel.cpp"