9
+ − 1 #include "gui/dialog/information.h"
+ − 2 #include "core/anime.h"
+ − 3 #include "core/strings.h"
+ − 4 #include "gui/pages/anime_list.h"
+ − 5 #include "gui/translate/anime.h"
+ − 6 #include "gui/ui_utils.h"
+ − 7 #include "gui/window.h"
+ − 8 #include <QDebug>
+ − 9 #include <QDialogButtonBox>
+ − 10 #include <QPlainTextEdit>
+ − 11 #include <QTextStream>
+ − 12 #include <QVBoxLayout>
+ − 13 #include <functional>
+ − 14
+ − 15 InformationDialog::InformationDialog(Anime::Anime& anime, std::function<void()> accept, QWidget* parent)
+ − 16 : QDialog(parent) {
+ − 17 setFixedSize(842, 613);
+ − 18 setWindowTitle(tr("Anime Information"));
+ − 19 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
+ − 20 setObjectName("infodiag");
+ − 21 setStyleSheet(UiUtils::IsInDarkMode() ? "" : "QDialog#infodiag{background-color: white;}");
+ − 22
+ − 23 QWidget* widget = new QWidget(this);
+ − 24
+ − 25 /* "sidebar", includes... just the anime image :) */
+ − 26 QWidget* sidebar = new QWidget(widget);
+ − 27 sidebar->setFixedWidth(175);
+ − 28
+ − 29 /* main widget */
+ − 30 QWidget* main_widget = new QWidget(widget);
+ − 31 main_widget->setStyleSheet(UiUtils::IsInDarkMode() ? "" : "background-color: white");
+ − 32 main_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ − 33
+ − 34 /* anime title header text */
+ − 35 UiUtils::Paragraph* anime_title =
+ − 36 new UiUtils::Paragraph(QString::fromUtf8(anime.GetUserPreferredTitle().c_str()), main_widget);
+ − 37 anime_title->setReadOnly(true);
+ − 38 anime_title->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ − 39 anime_title->setWordWrapMode(QTextOption::NoWrap);
+ − 40 anime_title->setFrameShape(QFrame::NoFrame);
+ − 41 anime_title->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
+ − 42 anime_title->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ − 43 anime_title->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ − 44 anime_title->setStyleSheet("font-size: 16px; color: blue; background: transparent;");
+ − 45
+ − 46 /* tabbed widget */
+ − 47 QTabWidget* tabbed_widget = new QTabWidget(main_widget);
+ − 48 tabbed_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+ − 49
+ − 50 /* main info tab */
+ − 51 QWidget* main_information_widget = new QWidget(tabbed_widget);
+ − 52 main_information_widget->setLayout(new QVBoxLayout);
+ − 53
+ − 54 /* alt titles */
+ − 55 main_information_widget->layout()->addWidget(new UiUtils::SelectableTextParagraph(
10
+ − 56 "Alternative titles", QString::fromUtf8(Strings::Implode(anime.GetTitleSynonyms(), ", ").c_str()),
9
+ − 57 main_information_widget));
+ − 58
+ − 59 /* details */
+ − 60 QString details_data;
+ − 61 QTextStream details_data_s(&details_data);
+ − 62 details_data_s << Translate::TranslateSeriesFormat(anime.GetFormat()).c_str() << "\n"
+ − 63 << anime.GetEpisodes() << "\n"
+ − 64 << Translate::TranslateListStatus(anime.GetUserStatus()).c_str() << "\n"
+ − 65 << Translate::TranslateSeriesSeason(anime.GetSeason()).c_str() << " " << anime.GetAirDate().GetYear()
+ − 66 << "\n"
10
+ − 67 << Strings::Implode(anime.GetGenres(), ", ").c_str() << "\n"
9
+ − 68 << anime.GetAudienceScore() << "%";
+ − 69 main_information_widget->layout()->addWidget(new UiUtils::LabelledTextParagraph(
+ − 70 "Details", "Type:\nEpisodes:\nStatus:\nSeason:\nGenres:\nScore:", details_data, main_information_widget));
+ − 71
+ − 72 /* synopsis */
+ − 73 UiUtils::SelectableTextParagraph* synopsis = new UiUtils::SelectableTextParagraph(
+ − 74 "Synopsis", QString::fromUtf8(anime.GetSynopsis().c_str()), main_information_widget);
+ − 75
+ − 76 synopsis->GetParagraph()->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
+ − 77 ((QVBoxLayout*)main_information_widget->layout())->addWidget(synopsis);
+ − 78
+ − 79 QWidget* settings_widget = new QWidget(tabbed_widget);
+ − 80
+ − 81 tabbed_widget->addTab(main_information_widget, "Main information");
+ − 82 tabbed_widget->addTab(settings_widget, "My list and settings");
+ − 83
+ − 84 QVBoxLayout* main_layout = new QVBoxLayout;
+ − 85 main_layout->addWidget(anime_title);
+ − 86 main_layout->addWidget(tabbed_widget);
+ − 87 main_layout->setMargin(0);
+ − 88 main_widget->setLayout(main_layout);
+ − 89
+ − 90 QHBoxLayout* layout = new QHBoxLayout;
+ − 91 layout->addWidget(sidebar);
+ − 92 layout->addWidget(main_widget);
+ − 93 widget->setLayout(layout);
+ − 94
+ − 95 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
+ − 96 connect(button_box, &QDialogButtonBox::accepted, this, [this, accept] {
+ − 97 accept();
+ − 98 QDialog::accept();
+ − 99 });
+ − 100 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
+ − 101
+ − 102 QVBoxLayout* buttons_layout = new QVBoxLayout;
+ − 103 buttons_layout->addWidget(widget);
+ − 104 buttons_layout->addWidget(button_box, 0, Qt::AlignBottom);
+ − 105 setLayout(buttons_layout);
+ − 106 }
+ − 107
+ − 108 #include "gui/dialog/moc_information.cpp"