1 | #include <QPainter> |
---|
2 | |
---|
3 | #include "widget.h" |
---|
4 | |
---|
5 | using namespace QPunchCard; |
---|
6 | |
---|
7 | CardWidget::CardWidget(QWidget * parent, Qt::WFlags f) { |
---|
8 | QWidget(parent,f); |
---|
9 | QSizePolicy size(QSizePolicy::Expanding, QSizePolicy::Expanding); |
---|
10 | // Lochkartenmasse: bloederweise nur uchar als Datenbereich!? |
---|
11 | size.setHorizontalStretch(74); |
---|
12 | size.setVerticalStretch(33); |
---|
13 | size.setHeightForWidth(true); |
---|
14 | |
---|
15 | setQuality(HighQuality); |
---|
16 | setSizePolicy(size); |
---|
17 | updateGeometry(); |
---|
18 | } |
---|
19 | |
---|
20 | int CardWidget::heightForWidth(int width) const { |
---|
21 | return (int)( ((float)width / 7375) * 3250 ); |
---|
22 | } |
---|
23 | |
---|
24 | QSize CardWidget::minimumSizeHint() const { |
---|
25 | return QSize(73, 32); |
---|
26 | } |
---|
27 | |
---|
28 | QSize CardWidget::sizeHint() const { |
---|
29 | return QSize(737, 325); |
---|
30 | } |
---|
31 | |
---|
32 | void CardWidget::paintEvent(QPaintEvent*) { |
---|
33 | QPainter painter(this); |
---|
34 | // internal coordinate system will measure in thou (1/1000 inch) |
---|
35 | // so the painting size is |
---|
36 | QRect bound = QRect(0,0, 7375, 3250); |
---|
37 | // width: 7-3/8 inch, height: 3-1/4 inch |
---|
38 | |
---|
39 | // hole dimensions: |
---|
40 | QRect hole = QRect(0,0,55,125); |
---|
41 | |
---|
42 | // prepare for painting |
---|
43 | if(quality() == HighQuality) |
---|
44 | painter.setRenderHint(QPainter::Antialiasing); |
---|
45 | painter.setWindow(bound); |
---|
46 | |
---|
47 | // paint punch card |
---|
48 | painter.setPen(Qt::lightGray); |
---|
49 | painter.drawRoundedRect(bound, 100.0, 100.0); |
---|
50 | |
---|
51 | // now iterate the columns of the card |
---|
52 | if(!card) { |
---|
53 | // keine Karte, nix machen... |
---|
54 | // vielleicht was drauf schreiben oder so... |
---|
55 | return; |
---|
56 | } |
---|
57 | |
---|
58 | int col, row; // counters |
---|
59 | QPoint hole_center; |
---|
60 | for(col=0; col < 80; col++) { |
---|
61 | // card.columns[i] would be the actual column |
---|
62 | for(row = 0; row < 12; row++) { |
---|
63 | // card.columns[col][row] would it be... |
---|
64 | // move our hole around |
---|
65 | hole_center.rx() = 251 + col * 87; |
---|
66 | hole_center.ry() = 250 * (row + 1); |
---|
67 | hole.moveCenter(hole_center); |
---|
68 | |
---|
69 | painter.setPen(Qt::black); |
---|
70 | |
---|
71 | static const int transform[] = {12,11,0,1,2,3,4,5,6,7,8,9}; |
---|
72 | //qDebug("Will ausgeben: row=%d, transform=%d < SIZE=%d", row, transform[row], card->get(col).size()); |
---|
73 | if(card->get(col).at( transform[row] )) |
---|
74 | // gelocht |
---|
75 | painter.fillRect(hole, Qt::black); |
---|
76 | else if(quality() != ThumbnailQuality) |
---|
77 | // ungelocht, nur high quality zeichnen |
---|
78 | painter.fillRect(hole, Qt::white); |
---|
79 | } |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | QDebug QPunchCard::operator<<(QDebug dbg, const CardWidget &c) { |
---|
84 | dbg.nospace() << "This is CardWidget, holding " << (c.getCard() ? "this card" : "no card"); |
---|
85 | if(c.getCard()) |
---|
86 | dbg.nospace() << *c.getCard(); |
---|
87 | return dbg.nospace(); |
---|
88 | } |
---|