diff --git a/assets/brightness-hot.png b/assets/brightness-hot.png new file mode 100644 index 0000000..9bffada Binary files /dev/null and b/assets/brightness-hot.png differ diff --git a/assets/circle-hot.png b/assets/circle-hot.png new file mode 100644 index 0000000..84368d7 Binary files /dev/null and b/assets/circle-hot.png differ diff --git a/assets/circle-pressed.png b/assets/circle-pressed.png new file mode 100644 index 0000000..7d03969 Binary files /dev/null and b/assets/circle-pressed.png differ diff --git a/assets/circle.png b/assets/circle.png new file mode 100644 index 0000000..dada437 Binary files /dev/null and b/assets/circle.png differ diff --git a/assets/connect.png b/assets/connect.png new file mode 100644 index 0000000..78143b9 Binary files /dev/null and b/assets/connect.png differ diff --git a/assets/cursor-hot.png b/assets/cursor-hot.png new file mode 100644 index 0000000..defedf6 Binary files /dev/null and b/assets/cursor-hot.png differ diff --git a/assets/power-hot.png b/assets/power-hot.png new file mode 100644 index 0000000..b11533e Binary files /dev/null and b/assets/power-hot.png differ diff --git a/assets/resources.qrc b/assets/resources.qrc index 1070e2d..17a9e9f 100644 --- a/assets/resources.qrc +++ b/assets/resources.qrc @@ -4,5 +4,15 @@ ico_warning.png ico_setting.png ico_info.png + connect.png + cursor-hot.png + power-hot.png + settings-hot.png + circle.png + circle-hot.png + circle-pressed.png + sleep-hot.png + wifi-hot.png + brightness-hot.png diff --git a/assets/settings-hot.png b/assets/settings-hot.png new file mode 100644 index 0000000..ddf6e86 Binary files /dev/null and b/assets/settings-hot.png differ diff --git a/assets/sleep-hot.png b/assets/sleep-hot.png new file mode 100644 index 0000000..f6f7480 Binary files /dev/null and b/assets/sleep-hot.png differ diff --git a/assets/wifi-hot.png b/assets/wifi-hot.png new file mode 100644 index 0000000..e26ee63 Binary files /dev/null and b/assets/wifi-hot.png differ diff --git a/include/f1x/openauto/autoapp/UI/MainWindow.hpp b/include/f1x/openauto/autoapp/UI/MainWindow.hpp index b7e2354..05d7ebd 100644 --- a/include/f1x/openauto/autoapp/UI/MainWindow.hpp +++ b/include/f1x/openauto/autoapp/UI/MainWindow.hpp @@ -20,6 +20,7 @@ #include #include +#include namespace Ui { @@ -47,9 +48,20 @@ signals: void openSettings(); void toggleCursor(); void openConnectDialog(); + void showBrightnessSlider(); + +private slots: + void on_horizontalSliderBrightness_valueChanged(int value); + +private slots: + void on_pushButtonBrightness_clicked(); private: Ui::MainWindow* ui_; + bool brightnessSliderVisible = false; + QString brightnessFilename = "/sys/class/backlight/rpi_backlight/brightness"; + QFile *brightnessFile; + char brightness_str[5]; }; } diff --git a/src/autoapp/UI/MainWindow.cpp b/src/autoapp/UI/MainWindow.cpp index 49954f8..92f78a4 100644 --- a/src/autoapp/UI/MainWindow.cpp +++ b/src/autoapp/UI/MainWindow.cpp @@ -18,6 +18,8 @@ #include #include +#include +#include #include "ui_mainwindow.h" namespace f1x @@ -33,11 +35,37 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui_(new Ui::MainWindow) { + + this->setStyleSheet("QMainWindow {background-color: rgb(0,0,0);} \ + QPushButton { background: url(:/circle.png); border: 0; } \ + QPushButton:hover { background: url(:/circle-hot.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(); + } + if (wallpaperFileExists) { + this->setStyleSheet( this->styleSheet().append("QMainWindow { background: url(wallpaper.png) }") ); + } else { + this->setStyleSheet( this->styleSheet().append("QMainWindow { background: url(:/connect.png) }") ); + } + ui_->setupUi(this); connect(ui_->pushButtonSettings, &QPushButton::clicked, this, &MainWindow::openSettings); connect(ui_->pushButtonExit, &QPushButton::clicked, this, &MainWindow::exit); connect(ui_->pushButtonToggleCursor, &QPushButton::clicked, this, &MainWindow::toggleCursor); connect(ui_->pushButtonWirelessConnection, &QPushButton::clicked, this, &MainWindow::openConnectDialog); + connect(ui_->pushButtonBrightness, &QPushButton::clicked, this, &MainWindow::showBrightnessSlider); + ui_->pushButtonToggleCursor->hide(); + ui_->horizontalSliderBrightness->hide(); + + QFileInfo brightnessFile(brightnessFilename); + if (!brightnessFile.exists()) { + ui_->pushButtonBrightness->hide(); + } } MainWindow::~MainWindow() @@ -49,3 +77,37 @@ MainWindow::~MainWindow() } } } + +void f1x::openauto::autoapp::ui::MainWindow::on_pushButtonBrightness_clicked() +{ + this->brightnessSliderVisible = !this->brightnessSliderVisible; + if (this->brightnessSliderVisible) { + // Get the current brightness value + this->brightnessFile = new QFile(this->brightnessFilename); + if (this->brightnessFile->open(QIODevice::ReadOnly)) { + QByteArray data = this->brightnessFile->readAll(); + std::string::size_type sz; + int brightness_val = std::stoi(data.toStdString(), &sz); + ui_->horizontalSliderBrightness->setValue(brightness_val); + this->brightnessFile->close(); + } + + ui_->horizontalSliderBrightness->show(); + } else { + ui_->horizontalSliderBrightness->hide(); + } +} + +void f1x::openauto::autoapp::ui::MainWindow::on_horizontalSliderBrightness_valueChanged(int value) +{ + int n = snprintf(this->brightness_str, 4, "%d", value); + + this->brightnessFile = new QFile(this->brightnessFilename); + + if (this->brightnessFile->open(QIODevice::WriteOnly)) { + this->brightness_str[n] = '\n'; + this->brightness_str[n+1] = '\0'; + this->brightnessFile->write(this->brightness_str); + this->brightnessFile->close(); + } +} diff --git a/src/autoapp/UI/mainwindow.ui b/src/autoapp/UI/mainwindow.ui index 6da956e..2b97899 100644 --- a/src/autoapp/UI/mainwindow.ui +++ b/src/autoapp/UI/mainwindow.ui @@ -13,48 +13,25 @@ MainWindow - - background-color: rgb(46, 52, 54); -color: rgb(238, 238, 236); - - - - - 290 - 30 - 281 - 41 - - - - <html><head/><body><p><span style=" font-size:22pt; font-weight:600; font-style:italic; color:#3465a4;">Waiting for device...</span></p></body></html> - - - - - - 180 - 20 - 101 - 101 - - - - <html><head/><body><p><img src=":/ico_androidauto.png"/></p></body></html> - - - 630 - 370 - 161 - 41 + 10 + 10 + 64 + 64 - - Settings + + + :/settings-hot.png:/settings-hot.png + + + + 64 + 64 + false @@ -62,144 +39,63 @@ color: rgb(238, 238, 236); false + + true + - 630 - 420 - 161 - 41 + 10 + 360 + 64 + 64 - - Exit + + + :/power-hot.png:/power-hot.png + + + + 64 + 64 + false - - - - - 340 - 70 - 301 - 31 - - - - <html><head/><body><p><span style=" font-style:italic; color:#eeeeec;">Plug in your device to start AndroidAuto (tm).</span></p></body></html> - - - - - - 10 - 440 - 271 - 21 - - - - <html><head/><body><p><a href="https://github.com/f1xpl/openauto"><span style=" text-decoration: underline; color:#007af4;">https://github.com/f1xpl/openauto</span></a></p></body></html> - - - - - - 30 - 170 - 31 - 41 - - - - <html><head/><body><p><img src=":/ico_warning.png"/></p></body></html> - - - - - - 80 - 130 - 531 - 101 - - - - <html><head/><body><p align="center"><span style=" color:#ef2929;">WARNING!</span></p><p><span style=" color:#ef2929;">Distraction may cause accidents. Do not attempt to operate while driving. Always concentrate on driving and obey Traffic Regulations. You assume total responsibility and risk for using this software.</span></p></body></html> - - + true - - - - 80 - 240 - 531 - 121 - - - - <html><head/><body><p><span style=" color:#ef2929;">This software is not certified by Google Inc. It is created for R&amp;D purposes and may not work as expected by the original authors. Do not use while driving.</span></p><p><span style=" color:#ef2929;">You use this software at your own risk.</span></p></body></html> - - - true - - - - - - 30 - 270 - 31 - 41 - - - - <html><head/><body><p><img src=":/ico_warning.png"/></p></body></html> - - - - - - 220 - 400 - 21 - 31 - - - - <html><head/><body><p><img src=":/ico_info.png"/></p></body></html> - - - - - - 250 - 400 - 361 - 31 - - - - <html><head/><body><p><span style=" font-style:italic;">AndroidAuto is registered trademark of Google Inc.</span></p></body></html> - - - 630 - 270 - 161 - 41 + 10 + 150 + 64 + 64 + + Qt::ClickFocus + + + display: none; + - Toggle cursor + + + + + :/cursor-hot.png:/cursor-hot.png + + + + 64 + 64 + false @@ -207,18 +103,51 @@ color: rgb(238, 238, 236); false + + true + - 630 - 320 - 161 - 41 + 10 + 80 + 64 + 64 - - Wireless connection + + + :/wifi-hot.png:/wifi-hot.png + + + + 64 + 64 + + + + true + + + + + + 10 + 220 + 64 + 64 + + + + + :/brightness-hot.png:/brightness-hot.png + + + + 64 + 64 + false @@ -226,6 +155,31 @@ color: rgb(238, 238, 236); false + + true + + + + + + 80 + 230 + 221 + 41 + + + + 1 + + + 255 + + + 5 + + + Qt::Horizontal + @@ -235,6 +189,8 @@ color: rgb(238, 238, 236); pushButtonSettings pushButtonExit - + + + diff --git a/src/autoapp/autoapp.cpp b/src/autoapp/autoapp.cpp index 8c2565c..b8ee6d8 100644 --- a/src/autoapp/autoapp.cpp +++ b/src/autoapp/autoapp.cpp @@ -102,11 +102,13 @@ int main(int argc, char* argv[]) QObject::connect(&mainWindow, &autoapp::ui::MainWindow::openSettings, &settingsWindow, &autoapp::ui::SettingsWindow::showFullScreen); QObject::connect(&mainWindow, &autoapp::ui::MainWindow::openConnectDialog, &connectDialog, &autoapp::ui::ConnectDialog::exec); +#ifdef RPI3_BUILD qApplication.setOverrideCursor(Qt::BlankCursor); QObject::connect(&mainWindow, &autoapp::ui::MainWindow::toggleCursor, [&qApplication]() { const auto cursor = qApplication.overrideCursor()->shape() == Qt::BlankCursor ? Qt::ArrowCursor : Qt::BlankCursor; qApplication.setOverrideCursor(cursor); }); +#endif mainWindow.showFullScreen();