0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-25 00:54:39 +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" #include "lrglobal.h"
LimeReport::PropertyDelegate::PropertyDelegate(QObject *parent) 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 void LimeReport::PropertyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{ {
if (!index.isValid()) return; 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()); LimeReport::ObjectPropItem *node = static_cast<LimeReport::ObjectPropItem*>(index.internalPointer());
if (node){ if (node){
if (!node->isHaveValue()){ if (!node->isHaveValue()){
@ -54,31 +57,17 @@ void LimeReport::PropertyDelegate::paint(QPainter *painter, const QStyleOptionVi
painter->save(); painter->save();
painter->setPen(option.palette.color(QPalette::HighlightedText)); painter->setPen(option.palette.color(QPalette::HighlightedText));
painter->setBackground(QBrush(option.palette.color(QPalette::Highlight))); 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.widget->style()->drawPrimitive(QStyle::PE_IndicatorBranch,&primitiveOpt,painter);
cellOpt.rect.adjust(primitiveOpt.rect.width(),0,0,0); cellOpt.rect.adjust(primitiveOpt.rect.width(),0,0,0);
cellOpt.font.setBold(true); cellOpt.font.setBold(true);
cellOpt.palette.setColor(QPalette::Text,cellOpt.palette.color(QPalette::BrightText)); 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());
painter->restore(); style->drawControl(QStyle::CE_ItemViewItem, &cellOpt, painter, cellOpt.widget);
} //drawDisplay(painter,cellOpt,cellOpt.rect,LimeReport::extractClassName(node->propertyName()));
} 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(); painter->restore();
} }
} else {
StyleOptionViewItem so = option; StyleOptionViewItem so = option;
if ((node->isValueReadonly())&&(!node->isHaveChildren())) { if ((node->isValueReadonly())&&(!node->isHaveChildren())) {
@ -98,14 +87,36 @@ void LimeReport::PropertyDelegate::paint(QPainter *painter, const QStyleOptionVi
else else
so.palette.setColor(QPalette::Text,Qt::black); so.palette.setColor(QPalette::Text,Qt::black);
drawBackground(painter,option,index); // drawBackground(painter,option,index);
if (!node->paint(painter,so,index))
QItemDelegate::paint(painter, so, 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(); QSize size=option.rect.size();
size.setHeight(option.fontMetrics.height()+ size.setHeight(option.fontMetrics.height()+
@ -113,8 +124,10 @@ QSize LimeReport::PropertyDelegate::sizeHint(const QStyleOptionViewItem &option,
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
+QApplication::style()->pixelMetric(QStyle::PM_FocusFrameVMargin) +QApplication::style()->pixelMetric(QStyle::PM_FocusFrameVMargin)
#endif #endif
+2); +4);
return size; //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 QWidget * LimeReport::PropertyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const

View File

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