Mercurial > minori
diff 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 |
line wrap: on
line diff
--- a/src/gui/dialog/information.cc Tue Oct 31 15:23:52 2023 -0400 +++ b/src/gui/dialog/information.cc Tue Oct 31 16:18:26 2023 -0400 @@ -87,35 +87,30 @@ QWidget* sg_anime_list_content = new QWidget(settings_widget); + constexpr int LAYOUT_HORIZ_SPACING = 25; + constexpr int LAYOUT_VERT_SPACING = 5; + constexpr int LAYOUT_ITEM_WIDTH = 175; + QVBoxLayout* al_layout = new QVBoxLayout(sg_anime_list_content); - al_layout->setSpacing(5); + al_layout->setSpacing(LAYOUT_VERT_SPACING); al_layout->setContentsMargins(12, 0, 0, 0); -#define LAYOUT_HORIZ_SPACING 25 -#define LAYOUT_VERT_SPACING 5 -#define LAYOUT_ITEM_WIDTH 175 + const auto CREATE_SECTION = [](QWidget* parent, std::function<void(QWidget*, QGridLayout*)> x) { + QWidget* section = new QWidget(parent); + QGridLayout* layout = new QGridLayout(section); + layout->setHorizontalSpacing(LAYOUT_HORIZ_SPACING); + layout->setVerticalSpacing(LAYOUT_VERT_SPACING); + layout->setContentsMargins(0, 0, 0, 0); + x(section, layout); + parent->layout()->addWidget(section); + }; -/* Creates a section in the parent `a` */ -#define CREATE_FULL_WIDTH_SECTION(a, x) \ - { \ - QWidget* section = new QWidget(a); \ - QVBoxLayout* layout = new QVBoxLayout(section); \ - layout->setSpacing(LAYOUT_HORIZ_SPACING); \ - layout->setContentsMargins(0, 0, 0, 0); \ - x; \ - a->layout()->addWidget(section); \ - } -#define CREATE_SECTION(a, x) \ - { \ - QWidget* section = new QWidget(a); \ - QGridLayout* layout = new QGridLayout(section); \ - layout->setSpacing(LAYOUT_HORIZ_SPACING); \ - layout->setContentsMargins(0, 0, 0, 0); \ - x; \ - a->layout()->addWidget(section); \ - } + const auto GRID_ADD_STRETCH = [](QGridLayout* layout) { + layout->setRowStretch(layout->rowCount(), 1); + layout->setColumnStretch(layout->columnCount(), 1); + }; - CREATE_SECTION(sg_anime_list_content, { + CREATE_SECTION(sg_anime_list_content, [this, &anime, &GRID_ADD_STRETCH](QWidget* section, QGridLayout* layout){ layout->addWidget(new QLabel(tr("Episodes watched:"), section), 0, 0); QSpinBox* spin_box = new QSpinBox(section); @@ -123,6 +118,7 @@ spin_box->setRange(0, anime.GetEpisodes()); spin_box->setSingleStep(1); spin_box->setValue(_progress = anime.GetUserProgress()); + spin_box->setFixedWidth(LAYOUT_ITEM_WIDTH); layout->addWidget(spin_box, 1, 0); layout->addWidget(new QLabel(tr(" "), section), 0, 1); @@ -131,9 +127,12 @@ connect(checkbox, QOverload<int>::of(&QCheckBox::stateChanged), this, [this](int state) { _rewatching = (state == Qt::Checked); }); checkbox->setCheckState((_rewatching = anime.GetUserIsRewatching()) ? Qt::Checked : Qt::Unchecked); + checkbox->setFixedWidth(LAYOUT_ITEM_WIDTH); layout->addWidget(checkbox, 1, 1); + GRID_ADD_STRETCH(layout); }); - CREATE_SECTION(sg_anime_list_content, { + + CREATE_SECTION(sg_anime_list_content, [this, &anime, &GRID_ADD_STRETCH](QWidget* section, QGridLayout* layout){ /* Status & score section */ layout->addWidget(new QLabel(tr("Status:"), section), 0, 0); @@ -147,6 +146,7 @@ connect(combo_box, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int i) { _status = Anime::ListStatuses[i]; }); combo_box->setCurrentIndex(static_cast<int>(_status = anime.GetUserStatus()) - 1); + combo_box->setFixedWidth(LAYOUT_ITEM_WIDTH); layout->addWidget(combo_box, 1, 0); layout->addWidget(new QLabel(tr("Score:"), section), 0, 1); @@ -156,10 +156,13 @@ spin_box->setRange(0, 100); spin_box->setSingleStep(5); spin_box->setValue(_score = anime.GetUserScore()); + spin_box->setFixedWidth(LAYOUT_ITEM_WIDTH); layout->addWidget(spin_box, 1, 1); + GRID_ADD_STRETCH(layout); }); - CREATE_FULL_WIDTH_SECTION(sg_anime_list_content, { - layout->addWidget(new QLabel(tr("Notes:"), section)); + + CREATE_SECTION(sg_anime_list_content, [this, &anime](QWidget* section, QGridLayout* layout){ + layout->addWidget(new QLabel(tr("Notes:"), section), 0, 0); QLineEdit* line_edit = new QLineEdit(section); connect(line_edit, &QLineEdit::textChanged, this, [this](const QString& text) { @@ -168,15 +171,17 @@ }); line_edit->setText(Strings::ToQString(_notes = anime.GetUserNotes())); line_edit->setPlaceholderText(tr("Enter your notes about this anime")); - layout->addWidget(line_edit); + layout->addWidget(line_edit, 1, 0); }); - CREATE_SECTION(sg_anime_list_content, { + + CREATE_SECTION(sg_anime_list_content, [this, &anime, &GRID_ADD_STRETCH](QWidget* section, QGridLayout* layout){ /* Dates section */ layout->addWidget(new QLabel(tr("Date started:"), section), 0, 0); OptionalDate* date = new OptionalDate(true, section); connect(date, &OptionalDate::DataChanged, this, [this](bool enabled, Date date) { _started = (enabled) ? date : Date(); }); + date->setFixedWidth(LAYOUT_ITEM_WIDTH); _started = anime.GetUserDateStarted(); if (!_started.IsValid()) { date->SetEnabled(false); @@ -190,6 +195,7 @@ date = new OptionalDate(true, section); connect(date, &OptionalDate::DataChanged, this, [this](bool enabled, Date date) { _completed = (enabled) ? date : Date(); }); + date->setFixedWidth(LAYOUT_ITEM_WIDTH); _completed = anime.GetUserDateCompleted(); if (!_completed.IsValid()) { date->SetEnabled(false); @@ -197,6 +203,7 @@ } date->SetDate(_completed); layout->addWidget(date, 1, 1); + GRID_ADD_STRETCH(layout); }); settings_layout->addWidget(sg_anime_list_content); @@ -208,16 +215,16 @@ sg_local_layout->setSpacing(5); sg_local_layout->setContentsMargins(12, 0, 0, 0); - CREATE_FULL_WIDTH_SECTION(sg_local_content, { - layout->addWidget(new QLabel(tr("Alternative titles:"), section)); + CREATE_SECTION(sg_local_content, [this, &anime](QWidget* section, QGridLayout* layout){ + layout->addWidget(new QLabel(tr("Alternative titles:"), section), 0, 0); QLineEdit* line_edit = new QLineEdit("", section); line_edit->setPlaceholderText( tr("Enter alternative titles here, separated by a semicolon (i.e. Title 1; Title 2)")); - layout->addWidget(line_edit); + layout->addWidget(line_edit, 1, 0); QCheckBox* checkbox = new QCheckBox(tr("Use the first alternative title to search for torrents")); - layout->addWidget(checkbox); + layout->addWidget(checkbox, 2, 0); }); #undef CREATE_SECTION #undef CREATE_FULL_WIDTH_SECTION