Mercurial > minori
annotate src/gui/widgets/text.cc @ 365:f81bed4e04ac
*: megacommit that probably breaks things
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Wed, 02 Oct 2024 23:06:43 -0400 |
parents | 6b0768158dcd |
children |
rev | line source |
---|---|
46 | 1 #include "gui/widgets/text.h" |
2 #include "core/session.h" | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
3 #include "core/strings.h" |
253 | 4 |
77 | 5 #include <QDebug> |
46 | 6 #include <QFrame> |
7 #include <QLabel> | |
8 #include <QTextBlock> | |
9 #include <QVBoxLayout> | |
291 | 10 #include <QScrollArea> |
11 #include <QDebug> | |
365
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
12 #include <QPainter> |
291 | 13 |
46 | 14 namespace TextWidgets { |
15 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
16 /* Generic header meant to be used in conjunction with Section<T> */ |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
17 |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
18 Header::Header(QWidget* parent) |
291 | 19 : QWidget(parent) |
365
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
20 , title_(new QLabel) |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
21 , separator_(new QFrame) { |
64 | 22 QVBoxLayout* layout = new QVBoxLayout(this); |
46 | 23 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); |
24 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
25 title_->setTextFormat(Qt::PlainText); |
183
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
105
diff
changeset
|
26 |
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
105
diff
changeset
|
27 { |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
28 QFont font = title_->font(); |
183
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
105
diff
changeset
|
29 font.setWeight(QFont::Bold); |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
30 title_->setFont(font); |
183
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
105
diff
changeset
|
31 } |
46 | 32 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
33 separator_->setFrameShape(QFrame::HLine); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
34 separator_->setFrameShadow(QFrame::Sunken); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
35 separator_->setFixedHeight(2); |
46 | 36 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
37 layout->addWidget(title_.data()); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
38 layout->addWidget(separator_.data()); |
64 | 39 layout->setSpacing(0); |
40 layout->setContentsMargins(0, 0, 0, 0); | |
46 | 41 } |
42 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
43 void Header::SetText(const std::string& text) { |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
44 title_->setText(Strings::ToQString(text)); |
83 | 45 updateGeometry(); |
46 | 46 } |
47 | |
365
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
48 Label::Label(QWidget *parent) : QLabel(parent) {} |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
49 Label::Label(const QString &string, QWidget *parent) : QLabel(string, parent) {} |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
50 |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
51 void Label::SetElidingMode(bool elide) { |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
52 elide_ = elide; |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
53 update(); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
54 } |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
55 |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
56 void Label::paintEvent(QPaintEvent *event) { |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
57 if (elide_) { |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
58 /* bruh */ |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
59 if (wordWrap()) { |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
60 QFrame::paintEvent(event); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
61 |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
62 const QString content = text(); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
63 |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
64 QPainter painter(this); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
65 QFontMetrics fontMetrics = painter.fontMetrics(); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
66 |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
67 bool didElide = false; |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
68 int lineSpacing = fontMetrics.lineSpacing(); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
69 int y = 0; |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
70 |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
71 QTextLayout textLayout(content, painter.font()); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
72 textLayout.beginLayout(); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
73 for (;;) { |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
74 QTextLine line = textLayout.createLine(); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
75 |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
76 if (!line.isValid()) |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
77 break; |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
78 |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
79 line.setLineWidth(width()); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
80 int nextLineY = y + lineSpacing; |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
81 |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
82 if (height() >= nextLineY + lineSpacing) { |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
83 line.draw(&painter, QPoint(0, y)); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
84 y = nextLineY; |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
85 } else { |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
86 QString lastLine = content.mid(line.textStart()); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
87 QString elidedLastLine = fontMetrics.elidedText(lastLine, Qt::ElideRight, width()); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
88 painter.drawText(QPoint(0, y + fontMetrics.ascent()), elidedLastLine); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
89 line = textLayout.createLine(); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
90 didElide = line.isValid(); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
91 break; |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
92 } |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
93 } |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
94 textLayout.endLayout(); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
95 } else { |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
96 QString backup_text = QLabel::text(); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
97 |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
98 QFontMetrics metric(fontMetrics()); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
99 QString elided_text = metric.elidedText(backup_text, Qt::ElideRight, width()); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
100 |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
101 QLabel::setText(elided_text); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
102 QLabel::paintEvent(event); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
103 QLabel::setText(backup_text); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
104 } |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
105 } else { |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
106 /* QLabel can handle everything... */ |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
107 QLabel::paintEvent(event); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
108 } |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
109 } |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
110 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
111 /* ---------------------------------------------------------------------------------- */ |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
112 /* "Paragraph" widgets, as in widgets meant to hold a bunch of text. */ |
291 | 113 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
114 Paragraph::Paragraph(QWidget *parent) : QWidget(parent), label_(new QLabel) { |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
115 QVBoxLayout *layout = new QVBoxLayout(this); |
291 | 116 layout->setSpacing(0); |
117 layout->setContentsMargins(0, 0, 0, 0); | |
118 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
119 label_->setTextInteractionFlags(Qt::TextBrowserInteraction); |
291 | 120 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
121 /* defaults */ |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
122 SetWordWrap(true); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
123 SetSelectable(true); |
75 | 124 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
125 layout->addWidget(label_.data()); |
83 | 126 } |
127 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
128 void Paragraph::SetText(const std::string& text) { |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
129 label_->setText(Strings::ToQString(text)); |
83 | 130 } |
131 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
132 void Paragraph::SetSelectable(bool enable) { |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
133 label_->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents, !enable); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
134 label_->setCursor(enable ? Qt::IBeamCursor : Qt::ArrowCursor); |
75 | 135 } |
136 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
137 void Paragraph::SetWordWrap(bool enable) { |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
138 label_->setWordWrap(enable); |
46 | 139 } |
140 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
141 /* LabelledParagraph implementation */ |
46 | 142 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
143 LabelledParagraph::LabelledParagraph(QWidget* parent) |
291 | 144 : QWidget(parent) |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
145 , contents_(new QWidget) |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
146 , contents_layout_(new QGridLayout) { |
253 | 147 QHBoxLayout* ly = new QHBoxLayout(this); |
148 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
149 contents_layout_->setVerticalSpacing(1); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
150 contents_layout_->setHorizontalSpacing(20); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
151 contents_layout_->setContentsMargins(0, 0, 0, 0); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
152 contents_layout_->setColumnStretch(1, 0); |
253 | 153 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
154 contents_->setLayout(contents_layout_.data()); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
155 |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
156 ly->addWidget(contents_.data()); |
253 | 157 ly->setContentsMargins(0, 0, 0, 0); |
158 } | |
159 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
160 LabelledParagraph::~LabelledParagraph() { |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
161 data_.clear(); |
253 | 162 } |
163 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
164 void LabelledParagraph::Clear(void) { |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
165 for (auto& [label, data] : data_) { |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
166 contents_layout_->removeWidget(label.data()); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
167 contents_layout_->removeWidget(data.data()); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
168 } |
46 | 169 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
170 data_.clear(); |
46 | 171 } |
172 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
173 void LabelledParagraph::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
|
174 Clear(); |
46 | 175 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
176 data_.reserve(data.size()); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
177 for (std::size_t i = 0; i < data.size(); i++) { |
365
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
178 QSharedPointer<Label> first(new Label); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
179 QSharedPointer<Label> second(new Label); |
46 | 180 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
181 first->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
182 |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
183 first->setText(Strings::ToQString(data[i].first)); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
184 second->setText(Strings::ToQString(data[i].second)); |
46 | 185 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
186 data_.push_back({first, second}); |
46 | 187 |
365
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
188 contents_layout_->addWidget(first.data(), i, 0); |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
189 contents_layout_->addWidget(second.data(), i, 1); |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
190 } |
46 | 191 } |
192 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
193 void LabelledParagraph::SetStyle(int style) { |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
194 const QString style_sheet = (style & LabelledParagraph::BoldedLabels) ? "font-weight: bold;" : ""; |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
195 for (auto& [label, data] : data_) |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
196 label->setStyleSheet(style_sheet); |
46 | 197 |
365
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
198 if (style & LabelledParagraph::ElidedData) { |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
199 for (auto& [label, data] : data_) { |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
200 data->setWordWrap(false); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
201 data->SetElidingMode(true); |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
202 } |
f81bed4e04ac
*: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents:
348
diff
changeset
|
203 } |
46 | 204 } |
205 | |
206 } // namespace TextWidgets |