Mercurial > minori
annotate src/gui/widgets/anime_button.cc @ 367:8d45d892be88 default tip
*: instead of pugixml, use Qt XML features
this means we have one extra Qt dependency though...
author | Paper <paper@tflc.us> |
---|---|
date | Sun, 17 Nov 2024 22:55:47 -0500 |
parents | f81bed4e04ac |
children |
rev | line source |
---|---|
253 | 1 #include "gui/widgets/anime_button.h" |
2 | |
3 #include "core/anime_db.h" | |
258 | 4 #include "core/session.h" |
253 | 5 #include "core/strings.h" |
6 #include "gui/widgets/elided_label.h" | |
7 #include "gui/widgets/poster.h" | |
258 | 8 #include "gui/widgets/text.h" |
253 | 9 |
258 | 10 #include <QDate> |
11 #include <QHBoxLayout> | |
253 | 12 #include <QVBoxLayout> |
258 | 13 #include <QWidget> |
253 | 14 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
15 #include <iostream> |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
16 |
253 | 17 /* This widget is only used on the Seasons page. */ |
18 | |
19 /***********************************\ | |
20 *|---------| Title * | |
21 *| | * | |
22 *| | Aired * | |
23 *| | Episodes * | |
24 *| Poster | Producers * | |
25 *| | Score * | |
26 *| | Popularity * | |
27 *| | * | |
28 *|_________| Synopsis * | |
29 \***********************************/ | |
30 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
31 AnimeButton::AnimeButton(QWidget* parent) : QFrame(parent) { |
253 | 32 setFrameShadow(QFrame::Plain); |
33 setFrameShape(QFrame::Box); | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
34 |
253 | 35 QHBoxLayout* ly = new QHBoxLayout(this); |
36 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
37 _poster.SetClickable(false); |
365
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
38 ly->addWidget(&_poster, 1, Qt::AlignTop); |
253 | 39 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
40 const std::vector<std::pair<std::string, std::string>> imap = { |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
41 {Strings::Translate("Aired:"), ""}, |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
42 {Strings::Translate("Episodes:"), ""}, |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
43 {Strings::Translate("Genres:"), ""}, |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
44 {Strings::Translate("Producers:"), ""}, |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
45 {Strings::Translate("Score:"), ""}, |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
46 {Strings::Translate("Popularity:"), ""}, |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
47 }; |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
48 |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
49 _info.SetData(imap); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
50 |
253 | 51 { |
52 QWidget* misc_section = new QWidget(this); | |
53 | |
54 QVBoxLayout* misc_layout = new QVBoxLayout(misc_section); | |
55 misc_layout->setContentsMargins(0, 0, 0, 0); | |
56 | |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
57 _title.setAutoFillBackground(true); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
58 _title.setContentsMargins(4, 4, 4, 4); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
59 _title.setStyleSheet("background-color: rgba(0, 245, 25, 50);"); |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
60 { |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
61 QFont fnt(_title.font()); |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
62 fnt.setWeight(QFont::Bold); |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
63 _title.setFont(fnt); |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
64 } |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
65 misc_layout->addWidget(&_title); |
253 | 66 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
67 _info.SetStyle(TextWidgets::LabelledParagraph::Style::BoldedLabels); |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
68 |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
69 _info.setContentsMargins(4, 0, 4, 0); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
70 _info.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
71 misc_layout->addWidget(&_info); |
253 | 72 |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
73 { |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
74 QWidget* dummy = new QWidget(misc_section); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
75 dummy->setContentsMargins(4, 0, 4, 0); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
76 QVBoxLayout* dummy_layout = new QVBoxLayout(dummy); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
77 dummy_layout->setSpacing(0); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
78 dummy_layout->setContentsMargins(0, 0, 0, 0); |
253 | 79 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
80 _synopsis.SetSelectable(false); |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
81 dummy_layout->addWidget(&_synopsis); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
82 misc_layout->addWidget(dummy); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
83 } |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
84 |
365
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
85 ly->addWidget(misc_section, 3, Qt::AlignTop); |
253 | 86 } |
87 } | |
88 | |
89 AnimeButton::AnimeButton(const Anime::Anime& anime, QWidget* parent) : AnimeButton(parent) { | |
90 SetAnime(anime); | |
91 } | |
92 | |
93 void AnimeButton::SetAnime(const Anime::Anime& anime) { | |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
94 _poster.SetAnime(anime); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
95 _title.setText(Strings::ToQString(anime.GetUserPreferredTitle())); |
253 | 96 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
97 const QLocale& locale = session.config.locale.GetLocale(); |
253 | 98 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
99 const std::vector<std::pair<std::string, std::string>> imap = { |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
100 {Strings::Translate("Aired:"), Strings::ToUtf8String(locale.toString(anime.GetStartedDate().GetAsQDate(), "dd MMM yyyy"))}, |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
101 {Strings::Translate("Episodes:"), Strings::ToUtf8String(anime.GetEpisodes())}, |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
102 {Strings::Translate("Genres:"), Strings::Implode(anime.GetGenres(), ", ")}, |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
103 {Strings::Translate("Producers:"), "..."}, |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
104 {Strings::Translate("Score:"), Strings::ToUtf8String(anime.GetAudienceScore()) + "%"}, |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
105 {Strings::Translate("Popularity:"), "..."}, |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
106 }; |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
107 |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
108 _info.SetData(imap); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
109 |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
324
diff
changeset
|
110 _synopsis.SetText(anime.GetSynopsis()); |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
111 } |
365
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
112 |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
113 bool AnimeButton::hasHeightForWidth() const { |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
114 return true; |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
115 } |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
116 |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
117 int AnimeButton::heightForWidth(int w) const { |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
118 return static_cast<int>(static_cast<double>(w) / 2.5); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
119 } |