aboutsummaryrefslogtreecommitdiff
path: root/stftxtexport.cc
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2021-09-16 10:56:37 +0200
committerJavier <dev.git@javispedro.com>2021-09-16 10:56:37 +0200
commitb78e171537fe8cc227521bb6b12bfb923a248f08 (patch)
tree62dac723ef9fc0647f5667635a4e235dbb625bdd /stftxtexport.cc
parent5d87ef1a3500c6e7b003a3a54a38b0ce7ab5abb1 (diff)
downloadscribiu-b78e171537fe8cc227521bb6b12bfb923a248f08.tar.gz
scribiu-b78e171537fe8cc227521bb6b12bfb923a248f08.zip
replace txt export support with specific txyz export
Diffstat (limited to 'stftxtexport.cc')
-rw-r--r--stftxtexport.cc39
1 files changed, 25 insertions, 14 deletions
diff --git a/stftxtexport.cc b/stftxtexport.cc
index 0163848..e6793b2 100644
--- a/stftxtexport.cc
+++ b/stftxtexport.cc
@@ -20,32 +20,42 @@
#include <QtCore/QTextStream>
#include "stftxtexport.h"
-class StfToTxtStrokeList : public StfReader::StrokeHandler {
+class StfToTXYP : public StfReader::StrokeHandler {
QTextStream _out;
QPoint _lastP;
- qint64 _lastTime;
+ int _lastForce;
+ qint64 _startTime;
+ bool _relativeTime;
public:
- StfToTxtStrokeList(QIODevice *out)
- : _out(out) {
+ StfToTXYP(QIODevice *out, bool relativeTime)
+ : _out(out), _lastP(), _lastForce(0), _startTime(0), _relativeTime(relativeTime) {
+ _out << "T\tX\tY\tP\n";
}
bool startStroke(const QPoint& p, int force, qint64 time) {
- _out << time << " penDown " << p.x() << ' ' << p.y() << ' ' << force << '\n';
+ if (_relativeTime && _startTime == 0) {
+ _startTime = time;
+ }
+ _out << (time - _startTime) << '\t' << p.x() << '\t' << p.y() << '\t' << force << '\n';
_lastP = p;
- _lastTime = time;
+ _lastForce = force;
return true;
}
bool strokePoint(const QPoint& p, int force, qint64 time) {
- _out << time << " penMove " << p.x() << ' ' << p.y() << ' ' << force << '\n';
+ _out << (time - _startTime) << '\t' << p.x() << '\t' << p.y() << '\t' << force << '\n';
_lastP = p;
- _lastTime = time;
+ _lastForce = force;
return true;
}
bool endStroke(qint64 time) {
- _out << time << " penUp " << _lastP.x() << ' ' << _lastP.y() << ' ' << 0 << '\n';
+ // Ensure there is a entry with force=0, in case the pen didn't provide it
+ if (_lastForce != 0) {
+ _out << (time - _startTime) << '\t' << _lastP.x() << '\t' << _lastP.y() << '\t' << 0 << '\n';
+ _lastForce = 0;
+ }
return true;
}
};
@@ -55,11 +65,15 @@ StfTxtExport::StfTxtExport(AfdNotebook *nb)
{
}
-void StfTxtExport::exportStrokeList(QIODevice *out, int pageNum)
+void StfTxtExport::exportToTXYP(QIODevice *out, int pageNum, bool relativeTime)
{
QStringList pens = _nb->penSerials();
if (pens.isEmpty()) return;
+ StfToTXYP h(out, relativeTime);
+ StfReader r;
+ r.setStrokeHandler(&h);
+
QStringList strokeFiles = _nb->strokeFiles(pens.first(), pageNum);
foreach (const QString &strokeFile, strokeFiles) {
QFile in(strokeFile);
@@ -68,11 +82,8 @@ void StfTxtExport::exportStrokeList(QIODevice *out, int pageNum)
continue;
}
- StfToTxtStrokeList h(out);
- StfReader r;
- r.setStrokeHandler(&h);
if (!r.parse(&in)) {
- qWarning() << "Could not open parse file:" << strokeFile;
+ qWarning() << "Could not parse stroke file:" << strokeFile;
continue;
}
}