summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKnud Dollereder <knud.dollereder@qt.io>2019-01-29 14:57:21 +0100
committerKnud Dollereder <knud.dollereder@qt.io>2019-01-29 14:34:47 +0000
commit566a9ce6a4fc840d5d4b1d5793166c023643e2c6 (patch)
treefd26d118bd967bf1ba0e453b840a5f346d81bda2
parent3cedb553d8f0bff015c118a3361d34733ecd0fb4 (diff)
Respect style conventions
Change-Id: I6cdbe71a2addfb08bf2ea167a6e5e1378bdf80be Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r--examples/curveeditorapp/curveeditorapp.pro9
-rw-r--r--examples/curveeditorapp/examplecurvemodel.cpp7
-rw-r--r--examples/curveeditorapp/examplecurvemodel.h5
-rw-r--r--examples/curveeditorapp/main.cpp7
-rw-r--r--examples/curveeditorapp/mainwindow.cpp24
-rw-r--r--examples/curveeditorapp/mainwindow.h3
-rw-r--r--src/curveeditor/colorcontrol.cpp10
-rw-r--r--src/curveeditor/colorcontrol.h5
-rw-r--r--src/curveeditor/curveeditor.cpp18
-rw-r--r--src/curveeditor/curveeditor.h12
-rw-r--r--src/curveeditor/curveeditormodel.h5
-rw-r--r--src/curveeditor/curveeditorstyle.cpp87
-rw-r--r--src/curveeditor/curveeditorstyle.h44
-rw-r--r--src/curveeditor/curveeditorview.cpp108
-rw-r--r--src/curveeditor/curveeditorview.h31
-rw-r--r--src/curveeditor/curveitem.cpp28
-rw-r--r--src/curveeditor/curveitem.h13
17 files changed, 184 insertions, 232 deletions
diff --git a/examples/curveeditorapp/curveeditorapp.pro b/examples/curveeditorapp/curveeditorapp.pro
index f2743a3..2602ffd 100644
--- a/examples/curveeditorapp/curveeditorapp.pro
+++ b/examples/curveeditorapp/curveeditorapp.pro
@@ -6,17 +6,8 @@ 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($$PWD/../../sharedcomponents.pri)
diff --git a/examples/curveeditorapp/examplecurvemodel.cpp b/examples/curveeditorapp/examplecurvemodel.cpp
index fef2dff..79b1899 100644
--- a/examples/curveeditorapp/examplecurvemodel.cpp
+++ b/examples/curveeditorapp/examplecurvemodel.cpp
@@ -24,8 +24,7 @@
****************************************************************************/
#include "examplecurvemodel.h"
-namespace DesignTools
-{
+namespace DesignTools {
double ExampleCurveModel::minimumTime() const
{
@@ -47,9 +46,9 @@ double ExampleCurveModel::maximumValue() const
return 100.0;
}
-std::vector< QPointF > ExampleCurveModel::curve(int i) const
+std::vector<QPointF> ExampleCurveModel::curve(int i) const
{
- if (i==0)
+ 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)};
diff --git a/examples/curveeditorapp/examplecurvemodel.h b/examples/curveeditorapp/examplecurvemodel.h
index 76e9b67..62bfc0b 100644
--- a/examples/curveeditorapp/examplecurvemodel.h
+++ b/examples/curveeditorapp/examplecurvemodel.h
@@ -27,8 +27,7 @@
#include "curveeditormodel.h"
-namespace DesignTools
-{
+namespace DesignTools {
class ExampleCurveModel : public CurveEditorModel
{
@@ -41,7 +40,7 @@ public:
double maximumValue() const override;
- std::vector< QPointF > curve(int i) const override;
+ std::vector<QPointF> curve(int i) const override;
CurveEditorStyle style() const override;
};
diff --git a/examples/curveeditorapp/main.cpp b/examples/curveeditorapp/main.cpp
index 18652c1..a17c5b7 100644
--- a/examples/curveeditorapp/main.cpp
+++ b/examples/curveeditorapp/main.cpp
@@ -26,14 +26,13 @@
#include <QApplication>
-int main( int argc, char* argv[] )
+int main(int argc, char *argv[])
{
- QApplication app( argc, argv );
+ QApplication app(argc, argv);
DesignTools::MainWindow window;
- window.show( );
+ window.show();
return app.exec();
}
-
diff --git a/examples/curveeditorapp/mainwindow.cpp b/examples/curveeditorapp/mainwindow.cpp
index a7b132d..1154538 100644
--- a/examples/curveeditorapp/mainwindow.cpp
+++ b/examples/curveeditorapp/mainwindow.cpp
@@ -34,19 +34,18 @@
#include <functional>
-namespace DesignTools
-{
+namespace DesignTools {
-QHBoxLayout* createSlider(const QString& name, std::function<void(int)> fun)
+QHBoxLayout *createSlider(const QString &name, std::function<void(int)> fun)
{
- QSlider* slider = new QSlider;
+ 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;
+ auto *hbox = new QHBoxLayout;
hbox->addWidget(new QLabel(name));
hbox->addWidget(slider);
@@ -54,21 +53,20 @@ QHBoxLayout* createSlider(const QString& name, std::function<void(int)> fun)
}
MainWindow::MainWindow()
- :
- QMainWindow( )
+ : QMainWindow()
{
- auto* model = new ExampleCurveModel;
- auto* editor = new CurveEditor(model);
+ 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 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;
+ auto *box = new QVBoxLayout;
box->addWidget(editor);
box->addLayout(createSlider("Zoom X", zoomX));
box->addLayout(createSlider("Zoom Y", zoomY));
- auto* centralWidget = new QWidget;
+ auto *centralWidget = new QWidget;
centralWidget->setLayout(box);
setCentralWidget(centralWidget);
}
diff --git a/examples/curveeditorapp/mainwindow.h b/examples/curveeditorapp/mainwindow.h
index 4d8c604..02bf4af 100644
--- a/examples/curveeditorapp/mainwindow.h
+++ b/examples/curveeditorapp/mainwindow.h
@@ -27,8 +27,7 @@
#include <QMainWindow>
-namespace DesignTools
-{
+namespace DesignTools {
class MainWindow : public QMainWindow
{
diff --git a/src/curveeditor/colorcontrol.cpp b/src/curveeditor/colorcontrol.cpp
index 0fcc247..a833a4c 100644
--- a/src/curveeditor/colorcontrol.cpp
+++ b/src/curveeditor/colorcontrol.cpp
@@ -24,14 +24,13 @@
****************************************************************************/
#include "colorcontrol.h"
-#include <QToolTip>
+#include <QColorDialog>
#include <QEvent>
#include <QHelpEvent>
#include <QPainter>
-#include <QColorDialog>
+#include <QToolTip>
-namespace DesignTools
-{
+namespace DesignTools {
ColorControl::ColorControl()
: QWidget(nullptr)
@@ -51,13 +50,12 @@ ColorControl::ColorControl(const QColor &color, QWidget *parent)
ColorControl::~ColorControl() = default;
-
QColor ColorControl::value() const
{
return m_color;
}
-void ColorControl::setValue(const QColor& val)
+void ColorControl::setValue(const QColor &val)
{
m_color = val;
}
diff --git a/src/curveeditor/colorcontrol.h b/src/curveeditor/colorcontrol.h
index c99064c..54dfe19 100644
--- a/src/curveeditor/colorcontrol.h
+++ b/src/curveeditor/colorcontrol.h
@@ -27,8 +27,7 @@
#include <QWidget>
-namespace DesignTools
-{
+namespace DesignTools {
class ColorControl : public QWidget
{
@@ -43,7 +42,7 @@ public:
QColor value() const;
- void setValue(const QColor& val);
+ void setValue(const QColor &val);
protected:
bool event(QEvent *event) override;
diff --git a/src/curveeditor/curveeditor.cpp b/src/curveeditor/curveeditor.cpp
index 9402d3d..95adefd 100644
--- a/src/curveeditor/curveeditor.cpp
+++ b/src/curveeditor/curveeditor.cpp
@@ -30,26 +30,24 @@
#include <QSplitter>
#include <QTreeView>
-namespace DesignTools
-{
+namespace DesignTools {
-CurveEditor::CurveEditor(CurveEditorModel* model, QWidget* parent)
- :
- QWidget(parent),
- m_tree(new QTreeView),
- m_view(new CurveEditorView(model))
+CurveEditor::CurveEditor(CurveEditorModel *model, QWidget *parent)
+ : QWidget(parent)
+ , m_tree(new QTreeView)
+ , m_view(new CurveEditorView(model))
{
- QSplitter* splitter = new QSplitter;
+ QSplitter *splitter = new QSplitter;
splitter->addWidget(m_tree);
splitter->addWidget(m_view);
splitter->setSizes({5, 80});
- QHBoxLayout* box = new QHBoxLayout;
+ QHBoxLayout *box = new QHBoxLayout;
box->addWidget(splitter);
setLayout(box);
}
-CurveEditorView* CurveEditor::view() const
+CurveEditorView *CurveEditor::view() const
{
return m_view;
}
diff --git a/src/curveeditor/curveeditor.h b/src/curveeditor/curveeditor.h
index bfc0599..f5e1af8 100644
--- a/src/curveeditor/curveeditor.h
+++ b/src/curveeditor/curveeditor.h
@@ -29,8 +29,7 @@
class QTreeView;
-namespace DesignTools
-{
+namespace DesignTools {
class CurveEditorModel;
class CurveEditorView;
@@ -40,15 +39,14 @@ class CurveEditor : public QWidget
Q_OBJECT
public:
- CurveEditor(CurveEditorModel* model, QWidget* parent = nullptr);
+ CurveEditor(CurveEditorModel *model, QWidget *parent = nullptr);
- CurveEditorView* view() const;
+ CurveEditorView *view() const;
private:
- QTreeView* m_tree;
+ QTreeView *m_tree;
- CurveEditorView* m_view;
+ CurveEditorView *m_view;
};
} // End namespace DesignTools.
-
diff --git a/src/curveeditor/curveeditormodel.h b/src/curveeditor/curveeditormodel.h
index 35ac6f5..883d928 100644
--- a/src/curveeditor/curveeditormodel.h
+++ b/src/curveeditor/curveeditormodel.h
@@ -31,8 +31,7 @@
class QPointF;
-namespace DesignTools
-{
+namespace DesignTools {
class CurveEditorModel
{
@@ -45,7 +44,7 @@ public:
virtual double maximumValue() const = 0;
- virtual std::vector< QPointF > curve( int i ) const = 0;
+ virtual std::vector<QPointF> curve(int i) const = 0;
virtual CurveEditorStyle style() const { return CurveEditorStyle(); }
};
diff --git a/src/curveeditor/curveeditorstyle.cpp b/src/curveeditor/curveeditorstyle.cpp
index 16485e0..a055596 100644
--- a/src/curveeditor/curveeditorstyle.cpp
+++ b/src/curveeditor/curveeditorstyle.cpp
@@ -32,38 +32,36 @@
#include <QSpinBox>
#include <QVBoxLayout>
-namespace DesignTools
-{
+namespace DesignTools {
-QHBoxLayout* createRow(const QString& title, QWidget* widget)
+QHBoxLayout *createRow(const QString &title, QWidget *widget)
{
- auto*label = new QLabel(title);
+ auto *label = new QLabel(title);
label->setFixedWidth(200);
label->setAlignment(Qt::AlignRight);
- auto* box = new QHBoxLayout;
+ 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) )
+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);
@@ -77,8 +75,8 @@ CurveEditorStyleDialog::CurveEditorStyleDialog(CurveEditorStyle& style, QWidget*
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);
+ 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);
@@ -97,20 +95,20 @@ CurveEditorStyleDialog::CurveEditorStyleDialog(CurveEditorStyle& style, QWidget*
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) );
+ 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);
@@ -135,15 +133,15 @@ CurveEditorStyle CurveEditorStyleDialog::style() const
return style;
}
-void CurveEditorStyleDialog::emitStyleChanged( )
+void CurveEditorStyleDialog::emitStyleChanged()
{
emit styleChanged(style());
}
-void CurveEditorStyleDialog::printStyle( )
+void CurveEditorStyleDialog::printStyle()
{
- auto toString = [](const QColor& color) {
- QString tmp = QString("QColor(%1, %2, %3)").arg(color.red()).arg(color.green() ).arg(color.blue());
+ auto toString = [](const QColor &color) {
+ QString tmp = QString("QColor(%1, %2, %3)").arg(color.red()).arg(color.green()).arg(color.blue());
return qPrintable(tmp);
};
@@ -151,14 +149,15 @@ void CurveEditorStyleDialog::printStyle( )
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.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.abscissaHeight = " << s.abscissaHeight << ";";
qDebug().nospace() << "out.ordinateWidth = " << s.ordinateWidth << ";";
qDebug().nospace() << "out.canvasMargin = " << s.canvasMargin << ";";
qDebug().nospace() << "out.cellCountX = " << s.cellCountX << ";";
diff --git a/src/curveeditor/curveeditorstyle.h b/src/curveeditor/curveeditorstyle.h
index 0659055..81cb83c 100644
--- a/src/curveeditor/curveeditorstyle.h
+++ b/src/curveeditor/curveeditorstyle.h
@@ -33,8 +33,7 @@ class QPushButton;
class QSpinBox;
class QDoubleSpinBox;
-namespace DesignTools
-{
+namespace DesignTools {
class ColorControl;
@@ -44,10 +43,9 @@ struct CurveEditorStyle
QBrush backgroundAlternateBrush = QBrush(QColor(0, 0, 50));
-
QColor fontColor = QColor(200, 200, 200);
- QColor curveColor = QColor(128, 128,128);
+ QColor curveColor = QColor(128, 128, 128);
QColor gridColor = QColor(128, 128, 128);
@@ -55,8 +53,7 @@ struct CurveEditorStyle
QColor rangeBarCapsColor = QColor(50, 50, 255);
- QColor playheadColor = QColor(200,200,0);
-
+ QColor playheadColor = QColor(200, 200, 0);
double abscissaHeight = 40.0;
@@ -64,18 +61,15 @@ struct CurveEditorStyle
double canvasMargin = 5.0;
-
int zoomInWidth = 100;
int zoomInHeight = 100;
-
int cellCountX = 10;
int cellCountY = 10;
};
-
class CurveEditorView;
class CurveEditorStyleDialog : public QDialog
@@ -83,10 +77,10 @@ class CurveEditorStyleDialog : public QDialog
Q_OBJECT
signals:
- void styleChanged(const CurveEditorStyle& style);
+ void styleChanged(const CurveEditorStyle &style);
public:
- CurveEditorStyleDialog(CurveEditorStyle& style, QWidget* parent = nullptr);
+ CurveEditorStyleDialog(CurveEditorStyle &style, QWidget *parent = nullptr);
CurveEditorStyle style() const;
@@ -96,33 +90,33 @@ private:
void printStyle();
private:
- QPushButton* m_printButton;
+ QPushButton *m_printButton;
- QDoubleSpinBox* m_abscissa;
+ QDoubleSpinBox *m_abscissa;
- QDoubleSpinBox* m_ordinate;
+ QDoubleSpinBox *m_ordinate;
- QDoubleSpinBox* m_canvasMargin;
+ QDoubleSpinBox *m_canvasMargin;
- QSpinBox* m_cellCountX;
+ QSpinBox *m_cellCountX;
- QSpinBox* m_cellCountY;
+ QSpinBox *m_cellCountY;
- ColorControl* m_background;
+ ColorControl *m_background;
- ColorControl* m_backgroundAlternate;
+ ColorControl *m_backgroundAlternate;
- ColorControl* m_fontColor;
+ ColorControl *m_fontColor;
- ColorControl* m_curveColor;
+ ColorControl *m_curveColor;
- ColorControl* m_gridColor;
+ ColorControl *m_gridColor;
- ColorControl* m_rangeBarColor;
+ ColorControl *m_rangeBarColor;
- ColorControl* m_rangeBarCapsColor;
+ ColorControl *m_rangeBarCapsColor;
- ColorControl* m_playhead;
+ ColorControl *m_playhead;
};
} // End namespace DesignTools.
diff --git a/src/curveeditor/curveeditorview.cpp b/src/curveeditor/curveeditorview.cpp
index 2817f24..5aba268 100644
--- a/src/curveeditor/curveeditorview.cpp
+++ b/src/curveeditor/curveeditorview.cpp
@@ -26,16 +26,15 @@
#include "curveeditormodel.h"
#include "curveitem.h"
+#include <QAction>
#include <QDebug>
-#include <QResizeEvent>
#include <QMenu>
-#include <QAction>
+#include <QResizeEvent>
#include <QScrollBar>
#include <cmath>
-namespace DesignTools
-{
+namespace DesignTools {
double clamp(double val, double lo, double hi)
{
@@ -44,29 +43,27 @@ double clamp(double val, double lo, double hi)
double lerp(double blend, double a, double b)
{
- return (1.0-blend) * a + blend *b;
+ return (1.0 - blend) * a + blend * b;
}
-double scaleX(const QTransform& transform)
+double scaleX(const QTransform &transform)
{
return transform.m11();
}
-double scaleY(const QTransform& transform)
+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)
+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);
@@ -76,14 +73,14 @@ CurveEditorView::CurveEditorView(CurveEditorModel* model, QWidget* parent)
connect(&m_dialog, &CurveEditorStyleDialog::styleChanged, this, &CurveEditorView::setStyle);
- m_scene.addItem(new CurveItem( model->curve(0) ));
- m_scene.addItem(new CurveItem( model->curve(1) ));
+ 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)
+void CurveEditorView::setStyle(const CurveEditorStyle &style)
{
m_style = style;
updateSceneRect();
@@ -102,7 +99,7 @@ void CurveEditorView::zoomY(double zoom)
update();
}
-void CurveEditorView::resizeEvent(QResizeEvent* event)
+void CurveEditorView::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
@@ -115,10 +112,10 @@ void CurveEditorView::contextMenuEvent(QContextMenuEvent *event)
{
Q_UNUSED(event);
- auto openStyleEditor = [this](){ m_dialog.show(); };
+ auto openStyleEditor = [this]() { m_dialog.show(); };
QMenu menu;
- QAction* openEditorAction = menu.addAction(tr("Open Style Editor"));
+ QAction *openEditorAction = menu.addAction(tr("Open Style Editor"));
connect(openEditorAction, &QAction::triggered, openStyleEditor);
menu.exec(event->globalPos());
@@ -128,20 +125,16 @@ 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()));
+ 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));
+ 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)
+void CurveEditorView::drawBackground(QPainter *painter, const QRectF &rect)
{
painter->fillRect(rect, m_style.backgroundBrush);
painter->fillRect(scene()->sceneRect(), m_style.backgroundAlternateBrush);
@@ -163,12 +156,12 @@ int CurveEditorView::mapValueToY(double y)
double CurveEditorView::mapXtoTime(int x)
{
- return static_cast<double>(x)/scaleX(m_transform);
+ return static_cast<double>(x) / scaleX(m_transform);
}
double CurveEditorView::mapYtoValue(int y)
{
- return static_cast<double>(y)/scaleY(m_transform);
+ return static_cast<double>(y) / scaleY(m_transform);
}
void CurveEditorView::applyZoom(double x, double y)
@@ -176,12 +169,12 @@ 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 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 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);
@@ -189,14 +182,14 @@ void CurveEditorView::applyZoom(double x, double y)
m_transform = QTransform::fromScale(scaleX, scaleY);
QRectF sceneBounds;
- for (auto* item : items())
- if (auto* curveItem = qgraphicsitem_cast< CurveItem* >(item))
+ 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)
+void CurveEditorView::updateSceneRect(const QRectF &rect)
{
if (rect.isValid())
scene()->setSceneRect(rect);
@@ -210,7 +203,7 @@ void CurveEditorView::updateSceneRect(const QRectF& rect)
setSceneRect(sr);
}
-void CurveEditorView::drawGrid(QPainter* painter, const QRectF &rect)
+void CurveEditorView::drawGrid(QPainter *painter, const QRectF &rect)
{
painter->save();
painter->setPen(m_style.gridColor);
@@ -221,44 +214,44 @@ void CurveEditorView::drawGrid(QPainter* painter, const QRectF &rect)
-m_style.canvasMargin,
-m_style.canvasMargin);
- auto drawVerticalLine = [painter, gridRect]( double position ) {
+ 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)
+ 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)
+void CurveEditorView::drawExtremaX(QPainter *painter, const QRectF &rect)
{
- auto drawVerticalLine = [rect, painter]( double position ) {
+ 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()) );
+ drawVerticalLine(mapTimetoX(m_model->minimumTime()));
+ drawVerticalLine(mapTimetoX(m_model->maximumTime()));
painter->restore();
}
-void CurveEditorView::drawExtremaY(QPainter* painter, const QRectF& rect)
+void CurveEditorView::drawExtremaY(QPainter *painter, const QRectF &rect)
{
- auto drawHorizontalLine = [rect, painter]( double position ) {
+ 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()) );
+ drawHorizontalLine(mapValueToY(m_model->minimumValue()));
+ drawHorizontalLine(mapValueToY(m_model->maximumValue()));
painter->restore();
}
-void CurveEditorView::drawTimeScale(QPainter* painter, const QRectF &rect)
+void CurveEditorView::drawTimeScale(QPainter *painter, const QRectF &rect)
{
painter->save();
painter->setPen(m_style.fontColor);
@@ -266,38 +259,38 @@ void CurveEditorView::drawTimeScale(QPainter* painter, const QRectF &rect)
QFontMetrics fm(painter->font());
- auto paintLabeledTick = [this, painter, rect, fm]( double time ) {
+ 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()) );
+ 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)
+ for (double i = m_model->minimumTime(); i <= m_model->maximumTime(); i += timeIncrement)
paintLabeledTick(i);
painter->restore();
}
-void CurveEditorView::drawValueScale(QPainter* painter, const QRectF &rect)
+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 ) {
+ 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) );
+ textRect.moveCenter(QPoint(rect.center().x(), position));
painter->drawText(textRect, Qt::AlignCenter, valueText);
};
@@ -306,7 +299,7 @@ void CurveEditorView::drawValueScale(QPainter* painter, const QRectF &rect)
painter->restore();
}
-double CurveEditorView::timeLabelInterval(QPainter* painter, double maxTime)
+double CurveEditorView::timeLabelInterval(QPainter *painter, double maxTime)
{
QFontMetrics fm(painter->font());
int minTextSpacing = fm.width(QString("X%1X").arg(maxTime));
@@ -315,8 +308,7 @@ double CurveEditorView::timeLabelInterval(QPainter* painter, double maxTime)
int nextFactor = 5;
double tickDistance = mapTimetoX(deltaTime);
- while (true)
- {
+ while (true) {
if (tickDistance > minTextSpacing)
break;
diff --git a/src/curveeditor/curveeditorview.h b/src/curveeditor/curveeditorview.h
index fde7b95..91a7023 100644
--- a/src/curveeditor/curveeditorview.h
+++ b/src/curveeditor/curveeditorview.h
@@ -27,11 +27,10 @@
#include "curveeditorstyle.h"
-#include <QGraphicsView>
#include <QGraphicsScene>
+#include <QGraphicsView>
-namespace DesignTools
-{
+namespace DesignTools {
class CurveEditorModel;
@@ -40,16 +39,16 @@ class CurveEditorView : public QGraphicsView
Q_OBJECT
public:
- CurveEditorView(CurveEditorModel* model, QWidget* parent = nullptr);
+ CurveEditorView(CurveEditorModel *model, QWidget *parent = nullptr);
- void setStyle(const CurveEditorStyle& style);
+ void setStyle(const CurveEditorStyle &style);
void zoomX(double zoom);
void zoomY(double zoom);
protected:
- void resizeEvent(QResizeEvent* event) override;
+ void resizeEvent(QResizeEvent *event) override;
void contextMenuEvent(QContextMenuEvent *event) override;
@@ -66,32 +65,28 @@ private:
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 updateSceneRect(const QRectF &rect = QRectF());
- void drawExtremaY(QPainter* painter, const QRectF& rect);
+ void drawGrid(QPainter *painter, const QRectF &rect);
+ void drawExtremaX(QPainter *painter, const QRectF &rect);
- void drawTimeScale(QPainter* painter, const QRectF &rect);
+ void drawExtremaY(QPainter *painter, const QRectF &rect);
- void drawValueScale(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);
+ double timeLabelInterval(QPainter *painter, double maxTime);
private:
QGraphicsScene m_scene;
CurveEditorStyle m_style;
- CurveEditorModel* m_model;
+ CurveEditorModel *m_model;
CurveEditorStyleDialog m_dialog;
diff --git a/src/curveeditor/curveitem.cpp b/src/curveeditor/curveitem.cpp
index ded3bc4..1514081 100644
--- a/src/curveeditor/curveitem.cpp
+++ b/src/curveeditor/curveitem.cpp
@@ -27,33 +27,29 @@
#include <QPainter>
#include <QPainterPath>
-namespace DesignTools
-{
-
-CurveItem::CurveItem(QGraphicsItem* parent)
- :
- QGraphicsObject(parent),
- m_points( { QPointF(0.0, 0.0), QPointF(1.1, 1.1) } )
-{ }
+namespace DesignTools {
-CurveItem::CurveItem(const std::vector<QPointF>& points, QGraphicsItem* parent)
- :
- QGraphicsObject(parent),
- m_points(points)
-{ }
+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* )
+void CurveItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
painter->drawPath(path());
}
-QRectF CurveItem::zoom(const QTransform& transform)
+QRectF CurveItem::zoom(const QTransform &transform)
{
prepareGeometryChange();
m_transform = transform;
@@ -66,7 +62,7 @@ QPainterPath CurveItem::path() const
return QPainterPath();
auto out = QPainterPath(m_points.front());
- for (size_t i=1; i<m_points.size(); ++i)
+ for (size_t i = 1; i < m_points.size(); ++i)
out.lineTo(m_transform.map(m_points[i]));
return out;
diff --git a/src/curveeditor/curveitem.h b/src/curveeditor/curveitem.h
index a16ba69..6bfc177 100644
--- a/src/curveeditor/curveitem.h
+++ b/src/curveeditor/curveitem.h
@@ -29,23 +29,22 @@
class QPainterPath;
-namespace DesignTools
-{
+namespace DesignTools {
class CurveItem : public QGraphicsObject
{
Q_OBJECT
public:
- CurveItem(QGraphicsItem* parent = nullptr);
+ CurveItem(QGraphicsItem *parent = nullptr);
- CurveItem(const std::vector<QPointF>& points, 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;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
- QRectF zoom(const QTransform& transform);
+ QRectF zoom(const QTransform &transform);
private:
QPainterPath path() const;
@@ -53,7 +52,7 @@ private:
private:
QTransform m_transform;
- std::vector< QPointF > m_points;
+ std::vector<QPointF> m_points;
};
} // End namespace DesignTools.