Mercurial > minori
comparison src/gui/widgets/optional_date.cc @ 81:9b2b41f83a5e
boring: mass rename to cc
because this is a very unix-y project, it makes more sense to use the
'cc' extension
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 23 Oct 2023 12:07:27 -0400 |
parents | src/gui/widgets/optional_date.cpp@3d2decf093bb |
children | 4d461ef7d424 |
comparison
equal
deleted
inserted
replaced
80:825506f0e221 | 81:9b2b41f83a5e |
---|---|
1 #include "gui/widgets/optional_date.h" | |
2 #include "core/date.h" | |
3 #include <QCheckBox> | |
4 #include <QDateEdit> | |
5 #include <QHBoxLayout> | |
6 | |
7 OptionalDate::OptionalDate(QWidget* parent) { | |
8 OptionalDate(false, parent); | |
9 } | |
10 | |
11 OptionalDate::OptionalDate(bool enabled, QWidget* parent) : QWidget(parent) { | |
12 QHBoxLayout* layout = new QHBoxLayout(this); | |
13 layout->setContentsMargins(0, 0, 0, 0); | |
14 | |
15 _checkbox = new QCheckBox(this); | |
16 _checkbox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); | |
17 | |
18 layout->addWidget(_checkbox, 0, Qt::AlignVCenter); | |
19 | |
20 _dateedit = new QDateEdit(this); | |
21 _dateedit->setDisplayFormat("yyyy-MM-dd"); | |
22 _dateedit->setCalendarPopup(true); | |
23 _dateedit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | |
24 | |
25 layout->addWidget(_dateedit); | |
26 | |
27 SetEnabled(enabled); | |
28 connect(_checkbox, &QCheckBox::stateChanged, this, [this](int state) { | |
29 SetEnabled(state == Qt::Checked); | |
30 emit DataChanged(IsEnabled(), GetDate()); | |
31 }); | |
32 connect(_dateedit, &QDateEdit::dateChanged, this, [this](QDate) { emit DataChanged(IsEnabled(), GetDate()); }); | |
33 } | |
34 | |
35 void OptionalDate::SetEnabled(bool enabled) { | |
36 _checkbox->setCheckState(enabled ? Qt::Checked : Qt::Unchecked); | |
37 _dateedit->setEnabled(enabled); | |
38 } | |
39 | |
40 bool OptionalDate::IsEnabled() { | |
41 return _dateedit->isEnabled(); | |
42 } | |
43 | |
44 void OptionalDate::SetDate(QDate date) { | |
45 _dateedit->setDate(date); | |
46 } | |
47 | |
48 void OptionalDate::SetDate(Date date) { | |
49 if (!date.IsValid()) | |
50 return; | |
51 SetDate(date.GetAsQDate()); | |
52 } | |
53 | |
54 Date OptionalDate::GetDate() { | |
55 return Date(_dateedit->date()); | |
56 } | |
57 | |
58 QDateEdit* OptionalDate::GetDateEdit() { | |
59 return _dateedit; | |
60 } | |
61 | |
62 QCheckBox* OptionalDate::GetCheckBox() { | |
63 return _checkbox; | |
64 } | |
65 | |
66 #include "gui/widgets/moc_optional_date.cpp" |