Mercurial > minori
annotate src/gui/widgets/text.cc @ 101:c537996cf67b
*: multitude of config changes
1. theme is now configurable from the settings menu
(but you have to restart for it to apply)
2. config is now stored in an INI file, with no method of
conversion from json (this repo is private-ish anyway)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 03 Nov 2023 14:06:02 -0400 |
parents | 18979b066284 |
children | b315f3759c56 |
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 | |
83 | 11 Header::Header(const 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 | |
83 | 32 void Header::SetText(const QString& text) { |
64 | 33 static_text_title->setText(text); |
83 | 34 updateGeometry(); |
46 | 35 } |
36 | |
75 | 37 /* inherits QPlainTextEdit and gives a much more reasonable minimum size */ |
83 | 38 Paragraph::Paragraph(const QString& text, QWidget* parent) : QPlainTextEdit(text, parent) { |
75 | 39 setTextInteractionFlags(Qt::TextBrowserInteraction); |
40 setFrameShape(QFrame::NoFrame); | |
41 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
42 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
43 | |
44 QPalette pal; | |
86 | 45 pal.setColor(QPalette::Base, Qt::transparent); |
75 | 46 setPalette(pal); |
47 | |
48 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | |
49 } | |
50 | |
83 | 51 void Paragraph::SetText(const QString& text) { |
75 | 52 QTextDocument* document = new QTextDocument(this); |
53 document->setDocumentLayout(new QPlainTextDocumentLayout(document)); | |
54 document->setPlainText(text); | |
55 setDocument(document); | |
83 | 56 updateGeometry(); |
75 | 57 } |
58 | |
59 /* highly based upon... some stackoverflow answer for PyQt */ | |
60 QSize Paragraph::minimumSizeHint() const { | |
61 return QSize(0, 0); | |
62 } | |
63 | |
64 QSize Paragraph::sizeHint() const { | |
65 QTextDocument* doc = document(); | |
66 doc->adjustSize(); | |
67 long h = 0; | |
68 for (QTextBlock line = doc->begin(); line != doc->end(); line = line.next()) { | |
69 h += doc->documentLayout()->blockBoundingRect(line).height(); | |
70 } | |
71 return QSize(doc->size().width(), h); | |
72 } | |
73 | |
74 /* Equivalent to Paragraph(), but is only capable of showing one line. Only | |
97
18979b066284
animia/unix: fix a bunch of stuff that breaks OS X things
Paper <mrpapersonic@gmail.com>
parents:
87
diff
changeset
|
75 exists because with SelectableSection it will let you go |
18979b066284
animia/unix: fix a bunch of stuff that breaks OS X things
Paper <mrpapersonic@gmail.com>
parents:
87
diff
changeset
|
76 out of bounds and that looks really fugly for most things */ |
83 | 77 Line::Line(QWidget* parent) : QLineEdit(parent) { |
75 | 78 setFrame(false); |
79 setReadOnly(true); | |
87
4aef97f4d998
information: use QGridLayout please...
Paper <mrpapersonic@gmail.com>
parents:
86
diff
changeset
|
80 setCursor(Qt::IBeamCursor); |
75 | 81 |
82 QPalette pal; | |
86 | 83 pal.setColor(QPalette::Base, Qt::transparent); |
75 | 84 setPalette(pal); |
85 | |
86 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | |
87 } | |
88 | |
83 | 89 Line::Line(const QString& text, QWidget* parent) : Line(parent) { |
90 SetText(text); | |
91 } | |
92 | |
93 void Line::SetText(const QString& text) { | |
94 setText(text); | |
95 setCursorPosition(0); /* displays left text first */ | |
96 } | |
97 | |
98 Title::Title(const QString& title, QWidget* parent) : Line(title, parent) { | |
75 | 99 QFont fnt(font()); |
100 fnt.setPixelSize(16); | |
101 setFont(fnt); | |
102 | |
103 QPalette pal(palette()); | |
86 | 104 pal.setColor(QPalette::Text, Qt::blue); |
75 | 105 setPalette(pal); |
106 } | |
107 | |
83 | 108 Section::Section(const QString& title, const QString& data, QWidget* parent) : QWidget(parent) { |
64 | 109 QVBoxLayout* layout = new QVBoxLayout(this); |
46 | 110 |
111 header = new Header(title, this); | |
112 | |
113 QWidget* content = new QWidget(this); | |
64 | 114 QHBoxLayout* content_layout = new QHBoxLayout(content); |
46 | 115 |
116 paragraph = new Paragraph(data, this); | |
117 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | |
118 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
119 paragraph->setWordWrapMode(QTextOption::NoWrap); | |
120 | |
64 | 121 content_layout->addWidget(paragraph); |
122 content_layout->setSpacing(0); | |
123 content_layout->setContentsMargins(0, 0, 0, 0); | |
46 | 124 content->setContentsMargins(12, 0, 0, 0); |
125 | |
64 | 126 layout->addWidget(header); |
127 layout->addWidget(paragraph); | |
128 layout->setSpacing(0); | |
129 layout->setContentsMargins(0, 0, 0, 0); | |
46 | 130 } |
131 | |
75 | 132 Header* Section::GetHeader() { |
46 | 133 return header; |
134 } | |
135 | |
75 | 136 Paragraph* Section::GetParagraph() { |
46 | 137 return paragraph; |
138 } | |
139 | |
83 | 140 LabelledSection::LabelledSection(const QString& title, const QString& label, const QString& data, QWidget* parent) : QWidget(parent) { |
64 | 141 QVBoxLayout* layout = new QVBoxLayout(this); |
46 | 142 |
143 header = new Header(title, this); | |
144 | |
145 // this is not accessible from the object because there's really | |
146 // no reason to make it accessible... | |
147 QWidget* content = new QWidget(this); | |
83 | 148 content->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); |
46 | 149 |
150 labels = new Paragraph(label, this); | |
151 labels->setTextInteractionFlags(Qt::NoTextInteraction); | |
152 labels->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
153 labels->setWordWrapMode(QTextOption::NoWrap); | |
83 | 154 labels->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding); |
46 | 155 |
156 paragraph = new Paragraph(data, this); | |
157 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | |
158 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
159 paragraph->setWordWrapMode(QTextOption::NoWrap); | |
83 | 160 paragraph->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
46 | 161 |
50
10868c3fb2be
text.cpp: set paragraph width from document, labelled texts are now...
Paper <mrpapersonic@gmail.com>
parents:
49
diff
changeset
|
162 QHBoxLayout* content_layout = new QHBoxLayout(content); |
46 | 163 content_layout->addWidget(labels, 0, Qt::AlignTop); |
164 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
|
165 content_layout->setSpacing(20); |
62 | 166 content_layout->setContentsMargins(0, 0, 0, 0); |
46 | 167 |
168 content->setContentsMargins(12, 0, 0, 0); | |
169 | |
64 | 170 layout->addWidget(header); |
171 layout->addWidget(content); | |
172 layout->setSpacing(0); | |
173 layout->setContentsMargins(0, 0, 0, 0); | |
46 | 174 } |
175 | |
75 | 176 Header* LabelledSection::GetHeader() { |
46 | 177 return header; |
178 } | |
179 | |
75 | 180 Paragraph* LabelledSection::GetLabels() { |
46 | 181 return labels; |
182 } | |
183 | |
75 | 184 Paragraph* LabelledSection::GetParagraph() { |
46 | 185 return paragraph; |
186 } | |
187 | |
83 | 188 SelectableSection::SelectableSection(const QString& title, const QString& data, QWidget* parent) : QWidget(parent) { |
64 | 189 QVBoxLayout* layout = new QVBoxLayout(this); |
46 | 190 |
191 header = new Header(title, this); | |
192 | |
193 QWidget* content = new QWidget(this); | |
64 | 194 QHBoxLayout* content_layout = new QHBoxLayout(content); |
46 | 195 |
196 paragraph = new Paragraph(data, content); | |
197 | |
64 | 198 content_layout->addWidget(paragraph); |
199 content_layout->setSpacing(0); | |
200 content_layout->setContentsMargins(0, 0, 0, 0); | |
46 | 201 content->setContentsMargins(12, 0, 0, 0); |
202 | |
64 | 203 layout->addWidget(header); |
204 layout->addWidget(content); | |
205 layout->setSpacing(0); | |
206 layout->setContentsMargins(0, 0, 0, 0); | |
46 | 207 } |
208 | |
75 | 209 Header* SelectableSection::GetHeader() { |
46 | 210 return header; |
211 } | |
212 | |
75 | 213 Paragraph* SelectableSection::GetParagraph() { |
46 | 214 return paragraph; |
215 } | |
216 | |
83 | 217 OneLineSection::OneLineSection(const QString& title, const QString& text, QWidget* parent) : QWidget(parent) { |
75 | 218 QVBoxLayout* layout = new QVBoxLayout(this); |
219 | |
220 header = new Header(title, this); | |
46 | 221 |
75 | 222 QWidget* content = new QWidget(this); |
223 QHBoxLayout* content_layout = new QHBoxLayout(content); | |
224 | |
225 line = new Line(text, content); | |
46 | 226 |
75 | 227 content_layout->addWidget(line); |
228 content_layout->setSpacing(0); | |
229 content_layout->setContentsMargins(0, 0, 0, 0); | |
230 content->setContentsMargins(12, 0, 0, 0); | |
46 | 231 |
75 | 232 layout->addWidget(header); |
233 layout->addWidget(content); | |
234 layout->setSpacing(0); | |
235 layout->setContentsMargins(0, 0, 0, 0); | |
64 | 236 } |
237 | |
75 | 238 Header* OneLineSection::GetHeader() { |
239 return header; | |
46 | 240 } |
241 | |
75 | 242 Line* OneLineSection::GetLine() { |
243 return line; | |
46 | 244 } |
245 | |
246 } // namespace TextWidgets | |
247 | |
248 #include "gui/widgets/moc_text.cpp" |