diff --git a/assets/day-hot.png b/assets/day-hot.png new file mode 100644 index 0000000..2e7a185 Binary files /dev/null and b/assets/day-hot.png differ diff --git a/assets/night-hot.png b/assets/night-hot.png new file mode 100644 index 0000000..5ee435e Binary files /dev/null and b/assets/night-hot.png differ diff --git a/assets/resources.qrc b/assets/resources.qrc index f952e89..6d5a501 100644 --- a/assets/resources.qrc +++ b/assets/resources.qrc @@ -15,5 +15,7 @@ wifi-hot.png brightness-hot.png camera-hot.png + day-hot.png + night-hot.png diff --git a/include/f1x/openauto/autoapp/UI/MainWindow.hpp b/include/f1x/openauto/autoapp/UI/MainWindow.hpp index d75556a..f5afce2 100644 --- a/include/f1x/openauto/autoapp/UI/MainWindow.hpp +++ b/include/f1x/openauto/autoapp/UI/MainWindow.hpp @@ -48,6 +48,8 @@ signals: void exit(); void openSettings(); void toggleCursor(); + void TriggerScriptDay(); + void TriggerScriptNight(); void toggleCamera(); void openConnectDialog(); void showBrightnessSlider(); @@ -57,6 +59,8 @@ private slots: private slots: void on_pushButtonBrightness_clicked(); + void switchGuiToDay(); + void switchGuiToNight(); private: Ui::MainWindow* ui_; diff --git a/src/autoapp/UI/MainWindow.cpp b/src/autoapp/UI/MainWindow.cpp index a873435..d62cf3e 100644 --- a/src/autoapp/UI/MainWindow.cpp +++ b/src/autoapp/UI/MainWindow.cpp @@ -41,16 +41,23 @@ MainWindow::MainWindow(configuration::IConfiguration::Pointer configuration, QWi QPushButton:focus { background: url(:/circle.png); } \ QPushButton:pressed { background: url(:/circle-pressed.png); } \ "); - QFileInfo wallpaperFile("wallpaper.png"); - bool wallpaperFileExists = wallpaperFile.exists(); - if (wallpaperFile.isSymLink()) { - QFileInfo linkTarget(wallpaperFile.symLinkTarget()); - wallpaperFileExists = linkTarget.exists(); + QFileInfo wallpaperDayFile("wallpaper.png"); + bool wallpaperDayFileExists = wallpaperDayFile.exists(); + + QFileInfo wallpaperNightFile("wallpaper-night.png"); + bool wallpaperNightFileExists = wallpaperNightFile.exists(); + + QFileInfo nightSwitchFile("/tmp/night_mode_enabled"); + bool nightSwitchExists = nightSwitchFile.exists(); + + if (wallpaperDayFile.isSymLink()) { + QFileInfo linkTarget(wallpaperDayFile.symLinkTarget()); + wallpaperDayFileExists = linkTarget.exists(); } - if (wallpaperFileExists) { - this->setStyleSheet( this->styleSheet().append("QMainWindow { background: url(wallpaper.png) }") ); - } else { - this->setStyleSheet( this->styleSheet().append("QMainWindow { background: url(:/connect.png) }") ); + + if (wallpaperNightFile.isSymLink()) { + QFileInfo linkTarget(wallpaperNightFile.symLinkTarget()); + wallpaperNightFileExists = linkTarget.exists(); } ui_->setupUi(this); @@ -58,9 +65,30 @@ MainWindow::MainWindow(configuration::IConfiguration::Pointer configuration, QWi connect(ui_->pushButtonExit, &QPushButton::clicked, this, &MainWindow::exit); connect(ui_->pushButtonToggleCamera, &QPushButton::clicked, this, &MainWindow::toggleCamera); connect(ui_->pushButtonToggleCursor, &QPushButton::clicked, this, &MainWindow::toggleCursor); + connect(ui_->pushButtonDay, &QPushButton::clicked, this, &MainWindow::TriggerScriptDay); + connect(ui_->pushButtonDay, &QPushButton::clicked, this, &MainWindow::switchGuiToDay); + connect(ui_->pushButtonNight, &QPushButton::clicked, this, &MainWindow::TriggerScriptNight); + connect(ui_->pushButtonNight, &QPushButton::clicked, this, &MainWindow::switchGuiToNight); connect(ui_->pushButtonWirelessConnection, &QPushButton::clicked, this, &MainWindow::openConnectDialog); connect(ui_->pushButtonBrightness, &QPushButton::clicked, this, &MainWindow::showBrightnessSlider); + if (!nightSwitchExists) { + ui_->pushButtonNight->show(); + ui_->pushButtonDay->hide(); + if (wallpaperDayFileExists) { + this->setStyleSheet( this->styleSheet().append("QMainWindow { background: url(wallpaper.png) }") ); + } else { + this->setStyleSheet( this->styleSheet().append("QMainWindow { background: url(:/connect.png) }") ); + } + } else { + ui_->pushButtonDay->show(); + ui_->pushButtonNight->hide(); + if (wallpaperNightFileExists) { + this->setStyleSheet( this->styleSheet().append("QMainWindow { background: url(wallpaper-night.png) }") ); + } else { + this->setStyleSheet( this->styleSheet().append("QMainWindow { background: url(:/connect.png) }") ); + } + } QFileInfo cursorButtonFile("/etc/button_cursor_visible"); bool cursorButtonForce = cursorButtonFile.exists(); @@ -137,3 +165,17 @@ void f1x::openauto::autoapp::ui::MainWindow::on_horizontalSliderBrightness_value this->brightnessFile->close(); } } + +void f1x::openauto::autoapp::ui::MainWindow::switchGuiToNight() +{ + this->setStyleSheet( this->styleSheet().append("QMainWindow { background: url(wallpaper-night.png) }") ); + ui_->pushButtonDay->show(); + ui_->pushButtonNight->hide(); +} + +void f1x::openauto::autoapp::ui::MainWindow::switchGuiToDay() +{ + this->setStyleSheet( this->styleSheet().append("QMainWindow { background: url(wallpaper.png) }") ); + ui_->pushButtonNight->show(); + ui_->pushButtonDay->hide(); +} diff --git a/src/autoapp/UI/mainwindow.ui b/src/autoapp/UI/mainwindow.ui index a8dfce1..b7a35ce 100644 --- a/src/autoapp/UI/mainwindow.ui +++ b/src/autoapp/UI/mainwindow.ui @@ -101,6 +101,76 @@ true + + + + 30 + 174 + 64 + 64 + + + + display: none; + + + + + + + :/day-hot.png:/day-hot.png + + + + 64 + 64 + + + + false + + + false + + + true + + + + + + 30 + 174 + 64 + 64 + + + + display: none; + + + + + + + :/night-hot.png:/night-hot.png + + + + 64 + 64 + + + + false + + + false + + + true + + diff --git a/src/autoapp/autoapp.cpp b/src/autoapp/autoapp.cpp index ddd74bf..aead3dd 100644 --- a/src/autoapp/autoapp.cpp +++ b/src/autoapp/autoapp.cpp @@ -119,6 +119,24 @@ int main(int argc, char* argv[]) #endif }); + QObject::connect(&mainWindow, &autoapp::ui::MainWindow::TriggerScriptNight, [&qApplication]() { +#ifdef RASPBERRYPI3 + system("/opt/crankshaft/service_daynight.sh night &"); + OPENAUTO_LOG(info) << "[CS] Run night script."; +#else + OPENAUTO_LOG(info) << "[CS] You are not running this on a Raspberry Pi, skipping Day/Night script."; +#endif + }); + + QObject::connect(&mainWindow, &autoapp::ui::MainWindow::TriggerScriptDay, [&qApplication]() { +#ifdef RASPBERRYPI3 + system("/opt/crankshaft/service_daynight.sh day &"); + OPENAUTO_LOG(info) << "[CS] Run day script."; +#else + OPENAUTO_LOG(info) << "[CS] You are not running this on a Raspberry Pi, skipping Day/Night script."; +#endif + }); + mainWindow.showFullScreen(); aasdk::usb::USBWrapper usbWrapper(usbContext);