delegate cleanups
This commit is contained in:
@@ -129,20 +129,20 @@ void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option
|
||||
|
||||
XQItem& item = xqItemFromIndex( index );
|
||||
|
||||
|
||||
switch( item.renderStyle() )
|
||||
{
|
||||
case XQItem::HeaderStyle :
|
||||
return drawHeaderStyle( painter, option, index );
|
||||
return drawHeaderStyle( painter, option, item );
|
||||
|
||||
case XQItem::ComboBoxStyle :
|
||||
return drawComboBoxStyle( painter, option, index );
|
||||
/*
|
||||
case XQItem::SpinBoxStyle :
|
||||
return drawSpinBoxStyle( painter, option, index );
|
||||
return drawComboBoxStyle( painter, option, item );
|
||||
|
||||
case XQItem::ColorBarStyle :
|
||||
return drawProgressBarStyle( painter, option, index );
|
||||
qDebug() << " --- JAJA: " << index.data().toString();
|
||||
return drawColorBarStyle( painter, option, item );
|
||||
/*
|
||||
case XQItem::SpinBoxStyle :
|
||||
return drawSpinBoxStyle( painter, option, item );
|
||||
*/
|
||||
case XQItem::HiddenStyle :
|
||||
return;
|
||||
@@ -158,15 +158,14 @@ void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option
|
||||
|
||||
//! einen section header im header-style zeichnen
|
||||
|
||||
void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewItem& option, const XQItem& item) const
|
||||
{
|
||||
QStyleOptionHeader headerOption;
|
||||
|
||||
XQItem& item = xqItemFromIndex( index );
|
||||
// use the header as "parent" for style init
|
||||
QWidget* srcWidget = treeTable();//->header();
|
||||
QWidget* srcWidget = treeTable();//->header();
|
||||
headerOption.initFrom(srcWidget);
|
||||
headerOption.text = index.data(Qt::DisplayRole).toString();
|
||||
headerOption.text = item.text();
|
||||
headerOption.rect = option.rect.adjusted(0,0,0,3);
|
||||
headerOption.styleObject = option.styleObject;
|
||||
// __ch: reduce inner offset when painting
|
||||
@@ -193,32 +192,43 @@ void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewIt
|
||||
|
||||
//! firz
|
||||
|
||||
void XQItemDelegate::drawProgressBarStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
void XQItemDelegate::drawColorBarStyle(QPainter* painter, const QStyleOptionViewItem& option, const XQItem& item) const
|
||||
{
|
||||
QStyleOptionProgressBar progressBarOption;
|
||||
progressBarOption.rect = option.rect;
|
||||
progressBarOption.state = option.state;
|
||||
progressBarOption.direction = option.direction;
|
||||
progressBarOption.fontMetrics = option.fontMetrics;
|
||||
progressBarOption.palette = option.palette;
|
||||
progressBarOption.styleObject = option.styleObject;
|
||||
progressBarOption.minimum = 0;
|
||||
progressBarOption.maximum = 100;
|
||||
progressBarOption.progress = 67; // Fester Wert
|
||||
progressBarOption.text = QStringLiteral("67%");
|
||||
progressBarOption.textVisible = true;
|
||||
progressBarOption.textAlignment = Qt::AlignCenter;
|
||||
//QStyledItemDelegate::paint(painter, option, item);
|
||||
|
||||
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
|
||||
// Wert aus dem Modell holen
|
||||
bool ok;
|
||||
int value = item.data(Qt::EditRole).toInt(&ok);
|
||||
if (!ok || value < 0 || value > 100)
|
||||
return;
|
||||
|
||||
// Balkenbereich berechnen
|
||||
QRect rect = option.rect.adjusted(2, 2, -2, -2); // etwas Padding
|
||||
int barWidth = static_cast<int>(rect.width() * (value / 100.0));
|
||||
|
||||
// Balken zeichnen
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
QRect barRect(rect.left(), rect.top(), barWidth, rect.height());
|
||||
QColor barColor = QColor(100, 180, 255); // z. B. hellblau
|
||||
painter->setBrush(barColor);
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->drawRect(barRect);
|
||||
|
||||
// Text (Zahl) zentriert zeichnen
|
||||
painter->setPen(Qt::black);
|
||||
//painter->drawText(rect, Qt::AlignCenter, QString::number(value)+" %");
|
||||
painter->drawText(rect, Qt::AlignCenter, item.text() );
|
||||
|
||||
painter->restore();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//! Zeichnet das Item als combo box.
|
||||
|
||||
void XQItemDelegate::drawComboBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
void XQItemDelegate::drawComboBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const XQItem& item) const
|
||||
{
|
||||
QWidget* srcWidget = qobject_cast<QWidget*>(option.styleObject);
|
||||
QStyleOptionComboBox comboOption;
|
||||
@@ -226,15 +236,14 @@ void XQItemDelegate::drawComboBoxStyle(QPainter* painter, const QStyleOptionView
|
||||
|
||||
comboOption.initFrom(srcWidget);
|
||||
|
||||
XQItem& item = xqItemFromIndex( index );
|
||||
// set options
|
||||
comboOption.rect = option.rect;
|
||||
comboOption.state = option.state | QStyle::State_Selected | QStyle::State_Enabled;
|
||||
// not editable => only visual, but painter needs to know it
|
||||
comboOption.editable = false;
|
||||
comboOption.currentText = item.text();//index.data(Qt::DisplayRole).toString();
|
||||
comboOption.currentText = item.text();
|
||||
// decoration (if any)
|
||||
comboOption.currentIcon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
|
||||
comboOption.currentIcon = qvariant_cast<QIcon>(item.data(Qt::DecorationRole));
|
||||
comboOption.iconSize = comboOption.currentIcon.actualSize(QSize(option.rect.height() - 3, option.rect.height() - 3));
|
||||
|
||||
// save painter
|
||||
@@ -250,12 +259,12 @@ void XQItemDelegate::drawComboBoxStyle(QPainter* painter, const QStyleOptionView
|
||||
|
||||
//! Zeichnet das Item als spin box.
|
||||
|
||||
void XQItemDelegate::drawSpinBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
void XQItemDelegate::drawSpinBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const XQItem& item) const
|
||||
{
|
||||
qDebug() << " --- jawas? SPINBOX!";
|
||||
bool isInt = false;
|
||||
// Den Wert aus dem Modell holen.
|
||||
QString textToShow = index.data(Qt::DisplayRole).toString();
|
||||
QString textToShow = item.data(Qt::DisplayRole).toString();
|
||||
textToShow.toInt(&isInt);
|
||||
|
||||
if (isInt) {
|
||||
@@ -285,9 +294,6 @@ void XQItemDelegate::drawSpinBoxStyle(QPainter* painter, const QStyleOptionViewI
|
||||
// Die Flags sorgen für die korrekte Ausrichtung (rechtsbündig, vertikal zentriert).
|
||||
painter->drawText(textRect, Qt::AlignRight | Qt::AlignVCenter, textToShow);
|
||||
|
||||
} else {
|
||||
// Fallback für alle anderen Datentypen.
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,3 +397,4 @@ void XQItemDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionVie
|
||||
//qDebug() << " --- update Editor Geometry";
|
||||
QStyledItemDelegate::updateEditorGeometry(editor, option, index);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user