void InsertTableColumnCommand::redo() { KoTableColumnAndRowStyleManager carsManager = KoTableColumnAndRowStyleManager::getManager(m_table); if (!m_first) { carsManager.insertColumns(m_column, 1, m_style); KUndo2Command::redo(); } else { m_first = false; QTextTableCell cell = m_table->cellAt(*m_textEditor->cursor()); m_column = cell.column() + (m_right ? 1 : 0); m_style = carsManager.columnStyle(cell.column()); m_table->insertColumns(m_column, 1); carsManager.insertColumns(m_column, 1, m_style); if (m_right && m_column == m_table->columns()-1) { // Copy the cell style. for the bottomright cell which Qt doesn't QTextTableCell cell = m_table->cellAt(m_table->rows()-1, m_column - 1); QTextCharFormat format = cell.format(); cell = m_table->cellAt(m_table->rows()-1, m_column); cell.setFormat(format); } if (m_changeId) { for (int i=0; i < m_table->rows(); i++) { QTextTableCellFormat cellFormat = m_table->cellAt(i, m_column).format().toTableCellFormat(); cellFormat.setProperty(KoCharacterStyle::ChangeTrackerId, m_changeId); m_table->cellAt(i, m_column).setFormat(cellFormat); } } } }
void MessageAction::featureUpdate() { QTextTableCell cell = textTable->cellAt(0,3); QTextTableCellFormat format; if (!isProcessed) format.setBackground(QColor(Qt::red)); else format.setBackground(QColor(Qt::white)); cell.setFormat(format); }
void QTextOdfWriter::writeTableCellFormat(QXmlStreamWriter &writer, QTextTableCellFormat format, int formatIndex) const { writer.writeStartElement(styleNS, QString::fromLatin1("style")); writer.writeAttribute(styleNS, QString::fromLatin1("name"), QString::fromLatin1("T%1").arg(formatIndex)); writer.writeAttribute(styleNS, QString::fromLatin1("family"), QString::fromLatin1("table")); writer.writeEmptyElement(styleNS, QString::fromLatin1("table-properties")); qreal padding = format.topPadding(); if (padding > 0 && padding == format.bottomPadding() && padding == format.leftPadding() && padding == format.rightPadding()) { writer.writeAttribute(foNS, QString::fromLatin1("padding"), pixelToPoint(padding)); } else { if (padding > 0) writer.writeAttribute(foNS, QString::fromLatin1("padding-top"), pixelToPoint(padding)); if (format.bottomPadding() > 0) writer.writeAttribute(foNS, QString::fromLatin1("padding-bottom"), pixelToPoint(format.bottomPadding())); if (format.leftPadding() > 0) writer.writeAttribute(foNS, QString::fromLatin1("padding-left"), pixelToPoint(format.leftPadding())); if (format.rightPadding() > 0) writer.writeAttribute(foNS, QString::fromLatin1("padding-right"), pixelToPoint(format.rightPadding())); } if (format.hasProperty(QTextFormat::TextVerticalAlignment)) { QString pos; switch (format.verticalAlignment()) { case QTextCharFormat::AlignMiddle: pos = QString::fromLatin1("middle"); break; case QTextCharFormat::AlignTop: pos = QString::fromLatin1("top"); break; case QTextCharFormat::AlignBottom: pos = QString::fromLatin1("bottom"); break; default: pos = QString::fromLatin1("automatic"); break; } writer.writeAttribute(styleNS, QString::fromLatin1("vertical-align"), pos); } // TODO // ODF just search for style-table-cell-properties-attlist) // QTextFormat::BackgroundImageUrl // format.background // QTextFormat::FrameBorder writer.writeEndElement(); // style }
void DeleteTableColumnCommand::redo() { KoTableColumnAndRowStyleManager carsManager = KoTableColumnAndRowStyleManager::getManager(m_table); if (!m_first) { if (!m_changeId) { carsManager.removeColumns(m_selectionColumn, m_selectionColumnSpan); } KUndo2Command::redo(); } else { m_first = false; int selectionRow; int selectionRowSpan; if(m_textEditor->hasComplexSelection()) { m_textEditor->cursor()->selectedTableCells(&selectionRow, &selectionRowSpan, &m_selectionColumn, &m_selectionColumnSpan); } else { QTextTableCell cell = m_table->cellAt(*m_textEditor->cursor()); m_selectionColumn = cell.column(); m_selectionColumnSpan = 1; } if (!m_changeId) { m_table->removeColumns(m_selectionColumn, m_selectionColumnSpan); for (int i = m_selectionColumn; i < m_selectionColumn + m_selectionColumnSpan; ++i) { m_deletedStyles.append(carsManager.columnStyle(i)); } carsManager.removeColumns(m_selectionColumn, m_selectionColumnSpan); } else { for (int i=0; i < m_table->rows(); i++) { QTextTableCellFormat cellFormat = m_table->cellAt(i, m_selectionColumn).format().toTableCellFormat(); cellFormat.setProperty(KoCharacterStyle::ChangeTrackerId, m_changeId); m_table->cellAt(i, m_selectionColumn).setFormat(cellFormat); } } } }
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; }
void TestTableLayout::initTest(int rows, int columns, KoTableStyle *tableStyle, const QList<KoTableColumnStyle *> &columnStyles, const QList<KoTableRowStyle *> &rowStyles, const QMap<QPair<int, int>, KoTableCellStyle *> &cellStyles, const QMap<QPair<int, int>, QString> &cellTexts) { // Mock shape of size 200x1000 pt. m_shape = new MockTextShape(); Q_ASSERT(m_shape); m_shape->setSize(QSizeF(200, 1000)); // Document layout. m_layout = m_shape->layout; Q_ASSERT(m_layout); // Document. m_doc = m_layout->document(); Q_ASSERT(m_doc); m_doc->setDefaultFont(QFont("Sans Serif", 12, QFont::Normal, false)); // Layout state (layout helper). m_textLayout = new Layout(m_layout); Q_ASSERT(m_textLayout); m_layout->setLayout(m_textLayout); // Style manager. m_styleManager = new KoStyleManager(); Q_ASSERT(m_styleManager); KoTextDocument(m_doc).setStyleManager(m_styleManager); // Table style. m_defaultTableStyle = new KoTableStyle(); Q_ASSERT(m_defaultTableStyle); m_defaultTableStyle->setMargin(0.0); m_defaultTableStyle->setWidth(QTextLength(QTextLength::FixedLength, 200)); QTextTableFormat tableFormat; if (tableStyle) { tableStyle->applyStyle(tableFormat); } else { m_defaultTableStyle->applyStyle(tableFormat); } // Table. QTextCursor cursor(m_doc); m_table = cursor.insertTable(rows, columns, tableFormat); Q_ASSERT(m_table); // Column and row style manager. m_tableColumnAndRowStyleManager = KoTableColumnAndRowStyleManager::getManager(m_table); // Column styles. m_defaultColumnStyle.setRelativeColumnWidth(50.0); for (int col = 0; col < columns; ++col) { if (columnStyles.value(col)) { m_tableColumnAndRowStyleManager.setColumnStyle(col, *(columnStyles.at(col))); } else { m_tableColumnAndRowStyleManager.setColumnStyle(col, m_defaultColumnStyle); } } // Row styles. for (int row = 0; row < rows; ++row) { if (rowStyles.value(row)) { m_tableColumnAndRowStyleManager.setRowStyle(row, *(rowStyles.at(row))); } else { m_tableColumnAndRowStyleManager.setRowStyle(row, m_defaultRowStyle); } } // Cell styles and texts. m_defaultCellStyle = new KoTableCellStyle(); Q_ASSERT(m_defaultCellStyle); for (int row = 0; row < m_table->rows(); ++row) { for (int col = 0; col < m_table->columns(); ++col) { // Style. QTextTableCell cell = m_table->cellAt(row, col); QTextTableCellFormat cellFormat = cell.format().toTableCellFormat(); if (cellStyles.contains(qMakePair(row, col))) { cellStyles.value(qMakePair(row, col))->applyStyle(cellFormat); cell.setFormat(cellFormat.toCharFormat()); } else { m_defaultCellStyle->applyStyle(cellFormat); } cell.setFormat(cellFormat.toCharFormat()); // Text. if (cellTexts.contains(qMakePair(row, col))) { cell.firstCursorPosition().insertText(cellTexts.value(qMakePair(row, col))); } } } KoParagraphStyle style; style.setStyleId(101); // needed to do manually since we don't use the stylemanager QTextBlock b2 = m_doc->begin(); while (b2.isValid()) { style.applyStyle(b2); b2 = b2.next(); } }