7#include <QStyleOptionViewItem>
14const QColor kOutputColor(0, 128, 0);
15const QColor kInputColor(0x75, 0x8e, 0xff);
18constexpr double kLineThickness = 4.0 / 30.0;
19constexpr double kBarWidth = 4.0 / 100.0;
20constexpr double kHighTop = 8.0 / 30.0;
21constexpr double kLowTop = 20.0 / 30.0;
22constexpr double kHighBottom = 12.0 / 30.0;
23constexpr double kLowBottom = 24.0 / 30.0;
27 : QItemDelegate(parent)
45void SignalDelegate::drawWaveform(QPainter *painter,
const QRectF &cell,
const WaveSegment seg,
const bool isInput)
const
47 const QColor color = isInput ? kInputColor : kOutputColor;
48 QColor bandColor = color;
49 bandColor.setAlpha(128);
51 const double x = cell.x();
52 const double y = cell.y();
53 const double w = cell.width();
54 const double h = cell.height();
58 const double lineTop = (high ? kHighTop : kLowTop) * h;
59 const double lineBottom = (high ? kHighBottom : kLowBottom) * h;
60 const double thickness = kLineThickness * h;
63 painter->fillRect(QRectF(x, y + lineBottom, w, h - lineBottom), bandColor);
64 painter->fillRect(QRectF(x, y + lineTop, w, thickness), color);
68 const double barTop = kHighTop * h;
69 const double barBottom = kLowBottom * h;
70 painter->fillRect(QRectF(x, y + barTop, kBarWidth * w, barBottom - barTop), color);
74void SignalDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index)
const
78 QStyleOptionViewItem opt(option);
79 opt.displayAlignment = Qt::AlignCenter;
80 QItemDelegate::paint(painter, opt, index);
86 const int value = index.data().toInt();
87 const QModelIndex prev = index.siblingAtColumn(index.column() - 1);
88 const bool hasPrev = prev.isValid();
92 if (
const auto *model = qobject_cast<const SignalModel *>(index.model())) {
93 isInput = model->isInputRow(index.row());
97 if (option.state & QStyle::State_Selected) {
98 painter->fillRect(option.rect, option.palette.highlight());
101 drawWaveform(painter, option.rect, seg, isInput);
SignalDelegate: paints digital waveform graphics into table cells.
WaveSegment
Identifies which waveform segment a Line-mode cell draws.
@ Falling
High → low transition (low plateau + leading edge).
@ Low
Logic-low plateau (signal stays at 0).
@ Rising
Low → high transition (high plateau + leading edge).
@ High
Logic-high plateau (signal stays at 1).
PlotType
Controls how signal cells are rendered in the waveform table.
@ Number
Cells display the numeric value (0/1).
SignalModel for the beWavedDolphin waveform table.
void setPlotType(PlotType plotType)
Selects the cell rendering mode (waveform graphics vs. numeric text).
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
PlotType plotType() const
Returns the current cell rendering mode.
static WaveSegment segmentFor(int value, bool hasPrev, int prevValue)
Returns the waveform segment a cell should draw.
SignalDelegate(QObject *parent=nullptr)
Constructs the delegate.