annotate src/dialog/information.cpp @ 8:b1f73678ef61

update text paragraphs are now their own objects, as they should be
author Paper <mrpapersonic@gmail.com>
date Sat, 26 Aug 2023 03:39:34 -0400
parents 07a9095eaeed
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
1 #include <QPlainTextEdit>
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
2 #include <QVBoxLayout>
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
3 #include <QTextStream>
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
4 #include <QDebug>
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
5 #include "window.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
6 #include "anime.h"
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
7 #include "anime_list.h"
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
8 #include "information.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
9 #include "ui_utils.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
10 #include "string_utils.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
11
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
12 #include <QDialogButtonBox>
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
13
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
14 void InformationDialog::OnOK() {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
15 model->UpdateAnime(*anime);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
16 QDialog::accept();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
17 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
18
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
19 InformationDialog::InformationDialog(Anime& a, AnimeListWidgetModel* model, QWidget* parent)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
20 : QDialog(parent)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
21 {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
22 this->model = model;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
23 this->anime = &a;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
24 setFixedSize(842, 613);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
25 setWindowTitle(tr("Anime Information"));
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
26 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
27 setObjectName("infodiag");
8
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
28
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
29 /* main widget */
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
30 QWidget* widget = new QWidget(this);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
31 widget->resize(842-175, 530);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
32 widget->move(175, 0);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
33 widget->setStyleSheet(UiUtils::IsInDarkMode() ? "" : "background-color: white");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
34 widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
8
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
35
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
36 /* anime title header text */
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
37 QPlainTextEdit* anime_title = new QPlainTextEdit(QString::fromUtf8(anime->GetUserPreferredTitle().c_str()), widget);
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
38 anime_title->setReadOnly(true);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
39 anime_title->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
40 anime_title->setWordWrapMode(QTextOption::NoWrap);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
41 anime_title->setFrameShape(QFrame::NoFrame);
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
42 anime_title->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
43 anime_title->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
44 anime_title->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
45 anime_title->setStyleSheet("font-size: 16px; color: blue; background: transparent;");
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
46 anime_title->resize(636, 28);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
47 anime_title->move(0, 12);
8
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
48
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
49 /* tabbed widget */
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
50 QTabWidget* tabbed_widget = new QTabWidget(widget);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
51 tabbed_widget->resize(636, 485);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
52 tabbed_widget->move(0, 45);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
53 tabbed_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
8
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
54
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
55 /* main info tab */
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
56 QWidget* main_information_widget = new QWidget(tabbed_widget);
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
57 main_information_widget->setLayout(new QVBoxLayout);
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
58
8
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
59 /* alt titles */
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
60 main_information_widget->layout()->addWidget(new UiUtils::SelectableTextParagraph("Alternative titles", QString::fromUtf8(StringUtils::Implode(anime->GetTitleSynonyms(), ", ").c_str()), main_information_widget));
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
61
8
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
62 /* details */
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
63 QString details_data;
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
64 QTextStream details_data_s(&details_data);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
65 details_data_s << AnimeFormatToStringMap[anime->type].c_str() << "\n"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
66 << anime->episodes << "\n"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
67 << AnimeAiringToStringMap[anime->airing].c_str() << "\n"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
68 << AnimeSeasonToStringMap[anime->season].c_str() << " " << anime->air_date.GetYear() << "\n"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
69 << StringUtils::Implode(anime->genres, ", ").c_str() << "\n"
8
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
70 << anime->audience_score << "%";
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
71 main_information_widget->layout()->addWidget(new UiUtils::LabelledTextParagraph("Details", "Type:\nEpisodes:\nStatus:\nSeason:\nGenres:\nScore:", details_data, main_information_widget));
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
72
8
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
73 /* synopsis */
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
74 UiUtils::SelectableTextParagraph* synopsis = new UiUtils::SelectableTextParagraph("Synopsis", QString::fromUtf8(anime->synopsis.c_str()), main_information_widget);
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
75 synopsis->GetParagraph()->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
76 ((QVBoxLayout*)main_information_widget->layout())->addWidget(synopsis);
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
77
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
78 //((QVBoxLayout*)main_information_widget->layout())->addStretch();
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
79
8
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
80 QWidget* settings_widget = new QWidget(tabbed_widget);
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
81
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
82 tabbed_widget->addTab(main_information_widget, "Main information");
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
83 tabbed_widget->addTab(settings_widget, "My list and settings");
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
84 QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
3
190ded9438c0 Fix many warnings
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
85 connect(button_box, &QDialogButtonBox::accepted, this, &InformationDialog::OnOK);
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
86 connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
6
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
87 QVBoxLayout* buttons_layout = new QVBoxLayout(this);
1d82f6e04d7d Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents: 3
diff changeset
88 //buttons_layout->addWidget(widget, 0, Qt::AlignTop);
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
89 buttons_layout->addWidget(button_box, 0, Qt::AlignBottom);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
90 // this should probably be win32-only
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
91 setStyleSheet(UiUtils::IsInDarkMode() ? "" : "QDialog#infodiag{background-color: white;}");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
92 setLayout(buttons_layout);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
93 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
94
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
95 #include "moc_information.cpp"