/*SPDX-FileCopyrightText: 2014-2017 Weng Xuetian <wengxt@gmail.com>SPDX-License-Identifier: GPL-2.0-or-later*/import QtQuick 2.6import QtQuick.Layouts 1.1import org.kde.plasma.plasmoid 2.0import org.kde.plasma.core as PlasmaCoreimport org.kde.plasma.components 3.0 as PlasmaComponents3import org.kde.plasma.private.kimpanel 0.1 as Kimpanelimport org.kde.kirigami 2.20 as Kirigamiimport org.kde.plasma.plasmoid 2.0PlasmaCore.Dialog {id: inputpaneltype: PlasmaCore.Dialog.PopupMenuflags: {var flag = Qt.WindowTransparentForInput | Qt.WindowStaysOnTopHint | Qt.WindowDoesNotAcceptFocus;if (Qt.platform.pluginName.includes("wayland")) {flag |= Qt.ToolTip;} else {flag |= Qt.Popup;}return flag;}location: PlasmaCore.Types.Floatingvisible: helper.auxVisible || helper.preeditVisible || helper.lookupTableVisiblereadonly property bool verticalLayout: (helper.lookupTableLayout === 1) || (helper.lookupTableLayout === 0 && Plasmoid.configuration.vertical_lookup_table);property int highlightCandidate: helper.lookupTableCursorproperty int hoveredCandidate: -1property font preferredFont: Plasmoid.configuration.use_default_font ? Kirigami.Theme.defaultFont : Plasmoid.configuration.fontreadonly property alias textOffset: fontMetrics.ascentreadonly property alias labelHeight: fontMetrics.heightproperty rect position: helper.spotRectonPositionChanged : updatePosition();onWidthChanged : updatePosition();onHeightChanged : updatePosition();mainItem: Item {Layout.minimumWidth: childrenRect.widthLayout.minimumHeight: childrenRect.heightLayout.maximumWidth: childrenRect.widthLayout.maximumHeight: childrenRect.heightFontMetrics {id: fontMetricsfont: preferredFont}Column {spacing: Kirigami.Units.smallSpacingRow {id: textLabelwidth: auxLabel.width + preedit.widthheight: inputpanel.labelHeightvisible: helper.auxVisible || helper.preeditVisiblebaselineOffset: inputpanel.textOffsetPlasmaComponents3.Label {id: auxLabelanchors.baseline: parent.baselinefont: preferredFonttext: helper.auxTexttextFormat: Text.PlainTextvisible: helper.auxVisible}Item {id: preeditwidth: preeditLabel1.width + preeditLabel2.width + 2height: parent.heightclip: truevisible: helper.preeditVisiblebaselineOffset: inputpanel.textOffsetPlasmaComponents3.Label {id: preeditLabel1anchors.baseline: parent.baselineanchors.left: parent.leftfont: preferredFonttextFormat: Text.PlainText}Rectangle {color: Kirigami.Theme.textColorheight: parent.heightwidth: 1opacity: 0.8z: 1anchors.verticalCenter: parent.verticalCenteranchors.left: preeditLabel1.right}PlasmaComponents3.Label {id: preeditLabel2anchors.baseline: parent.baselineanchors.left: preeditLabel1.rightfont: preferredFonttextFormat: Text.PlainText}}}GridLayout {flow: inputpanel.verticalLayout ? GridLayout.TopToBottom : GridLayout.LeftToRightcolumns: inputpanel.verticalLayout ? 1 : tableList.count + 1rows: inputpanel.verticalLayout ? tableList.count + 1 : 1Repeater {model: ListModel {id: tableListdynamicRoles: true}delegate: Item {id: candidateDelegatewidth: candidate.width + highlight.marginHints.left + highlight.marginHints.rightheight: inputpanel.labelHeight + highlight.marginHints.top + highlight.marginHints.bottomLayout.minimumWidth: widthLayout.minimumHeight: heightLayout.maximumWidth: widthLayout.maximumHeight: heightreadonly property bool selected: inputpanel.highlightCandidate === model.index || candidateMouseArea.pressedRow {id: candidatewidth: childrenRect.widthheight: childrenRect.heightx: highlight.marginHints.lefty: highlight.marginHints.topbaselineOffset: inputpanel.textOffsetspacing: Kirigami.Units.smallSpacingPlasmaComponents3.Label {id: tableLabeltext: model.labeltextFormat: Text.PlainTextfont: preferredFontopacity: 0.8color: Kirigami.Theme.textColoranchors.baseline: parent.baseline}PlasmaComponents3.Label {id: textLabeltext: model.texttextFormat: Text.PlainTextfont: preferredFontcolor: Kirigami.Theme.textColoranchors.baseline: parent.baseline}}MouseArea {id: candidateMouseAreaanchors.fill: parenthoverEnabled: trueonReleased: helper.selectCandidate(model.index)onContainsMouseChanged: {inputpanel.hoveredCandidate = containsMouse ? model.index : -1;}}CandidateHighlight {id: highlightz: -1visible: inputpanel.highlightCandidate === model.index || inputpanel.hoveredCandidate === model.indexselected: candidateDelegate.selectedanchors {fill: parent}}}}Row {id: buttonwidth: inputpanel.labelHeight * 2height: inputpanel.labelHeightLayout.minimumWidth: widthLayout.minimumHeight: heightLayout.maximumWidth: widthLayout.maximumHeight: heightspacing: Kirigami.Units.smallSpacingKirigami.Icon {id: prevButtonsource: inputpanel.verticalLayout ? "arrow-up" : "arrow-left"width: inputpanel.labelHeightheight: widthscale: prevButtonMouseArea.pressed ? 0.9 : 1active: prevButtonMouseArea.containsMouseMouseArea {id: prevButtonMouseAreaanchors.fill: parenthoverEnabled: trueonReleased: helper.lookupTablePageUp()}}Kirigami.Icon {id: nextButtonsource: inputpanel.verticalLayout ? "arrow-down" : "arrow-right"width: inputpanel.labelHeightheight: widthscale: nextButtonMouseArea.pressed ? 0.9 : 1active: nextButtonMouseArea.containsMouseMouseArea {id: nextButtonMouseAreaanchors.fill: parenthoverEnabled: trueonReleased: helper.lookupTablePageDown()}}}}}Kimpanel.Screen {id: screen}// Kimpanel's update may come in with in several DBus message. Use// timer to delegate the update so we get less flicker.Timer {id: timerinterval: 1onTriggered: updateLookupTable()}Connections {target: helperfunction onPreeditTextChanged() {var charArray = [...helper.preeditText];preeditLabel1.text = charArray.slice(0, helper.caretPos).join('');preeditLabel2.text = charArray.slice(helper.caretPos).join('');}function onLookupTableChanged() {timer.restart();}}}function updateLookupTable() {inputpanel.hoveredCandidate = -1;button.visible = helper.lookupTableVisible && (helper.hasPrev || helper.hasNext);var labels = helper.labels;var texts = helper.texts;var length = Math.min(labels.length, texts.length);if (helper.lookupTableVisible) {if (length< tableList.count) {tableList.remove(length, tableList.count - length);}for (var i = 0; i < length; i ++) {if (i >= tableList.count) {tableList.append({'label' : labels[i], 'text': texts[i], 'index': i});} else {tableList.set(i, {'label' : labels[i], 'text': texts[i], 'index': i});}}} else {tableList.clear();}}function updatePosition() {var rect = screen.geometryForPoint(position.x, position.y);var devicePerPixelRatio = screen.devicePixelRatioForPoint(position.x, position.y);var x, y;var width = inputpanel.width * devicePerPixelRatio;var height = inputpanel.height * devicePerPixelRatio;if (position.x < rect.x) {x = rect.x;} else {x = position.x;}if (position.y < rect.y) {y = rect.y;} else {y = position.y + position.height;}if (x + width > rect.x + rect.width) {x = rect.x + rect.width - width;}if (y + height > rect.y + rect.height) {if (y > rect.y + rect.height) {y = rect.y + rect.height - height - 40;} else {y = y - height - (position.height === 0 ? 40 : position.height);}}var newRect = screen.geometryForPoint(x, y);devicePerPixelRatio = screen.devicePixelRatioForPoint(x, y);inputpanel.x = newRect.x + (x - newRect.x) / devicePerPixelRatio;inputpanel.y = newRect.y + (y - newRect.y) / devicePerPixelRatio;}}