| 1 |
QTerm.loadExtension("qt.core"); |
| 2 |
QTerm.loadExtension("qt.network"); |
| 3 |
QTerm.loadExtension("qt.gui"); |
| 4 |
QTerm.loadExtension("qt.webkit"); |
| 5 |
|
| 6 |
var WebSnap = WebSnap ? WebSnap : new Object; |
| 7 |
WebSnap.webPage = new QWebPage; |
| 8 |
WebSnap.label = new QLabel; |
| 9 |
|
| 10 |
WebSnap.loading = false; |
| 11 |
|
| 12 |
WebSnap.showSnap = function(ok) |
| 13 |
{ |
| 14 |
if (!ok) { |
| 15 |
QTerm.osdMessage("cannot download the webpage"); |
| 16 |
return; |
| 17 |
} |
| 18 |
this.loading = false; |
| 19 |
var target = new QSize(400, 300); |
| 20 |
var size = this.webPage.mainFrame().contentsSize; |
| 21 |
size.setHeight(size.width() * target.height() / target.width()); |
| 22 |
|
| 23 |
|
| 24 |
var image = new QPixmap(size); |
| 25 |
image.fill(Qt.transparent); |
| 26 |
|
| 27 |
|
| 28 |
var p = new QPainter; |
| 29 |
p.begin(image); |
| 30 |
this.webPage.viewportSize = this.webPage.mainFrame().contentsSize; |
| 31 |
this.webPage.mainFrame().render(p); |
| 32 |
p.end(); |
| 33 |
image = image.scaled(target, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation); |
| 34 |
|
| 35 |
this.label.size = target; |
| 36 |
this.label.pixmap = image; |
| 37 |
} |
| 38 |
|
| 39 |
WebSnap.getWebsnap = function( urlStr ) |
| 40 |
{ |
| 41 |
|
| 42 |
var url = new QUrl(urlStr, QUrl.TolerantMode); |
| 43 |
|
| 44 |
|
| 45 |
this.webPage.loadFinished.connect(this,this.showSnap); |
| 46 |
this.webPage.mainFrame().load(url); |
| 47 |
this.loading = true; |
| 48 |
var image = new QPixmap; |
| 49 |
image.load(QTerm.localPath()+"pic/loading.png"); |
| 50 |
this.label.pixmap = image; |
| 51 |
|
| 52 |
this.label.move(QTerm.posX(),QTerm.posY()); |
| 53 |
this.label.show(); |
| 54 |
} |
| 55 |
|
| 56 |
QTerm.WebSnap = WebSnap; |
| 57 |
|
| 58 |
QTerm.onWebsnap = function() |
| 59 |
{ |
| 60 |
QTerm.WebSnap.getWebsnap(QTerm.getUrl()); |
| 61 |
} |
| 62 |
|
| 63 |
if (QTerm.addUrlMenu( "snapshot", "Web Snapshot" ) ) { |
| 64 |
QTerm.snapshot.triggered.connect(QTerm.onWebsnap); |
| 65 |
} |
| 66 |
|