本文整理汇总了C++中QTextTableFormat::setColumnWidthConstraints方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextTableFormat::setColumnWidthConstraints方法的具体用法?C++ QTextTableFormat::setColumnWidthConstraints怎么用?C++ QTextTableFormat::setColumnWidthConstraints使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextTableFormat
的用法示例。
在下文中一共展示了QTextTableFormat::setColumnWidthConstraints方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BuildTrainingSection
// 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);
}
示例2: onInsertTable
void MainWindow::onInsertTable(int rows, int columns, double width, bool relative)
{
qDebug() << "Insert table: rows = " << rows << ", columns = " << columns
<< ", width = " << width << ", relative = " << (relative ? "true" : "false");
QTextCursor cursor = ui->textEdit->textCursor();
QTextTableFormat tableFormat;
QVector<QTextLength> columnWidthConstraints;
columnWidthConstraints.reserve(columns);
double averageColumnWidth = width / columns;
if (relative)
{
for(int i = 0; i < columns; ++i) {
QTextLength textLength(QTextLength::PercentageLength, averageColumnWidth);
columnWidthConstraints.push_back(textLength);
}
}
else
{
for(int i = 0; i < columns; ++i) {
QTextLength textLength(QTextLength::FixedLength, averageColumnWidth);
columnWidthConstraints.push_back(textLength);
}
}
tableFormat.setColumnWidthConstraints(columnWidthConstraints);
Q_UNUSED(cursor.insertTable(rows, columns, tableFormat));
}
示例3: visitTextCellNodeBefore
// 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;
}
}
示例4: printDeckListNode
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);
}
示例5: insertColumns
/*!
\fn void QTextTable::insertColumns(int index, int columns)
Inserts a number of \a columns before the column with the specified \a index.
\sa insertRows() resize() removeRows() removeColumns() appendRows() appendColumns()
*/
void QTextTable::insertColumns(int pos, int num)
{
Q_D(QTextTable);
if (num <= 0)
return;
if (d->dirty)
d->update();
if (pos > d->nCols || pos < 0)
pos = d->nCols;
// qDebug() << "-------- insertCols" << pos << num;
QTextDocumentPrivate *p = d->pieceTable;
QTextFormatCollection *c = p->formatCollection();
p->beginEditBlock();
for (int i = 0; i < d->nRows; ++i) {
int cell;
if (i == d->nRows - 1 && pos == d->nCols)
cell = d->fragment_end;
else
cell = d->grid[i*d->nCols + pos];
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell);
QTextCharFormat fmt = c->charFormat(it->format);
if (pos > 0 && pos < d->nCols && cell == d->grid[i*d->nCols + pos - 1]) {
// cell spans the insertion place, extend it
fmt.setTableCellColumnSpan(fmt.tableCellColumnSpan() + num);
p->setCharFormat(it.position(), 1, fmt);
} else {
fmt.setTableCellRowSpan(1);
fmt.setTableCellColumnSpan(1);
Q_ASSERT(fmt.objectIndex() == objectIndex());
int position = it.position();
int cfmt = p->formatCollection()->indexForFormat(fmt);
int bfmt = p->formatCollection()->indexForFormat(QTextBlockFormat());
for (int i = 0; i < num; ++i)
p->insertBlock(QTextBeginningOfFrame, position, bfmt, cfmt, QTextUndoCommand::MoveCursor);
}
}
QTextTableFormat tfmt = format();
tfmt.setColumns(tfmt.columns()+num);
QVector<QTextLength> columnWidths = tfmt.columnWidthConstraints();
if (! columnWidths.isEmpty()) {
for (int i = num; i > 0; --i)
columnWidths.insert(pos, columnWidths[qMax(0, pos-1)]);
}
tfmt.setColumnWidthConstraints (columnWidths);
QTextObject::setFormat(tfmt);
// qDebug() << "-------- end insertCols" << pos << num;
p->endEditBlock();
}
示例6: BuildCallsSection
// 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);
}
示例7: cursor
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 );
}
示例8: QTextEdit
/*!
* \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);
}
示例9: insertTable
QObject* TextCursor::insertTable(int rows, int columns)
{
QTextTableFormat format;
//format.setColumns(columns);
//format.setHeaderRowCount(1);
format.setBackground(QColor("#e0e0e0"));
//format.setCellPadding(1); format.setCellSpacing(1); //testcase
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::PercentageLength, 16);
constraints << QTextLength(QTextLength::PercentageLength, 28);
constraints << QTextLength(QTextLength::PercentageLength, 28);
constraints << QTextLength(QTextLength::PercentageLength, 28);
format.setColumnWidthConstraints(constraints);
QTextTable* table = m_cursor.insertTable(rows, columns, format);
//QTextTable* t = m_cursor.insertTable(rows, columns);
QTextTableCell cell = table->cellAt(0, 0);
cell.firstCursorPosition().insertText(tr("aaa") /*, QTextCharFormat::charFormat*/);
table->cellAt(0, 1).firstCursorPosition().insertText(tr("bbb"));
return new TextTable(this, table);
}
示例10: uri
/** "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);
}
}
示例11: cursor
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"));
}
示例12: uri
/** "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);
//.........这里部分代码省略.........
示例13: draw
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);
//.........这里部分代码省略.........
示例14: createPages
void KWQTableView::createPages(QPrinter *printer, QTextDocument *textDoc, bool sendToPrinter)
{
printer->setFullPage(true);
int myDpi = printer->logicalDpiY();
if (Prefs::printStyle() == Prefs::EnumPrintStyle::Flashcard) {
printer->setOrientation(QPrinter::Landscape);
int cardWidth = qRound(5 * qreal(myDpi));
int cardHeight = qRound(3 * qreal(myDpi));
QTextTable *table = textDoc->rootFrame()->lastCursorPosition().insertTable(model()->rowCount(), 2);
QTextTableFormat tableFormat = table->format();
tableFormat.setHeaderRowCount(0);
tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_None);
tableFormat.setCellSpacing(0);
tableFormat.setCellPadding(0);
QVector<QTextLength> constraints;
constraints.append(QTextLength(QTextLength::FixedLength, cardWidth));
constraints.append(QTextLength(QTextLength::FixedLength, cardWidth));
tableFormat.setColumnWidthConstraints(constraints);
table->setFormat(tableFormat);
QTextBlockFormat headerFormat;
headerFormat.setAlignment(Qt::AlignLeft);
QTextCharFormat headerCharFormat;
headerCharFormat.setFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
QTextBlockFormat cellFormat;
cellFormat.setAlignment(Qt::AlignCenter);
QTextCharFormat cellCharFormat;
cellCharFormat.setFont(Prefs::editorFont());
QTextFrameFormat cardFormat;
cardFormat.setBorder(1);
cardFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
cardFormat.setBorderBrush(QBrush(Qt::black));
cardFormat.setWidth(QTextLength(QTextLength::FixedLength, cardWidth));
cardFormat.setHeight(QTextLength(QTextLength::FixedLength, cardHeight));
cardFormat.setPadding(qRound(0.25 * myDpi));
QTextFrameFormat lineFormat;
lineFormat.setBorder(1);
lineFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
lineFormat.setBorderBrush(QBrush(Qt::black));
lineFormat.setWidth(QTextLength(QTextLength::FixedLength, qRound(4.5 * myDpi)));
lineFormat.setHeight(1.1); //1 is drawn as a box whereas this is drawn as a line. Strange...
lineFormat.setPadding(0);
QTextFrame *card;
for (int i = 0; i < model()->rowCount(); i++) {
for (int j = 0; j < model()->columnCount(); j++) {
cardFormat.setPosition(QTextFrameFormat::FloatLeft);
card = table->cellAt(i, j).firstCursorPosition().insertFrame(cardFormat);
card->lastCursorPosition().insertText(model()->headerData(j, Qt::Horizontal, Qt::DisplayRole).toString(), headerCharFormat);
card->lastCursorPosition().insertFrame(lineFormat);
card->lastCursorPosition().insertBlock();
card->lastCursorPosition().insertBlock();
card->lastCursorPosition().insertBlock(cellFormat, cellCharFormat);
card->lastCursorPosition().insertText(model()->data(model()->index(i, j)).toString(), cellCharFormat);
}
}
}
else
{
textDoc->rootFrame()->lastCursorPosition().insertText(QStringLiteral("kwordquiz %1").arg(KWQ_VERSION));
if (Prefs::printStyle() == Prefs::EnumPrintStyle::Exam)
textDoc->rootFrame()->lastCursorPosition().insertText(' ' + i18n("Name:_____________________________ Date:__________"));
QTextTable* table;
if (Prefs::printStyle() == Prefs::EnumPrintStyle::Exam)
table = textDoc->rootFrame()->lastCursorPosition().insertTable(model()->rowCount() + 1, model()->columnCount() + 2);
else
table = textDoc->rootFrame()->lastCursorPosition().insertTable(model()->rowCount() + 1, model()->columnCount() + 1);
QTextTableFormat tableFormat = table->format();
tableFormat.setHeaderRowCount(1);
tableFormat.setBorder(1);
tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
tableFormat.setCellSpacing(0);
tableFormat.setBorderBrush(QBrush(Qt::black));
tableFormat.setCellPadding(2);
QVector<QTextLength> constraints;
constraints.append(QTextLength(QTextLength::FixedLength, verticalHeader()->width()));
constraints.append(QTextLength(QTextLength::FixedLength, columnWidth(0)));
constraints.append(QTextLength(QTextLength::FixedLength, columnWidth(1)));
if (Prefs::printStyle() == Prefs::EnumPrintStyle::Exam)
constraints.append(QTextLength(QTextLength::FixedLength, 50));
tableFormat.setColumnWidthConstraints(constraints);
table->setFormat(tableFormat);
QTextBlockFormat headerFormat;
//.........这里部分代码省略.........
示例15: printODT
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 ){
//.........这里部分代码省略.........