diff 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
line wrap: on
line diff
--- a/src/gui/widgets/optional_date.cpp	Mon Sep 25 13:50:56 2023 -0400
+++ b/src/gui/widgets/optional_date.cpp	Mon Sep 25 20:29:26 2023 -0400
@@ -1,4 +1,5 @@
 #include "gui/widgets/optional_date.h"
+#include "core/date.h"
 #include <QCheckBox>
 #include <QDateEdit>
 #include <QHBoxLayout>
@@ -12,7 +13,6 @@
 	layout->setMargin(0);
 
 	_checkbox = new QCheckBox(this);
-	_checkbox->setCheckState(enabled ? Qt::Checked : Qt::Unchecked);
 	_checkbox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
 
 	layout->addWidget(_checkbox, 0, Qt::AlignVCenter);
@@ -25,10 +25,17 @@
 	layout->addWidget(_dateedit);
 
 	SetEnabled(enabled);
-	connect(_checkbox, &QCheckBox::stateChanged, this, [this](int state) { SetEnabled(state == Qt::Checked); });
+	connect(_checkbox, &QCheckBox::stateChanged, this, [this](int state) {
+		SetEnabled(state == Qt::Checked);
+		emit DataChanged(IsEnabled(), GetDate());
+	});
+	connect(_dateedit, &QDateEdit::dateChanged, this, [this](QDate) {
+		emit DataChanged(IsEnabled(), GetDate());
+	});
 }
 
 void OptionalDate::SetEnabled(bool enabled) {
+	_checkbox->setCheckState(enabled ? Qt::Checked : Qt::Unchecked);
 	_dateedit->setEnabled(enabled);
 }
 
@@ -40,6 +47,15 @@
 	_dateedit->setDate(date);
 }
 
+void OptionalDate::SetDate(Date date) {
+	if (!date.IsValid()) return;
+	SetDate(date.GetAsQDate());
+}
+
+Date OptionalDate::GetDate() {
+	return Date(_dateedit->date());
+}
+
 QDateEdit* OptionalDate::GetDateEdit() {
 	return _dateedit;
 }
@@ -47,3 +63,5 @@
 QCheckBox* OptionalDate::GetCheckBox() {
 	return _checkbox;
 }
+
+#include "gui/widgets/moc_optional_date.cpp"