This repository has been archived on 2024-12-15. You can view files and clone it, but cannot push or open issues or pull requests.
ESGRAF48/source/PrintableModel.cpp

47 lines
1.2 KiB
C++

#include "PrintableModel.h"
QTextTableFormat PrintableModel::defaultTableFormat()
{
QTextTableFormat tableFormat;
tableFormat.setCellPadding(2);
tableFormat.setCellSpacing(0);
return tableFormat;
}
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);
}