-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathutils.hxx
More file actions
70 lines (53 loc) · 1.36 KB
/
utils.hxx
File metadata and controls
70 lines (53 loc) · 1.36 KB
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
#ifndef FRONT_END_UTILS_HXX
#define FRONT_END_UTILS_HXX
#include <qcolor.h>
#include <qcontainerfwd.h>
#include <qicon.h>
#include <qmessagebox.h>
#include <qpixmap.h>
#include <qstringview.h>
#include <qwidget.h>
#include <initializer_list>
#include <type_traits>
#include <vector>
#include "error_types.hxx"
using std::abort;
using std::initializer_list;
using std::is_same_v;
using std::stringstream;
using std::vector;
namespace Lazyboard::front_end_utils {
template <typename T>
concept is_qcolor = requires(const T& t) { QColor(t); };
template <is_qcolor... Args>
inline constexpr bool is_valid_hex_color(const Args&... args) noexcept {
return (
[&]() {
QColor color(args);
if (!color.isValid()) {
return false;
}
return true;
}(),
...);
}
inline QIcon image_from_bytes(const initializer_list<uint8_t>& data) noexcept {
QByteArray bytes_array;
bytes_array.reserve(static_cast<int>(data.size()));
for (auto byte : data) {
bytes_array.append(static_cast<char>(byte));
}
QPixmap pixmap;
if (pixmap.loadFromData(bytes_array)) {
return QIcon(pixmap);
}
return QIcon();
}
inline void error_dialog_show(QWidget* parent,
ErrorTypes error_types) noexcept {
auto error_string = error_to_string(error_types).data();
QMessageBox::critical(parent, "Error", error_string);
abort();
}
} // namespace Lazyboard::front_end_utils
#endif