kdeconnect-kde/plugins/notifications/sendreplydialog.cpp
Alexander Lohnau 2e67f95017 Add explicit moc includes to cpp files
The rationale is explained in https://planet.kde.org/friedrich-kossebau-2023-06-28-include-also-moc-files-of-headers/

In case of KDEConnect, it impressively speeds up compilation. Before it
took 390 seconds on a clean build and with this change it took 330 seconds.
This is due to the mocs_compilation having to include the header files
and thus all their headers. Due to the lots of small plugins we have,
this means that the same headers must be compiled plenty of times.
When we include the moc files directly in the C++ file, they are already
available.
2023-07-30 07:27:45 +00:00

71 lines
2 KiB
C++

/**
* SPDX-FileCopyrightText: 2015 Albert Vaca <albertvaka@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "sendreplydialog.h"
#include <QBoxLayout>
#include <QKeyEvent>
#include <QLineEdit>
#include <QPushButton>
#include <QStandardPaths>
#include <QTextEdit>
#include <KLocalizedString>
#include "ui_sendreplydialog.h"
SendReplyDialog::SendReplyDialog(const QString &originalMessage, const QString &replyId, const QString &topicName, QWidget *parent)
: QDialog(parent)
, m_replyId(replyId)
, m_ui(new Ui::SendReplyDialog)
{
m_ui->setupUi(this);
m_ui->textView->setText(topicName + QStringLiteral(": \n") + originalMessage);
auto button = m_ui->buttonBox->button(QDialogButtonBox::Ok);
button->setText(i18n("Send"));
const auto sendButtonClicked = [this]() {
Q_EMIT sendReply(m_replyId, m_ui->replyEdit->toPlainText());
close();
};
auto textEdit = m_ui->replyEdit;
connect(textEdit, &SendReplyTextEdit::send, this, sendButtonClicked);
connect(this, &QDialog::accepted, this, sendButtonClicked);
setWindowTitle(topicName);
setWindowIcon(QIcon::fromTheme(QStringLiteral("kdeconnect")));
setAttribute(Qt::WA_DeleteOnClose);
m_ui->replyEdit->setFocus();
}
SendReplyDialog::~SendReplyDialog() = default;
QSize SendReplyDialog::sizeHint() const
{
return QSize(512, 64);
}
SendReplyTextEdit::SendReplyTextEdit(QWidget *parent)
: QTextEdit(parent)
{
}
void SendReplyTextEdit::keyPressEvent(QKeyEvent *event)
{
// Send reply on enter, except when shift + enter is pressed, then insert newline
const int key = event->key();
if (key == Qt::Key_Return || key == Qt::Key_Enter) {
if ((key == Qt::Key_Enter && (event->modifiers() == Qt::KeypadModifier)) || !event->modifiers()) {
Q_EMIT send();
event->accept();
return;
}
}
QTextEdit::keyPressEvent(event);
}
#include "moc_sendreplydialog.cpp"