File indexing completed on 2024-10-27 04:39:09
0001 // SPDX-License-Identifier: GPL-2.0-or-later 0002 // SPDX-FileCopyrightText: 2018 Kevin Ottens <ervin@kde.org> 0003 0004 /* 0005 * Adapted by Louis Schul <schul9louis@gmail.com> 0006 * in 2023 for Klevernotes 0007 */ 0008 0009 #ifndef SKETCHVIEW_H 0010 #define SKETCHVIEW_H 0011 0012 #include <QQuickView> 0013 0014 #include "pointMaker.h" 0015 0016 class SketchViewHandler : public QObject 0017 { 0018 Q_OBJECT 0019 Q_PROPERTY(Event point READ point NOTIFY pointChanged) 0020 Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged) 0021 public: 0022 enum class Pointer { 0023 Pen, 0024 Eraser, 0025 }; 0026 Q_ENUM(Pointer) 0027 0028 explicit SketchViewHandler(QObject *parent = nullptr); 0029 0030 Q_INVOKABLE Stroke createStroke(Stroke::Type type, const QColor &color) const; 0031 Q_INVOKABLE StrokeSample createSample(const QVector2D &position, float width) const; 0032 0033 Event point() const; 0034 bool isPressed() const; 0035 0036 Q_INVOKABLE void changePointer(const int pointerIndex); 0037 Q_INVOKABLE void changeMousePress(bool pressed); 0038 Q_INVOKABLE void mouseMoved(const float x, const float y); 0039 0040 Q_SIGNALS: 0041 void pointChanged(const Event &point); 0042 void pressedChanged(const bool pressed); 0043 void isEraserChanged(const bool sketchViewIsEraser); 0044 0045 private Q_SLOTS: 0046 void onTabletEventReceived(QTabletEvent *event); 0047 0048 private: 0049 Event m_point; 0050 bool m_active = false; 0051 bool m_pressed = false; 0052 Pointer m_pointerType = Pointer::Pen; 0053 }; 0054 0055 class SketchView : public QQuickView 0056 { 0057 Q_OBJECT 0058 public: 0059 static SketchView *instance(); 0060 0061 explicit SketchView(QWindow *parent = nullptr); 0062 0063 void tabletEvent(QTabletEvent *event) override; 0064 0065 Q_SIGNALS: 0066 void tabletEventReceived(QTabletEvent *event); 0067 void pressedChanged(bool mousePressed); 0068 0069 private: 0070 QPointF m_lastGlobalPos; 0071 QEvent::Type m_lastType = QEvent::None; 0072 }; 0073 0074 #endif // SKETCHVIEW_H