summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKnud Dollereder <knud.dollereder@qt.io>2019-01-28 12:30:46 +0100
committerThomas Hartmann <thomas.hartmann@qt.io>2019-01-29 10:32:12 +0000
commit869b0d108c71c614c4bb514ebd54e9ac369d6e9d (patch)
tree978f2561a955caf25aaf02658e23a2f8cb09ca0d
parentae3ff4848bb68b4c234e5e4f0a801abd4394e4eb (diff)
Add initial version of the curve-editor and example application
Change-Id: Ieb2871709bc0d8b96559f2cc0e7b1ab748dc0af2 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r--examples/curveeditorapp/curveeditorapp.pro31
-rw-r--r--examples/curveeditorapp/examplecurvemodel.cpp78
-rw-r--r--examples/curveeditorapp/examplecurvemodel.h49
-rw-r--r--examples/curveeditorapp/main.cpp39
-rw-r--r--examples/curveeditorapp/mainwindow.cpp76
-rw-r--r--examples/curveeditorapp/mainwindow.h41
-rw-r--r--src/curveeditor/colorcontrol.cpp103
-rw-r--r--src/curveeditor/colorcontrol.h64
-rw-r--r--src/curveeditor/curveeditor.cpp57
-rw-r--r--src/curveeditor/curveeditor.h54
-rw-r--r--src/curveeditor/curveeditor.pri13
-rw-r--r--src/curveeditor/curveeditormodel.h53
-rw-r--r--src/curveeditor/curveeditorstyle.cpp170
-rw-r--r--src/curveeditor/curveeditorstyle.h128
-rw-r--r--src/curveeditor/curveeditorview.cpp335
-rw-r--r--src/curveeditor/curveeditorview.h105
-rw-r--r--src/curveeditor/curveitem.cpp75
-rw-r--r--src/curveeditor/curveitem.h59
18 files changed, 1530 insertions, 0 deletions
diff --git a/examples/curveeditorapp/curveeditorapp.pro b/examples/curveeditorapp/curveeditorapp.pro
new file mode 100644
index 0000000..543d9b0
--- /dev/null
+++ b/examples/curveeditorapp/curveeditorapp.pro
@@ -0,0 +1,31 @@
+TARGET = curveeditorapp
+
+TEMPLATE = app
+
+QT += widgets
+
+CONFIG += debug
+
+# The following define makes your compiler warn you if you use any
+# feature of Qt which has been marked as deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
+
+INCLUDEPATH += .
+
+include(../../sharedcomponents.pri)
+
+# Input
+HEADERS += \
+ mainwindow.h
+
+SOURCES += \
+ main.cpp \
+ mainwindow.cpp \
+ examplecurvemodel.cpp
diff --git a/examples/curveeditorapp/examplecurvemodel.cpp b/examples/curveeditorapp/examplecurvemodel.cpp
new file mode 100644
index 0000000..fef2dff
--- /dev/null
+++ b/examples/curveeditorapp/examplecurvemodel.cpp
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Design Tooling
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#include "examplecurvemodel.h"
+
+namespace DesignTools
+{
+
+double ExampleCurveModel::minimumTime() const
+{
+ return 0.0;
+}
+
+double ExampleCurveModel::maximumTime() const
+{
+ return 500.0;
+}
+
+double ExampleCurveModel::minimumValue() const
+{
+ return -50.0;
+}
+
+double ExampleCurveModel::maximumValue() const
+{
+ return 100.0;
+}
+
+std::vector< QPointF > ExampleCurveModel::curve(int i) const
+{
+ if (i==0)
+ return {QPointF(0.0, -5.0), QPointF(100.1, 0.9), QPointF(200., 0.7), QPointF(500., 0.3)};
+ else
+ return {QPointF(0.0, 10.0), QPointF(100.1, 30.), QPointF(200., -50.), QPointF(500., 100)};
+}
+
+CurveEditorStyle ExampleCurveModel::style() const
+{
+ // Pseudo auto generated. See: CurveEditorStyleDialog
+ CurveEditorStyle out;
+ out.backgroundBrush = QBrush(QColor(138, 226, 52));
+ out.backgroundAlternateBrush = QBrush(QColor(78, 154, 6));
+ out.fontColor = QColor(200, 200, 200);
+ out.curveColor = QColor(128, 128, 128);
+ out.gridColor = QColor(128, 128, 128);
+ out.rangeBarColor = QColor(50, 50, 255);
+ out.rangeBarCapsColor = QColor(50, 50, 255);
+ out.playheadColor = QColor(200, 200, 0);
+ out.abscissaHeight = 40;
+ out.ordinateWidth = 60;
+ out.canvasMargin = 5;
+ out.cellCountX = 10;
+ out.cellCountY = 10;
+ return out;
+}
+
+} // End namespace DesignTools.
diff --git a/examples/curveeditorapp/examplecurvemodel.h b/examples/curveeditorapp/examplecurvemodel.h
new file mode 100644
index 0000000..76e9b67
--- /dev/null
+++ b/examples/curveeditorapp/examplecurvemodel.h
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Design Tooling
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "curveeditormodel.h"
+
+namespace DesignTools
+{
+
+class ExampleCurveModel : public CurveEditorModel
+{
+public:
+ double minimumTime() const override;
+
+ double maximumTime() const override;
+
+ double minimumValue() const override;
+
+ double maximumValue() const override;
+
+ std::vector< QPointF > curve(int i) const override;
+
+ CurveEditorStyle style() const override;
+};
+
+} // End namespace DesignTools.
diff --git a/examples/curveeditorapp/main.cpp b/examples/curveeditorapp/main.cpp
new file mode 100644
index 0000000..18652c1
--- /dev/null
+++ b/examples/curveeditorapp/main.cpp
@@ -0,0 +1,39 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Design Tooling
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#include "mainwindow.h"
+
+#include <QApplication>
+
+int main( int argc, char* argv[] )
+{
+ QApplication app( argc, argv );
+
+ DesignTools::MainWindow window;
+
+ window.show( );
+
+ return app.exec();
+}
+
diff --git a/examples/curveeditorapp/mainwindow.cpp b/examples/curveeditorapp/mainwindow.cpp
new file mode 100644
index 0000000..a7b132d
--- /dev/null
+++ b/examples/curveeditorapp/mainwindow.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Design Tooling
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#include "mainwindow.h"
+#include "curveeditor.h"
+#include "curveeditorview.h"
+#include "examplecurvemodel.h"
+
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QSlider>
+#include <QVBoxLayout>
+
+#include <functional>
+
+namespace DesignTools
+{
+
+QHBoxLayout* createSlider(const QString& name, std::function<void(int)> fun)
+{
+ QSlider* slider = new QSlider;
+ slider->setMinimum(0);
+ slider->setMaximum(1000);
+ slider->setValue(0);
+ slider->setOrientation(Qt::Horizontal);
+ QObject::connect(slider, &QSlider::valueChanged, fun);
+
+ auto* hbox = new QHBoxLayout;
+ hbox->addWidget(new QLabel(name));
+ hbox->addWidget(slider);
+
+ return hbox;
+}
+
+MainWindow::MainWindow()
+ :
+ QMainWindow( )
+{
+ auto* model = new ExampleCurveModel;
+ auto* editor = new CurveEditor(model);
+
+ auto zoomX = [editor](int val) { editor->view()->zoomX(static_cast<double>(val)/1000.); };
+ auto zoomY = [editor](int val) { editor->view()->zoomY(static_cast<double>(val)/1000.); };
+
+ auto* box = new QVBoxLayout;
+ box->addWidget(editor);
+ box->addLayout(createSlider("Zoom X", zoomX));
+ box->addLayout(createSlider("Zoom Y", zoomY));
+
+ auto* centralWidget = new QWidget;
+ centralWidget->setLayout(box);
+ setCentralWidget(centralWidget);
+}
+
+} // End namespace DesignTools.
diff --git a/examples/curveeditorapp/mainwindow.h b/examples/curveeditorapp/mainwindow.h
new file mode 100644
index 0000000..4d8c604
--- /dev/null
+++ b/examples/curveeditorapp/mainwindow.h
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Design Tooling
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QMainWindow>
+
+namespace DesignTools
+{
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+};
+
+} // End namespace DesignTools.
diff --git a/src/curveeditor/colorcontrol.cpp b/src/curveeditor/colorcontrol.cpp
new file mode 100644
index 0000000..0fcc247
--- /dev/null
+++ b/src/curveeditor/colorcontrol.cpp
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Design Tooling
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#include "colorcontrol.h"
+
+#include <QToolTip>
+#include <QEvent>
+#include <QHelpEvent>
+#include <QPainter>
+#include <QColorDialog>
+
+namespace DesignTools
+{
+
+ColorControl::ColorControl()
+ : QWidget(nullptr)
+ , m_color(Qt::black)
+{
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+ setFixedHeight(20);
+}
+
+ColorControl::ColorControl(const QColor &color, QWidget *parent)
+ : QWidget(parent)
+ , m_color(color)
+{
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+ setFixedHeight(20);
+}
+
+ColorControl::~ColorControl() = default;
+
+
+QColor ColorControl::value() const
+{
+ return m_color;
+}
+
+void ColorControl::setValue(const QColor& val)
+{
+ m_color = val;
+}
+
+bool ColorControl::event(QEvent *event)
+{
+ if (event->type() == QEvent::ToolTip) {
+ if (auto helpEvent = static_cast<const QHelpEvent *>(event)) {
+ QToolTip::showText(helpEvent->globalPos(), m_color.name());
+ return true;
+ }
+ }
+ return QWidget::event(event);
+}
+
+void ColorControl::paintEvent(QPaintEvent *event)
+{
+ QPainter painter(this);
+ painter.fillRect(event->rect(), m_color);
+}
+
+void ColorControl::mouseReleaseEvent(QMouseEvent *event)
+{
+ QColor color = QColorDialog::getColor(m_color, this);
+
+ event->accept();
+
+ if (color != m_color) {
+ m_color = color;
+ update();
+ emit valueChanged();
+ }
+}
+
+void ColorControl::mousePressEvent(QMouseEvent *event)
+{
+ // Required if embedded in a QGraphicsProxywidget
+ // in order to call mouseRelease properly.
+ QWidget::mousePressEvent(event);
+ event->accept();
+}
+
+} // End namespace DesignTools.
diff --git a/src/curveeditor/colorcontrol.h b/src/curveeditor/colorcontrol.h
new file mode 100644
index 0000000..c99064c
--- /dev/null
+++ b/src/curveeditor/colorcontrol.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Design Tooling
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QWidget>
+
+namespace DesignTools
+{
+
+class ColorControl : public QWidget
+{
+ Q_OBJECT
+
+public:
+ ColorControl();
+
+ ColorControl(const QColor &color, QWidget *parent = nullptr);
+
+ ~ColorControl() override;
+
+ QColor value() const;
+
+ void setValue(const QColor& val);
+
+protected:
+ bool event(QEvent *event) override;
+
+ void paintEvent(QPaintEvent *event) override;
+
+ void mouseReleaseEvent(QMouseEvent *event) override;
+
+ void mousePressEvent(QMouseEvent *event) override;
+
+signals:
+ void valueChanged();
+
+private:
+ QColor m_color;
+};
+
+} // End namespace DesignTools.
diff --git a/src/curveeditor/curveeditor.cpp b/src/curveeditor/curveeditor.cpp
new file mode 100644
index 0000000..9402d3d
--- /dev/null
+++ b/src/curveeditor/curveeditor.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Design Tooling
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#include "curveeditor.h"
+#include "curveeditormodel.h"
+#include "curveeditorview.h"
+
+#include <QHBoxLayout>
+#include <QSplitter>
+#include <QTreeView>
+
+namespace DesignTools
+{
+
+CurveEditor::CurveEditor(CurveEditorModel* model, QWidget* parent)
+ :
+ QWidget(parent),
+ m_tree(new QTreeView),
+ m_view(new CurveEditorView(model))
+{
+ QSplitter* splitter = new QSplitter;
+ splitter->addWidget(m_tree);
+ splitter->addWidget(m_view);
+ splitter->setSizes({5, 80});
+
+ QHBoxLayout* box = new QHBoxLayout;
+ box->addWidget(splitter);
+ setLayout(box);
+}
+
+CurveEditorView* CurveEditor::view() const
+{
+ return m_view;
+}
+
+} // End namespace DesignTools.
diff --git a/src/curveeditor/curveeditor.h b/src/curveeditor/curveeditor.h
new file mode 100644
index 0000000..bfc0599
--- /dev/null
+++ b/src/curveeditor/curveeditor.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Design Tooling
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QWidget>
+
+class QTreeView;
+
+namespace DesignTools
+{
+
+class CurveEditorModel;
+class CurveEditorView;
+
+class CurveEditor : public QWidget
+{
+ Q_OBJECT
+
+public:
+ CurveEditor(CurveEditorModel* model, QWidget* parent = nullptr);
+
+ CurveEditorView* view() const;
+
+private:
+ QTreeView* m_tree;
+
+ CurveEditorView* m_view;
+};
+
+} // End namespace DesignTools.
+
diff --git a/src/curveeditor/curveeditor.pri b/src/curveeditor/curveeditor.pri
index 19cd8df..ba5aaf9 100644
--- a/src/curveeditor/curveeditor.pri
+++ b/src/curveeditor/curveeditor.pri
@@ -1,3 +1,16 @@
INCLUDEPATH += $$PWD
### include required files
+HEADERS += \
+ $$PWD/curveeditor.h \
+ $$PWD/curveeditorstyle.h \
+ $$PWD/curveeditorview.h \
+ $$PWD/curveitem.h \
+ $$PWD/colorcontrol.h
+
+SOURCES += \
+ $$PWD/curveeditor.cpp \
+ $$PWD/curveeditorstyle.cpp \
+ $$PWD/curveeditorview.cpp \
+ $$PWD/curveitem.cpp \
+ $$PWD/colorcontrol.cpp
diff --git a/src/curveeditor/curveeditormodel.h b/src/curveeditor/curveeditormodel.h
new file mode 100644
index 0000000..35ac6f5
--- /dev/null
+++ b/src/curveeditor/curveeditormodel.h
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Design Tooling
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "curveeditorstyle.h"
+
+#include <vector>
+
+class QPointF;
+
+namespace DesignTools
+{
+
+class CurveEditorModel
+{
+public:
+ virtual double minimumTime() const = 0;
+
+ virtual double maximumTime() const = 0;
+
+ virtual double minimumValue() const = 0;
+
+ virtual double maximumValue() const = 0;
+
+ virtual std::vector< QPointF > curve( int i ) const = 0;
+
+ virtual CurveEditorStyle style() const { return CurveEditorStyle(); }
+};
+
+} // End namespace DesignTools.
diff --git a/src/curveeditor/curveeditorstyle.cpp b/src/curveeditor/curveeditorstyle.cpp
new file mode 100644
index 0000000..16485e0
--- /dev/null
+++ b/src/curveeditor/curveeditorstyle.cpp
@@ -0,0 +1,170 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Design Tooling
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#include "curveeditorstyle.h"
+#include "colorcontrol.h"
+
+#include <QDebug>
+#include <QDoubleSpinBox>
+#include <QLabel>
+#include <QPushButton>
+#include <QSpinBox>
+#include <QVBoxLayout>
+
+namespace DesignTools
+{
+
+QHBoxLayout* createRow(const QString& title, QWidget* widget)
+{
+ auto*label = new QLabel(title);
+ label->setFixedWidth(200);
+ label->setAlignment(Qt::AlignRight);
+
+ auto* box = new QHBoxLayout;
+ box->addWidget(label);
+ box->addWidget(widget);
+ return box;
+}
+
+CurveEditorStyleDialog::CurveEditorStyleDialog(CurveEditorStyle& style, QWidget* parent )
+ :
+ QDialog(parent),
+ m_printButton(new QPushButton("Print")),
+ m_abscissa(new QDoubleSpinBox()),
+ m_ordinate(new QDoubleSpinBox()),
+ m_canvasMargin(new QDoubleSpinBox()),
+ m_cellCountX(new QSpinBox()),
+ m_cellCountY(new QSpinBox()),
+ m_background(new ColorControl(style.backgroundBrush.color())),
+ m_backgroundAlternate(new ColorControl(style.backgroundAlternateBrush.color())),
+ m_fontColor(new ColorControl(style.fontColor)),
+ m_curveColor(new ColorControl(style.curveColor)),
+ m_gridColor(new ColorControl(style.gridColor)),
+ m_rangeBarColor(new ColorControl(style.rangeBarCapsColor)),
+ m_rangeBarCapsColor(new ColorControl(style.rangeBarCapsColor)),
+ m_playhead(new ColorControl(style.playheadColor) )
+{
+ m_abscissa->setValue(style.abscissaHeight);
+ m_ordinate->setValue(style.ordinateWidth);
+ m_canvasMargin->setValue(style.canvasMargin);
+ m_cellCountX->setValue(style.cellCountX);
+ m_cellCountY->setValue(style.cellCountY);
+
+ connect(m_printButton, &QPushButton::released, this, &CurveEditorStyleDialog::printStyle);
+
+ auto intChanged = [this](int) { emitStyleChanged(); };
+ auto doubleChanged = [this](double) { emitStyleChanged(); };
+ auto colorChanged = [this]() { emitStyleChanged(); };
+
+ auto intSignal = static_cast< void (QSpinBox::*)(int) >(&QSpinBox::valueChanged);
+ auto doubleSignal = static_cast< void (QDoubleSpinBox::*)(double) >(&QDoubleSpinBox::valueChanged);
+
+ connect(m_abscissa, doubleSignal, doubleChanged);
+ connect(m_ordinate, doubleSignal, doubleChanged);
+ connect(m_canvasMargin, doubleSignal, doubleChanged);
+
+ connect(m_cellCountX, intSignal, intChanged);
+ connect(m_cellCountY, intSignal, intChanged);
+
+ connect(m_background, &ColorControl::valueChanged, colorChanged);
+ connect(m_backgroundAlternate, &ColorControl::valueChanged, colorChanged);
+
+ connect(m_fontColor, &ColorControl::valueChanged, colorChanged);
+ connect(m_curveColor, &ColorControl::valueChanged, colorChanged);
+ connect(m_gridColor, &ColorControl::valueChanged, colorChanged);
+ connect(m_rangeBarColor, &ColorControl::valueChanged, colorChanged);
+ connect(m_rangeBarCapsColor, &ColorControl::valueChanged, colorChanged);
+ connect(m_playhead, &ColorControl::valueChanged, colorChanged);
+
+ auto* box = new QVBoxLayout;
+ box->addLayout( createRow("Abscissa Width", m_abscissa) );
+ box->addLayout( createRow("Ordinate Width", m_ordinate) );
+ box->addLayout( createRow("Canvas Margin", m_canvasMargin) );
+ box->addLayout( createRow("Cellcount X", m_cellCountX) );
+ box->addLayout( createRow("Cellcount Y", m_cellCountY) );
+ box->addLayout( createRow("Background Color", m_background) );
+ box->addLayout( createRow("Alternate Background Color", m_backgroundAlternate) );
+ box->addLayout( createRow("Font Color", m_fontColor) );
+ box->addLayout( createRow("Curve Color", m_curveColor) );
+ box->addLayout( createRow("Grid Color", m_gridColor) );
+ box->addLayout( createRow("Range Bar Color", m_rangeBarColor) );
+ box->addLayout( createRow("Range Bar Caps Color", m_rangeBarCapsColor) );
+ box->addLayout( createRow("Playhead Color", m_playhead) );
+
+ box->addWidget(m_printButton);
+ setLayout(box);
+}
+
+CurveEditorStyle CurveEditorStyleDialog::style() const
+{
+ CurveEditorStyle style;
+ style.backgroundBrush = QBrush(m_background->value());
+ style.backgroundAlternateBrush = QBrush(m_backgroundAlternate->value());
+ style.fontColor = m_fontColor->value();
+ style.curveColor = m_curveColor->value();
+ style.gridColor = m_gridColor->value();
+ style.rangeBarColor = m_rangeBarColor->value();
+ style.rangeBarCapsColor = m_rangeBarCapsColor->value();
+ style.playheadColor = m_playhead->value();
+ style.abscissaHeight = m_abscissa->value();
+ style.ordinateWidth = m_ordinate->value();
+ style.canvasMargin = m_canvasMargin->value();
+ style.cellCountX = m_cellCountX->value();
+ style.cellCountY = m_cellCountY->value();
+ return style;
+}
+
+void CurveEditorStyleDialog::emitStyleChanged( )
+{
+ emit styleChanged(style());
+}
+
+void CurveEditorStyleDialog::printStyle( )
+{
+ auto toString = [](const QColor& color) {
+ QString tmp = QString("QColor(%1, %2, %3)").arg(color.red()).arg(color.green() ).arg(color.blue());
+ return qPrintable(tmp);
+ };
+
+ CurveEditorStyle s = style();
+ qDebug() << "";
+ qDebug().nospace() << "CurveEditorStyle out;";
+ qDebug().nospace() << "out.backgroundBrush = QBrush(" << toString(s.backgroundBrush.color()) << ");";
+ qDebug().nospace() << "out.backgroundAlternateBrush = QBrush(" << toString(s.backgroundAlternateBrush.color()) << ");";
+ qDebug().nospace() << "out.fontColor = " << toString(s.fontColor) << ";";
+ qDebug().nospace() << "out.curveColor = " << toString(s.curveColor) << ";";
+ qDebug().nospace() << "out.gridColor = " << toString(s.gridColor) << ";";
+ qDebug().nospace() << "out.rangeBarColor = " << toString(s.rangeBarColor) << ";";
+ qDebug().nospace() << "out.rangeBarCapsColor = " << toString(s.rangeBarCapsColor) << ";";
+ qDebug().nospace() << "out.playheadColor = " << toString(s.playheadColor) << ";";
+ qDebug().nospace() << "out.abscissaHeight = " << s.abscissaHeight << ";";
+ qDebug().nospace() << "out.ordinateWidth = " << s.ordinateWidth << ";";
+ qDebug().nospace() << "out.canvasMargin = " << s.canvasMargin << ";";
+ qDebug().nospace() << "out.cellCountX = " << s.cellCountX << ";";
+ qDebug().nospace() << "out.cellCountY = " << s.cellCountY << ";";
+ qDebug().nospace() << "return out;";
+ qDebug() << "";
+}
+
+} // End namespace DesignTools.
diff --git a/src/curveeditor/curveeditorstyle.h b/src/curveeditor/curveeditorstyle.h
new file mode 100644
index 0000000..0659055
--- /dev/null
+++ b/src/curveeditor/curveeditorstyle.h
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Design Tooling
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QBrush>
+#include <QColor>
+#include <QDialog>
+
+class QPushButton;
+class QSpinBox;
+class QDoubleSpinBox;
+
+namespace DesignTools
+{
+
+class ColorControl;
+
+struct CurveEditorStyle
+{
+ QBrush backgroundBrush = QBrush(QColor(5, 0, 100));
+
+ QBrush backgroundAlternateBrush = QBrush(QColor(0, 0, 50));
+
+
+ QColor fontColor = QColor(200, 200, 200);
+
+ QColor curveColor = QColor(128, 128,128);
+
+ QColor gridColor = QColor(128, 128, 128);
+
+ QColor rangeBarColor = QColor(128, 128, 128);
+
+ QColor rangeBarCapsColor = QColor(50, 50, 255);
+
+ QColor playheadColor = QColor(200,200,0);
+
+
+ double abscissaHeight = 40.0;
+
+ double ordinateWidth = 60.0;
+
+ double canvasMargin = 5.0;
+
+
+ int zoomInWidth = 100;
+
+ int zoomInHeight = 100;
+
+
+ int cellCountX = 10;
+
+ int cellCountY = 10;
+};
+
+
+class CurveEditorView;
+
+class CurveEditorStyleDialog : public QDialog
+{
+ Q_OBJECT
+
+signals:
+ void styleChanged(const CurveEditorStyle& style);
+
+public:
+ CurveEditorStyleDialog(CurveEditorStyle& style, QWidget* parent = nullptr);
+
+ CurveEditorStyle style() const;
+
+private:
+ void emitStyleChanged();
+
+ void printStyle();
+
+private:
+ QPushButton* m_printButton;
+
+ QDoubleSpinBox* m_abscissa;
+
+ QDoubleSpinBox* m_ordinate;
+
+ QDoubleSpinBox* m_canvasMargin;
+
+ QSpinBox* m_cellCountX;
+
+ QSpinBox* m_cellCountY;
+
+ ColorControl* m_background;
+
+ ColorControl* m_backgroundAlternate;
+
+ ColorControl* m_fontColor;
+
+ ColorControl* m_curveColor;
+
+ ColorControl* m_gridColor;
+
+ ColorControl* m_rangeBarColor;
+
+ ColorControl* m_rangeBarCapsColor;
+
+ ColorControl* m_playhead;
+};
+
+} // End namespace DesignTools.
diff --git a/src/curveeditor/curveeditorview.cpp b/src/curveeditor/curveeditorview.cpp
new file mode 100644
index 0000000..2817f24
--- /dev/null
+++ b/src/curveeditor/curveeditorview.cpp
@@ -0,0 +1,335 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Design Tooling
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#include "curveeditorview.h"
+#include "curveeditormodel.h"
+#include "curveitem.h"
+
+#include <QDebug>
+#include <QResizeEvent>
+#include <QMenu>
+#include <QAction>
+#include <QScrollBar>
+
+#include <cmath>
+
+namespace DesignTools
+{
+
+double clamp(double val, double lo, double hi)
+{
+ return val < lo ? lo : (val > hi ? hi : val);
+}
+
+double lerp(double blend, double a, double b)
+{
+ return (1.0-blend) * a + blend *b;
+}
+
+double scaleX(const QTransform& transform)
+{
+ return transform.m11();
+}
+
+double scaleY(const QTransform& transform)
+{
+ return transform.m22();
+}
+
+
+CurveEditorView::CurveEditorView(CurveEditorModel* model, QWidget* parent)
+ :
+ QGraphicsView(parent),
+ m_scene(),
+ m_style(model->style()),
+ m_model(model),
+ m_dialog(m_style, this),
+ m_zoomX(0.0),
+ m_zoomY(0.0)
+{
+ setScene(&m_scene);
+ setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+ setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
+
+ connect(&m_dialog, &CurveEditorStyleDialog::styleChanged, this, &CurveEditorView::setStyle);
+
+ m_scene.addItem(new CurveItem( model->curve(0) ));
+ m_scene.addItem(new CurveItem( model->curve(1) ));
+
+ applyZoom(m_zoomX, m_zoomY);
+ update();
+}
+
+void CurveEditorView::setStyle(const CurveEditorStyle& style)
+{
+ m_style = style;
+ updateSceneRect();
+ viewport()->update();
+}
+
+void CurveEditorView::zoomX(double zoom)
+{
+ applyZoom(zoom, m_zoomY);
+ update();
+}
+
+void CurveEditorView::zoomY(double zoom)
+{
+ applyZoom(m_zoomX, zoom);
+ update();
+}
+
+void CurveEditorView::resizeEvent(QResizeEvent* event)
+{
+ Q_UNUSED(event);
+
+ updateSceneRect();
+ applyZoom(m_zoomX, m_zoomY);
+ viewport()->update();
+}
+
+void CurveEditorView::contextMenuEvent(QContextMenuEvent *event)
+{
+ Q_UNUSED(event);
+
+ auto openStyleEditor = [this](){ m_dialog.show(); };
+
+ QMenu menu;
+ QAction* openEditorAction = menu.addAction(tr("Open Style Editor"));
+ connect(openEditorAction, &QAction::triggered, openStyleEditor);
+
+ menu.exec(event->globalPos());
+}
+
+void CurveEditorView::drawForeground(QPainter *painter, const QRectF &rect)
+{
+ auto gap = QRectF(rect.topLeft(), QSizeF(m_style.ordinateWidth, m_style.abscissaHeight));
+
+ auto abscissa = QRectF(
+ gap.topRight(),
+ rect.topRight() + QPointF(0.0, gap.height()));
+ drawTimeScale(painter, abscissa);
+
+ auto ordinate = QRectF(
+ gap.bottomLeft(),
+ rect.bottomLeft() + QPointF(gap.width(), 0.0));
+ drawValueScale(painter, ordinate);
+
+ painter->fillRect(gap, m_style.backgroundAlternateBrush);
+}
+
+void CurveEditorView::drawBackground(QPainter* painter, const QRectF& rect)
+{
+ painter->fillRect(rect, m_style.backgroundBrush);
+ painter->fillRect(scene()->sceneRect(), m_style.backgroundAlternateBrush);
+
+ drawGrid(painter, rect);
+ drawExtremaX(painter, rect);
+ drawExtremaY(painter, rect);
+}
+
+int CurveEditorView::mapTimetoX(double time)
+{
+ return std::round(time * scaleX(m_transform));
+}
+
+int CurveEditorView::mapValueToY(double y)
+{
+ return std::round(y * scaleY(m_transform));
+}
+
+double CurveEditorView::mapXtoTime(int x)
+{
+ return static_cast<double>(x)/scaleX(m_transform);
+}
+
+double CurveEditorView::mapYtoValue(int y)
+{
+ return static_cast<double>(y)/scaleY(m_transform);
+}
+
+void CurveEditorView::applyZoom(double x, double y)
+{
+ m_zoomX = x;
+ m_zoomY = y;
+
+ double canvasWidth = rect().width() - m_style.ordinateWidth - 2*m_style.canvasMargin - rect().width()/20.0;
+ double xZoomedOut = canvasWidth / (m_model->maximumTime() - m_model->minimumTime());
+ double xZoomedIn = m_style.zoomInWidth;
+ double scaleX = lerp(clamp(m_zoomX, 0.0, 1.0), xZoomedOut, xZoomedIn);
+
+ double canvasHeight = rect().height() - m_style.abscissaHeight - 2*m_style.canvasMargin - rect().height()/10;
+ double yZoomedOut = canvasHeight / (m_model->maximumValue() - m_model->minimumValue());
+ double yZoomedIn = m_style.zoomInHeight;
+ double scaleY = lerp(clamp(m_zoomY, 0.0, 1.0), -yZoomedOut, -yZoomedIn);
+
+ m_transform = QTransform::fromScale(scaleX, scaleY);
+
+ QRectF sceneBounds;
+ for (auto* item : items())
+ if (auto* curveItem = qgraphicsitem_cast< CurveItem* >(item))
+ sceneBounds = sceneBounds.united(curveItem->zoom(m_transform));
+
+ updateSceneRect(sceneBounds);
+}
+
+void CurveEditorView::updateSceneRect(const QRectF& rect)
+{
+ if (rect.isValid())
+ scene()->setSceneRect(rect);
+
+ QRectF sr = scene()->sceneRect().adjusted(
+ -m_style.ordinateWidth - m_style.canvasMargin,
+ -m_style.abscissaHeight - m_style.canvasMargin,
+ m_style.canvasMargin,
+ m_style.canvasMargin);
+
+ setSceneRect(sr);
+}
+
+void CurveEditorView::drawGrid(QPainter* painter, const QRectF &rect)
+{
+ painter->save();
+ painter->setPen(m_style.gridColor);
+
+ QRectF gridRect = rect.adjusted(
+ m_style.ordinateWidth + m_style.canvasMargin,
+ m_style.abscissaHeight + m_style.canvasMargin,
+ -m_style.canvasMargin,
+ -m_style.canvasMargin);
+
+ auto drawVerticalLine = [painter, gridRect]( double position ) {
+ painter->drawLine(position, gridRect.top(), position, gridRect.bottom());
+ };
+
+ double timeIncrement = timeLabelInterval(painter, m_model->maximumTime());
+ for (double i=m_model->minimumTime(); i<=m_model->maximumTime(); i+=timeIncrement)
+ drawVerticalLine(mapTimetoX(i));
+
+ painter->restore();
+}
+
+void CurveEditorView::drawExtremaX(QPainter* painter, const QRectF& rect)
+{
+ auto drawVerticalLine = [rect, painter]( double position ) {
+ painter->drawLine(position, rect.top(), position, rect.bottom());
+ };
+
+ painter->save();
+ painter->setPen(Qt::red);
+ drawVerticalLine( mapTimetoX(m_model->minimumTime()) );
+ drawVerticalLine( mapTimetoX(m_model->maximumTime()) );
+ painter->restore();
+}
+
+void CurveEditorView::drawExtremaY(QPainter* painter, const QRectF& rect)
+{
+ auto drawHorizontalLine = [rect, painter]( double position ) {
+ painter->drawLine(rect.left(), position, rect.right(), position);
+ };
+
+ painter->save();
+ painter->setPen(Qt::blue);
+ drawHorizontalLine( mapValueToY(m_model->minimumValue()) );
+ drawHorizontalLine( mapValueToY(m_model->maximumValue()) );
+ painter->restore();
+}
+
+void CurveEditorView::drawTimeScale(QPainter* painter, const QRectF &rect)
+{
+ painter->save();
+ painter->setPen(m_style.fontColor);
+ painter->fillRect(rect, m_style.backgroundAlternateBrush);
+
+ QFontMetrics fm(painter->font());
+
+ auto paintLabeledTick = [this, painter, rect, fm]( double time ) {
+ QString timeText = QString("%1").arg(time);
+
+ int position = mapTimetoX(time);
+
+ QRect textRect = fm.boundingRect(timeText);
+ textRect.moveCenter( QPoint(position, rect.center().y()) );
+ painter->drawText(textRect, Qt::AlignCenter, timeText);
+ painter->drawLine(position, rect.bottom() - 2, position, textRect.bottom() + 2);
+ };
+
+ double timeIncrement = timeLabelInterval(painter, m_model->maximumTime());
+ for (double i=m_model->minimumTime(); i<=m_model->maximumTime(); i+=timeIncrement)
+ paintLabeledTick(i);
+
+ painter->restore();
+}
+
+void CurveEditorView::drawValueScale(QPainter* painter, const QRectF &rect)
+{
+ painter->save();
+ painter->setPen(m_style.fontColor);
+ painter->fillRect(rect, m_style.backgroundAlternateBrush);
+
+ QFontMetrics fm(painter->font());
+ auto paintLabeledTick = [this, painter, rect, fm]( double value ) {
+ QString valueText = QString("%1").arg(value);
+
+ int position = mapValueToY(value);
+
+ QRect textRect = fm.boundingRect(valueText);
+ textRect.moveCenter( QPoint(rect.center().x(), position) );
+ painter->drawText(textRect, Qt::AlignCenter, valueText);
+ };
+
+ paintLabeledTick(m_model->minimumValue());
+ paintLabeledTick(m_model->maximumValue());
+ painter->restore();
+}
+
+double CurveEditorView::timeLabelInterval(QPainter* painter, double maxTime)
+{
+ QFontMetrics fm(painter->font());
+ int minTextSpacing = fm.width(QString("X%1X").arg(maxTime));
+
+ int deltaTime = 1;
+ int nextFactor = 5;
+
+ double tickDistance = mapTimetoX(deltaTime);
+ while (true)
+ {
+ if (tickDistance > minTextSpacing)
+ break;
+
+ deltaTime *= nextFactor;
+ tickDistance = mapTimetoX(deltaTime);
+
+ if (nextFactor == 5)
+ nextFactor = 2;
+ else
+ nextFactor = 5;
+ }
+
+ return deltaTime;
+}
+
+} // End namespace DesignTools.
diff --git a/src/curveeditor/curveeditorview.h b/src/curveeditor/curveeditorview.h
new file mode 100644
index 0000000..fde7b95
--- /dev/null
+++ b/src/curveeditor/curveeditorview.h
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Design Tooling
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "curveeditorstyle.h"
+
+#include <QGraphicsView>
+#include <QGraphicsScene>
+
+namespace DesignTools
+{
+
+class CurveEditorModel;
+
+class CurveEditorView : public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ CurveEditorView(CurveEditorModel* model, QWidget* parent = nullptr);
+
+ void setStyle(const CurveEditorStyle& style);
+
+ void zoomX(double zoom);
+
+ void zoomY(double zoom);
+
+protected:
+ void resizeEvent(QResizeEvent* event) override;
+
+ void contextMenuEvent(QContextMenuEvent *event) override;
+
+ void drawForeground(QPainter *painter, const QRectF &rect) override;
+
+ void drawBackground(QPainter *painter, const QRectF &rect) override;
+
+private:
+ int mapTimetoX(double time);
+
+ int mapValueToY(double value);
+
+ double mapXtoTime(int x);
+
+ double mapYtoValue(int y);
+
+
+ void applyZoom(double x, double y);
+
+ void updateSceneRect(const QRectF& rect = QRectF());
+
+
+ void drawGrid(QPainter* painter, const QRectF &rect);
+
+ void drawExtremaX(QPainter* painter, const QRectF& rect);
+
+ void drawExtremaY(QPainter* painter, const QRectF& rect);
+
+
+ void drawTimeScale(QPainter* painter, const QRectF &rect);
+
+ void drawValueScale(QPainter* painter, const QRectF &rect);
+
+
+ double timeLabelInterval(QPainter* painter, double maxTime);
+
+private:
+ QGraphicsScene m_scene;
+
+ CurveEditorStyle m_style;
+
+ CurveEditorModel* m_model;
+
+ CurveEditorStyleDialog m_dialog;
+
+ double m_zoomX;
+
+ double m_zoomY;
+
+ QTransform m_transform;
+};
+
+} // End namespace DesignTools.
diff --git a/src/curveeditor/curveitem.cpp b/src/curveeditor/curveitem.cpp
new file mode 100644
index 0000000..ded3bc4
--- /dev/null
+++ b/src/curveeditor/curveitem.cpp
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Design Tooling
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+#include "curveitem.h"
+
+#include <QPainter>
+#include <QPainterPath>
+
+namespace DesignTools
+{
+
+CurveItem::CurveItem(QGraphicsItem* parent)
+ :
+ QGraphicsObject(parent),
+ m_points( { QPointF(0.0, 0.0), QPointF(1.1, 1.1) } )
+{ }
+
+CurveItem::CurveItem(const std::vector<QPointF>& points, QGraphicsItem* parent)
+ :
+ QGraphicsObject(parent),
+ m_points(points)
+{ }
+
+
+QRectF CurveItem::boundingRect() const
+{
+ return path().boundingRect();
+}
+
+void CurveItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* , QWidget* )
+{
+ painter->drawPath(path());
+}
+
+QRectF CurveItem::zoom(const QTransform& transform)
+{
+ prepareGeometryChange();
+ m_transform = transform;
+ return boundingRect();
+}
+
+QPainterPath CurveItem::path() const
+{
+ if (m_points.empty())
+ return QPainterPath();
+
+ auto out = QPainterPath(m_points.front());
+ for (size_t i=1; i<m_points.size(); ++i)
+ out.lineTo(m_transform.map(m_points[i]));
+
+ return out;
+}
+
+} // End namespace DesignTools.
diff --git a/src/curveeditor/curveitem.h b/src/curveeditor/curveitem.h
new file mode 100644
index 0000000..a16ba69
--- /dev/null
+++ b/src/curveeditor/curveitem.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Design Tooling
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QGraphicsObject>
+
+class QPainterPath;
+
+namespace DesignTools
+{
+
+class CurveItem : public QGraphicsObject
+{
+ Q_OBJECT
+
+public:
+ CurveItem(QGraphicsItem* parent = nullptr);
+
+ CurveItem(const std::vector<QPointF>& points, QGraphicsItem* parent = nullptr);
+
+ QRectF boundingRect() const override;
+
+ void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override;
+
+ QRectF zoom(const QTransform& transform);
+
+private:
+ QPainterPath path() const;
+
+private:
+ QTransform m_transform;
+
+ std::vector< QPointF > m_points;
+};
+
+} // End namespace DesignTools.