-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 413b10c
Showing
320 changed files
with
432,139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.user |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#ifndef CONTROLLER_H | ||
#define CONTROLLER_H | ||
|
||
#include "CurveContainer.h" | ||
#include "CustomVariant.h" | ||
#include "Transformer.h" | ||
#include "Types.h" | ||
#include "Window.h" | ||
|
||
#include <Curves/Curve.h> | ||
#include <Renderers/RendererManager.h> | ||
|
||
#include <QFileDialog> | ||
#include <QObject> | ||
#include <QVariant> | ||
|
||
class Controller : public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit Controller(QObject *parent = nullptr); | ||
|
||
public slots: | ||
void onAction(Action action, CustomVariant value = CustomVariant()); | ||
void init(); | ||
|
||
private slots: | ||
void onWheelMoved(QWheelEvent *event); | ||
void onMousePressed(QMouseEvent *event); | ||
void onMouseReleased(QMouseEvent *event); | ||
void onMouseMoved(QMouseEvent *event); | ||
|
||
bool cursorInsideBoundingBox(QPointF position, QMarginsF margins = QMarginsF(-20, -20, 20, 20)); | ||
void zoom(float newZoomRatio, CustomVariant cursorPositionVariant = CustomVariant()); | ||
|
||
private: | ||
Window *mWindow; | ||
CurveContainer *mCurveContainer; | ||
Transformer *mTransformer; | ||
RendererManager *mRendererManager; | ||
|
||
ProjectionParameters *mProjectionParameters; | ||
|
||
Mode mModeBeforeKeyPress; | ||
Mode mModeBeforeMousePress; | ||
Mode mMode; | ||
|
||
bool mMouseLeftButtonPressed; | ||
bool mMouseMiddleButtonPressed; | ||
bool mMouseRightButtonPressed; | ||
bool mMousePressedOnCurve; | ||
QPointF mMousePosition; | ||
|
||
float mZoomStep; | ||
|
||
Qt::Key mPressedKey; | ||
|
||
QFileDialog *mFileDialog; | ||
Action mLastFileAction; | ||
}; | ||
|
||
#endif // CONTROLLER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
#include "CurveContainer.h" | ||
|
||
CurveContainer::CurveContainer(QObject *parent) | ||
: QObject(parent) | ||
, mSelectedCurve(nullptr) | ||
, mSelectedControlPoint(nullptr) | ||
, mSelectedColorPoint(nullptr) | ||
{} | ||
|
||
CurveContainer::~CurveContainer() | ||
{ | ||
for (auto &curve : mCurves) { | ||
if (curve) | ||
curve->deleteLater(); | ||
|
||
curve = nullptr; | ||
} | ||
} | ||
|
||
void CurveContainer::addCurve(Curve *curve) | ||
{ | ||
mCurves << curve; | ||
sortCurves(); | ||
} | ||
|
||
void CurveContainer::addCurves(const QVector<Curve *> curves) | ||
{ | ||
mCurves << curves; | ||
sortCurves(); | ||
} | ||
|
||
QVector<Curve *> &CurveContainer::getCurves() const | ||
{ | ||
return mCurves; | ||
} | ||
|
||
ControlPoint *CurveContainer::getClosestControlPointOnSelectedCurve(const QVector2D &nearbyPoint, float radius) const | ||
{ | ||
if (!mSelectedCurve) | ||
return nullptr; | ||
|
||
ControlPoint *controlPoint = const_cast<ControlPoint *>(mSelectedCurve->getClosestControlPoint(nearbyPoint)); | ||
|
||
if (controlPoint) { | ||
if (controlPoint->position().distanceToPoint(nearbyPoint) > radius) | ||
controlPoint = nullptr; | ||
} | ||
|
||
return controlPoint; | ||
} | ||
|
||
ColorPoint *CurveContainer::getClosestColorPointOnSelectedCurve(const QVector2D &nearbyPoint, float radius) const | ||
{ | ||
if (!mSelectedCurve) | ||
return nullptr; | ||
|
||
ColorPoint *colorPoint = const_cast<ColorPoint *>(mSelectedCurve->getClosestColorPoint(nearbyPoint)); | ||
|
||
if (colorPoint) { | ||
if (colorPoint->getPosition2D().distanceToPoint(nearbyPoint) > radius) | ||
colorPoint = nullptr; | ||
} | ||
|
||
return colorPoint; | ||
} | ||
|
||
Curve *CurveContainer::selectedCurve() | ||
{ | ||
return mSelectedCurve; | ||
} | ||
|
||
ControlPoint *CurveContainer::selectedControlPoint() | ||
{ | ||
return mSelectedControlPoint; | ||
} | ||
|
||
void CurveContainer::removeCurve(int index) | ||
{ | ||
if (0 <= index && index < mCurves.size()) { | ||
Curve *curve = mCurves[index]; | ||
mCurves.removeAt(index); | ||
curve->deleteLater(); | ||
sortCurves(); | ||
} | ||
} | ||
|
||
void CurveContainer::removeCurve(Curve *curve) | ||
{ | ||
for (int i = 0; i < mCurves.size(); ++i) { | ||
if (mCurves[i] == curve) { | ||
removeCurve(i); | ||
sortCurves(); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
Curve *CurveContainer::selectCurve(const QVector2D &position, float radius) | ||
{ | ||
float minDistance = std::numeric_limits<float>::infinity(); | ||
|
||
Curve *selectedCurve = nullptr; | ||
|
||
for (int i = 0; i < mCurves.size(); ++i) { | ||
float distance = mCurves[i]->distanceToPoint(position); | ||
if (distance < minDistance) { | ||
minDistance = distance; | ||
selectedCurve = mCurves[i]; | ||
} | ||
} | ||
|
||
if (minDistance < radius) | ||
return selectedCurve; | ||
|
||
return nullptr; | ||
} | ||
|
||
Curve *CurveContainer::selectCurve(const QPointF &position, float radius) | ||
{ | ||
return selectCurve(QVector2D(position.x(), position.y()), radius); | ||
} | ||
|
||
void CurveContainer::deselectAllCurves() | ||
{ | ||
for (int i = 0; i < mCurves.size(); ++i) | ||
mCurves[i]->setSelected(false); | ||
|
||
mSelectedCurve = nullptr; | ||
} | ||
|
||
void CurveContainer::setSelectedCurve(Curve *selectedCurve) | ||
{ | ||
if (mSelectedCurve == selectedCurve) | ||
return; | ||
|
||
if (mSelectedCurve) | ||
mSelectedCurve->setSelected(false); | ||
|
||
if (selectedCurve) | ||
selectedCurve->setSelected(true); | ||
|
||
mSelectedCurve = selectedCurve; | ||
emit selectedCurveChanged(selectedCurve); | ||
} | ||
|
||
void CurveContainer::setSelectedControlPoint(ControlPoint *selectedControlPoint) | ||
{ | ||
if (mSelectedControlPoint == selectedControlPoint) | ||
return; | ||
|
||
if (mSelectedControlPoint) | ||
mSelectedControlPoint->setSelected(false); | ||
|
||
if (selectedControlPoint) | ||
selectedControlPoint->setSelected(true); | ||
|
||
mSelectedControlPoint = selectedControlPoint; | ||
emit selectedControlPointChanged(selectedControlPoint); | ||
} | ||
|
||
void CurveContainer::sortCurves() | ||
{ | ||
if (mCurves.size() == 0 || mCurves.size() == 1) | ||
return; | ||
|
||
QVector<Curve *> sortedCurves; | ||
|
||
sortedCurves << mCurves[0]; | ||
|
||
for (int i = 1; i < mCurves.size(); i++) { | ||
Curve *curve = mCurves[i]; | ||
if (sortedCurves.last()->z() <= curve->z()) | ||
sortedCurves << curve; | ||
else | ||
for (int j = 0; j < sortedCurves.size(); j++) | ||
if (sortedCurves[j]->z() > curve->z()) { | ||
sortedCurves.insert(j, curve); | ||
break; | ||
} | ||
} | ||
|
||
mCurves = sortedCurves; | ||
} | ||
|
||
void CurveContainer::clear() | ||
{ | ||
for (auto &curve : mCurves) { | ||
if (curve) | ||
curve->deleteLater(); | ||
|
||
curve = nullptr; | ||
} | ||
|
||
mCurves.clear(); | ||
} | ||
|
||
ColorPoint *CurveContainer::selectedColorPoint() const | ||
{ | ||
return mSelectedColorPoint; | ||
} | ||
|
||
void CurveContainer::setSelectedColorPoint(ColorPoint *newSelectedColorPoint) | ||
{ | ||
if (mSelectedColorPoint == newSelectedColorPoint) | ||
return; | ||
|
||
if (mSelectedColorPoint) | ||
mSelectedColorPoint->setSelected(false); | ||
|
||
if (newSelectedColorPoint) | ||
newSelectedColorPoint->setSelected(true); | ||
|
||
mSelectedColorPoint = newSelectedColorPoint; | ||
emit selectedColorPointChanged(newSelectedColorPoint); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#ifndef CURVECONTAINER_H | ||
#define CURVECONTAINER_H | ||
|
||
#include <Curves/Curve.h> | ||
|
||
class CurveContainer : public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit CurveContainer(QObject *parent = nullptr); | ||
~CurveContainer(); | ||
|
||
void addCurve(Curve *curve); | ||
void addCurves(const QVector<Curve *> curves); | ||
|
||
QVector<Curve *> &getCurves() const; | ||
|
||
Curve *selectedCurve(); | ||
void setSelectedCurve(Curve *selectedCurve); | ||
|
||
ControlPoint *selectedControlPoint(); | ||
void setSelectedControlPoint(ControlPoint *selectedControlPoint); | ||
|
||
void removeCurve(int index); | ||
void removeCurve(Curve *curve); | ||
|
||
void deselectAllCurves(); | ||
|
||
Curve *selectCurve(const QVector2D &position, float radius = 20.0f); | ||
Curve *selectCurve(const QPointF &position, float radius = 20.0f); | ||
|
||
ControlPoint *getClosestControlPointOnSelectedCurve(const QVector2D &nearbyPoint, float radius = 20.0f) const; | ||
ColorPoint *getClosestColorPointOnSelectedCurve(const QVector2D &nearbyPoint, float radius = 20.0f) const; | ||
|
||
ColorPoint *selectedColorPoint() const; | ||
void setSelectedColorPoint(ColorPoint *newSelectedColorPoint); | ||
|
||
public slots: | ||
void sortCurves(); | ||
void clear(); | ||
|
||
signals: | ||
void selectedCurveChanged(Curve *selectedCurve); | ||
void selectedControlPointChanged(ControlPoint *selectedControlPoint); | ||
void selectedColorPointChanged(ColorPoint *selectedColorPoint); | ||
|
||
private: | ||
mutable QVector<Curve *> mCurves; | ||
Curve *mSelectedCurve; | ||
ControlPoint *mSelectedControlPoint; | ||
ColorPoint *mSelectedColorPoint; | ||
}; | ||
|
||
#endif // CURVECONTAINER_H |
Oops, something went wrong.