source: projects/punch-card/punch-card-editor/src/qpunchcard/widget.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: 2.3 KB
Line 
1#include <QPainter>
2
3#include "widget.h"
4
5using namespace QPunchCard;
6
7CardWidget::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
20int CardWidget::heightForWidth(int width) const {
21        return (int)( ((float)width / 7375) * 3250 );
22}
23
24QSize CardWidget::minimumSizeHint() const {
25        return QSize(73, 32);
26}
27
28QSize CardWidget::sizeHint() const {
29        return QSize(737, 325);
30}
31
32void 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
83QDebug 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}
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