55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
/**
|
|
* @file PaiListItemDelegate.cpp
|
|
* @date 2014-11-25
|
|
*/
|
|
#include <QPainter>
|
|
#include <QBrush>
|
|
#include <QLinearGradient>
|
|
#include <QApplication>
|
|
|
|
#include "PaiListItemDelegate.h"
|
|
|
|
using namespace pai::gui;
|
|
|
|
PaiListItemDelegate::PaiListItemDelegate(QObject *pParent) :
|
|
QStyledItemDelegate(pParent),
|
|
m_GridPen(QColor("#C9D5DC"), 0, Qt::SolidLine)
|
|
{
|
|
|
|
}
|
|
|
|
void PaiListItemDelegate::paint(QPainter *pPainter, const QStyleOptionViewItem & option, const QModelIndex & index) const
|
|
{
|
|
QStyleOptionViewItemV4 opt = option;
|
|
initStyleOption(&opt, index);
|
|
bool bSelected = opt.state & QStyle::State_Selected;
|
|
QPointF startPoint(0, 0);
|
|
QPointF finalPoint(0, opt.rect.height());
|
|
QLinearGradient linearGrad(startPoint, finalPoint);
|
|
|
|
if(bSelected)
|
|
{
|
|
opt.state = opt.state & ~QStyle::State_Selected;
|
|
linearGrad.setColorAt(0, QColor("#F6FDFF"));
|
|
linearGrad.setColorAt(1, QColor("#DAF3FD"));
|
|
opt.backgroundBrush = QBrush(linearGrad);
|
|
}
|
|
else
|
|
{
|
|
opt.backgroundBrush = QBrush(Qt::white);
|
|
}
|
|
|
|
const QWidget *pWidget = opt.widget;
|
|
QStyle *pStyle = pWidget ? pWidget->style() : QApplication::style();
|
|
|
|
pStyle->drawControl(QStyle::CE_ItemViewItem, &opt, pPainter, pWidget);
|
|
|
|
QPen oldPen(pPainter->pen());
|
|
pPainter->setPen(m_GridPen);
|
|
|
|
// paint horizontal lines
|
|
pPainter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
|
|
|
|
pPainter->setPen(oldPen);
|
|
}
|