some thoughts about fonts, lastInteraction and label into keyDelegate

This commit is contained in:
Blue 2023-01-11 23:45:38 +03:00
parent 2aed8a1209
commit 15fb4bbd62
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
15 changed files with 166 additions and 171 deletions

View File

@ -22,6 +22,7 @@ Shared::KeyInfo::KeyInfo(
uint32_t p_id, uint32_t p_id,
const QByteArray& p_fingerPrint, const QByteArray& p_fingerPrint,
const QString& p_label, const QString& p_label,
const QDateTime& p_lastInteraction,
Shared::TrustLevel p_trustLevel, Shared::TrustLevel p_trustLevel,
Shared::EncryptionProtocol p_protocol, Shared::EncryptionProtocol p_protocol,
bool p_currentDevice bool p_currentDevice
@ -29,6 +30,7 @@ Shared::KeyInfo::KeyInfo(
id(p_id), id(p_id),
fingerPrint(p_fingerPrint), fingerPrint(p_fingerPrint),
label(p_label), label(p_label),
lastInteraction(p_lastInteraction),
trustLevel(p_trustLevel), trustLevel(p_trustLevel),
protocol(p_protocol), protocol(p_protocol),
currentDevice(p_currentDevice) currentDevice(p_currentDevice)
@ -39,6 +41,7 @@ Shared::KeyInfo::KeyInfo():
id(0), id(0),
fingerPrint(), fingerPrint(),
label(), label(),
lastInteraction(),
trustLevel(TrustLevel::undecided), trustLevel(TrustLevel::undecided),
protocol(EncryptionProtocol::omemo), protocol(EncryptionProtocol::omemo),
currentDevice(false) currentDevice(false)
@ -49,6 +52,7 @@ Shared::KeyInfo::KeyInfo(const Shared::KeyInfo& other):
id(other.id), id(other.id),
fingerPrint(other.fingerPrint), fingerPrint(other.fingerPrint),
label(other.label), label(other.label),
lastInteraction(other.lastInteraction),
trustLevel(other.trustLevel), trustLevel(other.trustLevel),
protocol(other.protocol), protocol(other.protocol),
currentDevice(other.currentDevice) currentDevice(other.currentDevice)
@ -59,6 +63,7 @@ Shared::KeyInfo & Shared::KeyInfo::operator=(const Shared::KeyInfo& other) {
id = other.id; id = other.id;
fingerPrint = other.fingerPrint; fingerPrint = other.fingerPrint;
label = other.label; label = other.label;
lastInteraction = other.lastInteraction;
trustLevel = other.trustLevel; trustLevel = other.trustLevel;
protocol = other.protocol; protocol = other.protocol;
currentDevice = other.currentDevice; currentDevice = other.currentDevice;

View File

@ -19,6 +19,7 @@
#include <QString> #include <QString>
#include <QByteArray> #include <QByteArray>
#include <QDateTime>
#include <stdint.h> #include <stdint.h>
@ -31,9 +32,9 @@ class KeyInfo
public: public:
KeyInfo( KeyInfo(
uint32_t id, uint32_t id,
const QByteArray& const QByteArray& fingerPrint,
fingerPrint,
const QString& label, const QString& label,
const QDateTime& lastInteraction,
TrustLevel trustLevel, TrustLevel trustLevel,
EncryptionProtocol protocol = EncryptionProtocol::omemo, EncryptionProtocol protocol = EncryptionProtocol::omemo,
bool currentDevice = false bool currentDevice = false
@ -47,6 +48,7 @@ public:
uint32_t id; uint32_t id;
QByteArray fingerPrint; QByteArray fingerPrint;
QString label; QString label;
QDateTime lastInteraction;
TrustLevel trustLevel; TrustLevel trustLevel;
EncryptionProtocol protocol; EncryptionProtocol protocol;
bool currentDevice; bool currentDevice;

View File

@ -68,7 +68,6 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el,
feed->setItemDelegate(delegate); feed->setItemDelegate(delegate);
feed->setFrameShape(QFrame::NoFrame); feed->setFrameShape(QFrame::NoFrame);
feed->setContextMenuPolicy(Qt::CustomContextMenu); feed->setContextMenuPolicy(Qt::CustomContextMenu);
delegate->initializeFonts(feed->getFont());
feed->setModel(el->feed); feed->setModel(el->feed);
el->feed->incrementObservers(); el->feed->incrementObservers();
m_ui->widget->layout()->addWidget(feed); m_ui->widget->layout()->addWidget(feed);

View File

@ -24,6 +24,7 @@
#include <QApplication> #include <QApplication>
#include <QClipboard> #include <QClipboard>
#include <QDebug> #include <QDebug>
#include <QFontDatabase>
#include "messagedelegate.h" #include "messagedelegate.h"
#include "messagefeed.h" #include "messagefeed.h"
@ -40,6 +41,8 @@ const std::set<int> FeedView::geometryChangingRoles = {
Models::MessageFeed::Error, Models::MessageFeed::Error,
Models::MessageFeed::Date Models::MessageFeed::Date
}; };
QFont FeedView::dividerFont = QFontDatabase::systemFont(QFontDatabase::TitleFont);
QFontMetrics FeedView::dividerMetrics = QFontMetrics(dividerFont);
FeedView::FeedView(QWidget* parent): FeedView::FeedView(QWidget* parent):
QAbstractItemView(parent), QAbstractItemView(parent),
@ -51,8 +54,6 @@ FeedView::FeedView(QWidget* parent):
clearWidgetsMode(false), clearWidgetsMode(false),
modelState(Models::MessageFeed::complete), modelState(Models::MessageFeed::complete),
progress(), progress(),
dividerFont(),
dividerMetrics(dividerFont),
mousePressed(false), mousePressed(false),
dragging(false), dragging(false),
hovered(Shared::Hover::nothing), hovered(Shared::Hover::nothing),
@ -68,23 +69,11 @@ FeedView::FeedView(QWidget* parent):
progress.setParent(viewport()); progress.setParent(viewport());
progress.resize(progressSize, progressSize); progress.resize(progressSize, progressSize);
dividerFont = getFont();
dividerFont.setBold(true);
float ndps = dividerFont.pointSizeF();
if (ndps != -1) {
dividerFont.setPointSizeF(ndps * 1.2);
} else {
dividerFont.setPointSize(dividerFont.pointSize() + 2);
}
} }
FeedView::~FeedView() FeedView::~FeedView() {}
{
}
QModelIndex FeedView::indexAt(const QPoint& point) const QModelIndex FeedView::indexAt(const QPoint& point) const {
{
int32_t vh = viewport()->height(); int32_t vh = viewport()->height();
uint32_t y = vh - point.y() + vo; uint32_t y = vh - point.y() + vo;
@ -102,12 +91,8 @@ QModelIndex FeedView::indexAt(const QPoint& point) const
return QModelIndex(); return QModelIndex();
} }
void FeedView::scrollTo(const QModelIndex& index, QAbstractItemView::ScrollHint hint)
{
}
QRect FeedView::visualRect(const QModelIndex& index) const QRect FeedView::visualRect(const QModelIndex& index) const {
{
unsigned int row = index.row(); unsigned int row = index.row();
if (!index.isValid() || row >= hints.size()) { if (!index.isValid() || row >= hints.size()) {
qDebug() << "visualRect for" << row; qDebug() << "visualRect for" << row;
@ -119,44 +104,24 @@ QRect FeedView::visualRect(const QModelIndex& index) const
} }
} }
int FeedView::horizontalOffset() const QString FeedView::getSelectedText() const{return selectedText;}
{
return 0;
}
bool FeedView::isIndexHidden(const QModelIndex& index) const //TODO!!!
{ void FeedView::scrollTo(const QModelIndex& index, QAbstractItemView::ScrollHint hint) {}
return false; int FeedView::horizontalOffset() const {return 0;}
} bool FeedView::isIndexHidden(const QModelIndex& index) const{return false;}
QModelIndex FeedView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers) {return QModelIndex();}
void FeedView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command) {}
int FeedView::verticalOffset() const {return vo;}
QRegion FeedView::visualRegionForSelection(const QItemSelection& selection) const {return QRegion();}
QModelIndex FeedView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers) void FeedView::rowsInserted(const QModelIndex& parent, int start, int end){
{
return QModelIndex();
}
void FeedView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command)
{
}
int FeedView::verticalOffset() const
{
return vo;
}
QRegion FeedView::visualRegionForSelection(const QItemSelection& selection) const
{
return QRegion();
}
void FeedView::rowsInserted(const QModelIndex& parent, int start, int end)
{
QAbstractItemView::rowsInserted(parent, start, end); QAbstractItemView::rowsInserted(parent, start, end);
scheduleDelayedItemsLayout(); scheduleDelayedItemsLayout();
} }
void FeedView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles) void FeedView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles) {
{
if (specialDelegate) { if (specialDelegate) {
for (int role : roles) { for (int role : roles) {
if (geometryChangingRoles.count(role) != 0) { if (geometryChangingRoles.count(role) != 0) {
@ -168,8 +133,7 @@ void FeedView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottom
QAbstractItemView::dataChanged(topLeft, bottomRight, roles); QAbstractItemView::dataChanged(topLeft, bottomRight, roles);
} }
void FeedView::updateGeometries() void FeedView::updateGeometries() {
{
//qDebug() << "updateGeometries"; //qDebug() << "updateGeometries";
QScrollBar* bar = verticalScrollBar(); QScrollBar* bar = verticalScrollBar();
@ -260,8 +224,7 @@ void FeedView::updateGeometries()
QAbstractItemView::updateGeometries(); QAbstractItemView::updateGeometries();
} }
bool FeedView::tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewItem& option, const QAbstractItemModel* m, uint32_t totalHeight) bool FeedView::tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewItem& option, const QAbstractItemModel* m, uint32_t totalHeight) {
{
uint32_t previousOffset = elementMargin; uint32_t previousOffset = elementMargin;
QDateTime lastDate; QDateTime lastDate;
for (int i = 0, size = m->rowCount(); i < size; ++i) { for (int i = 0, size = m->rowCount(); i < size; ++i) {
@ -307,9 +270,7 @@ bool FeedView::tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewIt
return true; return true;
} }
void FeedView::paintEvent(QPaintEvent* event) {
void FeedView::paintEvent(QPaintEvent* event)
{
//qDebug() << "paint" << event->rect(); //qDebug() << "paint" << event->rect();
const QAbstractItemModel* m = model(); const QAbstractItemModel* m = model();
QWidget* vp = viewport(); QWidget* vp = viewport();
@ -388,8 +349,7 @@ void FeedView::paintEvent(QPaintEvent* event)
} }
} }
void FeedView::drawDateDevider(int top, const QDateTime& date, QPainter& painter) void FeedView::drawDateDevider(int top, const QDateTime& date, QPainter& painter) {
{
int divisionHeight = dateDeviderMargin * 2 + dividerMetrics.height(); int divisionHeight = dateDeviderMargin * 2 + dividerMetrics.height();
QRect r(QPoint(0, top), QSize(viewport()->width(), divisionHeight)); QRect r(QPoint(0, top), QSize(viewport()->width(), divisionHeight));
painter.save(); painter.save();
@ -398,8 +358,7 @@ void FeedView::drawDateDevider(int top, const QDateTime& date, QPainter& painter
painter.restore(); painter.restore();
} }
void FeedView::verticalScrollbarValueChanged(int value) void FeedView::verticalScrollbarValueChanged(int value) {
{
vo = verticalScrollBar()->maximum() - value; vo = verticalScrollBar()->maximum() - value;
positionProgress(); positionProgress();
@ -415,8 +374,7 @@ void FeedView::verticalScrollbarValueChanged(int value)
QAbstractItemView::verticalScrollbarValueChanged(vo); QAbstractItemView::verticalScrollbarValueChanged(vo);
} }
void FeedView::setAnchorHovered(Shared::Hover type) void FeedView::setAnchorHovered(Shared::Hover type) {
{
if (hovered != type) { if (hovered != type) {
hovered = type; hovered = type;
switch (hovered) { switch (hovered) {
@ -433,8 +391,7 @@ void FeedView::setAnchorHovered(Shared::Hover type)
} }
} }
void FeedView::mouseMoveEvent(QMouseEvent* event) void FeedView::mouseMoveEvent(QMouseEvent* event) {
{
if (!isVisible()) { if (!isVisible()) {
return; return;
} }
@ -479,8 +436,7 @@ void FeedView::mouseMoveEvent(QMouseEvent* event)
} }
} }
void FeedView::mousePressEvent(QMouseEvent* event) void FeedView::mousePressEvent(QMouseEvent* event) {
{
QAbstractItemView::mousePressEvent(event); QAbstractItemView::mousePressEvent(event);
mousePressed = event->button() == Qt::LeftButton; mousePressed = event->button() == Qt::LeftButton;
@ -500,8 +456,7 @@ void FeedView::mousePressEvent(QMouseEvent* event)
} }
} }
void FeedView::mouseDoubleClickEvent(QMouseEvent* event) void FeedView::mouseDoubleClickEvent(QMouseEvent* event) {
{
QAbstractItemView::mouseDoubleClickEvent(event); QAbstractItemView::mouseDoubleClickEvent(event);
mousePressed = event->button() == Qt::LeftButton; mousePressed = event->button() == Qt::LeftButton;
if (mousePressed) { if (mousePressed) {
@ -530,8 +485,7 @@ void FeedView::mouseDoubleClickEvent(QMouseEvent* event)
} }
} }
void FeedView::mouseReleaseEvent(QMouseEvent* event) void FeedView::mouseReleaseEvent(QMouseEvent* event) {
{
QAbstractItemView::mouseReleaseEvent(event); QAbstractItemView::mouseReleaseEvent(event);
if (mousePressed) { if (mousePressed) {
@ -551,8 +505,7 @@ void FeedView::mouseReleaseEvent(QMouseEvent* event)
} }
} }
void FeedView::keyPressEvent(QKeyEvent* event) void FeedView::keyPressEvent(QKeyEvent* event) {
{
QKeyEvent *key_event = static_cast<QKeyEvent*>(event); QKeyEvent *key_event = static_cast<QKeyEvent*>(event);
if (key_event->matches(QKeySequence::Copy)) { if (key_event->matches(QKeySequence::Copy)) {
if (selectedText.size() > 0) { if (selectedText.size() > 0) {
@ -562,16 +515,14 @@ void FeedView::keyPressEvent(QKeyEvent* event)
} }
} }
void FeedView::resizeEvent(QResizeEvent* event) void FeedView::resizeEvent(QResizeEvent* event) {
{
QAbstractItemView::resizeEvent(event); QAbstractItemView::resizeEvent(event);
positionProgress(); positionProgress();
emit resized(); emit resized();
} }
void FeedView::positionProgress() void FeedView::positionProgress() {
{
QSize layoutBounds = maximumViewportSize(); QSize layoutBounds = maximumViewportSize();
int progressPosition = layoutBounds.height() - progressSize; int progressPosition = layoutBounds.height() - progressSize;
std::deque<Hint>::size_type size = hints.size(); std::deque<Hint>::size_type size = hints.size();
@ -585,13 +536,7 @@ void FeedView::positionProgress()
progress.move((width() - progressSize) / 2, progressPosition); progress.move((width() - progressSize) / 2, progressPosition);
} }
QFont FeedView::getFont() const void FeedView::setItemDelegate(QAbstractItemDelegate* delegate) {
{
return viewOptions().font;
}
void FeedView::setItemDelegate(QAbstractItemDelegate* delegate)
{
if (specialDelegate) { if (specialDelegate) {
MessageDelegate* del = static_cast<MessageDelegate*>(itemDelegate()); MessageDelegate* del = static_cast<MessageDelegate*>(itemDelegate());
disconnect(del, &MessageDelegate::buttonPushed, this, &FeedView::onMessageButtonPushed); disconnect(del, &MessageDelegate::buttonPushed, this, &FeedView::onMessageButtonPushed);
@ -613,8 +558,7 @@ void FeedView::setItemDelegate(QAbstractItemDelegate* delegate)
} }
} }
void FeedView::setModel(QAbstractItemModel* p_model) void FeedView::setModel(QAbstractItemModel* p_model) {
{
if (specialModel) { if (specialModel) {
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model()); Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
disconnect(feed, &Models::MessageFeed::syncStateChange, this, &FeedView::onModelSyncStateChange); disconnect(feed, &Models::MessageFeed::syncStateChange, this, &FeedView::onModelSyncStateChange);
@ -633,24 +577,21 @@ void FeedView::setModel(QAbstractItemModel* p_model)
} }
} }
void FeedView::onMessageButtonPushed(const QString& messageId) void FeedView::onMessageButtonPushed(const QString& messageId) {
{
if (specialModel) { if (specialModel) {
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model()); Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
feed->downloadAttachment(messageId); feed->downloadAttachment(messageId);
} }
} }
void FeedView::onMessageInvalidPath(const QString& messageId) void FeedView::onMessageInvalidPath(const QString& messageId) {
{
if (specialModel) { if (specialModel) {
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model()); Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
feed->reportLocalPathInvalid(messageId); feed->reportLocalPathInvalid(messageId);
} }
} }
void FeedView::onModelSyncStateChange(Models::MessageFeed::SyncState state) void FeedView::onModelSyncStateChange(Models::MessageFeed::SyncState state) {
{
bool needToUpdateGeometry = false; bool needToUpdateGeometry = false;
if (modelState != state) { if (modelState != state) {
if (state == Models::MessageFeed::complete || modelState == Models::MessageFeed::complete) { if (state == Models::MessageFeed::complete || modelState == Models::MessageFeed::complete) {
@ -671,8 +612,3 @@ void FeedView::onModelSyncStateChange(Models::MessageFeed::SyncState state)
scheduleDelayedItemsLayout(); scheduleDelayedItemsLayout();
} }
} }
QString FeedView::getSelectedText() const
{
return selectedText;
}

View File

@ -50,7 +50,6 @@ public:
void setItemDelegate(QAbstractItemDelegate* delegate); void setItemDelegate(QAbstractItemDelegate* delegate);
void setModel(QAbstractItemModel * model) override; void setModel(QAbstractItemModel * model) override;
QFont getFont() const;
QString getSelectedText() const; QString getSelectedText() const;
signals: signals:
@ -100,8 +99,8 @@ private:
bool clearWidgetsMode; bool clearWidgetsMode;
Models::MessageFeed::SyncState modelState; Models::MessageFeed::SyncState modelState;
Progress progress; Progress progress;
QFont dividerFont; static QFont dividerFont;
QFontMetrics dividerMetrics; static QFontMetrics dividerMetrics;
bool mousePressed; bool mousePressed;
bool dragging; bool dragging;
Shared::Hover hovered; Shared::Hover hovered;

View File

@ -24,29 +24,40 @@
#include <QAbstractItemView> #include <QAbstractItemView>
#include <QAbstractTextDocumentLayout> #include <QAbstractTextDocumentLayout>
#include <QTextBlock> #include <QTextBlock>
#include <QFontDatabase>
#include <cmath> #include <cmath>
#include "messagedelegate.h" #include "messagedelegate.h"
#include "messagefeed.h" #include "messagefeed.h"
int MessageDelegate::avatarHeight(50); QFont getFont (QFontDatabase::SystemFont type, bool bold, bool italic) {
int MessageDelegate::margin(6); QFont font = QFontDatabase::systemFont(type);
if (bold)
font.setBold(true);
if (italic)
font.setItalic(true);
return font;
}
constexpr int textMargin = 2; constexpr int textMargin = 2;
constexpr int statusIconSize = 16; constexpr int statusIconSize = 16;
constexpr float nickFontMultiplier = 1.1;
constexpr float dateFontMultiplier = 0.8;
constexpr int bubbleMargin = 6; constexpr int bubbleMargin = 6;
constexpr int bubbleBorderRadius = 3; constexpr int bubbleBorderRadius = 3;
int MessageDelegate::avatarHeight(50);
int MessageDelegate::margin(6);
bool MessageDelegate::fontsInitialized(false);
QFont MessageDelegate::bodyFont;
QFont MessageDelegate::nickFont;
QFont MessageDelegate::dateFont;
QFontMetrics MessageDelegate::nickMetrics(nickFont);
QFontMetrics MessageDelegate::dateMetrics(dateFont);
MessageDelegate::MessageDelegate(QObject* parent): MessageDelegate::MessageDelegate(QObject* parent):
QStyledItemDelegate(parent), QStyledItemDelegate(parent),
bodyFont(),
nickFont(),
dateFont(),
bodyRenderer(new QTextDocument()), bodyRenderer(new QTextDocument()),
nickMetrics(nickFont),
dateMetrics(dateFont),
buttonHeight(0), buttonHeight(0),
buttonWidth(0), buttonWidth(0),
barHeight(0), barHeight(0),
@ -60,7 +71,13 @@ MessageDelegate::MessageDelegate(QObject* parent):
currentId(""), currentId(""),
selection(0, 0) selection(0, 0)
{ {
if (!fontsInitialized) {
fontsInitialized = true;
initializeFonts();
}
bodyRenderer->setDocumentMargin(0); bodyRenderer->setDocumentMargin(0);
bodyRenderer->setDefaultFont(bodyFont);
QPushButton btn(QCoreApplication::translate("MessageLine", "Download")); QPushButton btn(QCoreApplication::translate("MessageLine", "Download"));
buttonHeight = btn.sizeHint().height(); buttonHeight = btn.sizeHint().height();
@ -285,7 +302,6 @@ bool MessageDelegate::needToDrawSender(const QModelIndex& index, const Models::F
} }
} }
QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{ {
QRect messageRect = option.rect.adjusted(bubbleMargin, margin / 2 + bubbleMargin, -(avatarHeight + 3 * margin + bubbleMargin), -(margin + bubbleMargin) / 2); QRect messageRect = option.rect.adjusted(bubbleMargin, margin / 2 + bubbleMargin, -(avatarHeight + 3 * margin + bubbleMargin), -(margin + bubbleMargin) / 2);
@ -538,38 +554,6 @@ QString MessageDelegate::clearSelection()
return lastSelectedId; return lastSelectedId;
} }
void MessageDelegate::initializeFonts(const QFont& font)
{
bodyFont = font;
nickFont = font;
dateFont = font;
nickFont.setBold(true);
float ndps = nickFont.pointSizeF();
if (ndps != -1) {
nickFont.setPointSizeF(ndps * nickFontMultiplier);
} else {
nickFont.setPointSize(nickFont.pointSize() * nickFontMultiplier);
}
dateFont.setItalic(true);
float dps = dateFont.pointSizeF();
if (dps != -1) {
dateFont.setPointSizeF(dps * dateFontMultiplier);
} else {
dateFont.setPointSize(dateFont.pointSize() * dateFontMultiplier);
}
bodyFont.setKerning(false);
nickMetrics = QFontMetrics(nickFont);
dateMetrics = QFontMetrics(dateFont);
bodyRenderer->setDefaultFont(bodyFont);
Preview::initializeFont(bodyFont);
}
bool MessageDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) bool MessageDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index)
{ {
//qDebug() << event->type(); //qDebug() << event->type();
@ -828,3 +812,11 @@ void MessageDelegate::clearHelperWidget(const Models::FeedItem& data) const
} }
} }
} }
void MessageDelegate::initializeFonts () {
bodyFont = getFont(QFontDatabase::GeneralFont, false, false);
nickFont = getFont(QFontDatabase::TitleFont, true, false);
dateFont = getFont(QFontDatabase::SmallestReadableFont, false, true);
nickMetrics = QFontMetrics(nickFont);
dateMetrics = QFontMetrics(dateFont);
}

View File

@ -53,7 +53,6 @@ public:
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override; QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
//void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const override; //void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const override;
void initializeFonts(const QFont& font);
bool editorEvent(QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index) override; bool editorEvent(QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index) override;
void endClearWidgets(); void endClearWidgets();
void beginClearWidgets(); void beginClearWidgets();
@ -95,18 +94,22 @@ protected:
protected slots: protected slots:
void onButtonPushed() const; void onButtonPushed() const;
private:
static void initializeFonts();
private: private:
class FeedButton : public QPushButton { class FeedButton : public QPushButton {
public: public:
QString messageId; QString messageId;
}; };
QFont bodyFont; static bool fontsInitialized;
QFont nickFont; static QFont bodyFont;
QFont dateFont; static QFont nickFont;
static QFont dateFont;
QTextDocument* bodyRenderer; QTextDocument* bodyRenderer;
QFontMetrics nickMetrics; static QFontMetrics nickMetrics;
QFontMetrics dateMetrics; static QFontMetrics dateMetrics;
int buttonHeight; int buttonHeight;
int buttonWidth; int buttonWidth;

View File

@ -18,11 +18,18 @@
#include "preview.h" #include "preview.h"
#include <QFontDatabase>
constexpr int margin = 6; constexpr int margin = 6;
constexpr int maxAttachmentHeight = 500; constexpr int maxAttachmentHeight = 500;
QFont Preview::font; QFont getFont () {
QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
font.setBold(true);
return font;
}
QFont Preview::font = getFont();
QFontMetrics Preview::metrics(Preview::font); QFontMetrics Preview::metrics(Preview::font);
Preview::Preview(const QString& pPath, const QSize& pMaxSize, const QPoint& pos, QWidget* pParent): Preview::Preview(const QString& pPath, const QSize& pMaxSize, const QPoint& pos, QWidget* pParent):
@ -38,20 +45,12 @@ Preview::Preview(const QString& pPath, const QSize& pMaxSize, const QPoint& pos,
fileReachable(true), fileReachable(true),
actualPreview(false) actualPreview(false)
{ {
initializeElements(); initializeElements();
if (fileReachable) { if (fileReachable) {
positionElements(); positionElements();
} }
} }
void Preview::initializeFont(const QFont& newFont)
{
font = newFont;
font.setBold(true);
metrics = QFontMetrics(font);
}
Preview::~Preview() Preview::~Preview()
{ {
clean(); clean();

View File

@ -48,7 +48,6 @@ public:
bool isFileReachable() const; bool isFileReachable() const;
QSize size() const; QSize size() const;
static void initializeFont(const QFont& newFont);
static QSize constrainAttachSize(QSize src, QSize bounds); static QSize constrainAttachSize(QSize src, QSize bounds);
static QSize calculateAttachSize(const QString& path, const QRect& bounds); static QSize calculateAttachSize(const QString& path, const QRect& bounds);
static bool canVisualize(const Shared::Global::FileInfo& info); static bool canVisualize(const Shared::Global::FileInfo& info);

View File

@ -29,10 +29,11 @@ constexpr uint8_t maxSingleLineParts = 3;
UI::KeyDelegate::KeyDelegate(QObject* parent): UI::KeyDelegate::KeyDelegate(QObject* parent):
QStyledItemDelegate(parent), QStyledItemDelegate(parent),
fingerPrintFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)), fingerPrintFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)),
labelFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)),
fingerPrintMetrics(fingerPrintFont), fingerPrintMetrics(fingerPrintFont),
labelFontMetrics(labelFont),
spaceWidth(fingerPrintMetrics.horizontalAdvance(" ")) spaceWidth(fingerPrintMetrics.horizontalAdvance(" "))
{ {}
}
UI::KeyDelegate::~KeyDelegate() {} UI::KeyDelegate::~KeyDelegate() {}
@ -48,6 +49,24 @@ void UI::KeyDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
painter->restore(); 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); QVariant fingerPrintV = index.data(UI::KeysModel::FingerPrint);
if (fingerPrintV.isValid()) { if (fingerPrintV.isValid()) {
painter->save(); painter->save();
@ -55,8 +74,6 @@ void UI::KeyDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
QByteArray fingerPrint = fingerPrintV.toByteArray(); QByteArray fingerPrint = fingerPrintV.toByteArray();
std::vector<QString> parts = getParts(fingerPrint); std::vector<QString> parts = getParts(fingerPrint);
uint8_t partsLength = parts.size(); uint8_t partsLength = parts.size();
QRect rect = option.rect;
rect.adjust(margin, margin, 0, 0);
QRect r; QRect r;
uint8_t firstLine; uint8_t firstLine;
if (partsLength > maxSingleLineParts) 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(r.width() + spaceWidth ,0, 0, 0);
} }
rect.adjust(0, r.height() + fingerPrintMetrics.leading(), 0, 0);
rect.setLeft(option.rect.left() + margin);
painter->restore(); 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->drawText(option.rect, option.displayAlignment, index.data().toString());
painter->restore(); painter->restore();
@ -85,6 +119,12 @@ QSize UI::KeyDelegate::sizeHint(const QStyleOptionViewItem& option, const QModel
int mh = margin * 2; int mh = margin * 2;
int mw = 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); QVariant fingerPrintV = index.data(UI::KeysModel::FingerPrint);
if (fingerPrintV.isValid()) { if (fingerPrintV.isValid()) {
QString hex = fingerPrintV.toByteArray().toHex(); 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; 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) if (size.width() < mw)
size.setWidth(mw); size.setWidth(mw);

View File

@ -34,7 +34,9 @@ public:
private: private:
QFont fingerPrintFont; QFont fingerPrintFont;
QFont labelFont;
QFontMetrics fingerPrintMetrics; QFontMetrics fingerPrintMetrics;
QFontMetrics labelFontMetrics;
int spaceWidth; int spaceWidth;
private: private:

View File

@ -44,11 +44,21 @@ QVariant UI::KeysModel::data(const QModelIndex& index, int role) const {
switch (role) { switch (role) {
case Qt::DisplayRole: case Qt::DisplayRole:
case Label:
answer = keys[i]->label; answer = keys[i]->label;
break; break;
case FingerPrint: case FingerPrint:
answer = keys[i]->fingerPrint; answer = keys[i]->fingerPrint;
break; 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; return answer;

View File

@ -43,7 +43,9 @@ public:
enum Roles { enum Roles {
Label = Qt::UserRole + 1, Label = Qt::UserRole + 1,
FingerPrint, FingerPrint,
TrustLevel TrustLevel,
LastInteraction,
Dirty
}; };
private: private:

View File

@ -54,8 +54,12 @@ void Omemo::generateMockData()
} }
Shared::KeyInfo info; Shared::KeyInfo info;
info.id = i; 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; info.fingerPrint = fp;
if (i % 2 == 0)
info.lastInteraction = QDateTime::currentDateTime();
keysModel.addKey(info); keysModel.addKey(info);
} }
} }

View File

@ -82,7 +82,7 @@
<enum>QAbstractItemView::ScrollPerItem</enum> <enum>QAbstractItemView::ScrollPerItem</enum>
</property> </property>
<property name="uniformItemSizes"> <property name="uniformItemSizes">
<bool>true</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>