utils.h 1.45 KB
Newer Older
Thiago Santini's avatar
Thiago Santini committed
1 2 3 4 5 6 7 8 9 10 11 12 13
#ifndef UTILS_H
#define UTILS_H

#include <iostream>
#include <atomic>

#include <QElapsedTimer>
#include <QDebug>
#include <QDateTime>
#include <QFile>
#include <QTextStream>
#include <QMutex>
#include <QCameraViewfinderSettings>
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 19
#include <QWidget>
#include <QSettings>
20
#include <QSoundEffect>
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 31 32
// useful common tokens for data
class Token {
public:
	static const char Delimiter = '\t';
	static const char Newline = '\n';
Thiago Santini's avatar
Thiago Santini committed
33 34
	static const char JournalEntry = 'J';
	static const char HeaderEntry = 'H';
35 36
};

Thiago Santini's avatar
Thiago Santini committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
/*
 * Utility functions
 */

QDebug operator<<(QDebug dbg, const QCameraViewfinderSettings &p);

void logInitBanner();
void logExitBanner();
void logMessages(QtMsgType type, const QMessageLogContext &context, const QString &msg);

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

QString iniStr(QString str);

52 53 54
template<typename T>
T ns2ms(const T v) { return 1.0e-6 * v; }

55
void delay(const int &thMs);
Thiago Santini's avatar
Thiago Santini committed
56

57 58
template<typename T>
void set(const QSettings *settings, const QString key, T &v)
Thiago Santini's avatar
Thiago Santini committed
59 60 61 62 63 64 65 66
{
    if (!settings)
        return;
    QVariant variant = settings->value(key);
    if (variant.isValid())
        v = qvariant_cast<T>(variant);
}

67
void loadSoundEffect(const QString &fileName, const QString &exeDir, QSoundEffect &effect);
68

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