Example #1
0
void MainWindow::decreaseIndent()
{
	QTextBlockFormat blockFmt = ui->textNote->textCursor().blockFormat();
	QTextCursor cursor = ui->textNote->textCursor();

	if(blockFmt.indent() > 0)
		blockFmt.setIndent(blockFmt.indent()-1);
	else
		blockFmt.setIndent(0);
	cursor.setBlockFormat(blockFmt);
}
Example #2
0
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();
      }
Example #3
0
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();
}
void KNoteEdit::textList()
{
    QTextCursor c = textCursor();
    c.beginEditBlock();

    if ( m_textList->isChecked() ) {
        QTextListFormat lf;
        QTextBlockFormat bf = c.blockFormat();

        lf.setIndent( bf.indent() + 1 );
        bf.setIndent( 0 );

        lf.setStyle( QTextListFormat::ListDisc );

        c.setBlockFormat( bf );
        c.createList( lf );
    } else {
        QTextBlockFormat bf;
        bf.setObjectIndex( -1 );
        c.setBlockFormat( bf );

    }

    c.endEditBlock();
}
//段落标号、编号
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);
    }
}
Example #6
0
void PQTextEditor::slotUnindent()
{
    QTextBlockFormat format = mEditor->textCursor().blockFormat();
    if (format.indent() > 0) {
        format.setIndent(format.indent() - 1);
    }
}
/*!
    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);
}
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);
    }
}
Example #9
0
void MainWindow::increaseIndent()
{
	QTextBlockFormat blockFmt = ui->textNote->textCursor().blockFormat();
	QTextCursor cursor = ui->textNote->textCursor();

	blockFmt.setIndent(blockFmt.indent()+1);
	cursor.setBlockFormat(blockFmt);
}
Example #10
0
void Stack::increaseIndent()
{
	m_current_document->setRichText(true);
	QTextCursor cursor = m_current_document->text()->textCursor();
	QTextBlockFormat format = cursor.blockFormat();
	format.setIndent(format.indent() + 1);
	cursor.setBlockFormat(format);
	emit updateFormatActions();
}
void KNoteEdit::textDecreaseIndent()
{
  QTextBlockFormat f = textCursor().blockFormat();
  short int curIndent = f.indent();

  if ( curIndent > 0 ) {
    f.setIndent( curIndent - 1 );
  }
  textCursor().setBlockFormat( f );
}
Example #12
0
void MainWindow::toggleList(QTextListFormat::Style style)
{
	QTextCursor cursor = ui->textNote->textCursor();
	QTextBlockFormat blockFmt = cursor.blockFormat();
	QTextListFormat listFmt;

	bool list = (cursor.currentList() != 0);

	// change style if list exists and is a different style
	if(list && cursor.currentList()->format().style() != style)
	{
		listFmt.setStyle(style);
		cursor.currentList()->setFormat(listFmt);
	}
	// remove list if exists and matches style
	else if(list&& cursor.currentList()->format().style() == style)
	{
		cursor.currentList()->removeItem(0);
		blockFmt = ui->textNote->textCursor().blockFormat();
		cursor = ui->textNote->textCursor();
		blockFmt.setIndent(0);
		cursor.setBlockFormat(blockFmt);
	// create list if not exists
	}
	else
	{
		cursor.beginEditBlock();
		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();
	}
	updateMenus();
}
Example #13
0
void TextTools::indentMoreClicked()
      {
      QTextList* list = cursor()->currentList();
      if (list == 0) {
            QTextBlockFormat format = cursor()->blockFormat();
            format.setIndent(format.indent() + 1);
            cursor()->insertBlock(format);
            updateText();
            return;
            }
      unorderedListClicked();
      }
Example #14
0
void MRichTextEdit::indent(int delta)
{
    QTextCursor cursor = f_textedit->textCursor();
    cursor.beginEditBlock();
    QTextBlockFormat bfmt = cursor.blockFormat();
    int ind = bfmt.indent();

    if (ind + delta >= 0)
    {
        bfmt.setIndent(ind + delta);
    }

    cursor.setBlockFormat(bfmt);
    cursor.endEditBlock();
}
void TextEditWidget::sl_ListButton_Toggled(bool toggle) {
	QTextCursor cursor = this->textField->textCursor();
	if (toggle) {
		if (cursor.currentList()) {
			WARNING("Wrong button state");
			return;
		}
		QTextListFormat format;
		format.setStyle(QTextListFormat::ListDisc);
		cursor.createList(format);
	} else {
		QTextList *textList = cursor.currentList();
		if (!cursor.currentList()) {
			WARNING("Wrong button state");
			return;
		}
		QTextBlock block = cursor.block();
		textList->remove(block);
		QTextBlockFormat format = block.blockFormat();
		format.setIndent(0);
		cursor.setBlockFormat(format);
	}
}
Example #16
0
void Format::parseFrame( QTextCursor &cursor, const QDomElement &element )
{
  QTextBlock extraBlock;
  bool hasExtraBlock = false;

  QDomNode n;
  for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
    QDomElement e = n.toElement();
    if ( e.tagName() == "block" ) {
      if ( e.hasAttribute( "liststyle" ) ) {
        cursor.setCharFormat( TextFormats::normalCharFormat() );
        QTextListFormat f;
        f.setIndent( e.attribute( "listindent" ).toInt() );
        if ( e.attribute( "liststyle" ) == "decimal" ) {
          f.setStyle( QTextListFormat::ListDecimal );
        } else {
          f.setStyle( QTextListFormat::ListDisc );
        }
        cursor.mergeBlockFormat( TextFormats::normalBlockFormat() );
        cursor.insertList( f );
      } else if ( n != element.firstChild() ) {
        QTextBlockFormat f;
        if ( e.hasAttribute( "blockindent" ) ) {
          f.setIndent( e.attribute( "blockindent" ).toInt() );
        } else {
          f.setIndent( 0 );
        }
        if ( hasExtraBlock ) {
          QTextCursor c( extraBlock );
          c.setBlockFormat( f );
          hasExtraBlock = false;
        } else {
          cursor.insertBlock( f );
        }
      }
      if ( e.hasAttribute( "lastmodified" ) ) {
        QString str = e.attribute( "lastmodified" );
        QDateTime dt = QDateTime::fromString( str, Qt::ISODate );
        TextFormats::setLastModified( cursor, dt );
      }
      parseBlock( cursor, e );

      if ( e.hasAttribute( "titlestyle" ) ) {
        if ( e.attribute( "titlestyle" ) == "title" ) {
          cursor.mergeBlockFormat( TextFormats::titleBlockFormat() );
        } else if ( e.attribute( "titlestyle" ) == "subtitle" ) {
          cursor.mergeBlockFormat( TextFormats::subTitleBlockFormat() );
        }
      } else {
        cursor.mergeBlockFormat( TextFormats::normalBlockFormat() );
      }
    } else if ( e.tagName() == "frame" ) {
      QTextFrame *parentFrame = cursor.currentFrame();

      QTextFrame *frame = cursor.insertFrame( TextFormats::codeFrameFormat() );
      parseFrame( cursor, e );
      if ( e.attribute( "type" ) == "code" ) {
        TextFormats::setCodeFrameFormats( frame );
      }

      cursor = parentFrame->lastCursorPosition();
      extraBlock = cursor.block();
      hasExtraBlock = true;
    }
  }
}
Example #17
0
void PQTextEditor::slotIndent()
{
    QTextBlockFormat format = mEditor->textCursor().blockFormat();
    format.setIndent(format.indent() + 1);
}
void KNoteEdit::textIncreaseIndent()
{
  QTextBlockFormat f = textCursor().blockFormat();
  f.setIndent( f.indent() + 1 );
  textCursor().setBlockFormat( f );
}
ScriptFormatter::ScriptFormatter( QQmlEngine* newEngine, QObject *parent ) : QObject(parent) {
	QFont baseFont; //The base from which all other fonts are derived
	baseFont.setBold( false );
	baseFont.setCapitalization( QFont::MixedCase );
	baseFont.setFamily( "Courier" );
	baseFont.setItalic( false );
	baseFont.setPointSize( 12 );
	baseFont.setStyleHint( QFont::Courier );
	
	QTextBlockFormat baseFormat;
	baseFormat.setAlignment( Qt::AlignLeft );
	baseFormat.setIndent( 0 );
	baseFormat.setLineHeight( 1, QTextBlockFormat::SingleHeight ); //The first argument should be ignored according to the documentation, since we're setting the LineHeightType (2nd argument) to single height
	baseFormat.setNonBreakableLines( false );
	//baseFormat.setPageBreakPolicy( QTextFormat::PageBreak_Auto );
	baseFormat.setTextIndent( 0 );
	baseFormat.setTopMargin( 0 );
	baseFormat.setBottomMargin( 0 );
	baseFormat.setLeftMargin( 0 );
	baseFormat.setRightMargin( 0 );
	baseFormat.setNonBreakableLines( false );
	
	//Scenes are left-aligned, bold, and all caps
	sceneFont = QFont( baseFont );
	sceneFont.setBold( true );
	sceneFont.setCapitalization( QFont::AllUppercase );
	sceneBlockFormat = QTextBlockFormat( baseFormat );
	sceneBlockFormat.setAlignment( Qt::AlignLeft );
	//sceneBlockFormat.setPageBreakPolicy( QTextFormat::PageBreak_AlwaysBefore );
	
	//Actions are left-aligned
	actionFont = QFont( baseFont );
	actionBlockFormat = QTextBlockFormat( baseFormat );
	actionBlockFormat.setAlignment( Qt::AlignLeft );
	
	//Character names are centered and all caps
	characterFont = QFont( baseFont );
	characterFont.setCapitalization( QFont::AllUppercase );
	characterBlockFormat = QTextBlockFormat( baseFormat );
	characterBlockFormat.setAlignment( Qt::AlignHCenter );
	//characterBlockFormat.setPageBreakPolicy( QTextFormat::PageBreak_AlwaysBefore );
	
	//Dialog is centered
	dialogFont = QFont( baseFont );
	dialogBlockFormat = QTextBlockFormat( baseFormat );
	dialogBlockFormat.setAlignment( Qt::AlignHCenter );
	//dialogBlockFormat.setPageBreakPolicy( QTextFormat::PageBreak_AlwaysAfter );
	
	//Parentheticals are centered and italicized
	parentheticalFont = QFont( baseFont );
	parentheticalFont.setItalic( true );
	parentheticalBlockFormat = QTextBlockFormat( baseFormat );
	parentheticalBlockFormat.setAlignment( Qt::AlignHCenter );
	
	//Transitions are right-aligned and all caps
	transitionFont = QFont( baseFont );
	transitionFont.setCapitalization( QFont::AllUppercase );
	transitionBlockFormat = QTextBlockFormat( baseFormat );
	transitionBlockFormat.setAlignment( Qt::AlignRight );
	
	//Shots are left-aligned and all caps
	shotFont = QFont( baseFont );
	shotFont.setCapitalization( QFont::AllUppercase );
	shotBlockFormat = QTextBlockFormat( baseFormat );
	shotBlockFormat.setAlignment( Qt::AlignLeft );
	
	//Act breaks are centered, bold, and underlined
	actBreakFont = QFont( baseFont );
	actBreakFont.setBold( true );
	actBreakFont.setUnderline( true );
	actBreakBlockFormat = QTextBlockFormat( baseFormat );
	actBreakBlockFormat.setAlignment( Qt::AlignHCenter );
	
}
Example #20
0
void QGithubMarkdown::read(const QByteArray &markdown, QTextDocument *target)
{
	doc = target;
	doc->clear();
	cursor = QTextCursor(doc);
	cursor.beginEditBlock();
	const QList<Token> tokens = tokenize(clean(QString::fromUtf8(markdown)));
	const QList<Paragraph> paragraphs = paragraphize(tokens);
	const auto paralists = listize(paragraphs);
	//std::for_each(paragraphs.begin(), paragraphs.end(), [](const Paragraph &item){qDebug() << item;});
	bool firstBlock = true;
	for (const auto paralist : paralists)
	{
		auto insertTokens = [&](const QList<Token> &tokens, const QTextCharFormat &format, const bool isCode)
		{
			QTextCharFormat fmt(format);
			QTextCharFormat codeFmt(format);
			codeFmt.setFontFamily("Monospace");
			QListIterator<Token> iterator(tokens);
			while (iterator.hasNext())
			{
				const Token token = iterator.next();
				if (isCode)
				{
					cursor.insertText(token.source);
				}
				else
				{
					if (token.type == Token::Bold)
					{
						if (fmt.fontWeight() == QFont::Bold)
						{
							fmt.setFontWeight(QFont::Normal);
						}
						else
						{
							fmt.setFontWeight(QFont::Bold);
						}
					}
					else if (token.type == Token::Italic)
					{
						fmt.setFontItalic(!fmt.fontItalic());
					}
					else if (token.type == Token::InlineCodeDelimiter)
					{
						while (iterator.hasNext())
						{
							const Token next = iterator.next();
							if (next.type == Token::InlineCodeDelimiter)
							{
								break;
							}
							else
							{
								cursor.insertText(token.source, codeFmt);
							}
						}
					}
					else if (token.type == Token::Character)
					{
						cursor.insertText(token.content.toChar(), fmt);
					}
					else
					{
						cursor.insertText(token.source, fmt);
					}
				}
			}
		};

		if (paralist.second.indent == -1)
		{
			const Paragraph paragraph = paralist.first;
			QTextCharFormat charFmt;
			QTextBlockFormat blockFmt;
			blockFmt.setBottomMargin(5.0f);
			if (Paragraph::FirstHeading <= paragraph.type && paragraph.type <= Paragraph::LastHeading)
			{
				charFmt.setFontPointSize(sizeMap[paragraph.type]);
			}
			else if (paragraph.type == Paragraph::Quote)
			{
				blockFmt.setIndent(1);
			}
			else if (paragraph.type == Paragraph::Code)
			{
				blockFmt.setNonBreakableLines(true);
				charFmt.setFontFamily("Monospace");
			}

			if (!firstBlock)
			{
				cursor.insertBlock();
			}
			else
			{
				firstBlock = false;
			}
			cursor.setBlockFormat(blockFmt);
			cursor.block().setUserState(paragraph.type);
			insertTokens(paragraph.tokens, charFmt, paragraph.type == Paragraph::Code);
		}
		else
		{
			const List list = paralist.second;
			qDebug() << "##########################" << list.indent << list.ordered;
			std::for_each(list.paragraphs.begin(), list.paragraphs.end(), [](const Paragraph &item){qDebug() << item;});
			cursor.setBlockFormat(QTextBlockFormat());
			cursor.setBlockCharFormat(QTextCharFormat());
			QTextListFormat listFormat;
			listFormat.setStyle(list.ordered ? QTextListFormat::ListDecimal : QTextListFormat::ListDisc);
			listFormat.setIndent(list.indent);
			QTextList *l = cursor.insertList(listFormat);
			qDebug() << "inserting list" << list.indent;
			bool firstBlock = true;
			for (const Paragraph &paragraph : list.paragraphs)
			{
				if (firstBlock)
				{
					firstBlock = false;
				}
				else
				{
					cursor.insertBlock();
					qDebug() << "inserting block";
				}
				insertTokens(paragraph.tokens, QTextCharFormat(), false);
				qDebug() << l->count();
				l->add(cursor.block());
				qDebug() << l->count();
				qDebug() << "inserting characters";
			}
		}
	}
	cursor.endEditBlock();
	qDebug() << doc->toHtml();
}
void QTextHtmlImporter::import()
{
    cursor.beginEditBlock();
    hasBlock = true;
    forceBlockMerging = false;
    compressNextWhitespace = !textEditMode;
    blockTagClosed = false;
    for (currentNodeIdx = 0; currentNodeIdx < count(); ++currentNodeIdx) {
        currentNode = &at(currentNodeIdx);
        wsm = textEditMode ? QTextHtmlParserNode::WhiteSpacePreWrap : currentNode->wsm;

        /*
         * process each node in three stages:
         * 1) check if the hierarchy changed and we therefore passed the
         *    equivalent of a closing tag -> we may need to finish off
         *    some structures like tables
         *
         * 2) check if the current node is a special node like a
         *    <table>, <ul> or <img> tag that requires special processing
         *
         * 3) if the node should result in a QTextBlock create one and
         *    finally insert text that may be attached to the node
         */

        /* emit 'closing' table blocks or adjust current indent level
         * if we
         *  1) are beyond the first node
         *  2) the current node not being a child of the previous node
         *      means there was a tag closing in the input html
         */
        if (currentNodeIdx > 0 && (currentNode->parent != currentNodeIdx - 1)) {
            blockTagClosed = closeTag();
            // visually collapse subsequent block tags, but if the element after the closed block tag
            // is for example an inline element (!isBlock) we have to make sure we start a new paragraph by setting
            // hasBlock to false.
            if (blockTagClosed
                && !currentNode->isBlock()
                && currentNode->id != Html_unknown)
                hasBlock = false;
        }

        if (currentNode->displayMode == QTextHtmlElement::DisplayNone) {
            if (currentNode->id == Html_title)
                doc->setMetaInformation(QTextDocument::DocumentTitle, currentNode->text);
            // ignore explicitly 'invisible' elements
            continue;
        }

        if (processSpecialNodes() == ContinueWithNextNode)
            continue;

        // make sure there's a block for 'Blah' after <ul><li>foo</ul>Blah
        if (blockTagClosed
            && !hasBlock
            && !currentNode->isBlock()
            && !currentNode->text.isEmpty() && !currentNode->hasOnlyWhitespace()
            && currentNode->displayMode == QTextHtmlElement::DisplayInline) {

            QTextBlockFormat block = currentNode->blockFormat;
            block.setIndent(indent);

            appendBlock(block, currentNode->charFormat);

            hasBlock = true;
        }

        if (currentNode->isBlock()) {
            if (processBlockNode() == ContinueWithNextNode)
                continue;
        }

        if (currentNode->charFormat.isAnchor() && !currentNode->charFormat.anchorName().isEmpty()) {
            namedAnchors.append(currentNode->charFormat.anchorName());
        }

        if (appendNodeText())
            hasBlock = false; // if we actually appended text then we don't
                              // have an empty block anymore
    }

    cursor.endEditBlock();
}