mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-27 21:48:48 +03:00
add narrow layout
This commit is contained in:
parent
b599f5c0c6
commit
39d7390092
4 changed files with 66 additions and 27 deletions
|
@ -17,15 +17,16 @@ ApplicationWindow {
|
||||||
property InviteesModel invitees
|
property InviteesModel invitees
|
||||||
property var friendsCompleter
|
property var friendsCompleter
|
||||||
property var profile
|
property var profile
|
||||||
minimumWidth: 500
|
minimumWidth: 300
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
friendsCompleter = TimelineManager.completerFor("user", "friends")
|
friendsCompleter = TimelineManager.completerFor("user", "friends")
|
||||||
|
width = 600
|
||||||
}
|
}
|
||||||
|
|
||||||
function addInvite(mxid) {
|
function addInvite(mxid, displayName, avatarUrl) {
|
||||||
if (mxid.match("@.+?:.{3,}")) {
|
if (mxid.match("@.+?:.{3,}")) {
|
||||||
invitees.addUser(mxid);
|
invitees.addUser(mxid, displayName, avatarUrl);
|
||||||
if (mxid == inviteeEntry.text)
|
if (mxid == inviteeEntry.text)
|
||||||
inviteeEntry.clear();
|
inviteeEntry.clear();
|
||||||
} else
|
} else
|
||||||
|
@ -34,7 +35,7 @@ ApplicationWindow {
|
||||||
|
|
||||||
function cleanUpAndClose() {
|
function cleanUpAndClose() {
|
||||||
if (inviteeEntry.isValidMxid)
|
if (inviteeEntry.isValidMxid)
|
||||||
addInvite(inviteeEntry.text);
|
addInvite(inviteeEntry.text, "", "");
|
||||||
|
|
||||||
invitees.accept();
|
invitees.accept();
|
||||||
close();
|
close();
|
||||||
|
@ -61,13 +62,40 @@ ApplicationWindow {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: Nheko.paddingMedium
|
anchors.margins: Nheko.paddingMedium
|
||||||
spacing: Nheko.paddingMedium
|
spacing: Nheko.paddingMedium
|
||||||
|
Flow {
|
||||||
|
layoutDirection: Qt.LeftToRight
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.preferredHeight: implicitHeight
|
||||||
|
spacing: 4
|
||||||
|
Repeater {
|
||||||
|
id: inviteesRepeater
|
||||||
|
model: invitees
|
||||||
|
delegate: ItemDelegate {
|
||||||
|
onClicked: invitees.removeUser(model.mxid)
|
||||||
|
id: inviteeButton
|
||||||
|
visible: !inviteesList.visible
|
||||||
|
contentItem: Label {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
id: inviteeUserid
|
||||||
|
text: model.displayName
|
||||||
|
color: inviteeButton.hovered ? Nheko.colors.highlightedText: Nheko.colors.text
|
||||||
|
maximumLineCount: 1
|
||||||
|
}
|
||||||
|
background: Rectangle {
|
||||||
|
border.color: Nheko.colors.text
|
||||||
|
color: inviteeButton.hovered ? Nheko.colors.highlight : Nheko.colors.window
|
||||||
|
border.width: 1
|
||||||
|
radius: inviteeButton.height / 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
text: qsTr("User ID to invite")
|
text: qsTr("User to invite")
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
color: Nheko.colors.text
|
color: Nheko.colors.text
|
||||||
}
|
}
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
spacing: Nheko.paddingMedium
|
spacing: Nheko.paddingMedium
|
||||||
|
|
||||||
|
@ -81,7 +109,7 @@ ApplicationWindow {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
if (isValidMxid)
|
if (isValidMxid)
|
||||||
addInvite(text);
|
addInvite(text, "", "");
|
||||||
|
|
||||||
}
|
}
|
||||||
Component.onCompleted: forceActiveFocus()
|
Component.onCompleted: forceActiveFocus()
|
||||||
|
@ -123,7 +151,7 @@ ApplicationWindow {
|
||||||
Layout.preferredWidth: inviteDialogRoot.width/2
|
Layout.preferredWidth: inviteDialogRoot.width/2
|
||||||
Layout.alignment: Qt.AlignTop
|
Layout.alignment: Qt.AlignTop
|
||||||
Layout.preferredHeight: layout3.implicitHeight + Nheko.paddingSmall * 2
|
Layout.preferredHeight: layout3.implicitHeight + Nheko.paddingSmall * 2
|
||||||
onClicked: addInvite(inviteeEntry.text)
|
onClicked: addInvite(inviteeEntry.text, profile? profile.displayName : "", profile? profile.avatarUrl : "")
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
color: del3.hovered ? Nheko.colors.dark : inviteDialogRoot.color
|
color: del3.hovered ? Nheko.colors.dark : inviteDialogRoot.color
|
||||||
clip: true
|
clip: true
|
||||||
|
@ -174,7 +202,7 @@ ApplicationWindow {
|
||||||
id: del2
|
id: del2
|
||||||
width: ListView.view.width
|
width: ListView.view.width
|
||||||
height: layout2.implicitHeight + Nheko.paddingSmall * 2
|
height: layout2.implicitHeight + Nheko.paddingSmall * 2
|
||||||
onClicked: addInvite(model.userid)
|
onClicked: addInvite(model.userid, model.displayName, model.avatarUrl)
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
color: del2.hovered ? Nheko.colors.dark : inviteDialogRoot.color
|
color: del2.hovered ? Nheko.colors.dark : inviteDialogRoot.color
|
||||||
}
|
}
|
||||||
|
@ -221,6 +249,7 @@ ApplicationWindow {
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
model: invitees
|
model: invitees
|
||||||
clip: true
|
clip: true
|
||||||
|
visible: inviteDialogRoot.width >= 500
|
||||||
|
|
||||||
delegate: ItemDelegate {
|
delegate: ItemDelegate {
|
||||||
id: del
|
id: del
|
||||||
|
|
|
@ -16,7 +16,7 @@ InviteesModel::InviteesModel(QObject *parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
InviteesModel::addUser(QString mxid)
|
InviteesModel::addUser(QString mxid, QString displayName, QString avatarUrl)
|
||||||
{
|
{
|
||||||
for (const auto &invitee : qAsConst(invitees_))
|
for (const auto &invitee : qAsConst(invitees_))
|
||||||
if (invitee->mxid_ == mxid)
|
if (invitee->mxid_ == mxid)
|
||||||
|
@ -24,7 +24,7 @@ InviteesModel::addUser(QString mxid)
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), invitees_.count(), invitees_.count());
|
beginInsertRows(QModelIndex(), invitees_.count(), invitees_.count());
|
||||||
|
|
||||||
auto invitee = new Invitee{mxid, this};
|
auto invitee = new Invitee{mxid, displayName, avatarUrl, this};
|
||||||
auto indexOfInvitee = invitees_.count();
|
auto indexOfInvitee = invitees_.count();
|
||||||
connect(invitee, &Invitee::userInfoLoaded, this, [this, indexOfInvitee]() {
|
connect(invitee, &Invitee::userInfoLoaded, this, [this, indexOfInvitee]() {
|
||||||
emit dataChanged(index(indexOfInvitee), index(indexOfInvitee));
|
emit dataChanged(index(indexOfInvitee), index(indexOfInvitee));
|
||||||
|
@ -84,12 +84,14 @@ InviteesModel::mxids()
|
||||||
return mxidList;
|
return mxidList;
|
||||||
}
|
}
|
||||||
|
|
||||||
Invitee::Invitee(QString mxid, QObject *parent)
|
Invitee::Invitee(QString mxid, QString displayName, QString avatarUrl, QObject *parent)
|
||||||
: QObject{parent}
|
: QObject{parent}
|
||||||
, mxid_{std::move(mxid)}
|
, mxid_{std::move(mxid)}
|
||||||
{
|
{
|
||||||
|
if (displayName == "" || avatarUrl == "") {
|
||||||
http::client()->get_profile(
|
http::client()->get_profile(
|
||||||
mxid_.toStdString(), [this](const mtx::responses::Profile &res, mtx::http::RequestErr err) {
|
mxid_.toStdString(),
|
||||||
|
[this](const mtx::responses::Profile &res, mtx::http::RequestErr err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
nhlog::net()->warn("failed to retrieve profile info");
|
nhlog::net()->warn("failed to retrieve profile info");
|
||||||
emit userInfoLoaded();
|
emit userInfoLoaded();
|
||||||
|
@ -101,4 +103,9 @@ Invitee::Invitee(QString mxid, QObject *parent)
|
||||||
|
|
||||||
emit userInfoLoaded();
|
emit userInfoLoaded();
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
displayName_ = displayName;
|
||||||
|
avatarUrl_ = avatarUrl;
|
||||||
|
emit userInfoLoaded();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,10 @@ class Invitee final : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Invitee(QString mxid, QObject *parent = nullptr);
|
Invitee(QString mxid,
|
||||||
|
QString displayName = "",
|
||||||
|
QString avatarUrl = "",
|
||||||
|
QObject *parent = nullptr);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void userInfoLoaded();
|
void userInfoLoaded();
|
||||||
|
@ -43,7 +46,7 @@ public:
|
||||||
|
|
||||||
InviteesModel(QObject *parent = nullptr);
|
InviteesModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
Q_INVOKABLE void addUser(QString mxid);
|
Q_INVOKABLE void addUser(QString mxid, QString displayName = "", QString avatarUrl = "");
|
||||||
Q_INVOKABLE void removeUser(QString mxid);
|
Q_INVOKABLE void removeUser(QString mxid);
|
||||||
|
|
||||||
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
|
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
|
@ -77,11 +77,11 @@ UserDirectoryModel::data(const QModelIndex &index, int role) const
|
||||||
void
|
void
|
||||||
UserDirectoryModel::displaySearchResults(std::vector<mtx::responses::User> results)
|
UserDirectoryModel::displaySearchResults(std::vector<mtx::responses::User> results)
|
||||||
{
|
{
|
||||||
results_ = results;
|
|
||||||
if (results_.empty()) {
|
if (results_.empty()) {
|
||||||
nhlog::net()->error("mtxclient helper thread yielded empty chunk!");
|
nhlog::net()->error("mtxclient helper thread yielded empty chunk!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
beginInsertRows(QModelIndex(), 0, static_cast<int>(results_.size()) - 1);
|
beginInsertRows(QModelIndex(), 0, static_cast<int>(results_.size()) - 1);
|
||||||
|
results_ = results;
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue