Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
33cc7a88
Commit
33cc7a88
authored
Jun 26, 2009
by
Max-Wilhelm Bruker
Browse files
started implementing deck printing
parent
fb03c5cd
Changes
7
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/carditem.cpp
View file @
33cc7a88
...
...
@@ -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
();
}
...
...
cockatrice/src/decklist.cpp
View file @
33cc7a88
...
...
@@ -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
;
...
...
cockatrice/src/decklist.h
View file @
33cc7a88
...
...
@@ -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
;
};
...
...
cockatrice/src/decklistmodel.cpp
View file @
33cc7a88
...
...
@@ -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
);
}
cockatrice/src/decklistmodel.h
View file @
33cc7a88
...
...
@@ -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
{
...
...
cockatrice/src/window_deckeditor.cpp
View file @
33cc7a88
...
...
@@ -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
);
...
...
cockatrice/src/window_deckeditor.h
View file @
33cc7a88
...
...
@@ -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:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment