QTextFrame *QTextDocumentPrivate::insertFrame(int start, int end, const QTextFrameFormat &format) { Q_ASSERT(start >= 0 && start < length()); Q_ASSERT(end >= 0 && end < length()); Q_ASSERT(start <= end || end == -1); if (start != end && frameAt(start) != frameAt(end)) return 0; beginEditBlock(); QTextFrame *frame = qobject_cast<QTextFrame *>(createObject(format)); Q_ASSERT(frame); // #### using the default block and char format below might be wrong int idx = formats.indexForFormat(QTextBlockFormat()); QTextCharFormat cfmt; cfmt.setObjectIndex(frame->objectIndex()); int charIdx = formats.indexForFormat(cfmt); insertBlock(QTextBeginningOfFrame, start, idx, charIdx, QTextUndoCommand::MoveCursor); insertBlock(QTextEndOfFrame, ++end, idx, charIdx, QTextUndoCommand::KeepCursor); frame->d_func()->fragment_start = find(start).n; frame->d_func()->fragment_end = find(end).n; insert_frame(frame); endEditBlock(); return frame; }
void tst_QTextFormat::toFormat() { { QTextFormat fmt = QTextFrameFormat(); QCOMPARE(fmt.toFrameFormat().type(), int(QTextFormat::FrameFormat)); } { QTextFormat fmt = QTextTableFormat(); QCOMPARE(fmt.toTableFormat().type(), int(QTextFormat::FrameFormat)); QCOMPARE(fmt.toTableFormat().objectType(), int(QTextFormat::TableObject)); } { QTextFormat fmt = QTextBlockFormat(); QCOMPARE(fmt.toBlockFormat().type(), int(QTextFormat::BlockFormat)); } { QTextFormat fmt = QTextCharFormat(); QCOMPARE(fmt.toCharFormat().type(), int(QTextFormat::CharFormat)); } { QTextFormat fmt = QTextListFormat(); QCOMPARE(fmt.toListFormat().type(), int(QTextFormat::ListFormat)); } }
QImage KoStyleThumbnailer::thumbnail(KoCharacterStyle *characterStyle, KoParagraphStyle *paragraphStyle, QSize size, bool recreateThumbnail, KoStyleThumbnailerFlags flags) { if ((flags & UseStyleNameText) && (!characterStyle || characterStyle->name().isNull())) { return QImage(); } else if ((! (flags & UseStyleNameText)) && d->thumbnailText.isEmpty()) { return QImage(); } else if (characterStyle == 0) { return QImage(); } if (!size.isValid() || size.isNull()) { size = d->defaultSize; } QString imageKey = "c_" + QString::number(reinterpret_cast<unsigned long>(characterStyle)) + "_" + "p_" + QString::number(reinterpret_cast<unsigned long>(paragraphStyle)) + "_" + QString::number(size.width()) + "_" + QString::number(size.height()); if (!recreateThumbnail && d->thumbnailCache.object(imageKey)) { return QImage(*(d->thumbnailCache.object(imageKey))); } QImage *im = new QImage(size.width(), size.height(), QImage::Format_ARGB32_Premultiplied); im->fill(QColor(Qt::transparent).rgba()); QTextCursor cursor(d->thumbnailHelperDocument); QTextCharFormat format; // Default to black as text color, to match what KoTextLayoutArea::paint(...) // does, setting solid black if no brush is set. Otherwise the UI text color // would be used, which might be too bright with dark UI color schemes format.setForeground(QColor(Qt::black)); KoCharacterStyle *characterStyleClone = characterStyle->clone(); characterStyleClone->applyStyle(format); cursor.select(QTextCursor::Document); cursor.setBlockFormat(QTextBlockFormat()); cursor.setBlockCharFormat(QTextCharFormat()); cursor.setCharFormat(QTextCharFormat()); if (paragraphStyle) { KoParagraphStyle *paragraphStyleClone = paragraphStyle->clone(); // paragraphStyleClone->KoCharacterStyle::applyStyle(format); QTextBlock block = cursor.block(); paragraphStyleClone->applyStyle(block, true); delete paragraphStyleClone; paragraphStyleClone = 0; } if (flags & UseStyleNameText) { cursor.insertText(characterStyleClone->name(), format); } else { cursor.insertText(d->thumbnailText, format); } layoutThumbnail(size, im, flags); d->thumbnailCache.insert(imageKey, im); delete characterStyleClone; return QImage(*im); }
void NotesWindow::setVisible(bool visible) { if (ui->textEdit->document()->isEmpty()) { qSort(m_notes); QTextCursor cursor = ui->textEdit->textCursor(); foreach (const NoteText ¬e, m_notes) { //cursor.insertText(s_separator); cursor.insertHtml(QStringLiteral("<hr>")); cursor.insertBlock(); cursor.setBlockFormat(QTextBlockFormat()); cursor.insertHtml(note.htmlHeader()); cursor.setBlockFormat(QTextBlockFormat()); cursor.insertBlock(); cursor.insertBlock(); if (note.isHtml()) cursor.insertHtml(note.text()); else cursor.insertText(note.text()); }
/*! \fn void QTextTable::insertRows(int index, int rows) Inserts a number of \a rows before the row with the specified \a index. \sa resize() insertColumns() removeRows() removeColumns() */ void QTextTable::insertRows(int pos, int num) { Q_D(QTextTable); if (num <= 0) return; if (d->dirty) d->update(); if (pos > d->nRows || pos < 0) pos = d->nRows; // qDebug() << "-------- insertRows" << pos << num; QTextDocumentPrivate *p = d->pieceTable; QTextFormatCollection *c = p->formatCollection(); p->beginEditBlock(); int extended = 0; int insert_before = 0; if (pos > 0 && pos < d->nRows) { for (int i = 0; i < d->nCols; ++i) { int cell = d->grid[pos*d->nCols + i]; if (cell == d->grid[(pos-1)*d->nCols+i]) { // cell spans the insertion place, extend it QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); QTextCharFormat fmt = c->charFormat(it->format); fmt.setTableCellRowSpan(fmt.tableCellRowSpan() + num); p->setCharFormat(it.position(), 1, fmt); extended++; } else if (!insert_before) { insert_before = cell; } } } else { insert_before = (pos == 0 ? d->grid[0] : d->fragment_end); } if (extended < d->nCols) { Q_ASSERT(insert_before); QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), insert_before); QTextCharFormat fmt = c->charFormat(it->format); fmt.setTableCellRowSpan(1); fmt.setTableCellColumnSpan(1); Q_ASSERT(fmt.objectIndex() == objectIndex()); int pos = it.position(); int cfmt = p->formatCollection()->indexForFormat(fmt); int bfmt = p->formatCollection()->indexForFormat(QTextBlockFormat()); // qDebug("inserting %d cells, nCols=%d extended=%d", num*(d->nCols-extended), d->nCols, extended); for (int i = 0; i < num*(d->nCols-extended); ++i) p->insertBlock(QTextBeginningOfFrame, pos, bfmt, cfmt, QTextUndoCommand::MoveCursor); } // qDebug() << "-------- end insertRows" << pos << num; p->endEditBlock(); }
/*! \fn void QTextTable::insertColumns(int index, int columns) Inserts a number of \a columns before the column with the specified \a index. \sa insertRows() resize() removeRows() removeColumns() appendRows() appendColumns() */ void QTextTable::insertColumns(int pos, int num) { Q_D(QTextTable); if (num <= 0) return; if (d->dirty) d->update(); if (pos > d->nCols || pos < 0) pos = d->nCols; // qDebug() << "-------- insertCols" << pos << num; QTextDocumentPrivate *p = d->pieceTable; QTextFormatCollection *c = p->formatCollection(); p->beginEditBlock(); for (int i = 0; i < d->nRows; ++i) { int cell; if (i == d->nRows - 1 && pos == d->nCols) cell = d->fragment_end; else cell = d->grid[i*d->nCols + pos]; QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); QTextCharFormat fmt = c->charFormat(it->format); if (pos > 0 && pos < d->nCols && cell == d->grid[i*d->nCols + pos - 1]) { // cell spans the insertion place, extend it fmt.setTableCellColumnSpan(fmt.tableCellColumnSpan() + num); p->setCharFormat(it.position(), 1, fmt); } else { fmt.setTableCellRowSpan(1); fmt.setTableCellColumnSpan(1); Q_ASSERT(fmt.objectIndex() == objectIndex()); int position = it.position(); int cfmt = p->formatCollection()->indexForFormat(fmt); int bfmt = p->formatCollection()->indexForFormat(QTextBlockFormat()); for (int i = 0; i < num; ++i) p->insertBlock(QTextBeginningOfFrame, position, bfmt, cfmt, QTextUndoCommand::MoveCursor); } } QTextTableFormat tfmt = format(); tfmt.setColumns(tfmt.columns()+num); QVector<QTextLength> columnWidths = tfmt.columnWidthConstraints(); if (! columnWidths.isEmpty()) { for (int i = num; i > 0; --i) columnWidths.insert(pos, columnWidths[qMax(0, pos-1)]); } tfmt.setColumnWidthConstraints (columnWidths); QTextObject::setFormat(tfmt); // qDebug() << "-------- end insertCols" << pos << num; p->endEditBlock(); }
void QTextDocumentPrivate::init() { rtFrame = 0; framesDirty = false; bool undoState = undoEnabled; undoEnabled = false; initialBlockCharFormatIndex = formats.indexForFormat(QTextCharFormat()); insertBlock(0, formats.indexForFormat(QTextBlockFormat()), formats.indexForFormat(QTextCharFormat())); undoEnabled = undoState; modified = false; modifiedState = 0; }
QImage KoStyleThumbnailer::thumbnail(KoParagraphStyle *style, QSize size, bool recreateThumbnail, KoStyleThumbnailerFlags flags) { if ((flags & UseStyleNameText) && (!style || style->name().isNull())) { return QImage(); } else if ((! (flags & UseStyleNameText)) && d->thumbnailText.isEmpty()) { return QImage(); } if (!size.isValid() || size.isNull()) { size = d->defaultSize; } QString imageKey = "p_" + QString::number(reinterpret_cast<unsigned long>(style)) + "_" + QString::number(size.width()) + "_" + QString::number(size.height()); if (!recreateThumbnail && d->thumbnailCache.object(imageKey)) { return QImage(*(d->thumbnailCache.object(imageKey))); } QImage *im = new QImage(size.width(), size.height(), QImage::Format_ARGB32_Premultiplied); im->fill(QColor(Qt::transparent).rgba()); KoParagraphStyle *clone = style->clone(); //TODO: make the following real options //we ignore these properties when the thumbnail would not be sufficient to preview properly the whole paragraph with margins. clone->setMargin(QTextLength(QTextLength::FixedLength, 0)); clone->setPadding(0); // QTextCursor cursor(d->thumbnailHelperDocument); cursor.select(QTextCursor::Document); cursor.setBlockFormat(QTextBlockFormat()); cursor.setBlockCharFormat(QTextCharFormat()); cursor.setCharFormat(QTextCharFormat()); QTextBlock block = cursor.block(); clone->applyStyle(block, true); QTextCharFormat format; // Default to black as text color, to match what KoTextLayoutArea::paint(...) // does, setting solid black if no brush is set. Otherwise the UI text color // would be used, which might be too bright with dark UI color schemes format.setForeground(QColor(Qt::black)); clone->KoCharacterStyle::applyStyle(format); if (flags & UseStyleNameText) { cursor.insertText(clone->name(), format); } else { cursor.insertText(d->thumbnailText, format); } layoutThumbnail(size, im, flags); d->thumbnailCache.insert(imageKey, im); delete clone; return QImage(*im); }
/*! * \brief Changes the list attribute of the selected text to \a v */ void QwwRichTextEdit::setList(bool v){ QTextCursor cur = textCursor(); if(v){ QTextListFormat listFormat; listFormat.setStyle(QTextListFormat::ListDisc); currentList = cur.createList(listFormat); } else { cur.setBlockFormat(QTextBlockFormat()); // cur.movePosition(QTextCursor::NextBlock); // cur.insertBlock(QTextBlockFormat()); setTextCursor(cur); currentList = 0; } }
void Document::setRichText(bool rich_text) { // Get new file name m_old_states[m_text->document()->availableUndoSteps()] = qMakePair(m_filename, m_rich_text); if (!m_filename.isEmpty()) { QString filename = m_filename; int suffix_index = filename.lastIndexOf(QChar('.')); int file_index = filename.lastIndexOf(QChar('/')); if (suffix_index > file_index) { filename.chop(filename.length() - suffix_index); } filename.append(rich_text ? ".proseup" : ".txt"); QString selected; m_filename = QFileDialog::getSaveFileName(window(), tr("Save File As"), filename, fileFilter(filename), &selected); if (!m_filename.isEmpty()) { m_filename = fileNameWithExtension(m_filename, selected); clearIndex(); } else { findIndex(); } } // Set file type m_rich_text = rich_text; m_text->setAcceptRichText(m_rich_text); // Always remove formatting to have something to undo QTextCursor cursor(m_text->document()); cursor.beginEditBlock(); cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); cursor.setBlockFormat(QTextBlockFormat()); cursor.setCharFormat(QTextCharFormat()); cleanUpDocument(); cursor.endEditBlock(); m_old_states[m_text->document()->availableUndoSteps()] = qMakePair(m_filename, m_rich_text); // Save file if (!m_filename.isEmpty()) { save(); updateState(); m_text->document()->setModified(false); } emit changedName(); emit formattingEnabled(m_rich_text); }
QTextTable *QTextTablePrivate::createTable(QTextDocumentPrivate *pieceTable, int pos, int rows, int cols, const QTextTableFormat &tableFormat) { QTextTableFormat fmt = tableFormat; fmt.setColumns(cols); QTextTable *table = qobject_cast<QTextTable *>(pieceTable->createObject(fmt)); Q_ASSERT(table); pieceTable->beginEditBlock(); // qDebug("---> createTable: rows=%d, cols=%d at %d", rows, cols, pos); // add block after table QTextCharFormat charFmt; charFmt.setObjectIndex(table->objectIndex()); charFmt.setObjectType(QTextFormat::TableCellObject); int charIdx = pieceTable->formatCollection()->indexForFormat(charFmt); int cellIdx = pieceTable->formatCollection()->indexForFormat(QTextBlockFormat()); QTextTablePrivate *d = table->d_func(); d->blockFragmentUpdates = true; d->fragment_start = pieceTable->insertBlock(QTextBeginningOfFrame, pos, cellIdx, charIdx); d->cells.append(d->fragment_start); ++pos; for (int i = 1; i < rows*cols; ++i) { d->cells.append(pieceTable->insertBlock(QTextBeginningOfFrame, pos, cellIdx, charIdx)); // qDebug(" addCell at %d", pos); ++pos; } d->fragment_end = pieceTable->insertBlock(QTextEndOfFrame, pos, cellIdx, charIdx); // qDebug(" addEOR at %d", pos); ++pos; d->blockFragmentUpdates = false; d->dirty = true; pieceTable->endEditBlock(); return table; }
void OutputWindow::grayOutOldContent() { if (!d->cursor.atEnd()) d->cursor.movePosition(QTextCursor::End); QTextCharFormat endFormat = d->cursor.charFormat(); d->cursor.select(QTextCursor::Document); QTextCharFormat format; const QColor bkgColor = palette().base().color(); const QColor fgdColor = palette().text().color(); double bkgFactor = 0.50; double fgdFactor = 1.-bkgFactor; format.setForeground(QColor((bkgFactor * bkgColor.red() + fgdFactor * fgdColor.red()), (bkgFactor * bkgColor.green() + fgdFactor * fgdColor.green()), (bkgFactor * bkgColor.blue() + fgdFactor * fgdColor.blue()) )); d->cursor.mergeCharFormat(format); d->cursor.movePosition(QTextCursor::End); d->cursor.setCharFormat(endFormat); d->cursor.insertBlock(QTextBlockFormat()); }
void OcrEngine::startLine() { if (m_ocrDialog->verboseDebug()) kDebug(); if (!m_cursor->atStart()) m_cursor->insertBlock(QTextBlockFormat(), QTextCharFormat()); }
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 ¶graph : 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 RTF::Reader::resetBlockFormatting(qint32) { m_state.block_format = QTextBlockFormat(); m_cursor.setBlockFormat(m_state.block_format); }
/*! \fn void QTextTable::insertColumns(int index, int columns) Inserts a number of \a columns before the column with the specified \a index. \sa insertRows(), resize(), removeRows(), removeColumns(), appendRows(), appendColumns() */ void QTextTable::insertColumns(int pos, int num) { Q_D(QTextTable); if (num <= 0) return; if (d->dirty) d->update(); if (pos > d->nCols || pos < 0) pos = d->nCols; // qDebug() << "-------- insertCols" << pos << num; QTextDocumentPrivate *p = d->pieceTable; QTextFormatCollection *c = p->formatCollection(); p->beginEditBlock(); QList<int> extendedSpans; for (int i = 0; i < d->nRows; ++i) { int cell; if (i == d->nRows - 1 && pos == d->nCols) { cell = d->fragment_end; } else { int logicalGridIndexBeforePosition = pos > 0 ? d->findCellIndex(d->grid[i*d->nCols + pos - 1]) : -1; // Search for the logical insertion point by skipping past cells which are not the first // cell in a rowspan. This means any cell for which the logical grid index is // less than the logical cell index of the cell before the insertion. int logicalGridIndex; int gridArrayOffset = i*d->nCols + pos; do { cell = d->grid[gridArrayOffset]; logicalGridIndex = d->findCellIndex(cell); gridArrayOffset++; } while (logicalGridIndex < logicalGridIndexBeforePosition && gridArrayOffset < d->nRows*d->nCols); if (logicalGridIndex < logicalGridIndexBeforePosition && gridArrayOffset == d->nRows*d->nCols) cell = d->fragment_end; } if (pos > 0 && pos < d->nCols && cell == d->grid[i*d->nCols + pos - 1]) { // cell spans the insertion place, extend it if (!extendedSpans.contains(cell)) { QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); QTextCharFormat fmt = c->charFormat(it->format); fmt.setTableCellColumnSpan(fmt.tableCellColumnSpan() + num); p->setCharFormat(it.position(), 1, fmt); d->dirty = true; extendedSpans << cell; } } else { /* If the next cell is spanned from the row above, we need to find the right position to insert to */ if (i > 0 && pos < d->nCols && cell == d->grid[(i-1) * d->nCols + pos]) { int gridIndex = i*d->nCols + pos; const int gridEnd = d->nRows * d->nCols - 1; while (gridIndex < gridEnd && cell == d->grid[gridIndex]) { ++gridIndex; } if (gridIndex == gridEnd) cell = d->fragment_end; else cell = d->grid[gridIndex]; } QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell); QTextCharFormat fmt = c->charFormat(it->format); fmt.setTableCellRowSpan(1); fmt.setTableCellColumnSpan(1); Q_ASSERT(fmt.objectIndex() == objectIndex()); int position = it.position(); int cfmt = p->formatCollection()->indexForFormat(fmt); int bfmt = p->formatCollection()->indexForFormat(QTextBlockFormat()); for (int i = 0; i < num; ++i) p->insertBlock(QTextBeginningOfFrame, position, bfmt, cfmt, QTextUndoCommand::MoveCursor); } } QTextTableFormat tfmt = format(); tfmt.setColumns(tfmt.columns()+num); QVector<QTextLength> columnWidths = tfmt.columnWidthConstraints(); if (! columnWidths.isEmpty()) { for (int i = num; i > 0; --i) columnWidths.insert(pos, columnWidths[qMax(0, pos-1)]); } tfmt.setColumnWidthConstraints (columnWidths); QTextObject::setFormat(tfmt); // qDebug() << "-------- end insertCols" << pos << num; p->endEditBlock(); }
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 ); }
QTextTable * PrintDialog::insertCategoryTable(QTextCursor & cursor, const QString & categoryName) { QTextBlockFormat blockCategoryTitleFormat; blockCategoryTitleFormat.setAlignment(Qt::AlignCenter); blockCategoryTitleFormat.setTopMargin(40.0); blockCategoryTitleFormat.setBottomMargin(30.0); QTextCharFormat categoryTitleFormat; categoryTitleFormat.setFontCapitalization(QFont::AllUppercase); categoryTitleFormat.setFontWeight(25); categoryTitleFormat.setFontPointSize(14.0); QString category = "Category \""; category += categoryName; category += "\""; cursor.insertBlock(blockCategoryTitleFormat); cursor.insertText(category,categoryTitleFormat); cursor.insertBlock(QTextBlockFormat()); // to break the previous block format QTextTable * table = cursor.insertTable(1, 4); if(!table) return NULL; QTextTableFormat categoryTableFormat; categoryTableFormat.setAlignment(Qt::AlignHCenter); categoryTableFormat.setHeaderRowCount(1); // header line categoryTableFormat.setBorderStyle(QTextTableFormat::BorderStyle_Solid); categoryTableFormat.setBorder(1.0); categoryTableFormat.setCellPadding(10); categoryTableFormat.setCellSpacing(0); table->setFormat(categoryTableFormat); // header : // header cell format : QTextCharFormat headerCellFormat; headerCellFormat.setFontWeight(50); headerCellFormat.setFontPointSize(12.0); headerCellFormat.setBackground(QBrush(QColor(60,60,60))); headerCellFormat.setForeground(QBrush(QColor(255,255,255))); QTextTableCell cell = table->cellAt(0,0); cell.setFormat(headerCellFormat); cursor = cell.firstCursorPosition(); cursor.insertText(tr("Position")); cell = table->cellAt(0,1); cell.setFormat(headerCellFormat); cursor = cell.firstCursorPosition(); cursor.insertText(tr("LastName")); cell = table->cellAt(0,2); cell.setFormat(headerCellFormat); cursor = cell.firstCursorPosition(); cursor.insertText(tr("Firstname")); cell = table->cellAt(0,3); cell.setFormat(headerCellFormat); cursor = cell.firstCursorPosition(); cursor.insertText(tr("Time")); return table; }