void TestTableCellStyle::testMargin() { QTextTableFormat format1; format1.setProperty(QTextFormat::FrameLeftMargin, 4.0); format1.setProperty(QTextFormat::FrameRightMargin, 8.0); format1.setProperty(QTextFormat::FrameTopMargin, 9.0); format1.setProperty(QTextFormat::FrameBottomMargin, 3.0); KoTableStyle *style = new KoTableStyle(format1); QVERIFY(style); QCOMPARE(style->leftMargin(), 4.0); QCOMPARE(style->rightMargin(), 8.0); QCOMPARE(style->topMargin(), 9.0); QCOMPARE(style->bottomMargin(), 3.0); style->setLeftMargin(QTextLength(QTextLength::FixedLength, 14.0)); style->setRightMargin(QTextLength(QTextLength::FixedLength, 18.0)); style->setTopMargin(QTextLength(QTextLength::FixedLength, 19.0)); style->setBottomMargin(QTextLength(QTextLength::FixedLength, 13.0)); QTextTableFormat format2; style->applyStyle(format2); QCOMPARE(format2.doubleProperty(QTextFormat::FrameLeftMargin), 14.0); QCOMPARE(format2.doubleProperty(QTextFormat::FrameRightMargin), 18.0); QCOMPARE(format2.doubleProperty(QTextFormat::FrameTopMargin), 19.0); QCOMPARE(format2.doubleProperty(QTextFormat::FrameBottomMargin), 13.0); }
// 4) TRAINING void ResWaReport::BuildTrainingSection(QTextCursor& cursor) { cursor.movePosition(QTextCursor::End); cursor.insertBlock(); cursor.insertText("\n\n4) TRAINING & IN-SERVICES\n"); // VALUES int numTrainings; int numAttendingTrainings; CalculateTraining(numTrainings, numAttendingTrainings); // cursor.insertText("\t\t\t# of trainings: " + QString::number(numTrainings) + "\n"); // cursor.insertText("\t\t\t# attending trainings: " + QString::number(numAttendingTrainings) + "\n"); QTextTableFormat tableFormat; tableFormat.setHeaderRowCount(1); QVector<QTextLength> constraints; constraints << QTextLength(QTextLength::PercentageLength, 35); constraints << QTextLength(QTextLength::PercentageLength, 35); tableFormat.setColumnWidthConstraints(constraints); QTextTable *table = cursor.insertTable(2, 2, tableFormat); // HEADERS TextToCell(table, 0, 0, "# of trainings (observers)", &_tableTextFormat); TextToCell(table, 0, 1, "# attending trainings (all people in room)", &_tableTextFormat); // VALUES TextToCell(table, 1, 0, QString::number(numTrainings), &_tableCellBlue); TextToCell(table, 1, 1, QString::number(numAttendingTrainings), &_tableCellBlue); }
void TestStyles::testStyleInheritance() { KoParagraphStyle style1; style1.setTopMargin(QTextLength(QTextLength::FixedLength, 10.0)); QCOMPARE(style1.topMargin(), 10.0); KoParagraphStyle style2; style2.setParentStyle(&style1); QCOMPARE(style2.topMargin(), 10.0); style2.setTopMargin(QTextLength(QTextLength::FixedLength, 20.0)); QCOMPARE(style2.topMargin(), 20.0); QCOMPARE(style1.topMargin(), 10.0); style1.setTopMargin(QTextLength(QTextLength::FixedLength, 15.0)); QCOMPARE(style2.topMargin(), 20.0); QCOMPARE(style1.topMargin(), 15.0); style2.setTopMargin(QTextLength(QTextLength::FixedLength, 15.0)); // the same, resetting the difference. QCOMPARE(style2.topMargin(), 15.0); QCOMPARE(style1.topMargin(), 15.0); style1.setTopMargin(QTextLength(QTextLength::FixedLength, 12.0)); // parent, so both are affected QCOMPARE(style2.topMargin(), 12.0); QCOMPARE(style1.topMargin(), 12.0); }
void TestTableLayout::testTableWidth() { KoTableStyle *tableStyle = new KoTableStyle(); QVERIFY(tableStyle); initTestSimple(2, 2, tableStyle); /* * Fixed width. * * Rules: * - Table should have 1 rect. * - Width of this rect should be 60 pt (fixed). */ tableStyle->setWidth(QTextLength(QTextLength::FixedLength, 60.0)); QTextTableFormat tableFormat = m_table->format(); tableStyle->applyStyle(tableFormat); m_table->setFormat(tableFormat); m_layout->layout(); QCOMPARE(m_textLayout->m_tableLayout.m_tableLayoutData->m_tableRects.size(), 1); QCOMPARE(m_textLayout->m_tableLayout.m_tableLayoutData->m_tableRects.at(0).rect.width(), 60.0); /* * Relative width: * * Rules: * - Table should have 1 rect. * - Width of this rect should be 80 pt (40% of shape which is 200). */ tableStyle->setWidth(QTextLength(QTextLength::PercentageLength, 40.0)); tableStyle->applyStyle(tableFormat); m_table->setFormat(tableFormat); m_layout->layout(); QCOMPARE(m_textLayout->m_tableLayout.m_tableLayoutData->m_tableRects.size(), 1); QCOMPARE(m_textLayout->m_tableLayout.m_tableLayoutData->m_tableRects.at(0).rect.width(), 80.0); }
void TestStyles::testChangeParent() { KoParagraphStyle style1; style1.setTopMargin(QTextLength(QTextLength::FixedLength, 10.0)); KoParagraphStyle style2; style2.setTopMargin(QTextLength(QTextLength::FixedLength, 20.0)); style2.setParentStyle(&style1); QCOMPARE(style1.topMargin(), 10.0); QCOMPARE(style2.topMargin(), 20.0); KoParagraphStyle style3; style3.setParentStyle(&style1); QCOMPARE(style1.topMargin(), 10.0); QCOMPARE(style3.topMargin(), 10.0); // test that separating will leave the child with exactly the same dataset // as it had before the inheritance style3.setParentStyle(0); QCOMPARE(style1.topMargin(), 10.0); QCOMPARE(style3.topMargin(), 0.0); // we hadn't explicitly set the margin on style3 // test adding it to another will not destroy any data style3.setParentStyle(&style1); QCOMPARE(style1.topMargin(), 10.0); // from style1 QCOMPARE(style2.topMargin(), 20.0); // from style2 QCOMPARE(style3.topMargin(), 10.0); // inherited from style1 // Check that style3 now starts following the parent since it does not have // the property set style3.setParentStyle(&style2); QCOMPARE(style3.topMargin(), 20.0); // inherited from style2 }
void KDReports::Frame::build( ReportBuilder& builder ) const { // prepare the frame QTextFrameFormat format; if ( d->m_width ) { if ( d->m_widthUnit == Millimeters ) { format.setWidth( QTextLength( QTextLength::FixedLength, mmToPixels( d->m_width ) ) ); } else { format.setWidth( QTextLength( QTextLength::PercentageLength, d->m_width ) ); } } if ( d->m_height ) { if ( d->m_heightUnit == Millimeters ) { format.setHeight( QTextLength( QTextLength::FixedLength, mmToPixels( d->m_height ) ) ); } else { format.setHeight( QTextLength( QTextLength::PercentageLength, d->m_height ) ); } } format.setPadding( mmToPixels( padding() ) ); format.setBorder( d->m_border ); // TODO borderBrush like in AbstractTableElement format.setPosition( QTextFrameFormat::InFlow ); QTextCursor& textDocCursor = builder.cursor(); QTextFrame *frame = textDocCursor.insertFrame(format); QTextCursor contentsCursor = frame->firstCursorPosition(); ReportBuilder contentsBuilder( builder.currentDocumentData(), contentsCursor, builder.report() ); contentsBuilder.copyStateFrom( builder ); foreach( const KDReports::ElementData& ed, d->m_elements ) { switch ( ed.m_type ) { case KDReports::ElementData::Inline: contentsBuilder.addInlineElement( *ed.m_element ); break; case KDReports::ElementData::Block: contentsBuilder.addBlockElement( *ed.m_element, ed.m_align ); break; case KDReports::ElementData::Variable: contentsBuilder.addVariable( ed.m_variableType ); break; } } textDocCursor.movePosition( QTextCursor::End ); }
void TestTableLayout::testColumnWidthFixed() { KoTableStyle *tableStyle = new KoTableStyle; tableStyle->setWidth(QTextLength(QTextLength::FixedLength, 150.0)); setupTest("merged text", "top right text", "mid right text", "bottom left text", "bottom mid text", "bottom right text", tableStyle); KoTableColumnAndRowStyleManager styleManager = KoTableColumnAndRowStyleManager::getManager(m_table); KoTableColumnStyle column1style; column1style.setColumnWidth(2.3); styleManager.setColumnStyle(0, column1style); KoTableColumnStyle column2style; column2style.setColumnWidth(122.5); styleManager.setColumnStyle(1, column2style); KoTableColumnStyle column3style; column3style.setColumnWidth(362.9); styleManager.setColumnStyle(2, column3style); m_layout->layout(); QVERIFY(qAbs(QTextCursor(m_table->parentFrame()).block().layout()->lineAt(0).width() - 200.0) < ROUNDING); // table should grow to 200 QVERIFY(qAbs(mergedCellBlock().layout()->lineAt(0).width() - 124.8) < ROUNDING); QVERIFY(qAbs(topRightCellBlock().layout()->lineAt(0).width() - 362.9) < ROUNDING); QVERIFY(qAbs(bottomLeftCellBlock().layout()->lineAt(0).width() - 2.3) < ROUNDING); QVERIFY(qAbs(bottomMidCellBlock().layout()->lineAt(0).width() - 122.5) < ROUNDING); QVERIFY(qAbs(bottomRightCellBlock().layout()->lineAt(0).width() - 362.9) < ROUNDING); }
// TEXTCELL void PrinterVisitor::visitTextCellNodeBefore(TextCell *node) { if( !ignore_ || firstChild_ ) { ++currentTableRow_; table_->insertRows( currentTableRow_, 1 ); // first column QTextTableCell tableCell( table_->cellAt( currentTableRow_, 0 ) ); if( tableCell.isValid() ) { if( !node->ChapterCounterHtml().isNull() ) { QTextCursor cursor( tableCell.firstCursorPosition() ); cursor.insertFragment( QTextDocumentFragment::fromHtml( node->ChapterCounterHtml() )); } } // second column tableCell = table_->cellAt( currentTableRow_, 1 ); if( tableCell.isValid() ) { QTextCursor cursor( tableCell.firstCursorPosition() ); if( node->isViewExpression() ) { //view expression table QTextTableFormat tableFormatExpression; tableFormatExpression.setBorder( 0 ); tableFormatExpression.setColumns( 1 ); tableFormatExpression.setCellPadding( 2 ); // tableFormatExpression.setBackground( QColor(235, 235, 220) ); // 180, 180, 180 tableFormatExpression.setBackground( QColor(235, 0, 0) ); // 180, 180, 180 QVector<QTextLength> constraints; constraints << QTextLength(QTextLength::PercentageLength, 100); tableFormatExpression.setColumnWidthConstraints(constraints); cursor.insertTable( 1, 1, tableFormatExpression ); // QMessageBox::information(0,"uu2", node->text()); QString html = node->textHtml(); cursor.insertFragment( QTextDocumentFragment::fromHtml( html )); } else { QString html = node->textHtml(); html.remove( "file:///" ); printEditor_->document()->setTextWidth(700); cursor.insertFragment(QTextDocumentFragment::fromHtml( html )); // QMessageBox::information(0, "uu3", node->text()); } } if( firstChild_ ) firstChild_ = false; } }
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node) { static const int totalColumns = 3; if (node->height() == 1) { QTextBlockFormat blockFormat; QTextCharFormat charFormat; charFormat.setFontPointSize(11); charFormat.setFontWeight(QFont::Bold); cursor->insertBlock(blockFormat, charFormat); cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true))); QTextTableFormat tableFormat; tableFormat.setCellPadding(0); tableFormat.setCellSpacing(0); tableFormat.setBorder(0); QTextTable *table = cursor->insertTable(node->size() + 1, 2, tableFormat); for (int i = 0; i < node->size(); i++) { AbstractDecklistCardNode *card = dynamic_cast<AbstractDecklistCardNode *>(node->at(i)); QTextCharFormat cellCharFormat; cellCharFormat.setFontPointSize(9); QTextTableCell cell = table->cellAt(i, 0); cell.setFormat(cellCharFormat); QTextCursor cellCursor = cell.firstCursorPosition(); cellCursor.insertText(QString("%1 ").arg(card->getNumber())); cell = table->cellAt(i, 1); cell.setFormat(cellCharFormat); cellCursor = cell.firstCursorPosition(); cellCursor.insertText(card->getName()); } } else if (node->height() == 2) { QTextBlockFormat blockFormat; QTextCharFormat charFormat; charFormat.setFontPointSize(14); charFormat.setFontWeight(QFont::Bold); cursor->insertBlock(blockFormat, charFormat); cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true))); QTextTableFormat tableFormat; tableFormat.setCellPadding(10); tableFormat.setCellSpacing(0); tableFormat.setBorder(0); QVector<QTextLength> constraints; for (int i = 0; i < totalColumns; i++) constraints << QTextLength(QTextLength::PercentageLength, 100.0 / totalColumns); tableFormat.setColumnWidthConstraints(constraints); QTextTable *table = cursor->insertTable(1, totalColumns, tableFormat); for (int i = 0; i < node->size(); i++) { QTextCursor cellCursor = table->cellAt(0, (i * totalColumns) / node->size()).lastCursorPosition(); printDeckListNode(&cellCursor, dynamic_cast<InnerDecklistNode *>(node->at(i))); } } cursor->movePosition(QTextCursor::End); }
// 2) CALLS void ResWaReport::BuildCallsSection(QTextCursor& cursor) { cursor.movePosition(QTextCursor::End); cursor.insertBlock(); cursor.insertText("\n\n2) CALLS (Information, Intake, and Referal Calls)\n", _headerFormat); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); QTextTableFormat tableFormat; QVector<QTextLength> constraints; constraints << QTextLength(QTextLength::PercentageLength, 40); constraints << QTextLength(QTextLength::PercentageLength, 40); tableFormat.setColumnWidthConstraints(constraints); QTextTable *table = cursor.insertTable(1, 2, tableFormat); TextToCell(table, 0, 0, "Total calls", &_tableTextFormat); TextToCell(table, 0, 1, QString::number(_totalCalls), &_tableCellBlue); }
QTextTable *ChatAreaWidget::getMsgTable() { if (tableFrmt == nullptr) { tableFrmt = new QTextTableFormat(); tableFrmt->setCellSpacing(2); tableFrmt->setBorderStyle(QTextFrameFormat::BorderStyle_None); tableFrmt->setColumnWidthConstraints({QTextLength(QTextLength::FixedLength,nameWidth), QTextLength(QTextLength::FixedLength,2), QTextLength(QTextLength::PercentageLength,100), QTextLength(QTextLength::FixedLength,2), QTextLength(QTextLength::VariableLength,0)}); } QTextCursor tc = textCursor(); tc.movePosition(QTextCursor::End); QTextTable *chatTextTable = tc.insertTable(1, 5, *tableFrmt); return chatTextTable; }
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); }
void KDReports::AbstractTableElement::fillTableFormat( QTextTableFormat& tableFormat, QTextCursor& textDocCursor ) const { if ( d->m_width ) { if ( d->m_unit == Millimeters ) { tableFormat.setWidth( QTextLength( QTextLength::FixedLength, mmToPixels( d->m_width ) ) ); } else { tableFormat.setWidth( QTextLength( QTextLength::PercentageLength, d->m_width ) ); } } tableFormat.setBorder( border() ); #if QT_VERSION >= 0x040300 tableFormat.setBorderBrush( borderBrush() ); tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid ); #endif tableFormat.setCellPadding( mmToPixels( padding() ) ); tableFormat.setCellSpacing( -1 ); // HTML-like table borders look so old century if ( d->m_fontSpecified ) { QTextCharFormat charFormat = textDocCursor.charFormat(); charFormat.setFont( d->m_defaultFont ); textDocCursor.setCharFormat( charFormat ); } }
/*! * \author Anders Fernström * \date 2005-12-19 * * \brief The class constructor * * 2006-03-03 AF, Updated function so cells are printed in tables, * so chapter numbers can be added to the left of the text. This * change remade large part of this function (and the rest of the * class). */ PrinterVisitor::PrinterVisitor( QTextDocument* doc, QPrinter* printer ) : ignore_(false), firstChild_(true), closedCell_(0), currentTableRow_(0), printer_(printer) { printEditor_ = new QTextEdit(); printEditor_->setDocument( doc ); // set table format QTextTableFormat tableFormat; tableFormat.setBorder( 0 ); tableFormat.setColumns( 2 ); tableFormat.setCellPadding( 5 ); QVector<QTextLength> constraints; constraints << QTextLength(QTextLength::FixedLength, 50) << QTextLength(QTextLength::VariableLength, 620); tableFormat.setColumnWidthConstraints(constraints); // insert the table QTextCursor cursor = printEditor_->textCursor(); table_ = cursor.insertTable(1, 2, tableFormat); }
void CreateBlogMsg::addPostSplitter() { QTextBlockFormat f = ui.msgEdit->textCursor().blockFormat(); QTextBlockFormat f1 = f; f.setProperty( TextFormat::IsHtmlTagSign, true ); f.setProperty( QTextFormat::BlockTrailingHorizontalRulerWidth, QTextLength( QTextLength::PercentageLength, 80 ) ); if ( ui.msgEdit->textCursor().block().text().isEmpty() ) { ui.msgEdit->textCursor().mergeBlockFormat( f ); } else { ui.msgEdit->textCursor().insertBlock( f ); } ui.msgEdit->textCursor().insertBlock( f1 ); }
void ParagraphIndentSpacing::save(KoParagraphStyle *style) { // general note; we have to unset values by setting it to zero instead of removing the item // since this dialog may be used on a copy style, which will be applied later. And removing // items doesn't work for that. if (!m_textIndentInherited){ style->setTextIndent(QTextLength(QTextLength::FixedLength, widget.first->value())); } if (!m_leftMarginInherited){ style->setLeftMargin(QTextLength(QTextLength::FixedLength, widget.left->value())); } if (!m_rightMarginIngerited){ style->setRightMargin(QTextLength(QTextLength::FixedLength, widget.right->value())); } if (!m_topMarginInherited){ style->setTopMargin(QTextLength(QTextLength::FixedLength, widget.before->value())); } if (!m_bottomMarginInherited){ style->setBottomMargin(QTextLength(QTextLength::FixedLength, widget.after->value())); } if (!m_autoTextIndentInherited){ style->setAutoTextIndent(widget.autoTextIndent->isChecked()); } if (!m_spacingInherited) { style->setLineHeightAbsolute(0); // since it trumps percentage based line heights, unset it. style->setMinimumLineHeight(QTextLength(QTextLength::FixedLength, 0)); style->setLineSpacing(0); switch (widget.lineSpacing->currentIndex()) { case 0: style->setLineHeightPercent(120); break; case 1: style->setLineHeightPercent(180); break; case 2: style->setLineHeightPercent(240); break; case 3: style->setLineHeightPercent(widget.proportional->value()); break; case 4: if (widget.custom->value() == 0.0) { // then we need to save it differently. style->setLineHeightPercent(100); } else { style->setLineSpacing(widget.custom->value()); } break; case 5: style->setLineHeightAbsolute(widget.custom->value()); break; case 6: style->setMinimumLineHeight(QTextLength(QTextLength::FixedLength, widget.custom->value())); break; } style->setLineSpacingFromFont(widget.lineSpacing->currentIndex() != 5 && widget.useFont->isChecked()); } }
//----------fonction de construction du tableau type ------------------------------------------- QTextTableFormat ProduceDoc::myFormat(QTextTableFormat & tableFormat,QString & parametersForTableFormat){ QTextTableFormat table = tableFormat; QStringList parametersList = parametersForTableFormat.split(","); if (WarnDebugMessage) qDebug() << __FILE__ << QString::number(__LINE__) << " parametersList.size =" << QString::number(parametersList.size()) ; tableFormat .setBackground(QColor("#C0C0C0")); tableFormat .setAlignment(Qt::AlignCenter); tableFormat .setCellPadding(2); tableFormat .setCellSpacing(2); QVector<QTextLength> constraints; for(int i = 0;i < parametersList.size() ; i++){ if (WarnDebugMessage) qDebug() << __FILE__ << QString::number(__LINE__) << " parametersForTableFormat =" << parametersList[i] ; constraints << QTextLength(QTextLength::FixedLength, parametersList[i].toInt()); } tableFormat .setColumnWidthConstraints(constraints); return table; }
void KDReports::TextDocumentData::scaleFontsBy( qreal factor ) { QTextCursor cursor( m_document ); qreal currentPointSize = -1.0; QTextCursor lastCursor( m_document ); Q_FOREVER { qreal cursorFontPointSize = cursor.charFormat().fontPointSize(); //qDebug() << cursorFontPointSize << "last=" << currentPointSize << cursor.block().text() << "position=" << cursor.position(); if ( cursorFontPointSize != currentPointSize ) { if ( currentPointSize != -1.0 ) { setFontSizeHelper( lastCursor, cursor.position() - 1, currentPointSize, factor ); lastCursor.setPosition( cursor.position() - 1, QTextCursor::MoveAnchor ); } currentPointSize = cursorFontPointSize; } if ( cursor.atEnd() ) break; cursor.movePosition( QTextCursor::NextCharacter ); } if ( currentPointSize != -1.0 ) { setFontSizeHelper( lastCursor, cursor.position(), currentPointSize, factor ); } // Also adjust the padding in the cells so that it remains proportional, // and the column constraints. Q_FOREACH( QTextTable* table, m_tables ) { QTextTableFormat format = table->format(); format.setCellPadding( format.cellPadding() * factor ); QVector<QTextLength> constraints = format.columnWidthConstraints(); for ( int i = 0; i < constraints.size(); ++i ) { if ( constraints[i].type() == QTextLength::FixedLength ) { constraints[i] = QTextLength( QTextLength::FixedLength, constraints[i].rawValue() * factor ); } } format.setColumnWidthConstraints( constraints ); table->setFormat( format ); }
void TestTableLayout::testCellRowAndColumnSpanning() { KoTableStyle *tableStyle = new KoTableStyle(); QVERIFY(tableStyle); tableStyle->setWidth(QTextLength(QTextLength::FixedLength, 300)); initTestSimple(3, 3, tableStyle); QTextTableCell cell1 = m_table->cellAt(0, 0); m_table->mergeCells(0, 0, 2, 2); m_layout->layout(); cell1 = m_table->cellAt(0, 0); // We get it again, just in case. /* * Cell 0,0 rules: * x = 0 (no borders/margins/paddings) * y = 0 (no borders/margins/paddings) * width = 100*2 = 200 (column span 2) * height = 2 * 14.4 = 28.8 (row span 2) */ QCOMPARE(m_textLayout->m_tableLayout.cellBoundingRect(cell1), QRectF(0, 0, 200, 28.8)); cleanupTest(); }
/** "Help message" or "About" dialog box */ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : QDialog(parent), ui(new Ui::HelpMessageDialog) { ui->setupUi(this); QString version = tr("Beardcoin Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion()); /* On x86 add a bit specifier to the version so that users can distinguish between * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious. */ #if defined(__x86_64__) version += " " + tr("(%1-bit)").arg(64); #elif defined(__i386__ ) version += " " + tr("(%1-bit)").arg(32); #endif if (about) { setWindowTitle(tr("About Beardcoin Core")); /// HTML-format the license message from the core QString licenseInfo = QString::fromStdString(LicenseInfo()); QString licenseInfoHTML = licenseInfo; // Make URLs clickable QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2); uri.setMinimal(true); // use non-greedy matching licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>"); // Replace newlines with HTML breaks licenseInfoHTML.replace("\n\n", "<br><br>"); ui->aboutMessage->setTextFormat(Qt::RichText); ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); text = version + "\n" + licenseInfo; ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML); ui->aboutMessage->setWordWrap(true); ui->helpMessage->setVisible(false); } else { setWindowTitle(tr("Command-line options")); QString header = tr("Usage:") + "\n" + " beardcoin-qt [" + tr("command-line options") + "] " + "\n"; QTextCursor cursor(ui->helpMessage->document()); cursor.insertText(version); cursor.insertBlock(); cursor.insertText(header); cursor.insertBlock(); QString coreOptions = QString::fromStdString(HelpMessage(HMM_BITCOIN_QT)); text = version + "\n" + header + "\n" + coreOptions; QTextTableFormat tf; tf.setBorderStyle(QTextFrameFormat::BorderStyle_None); tf.setCellPadding(2); QVector<QTextLength> widths; widths << QTextLength(QTextLength::PercentageLength, 35); widths << QTextLength(QTextLength::PercentageLength, 65); tf.setColumnWidthConstraints(widths); QTextCharFormat bold; bold.setFontWeight(QFont::Bold); Q_FOREACH (const QString &line, coreOptions.split("\n")) { if (line.startsWith(" -")) { cursor.currentTable()->appendRows(1); cursor.movePosition(QTextCursor::PreviousCell); cursor.movePosition(QTextCursor::NextRow); cursor.insertText(line.trimmed()); cursor.movePosition(QTextCursor::NextCell); } else if (line.startsWith(" ")) { cursor.insertText(line.trimmed()+' '); } else if (line.size() > 0) { //Title of a group if (cursor.currentTable()) cursor.currentTable()->appendRows(1); cursor.movePosition(QTextCursor::Down); cursor.insertText(line.trimmed(), bold); cursor.insertTable(1, 2, tf); } } ui->helpMessage->moveCursor(QTextCursor::Start); ui->scrollArea->setVisible(false); ui->aboutLogo->setVisible(false); } }
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++; }
void ResWaReport::BuildCasesSection(QTextCursor& cursor) { CalculateCasesTable(); cursor.movePosition(QTextCursor::End); cursor.insertBlock(); QTextTableFormat tableFormat; tableFormat.setHeaderRowCount(1); QVector<QTextLength> constraints; constraints << QTextLength(QTextLength::PercentageLength, 15); constraints << QTextLength(QTextLength::PercentageLength, 7); constraints << QTextLength(QTextLength::PercentageLength, 7); constraints << QTextLength(QTextLength::PercentageLength, 7); constraints << QTextLength(QTextLength::PercentageLength, 7); constraints << QTextLength(QTextLength::PercentageLength, 7); constraints << QTextLength(QTextLength::PercentageLength, 7); constraints << QTextLength(QTextLength::PercentageLength, 7); constraints << QTextLength(QTextLength::PercentageLength, 7); constraints << QTextLength(QTextLength::PercentageLength, 7); constraints << QTextLength(QTextLength::PercentageLength, 7); constraints << QTextLength(QTextLength::PercentageLength, 7); constraints << QTextLength(QTextLength::PercentageLength, 7); constraints << QTextLength(QTextLength::PercentageLength, 7); tableFormat.setColumnWidthConstraints(constraints); QTextTable *table = cursor.insertTable(CasesTableRows, CasesTableCols, tableFormat); // HEADERS TextToCell(table, CT_TOTAL_CASES_SETTLED, 0, "Cases Settled"); TextToCell(table, CT_TOTAL_CASES_PERC, 0, "Percentage of Total Cases Settled"); TextToCell(table, 0, CT_H_PARENTING, "Parenting Plans"); TextToCell(table, 0, CT_H_DISOLUTION, "Dissolution"); TextToCell(table, 0, CT_H_FORECLOSURE, "Foreclosure"); TextToCell(table, 0, CT_H_TENANT, "Tenant Landlord"); TextToCell(table, 0, CT_H_BUSINESS, "Business"); TextToCell(table, 0, CT_H_WORKPLACE, "Workplace"); TextToCell(table, 0, CT_H_NEIGHBOR, "Neighbor"); TextToCell(table, 0, CT_H_VICTIM, "Victim Offender"); TextToCell(table, 0, CT_H_PARENT, "Parent Teen"); TextToCell(table, 0, CT_H_SCHOOL, "School"); TextToCell(table, 0, CT_H_ELDER, "Elder"); TextToCell(table, 0, CT_H_OTHER, "Other"); TextToCell(table, 0, CT_H_TOTAL, "Total"); // ROW INDICES TextToCell(table, CT_SMALL_CLAIMS , 0, "Small Claims Court Cases", nullptr, &_tableIndexDark); TextToCell(table, CT_SMALL_CLAIMS_SETTLED, 0, "Small Claims Court Cases Settled", nullptr, &_tableIndexDark); TextToCell(table, CT_SMALL_CLAIMS_PERC, 0, "Percentage of Small Claims Cases Settled", nullptr, &_tableIndexDark); TextToCell(table, CT_OTHER_DIST_COURT, 0, "Other District Court Cases"); TextToCell(table, CT_OTHER_DIST_COURT_SETTLED, 0, "Other District Court Cases Settled"); TextToCell(table, CT_OTHER_DIST_COURT_PERC, 0, "Percentage of District Court Cases Settled"); TextToCell(table, CT_JUVENIILE_COURT, 0, "Juvenile Court Cases", nullptr, &_tableIndexDark); TextToCell(table, CT_JUVENIILE_COURT_SETTLED, 0, "Juvenile Cases Settled", nullptr, &_tableIndexDark); TextToCell(table, CT_JUVENIILE_COURT_PERC, 0, "Percentage of Juvenile Cases Settled", nullptr, &_tableIndexDark); TextToCell(table, CT_SUPERIOR_COURT, 0, "Superior Court Cases"); TextToCell(table, CT_SUPERIOR_COURT_SETTLED, 0, "Superior Court Cases Settled"); TextToCell(table, CT_SUPERIOR_COURT_PERC, 0, "Percentage of Superior Cases Settled"); TextToCell(table, CT_OTHER_CASES, 0, "Other Cases", nullptr, &_tableIndexDark); TextToCell(table, CT_OTHER_CASES_SETTLED, 0, "Other Cases Settled", nullptr, &_tableIndexDark); TextToCell(table, CT_OTHER_CASES_PERC, 0, "Percentage of Other Cases Settled", nullptr, &_tableIndexDark); TextToCell(table, CT_TOTAL_CASES, 0, "Total Cases"); // POPULATE CELLS FROM MATRIX for (auto row = 1; row < CasesTableRows; ++row) for (auto col = 1; col < CasesTableCols; ++col) TextToCell(table, row, col, QString::number(_casesTable[row][col]),nullptr, &_tableCellBlue); }
void ResWaReport::BuildPeopleServedSection(QTextCursor& cursor) { CalculatePeople(); cursor.movePosition(QTextCursor::End); cursor.insertBlock(); cursor.insertText("\n\n5) People Served\n", _headerFormat); QTextTableFormat tableFormat; QVector<QTextLength> constraints; constraints << QTextLength(QTextLength::PercentageLength, 40); constraints << QTextLength(QTextLength::PercentageLength, 40); tableFormat.setColumnWidthConstraints(constraints); cursor.insertText("\nA. # of people served by telephone:\n", _headerFormat); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); QTextTable *table = cursor.insertTable(2, 2, tableFormat); // HEADERS TextToCell(table, 0, 0, "All People Directly Served", &_tableTextFormat); TextToCell(table, 1, 0, "Children Directly Served", &_tableTextFormat); // VALUES //JAS Per Rosemary's need to match #2 on report TextToCell(table, 0, 1, QString::number(_numDirectAdult), &_tableCellBlue); TextToCell(table, 1, 1, QString::number(_numChildByPhone), &_tableCellBlue); //TextToCell(table, 0, 1, QString::number(_numByPhone), &_tableCellBlue); //TextToCell(table, 1, 1, QString::number(_numChildByPhone), &_tableCellBlue); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); cursor.insertText("\n\nB. # of people served by conflict coaching:\n", _headerFormat); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); QTextTable *tableB = cursor.insertTable(2, 2, tableFormat); // HEADERS TextToCell(tableB, 0, 0, "All People Directly Served", &_tableTextFormat); TextToCell(tableB, 1, 0, "Children Directly Served", &_tableTextFormat); // VALUES TextToCell(tableB, 0, 1, QString::number(_numByCoaching), &_tableCellBlue); TextToCell(tableB, 1, 1, QString::number(_numChildByCoaching), &_tableCellBlue); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); cursor.insertText("\n\nC.# of people served by telephone concilliation:\n", _headerFormat); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); QTextTable *tableC = cursor.insertTable(2, 2, tableFormat); // HEADERS TextToCell(tableC, 0, 0, "All People Directly Served", &_tableTextFormat); TextToCell(tableC, 1, 0, "Children Directly Served", &_tableTextFormat); // VALUES TextToCell(tableC, 0, 1, QString::number(_numByPhoneConcilliation), &_tableCellBlue); TextToCell(tableC, 1, 1, QString::number(_numChildByPhoneConcilliation), &_tableCellBlue); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); cursor.insertText("\n\nD. # of people served by mediation sessions:\n", _headerFormat); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); QTextTable *tableD = cursor.insertTable(2, 2, tableFormat); // HEADERS TextToCell(tableD, 0, 0, "All People Directly Served", &_tableTextFormat); TextToCell(tableD, 1, 0, "Children Directly Served", &_tableTextFormat); // VALUES TextToCell(tableD, 0, 1, QString::number(_numBySessions), &_tableCellBlue); TextToCell(tableD, 1, 1, QString::number(_numChildBySessions), &_tableCellBlue); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); cursor.insertText("\n\nE. # of people served by facilliation sessions:\n", _headerFormat); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); QTextTable *tableE = cursor.insertTable(2, 2, tableFormat); // HEADERS TextToCell(tableE, 0, 0, "All People Directly Served", &_tableTextFormat); TextToCell(tableE, 1, 0, "Children Directly Served", &_tableTextFormat); // VALUES TextToCell(tableE, 0, 1, QString::number(_numBySessionFacilliation), &_tableCellBlue); TextToCell(tableE, 1, 1, QString::number(_numChildBySessionFacilliation), &_tableCellBlue); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); cursor.insertText("\n\nF. # of people INDIRECTLY served by phone, concilliation, mediation, facilliation:\n", _headerFormat); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); QTextTable *tableF = cursor.insertTable(2, 2, tableFormat); // HEADERS TextToCell(tableF, 0, 0, "All People Indirectly Served", &_tableTextFormat); TextToCell(tableF, 1, 0, "Children Indirectly Served", &_tableTextFormat); // VALUES TextToCell(tableF, 0, 1, QString::number(_numIndirectly), &_tableCellBlue); TextToCell(tableF, 1, 1, QString::number(_numChildIndirectly), &_tableCellBlue); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); cursor.insertText("\n\nG. # of people served by training and in-service:\n", _headerFormat); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); QTextTable *tableG = cursor.insertTable(2, 2, tableFormat); // HEADERS TextToCell(tableG, 0, 0, "All People Directly Served", &_tableTextFormat); TextToCell(tableG, 1, 0, "Children Directly Served", &_tableTextFormat); // VALUES TextToCell(tableG, 0, 1, QString::number(_numByTraining), &_tableCellBlue); TextToCell(tableG, 1, 1, QString::number(_numChildByTraining), &_tableCellBlue); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); cursor.insertText("\n\nH. # of additional people served:\n", _headerFormat); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); QTextTable *tableH = cursor.insertTable(2, 2, tableFormat); // HEADERS TextToCell(tableH, 0, 0, "All People Directly Served", &_tableTextFormat); TextToCell(tableH, 1, 0, "Children Directly Served", &_tableTextFormat); // VALUES TextToCell(tableH, 0, 1, QString::number(_numAdditionalServed), &_tableCellBlue); TextToCell(tableH, 1, 1, QString::number(_numChildAdditionalServed), &_tableCellBlue); }
void ResWaReport::BuildEvaluationSection(QTextCursor& cursor) { cursor.movePosition(QTextCursor::End); cursor.insertBlock(); cursor.insertText("\n\n8) Evaluations\n", _headerFormat); QTextTableFormat tableFormat; QVector<QTextLength> constraints; constraints << QTextLength(QTextLength::PercentageLength, 33); constraints << QTextLength(QTextLength::PercentageLength, 33); constraints << QTextLength(QTextLength::PercentageLength, 33); tableFormat.setColumnWidthConstraints(constraints); // fair cursor.insertBlock(); cursor.movePosition(QTextCursor::End); cursor.insertText("\n\n\tMediators fair and impartial?\n", _headerFormat); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); QTextTable *table1 = cursor.insertTable(3, 2, tableFormat); TextToCell(table1, 0, 0, "Yes", &_tableTextFormat); TextToCell(table1, 1, 0, "No", &_tableTextFormat); TextToCell(table1, 2, 0, "Somewhat", &_tableTextFormat); TextToCell(table1, 0, 1, QString::number(_q1Yes), &_tableCellBlue); TextToCell(table1, 1, 1, QString::number(_q1No), &_tableCellBlue); TextToCell(table1, 2, 1, QString::number(_q1Somewhat), &_tableCellBlue); // improved situation cursor.insertBlock(); cursor.movePosition(QTextCursor::End); cursor.insertText("\tSituation Improved By Mediation?\n", _headerFormat); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); QTextTable *table2 = cursor.insertTable(3, 2, tableFormat); TextToCell(table2, 0, 0, "Yes", &_tableTextFormat); TextToCell(table2, 1, 0, "No", &_tableTextFormat); TextToCell(table2, 2, 0, "Somewhat", &_tableTextFormat); TextToCell(table2, 0, 1, QString::number(_q2Yes), &_tableCellBlue); TextToCell(table2, 1, 1, QString::number(_q2No), &_tableCellBlue); TextToCell(table2, 2, 1, QString::number(_q2Somewhat), &_tableCellBlue); // helped you communicate cursor.insertBlock(); cursor.movePosition(QTextCursor::End); cursor.insertText("\tHelped to communicate with other party?\n", _headerFormat); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); QTextTable *table3 = cursor.insertTable(3, 2, tableFormat); TextToCell(table3, 0, 0, "Yes", &_tableTextFormat); TextToCell(table3, 1, 0, "No", &_tableTextFormat); TextToCell(table3, 2, 0, "Somewhat", &_tableTextFormat); TextToCell(table3, 0, 1, QString::number(_q3Yes), &_tableCellBlue); TextToCell(table3, 1, 1, QString::number(_q3No), &_tableCellBlue); TextToCell(table3, 2, 1, QString::number(_q3Somewhat), &_tableCellBlue); // helped understand other point view cursor.insertBlock(); cursor.movePosition(QTextCursor::End); cursor.insertText("\tHelped to better understand the issues?\n", _headerFormat); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); QTextTable *table4 = cursor.insertTable(3, 2, tableFormat); TextToCell(table4, 0, 0, "Yes", &_tableTextFormat); TextToCell(table4, 1, 0, "No", &_tableTextFormat); TextToCell(table4, 2, 0, "Somewhat", &_tableTextFormat); TextToCell(table4, 0, 1, QString::number(_q4Yes), &_tableCellBlue); TextToCell(table4, 1, 1, QString::number(_q4No), &_tableCellBlue); TextToCell(table4, 2, 1, QString::number(_q4Somewhat), &_tableCellBlue); // Would recommend to someone else cursor.insertBlock(); cursor.movePosition(QTextCursor::End); cursor.insertText("\tRecommend mediation to others?\n", _headerFormat); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); QTextTable *table5 = cursor.insertTable(3, 2, tableFormat); TextToCell(table5, 0, 0, "Yes", &_tableTextFormat); TextToCell(table5, 1, 0, "No", &_tableTextFormat); TextToCell(table5, 2, 0, "Somewhat", &_tableTextFormat); TextToCell(table5, 0, 1, QString::number(_q5Yes), &_tableCellBlue); TextToCell(table5, 1, 1, QString::number(_q5No), &_tableCellBlue); TextToCell(table5, 2, 1, QString::number(_q5Somewhat), &_tableCellBlue); // was agreement reached cursor.insertBlock(); cursor.movePosition(QTextCursor::End); cursor.insertText("\tDid you reach an agreement?\n", _headerFormat); cursor.insertBlock(); cursor.movePosition(QTextCursor::End); QTextTable *table6 = cursor.insertTable(3, 2, tableFormat); TextToCell(table6, 0, 0, "Yes", &_tableTextFormat); TextToCell(table6, 1, 0, "No", &_tableTextFormat); TextToCell(table6, 2, 0, "Somewhat", &_tableTextFormat); TextToCell(table6, 0, 1, QString::number(_q2Yes), &_tableCellBlue); TextToCell(table6, 1, 1, QString::number(_q2No), &_tableCellBlue); TextToCell(table6, 2, 1, QString::number(_q2Somewhat), &_tableCellBlue); }
MainWindow::MainWindow() { QMenu *fileMenu = new QMenu(tr("&File")); QAction *saveAction = fileMenu->addAction(tr("&Save...")); saveAction->setShortcut(tr("Ctrl+S")); QAction *quitAction = fileMenu->addAction(tr("E&xit")); quitAction->setShortcut(tr("Ctrl+Q")); QMenu *showMenu = new QMenu(tr("&Show")); QAction *showTableAction = showMenu->addAction(tr("&Table")); menuBar()->addMenu(fileMenu); menuBar()->addMenu(showMenu); editor = new QTextEdit(); //! [0] //! [1] QTextCursor cursor(editor->textCursor()); //! [0] cursor.movePosition(QTextCursor::Start); //! [1] int rows = 11; int columns = 4; //! [2] QTextTableFormat tableFormat; tableFormat.setBackground(QColor("#e0e0e0")); QVector<QTextLength> constraints; constraints << QTextLength(QTextLength::PercentageLength, 16); constraints << QTextLength(QTextLength::PercentageLength, 28); constraints << QTextLength(QTextLength::PercentageLength, 28); constraints << QTextLength(QTextLength::PercentageLength, 28); tableFormat.setColumnWidthConstraints(constraints); //! [3] QTextTable *table = cursor.insertTable(rows, columns, tableFormat); //! [2] //! [3] int column; int row; QTextTableCell cell; QTextCursor cellCursor; QTextCharFormat charFormat; charFormat.setForeground(Qt::black); //! [4] cell = table->cellAt(0, 0); cellCursor = cell.firstCursorPosition(); cellCursor.insertText(tr("Week"), charFormat); //! [4] //! [5] for (column = 1; column < columns; ++column) { cell = table->cellAt(0, column); cellCursor = cell.firstCursorPosition(); cellCursor.insertText(tr("Team %1").arg(column), charFormat); } for (row = 1; row < rows; ++row) { cell = table->cellAt(row, 0); cellCursor = cell.firstCursorPosition(); cellCursor.insertText(tr("%1").arg(row), charFormat); for (column = 1; column < columns; ++column) { if ((row-1) % 3 == column-1) { //! [5] //! [6] cell = table->cellAt(row, column); QTextCursor cellCursor = cell.firstCursorPosition(); cellCursor.insertText(tr("On duty"), charFormat); } //! [6] //! [7] } //! [7] //! [8] } //! [8] connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile())); connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); connect(showTableAction, SIGNAL(triggered()), this, SLOT(showTable())); setCentralWidget(editor); setWindowTitle(tr("Text Document Tables")); }
//! [5] void MainWindow::insertCalendar() { editor->clear(); QTextCursor cursor = editor->textCursor(); cursor.beginEditBlock(); QDate date(selectedDate.year(), selectedDate.month(), 1); //! [5] //! [6] QTextTableFormat tableFormat; tableFormat.setAlignment(Qt::AlignHCenter); tableFormat.setBackground(QColor("#e0e0e0")); tableFormat.setCellPadding(2); tableFormat.setCellSpacing(4); //! [6] //! [7] QVector<QTextLength> constraints; constraints << QTextLength(QTextLength::PercentageLength, 14) << QTextLength(QTextLength::PercentageLength, 14) << QTextLength(QTextLength::PercentageLength, 14) << QTextLength(QTextLength::PercentageLength, 14) << QTextLength(QTextLength::PercentageLength, 14) << QTextLength(QTextLength::PercentageLength, 14) << QTextLength(QTextLength::PercentageLength, 14); tableFormat.setColumnWidthConstraints(constraints); //! [7] //! [8] QTextTable *table = cursor.insertTable(1, 7, tableFormat); //! [8] //! [9] QTextFrame *frame = cursor.currentFrame(); QTextFrameFormat frameFormat = frame->frameFormat(); frameFormat.setBorder(1); frame->setFrameFormat(frameFormat); //! [9] //! [10] QTextCharFormat format = cursor.charFormat(); format.setFontPointSize(fontSize); QTextCharFormat boldFormat = format; boldFormat.setFontWeight(QFont::Bold); QTextCharFormat highlightedFormat = boldFormat; highlightedFormat.setBackground(Qt::yellow); //! [10] //! [11] for (int weekDay = 1; weekDay <= 7; ++weekDay) { QTextTableCell cell = table->cellAt(0, weekDay-1); //! [11] //! [12] QTextCursor cellCursor = cell.firstCursorPosition(); cellCursor.insertText(QString("%1").arg(QDate::longDayName(weekDay)), boldFormat); } //! [12] //! [13] table->insertRows(table->rows(), 1); //! [13] while (date.month() == selectedDate.month()) { int weekDay = date.dayOfWeek(); QTextTableCell cell = table->cellAt(table->rows()-1, weekDay-1); QTextCursor cellCursor = cell.firstCursorPosition(); if (date == QDate::currentDate()) cellCursor.insertText(QString("%1").arg(date.day()), highlightedFormat); else cellCursor.insertText(QString("%1").arg(date.day()), format); date = date.addDays(1); if (weekDay == 7 && date.month() == selectedDate.month()) table->insertRows(table->rows(), 1); } cursor.endEditBlock(); //! [14] setWindowTitle(tr("Calendar for %1 %2" ).arg(QDate::longMonthName(selectedDate.month()) ).arg(selectedDate.year())); }
void TestStyles::testUnapplyStyle() { // Used to test OverlineColor style QColor testOverlineColor(255, 128, 64); KoCharacterStyle::LineWeight testOverlineWeight = KoCharacterStyle::ThickLineWeight; qreal testOverlineWidth = 1.5; // in this test we should avoid testing any of the hardcodedDefaultProperties; see KoCharacterStyle for details! KoParagraphStyle headers; headers.setOverlineColor(testOverlineColor); headers.setOverlineMode(KoCharacterStyle::ContinuousLineMode); headers.setOverlineStyle(KoCharacterStyle::DottedLine); headers.setOverlineType(KoCharacterStyle::DoubleLine); headers.setOverlineWidth(testOverlineWeight, testOverlineWidth); headers.setFontWeight(QFont::Bold); headers.setAlignment(Qt::AlignCenter); KoParagraphStyle head1; head1.setParentStyle(&headers); head1.setLeftMargin(QTextLength(QTextLength::FixedLength, 40)); QTextDocument doc; doc.setPlainText("abc"); QTextBlock block = doc.begin(); head1.applyStyle(block); QTextCursor cursor(block); QTextBlockFormat bf = cursor.blockFormat(); KoParagraphStyle bfStyle (bf, cursor.charFormat()); QCOMPARE(bf.alignment(), Qt::AlignCenter); QCOMPARE(bfStyle.leftMargin(), 40.); QTextCharFormat cf = cursor.charFormat(); QCOMPARE(cf.colorProperty(KoCharacterStyle::OverlineColor), testOverlineColor); QCOMPARE(cf.intProperty(KoCharacterStyle::OverlineMode), (int) KoCharacterStyle::ContinuousLineMode); QCOMPARE(cf.intProperty(KoCharacterStyle::OverlineStyle), (int) KoCharacterStyle::DottedLine); QCOMPARE(cf.intProperty(KoCharacterStyle::OverlineType), (int) KoCharacterStyle::DoubleLine); QCOMPARE(cf.intProperty(KoCharacterStyle::OverlineWeight), (int) testOverlineWeight); QCOMPARE(cf.doubleProperty(KoCharacterStyle::OverlineWidth), testOverlineWidth); head1.unapplyStyle(block); bf = cursor.blockFormat(); QCOMPARE(bf.hasProperty(QTextFormat::BlockAlignment), false); QCOMPARE(bf.hasProperty(QTextFormat::BlockLeftMargin), false); cf = cursor.charFormat(); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineColor), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineMode), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineStyle), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineType), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineWeight), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineWidth), false); doc.clear(); block = doc.begin(); head1.applyStyle(block); bf = cursor.blockFormat(); KoParagraphStyle bfStyle2 (bf, cursor.charFormat()); QCOMPARE(bf.alignment(), Qt::AlignCenter); QCOMPARE(bfStyle2.leftMargin(), 40.); cf = cursor.charFormat(); //QCOMPARE(cf.fontOverline(), true); QCOMPARE(cf.colorProperty(KoCharacterStyle::OverlineColor), testOverlineColor); QCOMPARE(cf.intProperty(KoCharacterStyle::OverlineMode), (int) KoCharacterStyle::ContinuousLineMode); QCOMPARE(cf.intProperty(KoCharacterStyle::OverlineStyle), (int) KoCharacterStyle::DottedLine); QCOMPARE(cf.intProperty(KoCharacterStyle::OverlineType), (int) KoCharacterStyle::DoubleLine); QCOMPARE(cf.intProperty(KoCharacterStyle::OverlineWeight), (int) testOverlineWeight); QCOMPARE(cf.doubleProperty(KoCharacterStyle::OverlineWidth), testOverlineWidth); head1.unapplyStyle(block); bf = cursor.blockFormat(); QCOMPARE(bf.hasProperty(QTextFormat::BlockAlignment), false); QCOMPARE(bf.hasProperty(QTextFormat::BlockLeftMargin), false); cf = cursor.charFormat(); //QCOMPARE(cf.hasProperty(QTextFormat::FontOverline), false); doc.setHtml("bla bla<i>italic</i>enzo"); block = doc.begin(); head1.applyStyle(block); bf = cursor.blockFormat(); KoParagraphStyle bfStyle3(bf, cursor.charFormat()); QCOMPARE(bf.alignment(), Qt::AlignCenter); QCOMPARE(bfStyle3.leftMargin(), 40.); cf = cursor.charFormat(); //QCOMPARE(cf.fontOverline(), true); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineColor), true); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineMode), true); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineStyle), true); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineType), true); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineWeight), true); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineWidth), true); cursor.setPosition(7); cursor.setPosition(12, QTextCursor::KeepAnchor); QTextCharFormat italic; italic.setFontItalic(true); cursor.mergeCharFormat(italic); cursor.setPosition(8); cf = cursor.charFormat(); QCOMPARE(cf.fontItalic(), true); cursor.setPosition(0); head1.unapplyStyle(block); cursor.setPosition(0); bf = cursor.blockFormat(); QCOMPARE(bf.hasProperty(QTextFormat::BlockAlignment), false); QCOMPARE(bf.hasProperty(QTextFormat::BlockLeftMargin), false); cf = cursor.charFormat(); //QCOMPARE(cf.hasProperty(QTextFormat::FontOverline), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineColor), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineMode), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineStyle), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineType), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineWeight), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineWidth), false); cursor.setPosition(8); cf = cursor.charFormat(); //QCOMPARE(cf.hasProperty(QTextFormat::FontOverline), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineColor), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineMode), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineStyle), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineType), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineWeight), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineWidth), false); QCOMPARE(cf.fontItalic(), true); cursor.setPosition(12); cf = cursor.charFormat(); //QCOMPARE(cf.hasProperty(QTextFormat::FontOverline), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineColor), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineMode), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineStyle), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineType), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineWeight), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineWidth), false); QCOMPARE(cf.fontItalic(), true); cursor.setPosition(13); cf = cursor.charFormat(); //QCOMPARE(cf.hasProperty(QTextFormat::FontOverline), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineColor), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineMode), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineStyle), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineType), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineWeight), false); QCOMPARE(cf.hasProperty(KoCharacterStyle::OverlineWidth), false); QCOMPARE(cf.hasProperty(QTextFormat::FontWeight), false); QCOMPARE(cf.hasProperty(QTextFormat::FontItalic), false); }
TablePrintDialog::TablePrintDialog(QTableView *p_tableView, QPrinter * p_printer, QWidget *parent) : QDialog(parent) , tableView(p_tableView) , printer(p_printer) , gridMode(NoGrid) , lines(0) , pages(0) , leftMargin(80) , rightMargin(80) , topMargin(40) , bottomMargin(40) , spacing(4) , headerSize(60) , footerSize(60) , sceneZoomFactor(100) , columnZoomFactor(0.65) , rowHeight(0) , columnMultiplier(0) , model(tableView->model()) , titleFmt(NULL) , headerFmt(NULL) , fmt(NULL) { //setup printer printer->setFullPage(true); switch (QLocale::system().country()) { case QLocale::AnyCountry: case QLocale::Canada: case QLocale::UnitedStates: case QLocale::UnitedStatesMinorOutlyingIslands: printer->setPageSize(QPrinter::Letter); break; default: printer->setPageSize(QPrinter::A4); break; } setHeaderText("Document"); footerText=trUtf8("Page: "); //get column widths for (int i=0; i<model->columnCount(); i++) { int colWidth=tableView->columnWidth(i); colSizes.append(QTextLength(QTextLength::FixedLength,colWidth)); } //title font titleFont=tableView->font(); titleFont.setPointSize(24); titleFont.setBold(false); titleFont.setUnderline(false); titleFmt =new QFontMetrics(titleFont); //header font headerFont=tableView->font(); headerFont.setBold(true); headerFont.setUnderline(true); headerFont.setPointSize(9); headerFmt =new QFontMetrics(headerFont); //normal font font=tableView->font(); headerFont.setPointSize(9); fmt = new QFontMetrics(font); QString date=QDate::currentDate().toString(QLocale().dateFormat()); QString time=QTime::currentTime().toString(QLocale().timeFormat(QLocale::ShortFormat)); headerStdText = date+" "+time; setupPage(); columnMultiplier=pageScene.width()/tableView->width()*columnZoomFactor; }
bool PriceListPrinter::printODT( PriceListPrinter::PrintPriceItemsOption printOption, const QList<int> &fieldsToPrint, int priceDataSetToPrintInput, bool printPriceList, bool printPriceAP, bool APgroupPrAm, const QString &fileName, double pageWidth, double pageHeight, Qt::Orientation paperOrientation) { double borderWidth = 1.0f; if( m_d->priceList ){ int priceDataSetToPrint = 0; // controlliamo se il valore di input è corretto if( priceDataSetToPrintInput >= 0 && priceDataSetToPrintInput < m_d->priceList->priceDataSetCount() ){ priceDataSetToPrint = priceDataSetToPrintInput; } QTextDocument doc; QTextCursor cursor(&doc); if( paperOrientation == Qt::Horizontal ){ if( pageHeight > pageWidth ){ double com = pageHeight; pageHeight = pageWidth; pageWidth = com; } } else { if( pageHeight < pageWidth ){ double com = pageHeight; pageHeight = pageWidth; pageWidth = com; } } double margin = 10.0; double tableWidth = pageWidth - 2.0 * margin; QTextCharFormat headerBlockCharFormat; headerBlockCharFormat.setFontCapitalization( QFont::AllUppercase ); headerBlockCharFormat.setFontWeight( QFont::Bold ); QTextBlockFormat headerBlockFormat; headerBlockFormat.setAlignment( Qt::AlignHCenter ); QTextBlockFormat headerWithPBBlockFormat = headerBlockFormat; headerWithPBBlockFormat.setPageBreakPolicy( QTextFormat::PageBreak_AlwaysBefore ); QTextBlockFormat parBlockFormat; if( printPriceList ){ cursor.setBlockFormat( headerWithPBBlockFormat ); cursor.setBlockCharFormat( headerBlockCharFormat ); cursor.insertText( m_d->priceList->name() ); cursor.insertBlock( headerBlockFormat ); cursor.setBlockCharFormat( headerBlockCharFormat ); cursor.insertText(QObject::trUtf8("Elenco Prezzi") ); cursor.insertBlock( parBlockFormat ); QTextTableFormat tableFormat; tableFormat.setCellPadding(5); tableFormat.setHeaderRowCount(2); tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid); tableFormat.setWidth( QTextLength( QTextLength::FixedLength, tableWidth ) ); QVector<QTextLength> colWidths; if( paperOrientation == Qt::Horizontal ){ double descColWidth = tableWidth - ( 30.0 + 20.0 + 35.0 * fieldsToPrint.size() ); colWidths << QTextLength( QTextLength::FixedLength, 30.0 ) << QTextLength( QTextLength::FixedLength, descColWidth ) << QTextLength( QTextLength::FixedLength, 20.0 ); for( int i=0; i < fieldsToPrint.size(); ++i ){ colWidths << QTextLength( QTextLength::FixedLength, 35.0 ); } } else { double descColWidth = tableWidth - ( 25.0 + 15.0 + 30.0 * fieldsToPrint.size() ); colWidths << QTextLength( QTextLength::FixedLength, 25.0 ) << QTextLength( QTextLength::FixedLength, descColWidth ) << QTextLength( QTextLength::FixedLength, 15.0 ); for( int i=0; i < fieldsToPrint.size(); ++i ){ colWidths << QTextLength( QTextLength::FixedLength, 30.0 ); } } tableFormat.setColumnWidthConstraints( colWidths ); tableFormat.setHeaderRowCount( 2 ); cursor.insertTable(1, colWidths.size(), tableFormat); m_d->priceList->writeODTOnTable( &cursor, printOption, fieldsToPrint, priceDataSetToPrint ); cursor.movePosition( QTextCursor::End ); } if( printPriceAP ){ bool firstAP=true; QList<PriceItem *> priceItemList = m_d->priceList->priceItemList(); for( int i=0; i < priceItemList.size(); ++i ){ if( (!priceItemList.at(i)->hasChildren()) && (priceItemList.at(i)->associateAP(priceDataSetToPrint)) ){ if( firstAP ){ if( printPriceList ){ // abbiamo stampato già l'elenco prezzi cursor.insertBlock( headerWithPBBlockFormat ); } else { // printData == DataAP // non abbiamo stampato l'elenco prezzi cursor.setBlockFormat( headerWithPBBlockFormat ); } cursor.setBlockCharFormat( headerBlockCharFormat ); cursor.insertText( m_d->priceList->name() ); cursor.insertBlock( headerBlockFormat ); cursor.setBlockCharFormat( headerBlockCharFormat ); cursor.insertText(QObject::trUtf8("Analisi Prezzi") ); cursor.insertBlock( parBlockFormat ); firstAP = false; } else { cursor.insertBlock( headerWithPBBlockFormat ); cursor.insertText( QString() ); cursor.insertBlock( parBlockFormat ); } QTextTableCellFormat topLeftFormat; topLeftFormat.setProperty( QTextFormatUserDefined::TableCellBorderLeftStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) ); topLeftFormat.setProperty( QTextFormatUserDefined::TableCellBorderLeftWidth, QVariant(borderWidth) ); topLeftFormat.setProperty( QTextFormatUserDefined::TableCellBorderTopStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) ); topLeftFormat.setProperty( QTextFormatUserDefined::TableCellBorderTopWidth, QVariant(borderWidth) ); QTextTableCellFormat topRightFormat; topRightFormat.setProperty( QTextFormatUserDefined::TableCellBorderRightStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) ); topRightFormat.setProperty( QTextFormatUserDefined::TableCellBorderRightWidth, QVariant(borderWidth) ); topRightFormat.setProperty( QTextFormatUserDefined::TableCellBorderTopStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) ); topRightFormat.setProperty( QTextFormatUserDefined::TableCellBorderTopWidth, QVariant(borderWidth) ); QTextTableCellFormat bottomFormat; bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderLeftStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) ); bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderLeftWidth, QVariant(borderWidth) ); bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderRightStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) ); bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderRightWidth, QVariant(borderWidth) ); bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderBottomStyle, QVariant(QTextFrameFormat::BorderStyle_Solid) ); bottomFormat.setProperty( QTextFormatUserDefined::TableCellBorderBottomWidth, QVariant(borderWidth) ); // tabella con informazioni generali sul prezzo // descrizione, codice, etc QTextTableFormat tableFormat; tableFormat.setCellPadding(5); tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid); tableFormat.setWidth( QTextLength( QTextLength::FixedLength, tableWidth ) ); QVector<QTextLength> colWidths; colWidths << QTextLength( QTextLength::FixedLength, 25 ) << QTextLength( QTextLength::FixedLength, pageWidth-2.0*margin - 25 ); tableFormat.setColumnWidthConstraints( colWidths ); QTextTable * table = cursor.insertTable(1, colWidths.size(), tableFormat); table->cellAt( cursor ).setFormat( topLeftFormat ); cursor.insertText( priceItemList.at(i)->codeFull() ); cursor.movePosition(QTextCursor::NextCell); table->cellAt( cursor ).setFormat( topRightFormat ); cursor.insertText( priceItemList.at(i)->shortDescriptionFull() ); table->appendRows(1); table->mergeCells( 1, 0, 1, 2 ); cursor.movePosition(QTextCursor::PreviousRow ); cursor.movePosition(QTextCursor::NextCell ); table->cellAt( cursor ).setFormat( bottomFormat ); cursor.insertText( priceItemList.at(i)->longDescriptionFull() ); cursor.movePosition( QTextCursor::End ); // tabella con l'analisi prezzi vera e propria tableFormat.setCellPadding(5); tableFormat.setHeaderRowCount(2); tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid); tableFormat.setWidth( QTextLength( QTextLength::FixedLength, tableWidth ) ); colWidths.clear(); if( paperOrientation == Qt::Horizontal ){ if( fieldsToPrint.size() > 0 ){ colWidths << QTextLength( QTextLength::FixedLength, 10.0 ) << QTextLength( QTextLength::FixedLength, 30.0 ) << QTextLength( QTextLength::FixedLength, 70.0 ) << QTextLength( QTextLength::FixedLength, 20.0 ); double usedWidth = 10.0 + 30.0 + 70.0 + 20.0; double colEqualWidth = (tableWidth - usedWidth ) / (1 + 2*fieldsToPrint.size() ); for( int i=0; i < (1 + 2*fieldsToPrint.size() ); ++i ){ colWidths << QTextLength( QTextLength::FixedLength, colEqualWidth ); } } else { // fieldsToPrint.size() == 0 if( fieldsToPrint.size() > 1 ){ double descWidth = tableWidth - (10.0 + 30.0 + 20.0 + 30.0); colWidths << QTextLength( QTextLength::FixedLength, 10.0 ) << QTextLength( QTextLength::FixedLength, 30.0 ) << QTextLength( QTextLength::FixedLength, descWidth ) << QTextLength( QTextLength::FixedLength, 20.0 ) << QTextLength( QTextLength::FixedLength, 30.0 ); } } } else { if( fieldsToPrint.size() > 0 ){ double usedWidth = 0.0; if( fieldsToPrint.size() > 1 ){ colWidths << QTextLength( QTextLength::FixedLength, 10.0 ) << QTextLength( QTextLength::FixedLength, 20.0 ) << QTextLength( QTextLength::FixedLength, 45.0 ) << QTextLength( QTextLength::FixedLength, 15.0 ); usedWidth = 10.0 + 20.0 + 45.0 + 15.0; } else { // fieldsToPrint.size() == 1 colWidths << QTextLength( QTextLength::FixedLength, 10.0 ) << QTextLength( QTextLength::FixedLength, 25.0 ) << QTextLength( QTextLength::FixedLength, 65.0 ) << QTextLength( QTextLength::FixedLength, 15.0 ); usedWidth = 10.0 + 25.0 + 65.0 + 15.0; } double colEqualWidth = (tableWidth - usedWidth ) / (1 + 2*fieldsToPrint.size() ); for( int i=0; i < (1 + 2*fieldsToPrint.size() ); ++i ){ colWidths << QTextLength( QTextLength::FixedLength, colEqualWidth ); } } else { // fieldsToPrint.size() == 0 if( fieldsToPrint.size() > 1 ){ double descWidth = tableWidth - (10.0 + 30.0 + 20.0 + 30.0); colWidths << QTextLength( QTextLength::FixedLength, 10.0 ) << QTextLength( QTextLength::FixedLength, 30.0 ) << QTextLength( QTextLength::FixedLength, descWidth ) << QTextLength( QTextLength::FixedLength, 20.0 ) << QTextLength( QTextLength::FixedLength, 30.0 ); } } } tableFormat.setColumnWidthConstraints( colWidths ); tableFormat.setHeaderRowCount( 2 ); cursor.insertTable(1, colWidths.size(), tableFormat); BillPrinter::PrintBillItemsOption billPrItemsOption = BillPrinter::PrintShortDesc; if( printOption == PriceListPrinter::PrintShortDesc ){ billPrItemsOption = BillPrinter::PrintShortDesc; } else if( printOption == PriceListPrinter::PrintLongDesc ){ billPrItemsOption = BillPrinter::PrintLongDesc; } else if( printOption == PriceListPrinter::PrintShortLongDesc ){ billPrItemsOption = BillPrinter::PrintShortLongDesc; } else if( printOption == PriceListPrinter::PrintShortLongDescOpt ){ billPrItemsOption = BillPrinter::PrintShortLongDescOpt; } priceItemList.at(i)->associatedAP(priceDataSetToPrint)->writeODTBillOnTable( &cursor, billPrItemsOption, fieldsToPrint, APgroupPrAm ); cursor.movePosition( QTextCursor::End ); } } } QFile *file = new QFile(fileName); QString suf = QFileInfo(file->fileName()).suffix().toLower().toLatin1(); if (suf == "odf" || suf == "opendocumentformat" || suf == "odt") { OdtWriter writer(doc, file); writer.setPageSizeMM( pageWidth, pageHeight ); writer.setMarginsMM( margin, margin, margin, margin ); writer.setPageOrientation( paperOrientation ); // writer.setCodec(codec); return writer.writeAll(); } } return false; }
/** "Help message" or "About" dialog box */ HelpMessageDialog::HelpMessageDialog(QWidget *parent, HelpMode helpMode) : QDialog(parent), ui(new Ui::HelpMessageDialog) { ui->setupUi(this); QString version = tr("Terracoin Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion()); /* On x86 add a bit specifier to the version so that users can distinguish between * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious. */ #if defined(__x86_64__) version += " " + tr("(%1-bit)").arg(64); #elif defined(__i386__ ) version += " " + tr("(%1-bit)").arg(32); #endif if (helpMode == about) { setWindowTitle(tr("About Terracoin Core")); /// HTML-format the license message from the core QString licenseInfo = QString::fromStdString(LicenseInfo()); QString licenseInfoHTML = licenseInfo; // Make URLs clickable QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2); uri.setMinimal(true); // use non-greedy matching licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>"); // Replace newlines with HTML breaks licenseInfoHTML.replace("\n\n", "<br><br>"); ui->aboutMessage->setTextFormat(Qt::RichText); ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); text = version + "\n" + licenseInfo; ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML); ui->aboutMessage->setWordWrap(true); ui->helpMessage->setVisible(false); } else if (helpMode == cmdline) { setWindowTitle(tr("Command-line options")); QString header = tr("Usage:") + "\n" + " terracoin-qt [" + tr("command-line options") + "] " + "\n"; QTextCursor cursor(ui->helpMessage->document()); cursor.insertText(version); cursor.insertBlock(); cursor.insertText(header); cursor.insertBlock(); std::string strUsage = HelpMessage(HMM_BITCOIN_QT); const bool showDebug = GetBoolArg("-help-debug", false); strUsage += HelpMessageGroup(tr("UI Options:").toStdString()); if (showDebug) { strUsage += HelpMessageOpt("-allowselfsignedrootcertificates", strprintf("Allow self signed root certificates (default: %u)", DEFAULT_SELFSIGNED_ROOTCERTS)); } strUsage += HelpMessageOpt("-choosedatadir", strprintf(tr("Choose data directory on startup (default: %u)").toStdString(), DEFAULT_CHOOSE_DATADIR)); strUsage += HelpMessageOpt("-lang=<lang>", tr("Set language, for example \"de_DE\" (default: system locale)").toStdString()); strUsage += HelpMessageOpt("-min", tr("Start minimized").toStdString()); strUsage += HelpMessageOpt("-rootcertificates=<file>", tr("Set SSL root certificates for payment request (default: -system-)").toStdString()); strUsage += HelpMessageOpt("-splash", strprintf(tr("Show splash screen on startup (default: %u)").toStdString(), DEFAULT_SPLASHSCREEN)); strUsage += HelpMessageOpt("-resetguisettings", tr("Reset all settings changed in the GUI").toStdString()); if (showDebug) { strUsage += HelpMessageOpt("-uiplatform", strprintf("Select platform to customize UI for (one of windows, macosx, other; default: %s)", BitcoinGUI::DEFAULT_UIPLATFORM)); } QString coreOptions = QString::fromStdString(strUsage); text = version + "\n" + header + "\n" + coreOptions; QTextTableFormat tf; tf.setBorderStyle(QTextFrameFormat::BorderStyle_None); tf.setCellPadding(2); QVector<QTextLength> widths; widths << QTextLength(QTextLength::PercentageLength, 35); widths << QTextLength(QTextLength::PercentageLength, 65); tf.setColumnWidthConstraints(widths); QTextCharFormat bold; bold.setFontWeight(QFont::Bold); Q_FOREACH (const QString &line, coreOptions.split("\n")) { if (line.startsWith(" -")) { cursor.currentTable()->appendRows(1); cursor.movePosition(QTextCursor::PreviousCell); cursor.movePosition(QTextCursor::NextRow); cursor.insertText(line.trimmed()); cursor.movePosition(QTextCursor::NextCell); } else if (line.startsWith(" ")) { cursor.insertText(line.trimmed()+' '); } else if (line.size() > 0) { //Title of a group if (cursor.currentTable()) cursor.currentTable()->appendRows(1); cursor.movePosition(QTextCursor::Down); cursor.insertText(line.trimmed(), bold); cursor.insertTable(1, 2, tf); } } ui->helpMessage->moveCursor(QTextCursor::Start); ui->scrollArea->setVisible(false); ui->aboutLogo->setVisible(false); } else if (helpMode == pshelp) {