Graphic updates.

This commit is contained in:
2026-01-09 00:45:26 +01:00
parent d6da7aac9a
commit 95765226e9
9 changed files with 98 additions and 896 deletions

View File

@@ -44,6 +44,7 @@
#include <QPainter>
#include "bcanimateddelegate.h"
#include "bcsliderstyle.h"
BCAnimatedDelegate::BCAnimatedDelegate(const BCValueList& valueList, QTableView* view)
@@ -52,41 +53,37 @@ BCAnimatedDelegate::BCAnimatedDelegate(const BCValueList& valueList, QTableView*
}
/*
QString BCAnimatedDelegate::displayText(const QVariant& dataValue, const QLocale& locale) const
{
// Wir prüfen, ob im Variant unser Struct steckt
if (dataValue.canConvert<const BCValue&>())
{
const BCValue& bc = dataValue.value<const BCValue/>();
//qDebug() << " --- YES: " << bc.label;
// Hier bauen wir den String zusammen, den man sieht,
// wenn KEIN Editor offen ist.
// Format: "Label: Wert Einheit"
return QString("%1: %2 %3").arg(bc.label, bc.formattedValue, "mmX");
}
else
{
//qDebug() << " --- Nö!";
}
// Fallback für normale Strings/Zahlen
return QStyledItemDelegate::displayText(dataValue, locale);
}
*/
QWidget *BCAnimatedDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
{
/*
QVariant rawData = index.data(Qt::EditRole);
//if (!rawData.canConvert<BCValue*>())
if( index.column() == 1 )
return QStyledItemDelegate::createEditor(parent, option, index);
const BCValue& bc = *rawData.value<BCValue*>();
const BCValue& bcValue = *(_valueList[ index.row()].get());
Q_UNUSED(option)
Q_UNUSED(index)
auto* slider = new QSlider(Qt::Horizontal, parent);
slider->setRange(0, 100);
slider->setSingleStep(1);
slider->setPageStep(10);
//slider->setStyle(new FluentSliderStyle());
// Signal für sofortige Updates
connect(slider, &QSlider::valueChanged, this, [this, slider]()
{
// Commit data sofort bei Änderung
//emit const_cast<SliderDelegate*>(this)->commitData(slider);
});
return slider;
/*
// Nur bei Integern den Slider-Editor bauen
if (bc.value.typeId() == QMetaType::Int)
//if (bc.value.typeId() == QMetaType::Int)
{
QWidget *container = new QWidget(parent);
container->setAutoFillBackground(true);
@@ -96,8 +93,8 @@ QWidget *BCAnimatedDelegate::createEditor(QWidget *parent, const QStyleOptionVie
layout->setSpacing(10);
// Linkes Label (Name)
QLabel *lblName = new QLabel(bc.label, container);
lblName->setFixedWidth(80);
//QLabel *lblName = new QLabel(bcValue.label, container);
//lblName->setFixedWidth(80);
// Slider
QSlider *slider = new QSlider(Qt::Horizontal, container);
@@ -110,21 +107,22 @@ QWidget *BCAnimatedDelegate::createEditor(QWidget *parent, const QStyleOptionVie
lblUnit->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
lblUnit->setObjectName("lblUnit");
layout->addWidget(lblName);
//layout->addWidget(lblName);
layout->addWidget(slider);
layout->addWidget(lblUnit);
// Live-Update des Labels im Editor (aber noch kein Speichern im Model)
connect(slider, &QSlider::valueChanged, this, [=](int val){
connect(slider, &QSlider::valueChanged, this, [=](int val)
{
lblUnit->setText(QString("%1 %2").arg(val).arg("mm2"));
});
return container;
}
*/
return QStyledItemDelegate::createEditor(parent, option, index);
//return QStyledItemDelegate::createEditor(parent, option, index);
*/
}
void BCAnimatedDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const
@@ -210,7 +208,7 @@ void BCAnimatedDelegate::paint(QPainter *painter, const QStyleOptionViewItem& op
if( row>-1 && row <= _valueList.size() )
{
const BCValue& bcValue = *(_valueList[ index.row()].get());
qDebug() << " --- paintSLider: " << bcValue.label << " type: " << (int)bcValue.valueType << " flags:" << bcValue.valueFlags.toInt() << " RO: " << bcValue.isReadOnly();
//qDebug() << " --- paintSLider: " << bcValue.label << " type: " << (int)bcValue.valueType << " flags:" << bcValue.valueFlags.toInt() << " RO: " << bcValue.isReadOnly();
if( !bcValue.isReadOnly())
paintSliderIndicator(painter,option,bcValue);
}
@@ -218,9 +216,9 @@ void BCAnimatedDelegate::paint(QPainter *painter, const QStyleOptionViewItem& op
default:
break;
}
}
void BCAnimatedDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, int row) const
{
painter->save();
@@ -247,14 +245,15 @@ void BCAnimatedDelegate::paintHighlightRow(QPainter* painter, const QStyleOption
}
/**
* @brief Zeichnet eine passiven Slider, um den Wertebereich des übergebenen BCValue anzuzeigen.
* @param painter
* @param option
* @param bcValue
*/
void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOptionViewItem& option, const BCValue& bcValue) const
{
// wenn Werte readOnly sind, dann brauchen keinen EditHint
//if( bcValue.valueFlags.testFlag(BCValue::Flag::ReadOnly) )
// || bcValue.valueType == BCValue::ValueType::Plain )
// return;
// Hintergrund
if (option.state & QStyle::State_Selected)
{
@@ -267,6 +266,11 @@ void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOpt
}
// baby-Slider-Indikator zeichnen
// Anteil zwischen min und max berechnen
double ratio = bcValue.calcRatio();
if( !ratio)
return;
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
@@ -280,20 +284,27 @@ void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOpt
// Mini Progress Bar
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(0xE0E0E0));
QColor disabledText = option.palette.color(QPalette::Disabled, QPalette::Text);
painter->setBrush(disabledText);
painter->drawRoundedRect(barRect, 2, 2);
// Anteil zwischen min und max berechnen
double ratio = bcValue.calcRatio();
barRect.setWidth(barRect.width() * ratio );
painter->setBrush(QColor(0x0078D4));
//painter->setBrush(Qt::green);
//painter->setBrush( );
painter->drawRoundedRect(barRect, 2, 2);
painter->restore();
}
/**
* @brief Startet die Animation für die übergebene Zeile
* @param row
*/
void BCAnimatedDelegate::onHighlightRow(int row)
{
// Alte Animation für diese Zeile stoppen falls vorhanden
@@ -340,7 +351,11 @@ void BCAnimatedDelegate::onHighlightRow(int row)
anim->start(QAbstractAnimation::DeleteWhenStopped);
}
// Optional: alle Highlights sofort clearen
/**
* @brief Sopt alle gerade laufenden Animationen
*/
void BCAnimatedDelegate::clearAllHighlights()
{
for(auto* anim : std::as_const(_rowAnimations))
@@ -357,6 +372,12 @@ void BCAnimatedDelegate::clearAllHighlights()
}
}
/**
* @brief Zeichnet die übegebene Zeile neu.
* @param row
*/
void BCAnimatedDelegate::updateRow(int row)
{
if (_view && _view->model() && row >= 0)