Warning, /maui/mauikit/src/controls.5/private/ToastArea.qml is written in an unsupported language. File is not indexed.
0001 0002 /* 0003 * Copyright 2018 Camilo Higuita <milo.h@aol.com> 0004 * 0005 * This program is free software; you can redistribute it and/or modify 0006 * it under the terms of the GNU Library General Public License as 0007 * published by the Free Software Foundation; either version 2, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details 0014 * 0015 * You should have received a copy of the GNU Library General Public 0016 * License along with this program; if not, write to the 0017 * Free Software Foundation, Inc., 0018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0019 */ 0020 0021 import QtQuick 2.15 0022 import QtQuick.Controls 2.15 0023 import QtQuick.Layouts 1.3 0024 import QtQuick.Window 2.3 0025 0026 import QtGraphicalEffects 1.12 0027 0028 import QtQml.Models 2.3 0029 0030 import QtMultimedia 5.15 0031 0032 import org.mauikit.controls 1.3 as Maui 0033 0034 Control 0035 { 0036 id: control 0037 focus: true 0038 0039 padding: Maui.Style.contentMargins 0040 visible: _container.count > 0 0041 0042 hoverEnabled: true 0043 0044 property bool autoClose : Window.window.active 0045 0046 SoundEffect 0047 { 0048 id: playSound 0049 source: "qrc:/assets/notification_simple-01.wav" 0050 } 0051 0052 SoundEffect 0053 { 0054 id: _dismissSound 0055 source: "qrc:/assets/notification_simple-02.wav" 0056 } 0057 0058 Keys.enabled: true 0059 Keys.onEscapePressed: 0060 { 0061 control.dismiss() 0062 } 0063 0064 onVisibleChanged: 0065 { 0066 if(visible) 0067 { 0068 control.forceActiveFocus() 0069 } 0070 } 0071 0072 background: MouseArea 0073 { 0074 // opacity: 0.8 0075 0076 onClicked: 0077 { 0078 if(_container.count === 1) 0079 control.dismiss() 0080 } 0081 LinearGradient 0082 { 0083 anchors.fill: parent 0084 start: Qt.point(control.width/2, 0) 0085 end: Qt.point(control.width/2, control.height - _container.height) 0086 gradient: Gradient { 0087 GradientStop { position: 0.0; color: "transparent" } 0088 GradientStop { position: 1.0; color: Maui.Theme.backgroundColor } 0089 } 0090 } 0091 } 0092 0093 Component 0094 { 0095 id: _toastComponent 0096 0097 ItemDelegate 0098 { 0099 id: _toast 0100 0101 Maui.Theme.colorSet: Maui.Theme.View 0102 Maui.Theme.inherit: false 0103 0104 readonly property int mindex : ObjectModel.index 0105 width: ListView.view.width 0106 height: _layout.implicitHeight + topPadding +bottomPadding 0107 0108 hoverEnabled: true 0109 0110 padding: Maui.Style.contentMargins 0111 0112 property alias title : _template.label1.text 0113 property alias iconSource: _template.iconSource 0114 property alias imageSource: _template.imageSource 0115 property alias body: _template.label2.text 0116 property var callback : ({}) 0117 property alias buttonText: _button.text 0118 property int timeout : 3500 0119 0120 onClicked: control.remove(mindex) 0121 0122 background: Rectangle 0123 { 0124 radius: Maui.Style.radiusV 0125 color: _toast.hovered? Maui.Theme.hoverColor : Maui.Theme.backgroundColor 0126 0127 layer.enabled: true 0128 layer.effect: DropShadow 0129 { 0130 horizontalOffset: 0 0131 verticalOffset: 0 0132 radius: 8 0133 samples: 16 0134 color: "#80000000" 0135 transparentBorder: true 0136 } 0137 } 0138 0139 Component.onCompleted: _toastTimer.restart() 0140 0141 Timer 0142 { 0143 id: _toastTimer 0144 interval: _toast.timeout + (_toast.mindex * 500) 0145 0146 onTriggered: 0147 { 0148 if(_toast.hovered || _container.hovered || !control.autoClose) 0149 { 0150 _toastTimer.restart() 0151 return; 0152 } 0153 control.remove(_toast.mindex) 0154 } 0155 } 0156 0157 contentItem: ColumnLayout 0158 { 0159 id: _layout 0160 spacing: Maui.Style.space.medium 0161 0162 Maui.ListItemTemplate 0163 { 0164 id: _template 0165 Layout.fillWidth: true 0166 Layout.fillHeight: true 0167 label1.text: Maui.App.about.name 0168 label2.text: "" 0169 label2.wrapMode: Text.Wrap 0170 iconSource: "dialog-warning" 0171 iconSizeHint: Maui.Style.iconSizes.big 0172 } 0173 0174 Button 0175 { 0176 id: _button 0177 visible: _toast.callback instanceof Function 0178 text: i18n("Accept") 0179 Layout.fillWidth: true 0180 onClicked: 0181 { 0182 if(_toast.callback instanceof Function) 0183 { 0184 _toast.callback(_toast.mindex) 0185 } 0186 control.remove(_toast.mindex) 0187 } 0188 } 0189 } 0190 0191 DragHandler 0192 { 0193 id: _dragHandler 0194 yAxis.enabled: false 0195 0196 onActiveChanged: 0197 { 0198 if(!active) 0199 { 0200 if(_dragHandler.centroid.scenePressPosition.x.toFixed(1) - _dragHandler.centroid.scenePosition.x.toFixed(1) > 80) 0201 { 0202 control.remove(_toast.mindex) 0203 }else 0204 { 0205 _toast.x = 0 0206 } 0207 } 0208 } 0209 } 0210 } 0211 } 0212 0213 contentItem: Item 0214 { 0215 0216 Container 0217 { 0218 id: _container 0219 0220 hoverEnabled: true 0221 0222 width: Math.min(400, parent.width) 0223 height: Math.min( _listView.implicitHeight + topPadding + bottomPadding, 500) 0224 0225 anchors.bottom: parent.bottom 0226 anchors.horizontalCenter: parent.horizontalCenter 0227 0228 0229 0230 contentItem: Maui.ListBrowser 0231 { 0232 id: _listView 0233 0234 property bool expanded : true 0235 0236 orientation: ListView.Vertical 0237 snapMode: ListView.SnapOneItem 0238 0239 spacing: Maui.Style.space.medium 0240 0241 0242 model: _container.contentModel 0243 0244 footer: Item 0245 { 0246 width: ListView.view.width 0247 height: Maui.Style.toolBarHeight 0248 Button 0249 { 0250 id: _dimissButton 0251 visible: _container.count > 1 0252 width: parent.width 0253 anchors.centerIn: parent 0254 text: i18n("Dismiss All") 0255 onClicked: control.dismiss() 0256 } 0257 } 0258 } 0259 } 0260 } 0261 0262 function add(icon, title, body, callback, buttonText) 0263 { 0264 const properties = ({ 0265 'iconSource': icon, 0266 'title': title, 0267 'body': body, 0268 'callback': callback, 0269 'buttonText': buttonText 0270 }) 0271 const object = _toastComponent.createObject(_listView.flickable, properties); 0272 _container.insertItem(0, object) 0273 playSound.play() 0274 } 0275 0276 0277 function dismiss() 0278 { 0279 let count = _container.count 0280 let items = [] 0281 for(var i = 0; i< count; i++) 0282 { 0283 items.push(_container.itemAt(i)) 0284 } 0285 0286 for(var j of items) 0287 { 0288 _container.removeItem(j) 0289 } 0290 0291 _dismissSound.play() 0292 } 0293 0294 function remove(index) 0295 { 0296 _container.removeItem(_container.itemAt(index)) 0297 } 0298 }