diff options
author | kamathmanu <manuriddle@gmail.com> | 2021-08-12 10:45:42 -0400 |
---|---|---|
committer | kamathmanu <manuriddle@gmail.com> | 2021-08-12 10:45:42 -0400 |
commit | 9ab129613177f974afd10070e3a7d065d7aebbfa (patch) | |
tree | 1792c826a6f7cf101a6bc1b4bcece6728cebfafc | |
parent | Make search text selectable by clicking (diff) | |
download | nheko-9ab129613177f974afd10070e3a7d065d7aebbfa.tar.xz |
Ran qmlformat and make license
-rw-r--r-- | resources/qml/RoomDirectory.qml | 411 | ||||
-rw-r--r-- | src/RoomDirectoryModel.cpp | 31 | ||||
-rw-r--r-- | src/RoomDirectoryModel.h | 24 | ||||
-rw-r--r-- | src/timeline/TimelineViewManager.cpp | 3 |
4 files changed, 244 insertions, 225 deletions
diff --git a/resources/qml/RoomDirectory.qml b/resources/qml/RoomDirectory.qml index a3c3d4da..d507b796 100644 --- a/resources/qml/RoomDirectory.qml +++ b/resources/qml/RoomDirectory.qml @@ -1,195 +1,216 @@ -// SPDX-FileCopyrightText: 2021 Nheko Contributors -// -// SPDX-License-Identifier: GPL-3.0-or-later - -import "./ui" -import QtQuick 2.9 -import QtQuick.Controls 2.3 -import QtQuick.Layouts 1.3 -import im.nheko 1.0 - -ApplicationWindow { - id: roomDirectoryWindow - visible: true - - property RoomDirectoryModel publicRooms : RoomDirectoryModel {} - - x: MainWindow.x + (MainWindow.width / 2) - (width / 2) - y: MainWindow.y + (MainWindow.height / 2) - (height / 2) - minimumWidth: 650 - minimumHeight: 420 - palette: Nheko.colors - color: Nheko.colors.window - modality: Qt.WindowModal - flags: Qt.Dialog | Qt.WindowCloseButtonHint - title: qsTr("Explore Public Rooms") - - Shortcut { - sequence: StandardKey.Cancel - onActivated: roomDirectoryWindow.close() - } - - header: RowLayout { - id: searchBarLayout - spacing: Nheko.paddingMedium - width: parent.width - - implicitHeight: roomSearch.height - - MatrixTextField { - id: roomSearch - - Layout.fillWidth: true - selectByMouse: true - - font.pixelSize: fontMetrics.font.pixelSize - padding: Nheko.paddingMedium - color: Nheko.colors.text - placeholderText: qsTr("Search for public rooms") - onTextChanged: searchTimer.restart() - } - - Timer { - id: searchTimer - - interval: 350 - onTriggered: roomDirView.model.setSearchTerm(roomSearch.text) - } - } - - ListView { - id: roomDirView - anchors.fill: parent - model: publicRooms - delegate: Rectangle { - id: roomDirDelegate - - property color background: Nheko.colors.window - property color importantText: Nheko.colors.text - property color unimportantText: Nheko.colors.buttonText - property int avatarSize: fontMetrics.lineSpacing * 4 - - color: background - - height: avatarSize + 2.5 * Nheko.paddingMedium - width: ListView.view.width - - RowLayout { - - spacing: Nheko.paddingMedium - anchors.fill: parent - anchors.margins: Nheko.paddingMedium - implicitHeight: textContent.height - - Avatar { - id: roomAvatar - - Layout.alignment: Qt.AlignVCenter - width: avatarSize - height: avatarSize - url: model.avatarUrl.replace("mxc://", "image://MxcImage/") - displayName: model.name - } - - ColumnLayout { - id: textContent - - Layout.alignment: Qt.AlignLeft - Layout.fillWidth: true - width: parent.width - avatar.width - Layout.preferredWidth: parent.width - avatar.width - Layout.preferredHeight: roomNameRow.height + roomDescriptionRow.height - spacing: Nheko.paddingSmall - - RowLayout { - id: roomNameRow - Layout.fillWidth: true - spacing: 0 - - ElidedLabel { - Layout.alignment: Qt.AlignBottom - color: roomDirDelegate.importantText - elideWidth: textContent.width * 0.5 - Nheko.paddingMedium - font.pixelSize: fontMetrics.font.pixelSize * 1.1 - fullText: model.name - } - } - - RowLayout { - id: roomDescriptionRow - Layout.fillWidth: true - Layout.preferredWidth: parent.width - spacing: Nheko.paddingSmall - Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft - Layout.preferredHeight: fontMetrics.lineSpacing * 4 - - Label { - id: roomTopic - color: roomDirDelegate.unimportantText - font.weight: Font.Thin - Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft - font.pixelSize: fontMetrics.font.pixelSize - elide: Text.ElideRight - maximumLineCount: 2 - Layout.fillWidth: true - text: model.topic - verticalAlignment: Text.AlignVCenter - wrapMode: Text.WordWrap - } - Item { - id: numMembersRectangle - Layout.fillWidth: false - Layout.margins: Nheko.paddingSmall - width: roomCount.width - - Label { - id: roomCount - color: roomDirDelegate.unimportantText - anchors.centerIn: parent - Layout.fillWidth: false - font.weight: Font.Thin - font.pixelSize: fontMetrics.font.pixelSize - text: model.numMembers.toString() - } - } - - Item { - id: buttonRectangle - Layout.fillWidth: false - Layout.margins: Nheko.paddingSmall - width: joinRoomButton.width - Button { - id: joinRoomButton - visible: publicRooms.canJoinRoom(model.roomid) - anchors.centerIn: parent - width: Math.ceil(0.1 * roomDirectoryWindow.width) - text: "Join" - onClicked: publicRooms.joinRoom(model.index) - } - } - } - } - } - } - - footer: Item { - anchors.horizontalCenter: parent.horizontalCenter - width: parent.width - visible: (publicRooms.reachedEndOfPagination == false) && publicRooms.loadingMoreRooms - // hacky but works - height: loadingSpinner.height + 2 * Nheko.paddingLarge - anchors.margins: Nheko.paddingLarge - - Spinner { - id: loadingSpinner - - anchors.centerIn: parent - anchors.margins: Nheko.paddingLarge - running: visible - foreground: Nheko.colors.mid - z: 7 - } - } - - } -} +// SPDX-FileCopyrightText: 2021 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + +import "./ui" +import QtQuick 2.9 +import QtQuick.Controls 2.3 +import QtQuick.Layouts 1.3 +import im.nheko 1.0 + +ApplicationWindow { + id: roomDirectoryWindow + + property RoomDirectoryModel publicRooms + + visible: true + x: MainWindow.x + (MainWindow.width / 2) - (width / 2) + y: MainWindow.y + (MainWindow.height / 2) - (height / 2) + minimumWidth: 650 + minimumHeight: 420 + palette: Nheko.colors + color: Nheko.colors.window + modality: Qt.WindowModal + flags: Qt.Dialog | Qt.WindowCloseButtonHint + title: qsTr("Explore Public Rooms") + + Shortcut { + sequence: StandardKey.Cancel + onActivated: roomDirectoryWindow.close() + } + + ListView { + id: roomDirView + + anchors.fill: parent + model: publicRooms + + delegate: Rectangle { + id: roomDirDelegate + + property color background: Nheko.colors.window + property color importantText: Nheko.colors.text + property color unimportantText: Nheko.colors.buttonText + property int avatarSize: fontMetrics.lineSpacing * 4 + + color: background + height: avatarSize + 2.5 * Nheko.paddingMedium + width: ListView.view.width + + RowLayout { + spacing: Nheko.paddingMedium + anchors.fill: parent + anchors.margins: Nheko.paddingMedium + implicitHeight: textContent.height + + Avatar { + id: roomAvatar + + Layout.alignment: Qt.AlignVCenter + width: avatarSize + height: avatarSize + url: model.avatarUrl.replace("mxc://", "image://MxcImage/") + displayName: model.name + } + + ColumnLayout { + id: textContent + + Layout.alignment: Qt.AlignLeft + Layout.fillWidth: true + width: parent.width - avatar.width + Layout.preferredWidth: parent.width - avatar.width + Layout.preferredHeight: roomNameRow.height + roomDescriptionRow.height + spacing: Nheko.paddingSmall + + RowLayout { + id: roomNameRow + + Layout.fillWidth: true + spacing: 0 + + ElidedLabel { + Layout.alignment: Qt.AlignBottom + color: roomDirDelegate.importantText + elideWidth: textContent.width * 0.5 - Nheko.paddingMedium + font.pixelSize: fontMetrics.font.pixelSize * 1.1 + fullText: model.name + } + + } + + RowLayout { + id: roomDescriptionRow + + Layout.fillWidth: true + Layout.preferredWidth: parent.width + spacing: Nheko.paddingSmall + Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft + Layout.preferredHeight: fontMetrics.lineSpacing * 4 + + Label { + id: roomTopic + + color: roomDirDelegate.unimportantText + font.weight: Font.Thin + Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft + font.pixelSize: fontMetrics.font.pixelSize + elide: Text.ElideRight + maximumLineCount: 2 + Layout.fillWidth: true + text: model.topic + verticalAlignment: Text.AlignVCenter + wrapMode: Text.WordWrap + } + + Item { + id: numMembersRectangle + + Layout.fillWidth: false + Layout.margins: Nheko.paddingSmall + width: roomCount.width + + Label { + id: roomCount + + color: roomDirDelegate.unimportantText + anchors.centerIn: parent + Layout.fillWidth: false + font.weight: Font.Thin + font.pixelSize: fontMetrics.font.pixelSize + text: model.numMembers.toString() + } + + } + + Item { + id: buttonRectangle + + Layout.fillWidth: false + Layout.margins: Nheko.paddingSmall + width: joinRoomButton.width + + Button { + id: joinRoomButton + + visible: publicRooms.canJoinRoom(model.roomid) + anchors.centerIn: parent + width: Math.ceil(0.1 * roomDirectoryWindow.width) + text: "Join" + onClicked: publicRooms.joinRoom(model.index) + } + + } + + } + + } + + } + + } + + footer: Item { + anchors.horizontalCenter: parent.horizontalCenter + width: parent.width + visible: (publicRooms.reachedEndOfPagination == false) && publicRooms.loadingMoreRooms + // hacky but works + height: loadingSpinner.height + 2 * Nheko.paddingLarge + anchors.margins: Nheko.paddingLarge + + Spinner { + id: loadingSpinner + + anchors.centerIn: parent + anchors.margins: Nheko.paddingLarge + running: visible + foreground: Nheko.colors.mid + z: 7 + } + + } + + } + + publicRooms: RoomDirectoryModel { + } + + header: RowLayout { + id: searchBarLayout + + spacing: Nheko.paddingMedium + width: parent.width + implicitHeight: roomSearch.height + + MatrixTextField { + id: roomSearch + + Layout.fillWidth: true + selectByMouse: true + font.pixelSize: fontMetrics.font.pixelSize + padding: Nheko.paddingMedium + color: Nheko.colors.text + placeholderText: qsTr("Search for public rooms") + onTextChanged: searchTimer.restart() + } + + Timer { + id: searchTimer + + interval: 350 + onTriggered: roomDirView.model.setSearchTerm(roomSearch.text) + } + + } + +} diff --git a/src/RoomDirectoryModel.cpp b/src/RoomDirectoryModel.cpp index 7d6be13e..5873771f 100644 --- a/src/RoomDirectoryModel.cpp +++ b/src/RoomDirectoryModel.cpp @@ -82,10 +82,10 @@ RoomDirectoryModel::getViasForRoom(const std::vector<std::string> &aliases) vias.reserve(aliases.size()); - std::transform( - aliases.begin(), aliases.end(), std::back_inserter(vias), [](const auto &alias) { - return alias.substr(alias.find(":") + 1); - }); + std::transform(aliases.begin(), + aliases.end(), + std::back_inserter(vias), + [](const auto &alias) { return alias.substr(alias.find(":") + 1); }); return vias; } @@ -126,7 +126,8 @@ RoomDirectoryModel::data(const QModelIndex &index, int role) const void RoomDirectoryModel::fetchMore(const QModelIndex &) { - if (!canFetchMore_) return; + if (!canFetchMore_) + return; nhlog::net()->debug("Fetching more rooms from mtxclient..."); @@ -137,18 +138,18 @@ RoomDirectoryModel::fetchMore(const QModelIndex &) // req.third_party_instance_id = third_party_instance_id; auto requested_server = server_; - reachedEndOfPagination_ = false; - emit reachedEndOfPaginationChanged(); + reachedEndOfPagination_ = false; + emit reachedEndOfPaginationChanged(); - loadingMoreRooms_ = true; - emit loadingMoreRoomsChanged(); + loadingMoreRooms_ = true; + emit loadingMoreRoomsChanged(); http::client()->post_public_rooms( req, [requested_server, this, req](const mtx::responses::PublicRooms &res, mtx::http::RequestErr err) { - loadingMoreRooms_ = false; - emit loadingMoreRoomsChanged(); + loadingMoreRooms_ = false; + emit loadingMoreRoomsChanged(); if (err) { nhlog::net()->error( @@ -184,12 +185,12 @@ RoomDirectoryModel::displayRooms(std::vector<mtx::responses::PublicRoomsChunk> f endInsertRows(); if (next_batch.empty()) { - canFetchMore_ = false; - reachedEndOfPagination_ = true; - emit reachedEndOfPaginationChanged(); + canFetchMore_ = false; + reachedEndOfPagination_ = true; + emit reachedEndOfPaginationChanged(); } prevBatch_ = next_batch; - nhlog::ui()->debug ("Finished loading rooms"); + nhlog::ui()->debug("Finished loading rooms"); } diff --git a/src/RoomDirectoryModel.h b/src/RoomDirectoryModel.h index a7e6c0bc..b7eda00d 100644 --- a/src/RoomDirectoryModel.h +++ b/src/RoomDirectoryModel.h @@ -27,8 +27,9 @@ class RoomDirectoryModel : public QAbstractListModel { Q_OBJECT - Q_PROPERTY (bool loadingMoreRooms READ loadingMoreRooms NOTIFY loadingMoreRoomsChanged) - Q_PROPERTY (bool reachedEndOfPagination READ reachedEndOfPagination NOTIFY reachedEndOfPaginationChanged) + Q_PROPERTY(bool loadingMoreRooms READ loadingMoreRooms NOTIFY loadingMoreRoomsChanged) + Q_PROPERTY(bool reachedEndOfPagination READ reachedEndOfPagination NOTIFY + reachedEndOfPaginationChanged) public: explicit RoomDirectoryModel(QObject *parent = nullptr, const std::string &s = ""); @@ -52,14 +53,11 @@ public: return static_cast<int>(publicRoomsData_.size()); } - bool canFetchMore(const QModelIndex &) const override - { - return canFetchMore_; - } + bool canFetchMore(const QModelIndex &) const override { return canFetchMore_; } - bool loadingMoreRooms() const { return loadingMoreRooms_; } + bool loadingMoreRooms() const { return loadingMoreRooms_; } - bool reachedEndOfPagination() const { return reachedEndOfPagination_; } + bool reachedEndOfPagination() const { return reachedEndOfPagination_; } void fetchMore(const QModelIndex &) override; @@ -69,8 +67,8 @@ public: signals: void fetchedRoomsBatch(std::vector<mtx::responses::PublicRoomsChunk> rooms, const std::string &next_batch); - void loadingMoreRoomsChanged(); - void reachedEndOfPaginationChanged(); + void loadingMoreRoomsChanged(); + void reachedEndOfPaginationChanged(); public slots: void displayRooms(std::vector<mtx::responses::PublicRoomsChunk> rooms, @@ -85,9 +83,9 @@ private: std::string userSearchString_; std::string prevBatch_; std::string nextBatch_; - bool canFetchMore_ {true}; - bool loadingMoreRooms_ {false}; - bool reachedEndOfPagination_ {false}; + bool canFetchMore_{true}; + bool loadingMoreRooms_{false}; + bool reachedEndOfPagination_{false}; std::vector<mtx::responses::PublicRoomsChunk> publicRoomsData_; std::vector<std::string> getViasForRoom(const std::vector<std::string> &room); diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index ff60856a..6f935760 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -286,8 +286,7 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par "EmojiCategory", "Error: Only enums"); - qmlRegisterType<RoomDirectoryModel>( - "im.nheko", 1, 0, "RoomDirectoryModel"); + qmlRegisterType<RoomDirectoryModel>("im.nheko", 1, 0, "RoomDirectoryModel"); #ifdef USE_QUICK_VIEW view = new QQuickView(parent); |