Документация
ОС Аврора 5.1.0
Пример файла main.qml
custompopups/main.qml
/****************************************************************************
**
** Copyright (c) 2021 Open Mobile Platform LLC
**
****************************************************************************/
import QtQuick 2.0
import Sailfish.Silica 1.0
import Sailfish.WebView 1.0
import Sailfish.WebView.Popups 1.0
ApplicationWindow {
id: root
initialPage: Component {
Page {
id: page
WebView {
anchors.fill: parent
active: true
url: "https://browser.sailfishos.org/tests/testpage.html"
popupProvider: PopupProvider {
id: customPopupProvider
// реализации всплывающих окон могут быть предоставлены через строку URL-адреса компонента
passwordManagerPopup: "qrc:/CustomPasswordManagerPopup.qml"
authPopup: "qrc:/CustomAuthPopup.qml"
// или как экземпляры Component
promptPopup: Qt.createComponent("qrc:/CustomPromptPopup.qml")
locationPermissionPopup: customLocationPermissionPopup
// или как словарь с полями "type" и "component"
confirmPopup: ({"type": "item", "component": Qt.createComponent("qrc:/CustomConfirmPopup.qml")})
alertPopup: ({"type": "item", "component": "qrc:/CustomAlertPopup.qml"})
blockedTabPopup: ({"type": "item", "component": "qrc:/CustomBlockedTabPopup.qml"})
// если для какого-то типа всплывающего окна не предусмотрена пользовательская реализация,
// веб-представление будет использовать реализацию по умолчанию.
//contextMenu: "qrc:/CustomContextMenu.qml"
}
}
}
}
Component {
id: customLocationPermissionPopup
LocationPopupInterface {
id: popup
width: (parent.width/5)*4
height: (parent.height/5)*4
anchors.centerIn: parent
acceptText: "Allow"
cancelText: "Disallow"
preventDialogsValue: toggle.checked
rememberValue: remember.checked
Rectangle {
anchors.fill: parent
color: "blanchedalmond"
clip: flickable.contentHeight > height
SilicaFlickable {
id: flickable
anchors.fill: parent
contentHeight: content.height + Theme.paddingLarge
Column {
id: content
width: parent.width - 2 * Theme.horizontalPageMargin
anchors.centerIn: parent
spacing: Theme.paddingLarge
Text {
width: parent.width
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
font.bold: true
text: popup.title
}
Text {
width: parent.width
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
text: "Разрешить " + popup.host + " доступ к вашему местоположению?"
}
TextSwitch {
id: remember
anchors.horizontalCenter: parent.horizontalCenter
text: "Запомнить для этого сайта"
}
TextSwitch {
id: toggle
anchors.horizontalCenter: parent.horizontalCenter
height: visible ? implicitHeight : 0
visible: popup.preventDialogsVisible
checked: popup.preventDialogsVisible && popup.preventDialogsPrefillValue
text: "Не показывать это снова"
}
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: popup.acceptText
onClicked: { popup.accepted(); popup.visible = false }
}
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: popup.cancelText
onClicked: { popup.rejected(); popup.visible = false }
}
}
}
}
}
}
}