Mercurial > minori
comparison src/gui/widgets/optional_date.cpp @ 47:d8eb763e6661
information.cpp: add widgets to the list tab, and add an
"optional date" widget like taiga has so users can specify whether to
set the date or not
| author | Paper <mrpapersonic@gmail.com> | 
|---|---|
| date | Mon, 25 Sep 2023 00:43:38 -0400 | 
| parents | |
| children | e613772f41d5 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 46:d0adc4aedfc8 | 47:d8eb763e6661 | 
|---|---|
| 1 #include "gui/widgets/optional_date.h" | |
| 2 #include <QCheckBox> | |
| 3 #include <QDateEdit> | |
| 4 #include <QHBoxLayout> | |
| 5 | |
| 6 OptionalDate::OptionalDate(QWidget* parent) { | |
| 7 OptionalDate(false, parent); | |
| 8 } | |
| 9 | |
| 10 OptionalDate::OptionalDate(bool enabled, QWidget* parent) : QWidget(parent) { | |
| 11 QHBoxLayout* layout = new QHBoxLayout(this); | |
| 12 layout->setMargin(0); | |
| 13 | |
| 14 _checkbox = new QCheckBox(this); | |
| 15 _checkbox->setCheckState(enabled ? Qt::Checked : Qt::Unchecked); | |
| 16 _checkbox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); | |
| 17 | |
| 18 layout->addWidget(_checkbox); | |
| 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) { SetEnabled(state == Qt::Checked); }); | |
| 29 } | |
| 30 | |
| 31 void OptionalDate::SetEnabled(bool enabled) { | |
| 32 _dateedit->setEnabled(enabled); | |
| 33 } | |
| 34 | |
| 35 bool OptionalDate::IsEnabled() { | |
| 36 return _dateedit->isEnabled(); | |
| 37 } | |
| 38 | |
| 39 void OptionalDate::SetDate(QDate date) { | |
| 40 _dateedit->setDate(date); | |
| 41 } | |
| 42 | |
| 43 QDateEdit* OptionalDate::GetDateEdit() { | |
| 44 return _dateedit; | |
| 45 } | |
| 46 | |
| 47 QCheckBox* OptionalDate::GetCheckBox() { | |
| 48 return _checkbox; | |
| 49 } | 
