Mercurial > minori
comparison src/gui/dialog/settings/services.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 | 26721c28bf22 |
| children | 5ccb99bfa605 |
comparison
equal
deleted
inserted
replaced
| 67:442065432549 | 68:2417121d894e |
|---|---|
| 5 #include "services/anilist.h" | 5 #include "services/anilist.h" |
| 6 #include <QComboBox> | 6 #include <QComboBox> |
| 7 #include <QGroupBox> | 7 #include <QGroupBox> |
| 8 #include <QPushButton> | 8 #include <QPushButton> |
| 9 #include <QSizePolicy> | 9 #include <QSizePolicy> |
| 10 #include <QVBoxLayout> | |
| 11 #include <QLabel> | |
| 12 #include <QPushButton> | |
| 13 #include <QLineEdit> | |
| 10 | 14 |
| 11 QWidget* SettingsPageServices::CreateMainPage() { | 15 QWidget* SettingsPageServices::CreateMainPage() { |
| 12 QWidget* result = new QWidget(this); | 16 QWidget* result = new QWidget(this); |
| 13 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 17 result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
| 14 | 18 |
| 24 sync_combo_box->setCurrentIndex(static_cast<int>(service) - 1); | 28 sync_combo_box->setCurrentIndex(static_cast<int>(service) - 1); |
| 25 | 29 |
| 26 QLabel* sync_note_label = | 30 QLabel* sync_note_label = |
| 27 new QLabel(tr("Note: Minori is unable to synchronize multiple services at the same time."), sync_group_box); | 31 new QLabel(tr("Note: Minori is unable to synchronize multiple services at the same time."), sync_group_box); |
| 28 | 32 |
| 29 QVBoxLayout* sync_layout = new QVBoxLayout; | 33 QVBoxLayout* sync_layout = new QVBoxLayout(sync_group_box); |
| 30 sync_layout->addWidget(sync_combo_box_label); | 34 sync_layout->addWidget(sync_combo_box_label); |
| 31 sync_layout->addWidget(sync_combo_box); | 35 sync_layout->addWidget(sync_combo_box); |
| 32 sync_layout->addWidget(sync_note_label); | 36 sync_layout->addWidget(sync_note_label); |
| 33 sync_group_box->setLayout(sync_layout); | |
| 34 | 37 |
| 35 QVBoxLayout* full_layout = new QVBoxLayout; | 38 QVBoxLayout* full_layout = new QVBoxLayout(result); |
| 36 full_layout->addWidget(sync_group_box); | 39 full_layout->addWidget(sync_group_box); |
| 37 full_layout->setSpacing(10); | 40 full_layout->setSpacing(10); |
| 38 full_layout->addStretch(); | 41 full_layout->addStretch(); |
| 39 result->setLayout(full_layout); | 42 |
| 40 return result; | 43 return result; |
| 41 } | 44 } |
| 42 | 45 |
| 43 QWidget* SettingsPageServices::CreateAniListPage() { | 46 QWidget* SettingsPageServices::CreateAniListPage() { |
| 44 QWidget* result = new QWidget(this); | 47 QWidget* result = new QWidget(this); |
| 58 | 61 |
| 59 QPushButton* auth_button = new QPushButton(auth_widget); | 62 QPushButton* auth_button = new QPushButton(auth_widget); |
| 60 connect(auth_button, &QPushButton::clicked, this, [] { Services::AniList::AuthorizeUser(); }); | 63 connect(auth_button, &QPushButton::clicked, this, [] { Services::AniList::AuthorizeUser(); }); |
| 61 auth_button->setText(session.config.anilist.auth_token.empty() ? tr("Authorize...") : tr("Re-authorize...")); | 64 auth_button->setText(session.config.anilist.auth_token.empty() ? tr("Authorize...") : tr("Re-authorize...")); |
| 62 | 65 |
| 63 QHBoxLayout* auth_layout = new QHBoxLayout; | 66 QHBoxLayout* auth_layout = new QHBoxLayout(auth_widget); |
| 64 auth_layout->addWidget(username_entry); | 67 auth_layout->addWidget(username_entry); |
| 65 auth_layout->addWidget(auth_button); | 68 auth_layout->addWidget(auth_button); |
| 66 auth_widget->setLayout(auth_layout); | |
| 67 | 69 |
| 68 QLabel* note_label = new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box); | 70 QLabel* note_label = new QLabel(tr("<a href=\"http://anilist.co/\">Create a new AniList account</a>"), group_box); |
| 69 note_label->setTextFormat(Qt::RichText); | 71 note_label->setTextFormat(Qt::RichText); |
| 70 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); | 72 note_label->setTextInteractionFlags(Qt::TextBrowserInteraction); |
| 71 note_label->setOpenExternalLinks(true); | 73 note_label->setOpenExternalLinks(true); |
| 72 | 74 |
| 73 QVBoxLayout* layout = new QVBoxLayout; | 75 QVBoxLayout* layout = new QVBoxLayout(group_box); |
| 74 layout->addWidget(username_entry_label); | 76 layout->addWidget(username_entry_label); |
| 75 layout->addWidget(auth_widget); | 77 layout->addWidget(auth_widget); |
| 76 layout->addWidget(note_label); | 78 layout->addWidget(note_label); |
| 77 group_box->setLayout(layout); | |
| 78 | 79 |
| 79 QVBoxLayout* full_layout = new QVBoxLayout; | 80 QVBoxLayout* full_layout = new QVBoxLayout(result); |
| 80 full_layout->addWidget(group_box); | 81 full_layout->addWidget(group_box); |
| 81 full_layout->setSpacing(10); | 82 full_layout->setSpacing(10); |
| 82 full_layout->addStretch(); | 83 full_layout->addStretch(); |
| 83 result->setLayout(full_layout); | |
| 84 return result; | 84 return result; |
| 85 } | 85 } |
| 86 | 86 |
| 87 void SettingsPageServices::SaveInfo() { | 87 void SettingsPageServices::SaveInfo() { |
| 88 session.config.anilist.username = Strings::ToUtf8String(username); | 88 session.config.anilist.username = Strings::ToUtf8String(username); |
