mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-13 05:54:06 -07:00
Deck Loader is responsible for printing.
Took 8 minutes Took 2 seconds
This commit is contained in:
parent
919c9f0095
commit
164c40234b
5 changed files with 109 additions and 109 deletions
|
|
@ -14,6 +14,7 @@
|
||||||
#include <libcockatrice/card/database/card_database_manager.h>
|
#include <libcockatrice/card/database/card_database_manager.h>
|
||||||
#include <libcockatrice/deck_list/deck_list.h>
|
#include <libcockatrice/deck_list/deck_list.h>
|
||||||
#include <libcockatrice/deck_list/deck_list_card_node.h>
|
#include <libcockatrice/deck_list/deck_list_card_node.h>
|
||||||
|
#include <qtexttable.h>
|
||||||
|
|
||||||
const QStringList DeckLoader::ACCEPTED_FILE_EXTENSIONS = {"*.cod", "*.dec", "*.dek", "*.txt", "*.mwDeck"};
|
const QStringList DeckLoader::ACCEPTED_FILE_EXTENSIONS = {"*.cod", "*.dec", "*.dek", "*.txt", "*.mwDeck"};
|
||||||
|
|
||||||
|
|
@ -603,3 +604,97 @@ QString DeckLoader::getCompleteCardName(const QString &cardName) const
|
||||||
|
|
||||||
return cardName;
|
return cardName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeckLoader::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
|
||||||
|
{
|
||||||
|
const int totalColumns = 2;
|
||||||
|
|
||||||
|
if (node->height() == 1) {
|
||||||
|
QTextBlockFormat blockFormat;
|
||||||
|
QTextCharFormat charFormat;
|
||||||
|
charFormat.setFontPointSize(11);
|
||||||
|
charFormat.setFontWeight(QFont::Bold);
|
||||||
|
cursor->insertBlock(blockFormat, charFormat);
|
||||||
|
|
||||||
|
QTextTableFormat tableFormat;
|
||||||
|
tableFormat.setCellPadding(0);
|
||||||
|
tableFormat.setCellSpacing(0);
|
||||||
|
tableFormat.setBorder(0);
|
||||||
|
QTextTable *table = cursor->insertTable(node->size() + 1, totalColumns, tableFormat);
|
||||||
|
for (int i = 0; i < node->size(); i++) {
|
||||||
|
auto *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);
|
||||||
|
|
||||||
|
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 DeckLoader::printDeckList(QPrinter *printer)
|
||||||
|
{
|
||||||
|
QTextDocument doc;
|
||||||
|
|
||||||
|
QFont font("Serif");
|
||||||
|
font.setStyleHint(QFont::Serif);
|
||||||
|
doc.setDefaultFont(font);
|
||||||
|
|
||||||
|
QTextCursor cursor(&doc);
|
||||||
|
|
||||||
|
QTextBlockFormat headerBlockFormat;
|
||||||
|
QTextCharFormat headerCharFormat;
|
||||||
|
headerCharFormat.setFontPointSize(16);
|
||||||
|
headerCharFormat.setFontWeight(QFont::Bold);
|
||||||
|
|
||||||
|
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
||||||
|
cursor.insertText(getName());
|
||||||
|
|
||||||
|
headerCharFormat.setFontPointSize(12);
|
||||||
|
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
||||||
|
cursor.insertText(getComments());
|
||||||
|
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
||||||
|
|
||||||
|
for (int i = 0; i < getRoot()->size(); i++) {
|
||||||
|
cursor.insertHtml("<br><img src=theme:hr.jpg>");
|
||||||
|
// cursor.insertHtml("<hr>");
|
||||||
|
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
||||||
|
|
||||||
|
printDeckListNode(&cursor, dynamic_cast<InnerDecklistNode *>(getRoot()->at(i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
doc.print(printer);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@
|
||||||
#define DECK_LOADER_H
|
#define DECK_LOADER_H
|
||||||
|
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
|
#include <QPrinter>
|
||||||
|
#include <QTextCursor>
|
||||||
#include <libcockatrice/deck_list/deck_list.h>
|
#include <libcockatrice/deck_list/deck_list.h>
|
||||||
|
|
||||||
inline Q_LOGGING_CATEGORY(DeckLoaderLog, "deck_loader")
|
inline Q_LOGGING_CATEGORY(DeckLoaderLog, "deck_loader")
|
||||||
|
|
@ -19,6 +21,13 @@ signals:
|
||||||
void deckLoaded();
|
void deckLoaded();
|
||||||
void loadFinished(bool success);
|
void loadFinished(bool success);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
/**
|
||||||
|
* @brief Prints the decklist to the provided QPrinter.
|
||||||
|
* @param printer The printer to render the decklist to.
|
||||||
|
*/
|
||||||
|
void printDeckList(QPrinter *printer);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum FileFormat
|
enum FileFormat
|
||||||
{
|
{
|
||||||
|
|
@ -93,6 +102,9 @@ public:
|
||||||
bool saveToStream_Plain(QTextStream &out, bool addComments = true, bool addSetNameAndNumber = true) const;
|
bool saveToStream_Plain(QTextStream &out, bool addComments = true, bool addSetNameAndNumber = true) const;
|
||||||
bool convertToCockatriceFormat(QString fileName);
|
bool convertToCockatriceFormat(QString fileName);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void saveToStream_DeckHeader(QTextStream &out) const;
|
void saveToStream_DeckHeader(QTextStream &out) const;
|
||||||
void saveToStream_DeckZone(QTextStream &out,
|
void saveToStream_DeckZone(QTextStream &out,
|
||||||
|
|
|
||||||
|
|
@ -534,7 +534,7 @@ void AbstractTabDeckEditor::actSaveDeckToClipboardRawNoSetInfo()
|
||||||
void AbstractTabDeckEditor::actPrintDeck()
|
void AbstractTabDeckEditor::actPrintDeck()
|
||||||
{
|
{
|
||||||
auto *dlg = new QPrintPreviewDialog(this);
|
auto *dlg = new QPrintPreviewDialog(this);
|
||||||
connect(dlg, &QPrintPreviewDialog::paintRequested, deckDockWidget->deckModel, &DeckListModel::printDeckList);
|
connect(dlg, &QPrintPreviewDialog::paintRequested, deckDockWidget->getDeckLoader(), &DeckLoader::printDeckList);
|
||||||
dlg->exec();
|
dlg->exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
|
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QPrinter>
|
|
||||||
#include <QProgressDialog>
|
|
||||||
#include <QTextCursor>
|
|
||||||
#include <QTextDocument>
|
|
||||||
#include <QTextStream>
|
|
||||||
#include <QTextTable>
|
|
||||||
#include <libcockatrice/card/database/card_database_manager.h>
|
#include <libcockatrice/card/database/card_database_manager.h>
|
||||||
|
|
||||||
DeckListModel::DeckListModel(QObject *parent)
|
DeckListModel::DeckListModel(QObject *parent)
|
||||||
|
|
@ -623,97 +617,3 @@ QList<QString> *DeckListModel::getZones() const
|
||||||
}
|
}
|
||||||
return zones;
|
return zones;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
|
|
||||||
{
|
|
||||||
const int totalColumns = 2;
|
|
||||||
|
|
||||||
if (node->height() == 1) {
|
|
||||||
QTextBlockFormat blockFormat;
|
|
||||||
QTextCharFormat charFormat;
|
|
||||||
charFormat.setFontPointSize(11);
|
|
||||||
charFormat.setFontWeight(QFont::Bold);
|
|
||||||
cursor->insertBlock(blockFormat, charFormat);
|
|
||||||
|
|
||||||
QTextTableFormat tableFormat;
|
|
||||||
tableFormat.setCellPadding(0);
|
|
||||||
tableFormat.setCellSpacing(0);
|
|
||||||
tableFormat.setBorder(0);
|
|
||||||
QTextTable *table = cursor->insertTable(node->size() + 1, totalColumns, tableFormat);
|
|
||||||
for (int i = 0; i < node->size(); i++) {
|
|
||||||
auto *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);
|
|
||||||
|
|
||||||
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 DeckListModel::printDeckList(QPrinter *printer)
|
|
||||||
{
|
|
||||||
QTextDocument doc;
|
|
||||||
|
|
||||||
QFont font("Serif");
|
|
||||||
font.setStyleHint(QFont::Serif);
|
|
||||||
doc.setDefaultFont(font);
|
|
||||||
|
|
||||||
QTextCursor cursor(&doc);
|
|
||||||
|
|
||||||
QTextBlockFormat headerBlockFormat;
|
|
||||||
QTextCharFormat headerCharFormat;
|
|
||||||
headerCharFormat.setFontPointSize(16);
|
|
||||||
headerCharFormat.setFontWeight(QFont::Bold);
|
|
||||||
|
|
||||||
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
|
||||||
cursor.insertText(deckList->getName());
|
|
||||||
|
|
||||||
headerCharFormat.setFontPointSize(12);
|
|
||||||
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
|
||||||
cursor.insertText(deckList->getComments());
|
|
||||||
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
|
||||||
|
|
||||||
for (int i = 0; i < root->size(); i++) {
|
|
||||||
cursor.insertHtml("<br><img src=theme:hr.jpg>");
|
|
||||||
// cursor.insertHtml("<hr>");
|
|
||||||
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
|
||||||
|
|
||||||
printDeckListNode(&cursor, dynamic_cast<InnerDecklistNode *>(root->at(i)));
|
|
||||||
}
|
|
||||||
|
|
||||||
doc.print(printer);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -132,11 +132,6 @@ public slots:
|
||||||
* state of the deck.
|
* state of the deck.
|
||||||
*/
|
*/
|
||||||
void rebuildTree();
|
void rebuildTree();
|
||||||
/**
|
|
||||||
* @brief Prints the decklist to the provided QPrinter.
|
|
||||||
* @param printer The printer to render the decklist to.
|
|
||||||
*/
|
|
||||||
void printDeckList(QPrinter *printer);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
|
|
@ -252,8 +247,6 @@ private:
|
||||||
void emitRecursiveUpdates(const QModelIndex &index);
|
void emitRecursiveUpdates(const QModelIndex &index);
|
||||||
void sortHelper(InnerDecklistNode *node, Qt::SortOrder order);
|
void sortHelper(InnerDecklistNode *node, Qt::SortOrder order);
|
||||||
|
|
||||||
void printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node);
|
|
||||||
|
|
||||||
template <typename T> T getNode(const QModelIndex &index) const
|
template <typename T> T getNode(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue