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