Mercurial > minori
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 |
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> | |
12 | |
46 | 13 namespace TextWidgets { |
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 | 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 | 21 QVBoxLayout* layout = new QVBoxLayout(this); |
46 | 22 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); |
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 | 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 | 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 | 38 layout->setSpacing(0); |
39 layout->setContentsMargins(0, 0, 0, 0); | |
46 | 40 } |
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 | 44 updateGeometry(); |
46 | 45 } |
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 | 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 | 52 layout->setSpacing(0); |
53 layout->setContentsMargins(0, 0, 0, 0); | |
54 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
55 label_->setTextInteractionFlags(Qt::TextBrowserInteraction); |
291 | 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 | 60 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
61 layout->addWidget(label_.data()); |
83 | 62 } |
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 | 66 } |
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 | 71 } |
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 | 75 } |
76 | |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
77 /* LabelledParagraph implementation */ |
46 | 78 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
79 LabelledParagraph::LabelledParagraph(QWidget* parent) |
291 | 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 | 83 QHBoxLayout* ly = new QHBoxLayout(this); |
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 | 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 | 93 ly->setContentsMargins(0, 0, 0, 0); |
94 } | |
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 | 98 } |
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 | 105 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
106 data_.clear(); |
46 | 107 } |
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 | 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 | 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 | 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 | 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 | 127 } |
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 | 133 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
295
diff
changeset
|
134 // TODO ElidedData |
46 | 135 } |
136 | |
137 } // namespace TextWidgets |