diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/gui/widgets/optional_date.cpp	Mon Sep 25 00:43:38 2023 -0400
@@ -0,0 +1,49 @@
+#include "gui/widgets/optional_date.h"
+#include <QCheckBox>
+#include <QDateEdit>
+#include <QHBoxLayout>
+
+OptionalDate::OptionalDate(QWidget* parent) {
+	OptionalDate(false, parent);
+}
+
+OptionalDate::OptionalDate(bool enabled, QWidget* parent) : QWidget(parent) {
+	QHBoxLayout* layout = new QHBoxLayout(this);
+	layout->setMargin(0);
+
+	_checkbox = new QCheckBox(this);
+	_checkbox->setCheckState(enabled ? Qt::Checked : Qt::Unchecked);
+	_checkbox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
+
+	layout->addWidget(_checkbox);
+
+	_dateedit = new QDateEdit(this);
+	_dateedit->setDisplayFormat("yyyy-MM-dd");
+	_dateedit->setCalendarPopup(true);
+	_dateedit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+
+	layout->addWidget(_dateedit);
+
+	SetEnabled(enabled);
+	connect(_checkbox, &QCheckBox::stateChanged, this, [this](int state) { SetEnabled(state == Qt::Checked); });
+}
+
+void OptionalDate::SetEnabled(bool enabled) {
+	_dateedit->setEnabled(enabled);
+}
+
+bool OptionalDate::IsEnabled() {
+	return _dateedit->isEnabled();
+}
+
+void OptionalDate::SetDate(QDate date) {
+	_dateedit->setDate(date);
+}
+
+QDateEdit* OptionalDate::GetDateEdit() {
+	return _dateedit;
+}
+
+QCheckBox* OptionalDate::GetCheckBox() {
+	return _checkbox;
+}