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