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; }
bool KoReportODTRenderer::render(const KoReportRendererContext& context, ORODocument* document, int /*page*/) { QTextTableFormat tableFormat; tableFormat.setCellPadding(5); tableFormat.setHeaderRowCount(1); tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid); tableFormat.setWidth(QTextLength(QTextLength::PercentageLength, 100)); QTextTable *table = m_cursor.insertTable(1, 1, tableFormat); long renderedSections = 0; for (long s = 0; s < document->sections(); s++) { OROSection *section = document->section(s); section->sortPrimatives(OROSection::SortX); if (section->type() == KRSectionData::GroupHeader || section->type() == KRSectionData::GroupFooter || section->type() == KRSectionData::ReportHeader || section->type() == KRSectionData::ReportFooter || section->type() == KRSectionData::Detail){ //Add this section to the document //Resize the table to accommodate all the primitives in the section if (table->columns() < section->primitives()) { table->appendColumns(section->primitives() - table->columns()); } if (renderedSections > 0) { //We need to back a row, then forward a row to get at the start cell m_cursor.movePosition(QTextCursor::PreviousRow); m_cursor.movePosition(QTextCursor::NextRow); } else { //On the first row, ensure we are in the first cell after expanding the table while (m_cursor.movePosition(QTextCursor::PreviousCell)){} } //Render the objects in each section for (int i = 0; i < section->primitives(); i++) { //Colour the cell using hte section background colour OROPrimitive * prim = section->primitive(i); QTextTableCell cell = table->cellAt(m_cursor); QTextCharFormat format = cell.format(); format.setBackground(section->backgroundColor()); cell.setFormat(format); if (prim->type() == OROTextBox::TextBox) { OROTextBox * tb = (OROTextBox*) prim; m_cursor.insertText(tb->text()); } else if (prim->type() == OROImage::Image) { OROImage * im = (OROImage*) prim; m_cursor.insertImage(im->image().scaled(im->size().width(), im->size().height(), Qt::KeepAspectRatio)); } else if (prim->type() == OROPicture::Picture) { OROPicture * im = (OROPicture*) prim; QImage image(im->size().toSize(), QImage::Format_RGB32); QPainter painter(&image); im->picture()->play(&painter); m_cursor.insertImage(image); } else { kWarning() << "unhandled primitive type"; } m_cursor.movePosition(QTextCursor::NextCell); } if (s < document->sections() - 1) { table->appendRows(1); } renderedSections++; } } QTextDocumentWriter writer(context.destinationUrl.toLocalFile()); return writer.write(m_document); }
/** "Help message" or "About" dialog box */ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : QDialog(parent), ui(new Ui::HelpMessageDialog) { ui->setupUi(this); GUIUtil::restoreWindowGeometry("nHelpMessageDialogWindow", this->size(), this); QString version = tr("Unobtanium 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 Unobtanium 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")); QTextCursor cursor(ui->helpMessage->document()); cursor.insertText(version); cursor.insertBlock(); cursor.insertText(tr("Usage:") + '\n' + " bitcoin-qt [" + tr("command-line options") + "]\n"); cursor.insertBlock(); 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); QTextTable *table = cursor.insertTable(2, 2, tf); QString coreOptions = QString::fromStdString(HelpMessage(HMM_BITCOIN_QT)); bool first = true; QTextCharFormat bold; bold.setFontWeight(QFont::Bold); // note that coreOptions is not translated. foreach (const QString &line, coreOptions.split('\n')) { if (!first) { table->appendRows(1); cursor.movePosition(QTextCursor::NextRow); } first = false; if (line.startsWith(" ")) { int index = line.indexOf(' ', 3); if (index > 0) { cursor.insertText(line.left(index).trimmed()); cursor.movePosition(QTextCursor::NextCell); cursor.insertText(line.mid(index).trimmed()); continue; } } cursor.movePosition(QTextCursor::NextCell, QTextCursor::KeepAnchor); table->mergeCells(cursor); cursor.insertText(line.trimmed(), bold); } table->appendRows(6); cursor.movePosition(QTextCursor::NextRow); cursor.insertText(tr("UI options") + ":", bold); cursor.movePosition(QTextCursor::NextRow); if (GetBoolArg("-help-debug", false)) { cursor.insertText("-allowselfsignedrootcertificates"); cursor.movePosition(QTextCursor::NextCell); cursor.insertText(tr("Allow self signed root certificates (default: 0)")); cursor.movePosition(QTextCursor::NextCell); } cursor.insertText("-choosedatadir"); cursor.movePosition(QTextCursor::NextCell); cursor.insertText(tr("Choose data directory on startup (default: 0)")); cursor.movePosition(QTextCursor::NextCell); cursor.insertText("-lang=<lang>"); cursor.movePosition(QTextCursor::NextCell); cursor.insertText(tr("Set language, for example \"de_DE\" (default: system locale)")); cursor.movePosition(QTextCursor::NextCell); cursor.insertText("-min"); cursor.movePosition(QTextCursor::NextCell); cursor.insertText(tr("Start minimized")); cursor.movePosition(QTextCursor::NextCell); cursor.insertText("-rootcertificates=<file>"); cursor.movePosition(QTextCursor::NextCell); cursor.insertText(tr("Set SSL root certificates for payment request (default: -system-)")); cursor.movePosition(QTextCursor::NextCell); cursor.insertText("-splash"); cursor.movePosition(QTextCursor::NextCell); cursor.insertText(tr("Show splash screen on startup (default: 1)")); ui->helpMessage->moveCursor(QTextCursor::Start); ui->scrollArea->setVisible(false); ui->aboutLogo->setVisible(false); } }
bool OutputQtDocument::writeTable() { /* start of table */ m_cursor.beginEditBlock(); m_cursor.insertBlock(); m_cursor.insertBlock(); QTextFrame *topFrame = m_cursor.currentFrame(); QTextTableFormat tableFormat; tableFormat.setCellPadding(4); tableFormat.setHeaderRowCount(1); /* tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Double); */ tableFormat.setMargin(2); tableFormat.setWidth(QTextLength( QTextLength::PercentageLength, 100)); QTextTable *table = m_cursor.insertTable( m_params->height()+2, m_params->width()+5, tableFormat); /* headers */ m_cursor = table->cellAt(0, 0).firstCursorPosition(); m_cursor.insertText("i"); m_cursor = table->cellAt(0, 1).firstCursorPosition(); m_cursor.insertText(tr("basis")); m_cursor = table->cellAt(0, 2).firstCursorPosition(); m_cursor.insertHtml("C<sub>i</sub> "); m_cursor = table->cellAt(0, 3).firstCursorPosition(); m_cursor.insertText("B"); for(size_t j=0; j < m_params->width(); j++) { m_cursor = table->cellAt(0, j+4).firstCursorPosition(); m_cursor.insertHtml(QString("P<sub>%1</sub> ").arg(j+1)); /* m_cursor.insertHtml(QString("C<sub>%1</sub> =").arg(j+1)); if(m_params->variableType(j) == SimplexMethod::VariableArtificial) m_cursor.insertText("W"); else m_cursor.insertText(formatDouble(m_params->rowC(j))); */ } m_cursor = table->cellAt(0, m_params->width()+4).firstCursorPosition(); m_cursor.insertText(QChar(0x0398)); // theta /* matrix, columnCompareOp, columnB, columnTheta */ for(size_t i=0; i < m_params->height(); i++) { m_cursor = table->cellAt(i+1, 0).firstCursorPosition(); m_cursor.insertText(QString("%1").arg(i+1)); // basis m_cursor = table->cellAt(i+1, 1).firstCursorPosition(); size_t basisColumn = m_params->columnBasis(i); m_cursor.insertHtml(QString("P<sub>%1</sub> ").arg(basisColumn+1)); // basis C m_cursor = table->cellAt(i+1, 2).firstCursorPosition(); if(m_params->variableType(basisColumn) == SimplexMethod::VariableArtificial) m_cursor.insertText("W"); else m_cursor.insertText(formatDouble(m_params->rowC(basisColumn))); // B m_cursor = table->cellAt(i+1, 3).firstCursorPosition(); m_cursor.insertText(formatDouble(m_params->columnB(i))); // matrix for(size_t j=0; j < m_params->width(); j++) { m_cursor = table->cellAt(i+1, j+4).firstCursorPosition(); m_cursor.insertText(formatDouble(m_params->matrixA(i, j))); } // theta m_cursor = table->cellAt(i+1, m_params->width()+4).firstCursorPosition(); if(m_params->columnTheta(i) > 0) m_cursor.insertText(formatDouble(m_params->columnTheta(i))); else m_cursor.insertText("-"); } /* m+1 row */ m_cursor = table->cellAt(m_params->height()+1, 0).firstCursorPosition(); m_cursor.insertText("m+1"); m_cursor = table->cellAt(m_params->height()+1, 3).firstCursorPosition(); m_cursor.insertText(formatDouble(m_params->F())); for(size_t j=0; j < m_params->width(); j++) { m_cursor = table->cellAt(m_params->height()+1, j+4).firstCursorPosition(); m_cursor.insertText(formatDouble(m_params->rowD(j))); } /* m+2 row (for artificial variables) */ if(m_params->artificialFlag()) { table->appendRows(1); m_cursor = table->cellAt(m_params->height()+2, 0).firstCursorPosition(); m_cursor.insertText("m+2"); m_cursor = table->cellAt(m_params->height()+2, 3).firstCursorPosition(); m_cursor.insertText(formatDouble(m_params->WF())); for(size_t j=0; j < m_params->width(); j++) { m_cursor = table->cellAt(m_params->height()+2, j+4).firstCursorPosition(); m_cursor.insertText(formatDouble(m_params->rowWD(j))); } } /* end of table */ m_cursor.endEditBlock(); m_cursor.setPosition(topFrame->lastPosition()); return true; }