summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKnud Dollereder <knud.dollereder@qt.io>2019-02-26 14:09:33 +0100
committerKnud Dollereder <knud.dollereder@qt.io>2019-02-26 14:19:46 +0000
commit789a9502f2385bd95c3ea8ce0c0cc1e297df737a (patch)
tree43e22a9b186c93f84e35305d130d290eec719597
parentd64e872b61cfeb0f7bc36e21b2b98e5ff10f580a (diff)
Move TreeItems up one folder
Do not reject t values that are slightly above 1 when computing extrema Change-Id: I167ed2fc8c14c7993bd72ac4312a34aacb084c4e Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r--src/curveeditor/curveeditor.pri4
-rw-r--r--src/curveeditor/curveeditormodel.cpp40
-rw-r--r--src/curveeditor/curveeditormodel.h37
-rw-r--r--src/curveeditor/detail/curveitem.cpp5
-rw-r--r--src/curveeditor/detail/curvesegment.cpp9
-rw-r--r--src/curveeditor/treeitem.cpp (renamed from src/curveeditor/detail/treeitem.cpp)39
-rw-r--r--src/curveeditor/treeitem.h (renamed from src/curveeditor/detail/treeitem.h)33
7 files changed, 80 insertions, 87 deletions
diff --git a/src/curveeditor/curveeditor.pri b/src/curveeditor/curveeditor.pri
index 6b325e3..aa18c92 100644
--- a/src/curveeditor/curveeditor.pri
+++ b/src/curveeditor/curveeditor.pri
@@ -5,6 +5,7 @@ HEADERS += \
$$PWD/curveeditor.h \
$$PWD/curveeditormodel.h \
$$PWD/keyframe.h \
+ $$PWD/treeitem.h \
$$PWD/detail/colorcontrol.h \
$$PWD/detail/curveeditorstyledialog.h \
$$PWD/detail/curveitem.h \
@@ -13,7 +14,6 @@ HEADERS += \
$$PWD/detail/graphicsview.h \
$$PWD/detail/handleitem.h \
$$PWD/detail/keyframeitem.h \
- $$PWD/detail/treeitem.h \
$$PWD/detail/treeitemdelegate.h \
$$PWD/detail/treemodel.h \
$$PWD/detail/treeview.h
@@ -23,6 +23,7 @@ SOURCES += \
$$PWD/curveeditor.cpp \
$$PWD/curveeditormodel.cpp \
$$PWD/keyframe.cpp \
+ $$PWD/treeitem.cpp \
$$PWD/detail/colorcontrol.cpp \
$$PWD/detail/curveeditorstyledialog.cpp \
$$PWD/detail/curveitem.cpp \
@@ -31,7 +32,6 @@ SOURCES += \
$$PWD/detail/graphicsview.cpp \
$$PWD/detail/handleitem.cpp \
$$PWD/detail/keyframeitem.cpp \
- $$PWD/detail/treeitem.cpp \
$$PWD/detail/treeitemdelegate.cpp \
$$PWD/detail/treemodel.cpp \
$$PWD/detail/treeview.cpp \
diff --git a/src/curveeditor/curveeditormodel.cpp b/src/curveeditor/curveeditormodel.cpp
index 31d4d6b..7fd545a 100644
--- a/src/curveeditor/curveeditormodel.cpp
+++ b/src/curveeditor/curveeditormodel.cpp
@@ -24,6 +24,7 @@
****************************************************************************/
#include "curveeditormodel.h"
+#include "treeitem.h"
namespace DesignTools {
@@ -64,43 +65,4 @@ void CurveEditorModel::reset(const std::vector<TreeItem *> &items)
endResetModel();
}
-
-NodeTreeItem::NodeTreeItem(const QString &name, const QIcon &icon)
- : TreeItem(name)
- , m_icon(icon)
-{
- Q_UNUSED(icon);
-}
-
-NodeTreeItem *NodeTreeItem::asNodeItem()
-{
- return this;
-}
-
-QIcon NodeTreeItem::icon() const
-{
- return m_icon;
-}
-
-
-PropertyTreeItem::PropertyTreeItem(const QString &name, const AnimationCurve &curve)
- : TreeItem(name)
- , m_curve(curve)
-{}
-
-PropertyTreeItem *PropertyTreeItem::asPropertyItem()
-{
- return this;
-}
-
-AnimationCurve PropertyTreeItem::curve() const
-{
- return m_curve;
-}
-
-void PropertyTreeItem::setCurve(const AnimationCurve &curve)
-{
- m_curve = curve;
-}
-
} // End namespace DesignTools.
diff --git a/src/curveeditor/curveeditormodel.h b/src/curveeditor/curveeditormodel.h
index 5c0bb4e..1847158 100644
--- a/src/curveeditor/curveeditormodel.h
+++ b/src/curveeditor/curveeditormodel.h
@@ -25,11 +25,8 @@
#pragma once
-#include "detail/treeitem.h"
#include "detail/treemodel.h"
-#include <QIcon>
-
#include <vector>
class QPointF;
@@ -39,6 +36,8 @@ namespace DesignTools {
struct CurveEditorStyle;
class AnimationCurve;
+class PropertyTreeItem;
+class TreeItem;
class CurveEditorModel : public TreeModel
{
@@ -66,36 +65,4 @@ public:
void reset(const std::vector<TreeItem *> &items);
};
-
-class NodeTreeItem : public TreeItem
-{
-public:
- NodeTreeItem(const QString &name, const QIcon &icon);
-
- NodeTreeItem *asNodeItem() override;
-
- QIcon icon() const override;
-
-private:
- QIcon m_icon;
-};
-
-
-class PropertyTreeItem : public TreeItem
-{
-public:
- PropertyTreeItem(const QString &name, const AnimationCurve &curve);
-
- PropertyTreeItem *asPropertyItem() override;
-
- AnimationCurve curve() const;
-
- void setCurve(const AnimationCurve &curve);
-
-private:
- using TreeItem::addChild;
-
- AnimationCurve m_curve;
-};
-
} // End namespace DesignTools.
diff --git a/src/curveeditor/detail/curveitem.cpp b/src/curveeditor/detail/curveitem.cpp
index 2d8e462..68c22db 100644
--- a/src/curveeditor/detail/curveitem.cpp
+++ b/src/curveeditor/detail/curveitem.cpp
@@ -116,11 +116,6 @@ void CurveItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidg
painter->setPen(pen);
painter->drawPath(path());
- // Tmp. Remove later.
- painter->setPen(Qt::red);
- for (auto p : curve().extrema())
- painter->drawEllipse(m_transform.map(p), 6., 6.);
-
painter->restore();
}
}
diff --git a/src/curveeditor/detail/curvesegment.cpp b/src/curveeditor/detail/curvesegment.cpp
index 1bd0ad9..40f675f 100644
--- a/src/curveeditor/detail/curvesegment.cpp
+++ b/src/curveeditor/detail/curvesegment.cpp
@@ -24,6 +24,7 @@
****************************************************************************/
#include "curvesegment.h"
+#include "utils.h"
#include <qmath.h>
@@ -36,8 +37,6 @@ class CubicPolynomial
public:
CubicPolynomial(double p0, double p1, double p2, double p3);
- double evaluate(double x) const;
-
std::vector<double> extrema() const;
std::vector<double> roots() const;
@@ -61,8 +60,8 @@ std::vector<double> CubicPolynomial::extrema() const
std::vector<double> out;
auto addValidValue = [&out](double value) {
- if (!(std::isnan(value) || std::isinf(value)))
- out.push_back(value);
+ if (!std::isnan(value) && !std::isinf(value))
+ out.push_back(clamp(value, 0.0, 1.0));
};
// Find the roots of the first derivative of y.
@@ -191,8 +190,6 @@ std::vector<QPointF> CurveSegment::extrema() const
m_right.position().y());
for (double t : polynomial.extrema()) {
- if (t < 0.0 || t > 1.0)
- continue;
const double x = evaluateForT(
t,
diff --git a/src/curveeditor/detail/treeitem.cpp b/src/curveeditor/treeitem.cpp
index c8f5360..beed419 100644
--- a/src/curveeditor/detail/treeitem.cpp
+++ b/src/curveeditor/treeitem.cpp
@@ -185,4 +185,43 @@ void TreeItem::setPinned(bool pinned)
m_pinned = pinned;
}
+
+NodeTreeItem::NodeTreeItem(const QString &name, const QIcon &icon)
+ : TreeItem(name)
+ , m_icon(icon)
+{
+ Q_UNUSED(icon);
+}
+
+NodeTreeItem *NodeTreeItem::asNodeItem()
+{
+ return this;
+}
+
+QIcon NodeTreeItem::icon() const
+{
+ return m_icon;
+}
+
+
+PropertyTreeItem::PropertyTreeItem(const QString &name, const AnimationCurve &curve)
+ : TreeItem(name)
+ , m_curve(curve)
+{}
+
+PropertyTreeItem *PropertyTreeItem::asPropertyItem()
+{
+ return this;
+}
+
+AnimationCurve PropertyTreeItem::curve() const
+{
+ return m_curve;
+}
+
+void PropertyTreeItem::setCurve(const AnimationCurve &curve)
+{
+ m_curve = curve;
+}
+
} // End namespace DesignTools.
diff --git a/src/curveeditor/detail/treeitem.h b/src/curveeditor/treeitem.h
index 15a1014..e500483 100644
--- a/src/curveeditor/detail/treeitem.h
+++ b/src/curveeditor/treeitem.h
@@ -28,6 +28,7 @@
#include "animationcurve.h"
+#include <QIcon>
#include <QString>
#include <vector>
@@ -99,4 +100,36 @@ protected:
std::vector<TreeItem *> m_children;
};
+
+class NodeTreeItem : public TreeItem
+{
+public:
+ NodeTreeItem(const QString &name, const QIcon &icon);
+
+ NodeTreeItem *asNodeItem() override;
+
+ QIcon icon() const override;
+
+private:
+ QIcon m_icon;
+};
+
+
+class PropertyTreeItem : public TreeItem
+{
+public:
+ PropertyTreeItem(const QString &name, const AnimationCurve &curve);
+
+ PropertyTreeItem *asPropertyItem() override;
+
+ AnimationCurve curve() const;
+
+ void setCurve(const AnimationCurve &curve);
+
+private:
+ using TreeItem::addChild;
+
+ AnimationCurve m_curve;
+};
+
} // End namespace DesignTools.