forked from blue/squawk
some thoughts about fonts, lastInteraction and label into keyDelegate
This commit is contained in:
parent
2aed8a1209
commit
15fb4bbd62
15 changed files with 166 additions and 171 deletions
|
@ -29,10 +29,11 @@ constexpr uint8_t maxSingleLineParts = 3;
|
|||
UI::KeyDelegate::KeyDelegate(QObject* parent):
|
||||
QStyledItemDelegate(parent),
|
||||
fingerPrintFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)),
|
||||
labelFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)),
|
||||
fingerPrintMetrics(fingerPrintFont),
|
||||
labelFontMetrics(labelFont),
|
||||
spaceWidth(fingerPrintMetrics.horizontalAdvance(" "))
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
UI::KeyDelegate::~KeyDelegate() {}
|
||||
|
||||
|
@ -48,6 +49,24 @@ void UI::KeyDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
|
|||
painter->restore();
|
||||
}
|
||||
|
||||
QColor q = painter->pen().color();
|
||||
q.setAlpha(180);
|
||||
|
||||
QRect rect = option.rect;
|
||||
rect.adjust(margin, margin, 0, 0);
|
||||
QVariant labelV = index.data(UI::KeysModel::Label);
|
||||
if (labelV.isValid()) {
|
||||
QString label = labelV.toString();
|
||||
if (label.size() > 0) {
|
||||
painter->save();
|
||||
painter->setFont(labelFont);
|
||||
painter->setPen(q);
|
||||
painter->drawText(rect, Qt::AlignLeft | Qt::AlignTop, label);
|
||||
rect.adjust(0, labelFontMetrics.lineSpacing(), 0, 0);
|
||||
painter->restore();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant fingerPrintV = index.data(UI::KeysModel::FingerPrint);
|
||||
if (fingerPrintV.isValid()) {
|
||||
painter->save();
|
||||
|
@ -55,8 +74,6 @@ void UI::KeyDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
|
|||
QByteArray fingerPrint = fingerPrintV.toByteArray();
|
||||
std::vector<QString> parts = getParts(fingerPrint);
|
||||
uint8_t partsLength = parts.size();
|
||||
QRect rect = option.rect;
|
||||
rect.adjust(margin, margin, 0, 0);
|
||||
QRect r;
|
||||
uint8_t firstLine;
|
||||
if (partsLength > maxSingleLineParts)
|
||||
|
@ -73,8 +90,25 @@ void UI::KeyDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
|
|||
rect.adjust(r.width() + spaceWidth ,0, 0, 0);
|
||||
}
|
||||
|
||||
rect.adjust(0, r.height() + fingerPrintMetrics.leading(), 0, 0);
|
||||
rect.setLeft(option.rect.left() + margin);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
QVariant lastV = index.data(UI::KeysModel::LastInteraction);
|
||||
if (lastV.isValid()) {
|
||||
QDateTime last = lastV.toDateTime();
|
||||
if (last.isValid()) {
|
||||
painter->save();
|
||||
painter->setFont(labelFont);
|
||||
painter->setPen(q);
|
||||
painter->drawText(rect, Qt::AlignLeft | Qt::AlignTop, last.toString());
|
||||
rect.adjust(0, labelFontMetrics.lineSpacing(), 0, 0);
|
||||
painter->restore();
|
||||
}
|
||||
}
|
||||
//painter->drawText(option.rect, option.displayAlignment, index.data().toString());
|
||||
|
||||
painter->restore();
|
||||
|
@ -85,6 +119,12 @@ QSize UI::KeyDelegate::sizeHint(const QStyleOptionViewItem& option, const QModel
|
|||
|
||||
int mh = margin * 2;
|
||||
int mw = margin * 2;
|
||||
|
||||
QVariant labelV = index.data(UI::KeysModel::Label);
|
||||
if (labelV.isValid() && labelV.toString().size() > 0) {
|
||||
mh += labelFontMetrics.lineSpacing();
|
||||
}
|
||||
|
||||
QVariant fingerPrintV = index.data(UI::KeysModel::FingerPrint);
|
||||
if (fingerPrintV.isValid()) {
|
||||
QString hex = fingerPrintV.toByteArray().toHex();
|
||||
|
@ -103,7 +143,10 @@ QSize UI::KeyDelegate::sizeHint(const QStyleOptionViewItem& option, const QModel
|
|||
|
||||
mw += firstLine * partSize * spaceWidth + (firstLine - 1) * spaceWidth;
|
||||
}
|
||||
|
||||
QVariant lastV = index.data(UI::KeysModel::LastInteraction);
|
||||
if (lastV.isValid() && lastV.toDateTime().isValid()) {
|
||||
mh += labelFontMetrics.lineSpacing();
|
||||
}
|
||||
|
||||
if (size.width() < mw)
|
||||
size.setWidth(mw);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue