File indexing completed on 2025-01-19 03:50:33

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2005-04-21
0007  * Description : a widget to edit time stamp.
0008  *
0009  * SPDX-FileCopyrightText: 2005      by Tom Albers <tomalbers at kde dot nl>
0010  * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "ddatetimeedit.h"
0017 
0018 // Qt includes
0019 
0020 #include <QDateTimeEdit>
0021 
0022 // Local includes
0023 
0024 #include "ddateedit.h"
0025 
0026 namespace Digikam
0027 {
0028 
0029 class Q_DECL_HIDDEN DDateTimeEdit::Private
0030 {
0031 public:
0032 
0033     explicit Private()
0034       : timePopUp(nullptr),
0035         datePopUp(nullptr)
0036     {
0037     }
0038 
0039     QTimeEdit* timePopUp;
0040     DDateEdit* datePopUp;
0041 };
0042 
0043 DDateTimeEdit::DDateTimeEdit(QWidget* const parent, const QString& name)
0044     : DHBox(parent),
0045       d    (new Private)
0046 {
0047     setObjectName(name);
0048 
0049     d->datePopUp = new DDateEdit(this, QLatin1String("datepopup"));
0050     d->timePopUp = new QTimeEdit(QTime::currentTime(), this);
0051 
0052     d->timePopUp->setDisplayFormat(QLatin1String("hh:mm:ss"));
0053 
0054     connect(d->datePopUp, &DDateEdit::dateChanged,
0055             this, &DDateTimeEdit::slotDateTimeChanged);
0056 
0057     connect(d->timePopUp, &QTimeEdit::timeChanged,
0058             this, &DDateTimeEdit::slotDateTimeChanged);
0059 }
0060 
0061 DDateTimeEdit::~DDateTimeEdit()
0062 {
0063     delete d->datePopUp;
0064     d->datePopUp = nullptr;
0065 
0066     delete d->timePopUp;
0067     d->timePopUp = nullptr;
0068 
0069     delete d;
0070 }
0071 
0072 QDateTime DDateTimeEdit::dateTime() const
0073 {
0074     QDateTime dateTime(d->datePopUp->date(), d->timePopUp->time());
0075     dateTime.setTimeSpec(Qt::UTC);
0076 
0077     return dateTime;
0078 }
0079 
0080 void DDateTimeEdit::setDateTime(const QDateTime& dateTime)
0081 {
0082     d->datePopUp->setDate(dateTime.date());
0083     d->timePopUp->setTime(dateTime.time());
0084 }
0085 
0086 void DDateTimeEdit::slotDateTimeChanged()
0087 {
0088     Q_EMIT dateTimeChanged(dateTime());
0089 }
0090 
0091 } // namespace Digikam
0092 
0093 #include "moc_ddatetimeedit.cpp"