Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
46:d0adc4aedfc8 | 47:d8eb763e6661 |
---|---|
1 #include "gui/dialog/information.h" | 1 #include "gui/dialog/information.h" |
2 #include "core/anime.h" | 2 #include "core/anime.h" |
3 #include "core/anime_db.h" | |
3 #include "core/array.h" | 4 #include "core/array.h" |
4 #include "core/strings.h" | 5 #include "core/strings.h" |
5 #include "gui/pages/anime_list.h" | 6 #include "gui/pages/anime_list.h" |
6 #include "gui/translate/anime.h" | 7 #include "gui/translate/anime.h" |
7 #include "gui/widgets/text.h" | 8 #include "gui/widgets/text.h" |
9 #include "gui/widgets/optional_date.h" | |
8 #include "gui/window.h" | 10 #include "gui/window.h" |
9 #include <QCheckBox> | 11 #include <QCheckBox> |
10 #include <QComboBox> | 12 #include <QComboBox> |
13 #include <QDateEdit> | |
11 #include <QDebug> | 14 #include <QDebug> |
12 #include <QDialogButtonBox> | 15 #include <QDialogButtonBox> |
13 #include <QLineEdit> | 16 #include <QLineEdit> |
14 #include <QPlainTextEdit> | 17 #include <QPlainTextEdit> |
15 #include <QSpinBox> | 18 #include <QSpinBox> |
18 #include <QVBoxLayout> | 21 #include <QVBoxLayout> |
19 #include <functional> | 22 #include <functional> |
20 | 23 |
21 /* TODO: Taiga disables rendering of the tab widget entirely when the anime is not part of a list, | 24 /* TODO: Taiga disables rendering of the tab widget entirely when the anime is not part of a list, |
22 which sucks. Think of a better way to implement this later. */ | 25 which sucks. Think of a better way to implement this later. */ |
26 void InformationDialog::SaveData() { | |
27 Anime::Anime& anime = Anime::db.items[id]; | |
28 } | |
29 | |
23 InformationDialog::InformationDialog(const Anime::Anime& anime, std::function<void()> accept, QWidget* parent) | 30 InformationDialog::InformationDialog(const Anime::Anime& anime, std::function<void()> accept, QWidget* parent) |
24 : QDialog(parent) { | 31 : QDialog(parent) { |
25 setFixedSize(842, 613); | 32 setFixedSize(842, 613); |
26 setWindowTitle(tr("Anime Information")); | 33 setWindowTitle(tr("Anime Information")); |
27 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); | 34 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); |
114 settings_widget->layout()->addWidget(sg_anime_list_content); | 121 settings_widget->layout()->addWidget(sg_anime_list_content); |
115 sg_anime_list_content->setLayout(new QVBoxLayout); | 122 sg_anime_list_content->setLayout(new QVBoxLayout); |
116 sg_anime_list_content->layout()->setSpacing(5); | 123 sg_anime_list_content->layout()->setSpacing(5); |
117 sg_anime_list_content->layout()->setContentsMargins(12, 0, 0, 0); | 124 sg_anime_list_content->layout()->setContentsMargins(12, 0, 0, 0); |
118 | 125 |
119 /* Note: PLEASE find a way we can consolidate these. By ANY other means than | 126 /* these macros make this a lot easier to edit */ |
120 putting them in a separate function. Macros are very much preferred. */ | 127 #define LAYOUT_HORIZ_SPACING 25 |
121 #define LAYOUT_HORIZ_SPACING 9 | 128 #define LAYOUT_VERT_SPACING 5 |
122 #define LAYOUT_VERT_SPACING 5 | 129 #define LAYOUT_ITEM_WIDTH 175 |
123 { | 130 /* Creates a subsection with a width of 175 */ |
131 #define CREATE_SUBSECTION(x) \ | |
132 { \ | |
133 QWidget* subsection = new QWidget(section); \ | |
134 subsection->setLayout(new QVBoxLayout); \ | |
135 subsection->setFixedWidth(LAYOUT_ITEM_WIDTH); \ | |
136 subsection->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); \ | |
137 subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); \ | |
138 subsection->layout()->setMargin(0); \ | |
139 x; \ | |
140 layout->addWidget(subsection); \ | |
141 } | |
142 /* Creates a section in the parent `a` */ | |
143 #define CREATE_SECTION(a, x) \ | |
144 { \ | |
145 QWidget* section = new QWidget(a); \ | |
146 QHBoxLayout* layout = new QHBoxLayout(section); \ | |
147 layout->setSpacing(LAYOUT_HORIZ_SPACING); \ | |
148 layout->setMargin(0); \ | |
149 x; \ | |
150 layout->addStretch(); \ | |
151 a->layout()->addWidget(section); \ | |
152 } | |
153 /* Creates a subsection that takes up whatever space is necessary */ | |
154 #define CREATE_FULL_WIDTH_SUBSECTION(x) \ | |
155 { \ | |
156 QWidget* subsection = new QWidget(section); \ | |
157 subsection->setLayout(new QVBoxLayout); \ | |
158 subsection->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); \ | |
159 subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); \ | |
160 subsection->layout()->setMargin(0); \ | |
161 x; \ | |
162 layout->addWidget(subsection); \ | |
163 } | |
164 /* Creates a section in the parent `a` */ | |
165 #define CREATE_FULL_WIDTH_SECTION(a, x) \ | |
166 { \ | |
167 QWidget* section = new QWidget(a); \ | |
168 QHBoxLayout* layout = new QHBoxLayout(section); \ | |
169 layout->setSpacing(LAYOUT_HORIZ_SPACING); \ | |
170 layout->setMargin(0); \ | |
171 x; \ | |
172 a->layout()->addWidget(section); \ | |
173 } | |
174 | |
175 CREATE_SECTION(sg_anime_list_content, { | |
124 /* Episodes watched section */ | 176 /* Episodes watched section */ |
125 QWidget* section = new QWidget(sg_anime_list_content); | 177 CREATE_SUBSECTION({ |
126 QHBoxLayout* layout = new QHBoxLayout; | |
127 layout->setSpacing(LAYOUT_HORIZ_SPACING); | |
128 layout->setMargin(0); | |
129 section->setLayout(layout); | |
130 { | |
131 QWidget* subsection = new QWidget(section); | |
132 subsection->setLayout(new QVBoxLayout); | |
133 subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); | |
134 subsection->layout()->setMargin(0); | |
135 | |
136 subsection->layout()->addWidget(new QLabel(tr("Episodes watched:"), subsection)); | 178 subsection->layout()->addWidget(new QLabel(tr("Episodes watched:"), subsection)); |
137 | 179 |
138 QSpinBox* spin_box = new QSpinBox(subsection); | 180 QSpinBox* spin_box = new QSpinBox(subsection); |
139 spin_box->setRange(0, anime.GetEpisodes()); | 181 spin_box->setRange(0, anime.GetEpisodes()); |
140 spin_box->setSingleStep(1); | 182 spin_box->setSingleStep(1); |
141 spin_box->setValue(anime.GetUserProgress()); | 183 spin_box->setValue(anime.GetUserProgress()); |
142 subsection->layout()->addWidget(spin_box); | 184 subsection->layout()->addWidget(spin_box); |
143 | 185 }); |
144 layout->addWidget(subsection); | 186 CREATE_SUBSECTION({ |
145 } | |
146 { | |
147 QWidget* subsection = new QWidget(section); | |
148 subsection->setLayout(new QVBoxLayout); | |
149 subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); | |
150 subsection->layout()->setMargin(0); | |
151 | |
152 subsection->layout()->addWidget(new QLabel(tr(" "), subsection)); | 187 subsection->layout()->addWidget(new QLabel(tr(" "), subsection)); |
153 | 188 |
154 QCheckBox* rewatched_checkbox = new QCheckBox("Rewatching"); | 189 QCheckBox* rewatched_checkbox = new QCheckBox("Rewatching"); |
155 subsection->layout()->addWidget(rewatched_checkbox); | 190 subsection->layout()->addWidget(rewatched_checkbox); |
156 | 191 }); |
157 layout->addWidget(subsection); | 192 }); |
158 } | 193 CREATE_SECTION(sg_anime_list_content, { |
159 sg_anime_list_content->layout()->addWidget(section); | |
160 } | |
161 { | |
162 /* Status & score section */ | 194 /* Status & score section */ |
163 QWidget* section = new QWidget(sg_anime_list_content); | 195 CREATE_SUBSECTION({ |
164 QHBoxLayout* layout = new QHBoxLayout; | |
165 layout->setSpacing(LAYOUT_HORIZ_SPACING); | |
166 layout->setMargin(0); | |
167 section->setLayout(layout); | |
168 { | |
169 QWidget* subsection = new QWidget(section); | |
170 subsection->setLayout(new QVBoxLayout); | |
171 subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); | |
172 subsection->layout()->setMargin(0); | |
173 | |
174 subsection->layout()->addWidget(new QLabel(tr("Status:"), subsection)); | 196 subsection->layout()->addWidget(new QLabel(tr("Status:"), subsection)); |
175 | 197 |
176 QStringList string_list; | 198 QStringList string_list; |
177 for (unsigned int i = 0; i < ARRAYSIZE(Anime::ListStatuses); i++) | 199 for (unsigned int i = 0; i < ARRAYSIZE(Anime::ListStatuses); i++) |
178 string_list.append(QString::fromStdString(Translate::ToString(Anime::ListStatuses[i]))); | 200 string_list.append(QString::fromStdString(Translate::ToString(Anime::ListStatuses[i]))); |
179 | 201 |
180 QComboBox* combo_box = new QComboBox(subsection); | 202 QComboBox* combo_box = new QComboBox(subsection); |
181 combo_box->addItems(string_list); | 203 combo_box->addItems(string_list); |
182 subsection->layout()->addWidget(combo_box); | 204 subsection->layout()->addWidget(combo_box); |
183 | 205 }); |
184 layout->addWidget(subsection); | 206 CREATE_SUBSECTION({ |
185 } | |
186 { | |
187 QWidget* subsection = new QWidget(section); | |
188 subsection->setLayout(new QVBoxLayout); | |
189 subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); | |
190 subsection->layout()->setMargin(0); | |
191 | |
192 subsection->layout()->addWidget(new QLabel(tr("Score:"), subsection)); | 207 subsection->layout()->addWidget(new QLabel(tr("Score:"), subsection)); |
193 | 208 |
194 QSpinBox* spin_box = new QSpinBox(subsection); | 209 QSpinBox* spin_box = new QSpinBox(subsection); |
195 spin_box->setRange(0, 100); | 210 spin_box->setRange(0, 100); |
196 spin_box->setSingleStep(5); | 211 spin_box->setSingleStep(5); |
197 spin_box->setValue(anime.GetUserScore()); | 212 spin_box->setValue(anime.GetUserScore()); |
198 subsection->layout()->addWidget(spin_box); | 213 subsection->layout()->addWidget(spin_box); |
199 | 214 }); |
200 layout->addWidget(subsection); | 215 }); |
201 } | 216 CREATE_FULL_WIDTH_SECTION(sg_anime_list_content, { |
202 sg_anime_list_content->layout()->addWidget(section); | |
203 } | |
204 { | |
205 /* Notes section */ | 217 /* Notes section */ |
206 QWidget* section = new QWidget(sg_anime_list_content); | 218 CREATE_FULL_WIDTH_SUBSECTION({ |
207 QHBoxLayout* layout = new QHBoxLayout; | |
208 layout->setSpacing(LAYOUT_HORIZ_SPACING); | |
209 layout->setMargin(0); | |
210 section->setLayout(layout); | |
211 { | |
212 QWidget* subsection = new QWidget(section); | |
213 subsection->setLayout(new QVBoxLayout); | |
214 subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); | |
215 subsection->layout()->setMargin(0); | |
216 | |
217 subsection->layout()->addWidget(new QLabel(tr("Notes:"), subsection)); | 219 subsection->layout()->addWidget(new QLabel(tr("Notes:"), subsection)); |
218 | 220 |
219 QLineEdit* line_edit = new QLineEdit(QString::fromStdString(anime.GetUserNotes()), subsection); | 221 QLineEdit* line_edit = new QLineEdit(QString::fromStdString(anime.GetUserNotes()), subsection); |
220 line_edit->setPlaceholderText(tr("Enter your notes about this anime")); | 222 line_edit->setPlaceholderText(tr("Enter your notes about this anime")); |
221 subsection->layout()->addWidget(line_edit); | 223 subsection->layout()->addWidget(line_edit); |
222 | 224 }); |
223 layout->addWidget(subsection); | 225 }); |
224 } | 226 CREATE_SECTION(sg_anime_list_content, { |
225 sg_anime_list_content->layout()->addWidget(section); | 227 /* Dates section */ |
226 } | 228 CREATE_SUBSECTION({ |
229 subsection->layout()->addWidget(new QLabel(tr("Date started:"), subsection)); | |
230 | |
231 OptionalDate* date = new OptionalDate(true, subsection); | |
232 date->SetDate(QDate(2000, 1, 1)); | |
233 subsection->layout()->addWidget(date); | |
234 }); | |
235 CREATE_SUBSECTION({ | |
236 subsection->layout()->addWidget(new QLabel(tr("Date completed:"), subsection)); | |
237 | |
238 OptionalDate* date = new OptionalDate(true, subsection); | |
239 date->SetDate(QDate(2000, 1, 1)); | |
240 subsection->layout()->addWidget(date); | |
241 }); | |
242 }); | |
227 | 243 |
228 settings_widget->layout()->addWidget(new TextWidgets::Header(tr("Local settings"), settings_widget)); | 244 settings_widget->layout()->addWidget(new TextWidgets::Header(tr("Local settings"), settings_widget)); |
229 | 245 |
230 QWidget* sg_local_content = new QWidget(settings_widget); | 246 QWidget* sg_local_content = new QWidget(settings_widget); |
231 settings_widget->layout()->addWidget(sg_local_content); | 247 settings_widget->layout()->addWidget(sg_local_content); |
232 sg_local_content->setLayout(new QVBoxLayout); | 248 sg_local_content->setLayout(new QVBoxLayout); |
233 sg_local_content->layout()->setSpacing(5); | 249 sg_local_content->layout()->setSpacing(5); |
234 sg_local_content->layout()->setContentsMargins(12, 0, 0, 0); | 250 sg_local_content->layout()->setContentsMargins(12, 0, 0, 0); |
235 | 251 |
236 { | 252 CREATE_FULL_WIDTH_SECTION(sg_local_content, { |
237 /* Alternative titles */ | 253 /* Alternative titles */ |
238 QWidget* section = new QWidget(sg_local_content); | 254 CREATE_FULL_WIDTH_SUBSECTION({ |
239 QHBoxLayout* layout = new QHBoxLayout; | |
240 layout->setSpacing(LAYOUT_HORIZ_SPACING); | |
241 layout->setMargin(0); | |
242 section->setLayout(layout); | |
243 { | |
244 QWidget* subsection = new QWidget(section); | |
245 subsection->setLayout(new QVBoxLayout); | |
246 subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); | |
247 subsection->layout()->setMargin(0); | |
248 | |
249 subsection->layout()->addWidget(new QLabel(tr("Alternative titles:"), subsection)); | 255 subsection->layout()->addWidget(new QLabel(tr("Alternative titles:"), subsection)); |
250 | 256 |
251 QLineEdit* line_edit = new QLineEdit(QString::fromStdString(anime.GetUserNotes()), subsection); | 257 QLineEdit* line_edit = new QLineEdit(QString::fromStdString(anime.GetUserNotes()), subsection); |
252 line_edit->setPlaceholderText(tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)")); | 258 line_edit->setPlaceholderText( |
259 tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)")); | |
253 subsection->layout()->addWidget(line_edit); | 260 subsection->layout()->addWidget(line_edit); |
254 | 261 |
255 QCheckBox* checkbox = new QCheckBox("Use the first alternative title to search for torrents"); | 262 QCheckBox* checkbox = new QCheckBox("Use the first alternative title to search for torrents"); |
256 subsection->layout()->addWidget(checkbox); | 263 subsection->layout()->addWidget(checkbox); |
257 | 264 }); |
258 layout->addWidget(subsection); | 265 }); |
259 } | 266 #undef CREATE_SECTION |
260 sg_local_content->layout()->addWidget(section); | 267 #undef CREATE_SUBSECTION |
261 } | 268 #undef CREATE_FULL_WIDTH_SECTION |
269 #undef CREATE_FULL_WIDTH_SUBSECTION | |
262 | 270 |
263 static_cast<QBoxLayout*>(settings_widget->layout())->addStretch(); | 271 static_cast<QBoxLayout*>(settings_widget->layout())->addStretch(); |
264 | 272 |
265 tabbed_widget->addTab(main_information_widget, "Main information"); | 273 tabbed_widget->addTab(main_information_widget, "Main information"); |
266 tabbed_widget->addTab(settings_widget, "My list and settings"); | 274 tabbed_widget->addTab(settings_widget, "My list and settings"); |