void flush(void) { QTextBlockFormat bf = editor->textCursor().blockFormat(); bf.setBottomMargin(0); editor->textCursor().setBlockFormat(bf); editor->append(buffer); buffer.clear(); }
void TextOutputI::insertHtml(const QString& s) { QTextBlockFormat bf = editor->textCursor().blockFormat(); bf.setBottomMargin(0); editor->textCursor().setBlockFormat(bf); editor->insertHtml(s); editor->ensureCursorVisible(); }
/* set all margin to zero qt4 send 12 top 12 bottom by default */ QTextBlockFormat DefaultMargin( QTextBlockFormat rootformats ) { rootformats.setBottomMargin(4); rootformats.setTopMargin(4); rootformats.setRightMargin(0); rootformats.setLeftMargin(0); rootformats.setAlignment( Qt::AlignLeft ); return rootformats; }
virtual int overflow(int v = std::char_traits<char>::eof()) { if (v == '\n') { QTextBlockFormat bf = editor->textCursor().blockFormat(); bf.setBottomMargin(0); editor->textCursor().setBlockFormat(bf); editor->append(buffer); buffer.clear(); } else { buffer += (char)v; } return v; }
void TextZone::changeTextStyleSlot(int styleIndex) { QTextBlockFormat blockFormat; blockFormat.setBottomMargin(textStyles->blockBottomMarginAt(styleIndex)); blockFormat.setTextIndent(textStyles->blockFirstLineIndentAt(styleIndex)); blockFormat.setLeftMargin(textStyles->blockLeftMarginAt(styleIndex)); blockFormat.setAlignment(textStyles->blockAlignmentTrueNameAt(styleIndex)); blockFormat.setTopMargin(0); blockFormat.setRightMargin(0); QTextCharFormat charFormat; charFormat.setFontPointSize(textStyles->fontSizeAt(styleIndex)); charFormat.setFontFamily(textStyles->fontFamilyAt(styleIndex)); // charFormat.setFontItalic(textStyles->fontItalicAt(styleIndex)); // if (textStyles->fontBoldAt(styleIndex) == true) // charFormat.setFontWeight(75); // else // charFormat.setFontWeight(50); // charFormat.setFontUnderline(textStyles->fontUnderlineAt(styleIndex)); // charFormat.setFontStrikeOut(textStyles->fontStrikeOutAt(styleIndex)); // charFormat.clearForeground(); QTextCursor tCursor = this->textCursor(); // select all of the blocks selected : QTextCursor tStartCursor = this->textCursor(); tStartCursor.setPosition(tCursor.selectionStart()); tStartCursor.movePosition(QTextCursor::StartOfBlock); int startFirstBlock = tStartCursor.position(); QTextCursor tEndCursor = this->textCursor(); tEndCursor.setPosition(tCursor.selectionEnd()); tEndCursor.movePosition(QTextCursor::EndOfBlock); int endLastBlock = tEndCursor.position(); tCursor.setPosition(startFirstBlock); tCursor.setPosition(endLastBlock, QTextCursor::KeepAnchor); // merge : tCursor.mergeBlockFormat(blockFormat); tCursor.mergeCharFormat(charFormat); this->mergeCurrentCharFormat(charFormat); }
void PrintDialog::insertSeparatorLine(QTextCursor & cursor) { QTextBlockFormat blockSeparatorFormat; blockSeparatorFormat.setAlignment(Qt::AlignCenter); blockSeparatorFormat.setTopMargin(10.0); blockSeparatorFormat.setBottomMargin(10.0); QTextCharFormat separatorFormat; separatorFormat.setFontCapitalization(QFont::AllUppercase); separatorFormat.setFontWeight(50); separatorFormat.setFontPointSize(10.0); cursor.insertBlock(blockSeparatorFormat); cursor.insertText("_______________________________________________",separatorFormat); }
void PrintDialog::insertTitleResult(QTextCursor & cursor, const QString & raceName) { QTextBlockFormat blockTitleFormat; blockTitleFormat.setAlignment(Qt::AlignCenter); blockTitleFormat.setTopMargin(0.0); blockTitleFormat.setBottomMargin(80.0); QTextCharFormat titleFormat; titleFormat.setFontPointSize(20); titleFormat.setFontWeight(50); titleFormat.setFontCapitalization(QFont::AllUppercase); cursor.insertBlock(blockTitleFormat); cursor.insertText(raceName, titleFormat); }
QTextDocument *Exporter::prepareNoteDoc(QTextDocument *noteDoc) { QTextDocument *textDocument = noteDoc->clone(this); //cut blank spaces at the begining and end : QTextCursor *tCursor = new QTextCursor(textDocument); tCursor->movePosition(QTextCursor::Start, QTextCursor::MoveAnchor,1); tCursor->movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,1); while(tCursor->selectedText() == " "){ tCursor->deleteChar(); tCursor->movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,1); } tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1); tCursor->movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor,1); while(tCursor->selectedText() == " "){ tCursor->deleteChar(); tCursor->movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor,1); } //set text config : QTextBlockFormat blockFormat; blockFormat.setBottomMargin(0); blockFormat.setTopMargin(0); blockFormat.setTextIndent(72); blockFormat.setLineHeight(200, QTextBlockFormat::ProportionalHeight); blockFormat.setAlignment(Qt::AlignJustify); QTextCharFormat charFormat; charFormat.setFontPointSize(12); charFormat.setFontFamily("Courrier"); tCursor->select(QTextCursor::Document); tCursor->mergeBlockCharFormat(charFormat); tCursor->mergeBlockFormat(blockFormat); return textDocument; }
QTextCursor ChatView::prepareBlock(bool same) { lastSender.clear(); QTextCursor cursor(document()->lastBlock()); cursor.movePosition(QTextCursor::End); if (!same) { QTextBlockFormat blockFormat; if ((evenNumber = !evenNumber)) blockFormat.setBackground(palette().alternateBase()); blockFormat.setBottomMargin(2); cursor.insertBlock(blockFormat); } else cursor.insertHtml("<br>"); return cursor; }
void PrintDialog::insertHeaderResult(QTextCursor & cursor, const QString & location, const QString & date) { QTextBlockFormat blockHeaderFormat; blockHeaderFormat.setAlignment(Qt::AlignLeft); blockHeaderFormat.setTopMargin(5.0); blockHeaderFormat.setBottomMargin(0.0); blockHeaderFormat.setLeftMargin(20.0); QTextCharFormat headerFormat1; headerFormat1.setFontPointSize(10); headerFormat1.setFontWeight(50); QTextCharFormat headerFormat2; headerFormat2.setFontPointSize(10); headerFormat2.setFontWeight(50); cursor.insertBlock(blockHeaderFormat); cursor.insertText(tr("Location : "), headerFormat1); cursor.insertText(location, headerFormat2); cursor.insertBlock(blockHeaderFormat); cursor.insertText(tr("Date : "), headerFormat1); cursor.insertText(date, headerFormat2); }
WndListenJob::WndListenJob( int JobId, const QString & Name): WndText( "Listen Job"), jobid( JobId), jobname( Name) { #if QT_VERSION >= 0x040300 layout->setContentsMargins( 10, 10, 10, 10); #endif setContentsMargins(1,1,1,1); qTextEdit->moveCursor( QTextCursor::End, QTextCursor::KeepAnchor); QTextCursor cursor = qTextEdit->textCursor(); QTextBlockFormat blockFormat; blockFormat.setTopMargin(-5); blockFormat.setBottomMargin(-5); cursor.setBlockFormat( blockFormat); qTextEdit->setTextCursor( cursor); qTextEdit->setWordWrapMode( QTextOption::NoWrap); setWindowTitle( jobname); af::MCListenAddress mclass( af::MCListenAddress::TOLISTEN, Watch::getClientAddress(), jobid); Watch::sendMsg( new af::Msg( af::Msg::TTaskListenOutput, &mclass)); }
void CalcFrame::printCalc() { const auto milkReception = m_mainWindow->database()->milkReception(); if (!milkReception) { Utils::Main::showMsgIfDbNotChoosed(this); return; } DataWorker dw(m_mainWindow->database()); try { dw.loadMilkReceptions(getWhereQuery()); } catch (const QString &err) { QMessageBox::critical(this, tr("Расчеты"), tr("Произошла ошибка во время подгрузки данных: ") + err); } const auto deliverers = dw.getDeliverers().values(); if (deliverers.isEmpty()) { QMessageBox::information(this, tr("Печать"), tr("Отсутствуют данные для печати")); return; } const char f = 'f'; int row = 0; const auto settings = m_mainWindow->getSettings(); const auto printColumns = m_mainWindow->getSettings()->getPrint().columns; QStringList columns; for (int i = 0; i < printColumns.size(); ++i) { const auto &col = printColumns[i]; if (col.isShow) columns.append(printColumns[i].display); } const int columnsCount = columns.size(); if (columnsCount <= 0) { QMessageBox::information(this, tr("Печать сдачи молока"), tr("Не выбрана ни одна колонка для печати")); return; } const Settings::Column snCol = printColumns[Constants::PrintColumns::SerialNumber], delivNameCol = printColumns[Constants::PrintColumns::DeliverersName], litersCol = printColumns[Constants::PrintColumns::Liters], fatCol = printColumns[Constants::PrintColumns::Fat], proteinCol = printColumns[Constants::PrintColumns::Protein], fatUnitsCol = printColumns[Constants::PrintColumns::FatUnits], rankWeightCol = printColumns[Constants::PrintColumns::RankWeight], payCol = printColumns[Constants::PrintColumns::PayWithOutPrem], permiumCol = printColumns[Constants::PrintColumns::Premium], sumCol = printColumns[Constants::PrintColumns::Sum], signCol = printColumns[Constants::PrintColumns::Sign]; auto itemToPrintRow = [&](const QString &delivName, const CalculatedItem::Data &item, const int rowPos = -1) -> QStringList { QStringList row; if (snCol.isShow) row.append(rowPos >= 0 ? QString::number(rowPos) : QString()); if (delivNameCol.isShow) row.append(delivName); if (litersCol.isShow) row.append(QString::number(item.liters, f, litersCol.prec)); if (fatCol.isShow) row.append(QString::number(item.fat, f, fatCol.prec)); if (proteinCol.isShow) row.append(QString::number(item.protein, f, proteinCol.prec)); if (fatUnitsCol.isShow) row.append(QString::number(item.fatUnits, f, fatCol.prec)); if (rankWeightCol.isShow) row.append(QString::number(item.rankWeight, f, rankWeightCol.prec)); if (payCol.isShow) row.append(QString::number(item.paymentWithOutPremium, f, payCol.prec)); if (permiumCol.isShow) row.append(QString::number(item.premiumForFat, f, permiumCol.prec)); if (sumCol.isShow) row.append(QString::number(floor(item.sum), f, sumCol.prec)); if (signCol.isShow) row.append(QString()); return row; }; const auto &printSettings = settings->getPrint(); QTextTableFormat tableFormat; tableFormat.setBorder(printSettings.tableBorderWidth); tableFormat.setBorderStyle(static_cast<QTextFrameFormat::BorderStyle>(printSettings.tableBorderStyle)); tableFormat.setColumns(columnsCount); tableFormat.setAlignment(Qt::AlignHCenter); tableFormat.setWidth(QTextLength(QTextLength::VariableLength, 100)); tableFormat.setBorderBrush(QBrush(printSettings.tableBorderColor)); tableFormat.setCellSpacing(printSettings.cellSpacing); tableFormat.setCellPadding(printSettings.cellPadding); PrintTable print(columnsCount, tableFormat); { auto &textFormat = print.getTableBodyTextFormat(); textFormat.setFont(printSettings.tableTextFont); textFormat.setForeground(QBrush(printSettings.tableTextColor)); } { auto &textFormat = print.getTableHeadersFormat(); textFormat.setFont(printSettings.tableHeaderFont); textFormat.setForeground(QBrush(printSettings.tableHeaderColor)); } print.setHeaders(columns); CalculatedItem::Data allResult; for (const auto &deliverer: deliverers) { row++; const CalculatedItem::Data calcItem = deliverer->getCalculations(); print.addRow(itemToPrintRow(deliverer->name(), calcItem, row)); allResult += calcItem; } int mergeCount = 0; auto itemRow = itemToPrintRow("Итого", allResult, row); for (int i = 0; i < Constants::PrintColumns::Liters; i++) { const auto &col = printColumns[i]; if (col.isShow) mergeCount++; } QTextCharFormat resultFormat; resultFormat.setFont(printSettings.tableResultFont); resultFormat.setForeground(QBrush(printSettings.tableResultColor)); print.addRow(itemRow, resultFormat, mergeCount); auto &cursor = print.cursor(); cursor.setPosition(0); QTextFrameFormat topFrameFormat; topFrameFormat.setPadding(4); cursor.insertFrame(topFrameFormat); QTextBlockFormat textBlockFormat; textBlockFormat.setBottomMargin(4); textBlockFormat.setAlignment(Qt::AlignLeft); QTextBlockFormat captionBlockFormat; captionBlockFormat.setAlignment(Qt::AlignCenter); cursor.setBlockFormat(textBlockFormat); QTextCharFormat textCharFormat; textCharFormat.setFont(printSettings.textFont); QTextCharFormat captionCharFormat; captionCharFormat.setFont(printSettings.captionTextFont); captionCharFormat.setForeground(QBrush(printSettings.captionColor)); cursor.insertText(settings->getFirmName(), textCharFormat); cursor.insertBlock(); cursor.setBlockFormat(captionBlockFormat); auto dateMin = QDate(), dateMax = QDate(); if (isCalcByDate()) { dateMin = ui->dateEditFilterStart->date(); dateMax = ui->dateEditFilterEnd->date(); } else { dateMin = milkReception->getMinDeliveryDate(); dateMax = milkReception->getMaxDeliveryDate(); } const auto s = dateMax == dateMin ? tr("%1 число").arg(dateMin.toString(Constants::defaultDateFormat())) : tr("период с %1 по %2") .arg(dateMin.toString(Constants::defaultDateFormat())) .arg(dateMax.toString(Constants::defaultDateFormat())); cursor.insertText(QString(tr("Платежная ведомость №\n" "за сданное молоко\n" "за ") + s), captionCharFormat); cursor.insertBlock(); cursor.setBlockFormat(textBlockFormat); cursor.insertText(tr("Населенный пункт: ") + m_mainWindow->getCurrentLocalityName(), textCharFormat); cursor.insertBlock(); cursor.insertText(tr("Приемщик молока: ") + settings->getMilkInspector(), textCharFormat); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); QTextFrameFormat bottomFrameFormat; bottomFrameFormat.setPadding(4); cursor.insertFrame(bottomFrameFormat); cursor.setBlockFormat(textBlockFormat); const auto minMaxPrice = milkReception->getMinMaxPriceLiter(dateMin, dateMax); if (minMaxPrice.first > .0 && minMaxPrice.second > .0) { const QString minPrice = QString::number(minMaxPrice.first, f, 2), maxPrice = QString::number(minMaxPrice.second, f, 2); cursor.insertText(tr("Цена: %1").arg(minPrice == maxPrice ? minPrice : QString("%1 - %2") .arg(minPrice).arg(maxPrice))); cursor.insertBlock(); } cursor.insertText(tr("Деньги в сумме: "), textCharFormat); cursor.insertBlock(); cursor.insertText(tr("Получил и выдал согласно ведомости приемщик молока______") + settings->getMilkInspector_2(), textCharFormat); cursor.insertBlock(); cursor.insertText(tr("Директор ") + settings->getFirmName(), textCharFormat); print.showDialog(); }
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 ); }
void TextZone::insertFromMimeData (const QMimeData *source ) { QTextCursor cursor = this->textCursor(); int bottMargin; int textIndent; int leftMargin; Qt::Alignment textAlignment; int textHeight; QString fontFamily; if(cursor.atStart() == true || cursor.position() == 1 || cursor.position() == 0){ int defaultIndex = textStyles->defaultStyleIndex(); bottMargin = textStyles->blockBottomMarginAt(defaultIndex); textIndent = textStyles->blockFirstLineIndentAt(defaultIndex); leftMargin = textStyles->blockLeftMarginAt(defaultIndex); textAlignment = textStyles->blockAlignmentTrueNameAt(defaultIndex); textHeight = textStyles->fontSizeAt(defaultIndex); fontFamily = textStyles->fontFamilyAt(defaultIndex); } else{ bottMargin = cursor.blockFormat().bottomMargin(); textIndent = cursor.blockFormat().textIndent(); leftMargin = cursor.blockFormat().leftMargin(); textAlignment = cursor.blockFormat().alignment(); textHeight = cursor.charFormat().fontPointSize(); fontFamily = cursor.charFormat().fontFamily(); } if(source->hasHtml() && !forceCopyWithoutFormatting){ QByteArray richtext; if (source->hasFormat(QLatin1String("text/rtf"))) { richtext = source->data(QLatin1String("text/rtf")); } else if (source->hasHtml()) { richtext = mimeToRtf(source); } QTextEdit *textEdit = new QTextEdit(0); RTF::Reader reader; QBuffer buffer(&richtext); buffer.open(QIODevice::ReadOnly); reader.read(&buffer, textEdit->textCursor()); buffer.close(); QString sourceString = textEdit->toHtml(); sourceString.remove(QChar::ReplacementCharacter); sourceString.remove(QChar::ObjectReplacementCharacter); sourceString.remove(QChar::Null); //htmlText QTextDocument *document = new QTextDocument; document->setHtml(Utils::parseHtmlText(sourceString)); QTextBlockFormat blockFormat; blockFormat.setBottomMargin(bottMargin); blockFormat.setTextIndent(textIndent); blockFormat.setLeftMargin(leftMargin); blockFormat.setAlignment(textAlignment); blockFormat.setRightMargin(0); QTextCharFormat charFormat; charFormat.setFontPointSize(textHeight); charFormat.setFontFamily(fontFamily); charFormat.setBackground(QBrush(Qt::NoBrush)); charFormat.setForeground(QBrush(Qt::NoBrush)); charFormat.setAnchor(false); charFormat.setUnderlineStyle(QTextCharFormat::NoUnderline); charFormat.setFontStrikeOut(false); QTextCursor *tCursor = new QTextCursor(document); tCursor->movePosition(QTextCursor::Start, QTextCursor::MoveAnchor,1); tCursor->movePosition(QTextCursor::End, QTextCursor::KeepAnchor,1); tCursor->mergeCharFormat(charFormat); tCursor->mergeBlockFormat(blockFormat); QTextCursor cursor = this->textCursor(); cursor.insertHtml(document->toHtml("utf-8")); qDebug() << "insertFromMimeData Html"; } else if(source->hasText() || forceCopyWithoutFormatting){ QTextDocument *document = new QTextDocument; document->setPlainText(qvariant_cast<QString>(source->text())); QTextBlockFormat blockFormat; blockFormat.setBottomMargin(bottMargin); blockFormat.setTextIndent(textIndent); blockFormat.setLeftMargin(leftMargin); blockFormat.setAlignment(textAlignment); blockFormat.setRightMargin(0); QTextCharFormat charFormat; charFormat.setFontPointSize(textHeight); charFormat.setFontFamily(fontFamily); charFormat.clearForeground(); charFormat.setBackground(QBrush(Qt::NoBrush)); charFormat.setForeground(QBrush(Qt::NoBrush)); charFormat.setAnchor(false); charFormat.setUnderlineStyle(QTextCharFormat::NoUnderline); charFormat.setFontStrikeOut(false); QTextCursor *tCursor = new QTextCursor(document); tCursor->movePosition(QTextCursor::Start, QTextCursor::MoveAnchor,1); tCursor->movePosition(QTextCursor::End, QTextCursor::KeepAnchor,1); tCursor->mergeCharFormat(charFormat); tCursor->mergeBlockFormat(blockFormat); QTextCursor cursor = this->textCursor(); cursor.insertHtml(document->toHtml("utf-8")); qDebug() << "insertFromMimeData plainText"; } }
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(); }
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; }
int main(int argc, char *argv[]) { QApplication app(argc, argv); //! [0] QTextEdit *editor = new QTextEdit(); QTextCursor cursor(editor->textCursor()); //! [0] cursor.movePosition(QTextCursor::Start); QTextBlockFormat blockFormat = cursor.blockFormat(); blockFormat.setTopMargin(4); blockFormat.setLeftMargin(4); blockFormat.setRightMargin(4); blockFormat.setBottomMargin(4); cursor.setBlockFormat(blockFormat); cursor.insertText(tr("This contains plain text inside a " "text block with margins to keep it separate " "from other parts of the document.")); cursor.insertBlock(); //! [1] QTextBlockFormat backgroundFormat = blockFormat; backgroundFormat.setBackground(QColor("lightGray")); cursor.setBlockFormat(backgroundFormat); //! [1] cursor.insertText(tr("The background color of a text block can be " "changed to highlight text.")); cursor.insertBlock(); QTextBlockFormat rightAlignedFormat = blockFormat; rightAlignedFormat.setAlignment(Qt::AlignRight); cursor.setBlockFormat(rightAlignedFormat); cursor.insertText(tr("The alignment of the text within a block is " "controlled by the alignment properties of " "the block itself. This text block is " "right-aligned.")); cursor.insertBlock(); QTextBlockFormat paragraphFormat = blockFormat; paragraphFormat.setAlignment(Qt::AlignJustify); paragraphFormat.setTextIndent(32); cursor.setBlockFormat(paragraphFormat); cursor.insertText(tr("Text can be formatted so that the first " "line in a paragraph has its own margin. " "This makes the text more readable.")); cursor.insertBlock(); QTextBlockFormat reverseFormat = blockFormat; reverseFormat.setAlignment(Qt::AlignJustify); reverseFormat.setTextIndent(32); cursor.setBlockFormat(reverseFormat); cursor.insertText(tr("The direction of the text can be reversed. " "This is useful for right-to-left " "languages.")); editor->setWindowTitle(tr("Text Block Formats")); editor->resize(480, 480); editor->show(); return app.exec(); }
QTextDocument * Exporter::buildFinalDoc() { //search for checked items : QDomDocument domDoc = hub->project()->mainTreeDomDoc(); QDomElement root = domDoc.documentElement(); QList<QDomElement> itemList = searchForCheckedItems(root); if(itemList.size() == 0) return new QTextDocument(); // set up the progress bar : QWidget *progressWidget = new QWidget(this, Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); QHBoxLayout *progressLayout = new QHBoxLayout(progressWidget); QProgressBar *progressBar = new QProgressBar(progressWidget); int progressValue = 0; progressLayout->addWidget(progressBar); progressWidget->setLayout(progressLayout); progressBar->setMaximum(itemList.size()); progressBar->setValue(progressValue); progressWidget->show(); // QString debug; // qDebug() << "itemList" << debug.setNum(itemList->size()); QTextDocument *textDocument = new QTextDocument(this); QTextEdit *edit = new QTextEdit(this); textDocument->setDefaultStyleSheet("p, li { white-space: pre-wrap; } p{line-height: 2em; font-family:'Liberation Serif'; font-size:12pt;margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:72px;}"); for(int i = 0; i < itemList.size(); ++i){ QDomElement element = itemList.at(i); QTextCursor *tCursor = new QTextCursor(textDocument); QTextBlockFormat blockFormatLeft; blockFormatLeft.setBottomMargin(0); blockFormatLeft.setTopMargin(0); blockFormatLeft.setTextIndent(72); blockFormatLeft.setLineHeight(200, QTextBlockFormat::ProportionalHeight); blockFormatLeft.setAlignment(Qt::AlignJustify); QTextCharFormat charFormatLeft; charFormatLeft.setFontPointSize(12); charFormatLeft.setFontFamily("Courrier"); QTextBlockFormat blockFormatCenter; blockFormatCenter.setAlignment(Qt::AlignCenter); if(element.tagName() != "separator"){ qDebug() << "element name : "+ element.attribute("name"); MainTextDocument *textDoc = hub->project()->findChild<MainTextDocument *>("textDoc_" + element.attribute("number")); MainTextDocument *synDoc = hub->project()->findChild<MainTextDocument *>("synDoc_" + element.attribute("number")); MainTextDocument *noteDoc = hub->project()->findChild<MainTextDocument *>("noteDoc_" + element.attribute("number")); QTextDocumentFragment textFrag(prepareTextDoc(textDoc)); QTextDocumentFragment synFrag(prepareSynDoc(synDoc)); QTextDocumentFragment noteFrag(prepareNoteDoc(noteDoc)); edit->setDocument(textDocument); if(element.tagName() == "book"){ textDocument->setMetaInformation(QTextDocument::DocumentTitle,element.attribute("name", "")); edit->append("<h1>" + element.attribute("name", "") + "</h1>"); tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1); tCursor->mergeBlockFormat(blockFormatCenter); edit->append("<h4>" + QDateTime::currentDateTime().toString() + "</h4>"); tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1); tCursor->mergeBlockFormat(blockFormatCenter); edit->append("<br>"); edit->append("<br>"); } if(element.tagName() == "act"){ edit->append("<br>"); edit->append("<br>"); edit->append("<h2>" + element.attribute("name", "") + "</h2>"); tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1); tCursor->mergeBlockFormat(blockFormatCenter); edit->append("<br>"); } if(element.tagName() == "chapter"){ edit->append("<br>"); edit->append("<br>"); edit->append("<h2>" + element.attribute("name", "") + "</h2>"); tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1); tCursor->mergeBlockFormat(blockFormatCenter); edit->append("<br>"); } if(element.tagName() == "scene" && ui->setSceneTitlesComboBox->currentIndex() != 0){ QString sceneTitle; switch (ui->setSceneTitlesComboBox->currentIndex()){ case 1: sceneTitle = element.attribute("name", ""); break; case 2: sceneTitle = "###"; break; case 3: sceneTitle = "***"; break; default: sceneTitle = element.attribute("name", ""); break; } edit->append("<br>"); edit->append("<h3>" + sceneTitle + "</h3>"); tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1); tCursor->mergeBlockFormat(blockFormatCenter); edit->append("<br>"); } if(ui->synopsisCheckBox->isChecked() && !synFrag.isEmpty()){ edit->append("<br>"); edit->append("<h4>" + tr("Synopsis") + "</h4>"); tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1); tCursor->mergeBlockFormat(blockFormatCenter); edit->append("<br>"); tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1); tCursor->insertBlock(blockFormatLeft, charFormatLeft); tCursor->insertFragment(synFrag); } if(ui->notesCheckBox->isChecked() && !noteFrag.isEmpty()){ edit->append("<br>"); edit->append("<h4>" + tr("Note") + "</h4>"); tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1); tCursor->mergeBlockFormat(blockFormatCenter); edit->append("<br>"); tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1); tCursor->insertBlock(blockFormatLeft, charFormatLeft); tCursor->insertFragment(noteFrag); } if(ui->storyCheckBox->isChecked()){ if((ui->synopsisCheckBox->isChecked() || ui->notesCheckBox->isChecked()) && !textFrag.isEmpty()){ tCursor->insertBlock(); tCursor->insertHtml("<h4>" + tr("Story") + "</h4>"); tCursor->mergeBlockFormat(blockFormatCenter); tCursor->insertBlock(); } tCursor->insertHtml("<br>"); // tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1); tCursor->insertBlock(blockFormatLeft, charFormatLeft); tCursor->insertFragment(textFrag); // edit->append(textFrag->toHtml()); } } else if(element.tagName() == "separator"){ edit->append("<br>"); edit->append("<h3>#</h3>"); tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1); tCursor->mergeBlockFormat(blockFormatCenter); edit->append("<br>"); tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1); tCursor->mergeBlockFormat(blockFormatLeft); } progressValue += 1; progressBar->setValue(progressValue); } QRegExp reg("-qt-paragraph-type:.*;|margin-top:.*;|margin-bottom:.*;|margin-left:.*;|margin-right:.*;|-qt-block-indent:.*;|text-indent:.*;|font-family:.*;|font-size:.*;"); reg.setMinimal(true); textDocument->setHtml(textDocument->toHtml().remove(reg)); //find and change final page css style : //textDocument->setDefaultStyleSheet("p, li { white-space: pre-wrap; } p{line-height: 2em; font-family:'Liberation Serif'; font-size:14pt;margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:72px;}"); // <style type="text/css"> // p, li { white-space: pre-wrap; } // </style> // tCursor // qDebug() << textDocument->toHtml(); progressWidget->close(); return textDocument; }
QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processSpecialNodes() { switch (currentNode->id) { case Html_body: if (currentNode->charFormat.background().style() != Qt::NoBrush) { QTextFrameFormat fmt = doc->rootFrame()->frameFormat(); fmt.setBackground(currentNode->charFormat.background()); doc->rootFrame()->setFrameFormat(fmt); const_cast<QTextHtmlParserNode *>(currentNode)->charFormat.clearProperty(QTextFormat::BackgroundBrush); } break; case Html_ol: case Html_ul: { QTextListFormat::Style style = currentNode->listStyle; if (currentNode->id == Html_ul && !currentNode->hasOwnListStyle && currentNode->parent) { const QTextHtmlParserNode *n = &at(currentNode->parent); while (n) { if (n->id == Html_ul) { style = nextListStyle(currentNode->listStyle); } if (n->parent) n = &at(n->parent); else n = 0; } } QTextListFormat listFmt; listFmt.setStyle(style); ++indent; if (currentNode->hasCssListIndent) listFmt.setIndent(currentNode->cssListIndent); else listFmt.setIndent(indent); List l; l.format = listFmt; l.listNode = currentNodeIdx; lists.append(l); compressNextWhitespace = true; // broken html: <ul>Text here<li>Foo const QString simpl = currentNode->text.simplified(); if (simpl.isEmpty() || simpl.at(0).isSpace()) return ContinueWithNextNode; break; } case Html_table: { Table t = scanTable(currentNodeIdx); tables.append(t); hasBlock = false; return ContinueWithNextNode; } case Html_tr: return ContinueWithNextNode; case Html_img: { QTextImageFormat fmt; fmt.setName(currentNode->imageName); fmt.merge(currentNode->charFormat); if (currentNode->imageWidth >= 0) fmt.setWidth(currentNode->imageWidth); if (currentNode->imageHeight >= 0) fmt.setHeight(currentNode->imageHeight); cursor.insertImage(fmt, QTextFrameFormat::Position(currentNode->cssFloat)); cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor); cursor.mergeCharFormat(currentNode->charFormat); cursor.movePosition(QTextCursor::Right); hasBlock = false; return ContinueWithNextNode; } case Html_hr: { QTextBlockFormat blockFormat = currentNode->blockFormat; blockFormat.setTopMargin(topMargin(currentNodeIdx)); blockFormat.setBottomMargin(bottomMargin(currentNodeIdx)); blockFormat.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth, currentNode->width); if (hasBlock && importMode == ImportToDocument) cursor.mergeBlockFormat(blockFormat); else appendBlock(blockFormat); hasBlock = false; return ContinueWithNextNode; } default: break; } return ContinueWithCurrentNode; }
TableauDeRemplissage::TableauDeRemplissage(int idEvenement, QObject *parent) : Etat(tr("Tableau de remplissage"), idEvenement, parent) { QSqlQuery query; if (query.prepare("select *" " from tableau_de_remplissage" " where id_evenement=:id_evenement")) { query.bindValue(":id_evenement", idEvenement); if (query.exec()) { // FIXME : ce rapport devrait être une feuille de calcul QString symboleAcceptee = "●"; QString symboleProposee = "◍"; QString symbolePossible = "○"; QString symboleManquante = "◌"; QTextCursor c(this); QTextBlockFormat formatDuTitreDeLaLegende; formatDuTitreDeLaLegende.setBottomMargin(10); QTextCharFormat formatDesCaracteresDuTitreDeLaLegende; formatDesCaracteresDuTitreDeLaLegende.setUnderlineStyle(QTextCharFormat::SingleUnderline); QTextBlockFormat formatDesBlocsDeLaLegende; QTextCharFormat formatDesCaracteresDeLaLegende; QTextListFormat formatDeLaListeDeLaLegende; QTextBlockFormat formatDuBlocJour; formatDuBlocJour.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); formatDuBlocJour.setAlignment(Qt::AlignCenter); formatDuBlocJour.setBottomMargin(20); QTextCharFormat formatDesCaracteresDuJour; formatDesCaracteresDuJour.setFontCapitalization(QFont::Capitalize); formatDesCaracteresDuJour.setFontPointSize(14); formatDesCaracteresDuJour.setFontWeight(QFont::Bold); QTextBlockFormat formatDuBlocTour; formatDuBlocTour.setTopMargin(20); QTextCharFormat formatDesCaracteresDuTour; formatDesCaracteresDuTour.setFontWeight(QFont::Bold); QTextBlockFormat formatDuBlocDesResponsables; QTextCharFormat formatDesCaracteresDesResponsables; QTextBlockFormat formatDuBlocDuRemplissage; QTextCharFormat formatDesCaracteresDuRemplissage; if (query.first()) { c.movePosition(QTextCursor::End); c.insertBlock(formatDuTitreDeLaLegende, formatDesCaracteresDuTitreDeLaLegende); c.insertText(tr("Légende")); c.insertBlock(formatDesBlocsDeLaLegende, formatDesCaracteresDeLaLegende); c.insertList(formatDeLaListeDeLaLegende); c.insertText(tr("%1 affectation acceptée ou validée").arg(symboleAcceptee)); c.insertText("\n"); c.insertText(tr("%1 affectation proposée, en attente d'acceptation").arg(symboleProposee)); c.insertText("\n"); c.insertText(tr("%1 affectation possible, à proposer ou valider").arg(symbolePossible)); c.insertText("\n"); c.insertText(tr("%1 affectation manquante, reste à créer").arg(symboleManquante)); QSqlRecord r = query.record(); do { QDate jour = r.value("debut_tour").toDate(); c.insertBlock(formatDuBlocJour, formatDesCaracteresDuJour); c.insertText(QLocale().toString(jour)); do { int min = r.value("min").toInt(), max = r.value("max").toInt(), possibles = r.value("nombre_affectations_possibles").toInt(), proposees = r.value("nombre_affectations_proposees").toInt(), acceptees = r.value("nombre_affectations_validees_ou_acceptees").toInt(), trouvees = acceptees + proposees + possibles, manquantes = trouvees < min ? min - trouvees : 0, enTrop = max < trouvees ? trouvees - max : 0; QString responsables = r.value("liste_responsables").toString(); c.insertBlock(formatDuBlocTour, formatDesCaracteresDuTour); c.insertText(tr("De %1 à %2 / %3") .arg(r.value("debut_tour").toTime().toString("H:mm")) .arg(r.value("fin_tour").toTime().toString("H:mm")) .arg(r.value("nom_poste").toString()) ); if (!responsables.isEmpty()) { c.insertBlock(formatDuBlocDesResponsables, formatDesCaracteresDesResponsables); c.insertText(tr("Responsable(s) : %1").arg(responsables)); } c.insertBlock(formatDuBlocDuRemplissage, formatDesCaracteresDuRemplissage); c.insertText(symboleAcceptee.repeated(acceptees)); c.insertText(symboleProposee.repeated(proposees)); c.insertText(symbolePossible.repeated(possibles)); c.insertText(symboleManquante.repeated(manquantes)); if (enTrop) c.insertText(tr(" (%n affectation(s) en trop)", "", enTrop)); query.next(); r = query.record(); } while (query.isValid() && r.value("debut_tour").toDate() == jour); } while (query.isValid()); } else { qWarning() << tr("Aucune affectation trouvée"); } } else { qCritical() << query.lastError(); } } else { qCritical() << query.lastError(); } }
void CDiaryEdit::draw(QTextDocument& doc) { CDiaryEditLock lock(this); QFontMetrics fm(QFont(font().family(),10)); bool hasGeoCaches = false; int cnt; int w = doc.textWidth(); int pointSize = ((10 * (w - 2 * ROOT_FRAME_MARGIN)) / (CHAR_PER_LINE * fm.width("X"))); if(pointSize == 0) return; doc.setUndoRedoEnabled(false); QFont f = textEdit->font(); f.setPointSize(pointSize); textEdit->setFont(f); QTextCharFormat fmtCharHeading1; fmtCharHeading1.setFont(f); fmtCharHeading1.setFontWeight(QFont::Black); fmtCharHeading1.setFontPointSize(f.pointSize() + 8); QTextCharFormat fmtCharHeading2; fmtCharHeading2.setFont(f); fmtCharHeading2.setFontWeight(QFont::Black); fmtCharHeading2.setFontPointSize(f.pointSize() + 4); QTextCharFormat fmtCharStandard; fmtCharStandard.setFont(f); QTextCharFormat fmtCharHeader; fmtCharHeader.setFont(f); fmtCharHeader.setBackground(Qt::darkBlue); fmtCharHeader.setFontWeight(QFont::Bold); fmtCharHeader.setForeground(Qt::white); QTextBlockFormat fmtBlockStandard; fmtBlockStandard.setTopMargin(10); fmtBlockStandard.setBottomMargin(10); fmtBlockStandard.setAlignment(Qt::AlignJustify); QTextFrameFormat fmtFrameStandard; fmtFrameStandard.setTopMargin(5); fmtFrameStandard.setBottomMargin(5); fmtFrameStandard.setWidth(w - 2 * ROOT_FRAME_MARGIN); QTextFrameFormat fmtFrameRoot; fmtFrameRoot.setTopMargin(ROOT_FRAME_MARGIN); fmtFrameRoot.setBottomMargin(ROOT_FRAME_MARGIN); fmtFrameRoot.setLeftMargin(ROOT_FRAME_MARGIN); fmtFrameRoot.setRightMargin(ROOT_FRAME_MARGIN); QTextTableFormat fmtTableStandard; fmtTableStandard.setBorder(1); fmtTableStandard.setBorderBrush(Qt::black); fmtTableStandard.setCellPadding(4); fmtTableStandard.setCellSpacing(0); fmtTableStandard.setHeaderRowCount(1); fmtTableStandard.setTopMargin(10); fmtTableStandard.setBottomMargin(20); fmtTableStandard.setWidth(w - 2 * ROOT_FRAME_MARGIN); QVector<QTextLength> constraints; constraints << QTextLength(QTextLength::FixedLength, 32); constraints << QTextLength(QTextLength::VariableLength, 50); constraints << QTextLength(QTextLength::VariableLength, 100); fmtTableStandard.setColumnWidthConstraints(constraints); doc.rootFrame()->setFrameFormat(fmtFrameRoot); QTextCursor cursor = doc.rootFrame()->firstCursorPosition(); cursor.insertText(diary.getName(), fmtCharHeading1); cursor.setCharFormat(fmtCharStandard); cursor.setBlockFormat(fmtBlockStandard); diary.diaryFrame = cursor.insertFrame(fmtFrameStandard); { QTextCursor cursor1(diary.diaryFrame); cursor1.setCharFormat(fmtCharStandard); cursor1.setBlockFormat(fmtBlockStandard); if(diary.getComment().isEmpty()) { cursor1.insertText(tr("Add your own text here...")); } else { cursor1.insertHtml(diary.getComment()); } cursor.setPosition(cursor1.position()+1); } if(!diary.getWpts().isEmpty()) { QList<CWpt*>& wpts = diary.getWpts(); cursor.insertText(tr("Waypoints"),fmtCharHeading2); QTextTable * table = cursor.insertTable(wpts.count()+1, eMax, fmtTableStandard); diary.tblWpt = table; table->cellAt(0,eSym).setFormat(fmtCharHeader); table->cellAt(0,eInfo).setFormat(fmtCharHeader); table->cellAt(0,eComment).setFormat(fmtCharHeader); table->cellAt(0,eInfo).firstCursorPosition().insertText(tr("Info")); table->cellAt(0,eComment).firstCursorPosition().insertText(tr("Comment")); cnt = 1; qSort(wpts.begin(), wpts.end(), qSortWptLessTime); foreach(CWpt * wpt, wpts) { table->cellAt(cnt,eSym).firstCursorPosition().insertImage(wpt->getIcon().toImage().scaledToWidth(16, Qt::SmoothTransformation)); table->cellAt(cnt,eInfo).firstCursorPosition().insertText(wpt->getName() + "\n" + wpt->getInfo(), fmtCharStandard); QTextCursor c = table->cellAt(cnt,eComment).firstCursorPosition(); c.setCharFormat(fmtCharStandard); c.setBlockFormat(fmtBlockStandard); c.insertHtml(wpt->getComment()); if(wpt->isGeoCache()) { hasGeoCaches = true; } cnt++; }