Commit e567eba26a7422814e3920403d91a1a781ddf2d7

Authored by 김태훈
1 parent 64447473a0
Exists in master and in 2 other branches fhd, fhd-demo

터치 테스트 윈도우 구현

app/gui/oven_control/canvas.cpp
... ... @@ -0,0 +1,83 @@
  1 +#include "canvas.h"
  2 +
  3 +#include <QMouseEvent>
  4 +#include <QPainter>
  5 +
  6 +Canvas::Canvas(QWidget *parent) : QWidget(parent)
  7 +{
  8 + setAttribute(Qt::WA_StaticContents);
  9 + scribbling = false;
  10 + myPenWidth = 1;
  11 + myPenColor = Qt::blue;
  12 +}
  13 +
  14 +void Canvas::clearImage()
  15 +{
  16 + image.fill(qRgb(255, 255, 255));
  17 + update();
  18 +}
  19 +
  20 +void Canvas::mousePressEvent(QMouseEvent *event)
  21 +{
  22 + if (event->button() == Qt::LeftButton) {
  23 + lastPoint = event->pos();
  24 + scribbling = true;
  25 + }
  26 +}
  27 +
  28 +void Canvas::mouseMoveEvent(QMouseEvent *event)
  29 +{
  30 + if ((event->buttons() & Qt::LeftButton) && scribbling)
  31 + drawLineTo(event->pos());
  32 +}
  33 +
  34 +void Canvas::mouseReleaseEvent(QMouseEvent *event)
  35 +{
  36 + if (event->button() == Qt::LeftButton && scribbling) {
  37 + drawLineTo(event->pos());
  38 + scribbling = false;
  39 + }
  40 +}
  41 +
  42 +void Canvas::paintEvent(QPaintEvent *event)
  43 +{
  44 + QPainter painter(this);
  45 + QRect dirtyRect = event->rect();
  46 + painter.drawImage(dirtyRect, image, dirtyRect);
  47 +}
  48 +
  49 +void Canvas::resizeEvent(QResizeEvent *event)
  50 +{
  51 + if (width() > image.width() || height() > image.height()) {
  52 + int newWidth = qMax(width() + 128, image.width());
  53 + int newHeight = qMax(height() + 128, image.height());
  54 + resizeImage(&image, QSize(newWidth, newHeight));
  55 + update();
  56 + }
  57 + QWidget::resizeEvent(event);
  58 +}
  59 +
  60 +void Canvas::drawLineTo(const QPoint &endPoint)
  61 +{
  62 + QPainter painter(&image);
  63 + painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap,
  64 + Qt::RoundJoin));
  65 + painter.drawLine(lastPoint, endPoint);
  66 +
  67 + int rad = (myPenWidth / 2) + 2;
  68 + update(QRect(lastPoint, endPoint).normalized()
  69 + .adjusted(-rad, -rad, +rad, +rad));
  70 + lastPoint = endPoint;
  71 +}
  72 +
  73 +void Canvas::resizeImage(QImage *image, const QSize &newSize)
  74 +{
  75 + if (image->size() == newSize)
  76 + return;
  77 +
  78 + QImage newImage(newSize, QImage::Format_RGB32);
  79 + newImage.fill(qRgb(255, 255, 255));
  80 + QPainter painter(&newImage);
  81 + painter.drawImage(QPoint(0, 0), *image);
  82 + *image = newImage;
  83 +}
... ...
app/gui/oven_control/canvas.h
... ... @@ -0,0 +1,38 @@
  1 +#ifndef CANVAS_H
  2 +#define CANVAS_H
  3 +
  4 +#include <QWidget>
  5 +#include <QImage>
  6 +#include <QPoint>
  7 +
  8 +class Canvas : public QWidget
  9 +{
  10 + Q_OBJECT
  11 +public:
  12 + explicit Canvas(QWidget *parent = 0);
  13 +
  14 +signals:
  15 +
  16 +public slots:
  17 + void clearImage();
  18 +
  19 +protected:
  20 + void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  21 + void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  22 + void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  23 + void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
  24 + void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
  25 +
  26 +private:
  27 + void drawLineTo(const QPoint &endPoint);
  28 + void resizeImage(QImage *image, const QSize &newSize);
  29 +
  30 +
  31 + bool scribbling;
  32 + int myPenWidth;
  33 + QColor myPenColor;
  34 + QImage image;
  35 + QPoint lastPoint;
  36 +};
  37 +
  38 +#endif // CANVAS_H
... ...
app/gui/oven_control/oven_control.pro
... ... @@ -142,7 +142,9 @@ SOURCES += main.cpp\
142 142 multicookmanualwindow.cpp \
143 143 multicookautowindow.cpp \
144 144 multicookbook.cpp \
145   - haccp.cpp
  145 + haccp.cpp \
  146 + canvas.cpp \
  147 + touchtestwindow.cpp
146 148  
147 149  
148 150 HEADERS += mainwindow.h \
... ... @@ -275,7 +277,9 @@ HEADERS += mainwindow.h \
275 277 multicookmanualwindow.h \
276 278 multicookautowindow.h \
277 279 multicookbook.h \
278   - haccp.h
  280 + haccp.h \
  281 + canvas.h \
  282 + touchtestwindow.h
279 283  
280 284 FORMS += mainwindow.ui \
281 285 manualcookwindow.ui \
... ... @@ -359,7 +363,8 @@ FORMS += mainwindow.ui \
359 363 multicookwindow.ui \
360 364 multicookselectionwindow.ui \
361 365 multicookmanualwindow.ui \
362   - multicookautowindow.ui
  366 + multicookautowindow.ui \
  367 + touchtestwindow.ui
363 368  
364 369 RESOURCES += \
365 370 resources.qrc
... ...
app/gui/oven_control/touchtestwindow.cpp
... ... @@ -0,0 +1,26 @@
  1 +#include "touchtestwindow.h"
  2 +#include "ui_touchtestwindow.h"
  3 +
  4 +TouchTestWindow::TouchTestWindow(QWidget *parent) :
  5 + QMainWindow(parent),
  6 + ui(new Ui::TouchTestWindow)
  7 +{
  8 + ui->setupUi(this);
  9 +
  10 + setAttribute(Qt::WA_DeleteOnClose);
  11 +}
  12 +
  13 +TouchTestWindow::~TouchTestWindow()
  14 +{
  15 + delete ui;
  16 +}
  17 +
  18 +void TouchTestWindow::on_clearButton_clicked()
  19 +{
  20 + ui->canvas->clearImage();
  21 +}
  22 +
  23 +void TouchTestWindow::on_closeButton_clicked()
  24 +{
  25 + close();
  26 +}
... ...
app/gui/oven_control/touchtestwindow.h
... ... @@ -0,0 +1,27 @@
  1 +#ifndef TOUCHTESTWINDOW_H
  2 +#define TOUCHTESTWINDOW_H
  3 +
  4 +#include <QMainWindow>
  5 +
  6 +namespace Ui {
  7 +class TouchTestWindow;
  8 +}
  9 +
  10 +class TouchTestWindow : public QMainWindow
  11 +{
  12 + Q_OBJECT
  13 +
  14 +public:
  15 + explicit TouchTestWindow(QWidget *parent = 0);
  16 + ~TouchTestWindow();
  17 +
  18 +private slots:
  19 + void on_clearButton_clicked();
  20 +
  21 + void on_closeButton_clicked();
  22 +
  23 +private:
  24 + Ui::TouchTestWindow *ui;
  25 +};
  26 +
  27 +#endif // TOUCHTESTWINDOW_H
... ...
app/gui/oven_control/touchtestwindow.ui
... ... @@ -0,0 +1,63 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<ui version="4.0">
  3 + <class>TouchTestWindow</class>
  4 + <widget class="QMainWindow" name="TouchTestWindow">
  5 + <property name="geometry">
  6 + <rect>
  7 + <x>0</x>
  8 + <y>0</y>
  9 + <width>900</width>
  10 + <height>1600</height>
  11 + </rect>
  12 + </property>
  13 + <property name="windowTitle">
  14 + <string>MainWindow</string>
  15 + </property>
  16 + <widget class="Canvas" name="canvas">
  17 + <widget class="QPushButton" name="closeButton">
  18 + <property name="geometry">
  19 + <rect>
  20 + <x>850</x>
  21 + <y>0</y>
  22 + <width>50</width>
  23 + <height>50</height>
  24 + </rect>
  25 + </property>
  26 + <property name="styleSheet">
  27 + <string notr="true">QPushButton { border: 1px solid black; }
  28 +QPushButton:pressed { background-color: red; }</string>
  29 + </property>
  30 + <property name="text">
  31 + <string>X</string>
  32 + </property>
  33 + </widget>
  34 + <widget class="QPushButton" name="clearButton">
  35 + <property name="geometry">
  36 + <rect>
  37 + <x>800</x>
  38 + <y>0</y>
  39 + <width>50</width>
  40 + <height>50</height>
  41 + </rect>
  42 + </property>
  43 + <property name="styleSheet">
  44 + <string notr="true">QPushButton { border: 1px solid black; }
  45 +QPushButton:pressed { background-color: red; }</string>
  46 + </property>
  47 + <property name="text">
  48 + <string>C</string>
  49 + </property>
  50 + </widget>
  51 + </widget>
  52 + </widget>
  53 + <customwidgets>
  54 + <customwidget>
  55 + <class>Canvas</class>
  56 + <extends>QWidget</extends>
  57 + <header>canvas.h</header>
  58 + <container>1</container>
  59 + </customwidget>
  60 + </customwidgets>
  61 + <resources/>
  62 + <connections/>
  63 +</ui>
... ...