forked from adctl/adctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.cpp
executable file
·68 lines (61 loc) · 1.71 KB
/
utils.cpp
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
#include "utils.h"
#include <QMetaMethod>
#include <QQmlEngine>
#include <QQmlContext>
#include <QQmlApplicationEngine>
#include <QQuickWindow>
#include <QFileInfo>
#include <QFile>
#include <QDir>
#include <QDateTime>
#include <QStandardPaths>
#include <QDebug>
Util* Util::m_instance = nullptr;
Util* Util::getInstance() {
if(!m_instance){
m_instance = new Util;
}
return m_instance;
}
QString Util::screenShot()
{
if(qml_engine){
return Util::takeScreenShot(qml_engine);
}
return QString();
}
bool Util::javaScriptFuncExists(QObject* object, const char* method)
{
const QMetaObject* m = object->metaObject();
for (int i = 0 ; i < m->methodCount() ; i++ ) {
if (m->method(i).name() == method) {
return true;
}
}
return false;
}
QString Util::takeScreenShot(QQmlEngine* engine)
{
QString filename= QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
filename+= "/app_screenshot";
filename+= QDateTime::currentDateTime().toString(Qt::ISODate).replace(":","");
filename+= ".png";
QQmlApplicationEngine* app_eng = qobject_cast<QQmlApplicationEngine*>(engine);
if(app_eng){
foreach(QObject* obj, app_eng->rootObjects()) {
QQuickWindow* window = qobject_cast<QQuickWindow*>(obj);
if (window) {
QImage image = window->grabWindow();
bool saved =image.save(filename);
qDebug() << "image_path = " << filename;
qDebug() << "image_size = " << image.size();
if(saved){
qDebug() << "Image saved";
}else{
qDebug() << "Image save failed";
}
}
}
}
return filename;
}