Browse Source

SubtitleWriter: update to use new intruments widget

QGC4.4
Willian Galvani 5 years ago committed by Don Gagne
parent
commit
fc61f1a089
  1. 34
      src/VideoManager/SubtitleWriter.cc
  2. 5
      src/VideoManager/SubtitleWriter.h

34
src/VideoManager/SubtitleWriter.cc

@ -17,6 +17,9 @@ @@ -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>
@ -33,11 +36,22 @@ SubtitleWriter::SubtitleWriter(QObject* parent) @@ -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);
@ -102,10 +116,10 @@ void SubtitleWriter::_captureTelemetry() @@ -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
@ -118,7 +132,7 @@ void SubtitleWriter::_captureTelemetry() @@ -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;

5
src/VideoManager/SubtitleWriter.h

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
#pragma once
#include "QGCLoggingCategory.h"
#include "Fact.h"
#include <QObject>
#include <QTimer>
#include <QDateTime>
@ -42,9 +43,9 @@ private slots: @@ -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
};

Loading…
Cancel
Save