Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | Werner | 1 | |
2 | #include <QtGui> |
||
3 | |||
4 | #include "paintarea.h" |
||
5 | |||
6 | PaintArea::PaintArea(QWidget *parent) |
||
7 | : QWidget(parent) |
||
8 | { |
||
9 | //QTimer *timer = new QTimer(this); |
||
10 | //connect(timer, SIGNAL(timeout()), this, SLOT(update())); |
||
11 | //timer->start(1000); |
||
12 | |||
13 | //setWindowTitle(tr("Analog Clock")); |
||
7 | Werner | 14 | //resize(200, 200); |
21 | Werner | 15 | m_bitmap = QImage(this->size(), QImage::Format_ARGB32); |
49 | Werner | 16 | // enable mouse tracking |
17 | this->setMouseTracking(true); |
||
21 | Werner | 18 | |
3 | Werner | 19 | } |
20 | |||
21 | Werner | 21 | void PaintArea::resizeEvent(QResizeEvent *event) |
22 | { |
||
23 | m_bitmap = QImage(this->size(), QImage::Format_ARGB32); |
||
24 | qDebug() << "paintarea resize" << this->size(); |
||
25 | } |
||
3 | Werner | 26 | void PaintArea::paintEvent(QPaintEvent *) |
27 | { |
||
28 | |||
21 | Werner | 29 | QPainter painter(this); |
30 | QPainter pxpainter(&m_bitmap); |
||
31 | |||
32 | //QPainter pxpainter(m_bitmap); |
||
33 | //painter.drawRect(0, 0, width()-1, height()-1); |
||
34 | |||
35 | emit needsPainting(pxpainter); |
||
36 | painter.drawImage(rect(), m_bitmap); |
||
37 | //painter.drawPixmap(rect(), m_bitmap); |
||
3 | Werner | 38 | //painter.drawPixmap(0, 0, |
9 | Werner | 39 | // QStylePainter spainter(this); |
40 | // QStyleOption opt; |
||
41 | // spainter.drawPrimitive(QStyle::PE_PanelButtonCommand, opt); |
||
3 | Werner | 42 | |
43 | } |
||
6 | Werner | 44 | |
45 | void PaintArea::mousePressEvent ( QMouseEvent * event ) |
||
46 | { |
||
40 | Werner | 47 | m_lastDown = event->pos(); |
6 | Werner | 48 | emit mouseClick(event->pos()); |
49 | Werner | 49 | } |
6 | Werner | 50 | |
49 | Werner | 51 | void PaintArea::mouseMoveEvent( QMouseEvent * event ) |
52 | { |
||
53 | emit mouseMove(event->pos()); |
||
54 | } |
||
6 | Werner | 55 | |
113 | Werner | 56 | void PaintArea::wheelEvent ( QWheelEvent * event ) |
57 | { |
||
58 | emit mouseWheel(event->pos(), event->delta() / 120); |
||
59 | } |
||
60 | |||
40 | Werner | 61 | void PaintArea::mouseReleaseEvent ( QMouseEvent * event ) |
62 | { |
||
63 | setCursor(Qt::CrossCursor); |
||
113 | Werner | 64 | |
40 | Werner | 65 | if ( (event->pos()-m_lastDown).manhattanLength() > 3) { |
113 | Werner | 66 | emit mouseDrag(m_lastDown, event->pos(), event->button()); |
40 | Werner | 67 | } |
68 | //emit mouseClick(event->pos()); |
||
69 | //emit needsPainting(painter); |
||
70 | } |