Skip to content

Commit

Permalink
SubtitleWriter: update to use new intruments widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Williangalvani authored and DonLakeFlyer committed Jan 27, 2021
1 parent fa77875 commit b9f319b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
34 changes: 24 additions & 10 deletions src/VideoManager/SubtitleWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include "SubtitleWriter.h"
#include "QGCApplication.h"
#include "QGCCorePlugin.h"
#include "FactValueGrid.h"
#include "HorizontalFactValueGrid.h"
#include "InstrumentValueData.h"
#include <QDateTime>
#include <QString>
#include <QDate>
Expand All @@ -33,11 +36,22 @@ SubtitleWriter::SubtitleWriter(QObject* parent)

void SubtitleWriter::startCapturingTelemetry(const QString& videoFile)
{
// Get the facts displayed in the values widget and capture them, removing the "Vehicle." prefix.
QSettings settings;
settings.beginGroup("ValuesWidget");
_values = settings.value("large").toStringList().replaceInStrings(QStringLiteral("Vehicle."), QString());
_values += settings.value("small").toStringList().replaceInStrings(QStringLiteral("Vehicle."), QString());
// Delete facts of last run
_facts.clear();

// Gather the facts currently displayed into _facts
FactValueGrid* grid = new FactValueGrid();
grid->setProperty("userSettingsGroup", HorizontalFactValueGrid::telemetryBarUserSettingsGroup);
grid->setProperty("defaultSettingsGroup", HorizontalFactValueGrid::telemetryBarDefaultSettingsGroup);
grid->_loadSettings();
for (int colIndex = 0; colIndex < grid->columns()->count(); colIndex++) {
QmlObjectListModel* list = grid->columns()->value<QmlObjectListModel*>(colIndex);
for (int rowIndex = 0; rowIndex < list->count(); rowIndex++) {
InstrumentValueData* value = list->value<InstrumentValueData*>(rowIndex);
_facts += value->fact();
}
}
grid->deleteLater();

// One subtitle always starts where the previous ended
_lastEndTime = QTime(0, 0);
Expand Down Expand Up @@ -102,10 +116,10 @@ void SubtitleWriter::_captureTelemetry()
QStringList valuesStrings;

// Make a list of "factname:" strings and other with the values, so one can be aligned left and the other right
for (const auto& i : _values) {
valuesStrings << QStringLiteral("%2 %3").arg(vehicle->getFact(i)->cookedValueString())
.arg(vehicle->getFact(i)->cookedUnits());
namesStrings << QStringLiteral("%1:").arg(vehicle->getFact(i)->shortDescription());
for (const Fact* fact : _facts) {
valuesStrings << QStringLiteral("%2 %3").arg(fact->cookedValueString())
.arg(fact->cookedUnits());
namesStrings << QStringLiteral("%1:").arg(fact->shortDescription());
}

// The time to start displaying this subtitle text
Expand All @@ -118,7 +132,7 @@ void SubtitleWriter::_captureTelemetry()
// This splits the screen in N parts and uses the N-1 internal parts to align the subtitles to.
// Should we try to get the resolution from the pipeline? This seems to work fine with other resolutions too.
static const int rowWidth = (1920 + offsetFactor)/(nRows+1);
int nValuesByRow = ceil(_values.length() / nRows);
int nValuesByRow = ceil(_facts.length() / nRows);

QList<QStringList> dataColumns;
QStringList stringColumns;
Expand Down
5 changes: 3 additions & 2 deletions src/VideoManager/SubtitleWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#pragma once

#include "QGCLoggingCategory.h"
#include "Fact.h"
#include <QObject>
#include <QTimer>
#include <QDateTime>
Expand All @@ -42,9 +43,9 @@ private slots:

private:
QTimer _timer;
QStringList _values;
QList<Fact*> _facts;
QTime _lastEndTime;
QFile _file;

static const int _sampleRate;
static const int _sampleRate; // Sample rate in Hz for getting telemetry data, most players do weird stuff when > 1Hz
};

0 comments on commit b9f319b

Please sign in to comment.