[GUI] New assets and functionalities to Crankshaft

This commit is contained in:
Huan Truong 2018-03-02 17:22:33 -05:00
parent 4623f6b09b
commit 16a09529e8
15 changed files with 204 additions and 162 deletions

BIN
assets/brightness-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

BIN
assets/circle-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
assets/circle-pressed.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
assets/circle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
assets/connect.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
assets/cursor-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
assets/power-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -4,5 +4,15 @@
<file>ico_warning.png</file>
<file>ico_setting.png</file>
<file>ico_info.png</file>
<file>connect.png</file>
<file>cursor-hot.png</file>
<file>power-hot.png</file>
<file>settings-hot.png</file>
<file>circle.png</file>
<file>circle-hot.png</file>
<file>circle-pressed.png</file>
<file>sleep-hot.png</file>
<file>wifi-hot.png</file>
<file>brightness-hot.png</file>
</qresource>
</RCC>

BIN
assets/settings-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
assets/sleep-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
assets/wifi-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -20,6 +20,7 @@
#include <memory>
#include <QMainWindow>
#include <QFile>
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];
};
}

View File

@ -18,6 +18,8 @@
#include <QApplication>
#include <f1x/openauto/autoapp/UI/MainWindow.hpp>
#include <QFileInfo>
#include <QFile>
#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();
}
}

View File

@ -13,48 +13,25 @@
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(46, 52, 54);
color: rgb(238, 238, 236);</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QLabel" name="labelWaitingForDevice">
<property name="geometry">
<rect>
<x>290</x>
<y>30</y>
<width>281</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:22pt; font-weight:600; font-style:italic; color:#3465a4;&quot;&gt;Waiting for device...&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>180</x>
<y>20</y>
<width>101</width>
<height>101</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;img src=&quot;:/ico_androidauto.png&quot;/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QPushButton" name="pushButtonSettings">
<property name="geometry">
<rect>
<x>630</x>
<y>370</y>
<width>161</width>
<height>41</height>
<x>10</x>
<y>10</y>
<width>64</width>
<height>64</height>
</rect>
</property>
<property name="text">
<string>Settings</string>
<property name="icon">
<iconset resource="../../../assets/resources.qrc">
<normaloff>:/settings-hot.png</normaloff>:/settings-hot.png</iconset>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="autoDefault">
<bool>false</bool>
@ -62,144 +39,63 @@ color: rgb(238, 238, 236);</string>
<property name="default">
<bool>false</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="pushButtonExit">
<property name="geometry">
<rect>
<x>630</x>
<y>420</y>
<width>161</width>
<height>41</height>
<x>10</x>
<y>360</y>
<width>64</width>
<height>64</height>
</rect>
</property>
<property name="text">
<string>Exit</string>
<property name="icon">
<iconset resource="../../../assets/resources.qrc">
<normaloff>:/power-hot.png</normaloff>:/power-hot.png</iconset>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
<widget class="QLabel" name="labelPluginDeviceText">
<property name="geometry">
<rect>
<x>340</x>
<y>70</y>
<width>301</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-style:italic; color:#eeeeec;&quot;&gt;Plug in your device to start AndroidAuto (tm).&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QLabel" name="labelProjectHomePage">
<property name="geometry">
<rect>
<x>10</x>
<y>440</y>
<width>271</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/f1xpl/openauto&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#007af4;&quot;&gt;https://github.com/f1xpl/openauto&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QLabel" name="labelDistractionWarningIcon">
<property name="geometry">
<rect>
<x>30</x>
<y>170</y>
<width>31</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;img src=&quot;:/ico_warning.png&quot;/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QLabel" name="labelDistractionWarning">
<property name="geometry">
<rect>
<x>80</x>
<y>130</y>
<width>531</width>
<height>101</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; color:#ef2929;&quot;&gt;WARNING!&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; color:#ef2929;&quot;&gt;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.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<property name="flat">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="labelCertificationWarning">
<property name="geometry">
<rect>
<x>80</x>
<y>240</y>
<width>531</width>
<height>121</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; color:#ef2929;&quot;&gt;This software is not certified by Google Inc. It is created for R&amp;amp;D purposes and may not work as expected by the original authors. Do not use while driving.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; color:#ef2929;&quot;&gt;You use this software at your own risk.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="labelCertificationWarningIcon">
<property name="geometry">
<rect>
<x>30</x>
<y>270</y>
<width>31</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;img src=&quot;:/ico_warning.png&quot;/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QLabel" name="labelCopyrightsInfoIcon">
<property name="geometry">
<rect>
<x>220</x>
<y>400</y>
<width>21</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;img src=&quot;:/ico_info.png&quot;/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QLabel" name="labelTrademark">
<property name="geometry">
<rect>
<x>250</x>
<y>400</y>
<width>361</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;AndroidAuto is registered trademark of Google Inc.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QPushButton" name="pushButtonToggleCursor">
<property name="geometry">
<rect>
<x>630</x>
<y>270</y>
<width>161</width>
<height>41</height>
<x>10</x>
<y>150</y>
<width>64</width>
<height>64</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="styleSheet">
<string notr="true">display: none;</string>
</property>
<property name="text">
<string>Toggle cursor</string>
<string/>
</property>
<property name="icon">
<iconset resource="../../../assets/resources.qrc">
<normaloff>:/cursor-hot.png</normaloff>:/cursor-hot.png</iconset>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="autoDefault">
<bool>false</bool>
@ -207,18 +103,51 @@ color: rgb(238, 238, 236);</string>
<property name="default">
<bool>false</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="pushButtonWirelessConnection">
<property name="geometry">
<rect>
<x>630</x>
<y>320</y>
<width>161</width>
<height>41</height>
<x>10</x>
<y>80</y>
<width>64</width>
<height>64</height>
</rect>
</property>
<property name="text">
<string>Wireless connection</string>
<property name="icon">
<iconset resource="../../../assets/resources.qrc">
<normaloff>:/wifi-hot.png</normaloff>:/wifi-hot.png</iconset>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="pushButtonBrightness">
<property name="geometry">
<rect>
<x>10</x>
<y>220</y>
<width>64</width>
<height>64</height>
</rect>
</property>
<property name="icon">
<iconset resource="../../../assets/resources.qrc">
<normaloff>:/brightness-hot.png</normaloff>:/brightness-hot.png</iconset>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="autoDefault">
<bool>false</bool>
@ -226,6 +155,31 @@ color: rgb(238, 238, 236);</string>
<property name="default">
<bool>false</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
<widget class="QSlider" name="horizontalSliderBrightness">
<property name="geometry">
<rect>
<x>80</x>
<y>230</y>
<width>221</width>
<height>41</height>
</rect>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>255</number>
</property>
<property name="singleStep">
<number>5</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</widget>
</widget>
@ -235,6 +189,8 @@ color: rgb(238, 238, 236);</string>
<tabstop>pushButtonSettings</tabstop>
<tabstop>pushButtonExit</tabstop>
</tabstops>
<resources/>
<resources>
<include location="../../../assets/resources.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -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();