From b3c0dc9421d47ae5e9823e9b0c52fb930090b5a9 Mon Sep 17 00:00:00 2001 From: Black Hat Date: Sat, 7 Jul 2018 19:06:13 +0800 Subject: [PATCH] Fix imageprovider. --- main.cpp | 2 ++ matrique.pro | 6 ++++-- matrix/controller.cpp | 2 +- matrix/imageprovider.cpp | 8 -------- matrix/imageprovider.h | 23 +---------------------- matrix/imageproviderconnection.cpp | 9 +++++++++ matrix/imageproviderconnection.h | 29 +++++++++++++++++++++++++++++ matrix/roomlistmodel.cpp | 4 ++-- qml/Room.qml | 15 +++++++-------- qml/form/ListForm.qml | 6 ++++-- qml/form/RoomForm.qml | 8 ++++---- qml/main.qml | 5 +++-- 12 files changed, 66 insertions(+), 51 deletions(-) create mode 100644 matrix/imageproviderconnection.cpp create mode 100644 matrix/imageproviderconnection.h diff --git a/main.cpp b/main.cpp index 60538ea77..5cccb3252 100644 --- a/main.cpp +++ b/main.cpp @@ -37,7 +37,9 @@ int main(int argc, char *argv[]) ImageProvider* m_provider = new ImageProvider(); engine.rootContext()->setContextProperty("imageProvider", m_provider->getConnection()); + engine.addImageProvider(QLatin1String("mxc"), m_provider); + engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml"))); if (engine.rootObjects().isEmpty()) diff --git a/matrique.pro b/matrique.pro index 228330d84..b15e48f36 100644 --- a/matrique.pro +++ b/matrique.pro @@ -18,7 +18,8 @@ SOURCES += main.cpp \ matrix/controller.cpp \ matrix/roomlistmodel.cpp \ matrix/imageprovider.cpp \ - matrix/messageeventmodel.cpp + matrix/messageeventmodel.cpp \ + matrix/imageproviderconnection.cpp RESOURCES += \ res.qrc @@ -52,4 +53,5 @@ HEADERS += \ matrix/controller.h \ matrix/roomlistmodel.h \ matrix/imageprovider.h \ - matrix/messageeventmodel.h + matrix/messageeventmodel.h \ + matrix/imageproviderconnection.h diff --git a/matrix/controller.cpp b/matrix/controller.cpp index f48d4457c..08f3cee15 100644 --- a/matrix/controller.cpp +++ b/matrix/controller.cpp @@ -10,7 +10,7 @@ Controller::Controller(QObject *parent) : QObject(parent) { } Controller::~Controller() { - + m_connection->stopSync(); } void Controller::login() { diff --git a/matrix/imageprovider.cpp b/matrix/imageprovider.cpp index 9459fea45..be76a4002 100644 --- a/matrix/imageprovider.cpp +++ b/matrix/imageprovider.cpp @@ -10,14 +10,6 @@ using QMatrixClient::MediaThumbnailJob; -ImageProviderConnection::ImageProviderConnection(QObject* parent) : QObject(parent) { - -} - -ImageProviderConnection::~ImageProviderConnection() { - -} - ImageProvider::ImageProvider(QObject* parent) : QQuickImageProvider(QQmlImageProviderBase::Image, QQmlImageProviderBase::ForceAsynchronousImageLoading) diff --git a/matrix/imageprovider.h b/matrix/imageprovider.h index ef5babe7d..cb265604d 100644 --- a/matrix/imageprovider.h +++ b/matrix/imageprovider.h @@ -6,28 +6,7 @@ #include #include "libqmatrixclient/connection.h" - -class ImageProviderConnection: public QObject -{ - Q_OBJECT - - Q_PROPERTY(QMatrixClient::Connection* connection READ getConnection WRITE setConnection NOTIFY connectionChanged) - - public: - explicit ImageProviderConnection(QObject* parent = nullptr); - ~ImageProviderConnection(); - - QMatrixClient::Connection* getConnection() { return m_connection; } - Q_INVOKABLE void setConnection(QMatrixClient::Connection* connection) { - qDebug() << "Connection changed."; - emit connectionChanged(); - m_connection = connection; - } - private: - QMatrixClient::Connection* m_connection; - signals: - void connectionChanged(); -}; +#include "imageproviderconnection.h" class ImageProvider: public QQuickImageProvider { diff --git a/matrix/imageproviderconnection.cpp b/matrix/imageproviderconnection.cpp new file mode 100644 index 000000000..920c06f7b --- /dev/null +++ b/matrix/imageproviderconnection.cpp @@ -0,0 +1,9 @@ +#include "imageproviderconnection.h" + +ImageProviderConnection::ImageProviderConnection(QObject* parent) : QObject(parent) { + +} + +ImageProviderConnection::~ImageProviderConnection() { + +} diff --git a/matrix/imageproviderconnection.h b/matrix/imageproviderconnection.h new file mode 100644 index 000000000..752a04839 --- /dev/null +++ b/matrix/imageproviderconnection.h @@ -0,0 +1,29 @@ +#ifndef IMAGEPROVIDERCONNECTION_H +#define IMAGEPROVIDERCONNECTION_H + +#include + +#include "libqmatrixclient/connection.h" + +class ImageProviderConnection : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QMatrixClient::Connection* connection READ getConnection WRITE setConnection NOTIFY connectionChanged) + + public: + explicit ImageProviderConnection(QObject* parent = nullptr); + ~ImageProviderConnection(); + + QMatrixClient::Connection* getConnection() { return m_connection; } + void setConnection(QMatrixClient::Connection* connection) { + emit connectionChanged(); + m_connection = connection; + } + private: + QMatrixClient::Connection* m_connection; + signals: + void connectionChanged(); +}; + +#endif // IMAGEPROVIDERCONNECTION_H diff --git a/matrix/roomlistmodel.cpp b/matrix/roomlistmodel.cpp index 4622199f8..d1dbbb38b 100644 --- a/matrix/roomlistmodel.cpp +++ b/matrix/roomlistmodel.cpp @@ -70,12 +70,12 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const } if( role == Qt::DecorationRole ) { - if(room->avatarUrl().toString() != "") { + if ( room->avatarUrl().toString() != "" ) { return room->avatarUrl(); } return QVariant(); } - if (role == Qt::StatusTipRole ) + if ( role == Qt::StatusTipRole ) { return room->topic(); } diff --git a/qml/Room.qml b/qml/Room.qml index 41d307bec..3695d17e8 100644 --- a/qml/Room.qml +++ b/qml/Room.qml @@ -22,14 +22,13 @@ Page { id: roomListForm Layout.fillHeight: true -// Layout.preferredWidth: { -// if (page.width > 560) { -// return page.width * 0.4; -// } else { -// return 80; -// } -// } - Layout.preferredWidth: 320 + Layout.preferredWidth: { + if (page.width > 560) { + return page.width * 0.4; + } else { + return 80; + } + } Layout.maximumWidth: 360 listModel: roomListModel diff --git a/qml/form/ListForm.qml b/qml/form/ListForm.qml index cf84691a9..f031a4ec2 100644 --- a/qml/form/ListForm.qml +++ b/qml/form/ListForm.qml @@ -45,6 +45,8 @@ Item { Layout.fillHeight: true Layout.alignment: Qt.AlignHCenter + visible: parent.width > 80 + Label { Layout.fillWidth: true Layout.fillHeight: true @@ -79,9 +81,9 @@ Item { var roomCount = listModel.rowCount(); for (var i = 0; i < roomCount; i++){ var roomName = ""; - if (listModel.roomAt(i).name != "") { + if (listModel.roomAt(i).name !== "") { roomName = listModel.roomAt(i).name; - } else if (model.alias != "") { + } else if (model.alias !== "") { roomName = listModel.roomAt(i).alias; } else { roomName = listModel.roomAt(i).id; diff --git a/qml/form/RoomForm.qml b/qml/form/RoomForm.qml index 4aad0526e..a0aa79deb 100644 --- a/qml/form/RoomForm.qml +++ b/qml/form/RoomForm.qml @@ -16,7 +16,7 @@ Item { background: Item { anchors.fill: parent - visible: currentRoom == null + visible: currentRoom === null Pane { anchors.fill: parent } @@ -32,7 +32,7 @@ Item { anchors.fill: parent spacing: 0 - visible: currentRoom != null + visible: currentRoom !== null Pane { z: 10 @@ -61,7 +61,7 @@ Item { Label { Layout.fillWidth: true - text: currentRoom != null ? currentRoom.name : "" + text: currentRoom !== null ? currentRoom.displayName : "" font.pointSize: 16 elide: Text.ElideRight wrapMode: Text.NoWrap @@ -69,7 +69,7 @@ Item { Label { Layout.fillWidth: true - text: currentRoom != null ? currentRoom.topic : "" + text: currentRoom !== null ? currentRoom.topic : "" elide: Text.ElideRight wrapMode: Text.NoWrap } diff --git a/qml/main.qml b/qml/main.qml index 2b7443b5f..3d4b8ebe3 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -138,7 +138,9 @@ ApplicationWindow { SideNavButton { contentItem: MaterialIcon { icon: "\ue879"; color: "white" } - onClicked: Qt.quit() + onClicked: { + Qt.quit(); + } } } } @@ -153,7 +155,6 @@ ApplicationWindow { } Component.onCompleted: { - imageProvider.setConnection(matriqueController.connection) imageProvider.connection = matriqueController.connection console.log(matriqueController.homeserver, matriqueController.userID, matriqueController.token)