root/src/examples/flowingcanvas/flowwidget.h @ 167:4a9556a866ac

Revision 167:4a9556a866ac, 1.5 KB (checked in by Andreas Schaefer <gentryx@…>, 15 months ago)

presentable version

Line 
1#ifndef _libgeodecomp_examples_flowingcanvas_flowwidget_h_
2#define _libgeodecomp_examples_flowingcanvas_flowwidget_h_
3
4#include <iostream>
5#include <QKeyEvent>
6#include <QPainter>
7#include <QWidget>
8#include <libgeodecomp/examples/latticegas/fpscounter.h>
9
10class FlowWidget : public QWidget, FPSCounter
11{
12    Q_OBJECT
13
14public:
15    FlowWidget() :
16        frameCounter(0),
17        image(1024, 768, QImage::Format_ARGB32)
18    {
19        setFocusPolicy(Qt::StrongFocus);
20    }
21
22    // fixme: do we need to always draw the whole image?
23    virtual void paintEvent(QPaintEvent * /* event */)
24    {
25        QPainter painter(this);
26
27        painter.drawImage(0, 0, image);
28
29        painter.setPen(Qt::green);
30        painter.drawText(32, 32, "Frame " + QString::number(frameCounter));
31        ++frameCounter;
32    }
33
34    virtual void keyPressEvent(QKeyEvent *event)
35    {
36        std::cout << "got key " << event->key() << "\n";
37        if (event->key() == Qt::Key_Space) {
38            emit cycleViewModeParticle();
39        }
40
41        if (event->key() == Qt::Key_Enter) {
42            emit cycleViewModeCamera();
43        }
44    }
45
46public slots:
47    void ping()
48    {
49        emit updateImage(&image);
50        // if (simParamsHost.dumpFrames)
51        //     dumpFrame();
52        update();
53        incFrames();
54    }
55
56    void info()
57    {
58        std::cout << "FlowWidget @ " << fps() << " FPS\n";
59    }
60
61signals:
62    void updateImage(QImage*);
63    void cycleViewModeParticle();
64    void cycleViewModeCamera();
65
66private:
67    int frameCounter;
68    QImage image;
69};
70
71#endif
Note: See TracBrowser for help on using the browser.