Mercurial > minori
comparison src/gui/widgets/text.cpp @ 46:d0adc4aedfc8
*: update...
this commit:
1. consolidates dark theme stuff to dark_theme.cpp
2. creates a new widgets folder to store all of our
custom widgets
3. creates the list settings page in the information
dialog, although much of it is nonfunctional: it
doesn't save, and the status doesn't even get filled
in... we'll fix this later!
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sat, 23 Sep 2023 01:02:15 -0400 |
parents | |
children | f4bea5ef5b8a |
comparison
equal
deleted
inserted
replaced
45:4b05bc7668eb | 46:d0adc4aedfc8 |
---|---|
1 #include "gui/widgets/text.h" | |
2 #include "core/session.h" | |
3 #include <QFrame> | |
4 #include <QLabel> | |
5 #include <QPixmap> | |
6 #include <QTextBlock> | |
7 #include <QVBoxLayout> | |
8 | |
9 namespace TextWidgets { | |
10 | |
11 Header::Header(QString title, QWidget* parent) : QWidget(parent) { | |
12 setLayout(new QVBoxLayout); | |
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 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 | |
27 layout()->addWidget(static_text_title); | |
28 layout()->addWidget(static_text_line); | |
29 layout()->setSpacing(0); | |
30 layout()->setMargin(0); | |
31 } | |
32 | |
33 void Header::SetTitle(QString title) { | |
34 static_text_title->setText(title); | |
35 } | |
36 | |
37 TextParagraph::TextParagraph(QString title, QString data, QWidget* parent) : QWidget(parent) { | |
38 setLayout(new QVBoxLayout); | |
39 | |
40 header = new Header(title, this); | |
41 | |
42 QWidget* content = new QWidget(this); | |
43 content->setLayout(new QHBoxLayout); | |
44 | |
45 paragraph = new Paragraph(data, this); | |
46 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | |
47 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
48 paragraph->setWordWrapMode(QTextOption::NoWrap); | |
49 | |
50 content->layout()->addWidget(paragraph); | |
51 content->layout()->setSpacing(0); | |
52 content->layout()->setMargin(0); | |
53 content->setContentsMargins(12, 0, 0, 0); | |
54 | |
55 layout()->addWidget(header); | |
56 layout()->addWidget(paragraph); | |
57 layout()->setSpacing(0); | |
58 layout()->setMargin(0); | |
59 } | |
60 | |
61 Header* TextParagraph::GetHeader() { | |
62 return header; | |
63 } | |
64 | |
65 Paragraph* TextParagraph::GetParagraph() { | |
66 return paragraph; | |
67 } | |
68 | |
69 LabelledTextParagraph::LabelledTextParagraph(QString title, QString label, QString data, QWidget* parent) | |
70 : QWidget(parent) { | |
71 setLayout(new QVBoxLayout); | |
72 | |
73 header = new Header(title, this); | |
74 | |
75 // this is not accessible from the object because there's really | |
76 // no reason to make it accessible... | |
77 QWidget* content = new QWidget(this); | |
78 content->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | |
79 | |
80 labels = new Paragraph(label, this); | |
81 labels->setTextInteractionFlags(Qt::NoTextInteraction); | |
82 labels->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
83 labels->setWordWrapMode(QTextOption::NoWrap); | |
84 labels->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | |
85 labels->setFixedWidth(123); | |
86 | |
87 paragraph = new Paragraph(data, this); | |
88 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | |
89 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
90 paragraph->setWordWrapMode(QTextOption::NoWrap); | |
91 | |
92 QHBoxLayout* content_layout = new QHBoxLayout; | |
93 content_layout->addWidget(labels, 0, Qt::AlignTop); | |
94 content_layout->addWidget(paragraph, 0, Qt::AlignTop); | |
95 content_layout->setSpacing(0); | |
96 content_layout->setMargin(0); | |
97 content->setLayout(content_layout); | |
98 | |
99 content->setContentsMargins(12, 0, 0, 0); | |
100 | |
101 layout()->addWidget(header); | |
102 layout()->addWidget(content); | |
103 layout()->setSpacing(0); | |
104 layout()->setMargin(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 setLayout(new QVBoxLayout); | |
121 | |
122 header = new Header(title, this); | |
123 | |
124 QWidget* content = new QWidget(this); | |
125 content->setLayout(new QHBoxLayout); | |
126 | |
127 paragraph = new Paragraph(data, content); | |
128 | |
129 content->layout()->addWidget(paragraph); | |
130 content->layout()->setSpacing(0); | |
131 content->layout()->setMargin(0); | |
132 content->setContentsMargins(12, 0, 0, 0); | |
133 | |
134 layout()->addWidget(header); | |
135 layout()->addWidget(content); | |
136 layout()->setSpacing(0); | |
137 layout()->setMargin(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 */ | |
149 Paragraph::Paragraph(QString text, QWidget* parent) : QPlainTextEdit(text, parent) { | |
150 setReadOnly(true); | |
151 setTextInteractionFlags(Qt::TextBrowserInteraction); | |
152 setFrameShape(QFrame::NoFrame); | |
153 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
154 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
155 | |
156 QPalette pal; | |
157 pal.setColor(QPalette::Window, QColor(0, 0, 0, 0)); | |
158 setPalette(pal); | |
159 | |
160 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | |
161 } | |
162 | |
163 /* highly based upon... some stackoverflow answer for PyQt */ | |
164 QSize Paragraph::minimumSizeHint() const { | |
165 QTextDocument* doc = document(); | |
166 long h = (long)(blockBoundingGeometry(doc->findBlockByNumber(doc->blockCount() - 1)).bottom() + | |
167 (2 * doc->documentMargin())); | |
168 return QSize(QPlainTextEdit::sizeHint().width(), h); | |
169 } | |
170 | |
171 QSize Paragraph::sizeHint() const { | |
172 return minimumSizeHint(); | |
173 } | |
174 | |
175 /* this is still actually useful, so we'll keep it */ | |
176 void SetPlainTextEditData(QPlainTextEdit* text_edit, QString data) { | |
177 QTextDocument* document = new QTextDocument(text_edit); | |
178 document->setDocumentLayout(new QPlainTextDocumentLayout(document)); | |
179 document->setPlainText(data); | |
180 text_edit->setDocument(document); | |
181 } | |
182 | |
183 } // namespace TextWidgets | |
184 | |
185 #include "gui/widgets/moc_text.cpp" |