annotate include/gui/widgets/text.h @ 348:6b0768158dcd

text: redesign almost every widget i.e. Paragraph is now a QLabel, etc etc, some things will probably break, idc
author Paper <paper@paper.us.eu.org>
date Tue, 25 Jun 2024 11:19:54 -0400
parents b82841e76e79
children f81bed4e04ac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
261
3ec7804abf17 include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
1 #ifndef MINORI_GUI_WIDGETS_TEXT_H_
3ec7804abf17 include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
2 #define MINORI_GUI_WIDGETS_TEXT_H_
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
3
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
4 #include <QLineEdit>
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
5 #include <QPlainTextEdit>
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 64
diff changeset
6 #include <QSize>
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 75
diff changeset
7 #include <QWidget>
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
8 #include <QLabel>
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
9 #include <QVBoxLayout>
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
10 #include <QPointer>
69
27a19dd6cba1 *: fix up some stuff
Paper <mrpapersonic@gmail.com>
parents: 64
diff changeset
11
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
12 #include <memory>
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
13 #include <unordered_map>
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
14
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 namespace TextWidgets {
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
17 /* These used to have getter methods to get the real Qt widgets;
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
18 * don't make those anymore. Instead, add new methods that are
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
19 * wrappers around the Qt methods instead. */
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
20
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 class Header : public QWidget {
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 253
diff changeset
22 Q_OBJECT
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 253
diff changeset
24 public:
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
25 Header(QWidget* parent = nullptr);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
26 void SetText(const std::string& title);
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
28 protected:
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
29 QPointer<QLabel> title_;
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
30 QPointer<QFrame> separator_;
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31 };
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
33 /* This is a nice clean wrapper around Label suitable for our needs. */
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
34 class Paragraph : public QWidget {
253
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 95
diff changeset
35 Q_OBJECT
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
36
253
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 95
diff changeset
37 public:
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
38 Paragraph(QWidget* parent = nullptr);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
39 void SetText(const std::string& text);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
40 void SetSelectable(bool enable);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
41 void SetWordWrap(bool enable);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
42 void SetElidingMode(bool enable);
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
43
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
44 protected:
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
45 QPointer<QLabel> label_;
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
46 };
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
47
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
48 /* This aligns data with labels */
253
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 95
diff changeset
49 class LabelledParagraph final : public QWidget {
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 95
diff changeset
50 Q_OBJECT
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 95
diff changeset
51
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 95
diff changeset
52 public:
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
53 enum Style {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
54 BoldedLabels = (1 << 1),
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
55 ElidedData = (1 << 2), /* does nothing for now */
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
56 };
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
57
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
58 LabelledParagraph(QWidget* parent = nullptr);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
59 ~LabelledParagraph();
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
60 void SetData(const std::vector<std::pair<std::string, std::string>>& data);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
61 void SetStyle(int style); /* bit-flags from Style enum */
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
62 void Clear(void);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
63
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
64 protected:
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
65 QPointer<QWidget> contents_;
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
66 QPointer<QGridLayout> contents_layout_;
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
67
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
68 std::vector<std::pair<QSharedPointer<QLabel>, QSharedPointer<QLabel>>> data_;
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
69 };
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
70
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
71 /* this is just a generic QLabel with a specific font and foreground role,
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
72 * which is why it's defined inline */
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
73 class Title final : public Paragraph {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
74 public:
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
75 Title(QWidget* parent = nullptr) : Paragraph(parent) {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
76 QFont fnt(label_->font());
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
77 fnt.setPixelSize(16);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
78 label_->setFont(fnt);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
79
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
80 label_->setForegroundRole(QPalette::Highlight);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
81 }
253
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 95
diff changeset
82 };
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 95
diff changeset
83
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
84 /* ----------------------------------------------------------------------- */
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
85 /* Generic "Section" widget */
253
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 95
diff changeset
86
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
87 template<typename T>
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
88 class Section final : public QWidget {
253
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 95
diff changeset
89 public:
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
90 Section(QWidget* parent = nullptr) : QWidget(parent) {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
91 header_ = new Header(this);
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 261
diff changeset
92
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
93 content_container_ = new QWidget(this);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
94 content_ = new T(content_container_);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
95
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
96 QVBoxLayout* content_layout = new QVBoxLayout(content_container_);
75
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 69
diff changeset
97
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
98 content_layout->addWidget(content_);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
99 content_layout->setSpacing(0);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
100 content_layout->setContentsMargins(12, 0, 0, 0);
75
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 69
diff changeset
101
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
102 content_container_->setContentsMargins(0, 0, 0, 0);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
103
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
104 content_container_->setLayout(content_layout);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
105
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
106 QVBoxLayout* layout = new QVBoxLayout(this);
75
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 69
diff changeset
107
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
108 layout->addWidget(header_);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
109 layout->addWidget(content_container_);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
110 layout->setSpacing(0);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
111 layout->setContentsMargins(0, 0, 0, 0);
75
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 69
diff changeset
112
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
113 setLayout(layout);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
114 }
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
115
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
116 Header& GetHeader() { return *header_; }
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
117 T& GetContent() { return *content_; }
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
118
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 253
diff changeset
119 private:
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
120 Header* header_;
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
121 T* content_;
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
122
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
123 /* I don't think making a separate container
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
124 * widget is necessary anymore, but I'm paranoid */
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
125 QWidget* content_container_;
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
126 };
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
127
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
128 /* Old aliases used when the sections weren't templateized.
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
129 *
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
130 * These are kept to keep old code working and can largely
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
131 * be ignored for anything new.
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
132 *
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
133 * SelectableSection is actually just a generic "long text" */
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
134 using LabelledSection = Section<LabelledParagraph>;
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
135 using SelectableSection = Section<Paragraph>;
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
136 using OneLineSection = Section<Paragraph>;
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
137
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
138 } // namespace TextWidgets
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
139
261
3ec7804abf17 include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
140 #endif // MINORI_GUI_WIDGETS_TEXT_H_