1 | #include "deckmodel.h" |
---|
2 | |
---|
3 | #include <QPainter> |
---|
4 | |
---|
5 | using namespace QPunchCard; |
---|
6 | |
---|
7 | DeckModel::DeckModel(QObject* parent) : QAbstractListModel(parent) { |
---|
8 | icon_size = QSize(73, 32) * 3; |
---|
9 | } |
---|
10 | |
---|
11 | void DeckModel::setDeck(Deck* f) { |
---|
12 | this->deck = f; |
---|
13 | cardwidgets.clear(); |
---|
14 | if(deck) { |
---|
15 | // Widgets fuer alle Karten erstellen |
---|
16 | QVectorIterator< QPointer<Card> > i(*deck); |
---|
17 | while(i.hasNext()) { |
---|
18 | CardWidget* w = new CardWidget; // wird nicht kompilieren => dann 0 setzen. |
---|
19 | w->setCard(i.next()); |
---|
20 | w->setQuality(CardWidget::ThumbnailQuality); |
---|
21 | w->setGeometry( QRect(QPoint(), icon_size) ); |
---|
22 | cardwidgets.append(w); |
---|
23 | } |
---|
24 | } |
---|
25 | } |
---|
26 | |
---|
27 | QVariant DeckModel::data(const QModelIndex &index, int role) const { |
---|
28 | if(! index.isValid()) |
---|
29 | return QVariant(); |
---|
30 | |
---|
31 | if(role == Qt::DecorationRole) { |
---|
32 | // hm... will ne Deko kriegen und so |
---|
33 | int i = index.row(); |
---|
34 | if(i <= cardwidgets.count()) |
---|
35 | //qDebug("Zeichne Karte %d von %d (%d)", i, cardwidgets.count(), deck->count()); |
---|
36 | return QPixmap::grabWidget( cardwidgets[i], QRect(QPoint(), icon_size)); |
---|
37 | } else if(role == Qt::DisplayRole) { |
---|
38 | return tr("Card %1").arg(index.row()); |
---|
39 | } else if(role == Qt::StatusTipRole) { |
---|
40 | return tr("You can <b>click and move</b> this card in the deck. Or <b>select multiple cards<b> with the rubberband."); |
---|
41 | } |
---|
42 | |
---|
43 | return QVariant(); |
---|
44 | } |
---|
45 | |
---|
46 | Qt::ItemFlags DeckModel::flags(const QModelIndex &index) const { |
---|
47 | if(index.isValid()) |
---|
48 | return (Qt::ItemIsEnabled | Qt::ItemIsSelectable); |
---|
49 | else |
---|
50 | return 0; |
---|
51 | } |
---|
52 | |
---|
53 | int DeckModel::rowCount(const QModelIndex &parent) const { |
---|
54 | if(parent.isValid()) |
---|
55 | return 0; |
---|
56 | else |
---|
57 | return deck->size(); |
---|
58 | } |
---|
59 | |
---|
60 | void DeckModel::contentsChanged(int left, int right) { |
---|
61 | emit dataChanged( index(left), index(right)); |
---|
62 | } |
---|