comparison src/gui/dialog/information.cc @ 370:ea3a74ed2ef9

*: hm, last commit wasn't quite finished?
author Paper <paper@tflc.us>
date Fri, 25 Jul 2025 10:22:04 -0400
parents 6d37a998cf91
children
comparison
equal deleted inserted replaced
369:47c9f8502269 370:ea3a74ed2ef9
25 #include <QVBoxLayout> 25 #include <QVBoxLayout>
26 26
27 #include <functional> 27 #include <functional>
28 #include <iostream> 28 #include <iostream>
29 #ifdef WIN32 29 #ifdef WIN32
30 # include "sys/win32/dark_theme.h" 30 # include "sys/win32/dark_theme.h"
31 #endif 31 #endif
32 32
33 /* TODO: Taiga disables rendering of the tab widget entirely when the anime is not part of a list, 33 /* TODO: Taiga disables rendering of the tab widget entirely when the anime is not part of a list,
34 which sucks. Think of a better way to implement this later. */ 34 which sucks. Think of a better way to implement this later. */
35 void InformationDialog::SaveData(Anime::Anime* anime) { 35 void InformationDialog::SaveData(Anime::Anime *anime)
36 {
36 if (!anime->IsInUserList()) 37 if (!anime->IsInUserList())
37 return; 38 return;
38 39
39 anime->SetUserProgress(_progress); 40 anime->SetUserProgress(_progress);
40 anime->SetUserScore(_score); 41 anime->SetUserScore(_score);
43 anime->SetUserNotes(_notes); 44 anime->SetUserNotes(_notes);
44 anime->SetUserDateStarted(_started); 45 anime->SetUserDateStarted(_started);
45 anime->SetUserDateCompleted(_completed); 46 anime->SetUserDateCompleted(_completed);
46 } 47 }
47 48
48 InformationDialog::InformationDialog(Anime::Anime* anime, std::function<void(Anime::Anime*)> accept, enum Pages page, 49 InformationDialog::InformationDialog(Anime::Anime *anime, std::function<void(Anime::Anime *)> accept, enum Pages page,
49 QWidget* parent) 50 QWidget *parent)
50 : Dialog(parent) { 51 : Dialog(parent)
52 {
51 /* ack. lots of brackets here, but MUCH, MUCH MUCH better than what it used to be */ 53 /* ack. lots of brackets here, but MUCH, MUCH MUCH better than what it used to be */
52 setFixedSize(842, 613); 54 setFixedSize(842, 613);
53 setWindowTitle(tr("Anime Information")); 55 setWindowTitle(tr("Anime Information"));
54 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); 56 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
55 57
57 QPalette pal; 59 QPalette pal;
58 pal.setColor(QPalette::Window, pal.color(QPalette::Base)); 60 pal.setColor(QPalette::Window, pal.color(QPalette::Base));
59 setPalette(pal); 61 setPalette(pal);
60 } 62 }
61 63
62 QVBoxLayout* full_layout = new QVBoxLayout(this); 64 QVBoxLayout *full_layout = new QVBoxLayout(this);
63 65
64 { 66 {
65 /* this handles the actual page. */ 67 /* this handles the actual page. */
66 QWidget* widget = new QWidget(this); 68 QWidget *widget = new QWidget(this);
67 QHBoxLayout* layout = new QHBoxLayout(widget); 69 QHBoxLayout *layout = new QHBoxLayout(widget);
68 70
69 { 71 {
70 /* Sidebar */ 72 /* Sidebar */
71 QWidget* sidebar = new QWidget(widget); 73 QWidget *sidebar = new QWidget(widget);
72 QVBoxLayout* sidebar_layout = new QVBoxLayout(sidebar); 74 QVBoxLayout *sidebar_layout = new QVBoxLayout(sidebar);
73 { 75 {
74 /* Poster */ 76 /* Poster */
75 Poster* poster = new Poster(*anime, sidebar); 77 Poster *poster = new Poster(*anime, sidebar);
76 sidebar_layout->addWidget(poster); 78 sidebar_layout->addWidget(poster);
77 } 79 }
78 sidebar_layout->setContentsMargins(0, 0, 0, 0); 80 sidebar_layout->setContentsMargins(0, 0, 0, 0);
79 sidebar_layout->addStretch(); 81 sidebar_layout->addStretch();
80 layout->addWidget(sidebar); 82 layout->addWidget(sidebar);
81 } 83 }
82 84
83 { 85 {
84 /* ... everything else. */ 86 /* ... everything else. */
85 QWidget* main_widget = new QWidget(widget); 87 QWidget *main_widget = new QWidget(widget);
86 QVBoxLayout* main_layout = new QVBoxLayout(main_widget); 88 QVBoxLayout *main_layout = new QVBoxLayout(main_widget);
87 89
88 main_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 90 main_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
89 91
90 { 92 {
91 /* Anime title */ 93 /* Anime title */
92 TextWidgets::Title* anime_title = new TextWidgets::Title(main_widget); 94 TextWidgets::Title *anime_title = new TextWidgets::Title(main_widget);
93 anime_title->SetText(anime->GetUserPreferredTitle()); 95 anime_title->SetText(anime->GetUserPreferredTitle());
94 main_layout->addWidget(anime_title); 96 main_layout->addWidget(anime_title);
95 } 97 }
96 98
97 { 99 {
98 /* Tab widget, contains main info and settings */ 100 /* Tab widget, contains main info and settings */
99 QTabWidget* tabbed_widget = new QTabWidget(main_widget); 101 QTabWidget *tabbed_widget = new QTabWidget(main_widget);
100 tabbed_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 102 tabbed_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
101 103
102 { 104 {
103 /* Main information */ 105 /* Main information */
104 AnimeInfoWidget* main_information_widget = new AnimeInfoWidget(*anime, tabbed_widget); 106 AnimeInfoWidget *main_information_widget = new AnimeInfoWidget(*anime, tabbed_widget);
105 tabbed_widget->addTab(main_information_widget, tr("Main information")); 107 tabbed_widget->addTab(main_information_widget, tr("Main information"));
106 } 108 }
107 109
108 if (anime->IsInUserList()) { 110 if (anime->IsInUserList()) {
109 /* My list and settings */ 111 /* My list and settings */
110 QWidget* settings_widget = new QWidget(tabbed_widget); 112 QWidget *settings_widget = new QWidget(tabbed_widget);
111 settings_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); 113 settings_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
112 114
113 QVBoxLayout* settings_layout = new QVBoxLayout(settings_widget); 115 QVBoxLayout *settings_layout = new QVBoxLayout(settings_widget);
114 116
115 TextWidgets::Header* header = new TextWidgets::Header(settings_widget); 117 TextWidgets::Header *header = new TextWidgets::Header(settings_widget);
116 header->SetText(Strings::Translate("Anime list")); 118 header->SetText(Strings::Translate("Anime list"));
117 settings_layout->addWidget(header); 119 settings_layout->addWidget(header);
118 120
119 { 121 {
120 /* Anime List */ 122 /* Anime List */
121 QWidget* sg_anime_list_content = new QWidget(settings_widget); 123 QWidget *sg_anime_list_content = new QWidget(settings_widget);
122 124
123 constexpr int LAYOUT_HORIZ_SPACING = 25; 125 constexpr int LAYOUT_HORIZ_SPACING = 25;
124 constexpr int LAYOUT_VERT_SPACING = 5; 126 constexpr int LAYOUT_VERT_SPACING = 5;
125 constexpr int LAYOUT_ITEM_WIDTH = 175; 127 constexpr int LAYOUT_ITEM_WIDTH = 175;
126 128
127 QVBoxLayout* al_layout = new QVBoxLayout(sg_anime_list_content); 129 QVBoxLayout *al_layout = new QVBoxLayout(sg_anime_list_content);
128 al_layout->setSpacing(LAYOUT_VERT_SPACING); 130 al_layout->setSpacing(LAYOUT_VERT_SPACING);
129 al_layout->setContentsMargins(12, 0, 0, 0); 131 al_layout->setContentsMargins(12, 0, 0, 0);
130 132
131 /* Helper function for creating sections, reduces clutter. */ 133 /* Helper function for creating sections, reduces clutter. */
132 const auto CREATE_SECTION = [](QWidget* parent, std::function<void(QWidget*, QGridLayout*)> x) { 134 const auto CREATE_SECTION = [](QWidget *parent,
133 QWidget* section = new QWidget(parent); 135 std::function<void(QWidget *, QGridLayout *)> x) {
134 QGridLayout* layout = new QGridLayout(section); 136 QWidget *section = new QWidget(parent);
137 QGridLayout *layout = new QGridLayout(section);
135 layout->setHorizontalSpacing(LAYOUT_HORIZ_SPACING); 138 layout->setHorizontalSpacing(LAYOUT_HORIZ_SPACING);
136 layout->setVerticalSpacing(LAYOUT_VERT_SPACING); 139 layout->setVerticalSpacing(LAYOUT_VERT_SPACING);
137 layout->setContentsMargins(0, 0, 0, 0); 140 layout->setContentsMargins(0, 0, 0, 0);
138 x(section, layout); 141 x(section, layout);
139 parent->layout()->addWidget(section); 142 parent->layout()->addWidget(section);
140 }; 143 };
141 144
142 CREATE_SECTION(sg_anime_list_content, [this, &anime](QWidget* section, QGridLayout* layout) { 145 CREATE_SECTION(sg_anime_list_content, [this, &anime](QWidget *section, QGridLayout *layout) {
143 { 146 {
144 /* Episodes watched... */ 147 /* Episodes watched... */
145 layout->addWidget(new QLabel(tr("Episodes watched:"), section), 0, 0); 148 layout->addWidget(new QLabel(tr("Episodes watched:"), section), 0, 0);
146 149
147 QSpinBox* spin_box = new QSpinBox(section); 150 QSpinBox *spin_box = new QSpinBox(section);
148 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, 151 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this,
149 [this](int i) { _progress = i; }); 152 [this](int i) { _progress = i; });
150 spin_box->setRange(0, anime->GetEpisodes()); 153 spin_box->setRange(0, anime->GetEpisodes());
151 spin_box->setSingleStep(1); 154 spin_box->setSingleStep(1);
152 spin_box->setValue(_progress = anime->GetUserProgress()); 155 spin_box->setValue(_progress = anime->GetUserProgress());
153 spin_box->setFixedWidth(LAYOUT_ITEM_WIDTH); 156 spin_box->setFixedWidth(LAYOUT_ITEM_WIDTH);
154 layout->addWidget(spin_box, 1, 0); 157 layout->addWidget(spin_box, 1, 0);
155 } 158 }
156 159
157 { 160 {
158 /* Rewatching? */ 161 /* Rewatching? */
159 QCheckBox* checkbox = new QCheckBox(tr("Rewatching")); 162 QCheckBox *checkbox = new QCheckBox(tr("Rewatching"));
160 connect(checkbox, QOverload<int>::of(&QCheckBox::stateChanged), this, 163 connect(checkbox, QOverload<int>::of(&QCheckBox::stateChanged), this,
161 [this](int state) { _rewatching = (state == Qt::Checked); }); 164 [this](int state) { _rewatching = (state == Qt::Checked); });
162 checkbox->setCheckState((_rewatching = anime->GetUserIsRewatching()) ? Qt::Checked 165 checkbox->setCheckState((_rewatching = anime->GetUserIsRewatching()) ? Qt::Checked
163 : Qt::Unchecked); 166 : Qt::Unchecked);
164 checkbox->setFixedWidth(LAYOUT_ITEM_WIDTH); 167 checkbox->setFixedWidth(LAYOUT_ITEM_WIDTH);
165 layout->addWidget(checkbox, 1, 1); 168 layout->addWidget(checkbox, 1, 1);
166 } 169 }
167 layout->setColumnStretch(layout->columnCount(), 1); 170 layout->setColumnStretch(layout->columnCount(), 1);
168 }); 171 });
169 172
170 CREATE_SECTION(sg_anime_list_content, [this, &anime](QWidget* section, QGridLayout* layout) { 173 CREATE_SECTION(sg_anime_list_content, [this, &anime](QWidget *section, QGridLayout *layout) {
171 { 174 {
172 /* Status */ 175 /* Status */
173 layout->addWidget(new QLabel(tr("Status:"), section), 0, 0); 176 layout->addWidget(new QLabel(tr("Status:"), section), 0, 0);
174 177
175 QComboBox* combo_box = new QComboBox(section); 178 QComboBox *combo_box = new QComboBox(section);
176 179
177 _status = anime->GetUserStatus(); 180 _status = anime->GetUserStatus();
178 for (unsigned int i = 0; i < Anime::ListStatuses.size(); i++) { 181 for (unsigned int i = 0; i < Anime::ListStatuses.size(); i++) {
179 combo_box->addItem(Strings::ToQString(Translate::ToLocalString(Anime::ListStatuses[i])), 182 combo_box->addItem(
180 static_cast<int>(Anime::ListStatuses[i])); 183 Strings::ToQString(Translate::ToLocalString(Anime::ListStatuses[i])),
184 static_cast<int>(Anime::ListStatuses[i]));
181 if (Anime::ListStatuses[i] == _status) 185 if (Anime::ListStatuses[i] == _status)
182 combo_box->setCurrentIndex(i); 186 combo_box->setCurrentIndex(i);
183 } 187 }
184 188
185 connect(combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, 189 connect(combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
186 [this, combo_box](int) { 190 [this, combo_box](int) {
187 _status = static_cast<Anime::ListStatus>(combo_box->currentData().toInt()); 191 _status = static_cast<Anime::ListStatus>(combo_box->currentData().toInt());
188 }); 192 });
189 193
190 /* this should NEVER, EVER, be NOT_IN_LIST */ 194 /* this should NEVER, EVER, be NOT_IN_LIST */
191 combo_box->setFixedWidth(LAYOUT_ITEM_WIDTH); 195 combo_box->setFixedWidth(LAYOUT_ITEM_WIDTH);
192 layout->addWidget(combo_box, 1, 0); 196 layout->addWidget(combo_box, 1, 0);
193 } 197 }
194 198
195 { 199 {
196 /* Score */ 200 /* Score */
197 layout->addWidget(new QLabel(tr("Score:"), section), 0, 1); 201 layout->addWidget(new QLabel(tr("Score:"), section), 0, 1);
198 202
199 QSpinBox* spin_box = new QSpinBox(section); 203 QSpinBox *spin_box = new QSpinBox(section);
200 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, 204 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this,
201 [this](int i) { _score = i; }); 205 [this](int i) { _score = i; });
202 spin_box->setRange(0, 100); 206 spin_box->setRange(0, 100);
203 spin_box->setSingleStep(5); 207 spin_box->setSingleStep(5);
204 spin_box->setValue(_score = anime->GetUserScore()); 208 spin_box->setValue(_score = anime->GetUserScore());
205 spin_box->setFixedWidth(LAYOUT_ITEM_WIDTH); 209 spin_box->setFixedWidth(LAYOUT_ITEM_WIDTH);
206 layout->addWidget(spin_box, 1, 1); 210 layout->addWidget(spin_box, 1, 1);
207 } 211 }
208 layout->setColumnStretch(layout->columnCount(), 1); 212 layout->setColumnStretch(layout->columnCount(), 1);
209 }); 213 });
210 214
211 CREATE_SECTION(sg_anime_list_content, [this, &anime](QWidget* section, QGridLayout* layout) { 215 CREATE_SECTION(sg_anime_list_content, [this, &anime](QWidget *section, QGridLayout *layout) {
212 layout->addWidget(new QLabel(tr("Notes:"), section), 0, 0); 216 layout->addWidget(new QLabel(tr("Notes:"), section), 0, 0);
213 217
214 QLineEdit* line_edit = new QLineEdit(section); 218 QLineEdit *line_edit = new QLineEdit(section);
215 connect(line_edit, &QLineEdit::textChanged, this, [this](const QString& text) { 219 connect(line_edit, &QLineEdit::textChanged, this, [this](const QString &text) {
216 /* this sucks but I don't really want to implement anything smarter :) */ 220 /* this sucks but I don't really want to implement anything smarter :) */
217 _notes = Strings::ToUtf8String(text); 221 _notes = Strings::ToUtf8String(text);
218 }); 222 });
219 line_edit->setText(Strings::ToQString(_notes = anime->GetUserNotes())); 223 line_edit->setText(Strings::ToQString(_notes = anime->GetUserNotes()));
220 line_edit->setPlaceholderText(tr("Enter your notes about this anime")); 224 line_edit->setPlaceholderText(tr("Enter your notes about this anime"));
221 layout->addWidget(line_edit, 1, 0); 225 layout->addWidget(line_edit, 1, 0);
222 }); 226 });
223 227
224 CREATE_SECTION(sg_anime_list_content, [this, &anime](QWidget* section, QGridLayout* layout) { 228 CREATE_SECTION(sg_anime_list_content, [this, &anime](QWidget *section, QGridLayout *layout) {
225 /* Started */ 229 /* Started */
226 { 230 {
227 layout->addWidget(new QLabel(tr("Date started:"), section), 0, 0); 231 layout->addWidget(new QLabel(tr("Date started:"), section), 0, 0);
228 232
229 OptionalDate* date = new OptionalDate(true, section); 233 OptionalDate *date = new OptionalDate(true, section);
230 connect(date, &OptionalDate::DataChanged, this, 234 connect(date, &OptionalDate::DataChanged, this,
231 [this](bool enabled, Date date) { _started = enabled ? date : Date(); }); 235 [this](bool enabled, Date date) { _started = enabled ? date : Date(); });
232 date->setFixedWidth(LAYOUT_ITEM_WIDTH); 236 date->setFixedWidth(LAYOUT_ITEM_WIDTH);
233 _started = anime->GetUserDateStarted(); 237 _started = anime->GetUserDateStarted();
234 if (!_started.IsValid()) { 238 if (!_started.IsValid()) {
235 date->SetEnabled(false); 239 date->SetEnabled(false);
236 _started = anime->GetStartedDate(); 240 _started = anime->GetStartedDate();
241 245
242 /* Completed */ 246 /* Completed */
243 { 247 {
244 layout->addWidget(new QLabel(tr("Date completed:"), section), 0, 1); 248 layout->addWidget(new QLabel(tr("Date completed:"), section), 0, 1);
245 249
246 OptionalDate* date = new OptionalDate(true, section); 250 OptionalDate *date = new OptionalDate(true, section);
247 connect(date, &OptionalDate::DataChanged, this, 251 connect(date, &OptionalDate::DataChanged, this,
248 [this](bool enabled, Date date) { _completed = enabled ? date : Date(); }); 252 [this](bool enabled, Date date) { _completed = enabled ? date : Date(); });
249 date->setFixedWidth(LAYOUT_ITEM_WIDTH); 253 date->setFixedWidth(LAYOUT_ITEM_WIDTH);
250 _completed = anime->GetUserDateCompleted(); 254 _completed = anime->GetUserDateCompleted();
251 if (!_completed.IsValid()) { 255 if (!_completed.IsValid()) {
252 date->SetEnabled(false); 256 date->SetEnabled(false);
253 _completed = anime->GetCompletedDate(); 257 _completed = anime->GetCompletedDate();
261 settings_layout->addWidget(sg_anime_list_content); 265 settings_layout->addWidget(sg_anime_list_content);
262 } 266 }
263 267
264 /* 268 /*
265 { 269 {
266 // commenting this out until it actually gets implemented :) 270 // commenting this out until it actually gets implemented :)
267 271
268 settings_layout->addWidget(new TextWidgets::Header(tr("Local settings"), settings_widget)); 272 settings_layout->addWidget(new TextWidgets::Header(tr("Local settings"), settings_widget));
269 273
270 QWidget* sg_local_content = new QWidget(settings_widget); 274 QWidget* sg_local_content = new QWidget(settings_widget);
271 QVBoxLayout* sg_local_layout = new QVBoxLayout(sg_local_content); 275 QVBoxLayout* sg_local_layout = new QVBoxLayout(sg_local_content);
272 sg_local_layout->setSpacing(5); 276 sg_local_layout->setSpacing(5);
273 sg_local_layout->setContentsMargins(12, 0, 0, 0); 277 sg_local_layout->setContentsMargins(12, 0, 0, 0);
274 278
275 CREATE_SECTION(sg_local_content, [this, &anime](QWidget* section, QGridLayout* layout){ 279 CREATE_SECTION(sg_local_content, [this, &anime](QWidget* section, QGridLayout* layout){
276 layout->addWidget(new QLabel(tr("Alternative titles:"), section), 0, 0); 280 layout->addWidget(new QLabel(tr("Alternative titles:"), section), 0, 0);
277 281
278 QLineEdit* line_edit = new QLineEdit("", section); 282 QLineEdit* line_edit = new QLineEdit("", section);
279 line_edit->setPlaceholderText( 283 line_edit->setPlaceholderText(
280 tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)")); 284 tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)"));
281 layout->addWidget(line_edit, 1, 0); 285 layout->addWidget(line_edit, 1, 0);
282 286
283 QCheckBox* checkbox = new QCheckBox(tr("Use the first alternative title to search for 287 QCheckBox* checkbox = new QCheckBox(tr("Use the first alternative title to search for
284 torrents")); layout->addWidget(checkbox, 2, 0); 288 torrents")); layout->addWidget(checkbox, 2, 0);
285 }); 289 });
286 290
287 settings_layout->addWidget(sg_local_content); 291 settings_layout->addWidget(sg_local_content);
288 } 292 }
289 */ 293 */
290 294
291 settings_layout->addStretch(); 295 settings_layout->addStretch();
292 296
305 full_layout->addWidget(widget); 309 full_layout->addWidget(widget);
306 } 310 }
307 311
308 { 312 {
309 /* Dialog box buttons */ 313 /* Dialog box buttons */
310 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 314 QDialogButtonBox *button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
311 connect(button_box, &QDialogButtonBox::accepted, this, [this, accept, anime] { 315 connect(button_box, &QDialogButtonBox::accepted, this, [this, accept, anime] {
312 SaveData(anime); 316 SaveData(anime);
313 accept(anime); 317 accept(anime);
314 QDialog::accept(); 318 QDialog::accept();
315 }); 319 });