settings: Make the internet header selectable

Make the "Internet services" tab the internet providers category header instead of a tab under "User Interface".
This commit is contained in:
Jim Broadus 2021-03-21 23:19:19 -07:00 committed by John Maguire
parent e77595fba6
commit c12294c5ec
4 changed files with 30 additions and 5 deletions

View File

@ -17,9 +17,20 @@
#include "settingscategory.h"
#include "settingspage.h"
SettingsCategory::SettingsCategory(const QString& name, SettingsDialog* dialog)
: dialog_(dialog) {
setText(0, name);
setData(0, SettingsDialog::Role_IsSeparator, true);
setFlags(Qt::ItemIsEnabled);
}
SettingsCategory::SettingsCategory(SettingsDialog::Page id, SettingsPage* page,
SettingsDialog* dialog)
: dialog_(dialog) {
setText(0, page->windowTitle());
setData(0, SettingsDialog::Role_IsSeparator, true);
setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
dialog->AddPageToStack(id, page, this);
}

View File

@ -22,9 +22,13 @@
#include "settingsdialog.h"
class SettingsPage;
class SettingsCategory : public QTreeWidgetItem {
public:
SettingsCategory(const QString& name, SettingsDialog* dialog);
SettingsCategory(SettingsDialog::Page id, SettingsPage* page,
SettingsDialog* dialog);
protected:
SettingsDialog* dialog_;

View File

@ -114,7 +114,8 @@ void SettingsItemDelegate::paint(QPainter* painter,
if (is_separator) {
GroupedIconView::DrawHeader(painter, option.rect, option.font,
option.palette, index.data().toString(), false);
option.palette, index.data().toString(),
option.state & QStyle::State_Selected);
} else {
QStyledItemDelegate::paint(painter, option, index);
}
@ -168,11 +169,10 @@ SettingsDialog::SettingsDialog(Application* app, BackgroundStreams* streams,
SIGNAL(NotificationPreview(OSD::Behaviour, QString, QString)),
SIGNAL(NotificationPreview(OSD::Behaviour, QString, QString)));
AddPage(Page_InternetShow, new InternetShowSettingsPage(this), iface);
// Internet providers
InternetShowSettingsPage* internet_page = new InternetShowSettingsPage(this);
SettingsCategory* providers =
new SettingsCategory(tr("Internet providers"), this);
new SettingsCategory(Page_InternetShow, internet_page, this);
AddCategory(providers);
#ifdef HAVE_LIBLASTFM
@ -254,6 +254,11 @@ void SettingsDialog::AddPage(Page id, SettingsPage* page,
parent->addChild(item);
AddPageToStack(id, page, item);
}
void SettingsDialog::AddPageToStack(Page id, SettingsPage* page,
QTreeWidgetItem* item) {
// Create a scroll area containing the page
QScrollArea* area = new QScrollArea;
area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@ -345,7 +350,8 @@ void SettingsDialog::CurrentItemChanged(QTreeWidgetItem* item) {
for (const PageData& data : pages_.values()) {
if (data.item_ == item) {
ui_->stacked_widget->setCurrentWidget(data.scroll_area_);
break;
return;
}
}
qLog(Debug) << "Didn't find page for item!";
}

View File

@ -136,6 +136,10 @@ class SettingsDialog : public QDialog {
void AddCategory(SettingsCategory* category);
void AddPage(Page id, SettingsPage* page, QTreeWidgetItem* parent = nullptr);
private:
friend class SettingsCategory;
void AddPageToStack(Page id, SettingsPage* page, QTreeWidgetItem* item);
private:
Application* app_;
LibraryDirectoryModel* model_;