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