From 5d40996c0bab74347ebcee63c2ad2edb5f9a5338 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Sat, 27 Jun 2009 20:53:24 +0200 Subject: [PATCH] nice decklist printing --- cockatrice/src/decklistmodel.cpp | 89 ++++++++++++++++++++++------ cockatrice/src/window_deckeditor.cpp | 10 +++- cockatrice/src/window_deckeditor.h | 5 +- 3 files changed, 83 insertions(+), 21 deletions(-) diff --git a/cockatrice/src/decklistmodel.cpp b/cockatrice/src/decklistmodel.cpp index f7fdc4b4..a89841fb 100644 --- a/cockatrice/src/decklistmodel.cpp +++ b/cockatrice/src/decklistmodel.cpp @@ -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(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(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 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(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("
"); + cursor.insertBlock(headerBlockFormat, headerCharFormat); + printDeckListNode(&cursor, dynamic_cast(root->at(i))); - + } + doc.print(printer); } diff --git a/cockatrice/src/window_deckeditor.cpp b/cockatrice/src/window_deckeditor.cpp index 60075733..2b0f304d 100644 --- a/cockatrice/src/window_deckeditor.cpp +++ b/cockatrice/src/window_deckeditor.cpp @@ -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 ¤t, const QModelIndex &/*previous*/) { cardInfo->setCard(current.sibling(current.row(), 0).data().toString()); diff --git a/cockatrice/src/window_deckeditor.h b/cockatrice/src/window_deckeditor.h index c5d67c76..6390608a 100644 --- a/cockatrice/src/window_deckeditor.h +++ b/cockatrice/src/window_deckeditor.h @@ -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 ¤t, const QModelIndex &previous); void updateCardInfoRight(const QModelIndex ¤t, 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;