NNFS
Neural network library from scratch
Loading...
Searching...
No Matches
canvas.h
Go to the documentation of this file.
1#ifndef CANVAS_H
2#define CANVAS_H
3
4#include <QWidget>
5#include <QLabel>
6#include <QVBoxLayout>
7#include <QMouseEvent>
8#include <QPainter>
9#include <Eigen/Core>
10
16class Canvas : public QLabel
17{
18 Q_OBJECT
19
20public:
26 explicit Canvas(QWidget *parent = nullptr);
27
31 void clearImage();
32
36 void restartCanvas();
37
43 Eigen::MatrixXd getMatrix();
44
50 bool isDrawing() { return drawing; }
51
52protected:
58 void mousePressEvent(QMouseEvent *event) override;
59
65 void mouseMoveEvent(QMouseEvent *event) override;
66
72 void mouseReleaseEvent(QMouseEvent *event) override;
73
74private:
75 bool drawing;
76 QImage image;
77 QPointF lastPoint;
78 Eigen::MatrixXd image_matrix = Eigen::MatrixXd::Zero(1, 784);
79};
80
81#endif // CANVAS_H
The Canvas class represents a custom widget for drawing on a canvas.
Definition canvas.h:17
void mouseReleaseEvent(QMouseEvent *event) override
Handles the mouse release event.
Definition canvas.cpp:54
void clearImage()
Clears the image on the canvas.
Definition canvas.cpp:13
Eigen::MatrixXd getMatrix()
Gets the matrix representation of the image on the canvas.
Definition canvas.cpp:24
bool isDrawing()
Checks if the user is currently drawing on the canvas.
Definition canvas.h:50
void mousePressEvent(QMouseEvent *event) override
Handles the mouse press event.
Definition canvas.cpp:29
void restartCanvas()
Restarts the canvas by clearing the image and resetting the drawing state.
Definition canvas.cpp:19
void mouseMoveEvent(QMouseEvent *event) override
Handles the mouse move event.
Definition canvas.cpp:38