Mercurial > minori
annotate src/gui/widgets/text.cc @ 254:d14f8e0e40c3
[UNFINISHED] *: update anime button
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Wed, 07 Feb 2024 07:57:37 -0500 |
parents | b3549da699a6 |
children | 862d0d8619f6 |
rev | line source |
---|---|
46 | 1 #include "gui/widgets/text.h" |
2 #include "core/session.h" | |
253 | 3 |
77 | 4 #include <QDebug> |
46 | 5 #include <QFrame> |
6 #include <QLabel> | |
7 #include <QTextBlock> | |
8 #include <QVBoxLayout> | |
9 | |
10 namespace TextWidgets { | |
11 | |
83 | 12 Header::Header(const QString& title, QWidget* parent) : QWidget(parent) { |
64 | 13 QVBoxLayout* layout = new QVBoxLayout(this); |
46 | 14 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); |
15 | |
16 static_text_title = new QLabel(title, this); | |
17 static_text_title->setTextFormat(Qt::PlainText); | |
183
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
105
diff
changeset
|
18 |
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
105
diff
changeset
|
19 { |
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
105
diff
changeset
|
20 QFont font = static_text_title->font(); |
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
105
diff
changeset
|
21 font.setWeight(QFont::Bold); |
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
105
diff
changeset
|
22 static_text_title->setFont(font); |
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
105
diff
changeset
|
23 } |
46 | 24 |
25 static_text_line = new QFrame(this); | |
26 static_text_line->setFrameShape(QFrame::HLine); | |
27 static_text_line->setFrameShadow(QFrame::Sunken); | |
28 static_text_line->setFixedHeight(2); | |
29 | |
64 | 30 layout->addWidget(static_text_title); |
31 layout->addWidget(static_text_line); | |
32 layout->setSpacing(0); | |
33 layout->setContentsMargins(0, 0, 0, 0); | |
46 | 34 } |
35 | |
83 | 36 void Header::SetText(const QString& text) { |
64 | 37 static_text_title->setText(text); |
83 | 38 updateGeometry(); |
46 | 39 } |
40 | |
253 | 41 /* for now, this is a QLabel with a couple of default settings. |
42 * | |
43 * eventually I'll have to implement this as a QScrollArea, just in case | |
44 * some random text decides to overflow or something. | |
45 */ | |
46 Paragraph::Paragraph(const QString& text, QWidget* parent) : QLabel(text, parent) { | |
75 | 47 setTextInteractionFlags(Qt::TextBrowserInteraction); |
48 setFrameShape(QFrame::NoFrame); | |
253 | 49 setCursor(Qt::IBeamCursor); /* emulate Taiga */ |
50 setWordWrap(true); | |
75 | 51 |
253 | 52 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); |
75 | 53 } |
54 | |
253 | 55 /* kept here for legacy reasons, see explanation above */ |
56 void Paragraph::SetText(const QString& text) { | |
57 setText(text); | |
75 | 58 } |
59 | |
253 | 60 /* Equivalent to Paragraph(), but disables word wrap. */ |
61 Line::Line(QWidget* parent) : Paragraph("", parent) { | |
62 setWordWrap(false); | |
75 | 63 } |
64 | |
253 | 65 Line::Line(const QString& text, QWidget* parent) : Paragraph(text, parent) { |
66 setWordWrap(false); | |
83 | 67 } |
68 | |
253 | 69 /* legacy function, don't use in new code */ |
83 | 70 void Line::SetText(const QString& text) { |
71 setText(text); | |
72 } | |
73 | |
74 Title::Title(const QString& title, QWidget* parent) : Line(title, parent) { | |
75 | 75 QFont fnt(font()); |
76 fnt.setPixelSize(16); | |
77 setFont(fnt); | |
78 | |
79 QPalette pal(palette()); | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
80 pal.setColor(QPalette::Text, pal.color(QPalette::Highlight)); |
75 | 81 setPalette(pal); |
82 } | |
83 | |
83 | 84 Section::Section(const QString& title, const QString& data, QWidget* parent) : QWidget(parent) { |
64 | 85 QVBoxLayout* layout = new QVBoxLayout(this); |
46 | 86 |
87 header = new Header(title, this); | |
88 | |
89 QWidget* content = new QWidget(this); | |
64 | 90 QHBoxLayout* content_layout = new QHBoxLayout(content); |
46 | 91 |
92 paragraph = new Paragraph(data, this); | |
93 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | |
94 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
253 | 95 paragraph->setWordWrap(QTextOption::NoWrap); |
46 | 96 |
64 | 97 content_layout->addWidget(paragraph); |
98 content_layout->setSpacing(0); | |
99 content_layout->setContentsMargins(0, 0, 0, 0); | |
46 | 100 content->setContentsMargins(12, 0, 0, 0); |
101 | |
64 | 102 layout->addWidget(header); |
103 layout->addWidget(paragraph); | |
104 layout->setSpacing(0); | |
105 layout->setContentsMargins(0, 0, 0, 0); | |
46 | 106 } |
107 | |
75 | 108 Header* Section::GetHeader() { |
46 | 109 return header; |
110 } | |
111 | |
75 | 112 Paragraph* Section::GetParagraph() { |
46 | 113 return paragraph; |
114 } | |
115 | |
253 | 116 LabelledParagraph::LabelledParagraph(const QString& label, const QString& data, QWidget* parent) : QWidget(parent) { |
117 QHBoxLayout* ly = new QHBoxLayout(this); | |
118 | |
119 labels = new Paragraph(label, this); | |
120 labels->setTextInteractionFlags(Qt::NoTextInteraction); | |
121 labels->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
122 labels->setWordWrap(QTextOption::NoWrap); | |
123 labels->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding); | |
124 | |
125 paragraph = new Paragraph(data, this); | |
126 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | |
127 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
128 paragraph->setWordWrap(QTextOption::NoWrap); | |
129 paragraph->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | |
130 | |
131 ly->addWidget(labels, 0, Qt::AlignTop); | |
132 ly->addWidget(paragraph, 0, Qt::AlignTop); | |
133 ly->setSpacing(20); | |
134 ly->setContentsMargins(0, 0, 0, 0); | |
135 } | |
136 | |
137 Paragraph* LabelledParagraph::GetLabels() { | |
138 return labels; | |
139 } | |
140 | |
141 Paragraph* LabelledParagraph::GetParagraph() { | |
142 return paragraph; | |
143 } | |
144 | |
83 | 145 LabelledSection::LabelledSection(const QString& title, const QString& label, const QString& data, QWidget* parent) : QWidget(parent) { |
64 | 146 QVBoxLayout* layout = new QVBoxLayout(this); |
46 | 147 |
148 header = new Header(title, this); | |
149 | |
150 // this is not accessible from the object because there's really | |
151 // no reason to make it accessible... | |
253 | 152 content = new LabelledParagraph(label, data, this); |
83 | 153 content->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); |
46 | 154 content->setContentsMargins(12, 0, 0, 0); |
155 | |
64 | 156 layout->addWidget(header); |
157 layout->addWidget(content); | |
158 layout->setSpacing(0); | |
159 layout->setContentsMargins(0, 0, 0, 0); | |
46 | 160 } |
161 | |
75 | 162 Header* LabelledSection::GetHeader() { |
46 | 163 return header; |
164 } | |
165 | |
75 | 166 Paragraph* LabelledSection::GetLabels() { |
253 | 167 return content->GetLabels(); |
46 | 168 } |
169 | |
75 | 170 Paragraph* LabelledSection::GetParagraph() { |
253 | 171 return content->GetParagraph(); |
46 | 172 } |
173 | |
83 | 174 SelectableSection::SelectableSection(const QString& title, const QString& data, QWidget* parent) : QWidget(parent) { |
64 | 175 QVBoxLayout* layout = new QVBoxLayout(this); |
46 | 176 |
177 header = new Header(title, this); | |
178 | |
179 QWidget* content = new QWidget(this); | |
64 | 180 QHBoxLayout* content_layout = new QHBoxLayout(content); |
46 | 181 |
182 paragraph = new Paragraph(data, content); | |
183 | |
64 | 184 content_layout->addWidget(paragraph); |
185 content_layout->setSpacing(0); | |
102 | 186 content_layout->setContentsMargins(12, 0, 0, 0); |
187 content->setContentsMargins(0, 0, 0, 0); | |
46 | 188 |
64 | 189 layout->addWidget(header); |
190 layout->addWidget(content); | |
191 layout->setSpacing(0); | |
192 layout->setContentsMargins(0, 0, 0, 0); | |
46 | 193 } |
194 | |
75 | 195 Header* SelectableSection::GetHeader() { |
46 | 196 return header; |
197 } | |
198 | |
75 | 199 Paragraph* SelectableSection::GetParagraph() { |
46 | 200 return paragraph; |
201 } | |
202 | |
83 | 203 OneLineSection::OneLineSection(const QString& title, const QString& text, QWidget* parent) : QWidget(parent) { |
75 | 204 QVBoxLayout* layout = new QVBoxLayout(this); |
205 | |
206 header = new Header(title, this); | |
46 | 207 |
75 | 208 QWidget* content = new QWidget(this); |
209 QHBoxLayout* content_layout = new QHBoxLayout(content); | |
210 | |
211 line = new Line(text, content); | |
46 | 212 |
75 | 213 content_layout->addWidget(line); |
214 content_layout->setSpacing(0); | |
215 content_layout->setContentsMargins(0, 0, 0, 0); | |
216 content->setContentsMargins(12, 0, 0, 0); | |
46 | 217 |
75 | 218 layout->addWidget(header); |
219 layout->addWidget(content); | |
220 layout->setSpacing(0); | |
221 layout->setContentsMargins(0, 0, 0, 0); | |
64 | 222 } |
223 | |
75 | 224 Header* OneLineSection::GetHeader() { |
225 return header; | |
46 | 226 } |
227 | |
75 | 228 Line* OneLineSection::GetLine() { |
229 return line; | |
46 | 230 } |
231 | |
232 } // namespace TextWidgets |