KDELibs4Support

kdatetimewidget.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2002 Hans Petter bieker <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "kdatetimewidget.h"
20 
21 #include <QDate>
22 #include <QDebug>
23 #include <QLayout>
24 #include <QTimeEdit>
25 
26 #include "kdatewidget.h"
27 
28 class Q_DECL_HIDDEN KDateTimeWidget::KDateTimeWidgetPrivate
29 {
30 public:
31  KDateWidget *dateWidget;
32  QTimeEdit *timeWidget;
33 };
34 
36  : QWidget(parent)
37  , d(new KDateTimeWidgetPrivate)
38 {
39  initWidget();
40 }
41 
43  QWidget *parent)
44  : QWidget(parent)
45  , d(new KDateTimeWidgetPrivate)
46 
47 {
48  initWidget();
49 
50  setDateTime(datetime);
51 }
52 
54 {
55  delete d;
56 }
57 
58 void KDateTimeWidget::initWidget()
59 {
60  QHBoxLayout *layout = new QHBoxLayout(this);
61  layout->setContentsMargins(0, 0, 0, 0);
62 
63  d->dateWidget = new KDateWidget(this);
64  d->timeWidget = new QTimeEdit(this);
65  layout->addWidget(d->dateWidget);
66  layout->addWidget(d->timeWidget);
67 
68  connect(d->dateWidget, SIGNAL(changed(QDate)),
69  SLOT(slotValueChanged()));
70  connect(d->timeWidget, SIGNAL(timeChanged(QTime)),
71  SLOT(slotValueChanged()));
72 }
73 
75 {
76  d->dateWidget->setDate(datetime.date());
77  d->timeWidget->setTime(datetime.time());
78 }
79 
81 {
82  return QDateTime(d->dateWidget->date(), d->timeWidget->time());
83 }
84 
85 void KDateTimeWidget::slotValueChanged()
86 {
87  QDateTime datetime(d->dateWidget->date(),
88  d->timeWidget->time());
89 
90  //qDebug() << "slotValueChanged(): " << datetime << "\n";
91 
92  emit valueChanged(datetime);
93 }
94 
QLayout * layout() const const
void setContentsMargins(int left, int top, int right, int bottom)
QTime time() const const
QDateTime dateTime() const
Returns the currently selected date and time.
void setDateTime(const QDateTime &datetime)
Changes the selected date and time to datetime.
void valueChanged(const QDateTime &datetime)
Emitted whenever the date or time of the widget is changed, either with setDateTime() or via user sel...
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
virtual ~KDateTimeWidget()
Destructs the date and time selection widget.
A date selection widget.
Definition: kdatewidget.h:44
KDateTimeWidget(QWidget *parent=nullptr)
Constructs a date and time selection widget.
QDate date() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
A combination of a date and a time selection widget.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jul 4 2020 22:58:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.