diff --git a/qml/Setting.qml b/qml/Setting.qml index 5dab213..ccf18b2 100644 --- a/qml/Setting.qml +++ b/qml/Setting.qml @@ -28,52 +28,112 @@ Page { id: accountSettingsListView - delegate: SwipeDelegate { - width: accountSettingsListView.width - height: 64 + delegate: Column { + SwipeDelegate { + width: accountSettingsListView.width + height: 64 - clip: true + clip: true - Row { - anchors.fill: parent - anchors.margins: 8 + Row { + anchors.fill: parent + anchors.margins: 8 - spacing: 8 + spacing: 8 - ImageItem { + ImageItem { + width: parent.height + height: parent.height + + hint: user.displayName + defaultColor: Util.stringToColor(user.displayName) + image: user.avatar + } + + ColumnLayout { + Label { + text: user.displayName + } + Label { + text: user.id + } + } + } + + swipe.right: Rectangle { width: parent.height height: parent.height + anchors.right: parent.right - hint: name - defaultColor: Util.stringToColor(name) - image: avatar + color: Material.accent + + MaterialIcon { + anchors.fill: parent + + icon: "\ue879" + color: "white" + } + + SwipeDelegate.onClicked: matriqueController.logout(connection) } - ColumnLayout { - Label { - text: name - } - Label { - text: accountID - } - } + onClicked: accountSettingsListView.currentIndex == index ? accountSettingsListView.currentIndex = -1 : accountSettingsListView.currentIndex = index } - swipe.right: Rectangle { - width: parent.height - height: parent.height - anchors.right: parent.right + Rectangle { + width: parent.width + height: 2 + visible: accountSettingsListView.currentIndex == index color: Material.accent + } - MaterialIcon { - anchors.fill: parent + ColumnLayout { + visible: accountSettingsListView.currentIndex == index + width: parent.width - 32 + anchors.horizontalCenter: parent.horizontalCenter - icon: "\ue879" - color: "white" + RowLayout { + Layout.fillWidth: true + + spacing: 16 + + Label { text: "Homeserver:" } + TextField { + Layout.fillWidth: true + + text: connection.homeserver + selectByMouse: true + } } - SwipeDelegate.onClicked: matriqueController.logout(connection) + RowLayout { + Layout.fillWidth: true + + spacing: 16 + + Label { text: "Device ID:" } + TextField { + Layout.fillWidth: true + + text: connection.deviceId + selectByMouse: true + } + } + + RowLayout { + Layout.fillWidth: true + + spacing: 16 + + Label { text: "Access Token:" } + TextField { + Layout.fillWidth: true + + text: connection.accessToken + selectByMouse: true + } + } } } } diff --git a/qml/main.qml b/qml/main.qml index c2648e9..a80e99c 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -123,8 +123,8 @@ ApplicationWindow { anchors.fill: parent anchors.margins: 12 - hint: name - image: avatar + hint: user.displayName + image: user.avatar defaultColor: Material.accent } diff --git a/src/accountlistmodel.cpp b/src/accountlistmodel.cpp index d9868c1..198ac4f 100644 --- a/src/accountlistmodel.cpp +++ b/src/accountlistmodel.cpp @@ -12,10 +12,7 @@ void AccountListModel::setController(Controller* value) { m_controller = value; - for (auto c : m_controller->connections()) { - connectConnectionSignals(c); - m_connections.append(c); - }; + for (auto c : m_controller->connections()) m_connections.append(c); connect(m_controller, &Controller::connectionAdded, this, [=](Connection* conn) { @@ -23,7 +20,6 @@ void AccountListModel::setController(Controller* value) { } beginInsertRows(QModelIndex(), m_connections.count(), m_connections.count()); - connectConnectionSignals(conn); m_connections.append(conn); endInsertRows(); }); @@ -57,16 +53,8 @@ QVariant AccountListModel::data(const QModelIndex& index, int role) const { return QVariant(); } auto m_connection = m_connections.at(index.row()); - if (role == NameRole) { - return m_connection->user()->displayname(); - } - if (role == AccountIDRole) { - return m_connection->user()->id(); - } - if (role == AvatarRole) { - if (!m_connection->user()->avatarUrl().isEmpty()) - return m_connection->user()->avatar(64); - return QImage(); + if (role == UserRole) { + return QVariant::fromValue(m_connection->user()); } if (role == ConnectionRole) { return QVariant::fromValue(m_connection); @@ -81,22 +69,9 @@ int AccountListModel::rowCount(const QModelIndex& parent) const { return m_connections.count(); } -void AccountListModel::connectConnectionSignals(Connection* conn) { - connect(conn->user(), &User::avatarChanged, this, [=] { - const auto it = std::find(m_connections.begin(), m_connections.end(), conn); - if (it == m_connections.end()) { - return; - } - const auto idx = index(it - m_connections.begin()); - emit dataChanged(idx, idx, {AvatarRole}); - }); -} - QHash AccountListModel::roleNames() const { QHash roles; - roles[NameRole] = "name"; - roles[AccountIDRole] = "accountID"; - roles[AvatarRole] = "avatar"; + roles[UserRole] = "user"; roles[ConnectionRole] = "connection"; return roles; } diff --git a/src/accountlistmodel.h b/src/accountlistmodel.h index e8a8061..bf252e1 100644 --- a/src/accountlistmodel.h +++ b/src/accountlistmodel.h @@ -11,16 +11,11 @@ class AccountListModel : public QAbstractListModel { Q_PROPERTY(Controller* controller READ controller WRITE setController NOTIFY controllerChanged) public: - enum EventRoles { - NameRole = Qt::UserRole + 1, - AccountIDRole, - AvatarRole, - ConnectionRole - }; + enum EventRoles { UserRole = Qt::UserRole + 1, ConnectionRole }; AccountListModel(QObject* parent = nullptr); - QVariant data(const QModelIndex& index, int role = NameRole) const override; + QVariant data(const QModelIndex& index, int role = UserRole) const override; int rowCount(const QModelIndex& parent = QModelIndex()) const override; QHash roleNames() const override; @@ -32,7 +27,6 @@ class AccountListModel : public QAbstractListModel { Controller* m_controller; QVector m_connections; - void connectConnectionSignals(Connection* conn); signals: void controllerChanged(); };