Mercurial > minori
diff src/gui/dialog/settings/application.cpp @ 68:2417121d894e
*: normalize usage of layouts
before, I used them two ways, once was by setting the layout later
by using setLayout(QWidget), and the other was just using the constructor.
I find the constructor to be easier to read, so I chose that one.
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 02 Oct 2023 21:33:25 -0400 |
parents | 4c6dd5999b39 |
children |
line wrap: on
line diff
--- a/src/gui/dialog/settings/application.cpp Mon Oct 02 07:06:44 2023 -0400 +++ b/src/gui/dialog/settings/application.cpp Mon Oct 02 21:33:25 2023 -0400 @@ -3,8 +3,11 @@ #include <QCheckBox> #include <QComboBox> #include <QGroupBox> +#include <QHBoxLayout> +#include <QLabel> #include <QPushButton> #include <QSizePolicy> +#include <QVBoxLayout> QWidget* SettingsPageApplication::CreateAnimeListWidget() { QWidget* result = new QWidget(this); @@ -19,11 +22,10 @@ QComboBox* dc_combo_box = new QComboBox(double_click_widget); dc_combo_box->addItem(tr("View anime info")); - QVBoxLayout* double_click_layout = new QVBoxLayout; + QVBoxLayout* double_click_layout = new QVBoxLayout(double_click_widget); double_click_layout->addWidget(dc_combo_box_label); double_click_layout->addWidget(dc_combo_box); double_click_layout->setContentsMargins(0, 0, 0, 0); - double_click_widget->setLayout(double_click_layout); /* Actions/Middle click */ QWidget* middle_click_widget = new QWidget(actions_group_box); @@ -31,17 +33,15 @@ QComboBox* mc_combo_box = new QComboBox(middle_click_widget); mc_combo_box->addItem(tr("Play next episode")); - QVBoxLayout* middle_click_layout = new QVBoxLayout; + QVBoxLayout* middle_click_layout = new QVBoxLayout(middle_click_widget); middle_click_layout->addWidget(mc_combo_box_label); middle_click_layout->addWidget(mc_combo_box); middle_click_layout->setContentsMargins(0, 0, 0, 0); - middle_click_widget->setLayout(middle_click_layout); /* Actions */ - QHBoxLayout* actions_layout = new QHBoxLayout; + QHBoxLayout* actions_layout = new QHBoxLayout(actions_group_box); actions_layout->addWidget(double_click_widget); actions_layout->addWidget(middle_click_widget); - actions_group_box->setLayout(actions_layout); QGroupBox* appearance_group_box = new QGroupBox(tr("Appearance"), result); appearance_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); @@ -59,23 +59,22 @@ new QCheckBox(tr("Highlight anime if next episode is available in library folders"), appearance_group_box); QCheckBox* hl_above_anime_box = new QCheckBox(tr("Display highlighted anime above others"), appearance_group_box); connect(hl_anime_box, &QCheckBox::stateChanged, this, [this, hl_above_anime_box](int state) { - highlight_anime_if_available = (state == Qt::Unchecked) ? false : true; + highlight_anime_if_available = !(state == Qt::Unchecked); hl_above_anime_box->setEnabled(state); }); connect(hl_above_anime_box, &QCheckBox::stateChanged, this, - [this](int state) { highlight_anime_if_available = (state == Qt::Unchecked) ? false : true; }); + [this](int state) { highlight_anime_if_available = !(state == Qt::Unchecked); }); hl_anime_box->setCheckState(highlight_anime_if_available ? Qt::Checked : Qt::Unchecked); hl_above_anime_box->setCheckState(highlighted_anime_above_others ? Qt::Checked : Qt::Unchecked); hl_above_anime_box->setEnabled(hl_anime_box->checkState() != Qt::Unchecked); hl_above_anime_box->setContentsMargins(10, 0, 0, 0); /* Appearance */ - QVBoxLayout* appearance_layout = new QVBoxLayout; + QVBoxLayout* appearance_layout = new QVBoxLayout(appearance_group_box); appearance_layout->addWidget(lang_combo_box_label); appearance_layout->addWidget(lang_combo_box); appearance_layout->addWidget(hl_anime_box); appearance_layout->addWidget(hl_above_anime_box); - appearance_group_box->setLayout(appearance_layout); QGroupBox* progress_group_box = new QGroupBox(tr("Progress"), result); progress_group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); @@ -83,27 +82,26 @@ QCheckBox* progress_display_aired_episodes = new QCheckBox(tr("Display aired episodes (estimated)"), progress_group_box); connect(progress_display_aired_episodes, &QCheckBox::stateChanged, this, - [this](int state) { display_aired_episodes = (state == Qt::Unchecked) ? false : true; }); + [this](int state) { display_aired_episodes = !(state == Qt::Unchecked); }); progress_display_aired_episodes->setCheckState(display_aired_episodes ? Qt::Checked : Qt::Unchecked); QCheckBox* progress_display_available_episodes = new QCheckBox(tr("Display available episodes in library folders"), progress_group_box); connect(progress_display_available_episodes, &QCheckBox::stateChanged, this, - [this](int state) { display_available_episodes = (state == Qt::Unchecked) ? false : true; }); + [this](int state) { display_available_episodes = !(state == Qt::Unchecked); }); progress_display_available_episodes->setCheckState(display_available_episodes ? Qt::Checked : Qt::Unchecked); - QVBoxLayout* progress_layout = new QVBoxLayout; + QVBoxLayout* progress_layout = new QVBoxLayout(progress_group_box); progress_layout->addWidget(progress_display_aired_episodes); progress_layout->addWidget(progress_display_available_episodes); - progress_group_box->setLayout(progress_layout); - QVBoxLayout* full_layout = new QVBoxLayout; + QVBoxLayout* full_layout = new QVBoxLayout(result); full_layout->addWidget(actions_group_box); full_layout->addWidget(appearance_group_box); full_layout->addWidget(progress_group_box); full_layout->setSpacing(10); full_layout->addStretch(); - result->setLayout(full_layout); + return result; }