forked from qt-creator/qt-creator
CurveEditor: Fix bounding rect computation for the graphicsscene
Task-number: QDS-2957 Change-Id: I0019d538e7460e923b35024bd02f7186e1935f6b Reviewed-by: Henning Gründl <henning.gruendl@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -39,10 +39,10 @@
|
|||||||
|
|
||||||
namespace DesignTools {
|
namespace DesignTools {
|
||||||
|
|
||||||
CurveEditorModel::CurveEditorModel(double minTime, double maxTime, QObject *parent)
|
CurveEditorModel::CurveEditorModel(QObject *parent)
|
||||||
: TreeModel(parent)
|
: TreeModel(parent)
|
||||||
, m_minTime(minTime)
|
, m_minTime(CurveEditorStyle::defaultTimeMin)
|
||||||
, m_maxTime(maxTime)
|
, m_maxTime(CurveEditorStyle::defaultTimeMax)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
CurveEditorModel::~CurveEditorModel() {}
|
CurveEditorModel::~CurveEditorModel() {}
|
||||||
|
@@ -57,7 +57,7 @@ signals:
|
|||||||
void curveChanged(PropertyTreeItem *item);
|
void curveChanged(PropertyTreeItem *item);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CurveEditorModel(double minTime, double maxTime, QObject *parent = nullptr);
|
CurveEditorModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
~CurveEditorModel() override;
|
~CurveEditorModel() override;
|
||||||
|
|
||||||
|
@@ -105,6 +105,13 @@ struct Shortcuts
|
|||||||
|
|
||||||
struct CurveEditorStyle
|
struct CurveEditorStyle
|
||||||
{
|
{
|
||||||
|
static constexpr double defaultTimeMin = 0.0;
|
||||||
|
static constexpr double defaultTimeMax = 100.0;
|
||||||
|
static constexpr double defaultValueMin = -1.0;
|
||||||
|
static constexpr double defaultValueMax = 1.0;
|
||||||
|
|
||||||
|
static double defaultValueRange() { return std::abs(defaultValueMin - defaultValueMax); }
|
||||||
|
|
||||||
Shortcuts shortcuts;
|
Shortcuts shortcuts;
|
||||||
|
|
||||||
QBrush backgroundBrush = QBrush(QColor(5, 0, 100));
|
QBrush backgroundBrush = QBrush(QColor(5, 0, 100));
|
||||||
@@ -124,7 +131,7 @@ struct CurveEditorStyle
|
|||||||
double valueAxisWidth = 60.0;
|
double valueAxisWidth = 60.0;
|
||||||
double valueOffsetTop = 10.0;
|
double valueOffsetTop = 10.0;
|
||||||
double valueOffsetBottom = 10.0;
|
double valueOffsetBottom = 10.0;
|
||||||
double labelDensityY = 1.5;
|
double labelDensityY = 2.0;
|
||||||
|
|
||||||
HandleItemStyleOption handleStyle;
|
HandleItemStyleOption handleStyle;
|
||||||
KeyframeItemStyleOption keyframeStyle;
|
KeyframeItemStyleOption keyframeStyle;
|
||||||
|
@@ -42,7 +42,7 @@ namespace QmlDesigner {
|
|||||||
CurveEditorView::CurveEditorView(QObject *parent)
|
CurveEditorView::CurveEditorView(QObject *parent)
|
||||||
: AbstractView(parent)
|
: AbstractView(parent)
|
||||||
, m_block(false)
|
, m_block(false)
|
||||||
, m_model(new DesignTools::CurveEditorModel(0., 500.))
|
, m_model(new DesignTools::CurveEditorModel())
|
||||||
, m_editor(new DesignTools::CurveEditor(m_model))
|
, m_editor(new DesignTools::CurveEditor(m_model))
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
Q_UNUSED(parent);
|
||||||
@@ -267,7 +267,7 @@ ModelNode getTargetNode1(DesignTools::PropertyTreeItem *item, const QmlTimeline
|
|||||||
QString targetId = nodeItem->name();
|
QString targetId = nodeItem->name();
|
||||||
if (timeline.isValid()) {
|
if (timeline.isValid()) {
|
||||||
for (auto &&target : timeline.allTargets()) {
|
for (auto &&target : timeline.allTargets()) {
|
||||||
if (target.displayName() == targetId)
|
if (target.isValid() && target.displayName() == targetId)
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -87,6 +87,16 @@ QRectF CurveItem::boundingRect() const
|
|||||||
for (auto *item : m_keyframes)
|
for (auto *item : m_keyframes)
|
||||||
bbox(bounds, item->keyframe());
|
bbox(bounds, item->keyframe());
|
||||||
|
|
||||||
|
if (auto *s = qobject_cast<GraphicsScene *>(scene())) {
|
||||||
|
bounds.setLeft(s->animationRangeMin());
|
||||||
|
bounds.setRight(s->animationRangeMax());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qFuzzyCompare(bounds.height(), 0.0)) {
|
||||||
|
auto tmp = CurveEditorStyle::defaultValueRange() / 2.0;
|
||||||
|
bounds.adjust(0.0, -tmp, 0.0, tmp);
|
||||||
|
}
|
||||||
|
|
||||||
return m_transform.mapRect(bounds);
|
return m_transform.mapRect(bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -114,9 +114,29 @@ double GraphicsScene::maximumValue() const
|
|||||||
return limits().top();
|
return limits().top();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double GraphicsScene::animationRangeMin() const
|
||||||
|
{
|
||||||
|
if (GraphicsView *gview = graphicsView())
|
||||||
|
return gview->minimumTime();
|
||||||
|
|
||||||
|
return minimumTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
double GraphicsScene::animationRangeMax() const
|
||||||
|
{
|
||||||
|
if (GraphicsView *gview = graphicsView())
|
||||||
|
return gview->maximumTime();
|
||||||
|
|
||||||
|
return maximumTime();
|
||||||
|
}
|
||||||
|
|
||||||
QRectF GraphicsScene::rect() const
|
QRectF GraphicsScene::rect() const
|
||||||
{
|
{
|
||||||
return sceneRect();
|
QRectF rect;
|
||||||
|
for (auto *curve : curves())
|
||||||
|
rect |= curve->boundingRect();
|
||||||
|
|
||||||
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<CurveItem *> GraphicsScene::curves() const
|
QVector<CurveItem *> GraphicsScene::curves() const
|
||||||
@@ -410,6 +430,11 @@ QRectF GraphicsScene::limits() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_limits = QRectF(QPointF(min.x(), max.y()), QPointF(max.x(), min.y()));
|
m_limits = QRectF(QPointF(min.x(), max.y()), QPointF(max.x(), min.y()));
|
||||||
|
if (qFuzzyCompare(m_limits.height(), 0.0)) {
|
||||||
|
auto tmp = CurveEditorStyle::defaultValueRange() / 2.0;
|
||||||
|
m_limits.adjust(0.0, tmp, 0.0, -tmp);
|
||||||
|
}
|
||||||
|
|
||||||
m_dirty = false;
|
m_dirty = false;
|
||||||
}
|
}
|
||||||
return m_limits;
|
return m_limits;
|
||||||
|
@@ -67,6 +67,10 @@ public:
|
|||||||
|
|
||||||
double maximumValue() const;
|
double maximumValue() const;
|
||||||
|
|
||||||
|
double animationRangeMin() const;
|
||||||
|
|
||||||
|
double animationRangeMax() const;
|
||||||
|
|
||||||
QRectF rect() const;
|
QRectF rect() const;
|
||||||
|
|
||||||
QVector<CurveItem *> curves() const;
|
QVector<CurveItem *> curves() const;
|
||||||
|
@@ -126,12 +126,12 @@ double GraphicsView::maximumTime() const
|
|||||||
|
|
||||||
double GraphicsView::minimumValue() const
|
double GraphicsView::minimumValue() const
|
||||||
{
|
{
|
||||||
return m_scene->empty() ? -1.0 : m_scene->minimumValue();
|
return m_scene->empty() ? CurveEditorStyle::defaultValueMin : m_scene->minimumValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
double GraphicsView::maximumValue() const
|
double GraphicsView::maximumValue() const
|
||||||
{
|
{
|
||||||
return m_scene->empty() ? 1.0 : m_scene->maximumValue();
|
return m_scene->empty() ? CurveEditorStyle::defaultValueMax : m_scene->maximumValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
double GraphicsView::zoomX() const
|
double GraphicsView::zoomX() const
|
||||||
|
Reference in New Issue
Block a user