PDA

View Full Version : QAbstractTextDocumentLayout handler problem



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);
}

patrik08
26th April 2008, 20:58
I find its :) without QPalette QAbstractTextDocumentLayout its draw nothing
Maybe its can not read default palette style...

super now i having a thiny QGraphicsTextItem to build a extended layer editor
if you like to play grab the initial running code on:
svn co http://fop-miniscribus.googlecode.com/svn/trunk/GraphicsTextEditor/ GraphicsTextEditor

here the solution to display blinking cursor and selected cursor text...




if (edit_enable) {
if (C_cursor.hasSelection()) {
QAbstractTextDocumentLayout::Selection Internal_selection;
Internal_selection.cursor = C_cursor;
QPalette::ColorGroup cg = cursorIsFocusIndicator ? QPalette::Active : QPalette::Inactive;
Internal_selection.format.setBackground(CTX.palett e.brush(cg, QPalette::Highlight));
Internal_selection.format.setForeground(CTX.palett e.brush(cg, QPalette::HighlightedText));
Internal_selection.format.setProperty(QTextFormat: :FullWidthSelection, true);
CTX.selections.append(Internal_selection);
}
}