annotate src/gui/widgets/text.cc @ 359:4e0e17d3c67a

CI/linux: ignore linuxdeployqt silently failing
author Paper <paper@paper.us.eu.org>
date Mon, 15 Jul 2024 01:06:39 -0400
parents 6b0768158dcd
children f81bed4e04ac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #include "gui/widgets/text.h"
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
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
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
4
77
6f7385bd334c *: update
Paper <mrpapersonic@gmail.com>
parents: 76
diff changeset
5 #include <QDebug>
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 #include <QFrame>
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
7 #include <QLabel>
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8 #include <QTextBlock>
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 #include <QVBoxLayout>
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
10 #include <QScrollArea>
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
11 #include <QDebug>
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
12
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 namespace TextWidgets {
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
15 /* 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
16
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
17 Header::Header(QWidget* parent)
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
18 : QWidget(parent)
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
19 , title_(new QLabel(this))
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
20 , separator_(new QFrame(this)) {
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
21 QVBoxLayout* layout = new QVBoxLayout(this);
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
24 title_->setTextFormat(Qt::PlainText);
183
01d259b9c89f pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
25
01d259b9c89f pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
26 {
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
27 QFont font = title_->font();
183
01d259b9c89f pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
28 font.setWeight(QFont::Bold);
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
29 title_->setFont(font);
183
01d259b9c89f pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents: 105
diff changeset
30 }
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
32 separator_->setFrameShape(QFrame::HLine);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
33 separator_->setFrameShadow(QFrame::Sunken);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
34 separator_->setFixedHeight(2);
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
35
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
36 layout->addWidget(title_.data());
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
37 layout->addWidget(separator_.data());
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
38 layout->setSpacing(0);
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
39 layout->setContentsMargins(0, 0, 0, 0);
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
40 }
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
41
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
42 void Header::SetText(const std::string& text) {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
43 title_->setText(Strings::ToQString(text));
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
44 updateGeometry();
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
45 }
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
46
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
47 /* ---------------------------------------------------------------------------------- */
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
48 /* "Paragraph" widgets, as in widgets meant to hold a bunch of text. */
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
49
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
50 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
51 QVBoxLayout *layout = new QVBoxLayout(this);
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
52 layout->setSpacing(0);
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
53 layout->setContentsMargins(0, 0, 0, 0);
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
54
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
55 label_->setTextInteractionFlags(Qt::TextBrowserInteraction);
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
56
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
57 /* defaults */
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
58 SetWordWrap(true);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
59 SetSelectable(true);
75
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 74
diff changeset
60
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
61 layout->addWidget(label_.data());
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
62 }
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
63
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
64 void Paragraph::SetText(const std::string& text) {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
65 label_->setText(Strings::ToQString(text));
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
66 }
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
67
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
68 void Paragraph::SetSelectable(bool enable) {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
69 label_->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents, !enable);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
70 label_->setCursor(enable ? Qt::IBeamCursor : Qt::ArrowCursor);
75
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 74
diff changeset
71 }
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents: 74
diff changeset
72
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
73 void Paragraph::SetWordWrap(bool enable) {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
74 label_->setWordWrap(enable);
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
75 }
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
76
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
77 /* LabelledParagraph implementation */
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
78
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
79 LabelledParagraph::LabelledParagraph(QWidget* parent)
291
9a88e1725fd2 *: refactor lots of stuff
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
80 : QWidget(parent)
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
81 , contents_(new QWidget)
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
82 , contents_layout_(new QGridLayout) {
253
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
83 QHBoxLayout* ly = new QHBoxLayout(this);
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
84
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
85 contents_layout_->setVerticalSpacing(1);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
86 contents_layout_->setHorizontalSpacing(20);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
87 contents_layout_->setContentsMargins(0, 0, 0, 0);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
88 contents_layout_->setColumnStretch(1, 0);
253
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
89
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
90 contents_->setLayout(contents_layout_.data());
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
91
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
92 ly->addWidget(contents_.data());
253
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
93 ly->setContentsMargins(0, 0, 0, 0);
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
94 }
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
95
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
96 LabelledParagraph::~LabelledParagraph() {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
97 data_.clear();
253
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
98 }
b3549da699a6 *: ooooh! stupid big commit!
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
99
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
100 void LabelledParagraph::Clear(void) {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
101 for (auto& [label, data] : data_) {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
102 contents_layout_->removeWidget(label.data());
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
103 contents_layout_->removeWidget(data.data());
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
104 }
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
105
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
106 data_.clear();
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
107 }
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
108
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
109 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
110 Clear();
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
111
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
112 data_.reserve(data.size());
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
113 for (std::size_t i = 0; i < data.size(); i++) {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
114 QSharedPointer<QLabel> first(new QLabel);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
115 QSharedPointer<QLabel> second(new QLabel);
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
116
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
117 first->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
118
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
119 first->setText(Strings::ToQString(data[i].first));
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
120 second->setText(Strings::ToQString(data[i].second));
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
121
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
122 data_.push_back({first, second});
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
123
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
124 contents_layout_->addWidget(first.data(), i, 0);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
125 contents_layout_->addWidget(second.data(), i, 1);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
126 }
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
127 }
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
128
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
129 void LabelledParagraph::SetStyle(int style) {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
130 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
131 for (auto& [label, data] : data_)
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
132 label->setStyleSheet(style_sheet);
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
133
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 295
diff changeset
134 // TODO ElidedData
46
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
135 }
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
136
d0adc4aedfc8 *: update...
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
137 } // namespace TextWidgets