started implementing deck printing
This commit is contained in:
parent
fb03c5cdbb
commit
33cc7a8859
7 changed files with 87 additions and 6 deletions
|
@ -62,11 +62,21 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|||
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
||||
}
|
||||
if (counters) {
|
||||
painter->setFont(QFont("Times", 32, QFont::Bold));
|
||||
painter->setPen(QPen(Qt::black));
|
||||
painter->setBackground(QBrush(QColor(255, 255, 255, 100)));
|
||||
painter->setBackgroundMode(Qt::OpaqueMode);
|
||||
painter->drawText(boundingRect(), Qt::AlignCenter, QString::number(counters));
|
||||
QString numStr = QString::number(counters);
|
||||
QFont font("Times", 32, QFont::Bold);
|
||||
QFontMetrics fm(font);
|
||||
QRect br = fm.boundingRect(numStr);
|
||||
double w = br.width() * 1.42;
|
||||
double h = br.height() * 1.42;
|
||||
if (w < h)
|
||||
w = h;
|
||||
|
||||
painter->setPen(Qt::black);
|
||||
painter->setBrush(QColor(255, 255, 255, 150));
|
||||
painter->drawEllipse(QRectF((boundingRect().width() - w) / 2.0, (boundingRect().height() - h) / 2.0, w, h));
|
||||
|
||||
painter->setFont(font);
|
||||
painter->drawText(boundingRect(), Qt::AlignCenter, numStr);
|
||||
}
|
||||
painter->restore();
|
||||
}
|
||||
|
|
|
@ -53,6 +53,11 @@ AbstractDecklistNode *InnerDecklistNode::findChild(const QString &name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int InnerDecklistNode::height() const
|
||||
{
|
||||
return at(0)->height() + 1;
|
||||
}
|
||||
|
||||
int InnerDecklistNode::recursiveCount(bool countTotalCards) const
|
||||
{
|
||||
int result = 0;
|
||||
|
|
|
@ -19,6 +19,7 @@ public:
|
|||
virtual QString getName() const = 0;
|
||||
InnerDecklistNode *getParent() const { return parent; }
|
||||
int depth() const;
|
||||
virtual int height() const = 0;
|
||||
virtual bool compare(AbstractDecklistNode *other) const = 0;
|
||||
};
|
||||
|
||||
|
@ -34,6 +35,7 @@ public:
|
|||
virtual QString getVisibleName() const;
|
||||
void clearTree();
|
||||
AbstractDecklistNode *findChild(const QString &name);
|
||||
int height() const;
|
||||
int recursiveCount(bool countTotalCards = false) const;
|
||||
bool compare(AbstractDecklistNode *other) const;
|
||||
void sort(Qt::SortOrder order = Qt::AscendingOrder);
|
||||
|
@ -46,6 +48,7 @@ public:
|
|||
virtual void setNumber(int _number) = 0;
|
||||
virtual QString getName() const = 0;
|
||||
virtual void setName(const QString &_name) = 0;
|
||||
int height() const { return 0; }
|
||||
bool compare(AbstractDecklistNode *other) const;
|
||||
};
|
||||
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
#include <QTextStream>
|
||||
#include <QFont>
|
||||
#include <QBrush>
|
||||
#include <QTextCursor>
|
||||
#include <QTextDocument>
|
||||
#include <QPrinter>
|
||||
#include <QTextTable>
|
||||
#include "decklistmodel.h"
|
||||
#include "carddatabase.h"
|
||||
|
||||
|
@ -282,3 +286,43 @@ void DeckListModel::cleanList()
|
|||
deckList->cleanList();
|
||||
reset();
|
||||
}
|
||||
|
||||
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
|
||||
{
|
||||
cursor->insertBlock();
|
||||
cursor->insertText(node->getVisibleName());
|
||||
if (node->height() == 1) {
|
||||
QTextTableFormat tableFormat;
|
||||
// XXX
|
||||
QTextTable *table = cursor->insertTable(node->size(), 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();
|
||||
cellCursor.insertText(card->getName());
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < node->size(); i++)
|
||||
printDeckListNode(cursor, dynamic_cast<InnerDecklistNode *>(node->at(i)));
|
||||
}
|
||||
cursor->movePosition(QTextCursor::End);
|
||||
}
|
||||
|
||||
void DeckListModel::printDeckList(QPrinter *printer)
|
||||
{
|
||||
QTextDocument doc;
|
||||
QTextCursor cursor(&doc);
|
||||
|
||||
cursor.insertBlock();
|
||||
cursor.insertText(deckList->getName());
|
||||
|
||||
cursor.insertBlock();
|
||||
cursor.insertText(deckList->getComments());
|
||||
|
||||
for (int i = 0; i < root->size(); i++)
|
||||
printDeckListNode(&cursor, dynamic_cast<InnerDecklistNode *>(root->at(i)));
|
||||
|
||||
doc.print(printer);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include "decklist.h"
|
||||
|
||||
class CardDatabase;
|
||||
class QPrinter;
|
||||
class QTextCursor;
|
||||
|
||||
class DecklistModelCardNode : public AbstractDecklistCardNode {
|
||||
private:
|
||||
|
@ -23,6 +25,8 @@ class DeckListModel : public QAbstractItemModel {
|
|||
Q_OBJECT
|
||||
private slots:
|
||||
void rebuildTree();
|
||||
public slots:
|
||||
void printDeckList(QPrinter *printer);
|
||||
public:
|
||||
DeckListModel(CardDatabase *_db, QObject *parent = 0);
|
||||
~DeckListModel();
|
||||
|
@ -48,6 +52,8 @@ private:
|
|||
void emitRecursiveUpdates(const QModelIndex &index);
|
||||
void debugIndexInfo(const QString &func, const QModelIndex &index) const;
|
||||
void debugShowTree(InnerDecklistNode *node, int depth) const;
|
||||
|
||||
void printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node);
|
||||
|
||||
template<typename T> T getNode(const QModelIndex &index) const
|
||||
{
|
||||
|
|
|
@ -94,6 +94,9 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent)
|
|||
aSaveDeckAs = new QAction(tr("&Save deck as..."), this);
|
||||
// aSaveDeckAs->setShortcuts(QKeySequence::SaveAs);
|
||||
connect(aSaveDeckAs, SIGNAL(triggered()), this, SLOT(actSaveDeckAs()));
|
||||
aPrintDeck = new QAction(tr("&Print deck..."), this);
|
||||
aPrintDeck->setShortcuts(QKeySequence::Print);
|
||||
connect(aPrintDeck, SIGNAL(triggered()), this, SLOT(actPrintDeck()));
|
||||
aClose = new QAction(tr("&Close"), this);
|
||||
aClose->setShortcut(tr("Ctrl+Q"));
|
||||
connect(aClose, SIGNAL(triggered()), this, SLOT(close()));
|
||||
|
@ -107,6 +110,8 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent)
|
|||
deckMenu->addAction(aSaveDeck);
|
||||
deckMenu->addAction(aSaveDeckAs);
|
||||
deckMenu->addSeparator();
|
||||
deckMenu->addAction(aPrintDeck);
|
||||
deckMenu->addSeparator();
|
||||
deckMenu->addAction(aClose);
|
||||
|
||||
setsMenu = menuBar()->addMenu(tr("&Sets"));
|
||||
|
@ -234,6 +239,13 @@ bool WndDeckEditor::actSaveDeckAs()
|
|||
return false;
|
||||
}
|
||||
|
||||
void WndDeckEditor::actPrintDeck()
|
||||
{
|
||||
QPrintPreviewDialog *dlg = new QPrintPreviewDialog(this);
|
||||
connect(dlg, SIGNAL(paintRequested(QPrinter *)), deckModel, SLOT(printDeckList(QPrinter *)));
|
||||
dlg->exec();
|
||||
}
|
||||
|
||||
void WndDeckEditor::actEditSets()
|
||||
{
|
||||
WndSets *w = new WndSets(db, this);
|
||||
|
|
|
@ -24,6 +24,7 @@ private slots:
|
|||
void actLoadDeck();
|
||||
bool actSaveDeck();
|
||||
bool actSaveDeckAs();
|
||||
void actPrintDeck();
|
||||
|
||||
void actEditSets();
|
||||
|
||||
|
@ -49,7 +50,7 @@ private:
|
|||
QLineEdit *searchEdit, *nameEdit, *commentsEdit;
|
||||
|
||||
QMenu *deckMenu, *setsMenu;
|
||||
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aClose;
|
||||
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aPrintDeck, *aClose;
|
||||
QAction *aEditSets;
|
||||
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue