-
Notifications
You must be signed in to change notification settings - Fork 8
/
display.cpp
98 lines (83 loc) · 2.36 KB
/
display.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "display.h"
Display::Display(double imageWidth, double imageHeight, QWidget *parent) :
QWidget(parent)
{
width = imageWidth;
height = imageHeight;
disp = QImage(width, height, QImage::Format_RGB32);
disp.fill(0);
colorMap = QVector<QVector<QRgb>>(width, QVector<QRgb>(height));
}
void Display::setPixel(int i, int j, QRgb color)
{
// disp.setPixel(i, j, color);
colorMap[i][j] = color;
}
//void Display::shrink()
//{
// int newSize = disp.width();
// if (disp.width() * (1 - SCREEN_SCALING_FACTOR) >= MIN_PREVIEW_IMAGE_SIZE) {
// newSize = (int)(newSize * (1 - SCREEN_SCALING_FACTOR));
// }
// else {
// newSize = MIN_PREVIEW_IMAGE_SIZE;
// }
//
// disp = disp.scaled(newSize, newSize, Qt::KeepAspectRatio);
// update();
//}
//
//void Display::enlarge()
//{
// int newSize = disp.width();
// if (disp.width() * (1 + SCREEN_SCALING_FACTOR) <= MAX_PREVIEW_IMAGE_SIZE) {
// newSize = (int)(newSize * (1 + SCREEN_SCALING_FACTOR));
// }
// else {
// newSize = MAX_PREVIEW_IMAGE_SIZE;
// }
//
// disp = disp.scaled(newSize, newSize, Qt::KeepAspectRatio);
// update();
//}
void Display::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
mouseMoving = true;
emit displayPressed(event->pos());
}
}
void Display::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
mouseMoving = false;
emit displayReleased(event->pos());
}
}
void Display::mouseMoveEvent(QMouseEvent *event)
{
if (mouseMoving) {
emit displayMoved(event->pos());
}
}
QSize Display::changeDisplayDimensions(double width, double height) {
if (width > height) {
this->height = this->width * (double)(height/width);
} else {
this->width = this->height * (double)(width/height);
}
resetSize();
return QSize(this->width, this->height);
}
void Display::paintEvent(QPaintEvent * /* unused */)
{
QPainter painter(this);
QColor color;
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
color = QColor::fromRgb(colorMap[i][j]);
painter.setPen(color);
painter.drawPoint(i, j);
}
}
}