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:
61
src/FeatureBrowser.cpp
Normal file
61
src/FeatureBrowser.cpp
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#include "FeatureBrowser.h"
|
||||||
|
#include "Document.h"
|
||||||
|
#include "Feature.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <QFont>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
FeatureBrowser::FeatureBrowser()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void FeatureBrowser::setDocument(Document* document)
|
||||||
|
{
|
||||||
|
m_document = document;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FeatureBrowser::paint(QPainter& painter, int viewportWidth, int viewportHeight)
|
||||||
|
{
|
||||||
|
if (!m_document) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
painter.setFont(QFont("Arial", 12));
|
||||||
|
|
||||||
|
const int padding = 5;
|
||||||
|
const int margin = 10;
|
||||||
|
int x = margin;
|
||||||
|
int y = 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;
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
19
src/FeatureBrowser.h
Normal file
19
src/FeatureBrowser.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef FEATUREBROWSER_H
|
||||||
|
#define FEATUREBROWSER_H
|
||||||
|
|
||||||
|
class QPainter;
|
||||||
|
class Document;
|
||||||
|
|
||||||
|
class FeatureBrowser
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FeatureBrowser();
|
||||||
|
|
||||||
|
void setDocument(Document* document);
|
||||||
|
void paint(QPainter& painter, int viewportWidth, int viewportHeight);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Document* m_document = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FEATUREBROWSER_H
|
||||||
@@ -2,8 +2,7 @@
|
|||||||
#include "ViewCube.h"
|
#include "ViewCube.h"
|
||||||
#include "SketchGrid.h"
|
#include "SketchGrid.h"
|
||||||
#include "Document.h"
|
#include "Document.h"
|
||||||
#include "Feature.h"
|
#include "FeatureBrowser.h"
|
||||||
#include <algorithm>
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
@@ -16,17 +15,19 @@ ViewportWidget::ViewportWidget(QWidget *parent)
|
|||||||
{
|
{
|
||||||
m_viewCube = new ViewCube();
|
m_viewCube = new ViewCube();
|
||||||
m_sketchGrid = new SketchGrid();
|
m_sketchGrid = new SketchGrid();
|
||||||
|
m_featureBrowser = new FeatureBrowser();
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewportWidget::~ViewportWidget()
|
ViewportWidget::~ViewportWidget()
|
||||||
{
|
{
|
||||||
delete m_viewCube;
|
delete m_viewCube;
|
||||||
delete m_sketchGrid;
|
delete m_sketchGrid;
|
||||||
|
delete m_featureBrowser;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewportWidget::setDocument(Document* document)
|
void ViewportWidget::setDocument(Document* document)
|
||||||
{
|
{
|
||||||
m_document = document;
|
m_featureBrowser->setDocument(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewportWidget::initializeGL()
|
void ViewportWidget::initializeGL()
|
||||||
@@ -73,7 +74,7 @@ void ViewportWidget::paintGL()
|
|||||||
if (m_currentPlane != SketchPlane::NONE) {
|
if (m_currentPlane != SketchPlane::NONE) {
|
||||||
drawAxisLabels(painter, model, projection);
|
drawAxisLabels(painter, model, projection);
|
||||||
}
|
}
|
||||||
drawFeatureBrowser(painter);
|
m_featureBrowser->paint(painter, width(), height());
|
||||||
painter.end();
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
class ViewCube;
|
class ViewCube;
|
||||||
class SketchGrid;
|
class SketchGrid;
|
||||||
class Document;
|
class Document;
|
||||||
class Feature;
|
class FeatureBrowser;
|
||||||
|
|
||||||
class ViewportWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
class ViewportWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
||||||
{
|
{
|
||||||
@@ -43,12 +43,11 @@ protected:
|
|||||||
private:
|
private:
|
||||||
QVector3D project(const QVector3D& worldCoord, const QMatrix4x4& modelView, const QMatrix4x4& projection, const QRect& viewport);
|
QVector3D project(const QVector3D& worldCoord, const QMatrix4x4& modelView, const QMatrix4x4& projection, const QRect& viewport);
|
||||||
void drawAxisLabels(QPainter& painter, const QMatrix4x4& modelView, const QMatrix4x4& projection);
|
void drawAxisLabels(QPainter& painter, const QMatrix4x4& modelView, const QMatrix4x4& projection);
|
||||||
void drawFeatureBrowser(QPainter& painter);
|
|
||||||
|
|
||||||
QMatrix4x4 projection;
|
QMatrix4x4 projection;
|
||||||
ViewCube* m_viewCube;
|
ViewCube* m_viewCube;
|
||||||
SketchGrid* m_sketchGrid = nullptr;
|
SketchGrid* m_sketchGrid = nullptr;
|
||||||
Document* m_document = nullptr;
|
FeatureBrowser* m_featureBrowser = nullptr;
|
||||||
SketchPlane m_currentPlane = SketchPlane::NONE;
|
SketchPlane m_currentPlane = SketchPlane::NONE;
|
||||||
|
|
||||||
float xRot = 0;
|
float xRot = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user