digiKam
sketchwidget.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2008-05-19
7  * Description : a widget to draw sketch.
8  *
9  * Copyright (C) 2008-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2008-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_SKETCH_WIDGET_H
26 #define DIGIKAM_SKETCH_WIDGET_H
27 
28 // Qt includes
29 
30 #include <QWidget>
31 #include <QXmlStreamReader>
32 #include <QXmlStreamWriter>
33 
34 namespace Digikam
35 {
36 
37 class SketchWidget : public QWidget
38 {
39  Q_OBJECT
40 
41 public:
42 
43  explicit SketchWidget(QWidget* const parent = nullptr);
44  ~SketchWidget() override;
45 
46  QColor penColor() const;
47  int penWidth() const;
48  bool isClear() const;
49 
50  QImage sketchImage() const;
51  void setSketchImage(const QImage& image);
52 
57  void sketchImageToXML(QXmlStreamWriter& writer);
58  QString sketchImageToXML();
59 
65  bool setSketchImageFromXML(QXmlStreamReader& reader);
66  bool setSketchImageFromXML(const QString& xml);
67 
68 Q_SIGNALS:
69 
70  void signalSketchChanged(const QImage&);
72  void signalPenColorChanged(const QColor&);
73  void signalUndoRedoStateChanged(bool hasUndo, bool hasRedo);
74 
75 public Q_SLOTS:
76 
77  void setPenColor(const QColor& newColor);
78  void setPenWidth(int newWidth);
79  void slotClear();
80  void slotUndo();
81  void slotRedo();
82 
83 protected:
84 
85  void mousePressEvent(QMouseEvent*) override;
86  void mouseMoveEvent(QMouseEvent*) override;
87  void wheelEvent(QWheelEvent*) override;
88  void mouseReleaseEvent(QMouseEvent*) override;
89  void keyPressEvent(QKeyEvent*) override;
90  void keyReleaseEvent(QKeyEvent*) override;
91  void paintEvent(QPaintEvent*) override;
92 
93 private:
94 
95  void updateDrawCursor();
96  void replayEvents(int index);
97  void drawLineTo(const QPoint& endPoint);
98  void drawLineTo(int width, const QColor& color, const QPoint& start, const QPoint& end);
99  void drawPath(int width, const QColor& color, const QPainterPath& path);
100  void addPath(QXmlStreamReader& reader);
101 /*
102  QDomElement addXmlTextElement(QDomDocument& document, QDomElement& target,
103  const QString& tag, const QString& text);
104 */
105 private:
106 
107  class Private;
108  Private* const d;
109 };
110 
111 } // namespace Digikam
112 
113 #endif // DIGIKAM_SKETCH_WIDGET_H
Definition: sketchwidget.h:38
void slotClear()
Definition: sketchwidget.cpp:169
void wheelEvent(QWheelEvent *) override
Definition: sketchwidget.cpp:564
void signalSketchChanged(const QImage &)
void setPenColor(const QColor &newColor)
Definition: sketchwidget.cpp:185
~SketchWidget() override
Definition: sketchwidget.cpp:164
QColor penColor() const
Definition: sketchwidget.cpp:191
void mouseReleaseEvent(QMouseEvent *) override
Definition: sketchwidget.cpp:588
void setPenWidth(int newWidth)
Definition: sketchwidget.cpp:196
int penWidth() const
Definition: sketchwidget.cpp:203
void signalPenColorChanged(const QColor &)
SketchWidget(QWidget *const parent=nullptr)
Definition: sketchwidget.cpp:150
void setSketchImage(const QImage &image)
Definition: sketchwidget.cpp:489
void slotUndo()
Definition: sketchwidget.cpp:208
bool isClear() const
Definition: sketchwidget.cpp:180
void paintEvent(QPaintEvent *) override
Definition: sketchwidget.cpp:620
void keyPressEvent(QKeyEvent *) override
Definition: sketchwidget.cpp:600
bool setSketchImageFromXML(QXmlStreamReader &reader)
Definition: sketchwidget.cpp:353
void mousePressEvent(QMouseEvent *) override
Definition: sketchwidget.cpp:501
QImage sketchImage() const
Definition: sketchwidget.cpp:484
void mouseMoveEvent(QMouseEvent *) override
Definition: sketchwidget.cpp:531
void signalUndoRedoStateChanged(bool hasUndo, bool hasRedo)
void slotRedo()
Definition: sketchwidget.cpp:239
void keyReleaseEvent(QKeyEvent *) override
Definition: sketchwidget.cpp:610
QString sketchImageToXML()
Definition: sketchwidget.cpp:323
void signalPenSizeChanged(int)
Definition: datefolderview.cpp:43