-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
76 lines (60 loc) · 1.78 KB
/
example.js
File metadata and controls
76 lines (60 loc) · 1.78 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
71
72
73
74
75
76
var util = require('util');
var qt = require('./');
// create the basic window example with the improved event binding and accessors
function createApp(name, url){
var app = new qt.App(name);
var window = app.main;
var mousePos;
var appPos;
var dragDiff;
app.on('start', function(event){
var webview = new qt.WebView(window);
webview.load(new qt.URL(url));
webview.show();
});
// window.on('paint', function(event){
// var p = new qt.Painter;
// p.begin(event.target);
// if (mousePos) p.drawText(20, 30, util.inspect(mousePos));
// if (appPos) p.drawText(20, 60, util.inspect(appPos));
// if (dragDiff) p.drawText(20, 90, util.inspect(dragDiff));
// p.end();
// });
window.on('mousemove', function(event){
mousePos = { x: event.x, y: event.y };
event.target.update();
});
window.on('move', function(event){
appPos = event.pos;
event.target.update();
});
window.on('mouseup', function(event){
if (event.button === 2) app.stop();
});
// window.on('*', function(event){
// if (event.type !== 'mousemove' && event.type !== 'paint') {
// createApp.log(event);
// }
// });
window.on('mousedown', function(event){
if (event.button !== 1) return;
var offset = { x: window.x - event.globalX, y: window.y - event.globalY };
function drag(event){
window.move(event.globalX + offset.x, event.globalY + offset.y);
}
window.on('mousemove', drag);
window.once('mouseup', function(){
window.off('mousemove', drag);
});
event.accept();
});
return app;
}
createApp.log = function(e){
console.log(util.inspect(e, false, 4, true));
};
module.exports = createApp;
if (module === process.mainModule) {
var app = createApp('Test', 'http://www.google.com');
app.start();
}