EnergySpectrumAnalyer/src/EnergyCountPeakFitView/PlotRectItem.cpp

43 lines
1.1 KiB
C++
Raw Normal View History

2026-04-15 18:17:16 +08:00
#include "PlotRectItem.h"
#include <QPainter>
#include <QwtScaleMap>
PlotRectItem::PlotRectItem(const QString &title)
: QwtPlotItem() {
setTitle(title);
setZ(1000);
m_pen = QPen(Qt::red, 2, Qt::SolidLine);
m_brush = QBrush(QColor(255, 0, 0, 30));
}
void PlotRectItem::setRect(const QRectF &rect) {
m_rect = rect;
}
void PlotRectItem::setPen(const QPen &pen) {
m_pen = pen;
}
void PlotRectItem::setBrush(const QBrush &brush) {
m_brush = brush;
}
void PlotRectItem::draw(QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &) const {
const int x1 = xMap.transform(m_rect.left());
const int x2 = xMap.transform(m_rect.right());
const int y1 = yMap.transform(m_rect.top());
const int y2 = yMap.transform(m_rect.bottom());
const QRect rect(QPoint(x1, y1), QPoint(x2, y2));
painter->save();
painter->setPen(m_pen);
painter->setBrush(m_brush);
painter->drawRect(rect);
painter->restore();
}
QRectF PlotRectItem::boundingRect() const {
return m_rect;
}