Hightlight lines when touched.
This commit is contained in:
@@ -3,14 +3,17 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QWidget>
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QTimer>
|
||||
#include <QListView>
|
||||
|
||||
#include "bcitemdelegate.h"
|
||||
#include "bcvalue.h"
|
||||
#include "qapplication.h"
|
||||
|
||||
|
||||
BCItemDelegate::BCItemDelegate(QObject *parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
BCItemDelegate::BCItemDelegate(QListView *view)
|
||||
: QStyledItemDelegate(view), _view{view}
|
||||
{
|
||||
|
||||
}
|
||||
@@ -26,7 +29,7 @@ QString BCItemDelegate::displayText(const QVariant& dataValue, const QLocale& lo
|
||||
// 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.value.toString(), "mm1");
|
||||
return QString("%1: %2 %3").arg(bc.label, bc.value.toString(), "mmX");
|
||||
}
|
||||
|
||||
// Fallback für normale Strings/Zahlen
|
||||
@@ -132,6 +135,51 @@ QSize BCItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelI
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void BCItemDelegate::onHighlightRow(int row)
|
||||
{
|
||||
qDebug() << " --- should highlight: " << row;
|
||||
_highlightedRow = row;
|
||||
|
||||
// Trigger Repaint der View (damit der Rahmen sofort erscheint)
|
||||
_view->viewport()->update();
|
||||
|
||||
// Timer: Nach 1 Sekunde wieder ausschalten (Temporär)
|
||||
QTimer::singleShot(1000, this, [=, this]()
|
||||
{
|
||||
if(_highlightedRow == row)
|
||||
{ // Nur zurücksetzen, wenn es noch dieselbe Zeile ist
|
||||
_highlightedRow = -1;
|
||||
if (_view)
|
||||
_view->viewport()->update();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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-Overly: 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();
|
||||
}
|
||||
}
|
||||
QString BCItemDelegate::formatDisplayString(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
|
||||
Reference in New Issue
Block a user