1import QtQuick 2.0
2
3
4Rectangle {
5 //do not define anchors or a initialisize here! This would messup with QSGViewSizeRootObjetToView.
6
7 property bool printLoadedUrls: false
8 property alias navigation: browserView.navigation
9 property alias title: browserView.title
10 property alias webView: browserView
11
12 signal pageTitleChanged(string title)
13
14 function load(address) {
15 browserView.load(address)
16 }
17
18 function setFocusToAddressBar() {
19 addressLine.forceActiveFocus()
20 addressLine.selectAll()
21 }
22
23 Rectangle {
24 id: navigationBar
25 color: "#efefef"
26 anchors.top: parent.top
27 anchors.left: parent.left
28 anchors.right: parent.right
29 height: 30
30
31 Row {
32 id: controlsRow
33 spacing: 4
34 Rectangle {
35 id: backButton
36 height: navigationBar.height-2
37 width: height
38 color: "#efefef"
39
40 Image {
41 anchors.centerIn: parent
42 source: "../icons/previous.png"
43 }
44
45 Rectangle {
46 anchors.fill: parent
47 color: reloadButton.color
48 opacity: 0.8
49 visible: !navigation.canGoBack
50 }
51
52 MouseArea {
53 anchors.fill: parent
54 onClicked: {
55 console.log("going back")
56 navigation.goBack()
57 }
58 }
59 }
60 Rectangle {
61 id: forwardButton
62 height: navigationBar.height-2
63 width: height
64 color: "#efefef"
65
66 Image {
67 anchors.centerIn: parent
68 source: "../icons/next.png"
69 }
70
71 Rectangle {
72 anchors.fill: parent
73 color: forwardButton.color
74 opacity: 0.8
75 visible: !navigation.canGoForward
76 }
77
78 MouseArea {
79 anchors.fill: parent
80 onClicked: {
81 console.log("going forward")
82 navigation.goForward()
83 }
84 }
85 }
86 Rectangle {
87 id: reloadButton
88 height: navigationBar.height-2
89 width: height
90 color: "#efefef"
91
92 Image {
93 anchors.centerIn: parent
94 source: navigation.canStop ? "../icons/stop.png" : "../icons/refresh.png"
95 }
96
97 MouseArea {
98 anchors.fill: parent
99 onClicked: {
100 if (navigation.canStop) {
101 console.log("stop loading")
102 navigation.stop()
103 } else {
104 console.log("reloading")
105 navigation.reload()
106 }
107 }
108 }
109 }
110 }
111 Rectangle {
112 color: "white"
113 anchors.left: controlsRow.right
114 anchors.right: parent.right
115 anchors.margins: 2
116 anchors.verticalCenter: parent.verticalCenter
117 height: navigationBar.height-4
118 border.width: 1
119 Rectangle {
120 anchors.top: parent.top
121 anchors.bottom: parent.bottom
122 anchors.left: parent.left
123 width: parent.width/100*browserView.loadProgress
124 color: "blue"
125 opacity: 0.3
126 visible: browserView.loadProgress != 100
127 }
128
129 TextInput {
130 id: addressLine
131 anchors.verticalCenter: parent.verticalCenter
132 anchors.left: parent.left
133 anchors.right: parent.right
134 anchors.margins: 2
135 font.pointSize: 14
136 font.family: "Helvetica"
137 clip: true
138 selectByMouse: true
139
140 Keys.onReturnPressed:{
141 console.log("going to: ", addressLine.text)
142 browserView.load(addressLine.text)
143 }
144 }
145 }
146 }
147
148 BrowserView {
149 id: browserView
150 anchors.top: navigationBar.bottom
151 anchors.left: parent.left
152 anchors.right: parent.right
153 anchors.bottom: parent.bottom
154
155 onTitleChanged: {
156 pageTitleChanged(title)
157 }
158
159 onUrlChanged: {
160 addressLine.text = url
161 if (printLoadedUrls)
162 console.log("Loaded:", url);
163 forceActiveFocus();
164 }
165 }
166}