forked from blue/squawk
trust level display in delegate, list size tweaking
This commit is contained in:
parent
d4bf7e599a
commit
b72a837754
@ -144,6 +144,8 @@ enum class TrustLevel {
|
||||
authenticated
|
||||
};
|
||||
Q_ENUM_NS(TrustLevel)
|
||||
static const TrustLevel TrustLevelHighest = TrustLevel::undecided;
|
||||
static const TrustLevel TrustLevelLowest = TrustLevel::authenticated;
|
||||
|
||||
enum class EncryptionProtocol {
|
||||
omemo
|
||||
|
@ -113,6 +113,14 @@ Shared::Global::Global():
|
||||
tr("Always Ask", "AccountPassword"),
|
||||
tr("KWallet", "AccountPassword")
|
||||
}),
|
||||
trustLevel({
|
||||
tr("Undecided", "TrustLevel"),
|
||||
tr("Automatically distrusted", "TrustLevel"),
|
||||
tr("Manually distrusted", "TrustLevel"),
|
||||
tr("Automatically trusted", "TrustLevel"),
|
||||
tr("Manually trusted", "TrustLevel"),
|
||||
tr("Authenticated", "TrustLevel")
|
||||
}),
|
||||
accountPasswordDescription({
|
||||
tr("Your password is going to be stored in config file in plain text", "AccountPasswordDescription"),
|
||||
tr("Your password is going to be stored in config file but jammed with constant encryption key you can find in program source code. It might look like encryption but it's not", "AccountPasswordDescription"),
|
||||
@ -123,10 +131,12 @@ Shared::Global::Global():
|
||||
defaultSystemPalette(QApplication::palette()),
|
||||
omemoSupport(OMEMO_SUPPORT),
|
||||
defaultFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont)),
|
||||
monospaceFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)),
|
||||
smallFont(getFont(QFontDatabase::SmallestReadableFont, false, true)),
|
||||
headerFont(getFont(QFontDatabase::TitleFont, true, false, 1.1)),
|
||||
titleFont(getFont(QFontDatabase::TitleFont, true, false, 1.3)),
|
||||
defaultFontMetrics(defaultFont),
|
||||
monospaceMetrics(monospaceFont),
|
||||
smallFontMetrics(smallFont),
|
||||
headerFontMetrics(headerFont),
|
||||
titleFontMetrics(titleFont),
|
||||
@ -256,6 +266,11 @@ QString Shared::Global::getName(Shared::AccountPassword ap)
|
||||
return instance->accountPassword[static_cast<int>(ap)];
|
||||
}
|
||||
|
||||
QString Shared::Global::getName(Shared::TrustLevel tl)
|
||||
{
|
||||
return instance->trustLevel[static_cast<int>(tl)];
|
||||
}
|
||||
|
||||
void Shared::Global::setSupported(const QString& pluginName, bool support)
|
||||
{
|
||||
std::map<QString, bool>::iterator itr = instance->pluginSupport.find(pluginName);
|
||||
@ -405,3 +420,4 @@ FROM_INT_INPL(Shared::SubscriptionState)
|
||||
FROM_INT_INPL(Shared::AccountPassword)
|
||||
FROM_INT_INPL(Shared::Avatar)
|
||||
FROM_INT_INPL(Shared::Availability)
|
||||
FROM_INT_INPL(Shared::TrustLevel)
|
||||
|
@ -74,6 +74,7 @@ namespace Shared {
|
||||
static QString getName(Role rl);
|
||||
static QString getName(Message::State rl);
|
||||
static QString getName(AccountPassword ap);
|
||||
static QString getName(TrustLevel tl);
|
||||
|
||||
static QString getDescription(AccountPassword ap);
|
||||
|
||||
@ -84,6 +85,7 @@ namespace Shared {
|
||||
const std::deque<QString> role;
|
||||
const std::deque<QString> messageState;
|
||||
const std::deque<QString> accountPassword;
|
||||
const std::deque<QString> trustLevel;
|
||||
|
||||
const std::deque<QString> accountPasswordDescription;
|
||||
|
||||
@ -103,10 +105,12 @@ namespace Shared {
|
||||
static void setStyle(const QString& style);
|
||||
const bool omemoSupport;
|
||||
QFont defaultFont;
|
||||
QFont monospaceFont;
|
||||
QFont smallFont;
|
||||
QFont headerFont;
|
||||
QFont titleFont;
|
||||
QFontMetrics defaultFontMetrics;
|
||||
QFontMetrics monospaceMetrics;
|
||||
QFontMetrics smallFontMetrics;
|
||||
QFontMetrics headerFontMetrics;
|
||||
QFontMetrics titleFontMetrics;
|
||||
|
@ -15,4 +15,6 @@ target_sources(squawk PRIVATE
|
||||
resizer.h
|
||||
shadowoverlay.cpp
|
||||
shadowoverlay.h
|
||||
expandinglist.cpp
|
||||
expandinglist.h
|
||||
)
|
||||
|
43
ui/utils/expandinglist.cpp
Normal file
43
ui/utils/expandinglist.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
// Squawk messenger.
|
||||
// Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "expandinglist.h"
|
||||
|
||||
QSize ExpandingList::viewportSizeHint() const {
|
||||
if (QAbstractItemView::sizeAdjustPolicy() != QAbstractScrollArea::AdjustToContents)
|
||||
return QListView::viewportSizeHint();
|
||||
|
||||
if (model() == nullptr)
|
||||
return QSize(0, 0);
|
||||
if (model()->rowCount() == 0)
|
||||
return QSize(0, 0);
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))
|
||||
const int rowCount = model()->rowCount();
|
||||
int height = 0;
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
height += QListView::sizeHintForRow(i);
|
||||
}
|
||||
return QSize(QListView::viewportSizeHint().width(), height);
|
||||
#else
|
||||
return QListView::viewportSizeHint();
|
||||
#endif
|
||||
}
|
||||
|
||||
QSize ExpandingList::minimumSizeHint() const {
|
||||
return viewportSizeHint();
|
||||
}
|
||||
|
31
ui/utils/expandinglist.h
Normal file
31
ui/utils/expandinglist.h
Normal file
@ -0,0 +1,31 @@
|
||||
// Squawk messenger.
|
||||
// Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef EXPANDINGLIST_H
|
||||
#define EXPANDINGLIST_H
|
||||
|
||||
#include <QListView>
|
||||
|
||||
class ExpandingList : public QListView {
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QListView::QListView; //explicit constructor inheriatnce
|
||||
|
||||
QSize viewportSizeHint() const override;
|
||||
QSize minimumSizeHint() const override;
|
||||
};
|
||||
|
||||
#endif // EXPANDINGLIST_H
|
@ -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…
Reference in New Issue
Block a user