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 {
|
||||
|
||||
CurveEditorModel::CurveEditorModel(double minTime, double maxTime, QObject *parent)
|
||||
CurveEditorModel::CurveEditorModel(QObject *parent)
|
||||
: TreeModel(parent)
|
||||
, m_minTime(minTime)
|
||||
, m_maxTime(maxTime)
|
||||
, m_minTime(CurveEditorStyle::defaultTimeMin)
|
||||
, m_maxTime(CurveEditorStyle::defaultTimeMax)
|
||||
{}
|
||||
|
||||
CurveEditorModel::~CurveEditorModel() {}
|
||||
|
@@ -57,7 +57,7 @@ signals:
|
||||
void curveChanged(PropertyTreeItem *item);
|
||||
|
||||
public:
|
||||
CurveEditorModel(double minTime, double maxTime, QObject *parent = nullptr);
|
||||
CurveEditorModel(QObject *parent = nullptr);
|
||||
|
||||
~CurveEditorModel() override;
|
||||
|
||||
|
@@ -105,6 +105,13 @@ struct Shortcuts
|
||||
|
||||
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;
|
||||
|
||||
QBrush backgroundBrush = QBrush(QColor(5, 0, 100));
|
||||
@@ -124,7 +131,7 @@ struct CurveEditorStyle
|
||||
double valueAxisWidth = 60.0;
|
||||
double valueOffsetTop = 10.0;
|
||||
double valueOffsetBottom = 10.0;
|
||||
double labelDensityY = 1.5;
|
||||
double labelDensityY = 2.0;
|
||||
|
||||
HandleItemStyleOption handleStyle;
|
||||
KeyframeItemStyleOption keyframeStyle;
|
||||
|
@@ -42,7 +42,7 @@ namespace QmlDesigner {
|
||||
CurveEditorView::CurveEditorView(QObject *parent)
|
||||
: AbstractView(parent)
|
||||
, m_block(false)
|
||||
, m_model(new DesignTools::CurveEditorModel(0., 500.))
|
||||
, m_model(new DesignTools::CurveEditorModel())
|
||||
, m_editor(new DesignTools::CurveEditor(m_model))
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
@@ -267,7 +267,7 @@ ModelNode getTargetNode1(DesignTools::PropertyTreeItem *item, const QmlTimeline
|
||||
QString targetId = nodeItem->name();
|
||||
if (timeline.isValid()) {
|
||||
for (auto &&target : timeline.allTargets()) {
|
||||
if (target.displayName() == targetId)
|
||||
if (target.isValid() && target.displayName() == targetId)
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
@@ -87,6 +87,16 @@ QRectF CurveItem::boundingRect() const
|
||||
for (auto *item : m_keyframes)
|
||||
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);
|
||||
}
|
||||
|
||||
|
@@ -114,9 +114,29 @@ double GraphicsScene::maximumValue() const
|
||||
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
|
||||
{
|
||||
return sceneRect();
|
||||
QRectF rect;
|
||||
for (auto *curve : curves())
|
||||
rect |= curve->boundingRect();
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
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()));
|
||||
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;
|
||||
}
|
||||
return m_limits;
|
||||
|
@@ -67,6 +67,10 @@ public:
|
||||
|
||||
double maximumValue() const;
|
||||
|
||||
double animationRangeMin() const;
|
||||
|
||||
double animationRangeMax() const;
|
||||
|
||||
QRectF rect() const;
|
||||
|
||||
QVector<CurveItem *> curves() const;
|
||||
|
@@ -126,12 +126,12 @@ double GraphicsView::maximumTime() 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
|
||||
{
|
||||
return m_scene->empty() ? 1.0 : m_scene->maximumValue();
|
||||
return m_scene->empty() ? CurveEditorStyle::defaultValueMax : m_scene->maximumValue();
|
||||
}
|
||||
|
||||
double GraphicsView::zoomX() const
|
||||
|
Reference in New Issue
Block a user