QtQuick中解析富文本<初>
扫描二维码
随时随地手机看文章
#include
void TQmlHelper::makeDoc( QQuickTextDocument* doc)
{
jAVA_QMessage("开始");
QTextDocument *document =doc->textDocument();
if(document==NULL)
{
jAVA_QMessage("NULL DOCUMENT");
}
QTextBlock currentBlock = document->begin();
QTextBlock::iterator it;
while( true)
{
for (it = currentBlock.begin(); !(it.atEnd()); )
{
QTextFragment currentFragment = it.fragment();
QTextImageFormat newImageFormat = currentFragment.charFormat().toImageFormat();
if (newImageFormat.isValid()) {
// 为image
jAVA_QMessage(newImageFormat.name());
}
++it;
}
currentBlock = currentBlock.next();
jAVA_QMessage("一循环");
if(!currentBlock.isValid())
{
break;
}
}
}
Rectangle{
id:sendroot
xxx..
property var offsetBeginX: 20
property var offsetendx: 10
Rectangle{
id: flickable
x:offsetBeginX
anchors.bottom: parent.bottom
width: sendroot.width - btn.width -offsetBeginX-offsetendx
height:edit.focus==true?flick.height:btn.height
color: "transparent"
radius: 5
border.width: 1
border.color: "#cccccc"
clip: true
Flickable{
id:flick
width: parent.width
height: contentHeight>100?100:contentHeight
contentHeight: edit.height
TextArea.flickable: TextArea{
Material.foreground : "#ffffff"
id:edit
padding: 0
width: parent.width
font.pointSize: 14
height: contentHeight>btn.height?contentHeight:btn.height
wrapMode: TextArea.Wrap
textFormat: TextEdit.RichText
text:"Hello~~"
Component.onCompleted: {
edit.insert(edit.length,"");
}
onTextChanged: {
lizi.dodo(20)
}
onFocusChanged: {
if(focus == true)
{
cursorPosition = length
}
}
Lizi{
id:lizi
x:edit.cursorRectangle.x
y:edit.cursorRectangle.y
每秒发射个数:10
初始大小:8
大小变化范围:14
初始生命:1000
生命变化范围:500
粒子速度:20
角度:0
角度变化范围:360
}
}
ScrollBar.vertical: ScrollBar{
active: true
pressed: true}
}
}
Ola.Button{
x:flickable.x+flickable.width + offsetendx
anchors.bottom: parent.bottom
id:btn
text:"发送"
isDefault: true
// font.bold: true
// font.pointSize: 14
height: 40
width: 100
onClicked: {
myapp.jAVA_QMessage(edit.textDocument);
myapp.makeDoc(edit.textDocument);
xxx..
}
}
}