Mini-Breakthrough: Animantion works.
This commit is contained in:
@@ -43,20 +43,20 @@
|
||||
#include <QPropertyAnimation>
|
||||
#include <QPainter>
|
||||
|
||||
#include "bcdelegate.h"
|
||||
#include "bcitemdelegate.h"
|
||||
#include "bcvalue.h"
|
||||
#include "qapplication.h"
|
||||
|
||||
|
||||
|
||||
BCDelegate::BCDelegate(const BCValueList& valueList, QTableView* view)
|
||||
|
||||
BCItemDelegate::BCItemDelegate(const BCValueList& valueList, QTableView* view)
|
||||
: QStyledItemDelegate{view}, _valueList{valueList}, _view{view}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
QString BCDelegate::displayText(const QVariant& dataValue, const QLocale& locale) const
|
||||
/*
|
||||
QString BCItemDelegate::displayText(const QVariant& dataValue, const QLocale& locale) const
|
||||
{
|
||||
// Wir prüfen, ob im Variant unser Struct steckt
|
||||
if (dataValue.canConvert<const BCValue*>())
|
||||
@@ -76,9 +76,10 @@ QString BCDelegate::displayText(const QVariant& dataValue, const QLocale& locale
|
||||
// Fallback für normale Strings/Zahlen
|
||||
return QStyledItemDelegate::displayText(dataValue, locale);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
QWidget *BCDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
|
||||
QWidget *BCItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
|
||||
{
|
||||
QVariant rawData = index.data(Qt::EditRole);
|
||||
//if (!rawData.canConvert<BCValue*>())
|
||||
@@ -128,7 +129,7 @@ QWidget *BCDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &o
|
||||
*/
|
||||
}
|
||||
|
||||
void BCDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const
|
||||
void BCItemDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const
|
||||
{
|
||||
// Daten vom Model in den Editor laden
|
||||
const BCValue& bc = *index.data(Qt::EditRole).value<BCValue*>();
|
||||
@@ -147,7 +148,7 @@ void BCDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const
|
||||
}
|
||||
}
|
||||
|
||||
void BCDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const
|
||||
void BCItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const
|
||||
{
|
||||
// Daten vom Editor zurück ins Model speichern (Beim Schließen)
|
||||
QSlider *slider = editor->findChild<QSlider*>("slider");
|
||||
@@ -160,13 +161,13 @@ void BCDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const
|
||||
}
|
||||
}
|
||||
|
||||
void BCDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const
|
||||
void BCItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const
|
||||
{
|
||||
// __fix!
|
||||
editor->setGeometry(option.rect);
|
||||
}
|
||||
|
||||
QSize BCDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex& index) const
|
||||
QSize BCItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex& index) const
|
||||
{
|
||||
return QStyledItemDelegate::sizeHint(option,index);
|
||||
/*
|
||||
@@ -180,34 +181,13 @@ QSize BCDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex
|
||||
}
|
||||
|
||||
|
||||
void BCDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
void BCItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
|
||||
/*
|
||||
// 1. Standard-Zeichnen (Text, Hintergrund, Selection) durchführen
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
|
||||
// 2. Unser Custom-Overlay: Oranger Rahmen, wenn Zeile passt
|
||||
if (index.row() == _highlightedRow)
|
||||
{
|
||||
painter->save();
|
||||
|
||||
qDebug() << " --- is highlight: " << index.row();
|
||||
|
||||
// Setup Stift
|
||||
QPen pen(QColor(255, 165, 0)); // Orange
|
||||
pen.setWidth(2);
|
||||
painter->setPen(pen);
|
||||
|
||||
// Rechteck zeichnen (leicht eingezogen, damit es nicht abgeschnitten wird)
|
||||
QRect rect = option.rect.adjusted(1, 1, -1, -1);
|
||||
painter->drawRect(rect);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
*/
|
||||
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
//QPen pen(QColor(255, 165, 0)); // Orange
|
||||
|
||||
/*
|
||||
if (index.row() == _highlightedRow && _opacity > 0.0)
|
||||
@@ -231,61 +211,70 @@ void BCDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, co
|
||||
|
||||
int row = index.row();
|
||||
|
||||
if (m_rowOpacities.contains(row))
|
||||
if (index.column() == 1 )
|
||||
{
|
||||
/*
|
||||
qreal opacity = m_rowOpacities.value(row);
|
||||
if (opacity > 0.01)
|
||||
qDebug() << " --- is highlight: " << row << " : " << index.column();
|
||||
//if( m_rowOpacities.contains(row))
|
||||
{
|
||||
painter->save();
|
||||
painter->setOpacity(opacity);
|
||||
painter->fillRect(option.rect, QColor(255, 140, 0, 120));
|
||||
painter->restore();
|
||||
qDebug() << " --- PAINT highlight:";
|
||||
//if ( m_rowOpacities.contains(row))
|
||||
paintHighlightRow(painter,option,index);
|
||||
}
|
||||
*/
|
||||
paintHighlightRow(painter,option,index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BCDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
/*
|
||||
qreal opacity = m_rowOpacities.value(row);
|
||||
if (opacity > 0.01)
|
||||
{
|
||||
painter->save();
|
||||
painter->setOpacity(opacity);
|
||||
painter->fillRect(option.rect, QColor(255, 140, 0, 120));
|
||||
painter->restore();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
void BCItemDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
int row = index.row();
|
||||
qreal opacity = m_rowOpacities.value(row);
|
||||
painter->setOpacity(opacity);
|
||||
// Margin von 4px
|
||||
QRect itemRect = option.rect.adjusted(4, 4, -4, -4);
|
||||
QRect itemRect = option.rect.adjusted(3, 3, -3, -3);
|
||||
|
||||
// Border von 2px berücksichtigen (nach innen)
|
||||
QRect contentRect = itemRect.adjusted(2, 2, -2, -2);
|
||||
|
||||
// painter->fillRect(contentRect,Qt::green);
|
||||
/*
|
||||
// Hintergrund (weiß)
|
||||
painter->setBrush(Qt::white);
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->drawRoundedRect(itemRect, 8, 8);
|
||||
|
||||
*/
|
||||
// Border (2px solid #2196F3)
|
||||
QPen borderPen( Qt::red, 2);
|
||||
QPen borderPen( Qt::red, 1);
|
||||
painter->setPen(borderPen);
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
painter->drawRoundedRect(itemRect, 8, 8);
|
||||
painter->drawRoundedRect(itemRect, 2, 2);
|
||||
|
||||
// Padding von 8px für den Content
|
||||
QRect textRect = contentRect.adjusted(8, 8, -8, -8);
|
||||
//QRect textRect = contentRect.adjusted(8, 8, -8, -8);
|
||||
|
||||
/*
|
||||
// Text zeichnen
|
||||
painter->setPen(Qt::black); // oder option.palette.color(QPalette::Text)
|
||||
QString text = index.data(Qt::DisplayRole).toString();
|
||||
painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text);
|
||||
|
||||
*/
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
void BCDelegate::onHighlightRow(int row)
|
||||
void BCItemDelegate::onHighlightRow(int row)
|
||||
{
|
||||
qDebug() << " --- should highlight: " << row;
|
||||
|
||||
@@ -334,7 +323,7 @@ void BCDelegate::onHighlightRow(int row)
|
||||
}
|
||||
|
||||
// Optional: alle Highlights sofort clearen
|
||||
void BCDelegate::clearAllHighlights()
|
||||
void BCItemDelegate::clearAllHighlights()
|
||||
{
|
||||
for(auto* anim : std::as_const(m_rowAnimations))
|
||||
{
|
||||
@@ -350,11 +339,11 @@ void BCDelegate::clearAllHighlights()
|
||||
}
|
||||
}
|
||||
|
||||
void BCDelegate::updateRow(int row)
|
||||
void BCItemDelegate::updateRow(int row)
|
||||
{
|
||||
if (_view && _view->model() && row >= 0)
|
||||
{
|
||||
QModelIndex idx = _view->model()->index(row, 0);
|
||||
QModelIndex idx = _view->model()->index(row,1);
|
||||
QRect rect = _view->visualRect(idx);
|
||||
if (!rect.isEmpty()) {
|
||||
_view->viewport()->update(rect);
|
||||
@@ -362,35 +351,3 @@ void BCDelegate::updateRow(int row)
|
||||
}
|
||||
}
|
||||
|
||||
QString BCDelegate::formatDisplayString(const QModelIndex& index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QString();
|
||||
|
||||
QString displayStr;
|
||||
|
||||
/*
|
||||
QString label = index.data(BCValueListModel::LabelRole).toString();
|
||||
QVariant value = index.data(BCValueListModel::ValueRole);
|
||||
QString unit = index.data(BCValueListModel::UnitRole).toString();
|
||||
|
||||
QString valueStr = value.toString();
|
||||
|
||||
// Formatierung für Zahlen
|
||||
bool ok;
|
||||
double numValue = value.toDouble(&ok);
|
||||
if (ok) {
|
||||
valueStr = QString::number(numValue, 'f', 2);
|
||||
}
|
||||
|
||||
// Zusammensetzen des Anzeige-Strings
|
||||
QString displayStr = label;
|
||||
if (!displayStr.isEmpty() && !valueStr.isEmpty())
|
||||
displayStr += ": ";
|
||||
displayStr += valueStr;
|
||||
if (!unit.isEmpty())
|
||||
displayStr += " " + unit;
|
||||
*/
|
||||
|
||||
return displayStr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user