Mercurial > minori
annotate src/gui/widgets/text.cc @ 281:3ede7be4f449
anime_season: forgot these
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Mon, 06 May 2024 17:44:16 -0400 |
parents | 862d0d8619f6 |
children | 9a88e1725fd2 |
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. | |
258 | 45 */ |
253 | 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 | |
258 | 145 LabelledSection::LabelledSection(const QString& title, const QString& label, const QString& data, QWidget* parent) |
146 : QWidget(parent) { | |
64 | 147 QVBoxLayout* layout = new QVBoxLayout(this); |
46 | 148 |
149 header = new Header(title, this); | |
150 | |
151 // this is not accessible from the object because there's really | |
152 // no reason to make it accessible... | |
253 | 153 content = new LabelledParagraph(label, data, this); |
83 | 154 content->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); |
46 | 155 content->setContentsMargins(12, 0, 0, 0); |
156 | |
64 | 157 layout->addWidget(header); |
158 layout->addWidget(content); | |
159 layout->setSpacing(0); | |
160 layout->setContentsMargins(0, 0, 0, 0); | |
46 | 161 } |
162 | |
75 | 163 Header* LabelledSection::GetHeader() { |
46 | 164 return header; |
165 } | |
166 | |
75 | 167 Paragraph* LabelledSection::GetLabels() { |
253 | 168 return content->GetLabels(); |
46 | 169 } |
170 | |
75 | 171 Paragraph* LabelledSection::GetParagraph() { |
253 | 172 return content->GetParagraph(); |
46 | 173 } |
174 | |
83 | 175 SelectableSection::SelectableSection(const QString& title, const QString& data, QWidget* parent) : QWidget(parent) { |
64 | 176 QVBoxLayout* layout = new QVBoxLayout(this); |
46 | 177 |
178 header = new Header(title, this); | |
179 | |
180 QWidget* content = new QWidget(this); | |
64 | 181 QHBoxLayout* content_layout = new QHBoxLayout(content); |
46 | 182 |
183 paragraph = new Paragraph(data, content); | |
184 | |
64 | 185 content_layout->addWidget(paragraph); |
186 content_layout->setSpacing(0); | |
102 | 187 content_layout->setContentsMargins(12, 0, 0, 0); |
188 content->setContentsMargins(0, 0, 0, 0); | |
46 | 189 |
64 | 190 layout->addWidget(header); |
191 layout->addWidget(content); | |
192 layout->setSpacing(0); | |
193 layout->setContentsMargins(0, 0, 0, 0); | |
46 | 194 } |
195 | |
75 | 196 Header* SelectableSection::GetHeader() { |
46 | 197 return header; |
198 } | |
199 | |
75 | 200 Paragraph* SelectableSection::GetParagraph() { |
46 | 201 return paragraph; |
202 } | |
203 | |
83 | 204 OneLineSection::OneLineSection(const QString& title, const QString& text, QWidget* parent) : QWidget(parent) { |
75 | 205 QVBoxLayout* layout = new QVBoxLayout(this); |
206 | |
207 header = new Header(title, this); | |
46 | 208 |
75 | 209 QWidget* content = new QWidget(this); |
210 QHBoxLayout* content_layout = new QHBoxLayout(content); | |
211 | |
212 line = new Line(text, content); | |
46 | 213 |
75 | 214 content_layout->addWidget(line); |
215 content_layout->setSpacing(0); | |
216 content_layout->setContentsMargins(0, 0, 0, 0); | |
217 content->setContentsMargins(12, 0, 0, 0); | |
46 | 218 |
75 | 219 layout->addWidget(header); |
220 layout->addWidget(content); | |
221 layout->setSpacing(0); | |
222 layout->setContentsMargins(0, 0, 0, 0); | |
64 | 223 } |
224 | |
75 | 225 Header* OneLineSection::GetHeader() { |
226 return header; | |
46 | 227 } |
228 | |
75 | 229 Line* OneLineSection::GetLine() { |
230 return line; | |
46 | 231 } |
232 | |
233 } // namespace TextWidgets |