Merge branch 'browser' into infoview

Conflicts:
	tests/ui/src/main.cpp
This commit is contained in:
Brad Davis 2015-04-28 17:54:04 -07:00
commit 0fb8884f9c
3 changed files with 169 additions and 44 deletions

View file

@ -2,29 +2,149 @@ import QtQuick 2.3
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtWebKit 3.0 import QtWebKit 3.0
import "controls" import "controls"
import "styles"
Dialog { Dialog {
title: "Browser Window" id: root
id: testDialog HifiConstants { id: hifi }
objectName: "Browser" title: "Browser"
width: 1280 resizable: true
height: 720 contentImplicitWidth: clientArea.implicitWidth
contentImplicitHeight: clientArea.implicitHeight
backgroundColor: "#7f000000"
Component.onCompleted: {
enabled = true
addressBar.text = webview.url
}
onParentChanged: {
if (visible && enabled) {
addressBar.forceActiveFocus();
addressBar.selectAll()
}
}
Item { Item {
id: clientArea id: clientArea
// The client area implicitHeight: 600
anchors.fill: parent implicitWidth: 800
anchors.margins: parent.margins x: root.clientX
anchors.topMargin: parent.topMargin y: root.clientY
width: root.clientWidth
height: root.clientHeight
Rectangle {
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: scrollView.top
color: "white"
}
Row {
id: buttons
spacing: 4
anchors.top: parent.top
anchors.topMargin: 8
anchors.left: parent.left
anchors.leftMargin: 8
FontAwesome {
id: back; text: "\uf0a8"; size: 48; enabled: webview.canGoBack;
color: enabled ? hifi.colors.text : hifi.colors.disabledText
MouseArea { anchors.fill: parent; onClicked: webview.goBack() }
}
FontAwesome {
id: forward; text: "\uf0a9"; size: 48; enabled: webview.canGoForward;
color: enabled ? hifi.colors.text : hifi.colors.disabledText
MouseArea { anchors.fill: parent; onClicked: webview.goBack() }
}
FontAwesome {
id: reload; size: 48; text: webview.loading ? "\uf057" : "\uf021"
MouseArea { anchors.fill: parent; onClicked: webview.loading ? webview.stop() : webview.reload() }
}
}
Border {
height: 48
radius: 8
anchors.top: parent.top
anchors.topMargin: 8
anchors.right: parent.right
anchors.rightMargin: 8
anchors.left: buttons.right
anchors.leftMargin: 8
Item {
id: barIcon
width: parent.height
height: parent.height
Image {
source: webview.icon;
x: (parent.height - height) / 2
y: (parent.width - width) / 2
verticalAlignment: Image.AlignVCenter;
horizontalAlignment: Image.AlignHCenter
onSourceChanged: console.log("Icon url: " + source)
}
}
TextInput {
id: addressBar
anchors.right: parent.right
anchors.rightMargin: 8
anchors.left: barIcon.right
anchors.leftMargin: 0
anchors.verticalCenter: parent.verticalCenter
Keys.onPressed: {
switch(event.key) {
case Qt.Key_Enter:
case Qt.Key_Return:
event.accepted = true
if (text.indexOf("http") != 0) {
text = "http://" + text
}
webview.url = text
break;
}
}
}
}
ScrollView { ScrollView {
anchors.fill: parent id: scrollView
anchors.top: buttons.bottom
anchors.topMargin: 8
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
WebView { WebView {
id: webview id: webview
url: "http://slashdot.org" url: "http://highfidelity.com"
anchors.fill: parent anchors.fill: parent
onLoadingChanged: {
if (loadRequest.status == WebView.LoadSucceededStarted) {
addressBar.text = loadRequest.url
}
}
onIconChanged: {
barIcon.source = icon
}
} }
} }
} // item
}
} Keys.onPressed: {
switch(event.key) {
case Qt.Key_L:
if (event.modifiers == Qt.ControlModifier) {
event.accepted = true
addressBar.selectAll()
addressBar.forceActiveFocus()
}
break;
}
}
} // dialog

View file

@ -1095,6 +1095,13 @@ void Application::keyPressEvent(QKeyEvent* event) {
Menu::getInstance()->triggerOption(MenuOption::AddressBar); Menu::getInstance()->triggerOption(MenuOption::AddressBar);
break; break;
case Qt::Key_B:
if (isMeta) {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
offscreenUi->load("Browser.qml");
}
break;
case Qt::Key_L: case Qt::Key_L:
if (isShifted && isMeta) { if (isShifted && isMeta) {
Menu::getInstance()->triggerOption(MenuOption::Log); Menu::getInstance()->triggerOption(MenuOption::Log);

View file

@ -414,25 +414,31 @@ protected:
void keyPressEvent(QKeyEvent* event) { void keyPressEvent(QKeyEvent* event) {
_altPressed = Qt::Key_Alt == event->key(); _altPressed = Qt::Key_Alt == event->key();
switch (event->key()) { switch (event->key()) {
case Qt::Key_L: case Qt::Key_B:
if (event->modifiers() & Qt::CTRL) { if (event->modifiers() & Qt::CTRL) {
InfoView::show(getResourcesDir() + "html/interface-welcome.html", true); auto offscreenUi = DependencyManager::get<OffscreenUi>();
} offscreenUi->load("Browser.qml");
break; }
case Qt::Key_K: break;
if (event->modifiers() & Qt::CTRL) { case Qt::Key_L:
OffscreenUi::question("Message title", "Message contents", [](QMessageBox::Button b){ if (event->modifiers() & Qt::CTRL) {
qDebug() << b; InfoView::show(getResourcesDir() + "html/interface-welcome.html", true);
}); }
} break;
break; case Qt::Key_K:
case Qt::Key_J: if (event->modifiers() & Qt::CTRL) {
if (event->modifiers() & Qt::CTRL) { OffscreenUi::question("Message title", "Message contents", [](QMessageBox::Button b){
auto offscreenUi = DependencyManager::get<OffscreenUi>(); qDebug() << b;
rootMenu = offscreenUi->getRootItem()->findChild<QObject*>("rootMenu"); });
QMetaObject::invokeMethod(rootMenu, "popup"); }
} break;
break; case Qt::Key_J:
if (event->modifiers() & Qt::CTRL) {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
rootMenu = offscreenUi->getRootItem()->findChild<QObject*>("rootMenu");
QMetaObject::invokeMethod(rootMenu, "popup");
}
break;
} }
QWindow::keyPressEvent(event); QWindow::keyPressEvent(event);
} }
@ -448,7 +454,7 @@ protected:
if (devicePixelRatio() != oldPixelRatio) { if (devicePixelRatio() != oldPixelRatio) {
oldPixelRatio = devicePixelRatio(); oldPixelRatio = devicePixelRatio();
resizeWindow(size()); resizeWindow(size());
} }
QWindow::moveEvent(event); QWindow::moveEvent(event);
} }
}; };
@ -485,14 +491,6 @@ hifi.offscreen.focus.debug=false
qt.quick.mouse.debug=false qt.quick.mouse.debug=false
)V0G0N"; )V0G0N";
//int main(int argc, char *argv[]) {
// QGuiApplication app(argc, argv);
// QQmlApplicationEngine engine;
// engine.setBaseUrl(QUrl::fromLocalFile(getQmlDir()));
// engine.load(QUrl("Main.qml"));
// return app.exec();
//}
int main(int argc, char** argv) { int main(int argc, char** argv) {
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
QLoggingCategory::setFilterRules(LOG_FILTER_RULES); QLoggingCategory::setFilterRules(LOG_FILTER_RULES);