-
Notifications
You must be signed in to change notification settings - Fork 1
/
Utils.h
93 lines (76 loc) · 2.48 KB
/
Utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* \file Utils.h
* \brief Utils
*/
#pragma once
#include "Common.h"
//-------------------------------------------------------------------------------------------------
namespace qtlib
{
class Utils
/// Utils
{
public:
///\name ctors, dtor
///\{
Utils() = delete;
///\}
///\name UI
static void widgetAlignCenter(QWidget *widget);
///< align main widget
static void widgetAlignTopCenter(QWidget *widget);
///< align main widget
static void widgetAlwaysOnTop(QWidget *widget, cbool isChecked);
///< toggle 'always on top' for a QWidget
static void widgetAlwaysOnTop(QMainWindow *window);
///< toggle 'always on top' for a QMainWindow
static void widgetActivate(QWidget *widget);
///< activate widget
///\}
///\name Grafics
static void imageConvert(cQString &filePathIn, QByteArray *photo, cQByteArray &format = "JPEG");
///< convert images
///\}
///\name Converters
static std::wstring toStdWString(cQString &str);
///< convert a QString to an std::wstring
static QString fromStdWString(const std::wstring &str);
///< convert an std::wstring to a QString
///\}
///\name Debug
static void debugTest(cQString &expression, cQString &filePath, culong fileLine,
cQString &functionName, cqint64 logSizeMaxBytes);
///< custom assert
static void debugTracer(QtMsgType type, const QMessageLogContext &context, cQString &msg);
///< callback for qInstallMessageHandler
///\}
///\name Etc
static void sleepMsec(cint timeoutMsec);
static QString clipBoardSelecrtionOrClipboard();
///\}
};
} // namespace qtlib
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
namespace qtlib
{
class AutoTrace
/// Auto trace logger
{
public:
explicit AutoTrace(const char *a_str) :
_str(a_str)
{
qDebug() << "\n\n::: Start " << _str << " (" << QDateTime::currentDateTime().toString() << ") :::";
}
~AutoTrace()
{
qDebug() << "\n::: Finish " << _str << " (" << QDateTime::currentDateTime().toString() << ") :::";
}
private:
const char *_str {};
};
#define qTRACE_SCOPE(s) qtlib::AutoTrace autoLog(s)
#define qTRACE_SCOPE_FUNC qTRACE_SCOPE(__FUNCTION__)
} // namespace qtlib
//-------------------------------------------------------------------------------------------------