diff --git a/include/app/config.hpp b/include/app/config.hpp index 758c6ad6..5e01715a 100644 --- a/include/app/config.hpp +++ b/include/app/config.hpp @@ -130,6 +130,9 @@ class Config : public QObject { // emit scale_changed(this->scale); } + inline QString get_default_page() { return this->default_page; } + inline void set_default_page(QString default_page) { this->default_page = default_page; } + inline bool get_page(QWidget *page) { return this->pages.value(page->objectName(), true); } inline void set_page(QWidget *page, bool enabled) { @@ -219,6 +222,7 @@ class Config : public QObject { QVideoFrame::PixelFormat cam_local_format_override; bool cam_autoconnect; int cam_autoconnect_time_secs; + QString default_page; QMap pages; QString vehicle_plugin; bool vehicle_can_bus; diff --git a/include/app/pages/settings.hpp b/include/app/pages/settings.hpp index 63057d93..d715ed9a 100644 --- a/include/app/pages/settings.hpp +++ b/include/app/pages/settings.hpp @@ -49,6 +49,8 @@ class LayoutSettingsTab : public QWidget { private: QWidget *settings_widget(); + QWidget *default_page_widget(); + QWidget *default_page_select_widget(); QWidget *pages_widget(); QWidget *controls_bar_widget(); QWidget *quick_view_row_widget(); diff --git a/src/app/config.cpp b/src/app/config.cpp index fb018781..b70f8fa6 100644 --- a/src/app/config.cpp +++ b/src/app/config.cpp @@ -45,6 +45,7 @@ Config::Config() this->vehicle_plugin = this->settings.value("Vehicle/plugin", QString()).toString(); this->vehicle_can_bus = this->settings.value("Vehicle/can_bus", false).toBool(); this->vehicle_interface = this->settings.value("Vehicle/interface", QString()).toString(); + this->default_page = this->settings.value("default_page", "Android Auto").toString(); this->settings.beginGroup("Pages"); for (auto key : this->settings.childKeys()) this->pages[key] = this->settings.value(key, true).toBool(); @@ -128,6 +129,8 @@ void Config::save() this->settings.setValue("Vehicle/can_bus", this->vehicle_can_bus); if (this->vehicle_interface != this->settings.value("Vehicle/interface").toString()) this->settings.setValue("Vehicle/interface", this->vehicle_interface); + if (this->default_page != this->settings.value("default_page").toString()) + this->settings.setValue("default_page", this->default_page); for (auto id : this->pages.keys()) { QString config_key = QString("Pages/%1").arg(id); bool page_enabled = this->pages[id]; diff --git a/src/app/pages/settings.cpp b/src/app/pages/settings.cpp index beb9dbdf..ed7d9fe7 100644 --- a/src/app/pages/settings.cpp +++ b/src/app/pages/settings.cpp @@ -278,6 +278,8 @@ QWidget *LayoutSettingsTab::settings_widget() QWidget *widget = new QWidget(this); QVBoxLayout *layout = new QVBoxLayout(widget); + layout->addWidget(this->default_page_widget()); + layout->addWidget(Theme::br(widget), 1); layout->addWidget(this->pages_widget()); layout->addWidget(Theme::br(widget), 1); layout->addWidget(this->controls_bar_widget(), 1); @@ -298,6 +300,41 @@ QWidget *LayoutSettingsTab::settings_widget() return scroll_area; } +QWidget *LayoutSettingsTab::default_page_widget() +{ + QWidget *widget = new QWidget(this); + QHBoxLayout *layout = new QHBoxLayout(widget); + + QLabel *label = new QLabel("Default Page", widget); + label->setFont(Theme::font_14); + layout->addWidget(label, 1); + + layout->addWidget(this->default_page_select_widget(), 1); + + return widget; +} + +QWidget *LayoutSettingsTab::default_page_select_widget() +{ + QWidget *widget = new QWidget(this); + QHBoxLayout *layout = new QHBoxLayout(widget); + + DashWindow *window = qobject_cast(this->window()); + + QList pages; + for (QAbstractButton *page : window->get_pages()) { + pages.append(page->property("page").value()->objectName()); + } + Selector *selector = new Selector(pages, this->config->get_default_page(), Theme::font_14, widget); + connect(selector, &Selector::item_changed, [config = this->config](QString item) { config->set_default_page(item); }); + + layout->addStretch(1); + layout->addWidget(selector, 10); + layout->addStretch(1); + + return widget; +} + QWidget *LayoutSettingsTab::pages_widget() { QWidget *widget = new QWidget(this); diff --git a/src/app/window.cpp b/src/app/window.cpp index 125e465b..9465c7da 100644 --- a/src/app/window.cpp +++ b/src/app/window.cpp @@ -157,8 +157,9 @@ void DashWindow::add_pages() this->add_page("Settings", new SettingsPage(this), "tune"); // toggle initial page + QString default_page = this->config->get_default_page(); for (QAbstractButton *button : this->rail_group->buttons()) { - if (!button->isHidden()) { + if (!button->isHidden() && default_page == button->property("page").value()->objectName()) { button->setChecked(true); break; }