本文整理汇总了C++中QTextFrame类的典型用法代码示例。如果您正苦于以下问题:C++ QTextFrame类的具体用法?C++ QTextFrame怎么用?C++ QTextFrame使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTextFrame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QwtRichTextDocument
QwtRichTextDocument( const QString &text, int flags, const QFont &font )
{
setUndoRedoEnabled( false );
setDefaultFont( font );
setHtml( text );
// make sure we have a document layout
( void )documentLayout();
QTextOption option = defaultTextOption();
if ( flags & Qt::TextWordWrap )
option.setWrapMode( QTextOption::WordWrap );
else
option.setWrapMode( QTextOption::NoWrap );
option.setAlignment( ( Qt::Alignment ) flags );
setDefaultTextOption( option );
QTextFrame *root = rootFrame();
QTextFrameFormat fm = root->frameFormat();
fm.setBorder( 0 );
fm.setMargin( 0 );
fm.setPadding( 0 );
fm.setBottomMargin( 0 );
fm.setLeftMargin( 0 );
root->setFrameFormat( fm );
adjustSize();
}
示例2: QGraphicsItem
TextLayer::TextLayer(const int layer_id , QGraphicsItem *parent , QGraphicsScene *scene )
: QGraphicsItem(parent,scene),evesum(0),modus(Show),border(1.),currentprintrender(false),
hi(Metric("30px")),wi(Metric("110px")),bgcolor(QColor(Qt::white)),SwapLockBreak(false),
bordercolor(QColor(Qt::red)),Rotate(0),check_view_area_time(0),ActionHover(false),
format(DIV_ABSOLUTE),mount(new TextController)
{
mount->q = this;
setAcceptsHoverEvents(true);
wisub_border = wi + border;
history.clear();
id = layer_id;
setAcceptDrops(true);
setFlag(QGraphicsItem::ItemIsSelectable,true);
setFlag(QGraphicsItem::ItemIsFocusable,true);
setFlag(QGraphicsItem::ItemIsMovable,false);
setSelected(false);
_doc = new QTextDocument();
_doc->setHtml(tr("<p>Write your text<p>"));
QTextFrame *Tframe = _doc->rootFrame();
QTextFrameFormat rootformats = Tframe->frameFormat();
rootformats.setWidth(wi);
rootformats.setBorder(0);
Tframe->setFrameFormat(rootformats);
_doc->setPageSize(QSizeF(wi,hi));
DLayout = _doc->documentLayout();
setDocument(_doc);
mount->txtControl()->document()->toHtml().size(); /* connect all */
setZValue(1.99999);
RestoreMoveAction();
init();
}
示例3: Q_Q
void QTextFramePrivate::remove_me()
{
Q_Q(QTextFrame);
if (fragment_start == 0 && fragment_end == 0
&& !parentFrame) {
q->document()->docHandle()->deleteObject(q);
return;
}
if (!parentFrame)
return;
int index = parentFrame->d_func()->childFrames.indexOf(q);
// iterator over all children and move them to the parent
for (int i = 0; i < childFrames.size(); ++i) {
QTextFrame *c = childFrames.at(i);
parentFrame->d_func()->childFrames.insert(index, c);
c->d_func()->parentFrame = parentFrame;
++index;
}
Q_ASSERT(parentFrame->d_func()->childFrames.at(index) == q);
parentFrame->d_func()->childFrames.removeAt(index);
childFrames.clear();
parentFrame = 0;
}
示例4: Q_ASSERT
void QTextDocumentPrivate::insert_string(int pos, uint strPos, uint length, int format, QTextUndoCommand::Operation op)
{
// ##### optimise when only appending to the fragment!
Q_ASSERT(noBlockInString(text.mid(strPos, length)));
split(pos);
uint x = fragments.insert_single(pos, length);
QTextFragmentData *X = fragments.fragment(x);
X->format = format;
X->stringPosition = strPos;
uint w = fragments.previous(x);
if (w)
unite(w);
int b = blocks.findNode(pos);
blocks.setSize(b, blocks.size(b)+length);
Q_ASSERT(blocks.length() == fragments.length());
QTextFrame *frame = qobject_cast<QTextFrame *>(objectForFormat(format));
if (frame) {
frame->d_func()->fragmentAdded(text.at(strPos), x);
framesDirty = true;
}
adjustDocumentChangesAndCursors(pos, length, op);
}
示例5: UpdateVars
void WymsingTxt::UpdateVars() {
BorderDicks = MarginSize->value();
InitValue.setWidth( BoxLarghezza->value() );
InitValue.setHeight ( BoxAltezza->value() );
BGColor.setAlpha ( AlphaColor );
rootformat.setBottomMargin ( psud->value() );
rootformat.setLeftMargin ( pwest->value() );
rootformat.setRightMargin ( post->value() );
rootformat.setTopMargin ( pnord->value() );
rootformat.setBackground ( BGColor );
tdoc = wtxt->document()->clone();
QTextFrame *TfNewFo = tdoc->rootFrame();
TfNewFo->setFrameFormat ( rootformat );
DocFrameFormings = rootformat;
wtxt->setDocument ( tdoc );
wtxt->document()->setUseDesignMetrics (true );
destimage->setDocument ( tdoc );
destimage->setPos ( QPointF(XXset->value(),YYset->value()) );
emit RetocValues(InitValue,BorderDicks,BGColor,MarginColor,tdoc,wtxt->GetListBlock());
DocFrameFormings.setWidth( BoxLarghezza->value() );
wtxt->document()->rootFrame()->setFrameFormat ( DocFrameFormings );
}
示例6: appendMessageToCurrentSession
/*! Append a new message to the current session and scroll to the end of the message protocol and
returns true if the action was successful. The \a messageColor defines the color of the message
box and should be provided as a full-color (no dimming required) color, as it is automatically
adjusted for the border and background.
*/
bool QwcPrivateMessager::appendMessageToCurrentSession(QTextDocument *document, const QString message, const QColor messageColor)
{
if (!document) { return false; }
QTextCursor cursor = document->rootFrame()->lastCursorPosition();
cursor.movePosition(QTextCursor::StartOfBlock);
QTextFrameFormat frameFormat;
frameFormat.setPadding(4);
frameFormat.setBackground(messageColor.lighter(190));
frameFormat.setMargin(0);
frameFormat.setBorder(2);
frameFormat.setBorderBrush(messageColor.lighter(150));
frameFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Outset);
// Title
QTextCharFormat backupCharFormat = cursor.charFormat();
QTextCharFormat newCharFormat;
newCharFormat.setFontPointSize(9);
QTextBlockFormat headerFormat;
headerFormat.setAlignment(Qt::AlignHCenter);
cursor.insertBlock(headerFormat);
cursor.setCharFormat(newCharFormat);
cursor.insertText(QDateTime::currentDateTime().toString());
QTextFrame *frame = cursor.insertFrame(frameFormat);
cursor.setCharFormat(backupCharFormat);
frame->firstCursorPosition().insertText(message);
return true;
}
示例7: kDebug
int TextDocumentStructureModel::rowCount(const QModelIndex &index) const
{
kDebug(32500) << "-------------------------- index:"<<index<<m_textDocument;
if (! m_textDocument) {
return 0;
}
if (! index.isValid()) {
// one root frame
return 1;
}
Q_ASSERT(index.internalId() < uint(m_nodeDataTable.count()));
const NodeData &nodeData = m_nodeDataTable.at(index.internalId());
if (nodeData.type == NodeData::Frame) {
QTextFrame* frame = nodeData.frame;
// count frames and blocks
int count = 0;
for (QTextFrame::iterator iterator = frame->begin(); !iterator.atEnd(); ++iterator) {
++count;
}
return count;
}
// should be a block then, no childs for now
return 0;
}
示例8: QTextEdit
ClientTextEdit::ClientTextEdit(QWidget* parent) : QTextEdit(parent) {
setReadOnly(true);
setOverwriteMode(true);
setUndoRedoEnabled(false);
setDocumentTitle("mClient");
setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
setTabChangesFocus(false);
//_doc->setMaximumBlockCount(Config().scrollbackSize); // max number of lines?
document()->setUndoRedoEnabled(false);
QTextFrame* frame = document()->rootFrame();
_cursor = frame->firstCursorPosition();
// Default Colors
_foregroundColor = Qt::lightGray;
_backgroundColor = Qt::black;
_blackColor = Qt::darkGray;
_redColor = Qt::darkRed;
_greenColor = Qt::darkGreen;
_yellowColor = Qt::darkYellow;
_blueColor = Qt::darkBlue;
_magentaColor = Qt::darkMagenta;
_cyanColor = Qt::darkCyan;
_grayColor = Qt::lightGray;
_darkGrayColor = Qt::gray;
_brightRedColor = Qt::red;
_brightGreenColor = Qt::green;
_brightYellowColor = Qt::yellow;
_brightBlueColor = Qt::blue;
_brightMagentaColor = Qt::magenta;
_brightCyanColor = Qt::cyan;
_whiteColor = Qt::white;
// Default Fonts
_serverOutputFont = QFont("Monospace", 10);
_inputLineFont = QFont("Monospace", 10); //QApplication::font();
_serverOutputFont.setStyleHint(QFont::TypeWriter, QFont::PreferAntialias);
QTextFrameFormat frameFormat = frame->frameFormat();
frameFormat.setBackground(_backgroundColor);
frameFormat.setForeground(_foregroundColor);
frame->setFrameFormat(frameFormat);
_format = _cursor.charFormat();
setDefaultFormat(_format);
_defaultFormat = _format;
_cursor.setCharFormat(_format);
QFontMetrics fm(_serverOutputFont);
setTabStopWidth(fm.width(" ") * 8); // A tab is 8 spaces wide
QScrollBar* scrollbar = verticalScrollBar();
scrollbar->setSingleStep(fm.leading()+fm.height());
connect(scrollbar, SIGNAL(sliderReleased()),
this, SLOT(scrollBarReleased()));
previous = 0;
}
示例9: hitTestIterated
int KTextDocumentLayout::hitTestIterated(QTextFrame::iterator begin, QTextFrame::iterator end, const QPointF &point, Qt::HitTestAccuracy accuracy) const
{
int position = -1;
QTextFrame::iterator it = begin;
for (it = begin; it != end; ++it) {
QTextBlock block = it.currentBlock();
QTextTable *table = qobject_cast<QTextTable*>(it.currentFrame());
QTextFrame *subFrame = it.currentFrame();
if (table) {
QTextTableCell cell = m_state->hitTestTable(table, point);
if (cell.isValid()) {
position = hitTestIterated(cell.begin(), cell.end(), point,
accuracy);
if (position == -1)
position = cell.lastPosition();
return position;
}
continue;
} else if (subFrame) {
position = hitTestIterated(subFrame->begin(), subFrame->end(), point, accuracy);
if (position != -1)
return position;
continue;
} else {
if (!block.isValid())
continue;
}
// kDebug(32500) <<"hitTest[" << point.x() <<"," << point.y() <<"]";
QTextLayout *layout = block.layout();
if (point.y() > layout->boundingRect().bottom()) {
// just skip this block. position = block.position() + block.length() - 1;
continue;
}
for (int i = 0; i < layout->lineCount(); i++) {
QTextLine line = layout->lineAt(i);
// kDebug(32500) <<" + line[" << line.textStart() <<"]:" << line.y() <<"-" << line.height();
if (point.y() > line.y() + line.height()) {
position = line.textStart() + line.textLength();
continue;
}
if (accuracy == Qt::ExactHit && point.y() < line.y()) // between lines
return -1;
if (accuracy == Qt::ExactHit && // left or right of line
(point.x() < line.x() || point.x() > line.x() + line.width()))
return -1;
if (point.x() > line.width() && layout->textOption().textDirection() == Qt::RightToLeft) {
// totally right of RTL text means the position is the start of the text.
return block.position() + line.textStart();
}
return block.position() + line.xToCursor(point.x());
}
}
return -1;
}
示例10:
static QTextFrame *findChildFrame(QTextFrame *f, int pos)
{
// ##### use binary search
QList<QTextFrame *> children = f->childFrames();
for (int i = 0; i < children.size(); ++i) {
QTextFrame *c = children.at(i);
if (pos >= c->firstPosition() && pos <= c->lastPosition())
return c;
}
return 0;
}
示例11: selectFrame
void MainWindow::selectFrame()
{
QTextCursor cursor = editor->textCursor();
QTextFrame *frame = cursor.currentFrame();
cursor.beginEditBlock();
cursor.setPosition(frame->firstPosition());
cursor.setPosition(frame->lastPosition(), QTextCursor::KeepAnchor);
cursor.endEditBlock();
editor->setTextCursor(cursor);
}
示例12: QMainWindow
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// 获取文档对象
QTextDocument *document = ui->textEdit->document();
// 获取根框架
QTextFrame *rootFrame = document->rootFrame();
// 创建框架格式
QTextFrameFormat format;
// 边界颜色
format.setBorderBrush(Qt::red);
// 边界宽度
format.setBorder(3);
// 框架使用格式
rootFrame->setFrameFormat(format);
QTextFrameFormat frameFormat;
// 设置背景颜色
frameFormat.setBackground(Qt::lightGray);
// 设置边距
frameFormat.setMargin(10);
// 设置填衬
frameFormat.setPadding(5);
frameFormat.setBorder(2);
frameFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Dotted); //设置边框样式
// 获取光标
QTextCursor cursor = ui->textEdit->textCursor();
// 在光标处插入框架
cursor.insertFrame(frameFormat);
//以下是5.2.2节内容
QAction *action_textFrame = new QAction(tr("框架"),this);
connect(action_textFrame,SIGNAL(triggered()),this,SLOT(showTextFrame()));
// 在工具栏添加动作
ui->mainToolBar->addAction(action_textFrame);
QAction *action_textBlock = new QAction(tr("文本块"),this);
connect(action_textBlock,SIGNAL(triggered()),this,SLOT(showTextBlock()));
ui->mainToolBar->addAction(action_textBlock);
QAction *action_font = new QAction(tr("字体"),this);
// 设置动作可以被选中
action_font->setCheckable(true);
connect(action_font,SIGNAL(toggled(bool)),this,SLOT(setTextFont(bool)));
ui->mainToolBar->addAction(action_font);
}
示例13: Q_UNUSED
void QSGTextNode::addTextDocument(const QPointF &position, QTextDocument *textDocument, const QColor &color,
QSGText::TextStyle style, const QColor &styleColor)
{
Q_UNUSED(position)
QTextFrame *textFrame = textDocument->rootFrame();
QPointF p = textDocument->documentLayout()->frameBoundingRect(textFrame).topLeft();
QTextFrame::iterator it = textFrame->begin();
while (!it.atEnd()) {
addTextBlock(p, textDocument, it.currentBlock(), color, style, styleColor);
++it;
}
}
示例14: QTextLength
void KDReports::Frame::build( ReportBuilder& builder ) const
{
// prepare the frame
QTextFrameFormat format;
if ( d->m_width ) {
if ( d->m_widthUnit == Millimeters ) {
format.setWidth( QTextLength( QTextLength::FixedLength, mmToPixels( d->m_width ) ) );
} else {
format.setWidth( QTextLength( QTextLength::PercentageLength, d->m_width ) );
}
}
if ( d->m_height ) {
if ( d->m_heightUnit == Millimeters ) {
format.setHeight( QTextLength( QTextLength::FixedLength, mmToPixels( d->m_height ) ) );
} else {
format.setHeight( QTextLength( QTextLength::PercentageLength, d->m_height ) );
}
}
format.setPadding( mmToPixels( padding() ) );
format.setBorder( d->m_border );
// TODO borderBrush like in AbstractTableElement
format.setPosition( QTextFrameFormat::InFlow );
QTextCursor& textDocCursor = builder.cursor();
QTextFrame *frame = textDocCursor.insertFrame(format);
QTextCursor contentsCursor = frame->firstCursorPosition();
ReportBuilder contentsBuilder( builder.currentDocumentData(),
contentsCursor, builder.report() );
contentsBuilder.copyStateFrom( builder );
foreach( const KDReports::ElementData& ed, d->m_elements )
{
switch ( ed.m_type ) {
case KDReports::ElementData::Inline:
contentsBuilder.addInlineElement( *ed.m_element );
break;
case KDReports::ElementData::Block:
contentsBuilder.addBlockElement( *ed.m_element, ed.m_align );
break;
case KDReports::ElementData::Variable:
contentsBuilder.addVariable( ed.m_variableType );
break;
}
}
textDocCursor.movePosition( QTextCursor::End );
}
示例15: unapplyStyle
void KoSectionStyle::unapplyStyle(QTextFrame §ion) const
{
if (d->parentStyle)
d->parentStyle->unapplyStyle(section);
QTextFrameFormat format = section.frameFormat();
QList<int> keys = d->stylesPrivate.keys();
for (int i = 0; i < keys.count(); i++) {
QVariant variant = d->stylesPrivate.value(keys[i]);
if (variant == format.property(keys[i]))
format.clearProperty(keys[i]);
}
section.setFrameFormat(format);
}