From 824eac228eac8af3e2343a4164f4001dd52adc7d Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 3 Aug 2017 17:23:12 +0200 Subject: [PATCH] Improvements on the SendReplyDialog Use a designer file for it Make sure the focus is on the reply widget Disable focus from the original text raise() the dialog when we show it to make sure it's over the other windows --- plugins/notifications/CMakeLists.txt | 2 + .../notificationsdbusinterface.cpp | 1 + plugins/notifications/sendreplydialog.cpp | 24 +++--- plugins/notifications/sendreplydialog.h | 9 +-- plugins/notifications/sendreplydialog.ui | 74 +++++++++++++++++++ 5 files changed, 91 insertions(+), 19 deletions(-) create mode 100644 plugins/notifications/sendreplydialog.ui diff --git a/plugins/notifications/CMakeLists.txt b/plugins/notifications/CMakeLists.txt index a3932a4ba..86f962c54 100644 --- a/plugins/notifications/CMakeLists.txt +++ b/plugins/notifications/CMakeLists.txt @@ -7,6 +7,8 @@ set(kdeconnect_notifications_SRCS sendreplydialog.cpp ) +ki18n_wrap_ui(kdeconnect_notifications_SRCS sendreplydialog.ui) + kdeconnect_add_plugin(kdeconnect_notifications JSON kdeconnect_notifications.json SOURCES ${kdeconnect_notifications_SRCS}) target_link_libraries(kdeconnect_notifications diff --git a/plugins/notifications/notificationsdbusinterface.cpp b/plugins/notifications/notificationsdbusinterface.cpp index d6cb3cfc5..c64409ae6 100644 --- a/plugins/notifications/notificationsdbusinterface.cpp +++ b/plugins/notifications/notificationsdbusinterface.cpp @@ -160,6 +160,7 @@ void NotificationsDbusInterface::replyRequested(Notification* noti) SendReplyDialog* dialog = new SendReplyDialog(originalMessage, replyId, appName); connect(dialog, &SendReplyDialog::sendReply, this, &NotificationsDbusInterface::sendReply); dialog->show(); + dialog->raise(); } void NotificationsDbusInterface::sendReply(const QString& replyId, const QString& message) diff --git a/plugins/notifications/sendreplydialog.cpp b/plugins/notifications/sendreplydialog.cpp index e40c2170a..3ed59ac47 100644 --- a/plugins/notifications/sendreplydialog.cpp +++ b/plugins/notifications/sendreplydialog.cpp @@ -27,34 +27,30 @@ #include +#include "ui_sendreplydialog.h" + SendReplyDialog::SendReplyDialog(const QString& originalMessage, const QString& replyId, const QString& topicName, QWidget* parent) : QDialog(parent) , mReplyId(replyId) + , m_ui(new Ui::SendReplyDialog) { - QVBoxLayout* layout = new QVBoxLayout; + m_ui->setupUi(this); + m_ui->textView->setText(topicName + ": \n" + originalMessage); - QTextEdit* textView = new QTextEdit(this); - textView->setReadOnly(true); - textView->setText(topicName + ": \n" + originalMessage); - layout->addWidget(textView); + auto button = m_ui->buttonBox->button(QDialogButtonBox::Ok); + button->setText(i18n("Send")); - mTextEdit = new QTextEdit(this); - layout->addWidget(mTextEdit); - - QPushButton* sendButton = new QPushButton(i18n("Send"), this); - connect(sendButton, &QAbstractButton::clicked, this, &SendReplyDialog::sendButtonClicked); - layout->addWidget(sendButton); - - setLayout(layout); + connect(this, &QDialog::accepted, this, &SendReplyDialog::sendButtonClicked); setWindowTitle(topicName); setWindowIcon(QIcon::fromTheme(QStringLiteral("kdeconnect"))); setAttribute(Qt::WA_DeleteOnClose); } +SendReplyDialog::~SendReplyDialog() = default; void SendReplyDialog::sendButtonClicked() { - Q_EMIT sendReply(mReplyId, mTextEdit->toPlainText()); + Q_EMIT sendReply(mReplyId, m_ui->replyEdit->toPlainText()); close(); } diff --git a/plugins/notifications/sendreplydialog.h b/plugins/notifications/sendreplydialog.h index 8540d5a5a..086773c14 100644 --- a/plugins/notifications/sendreplydialog.h +++ b/plugins/notifications/sendreplydialog.h @@ -24,9 +24,7 @@ #include #include -class QTextEdit; -class QLineEdit; -class QPushButton; +namespace Ui { class SendReplyDialog; } class SendReplyDialog : public QDialog { @@ -34,6 +32,7 @@ class SendReplyDialog : public QDialog public: explicit SendReplyDialog(const QString& originalMessage, const QString& replyId, const QString& topicName, QWidget *parent = nullptr); + ~SendReplyDialog() override; QSize sizeHint() const override; private Q_SLOTS: @@ -43,8 +42,8 @@ Q_SIGNALS: void sendReply(const QString& replyId, const QString& messageBody); private: - QString mReplyId; - QTextEdit *mTextEdit; + const QString mReplyId; + const QScopedPointer m_ui; }; #endif diff --git a/plugins/notifications/sendreplydialog.ui b/plugins/notifications/sendreplydialog.ui new file mode 100644 index 000000000..07db50b40 --- /dev/null +++ b/plugins/notifications/sendreplydialog.ui @@ -0,0 +1,74 @@ + + + SendReplyDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + + Qt::NoFocus + + + true + + + + + + + + + + QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + SendReplyDialog + accept() + + + 82 + 274 + + + 2 + 279 + + + + + buttonBox + rejected() + SendReplyDialog + reject() + + + 149 + 284 + + + 143 + 298 + + + + +