代码拉取完成,页面将自动刷新
同步操作将从 LukeLee/QmlInputMethod 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import QtQuick 2.9
import QtQuick.Controls 2.2
import InputMethod 1.0
Item {
id: candidateBarRoot
width: wordsLoader.width + pageRow.width + wordsSpacing
height: wordsLoader.height
property var wordslist : []
property int page: 0
property int style
property int wordsPerPage
property int fontSize
property int pageButtonSize
property int wordsSpacing
property string wordsColor
property string firstWordColor
signal wordClicked(int index)
Loader {
id: wordsLoader
sourceComponent: {
if (style == Input.CandidateWords_Horizontal)
return wordsRowComp
else if (style == Input.CandidateWords_Vertical) {
return wordsColComp
}
}
}
Row {
id: pageRow
anchors.left: wordsLoader.right
anchors.leftMargin: wordsSpacing
anchors.bottom: wordsLoader.bottom
visible: wordslist.length
ItemDelegate {
width: preText.width + wordsSpacing
height: preText.height + wordsSpacing
onClicked: {
prePage()
}
Label {
id: preText
text: "<"
anchors.centerIn: parent
font.pixelSize: pageButtonSize
color: wordsColor
}
}
ItemDelegate {
width: nextText.width + wordsSpacing
height: nextText.height + wordsSpacing
onClicked: {
nextPage()
}
Label {
id: nextText
text: ">"
anchors.centerIn: parent
font.pixelSize: pageButtonSize
color: wordsColor
}
}
}
Component {
id: wordsRowComp
Row {
Repeater {
model: wordsCount
delegate: wordTextComp
}
}
}
Component {
id: wordsColComp
Column {
Repeater {
model: wordsCount
delegate: wordTextComp
}
}
}
// 每页最多wordsPerPage个候选词
readonly property int wordsCount: wordslist.length < (page+1) * wordsPerPage
? wordslist.length - page * wordsPerPage
: wordsPerPage
Component {
id: wordTextComp
ItemDelegate {
width: word.width + wordsSpacing
height: word.height + wordsSpacing
onClicked: {
candidateBarRoot.wordClicked(index + 1)
}
Text {
id: word
anchors.centerIn: parent
font.pixelSize: fontSize
text: (index+1) + "." +wordslist[index+page*wordsPerPage]
color: index == 0 ? firstWordColor : wordsColor
}
}
}
function clear() {
wordslist = []
page = 0
}
function nextPage() {
if (wordslist.length > wordsPerPage * (page+1)) {
page += 1
}
}
function prePage() {
if (page > 0) {
page -= 1
}
}
function getText(index) {
return wordslist[(page*wordsPerPage+index-1)]
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。