Mercurial > minori
comparison src/gui/dialog/information.cpp @ 46:d0adc4aedfc8
*: update...
this commit:
1. consolidates dark theme stuff to dark_theme.cpp
2. creates a new widgets folder to store all of our
custom widgets
3. creates the list settings page in the information
dialog, although much of it is nonfunctional: it
doesn't save, and the status doesn't even get filled
in... we'll fix this later!
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Sat, 23 Sep 2023 01:02:15 -0400 |
| parents | 2743011a6042 |
| children | d8eb763e6661 |
comparison
equal
deleted
inserted
replaced
| 45:4b05bc7668eb | 46:d0adc4aedfc8 |
|---|---|
| 1 #include "gui/dialog/information.h" | 1 #include "gui/dialog/information.h" |
| 2 #include "core/anime.h" | 2 #include "core/anime.h" |
| 3 #include "core/array.h" | |
| 3 #include "core/strings.h" | 4 #include "core/strings.h" |
| 4 #include "gui/pages/anime_list.h" | 5 #include "gui/pages/anime_list.h" |
| 5 #include "gui/translate/anime.h" | 6 #include "gui/translate/anime.h" |
| 6 #include "gui/ui_utils.h" | 7 #include "gui/widgets/text.h" |
| 7 #include "gui/window.h" | 8 #include "gui/window.h" |
| 9 #include <QCheckBox> | |
| 10 #include <QComboBox> | |
| 8 #include <QDebug> | 11 #include <QDebug> |
| 9 #include <QDialogButtonBox> | 12 #include <QDialogButtonBox> |
| 13 #include <QLineEdit> | |
| 10 #include <QPlainTextEdit> | 14 #include <QPlainTextEdit> |
| 15 #include <QSpinBox> | |
| 16 #include <QStringList> | |
| 11 #include <QTextStream> | 17 #include <QTextStream> |
| 12 #include <QVBoxLayout> | 18 #include <QVBoxLayout> |
| 13 #include <functional> | 19 #include <functional> |
| 14 | 20 |
| 15 InformationDialog::InformationDialog(Anime::Anime& anime, std::function<void()> accept, QWidget* parent) | 21 /* TODO: Taiga disables rendering of the tab widget entirely when the anime is not part of a list, |
| 22 which sucks. Think of a better way to implement this later. */ | |
| 23 InformationDialog::InformationDialog(const Anime::Anime& anime, std::function<void()> accept, QWidget* parent) | |
| 16 : QDialog(parent) { | 24 : QDialog(parent) { |
| 17 setFixedSize(842, 613); | 25 setFixedSize(842, 613); |
| 18 setWindowTitle(tr("Anime Information")); | 26 setWindowTitle(tr("Anime Information")); |
| 19 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); | 27 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); |
| 20 | 28 |
| 40 } | 48 } |
| 41 | 49 |
| 42 main_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | 50 main_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
| 43 | 51 |
| 44 /* anime title header text */ | 52 /* anime title header text */ |
| 45 UiUtils::Paragraph* anime_title = | 53 TextWidgets::Paragraph* anime_title = |
| 46 new UiUtils::Paragraph(QString::fromUtf8(anime.GetUserPreferredTitle().c_str()), main_widget); | 54 new TextWidgets::Paragraph(QString::fromUtf8(anime.GetUserPreferredTitle().c_str()), main_widget); |
| 47 anime_title->setReadOnly(true); | 55 anime_title->setReadOnly(true); |
| 48 anime_title->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 56 anime_title->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
| 49 anime_title->setWordWrapMode(QTextOption::NoWrap); | 57 anime_title->setWordWrapMode(QTextOption::NoWrap); |
| 50 anime_title->setFrameShape(QFrame::NoFrame); | 58 anime_title->setFrameShape(QFrame::NoFrame); |
| 51 anime_title->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 59 anime_title->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
| 58 anime_title->setFont(font); | 66 anime_title->setFont(font); |
| 59 } | 67 } |
| 60 | 68 |
| 61 { | 69 { |
| 62 QPalette pal; | 70 QPalette pal; |
| 63 pal.setColor(QPalette::Window, QColor(255, 255, 255, 0)); | 71 pal.setColor(QPalette::Window, Qt::transparent); |
| 64 pal.setColor(QPalette::WindowText, Qt::blue); | 72 pal.setColor(QPalette::WindowText, Qt::blue); |
| 65 } | 73 } |
| 66 | 74 |
| 67 /* tabbed widget */ | 75 /* tabbed widget */ |
| 68 QTabWidget* tabbed_widget = new QTabWidget(main_widget); | 76 QTabWidget* tabbed_widget = new QTabWidget(main_widget); |
| 71 /* main info tab */ | 79 /* main info tab */ |
| 72 QWidget* main_information_widget = new QWidget(tabbed_widget); | 80 QWidget* main_information_widget = new QWidget(tabbed_widget); |
| 73 main_information_widget->setLayout(new QVBoxLayout); | 81 main_information_widget->setLayout(new QVBoxLayout); |
| 74 | 82 |
| 75 /* alt titles */ | 83 /* alt titles */ |
| 76 main_information_widget->layout()->addWidget(new UiUtils::SelectableTextParagraph( | 84 main_information_widget->layout()->addWidget(new TextWidgets::SelectableTextParagraph( |
| 77 "Alternative titles", QString::fromUtf8(Strings::Implode(anime.GetTitleSynonyms(), ", ").c_str()), | 85 "Alternative titles", QString::fromUtf8(Strings::Implode(anime.GetTitleSynonyms(), ", ").c_str()), |
| 78 main_information_widget)); | 86 main_information_widget)); |
| 79 | 87 |
| 80 /* details */ | 88 /* details */ |
| 81 QString details_data; | 89 QString details_data; |
| 82 QTextStream details_data_s(&details_data); | 90 QTextStream details_data_s(&details_data); |
| 83 details_data_s << Translate::ToString(anime.GetFormat()).c_str() << "\n" | 91 details_data_s << Translate::ToString(anime.GetFormat()).c_str() << "\n" |
| 84 << anime.GetEpisodes() << "\n" | 92 << anime.GetEpisodes() << "\n" |
| 85 << Translate::ToString(anime.GetUserStatus()).c_str() << "\n" | 93 << Translate::ToString(anime.GetUserStatus()).c_str() << "\n" |
| 86 << Translate::ToString(anime.GetSeason()).c_str() << " " << anime.GetAirDate().GetYear() | 94 << Translate::ToString(anime.GetSeason()).c_str() << " " << anime.GetAirDate().GetYear() << "\n" |
| 87 << "\n" | |
| 88 << Strings::Implode(anime.GetGenres(), ", ").c_str() << "\n" | 95 << Strings::Implode(anime.GetGenres(), ", ").c_str() << "\n" |
| 89 << anime.GetAudienceScore() << "%"; | 96 << anime.GetAudienceScore() << "%"; |
| 90 main_information_widget->layout()->addWidget(new UiUtils::LabelledTextParagraph( | 97 main_information_widget->layout()->addWidget(new TextWidgets::LabelledTextParagraph( |
| 91 "Details", "Type:\nEpisodes:\nStatus:\nSeason:\nGenres:\nScore:", details_data, main_information_widget)); | 98 "Details", "Type:\nEpisodes:\nStatus:\nSeason:\nGenres:\nScore:", details_data, main_information_widget)); |
| 92 | 99 |
| 93 /* synopsis */ | 100 /* synopsis */ |
| 94 UiUtils::SelectableTextParagraph* synopsis = new UiUtils::SelectableTextParagraph( | 101 TextWidgets::SelectableTextParagraph* synopsis = new TextWidgets::SelectableTextParagraph( |
| 95 "Synopsis", QString::fromUtf8(anime.GetSynopsis().c_str()), main_information_widget); | 102 "Synopsis", QString::fromUtf8(anime.GetSynopsis().c_str()), main_information_widget); |
| 96 | 103 |
| 97 synopsis->GetParagraph()->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | 104 synopsis->GetParagraph()->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
| 98 ((QVBoxLayout*)main_information_widget->layout())->addWidget(synopsis); | 105 main_information_widget->layout()->addWidget(synopsis); |
| 99 | 106 |
| 100 QWidget* settings_widget = new QWidget(tabbed_widget); | 107 QWidget* settings_widget = new QWidget(tabbed_widget); |
| 108 settings_widget->setLayout(new QVBoxLayout); | |
| 109 settings_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); | |
| 110 | |
| 111 settings_widget->layout()->addWidget(new TextWidgets::Header(tr("Anime list"), settings_widget)); | |
| 112 | |
| 113 QWidget* sg_anime_list_content = new QWidget(settings_widget); | |
| 114 settings_widget->layout()->addWidget(sg_anime_list_content); | |
| 115 sg_anime_list_content->setLayout(new QVBoxLayout); | |
| 116 sg_anime_list_content->layout()->setSpacing(5); | |
| 117 sg_anime_list_content->layout()->setContentsMargins(12, 0, 0, 0); | |
| 118 | |
| 119 /* Note: PLEASE find a way we can consolidate these. By ANY other means than | |
| 120 putting them in a separate function. Macros are very much preferred. */ | |
| 121 #define LAYOUT_HORIZ_SPACING 9 | |
| 122 #define LAYOUT_VERT_SPACING 5 | |
| 123 { | |
| 124 /* Episodes watched section */ | |
| 125 QWidget* section = new QWidget(sg_anime_list_content); | |
| 126 QHBoxLayout* layout = new QHBoxLayout; | |
| 127 layout->setSpacing(LAYOUT_HORIZ_SPACING); | |
| 128 layout->setMargin(0); | |
| 129 section->setLayout(layout); | |
| 130 { | |
| 131 QWidget* subsection = new QWidget(section); | |
| 132 subsection->setLayout(new QVBoxLayout); | |
| 133 subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); | |
| 134 subsection->layout()->setMargin(0); | |
| 135 | |
| 136 subsection->layout()->addWidget(new QLabel(tr("Episodes watched:"), subsection)); | |
| 137 | |
| 138 QSpinBox* spin_box = new QSpinBox(subsection); | |
| 139 spin_box->setRange(0, anime.GetEpisodes()); | |
| 140 spin_box->setSingleStep(1); | |
| 141 spin_box->setValue(anime.GetUserProgress()); | |
| 142 subsection->layout()->addWidget(spin_box); | |
| 143 | |
| 144 layout->addWidget(subsection); | |
| 145 } | |
| 146 { | |
| 147 QWidget* subsection = new QWidget(section); | |
| 148 subsection->setLayout(new QVBoxLayout); | |
| 149 subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); | |
| 150 subsection->layout()->setMargin(0); | |
| 151 | |
| 152 subsection->layout()->addWidget(new QLabel(tr(" "), subsection)); | |
| 153 | |
| 154 QCheckBox* rewatched_checkbox = new QCheckBox("Rewatching"); | |
| 155 subsection->layout()->addWidget(rewatched_checkbox); | |
| 156 | |
| 157 layout->addWidget(subsection); | |
| 158 } | |
| 159 sg_anime_list_content->layout()->addWidget(section); | |
| 160 } | |
| 161 { | |
| 162 /* Status & score section */ | |
| 163 QWidget* section = new QWidget(sg_anime_list_content); | |
| 164 QHBoxLayout* layout = new QHBoxLayout; | |
| 165 layout->setSpacing(LAYOUT_HORIZ_SPACING); | |
| 166 layout->setMargin(0); | |
| 167 section->setLayout(layout); | |
| 168 { | |
| 169 QWidget* subsection = new QWidget(section); | |
| 170 subsection->setLayout(new QVBoxLayout); | |
| 171 subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); | |
| 172 subsection->layout()->setMargin(0); | |
| 173 | |
| 174 subsection->layout()->addWidget(new QLabel(tr("Status:"), subsection)); | |
| 175 | |
| 176 QStringList string_list; | |
| 177 for (unsigned int i = 0; i < ARRAYSIZE(Anime::ListStatuses); i++) | |
| 178 string_list.append(QString::fromStdString(Translate::ToString(Anime::ListStatuses[i]))); | |
| 179 | |
| 180 QComboBox* combo_box = new QComboBox(subsection); | |
| 181 combo_box->addItems(string_list); | |
| 182 subsection->layout()->addWidget(combo_box); | |
| 183 | |
| 184 layout->addWidget(subsection); | |
| 185 } | |
| 186 { | |
| 187 QWidget* subsection = new QWidget(section); | |
| 188 subsection->setLayout(new QVBoxLayout); | |
| 189 subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); | |
| 190 subsection->layout()->setMargin(0); | |
| 191 | |
| 192 subsection->layout()->addWidget(new QLabel(tr("Score:"), subsection)); | |
| 193 | |
| 194 QSpinBox* spin_box = new QSpinBox(subsection); | |
| 195 spin_box->setRange(0, 100); | |
| 196 spin_box->setSingleStep(5); | |
| 197 spin_box->setValue(anime.GetUserScore()); | |
| 198 subsection->layout()->addWidget(spin_box); | |
| 199 | |
| 200 layout->addWidget(subsection); | |
| 201 } | |
| 202 sg_anime_list_content->layout()->addWidget(section); | |
| 203 } | |
| 204 { | |
| 205 /* Notes section */ | |
| 206 QWidget* section = new QWidget(sg_anime_list_content); | |
| 207 QHBoxLayout* layout = new QHBoxLayout; | |
| 208 layout->setSpacing(LAYOUT_HORIZ_SPACING); | |
| 209 layout->setMargin(0); | |
| 210 section->setLayout(layout); | |
| 211 { | |
| 212 QWidget* subsection = new QWidget(section); | |
| 213 subsection->setLayout(new QVBoxLayout); | |
| 214 subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); | |
| 215 subsection->layout()->setMargin(0); | |
| 216 | |
| 217 subsection->layout()->addWidget(new QLabel(tr("Notes:"), subsection)); | |
| 218 | |
| 219 QLineEdit* line_edit = new QLineEdit(QString::fromStdString(anime.GetUserNotes()), subsection); | |
| 220 line_edit->setPlaceholderText(tr("Enter your notes about this anime")); | |
| 221 subsection->layout()->addWidget(line_edit); | |
| 222 | |
| 223 layout->addWidget(subsection); | |
| 224 } | |
| 225 sg_anime_list_content->layout()->addWidget(section); | |
| 226 } | |
| 227 | |
| 228 settings_widget->layout()->addWidget(new TextWidgets::Header(tr("Local settings"), settings_widget)); | |
| 229 | |
| 230 QWidget* sg_local_content = new QWidget(settings_widget); | |
| 231 settings_widget->layout()->addWidget(sg_local_content); | |
| 232 sg_local_content->setLayout(new QVBoxLayout); | |
| 233 sg_local_content->layout()->setSpacing(5); | |
| 234 sg_local_content->layout()->setContentsMargins(12, 0, 0, 0); | |
| 235 | |
| 236 { | |
| 237 /* Alternative titles */ | |
| 238 QWidget* section = new QWidget(sg_local_content); | |
| 239 QHBoxLayout* layout = new QHBoxLayout; | |
| 240 layout->setSpacing(LAYOUT_HORIZ_SPACING); | |
| 241 layout->setMargin(0); | |
| 242 section->setLayout(layout); | |
| 243 { | |
| 244 QWidget* subsection = new QWidget(section); | |
| 245 subsection->setLayout(new QVBoxLayout); | |
| 246 subsection->layout()->setSpacing(LAYOUT_VERT_SPACING); | |
| 247 subsection->layout()->setMargin(0); | |
| 248 | |
| 249 subsection->layout()->addWidget(new QLabel(tr("Alternative titles:"), subsection)); | |
| 250 | |
| 251 QLineEdit* line_edit = new QLineEdit(QString::fromStdString(anime.GetUserNotes()), subsection); | |
| 252 line_edit->setPlaceholderText(tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)")); | |
| 253 subsection->layout()->addWidget(line_edit); | |
| 254 | |
| 255 QCheckBox* checkbox = new QCheckBox("Use the first alternative title to search for torrents"); | |
| 256 subsection->layout()->addWidget(checkbox); | |
| 257 | |
| 258 layout->addWidget(subsection); | |
| 259 } | |
| 260 sg_local_content->layout()->addWidget(section); | |
| 261 } | |
| 262 | |
| 263 static_cast<QBoxLayout*>(settings_widget->layout())->addStretch(); | |
| 101 | 264 |
| 102 tabbed_widget->addTab(main_information_widget, "Main information"); | 265 tabbed_widget->addTab(main_information_widget, "Main information"); |
| 103 tabbed_widget->addTab(settings_widget, "My list and settings"); | 266 tabbed_widget->addTab(settings_widget, "My list and settings"); |
| 104 | 267 |
| 105 QVBoxLayout* main_layout = new QVBoxLayout; | 268 QVBoxLayout* main_layout = new QVBoxLayout; |
