0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 08:34:38 +03:00

Property delegate updated

This commit is contained in:
Arin Alex 2017-10-05 01:39:16 +03:00
parent 3303d4461b
commit b0137f9f7f
2 changed files with 41 additions and 28 deletions

View File

@ -36,13 +36,16 @@
#include "lrglobal.h"
LimeReport::PropertyDelegate::PropertyDelegate(QObject *parent)
:QItemDelegate(parent), m_objectInspector(NULL), m_editingItem(0), m_isEditing(false)
:QStyledItemDelegate(parent), m_objectInspector(NULL), m_editingItem(0), m_isEditing(false)
{}
void LimeReport::PropertyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (!index.isValid()) return;
QStyleOptionViewItemV4 opt = option;
QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
LimeReport::ObjectPropItem *node = static_cast<LimeReport::ObjectPropItem*>(index.internalPointer());
if (node){
if (!node->isHaveValue()){
@ -54,31 +57,17 @@ void LimeReport::PropertyDelegate::paint(QPainter *painter, const QStyleOptionVi
painter->save();
painter->setPen(option.palette.color(QPalette::HighlightedText));
painter->setBackground(QBrush(option.palette.color(QPalette::Highlight)));
drawBackground(painter,option,index);
//drawBackground(painter,option,index);
cellOpt.widget->style()->drawPrimitive(QStyle::PE_IndicatorBranch,&primitiveOpt,painter);
cellOpt.rect.adjust(primitiveOpt.rect.width(),0,0,0);
cellOpt.font.setBold(true);
cellOpt.palette.setColor(QPalette::Text,cellOpt.palette.color(QPalette::BrightText));
drawDisplay(painter,cellOpt,cellOpt.rect,LimeReport::extractClassName(node->propertyName()));
cellOpt.text = LimeReport::extractClassName(node->propertyName());
style->drawControl(QStyle::CE_ItemViewItem, &cellOpt, painter, cellOpt.widget);
//drawDisplay(painter,cellOpt,cellOpt.rect,LimeReport::extractClassName(node->propertyName()));
painter->restore();
}
} else
{
if (index.column()==0){
QPointF start(
option.rect.x()+option.rect.width()-1,
option.rect.y()
);
QPointF end(
option.rect.x()+option.rect.width()-1,
option.rect.y()+option.rect.height()
);
painter->save();
QColor color = static_cast<QRgb>(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &option));
painter->setPen(color);
painter->drawLine(start,end);
painter->restore();
}
} else {
StyleOptionViewItem so = option;
if ((node->isValueReadonly())&&(!node->isHaveChildren())) {
@ -98,14 +87,36 @@ void LimeReport::PropertyDelegate::paint(QPainter *painter, const QStyleOptionVi
else
so.palette.setColor(QPalette::Text,Qt::black);
drawBackground(painter,option,index);
if (!node->paint(painter,so,index))
QItemDelegate::paint(painter, so, index);
// drawBackground(painter,option,index);
opt.text = "";
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget);
if (!node->paint(painter,so,index)){
so.state &= ~QStyle::State_HasFocus;
QStyledItemDelegate::paint(painter, so, index);
}
if (index.column()==0){
QPointF start(
option.rect.x()+option.rect.width()-1,
option.rect.y()
);
QPointF end(
option.rect.x()+option.rect.width()-1,
option.rect.y()+option.rect.height()
);
painter->save();
QColor color = static_cast<QRgb>(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &option));
painter->setPen(color);
painter->drawLine(start,end);
painter->restore();
}
}
}
}
QSize LimeReport::PropertyDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &/*index*/) const
QSize LimeReport::PropertyDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QSize size=option.rect.size();
size.setHeight(option.fontMetrics.height()+
@ -113,8 +124,10 @@ QSize LimeReport::PropertyDelegate::sizeHint(const QStyleOptionViewItem &option,
#ifdef Q_OS_MAC
+QApplication::style()->pixelMetric(QStyle::PM_FocusFrameVMargin)
#endif
+2);
return size;
+4);
//return size;
QSize defaultSize = QStyledItemDelegate::sizeHint(option, index);
return size.height() > defaultSize.height() ? size : defaultSize;
}
QWidget * LimeReport::PropertyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const

View File

@ -40,8 +40,8 @@
namespace LimeReport{
class ObjectInspectorWidget;
class PropertyDelegate : public QItemDelegate
//class PropertyDelegate : public QStyledItemDelegate
//class PropertyDelegate : public QItemDelegate
class PropertyDelegate : public QStyledItemDelegate
{
Q_OBJECT
public: