Mercurial > minori
comparison src/gui/widgets/text.cpp @ 75:d3e9310598b1
*: refactor some stuff
text: "TextParagraph"s are now called sections, because that's the
actual word for it :P
text: new classes: Line and OneLineSection, solves many problems with
paragraphs that are only one line long (ex. going out of bounds)
http: reworked http stuff to allow threaded get requests, also moved it
to its own file to (hopefully) remove clutter
eventually I'll make a threaded post request method and use that in
the "basic" function
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Wed, 04 Oct 2023 01:42:30 -0400 |
| parents | 5ccb99bfa605 |
| children | 3364fadc8a36 |
comparison
equal
deleted
inserted
replaced
| 74:5ccb99bfa605 | 75:d3e9310598b1 |
|---|---|
| 1 #include "gui/widgets/text.h" | 1 #include "gui/widgets/text.h" |
| 2 #include "core/session.h" | 2 #include "core/session.h" |
| 3 #include <QDebug> | |
| 4 #include <QFrame> | 3 #include <QFrame> |
| 5 #include <QLabel> | 4 #include <QLabel> |
| 6 #include <QPixmap> | |
| 7 #include <QTextBlock> | 5 #include <QTextBlock> |
| 8 #include <QVBoxLayout> | 6 #include <QVBoxLayout> |
| 9 | 7 |
| 10 namespace TextWidgets { | 8 namespace TextWidgets { |
| 11 | 9 |
| 34 | 32 |
| 35 void Header::SetText(QString text) { | 33 void Header::SetText(QString text) { |
| 36 static_text_title->setText(text); | 34 static_text_title->setText(text); |
| 37 } | 35 } |
| 38 | 36 |
| 39 TextParagraph::TextParagraph(QString title, QString data, QWidget* parent) : QWidget(parent) { | |
| 40 QVBoxLayout* layout = new QVBoxLayout(this); | |
| 41 | |
| 42 header = new Header(title, this); | |
| 43 | |
| 44 QWidget* content = new QWidget(this); | |
| 45 QHBoxLayout* content_layout = new QHBoxLayout(content); | |
| 46 | |
| 47 paragraph = new Paragraph(data, this); | |
| 48 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | |
| 49 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
| 50 paragraph->setWordWrapMode(QTextOption::NoWrap); | |
| 51 | |
| 52 content_layout->addWidget(paragraph); | |
| 53 content_layout->setSpacing(0); | |
| 54 content_layout->setContentsMargins(0, 0, 0, 0); | |
| 55 content->setContentsMargins(12, 0, 0, 0); | |
| 56 | |
| 57 layout->addWidget(header); | |
| 58 layout->addWidget(paragraph); | |
| 59 layout->setSpacing(0); | |
| 60 layout->setContentsMargins(0, 0, 0, 0); | |
| 61 } | |
| 62 | |
| 63 Header* TextParagraph::GetHeader() { | |
| 64 return header; | |
| 65 } | |
| 66 | |
| 67 Paragraph* TextParagraph::GetParagraph() { | |
| 68 return paragraph; | |
| 69 } | |
| 70 | |
| 71 LabelledTextParagraph::LabelledTextParagraph(QString title, QString label, QString data, QWidget* parent) | |
| 72 : QWidget(parent) { | |
| 73 QVBoxLayout* layout = new QVBoxLayout(this); | |
| 74 | |
| 75 header = new Header(title, this); | |
| 76 | |
| 77 // this is not accessible from the object because there's really | |
| 78 // no reason to make it accessible... | |
| 79 QWidget* content = new QWidget(this); | |
| 80 content->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | |
| 81 | |
| 82 labels = new Paragraph(label, this); | |
| 83 labels->setTextInteractionFlags(Qt::NoTextInteraction); | |
| 84 labels->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
| 85 labels->setWordWrapMode(QTextOption::NoWrap); | |
| 86 labels->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | |
| 87 | |
| 88 paragraph = new Paragraph(data, this); | |
| 89 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | |
| 90 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
| 91 paragraph->setWordWrapMode(QTextOption::NoWrap); | |
| 92 | |
| 93 QHBoxLayout* content_layout = new QHBoxLayout(content); | |
| 94 content_layout->addWidget(labels, 0, Qt::AlignTop); | |
| 95 content_layout->addWidget(paragraph, 0, Qt::AlignTop); | |
| 96 content_layout->setSpacing(20); | |
| 97 content_layout->setContentsMargins(0, 0, 0, 0); | |
| 98 | |
| 99 content->setContentsMargins(12, 0, 0, 0); | |
| 100 | |
| 101 layout->addWidget(header); | |
| 102 layout->addWidget(content); | |
| 103 layout->setSpacing(0); | |
| 104 layout->setContentsMargins(0, 0, 0, 0); | |
| 105 } | |
| 106 | |
| 107 Header* LabelledTextParagraph::GetHeader() { | |
| 108 return header; | |
| 109 } | |
| 110 | |
| 111 Paragraph* LabelledTextParagraph::GetLabels() { | |
| 112 return labels; | |
| 113 } | |
| 114 | |
| 115 Paragraph* LabelledTextParagraph::GetParagraph() { | |
| 116 return paragraph; | |
| 117 } | |
| 118 | |
| 119 SelectableTextParagraph::SelectableTextParagraph(QString title, QString data, QWidget* parent) : QWidget(parent) { | |
| 120 QVBoxLayout* layout = new QVBoxLayout(this); | |
| 121 | |
| 122 header = new Header(title, this); | |
| 123 | |
| 124 QWidget* content = new QWidget(this); | |
| 125 QHBoxLayout* content_layout = new QHBoxLayout(content); | |
| 126 | |
| 127 paragraph = new Paragraph(data, content); | |
| 128 | |
| 129 content_layout->addWidget(paragraph); | |
| 130 content_layout->setSpacing(0); | |
| 131 content_layout->setContentsMargins(0, 0, 0, 0); | |
| 132 content->setContentsMargins(12, 0, 0, 0); | |
| 133 | |
| 134 layout->addWidget(header); | |
| 135 layout->addWidget(content); | |
| 136 layout->setSpacing(0); | |
| 137 layout->setContentsMargins(0, 0, 0, 0); | |
| 138 } | |
| 139 | |
| 140 Header* SelectableTextParagraph::GetHeader() { | |
| 141 return header; | |
| 142 } | |
| 143 | |
| 144 Paragraph* SelectableTextParagraph::GetParagraph() { | |
| 145 return paragraph; | |
| 146 } | |
| 147 | |
| 148 /* inherits QPlainTextEdit and gives a much more reasonable minimum size */ | 37 /* inherits QPlainTextEdit and gives a much more reasonable minimum size */ |
| 149 Paragraph::Paragraph(QString text, QWidget* parent) : QPlainTextEdit(text, parent) { | 38 Paragraph::Paragraph(QString text, QWidget* parent) : QPlainTextEdit(text, parent) { |
| 150 setTextInteractionFlags(Qt::TextBrowserInteraction); | 39 setTextInteractionFlags(Qt::TextBrowserInteraction); |
| 151 setFrameShape(QFrame::NoFrame); | 40 setFrameShape(QFrame::NoFrame); |
| 152 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 41 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
| 153 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 42 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
| 154 | 43 |
| 155 QPalette pal; | 44 QPalette pal; |
| 156 pal.setColor(QPalette::Window, QColor(0, 0, 0, 0)); | 45 pal.setColor(QPalette::Window, Qt::transparent); |
| 157 setPalette(pal); | 46 setPalette(pal); |
| 158 | 47 |
| 159 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | 48 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); |
| 160 } | 49 } |
| 161 | 50 |
| 179 h += doc->documentLayout()->blockBoundingRect(line).height(); | 68 h += doc->documentLayout()->blockBoundingRect(line).height(); |
| 180 } | 69 } |
| 181 return QSize(doc->size().width(), h); | 70 return QSize(doc->size().width(), h); |
| 182 } | 71 } |
| 183 | 72 |
| 184 Title::Title(QString title, QWidget* parent) : Paragraph(title, parent) { | 73 /* Equivalent to Paragraph(), but is only capable of showing one line. Only |
| 74 exists because sometimes with SelectableSection it will let you go | |
| 75 out of bounds */ | |
| 76 Line::Line(QString text, QWidget* parent) : QLineEdit(text, parent) { | |
| 77 setFrame(false); | |
| 185 setReadOnly(true); | 78 setReadOnly(true); |
| 186 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 79 |
| 187 setWordWrapMode(QTextOption::NoWrap); | 80 QPalette pal; |
| 188 setFrameShape(QFrame::NoFrame); | 81 pal.setColor(QPalette::Window, Qt::transparent); |
| 82 setPalette(pal); | |
| 83 | |
| 189 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 84 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
| 190 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 85 } |
| 191 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 86 |
| 192 | 87 Title::Title(QString title, QWidget* parent) : Line(title, parent) { |
| 193 QFont fnt(font()); | 88 QFont fnt(font()); |
| 194 fnt.setPixelSize(16); | 89 fnt.setPixelSize(16); |
| 195 setFont(fnt); | 90 setFont(fnt); |
| 196 | 91 |
| 197 QPalette pal(palette()); | 92 QPalette pal(palette()); |
| 198 pal.setColor(QPalette::Window, Qt::transparent); | 93 pal.setColor(QPalette::Window, Qt::transparent); |
| 199 pal.setColor(QPalette::Text, QColor(0x00, 0x33, 0x99)); | 94 pal.setColor(QPalette::Text, QColor(0x00, 0x33, 0x99)); |
| 200 setPalette(pal); | 95 setPalette(pal); |
| 201 } | 96 } |
| 202 | 97 |
| 98 Section::Section(QString title, QString data, QWidget* parent) : QWidget(parent) { | |
| 99 QVBoxLayout* layout = new QVBoxLayout(this); | |
| 100 | |
| 101 header = new Header(title, this); | |
| 102 | |
| 103 QWidget* content = new QWidget(this); | |
| 104 QHBoxLayout* content_layout = new QHBoxLayout(content); | |
| 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 | |
| 111 content_layout->addWidget(paragraph); | |
| 112 content_layout->setSpacing(0); | |
| 113 content_layout->setContentsMargins(0, 0, 0, 0); | |
| 114 content->setContentsMargins(12, 0, 0, 0); | |
| 115 | |
| 116 layout->addWidget(header); | |
| 117 layout->addWidget(paragraph); | |
| 118 layout->setSpacing(0); | |
| 119 layout->setContentsMargins(0, 0, 0, 0); | |
| 120 } | |
| 121 | |
| 122 Header* Section::GetHeader() { | |
| 123 return header; | |
| 124 } | |
| 125 | |
| 126 Paragraph* Section::GetParagraph() { | |
| 127 return paragraph; | |
| 128 } | |
| 129 | |
| 130 LabelledSection::LabelledSection(QString title, QString label, QString data, QWidget* parent) | |
| 131 : QWidget(parent) { | |
| 132 QVBoxLayout* layout = new QVBoxLayout(this); | |
| 133 | |
| 134 header = new Header(title, this); | |
| 135 | |
| 136 // this is not accessible from the object because there's really | |
| 137 // no reason to make it accessible... | |
| 138 QWidget* content = new QWidget(this); | |
| 139 content->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | |
| 140 | |
| 141 labels = new Paragraph(label, this); | |
| 142 labels->setTextInteractionFlags(Qt::NoTextInteraction); | |
| 143 labels->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
| 144 labels->setWordWrapMode(QTextOption::NoWrap); | |
| 145 labels->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | |
| 146 | |
| 147 paragraph = new Paragraph(data, this); | |
| 148 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | |
| 149 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
| 150 paragraph->setWordWrapMode(QTextOption::NoWrap); | |
| 151 | |
| 152 QHBoxLayout* content_layout = new QHBoxLayout(content); | |
| 153 content_layout->addWidget(labels, 0, Qt::AlignTop); | |
| 154 content_layout->addWidget(paragraph, 0, Qt::AlignTop); | |
| 155 content_layout->setSpacing(20); | |
| 156 content_layout->setContentsMargins(0, 0, 0, 0); | |
| 157 | |
| 158 content->setContentsMargins(12, 0, 0, 0); | |
| 159 | |
| 160 layout->addWidget(header); | |
| 161 layout->addWidget(content); | |
| 162 layout->setSpacing(0); | |
| 163 layout->setContentsMargins(0, 0, 0, 0); | |
| 164 } | |
| 165 | |
| 166 Header* LabelledSection::GetHeader() { | |
| 167 return header; | |
| 168 } | |
| 169 | |
| 170 Paragraph* LabelledSection::GetLabels() { | |
| 171 return labels; | |
| 172 } | |
| 173 | |
| 174 Paragraph* LabelledSection::GetParagraph() { | |
| 175 return paragraph; | |
| 176 } | |
| 177 | |
| 178 SelectableSection::SelectableSection(QString title, QString data, QWidget* parent) : QWidget(parent) { | |
| 179 QVBoxLayout* layout = new QVBoxLayout(this); | |
| 180 | |
| 181 header = new Header(title, this); | |
| 182 | |
| 183 QWidget* content = new QWidget(this); | |
| 184 QHBoxLayout* content_layout = new QHBoxLayout(content); | |
| 185 | |
| 186 paragraph = new Paragraph(data, content); | |
| 187 | |
| 188 content_layout->addWidget(paragraph); | |
| 189 content_layout->setSpacing(0); | |
| 190 content_layout->setContentsMargins(0, 0, 0, 0); | |
| 191 content->setContentsMargins(12, 0, 0, 0); | |
| 192 | |
| 193 layout->addWidget(header); | |
| 194 layout->addWidget(content); | |
| 195 layout->setSpacing(0); | |
| 196 layout->setContentsMargins(0, 0, 0, 0); | |
| 197 } | |
| 198 | |
| 199 Header* SelectableSection::GetHeader() { | |
| 200 return header; | |
| 201 } | |
| 202 | |
| 203 Paragraph* SelectableSection::GetParagraph() { | |
| 204 return paragraph; | |
| 205 } | |
| 206 | |
| 207 OneLineSection::OneLineSection(QString title, QString text, QWidget* parent) : QWidget(parent) { | |
| 208 QVBoxLayout* layout = new QVBoxLayout(this); | |
| 209 | |
| 210 header = new Header(title, this); | |
| 211 | |
| 212 QWidget* content = new QWidget(this); | |
| 213 QHBoxLayout* content_layout = new QHBoxLayout(content); | |
| 214 | |
| 215 line = new Line(text, content); | |
| 216 | |
| 217 content_layout->addWidget(line); | |
| 218 content_layout->setSpacing(0); | |
| 219 content_layout->setContentsMargins(0, 0, 0, 0); | |
| 220 content->setContentsMargins(12, 0, 0, 0); | |
| 221 | |
| 222 layout->addWidget(header); | |
| 223 layout->addWidget(content); | |
| 224 layout->setSpacing(0); | |
| 225 layout->setContentsMargins(0, 0, 0, 0); | |
| 226 } | |
| 227 | |
| 228 Header* OneLineSection::GetHeader() { | |
| 229 return header; | |
| 230 } | |
| 231 | |
| 232 Line* OneLineSection::GetLine() { | |
| 233 return line; | |
| 234 } | |
| 235 | |
| 203 } // namespace TextWidgets | 236 } // namespace TextWidgets |
| 204 | 237 |
| 205 #include "gui/widgets/moc_text.cpp" | 238 #include "gui/widgets/moc_text.cpp" |
