mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2024-11-24 04:20:46 +08:00
55 lines
1.4 KiB
C
55 lines
1.4 KiB
C
|
// Copyright (C) 2016 The Qt Company Ltd.
|
||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||
|
|
||
|
#ifndef PAINTAREA_H
|
||
|
#define PAINTAREA_H
|
||
|
|
||
|
#include <QColor>
|
||
|
#include <QImage>
|
||
|
#include <QPainterPath>
|
||
|
#include <QWidget>
|
||
|
|
||
|
class BrushInterface;
|
||
|
|
||
|
class PaintArea : public QWidget
|
||
|
{
|
||
|
Q_OBJECT
|
||
|
|
||
|
public:
|
||
|
PaintArea(QWidget *parent = nullptr);
|
||
|
|
||
|
bool openImage(const QString &fileName);
|
||
|
bool saveImage(const QString &fileName, const char *fileFormat);
|
||
|
void setImage(const QImage &image);
|
||
|
void insertShape(const QPainterPath &path);
|
||
|
void setBrushColor(const QColor &color);
|
||
|
void setBrushWidth(int width);
|
||
|
void setBrush(BrushInterface *brushInterface, const QString &brush);
|
||
|
|
||
|
QImage image() const { return theImage; }
|
||
|
QColor brushColor() const { return color; }
|
||
|
int brushWidth() const { return thickness; }
|
||
|
QSize sizeHint() const override;
|
||
|
|
||
|
protected:
|
||
|
void paintEvent(QPaintEvent *event) override;
|
||
|
void mousePressEvent(QMouseEvent *event) override;
|
||
|
void mouseMoveEvent(QMouseEvent *event) override;
|
||
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||
|
|
||
|
private:
|
||
|
void setupPainter(QPainter &painter);
|
||
|
|
||
|
QImage theImage = {500, 400, QImage::Format_RGB32};
|
||
|
QColor color = Qt::blue;
|
||
|
int thickness = 3;
|
||
|
|
||
|
BrushInterface *brushInterface = nullptr;
|
||
|
QString brush;
|
||
|
QPoint lastPos = {-1, -1};
|
||
|
|
||
|
QPainterPath pendingPath;
|
||
|
};
|
||
|
|
||
|
#endif
|