Mercurial > minori
comparison src/gui/widgets/optional_date.cpp @ 51:75c804f713b2
window: add about window,
*: use tr() when applicable (useful for i18n)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 25 Sep 2023 20:29:26 -0400 |
parents | e613772f41d5 |
children | 4c6dd5999b39 |
comparison
equal
deleted
inserted
replaced
50:10868c3fb2be | 51:75c804f713b2 |
---|---|
1 #include "gui/widgets/optional_date.h" | 1 #include "gui/widgets/optional_date.h" |
2 #include "core/date.h" | |
2 #include <QCheckBox> | 3 #include <QCheckBox> |
3 #include <QDateEdit> | 4 #include <QDateEdit> |
4 #include <QHBoxLayout> | 5 #include <QHBoxLayout> |
5 | 6 |
6 OptionalDate::OptionalDate(QWidget* parent) { | 7 OptionalDate::OptionalDate(QWidget* parent) { |
10 OptionalDate::OptionalDate(bool enabled, QWidget* parent) : QWidget(parent) { | 11 OptionalDate::OptionalDate(bool enabled, QWidget* parent) : QWidget(parent) { |
11 QHBoxLayout* layout = new QHBoxLayout(this); | 12 QHBoxLayout* layout = new QHBoxLayout(this); |
12 layout->setMargin(0); | 13 layout->setMargin(0); |
13 | 14 |
14 _checkbox = new QCheckBox(this); | 15 _checkbox = new QCheckBox(this); |
15 _checkbox->setCheckState(enabled ? Qt::Checked : Qt::Unchecked); | |
16 _checkbox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); | 16 _checkbox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); |
17 | 17 |
18 layout->addWidget(_checkbox, 0, Qt::AlignVCenter); | 18 layout->addWidget(_checkbox, 0, Qt::AlignVCenter); |
19 | 19 |
20 _dateedit = new QDateEdit(this); | 20 _dateedit = new QDateEdit(this); |
23 _dateedit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | 23 _dateedit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
24 | 24 |
25 layout->addWidget(_dateedit); | 25 layout->addWidget(_dateedit); |
26 | 26 |
27 SetEnabled(enabled); | 27 SetEnabled(enabled); |
28 connect(_checkbox, &QCheckBox::stateChanged, this, [this](int state) { SetEnabled(state == Qt::Checked); }); | 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) { | |
33 emit DataChanged(IsEnabled(), GetDate()); | |
34 }); | |
29 } | 35 } |
30 | 36 |
31 void OptionalDate::SetEnabled(bool enabled) { | 37 void OptionalDate::SetEnabled(bool enabled) { |
38 _checkbox->setCheckState(enabled ? Qt::Checked : Qt::Unchecked); | |
32 _dateedit->setEnabled(enabled); | 39 _dateedit->setEnabled(enabled); |
33 } | 40 } |
34 | 41 |
35 bool OptionalDate::IsEnabled() { | 42 bool OptionalDate::IsEnabled() { |
36 return _dateedit->isEnabled(); | 43 return _dateedit->isEnabled(); |
38 | 45 |
39 void OptionalDate::SetDate(QDate date) { | 46 void OptionalDate::SetDate(QDate date) { |
40 _dateedit->setDate(date); | 47 _dateedit->setDate(date); |
41 } | 48 } |
42 | 49 |
50 void OptionalDate::SetDate(Date date) { | |
51 if (!date.IsValid()) return; | |
52 SetDate(date.GetAsQDate()); | |
53 } | |
54 | |
55 Date OptionalDate::GetDate() { | |
56 return Date(_dateedit->date()); | |
57 } | |
58 | |
43 QDateEdit* OptionalDate::GetDateEdit() { | 59 QDateEdit* OptionalDate::GetDateEdit() { |
44 return _dateedit; | 60 return _dateedit; |
45 } | 61 } |
46 | 62 |
47 QCheckBox* OptionalDate::GetCheckBox() { | 63 QCheckBox* OptionalDate::GetCheckBox() { |
48 return _checkbox; | 64 return _checkbox; |
49 } | 65 } |
66 | |
67 #include "gui/widgets/moc_optional_date.cpp" |