|
|
|
|
@@ -54,76 +54,6 @@ BCAnimatedDelegate::BCAnimatedDelegate(const BCValueList& valueList, QTableView*
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QWidget *BCAnimatedDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if( index.column() == 1 )
|
|
|
|
|
return QStyledItemDelegate::createEditor(parent, option, index);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
QWidget *container = new QWidget(parent);
|
|
|
|
|
container->setAutoFillBackground(true);
|
|
|
|
|
|
|
|
|
|
QHBoxLayout *layout = new QHBoxLayout(container);
|
|
|
|
|
layout->setContentsMargins(4, 0, 4, 0);
|
|
|
|
|
layout->setSpacing(10);
|
|
|
|
|
|
|
|
|
|
// Linkes Label (Name)
|
|
|
|
|
//QLabel *lblName = new QLabel(bcValue.label, container);
|
|
|
|
|
//lblName->setFixedWidth(80);
|
|
|
|
|
|
|
|
|
|
// Slider
|
|
|
|
|
QSlider *slider = new QSlider(Qt::Horizontal, container);
|
|
|
|
|
slider->setRange(0, 100);
|
|
|
|
|
slider->setObjectName("slider");
|
|
|
|
|
|
|
|
|
|
// Rechtes Label (Vorschau Wert + Einheit)
|
|
|
|
|
QLabel *lblUnit = new QLabel(container);
|
|
|
|
|
lblUnit->setFixedWidth(60);
|
|
|
|
|
lblUnit->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
|
|
|
lblUnit->setObjectName("lblUnit");
|
|
|
|
|
|
|
|
|
|
//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)
|
|
|
|
|
{
|
|
|
|
|
lblUnit->setText(QString("%1 %2").arg(val).arg("mm2"));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return container;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//return QStyledItemDelegate::createEditor(parent, option, index);
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BCAnimatedDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const
|
|
|
|
|
{
|
|
|
|
|
@@ -150,10 +80,9 @@ void BCAnimatedDelegate::setEditorData(QWidget *editor, const QModelIndex& index
|
|
|
|
|
|
|
|
|
|
void BCAnimatedDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
qDebug() << "... SHUHU!";
|
|
|
|
|
// Daten vom Editor zurück ins Model speichern (Beim Schließen)
|
|
|
|
|
QSlider *slider = editor->findChild<QSlider*>("slider");
|
|
|
|
|
|
|
|
|
|
if (slider)
|
|
|
|
|
{
|
|
|
|
|
int value = slider->value();
|
|
|
|
|
@@ -163,13 +92,28 @@ void BCAnimatedDelegate::setModelData(QWidget *editor, QAbstractItemModel *model
|
|
|
|
|
{
|
|
|
|
|
QStyledItemDelegate::setModelData(editor, model, index);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BCAnimatedDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Q_UNUSED(index)
|
|
|
|
|
/*
|
|
|
|
|
QRect barRect = option.rect.adjusted(option.rect.width() - 55,
|
|
|
|
|
option.rect.height() / 2 - 2,
|
|
|
|
|
-8,
|
|
|
|
|
-option.rect.height() / 2 + 2);
|
|
|
|
|
*/
|
|
|
|
|
QRect sliderRect = option.rect.adjusted(
|
|
|
|
|
option.rect.width() - 125, // Von rechts: 115px (Breite der Progress Bar)
|
|
|
|
|
0, // Oben: kein Offset
|
|
|
|
|
-8, // Rechts: 8px Padding
|
|
|
|
|
0 // Unten: kein Offset
|
|
|
|
|
);
|
|
|
|
|
editor->setGeometry(sliderRect); // Slider nur über Progress Bar
|
|
|
|
|
//editor->setGeometry(option.rect);
|
|
|
|
|
// __fix!
|
|
|
|
|
editor->setGeometry(option.rect);
|
|
|
|
|
//editor->setGeometry(option.rect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize BCAnimatedDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex& index) const
|
|
|
|
|
@@ -193,18 +137,9 @@ void BCAnimatedDelegate::paint(QPainter *painter, const QStyleOptionViewItem& op
|
|
|
|
|
QStyledItemDelegate::paint(painter, option, index);
|
|
|
|
|
|
|
|
|
|
int row = index.row();
|
|
|
|
|
int col = index.column();
|
|
|
|
|
|
|
|
|
|
switch (col)
|
|
|
|
|
if( index.column() == 1 )
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
|
|
if(_rowOpacities.contains(row))
|
|
|
|
|
paintHighlightRow(painter,option,index.row());
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
|
|
if( row>-1 && row <= _valueList.size() )
|
|
|
|
|
{
|
|
|
|
|
const BCValue& bcValue = *(_valueList[ index.row()].get());
|
|
|
|
|
@@ -213,12 +148,36 @@ void BCAnimatedDelegate::paint(QPainter *painter, const QStyleOptionViewItem& op
|
|
|
|
|
paintSliderIndicator(painter,option,bcValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
if(_rowOpacities.contains(row))
|
|
|
|
|
paintHighlightRow(painter,option,index.row());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QWidget* BCAnimatedDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
|
|
|
|
|
{
|
|
|
|
|
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<BCAnimatedDelegate*>(this)->commitData(slider);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return slider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BCAnimatedDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, int row) const
|
|
|
|
|
{
|
|
|
|
|
painter->save();
|
|
|
|
|
@@ -254,6 +213,43 @@ void BCAnimatedDelegate::paintHighlightRow(QPainter* painter, const QStyleOption
|
|
|
|
|
*/
|
|
|
|
|
void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOptionViewItem& option, const BCValue& bcValue) const
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// Text und kleiner Slider-Indikator zeichnen
|
|
|
|
|
painter->save();
|
|
|
|
|
|
|
|
|
|
painter->setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
/*
|
|
|
|
|
QRect barRect = option.rect.adjusted(option.rect.width() - 130,
|
|
|
|
|
option.rect.height() / 2 - 2,
|
|
|
|
|
-8,
|
|
|
|
|
-option.rect.height() / 2 + 2);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
QRect barRect = option.rect.adjusted(option.rect.width() - 130,
|
|
|
|
|
option.rect.height() / 2 + 1,
|
|
|
|
|
-8,
|
|
|
|
|
-option.rect.height() / 2 - 3);
|
|
|
|
|
|
|
|
|
|
double ratio = bcValue.calcRatio();
|
|
|
|
|
if( ratio)
|
|
|
|
|
{
|
|
|
|
|
// Mini Progress Bar
|
|
|
|
|
painter->setPen(Qt::NoPen);
|
|
|
|
|
painter->setBrush(QColor(0xE0E0E0));
|
|
|
|
|
painter->drawRoundedRect(barRect, 2, 2);
|
|
|
|
|
|
|
|
|
|
QRect fillRect = barRect;
|
|
|
|
|
fillRect.setWidth(barRect.width() * ratio);
|
|
|
|
|
painter->setBrush(QColor(0x0078D4));
|
|
|
|
|
painter->drawRoundedRect(fillRect, 2, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
painter->restore();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// -------
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// Hintergrund
|
|
|
|
|
if (option.state & QStyle::State_Selected)
|
|
|
|
|
{
|
|
|
|
|
@@ -264,7 +260,10 @@ void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOpt
|
|
|
|
|
QColor bcColor = option.palette.color(QPalette::Base);
|
|
|
|
|
painter->fillRect(option.rect, bcColor);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// baby-Slider-Indikator zeichnen
|
|
|
|
|
// Anteil zwischen min und max berechnen
|
|
|
|
|
double ratio = bcValue.calcRatio();
|
|
|
|
|
@@ -296,7 +295,7 @@ void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOpt
|
|
|
|
|
painter->drawRoundedRect(barRect, 2, 2);
|
|
|
|
|
|
|
|
|
|
painter->restore();
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|