From e567eba26a7422814e3920403d91a1a781ddf2d7 Mon Sep 17 00:00:00 2001 From: victor Date: Thu, 19 Oct 2017 17:39:21 +0900 Subject: [PATCH] =?UTF-8?q?=ED=84=B0=EC=B9=98=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9C=88=EB=8F=84=EC=9A=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/gui/oven_control/canvas.cpp | 83 ++++++++++++++++++++++++++++++++ app/gui/oven_control/canvas.h | 38 +++++++++++++++ app/gui/oven_control/oven_control.pro | 11 +++-- app/gui/oven_control/touchtestwindow.cpp | 26 ++++++++++ app/gui/oven_control/touchtestwindow.h | 27 +++++++++++ app/gui/oven_control/touchtestwindow.ui | 63 ++++++++++++++++++++++++ 6 files changed, 245 insertions(+), 3 deletions(-) create mode 100644 app/gui/oven_control/canvas.cpp create mode 100644 app/gui/oven_control/canvas.h create mode 100644 app/gui/oven_control/touchtestwindow.cpp create mode 100644 app/gui/oven_control/touchtestwindow.h create mode 100644 app/gui/oven_control/touchtestwindow.ui diff --git a/app/gui/oven_control/canvas.cpp b/app/gui/oven_control/canvas.cpp new file mode 100644 index 0000000..4f7ccf3 --- /dev/null +++ b/app/gui/oven_control/canvas.cpp @@ -0,0 +1,83 @@ +#include "canvas.h" + +#include +#include + +Canvas::Canvas(QWidget *parent) : QWidget(parent) +{ + setAttribute(Qt::WA_StaticContents); + scribbling = false; + myPenWidth = 1; + myPenColor = Qt::blue; +} + +void Canvas::clearImage() +{ + image.fill(qRgb(255, 255, 255)); + update(); +} + +void Canvas::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + lastPoint = event->pos(); + scribbling = true; + } +} + +void Canvas::mouseMoveEvent(QMouseEvent *event) +{ + if ((event->buttons() & Qt::LeftButton) && scribbling) + drawLineTo(event->pos()); +} + +void Canvas::mouseReleaseEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton && scribbling) { + drawLineTo(event->pos()); + scribbling = false; + } +} + +void Canvas::paintEvent(QPaintEvent *event) +{ + QPainter painter(this); + QRect dirtyRect = event->rect(); + painter.drawImage(dirtyRect, image, dirtyRect); +} + +void Canvas::resizeEvent(QResizeEvent *event) +{ + if (width() > image.width() || height() > image.height()) { + int newWidth = qMax(width() + 128, image.width()); + int newHeight = qMax(height() + 128, image.height()); + resizeImage(&image, QSize(newWidth, newHeight)); + update(); + } + QWidget::resizeEvent(event); +} + +void Canvas::drawLineTo(const QPoint &endPoint) +{ + QPainter painter(&image); + painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap, + Qt::RoundJoin)); + painter.drawLine(lastPoint, endPoint); + + int rad = (myPenWidth / 2) + 2; + update(QRect(lastPoint, endPoint).normalized() + .adjusted(-rad, -rad, +rad, +rad)); + lastPoint = endPoint; +} + +void Canvas::resizeImage(QImage *image, const QSize &newSize) +{ + if (image->size() == newSize) + return; + + QImage newImage(newSize, QImage::Format_RGB32); + newImage.fill(qRgb(255, 255, 255)); + QPainter painter(&newImage); + painter.drawImage(QPoint(0, 0), *image); + *image = newImage; +} diff --git a/app/gui/oven_control/canvas.h b/app/gui/oven_control/canvas.h new file mode 100644 index 0000000..56989c9 --- /dev/null +++ b/app/gui/oven_control/canvas.h @@ -0,0 +1,38 @@ +#ifndef CANVAS_H +#define CANVAS_H + +#include +#include +#include + +class Canvas : public QWidget +{ + Q_OBJECT +public: + explicit Canvas(QWidget *parent = 0); + +signals: + +public slots: + void clearImage(); + +protected: + void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; + void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; + +private: + void drawLineTo(const QPoint &endPoint); + void resizeImage(QImage *image, const QSize &newSize); + + + bool scribbling; + int myPenWidth; + QColor myPenColor; + QImage image; + QPoint lastPoint; +}; + +#endif // CANVAS_H diff --git a/app/gui/oven_control/oven_control.pro b/app/gui/oven_control/oven_control.pro index 3c7a6b7..909ad75 100644 --- a/app/gui/oven_control/oven_control.pro +++ b/app/gui/oven_control/oven_control.pro @@ -142,7 +142,9 @@ SOURCES += main.cpp\ multicookmanualwindow.cpp \ multicookautowindow.cpp \ multicookbook.cpp \ - haccp.cpp + haccp.cpp \ + canvas.cpp \ + touchtestwindow.cpp HEADERS += mainwindow.h \ @@ -275,7 +277,9 @@ HEADERS += mainwindow.h \ multicookmanualwindow.h \ multicookautowindow.h \ multicookbook.h \ - haccp.h + haccp.h \ + canvas.h \ + touchtestwindow.h FORMS += mainwindow.ui \ manualcookwindow.ui \ @@ -359,7 +363,8 @@ FORMS += mainwindow.ui \ multicookwindow.ui \ multicookselectionwindow.ui \ multicookmanualwindow.ui \ - multicookautowindow.ui + multicookautowindow.ui \ + touchtestwindow.ui RESOURCES += \ resources.qrc diff --git a/app/gui/oven_control/touchtestwindow.cpp b/app/gui/oven_control/touchtestwindow.cpp new file mode 100644 index 0000000..3064c13 --- /dev/null +++ b/app/gui/oven_control/touchtestwindow.cpp @@ -0,0 +1,26 @@ +#include "touchtestwindow.h" +#include "ui_touchtestwindow.h" + +TouchTestWindow::TouchTestWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::TouchTestWindow) +{ + ui->setupUi(this); + + setAttribute(Qt::WA_DeleteOnClose); +} + +TouchTestWindow::~TouchTestWindow() +{ + delete ui; +} + +void TouchTestWindow::on_clearButton_clicked() +{ + ui->canvas->clearImage(); +} + +void TouchTestWindow::on_closeButton_clicked() +{ + close(); +} diff --git a/app/gui/oven_control/touchtestwindow.h b/app/gui/oven_control/touchtestwindow.h new file mode 100644 index 0000000..05ce506 --- /dev/null +++ b/app/gui/oven_control/touchtestwindow.h @@ -0,0 +1,27 @@ +#ifndef TOUCHTESTWINDOW_H +#define TOUCHTESTWINDOW_H + +#include + +namespace Ui { +class TouchTestWindow; +} + +class TouchTestWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit TouchTestWindow(QWidget *parent = 0); + ~TouchTestWindow(); + +private slots: + void on_clearButton_clicked(); + + void on_closeButton_clicked(); + +private: + Ui::TouchTestWindow *ui; +}; + +#endif // TOUCHTESTWINDOW_H diff --git a/app/gui/oven_control/touchtestwindow.ui b/app/gui/oven_control/touchtestwindow.ui new file mode 100644 index 0000000..bbc02c9 --- /dev/null +++ b/app/gui/oven_control/touchtestwindow.ui @@ -0,0 +1,63 @@ + + + TouchTestWindow + + + + 0 + 0 + 900 + 1600 + + + + MainWindow + + + + + + 850 + 0 + 50 + 50 + + + + QPushButton { border: 1px solid black; } +QPushButton:pressed { background-color: red; } + + + X + + + + + + 800 + 0 + 50 + 50 + + + + QPushButton { border: 1px solid black; } +QPushButton:pressed { background-color: red; } + + + C + + + + + + + Canvas + QWidget +
canvas.h
+ 1 +
+
+ + +
-- 2.1.4