-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpainter.h
38 lines (35 loc) · 1.04 KB
/
painter.h
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
#ifndef PAINTER_H
#define PAINTER_H
#include <QtWidgets>
#include <iostream>
class Painter : public QWidget {
public:
using QWidget::QWidget;
void paintEvent(QPaintEvent *) override {
QPainter painter{this};
painter.drawPixmap(0, 0, m_pixmap);
}
void mousePressEvent(QMouseEvent * ev) override {
std::cout << "zebi is PRESSED" << std::endl;
if (m_pen) {
std::cout << "pen is good" << std::endl;
m_lastPos = ev->pos();
draw(ev->pos());
}
}
void mouseMoveEvent(QMouseEvent * ev) override {
if (m_pen) {
draw(ev->pos());
}
}
void setPixmap(QPixmap &pm);
void setLabel(QLabel *label);
void setPen(bool &pen);
void draw(const QPoint & pos);
private:
QPixmap m_pixmap;
QPoint m_lastPos;
QLabel *m_label;
bool m_pen;
};
#endif // PAINTER_H