Files
intelliphoto/IntelliPhoto/Scribble/scribblearea.h
2019-11-21 13:02:00 +01:00

74 lines
1.8 KiB
C++

// ---------- scribblearea.h ----------
#ifndef SCRIBBLEAREA_H
#define SCRIBBLEAREA_H
#include <QColor>
#include <QImage>
#include <QPoint>
#include <QWidget>
class ScribbleArea : public QWidget
{
// Declares our class as a QObject which is the base class
// for all Qt objects
// QObjects handle events
Q_OBJECT
public:
ScribbleArea(QWidget *parent = nullptr);
// Handles all events
bool openImage(const QString &fileName);
bool saveImage(const QString &fileName, const char *fileFormat);
void setPenColor(const QColor &newColor);
void setPenWidth(int newWidth);
// Has the image been modified since last save
bool isModified() const { return modified; }
QColor penColor() const { return myPenColor; }
int penWidth() const { return myPenWidth; }
public slots:
// Events to handle
void clearImage();
protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
// Updates the scribble area where we are painting
void paintEvent(QPaintEvent *event) override;
// Makes sure the area we are drawing on remains
// as large as the widget
void resizeEvent(QResizeEvent *event) override;
private:
void drawLineTo(const QPoint &endPoint);
void resizeImage(QImage *image, const QSize &newSize);
// Will be marked true or false depending on if
// we have saved after a change
bool modified;
// Marked true or false depending on if the user
// is drawing
bool scribbling;
// Holds the current pen width & color
int myPenWidth;
QColor myPenColor;
// Stores the image being drawn
QImage image;
// Stores the location at the current mouse event
QPoint lastPoint;
};
#endif