Mercurial > minori
annotate src/gui/widgets/text.cpp @ 76:3364fadc8a36
*: format source code
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Wed, 04 Oct 2023 01:46:33 -0400 |
| parents | d3e9310598b1 |
| children | 6f7385bd334c |
| rev | line source |
|---|---|
| 46 | 1 #include "gui/widgets/text.h" |
| 2 #include "core/session.h" | |
| 3 #include <QFrame> | |
| 4 #include <QLabel> | |
| 5 #include <QTextBlock> | |
| 6 #include <QVBoxLayout> | |
| 7 | |
| 8 namespace TextWidgets { | |
| 9 | |
| 10 Header::Header(QString title, QWidget* parent) : QWidget(parent) { | |
| 64 | 11 QVBoxLayout* layout = new QVBoxLayout(this); |
| 46 | 12 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); |
| 13 | |
| 14 static_text_title = new QLabel(title, this); | |
| 15 static_text_title->setTextFormat(Qt::PlainText); | |
| 16 QFont font = static_text_title->font(); | |
| 17 font.setWeight(QFont::Bold); | |
| 18 static_text_title->setFont(font); | |
| 64 | 19 /* FIXME: is this needed? */ |
| 46 | 20 static_text_title->setFixedHeight(16); |
| 21 | |
| 22 static_text_line = new QFrame(this); | |
| 23 static_text_line->setFrameShape(QFrame::HLine); | |
| 24 static_text_line->setFrameShadow(QFrame::Sunken); | |
| 25 static_text_line->setFixedHeight(2); | |
| 26 | |
| 64 | 27 layout->addWidget(static_text_title); |
| 28 layout->addWidget(static_text_line); | |
| 29 layout->setSpacing(0); | |
| 30 layout->setContentsMargins(0, 0, 0, 0); | |
| 46 | 31 } |
| 32 | |
| 64 | 33 void Header::SetText(QString text) { |
| 34 static_text_title->setText(text); | |
| 46 | 35 } |
| 36 | |
| 75 | 37 /* inherits QPlainTextEdit and gives a much more reasonable minimum size */ |
| 38 Paragraph::Paragraph(QString text, QWidget* parent) : QPlainTextEdit(text, parent) { | |
| 39 setTextInteractionFlags(Qt::TextBrowserInteraction); | |
| 40 setFrameShape(QFrame::NoFrame); | |
| 41 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
| 42 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
| 43 | |
| 44 QPalette pal; | |
| 45 pal.setColor(QPalette::Window, Qt::transparent); | |
| 46 setPalette(pal); | |
| 47 | |
| 48 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | |
| 49 } | |
| 50 | |
| 51 void Paragraph::SetText(QString text) { | |
| 52 QTextDocument* document = new QTextDocument(this); | |
| 53 document->setDocumentLayout(new QPlainTextDocumentLayout(document)); | |
| 54 document->setPlainText(text); | |
| 55 setDocument(document); | |
| 56 } | |
| 57 | |
| 58 /* highly based upon... some stackoverflow answer for PyQt */ | |
| 59 QSize Paragraph::minimumSizeHint() const { | |
| 60 return QSize(0, 0); | |
| 61 } | |
| 62 | |
| 63 QSize Paragraph::sizeHint() const { | |
| 64 QTextDocument* doc = document(); | |
| 65 doc->adjustSize(); | |
| 66 long h = 0; | |
| 67 for (QTextBlock line = doc->begin(); line != doc->end(); line = line.next()) { | |
| 68 h += doc->documentLayout()->blockBoundingRect(line).height(); | |
| 69 } | |
| 70 return QSize(doc->size().width(), h); | |
| 71 } | |
| 72 | |
| 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); | |
| 78 setReadOnly(true); | |
| 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" |
