Mercurial > minori
comparison src/gui/dialog/information.cc @ 81:9b2b41f83a5e
boring: mass rename to cc
because this is a very unix-y project, it makes more sense to use the
'cc' extension
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 23 Oct 2023 12:07:27 -0400 |
parents | src/gui/dialog/information.cpp@6f7385bd334c |
children | d02fdf1d6708 |
comparison
equal
deleted
inserted
replaced
80:825506f0e221 | 81:9b2b41f83a5e |
---|---|
1 #include "gui/dialog/information.h" | |
2 #include "core/anime.h" | |
3 #include "core/anime_db.h" | |
4 #include "core/array.h" | |
5 #include "core/strings.h" | |
6 #include "gui/pages/anime_list.h" | |
7 #include "gui/translate/anime.h" | |
8 #include "gui/widgets/anime_info.h" | |
9 #include "gui/widgets/optional_date.h" | |
10 #include "gui/widgets/poster.h" | |
11 #include "gui/widgets/text.h" | |
12 #include "gui/window.h" | |
13 #include <QCheckBox> | |
14 #include <QComboBox> | |
15 #include <QDateEdit> | |
16 #include <QDebug> | |
17 #include <QDialogButtonBox> | |
18 #include <QLabel> | |
19 #include <QLineEdit> | |
20 #include <QPlainTextEdit> | |
21 #include <QSpinBox> | |
22 #include <QStringList> | |
23 #include <QTextStream> | |
24 #include <QVBoxLayout> | |
25 #include <functional> | |
26 | |
27 /* TODO: Taiga disables rendering of the tab widget entirely when the anime is not part of a list, | |
28 which sucks. Think of a better way to implement this later. */ | |
29 void InformationDialog::SaveData() { | |
30 Anime::Anime& anime = Anime::db.items[id]; | |
31 anime.SetUserProgress(progress); | |
32 anime.SetUserScore(score); | |
33 anime.SetUserIsRewatching(rewatching); | |
34 anime.SetUserStatus(status); | |
35 anime.SetUserNotes(notes); | |
36 anime.SetUserDateStarted(started); | |
37 anime.SetUserDateCompleted(completed); | |
38 } | |
39 | |
40 InformationDialog::InformationDialog(const Anime::Anime& anime, std::function<void()> accept, QWidget* parent) | |
41 : QDialog(parent) { | |
42 setFixedSize(842, 613); | |
43 setWindowTitle(tr("Anime Information")); | |
44 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); | |
45 | |
46 { | |
47 QPalette pal(palette()); | |
48 pal.setColor(QPalette::Window, pal.color(QPalette::Base)); | |
49 setPalette(pal); | |
50 } | |
51 | |
52 QWidget* widget = new QWidget(this); | |
53 | |
54 /* "sidebar", includes... just the anime image :) */ | |
55 QWidget* sidebar = new QWidget(widget); | |
56 QVBoxLayout* sidebar_layout = new QVBoxLayout(sidebar); | |
57 Poster* poster = new Poster(anime.GetId(), sidebar); | |
58 sidebar_layout->addWidget(poster); | |
59 sidebar_layout->setContentsMargins(0, 0, 0, 0); | |
60 sidebar_layout->addStretch(); | |
61 | |
62 /* main widget */ | |
63 QWidget* main_widget = new QWidget(widget); | |
64 | |
65 main_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
66 | |
67 id = anime.GetId(); | |
68 /* anime title header text */ | |
69 TextWidgets::Title* anime_title = | |
70 new TextWidgets::Title(Strings::ToQString(anime.GetUserPreferredTitle()), main_widget); | |
71 | |
72 /* tabbed widget */ | |
73 QTabWidget* tabbed_widget = new QTabWidget(main_widget); | |
74 tabbed_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | |
75 | |
76 /* main info tab */ | |
77 AnimeInfoWidget* main_information_widget = new AnimeInfoWidget(anime, tabbed_widget); | |
78 | |
79 { | |
80 QPalette pal(main_information_widget->palette()); | |
81 pal.setColor(QPalette::Base, pal.color(QPalette::Window)); | |
82 main_information_widget->setPalette(pal); | |
83 } | |
84 | |
85 QWidget* settings_widget = new QWidget(tabbed_widget); | |
86 settings_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); | |
87 | |
88 QVBoxLayout* settings_layout = new QVBoxLayout(settings_widget); | |
89 settings_layout->addWidget(new TextWidgets::Header(tr("Anime list"), settings_widget)); | |
90 | |
91 QWidget* sg_anime_list_content = new QWidget(settings_widget); | |
92 | |
93 QVBoxLayout* al_layout = new QVBoxLayout(sg_anime_list_content); | |
94 al_layout->setSpacing(5); | |
95 al_layout->setContentsMargins(12, 0, 0, 0); | |
96 | |
97 #define LAYOUT_HORIZ_SPACING 25 | |
98 #define LAYOUT_VERT_SPACING 5 | |
99 #define LAYOUT_ITEM_WIDTH 175 | |
100 /* Creates a subsection that takes up whatever space is necessary */ | |
101 #define CREATE_FULL_WIDTH_SUBSECTION(x) \ | |
102 { \ | |
103 QWidget* subsection = new QWidget(section); \ | |
104 subsection->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); \ | |
105 QVBoxLayout* subsection_layout = new QVBoxLayout(subsection); \ | |
106 subsection_layout->setSpacing(LAYOUT_VERT_SPACING); \ | |
107 subsection_layout->setContentsMargins(0, 0, 0, 0); \ | |
108 x; \ | |
109 layout->addWidget(subsection, 0, Qt::AlignBottom); \ | |
110 } | |
111 | |
112 /* Creates a section in the parent `a` */ | |
113 #define CREATE_FULL_WIDTH_SECTION(a, x) \ | |
114 { \ | |
115 QWidget* section = new QWidget(a); \ | |
116 QHBoxLayout* layout = new QHBoxLayout(section); \ | |
117 layout->setSpacing(LAYOUT_HORIZ_SPACING); \ | |
118 layout->setContentsMargins(0, 0, 0, 0); \ | |
119 x; \ | |
120 a->layout()->addWidget(section); \ | |
121 } | |
122 | |
123 /* Creates a subsection with a width of 175 */ | |
124 #define CREATE_SUBSECTION(x) CREATE_FULL_WIDTH_SUBSECTION(x subsection->setFixedWidth(LAYOUT_ITEM_WIDTH);) | |
125 /* Creates a section in the parent `a` */ | |
126 #define CREATE_SECTION(a, x) CREATE_FULL_WIDTH_SECTION(a, x layout->addStretch();) | |
127 | |
128 CREATE_SECTION(sg_anime_list_content, { | |
129 /* Episodes watched section */ | |
130 CREATE_SUBSECTION({ | |
131 subsection_layout->addWidget(new QLabel(tr("Episodes watched:"), subsection)); | |
132 | |
133 QSpinBox* spin_box = new QSpinBox(subsection); | |
134 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) { progress = i; }); | |
135 spin_box->setRange(0, anime.GetEpisodes()); | |
136 spin_box->setSingleStep(1); | |
137 spin_box->setValue(progress = anime.GetUserProgress()); | |
138 subsection_layout->addWidget(spin_box); | |
139 }); | |
140 CREATE_SUBSECTION({ | |
141 subsection_layout->addWidget(new QLabel(tr(" "), subsection)); | |
142 | |
143 QCheckBox* checkbox = new QCheckBox(tr("Rewatching")); | |
144 connect(checkbox, QOverload<int>::of(&QCheckBox::stateChanged), this, | |
145 [this](int state) { rewatching = (state == Qt::Checked); }); | |
146 checkbox->setCheckState(anime.GetUserIsRewatching() ? Qt::Checked : Qt::Unchecked); | |
147 subsection_layout->addWidget(checkbox); | |
148 }); | |
149 }); | |
150 CREATE_SECTION(sg_anime_list_content, { | |
151 /* Status & score section */ | |
152 CREATE_SUBSECTION({ | |
153 subsection_layout->addWidget(new QLabel(tr("Status:"), subsection)); | |
154 | |
155 QStringList string_list; | |
156 for (unsigned int i = 0; i < ARRAYSIZE(Anime::ListStatuses); i++) | |
157 string_list.append(Strings::ToQString(Translate::ToString(Anime::ListStatuses[i]))); | |
158 | |
159 QComboBox* combo_box = new QComboBox(subsection); | |
160 combo_box->addItems(string_list); | |
161 connect(combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | |
162 [this](int i) { status = Anime::ListStatuses[i]; }); | |
163 combo_box->setCurrentIndex(static_cast<int>(status = anime.GetUserStatus()) - 1); | |
164 subsection_layout->addWidget(combo_box); | |
165 }); | |
166 CREATE_SUBSECTION({ | |
167 subsection_layout->addWidget(new QLabel(tr("Score:"), subsection)); | |
168 | |
169 QSpinBox* spin_box = new QSpinBox(subsection); | |
170 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) { score = i; }); | |
171 spin_box->setRange(0, 100); | |
172 spin_box->setSingleStep(5); | |
173 spin_box->setValue(score = anime.GetUserScore()); | |
174 subsection_layout->addWidget(spin_box); | |
175 }); | |
176 }); | |
177 CREATE_FULL_WIDTH_SECTION(sg_anime_list_content, { | |
178 /* Notes section */ | |
179 CREATE_FULL_WIDTH_SUBSECTION({ | |
180 subsection_layout->addWidget(new QLabel(tr("Notes:"), subsection)); | |
181 | |
182 QLineEdit* line_edit = new QLineEdit(subsection); | |
183 connect(line_edit, &QLineEdit::textChanged, this, [this](const QString& text) { | |
184 /* this sucks but I don't really want to implement anything smarter :) */ | |
185 notes = Strings::ToUtf8String(text); | |
186 }); | |
187 line_edit->setText(Strings::ToQString(notes = anime.GetUserNotes())); | |
188 line_edit->setPlaceholderText(tr("Enter your notes about this anime")); | |
189 subsection_layout->addWidget(line_edit); | |
190 }); | |
191 }); | |
192 CREATE_SECTION(sg_anime_list_content, { | |
193 /* Dates section */ | |
194 CREATE_SUBSECTION({ | |
195 subsection_layout->addWidget(new QLabel(tr("Date started:"), subsection)); | |
196 | |
197 OptionalDate* date = new OptionalDate(true, subsection); | |
198 connect(date, &OptionalDate::DataChanged, this, | |
199 [this](bool enabled, Date date) { started = (enabled) ? date : Date(); }); | |
200 started = anime.GetUserDateStarted(); | |
201 if (!started.IsValid()) { | |
202 date->SetEnabled(false); | |
203 started = anime.GetAirDate(); | |
204 } | |
205 date->SetDate(started); | |
206 subsection_layout->addWidget(date); | |
207 }); | |
208 CREATE_SUBSECTION({ | |
209 subsection_layout->addWidget(new QLabel(tr("Date completed:"), subsection)); | |
210 | |
211 OptionalDate* date = new OptionalDate(true, subsection); | |
212 connect(date, &OptionalDate::DataChanged, this, | |
213 [this](bool enabled, Date date) { completed = (enabled) ? date : Date(); }); | |
214 completed = anime.GetUserDateCompleted(); | |
215 if (!completed.IsValid()) { | |
216 date->SetEnabled(false); | |
217 completed = anime.GetAirDate(); | |
218 } | |
219 date->SetDate(completed); | |
220 subsection_layout->addWidget(date); | |
221 }); | |
222 }); | |
223 | |
224 settings_layout->addWidget(sg_anime_list_content); | |
225 | |
226 settings_layout->addWidget(new TextWidgets::Header(tr("Local settings"), settings_widget)); | |
227 | |
228 QWidget* sg_local_content = new QWidget(settings_widget); | |
229 QVBoxLayout* sg_local_layout = new QVBoxLayout(sg_local_content); | |
230 sg_local_layout->setSpacing(5); | |
231 sg_local_layout->setContentsMargins(12, 0, 0, 0); | |
232 | |
233 CREATE_FULL_WIDTH_SECTION(sg_local_content, { | |
234 /* Alternative titles */ | |
235 CREATE_FULL_WIDTH_SUBSECTION({ | |
236 subsection_layout->addWidget(new QLabel(tr("Alternative titles:"), subsection)); | |
237 | |
238 QLineEdit* line_edit = new QLineEdit("", subsection); | |
239 line_edit->setPlaceholderText( | |
240 tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)")); | |
241 subsection_layout->addWidget(line_edit); | |
242 | |
243 QCheckBox* checkbox = new QCheckBox(tr("Use the first alternative title to search for torrents")); | |
244 subsection_layout->addWidget(checkbox); | |
245 }); | |
246 }); | |
247 #undef CREATE_SECTION | |
248 #undef CREATE_SUBSECTION | |
249 #undef CREATE_FULL_WIDTH_SECTION | |
250 #undef CREATE_FULL_WIDTH_SUBSECTION | |
251 | |
252 settings_layout->addWidget(sg_local_content); | |
253 settings_layout->addStretch(); | |
254 | |
255 tabbed_widget->addTab(main_information_widget, tr("Main information")); | |
256 tabbed_widget->addTab(settings_widget, tr("My list and settings")); | |
257 | |
258 QVBoxLayout* main_layout = new QVBoxLayout(main_widget); | |
259 main_layout->addWidget(anime_title); | |
260 main_layout->addWidget(tabbed_widget); | |
261 main_layout->setContentsMargins(0, 0, 0, 0); | |
262 | |
263 QHBoxLayout* layout = new QHBoxLayout(widget); | |
264 layout->addWidget(sidebar); | |
265 layout->addWidget(main_widget); | |
266 layout->setSpacing(12); | |
267 | |
268 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); | |
269 connect(button_box, &QDialogButtonBox::accepted, this, [this, accept] { | |
270 SaveData(); | |
271 accept(); | |
272 QDialog::accept(); | |
273 }); | |
274 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); | |
275 | |
276 QVBoxLayout* buttons_layout = new QVBoxLayout(this); | |
277 buttons_layout->addWidget(widget); | |
278 buttons_layout->addWidget(button_box, 0, Qt::AlignBottom); | |
279 } | |
280 | |
281 #include "gui/dialog/moc_information.cpp" |