utils.h 1.97 KB
Newer Older
Thiago Santini's avatar
Thiago Santini committed
1 2 3 4
#ifndef UTILS_H
#define UTILS_H

#include <atomic>
5
#include <iostream>
Thiago Santini's avatar
Thiago Santini committed
6

7
#include <QCameraViewfinderSettings>
Thiago Santini's avatar
Thiago Santini committed
8
#include <QDateTime>
9 10
#include <QDebug>
#include <QElapsedTimer>
Thiago Santini's avatar
Thiago Santini committed
11 12
#include <QFile>
#include <QMutex>
13
#include <QTextStream>
14

Thiago Santini's avatar
Thiago Santini committed
15
#include <QCameraInfo>
16 17
Q_DECLARE_METATYPE(QCameraInfo)

Thiago Santini's avatar
Thiago Santini committed
18
#include <QSettings>
19
#include <QSoundEffect>
20
#include <QWidget>
Thiago Santini's avatar
Thiago Santini committed
21

Thiago Santini's avatar
Thiago Santini committed
22 23
#include "LogWidget.h"

Thiago Santini's avatar
Thiago Santini committed
24
typedef qint64 Timestamp;
25
extern const Timestamp maxTimestamp;
26
Q_DECLARE_METATYPE(Timestamp)
Thiago Santini's avatar
Thiago Santini committed
27

28 29 30
// useful common tokens for data
class Token {
public:
31 32 33 34
    static const char Delimiter;
    static const char Newline;
    static const char JournalEntry;
    static const char HeaderEntry;
Thiago Santini's avatar
Thiago Santini committed
35 36 37 38
    static const char MarkerIdDelimiter;
    static const char MarkerValueDelimiter;
    static const char MarkerEnd;
    static const int Precision;
39 40
};

Thiago Santini's avatar
Thiago Santini committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
template <typename T>
inline QString journalField(const T& v)
{
    return QString("%1%2").arg(v).arg(Token::Delimiter);
}
template <>
inline QString journalField<double>(const double& v)
{
    return QString("%1%2").arg(v, 0, 'g', Token::Precision).arg(Token::Delimiter);
}
template <>
inline QString journalField<float>(const float& v)
{
    return journalField(static_cast<double>(v));
}

Thiago Santini's avatar
Thiago Santini committed
57 58 59 60
/*
 * Utility functions
 */

Thiago Santini's avatar
Thiago Santini committed
61 62
QDebug
operator<<(QDebug dbg, const QCameraViewfinderSettings& p);
Thiago Santini's avatar
Thiago Santini committed
63 64 65

void logInitBanner();
void logExitBanner();
66
void logMessages(QtMsgType type, const QMessageLogContext& context, const QString& msg);
Thiago Santini's avatar
Thiago Santini committed
67 68 69 70 71 72

QString toQString(QVideoFrame::PixelFormat format);
QString toQString(QCameraViewfinderSettings setting);

QString iniStr(QString str);

73
template <typename T>
74 75
T ns2ms(const T v) { return 1.0e-6 * v; }

76
void delay(const int& thMs);
Thiago Santini's avatar
Thiago Santini committed
77

78 79
template <typename T>
void set(const QSettings* settings, const QString key, T& v)
Thiago Santini's avatar
Thiago Santini committed
80 81 82 83 84 85 86 87
{
    if (!settings)
        return;
    QVariant variant = settings->value(key);
    if (variant.isValid())
        v = qvariant_cast<T>(variant);
}

88
void loadSoundEffect(const QString& fileName, const QString& exeDir, QSoundEffect& effect);
89

Thiago Santini's avatar
Thiago Santini committed
90
#endif // UTILS_H