Improve accountlistmodel.
This commit is contained in:
parent
647a2cdbf2
commit
20113fb47f
|
@ -28,7 +28,8 @@ Page {
|
||||||
|
|
||||||
id: accountSettingsListView
|
id: accountSettingsListView
|
||||||
|
|
||||||
delegate: SwipeDelegate {
|
delegate: Column {
|
||||||
|
SwipeDelegate {
|
||||||
width: accountSettingsListView.width
|
width: accountSettingsListView.width
|
||||||
height: 64
|
height: 64
|
||||||
|
|
||||||
|
@ -44,17 +45,17 @@ Page {
|
||||||
width: parent.height
|
width: parent.height
|
||||||
height: parent.height
|
height: parent.height
|
||||||
|
|
||||||
hint: name
|
hint: user.displayName
|
||||||
defaultColor: Util.stringToColor(name)
|
defaultColor: Util.stringToColor(user.displayName)
|
||||||
image: avatar
|
image: user.avatar
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
Label {
|
Label {
|
||||||
text: name
|
text: user.displayName
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
text: accountID
|
text: user.id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,6 +76,65 @@ Page {
|
||||||
|
|
||||||
SwipeDelegate.onClicked: matriqueController.logout(connection)
|
SwipeDelegate.onClicked: matriqueController.logout(connection)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onClicked: accountSettingsListView.currentIndex == index ? accountSettingsListView.currentIndex = -1 : accountSettingsListView.currentIndex = index
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
width: parent.width
|
||||||
|
height: 2
|
||||||
|
visible: accountSettingsListView.currentIndex == index
|
||||||
|
|
||||||
|
color: Material.accent
|
||||||
|
}
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
visible: accountSettingsListView.currentIndex == index
|
||||||
|
width: parent.width - 32
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
|
||||||
|
spacing: 16
|
||||||
|
|
||||||
|
Label { text: "Homeserver:" }
|
||||||
|
TextField {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
|
||||||
|
text: connection.homeserver
|
||||||
|
selectByMouse: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,8 +123,8 @@ ApplicationWindow {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: 12
|
anchors.margins: 12
|
||||||
|
|
||||||
hint: name
|
hint: user.displayName
|
||||||
image: avatar
|
image: user.avatar
|
||||||
defaultColor: Material.accent
|
defaultColor: Material.accent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,7 @@ void AccountListModel::setController(Controller* value) {
|
||||||
|
|
||||||
m_controller = value;
|
m_controller = value;
|
||||||
|
|
||||||
for (auto c : m_controller->connections()) {
|
for (auto c : m_controller->connections()) m_connections.append(c);
|
||||||
connectConnectionSignals(c);
|
|
||||||
m_connections.append(c);
|
|
||||||
};
|
|
||||||
|
|
||||||
connect(m_controller, &Controller::connectionAdded, this,
|
connect(m_controller, &Controller::connectionAdded, this,
|
||||||
[=](Connection* conn) {
|
[=](Connection* conn) {
|
||||||
|
@ -23,7 +20,6 @@ void AccountListModel::setController(Controller* value) {
|
||||||
}
|
}
|
||||||
beginInsertRows(QModelIndex(), m_connections.count(),
|
beginInsertRows(QModelIndex(), m_connections.count(),
|
||||||
m_connections.count());
|
m_connections.count());
|
||||||
connectConnectionSignals(conn);
|
|
||||||
m_connections.append(conn);
|
m_connections.append(conn);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
});
|
});
|
||||||
|
@ -57,16 +53,8 @@ QVariant AccountListModel::data(const QModelIndex& index, int role) const {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
auto m_connection = m_connections.at(index.row());
|
auto m_connection = m_connections.at(index.row());
|
||||||
if (role == NameRole) {
|
if (role == UserRole) {
|
||||||
return m_connection->user()->displayname();
|
return QVariant::fromValue(m_connection->user());
|
||||||
}
|
|
||||||
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 == ConnectionRole) {
|
if (role == ConnectionRole) {
|
||||||
return QVariant::fromValue(m_connection);
|
return QVariant::fromValue(m_connection);
|
||||||
|
@ -81,22 +69,9 @@ int AccountListModel::rowCount(const QModelIndex& parent) const {
|
||||||
return m_connections.count();
|
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<int, QByteArray> AccountListModel::roleNames() const {
|
QHash<int, QByteArray> AccountListModel::roleNames() const {
|
||||||
QHash<int, QByteArray> roles;
|
QHash<int, QByteArray> roles;
|
||||||
roles[NameRole] = "name";
|
roles[UserRole] = "user";
|
||||||
roles[AccountIDRole] = "accountID";
|
|
||||||
roles[AvatarRole] = "avatar";
|
|
||||||
roles[ConnectionRole] = "connection";
|
roles[ConnectionRole] = "connection";
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,16 +11,11 @@ class AccountListModel : public QAbstractListModel {
|
||||||
Q_PROPERTY(Controller* controller READ controller WRITE setController NOTIFY
|
Q_PROPERTY(Controller* controller READ controller WRITE setController NOTIFY
|
||||||
controllerChanged)
|
controllerChanged)
|
||||||
public:
|
public:
|
||||||
enum EventRoles {
|
enum EventRoles { UserRole = Qt::UserRole + 1, ConnectionRole };
|
||||||
NameRole = Qt::UserRole + 1,
|
|
||||||
AccountIDRole,
|
|
||||||
AvatarRole,
|
|
||||||
ConnectionRole
|
|
||||||
};
|
|
||||||
|
|
||||||
AccountListModel(QObject* parent = nullptr);
|
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;
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
|
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
@ -32,7 +27,6 @@ class AccountListModel : public QAbstractListModel {
|
||||||
Controller* m_controller;
|
Controller* m_controller;
|
||||||
QVector<Connection*> m_connections;
|
QVector<Connection*> m_connections;
|
||||||
|
|
||||||
void connectConnectionSignals(Connection* conn);
|
|
||||||
signals:
|
signals:
|
||||||
void controllerChanged();
|
void controllerChanged();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue