57 int index = outputFileName.lastIndexOf('.'); |
57 int index = outputFileName.lastIndexOf('.'); |
58 m_fileName = (index == -1) ? outputFileName + ".png" : outputFileName; |
58 m_fileName = (index == -1) ? outputFileName + ".png" : outputFileName; |
59 m_page.mainFrame()->load(url); |
59 m_page.mainFrame()->load(url); |
60 m_page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); |
60 m_page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); |
61 m_page.mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); |
61 m_page.mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); |
|
62 m_page.setViewportSize(QSize(1024, 768)); |
62 } |
63 } |
63 |
64 |
64 void FrameCapture::printProgress(int percent) |
65 void FrameCapture::printProgress(int percent) |
65 { |
66 { |
66 if (m_percent >= percent) |
67 if (m_percent >= percent) |
79 std::cerr << "Failed loading " << qPrintable(m_page.mainFrame()->url().toString()) << std::endl; |
80 std::cerr << "Failed loading " << qPrintable(m_page.mainFrame()->url().toString()) << std::endl; |
80 emit finished(); |
81 emit finished(); |
81 return; |
82 return; |
82 } |
83 } |
83 |
84 |
84 // save each internal frame in different image files |
85 // save each frame in different image files |
85 int frameCounter = 0; |
86 saveFrame(m_page.mainFrame()); |
86 foreach(QWebFrame *frame, m_page.mainFrame()->childFrames()) { |
|
87 QString fileName(m_fileName); |
|
88 int index = m_fileName.lastIndexOf('.'); |
|
89 fileName = fileName.insert(index, "_frame" + QString::number(++frameCounter)); |
|
90 |
|
91 frame->setClipRenderToViewport(false); |
|
92 |
|
93 QImage image(frame->contentsSize(), QImage::Format_ARGB32_Premultiplied); |
|
94 image.fill(Qt::transparent); |
|
95 |
|
96 saveFrame(frame, image, fileName); |
|
97 } |
|
98 |
|
99 // save the main frame |
|
100 m_page.setViewportSize(m_page.mainFrame()->contentsSize()); |
|
101 QImage image(m_page.mainFrame()->contentsSize(), QImage::Format_ARGB32_Premultiplied); |
|
102 image.fill(Qt::transparent); |
|
103 saveFrame(m_page.mainFrame(), image, m_fileName); |
|
104 |
87 |
105 emit finished(); |
88 emit finished(); |
106 } |
89 } |
107 |
90 |
108 void FrameCapture::saveFrame(QWebFrame *frame, QImage image, QString fileName) |
91 void FrameCapture::saveFrame(QWebFrame *frame) |
109 { |
92 { |
|
93 static int frameCounter = 0; |
|
94 |
|
95 QString fileName(m_fileName); |
|
96 if (frameCounter) { |
|
97 int index = m_fileName.lastIndexOf('.'); |
|
98 fileName = fileName.insert(index, "_frame" + QString::number(frameCounter)); |
|
99 } |
|
100 |
|
101 QImage image(frame->contentsSize(), QImage::Format_ARGB32_Premultiplied); |
|
102 image.fill(Qt::transparent); |
|
103 |
110 QPainter painter(&image); |
104 QPainter painter(&image); |
111 painter.setRenderHint(QPainter::Antialiasing, true); |
105 painter.setRenderHint(QPainter::Antialiasing, true); |
112 painter.setRenderHint(QPainter::TextAntialiasing, true); |
106 painter.setRenderHint(QPainter::TextAntialiasing, true); |
113 painter.setRenderHint(QPainter::SmoothPixmapTransform, true); |
107 painter.setRenderHint(QPainter::SmoothPixmapTransform, true); |
114 |
108 frame->documentElement().render(&painter); |
115 frame->render(&painter); |
|
116 |
|
117 painter.end(); |
109 painter.end(); |
118 |
110 |
119 image.save(fileName); |
111 image.save(fileName); |
|
112 |
|
113 ++frameCounter; |
|
114 foreach(QWebFrame *childFrame, frame->childFrames()) |
|
115 saveFrame(childFrame); |
120 } |
116 } |
121 |
117 |