Mercurial > projects > qtd
comparison demos/browser/webview.d @ 94:87bb4e622f9e
more porting
author | mandel |
---|---|
date | Thu, 28 May 2009 22:11:52 +0000 |
parents | 5c8c9c5d9ee1 |
children | dcd36d8db2da |
comparison
equal
deleted
inserted
replaced
93:55fd7080c4b9 | 94:87bb4e622f9e |
---|---|
42 | 42 |
43 import qt.gui.QClipboard; | 43 import qt.gui.QClipboard; |
44 import qt.gui.QMenu; | 44 import qt.gui.QMenu; |
45 import qt.gui.QMessageBox; | 45 import qt.gui.QMessageBox; |
46 import qt.gui.QMouseEvent; | 46 import qt.gui.QMouseEvent; |
47 | 47 //import qt.core.QDebug; |
48 import qt.core.QDebug; | |
49 import qt.core.QBuffer; | 48 import qt.core.QBuffer; |
50 | 49 |
51 import QtWebKit.QWebView; | 50 import qt.webkit.QWebView; |
52 import QtWebKit.QWebHitTestResult; | 51 import qt.webkit.QWebHitTestResult; |
53 import QtUiTools.QUiLoader; | 52 version(QT_NO_UITOOLS) {} else |
54 | 53 { |
54 import qt.uitools.QUiLoader; | |
55 } | |
55 import browserapplication; | 56 import browserapplication; |
56 import browsermainwindow; | 57 import browsermainwindow; |
57 import cookiejar; | 58 import cookiejar; |
58 import downloadmanager; | 59 import downloadmanager; |
59 import networkaccessmanager; | 60 import networkaccessmanager; |
67 public: | 68 public: |
68 | 69 |
69 this(QObject parent = null) | 70 this(QObject parent = null) |
70 { | 71 { |
71 super(parent); | 72 super(parent); |
72 m_keyboardModifiers = Qt.NoModifier; | 73 m_keyboardModifiers = Qt_KeyboardModifier.NoModifier; |
73 m_pressedButtons = Qt.NoButton; | 74 m_pressedButtons = Qt_MouseButton.NoButton; |
74 m_openInNewTab = false; | 75 m_openInNewTab = false; |
75 setNetworkAccessManager(BrowserApplication.networkAccessManager()); | 76 setNetworkAccessManager(BrowserApplication.networkAccessManager()); |
76 this.unsupportedContent.connect(&this.handleUnsupportedContent); | 77 this.unsupportedContent.connect(&this.handleUnsupportedContent); |
77 } | 78 } |
78 | 79 |
93 { | 94 { |
94 // ctrl open in new tab | 95 // ctrl open in new tab |
95 // ctrl-shift open in new tab and select | 96 // ctrl-shift open in new tab and select |
96 // ctrl-alt open in new window | 97 // ctrl-alt open in new window |
97 if (type == QWebPage.NavigationTypeLinkClicked | 98 if (type == QWebPage.NavigationTypeLinkClicked |
98 && (m_keyboardModifiers & Qt.ControlModifier | 99 && (m_keyboardModifiers & Qt_KeyboardModifier.ControlModifier |
99 || m_pressedButtons == Qt.MidButton)) { | 100 || m_pressedButtons == Qt_MouseButton.MidButton)) { |
100 bool newWindow = (m_keyboardModifiers & Qt.AltModifier); | 101 bool newWindow = (m_keyboardModifiers & Qt_KeyboardModifier.AltModifier); |
101 WebView webView; | 102 WebView webView; |
102 if (newWindow) { | 103 if (newWindow) { |
103 BrowserApplication.instance().newMainWindow(); | 104 BrowserApplication.instance().newMainWindow(); |
104 BrowserMainWindow newMainWindow = BrowserApplication.instance().mainWindow(); | 105 BrowserMainWindow newMainWindow = BrowserApplication.instance().mainWindow(); |
105 webView = newMainWindow.currentTab(); | 106 webView = newMainWindow.currentTab(); |
106 newMainWindow.raise(); | 107 newMainWindow.raise(); |
107 newMainWindow.activateWindow(); | 108 newMainWindow.activateWindow(); |
108 webView.setFocus(); | 109 webView.setFocus(); |
109 } else { | 110 } else { |
110 bool selectNewTab = (m_keyboardModifiers & Qt.ShiftModifier); | 111 bool selectNewTab = (m_keyboardModifiers & Qt_KeyboardModifier.ShiftModifier); |
111 webView = mainWindow().tabWidget().newTab(selectNewTab); | 112 webView = mainWindow().tabWidget().newTab(selectNewTab); |
112 } | 113 } |
113 webView.load(request); | 114 webView.load(request); |
114 m_keyboardModifiers = Qt.NoModifier; | 115 m_keyboardModifiers = Qt_KeyboardModifier.NoModifier; |
115 m_pressedButtons = Qt.NoButton; | 116 m_pressedButtons = Qt_MouseButton.NoButton; |
116 return false; | 117 return false; |
117 } | 118 } |
118 if (frame == mainFrame()) { | 119 if (frame == mainFrame()) { |
119 m_loadingUrl = request.url(); | 120 m_loadingUrl = request.url(); |
120 loadingUrl.emit(m_loadingUrl); | 121 loadingUrl.emit(m_loadingUrl); |
122 return QWebPage.acceptNavigationRequest(frame, request, type); | 123 return QWebPage.acceptNavigationRequest(frame, request, type); |
123 } | 124 } |
124 | 125 |
125 QWebPage createWindow(QWebPage.WebWindowType type) | 126 QWebPage createWindow(QWebPage.WebWindowType type) |
126 { | 127 { |
127 if (m_keyboardModifiers & Qt.ControlModifier || m_pressedButtons == Qt.MidButton) | 128 if (m_keyboardModifiers & Qt_KeyboardModifier.ControlModifier || m_pressedButtons == Qt_MouseButton.MidButton) |
128 m_openInNewTab = true; | 129 m_openInNewTab = true; |
129 if (m_openInNewTab) { | 130 if (m_openInNewTab) { |
130 m_openInNewTab = false; | 131 m_openInNewTab = false; |
131 return mainWindow().tabWidget().newTab().page(); | 132 return mainWindow().tabWidget().newTab().page(); |
132 } | 133 } |
189 } | 190 } |
190 | 191 |
191 private: | 192 private: |
192 | 193 |
193 // set the webview mousepressedevent | 194 // set the webview mousepressedevent |
194 Qt.KeyboardModifiers m_keyboardModifiers; | 195 Qt_KeyboardModifier m_keyboardModifiers; |
195 Qt.MouseButtons m_pressedButtons; | 196 Qt_MouseButton m_pressedButtons; |
196 bool m_openInNewTab; | 197 bool m_openInNewTab; |
197 QUrl m_loadingUrl; | 198 QUrl m_loadingUrl; |
198 } | 199 } |
199 | 200 |
200 class WebView : public QWebView | 201 class WebView : public QWebView |
221 { | 222 { |
222 m_initialUrl = url; | 223 m_initialUrl = url; |
223 load(url); | 224 load(url); |
224 } | 225 } |
225 | 226 |
226 QUrl url() | 227 QUrl getUrl() |
227 { | 228 { |
228 QUrl url = QWebView.url(); | 229 QUrl url = QWebView.url(); |
229 if (!url.isEmpty()) | 230 if (!url.isEmpty()) |
230 return url; | 231 return url; |
231 return m_initialUrl; | 232 return m_initialUrl; |
251 } | 252 } |
252 | 253 |
253 void mouseReleaseEvent(QMouseEvent event) | 254 void mouseReleaseEvent(QMouseEvent event) |
254 { | 255 { |
255 QWebView.mouseReleaseEvent(event); | 256 QWebView.mouseReleaseEvent(event); |
256 if (!event.isAccepted() && (m_page.m_pressedButtons & Qt.MidButton)) { | 257 if (!event.isAccepted() && (m_page.m_pressedButtons & Qt_MouseButton.MidButton)) { |
257 auto url = new QUrl(QApplication.clipboard().text(QClipboard.Selection)); | 258 auto url = new QUrl(QApplication.clipboard().text(QClipboard.Selection)); |
258 if (!url.isEmpty() && url.isValid() && !url.scheme().isEmpty()) { | 259 if (!url.isEmpty() && url.isValid() && !url.scheme().isEmpty()) { |
259 setUrl(url); | 260 setUrl(url); |
260 } | 261 } |
261 } | 262 } |
302 } | 303 } |
303 | 304 |
304 void loadFinished() | 305 void loadFinished() |
305 { | 306 { |
306 if (100 != m_progress) { | 307 if (100 != m_progress) { |
307 qWarning() << "Received finished signal while progress is still:" << progress() << "Url:" << url(); | 308 qWarning("Received finished signal while progress is still:" ~ progress() ~ "Url:" ~ url()); |
308 } | 309 } |
309 m_progress = 0; | 310 m_progress = 0; |
310 } | 311 } |
311 | 312 |
312 void setStatusBarText(string str) | 313 void setStatusBarText(string str) |