void ChatView::appendMessage(const QString &sender, const QString &message) { QTextCursor cellCursor = table->cellAt(table->rows() - 1, 0).lastCursorPosition(); cellCursor.insertText(QDateTime::currentDateTime().toString("[hh:mm]")); QTextTableCell senderCell = table->cellAt(table->rows() - 1, 1); QTextCharFormat senderFormat; if (sender == ownName) { senderFormat.setFontWeight(QFont::Bold); senderFormat.setForeground(Qt::red); } else senderFormat.setForeground(Qt::blue); senderCell.setFormat(senderFormat); cellCursor = senderCell.lastCursorPosition(); cellCursor.insertText(sender); QTextTableCell messageCell = table->cellAt(table->rows() - 1, 2); QTextCharFormat messageFormat; if (sender.isEmpty()) messageFormat.setForeground(Qt::darkGreen); messageCell.setFormat(messageFormat); cellCursor = messageCell.lastCursorPosition(); cellCursor.insertText(message); table->appendRows(1); verticalScrollBar()->setValue(verticalScrollBar()->maximum()); }
void PrintDialog::fillCategoryTableLine( QTextTable * table, const unsigned int & row, const QString & position, const QString & lastname, const QString & firstname, const QString & time) { int realRow = row + 1; table->insertRows ( realRow, 1 ); QTextCharFormat cellFormat; cellFormat.setFontPointSize(10.0); if(row%2) cellFormat.setBackground(QBrush(QColor(240,240,240))); QTextTableCell cell = table->cellAt(realRow, 0); QTextCursor cursor = cell.firstCursorPosition(); cell.setFormat(cellFormat); cursor.insertText(position); cell = table->cellAt(realRow, 1); cursor = cell.firstCursorPosition(); cell.setFormat(cellFormat); cursor.insertText(lastname); cell = table->cellAt(realRow, 2); cursor = cell.firstCursorPosition(); cell.setFormat(cellFormat); cursor.insertText(firstname); cell = table->cellAt(realRow, 3); cursor = cell.firstCursorPosition(); cell.setFormat(cellFormat); cursor.insertText(time); }
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); }
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 ChatDialog::appendChatMessage(const QString& nick, const QString& text, time_t timestamp) { QTextCharFormat nickFormat; nickFormat.setForeground(Qt::darkGreen); nickFormat.setFontWeight(QFont::Bold); nickFormat.setFontUnderline(true); nickFormat.setUnderlineColor(Qt::gray); // Print who & when QTextCursor cursor(ui->textEdit->textCursor()); cursor.movePosition(QTextCursor::End); QTextTableFormat tableFormat; tableFormat.setBorder(0); QTextTable *table = cursor.insertTable(1, 2, tableFormat); QString from = QString("%1 ").arg(nick); QTextTableCell fromCell = table->cellAt(0, 0); fromCell.setFormat(nickFormat); fromCell.firstCursorPosition().insertText(from); printTimeInCell(table, timestamp); // Print what QTextCursor nextCursor(ui->textEdit->textCursor()); nextCursor.movePosition(QTextCursor::End); table = nextCursor.insertTable(1, 1, tableFormat); table->cellAt(0, 0).firstCursorPosition().insertText(text); // Popup notification showMessage(from, text); QScrollBar *bar = ui->textEdit->verticalScrollBar(); bar->setValue(bar->maximum()); }
void FillCellHelper::fill( QTextTable* textTable, KDReports::ReportBuilder& builder, QTextDocument& textDoc, QTextTableCell& cell ) { cellCursor = cell.firstCursorPosition(); QTextCharFormat cellFormat = cell.format(); if ( background.isValid() ) { cellFormat.setBackground( background ); } cellFormat.setVerticalAlignment( toVerticalAlignment( alignment ) ); cell.setFormat( cellFormat ); QTextBlockFormat blockFormat = cellCursor.blockFormat(); blockFormat.setAlignment( alignment ); blockFormat.setNonBreakableLines( nonBreakableLines ); builder.setupBlockFormat( blockFormat ); cellCursor.setBlockFormat( blockFormat ); const bool hasIcon = !cellDecoration.isNull(); const bool iconAfterText = decorationAlignment.isValid() && ( decorationAlignment.toInt() & Qt::AlignRight ); if ( hasIcon && !iconAfterText ) { insertDecoration( builder, textDoc ); } QTextCharFormat charFormat = cellCursor.charFormat(); if ( cellFont.isValid() ) { QFont cellQFont = qvariant_cast<QFont>( cellFont ); #if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) charFormat.setFont( cellQFont, QTextCharFormat::FontPropertiesSpecifiedOnly ); #else charFormat.setFont( cellQFont ); #endif } else { charFormat.setFont( builder.defaultFont() ); } if ( foreground.isValid() ) charFormat.setForeground( foreground ); cellCursor.setCharFormat( charFormat ); if ( hasIcon && !iconAfterText ) { cellCursor.insertText( QChar::fromLatin1( ' ' ) ); // spacing between icon and text } //qDebug() << cellText; if (cellText.startsWith(QLatin1String("<qt>")) || cellText.startsWith(QLatin1String("<html>"))) cellCursor.insertHtml( cellText ); else cellCursor.insertText( cellText ); if ( hasIcon && iconAfterText ) { cellCursor.insertText( QChar::fromLatin1( ' ' ) ); // spacing between icon and text insertDecoration( builder, textDoc ); } if ( span.width() > 1 || span.height() > 1 ) textTable->mergeCells( cell.row(), cell.column(), span.height(), span.width() ); }
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 ChatDialog::printTimeInCell(QTextTable *table, time_t timestamp) { QTextCharFormat timeFormat; timeFormat.setForeground(Qt::gray); timeFormat.setFontUnderline(true); timeFormat.setUnderlineColor(Qt::gray); QTextTableCell timeCell = table->cellAt(0, 1); timeCell.setFormat(timeFormat); timeCell.firstCursorPosition().insertText(formatTime(timestamp)); }
static PyObject *meth_QTextTableCell_setFormat(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { const QTextCharFormat* a0; QTextTableCell *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "BJ9", &sipSelf, sipType_QTextTableCell, &sipCpp, sipType_QTextCharFormat, &a0)) { sipCpp->setFormat(*a0); Py_INCREF(Py_None); return Py_None; } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QTextTableCell, sipName_setFormat, doc_QTextTableCell_setFormat); return NULL; }
void ChatDialog::appendControlMessage(const QString& nick, const QString& action, time_t timestamp) { QTextCharFormat nickFormat; nickFormat.setForeground(Qt::gray); nickFormat.setFontWeight(QFont::Bold); nickFormat.setFontUnderline(true); nickFormat.setUnderlineColor(Qt::gray); QTextCursor cursor(ui->textEdit->textCursor()); cursor.movePosition(QTextCursor::End); QTextTableFormat tableFormat; tableFormat.setBorder(0); QTextTable *table = cursor.insertTable(1, 2, tableFormat); QString controlMsg = QString("%1 %2 ").arg(nick).arg(action); QTextTableCell fromCell = table->cellAt(0, 0); fromCell.setFormat(nickFormat); fromCell.firstCursorPosition().insertText(controlMsg); printTimeInCell(table, timestamp); }
void KDReports::AutoTableElement::build( ReportBuilder& builder ) const { if( !d->m_tableModel ) { return; } QTextDocument& textDoc = builder.currentDocument(); QTextCursor& textDocCursor = builder.cursor(); textDocCursor.beginEditBlock(); QTextTableFormat tableFormat; const int headerRowCount = d->m_horizontalHeaderVisible ? 1 : 0; const int headerColumnCount = d->m_verticalHeaderVisible ? 1 : 0; tableFormat.setHeaderRowCount( headerRowCount ); tableFormat.setProperty( KDReports::HeaderColumnsProperty, headerColumnCount ); tableFormat.setAlignment( textDocCursor.blockFormat().alignment() ); fillTableFormat( tableFormat, textDocCursor ); while (d->m_tableModel->canFetchMore(QModelIndex())) d->m_tableModel->fetchMore(QModelIndex()); const int rows = d->m_tableModel->rowCount(); const int columns = d->m_tableModel->columnCount(); QTextTable* textTable = textDocCursor.insertTable( rows + headerRowCount, columns + headerColumnCount, tableFormat ); QTextCharFormat tableHeaderFormat; tableHeaderFormat.setBackground( d->m_headerBackground ); //qDebug( "rows = %d, columns = %d", textTable->rows(), textTable->columns() ); if( d->m_horizontalHeaderVisible ) { for( int column = 0; column < columns; column++ ) { QTextTableCell cell = textTable->cellAt( 0, column + headerColumnCount ); Q_ASSERT( cell.isValid() ); cell.setFormat( tableHeaderFormat ); d->fillCellFromHeaderData( column, Qt::Horizontal, cell, textDoc, textTable, builder ); } } if( d->m_verticalHeaderVisible ) { for( int row = 0; row < rows; row++ ) { QTextTableCell cell = textTable->cellAt( row + headerRowCount, 0 ); Q_ASSERT( cell.isValid() ); cell.setFormat( tableHeaderFormat ); d->fillCellFromHeaderData( row, Qt::Vertical, cell, textDoc, textTable, builder ); } } QVector<QBitArray> coveredCells; coveredCells.resize(rows); for( int row = 0; row < rows; row++ ) coveredCells[row].resize(columns); // The normal data for( int row = 0; row < rows; row++ ) { for( int column = 0; column < columns; column++ ) { if (coveredCells[row].testBit(column)) continue; QTextTableCell cell = textTable->cellAt( row + headerRowCount, column + headerColumnCount ); Q_ASSERT( cell.isValid() ); const QSize span = d->fillTableCell( row, column, cell, textDoc, textTable, builder ); if (span.isValid()) { for (int r = row; r < row + span.height() && r < rows; ++r) { for (int c = column; c < column + span.width() && c < columns; ++c) { coveredCells[r].setBit(c); } } } } } textDocCursor.movePosition( QTextCursor::End ); textDocCursor.endEditBlock(); builder.currentDocumentData().registerAutoTable( textTable, this ); }
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(); } }
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); }
QTextTable * PrintDialog::insertCategoryTable(QTextCursor & cursor, const QString & categoryName) { QTextBlockFormat blockCategoryTitleFormat; blockCategoryTitleFormat.setAlignment(Qt::AlignCenter); blockCategoryTitleFormat.setTopMargin(40.0); blockCategoryTitleFormat.setBottomMargin(30.0); QTextCharFormat categoryTitleFormat; categoryTitleFormat.setFontCapitalization(QFont::AllUppercase); categoryTitleFormat.setFontWeight(25); categoryTitleFormat.setFontPointSize(14.0); QString category = "Category \""; category += categoryName; category += "\""; cursor.insertBlock(blockCategoryTitleFormat); cursor.insertText(category,categoryTitleFormat); cursor.insertBlock(QTextBlockFormat()); // to break the previous block format QTextTable * table = cursor.insertTable(1, 4); if(!table) return NULL; QTextTableFormat categoryTableFormat; categoryTableFormat.setAlignment(Qt::AlignHCenter); categoryTableFormat.setHeaderRowCount(1); // header line categoryTableFormat.setBorderStyle(QTextTableFormat::BorderStyle_Solid); categoryTableFormat.setBorder(1.0); categoryTableFormat.setCellPadding(10); categoryTableFormat.setCellSpacing(0); table->setFormat(categoryTableFormat); // header : // header cell format : QTextCharFormat headerCellFormat; headerCellFormat.setFontWeight(50); headerCellFormat.setFontPointSize(12.0); headerCellFormat.setBackground(QBrush(QColor(60,60,60))); headerCellFormat.setForeground(QBrush(QColor(255,255,255))); QTextTableCell cell = table->cellAt(0,0); cell.setFormat(headerCellFormat); cursor = cell.firstCursorPosition(); cursor.insertText(tr("Position")); cell = table->cellAt(0,1); cell.setFormat(headerCellFormat); cursor = cell.firstCursorPosition(); cursor.insertText(tr("LastName")); cell = table->cellAt(0,2); cell.setFormat(headerCellFormat); cursor = cell.firstCursorPosition(); cursor.insertText(tr("Firstname")); cell = table->cellAt(0,3); cell.setFormat(headerCellFormat); cursor = cell.firstCursorPosition(); cursor.insertText(tr("Time")); return table; }