nice decklist printing

This commit is contained in:
Max-Wilhelm Bruker 2009-06-27 20:53:24 +02:00
parent c9f680f25f
commit 5d40996c0b
3 changed files with 83 additions and 21 deletions

View file

@ -289,23 +289,60 @@ void DeckListModel::cleanList()
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
{
cursor->insertBlock();
cursor->insertText(node->getVisibleName());
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;
// XXX
QTextTable *table = cursor->insertTable(node->size(), 2, 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));
QTextCursor cellCursor = table->cellAt(i, 0).firstCursorPosition();
cellCursor.insertText(QString::number(card->getNumber()));
cellCursor = table->cellAt(i, 1).firstCursorPosition();
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 {
for (int i = 0; i < node->size(); i++)
printDeckListNode(cursor, dynamic_cast<InnerDecklistNode *>(node->at(i)));
} 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);
}
@ -313,16 +350,32 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no
void DeckListModel::printDeckList(QPrinter *printer)
{
QTextDocument doc;
/* QFont font("Times");
font.setStyleHint(QFont::Serif);
doc.setDefaultFont(font);
*/
QTextCursor cursor(&doc);
cursor.insertBlock();
QTextBlockFormat headerBlockFormat;
QTextCharFormat headerCharFormat;
headerCharFormat.setFontPointSize(16);
headerCharFormat.setFontWeight(QFont::Bold);
cursor.insertBlock(headerBlockFormat, headerCharFormat);
cursor.insertText(deckList->getName());
cursor.insertBlock();
headerCharFormat.setFontPointSize(12);
cursor.insertBlock(headerBlockFormat, headerCharFormat);
cursor.insertText(deckList->getComments());
for (int i = 0; i < root->size(); i++)
cursor.insertBlock(headerBlockFormat, headerCharFormat);
for (int i = 0; i < root->size(); i++) {
cursor.insertHtml("<hr>");
cursor.insertBlock(headerBlockFormat, headerCharFormat);
printDeckListNode(&cursor, dynamic_cast<InnerDecklistNode *>(root->at(i)));
}
doc.print(printer);
}

View file

@ -58,9 +58,10 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent)
nameLabel->setBuddy(nameEdit);
connect(nameEdit, SIGNAL(textChanged(const QString &)), deckModel->getDeckList(), SLOT(setName(const QString &)));
QLabel *commentsLabel = new QLabel(tr("&Comments:"));
commentsEdit = new QLineEdit;
commentsEdit = new QTextEdit;
commentsEdit->setMaximumHeight(70);
commentsLabel->setBuddy(commentsEdit);
connect(commentsEdit, SIGNAL(textChanged(const QString &)), deckModel->getDeckList(), SLOT(setComments(const QString &)));
connect(commentsEdit, SIGNAL(textChanged()), this, SLOT(updateComments()));
QGridLayout *grid = new QGridLayout;
grid->addWidget(nameLabel, 0, 0);
grid->addWidget(nameEdit, 0, 1);
@ -145,6 +146,11 @@ WndDeckEditor::~WndDeckEditor()
}
void WndDeckEditor::updateComments()
{
deckModel->getDeckList()->setComments(commentsEdit->toPlainText());
}
void WndDeckEditor::updateCardInfoLeft(const QModelIndex &current, const QModelIndex &/*previous*/)
{
cardInfo->setCard(current.sibling(current.row(), 0).data().toString());

View file

@ -12,10 +12,12 @@ class QTreeView;
class QTableView;
class CardInfoWidget;
class QLineEdit;
class QTextEdit;
class WndDeckEditor : public QMainWindow {
Q_OBJECT
private slots:
void updateComments();
void updateCardInfoLeft(const QModelIndex &current, const QModelIndex &previous);
void updateCardInfoRight(const QModelIndex &current, const QModelIndex &previous);
void updateSearch(const QString &search);
@ -47,7 +49,8 @@ private:
QTreeView *databaseView;
QTreeView *deckView;
CardInfoWidget *cardInfo;
QLineEdit *searchEdit, *nameEdit, *commentsEdit;
QLineEdit *searchEdit, *nameEdit;
QTextEdit *commentsEdit;
QMenu *deckMenu, *setsMenu;
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aPrintDeck, *aClose;