Mercurial > minori
annotate src/gui/widgets/text.cc @ 81:9b2b41f83a5e
boring: mass rename to cc
because this is a very unix-y project, it makes more sense to use the
'cc' extension
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 23 Oct 2023 12:07:27 -0400 |
parents | src/gui/widgets/text.cpp@6f7385bd334c |
children | d02fdf1d6708 |
rev | line source |
---|---|
46 | 1 #include "gui/widgets/text.h" |
2 #include "core/session.h" | |
77 | 3 #include <QDebug> |
46 | 4 #include <QFrame> |
5 #include <QLabel> | |
6 #include <QTextBlock> | |
7 #include <QVBoxLayout> | |
8 | |
9 namespace TextWidgets { | |
10 | |
11 Header::Header(QString title, QWidget* parent) : QWidget(parent) { | |
64 | 12 QVBoxLayout* layout = new QVBoxLayout(this); |
46 | 13 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); |
14 | |
15 static_text_title = new QLabel(title, this); | |
16 static_text_title->setTextFormat(Qt::PlainText); | |
17 QFont font = static_text_title->font(); | |
18 font.setWeight(QFont::Bold); | |
19 static_text_title->setFont(font); | |
20 | |
21 static_text_line = new QFrame(this); | |
22 static_text_line->setFrameShape(QFrame::HLine); | |
23 static_text_line->setFrameShadow(QFrame::Sunken); | |
24 static_text_line->setFixedHeight(2); | |
25 | |
64 | 26 layout->addWidget(static_text_title); |
27 layout->addWidget(static_text_line); | |
28 layout->setSpacing(0); | |
29 layout->setContentsMargins(0, 0, 0, 0); | |
46 | 30 } |
31 | |
64 | 32 void Header::SetText(QString text) { |
33 static_text_title->setText(text); | |
46 | 34 } |
35 | |
75 | 36 /* inherits QPlainTextEdit and gives a much more reasonable minimum size */ |
37 Paragraph::Paragraph(QString text, QWidget* parent) : QPlainTextEdit(text, parent) { | |
38 setTextInteractionFlags(Qt::TextBrowserInteraction); | |
39 setFrameShape(QFrame::NoFrame); | |
40 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
41 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
42 | |
43 QPalette pal; | |
44 pal.setColor(QPalette::Window, Qt::transparent); | |
45 setPalette(pal); | |
46 | |
47 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | |
48 } | |
49 | |
50 void Paragraph::SetText(QString text) { | |
51 QTextDocument* document = new QTextDocument(this); | |
52 document->setDocumentLayout(new QPlainTextDocumentLayout(document)); | |
53 document->setPlainText(text); | |
54 setDocument(document); | |
55 } | |
56 | |
57 /* highly based upon... some stackoverflow answer for PyQt */ | |
58 QSize Paragraph::minimumSizeHint() const { | |
59 return QSize(0, 0); | |
60 } | |
61 | |
62 QSize Paragraph::sizeHint() const { | |
63 QTextDocument* doc = document(); | |
64 doc->adjustSize(); | |
65 long h = 0; | |
66 for (QTextBlock line = doc->begin(); line != doc->end(); line = line.next()) { | |
67 h += doc->documentLayout()->blockBoundingRect(line).height(); | |
68 } | |
69 return QSize(doc->size().width(), h); | |
70 } | |
71 | |
72 /* Equivalent to Paragraph(), but is only capable of showing one line. Only | |
73 exists because sometimes with SelectableSection it will let you go | |
74 out of bounds */ | |
75 Line::Line(QString text, QWidget* parent) : QLineEdit(text, parent) { | |
76 setFrame(false); | |
77 setReadOnly(true); | |
77 | 78 setCursorPosition(0); /* displays left text first */ |
75 | 79 |
80 QPalette pal; | |
81 pal.setColor(QPalette::Window, Qt::transparent); | |
82 setPalette(pal); | |
83 | |
84 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
85 } | |
86 | |
87 Title::Title(QString title, QWidget* parent) : Line(title, parent) { | |
88 QFont fnt(font()); | |
89 fnt.setPixelSize(16); | |
90 setFont(fnt); | |
91 | |
92 QPalette pal(palette()); | |
93 pal.setColor(QPalette::Window, Qt::transparent); | |
94 pal.setColor(QPalette::Text, QColor(0x00, 0x33, 0x99)); | |
95 setPalette(pal); | |
96 } | |
97 | |
98 Section::Section(QString title, QString data, QWidget* parent) : QWidget(parent) { | |
64 | 99 QVBoxLayout* layout = new QVBoxLayout(this); |
46 | 100 |
101 header = new Header(title, this); | |
102 | |
103 QWidget* content = new QWidget(this); | |
64 | 104 QHBoxLayout* content_layout = new QHBoxLayout(content); |
46 | 105 |
106 paragraph = new Paragraph(data, this); | |
107 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | |
108 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
109 paragraph->setWordWrapMode(QTextOption::NoWrap); | |
110 | |
64 | 111 content_layout->addWidget(paragraph); |
112 content_layout->setSpacing(0); | |
113 content_layout->setContentsMargins(0, 0, 0, 0); | |
46 | 114 content->setContentsMargins(12, 0, 0, 0); |
115 | |
64 | 116 layout->addWidget(header); |
117 layout->addWidget(paragraph); | |
118 layout->setSpacing(0); | |
119 layout->setContentsMargins(0, 0, 0, 0); | |
46 | 120 } |
121 | |
75 | 122 Header* Section::GetHeader() { |
46 | 123 return header; |
124 } | |
125 | |
75 | 126 Paragraph* Section::GetParagraph() { |
46 | 127 return paragraph; |
128 } | |
129 | |
76 | 130 LabelledSection::LabelledSection(QString title, QString label, QString data, QWidget* parent) : QWidget(parent) { |
64 | 131 QVBoxLayout* layout = new QVBoxLayout(this); |
46 | 132 |
133 header = new Header(title, this); | |
134 | |
135 // this is not accessible from the object because there's really | |
136 // no reason to make it accessible... | |
137 QWidget* content = new QWidget(this); | |
138 content->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | |
139 | |
140 labels = new Paragraph(label, this); | |
141 labels->setTextInteractionFlags(Qt::NoTextInteraction); | |
142 labels->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
143 labels->setWordWrapMode(QTextOption::NoWrap); | |
144 labels->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | |
145 | |
146 paragraph = new Paragraph(data, this); | |
147 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | |
148 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
149 paragraph->setWordWrapMode(QTextOption::NoWrap); | |
150 | |
50
10868c3fb2be
text.cpp: set paragraph width from document, labelled texts are now...
Paper <mrpapersonic@gmail.com>
parents:
49
diff
changeset
|
151 QHBoxLayout* content_layout = new QHBoxLayout(content); |
46 | 152 content_layout->addWidget(labels, 0, Qt::AlignTop); |
153 content_layout->addWidget(paragraph, 0, Qt::AlignTop); | |
50
10868c3fb2be
text.cpp: set paragraph width from document, labelled texts are now...
Paper <mrpapersonic@gmail.com>
parents:
49
diff
changeset
|
154 content_layout->setSpacing(20); |
62 | 155 content_layout->setContentsMargins(0, 0, 0, 0); |
46 | 156 |
157 content->setContentsMargins(12, 0, 0, 0); | |
158 | |
64 | 159 layout->addWidget(header); |
160 layout->addWidget(content); | |
161 layout->setSpacing(0); | |
162 layout->setContentsMargins(0, 0, 0, 0); | |
46 | 163 } |
164 | |
75 | 165 Header* LabelledSection::GetHeader() { |
46 | 166 return header; |
167 } | |
168 | |
75 | 169 Paragraph* LabelledSection::GetLabels() { |
46 | 170 return labels; |
171 } | |
172 | |
75 | 173 Paragraph* LabelledSection::GetParagraph() { |
46 | 174 return paragraph; |
175 } | |
176 | |
75 | 177 SelectableSection::SelectableSection(QString title, QString data, QWidget* parent) : QWidget(parent) { |
64 | 178 QVBoxLayout* layout = new QVBoxLayout(this); |
46 | 179 |
180 header = new Header(title, this); | |
181 | |
182 QWidget* content = new QWidget(this); | |
64 | 183 QHBoxLayout* content_layout = new QHBoxLayout(content); |
46 | 184 |
185 paragraph = new Paragraph(data, content); | |
186 | |
64 | 187 content_layout->addWidget(paragraph); |
188 content_layout->setSpacing(0); | |
189 content_layout->setContentsMargins(0, 0, 0, 0); | |
46 | 190 content->setContentsMargins(12, 0, 0, 0); |
191 | |
64 | 192 layout->addWidget(header); |
193 layout->addWidget(content); | |
194 layout->setSpacing(0); | |
195 layout->setContentsMargins(0, 0, 0, 0); | |
46 | 196 } |
197 | |
75 | 198 Header* SelectableSection::GetHeader() { |
46 | 199 return header; |
200 } | |
201 | |
75 | 202 Paragraph* SelectableSection::GetParagraph() { |
46 | 203 return paragraph; |
204 } | |
205 | |
75 | 206 OneLineSection::OneLineSection(QString title, QString text, QWidget* parent) : QWidget(parent) { |
207 QVBoxLayout* layout = new QVBoxLayout(this); | |
208 | |
209 header = new Header(title, this); | |
46 | 210 |
75 | 211 QWidget* content = new QWidget(this); |
212 QHBoxLayout* content_layout = new QHBoxLayout(content); | |
213 | |
214 line = new Line(text, content); | |
46 | 215 |
75 | 216 content_layout->addWidget(line); |
217 content_layout->setSpacing(0); | |
218 content_layout->setContentsMargins(0, 0, 0, 0); | |
219 content->setContentsMargins(12, 0, 0, 0); | |
46 | 220 |
75 | 221 layout->addWidget(header); |
222 layout->addWidget(content); | |
223 layout->setSpacing(0); | |
224 layout->setContentsMargins(0, 0, 0, 0); | |
64 | 225 } |
226 | |
75 | 227 Header* OneLineSection::GetHeader() { |
228 return header; | |
46 | 229 } |
230 | |
75 | 231 Line* OneLineSection::GetLine() { |
232 return line; | |
46 | 233 } |
234 | |
235 } // namespace TextWidgets | |
236 | |
237 #include "gui/widgets/moc_text.cpp" |