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

0001 /*
0002     SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
0003     SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "delegateselector.h"
0009 
0010 #include <PimCommonAkonadi/AddresseeLineEdit>
0011 
0012 #include <KLocalizedString>
0013 
0014 #include <QCheckBox>
0015 #include <QDialogButtonBox>
0016 #include <QLabel>
0017 #include <QPushButton>
0018 #include <QVBoxLayout>
0019 
0020 DelegateSelector::DelegateSelector(QWidget *parent)
0021     : QDialog(parent)
0022     , mDelegate(new PimCommon::AddresseeLineEdit(this))
0023     , mRsvp(new QCheckBox(i18n("Keep me informed about status changes of this incidence."), this))
0024 {
0025     setWindowTitle(i18nc("@title:window", "Select delegate"));
0026     auto mainLayout = new QVBoxLayout(this);
0027 
0028     auto label = new QLabel(i18n("Delegate:"), this);
0029     label->setObjectName(QLatin1StringView("label"));
0030     mainLayout->addWidget(label);
0031 
0032     mDelegate->setObjectName(QLatin1StringView("delegate"));
0033     mainLayout->addWidget(mDelegate);
0034 
0035     connect(mDelegate, &PimCommon::AddresseeLineEdit::textChanged, this, &DelegateSelector::slotTextChanged);
0036     mRsvp->setObjectName(QLatin1StringView("informcheckbox"));
0037 
0038     mRsvp->setChecked(true);
0039     mainLayout->addWidget(mRsvp);
0040 
0041     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0042     buttonBox->setObjectName(QLatin1StringView("buttonbox"));
0043     mOkButton = buttonBox->button(QDialogButtonBox::Ok);
0044     mOkButton->setObjectName(QLatin1StringView("okbutton"));
0045     mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0046     connect(buttonBox, &QDialogButtonBox::accepted, this, &DelegateSelector::accept);
0047     connect(buttonBox, &QDialogButtonBox::rejected, this, &DelegateSelector::reject);
0048     mOkButton->setDefault(true);
0049     mOkButton->setEnabled(false);
0050 
0051     mainLayout->addWidget(buttonBox);
0052 }
0053 
0054 void DelegateSelector::slotTextChanged(const QString &text)
0055 {
0056     mOkButton->setEnabled(!text.trimmed().isEmpty());
0057 }
0058 
0059 QString DelegateSelector::delegate() const
0060 {
0061     return mDelegate->text();
0062 }
0063 
0064 bool DelegateSelector::rsvp() const
0065 {
0066     return mRsvp->isChecked();
0067 }
0068 
0069 #include "moc_delegateselector.cpp"