KSeExpr 6.0.0.0
ExprCurve.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2011-2019 Disney Enterprises, Inc.
2// SPDX-License-Identifier: LicenseRef-Apache-2.0
3// SPDX-FileCopyrightText: 2020 L. E. Segovia <amy@amyspark.me>
4// SPDX-License-Identifier: GPL-3.0-or-later
5/*
6* @file ExprCurve.h
7* @brief Contains PyQt4 Ramp Widget to emulate Maya's ramp widget
8* @author Arthur Shek
9* @version ashek 05/04/09 Initial Version
10*/
11
12#pragma once
13
14#include <cstddef>
15#include <vector>
16
17#include <QObject>
18#include <QComboBox>
19#include <QGraphicsPolygonItem>
20#include <QGraphicsView>
21#include <QLineEdit>
22
23#include <KSeExpr/Curve.h>
24
25/*
26 This class overrides QGraphicsView so we can get resize events
27*/
28class CurveGraphicsView : public QGraphicsView {
29 Q_OBJECT
30 public:
32 setTransformationAnchor(QGraphicsView::NoAnchor);
33 setResizeAnchor(QGraphicsView::NoAnchor);
34 }
35 ~CurveGraphicsView() override = default;
36
37 void resizeEvent(QResizeEvent *event) override;
38
39Q_SIGNALS:
40 void resizeSignal(int width, int height);
41};
42
43/*
44 This class overrides QGraphicsScene so we can handle mouse
45 press, drag and keyboard events
46*/
47class CurveScene : public QGraphicsScene {
48 Q_OBJECT
49
52
53 public:
54 CurveScene();
55 ~CurveScene() override;
56
57 void addPoint(double x, double y, T_INTERP interp, bool select = true);
58
59 void removePoint(int index);
60 void removeAll();
61
62 void keyPressEvent(QKeyEvent *event) override;
63
64 void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
65 void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
66 void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) override;
67 void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
68 void drawRect();
69
70 void drawPoly();
71
72 void drawPoints();
73
74 void emitCurveChanged();
75
76 void rebuildCurve();
77
78 std::vector<T_CURVE::CV> _cvs; // unsorted cvs
79
80 friend class ExprCurve;
81
82 private:
84 public
85Q_SLOTS:
86 void interpChanged(int interp);
87 void selPosChanged(double pos);
88 void selValChanged(double val);
89 void resize(int width, int height);
90
91Q_SIGNALS:
92 void cvSelected(double x, double y, T_INTERP interp);
94
95 private:
96 int _width;
99 std::vector<QGraphicsEllipseItem *> _circleObjects;
101 QGraphicsPolygonItem *_curvePoly{nullptr};
102 QGraphicsRectItem *_baseRect{nullptr};
103 bool _lmb;
104};
105
106class ExprCurve : public QWidget {
107 Q_OBJECT
108
111
112 public:
113 ExprCurve(QWidget *parent = nullptr,
114 QString pLabel = QString(),
115 QString vLabel = QString(),
116 QString iLabel = QString(),
117 bool expandable = true);
118 ~ExprCurve() override = default;
119
120 // Convenience Functions
121 void addPoint(double x, double y, T_INTERP interp, bool select = false)
122 {
123 _scene->addPoint(x, y, interp, select);
124 }
125
127
128 public
129Q_SLOTS:
130 void cvSelectedSlot(double pos, double val, T_INTERP interp);
131 void selPosChanged();
132 void selValChanged();
133 void openDetail();
134
135Q_SIGNALS:
136 void selPosChangedSignal(double pos);
137 void selValChangedSignal(double val);
138
139 private:
140 QLineEdit *_selPosEdit{nullptr};
141 QLineEdit *_selValEdit{nullptr};
142 QComboBox *_interpComboBox{nullptr};
143};
~CurveGraphicsView() override=default
void resizeEvent(QResizeEvent *event) override
Definition ExprCurve.cpp:34
void resizeSignal(int width, int height)
void drawPoints()
void cvSelected(double x, double y, T_INTERP interp)
int _height
Definition ExprCurve.h:97
void removeAll()
Definition ExprCurve.cpp:29
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) override
void removePoint(int index)
Definition ExprCurve.cpp:92
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) override
int _selectedItem
Definition ExprCurve.h:100
QGraphicsRectItem * _baseRect
Definition ExprCurve.h:102
void resize(int width, int height)
Definition ExprCurve.cpp:56
void drawRect()
void selValChanged(double val)
void rebuildCurve()
Definition ExprCurve.cpp:67
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) override
std::vector< QGraphicsEllipseItem * > _circleObjects
Definition ExprCurve.h:99
void drawPoly()
void addPoint(double x, double y, T_INTERP interp, bool select=true)
Definition ExprCurve.cpp:76
void emitCurveChanged()
QGraphicsPolygonItem * _curvePoly
Definition ExprCurve.h:101
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
void interpChanged(int interp)
std::vector< T_CURVE::CV > _cvs
Definition ExprCurve.h:78
void curveChanged()
~CurveScene() override
Definition ExprCurve.cpp:51
void selPosChanged(double pos)
T_INTERP _interp
Definition ExprCurve.h:98
void keyPressEvent(QKeyEvent *event) override
T_CURVE * _curve
Definition ExprCurve.h:83
QLineEdit * _selValEdit
Definition ExprCurve.h:141
void cvSelectedSlot(double pos, double val, T_INTERP interp)
void addPoint(double x, double y, T_INTERP interp, bool select=false)
Definition ExprCurve.h:121
void selValChanged()
void selValChangedSignal(double val)
QComboBox * _interpComboBox
Definition ExprCurve.h:142
void selPosChangedSignal(double pos)
void openDetail()
CurveScene * _scene
Definition ExprCurve.h:126
QLineEdit * _selPosEdit
Definition ExprCurve.h:140
~ExprCurve() override=default
void selPosChanged()
Interpolation curve class for double->double and double->Vec3D.
Definition Curve.h:27
InterpType
Supported interpolation types.
Definition Curve.h:32