ESGRAF48/source/PrintableModel.cpp

47 lines
1.2 KiB
C++
Raw Permalink Normal View History

2018-12-15 15:12:20 +00:00
#include "PrintableModel.h"
QTextTableFormat PrintableModel::defaultTableFormat()
{
QTextTableFormat tableFormat;
tableFormat.setCellPadding(2);
tableFormat.setCellSpacing(0);
return tableFormat;
}
2018-12-15 15:31:51 +00:00
void PrintableModel::setCellText(QTextTable &table, int row, int column, const QString &text)
{
auto cell = table.cellAt(row, column);
auto textCursor = cell.firstCursorPosition();
auto blockFormat = textCursor.blockFormat();
blockFormat.setAlignment(Qt::AlignCenter);
textCursor.setBlockFormat(blockFormat);
auto cellFormat = cell.format();
cellFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle);
cell.setFormat(cellFormat);
auto charFormat = textCursor.charFormat();
charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle);
charFormat.setFontPointSize(8);
textCursor.setCharFormat(charFormat);
textCursor.insertText(text);
}
void PrintableModel::setCellChecked(QTextTable &table, int row, int column, bool check)
{
setCellText(table, row, column, check ? "x" : "\u2610");
}
void PrintableModel::setCellBackground(QTextTable &table, int row, int column, const QColor &color)
{
auto cell = table.cellAt(row, column);
auto cellFormat = cell.format();
cellFormat.setBackground(QBrush(color));
cell.setFormat(cellFormat);
}