Skip to content

Commit

Permalink
Add the ability to specify the default page
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroErrors committed Dec 21, 2020
1 parent 3f7891a commit 8d84a7c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/app/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<QString, bool> pages;
QString vehicle_plugin;
bool vehicle_can_bus;
Expand Down
2 changes: 2 additions & 0 deletions include/app/pages/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/app/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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];
Expand Down
37 changes: 37 additions & 0 deletions src/app/pages/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<DashWindow *>(this->window());

QList<QString> pages;
for (QAbstractButton *page : window->get_pages()) {
pages.append(page->property("page").value<QWidget *>()->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);
Expand Down
3 changes: 2 additions & 1 deletion src/app/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QWidget *>()->objectName()) {
button->setChecked(true);
break;
}
Expand Down

0 comments on commit 8d84a7c

Please sign in to comment.