trust level display in delegate, list size tweaking
This commit is contained in:
parent
d4bf7e599a
commit
b72a837754
10 changed files with 203 additions and 27 deletions
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "keydelegate.h"
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
|
||||
#include "keysmodel.h"
|
||||
#include <shared/global.h>
|
||||
|
@ -26,10 +27,12 @@ constexpr uint8_t maxSingleLineParts = 3;
|
|||
|
||||
UI::KeyDelegate::KeyDelegate(QObject* parent):
|
||||
QStyledItemDelegate(parent),
|
||||
fingerPrintFont(Shared::Global::getInstance()->defaultFont),
|
||||
defaultFont(Shared::Global::getInstance()->defaultFont),
|
||||
fingerPrintFont(Shared::Global::getInstance()->monospaceFont),
|
||||
labelFont(Shared::Global::getInstance()->smallFont),
|
||||
fingerPrintMetrics(Shared::Global::getInstance()->defaultFontMetrics),
|
||||
labelFontMetrics(Shared::Global::getInstance()->smallFontMetrics),
|
||||
defaultMetrics(Shared::Global::getInstance()->defaultFontMetrics),
|
||||
fingerPrintMetrics(Shared::Global::getInstance()->monospaceMetrics),
|
||||
labelMetrics(Shared::Global::getInstance()->smallFontMetrics),
|
||||
spaceWidth(fingerPrintMetrics.horizontalAdvance(" "))
|
||||
{}
|
||||
|
||||
|
@ -47,11 +50,14 @@ void UI::KeyDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
|
|||
painter->restore();
|
||||
}
|
||||
|
||||
QRect r;
|
||||
int maxRight = 0;
|
||||
int leftOrigin = option.rect.left() + margin;
|
||||
QColor q = painter->pen().color();
|
||||
q.setAlpha(180);
|
||||
|
||||
QRect rect = option.rect;
|
||||
rect.adjust(margin, margin, 0, 0);
|
||||
rect.adjust(margin, margin, -margin, -margin);
|
||||
QVariant labelV = index.data(UI::KeysModel::Label);
|
||||
if (labelV.isValid()) {
|
||||
QString label = labelV.toString();
|
||||
|
@ -59,8 +65,9 @@ void UI::KeyDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
|
|||
painter->save();
|
||||
painter->setFont(labelFont);
|
||||
painter->setPen(q);
|
||||
painter->drawText(rect, Qt::AlignLeft | Qt::AlignTop, label);
|
||||
rect.adjust(0, labelFontMetrics.lineSpacing(), 0, 0);
|
||||
painter->drawText(rect, Qt::AlignLeft | Qt::AlignTop, label, &r);
|
||||
rect.adjust(0, labelMetrics.lineSpacing(), 0, 0);
|
||||
maxRight = std::max(r.width(), maxRight);
|
||||
painter->restore();
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +79,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 r;
|
||||
uint8_t firstLine;
|
||||
if (partsLength > maxSingleLineParts)
|
||||
firstLine = partsLength / 2 + partsLength % 2;
|
||||
|
@ -81,15 +87,17 @@ void UI::KeyDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
|
|||
|
||||
for (uint8_t i = 0; i < partsLength; ++i) {
|
||||
if (i == firstLine) {
|
||||
rect.setLeft(option.rect.left() + margin);
|
||||
maxRight = std::max(rect.left() - leftOrigin - margin, maxRight);
|
||||
rect.setLeft(leftOrigin);
|
||||
rect.adjust(0, r.height() + fingerPrintMetrics.leading(), 0, 0);
|
||||
}
|
||||
painter->drawText(rect, Qt::AlignLeft | Qt::AlignTop, parts[i], &r);
|
||||
rect.adjust(r.width() + spaceWidth ,0, 0, 0);
|
||||
}
|
||||
|
||||
maxRight = std::max(rect.left() - leftOrigin - margin, maxRight);
|
||||
rect.adjust(0, r.height() + fingerPrintMetrics.leading(), 0, 0);
|
||||
rect.setLeft(option.rect.left() + margin);
|
||||
rect.setLeft(leftOrigin);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
@ -102,12 +110,27 @@ void UI::KeyDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
|
|||
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->drawText(rect, Qt::AlignLeft | Qt::AlignTop, last.toString(), &r);
|
||||
rect.adjust(0, labelMetrics.lineSpacing(), 0, 0);
|
||||
maxRight = std::max(r.width(), maxRight);
|
||||
painter->restore();
|
||||
}
|
||||
}
|
||||
//painter->drawText(option.rect, option.displayAlignment, index.data().toString());
|
||||
|
||||
QVariant levelV = index.data(UI::KeysModel::TrustLevel);
|
||||
if (levelV.isValid()) {
|
||||
Shared::TrustLevel level = static_cast<Shared::TrustLevel>(levelV.toUInt());
|
||||
QString levelName = Shared::Global::getName(level);
|
||||
|
||||
if (maxRight > 0)
|
||||
maxRight += margin;
|
||||
rect.setLeft(leftOrigin + maxRight);
|
||||
rect.setTop(option.rect.top() + maxRight);
|
||||
rect.setBottom(option.rect.bottom() - maxRight);
|
||||
painter->setFont(defaultFont);
|
||||
painter->drawText(rect, Qt::AlignLeft | Qt::AlignVCenter, levelName, &r);
|
||||
}
|
||||
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
@ -117,10 +140,15 @@ QSize UI::KeyDelegate::sizeHint(const QStyleOptionViewItem& option, const QModel
|
|||
|
||||
int mh = margin * 2;
|
||||
int mw = margin * 2;
|
||||
int width = 0;
|
||||
|
||||
QVariant labelV = index.data(UI::KeysModel::Label);
|
||||
if (labelV.isValid() && labelV.toString().size() > 0) {
|
||||
mh += labelFontMetrics.lineSpacing();
|
||||
if (labelV.isValid()) {
|
||||
QString label = labelV.toString();
|
||||
if (label.size() > 0) {
|
||||
mh += labelMetrics.lineSpacing();
|
||||
width = labelMetrics.horizontalAdvance(label);
|
||||
}
|
||||
}
|
||||
|
||||
QVariant fingerPrintV = index.data(UI::KeysModel::FingerPrint);
|
||||
|
@ -129,9 +157,8 @@ QSize UI::KeyDelegate::sizeHint(const QStyleOptionViewItem& option, const QModel
|
|||
uint8_t parts = hex.size() / partSize;
|
||||
|
||||
mh += fingerPrintMetrics.height();
|
||||
if (parts > maxSingleLineParts) {
|
||||
if (parts > maxSingleLineParts)
|
||||
mh += fingerPrintMetrics.height() + fingerPrintMetrics.leading();
|
||||
}
|
||||
|
||||
uint8_t firstLine;
|
||||
if (parts > maxSingleLineParts)
|
||||
|
@ -139,13 +166,29 @@ QSize UI::KeyDelegate::sizeHint(const QStyleOptionViewItem& option, const QModel
|
|||
else
|
||||
firstLine = parts;
|
||||
|
||||
mw += firstLine * partSize * spaceWidth + (firstLine - 1) * spaceWidth;
|
||||
width = std::max(width, firstLine * fingerPrintMetrics.horizontalAdvance(hex, partSize) + (firstLine - 1) * spaceWidth);
|
||||
}
|
||||
QVariant lastV = index.data(UI::KeysModel::LastInteraction);
|
||||
if (lastV.isValid() && lastV.toDateTime().isValid()) {
|
||||
mh += labelFontMetrics.lineSpacing();
|
||||
if (lastV.isValid()) {
|
||||
QDateTime last = lastV.toDateTime();
|
||||
if (last.isValid()) {
|
||||
mh += labelMetrics.lineSpacing();
|
||||
QString dt = last.toString();
|
||||
width = std::max(labelMetrics.horizontalAdvance(dt), width);
|
||||
}
|
||||
}
|
||||
|
||||
QVariant levelV = index.data(UI::KeysModel::TrustLevel);
|
||||
if (levelV.isValid()) {
|
||||
Shared::TrustLevel level = static_cast<Shared::TrustLevel>(levelV.toUInt());
|
||||
QString levelName = Shared::Global::getName(level);
|
||||
if (width > 0)
|
||||
width += margin;
|
||||
|
||||
width += defaultMetrics.horizontalAdvance(levelName);
|
||||
}
|
||||
|
||||
mw += width;
|
||||
if (size.width() < mw)
|
||||
size.setWidth(mw);
|
||||
|
||||
|
|
|
@ -33,10 +33,12 @@ public:
|
|||
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||
|
||||
private:
|
||||
const QFont& defaultFont;
|
||||
const QFont& fingerPrintFont;
|
||||
const QFont& labelFont;
|
||||
const QFontMetrics& defaultMetrics;
|
||||
const QFontMetrics& fingerPrintMetrics;
|
||||
const QFontMetrics& labelFontMetrics;
|
||||
const QFontMetrics& labelMetrics;
|
||||
int spaceWidth;
|
||||
|
||||
private:
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "ui_omemo.h"
|
||||
|
||||
#include <random>
|
||||
constexpr uint8_t fingerprintLength = 24;
|
||||
constexpr uint8_t fingerprintLength = 32;
|
||||
|
||||
Omemo::Omemo(QWidget* parent):
|
||||
QWidget(parent),
|
||||
|
|
|
@ -65,21 +65,24 @@
|
|||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout" columnstretch="1,3,1">
|
||||
<item row="1" column="1">
|
||||
<widget class="QListView" name="keysView">
|
||||
<widget class="ExpandingList" name="keysView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||
</property>
|
||||
<property name="showDropIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectColumns</enum>
|
||||
</property>
|
||||
<property name="verticalScrollMode">
|
||||
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollMode">
|
||||
<enum>QAbstractItemView::ScrollPerItem</enum>
|
||||
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||
</property>
|
||||
<property name="uniformItemSizes">
|
||||
<bool>false</bool>
|
||||
|
@ -122,7 +125,29 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QListView" name="unusedKeysView"/>
|
||||
<widget class="ExpandingList" name="unusedKeysView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||
</property>
|
||||
<property name="showDropIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="verticalScrollMode">
|
||||
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollMode">
|
||||
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||
</property>
|
||||
<property name="uniformItemSizes">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="6">
|
||||
<spacer name="spacerLeft">
|
||||
|
@ -156,6 +181,14 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ExpandingList</class>
|
||||
<extends>QListView</extends>
|
||||
<header location="global">ui/utils/expandinglist.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue