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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user