feat: Implement floating feature browser in viewport with transparent background

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2026-02-09 17:33:01 -07:00
parent f8386938cb
commit c6f82a04e8
6 changed files with 92 additions and 40 deletions

View File

@@ -1,6 +1,9 @@
#include "ViewportWidget.h"
#include "ViewCube.h"
#include "SketchGrid.h"
#include "Document.h"
#include "Feature.h"
#include <algorithm>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QApplication>
@@ -21,6 +24,11 @@ ViewportWidget::~ViewportWidget()
delete m_sketchGrid;
}
void ViewportWidget::setDocument(Document* document)
{
m_document = document;
}
void ViewportWidget::initializeGL()
{
initializeOpenGLFunctions();
@@ -61,11 +69,12 @@ void ViewportWidget::paintGL()
glViewport(0, 0, width(), height());
QPainter painter(this);
if (m_currentPlane != SketchPlane::NONE) {
QPainter painter(this);
drawAxisLabels(painter, model, projection);
painter.end();
}
drawFeatureBrowser(painter);
painter.end();
}
void ViewportWidget::resizeGL(int w, int h)
@@ -181,3 +190,50 @@ void ViewportWidget::drawAxisLabels(QPainter& painter, const QMatrix4x4& modelVi
drawLabelsForAxis(2); // Z
}
}
void ViewportWidget::drawFeatureBrowser(QPainter& painter)
{
if (!m_document) {
return;
}
painter.setRenderHint(QPainter::Antialiasing);
painter.setFont(QFont("Arial", 10));
const int padding = 5;
const int margin = 10;
int x = margin;
int y = height() - margin;
int lineHeight = painter.fontMetrics().height();
const QList<Feature*>& features = m_document->features();
QString docName = m_document->fileName();
int maxWidth = painter.fontMetrics().horizontalAdvance(docName);
for (const Feature* feature : features) {
maxWidth = std::max(maxWidth, painter.fontMetrics().horizontalAdvance(" " + feature->name()));
}
int boxWidth = maxWidth + 2 * padding;
int boxHeight = (features.size() + 1) * lineHeight + 2 * padding;
y -= boxHeight; // Adjust y to be the top of the box
// Draw transparent background
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(50, 50, 50, 150));
painter.drawRoundedRect(x, y, boxWidth, boxHeight, 3, 3);
// Draw text
painter.setPen(Qt::white);
int currentY = y + padding + lineHeight;
int textX = x + padding;
painter.drawText(textX, currentY, docName);
currentY += lineHeight;
for (const Feature* feature : features) {
painter.drawText(textX + 10, currentY, feature->name());
currentY += lineHeight;
}
}