forked from andrewbalan/Neural-network-Qt-C-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
digitviewer.cpp
58 lines (47 loc) · 1.32 KB
/
digitviewer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "digitviewer.h"
#include "QDebug"
#include "QPainter"
DigitViewer::DigitViewer(char* digits, QWidget *parent ) : QWidget(parent)
{
setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
data = digits;
}
DigitViewer::DigitViewer(QWidget *parent) : QWidget(parent)
{
setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
data = new char[dimension];
for (int i = 0; i < dimension; ++i) {
data[i] = 5;
}
}
void DigitViewer::paintEvent(QPaintEvent *)
{
QPainter ptr(this);
ptr.fillRect(rect(), Qt::white);
ptr.setPen(QColor(50, 50, 50, 0));
for (int row = 0; row < side; ++row) {
for (int col = 0; col < side; ++col) {
unsigned char alpha = (unsigned char) data[row * side + col];
ptr.setBrush ( QBrush(QColor(0, 0, 0, alpha)) );
int x = row * squareSize;
int y = col * squareSize;
ptr.drawRect (y, x, squareSize, squareSize);
}
}
}
QSize DigitViewer::sizeHint() const
{
int width = side * squareSize;
return(QSize(width + 1, width + 1));
}
void DigitViewer::changeData(double* digits)
{
for (int i = 0; i < dimension; ++i) {
data[i] = digits[i];
}
repaint();
}
DigitViewer::~DigitViewer()
{
delete[] data;
}