File indexing completed on 2024-06-23 05:18:37

0001 /*
0002    SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "sendlatertimedatewidget_p.h"
0008 
0009 #include <KDateComboBox>
0010 #include <KLocalizedString>
0011 #include <KTimeComboBox>
0012 #include <QLineEdit>
0013 
0014 #include <QHBoxLayout>
0015 
0016 using namespace MessageComposer;
0017 
0018 SendLaterTimeDateWidget::SendLaterTimeDateWidget(QWidget *parent)
0019     : QWidget(parent)
0020     , mTimeComboBox(new KTimeComboBox(this))
0021     , mDateComboBox(new KDateComboBox(this))
0022 {
0023     auto lay = new QHBoxLayout(this);
0024     lay->setContentsMargins({});
0025 
0026     QDateTime t = QDateTime::currentDateTime();
0027     t = t.addSecs(60 * 60);
0028     connect(mTimeComboBox, &KTimeComboBox::timeChanged, this, &SendLaterTimeDateWidget::slotDateTimeChanged);
0029     mTimeComboBox->setObjectName(QLatin1StringView("time_sendlater"));
0030 
0031     mDateComboBox->setOptions(KDateComboBox::EditDate | KDateComboBox::SelectDate | KDateComboBox::DatePicker | KDateComboBox::DateKeywords
0032                               | KDateComboBox::WarnOnInvalid);
0033     mDateComboBox->setObjectName(QLatin1StringView("date_sendlater"));
0034     connect(mDateComboBox->lineEdit(), &QLineEdit::textChanged, this, &SendLaterTimeDateWidget::dateChanged);
0035     mDateComboBox->setMinimumDate(t.date(), i18n("You cannot select a date prior to the current date."));
0036     connect(mDateComboBox, &KDateComboBox::dateChanged, this, &SendLaterTimeDateWidget::slotDateTimeChanged);
0037 
0038     lay->addWidget(mDateComboBox);
0039     lay->addWidget(mTimeComboBox);
0040 }
0041 
0042 SendLaterTimeDateWidget::~SendLaterTimeDateWidget() = default;
0043 
0044 void SendLaterTimeDateWidget::slotDateTimeChanged()
0045 {
0046     QDateTime dt;
0047     dt.setDate(mDateComboBox->date());
0048     dt.setTime(mTimeComboBox->time());
0049     Q_EMIT dateTimeChanged(dt);
0050 }
0051 
0052 QDateTime SendLaterTimeDateWidget::dateTime() const
0053 {
0054     QDateTime dt;
0055     dt.setDate(mDateComboBox->date());
0056     dt.setTime(mTimeComboBox->time());
0057     return dt;
0058 }
0059 
0060 void SendLaterTimeDateWidget::setDateTime(const QDateTime &datetime)
0061 {
0062     mTimeComboBox->setTime(datetime.time());
0063     mDateComboBox->setDate(datetime.date());
0064 }
0065 
0066 #include "moc_sendlatertimedatewidget_p.cpp"