Mercurial > minori
comparison src/gui/widgets/text.cpp @ 64:fe719c109dbc
*: update
1. add media tracking ability, and it displays info on the `now playing` page
2. the `now playing` page now actually shows something
3. renamed every page class to be more accurate to what it is
4. ...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 01 Oct 2023 23:15:43 -0400 |
parents | 3d2decf093bb |
children | 5ccb99bfa605 |
comparison
equal
deleted
inserted
replaced
63:3d2decf093bb | 64:fe719c109dbc |
---|---|
8 #include <QVBoxLayout> | 8 #include <QVBoxLayout> |
9 | 9 |
10 namespace TextWidgets { | 10 namespace TextWidgets { |
11 | 11 |
12 Header::Header(QString title, QWidget* parent) : QWidget(parent) { | 12 Header::Header(QString title, QWidget* parent) : QWidget(parent) { |
13 setLayout(new QVBoxLayout); | 13 QVBoxLayout* layout = new QVBoxLayout(this); |
14 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); | 14 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); |
15 | 15 |
16 static_text_title = new QLabel(title, this); | 16 static_text_title = new QLabel(title, this); |
17 static_text_title->setTextFormat(Qt::PlainText); | 17 static_text_title->setTextFormat(Qt::PlainText); |
18 QFont font = static_text_title->font(); | 18 QFont font = static_text_title->font(); |
19 font.setWeight(QFont::Bold); | 19 font.setWeight(QFont::Bold); |
20 static_text_title->setFont(font); | 20 static_text_title->setFont(font); |
21 /* FIXME: is this needed? */ | |
21 static_text_title->setFixedHeight(16); | 22 static_text_title->setFixedHeight(16); |
22 | 23 |
23 static_text_line = new QFrame(this); | 24 static_text_line = new QFrame(this); |
24 static_text_line->setFrameShape(QFrame::HLine); | 25 static_text_line->setFrameShape(QFrame::HLine); |
25 static_text_line->setFrameShadow(QFrame::Sunken); | 26 static_text_line->setFrameShadow(QFrame::Sunken); |
26 static_text_line->setFixedHeight(2); | 27 static_text_line->setFixedHeight(2); |
27 | 28 |
28 layout()->addWidget(static_text_title); | 29 layout->addWidget(static_text_title); |
29 layout()->addWidget(static_text_line); | 30 layout->addWidget(static_text_line); |
30 layout()->setSpacing(0); | 31 layout->setSpacing(0); |
31 layout()->setContentsMargins(0, 0, 0, 0); | 32 layout->setContentsMargins(0, 0, 0, 0); |
32 } | 33 } |
33 | 34 |
34 void Header::SetTitle(QString title) { | 35 void Header::SetText(QString text) { |
35 static_text_title->setText(title); | 36 static_text_title->setText(text); |
36 } | 37 } |
37 | 38 |
38 TextParagraph::TextParagraph(QString title, QString data, QWidget* parent) : QWidget(parent) { | 39 TextParagraph::TextParagraph(QString title, QString data, QWidget* parent) : QWidget(parent) { |
39 setLayout(new QVBoxLayout); | 40 QVBoxLayout* layout = new QVBoxLayout(this); |
40 | 41 |
41 header = new Header(title, this); | 42 header = new Header(title, this); |
42 | 43 |
43 QWidget* content = new QWidget(this); | 44 QWidget* content = new QWidget(this); |
44 content->setLayout(new QHBoxLayout); | 45 QHBoxLayout* content_layout = new QHBoxLayout(content); |
45 | 46 |
46 paragraph = new Paragraph(data, this); | 47 paragraph = new Paragraph(data, this); |
47 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | 48 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); |
48 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | 49 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); |
49 paragraph->setWordWrapMode(QTextOption::NoWrap); | 50 paragraph->setWordWrapMode(QTextOption::NoWrap); |
50 | 51 |
51 content->layout()->addWidget(paragraph); | 52 content_layout->addWidget(paragraph); |
52 content->layout()->setSpacing(0); | 53 content_layout->setSpacing(0); |
53 content->layout()->setContentsMargins(0, 0, 0, 0); | 54 content_layout->setContentsMargins(0, 0, 0, 0); |
54 content->setContentsMargins(12, 0, 0, 0); | 55 content->setContentsMargins(12, 0, 0, 0); |
55 | 56 |
56 layout()->addWidget(header); | 57 layout->addWidget(header); |
57 layout()->addWidget(paragraph); | 58 layout->addWidget(paragraph); |
58 layout()->setSpacing(0); | 59 layout->setSpacing(0); |
59 layout()->setContentsMargins(0, 0, 0, 0); | 60 layout->setContentsMargins(0, 0, 0, 0); |
60 } | 61 } |
61 | 62 |
62 Header* TextParagraph::GetHeader() { | 63 Header* TextParagraph::GetHeader() { |
63 return header; | 64 return header; |
64 } | 65 } |
67 return paragraph; | 68 return paragraph; |
68 } | 69 } |
69 | 70 |
70 LabelledTextParagraph::LabelledTextParagraph(QString title, QString label, QString data, QWidget* parent) | 71 LabelledTextParagraph::LabelledTextParagraph(QString title, QString label, QString data, QWidget* parent) |
71 : QWidget(parent) { | 72 : QWidget(parent) { |
72 setLayout(new QVBoxLayout); | 73 QVBoxLayout* layout = new QVBoxLayout(this); |
73 | 74 |
74 header = new Header(title, this); | 75 header = new Header(title, this); |
75 | 76 |
76 // this is not accessible from the object because there's really | 77 // this is not accessible from the object because there's really |
77 // no reason to make it accessible... | 78 // no reason to make it accessible... |
95 content_layout->setSpacing(20); | 96 content_layout->setSpacing(20); |
96 content_layout->setContentsMargins(0, 0, 0, 0); | 97 content_layout->setContentsMargins(0, 0, 0, 0); |
97 | 98 |
98 content->setContentsMargins(12, 0, 0, 0); | 99 content->setContentsMargins(12, 0, 0, 0); |
99 | 100 |
100 layout()->addWidget(header); | 101 layout->addWidget(header); |
101 layout()->addWidget(content); | 102 layout->addWidget(content); |
102 layout()->setSpacing(0); | 103 layout->setSpacing(0); |
103 layout()->setContentsMargins(0, 0, 0, 0); | 104 layout->setContentsMargins(0, 0, 0, 0); |
104 } | 105 } |
105 | 106 |
106 Header* LabelledTextParagraph::GetHeader() { | 107 Header* LabelledTextParagraph::GetHeader() { |
107 return header; | 108 return header; |
108 } | 109 } |
114 Paragraph* LabelledTextParagraph::GetParagraph() { | 115 Paragraph* LabelledTextParagraph::GetParagraph() { |
115 return paragraph; | 116 return paragraph; |
116 } | 117 } |
117 | 118 |
118 SelectableTextParagraph::SelectableTextParagraph(QString title, QString data, QWidget* parent) : QWidget(parent) { | 119 SelectableTextParagraph::SelectableTextParagraph(QString title, QString data, QWidget* parent) : QWidget(parent) { |
119 setLayout(new QVBoxLayout); | 120 QVBoxLayout* layout = new QVBoxLayout(this); |
120 | 121 |
121 header = new Header(title, this); | 122 header = new Header(title, this); |
122 | 123 |
123 QWidget* content = new QWidget(this); | 124 QWidget* content = new QWidget(this); |
124 content->setLayout(new QHBoxLayout); | 125 QHBoxLayout* content_layout = new QHBoxLayout(content); |
125 | 126 |
126 paragraph = new Paragraph(data, content); | 127 paragraph = new Paragraph(data, content); |
127 | 128 |
128 content->layout()->addWidget(paragraph); | 129 content_layout->addWidget(paragraph); |
129 content->layout()->setSpacing(0); | 130 content_layout->setSpacing(0); |
130 content->layout()->setContentsMargins(0, 0, 0, 0); | 131 content_layout->setContentsMargins(0, 0, 0, 0); |
131 content->setContentsMargins(12, 0, 0, 0); | 132 content->setContentsMargins(12, 0, 0, 0); |
132 | 133 |
133 layout()->addWidget(header); | 134 layout->addWidget(header); |
134 layout()->addWidget(content); | 135 layout->addWidget(content); |
135 layout()->setSpacing(0); | 136 layout->setSpacing(0); |
136 layout()->setContentsMargins(0, 0, 0, 0); | 137 layout->setContentsMargins(0, 0, 0, 0); |
137 } | 138 } |
138 | 139 |
139 Header* SelectableTextParagraph::GetHeader() { | 140 Header* SelectableTextParagraph::GetHeader() { |
140 return header; | 141 return header; |
141 } | 142 } |
156 setPalette(pal); | 157 setPalette(pal); |
157 | 158 |
158 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | 159 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); |
159 } | 160 } |
160 | 161 |
162 void Paragraph::SetText(QString text) { | |
163 QTextDocument* document = new QTextDocument(this); | |
164 document->setDocumentLayout(new QPlainTextDocumentLayout(document)); | |
165 document->setPlainText(text); | |
166 setDocument(document); | |
167 } | |
168 | |
161 /* highly based upon... some stackoverflow answer for PyQt */ | 169 /* highly based upon... some stackoverflow answer for PyQt */ |
162 QSize Paragraph::minimumSizeHint() const { | 170 QSize Paragraph::minimumSizeHint() const { |
171 return QSize(0, 0); | |
172 } | |
173 | |
174 QSize Paragraph::sizeHint() const { | |
163 QTextDocument* doc = document(); | 175 QTextDocument* doc = document(); |
164 doc->adjustSize(); | 176 doc->adjustSize(); |
165 long h = 0; | 177 long h = 0; |
166 for (QTextBlock line = doc->begin(); line != doc->end(); line = line.next()) { | 178 for (QTextBlock line = doc->begin(); line != doc->end(); line = line.next()) { |
167 h += doc->documentLayout()->blockBoundingRect(line).height(); | 179 h += doc->documentLayout()->blockBoundingRect(line).height(); |
168 } | 180 } |
169 return QSize(doc->size().width(), h); | 181 return QSize(doc->size().width(), h); |
170 } | 182 } |
171 | 183 |
172 QSize Paragraph::sizeHint() const { | 184 Title::Title(QString title, QWidget* parent) : Paragraph(title, parent) { |
173 return minimumSizeHint(); | 185 setReadOnly(true); |
174 } | 186 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
175 | 187 setWordWrapMode(QTextOption::NoWrap); |
176 /* this is still actually useful, so we'll keep it */ | 188 setFrameShape(QFrame::NoFrame); |
177 void SetPlainTextEditData(QPlainTextEdit* text_edit, QString data) { | 189 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
178 QTextDocument* document = new QTextDocument(text_edit); | 190 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
179 document->setDocumentLayout(new QPlainTextDocumentLayout(document)); | 191 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
180 document->setPlainText(data); | 192 |
181 text_edit->setDocument(document); | 193 QFont fnt(font()); |
194 fnt.setPointSize(12); | |
195 setFont(fnt); | |
196 | |
197 QPalette pal(palette()); | |
198 pal.setColor(QPalette::Window, Qt::transparent); | |
199 pal.setColor(QPalette::Text, QColor(0x00, 0x33, 0x99)); | |
200 setPalette(pal); | |
182 } | 201 } |
183 | 202 |
184 } // namespace TextWidgets | 203 } // namespace TextWidgets |
185 | 204 |
186 #include "gui/widgets/moc_text.cpp" | 205 #include "gui/widgets/moc_text.cpp" |