Warning, /frameworks/knewstuff/src/qtquick/qml/QuestionAsker.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2019 Dan Leinir Turthra Jensen <admin@leinir.dk> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 /** 0008 * @brief A component used to forward questions from KNewStuff's engine to the UI 0009 * 0010 * This component is equivalent to the WidgetQuestionListener 0011 * @see KNewStuff::WidgetQuestionListener 0012 * @see KNewStuffCore::Question 0013 * @since 5.63 0014 */ 0015 0016 import QtQuick 2.11 0017 import QtQuick.Controls 2.11 as QtControls 0018 import QtQuick.Layouts 1.11 as QtLayouts 0019 0020 import org.kde.kirigami 2.7 as Kirigami 0021 0022 import org.kde.newstuff.core 1.62 as NewStuffCore 0023 import org.kde.newstuff 1.62 as NewStuff 0024 0025 QtControls.Dialog { 0026 id: dialog 0027 modal: true 0028 focus: true 0029 property int questionType 0030 anchors.centerIn: QtControls.Overlay.overlay 0031 margins: Kirigami.Units.largeSpacing 0032 padding: Kirigami.Units.largeSpacing 0033 standardButtons: { 0034 switch (questionType) { 0035 case NewStuffCore.Question.SelectFromListQuestion: 0036 case NewStuffCore.Question.InputTextQuestion: 0037 case NewStuffCore.Question.PasswordQuestion: 0038 case NewStuffCore.Question.ContinueCancelQuestion: 0039 // QtControls Dialog standardButtons does not have a Continue button... 0040 return QtControls.Dialog.Ok | QtControls.Dialog.Cancel; 0041 break; 0042 case NewStuffCore.Question.YesNoQuestion: 0043 return QtControls.Dialog.Yes | QtControls.Dialog.No; 0044 break; 0045 default: 0046 break; 0047 } 0048 } 0049 0050 Connections { 0051 target: NewStuff.QuickQuestionListener 0052 function onAskListQuestion(title, question, list) { 0053 dialog.questionType = NewStuffCore.Question.SelectFromListQuestion; 0054 dialog.title = title; 0055 questionLabel.text = question; 0056 for (var i = 0; i < list.length; i++) { 0057 listView.model.append({ text: list[i] }); 0058 } 0059 listView.currentIndex = 0; 0060 listView.visible = true; 0061 dialog.open(); 0062 } 0063 function onAskContinueCancelQuestion(title, question) { 0064 dialog.questionType = NewStuffCore.Question.ContinueCancelQuestion; 0065 dialog.title = title; 0066 questionLabel.text = question; 0067 dialog.open(); 0068 } 0069 function onAskTextInputQuestion(title, question) { 0070 dialog.questionType = NewStuffCore.Question.InputTextQuestion; 0071 dialog.title = title; 0072 questionLabel.text = question; 0073 textInput.visible = true; 0074 dialog.open(); 0075 } 0076 function onAskPasswordQuestion(title, question) { 0077 dialog.questionType = NewStuffCore.Question.PasswordQuestion; 0078 dialog.title = title; 0079 questionLabel.text = question; 0080 textInput.echoMode = QtControls.TextInput.PasswordEchoOnEdit; 0081 textInput.visible = true; 0082 dialog.open(); 0083 } 0084 function onAskYesNoQuestion(title, question) { 0085 dialog.questionType = NewStuffCore.Question.YesNoQuestion; 0086 dialog.title = title; 0087 questionLabel.text = question; 0088 dialog.open(); 0089 } 0090 } 0091 function passResponse(responseIsContinue) { 0092 var input = ""; 0093 switch(dialog.questionType) { 0094 case NewStuffCore.Question.SelectFromListQuestion: 0095 input = listView.currentItem.text; 0096 listView.model.clear(); 0097 listView.visible = false; 0098 break; 0099 case NewStuffCore.Question.InputTextQuestion: 0100 input = textInput.text; 0101 textInput.text = ""; 0102 textInput.visible = false; 0103 break; 0104 case NewStuffCore.Question.PasswordQuestion: 0105 input = textInput.text; 0106 textInput.text = ""; 0107 textInput.visible = false; 0108 textInput.echoMode = QtControls.TextInput.Normal; 0109 break; 0110 case NewStuffCore.Question.ContinueCancelQuestion: 0111 case NewStuffCore.Question.YesNoQuestion: 0112 default: 0113 // Nothing special to do for these types of question, we just pass along the positive or negative response 0114 break; 0115 } 0116 NewStuff.QuickQuestionListener.passResponse(responseIsContinue, input); 0117 } 0118 0119 QtLayouts.ColumnLayout { 0120 anchors.fill: parent 0121 property int maxWidth: applicationWindow().width - (dialog.leftPadding + dialog.leftMargin + dialog.rightMargin + dialog.rightPadding) 0122 QtControls.Label { 0123 id: questionLabel 0124 QtLayouts.Layout.maximumWidth: parent.maxWidth 0125 wrapMode: Text.Wrap 0126 } 0127 ListView { 0128 id: listView 0129 visible: false 0130 QtLayouts.Layout.maximumWidth: parent.maxWidth 0131 QtLayouts.Layout.fillWidth: true 0132 QtLayouts.Layout.minimumHeight: Kirigami.Units.gridUnit * 6 0133 model: ListModel { } 0134 delegate: Kirigami.BasicListItem { 0135 reserveSpaceForIcon: false 0136 text: model.text 0137 } 0138 } 0139 QtControls.TextField { 0140 id: textInput 0141 visible: false 0142 QtLayouts.Layout.maximumWidth: parent.maxWidth 0143 QtLayouts.Layout.fillWidth: true 0144 } 0145 } 0146 onAccepted: { 0147 passResponse(true); 0148 } 0149 onRejected: { 0150 passResponse(false); 0151 } 0152 }