Mercurial > minori
annotate src/gui/widgets/anime_button.cc @ 294:99cbc51433e4
*: cleanup uses of QPalette
I didn't know about setBackgroundRole() which is very useful
in 99% of the cases where I even needed to edit the palette
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Sun, 12 May 2024 18:16:08 -0400 |
parents | 9a88e1725fd2 |
children | b82841e76e79 |
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 |
15 /* This widget is only used on the Seasons page. */ | |
16 | |
17 /***********************************\ | |
18 *|---------| Title * | |
19 *| | * | |
20 *| | Aired * | |
21 *| | Episodes * | |
22 *| Poster | Producers * | |
23 *| | Score * | |
24 *| | Popularity * | |
25 *| | * | |
26 *|_________| Synopsis * | |
27 \***********************************/ | |
28 | |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
29 AnimeButton::AnimeButton(QWidget* parent) |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
30 : QFrame(parent) |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
31 , _info(tr("Aired:\nEpisodes:\nGenres:\nProducers:\nScore:\nPopularity:"), "\n\n\n\n\n", nullptr) |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
32 , _synopsis("", nullptr) { |
253 | 33 setFrameShadow(QFrame::Plain); |
34 setFrameShape(QFrame::Box); | |
35 QHBoxLayout* ly = new QHBoxLayout(this); | |
36 | |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
37 _poster.setFixedSize(120, 170); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
38 _poster.SetClickable(false); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
39 ly->addWidget(&_poster, 0, Qt::AlignTop); |
253 | 40 |
41 { | |
42 QWidget* misc_section = new QWidget(this); | |
43 misc_section->setFixedSize(354, 180); | |
44 | |
45 QVBoxLayout* misc_layout = new QVBoxLayout(misc_section); | |
46 misc_layout->setContentsMargins(0, 0, 0, 0); | |
47 | |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
48 _title.setAutoFillBackground(true); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
49 _title.setContentsMargins(4, 4, 4, 4); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
50 _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
|
51 { |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
52 QFont fnt(_title.font()); |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
53 fnt.setWeight(QFont::Bold); |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
54 _title.setFont(fnt); |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
55 } |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
56 misc_layout->addWidget(&_title); |
253 | 57 |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
58 { |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
59 QFont fnt(_info.GetLabels()->font()); |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
60 fnt.setWeight(QFont::Bold); |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
61 _info.GetLabels()->setFont(fnt); |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
62 } |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
63 |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
64 _info.setContentsMargins(4, 0, 4, 0); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
65 _info.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
66 misc_layout->addWidget(&_info); |
253 | 67 |
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 QWidget* dummy = new QWidget(misc_section); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
70 dummy->setContentsMargins(4, 0, 4, 0); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
71 QVBoxLayout* dummy_layout = new QVBoxLayout(dummy); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
72 dummy_layout->setSpacing(0); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
73 dummy_layout->setContentsMargins(0, 0, 0, 0); |
253 | 74 |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
75 _synopsis.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
76 dummy_layout->addWidget(&_synopsis); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
77 misc_layout->addWidget(dummy); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
78 } |
254
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
79 |
d14f8e0e40c3
[UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents:
253
diff
changeset
|
80 ly->addWidget(misc_section, 0, Qt::AlignTop); |
253 | 81 } |
82 } | |
83 | |
84 AnimeButton::AnimeButton(const Anime::Anime& anime, QWidget* parent) : AnimeButton(parent) { | |
85 SetAnime(anime); | |
86 } | |
87 | |
88 void AnimeButton::SetAnime(const Anime::Anime& anime) { | |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
89 _poster.SetAnime(anime); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
90 _title.setText(Strings::ToQString(anime.GetUserPreferredTitle())); |
253 | 91 |
92 { | |
93 const QLocale& locale = session.config.locale.GetLocale(); | |
291 | 94 _info.GetData()->setText(locale.toString(anime.GetAirDate().GetAsQDate(), "dd MMM yyyy") + "\n" + |
95 QString::number(anime.GetEpisodes()) + "\n" + | |
96 Strings::ToQString(Strings::Implode(anime.GetGenres(), ", ")) + "\n" + "...\n" + | |
97 QString::number(anime.GetAudienceScore()) + "%\n" + "..."); | |
253 | 98 } |
99 | |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
100 _synopsis.SetText(Strings::ToQString(anime.GetSynopsis())); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
101 } |