refactor: Move axis label drawing logic from ViewportWidget to SketchGrid
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -46,7 +46,7 @@ ViewportWidget::ViewportWidget(QWidget *parent)
|
||||
connect(m_camera, &Camera::cameraChanged, this, QOverload<>::of(&QWidget::update));
|
||||
connect(m_camera, &Camera::restoreStateAnimationFinished, this, &ViewportWidget::onRestoreStateAnimationFinished);
|
||||
m_viewCube = new ViewCube();
|
||||
m_sketchGrid = new SketchGrid();
|
||||
m_sketchGrid = new SketchGrid(this);
|
||||
m_featureBrowser = new FeatureBrowser();
|
||||
setMouseTracking(true);
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
@@ -171,7 +171,7 @@ void ViewportWidget::paintGL()
|
||||
|
||||
QPainter painter(this);
|
||||
if (m_currentPlane != SketchPlane::NONE) {
|
||||
drawAxisLabels(painter, model, projection);
|
||||
m_sketchGrid->paintAxisLabels(painter, static_cast<SketchGrid::SketchPlane>(m_currentPlane), model, projection);
|
||||
}
|
||||
m_featureBrowser->paint(painter, width(), height());
|
||||
|
||||
@@ -353,39 +353,6 @@ QVector3D ViewportWidget::project(const QVector3D& worldCoord, const QMatrix4x4&
|
||||
return QVector3D(winX, winY, (ndc.z() + 1.0) / 2.0);
|
||||
}
|
||||
|
||||
void ViewportWidget::drawAxisLabels(QPainter& painter, const QMatrix4x4& modelView, const QMatrix4x4& projection)
|
||||
{
|
||||
painter.setPen(Qt::white);
|
||||
painter.setFont(QFont("Arial", 10));
|
||||
|
||||
const int range = 50;
|
||||
const int step = 5;
|
||||
|
||||
auto drawLabelsForAxis = [&](int axis_idx) {
|
||||
for (int i = -range; i <= range; i += step) {
|
||||
if (i == 0) continue;
|
||||
QVector3D worldCoord;
|
||||
worldCoord[axis_idx] = i;
|
||||
|
||||
QVector3D screenPos = project(worldCoord, modelView, projection, rect());
|
||||
if (screenPos.z() < 1.0f) { // Not clipped
|
||||
painter.drawText(screenPos.toPoint(), QString::number(i));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (m_currentPlane == SketchPlane::XY) {
|
||||
drawLabelsForAxis(0); // X
|
||||
drawLabelsForAxis(2); // Y
|
||||
} else if (m_currentPlane == SketchPlane::XZ) {
|
||||
drawLabelsForAxis(0); // X
|
||||
drawLabelsForAxis(1); // Z
|
||||
} else if (m_currentPlane == SketchPlane::YZ) {
|
||||
drawLabelsForAxis(1); // Y
|
||||
drawLabelsForAxis(2); // Z
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportWidget::onActiveToolChanged(int tool)
|
||||
{
|
||||
if (m_activeSketchTool) {
|
||||
|
||||
Reference in New Issue
Block a user