From 1ec20886a8acadc4212845695de167666724a29f Mon Sep 17 00:00:00 2001 From: Simon Redman Date: Tue, 26 Feb 2019 22:45:54 -0700 Subject: [PATCH] [SMS App] Add highlighting to ConversationList view Summary: Let the ListView use its default highlighting (did I not notice before?) and keep the currently-selected chat highlighted at all times Test Plan: - Launch app - Use mouse or arrow keys to select a conversation. The highlight should follow the selected conversation Reviewers: #kde_connect, apol Reviewed By: #kde_connect, apol Subscribers: apol, kdeconnect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D17612 --- smsapp/conversationlistmodel.cpp | 1 + smsapp/conversationlistmodel.h | 5 ++++- smsapp/conversationmodel.cpp | 3 ++- smsapp/qml/ConversationList.qml | 14 ++++++++++++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/smsapp/conversationlistmodel.cpp b/smsapp/conversationlistmodel.cpp index ade64d485..49610fa03 100644 --- a/smsapp/conversationlistmodel.cpp +++ b/smsapp/conversationlistmodel.cpp @@ -67,6 +67,7 @@ void ConversationListModel::setDeviceId(const QString& deviceId) } m_deviceId = deviceId; + Q_EMIT deviceIdChanged(); // This method still gets called *with a valid deviceID* when the device is not connected while the component is setting up // Detect that case and don't do anything. diff --git a/smsapp/conversationlistmodel.h b/smsapp/conversationlistmodel.h index 7193e6dd9..61885be9e 100644 --- a/smsapp/conversationlistmodel.h +++ b/smsapp/conversationlistmodel.h @@ -68,7 +68,7 @@ class ConversationListModel : public QStandardItemModel { Q_OBJECT - Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId) + Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged) public: ConversationListModel(QObject* parent = nullptr); @@ -92,6 +92,9 @@ public Q_SLOTS: void createRowFromMessage(const QVariantMap& message); void printDBusError(const QDBusError& error); +Q_SIGNALS: + void deviceIdChanged(); + private: /** * Get all conversations currently known by the conversationsInterface, if any diff --git a/smsapp/conversationmodel.cpp b/smsapp/conversationmodel.cpp index ee4f26e22..085746f34 100644 --- a/smsapp/conversationmodel.cpp +++ b/smsapp/conversationmodel.cpp @@ -51,7 +51,8 @@ void ConversationModel::setThreadId(const qint64& threadId) m_threadId = threadId; clear(); - if (threadId != INVALID_THREAD_ID) { + knownMessageIDs.clear(); + if (m_threadId != INVALID_THREAD_ID && m_deviceId != "") { requestMoreMessages(); } } diff --git a/smsapp/qml/ConversationList.qml b/smsapp/qml/ConversationList.qml index c405d2278..038b66f72 100644 --- a/smsapp/qml/ConversationList.qml +++ b/smsapp/qml/ConversationList.qml @@ -55,7 +55,7 @@ Kirigami.ScrollablePage readonly property QtObject device: devicesCombo.currentIndex >= 0 ? devicesModel.data(devicesModel.index(devicesCombo.currentIndex, 0), DevicesModel.DeviceRole) : null readonly property alias lastDeviceId: conversationListModel.deviceId - Component { + ConversationDisplay { id: chatView ConversationDisplay { deviceId: page.lastDeviceId @@ -122,7 +122,17 @@ Kirigami.ScrollablePage conversationId: model.conversationId, }) } - onClicked: { startChat(); } + onClicked: { + startChat(); + view.currentIndex = index + } + // Keep the currently-open chat highlighted even if this element is not focused + highlighted: chatView.conversationId == model.conversationId + } + + Component.onCompleted: { + currentIndex = -1 + focus = true } }