Mercurial > projects > qtd
comparison demos/browser/webview.d @ 74:37caa90ce503
more porting
author | mandel |
---|---|
date | Fri, 22 May 2009 23:43:58 +0000 |
parents | 7bfd46c330dc |
children | 0654fc9bac95 |
comparison
equal
deleted
inserted
replaced
73:7bfd46c330dc | 74:37caa90ce503 |
---|---|
60 import tabwidget; | 60 import tabwidget; |
61 | 61 |
62 | 62 |
63 class WebPage : public QWebPage | 63 class WebPage : public QWebPage |
64 { | 64 { |
65 mixin Signal!("loadingUrl", QUrl url); | 65 mixin Signal!("loadingUrl", QUrl /*url*/); |
66 | 66 |
67 public: | 67 public: |
68 | 68 |
69 this(QObject parent = null) | 69 this(QObject parent = null) |
70 { | 70 { |
87 return BrowserApplication.instance().mainWindow(); | 87 return BrowserApplication.instance().mainWindow(); |
88 } | 88 } |
89 | 89 |
90 protected: | 90 protected: |
91 | 91 |
92 bool acceptNavigationRequest(QWebFrame frame, QNetworkRequest request, NavigationType type); | 92 bool acceptNavigationRequest(QWebFrame frame, QNetworkRequest request, NavigationType type) |
93 { | 93 { |
94 // ctrl open in new tab | 94 // ctrl open in new tab |
95 // ctrl-shift open in new tab and select | 95 // ctrl-shift open in new tab and select |
96 // ctrl-alt open in new window | 96 // ctrl-alt open in new window |
97 if (type == QWebPage.NavigationTypeLinkClicked | 97 if (type == QWebPage.NavigationTypeLinkClicked |
136 return mainWindow.currentTab().page(); | 136 return mainWindow.currentTab().page(); |
137 } | 137 } |
138 | 138 |
139 version(QT_NO_UITOOLS) {} else | 139 version(QT_NO_UITOOLS) {} else |
140 { | 140 { |
141 QObject createPlugin(const QString &classId, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues); | 141 QObject createPlugin(QString classId, QUrl url, QStringList paramNames, QStringList paramValues); |
142 { | 142 { |
143 //Q_UNUSED(url); | 143 //Q_UNUSED(url); |
144 //Q_UNUSED(paramNames); | 144 //Q_UNUSED(paramNames); |
145 //Q_UNUSED(paramValues); | 145 //Q_UNUSED(paramValues); |
146 QUiLoader loader; | 146 QUiLoader loader; |
157 return; | 157 return; |
158 } | 158 } |
159 | 159 |
160 QFile file(QLatin1String(":/notfound.html")); | 160 QFile file(QLatin1String(":/notfound.html")); |
161 bool isOpened = file.open(QIODevice.ReadOnly); | 161 bool isOpened = file.open(QIODevice.ReadOnly); |
162 Q_ASSERT(isOpened); | 162 assert(isOpened); |
163 QString title = tr("Error loading page: %1").arg(reply.url().toString()); | 163 QString title = tr("Error loading page: %1").arg(reply.url().toString()); |
164 QString html = QString(QLatin1String(file.readAll())) | 164 QString html = QString(QLatin1String(file.readAll())) |
165 .arg(title) | 165 .arg(title) |
166 .arg(reply.errorString()) | 166 .arg(reply.errorString()) |
167 .arg(reply.url().toString()); | 167 .arg(reply.url().toString()); |
173 if (pixmap.save(&imageBuffer, "PNG")) { | 173 if (pixmap.save(&imageBuffer, "PNG")) { |
174 html.replace(QLatin1String("IMAGE_BINARY_DATA_HERE"), | 174 html.replace(QLatin1String("IMAGE_BINARY_DATA_HERE"), |
175 QString(QLatin1String(imageBuffer.buffer().toBase64()))); | 175 QString(QLatin1String(imageBuffer.buffer().toBase64()))); |
176 } | 176 } |
177 | 177 |
178 QList<QWebFrame*> frames; | 178 QWebFrame[] frames; |
179 frames.append(mainFrame()); | 179 frames.append(mainFrame()); |
180 while (!frames.isEmpty()) { | 180 while (!frames.isEmpty()) { |
181 QWebFrame frame = frames.takeFirst(); | 181 QWebFrame frame = frames.takeFirst(); |
182 if (frame.url() == reply.url()) { | 182 if (frame.url() == reply.url()) { |
183 frame.setHtml(html, reply.url()); | 183 frame.setHtml(html, reply.url()); |
184 return; | 184 return; |
185 } | 185 } |
186 QList<QWebFrame > children = frame.childFrames(); | 186 QWebFrame[] children = frame.childFrames(); |
187 foreach(QWebFrame frame, children) | 187 foreach(QWebFrame frame; children) |
188 frames.append(frame); | 188 frames.append(frame); |
189 } | 189 } |
190 if (m_loadingUrl == reply.url()) { | 190 if (m_loadingUrl == reply.url()) { |
191 mainFrame().setHtml(html, reply.url()); | 191 mainFrame().setHtml(html, reply.url()); |
192 } | 192 } |
225 { | 225 { |
226 m_initialUrl = url; | 226 m_initialUrl = url; |
227 load(url); | 227 load(url); |
228 } | 228 } |
229 | 229 |
230 QUrl url() const | 230 QUrl url() |
231 { | 231 { |
232 QUrl url = QWebView.url(); | 232 QUrl url = QWebView.url(); |
233 if (!url.isEmpty()) | 233 if (!url.isEmpty()) |
234 return url; | 234 return url; |
235 return m_initialUrl; | 235 return m_initialUrl; |
242 | 242 |
243 int progress() const { return m_progress; } | 243 int progress() const { return m_progress; } |
244 | 244 |
245 protected: | 245 protected: |
246 | 246 |
247 void mousePressEvent(QMouseEvent event); | 247 void mousePressEvent(QMouseEvent event) |
248 { | 248 { |
249 m_page.m_pressedButtons = event.buttons(); | 249 m_page.m_pressedButtons = event.buttons(); |
250 m_page.m_keyboardModifiers = event.modifiers(); | 250 m_page.m_keyboardModifiers = event.modifiers(); |
251 QWebView.mousePressEvent(event); | 251 QWebView.mousePressEvent(event); |
252 } | 252 } |