patrik08
26th April 2008, 09:56
I draw a QTextDocument on QGraphicsItem to edit xhtml <div> layer
on a separate QObject i handle all text like QTextControl i connect my timer from blink cursor and the doc
d = new QTextDocument(this);
_layout = _d->documentLayout();
connect ....
by timer event on blink cursor i update only his rect,
now i have trouble to handle QAbstractTextDocumentLayout
cursor blink run , i can edit document , move its , and all other...
only text Highlight by selection from cursor not run...
On line 36 from this code i have a true selecection by text
selectAll(); or word select i send the update request and his not draw :-( why,
note C_cursor ist the original QTextCursor from selection...
/* child from class TextLayer : public QObject, public QGraphicsItem */
void MountTextPrivate::paint_doc( QPainter * painter ,
const QStyleOptionGraphicsItem *option ,
QBrush BGpage ,
const QRectF fulllayer ,
bool alternate )
{
/* Layer Background draw! */
painter->save();
painter->setPen(Qt::NoPen);
painter->setBrush(BGpage);
painter->drawRect(fulllayer);
painter->restore();
/* rect from frame root QTextDocument*/
QRectF doc_rect = boundingRect();
QColor BackHightlight("#a6ffc7");
BackHightlight.setAlpha(140);
QAbstractTextDocumentLayout::PaintContext CTX;
CTX.selections;
if (doc_rect.isValid()) {
painter->setClipRect(doc_rect, Qt::IntersectClip);
CTX.clip = doc_rect;
}
CTX.palette.setColor(QPalette::Highlight,BackHight light);
CTX.palette.setColor(QPalette::HighlightedText,Qt: :black);
/* blink cursor from timer event ! */
if (cursortime) {
CTX.cursorPosition = cursor_position;
}
if (C_cursor.hasSelection()) {
QAbstractTextDocumentLayout::Selection Internal_selection;
Internal_selection.cursor = C_cursor;
CTX.selections.append(Internal_selection);
}
_layout->draw(painter,CTX);
}
on a separate QObject i handle all text like QTextControl i connect my timer from blink cursor and the doc
d = new QTextDocument(this);
_layout = _d->documentLayout();
connect ....
by timer event on blink cursor i update only his rect,
now i have trouble to handle QAbstractTextDocumentLayout
cursor blink run , i can edit document , move its , and all other...
only text Highlight by selection from cursor not run...
On line 36 from this code i have a true selecection by text
selectAll(); or word select i send the update request and his not draw :-( why,
note C_cursor ist the original QTextCursor from selection...
/* child from class TextLayer : public QObject, public QGraphicsItem */
void MountTextPrivate::paint_doc( QPainter * painter ,
const QStyleOptionGraphicsItem *option ,
QBrush BGpage ,
const QRectF fulllayer ,
bool alternate )
{
/* Layer Background draw! */
painter->save();
painter->setPen(Qt::NoPen);
painter->setBrush(BGpage);
painter->drawRect(fulllayer);
painter->restore();
/* rect from frame root QTextDocument*/
QRectF doc_rect = boundingRect();
QColor BackHightlight("#a6ffc7");
BackHightlight.setAlpha(140);
QAbstractTextDocumentLayout::PaintContext CTX;
CTX.selections;
if (doc_rect.isValid()) {
painter->setClipRect(doc_rect, Qt::IntersectClip);
CTX.clip = doc_rect;
}
CTX.palette.setColor(QPalette::Highlight,BackHight light);
CTX.palette.setColor(QPalette::HighlightedText,Qt: :black);
/* blink cursor from timer event ! */
if (cursortime) {
CTX.cursorPosition = cursor_position;
}
if (C_cursor.hasSelection()) {
QAbstractTextDocumentLayout::Selection Internal_selection;
Internal_selection.cursor = C_cursor;
CTX.selections.append(Internal_selection);
}
_layout->draw(painter,CTX);
}