#include "FeatureBrowser.h" #include "Document.h" #include "Feature.h" #include #include #include 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& 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; } }