Repository navigation
Expand file tree
/
Copy pathwebapp.cpp
More file actions
70 lines (56 loc) · 1.33 KB
/
Copy pathwebapp.cpp
File metadata and controls
70 lines (56 loc) · 1.33 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
#include "webapp.h"
#include <QDebug>
#include <QUndoStack>
WebApp *WebApp::m_instance = NULL;
WebApp::WebApp(QObject *parent) :QWebPage(parent)
{
m_isSidebarVisible = true;
m_undoStack = this->undoStack();
connect(this->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(attachObject()));
connect(m_undoStack, SIGNAL(canUndoChanged(bool)), this, SLOT(undoChanged(bool)));
}
void WebApp::loadFile(const QString &filePath)
{
mainFrame()->setUrl(QUrl(filePath));
}
QVariant WebApp::eval(const QString &scriptSource)
{
return mainFrame()->evaluateJavaScript(scriptSource);
}
void WebApp::addObject(const QString &name, QObject *object)
{
mainFrame()->addToJavaScriptWindowObject(name, object);
}
void WebApp::log(const QString &text)
{
eval(tr("log('%1')").arg(text));
}
void WebApp::attachObject()
{
addObject("APP", this);
}
bool WebApp::isSidebarVisible()
{
return m_isSidebarVisible;
}
void WebApp::setSidebarVisible(bool visible)
{
if(m_isSidebarVisible != visible)
{
m_isSidebarVisible = visible;
emit toggleSidebar(visible);
}
}
void WebApp::undoChanged(bool change)
{
qDebug()<<"Undo changed: "<<change;
qDebug()<<"Redo: "<<m_undoStack->canRedo();
}
void WebApp::undo()
{
eval("editor.undo()");
}
void WebApp::redo()
{
eval("editor.redo()");
}