diff options
author | bd <bdunahu@operationnull.com> | 2025-04-26 12:32:34 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-04-26 12:32:34 -0400 |
commit | 94c0d7b5045244f20dfa13f7d31e0e06901908c2 (patch) | |
tree | 2e7d8faf981fb84dcd2c1fbe2daad0e3e013dd0c /gui/digitlabeldelegate.cc | |
parent | a78163745b43a0c420ae4ea5792def30a94420eb (diff) |
Add a digit delegate to toggle table base display
Diffstat (limited to 'gui/digitlabeldelegate.cc')
-rw-r--r-- | gui/digitlabeldelegate.cc | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/gui/digitlabeldelegate.cc b/gui/digitlabeldelegate.cc new file mode 100644 index 0000000..641b5a0 --- /dev/null +++ b/gui/digitlabeldelegate.cc @@ -0,0 +1,57 @@ +// Simulator for the RISC-V[ECTOR] mini-ISA +// Copyright (C) 2025 Siddarth Suresh +// Copyright (C) 2025 bdunahu + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +#include "digitlabeldelegate.h" +#include "digitlabelhelper.h" +#include <QString> + +DigitLabelDelegate::DigitLabelDelegate(QObject *parent) + : QStyledItemDelegate(parent) +{ + ; +} + +void DigitLabelDelegate::set_hex_display(bool hex) +{ + if (this->is_hex != hex) { + this->is_hex = hex; + if (auto v = qobject_cast<QAbstractItemView *>(parent())) + v->viewport()->update(); + } +} + +void DigitLabelDelegate::paint( + QPainter *painter, + const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + int v; + QString t; + QStyleOptionViewItem o; + QStyle *s; + + v = index.data(Qt::DisplayRole).toInt(); + t = DigitLabelHelper::format_value(v, this->is_hex); + + o = option; + initStyleOption(&o, index); + o.text = t; + + const QWidget *w = option.widget; + s = w ? w->style() : QApplication::style(); + s->drawControl(QStyle::CE_ItemViewItem, &o, painter, w); +} |