diff src/gui/dialog/information.cc @ 87:4aef97f4d998

information: use QGridLayout please... text: fix Line selection :)
author Paper <mrpapersonic@gmail.com>
date Tue, 31 Oct 2023 15:23:52 -0400
parents c912128af0eb
children 1b19d80b3f8c
line wrap: on
line diff
--- a/src/gui/dialog/information.cc	Tue Oct 31 13:52:36 2023 -0400
+++ b/src/gui/dialog/information.cc	Tue Oct 31 15:23:52 2023 -0400
@@ -94,129 +94,109 @@
 #define LAYOUT_HORIZ_SPACING 25
 #define LAYOUT_VERT_SPACING  5
 #define LAYOUT_ITEM_WIDTH    175
-/* Creates a subsection that takes up whatever space is necessary */
-#define CREATE_FULL_WIDTH_SUBSECTION(x) \
-	{ \
-		QWidget* subsection = new QWidget(section); \
-		subsection->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); \
-		QVBoxLayout* subsection_layout = new QVBoxLayout(subsection); \
-		subsection_layout->setSpacing(LAYOUT_VERT_SPACING); \
-		subsection_layout->setContentsMargins(0, 0, 0, 0); \
-		x; \
-		layout->addWidget(subsection, 0, Qt::AlignBottom); \
-	}
 
 /* Creates a section in the parent `a` */
 #define CREATE_FULL_WIDTH_SECTION(a, x) \
 	{ \
 		QWidget* section = new QWidget(a); \
-		QHBoxLayout* layout = new QHBoxLayout(section); \
+		QVBoxLayout* layout = new QVBoxLayout(section); \
+		layout->setSpacing(LAYOUT_HORIZ_SPACING); \
+		layout->setContentsMargins(0, 0, 0, 0); \
+		x; \
+		a->layout()->addWidget(section); \
+	}
+#define CREATE_SECTION(a, x) \
+	{ \
+		QWidget* section = new QWidget(a); \
+		QGridLayout* layout = new QGridLayout(section); \
 		layout->setSpacing(LAYOUT_HORIZ_SPACING); \
 		layout->setContentsMargins(0, 0, 0, 0); \
 		x; \
 		a->layout()->addWidget(section); \
 	}
 
-/* Creates a subsection with a width of 175 */
-#define CREATE_SUBSECTION(x) CREATE_FULL_WIDTH_SUBSECTION(x subsection->setFixedWidth(LAYOUT_ITEM_WIDTH);)
-/* Creates a section in the parent `a` */
-#define CREATE_SECTION(a, x) CREATE_FULL_WIDTH_SECTION(a, x layout->addStretch();)
-
 	CREATE_SECTION(sg_anime_list_content, {
-		/* Episodes watched section */
-		CREATE_SUBSECTION({
-			subsection_layout->addWidget(new QLabel(tr("Episodes watched:"), subsection));
+		layout->addWidget(new QLabel(tr("Episodes watched:"), section), 0, 0);
 
-			QSpinBox* spin_box = new QSpinBox(subsection);
-			connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) { _progress = i; });
-			spin_box->setRange(0, anime.GetEpisodes());
-			spin_box->setSingleStep(1);
-			spin_box->setValue(_progress = anime.GetUserProgress());
-			subsection_layout->addWidget(spin_box);
-		});
-		CREATE_SUBSECTION({
-			subsection_layout->addWidget(new QLabel(tr(" "), subsection));
+		QSpinBox* spin_box = new QSpinBox(section);
+		connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) { _progress = i; });
+		spin_box->setRange(0, anime.GetEpisodes());
+		spin_box->setSingleStep(1);
+		spin_box->setValue(_progress = anime.GetUserProgress());
+		layout->addWidget(spin_box, 1, 0);
 
-			QCheckBox* checkbox = new QCheckBox(tr("Rewatching"));
-			connect(checkbox, QOverload<int>::of(&QCheckBox::stateChanged), this,
-			        [this](int state) { _rewatching = (state == Qt::Checked); });
-			checkbox->setCheckState((_rewatching = anime.GetUserIsRewatching()) ? Qt::Checked : Qt::Unchecked);
-			subsection_layout->addWidget(checkbox);
-		});
+		layout->addWidget(new QLabel(tr(" "), section), 0, 1);
+
+		QCheckBox* checkbox = new QCheckBox(tr("Rewatching"));
+		connect(checkbox, QOverload<int>::of(&QCheckBox::stateChanged), this,
+		        [this](int state) { _rewatching = (state == Qt::Checked); });
+		checkbox->setCheckState((_rewatching = anime.GetUserIsRewatching()) ? Qt::Checked : Qt::Unchecked);
+		layout->addWidget(checkbox, 1, 1);
 	});
 	CREATE_SECTION(sg_anime_list_content, {
 		/* Status & score section */
-		CREATE_SUBSECTION({
-			subsection_layout->addWidget(new QLabel(tr("Status:"), subsection));
+		layout->addWidget(new QLabel(tr("Status:"), section), 0, 0);
 
-			/* FIXME: this sucks */
-			QStringList string_list;
-			for (unsigned int i = 0; i < Anime::ListStatuses.size(); i++)
-				string_list.append(Strings::ToQString(Translate::ToString(Anime::ListStatuses[i])));
+		/* FIXME: this sucks */
+		QStringList string_list;
+		for (unsigned int i = 0; i < Anime::ListStatuses.size(); i++)
+			string_list.append(Strings::ToQString(Translate::ToString(Anime::ListStatuses[i])));
 
-			QComboBox* combo_box = new QComboBox(subsection);
-			combo_box->addItems(string_list);
-			connect(combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
-			        [this](int i) { _status = Anime::ListStatuses[i]; });
-			combo_box->setCurrentIndex(static_cast<int>(_status = anime.GetUserStatus()) - 1);
-			subsection_layout->addWidget(combo_box);
-		});
-		CREATE_SUBSECTION({
-			subsection_layout->addWidget(new QLabel(tr("Score:"), subsection));
+		QComboBox* combo_box = new QComboBox(section);
+		combo_box->addItems(string_list);
+		connect(combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
+		        [this](int i) { _status = Anime::ListStatuses[i]; });
+		combo_box->setCurrentIndex(static_cast<int>(_status = anime.GetUserStatus()) - 1);
+		layout->addWidget(combo_box, 1, 0);
+	
+		layout->addWidget(new QLabel(tr("Score:"), section), 0, 1);
 
-			QSpinBox* spin_box = new QSpinBox(subsection);
-			connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) { _score = i; });
-			spin_box->setRange(0, 100);
-			spin_box->setSingleStep(5);
-			spin_box->setValue(_score = anime.GetUserScore());
-			subsection_layout->addWidget(spin_box);
-		});
+		QSpinBox* spin_box = new QSpinBox(section);
+		connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) { _score = i; });
+		spin_box->setRange(0, 100);
+		spin_box->setSingleStep(5);
+		spin_box->setValue(_score = anime.GetUserScore());
+		layout->addWidget(spin_box, 1, 1);
 	});
 	CREATE_FULL_WIDTH_SECTION(sg_anime_list_content, {
-		/* Notes section */
-		CREATE_FULL_WIDTH_SUBSECTION({
-			subsection_layout->addWidget(new QLabel(tr("Notes:"), subsection));
+		layout->addWidget(new QLabel(tr("Notes:"), section));
 
-			QLineEdit* line_edit = new QLineEdit(subsection);
-			connect(line_edit, &QLineEdit::textChanged, this, [this](const QString& text) {
-				/* this sucks but I don't really want to implement anything smarter :) */
-				_notes = Strings::ToUtf8String(text);
-			});
-			line_edit->setText(Strings::ToQString(_notes = anime.GetUserNotes()));
-			line_edit->setPlaceholderText(tr("Enter your notes about this anime"));
-			subsection_layout->addWidget(line_edit);
+		QLineEdit* line_edit = new QLineEdit(section);
+		connect(line_edit, &QLineEdit::textChanged, this, [this](const QString& text) {
+			/* this sucks but I don't really want to implement anything smarter :) */
+			_notes = Strings::ToUtf8String(text);
 		});
+		line_edit->setText(Strings::ToQString(_notes = anime.GetUserNotes()));
+		line_edit->setPlaceholderText(tr("Enter your notes about this anime"));
+		layout->addWidget(line_edit);
 	});
 	CREATE_SECTION(sg_anime_list_content, {
 		/* Dates section */
-		CREATE_SUBSECTION({
-			subsection_layout->addWidget(new QLabel(tr("Date started:"), subsection));
+		layout->addWidget(new QLabel(tr("Date started:"), section), 0, 0);
+
+		OptionalDate* date = new OptionalDate(true, section);
+		connect(date, &OptionalDate::DataChanged, this,
+		        [this](bool enabled, Date date) { _started = (enabled) ? date : Date(); });
+		_started = anime.GetUserDateStarted();
+		if (!_started.IsValid()) {
+			date->SetEnabled(false);
+			_started = anime.GetAirDate();
+		}
+		date->SetDate(_started);
+		layout->addWidget(date, 1, 0);
 
-			OptionalDate* date = new OptionalDate(true, subsection);
-			connect(date, &OptionalDate::DataChanged, this,
-			        [this](bool enabled, Date date) { _started = (enabled) ? date : Date(); });
-			_started = anime.GetUserDateStarted();
-			if (!_started.IsValid()) {
-				date->SetEnabled(false);
-				_started = anime.GetAirDate();
-			}
-			date->SetDate(_started);
-			subsection_layout->addWidget(date);
-		});
-		CREATE_SUBSECTION({
-			subsection_layout->addWidget(new QLabel(tr("Date completed:"), subsection));
+		layout->addWidget(new QLabel(tr("Date completed:"), section), 0, 1);
 
-			OptionalDate* date = new OptionalDate(true, subsection);
-			connect(date, &OptionalDate::DataChanged, this,
-			        [this](bool enabled, Date date) { _completed = (enabled) ? date : Date(); });
-			_completed = anime.GetUserDateCompleted();
-			if (!_completed.IsValid()) {
-				date->SetEnabled(false);
-				_completed = anime.GetAirDate();
-			}
-			date->SetDate(_completed);
-			subsection_layout->addWidget(date);
-		});
+		date = new OptionalDate(true, section);
+		connect(date, &OptionalDate::DataChanged, this,
+		        [this](bool enabled, Date date) { _completed = (enabled) ? date : Date(); });
+		_completed = anime.GetUserDateCompleted();
+		if (!_completed.IsValid()) {
+			date->SetEnabled(false);
+			_completed = anime.GetAirDate();
+		}
+		date->SetDate(_completed);
+		layout->addWidget(date, 1, 1);
 	});
 
 	settings_layout->addWidget(sg_anime_list_content);
@@ -229,23 +209,18 @@
 	sg_local_layout->setContentsMargins(12, 0, 0, 0);
 
 	CREATE_FULL_WIDTH_SECTION(sg_local_content, {
-		/* Alternative titles */
-		CREATE_FULL_WIDTH_SUBSECTION({
-			subsection_layout->addWidget(new QLabel(tr("Alternative titles:"), subsection));
+		layout->addWidget(new QLabel(tr("Alternative titles:"), section));
 
-			QLineEdit* line_edit = new QLineEdit("", subsection);
-			line_edit->setPlaceholderText(
-			    tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)"));
-			subsection_layout->addWidget(line_edit);
+		QLineEdit* line_edit = new QLineEdit("", section);
+		line_edit->setPlaceholderText(
+		    tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)"));
+		layout->addWidget(line_edit);
 
-			QCheckBox* checkbox = new QCheckBox(tr("Use the first alternative title to search for torrents"));
-			subsection_layout->addWidget(checkbox);
-		});
+		QCheckBox* checkbox = new QCheckBox(tr("Use the first alternative title to search for torrents"));
+		layout->addWidget(checkbox);
 	});
 #undef CREATE_SECTION
-#undef CREATE_SUBSECTION
 #undef CREATE_FULL_WIDTH_SECTION
-#undef CREATE_FULL_WIDTH_SUBSECTION
 
 	settings_layout->addWidget(sg_local_content);
 	settings_layout->addStretch();