Mercurial > minori
comparison src/gui/dialog/information.cc @ 87:4aef97f4d998
information: use QGridLayout please...
text: fix Line selection :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 31 Oct 2023 15:23:52 -0400 |
parents | c912128af0eb |
children | 1b19d80b3f8c |
comparison
equal
deleted
inserted
replaced
86:c912128af0eb | 87:4aef97f4d998 |
---|---|
92 al_layout->setContentsMargins(12, 0, 0, 0); | 92 al_layout->setContentsMargins(12, 0, 0, 0); |
93 | 93 |
94 #define LAYOUT_HORIZ_SPACING 25 | 94 #define LAYOUT_HORIZ_SPACING 25 |
95 #define LAYOUT_VERT_SPACING 5 | 95 #define LAYOUT_VERT_SPACING 5 |
96 #define LAYOUT_ITEM_WIDTH 175 | 96 #define LAYOUT_ITEM_WIDTH 175 |
97 /* Creates a subsection that takes up whatever space is necessary */ | |
98 #define CREATE_FULL_WIDTH_SUBSECTION(x) \ | |
99 { \ | |
100 QWidget* subsection = new QWidget(section); \ | |
101 subsection->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); \ | |
102 QVBoxLayout* subsection_layout = new QVBoxLayout(subsection); \ | |
103 subsection_layout->setSpacing(LAYOUT_VERT_SPACING); \ | |
104 subsection_layout->setContentsMargins(0, 0, 0, 0); \ | |
105 x; \ | |
106 layout->addWidget(subsection, 0, Qt::AlignBottom); \ | |
107 } | |
108 | 97 |
109 /* Creates a section in the parent `a` */ | 98 /* Creates a section in the parent `a` */ |
110 #define CREATE_FULL_WIDTH_SECTION(a, x) \ | 99 #define CREATE_FULL_WIDTH_SECTION(a, x) \ |
111 { \ | 100 { \ |
112 QWidget* section = new QWidget(a); \ | 101 QWidget* section = new QWidget(a); \ |
113 QHBoxLayout* layout = new QHBoxLayout(section); \ | 102 QVBoxLayout* layout = new QVBoxLayout(section); \ |
114 layout->setSpacing(LAYOUT_HORIZ_SPACING); \ | 103 layout->setSpacing(LAYOUT_HORIZ_SPACING); \ |
115 layout->setContentsMargins(0, 0, 0, 0); \ | 104 layout->setContentsMargins(0, 0, 0, 0); \ |
116 x; \ | 105 x; \ |
117 a->layout()->addWidget(section); \ | 106 a->layout()->addWidget(section); \ |
118 } | 107 } |
119 | 108 #define CREATE_SECTION(a, x) \ |
120 /* Creates a subsection with a width of 175 */ | 109 { \ |
121 #define CREATE_SUBSECTION(x) CREATE_FULL_WIDTH_SUBSECTION(x subsection->setFixedWidth(LAYOUT_ITEM_WIDTH);) | 110 QWidget* section = new QWidget(a); \ |
122 /* Creates a section in the parent `a` */ | 111 QGridLayout* layout = new QGridLayout(section); \ |
123 #define CREATE_SECTION(a, x) CREATE_FULL_WIDTH_SECTION(a, x layout->addStretch();) | 112 layout->setSpacing(LAYOUT_HORIZ_SPACING); \ |
113 layout->setContentsMargins(0, 0, 0, 0); \ | |
114 x; \ | |
115 a->layout()->addWidget(section); \ | |
116 } | |
124 | 117 |
125 CREATE_SECTION(sg_anime_list_content, { | 118 CREATE_SECTION(sg_anime_list_content, { |
126 /* Episodes watched section */ | 119 layout->addWidget(new QLabel(tr("Episodes watched:"), section), 0, 0); |
127 CREATE_SUBSECTION({ | 120 |
128 subsection_layout->addWidget(new QLabel(tr("Episodes watched:"), subsection)); | 121 QSpinBox* spin_box = new QSpinBox(section); |
129 | 122 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) { _progress = i; }); |
130 QSpinBox* spin_box = new QSpinBox(subsection); | 123 spin_box->setRange(0, anime.GetEpisodes()); |
131 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) { _progress = i; }); | 124 spin_box->setSingleStep(1); |
132 spin_box->setRange(0, anime.GetEpisodes()); | 125 spin_box->setValue(_progress = anime.GetUserProgress()); |
133 spin_box->setSingleStep(1); | 126 layout->addWidget(spin_box, 1, 0); |
134 spin_box->setValue(_progress = anime.GetUserProgress()); | 127 |
135 subsection_layout->addWidget(spin_box); | 128 layout->addWidget(new QLabel(tr(" "), section), 0, 1); |
136 }); | 129 |
137 CREATE_SUBSECTION({ | 130 QCheckBox* checkbox = new QCheckBox(tr("Rewatching")); |
138 subsection_layout->addWidget(new QLabel(tr(" "), subsection)); | 131 connect(checkbox, QOverload<int>::of(&QCheckBox::stateChanged), this, |
139 | 132 [this](int state) { _rewatching = (state == Qt::Checked); }); |
140 QCheckBox* checkbox = new QCheckBox(tr("Rewatching")); | 133 checkbox->setCheckState((_rewatching = anime.GetUserIsRewatching()) ? Qt::Checked : Qt::Unchecked); |
141 connect(checkbox, QOverload<int>::of(&QCheckBox::stateChanged), this, | 134 layout->addWidget(checkbox, 1, 1); |
142 [this](int state) { _rewatching = (state == Qt::Checked); }); | |
143 checkbox->setCheckState((_rewatching = anime.GetUserIsRewatching()) ? Qt::Checked : Qt::Unchecked); | |
144 subsection_layout->addWidget(checkbox); | |
145 }); | |
146 }); | 135 }); |
147 CREATE_SECTION(sg_anime_list_content, { | 136 CREATE_SECTION(sg_anime_list_content, { |
148 /* Status & score section */ | 137 /* Status & score section */ |
149 CREATE_SUBSECTION({ | 138 layout->addWidget(new QLabel(tr("Status:"), section), 0, 0); |
150 subsection_layout->addWidget(new QLabel(tr("Status:"), subsection)); | 139 |
151 | 140 /* FIXME: this sucks */ |
152 /* FIXME: this sucks */ | 141 QStringList string_list; |
153 QStringList string_list; | 142 for (unsigned int i = 0; i < Anime::ListStatuses.size(); i++) |
154 for (unsigned int i = 0; i < Anime::ListStatuses.size(); i++) | 143 string_list.append(Strings::ToQString(Translate::ToString(Anime::ListStatuses[i]))); |
155 string_list.append(Strings::ToQString(Translate::ToString(Anime::ListStatuses[i]))); | 144 |
156 | 145 QComboBox* combo_box = new QComboBox(section); |
157 QComboBox* combo_box = new QComboBox(subsection); | 146 combo_box->addItems(string_list); |
158 combo_box->addItems(string_list); | 147 connect(combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, |
159 connect(combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | 148 [this](int i) { _status = Anime::ListStatuses[i]; }); |
160 [this](int i) { _status = Anime::ListStatuses[i]; }); | 149 combo_box->setCurrentIndex(static_cast<int>(_status = anime.GetUserStatus()) - 1); |
161 combo_box->setCurrentIndex(static_cast<int>(_status = anime.GetUserStatus()) - 1); | 150 layout->addWidget(combo_box, 1, 0); |
162 subsection_layout->addWidget(combo_box); | 151 |
152 layout->addWidget(new QLabel(tr("Score:"), section), 0, 1); | |
153 | |
154 QSpinBox* spin_box = new QSpinBox(section); | |
155 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) { _score = i; }); | |
156 spin_box->setRange(0, 100); | |
157 spin_box->setSingleStep(5); | |
158 spin_box->setValue(_score = anime.GetUserScore()); | |
159 layout->addWidget(spin_box, 1, 1); | |
160 }); | |
161 CREATE_FULL_WIDTH_SECTION(sg_anime_list_content, { | |
162 layout->addWidget(new QLabel(tr("Notes:"), section)); | |
163 | |
164 QLineEdit* line_edit = new QLineEdit(section); | |
165 connect(line_edit, &QLineEdit::textChanged, this, [this](const QString& text) { | |
166 /* this sucks but I don't really want to implement anything smarter :) */ | |
167 _notes = Strings::ToUtf8String(text); | |
163 }); | 168 }); |
164 CREATE_SUBSECTION({ | 169 line_edit->setText(Strings::ToQString(_notes = anime.GetUserNotes())); |
165 subsection_layout->addWidget(new QLabel(tr("Score:"), subsection)); | 170 line_edit->setPlaceholderText(tr("Enter your notes about this anime")); |
166 | 171 layout->addWidget(line_edit); |
167 QSpinBox* spin_box = new QSpinBox(subsection); | |
168 connect(spin_box, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int i) { _score = i; }); | |
169 spin_box->setRange(0, 100); | |
170 spin_box->setSingleStep(5); | |
171 spin_box->setValue(_score = anime.GetUserScore()); | |
172 subsection_layout->addWidget(spin_box); | |
173 }); | |
174 }); | |
175 CREATE_FULL_WIDTH_SECTION(sg_anime_list_content, { | |
176 /* Notes section */ | |
177 CREATE_FULL_WIDTH_SUBSECTION({ | |
178 subsection_layout->addWidget(new QLabel(tr("Notes:"), subsection)); | |
179 | |
180 QLineEdit* line_edit = new QLineEdit(subsection); | |
181 connect(line_edit, &QLineEdit::textChanged, this, [this](const QString& text) { | |
182 /* this sucks but I don't really want to implement anything smarter :) */ | |
183 _notes = Strings::ToUtf8String(text); | |
184 }); | |
185 line_edit->setText(Strings::ToQString(_notes = anime.GetUserNotes())); | |
186 line_edit->setPlaceholderText(tr("Enter your notes about this anime")); | |
187 subsection_layout->addWidget(line_edit); | |
188 }); | |
189 }); | 172 }); |
190 CREATE_SECTION(sg_anime_list_content, { | 173 CREATE_SECTION(sg_anime_list_content, { |
191 /* Dates section */ | 174 /* Dates section */ |
192 CREATE_SUBSECTION({ | 175 layout->addWidget(new QLabel(tr("Date started:"), section), 0, 0); |
193 subsection_layout->addWidget(new QLabel(tr("Date started:"), subsection)); | 176 |
194 | 177 OptionalDate* date = new OptionalDate(true, section); |
195 OptionalDate* date = new OptionalDate(true, subsection); | 178 connect(date, &OptionalDate::DataChanged, this, |
196 connect(date, &OptionalDate::DataChanged, this, | 179 [this](bool enabled, Date date) { _started = (enabled) ? date : Date(); }); |
197 [this](bool enabled, Date date) { _started = (enabled) ? date : Date(); }); | 180 _started = anime.GetUserDateStarted(); |
198 _started = anime.GetUserDateStarted(); | 181 if (!_started.IsValid()) { |
199 if (!_started.IsValid()) { | 182 date->SetEnabled(false); |
200 date->SetEnabled(false); | 183 _started = anime.GetAirDate(); |
201 _started = anime.GetAirDate(); | 184 } |
202 } | 185 date->SetDate(_started); |
203 date->SetDate(_started); | 186 layout->addWidget(date, 1, 0); |
204 subsection_layout->addWidget(date); | 187 |
205 }); | 188 layout->addWidget(new QLabel(tr("Date completed:"), section), 0, 1); |
206 CREATE_SUBSECTION({ | 189 |
207 subsection_layout->addWidget(new QLabel(tr("Date completed:"), subsection)); | 190 date = new OptionalDate(true, section); |
208 | 191 connect(date, &OptionalDate::DataChanged, this, |
209 OptionalDate* date = new OptionalDate(true, subsection); | 192 [this](bool enabled, Date date) { _completed = (enabled) ? date : Date(); }); |
210 connect(date, &OptionalDate::DataChanged, this, | 193 _completed = anime.GetUserDateCompleted(); |
211 [this](bool enabled, Date date) { _completed = (enabled) ? date : Date(); }); | 194 if (!_completed.IsValid()) { |
212 _completed = anime.GetUserDateCompleted(); | 195 date->SetEnabled(false); |
213 if (!_completed.IsValid()) { | 196 _completed = anime.GetAirDate(); |
214 date->SetEnabled(false); | 197 } |
215 _completed = anime.GetAirDate(); | 198 date->SetDate(_completed); |
216 } | 199 layout->addWidget(date, 1, 1); |
217 date->SetDate(_completed); | |
218 subsection_layout->addWidget(date); | |
219 }); | |
220 }); | 200 }); |
221 | 201 |
222 settings_layout->addWidget(sg_anime_list_content); | 202 settings_layout->addWidget(sg_anime_list_content); |
223 | 203 |
224 settings_layout->addWidget(new TextWidgets::Header(tr("Local settings"), settings_widget)); | 204 settings_layout->addWidget(new TextWidgets::Header(tr("Local settings"), settings_widget)); |
227 QVBoxLayout* sg_local_layout = new QVBoxLayout(sg_local_content); | 207 QVBoxLayout* sg_local_layout = new QVBoxLayout(sg_local_content); |
228 sg_local_layout->setSpacing(5); | 208 sg_local_layout->setSpacing(5); |
229 sg_local_layout->setContentsMargins(12, 0, 0, 0); | 209 sg_local_layout->setContentsMargins(12, 0, 0, 0); |
230 | 210 |
231 CREATE_FULL_WIDTH_SECTION(sg_local_content, { | 211 CREATE_FULL_WIDTH_SECTION(sg_local_content, { |
232 /* Alternative titles */ | 212 layout->addWidget(new QLabel(tr("Alternative titles:"), section)); |
233 CREATE_FULL_WIDTH_SUBSECTION({ | 213 |
234 subsection_layout->addWidget(new QLabel(tr("Alternative titles:"), subsection)); | 214 QLineEdit* line_edit = new QLineEdit("", section); |
235 | 215 line_edit->setPlaceholderText( |
236 QLineEdit* line_edit = new QLineEdit("", subsection); | 216 tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)")); |
237 line_edit->setPlaceholderText( | 217 layout->addWidget(line_edit); |
238 tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)")); | 218 |
239 subsection_layout->addWidget(line_edit); | 219 QCheckBox* checkbox = new QCheckBox(tr("Use the first alternative title to search for torrents")); |
240 | 220 layout->addWidget(checkbox); |
241 QCheckBox* checkbox = new QCheckBox(tr("Use the first alternative title to search for torrents")); | |
242 subsection_layout->addWidget(checkbox); | |
243 }); | |
244 }); | 221 }); |
245 #undef CREATE_SECTION | 222 #undef CREATE_SECTION |
246 #undef CREATE_SUBSECTION | |
247 #undef CREATE_FULL_WIDTH_SECTION | 223 #undef CREATE_FULL_WIDTH_SECTION |
248 #undef CREATE_FULL_WIDTH_SUBSECTION | |
249 | 224 |
250 settings_layout->addWidget(sg_local_content); | 225 settings_layout->addWidget(sg_local_content); |
251 settings_layout->addStretch(); | 226 settings_layout->addStretch(); |
252 | 227 |
253 tabbed_widget->addTab(main_information_widget, tr("Main information")); | 228 tabbed_widget->addTab(main_information_widget, tr("Main information")); |