This commit is contained in:
2026-01-10 22:18:54 +01:00
parent aa4b2a1b84
commit 7780657d82
12 changed files with 160 additions and 52 deletions

View File

@@ -46,7 +46,6 @@ windows
SOURCES += \ SOURCES += \
bc.cpp \ bc.cpp \
bcanimateddelegate.cpp \
bcdelightpmwidget.cpp \ bcdelightpmwidget.cpp \
bcdeviceview.cpp \ bcdeviceview.cpp \
bcdriver.cpp \ bcdriver.cpp \
@@ -57,6 +56,8 @@ SOURCES += \
bctoggleswitch.cpp \ bctoggleswitch.cpp \
bctransmitter.cpp \ bctransmitter.cpp \
bcvalue.cpp \ bcvalue.cpp \
bcvaluedelegate.cpp \
bcvalueeditor.cpp \
bcvaluemodel.cpp \ bcvaluemodel.cpp \
bcxmlloader.cpp \ bcxmlloader.cpp \
libwin/can_drv_win.c \ libwin/can_drv_win.c \
@@ -66,7 +67,6 @@ SOURCES += \
HEADERS += \ HEADERS += \
bc.h \ bc.h \
bcanimateddelegate.h \
bcdelightpmwidget.h \ bcdelightpmwidget.h \
bcdeviceview.h \ bcdeviceview.h \
bcdriver.h \ bcdriver.h \
@@ -78,6 +78,8 @@ HEADERS += \
bctoggleswitch.h \ bctoggleswitch.h \
bctransmitter.h \ bctransmitter.h \
bcvalue.h \ bcvalue.h \
bcvaluedelegate.h \
bcvalueeditor.h \
bcvaluemodel.h \ bcvaluemodel.h \
bcxmlloader.h bcxmlloader.h

View File

@@ -33,7 +33,7 @@
#include <QHeaderView> #include <QHeaderView>
#include <bcdeviceview.h> #include <bcdeviceview.h>
#include <bcanimateddelegate.h> #include <bcvaluedelegate.h>
BCDeviceView::BCDeviceView(QWidget *parent) BCDeviceView::BCDeviceView(QWidget *parent)
: QTableView(parent) : QTableView(parent)
@@ -44,7 +44,7 @@ BCDeviceView::BCDeviceView(QWidget *parent)
//horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); //horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
// __fix! ziemlich wildes ge-pointere, hier // __fix! ziemlich wildes ge-pointere, hier
_itemDelegate = new BCAnimatedDelegate( _valueModel.getValueList(), this); _itemDelegate = new BCValueDelegate( _valueModel.getValueList(), this);
setItemDelegateForColumn( 1, _itemDelegate ); setItemDelegateForColumn( 1, _itemDelegate );
} }

View File

@@ -38,7 +38,7 @@
#include <bcvaluemodel.h> #include <bcvaluemodel.h>
class BCAnimatedDelegate; class BCValueDelegate;
class BCDeviceView : public QTableView class BCDeviceView : public QTableView
{ {
@@ -67,7 +67,7 @@ protected:
bool _firstExpose{true}; bool _firstExpose{true};
BCDevice::ID _devideID{BCDevice::ID::Invalid}; BCDevice::ID _devideID{BCDevice::ID::Invalid};
BCValueModel _valueModel; BCValueModel _valueModel;
BCAnimatedDelegate* _itemDelegate{}; BCValueDelegate* _itemDelegate{};
}; };

View File

@@ -75,7 +75,8 @@ TransmitResult BCDriverDummy::readRawByte( uint32_t deviceID, uint8_t registerID
Q_UNUSED(deviceID) Q_UNUSED(deviceID)
Q_UNUSED(registerID) Q_UNUSED(registerID)
// Tätigkeit simulieren // Tätigkeit simulieren
bc::delay_millis(200); //bc::delay_millis(200);
bc::delay_millis(50);
uint8_t myRandomByte = static_cast<uint8_t>(QRandomGenerator::global()->bounded(256)); uint8_t myRandomByte = static_cast<uint8_t>(QRandomGenerator::global()->bounded(256));
return myRandomByte; return myRandomByte;
} }

View File

@@ -37,7 +37,7 @@
#include <bcthemeswitchbutton.h> #include <bcthemeswitchbutton.h>
#include <bcdriverstatewidget.h> #include <bcdriverstatewidget.h>
#include <bcmainwindow.h> #include <bcmainwindow.h>
#include <bcanimateddelegate.h> #include <bcvaluedelegate.h>
#include <ui_bcmainwindow.h> #include <ui_bcmainwindow.h>
/** /**

View File

@@ -242,7 +242,7 @@
<number>0</number> <number>0</number>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>2</number> <number>1</number>
</property> </property>
<widget class="BCDeviceView" name="_consolePanel"> <widget class="BCDeviceView" name="_consolePanel">
<property name="frameShape"> <property name="frameShape">
@@ -254,6 +254,9 @@
<property name="lineWidth"> <property name="lineWidth">
<number>0</number> <number>0</number>
</property> </property>
<property name="editTriggers">
<set>QAbstractItemView::EditTrigger::AnyKeyPressed|QAbstractItemView::EditTrigger::DoubleClicked|QAbstractItemView::EditTrigger::EditKeyPressed|QAbstractItemView::EditTrigger::SelectedClicked</set>
</property>
<property name="showGrid"> <property name="showGrid">
<bool>false</bool> <bool>false</bool>
</property> </property>
@@ -283,6 +286,9 @@
<property name="lineWidth"> <property name="lineWidth">
<number>0</number> <number>0</number>
</property> </property>
<property name="editTriggers">
<set>QAbstractItemView::EditTrigger::AnyKeyPressed|QAbstractItemView::EditTrigger::DoubleClicked|QAbstractItemView::EditTrigger::EditKeyPressed|QAbstractItemView::EditTrigger::SelectedClicked</set>
</property>
<property name="showGrid"> <property name="showGrid">
<bool>false</bool> <bool>false</bool>
</property> </property>
@@ -312,6 +318,9 @@
<property name="lineWidth"> <property name="lineWidth">
<number>0</number> <number>0</number>
</property> </property>
<property name="editTriggers">
<set>QAbstractItemView::EditTrigger::AnyKeyPressed|QAbstractItemView::EditTrigger::DoubleClicked|QAbstractItemView::EditTrigger::EditKeyPressed|QAbstractItemView::EditTrigger::SelectedClicked</set>
</property>
<property name="showGrid"> <property name="showGrid">
<bool>false</bool> <bool>false</bool>
</property> </property>

View File

@@ -59,11 +59,11 @@
#include <QGraphicsDropShadowEffect> #include <QGraphicsDropShadowEffect>
// Fluent Design Slider Style // Fluent Design Slider Style
class FluentSliderStyle : public QProxyStyle class BCSliderStyle : public QProxyStyle
{ {
public: public:
FluentSliderStyle() BCSliderStyle()
: QProxyStyle() : QProxyStyle()
{} {}

View File

@@ -43,11 +43,10 @@
#include <QPropertyAnimation> #include <QPropertyAnimation>
#include <QPainter> #include <QPainter>
#include "bcanimateddelegate.h" #include <bcvaluedelegate.h>
#include "bcsliderstyle.h" #include <bcvalueeditor.h>
BCValueDelegate::BCValueDelegate(const BCValueList& valueList, QTableView* view)
BCAnimatedDelegate::BCAnimatedDelegate(const BCValueList& valueList, QTableView* view)
: QStyledItemDelegate{view}, _valueList{valueList}, _view{view} : QStyledItemDelegate{view}, _valueList{valueList}, _view{view}
{ {
@@ -55,7 +54,26 @@ BCAnimatedDelegate::BCAnimatedDelegate(const BCValueList& valueList, QTableView*
void BCAnimatedDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const QWidget* BCValueDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
{
const BCValue& bcValue = *(_valueList[ index.row()].get());
Q_UNUSED(option)
Q_UNUSED(index)
auto* valueEditor = new BCValueEditor(bcValue, parent);
// Signal für sofortige Updates
connect(valueEditor, &BCValueEditor::valueChanged, this, [this, valueEditor]()
{
// Commit data sofort bei Änderung
emit const_cast<BCValueDelegate*>(this)->commitData(valueEditor);
});
return valueEditor;
}
void BCValueDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const
{ {
/* /*
// Daten vom Model in den Editor laden // Daten vom Model in den Editor laden
@@ -78,7 +96,7 @@ void BCAnimatedDelegate::setEditorData(QWidget *editor, const QModelIndex& index
*/ */
} }
void BCAnimatedDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const void BCValueDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const
{ {
// Daten vom Editor zurück ins Model speichern (Beim Schließen) // Daten vom Editor zurück ins Model speichern (Beim Schließen)
QSlider *slider = editor->findChild<QSlider*>("slider"); QSlider *slider = editor->findChild<QSlider*>("slider");
@@ -93,7 +111,7 @@ void BCAnimatedDelegate::setModelData(QWidget *editor, QAbstractItemModel *model
} }
} }
void BCAnimatedDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const void BCValueDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const
{ {
Q_UNUSED(index) Q_UNUSED(index)
@@ -113,7 +131,7 @@ void BCAnimatedDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptio
} }
QSize BCAnimatedDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex& index) const QSize BCValueDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex& index) const
{ {
return QStyledItemDelegate::sizeHint(option,index); return QStyledItemDelegate::sizeHint(option,index);
/* /*
@@ -127,7 +145,7 @@ QSize BCAnimatedDelegate::sizeHint(const QStyleOptionViewItem &option, const QMo
} }
void BCAnimatedDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const void BCValueDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{ {
// Standard-Zeichnen (Text, Hintergrund, Selection) durchführen // Standard-Zeichnen (Text, Hintergrund, Selection) durchführen
@@ -151,30 +169,9 @@ void BCAnimatedDelegate::paint(QPainter *painter, const QStyleOptionViewItem& op
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 void BCValueDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, int row) const
{ {
painter->save(); painter->save();
painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing);
@@ -207,7 +204,7 @@ void BCAnimatedDelegate::paintHighlightRow(QPainter* painter, const QStyleOption
* @param option * @param option
* @param bcValue * @param bcValue
*/ */
void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOptionViewItem& option, const BCValue& bcValue) const void BCValueDelegate::paintSliderIndicator(QPainter* painter, const QStyleOptionViewItem& option, const BCValue& bcValue) const
{ {
// Text und kleiner Slider-Indikator zeichnen // Text und kleiner Slider-Indikator zeichnen
@@ -300,7 +297,7 @@ void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOpt
* @param row * @param row
*/ */
void BCAnimatedDelegate::onHighlightRow(int row) void BCValueDelegate::onHighlightRow(int row)
{ {
// Alte Animation für diese Zeile stoppen falls vorhanden // Alte Animation für diese Zeile stoppen falls vorhanden
if (_rowAnimations.contains(row)) if (_rowAnimations.contains(row))
@@ -351,7 +348,7 @@ void BCAnimatedDelegate::onHighlightRow(int row)
* @brief Sopt alle gerade laufenden Animationen * @brief Sopt alle gerade laufenden Animationen
*/ */
void BCAnimatedDelegate::clearAllHighlights() void BCValueDelegate::clearAllHighlights()
{ {
for(auto* anim : std::as_const(_rowAnimations)) for(auto* anim : std::as_const(_rowAnimations))
{ {
@@ -373,7 +370,7 @@ void BCAnimatedDelegate::clearAllHighlights()
* @param row * @param row
*/ */
void BCAnimatedDelegate::updateRow(int row) void BCValueDelegate::updateRow(int row)
{ {
if (_view && _view->model() && row >= 0) if (_view && _view->model() && row >= 0)
{ {

View File

@@ -30,8 +30,8 @@
***************************************************************************/ ***************************************************************************/
#ifndef BCANIMATEDDELEGATE_H #ifndef BCVALUEDELEGATE_H
#define BCANIMATEDDELEGATE_H #define BCVALUEDELEGATE_H
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
@@ -42,13 +42,13 @@ class QVariantAnimation;
class QTableView; class QTableView;
class BCAnimatedDelegate : public QStyledItemDelegate class BCValueDelegate : public QStyledItemDelegate
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit BCAnimatedDelegate(const BCValueList& valueList, QTableView* view ); explicit BCValueDelegate(const BCValueList& valueList, QTableView* view );
// QString displayText(const QVariant& dataValue, const QLocale& locale) const override; // QString displayText(const QVariant& dataValue, const QLocale& locale) const override;
@@ -94,4 +94,4 @@ protected:
}; };
#endif // BCANIMATEDDELEGATE_H #endif // BCVALUEDELEGATE_H

66
bcvalueeditor.cpp Normal file
View File

@@ -0,0 +1,66 @@
//#include <QApplication>
#include <QVBoxLayout>
//#include <QStyledItemDelegate>
#include <QSlider>
#include <QPushButton>
#include <bcvalueeditor.h>
#include <bcsliderstyle.h>
BCValueEditor::BCValueEditor(const BCValue& bcValue, QWidget *parent )
: QWidget(parent), _bcValue{bcValue}
{
setAutoFillBackground(true);
_slider = new QSlider(Qt::Horizontal, this);
_slider->setRange(0, 100);
_slider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
_slider->setSingleStep(1);
_slider->setPageStep(10);
_slider->setStyle(new BCSliderStyle());
_commitButton = new QPushButton(this);
_commitButton->setIcon(style()->standardIcon(QStyle::SP_DialogResetButton));
_commitButton->setFixedSize(32, 32);
auto *layout = new QHBoxLayout(this);
// Deine gewünschten Margins für 36px Zeilenhöhe
layout->setContentsMargins(2, 2, 2, 2);
layout->setSpacing(4);
layout->addWidget(_slider);
layout->addWidget(_commitButton);
setLayout(layout);
// Wenn Slider bewegt wird -> Signal nach außen senden
connect(_slider, &QSlider::valueChanged, this, [this](int val)
{
emit valueChanged(val);
});
// Wenn Reset gedrückt wird -> Slider auf 0 (löst auch valueChanged aus)
connect(_commitButton, &QPushButton::clicked, this, [this](){
_slider->setValue(0);
});
}
int BCValueEditor::getValue() const
{
return _slider->value();
}
void BCValueEditor::setValue(int val)
{
// WICHTIG: Block Signals verhindern Endlosschleifen, falls das Model
// das Widget während des Updates neu setzt (passiert manchmal bei Live-Updates).
if (val != _slider->value())
{
bool blocked = _slider->blockSignals(true);
_slider->setValue(val);
_slider->blockSignals(blocked);
}
}

33
bcvalueeditor.h Normal file
View File

@@ -0,0 +1,33 @@
#ifndef BCVALUEEDITOR_H
#define BCVALUEEDITOR_H
#include <QWidget>
class QSlider;
class QPushButton;
class BCValue;
class BCValueEditor : public QWidget
{
Q_OBJECT
public:
explicit BCValueEditor(const BCValue& bcValue, QWidget *parent = nullptr);
int getValue() const;
void setValue(int val);
signals:
void valueChanged(int value);
private:
const BCValue& _bcValue;
QSlider* _slider;
QPushButton* _commitButton;
};
#endif // BCVALUEEDITOR_H

View File

@@ -194,7 +194,7 @@ bool BCValueModel::setData(const QModelIndex& index, const QVariant& variant, in
if( variant.toInt() == 42) if( variant.toInt() == 42)
{ {
qDebug() << "--- YES! " << variant.toInt(); qDebug() << "--- YES! " << variant.toInt();
emit makeSimonHappy(); //emit makeSimonHappy();
} }
value->rawValue = variant.toInt(); value->rawValue = variant.toInt();
} }