76 lines
2.6 KiB
C++
76 lines
2.6 KiB
C++
#ifndef LABELVOLTAGEDELEGATE_H
|
|
#define LABELVOLTAGEDELEGATE_H
|
|
|
|
#include <QStyledItemDelegate>
|
|
#include <QPainter>
|
|
|
|
class LabelVoltageDelegate : public QStyledItemDelegate
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
LabelVoltageDelegate(QObject *parent = nullptr);
|
|
|
|
public:
|
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
|
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
|
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
|
|
|
private:
|
|
int m_circleSize;
|
|
|
|
class RectClass
|
|
{
|
|
public:
|
|
void draw(QPainter *painter, const QRectF &rectL, QColor colorL = QColor("#FFFFFF"), int radiusL = 0) const
|
|
{
|
|
painter->save();
|
|
// Rect
|
|
QPen penw(colorL);
|
|
painter->setPen(penw);
|
|
painter->drawRect(rectL);
|
|
painter->restore();
|
|
}
|
|
};
|
|
|
|
|
|
class LineWithText
|
|
{
|
|
public:
|
|
void draw(QPainter *painter, const QRectF &rectL, QColor colorL = QColor("#FFFFFF"), int radiusL = 0,
|
|
const QRectF rectT=QRectF(0,0,0,0), QString text = "", QColor colorT = QColor("#000000"), QFont fontT = QFont("Arial", 13, QFont::Bold) , QColor colorBackground = QColor("#FFFFFF")) const
|
|
//;
|
|
//void LineWithText::draw (QPainter *painter, const QRectF &rectL, QColor colorL, int radiusL,
|
|
// const QRectF rectT, QString text, QColor colorT, QFont fontT ) const
|
|
{
|
|
painter->save();
|
|
|
|
// Line
|
|
QPen pen(colorL);
|
|
pen.setStyle(Qt::DotLine);
|
|
painter->setPen(pen);
|
|
painter->drawLine(rectL.left(), rectL.top(), rectL.right()*1.15, rectL.bottom());
|
|
// Rect
|
|
QPen penw(colorBackground);
|
|
painter->setPen(penw);
|
|
QFontMetrics fm(fontT);
|
|
double width = 0.0;
|
|
//width = fm.horizontalAdvance(text);
|
|
int width1 = fm.lineWidth();
|
|
int len = ((rectL.right()/2)-(width/2));
|
|
painter->drawRect(rectL.left()+27, rectL.top(), width*1.2, rectL.bottom());
|
|
// Text
|
|
painter->setFont(fontT);
|
|
painter->setPen(QPen(colorT));
|
|
painter->drawText(rectT, Qt::AlignCenter, text);
|
|
|
|
painter->restore();
|
|
}
|
|
};
|
|
|
|
};
|
|
|
|
#endif // LABELVOLTAGEDELEGATE_H
|