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