Mercurial > minori
annotate src/gui/dialog/information.cc @ 327:b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
ToLocalString has also been altered to take in both season
and year because lots of locales actually treat formatting
seasons differently! most notably is Russian which adds a
suffix at the end to notate seasons(??)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Thu, 13 Jun 2024 01:49:18 -0400 |
parents | 5d3c9b31aa6e |
children | 6b0768158dcd |
rev | line source |
---|---|
9 | 1 #include "gui/dialog/information.h" |
2 #include "core/anime.h" | |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
3 #include "core/anime_db.h" |
258 | 4 #include "core/session.h" |
9 | 5 #include "core/strings.h" |
6 #include "gui/pages/anime_list.h" | |
7 #include "gui/translate/anime.h" | |
64 | 8 #include "gui/widgets/anime_info.h" |
76 | 9 #include "gui/widgets/optional_date.h" |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
65
diff
changeset
|
10 #include "gui/widgets/poster.h" |
46 | 11 #include "gui/widgets/text.h" |
9 | 12 #include "gui/window.h" |
258 | 13 |
46 | 14 #include <QCheckBox> |
15 #include <QComboBox> | |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
16 #include <QDateEdit> |
9 | 17 #include <QDebug> |
18 #include <QDialogButtonBox> | |
76 | 19 #include <QLabel> |
46 | 20 #include <QLineEdit> |
9 | 21 #include <QPlainTextEdit> |
46 | 22 #include <QSpinBox> |
23 #include <QStringList> | |
9 | 24 #include <QTextStream> |
25 #include <QVBoxLayout> | |
258 | 26 |
9 | 27 #include <functional> |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
28 #include <iostream> |
108 | 29 #ifdef WIN32 |
258 | 30 # include "sys/win32/dark_theme.h" |
108 | 31 #endif |
9 | 32 |
46 | 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. */ | |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
35 void InformationDialog::SaveData(Anime::Anime* anime) { |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
36 if (!anime->IsInUserList()) |
250 | 37 return; |
38 | |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
39 anime->SetUserProgress(_progress); |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
40 anime->SetUserScore(_score); |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
41 anime->SetUserIsRewatching(_rewatching); |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
42 anime->SetUserStatus(_status); |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
43 anime->SetUserNotes(_notes); |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
44 anime->SetUserDateStarted(_started); |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
45 anime->SetUserDateCompleted(_completed); |
47
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
46 } |
d8eb763e6661
information.cpp: add widgets to the list tab, and add an
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
47 |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
48 InformationDialog::InformationDialog(Anime::Anime* anime, std::function<void(Anime::Anime*)> accept, enum Pages page, |
258 | 49 QWidget* parent) |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
50 : QDialog(parent) { |
258 | 51 /* ack. lots of brackets here, but MUCH, MUCH MUCH better than what it used to be */ |
9 | 52 setFixedSize(842, 613); |
53 setWindowTitle(tr("Anime Information")); | |
54 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); | |
36 | 55 |
56 { | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
89
diff
changeset
|
57 QPalette pal; |
69 | 58 pal.setColor(QPalette::Window, pal.color(QPalette::Base)); |
36 | 59 setPalette(pal); |
60 } | |
9 | 61 |
108 | 62 QVBoxLayout* full_layout = new QVBoxLayout(this); |
63 | |
64 { | |
65 /* this handles the actual page. */ | |
66 QWidget* widget = new QWidget(this); | |
67 QHBoxLayout* layout = new QHBoxLayout(widget); | |
68 | |
69 { | |
70 /* Sidebar */ | |
71 QWidget* sidebar = new QWidget(widget); | |
72 QVBoxLayout* sidebar_layout = new QVBoxLayout(sidebar); | |
73 { | |
74 /* Poster */ | |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
75 Poster* poster = new Poster(*anime, sidebar); |
108 | 76 sidebar_layout->addWidget(poster); |
77 } | |
78 sidebar_layout->setContentsMargins(0, 0, 0, 0); | |
79 sidebar_layout->addStretch(); | |
80 layout->addWidget(sidebar); | |
81 } | |
82 | |
83 { | |
84 /* ... everything else. */ | |
85 QWidget* main_widget = new QWidget(widget); | |
86 QVBoxLayout* main_layout = new QVBoxLayout(main_widget); | |
87 | |
88 main_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
9 | 89 |
108 | 90 { |
91 /* Anime title */ | |
92 TextWidgets::Title* anime_title = | |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
93 new TextWidgets::Title(Strings::ToQString(anime->GetUserPreferredTitle()), main_widget); |
108 | 94 main_layout->addWidget(anime_title); |
95 } | |
96 | |
97 { | |
98 /* Tab widget, contains main info and settings */ | |
99 QTabWidget* tabbed_widget = new QTabWidget(main_widget); | |
253 | 100 tabbed_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
9 | 101 |
108 | 102 { |
103 /* Main information */ | |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
104 AnimeInfoWidget* main_information_widget = new AnimeInfoWidget(*anime, tabbed_widget); |
108 | 105 tabbed_widget->addTab(main_information_widget, tr("Main information")); |
106 } | |
36 | 107 |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
108 if (anime->IsInUserList()) { |
108 | 109 /* My list and settings */ |
110 QWidget* settings_widget = new QWidget(tabbed_widget); | |
111 settings_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); | |
9 | 112 |
108 | 113 QVBoxLayout* settings_layout = new QVBoxLayout(settings_widget); |
114 settings_layout->addWidget(new TextWidgets::Header(tr("Anime list"), settings_widget)); | |
115 | |
116 { | |
117 /* Anime List */ | |
118 QWidget* sg_anime_list_content = new QWidget(settings_widget); | |
9 | 119 |
108 | 120 constexpr int LAYOUT_HORIZ_SPACING = 25; |
258 | 121 constexpr int LAYOUT_VERT_SPACING = 5; |
122 constexpr int LAYOUT_ITEM_WIDTH = 175; | |
108 | 123 |
124 QVBoxLayout* al_layout = new QVBoxLayout(sg_anime_list_content); | |
125 al_layout->setSpacing(LAYOUT_VERT_SPACING); | |
126 al_layout->setContentsMargins(12, 0, 0, 0); | |
9 | 127 |
108 | 128 /* Helper function for creating sections, reduces clutter. */ |
129 const auto CREATE_SECTION = [](QWidget* parent, std::function<void(QWidget*, QGridLayout*)> x) { | |
130 QWidget* section = new QWidget(parent); | |
131 QGridLayout* layout = new QGridLayout(section); | |
132 layout->setHorizontalSpacing(LAYOUT_HORIZ_SPACING); | |
133 layout->setVerticalSpacing(LAYOUT_VERT_SPACING); | |
134 layout->setContentsMargins(0, 0, 0, 0); | |
135 x(section, layout); | |
136 parent->layout()->addWidget(section); | |
137 }; | |
9 | 138 |
258 | 139 CREATE_SECTION(sg_anime_list_content, [this, &anime](QWidget* section, QGridLayout* layout) { |
108 | 140 { |
141 /* Episodes watched... */ | |
142 layout->addWidget(new QLabel(tr("Episodes watched:"), section), 0, 0); | |
46 | 143 |
108 | 144 QSpinBox* spin_box = new QSpinBox(section); |
258 | 145 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, |
146 [this](int i) { _progress = i; }); | |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
147 spin_box->setRange(0, anime->GetEpisodes()); |
108 | 148 spin_box->setSingleStep(1); |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
149 spin_box->setValue(_progress = anime->GetUserProgress()); |
108 | 150 spin_box->setFixedWidth(LAYOUT_ITEM_WIDTH); |
151 layout->addWidget(spin_box, 1, 0); | |
152 } | |
46 | 153 |
108 | 154 { |
155 /* Rewatching? */ | |
156 QCheckBox* checkbox = new QCheckBox(tr("Rewatching")); | |
157 connect(checkbox, QOverload<int>::of(&QCheckBox::stateChanged), this, | |
158 [this](int state) { _rewatching = (state == Qt::Checked); }); | |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
159 checkbox->setCheckState((_rewatching = anime->GetUserIsRewatching()) ? Qt::Checked |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
160 : Qt::Unchecked); |
108 | 161 checkbox->setFixedWidth(LAYOUT_ITEM_WIDTH); |
162 layout->addWidget(checkbox, 1, 1); | |
163 } | |
164 layout->setColumnStretch(layout->columnCount(), 1); | |
165 }); | |
88
1b19d80b3f8c
dialog/information.cc: fix QGridLayout :)
Paper <mrpapersonic@gmail.com>
parents:
87
diff
changeset
|
166 |
258 | 167 CREATE_SECTION(sg_anime_list_content, [this, &anime](QWidget* section, QGridLayout* layout) { |
108 | 168 { |
169 /* Status */ | |
170 layout->addWidget(new QLabel(tr("Status:"), section), 0, 0); | |
171 | |
172 QComboBox* combo_box = new QComboBox(section); | |
173 | |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
174 _status = anime->GetUserStatus(); |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
175 for (unsigned int i = 0; i < Anime::ListStatuses.size(); i++) { |
291 | 176 combo_box->addItem(Strings::ToQString(Translate::ToLocalString(Anime::ListStatuses[i])), |
258 | 177 static_cast<int>(Anime::ListStatuses[i])); |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
178 if (Anime::ListStatuses[i] == _status) |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
179 combo_box->setCurrentIndex(i); |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
180 } |
108 | 181 |
258 | 182 connect(combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, |
183 [this, combo_box](int) { | |
184 _status = static_cast<Anime::ListStatus>(combo_box->currentData().toInt()); | |
185 }); | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
186 |
108 | 187 /* this should NEVER, EVER, be NOT_IN_LIST */ |
188 combo_box->setFixedWidth(LAYOUT_ITEM_WIDTH); | |
189 layout->addWidget(combo_box, 1, 0); | |
190 } | |
191 | |
192 { | |
193 /* Score */ | |
194 layout->addWidget(new QLabel(tr("Score:"), section), 0, 1); | |
195 | |
196 QSpinBox* spin_box = new QSpinBox(section); | |
258 | 197 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, |
198 [this](int i) { _score = i; }); | |
108 | 199 spin_box->setRange(0, 100); |
200 spin_box->setSingleStep(5); | |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
201 spin_box->setValue(_score = anime->GetUserScore()); |
108 | 202 spin_box->setFixedWidth(LAYOUT_ITEM_WIDTH); |
203 layout->addWidget(spin_box, 1, 1); | |
204 } | |
205 layout->setColumnStretch(layout->columnCount(), 1); | |
206 }); | |
207 | |
258 | 208 CREATE_SECTION(sg_anime_list_content, [this, &anime](QWidget* section, QGridLayout* layout) { |
108 | 209 layout->addWidget(new QLabel(tr("Notes:"), section), 0, 0); |
64 | 210 |
108 | 211 QLineEdit* line_edit = new QLineEdit(section); |
212 connect(line_edit, &QLineEdit::textChanged, this, [this](const QString& text) { | |
213 /* this sucks but I don't really want to implement anything smarter :) */ | |
214 _notes = Strings::ToUtf8String(text); | |
215 }); | |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
216 line_edit->setText(Strings::ToQString(_notes = anime->GetUserNotes())); |
108 | 217 line_edit->setPlaceholderText(tr("Enter your notes about this anime")); |
218 layout->addWidget(line_edit, 1, 0); | |
219 }); | |
220 | |
258 | 221 CREATE_SECTION(sg_anime_list_content, [this, &anime](QWidget* section, QGridLayout* layout) { |
108 | 222 /* Started */ |
223 { | |
224 layout->addWidget(new QLabel(tr("Date started:"), section), 0, 0); | |
46 | 225 |
108 | 226 OptionalDate* date = new OptionalDate(true, section); |
227 connect(date, &OptionalDate::DataChanged, this, | |
228 [this](bool enabled, Date date) { _started = enabled ? date : Date(); }); | |
229 date->setFixedWidth(LAYOUT_ITEM_WIDTH); | |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
230 _started = anime->GetUserDateStarted(); |
108 | 231 if (!_started.IsValid()) { |
232 date->SetEnabled(false); | |
324
5d3c9b31aa6e
anime: add completed date member
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
233 _started = anime->GetStartedDate(); |
108 | 234 } |
235 date->SetDate(_started); | |
236 layout->addWidget(date, 1, 0); | |
237 } | |
238 | |
239 /* Completed */ | |
240 { | |
241 layout->addWidget(new QLabel(tr("Date completed:"), section), 0, 1); | |
46 | 242 |
108 | 243 OptionalDate* date = new OptionalDate(true, section); |
244 connect(date, &OptionalDate::DataChanged, this, | |
245 [this](bool enabled, Date date) { _completed = enabled ? date : Date(); }); | |
246 date->setFixedWidth(LAYOUT_ITEM_WIDTH); | |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
247 _completed = anime->GetUserDateCompleted(); |
108 | 248 if (!_completed.IsValid()) { |
249 date->SetEnabled(false); | |
324
5d3c9b31aa6e
anime: add completed date member
Paper <paper@paper.us.eu.org>
parents:
305
diff
changeset
|
250 _completed = anime->GetCompletedDate(); |
108 | 251 } |
252 date->SetDate(_completed); | |
253 layout->addWidget(date, 1, 1); | |
254 } | |
255 layout->setColumnStretch(layout->columnCount(), 1); | |
256 }); | |
88
1b19d80b3f8c
dialog/information.cc: fix QGridLayout :)
Paper <mrpapersonic@gmail.com>
parents:
87
diff
changeset
|
257 |
108 | 258 settings_layout->addWidget(sg_anime_list_content); |
259 } | |
260 | |
261 /* | |
262 { | |
258 | 263 // commenting this out until it actually gets implemented :) |
46 | 264 |
258 | 265 settings_layout->addWidget(new TextWidgets::Header(tr("Local settings"), settings_widget)); |
108 | 266 |
258 | 267 QWidget* sg_local_content = new QWidget(settings_widget); |
268 QVBoxLayout* sg_local_layout = new QVBoxLayout(sg_local_content); | |
269 sg_local_layout->setSpacing(5); | |
270 sg_local_layout->setContentsMargins(12, 0, 0, 0); | |
108 | 271 |
258 | 272 CREATE_SECTION(sg_local_content, [this, &anime](QWidget* section, QGridLayout* layout){ |
273 layout->addWidget(new QLabel(tr("Alternative titles:"), section), 0, 0); | |
89
e6fab256ddc4
dialog/info: make some stuff more sane
Paper <mrpapersonic@gmail.com>
parents:
88
diff
changeset
|
274 |
258 | 275 QLineEdit* line_edit = new QLineEdit("", section); |
276 line_edit->setPlaceholderText( | |
277 tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)")); | |
278 layout->addWidget(line_edit, 1, 0); | |
108 | 279 |
258 | 280 QCheckBox* checkbox = new QCheckBox(tr("Use the first alternative title to search for |
281 torrents")); layout->addWidget(checkbox, 2, 0); | |
282 }); | |
108 | 283 |
258 | 284 settings_layout->addWidget(sg_local_content); |
108 | 285 } |
286 */ | |
287 | |
288 settings_layout->addStretch(); | |
46 | 289 |
108 | 290 tabbed_widget->addTab(settings_widget, tr("My list and settings")); |
291 } | |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
292 tabbed_widget->setCurrentIndex(static_cast<int>(page)); |
108 | 293 main_layout->addWidget(tabbed_widget); |
294 main_layout->setContentsMargins(0, 0, 0, 0); | |
295 main_layout->setSpacing(12); | |
296 } | |
89
e6fab256ddc4
dialog/info: make some stuff more sane
Paper <mrpapersonic@gmail.com>
parents:
88
diff
changeset
|
297 |
108 | 298 layout->addWidget(main_widget); |
299 } | |
300 layout->setSpacing(12); | |
294 | 301 layout->setContentsMargins(0, 0, 0, 0); |
108 | 302 full_layout->addWidget(widget); |
303 } | |
46 | 304 |
108 | 305 { |
306 /* Dialog box buttons */ | |
307 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); | |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
308 connect(button_box, &QDialogButtonBox::accepted, this, [this, accept, anime] { |
108 | 309 SaveData(anime); |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
294
diff
changeset
|
310 accept(anime); |
108 | 311 QDialog::accept(); |
89
e6fab256ddc4
dialog/info: make some stuff more sane
Paper <mrpapersonic@gmail.com>
parents:
88
diff
changeset
|
312 }); |
108 | 313 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); |
314 full_layout->addWidget(button_box, 0, Qt::AlignBottom); | |
315 } | |
316 } | |
46 | 317 |
108 | 318 void InformationDialog::showEvent(QShowEvent* event) { |
319 QDialog::showEvent(event); | |
320 #ifdef WIN32 | |
321 win32::SetTitleBarsToBlack(session.config.theme.IsInDarkTheme()); | |
322 #endif | |
9 | 323 } |