nice decklist printing
This commit is contained in:
parent
c9f680f25f
commit
5d40996c0b
3 changed files with 83 additions and 21 deletions
|
@ -289,23 +289,60 @@ void DeckListModel::cleanList()
|
||||||
|
|
||||||
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
|
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
|
||||||
{
|
{
|
||||||
cursor->insertBlock();
|
static const int totalColumns = 3;
|
||||||
cursor->insertText(node->getVisibleName());
|
|
||||||
if (node->height() == 1) {
|
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;
|
QTextTableFormat tableFormat;
|
||||||
// XXX
|
tableFormat.setCellPadding(0);
|
||||||
QTextTable *table = cursor->insertTable(node->size(), 2, tableFormat);
|
tableFormat.setCellSpacing(0);
|
||||||
|
tableFormat.setBorder(0);
|
||||||
|
QTextTable *table = cursor->insertTable(node->size() + 1, 2, tableFormat);
|
||||||
for (int i = 0; i < node->size(); i++) {
|
for (int i = 0; i < node->size(); i++) {
|
||||||
AbstractDecklistCardNode *card = dynamic_cast<AbstractDecklistCardNode *>(node->at(i));
|
AbstractDecklistCardNode *card = dynamic_cast<AbstractDecklistCardNode *>(node->at(i));
|
||||||
|
|
||||||
QTextCursor cellCursor = table->cellAt(i, 0).firstCursorPosition();
|
QTextCharFormat cellCharFormat;
|
||||||
cellCursor.insertText(QString::number(card->getNumber()));
|
cellCharFormat.setFontPointSize(9);
|
||||||
cellCursor = table->cellAt(i, 1).firstCursorPosition();
|
|
||||||
|
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());
|
cellCursor.insertText(card->getName());
|
||||||
}
|
}
|
||||||
} else {
|
} else if (node->height() == 2) {
|
||||||
for (int i = 0; i < node->size(); i++)
|
QTextBlockFormat blockFormat;
|
||||||
printDeckListNode(cursor, dynamic_cast<InnerDecklistNode *>(node->at(i)));
|
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);
|
cursor->movePosition(QTextCursor::End);
|
||||||
}
|
}
|
||||||
|
@ -313,16 +350,32 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no
|
||||||
void DeckListModel::printDeckList(QPrinter *printer)
|
void DeckListModel::printDeckList(QPrinter *printer)
|
||||||
{
|
{
|
||||||
QTextDocument doc;
|
QTextDocument doc;
|
||||||
|
|
||||||
|
/* QFont font("Times");
|
||||||
|
font.setStyleHint(QFont::Serif);
|
||||||
|
doc.setDefaultFont(font);
|
||||||
|
*/
|
||||||
QTextCursor cursor(&doc);
|
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.insertText(deckList->getName());
|
||||||
|
|
||||||
cursor.insertBlock();
|
headerCharFormat.setFontPointSize(12);
|
||||||
|
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
||||||
cursor.insertText(deckList->getComments());
|
cursor.insertText(deckList->getComments());
|
||||||
|
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
||||||
for (int i = 0; i < root->size(); i++)
|
|
||||||
|
for (int i = 0; i < root->size(); i++) {
|
||||||
|
cursor.insertHtml("<hr>");
|
||||||
|
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
||||||
|
|
||||||
printDeckListNode(&cursor, dynamic_cast<InnerDecklistNode *>(root->at(i)));
|
printDeckListNode(&cursor, dynamic_cast<InnerDecklistNode *>(root->at(i)));
|
||||||
|
}
|
||||||
|
|
||||||
doc.print(printer);
|
doc.print(printer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,9 +58,10 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent)
|
||||||
nameLabel->setBuddy(nameEdit);
|
nameLabel->setBuddy(nameEdit);
|
||||||
connect(nameEdit, SIGNAL(textChanged(const QString &)), deckModel->getDeckList(), SLOT(setName(const QString &)));
|
connect(nameEdit, SIGNAL(textChanged(const QString &)), deckModel->getDeckList(), SLOT(setName(const QString &)));
|
||||||
QLabel *commentsLabel = new QLabel(tr("&Comments:"));
|
QLabel *commentsLabel = new QLabel(tr("&Comments:"));
|
||||||
commentsEdit = new QLineEdit;
|
commentsEdit = new QTextEdit;
|
||||||
|
commentsEdit->setMaximumHeight(70);
|
||||||
commentsLabel->setBuddy(commentsEdit);
|
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;
|
QGridLayout *grid = new QGridLayout;
|
||||||
grid->addWidget(nameLabel, 0, 0);
|
grid->addWidget(nameLabel, 0, 0);
|
||||||
grid->addWidget(nameEdit, 0, 1);
|
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*/)
|
void WndDeckEditor::updateCardInfoLeft(const QModelIndex ¤t, const QModelIndex &/*previous*/)
|
||||||
{
|
{
|
||||||
cardInfo->setCard(current.sibling(current.row(), 0).data().toString());
|
cardInfo->setCard(current.sibling(current.row(), 0).data().toString());
|
||||||
|
|
|
@ -12,10 +12,12 @@ class QTreeView;
|
||||||
class QTableView;
|
class QTableView;
|
||||||
class CardInfoWidget;
|
class CardInfoWidget;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
|
class QTextEdit;
|
||||||
|
|
||||||
class WndDeckEditor : public QMainWindow {
|
class WndDeckEditor : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
|
void updateComments();
|
||||||
void updateCardInfoLeft(const QModelIndex ¤t, const QModelIndex &previous);
|
void updateCardInfoLeft(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
void updateCardInfoRight(const QModelIndex ¤t, const QModelIndex &previous);
|
void updateCardInfoRight(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
void updateSearch(const QString &search);
|
void updateSearch(const QString &search);
|
||||||
|
@ -47,7 +49,8 @@ private:
|
||||||
QTreeView *databaseView;
|
QTreeView *databaseView;
|
||||||
QTreeView *deckView;
|
QTreeView *deckView;
|
||||||
CardInfoWidget *cardInfo;
|
CardInfoWidget *cardInfo;
|
||||||
QLineEdit *searchEdit, *nameEdit, *commentsEdit;
|
QLineEdit *searchEdit, *nameEdit;
|
||||||
|
QTextEdit *commentsEdit;
|
||||||
|
|
||||||
QMenu *deckMenu, *setsMenu;
|
QMenu *deckMenu, *setsMenu;
|
||||||
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aPrintDeck, *aClose;
|
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aPrintDeck, *aClose;
|
||||||
|
|
Loading…
Reference in a new issue