Mercurial > minori
comparison src/gui/widgets/optional_date.cc @ 370:ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
author | Paper <paper@tflc.us> |
---|---|
date | Fri, 25 Jul 2025 10:22:04 -0400 |
parents | 4d461ef7d424 |
children |
comparison
equal
deleted
inserted
replaced
369:47c9f8502269 | 370:ea3a74ed2ef9 |
---|---|
2 #include "core/date.h" | 2 #include "core/date.h" |
3 #include <QCheckBox> | 3 #include <QCheckBox> |
4 #include <QDateEdit> | 4 #include <QDateEdit> |
5 #include <QHBoxLayout> | 5 #include <QHBoxLayout> |
6 | 6 |
7 OptionalDate::OptionalDate(QWidget* parent) { | 7 OptionalDate::OptionalDate(QWidget *parent) |
8 { | |
8 OptionalDate(false, parent); | 9 OptionalDate(false, parent); |
9 } | 10 } |
10 | 11 |
11 OptionalDate::OptionalDate(bool enabled, QWidget* parent) : QWidget(parent) { | 12 OptionalDate::OptionalDate(bool enabled, QWidget *parent) : QWidget(parent) |
12 QHBoxLayout* layout = new QHBoxLayout(this); | 13 { |
14 QHBoxLayout *layout = new QHBoxLayout(this); | |
13 layout->setContentsMargins(0, 0, 0, 0); | 15 layout->setContentsMargins(0, 0, 0, 0); |
14 | 16 |
15 _checkbox = new QCheckBox(this); | 17 _checkbox = new QCheckBox(this); |
16 _checkbox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); | 18 _checkbox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); |
17 | 19 |
30 emit DataChanged(IsEnabled(), GetDate()); | 32 emit DataChanged(IsEnabled(), GetDate()); |
31 }); | 33 }); |
32 connect(_dateedit, &QDateEdit::dateChanged, this, [this](QDate) { emit DataChanged(IsEnabled(), GetDate()); }); | 34 connect(_dateedit, &QDateEdit::dateChanged, this, [this](QDate) { emit DataChanged(IsEnabled(), GetDate()); }); |
33 } | 35 } |
34 | 36 |
35 void OptionalDate::SetEnabled(bool enabled) { | 37 void OptionalDate::SetEnabled(bool enabled) |
38 { | |
36 _checkbox->setCheckState(enabled ? Qt::Checked : Qt::Unchecked); | 39 _checkbox->setCheckState(enabled ? Qt::Checked : Qt::Unchecked); |
37 _dateedit->setEnabled(enabled); | 40 _dateedit->setEnabled(enabled); |
38 } | 41 } |
39 | 42 |
40 bool OptionalDate::IsEnabled() { | 43 bool OptionalDate::IsEnabled() |
44 { | |
41 return _dateedit->isEnabled(); | 45 return _dateedit->isEnabled(); |
42 } | 46 } |
43 | 47 |
44 void OptionalDate::SetDate(QDate date) { | 48 void OptionalDate::SetDate(QDate date) |
49 { | |
45 _dateedit->setDate(date); | 50 _dateedit->setDate(date); |
46 } | 51 } |
47 | 52 |
48 void OptionalDate::SetDate(Date date) { | 53 void OptionalDate::SetDate(Date date) |
54 { | |
49 if (!date.IsValid()) | 55 if (!date.IsValid()) |
50 return; | 56 return; |
51 SetDate(date.GetAsQDate()); | 57 SetDate(date.GetAsQDate()); |
52 } | 58 } |
53 | 59 |
54 Date OptionalDate::GetDate() { | 60 Date OptionalDate::GetDate() |
61 { | |
55 return Date(_dateedit->date()); | 62 return Date(_dateedit->date()); |
56 } | 63 } |
57 | 64 |
58 QDateEdit* OptionalDate::GetDateEdit() { | 65 QDateEdit *OptionalDate::GetDateEdit() |
66 { | |
59 return _dateedit; | 67 return _dateedit; |
60 } | 68 } |
61 | 69 |
62 QCheckBox* OptionalDate::GetCheckBox() { | 70 QCheckBox *OptionalDate::GetCheckBox() |
71 { | |
63 return _checkbox; | 72 return _checkbox; |
64 } | 73 } |