source: projects/punch-card/punch-card-editor/src/qpunchcard/deckmodel.cc @ 44

Last change on this file since 44 was 44, checked in by sven, 14 years ago

Import of the Punch Card Editor Project.
This is a C++/Qt project (using qmake) that I've started this weekend.
Of course it's supposed to be released as open source.

I've tried to start with a clean (but now still empty, of course)
directory structure. There will come the sourcecode for a complete
AVR ATmega microcontroller punch card device controller, soon.
I'm planing to finish this editing program and to implement the
communication protocol (over TTY, using some platform indepentent library).
Unfortunately that will take some time (and I don't have much time
any more...)

-- Sven @ workstation

File size: 1.6 KB
Line 
1#include "deckmodel.h"
2
3#include <QPainter>
4
5using namespace QPunchCard;
6
7DeckModel::DeckModel(QObject* parent) : QAbstractListModel(parent) {
8        icon_size = QSize(73, 32) * 3;
9}
10
11void 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
27QVariant 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
46Qt::ItemFlags DeckModel::flags(const QModelIndex &index) const {
47        if(index.isValid())
48                return (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
49        else
50                return 0;
51}
52
53int DeckModel::rowCount(const QModelIndex &parent) const {
54        if(parent.isValid())
55                return 0;
56        else
57                return deck->size();
58}
59
60void DeckModel::contentsChanged(int left, int right) {
61        emit dataChanged( index(left), index(right));
62}
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License