32 #include <QApplication>
33 #include <QDesktopWidget>
38 #include <boost/algorithm/string/erase.hpp>
42 static QApplication*
pApp =
nullptr;
45 QNetworkProxyFactory::setUseSystemConfiguration(
true);
48 pApp =
new QApplication(argc,
nullptr);
63 image_(cvCreateImage(cvSize(width_,height_),IPL_DEPTH_8U,3)),
68 pApp->sendPostedEvents();
69 pApp->processEvents();
73 page_.mainFrame()->setHtml(QString::fromLatin1(
"<html></html>"));
75 page_.mainFrame()->load(QUrl::fromUserInput(QString::fromLatin1(url)));
76 page_.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
77 page_.mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
80 pApp->sendPostedEvents();
81 pApp->processEvents();
93 QWebElement child = elem.firstChild();
94 bool result = !child.isNull();
95 while(!child.isNull()) {
98 const QRect rect = child.geometry();
101 string tagName = child.tagName().toStdString();
105 || tagName ==
"OPTION"
106 || tagName ==
"INPUT") {
107 string text = child.toPlainText().toStdString();
108 boost::erase_all(text,
"\r");
109 boost::erase_all(text,
"\n");
116 regions_.back().right = rect.right();
117 regions_.back().bottom = rect.bottom();
120 << child.geometry().center().x() <<
","
121 << child.geometry().center().y() <<
" ";
128 child = child.nextSibling();
136 pApp->sendPostedEvents();
137 pApp->processEvents();
139 QImage image(
page_.mainFrame()->contentsSize(), QImage::Format_ARGB32_Premultiplied);
140 if(!image.isNull()) {
141 image.fill(Qt::transparent);
142 QPainter painter(&image);
143 if(painter.isActive()) {
144 painter.setRenderHint(QPainter::Antialiasing,
true);
145 painter.setRenderHint(QPainter::TextAntialiasing,
true);
146 painter.setRenderHint(QPainter::SmoothPixmapTransform,
true);
147 page_.mainFrame()->documentElement().render(&painter);
150 for(
int y=0;y<std::min(image.height(),
height_);++y) {
151 for(
int x=0;x<std::min(image.width(),
width_);++x) {
158 QWebFrame *frame =
page_.mainFrame();
161 QWebElement document = frame->documentElement();
193 #if QT_VERSION > 0x050000
194 QMouseEvent *pEvent =
new QMouseEvent(QEvent::MouseMove, QPointF(x,y), Qt::NoButton, Qt::NoButton, 0);
196 QMouseEvent *pEvent =
new QMouseEvent(QEvent::MouseMove, QPoint(x,y), Qt::NoButton, Qt::NoButton, 0);
203 #if QT_VERSION > 0x050000
204 QMouseEvent *pEvent =
new QMouseEvent(QEvent::MouseButtonPress,
207 pEvent =
new QMouseEvent(QEvent::MouseButtonRelease,
211 QMouseEvent *pEvent =
new QMouseEvent(QEvent::MouseButtonPress,
214 pEvent =
new QMouseEvent(QEvent::MouseButtonRelease,
221 QKeyEvent *pEvent =
new QKeyEvent(QEvent::KeyPress, key, 0);
223 pEvent =
new QKeyEvent(QEvent::KeyRelease, key, 0);
233 image_(cvCreateImage(cvSize(width_,height_),IPL_DEPTH_8U,3)),
236 pApp->sendPostedEvents();
237 pApp->processEvents();
252 pApp->sendPostedEvents();
253 pApp->processEvents();
255 QScreen *screen = QGuiApplication::primaryScreen();
257 QPixmap pixmap = screen->grabWindow(0);
258 QImage image = pixmap.toImage();
260 for(
int y=0;y<std::min(image.height(),
height_);++y) {
261 for(
int x=0;x<std::min(image.width(),
width_);++x) {
283 pApp->sendPostedEvents();
284 pApp->processEvents();