comparison src/gui/widgets/text.cc @ 253:b3549da699a6

*: ooooh! stupid big commit! oops
author Paper <paper@paper.us.eu.org>
date Tue, 06 Feb 2024 16:56:32 -0500
parents 4d461ef7d424
children 862d0d8619f6
comparison
equal deleted inserted replaced
252:a0eeb2cc7e6d 253:b3549da699a6
1 #include "gui/widgets/text.h" 1 #include "gui/widgets/text.h"
2 #include "core/session.h" 2 #include "core/session.h"
3
3 #include <QDebug> 4 #include <QDebug>
4 #include <QFrame> 5 #include <QFrame>
5 #include <QLabel> 6 #include <QLabel>
6 #include <QTextBlock> 7 #include <QTextBlock>
7 #include <QVBoxLayout> 8 #include <QVBoxLayout>
35 void Header::SetText(const QString& text) { 36 void Header::SetText(const QString& text) {
36 static_text_title->setText(text); 37 static_text_title->setText(text);
37 updateGeometry(); 38 updateGeometry();
38 } 39 }
39 40
40 /* inherits QPlainTextEdit and gives a much more reasonable minimum size */ 41 /* for now, this is a QLabel with a couple of default settings.
41 Paragraph::Paragraph(const QString& text, QWidget* parent) : QPlainTextEdit(text, parent) { 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) {
42 setTextInteractionFlags(Qt::TextBrowserInteraction); 47 setTextInteractionFlags(Qt::TextBrowserInteraction);
43 setFrameShape(QFrame::NoFrame); 48 setFrameShape(QFrame::NoFrame);
44 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 49 setCursor(Qt::IBeamCursor); /* emulate Taiga */
45 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 50 setWordWrap(true);
46 51
47 QPalette pal; 52 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
48 pal.setColor(QPalette::Base, Qt::transparent); 53 }
49 setPalette(pal); 54
50 55 /* kept here for legacy reasons, see explanation above */
51 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
52 }
53
54 void Paragraph::SetText(const QString& text) { 56 void Paragraph::SetText(const QString& text) {
55 QTextDocument* document = new QTextDocument(this); 57 setText(text);
56 document->setDocumentLayout(new QPlainTextDocumentLayout(document)); 58 }
57 document->setPlainText(text); 59
58 setDocument(document); 60 /* Equivalent to Paragraph(), but disables word wrap. */
59 updateGeometry(); 61 Line::Line(QWidget* parent) : Paragraph("", parent) {
60 } 62 setWordWrap(false);
61 63 }
62 /* highly based upon... some stackoverflow answer for PyQt */ 64
63 QSize Paragraph::minimumSizeHint() const { 65 Line::Line(const QString& text, QWidget* parent) : Paragraph(text, parent) {
64 return QSize(0, 0); 66 setWordWrap(false);
65 } 67 }
66 68
67 QSize Paragraph::sizeHint() const { 69 /* legacy function, don't use in new code */
68 QTextDocument* doc = document();
69 doc->adjustSize();
70 long h = 0;
71 for (QTextBlock line = doc->begin(); line != doc->end(); line = line.next()) {
72 h += doc->documentLayout()->blockBoundingRect(line).height();
73 }
74 return QSize(doc->size().width(), h);
75 }
76
77 /* Equivalent to Paragraph(), but is only capable of showing one line. Only
78 exists because with SelectableSection it will let you go
79 out of bounds and that looks really fugly for most things */
80 Line::Line(QWidget* parent) : QLineEdit(parent) {
81 setFrame(false);
82 setReadOnly(true);
83 setCursor(Qt::IBeamCursor);
84
85 QPalette pal;
86 pal.setColor(QPalette::Window, Qt::transparent);
87 pal.setColor(QPalette::Base, Qt::transparent);
88 setPalette(pal);
89
90 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
91 }
92
93 Line::Line(const QString& text, QWidget* parent) : Line(parent) {
94 SetText(text);
95 }
96
97 void Line::SetText(const QString& text) { 70 void Line::SetText(const QString& text) {
98 setText(text); 71 setText(text);
99 setCursorPosition(0); /* displays left text first */
100 } 72 }
101 73
102 Title::Title(const QString& title, QWidget* parent) : Line(title, parent) { 74 Title::Title(const QString& title, QWidget* parent) : Line(title, parent) {
103 QFont fnt(font()); 75 QFont fnt(font());
104 fnt.setPixelSize(16); 76 fnt.setPixelSize(16);
118 QHBoxLayout* content_layout = new QHBoxLayout(content); 90 QHBoxLayout* content_layout = new QHBoxLayout(content);
119 91
120 paragraph = new Paragraph(data, this); 92 paragraph = new Paragraph(data, this);
121 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); 93 paragraph->setTextInteractionFlags(Qt::NoTextInteraction);
122 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); 94 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents);
123 paragraph->setWordWrapMode(QTextOption::NoWrap); 95 paragraph->setWordWrap(QTextOption::NoWrap);
124 96
125 content_layout->addWidget(paragraph); 97 content_layout->addWidget(paragraph);
126 content_layout->setSpacing(0); 98 content_layout->setSpacing(0);
127 content_layout->setContentsMargins(0, 0, 0, 0); 99 content_layout->setContentsMargins(0, 0, 0, 0);
128 content->setContentsMargins(12, 0, 0, 0); 100 content->setContentsMargins(12, 0, 0, 0);
139 111
140 Paragraph* Section::GetParagraph() { 112 Paragraph* Section::GetParagraph() {
141 return paragraph; 113 return paragraph;
142 } 114 }
143 115
144 LabelledSection::LabelledSection(const QString& title, const QString& label, const QString& data, QWidget* parent) : QWidget(parent) { 116 LabelledParagraph::LabelledParagraph(const QString& label, const QString& data, QWidget* parent) : QWidget(parent) {
145 QVBoxLayout* layout = new QVBoxLayout(this); 117 QHBoxLayout* ly = new QHBoxLayout(this);
146
147 header = new Header(title, this);
148
149 // this is not accessible from the object because there's really
150 // no reason to make it accessible...
151 QWidget* content = new QWidget(this);
152 content->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
153 118
154 labels = new Paragraph(label, this); 119 labels = new Paragraph(label, this);
155 labels->setTextInteractionFlags(Qt::NoTextInteraction); 120 labels->setTextInteractionFlags(Qt::NoTextInteraction);
156 labels->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); 121 labels->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents);
157 labels->setWordWrapMode(QTextOption::NoWrap); 122 labels->setWordWrap(QTextOption::NoWrap);
158 labels->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding); 123 labels->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
159 124
160 paragraph = new Paragraph(data, this); 125 paragraph = new Paragraph(data, this);
161 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); 126 paragraph->setTextInteractionFlags(Qt::NoTextInteraction);
162 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); 127 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents);
163 paragraph->setWordWrapMode(QTextOption::NoWrap); 128 paragraph->setWordWrap(QTextOption::NoWrap);
164 paragraph->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); 129 paragraph->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
165 130
166 QHBoxLayout* content_layout = new QHBoxLayout(content); 131 ly->addWidget(labels, 0, Qt::AlignTop);
167 content_layout->addWidget(labels, 0, Qt::AlignTop); 132 ly->addWidget(paragraph, 0, Qt::AlignTop);
168 content_layout->addWidget(paragraph, 0, Qt::AlignTop); 133 ly->setSpacing(20);
169 content_layout->setSpacing(20); 134 ly->setContentsMargins(0, 0, 0, 0);
170 content_layout->setContentsMargins(0, 0, 0, 0); 135 }
171 136
137 Paragraph* LabelledParagraph::GetLabels() {
138 return labels;
139 }
140
141 Paragraph* LabelledParagraph::GetParagraph() {
142 return paragraph;
143 }
144
145 LabelledSection::LabelledSection(const QString& title, const QString& label, const QString& data, QWidget* parent) : QWidget(parent) {
146 QVBoxLayout* layout = new QVBoxLayout(this);
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...
152 content = new LabelledParagraph(label, data, this);
153 content->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
172 content->setContentsMargins(12, 0, 0, 0); 154 content->setContentsMargins(12, 0, 0, 0);
173 155
174 layout->addWidget(header); 156 layout->addWidget(header);
175 layout->addWidget(content); 157 layout->addWidget(content);
176 layout->setSpacing(0); 158 layout->setSpacing(0);
180 Header* LabelledSection::GetHeader() { 162 Header* LabelledSection::GetHeader() {
181 return header; 163 return header;
182 } 164 }
183 165
184 Paragraph* LabelledSection::GetLabels() { 166 Paragraph* LabelledSection::GetLabels() {
185 return labels; 167 return content->GetLabels();
186 } 168 }
187 169
188 Paragraph* LabelledSection::GetParagraph() { 170 Paragraph* LabelledSection::GetParagraph() {
189 return paragraph; 171 return content->GetParagraph();
190 } 172 }
191 173
192 SelectableSection::SelectableSection(const QString& title, const QString& data, QWidget* parent) : QWidget(parent) { 174 SelectableSection::SelectableSection(const QString& title, const QString& data, QWidget* parent) : QWidget(parent) {
193 QVBoxLayout* layout = new QVBoxLayout(this); 175 QVBoxLayout* layout = new QVBoxLayout(this);
194 176