mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-08-15 08:29:23 +00:00
60 lines
1.4 KiB
C++
60 lines
1.4 KiB
C++
#ifndef CCUSTOMDELEGATE_H
|
|
#define CCUSTOMDELEGATE_H
|
|
|
|
#include <QFont>
|
|
#include <QFontMetrics>
|
|
#include <QPen>
|
|
#include <QStyledItemDelegate>
|
|
|
|
/** Font parameters for rendering text */
|
|
struct SDelegateFontInfo
|
|
{
|
|
QFont NameFont;
|
|
QFont InfoFont;
|
|
QFontMetrics NameFontMetrics;
|
|
QFontMetrics InfoFontMetrics;
|
|
QPen NamePen;
|
|
QPen InfoPen;
|
|
int Margin;
|
|
int Spacing;
|
|
|
|
SDelegateFontInfo()
|
|
: NameFontMetrics(NameFont), InfoFontMetrics(InfoFont) {}
|
|
};
|
|
|
|
/** Common base class of custom item delegate implementations */
|
|
class CCustomDelegate : public QStyledItemDelegate
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit CCustomDelegate(QObject* pParent = 0)
|
|
: QStyledItemDelegate(pParent)
|
|
{}
|
|
|
|
virtual SDelegateFontInfo GetFontInfo(const QStyleOptionViewItem& rkOption) const
|
|
{
|
|
SDelegateFontInfo Info;
|
|
|
|
Info.NameFont = rkOption.font;
|
|
Info.NameFont.setPointSize( rkOption.font.pointSize() + 1 );
|
|
Info.NameFontMetrics = QFontMetrics(Info.NameFont);
|
|
|
|
Info.InfoFont = rkOption.font;
|
|
Info.InfoFont.setPointSize( rkOption.font.pointSize() - 1 );
|
|
Info.InfoFontMetrics = QFontMetrics(Info.InfoFont);
|
|
|
|
Info.NamePen = QPen(rkOption.palette.text(), 1.f);
|
|
|
|
Info.InfoPen = QPen(rkOption.palette.text(), 1.f);
|
|
Info.InfoPen.setColor( Info.InfoPen.color().darker(140) );
|
|
|
|
Info.Margin = 3;
|
|
Info.Spacing = 3;
|
|
|
|
return Info;
|
|
}
|
|
};
|
|
|
|
#endif // CCUSTOMDELEGATE_H
|