Mercurial > minori
diff src/gui/dialog/information.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 | d0adc4aedfc8 |
children | 75c804f713b2 |
line wrap: on
line diff
--- a/src/gui/dialog/information.cpp Sat Sep 23 01:02:15 2023 -0400 +++ b/src/gui/dialog/information.cpp Mon Sep 25 00:43:38 2023 -0400 @@ -1,13 +1,16 @@ #include "gui/dialog/information.h" #include "core/anime.h" +#include "core/anime_db.h" #include "core/array.h" #include "core/strings.h" #include "gui/pages/anime_list.h" #include "gui/translate/anime.h" #include "gui/widgets/text.h" +#include "gui/widgets/optional_date.h" #include "gui/window.h" #include <QCheckBox> #include <QComboBox> +#include <QDateEdit> #include <QDebug> #include <QDialogButtonBox> #include <QLineEdit> @@ -20,6 +23,10 @@ /* TODO: Taiga disables rendering of the tab widget entirely when the anime is not part of a list, which sucks. Think of a better way to implement this later. */ +void InformationDialog::SaveData() { + Anime::Anime& anime = Anime::db.items[id]; +} + InformationDialog::InformationDialog(const Anime::Anime& anime, std::function<void()> accept, QWidget* parent) : QDialog(parent) { setFixedSize(842, 613); @@ -116,23 +123,58 @@ sg_anime_list_content->layout()->setSpacing(5); sg_anime_list_content->layout()->setContentsMargins(12, 0, 0, 0); - /* Note: PLEASE find a way we can consolidate these. By ANY other means than - putting them in a separate function. Macros are very much preferred. */ -#define LAYOUT_HORIZ_SPACING 9 -#define LAYOUT_VERT_SPACING 5 - { +/* these macros make this a lot easier to edit */ +#define LAYOUT_HORIZ_SPACING 25 +#define LAYOUT_VERT_SPACING 5 +#define LAYOUT_ITEM_WIDTH 175 +/* Creates a subsection with a width of 175 */ +#define CREATE_SUBSECTION(x) \ + { \ + QWidget* subsection = new QWidget(section); \ + subsection->setLayout(new QVBoxLayout); \ + subsection->setFixedWidth(LAYOUT_ITEM_WIDTH); \ + subsection->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); \ + subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); \ + subsection->layout()->setMargin(0); \ + x; \ + layout->addWidget(subsection); \ + } +/* Creates a section in the parent `a` */ +#define CREATE_SECTION(a, x) \ + { \ + QWidget* section = new QWidget(a); \ + QHBoxLayout* layout = new QHBoxLayout(section); \ + layout->setSpacing(LAYOUT_HORIZ_SPACING); \ + layout->setMargin(0); \ + x; \ + layout->addStretch(); \ + a->layout()->addWidget(section); \ + } +/* Creates a subsection that takes up whatever space is necessary */ +#define CREATE_FULL_WIDTH_SUBSECTION(x) \ + { \ + QWidget* subsection = new QWidget(section); \ + subsection->setLayout(new QVBoxLayout); \ + subsection->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); \ + subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); \ + subsection->layout()->setMargin(0); \ + x; \ + layout->addWidget(subsection); \ + } +/* Creates a section in the parent `a` */ +#define CREATE_FULL_WIDTH_SECTION(a, x) \ + { \ + QWidget* section = new QWidget(a); \ + QHBoxLayout* layout = new QHBoxLayout(section); \ + layout->setSpacing(LAYOUT_HORIZ_SPACING); \ + layout->setMargin(0); \ + x; \ + a->layout()->addWidget(section); \ + } + + CREATE_SECTION(sg_anime_list_content, { /* Episodes watched section */ - QWidget* section = new QWidget(sg_anime_list_content); - QHBoxLayout* layout = new QHBoxLayout; - layout->setSpacing(LAYOUT_HORIZ_SPACING); - layout->setMargin(0); - section->setLayout(layout); - { - QWidget* subsection = new QWidget(section); - subsection->setLayout(new QVBoxLayout); - subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); - subsection->layout()->setMargin(0); - + CREATE_SUBSECTION({ subsection->layout()->addWidget(new QLabel(tr("Episodes watched:"), subsection)); QSpinBox* spin_box = new QSpinBox(subsection); @@ -140,37 +182,17 @@ spin_box->setSingleStep(1); spin_box->setValue(anime.GetUserProgress()); subsection->layout()->addWidget(spin_box); - - layout->addWidget(subsection); - } - { - QWidget* subsection = new QWidget(section); - subsection->setLayout(new QVBoxLayout); - subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); - subsection->layout()->setMargin(0); - + }); + CREATE_SUBSECTION({ subsection->layout()->addWidget(new QLabel(tr(" "), subsection)); QCheckBox* rewatched_checkbox = new QCheckBox("Rewatching"); subsection->layout()->addWidget(rewatched_checkbox); - - layout->addWidget(subsection); - } - sg_anime_list_content->layout()->addWidget(section); - } - { + }); + }); + CREATE_SECTION(sg_anime_list_content, { /* Status & score section */ - QWidget* section = new QWidget(sg_anime_list_content); - QHBoxLayout* layout = new QHBoxLayout; - layout->setSpacing(LAYOUT_HORIZ_SPACING); - layout->setMargin(0); - section->setLayout(layout); - { - QWidget* subsection = new QWidget(section); - subsection->setLayout(new QVBoxLayout); - subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); - subsection->layout()->setMargin(0); - + CREATE_SUBSECTION({ subsection->layout()->addWidget(new QLabel(tr("Status:"), subsection)); QStringList string_list; @@ -180,15 +202,8 @@ QComboBox* combo_box = new QComboBox(subsection); combo_box->addItems(string_list); subsection->layout()->addWidget(combo_box); - - layout->addWidget(subsection); - } - { - QWidget* subsection = new QWidget(section); - subsection->setLayout(new QVBoxLayout); - subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); - subsection->layout()->setMargin(0); - + }); + CREATE_SUBSECTION({ subsection->layout()->addWidget(new QLabel(tr("Score:"), subsection)); QSpinBox* spin_box = new QSpinBox(subsection); @@ -196,34 +211,35 @@ spin_box->setSingleStep(5); spin_box->setValue(anime.GetUserScore()); subsection->layout()->addWidget(spin_box); - - layout->addWidget(subsection); - } - sg_anime_list_content->layout()->addWidget(section); - } - { + }); + }); + CREATE_FULL_WIDTH_SECTION(sg_anime_list_content, { /* Notes section */ - QWidget* section = new QWidget(sg_anime_list_content); - QHBoxLayout* layout = new QHBoxLayout; - layout->setSpacing(LAYOUT_HORIZ_SPACING); - layout->setMargin(0); - section->setLayout(layout); - { - QWidget* subsection = new QWidget(section); - subsection->setLayout(new QVBoxLayout); - subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); - subsection->layout()->setMargin(0); - + CREATE_FULL_WIDTH_SUBSECTION({ subsection->layout()->addWidget(new QLabel(tr("Notes:"), subsection)); QLineEdit* line_edit = new QLineEdit(QString::fromStdString(anime.GetUserNotes()), subsection); line_edit->setPlaceholderText(tr("Enter your notes about this anime")); subsection->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(subsection); - } - sg_anime_list_content->layout()->addWidget(section); - } + OptionalDate* date = new OptionalDate(true, subsection); + date->SetDate(QDate(2000, 1, 1)); + subsection->layout()->addWidget(date); + }); + CREATE_SUBSECTION({ + subsection->layout()->addWidget(new QLabel(tr("Date completed:"), subsection)); + + OptionalDate* date = new OptionalDate(true, subsection); + date->SetDate(QDate(2000, 1, 1)); + subsection->layout()->addWidget(date); + }); + }); settings_widget->layout()->addWidget(new TextWidgets::Header(tr("Local settings"), settings_widget)); @@ -233,32 +249,24 @@ sg_local_content->layout()->setSpacing(5); sg_local_content->layout()->setContentsMargins(12, 0, 0, 0); - { + CREATE_FULL_WIDTH_SECTION(sg_local_content, { /* Alternative titles */ - QWidget* section = new QWidget(sg_local_content); - QHBoxLayout* layout = new QHBoxLayout; - layout->setSpacing(LAYOUT_HORIZ_SPACING); - layout->setMargin(0); - section->setLayout(layout); - { - QWidget* subsection = new QWidget(section); - subsection->setLayout(new QVBoxLayout); - subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); - subsection->layout()->setMargin(0); - + CREATE_FULL_WIDTH_SUBSECTION({ subsection->layout()->addWidget(new QLabel(tr("Alternative titles:"), subsection)); QLineEdit* line_edit = new QLineEdit(QString::fromStdString(anime.GetUserNotes()), subsection); - line_edit->setPlaceholderText(tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)")); + line_edit->setPlaceholderText( + tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)")); subsection->layout()->addWidget(line_edit); QCheckBox* checkbox = new QCheckBox("Use the first alternative title to search for torrents"); subsection->layout()->addWidget(checkbox); - - layout->addWidget(subsection); - } - sg_local_content->layout()->addWidget(section); - } + }); + }); +#undef CREATE_SECTION +#undef CREATE_SUBSECTION +#undef CREATE_FULL_WIDTH_SECTION +#undef CREATE_FULL_WIDTH_SUBSECTION static_cast<QBoxLayout*>(settings_widget->layout())->addStretch();