[OpenDocString] kdeconnect-kde (cpp)
sendreplydialog.cpp
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"));

    auto textEdit = m_ui->replyEdit;
    connect(textEdit, &SendReplyTextEdit::send, this, &SendReplyDialog::sendButtonClicked);

    connect(this, &QDialog::accepted, this, &SendReplyDialog::sendButtonClicked);
    setWindowTitle(topicName);
    setWindowIcon(QIcon::fromTheme(QStringLiteral("kdeconnect")));
    setAttribute(Qt::WA_DeleteOnClose);
    m_ui->replyEdit->setFocus();
}
This creates a send reply dialog with a text view and a button to send the message to the given topic. It sets the title and icon of the dialog to the original message.
SendReplyDialog::~SendReplyDialog() = default;
Sets the default behavior of the send reply dialog.
void SendReplyDialog::sendButtonClicked()
{
    Q_EMIT sendReply(m_replyId, m_ui->replyEdit->toPlainText());
    close();
}
This sends the reply text of the currently selected reply object to the sender.
QSize SendReplyDialog::sizeHint() const
{
    return QSize(512, 64);
}
Returns a QSize object that can be used to resize the message body.
SendReplyTextEdit::SendReplyTextEdit(QWidget *parent)
    : QTextEdit(parent)
{
}
This constructor builds a QTextEdit object and sends it to the parent widget.
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);
}
This sends a reply on enter if the key is pressed. It first checks if the key is Return or Enter and if it is Shift + enter is pressed. Then it inserts a newline.