コード例 #1
0
ファイル: chatview_te.cpp プロジェクト: ackbarr/psi
void ChatView::doTrackBar()
{
	// save position, because our manipulations could change it
	int scrollbarValue = verticalScrollBar()->value();

	QTextCursor cursor = textCursor();
	cursor.beginEditBlock();
	PsiRichText::Selection selection = PsiRichText::saveSelection(this, cursor);

	//removeTrackBar(cursor);
	if (oldTrackBarPosition) {
		cursor.setPosition(oldTrackBarPosition, QTextCursor::KeepAnchor);
		QTextBlockFormat blockFormat = cursor.blockFormat();
		blockFormat.clearProperty(QTextFormat::BlockTrailingHorizontalRulerWidth);
		cursor.clearSelection();
		cursor.setBlockFormat(blockFormat);
	}

	//addTrackBar(cursor);
	cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
	oldTrackBarPosition = cursor.position();
	QTextBlockFormat blockFormat = cursor.blockFormat();
	blockFormat.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth, QVariant(true));
	cursor.clearSelection();
	cursor.setBlockFormat(blockFormat);

	PsiRichText::restoreSelection(this, cursor, selection);
	cursor.endEditBlock();
	setTextCursor(cursor);

	verticalScrollBar()->setValue(scrollbarValue);
}
コード例 #2
0
 void flush(void) {
   QTextBlockFormat bf = editor->textCursor().blockFormat();
   bf.setBottomMargin(0);
   editor->textCursor().setBlockFormat(bf);
   editor->append(buffer);
   buffer.clear();        
 }
コード例 #3
0
ファイル: qsplashscreen.cpp プロジェクト: AtlantisCD9/Qt
/*!
    Draw the contents of the splash screen using painter \a painter.
    The default implementation draws the message passed by showMessage().
    Reimplement this function if you want to do your own drawing on
    the splash screen.
*/
void QSplashScreen::drawContents(QPainter *painter)
{
    Q_D(QSplashScreen);
    painter->setPen(d->currColor);
    QRect r = rect().adjusted(5, 5, -5, -5);
    if (Qt::mightBeRichText(d->currStatus)) {
        QTextDocument doc;
#ifdef QT_NO_TEXTHTMLPARSER
        doc.setPlainText(d->currStatus);
#else
        doc.setHtml(d->currStatus);
#endif
        doc.setTextWidth(r.width());
        QTextCursor cursor(&doc);
        cursor.select(QTextCursor::Document);
        QTextBlockFormat fmt;
        fmt.setAlignment(Qt::Alignment(d->currAlign));
        cursor.mergeBlockFormat(fmt);
        painter->save();
        painter->translate(r.topLeft());
        doc.drawContents(painter);
        painter->restore();
    } else {
        painter->drawText(r, d->currAlign, d->currStatus);
    }
}
コード例 #4
0
void KoTextBlockBorderData::setEdge(Side side, const QTextBlockFormat &bf,
                                    KoParagraphStyle::Property style, KoParagraphStyle::Property width,
                                    KoParagraphStyle::Property color, KoParagraphStyle::Property space,
                                    KoParagraphStyle::Property innerWidth)
{

    Edge edge;
    KoBorder::BorderStyle  borderStyle;
    borderStyle = static_cast<KoBorder::BorderStyle>(bf.intProperty(style));
    switch (borderStyle) {
    case KoBorder::BorderDotted: edge.innerPen.setStyle(Qt::DotLine); break;
    case KoBorder::BorderDashed: edge.innerPen.setStyle(Qt::DashLine); break;
    case KoBorder::BorderDashDot: edge.innerPen.setStyle(Qt::DashDotLine); break;
    case KoBorder::BorderDashDotDot: edge.innerPen.setStyle(Qt::DashDotDotLine); break;
    case KoBorder::BorderGroove: /* TODO */ break;
    case KoBorder::BorderRidge: /* TODO */ break;
    case KoBorder::BorderInset: /* TODO */ break;
    case KoBorder::BorderOutset: /* TODO */ break;
    default:
        edge.innerPen.setStyle(Qt::SolidLine);
    }
    edge.innerPen.setColor(bf.colorProperty(color));
    edge.innerPen.setJoinStyle(Qt::MiterJoin);
    edge.innerPen.setCapStyle(Qt::FlatCap);
    edge.outerPen = edge.innerPen;
    edge.outerPen.setWidthF(bf.doubleProperty(width));   // TODO check if this does not need any conversion

    edge.distance = bf.doubleProperty(space);
    edge.innerPen.setWidthF(bf.doubleProperty(innerWidth));

    d->edges[side] = edge;
}
コード例 #5
0
ファイル: texttools.cpp プロジェクト: briff/MuseScore
void TextTools::setRightAlign()
      {
      QTextBlockFormat bformat;
      bformat.setAlignment((bformat.alignment() & ~Qt::AlignHorizontal_Mask) | Qt::AlignRight);
      cursor()->mergeBlockFormat(bformat);
      updateTools();
      }
コード例 #6
0
void NoteEditWidget::resizeEvent(QResizeEvent *)
{
    int screenWidth = width();
    int screenHeight = height();
    if (screenWidth > screenHeight) { // we have a classical landscape monitor
        noteEditHeight = screenHeight - TextEditMargin;
        noteEditWidth = static_cast<int>(noteEditHeight * NoteEditWidthMultiplier);
    } else { // we have monitor standing in portrait
        noteEditWidth = screenWidth - TextEditMargin;
        noteEditHeight = static_cast<int>(noteEditWidth / NoteEditWidthMultiplier);
    }
    noteEditXPos = (screenWidth - noteEditWidth) / 2;
    noteEditYPos = (screenHeight - noteEditHeight) / 2;

    visualCover->setGeometry(0, 0, width(), height());
    textEdit->setGeometry(noteEditXPos, noteEditYPos, noteEditWidth, noteEditHeight);
    textEdit->setFocus();
    textEdit->setFont(getFontForTextEditWith(noteEditWidth));

    for (QTextBlock block = textEdit->document()->begin(); block.isValid(); block = block.next())
    {
        QTextCursor tc = QTextCursor(block);
        QTextBlockFormat fmt = block.blockFormat();
        fmt.setLineHeight(LineHeightPercentage, QTextBlockFormat::ProportionalHeight);
        tc.setBlockFormat(fmt);
    }
}
コード例 #7
0
ファイル: inputwidget.cpp プロジェクト: ageekymonk/quassel
void InputWidget::currentChanged(const QModelIndex &current, const QModelIndex &previous)
{
    BufferId currentBufferId = current.data(NetworkModel::BufferIdRole).value<BufferId>();
    BufferId previousBufferId = previous.data(NetworkModel::BufferIdRole).value<BufferId>();

    if (_perChatHistory) {
        //backup
        historyMap[previousBufferId].history = inputLine()->history();
        historyMap[previousBufferId].tempHistory = inputLine()->tempHistory();
        historyMap[previousBufferId].idx = inputLine()->idx();
        historyMap[previousBufferId].inputLine = inputLine()->html();

        //restore
        inputLine()->setHistory(historyMap[currentBufferId].history);
        inputLine()->setTempHistory(historyMap[currentBufferId].tempHistory);
        inputLine()->setIdx(historyMap[currentBufferId].idx);
        inputLine()->setHtml(historyMap[currentBufferId].inputLine);
        inputLine()->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor);

        // FIXME this really should be in MultiLineEdit (and the const int on top removed)
        QTextBlockFormat format = inputLine()->textCursor().blockFormat();
        format.setLeftMargin(leftMargin); // we want a little space between the frame and the contents
        inputLine()->textCursor().setBlockFormat(format);
    }

    NetworkId networkId = current.data(NetworkModel::NetworkIdRole).value<NetworkId>();
    if (networkId == _networkId)
        return;

    setNetwork(networkId);
    updateNickSelector();
    updateEnabledState();
}
コード例 #8
0
void NumberedTextView::textChanged( int pos, int removed, int added )
{
    Q_UNUSED( pos );

    if ( removed == 0 && added == 0 )
	return;

    QTextBlock block = highlight.block();
    QTextBlockFormat fmt = block.blockFormat();
    QColor bg = view->palette().base().color();
    fmt.setBackground( bg );
    highlight.setBlockFormat( fmt );

    int lineCount = 1;
    for ( QTextBlock block = view->document()->begin();
	  block.isValid(); block = block.next(), ++lineCount ) 
    {
        if ( lineCount == markedLine )
        {
            fmt = block.blockFormat();
            QColor bg = Qt::red;
            fmt.setBackground( bg.light(150) );

            highlight = QTextCursor( block );
            highlight.movePosition( QTextCursor::EndOfBlock, QTextCursor::KeepAnchor );
            highlight.setBlockFormat( fmt );

            break;
        }
    }
}
コード例 #9
0
ファイル: text.cpp プロジェクト: SSMN/MuseScore
void Text::setText(const QString& s)
      {
#if 0
      Align align = style().align();
//      _doc->clear();
      Font font(style().font(spatium()));
//      _doc->setDefaultFont(font);

      QTextCursor cursor(_doc);
      cursor.setVisualNavigation(true);
      cursor.movePosition(QTextCursor::Start);
      Qt::Alignment a;
      if (align & ALIGN_HCENTER)
            a = Qt::AlignHCenter;
      else if (align & ALIGN_RIGHT)
            a = Qt::AlignRight;
      else
            a = Qt::AlignLeft;
      QTextBlockFormat bf = cursor.blockFormat();
      bf.setAlignment(a);
      cursor.setBlockFormat(bf);

      QTextCharFormat tf = cursor.charFormat();
//      tf.setFont(font);
      cursor.setBlockCharFormat(tf);
      cursor.insertText(s);
#endif
      }
コード例 #10
0
ファイル: tst_qtextformat.cpp プロジェクト: CodeDJ/qt5-hidpi
void tst_QTextFormat::testTabsUsed()
{
    QTextDocument doc;
    QTextCursor cursor(&doc);

    QList<QTextOption::Tab> tabs;
    QTextBlockFormat format;
    QTextOption::Tab tab;
    tab.position = 100;
    tabs.append(tab);
    format.setTabPositions(tabs);
    cursor.mergeBlockFormat(format);
    cursor.insertText("foo\tbar");
    //doc.setPageSize(QSizeF(200, 200));
    doc.documentLayout()->pageCount(); // force layout;

    QTextBlock block = doc.begin();
    QTextLayout *layout = block.layout();
    QVERIFY(layout);
    QCOMPARE(layout->lineCount(), 1);
    QTextLine line = layout->lineAt(0);
    QCOMPARE(line.cursorToX(4), 100.);

    QTextOption option = layout->textOption();
    QCOMPARE(option.tabs().count(), tabs.count());

}
コード例 #11
0
void MenuMainScreen::setCurrentOption(QGraphicsSimpleTextItem *option) {
	QBrush whiteBrush(Qt::white);
	QBrush yellowBrush(Qt::yellow);

	if (!!_currentOption)
		_currentOption->setBrush(whiteBrush);

	_currentOption = option;
	_currentOption->setBrush(yellowBrush);

	if (option->text() == QString("Character"))
		_textField->setPlainText("View more information about the selected character.");
	else if (option->text() == QString("Equipment"))
		_textField->setPlainText("View or change the equipment the selected character is wearing.");
	else if (option->text() == QString("Abilities"))
		_textField->setPlainText("View the abilities of the selected character.");
	else if (option->text() == QString("Inventory"))
		_textField->setPlainText("View the items collected by the party.");
	else if (option->text() == QString("Exit"))
		_textField->setPlainText("Exit the menu.");

	QFont font("Times", 12, QFont::Bold);
	_textField->setFont(font);

	QTextBlockFormat format;
	format.setAlignment(Qt::AlignLeft);
	QTextCursor cursor = _textField->textCursor();
	cursor.select(QTextCursor::Document);
	cursor.mergeBlockFormat(format);
	cursor.clearSelection();
	_textField->setTextCursor(cursor);
}
コード例 #12
0
ファイル: tst_qtextformat.cpp プロジェクト: CodeDJ/qt5-hidpi
void tst_QTextFormat::defaultAlignment()
{
    QTextBlockFormat fmt;
    QVERIFY(!fmt.hasProperty(QTextFormat::BlockAlignment));
    QCOMPARE(fmt.intProperty(QTextFormat::BlockAlignment), 0);
    QVERIFY(fmt.alignment() == Qt::AlignLeft);
}
コード例 #13
0
ファイル: KoTosContainer.cpp プロジェクト: AninaRJ/krita
void KoTosContainer::setTextAlignment(Qt::Alignment alignment)
{
    Q_D(KoTosContainer);

    KoShape *textShape = this->textShape();
    if (textShape == 0) {
        warnFlake << "No text shape present in KoTosContainer";
        return;
    }

    // vertical
    KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(textShape->userData());
    shapeData->setVerticalAlignment(alignment);

    // horizontal
    Q_ASSERT(shapeData->document());
    QTextBlockFormat bf;
    bf.setAlignment(alignment & Qt::AlignHorizontal_Mask);

    QTextCursor cursor(shapeData->document());
    cursor.setPosition(QTextCursor::End, QTextCursor::KeepAnchor);
    cursor.mergeBlockFormat(bf);

    d->alignment = alignment;
}
コード例 #14
0
//段落标号、编号
void MyChild::setStyle(int style)
{
    QTextCursor cursor = this->textCursor();

    if (style != 0) {
        QTextListFormat::Style stylename = QTextListFormat::ListDisc;

        switch (style) {
            default:
            case 1:
                stylename = QTextListFormat::ListDisc;
                break;
            case 2:
                stylename = QTextListFormat::ListCircle;
                break;
            case 3:
                stylename = QTextListFormat::ListSquare;
                break;
            case 4:
                stylename = QTextListFormat::ListDecimal;
                break;
            case 5:
                stylename = QTextListFormat::ListLowerAlpha;
                break;
            case 6:
                stylename = QTextListFormat::ListUpperAlpha;
                break;
            case 7:
                stylename = QTextListFormat::ListLowerRoman;
                break;
            case 8:
                stylename = QTextListFormat::ListUpperRoman;
                break;
        }

        cursor.beginEditBlock();

        QTextBlockFormat blockFmt = cursor.blockFormat();

        QTextListFormat listFmt;

        if (cursor.currentList()) {
            listFmt = cursor.currentList()->format();
        } else {
            listFmt.setIndent(blockFmt.indent() + 1);
            blockFmt.setIndent(0);
            cursor.setBlockFormat(blockFmt);
        }

        listFmt.setStyle(stylename);

        cursor.createList(listFmt);

        cursor.endEditBlock();
    } else {
        QTextBlockFormat bfmt;
        bfmt.setObjectIndex(-1);
        cursor.mergeBlockFormat(bfmt);
    }
}
コード例 #15
0
ファイル: mainwindow.cpp プロジェクト: Rookiee/Qt_Codes
// 设置字体格式
void MainWindow::setTextFont(bool checked)
{
    // 如果处于选中状态
    if(checked){
        QTextCursor cursor = ui->textEdit->textCursor();

        // 文本块格式
        QTextBlockFormat blockFormat;
        // 水平居中
        blockFormat.setAlignment(Qt::AlignCenter);
        // 使用文本块格式
        cursor.insertBlock(blockFormat);

        // 字符格式
        QTextCharFormat charFormat;
        // 背景色
        charFormat.setBackground(Qt::lightGray);
        // 字体颜色
        charFormat.setForeground(Qt::blue);
        // 使用宋体,12号,加粗,倾斜
        charFormat.setFont(QFont(tr("宋体"),12,QFont::Bold,true));

        // 使用下划线
        charFormat.setFontUnderline(true);
        // 使用字符格式
        cursor.setCharFormat(charFormat);
        // 插入文本
        cursor.insertText(tr("测试字体"));
    }
    // 如果处于非选中状态,可以进行其他操作
    else{/*恢复默认的字体格式*/}
}
コード例 #16
0
void AnnotationSettings::updateStyleButtons()
{
	QTextBlockFormat bf = _ui->content->textCursor().blockFormat();
	switch(bf.alignment()) {
	case Qt::AlignLeft: _ui->left->setChecked(true); break;
	case Qt::AlignCenter: _ui->center->setChecked(true); break;
	case Qt::AlignJustify: _ui->justify->setChecked(true); break;
	case Qt::AlignRight: _ui->right->setChecked(true); break;
	default: break;
	}
	QTextCharFormat cf = _ui->content->textCursor().charFormat();
	_ui->btnTextColor->setColor(cf.foreground().color());

	_ui->size->blockSignals(true);
	if(cf.fontPointSize() < 1)
		_ui->size->setValue(12);
	else
		_ui->size->setValue(cf.fontPointSize());
	_ui->size->blockSignals(false);

	_ui->font->blockSignals(true);
	_ui->font->setCurrentFont(cf.font());
	_ui->font->blockSignals(false);

	_ui->italic->setChecked(cf.fontItalic());
	_ui->bold->setChecked(cf.fontWeight() > QFont::Normal);
	_ui->underline->setChecked(cf.fontUnderline());
	_ui->strikethrough->setChecked(cf.font().strikeOut());
}
コード例 #17
0
/*! 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;
}
コード例 #18
0
ファイル: KStyleManager.cpp プロジェクト: KDE/koffice
void KStyleManagerPrivate::refreshUnsetStoreFor(int key)
{
    QMap<int, QVariant> keys;
    KParagraphStyle *parag = paragStyles.value(key);
    if (parag) {
        QTextBlockFormat bf;
        parag->applyStyle(bf);
        keys = bf.properties();
    } else {
        KCharacterStyle *charStyle = charStyles.value(key);
        if (charStyle) {
            QTextCharFormat cf;
            charStyle->applyStyle(cf);
            // find all relevant char styles downwards (to root).
	    for (QHash<int, KParagraphStyle*>::const_iterator it = paragStyles.constBegin(); it != paragStyles.constEnd(); ++it) {
                KParagraphStyle *ps = it.value();
                if (ps->characterStyle() == charStyle) { // he uses us, lets apply all parents too
                    KParagraphStyle *parent = ps->parentStyle();
                    while (parent) {
                        parent->characterStyle()->applyStyle(cf);
                        parent = parent->parentStyle();
                    }
                }
            }
            keys = cf.properties();
        }
    }
    unsetStore.insert(key, keys);
}
コード例 #19
0
void GraphicTextDialog::textStyle(int styleIndex)
{
    QTextCursor cursor = textEdit->textCursor();

    if(styleIndex != 0) {
        QTextListFormat::Style style = QTextListFormat::ListDisc;

        switch (styleIndex) {
            default:
            case 1:
                style = QTextListFormat::ListDisc;
                break;

            case 2:
                style = QTextListFormat::ListCircle;
                break;

            case 3:
                style = QTextListFormat::ListSquare;
                break;

            case 4:
                style = QTextListFormat::ListDecimal;
                break;

            case 5:
                style = QTextListFormat::ListLowerAlpha;
                break;

            case 6:
                style = QTextListFormat::ListUpperAlpha;
                break;
        }

        cursor.beginEditBlock();

        QTextBlockFormat blockFmt = cursor.blockFormat();

        QTextListFormat listFmt;

        if(cursor.currentList()) {
            listFmt = cursor.currentList()->format();
        } else {
            listFmt.setIndent(blockFmt.indent() + 1);
            blockFmt.setIndent(0);
            cursor.setBlockFormat(blockFmt);
        }

        listFmt.setStyle(style);

        cursor.createList(listFmt);

        cursor.endEditBlock();
    } else {
        // ####
        QTextBlockFormat bfmt;
        bfmt.setObjectIndex(-1);
        cursor.mergeBlockFormat(bfmt);
    }
}
コード例 #20
0
ファイル: text.cpp プロジェクト: briff/MuseScore
void Text::startEdit(MuseScoreView*, const QPointF& p)
      {
      _editMode = true;
      if (styled()) {
            createDoc();
            setUnstyledText(SimpleText::getText());
            layout();
            }
      _cursor = new QTextCursor(_doc);
      _cursor->setVisualNavigation(true);
      setCursor(p);

      if (_cursor->position() == 0 && align()) {
            QTextBlockFormat bf = _cursor->blockFormat();
            Qt::Alignment alignment = 0;
            if (align() & ALIGN_HCENTER)
                  alignment |= Qt::AlignHCenter;
            else if (align() & ALIGN_LEFT)
                  alignment |= Qt::AlignLeft;
            else if (align() & ALIGN_RIGHT)
                  alignment |= Qt::AlignRight;
            bf.setAlignment(alignment);
            setBlockFormat(bf);
            }
      qreal w = 2.0; // 8.0 / view->matrix().m11();
      score()->rebuildBspTree();
      score()->addRefresh(canvasBoundingRect().adjusted(-w, -w, w, w));
      }
コード例 #21
0
ファイル: gpx_block.cpp プロジェクト: lucciano/powerdevs
void GpxBlock::updateTextPosition()
{
	QPointF pos;
  	//_name_item.setTextWidth(_name_item.boundingRect().width());
    QTextCursor cursor = _name_item.textCursor();
  	QTextBlockFormat bfmt = cursor.blockFormat();
 	bfmt.setAlignment(Qt::AlignCenter);
  	cursor.setBlockFormat(bfmt);
  	_name_item.setTextCursor(cursor); 
  	_name_item.setTextWidth(_width+20);

  switch (direction())
  {
    case Graphic::RIGHT:
      pos.setX(-(_name_item.boundingRect().width()/2));
      pos.setY(_height / 2 + 3);
      break;
    case Graphic::LEFT:
      pos.setX((_name_item.boundingRect().width() / 2));
      pos.setY(-_height / 2 - 3);
      break;
    case Graphic::DOWN:
      pos.setY((_name_item.boundingRect().width() / 2));
      pos.setX(_width/ 2 + 3);
      break;
    case Graphic::UP:
      pos.setY(-(_name_item.boundingRect().width() / 2));
      pos.setX(-_width / 2 - 3);
      break;
  }
	_name_item.setPos(pos);
}
コード例 #22
0
ファイル: text.cpp プロジェクト: briff/MuseScore
void Text::setUnstyledText(const QString& s)
      {
      Align align = textStyle().align();
      _doc->clear();

      QTextCursor c(_doc);
      c.setVisualNavigation(true);
      c.movePosition(QTextCursor::Start);
      Qt::Alignment a;
      if (align & ALIGN_HCENTER)
            a = Qt::AlignHCenter;
      else if (align & ALIGN_RIGHT)
            a = Qt::AlignRight;
      else
            a = Qt::AlignLeft;
      QTextBlockFormat bf = c.blockFormat();
      bf.setAlignment(a);
      c.setBlockFormat(bf);

      QTextCharFormat tf = c.charFormat();
      tf.setFont(textStyle().font(spatium()));
      c.setBlockCharFormat(tf);
      c.insertText(s);
      textChanged();
      }
コード例 #23
0
ファイル: texttools.cpp プロジェクト: briff/MuseScore
void TextTools::indentLessClicked()
      {
      QTextList* list = cursor()->currentList();
      if (list == 0) {
            QTextBlockFormat format = cursor()->blockFormat();
            int indent = format.indent();
            if (indent) {
                  indent--;
                  format.setIndent(indent);
                  cursor()->insertBlock(format);
                  updateText();
                  }
            return;
            }
      QTextCharFormat format = cursor()->blockCharFormat();
      QTextListFormat listFormat = list->format();
      QTextBlock block = cursor()->block();
      if (block.next().isValid())
            block = block.next();
      else {
            block = QTextBlock();
            }
      cursor()->insertBlock(block.blockFormat());
      cursor()->setCharFormat(block.charFormat());
      updateText();
      }
コード例 #24
0
ファイル: textroom.cpp プロジェクト: AlanLZY/textroom
void TextRoom::alignCenter()
{
    QTextBlockFormat fmt;
    QTextCursor tc = textEdit->textCursor();
    fmt.setAlignment(Qt::AlignHCenter);
    tc.mergeBlockFormat(fmt);
}
コード例 #25
0
/*!
    Removes the given \a block from the list.

    \sa add(), removeItem()
*/
void QTextList::remove(const QTextBlock &block)
{
    QTextBlockFormat fmt = block.blockFormat();
    fmt.setIndent(fmt.indent() + format().indent());
    fmt.setObjectIndex(-1);
    block.docHandle()->setBlockFormat(block, block, fmt, QTextDocumentPrivate::SetFormat);
}
コード例 #26
0
ファイル: mainwindow.cpp プロジェクト: BennyH26/phantomjs
void MainWindow::highlightListItems()
{
    QTextCursor cursor = editor->textCursor();
    QTextList *list = cursor.currentList();

    if (!list)
        return;

    cursor.beginEditBlock();
//! [0]
    for (int index = 0; index < list->count(); ++index) {
        QTextBlock listItem = list->item(index);
//! [0]
        QTextBlockFormat newBlockFormat = listItem.blockFormat();
        newBlockFormat.setBackground(Qt::lightGray);
        QTextCursor itemCursor = cursor;
        itemCursor.setPosition(listItem.position());
        //itemCursor.movePosition(QTextCursor::StartOfBlock);
        itemCursor.movePosition(QTextCursor::EndOfBlock,
                                QTextCursor::KeepAnchor);
        itemCursor.setBlockFormat(newBlockFormat);
        /*
        //! [1]
        processListItem(listItem);
        //! [1]
        */
//! [2]
    }
//! [2]
    cursor.endEditBlock();
}
コード例 #27
0
void TextContentsModelImpl::documentLayoutFinished()
{
    QTextBlock block = d->textDocument->firstBlock();
    d->entries.clear();

    while (block.isValid())
    {
        QTextBlockFormat format = block.blockFormat();
        if (format.hasProperty(KoParagraphStyle::OutlineLevel))
        {
            ContentsEntry entry;
            entry.title = block.text();
            entry.level = format.intProperty(KoParagraphStyle::OutlineLevel);

            auto rootArea = d->layout->rootAreaForPosition(block.position());
            if (rootArea) {
                if (rootArea->page()) {
                    entry.pageNumber = rootArea->page()->visiblePageNumber();
                    entry.page = static_cast<KWPage*>(rootArea->page());
                }
            }

            d->entries.append(entry);
        }
        block = block.next();
    }

    emit listContentsCompleted();
}
コード例 #28
0
ファイル: mrichtextedit.cpp プロジェクト: Iownnoname/qt
void MRichTextEdit::list(bool checked, QTextListFormat::Style style)
{
    QTextCursor cursor = f_textedit->textCursor();
    cursor.beginEditBlock();

    if (!checked)
    {
        QTextBlockFormat obfmt = cursor.blockFormat();
        QTextBlockFormat bfmt;
        bfmt.setIndent(obfmt.indent());
        cursor.setBlockFormat(bfmt);
    }
    else
    {
        QTextListFormat listFmt;

        if (cursor.currentList())
        {
            listFmt = cursor.currentList()->format();
        }
        listFmt.setStyle(style);
        cursor.createList(listFmt);
    }

    cursor.endEditBlock();
}
コード例 #29
0
ファイル: pqtexteditor.cpp プロジェクト: danvratil/presquile
void PQTextEditor::slotUnindent()
{
    QTextBlockFormat format = mEditor->textCursor().blockFormat();
    if (format.indent() > 0) {
        format.setIndent(format.indent() - 1);
    }
}
コード例 #30
0
ファイル: textoutput.cpp プロジェクト: akiernan/gecode
void
TextOutputI::insertHtml(const QString& s) {
    QTextBlockFormat bf = editor->textCursor().blockFormat();
    bf.setBottomMargin(0);
    editor->textCursor().setBlockFormat(bf);
    editor->insertHtml(s);
    editor->ensureCursorVisible();
}