diff --git a/src/widgets/room/messagelineedit.cpp b/src/widgets/room/messagelineedit.cpp index e8eeacd2..64f32fa6 100644 --- a/src/widgets/room/messagelineedit.cpp +++ b/src/widgets/room/messagelineedit.cpp @@ -1,38 +1,54 @@ /* Copyright (c) 2020 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "messagelineedit.h" +#include + MessageLineEdit::MessageLineEdit(QWidget *parent) : QLineEdit(parent) { setClearButtonEnabled(true); connect(this, &MessageLineEdit::returnPressed, this, [this]() { Q_EMIT sendMessage(text()); clear(); }); } MessageLineEdit::~MessageLineEdit() { } +void MessageLineEdit::keyPressEvent(QKeyEvent *e) +{ + switch (e->key()) { + case Qt::Key_Escape: + e->ignore(); + Q_EMIT clearNotification(); + return; + default: + break; + } + QLineEdit::keyPressEvent(e); +} + + //TODO add keyEvent diff --git a/src/widgets/room/messagelineedit.h b/src/widgets/room/messagelineedit.h index 77b8f8c3..18d7075b 100644 --- a/src/widgets/room/messagelineedit.h +++ b/src/widgets/room/messagelineedit.h @@ -1,37 +1,40 @@ /* Copyright (c) 2020 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MESSAGELINEEDIT_H #define MESSAGELINEEDIT_H #include #include "libruqolawidgets_private_export.h" class LIBRUQOLAWIDGETS_TESTS_EXPORT MessageLineEdit : public QLineEdit { Q_OBJECT public: explicit MessageLineEdit(QWidget *parent = nullptr); ~MessageLineEdit(); Q_SIGNALS: void sendMessage(const QString &str); + void clearNotification(); +protected: + void keyPressEvent(QKeyEvent *e) override; }; #endif // MESSAGELINEEDIT_H diff --git a/src/widgets/room/messagelinewidget.cpp b/src/widgets/room/messagelinewidget.cpp index a7490d4a..79980b7d 100644 --- a/src/widgets/room/messagelinewidget.cpp +++ b/src/widgets/room/messagelinewidget.cpp @@ -1,41 +1,42 @@ /* Copyright (c) 2020 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "messagelineedit.h" #include "messagelinewidget.h" #include MessageLineWidget::MessageLineWidget(QWidget *parent) : QWidget(parent) { QHBoxLayout *mainLayout = new QHBoxLayout(this); mainLayout->setObjectName(QStringLiteral("mainLayout")); mainLayout->setContentsMargins(0, 0, 0, 0); mMessageLineEdit = new MessageLineEdit(this); mMessageLineEdit->setObjectName(QStringLiteral("mMessageLineEdit")); mainLayout->addWidget(mMessageLineEdit); connect(mMessageLineEdit, &MessageLineEdit::sendMessage, this, &MessageLineWidget::sendMessage); + connect(mMessageLineEdit, &MessageLineEdit::clearNotification, this, &MessageLineWidget::clearNotification); } MessageLineWidget::~MessageLineWidget() { } diff --git a/src/widgets/room/messagelinewidget.h b/src/widgets/room/messagelinewidget.h index 5cbd45b2..713c9d4a 100644 --- a/src/widgets/room/messagelinewidget.h +++ b/src/widgets/room/messagelinewidget.h @@ -1,42 +1,43 @@ /* Copyright (c) 2020 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MESSAGELINEWIDGET_H #define MESSAGELINEWIDGET_H #include #include "libruqolawidgets_private_export.h" class MessageLineEdit; class LIBRUQOLAWIDGETS_TESTS_EXPORT MessageLineWidget : public QWidget { Q_OBJECT public: explicit MessageLineWidget(QWidget *parent = nullptr); ~MessageLineWidget(); Q_SIGNALS: void sendMessage(const QString &str); + void clearNotification(); private: MessageLineEdit *mMessageLineEdit = nullptr; }; #endif // MESSAGELINEWIDGET_H diff --git a/src/widgets/room/roomwidget.cpp b/src/widgets/room/roomwidget.cpp index ac4192f7..5f78ac8a 100644 --- a/src/widgets/room/roomwidget.cpp +++ b/src/widgets/room/roomwidget.cpp @@ -1,79 +1,85 @@ /* Copyright (c) 2020 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "roomwidget.h" #include "roomheaderwidget.h" #include "messagelistview.h" #include "messagelinewidget.h" #include #include #include "ruqola.h" #include "rocketchataccount.h" RoomWidget::RoomWidget(QWidget *parent) : QWidget(parent) { QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setObjectName(QStringLiteral("mainLayout")); mainLayout->setContentsMargins(0, 0, 0, 0); mRoomHeaderWidget = new RoomHeaderWidget(this); mRoomHeaderWidget->setObjectName(QStringLiteral("mRoomHeaderWidget")); mainLayout->addWidget(mRoomHeaderWidget); mMessageListView = new MessageListView(this); mMessageListView->setObjectName(QStringLiteral("mMessageListView")); mainLayout->addWidget(mMessageListView); mMessageLineWidget = new MessageLineWidget(this); mMessageLineWidget->setObjectName(QStringLiteral("mMessageLineWidget")); mainLayout->addWidget(mMessageLineWidget); connect(this, &RoomWidget::channelSelected, this, &RoomWidget::setChannelSelected); connect(mMessageLineWidget, &MessageLineWidget::sendMessage, this, &RoomWidget::slotSendMessage); + connect(mMessageLineWidget, &MessageLineWidget::clearNotification, this, &RoomWidget::slotClearNotification); } RoomWidget::~RoomWidget() { } void RoomWidget::slotSendMessage(const QString &msg) { Ruqola::self()->rocketChatAccount()->sendMessage(mRoomId, msg); } void RoomWidget::setChannelSelected(const QModelIndex &index) { setRoomId(index.data(RoomModel::RoomID).toString()); mRoomHeaderWidget->setRoomName(index.data(RoomModel::RoomFName).toString()); } QString RoomWidget::roomId() const { return mRoomId; } void RoomWidget::setRoomId(const QString &roomId) { if (mRoomId != roomId) { mRoomId = roomId; mMessageListView->setChannelSelected(roomId); } } + +void RoomWidget::slotClearNotification() +{ + Ruqola::self()->rocketChatAccount()->clearUnreadMessages(mRoomId); +} diff --git a/src/widgets/room/roomwidget.h b/src/widgets/room/roomwidget.h index 997ad726..97eedd20 100644 --- a/src/widgets/room/roomwidget.h +++ b/src/widgets/room/roomwidget.h @@ -1,51 +1,52 @@ /* Copyright (c) 2020 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef ROOMWIDGET_H #define ROOMWIDGET_H #include #include "libruqolawidgets_private_export.h" class RoomHeaderWidget; class MessageListView; class MessageLineWidget; class LIBRUQOLAWIDGETS_TESTS_EXPORT RoomWidget : public QWidget { Q_OBJECT public: explicit RoomWidget(QWidget *parent = nullptr); ~RoomWidget(); Q_REQUIRED_RESULT QString roomId() const; void setRoomId(const QString &roomId); Q_SIGNALS: void channelSelected(const QModelIndex &index); private: void setChannelSelected(const QModelIndex &index); void slotSendMessage(const QString &msg); + void slotClearNotification(); QString mRoomId; RoomHeaderWidget *mRoomHeaderWidget = nullptr; MessageListView *mMessageListView = nullptr; MessageLineWidget *mMessageLineWidget = nullptr; }; #endif // ROOMWIDGET_H