use QStandardPaths to get resource locations (#44)

* use QStandardPaths to get resource locations

While this shouldn't change behaviour for windows, it allows installing the resource files seperate from the binary on unix systems

* initialize battery overlay handles to 0
This commit is contained in:
Robin Appelman
2019-01-12 16:34:45 -06:00
committed by ykeara
parent b418c76315
commit e75a4c2353
5 changed files with 43 additions and 34 deletions
+7 -6
View File
@@ -70,13 +70,14 @@ void AudioTabController::initStage2( OverlayController* var_parent,
notifKey.c_str(), notifKey.c_str(), &m_ulNotificationOverlayHandle );
if ( overlayError == vr::VROverlayError_None )
{
std::string notifIconPath
= QApplication::applicationDirPath().toStdString()
+ "/res/qml/ptt_notification.png";
if ( QFile::exists( QString::fromStdString( notifIconPath ) ) )
QString notifIconPath = QStandardPaths::locate(
QStandardPaths::AppDataLocation,
QStringLiteral( "/res/qml/ptt_notification.png" ) );
if ( QFile::exists( notifIconPath ) )
{
vr::VROverlay()->SetOverlayFromFile( m_ulNotificationOverlayHandle,
notifIconPath.c_str() );
vr::VROverlay()->SetOverlayFromFile(
m_ulNotificationOverlayHandle,
notifIconPath.toStdString().c_str() );
vr::VROverlay()->SetOverlayWidthInMeters(
m_ulNotificationOverlayHandle, 0.02f );
vr::HmdMatrix34_t notificationTransform
+19 -16
View File
@@ -267,6 +267,14 @@ void UtilitiesTabController::modAlarmTimeMinute( int value, bool notify )
}
}
QString getBatteryIconPath( int batteryState )
{
QString batteryPrefix = "/res/battery_";
return QStandardPaths::locate(
QStandardPaths::AppDataLocation,
batteryPrefix + QString::number( batteryState ) + ".png" );
}
vr::VROverlayHandle_t createBatteryOverlay( vr::TrackedDeviceIndex_t index )
{
vr::VROverlayHandle_t handle = vr::k_ulOverlayHandleInvalid;
@@ -276,13 +284,11 @@ vr::VROverlayHandle_t createBatteryOverlay( vr::TrackedDeviceIndex_t index )
batteryKey.c_str(), batteryKey.c_str(), &handle );
if ( overlayError == vr::VROverlayError_None )
{
std::string batteryIconPath
= QApplication::applicationDirPath().toStdString()
+ "/res/battery_0.png";
if ( QFile::exists( QString::fromStdString( batteryIconPath ) ) )
QString batteryIconPath = getBatteryIconPath( 0 );
if ( QFile::exists( batteryIconPath ) )
{
vr::VROverlay()->SetOverlayFromFile( handle,
batteryIconPath.c_str() );
vr::VROverlay()->SetOverlayFromFile(
handle, batteryIconPath.toStdString().c_str() );
vr::VROverlay()->SetOverlayWidthInMeters( handle, 0.05f );
vr::HmdMatrix34_t notificationTransform
= { { { 1.0f, 0.0f, 0.0f, 0.00f },
@@ -486,8 +492,7 @@ void UtilitiesTabController::eventLoopTick()
if ( deviceClass
== vr::ETrackedDeviceClass::TrackedDeviceClass_GenericTracker )
{
if ( m_batteryOverlayHandles[i]
== vr::k_ulOverlayHandleInvalid )
if ( m_batteryOverlayHandles[i] == 0 )
{
LOG( INFO ) << "Creating battery overlay for device " << i;
m_batteryOverlayHandles[i] = createBatteryOverlay( i );
@@ -529,17 +534,15 @@ void UtilitiesTabController::eventLoopTick()
{
LOG( INFO )
<< "Updating battery overlay for device " << i
<< " to " << batteryState << "(" << battery << "";
std::string batteryIconPath
= QApplication::applicationDirPath().toStdString()
+ "/res/battery_" + std::to_string( batteryState )
+ ".png";
if ( QFile::exists(
QString::fromStdString( batteryIconPath ) ) )
<< " to " << batteryState << "(" << battery << ")"
<< QString::number( m_batteryOverlayHandles[i] );
QString batteryIconPath
= getBatteryIconPath( batteryState );
if ( QFile::exists( batteryIconPath ) )
{
vr::VROverlay()->SetOverlayFromFile(
m_batteryOverlayHandles[i],
batteryIconPath.c_str() );
batteryIconPath.toStdString().c_str() );
}
else
{
+2 -2
View File
@@ -44,8 +44,8 @@ private:
QTime m_alarmLastCheckTime;
bool m_steamDesktopOverlayAvailable = false;
float m_steamDesktopOverlayWidth = 4.0f;
vr::VROverlayHandle_t
m_batteryOverlayHandles[vr::k_unMaxTrackedDeviceCount];
vr::VROverlayHandle_t m_batteryOverlayHandles[vr::k_unMaxTrackedDeviceCount]
= { 0 };
int m_batteryState[vr::k_unMaxTrackedDeviceCount];
bool m_batteryVisible[vr::k_unMaxTrackedDeviceCount];