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);
|
||||
|
|
|
@ -34,7 +34,9 @@ public:
|
|||
|
||||
private:
|
||||
QFont fingerPrintFont;
|
||||
QFont labelFont;
|
||||
QFontMetrics fingerPrintMetrics;
|
||||
QFontMetrics labelFontMetrics;
|
||||
int spaceWidth;
|
||||
|
||||
private:
|
||||
|
|
|
@ -44,11 +44,21 @@ QVariant UI::KeysModel::data(const QModelIndex& index, int role) const {
|
|||
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case Label:
|
||||
answer = keys[i]->label;
|
||||
break;
|
||||
case FingerPrint:
|
||||
answer = keys[i]->fingerPrint;
|
||||
break;
|
||||
case TrustLevel:
|
||||
answer = static_cast<uint8_t>(keys[i]->trustLevel);
|
||||
break;
|
||||
case LastInteraction:
|
||||
answer = keys[i]->lastInteraction;
|
||||
break;
|
||||
case Dirty:
|
||||
answer = false;
|
||||
break;
|
||||
}
|
||||
|
||||
return answer;
|
||||
|
|
|
@ -43,7 +43,9 @@ public:
|
|||
enum Roles {
|
||||
Label = Qt::UserRole + 1,
|
||||
FingerPrint,
|
||||
TrustLevel
|
||||
TrustLevel,
|
||||
LastInteraction,
|
||||
Dirty
|
||||
};
|
||||
|
||||
private:
|
||||
|
|
|
@ -54,8 +54,12 @@ void Omemo::generateMockData()
|
|||
}
|
||||
Shared::KeyInfo info;
|
||||
info.id = i;
|
||||
info.label = QString("test_") + std::to_string(i).c_str();
|
||||
if (i % 3 == 0)
|
||||
info.label = QString("test_") + std::to_string(i).c_str();
|
||||
info.fingerPrint = fp;
|
||||
if (i % 2 == 0)
|
||||
info.lastInteraction = QDateTime::currentDateTime();
|
||||
|
||||
keysModel.addKey(info);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@
|
|||
<enum>QAbstractItemView::ScrollPerItem</enum>
|
||||
</property>
|
||||
<property name="uniformItemSizes">
|
||||
<bool>true</bool>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue