Warning, /utilities/mangonel/main.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 2.2
0002 import QtQuick.Window 2.2
0003 import QtQuick.Controls 1.4
0004 import org.kde 1.0
0005 import QtGraphicalEffects 1.0
0006
0007 Window {
0008 id: window
0009 flags: Qt.Dialog | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
0010
0011 color: "transparent"
0012
0013 height: 650
0014
0015 width: 300;//Math.max(window.screen.width / 4, 300)
0016 y: window.screen.height / 2 - height / 2
0017 x: window.screen.width / 2 - width / 2
0018 visible :false
0019
0020 onVisibleChanged:{
0021 inputText.text = ""
0022
0023 if (visible) {
0024 modality = Qt.ApplicationModal
0025 requestActivate()
0026
0027 var desktopWidth = window.screen.width
0028 window.width = Math.min(desktopWidth / 1.5, window.height * 2)
0029 } else {
0030 modality = Qt.NonModal
0031 }
0032
0033 inputText.preHistoryText = ""
0034 inputText.historyIndex = -1
0035 }
0036
0037 onActiveChanged: if (!active) visible = false
0038 onActiveFocusItemChanged: if (!activeFocusItem) visible = false
0039
0040 Connections {
0041 target: Mangonel
0042 function onTriggered() {
0043 window.visible = true
0044 }
0045 }
0046
0047 Rectangle {
0048 id: background
0049 anchors {
0050 top: parent.top
0051 left: parent.left
0052 right: parent.right
0053 }
0054 height: 400 + historyList.height
0055
0056 Behavior on height { NumberAnimation { duration: 50 } }
0057
0058 color: Qt.rgba(0, 0, 0, 0.75)
0059 radius: 10
0060 border.width: 5
0061 border.color: "black"
0062
0063 Rectangle {
0064 id: bottomBackground
0065
0066 anchors {
0067 bottom: background.bottom
0068 left: background.left
0069 right: background.right
0070 }
0071 color: "black"
0072 height: inputText.height + 20
0073 }
0074 }
0075
0076 MouseArea {
0077 id: mouseArea
0078 anchors.fill: background
0079 acceptedButtons: Qt.RightButton
0080 onClicked: {
0081 popupMenu.popup()
0082 }
0083 }
0084
0085 ListView {
0086 id: resultList
0087 visible: false
0088
0089 anchors {
0090 top: background.top
0091 left: background.left
0092 right: background.right
0093 }
0094 height: 350
0095 clip: true
0096 orientation: Qt.Horizontal
0097 highlightMoveDuration: 100
0098 preferredHighlightBegin: width/2 - itemWidth/2
0099 preferredHighlightEnd: width/2 + itemWidth/2
0100 highlightRangeMode: ListView.StrictlyEnforceRange
0101
0102 property real itemWidth: height
0103
0104 delegate: Item {
0105 width: resultList.itemWidth
0106 height: resultList.height
0107
0108 function launch() {
0109 if (!modelData) {
0110 return
0111 }
0112
0113 Mangonel.launch(modelData)
0114 }
0115
0116 property string type: modelData.type
0117 property string completion: modelData.completion
0118
0119 opacity: ListView.view.currentIndex === index ? 1 : 0.2
0120 Behavior on opacity { NumberAnimation { duration: 100 } }
0121
0122 Image {
0123 id: icon
0124 anchors {
0125 top: parent.top
0126 topMargin: 10
0127 horizontalCenter: parent.horizontalCenter
0128 }
0129
0130 source: "image://icon/" + modelData.icon
0131 sourceSize.width: parent.width
0132 sourceSize.height: parent.height - nameText.height - 20
0133 }
0134
0135 Text {
0136 id: nameText
0137 anchors {
0138 bottom: parent.bottom
0139 bottomMargin: 20
0140 left: parent.left
0141 right: parent.right
0142 }
0143 property string name: modelData.completion
0144 onNameChanged: {
0145 var index = name.toLowerCase().indexOf(inputText.text.toLowerCase())
0146 if (index === -1) {
0147 text = name
0148 return
0149 }
0150
0151 text = name.substring(0, index)
0152 text += "<b>"
0153 text += name.substring(index, index + inputText.text.length)
0154 text += "</b>"
0155 text += name.substring(index + inputText.text.length)
0156 }
0157 color: "white"
0158
0159 font.pointSize: 20
0160 horizontalAlignment: Text.AlignHCenter
0161 verticalAlignment: Text.AlignVCenter
0162 text: modelData.completion
0163 wrapMode: Text.WordWrap
0164 }
0165 }
0166 }
0167
0168 LinearGradient {
0169 id: mask
0170 anchors.fill: resultList
0171 property real centerLeft: (width / 2 - resultList.itemWidth / 2) / width
0172 property real centerRight: (width / 2 + resultList.itemWidth / 2) / width
0173
0174 gradient: Gradient {
0175 GradientStop { position: 0.1; color: Qt.rgba(1, 1, 1, 1) }
0176 GradientStop { position: mask.centerLeft; color: Qt.rgba(0, 0, 0, 0) }
0177 GradientStop { position: mask.centerRight; color: Qt.rgba(0, 0, 0, 0) }
0178 GradientStop { position: 0.9; color: Qt.rgba(1, 1, 1, 1) }
0179 }
0180
0181 start: Qt.point(0, 0)
0182 end: Qt.point(resultList.width, 0)
0183 opacity: 0.5
0184 visible: false
0185 }
0186
0187 MaskedBlur {
0188 anchors.centerIn: resultList
0189 width: parent.visible ? resultList.width : 0
0190 height: parent.visible ? resultList.height : 0
0191 source: resultList
0192 maskSource: mask
0193 radius: parent.visible ? 8 : 0
0194 samples: 24
0195 Behavior on height { NumberAnimation { duration: 10 } }
0196 Behavior on width { NumberAnimation { duration: 10 } }
0197 }
0198
0199 // Can't use a MouseArea directly in the item delegates because it is invisible, because of the blur
0200 Row {
0201 id: clickableRow
0202 anchors {
0203 fill: resultList
0204 margins: spacing
0205 leftMargin: -resultList.itemWidth/2 + spacing*2
0206 }
0207 spacing: 35
0208
0209 Repeater {
0210 id: clickableRepeater
0211 model: 5
0212 MouseArea {
0213 height: resultList.height - clickableRow.spacing
0214 width: resultList.itemWidth - clickableRow.spacing * 2
0215 cursorShape: Qt.PointingHandCursor
0216 property real diff: modelData - Math.floor(clickableRepeater.model/2)
0217 onClicked: {
0218 const newIndex = resultList.currentIndex + diff;
0219 if (newIndex < 0 || newIndex >= resultList.count) {
0220 return;
0221 }
0222 resultList.currentIndex = newIndex;
0223 }
0224 }
0225 }
0226 }
0227
0228 Text {
0229 anchors {
0230 left: background.left
0231 leftMargin: 15
0232 verticalCenter: inputText.verticalCenter
0233 }
0234 text: (resultList.count > 0 && resultList.currentItem !== null) ? resultList.currentItem.type : ""
0235 color: "white"
0236 }
0237
0238 ListView {
0239 id: historyList
0240 anchors {
0241 bottom: inputText.top
0242 bottomMargin: 15
0243 }
0244 x: inputText.x + inputText.cursorRectangle.x - inputText.width
0245 height: inputText.historyIndex >= 0 ? 190 : 0
0246 interactive: false
0247 highlightFollowsCurrentItem: true
0248 currentIndex: inputText.historyIndex
0249
0250 model: height ? Mangonel.history : 0
0251 verticalLayoutDirection: ListView.BottomToTop
0252
0253 delegate: Text { text: modelData; color: "white"; font.bold: index == inputText.historyIndex; opacity: font.bold ? 1 : 0.4 }
0254 }
0255
0256 TextInput {
0257 id: inputText
0258 anchors {
0259 horizontalCenter: background.horizontalCenter
0260 bottom: background.bottom
0261 bottomMargin: 10
0262 }
0263
0264 property var history: Mangonel.history
0265 property int historyIndex: -1
0266 property string preHistoryText: ""
0267
0268 onHistoryIndexChanged: {
0269 if (historyIndex < 0) {
0270 text = preHistoryText
0271 return
0272 }
0273 if (historyIndex >= history.length ) return
0274
0275 text = history[historyIndex]
0276 }
0277
0278 Keys.onDownPressed: {
0279 if (historyIndex >= 0) {
0280 historyIndex--
0281 }
0282 }
0283
0284 Keys.onUpPressed: {
0285 if (historyIndex < 0) { // preserve what is written now
0286 preHistoryText = text
0287 }
0288
0289 if (historyIndex <= history.length - 1) {
0290 historyIndex++
0291 }
0292 }
0293
0294 color: "white"
0295 focus: true
0296 font.pointSize: 15
0297 font.bold: true
0298 onTextChanged: resultList.model = Mangonel.setQuery(text)
0299
0300 Keys.onEscapePressed: window.visible = false
0301 Keys.onLeftPressed: {
0302 if (resultList.currentIndex > 0) {
0303 resultList.currentIndex--
0304 }
0305 event.accepted = true
0306 }
0307 Keys.onRightPressed: {
0308 if (resultList.currentIndex < resultList.count - 1) {
0309 resultList.currentIndex++
0310 }
0311 event.accepted = true
0312 }
0313 Keys.onTabPressed: {
0314 event.accepted = true
0315 if (resultList.currentItem === null) {
0316 return
0317 }
0318 text = resultList.currentItem.completion
0319 }
0320
0321 onAccepted: {
0322 if (resultList.currentItem === null) {
0323 return
0324 }
0325
0326 resultList.currentItem.launch()
0327 window.visible = false
0328 }
0329 }
0330
0331 MouseArea {
0332 anchors {
0333 left: background.left
0334 right: background.right
0335 bottom: background.bottom
0336 }
0337
0338 acceptedButtons: "MiddleButton"
0339 onClicked: inputText.text += Mangonel.selectionClipboardContent()
0340 height: bottomBackground.height
0341 }
0342
0343 Menu {
0344 id: popupMenu
0345 title: "Mangonel"
0346 MenuItem {
0347 text: qsTr("Configure &shortcuts")
0348 iconName: "configure-shortcuts"
0349 onTriggered: Mangonel.showConfig()
0350 shortcut: StandardKey.Preferences
0351 }
0352 MenuItem {
0353 text: qsTr("Configure ¬ifications")
0354 iconName: "preferences-desktop-notifications"
0355 onTriggered: Mangonel.configureNotifications()
0356 }
0357 MenuSeparator {}
0358 MenuItem {
0359 text: qsTr("&Quit")
0360 iconName: "application-exit"
0361 onTriggered: Qt.quit()
0362 shortcut: StandardKey.Quit
0363 }
0364 }
0365 }