[gui][script] Switchable day/night mode
This commit is contained in:
parent
ed96372595
commit
5440d0e3b0
BIN
assets/day-hot.png
Normal file
BIN
assets/day-hot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
BIN
assets/night-hot.png
Normal file
BIN
assets/night-hot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
@ -15,5 +15,7 @@
|
||||
<file>wifi-hot.png</file>
|
||||
<file>brightness-hot.png</file>
|
||||
<file>camera-hot.png</file>
|
||||
<file>day-hot.png</file>
|
||||
<file>night-hot.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -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_;
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -101,6 +101,76 @@
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButtonDay">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>174</y>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">display: none;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../assets/resources.qrc">
|
||||
<normaloff>:/day-hot.png</normaloff>:/day-hot.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoDefault">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="default">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButtonNight">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>174</y>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">display: none;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../assets/resources.qrc">
|
||||
<normaloff>:/night-hot.png</normaloff>:/night-hot.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoDefault">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="default">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButtonBrightness">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user