File indexing completed on 2025-01-19 04:46:48

0001 /*
0002    SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "reactiontoinvitationdialog.h"
0008 #include <KConfigGroup>
0009 #include <KLocalizedString>
0010 #include <KSharedConfig>
0011 #include <KWindowConfig>
0012 #include <QDialogButtonBox>
0013 #include <QLabel>
0014 #include <QPushButton>
0015 #include <QVBoxLayout>
0016 #include <QWindow>
0017 #include <TextCustomEditor/PlainTextEditor>
0018 #include <TextCustomEditor/PlainTextEditorWidget>
0019 namespace
0020 {
0021 static const char myConfigReactionToInvitationDialog[] = "ReactionToInvitationDialog";
0022 }
0023 ReactionToInvitationDialog::ReactionToInvitationDialog(QWidget *parent)
0024     : QDialog(parent)
0025     , mPlainTextEditor(new TextCustomEditor::PlainTextEditorWidget(this))
0026 {
0027     auto layout = new QVBoxLayout(this);
0028     layout->setObjectName(QLatin1StringView("layout"));
0029 
0030     auto label = new QLabel(i18n("Comment:"), this);
0031     label->setObjectName(QLatin1StringView("label"));
0032     layout->addWidget(label);
0033 
0034     mPlainTextEditor->setObjectName(QLatin1StringView("plaintexteditor"));
0035     layout->addWidget(mPlainTextEditor);
0036     connect(mPlainTextEditor->editor(), &TextCustomEditor::PlainTextEditor::textChanged, this, &ReactionToInvitationDialog::slotTextChanged);
0037 
0038     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0039     buttonBox->setObjectName(QLatin1StringView("buttonbox"));
0040     layout->addWidget(buttonBox);
0041     mOkButton = buttonBox->button(QDialogButtonBox::Ok);
0042     connect(buttonBox, &QDialogButtonBox::accepted, this, &ReactionToInvitationDialog::accept);
0043     connect(buttonBox, &QDialogButtonBox::rejected, this, &ReactionToInvitationDialog::reject);
0044     readConfig();
0045 }
0046 
0047 ReactionToInvitationDialog::~ReactionToInvitationDialog()
0048 {
0049     disconnect(mPlainTextEditor->editor(), &TextCustomEditor::PlainTextEditor::textChanged, this, &ReactionToInvitationDialog::slotTextChanged);
0050     writeConfig();
0051 }
0052 
0053 void ReactionToInvitationDialog::slotTextChanged()
0054 {
0055     mOkButton->setEnabled(!mPlainTextEditor->editor()->document()->isEmpty());
0056 }
0057 
0058 QString ReactionToInvitationDialog::comment() const
0059 {
0060     return mPlainTextEditor->toPlainText();
0061 }
0062 
0063 void ReactionToInvitationDialog::readConfig()
0064 {
0065     create(); // ensure a window is created
0066     windowHandle()->resize(QSize(600, 400));
0067     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myConfigReactionToInvitationDialog));
0068     KWindowConfig::restoreWindowSize(windowHandle(), group);
0069     resize(windowHandle()->size()); // workaround for QTBUG-40584
0070 }
0071 
0072 void ReactionToInvitationDialog::writeConfig()
0073 {
0074     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myConfigReactionToInvitationDialog));
0075     KWindowConfig::saveWindowSize(windowHandle(), group);
0076     group.sync();
0077 }
0078 
0079 #include "moc_reactiontoinvitationdialog.cpp"