refactor: Refactor feature browser, move to top-left, and increase font size

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2026-02-09 17:36:45 -07:00
parent c6f82a04e8
commit 6e335ef724
4 changed files with 87 additions and 53 deletions

View File

@@ -2,8 +2,7 @@
#include "ViewCube.h"
#include "SketchGrid.h"
#include "Document.h"
#include "Feature.h"
#include <algorithm>
#include "FeatureBrowser.h"
#include <QMouseEvent>
#include <QWheelEvent>
#include <QApplication>
@@ -16,17 +15,19 @@ ViewportWidget::ViewportWidget(QWidget *parent)
{
m_viewCube = new ViewCube();
m_sketchGrid = new SketchGrid();
m_featureBrowser = new FeatureBrowser();
}
ViewportWidget::~ViewportWidget()
{
delete m_viewCube;
delete m_sketchGrid;
delete m_featureBrowser;
}
void ViewportWidget::setDocument(Document* document)
{
m_document = document;
m_featureBrowser->setDocument(document);
}
void ViewportWidget::initializeGL()
@@ -73,7 +74,7 @@ void ViewportWidget::paintGL()
if (m_currentPlane != SketchPlane::NONE) {
drawAxisLabels(painter, model, projection);
}
drawFeatureBrowser(painter);
m_featureBrowser->paint(painter, width(), height());
painter.end();
}
@@ -191,49 +192,3 @@ void ViewportWidget::drawAxisLabels(QPainter& painter, const QMatrix4x4& modelVi
}
}
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;
}
}