forked from qt-creator/qt-creator
QmlDesigner: Tie 3D helper grid to snap interval
Helper grid minimum step now changes to match set snap interval. Fixes: QDS-10624 Change-Id: I82b8206774b3769bee19be5eb0f38930f3b49c12 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -13,9 +13,8 @@ Node {
|
||||
property bool orthoMode: false
|
||||
property double distance: 500
|
||||
|
||||
readonly property int minGridStep: 50
|
||||
readonly property int maxGridStep: 32 * minGridStep
|
||||
readonly property int gridArea: minGridStep * 512
|
||||
readonly property int maxGridStep: 32 * _generalHelper.minGridStep
|
||||
readonly property int gridArea: _generalHelper.minGridStep * 512
|
||||
|
||||
// Step of the main lines of the grid, between those is always one subdiv line
|
||||
property int gridStep: 100
|
||||
@@ -32,12 +31,13 @@ Node {
|
||||
return Math.atan(step / distance)
|
||||
}
|
||||
|
||||
onDistanceChanged: {
|
||||
function calcStep()
|
||||
{
|
||||
if (distance === 0)
|
||||
return
|
||||
|
||||
// Calculate new grid step
|
||||
let newStep = gridStep
|
||||
let newStep = _generalHelper.minGridStep
|
||||
let gridRad = calcRad(newStep)
|
||||
while (gridRad < minGridRad && newStep < maxGridStep) {
|
||||
newStep *= 2
|
||||
@@ -45,16 +45,13 @@ Node {
|
||||
newStep = maxGridStep
|
||||
gridRad = calcRad(newStep)
|
||||
}
|
||||
while (gridRad > minGridRad * 2 && newStep > minGridStep) {
|
||||
newStep /= 2
|
||||
if (newStep < minGridStep)
|
||||
newStep = minGridStep
|
||||
gridRad = calcRad(newStep)
|
||||
}
|
||||
gridStep = newStep
|
||||
subGridMaterial.generalAlpha = Math.min(1, 2 * (1 - (minGridRad / gridRad)))
|
||||
}
|
||||
|
||||
onMaxGridStepChanged: calcStep()
|
||||
onDistanceChanged: calcStep()
|
||||
|
||||
// Note: Only one instance of HelperGrid is supported, as the geometry names are fixed
|
||||
|
||||
Model { // Main grid lines
|
||||
|
@@ -14,6 +14,11 @@ void MAIN()
|
||||
float cosAngle = dot(normalize(camDir), normalize(camLevel));
|
||||
float angleDepth = density * pow(cosAngle, 8);
|
||||
float alpha = generalAlpha * clamp((1.0 - ((angleDepth * depth - alphaStartDepth) / (alphaEndDepth - alphaStartDepth))), 0, 1);
|
||||
|
||||
// Force additional alpha when approaching the far clip of edit camera
|
||||
if (depth > 90000.0)
|
||||
alpha *= clamp((100000.0 - depth) / 10000.0, 0, 1);
|
||||
|
||||
if (alpha > 0.01)
|
||||
FRAGCOLOR = vec4(color.x * alpha, color.y * alpha, color.z * alpha, alpha);
|
||||
else
|
||||
|
@@ -954,6 +954,20 @@ QVector3D GeneralHelper::adjustScaleForSnap(const QVector3D &newScale)
|
||||
return adjScale;
|
||||
}
|
||||
|
||||
void GeneralHelper::setSnapPositionInterval(double interval)
|
||||
{
|
||||
if (m_snapPositionInterval != interval) {
|
||||
m_snapPositionInterval = interval;
|
||||
emit minGridStepChanged();
|
||||
}
|
||||
}
|
||||
|
||||
double GeneralHelper::minGridStep() const
|
||||
{
|
||||
// Minimum grid step is a multiple of snap interval, as the last step is divided to subgrid
|
||||
return 2. * m_snapPositionInterval;
|
||||
}
|
||||
|
||||
void GeneralHelper::setBgColor(const QVariant &colors)
|
||||
{
|
||||
if (m_bgColor != colors) {
|
||||
|
@@ -33,6 +33,7 @@ class GeneralHelper : public QObject
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool isMacOS READ isMacOS CONSTANT)
|
||||
Q_PROPERTY(QVariant bgColor READ bgColor NOTIFY bgColorChanged FINAL)
|
||||
Q_PROPERTY(double minGridStep READ minGridStep NOTIFY minGridStepChanged FINAL)
|
||||
|
||||
public:
|
||||
GeneralHelper();
|
||||
@@ -114,10 +115,12 @@ public:
|
||||
void setSnapPosition(bool enable) { m_snapPosition = enable; }
|
||||
void setSnapRotation(bool enable) { m_snapRotation = enable; }
|
||||
void setSnapScale(bool enable) { m_snapScale = enable; }
|
||||
void setSnapPositionInterval(double interval) { m_snapPositionInterval = interval; }
|
||||
void setSnapPositionInterval(double interval);
|
||||
void setSnapRotationInterval(double interval) { m_snapRotationInterval = interval; }
|
||||
void setSnapScaleInterval(double interval) { m_snapScaleInterval = interval / 100.; }
|
||||
|
||||
double minGridStep() const;
|
||||
|
||||
void setBgColor(const QVariant &colors);
|
||||
QVariant bgColor() const { return m_bgColor; }
|
||||
|
||||
@@ -128,6 +131,8 @@ signals:
|
||||
void lockedStateChanged(QQuick3DNode *node);
|
||||
void rotationBlocksChanged();
|
||||
void bgColorChanged();
|
||||
void minGridStepChanged();
|
||||
|
||||
private:
|
||||
void handlePendingToolStateUpdate();
|
||||
QVector3D pivotScenePosition(QQuick3DNode *node) const;
|
||||
|
Reference in New Issue
Block a user