forked from blue/squawk
some thoughts about fonts, lastInteraction and label into keyDelegate
This commit is contained in:
parent
2aed8a1209
commit
15fb4bbd62
@ -22,6 +22,7 @@ Shared::KeyInfo::KeyInfo(
|
||||
uint32_t p_id,
|
||||
const QByteArray& p_fingerPrint,
|
||||
const QString& p_label,
|
||||
const QDateTime& p_lastInteraction,
|
||||
Shared::TrustLevel p_trustLevel,
|
||||
Shared::EncryptionProtocol p_protocol,
|
||||
bool p_currentDevice
|
||||
@ -29,6 +30,7 @@ Shared::KeyInfo::KeyInfo(
|
||||
id(p_id),
|
||||
fingerPrint(p_fingerPrint),
|
||||
label(p_label),
|
||||
lastInteraction(p_lastInteraction),
|
||||
trustLevel(p_trustLevel),
|
||||
protocol(p_protocol),
|
||||
currentDevice(p_currentDevice)
|
||||
@ -39,6 +41,7 @@ Shared::KeyInfo::KeyInfo():
|
||||
id(0),
|
||||
fingerPrint(),
|
||||
label(),
|
||||
lastInteraction(),
|
||||
trustLevel(TrustLevel::undecided),
|
||||
protocol(EncryptionProtocol::omemo),
|
||||
currentDevice(false)
|
||||
@ -49,6 +52,7 @@ Shared::KeyInfo::KeyInfo(const Shared::KeyInfo& other):
|
||||
id(other.id),
|
||||
fingerPrint(other.fingerPrint),
|
||||
label(other.label),
|
||||
lastInteraction(other.lastInteraction),
|
||||
trustLevel(other.trustLevel),
|
||||
protocol(other.protocol),
|
||||
currentDevice(other.currentDevice)
|
||||
@ -59,6 +63,7 @@ Shared::KeyInfo & Shared::KeyInfo::operator=(const Shared::KeyInfo& other) {
|
||||
id = other.id;
|
||||
fingerPrint = other.fingerPrint;
|
||||
label = other.label;
|
||||
lastInteraction = other.lastInteraction;
|
||||
trustLevel = other.trustLevel;
|
||||
protocol = other.protocol;
|
||||
currentDevice = other.currentDevice;
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QByteArray>
|
||||
#include <QDateTime>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@ -31,9 +32,9 @@ class KeyInfo
|
||||
public:
|
||||
KeyInfo(
|
||||
uint32_t id,
|
||||
const QByteArray&
|
||||
fingerPrint,
|
||||
const QByteArray& fingerPrint,
|
||||
const QString& label,
|
||||
const QDateTime& lastInteraction,
|
||||
TrustLevel trustLevel,
|
||||
EncryptionProtocol protocol = EncryptionProtocol::omemo,
|
||||
bool currentDevice = false
|
||||
@ -47,6 +48,7 @@ public:
|
||||
uint32_t id;
|
||||
QByteArray fingerPrint;
|
||||
QString label;
|
||||
QDateTime lastInteraction;
|
||||
TrustLevel trustLevel;
|
||||
EncryptionProtocol protocol;
|
||||
bool currentDevice;
|
||||
|
@ -68,7 +68,6 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el,
|
||||
feed->setItemDelegate(delegate);
|
||||
feed->setFrameShape(QFrame::NoFrame);
|
||||
feed->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
delegate->initializeFonts(feed->getFont());
|
||||
feed->setModel(el->feed);
|
||||
el->feed->incrementObservers();
|
||||
m_ui->widget->layout()->addWidget(feed);
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QDebug>
|
||||
#include <QFontDatabase>
|
||||
|
||||
#include "messagedelegate.h"
|
||||
#include "messagefeed.h"
|
||||
@ -40,6 +41,8 @@ const std::set<int> FeedView::geometryChangingRoles = {
|
||||
Models::MessageFeed::Error,
|
||||
Models::MessageFeed::Date
|
||||
};
|
||||
QFont FeedView::dividerFont = QFontDatabase::systemFont(QFontDatabase::TitleFont);
|
||||
QFontMetrics FeedView::dividerMetrics = QFontMetrics(dividerFont);
|
||||
|
||||
FeedView::FeedView(QWidget* parent):
|
||||
QAbstractItemView(parent),
|
||||
@ -51,8 +54,6 @@ FeedView::FeedView(QWidget* parent):
|
||||
clearWidgetsMode(false),
|
||||
modelState(Models::MessageFeed::complete),
|
||||
progress(),
|
||||
dividerFont(),
|
||||
dividerMetrics(dividerFont),
|
||||
mousePressed(false),
|
||||
dragging(false),
|
||||
hovered(Shared::Hover::nothing),
|
||||
@ -68,23 +69,11 @@ FeedView::FeedView(QWidget* parent):
|
||||
|
||||
progress.setParent(viewport());
|
||||
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();
|
||||
uint32_t y = vh - point.y() + vo;
|
||||
|
||||
@ -102,12 +91,8 @@ QModelIndex FeedView::indexAt(const QPoint& point) const
|
||||
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();
|
||||
if (!index.isValid() || row >= hints.size()) {
|
||||
qDebug() << "visualRect for" << row;
|
||||
@ -119,44 +104,24 @@ QRect FeedView::visualRect(const QModelIndex& index) const
|
||||
}
|
||||
}
|
||||
|
||||
int FeedView::horizontalOffset() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
QString FeedView::getSelectedText() const{return selectedText;}
|
||||
|
||||
bool FeedView::isIndexHidden(const QModelIndex& index) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//TODO!!!
|
||||
void FeedView::scrollTo(const QModelIndex& index, QAbstractItemView::ScrollHint hint) {}
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
void FeedView::rowsInserted(const QModelIndex& parent, int start, int end){
|
||||
QAbstractItemView::rowsInserted(parent, start, end);
|
||||
|
||||
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) {
|
||||
for (int role : roles) {
|
||||
if (geometryChangingRoles.count(role) != 0) {
|
||||
@ -168,8 +133,7 @@ void FeedView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottom
|
||||
QAbstractItemView::dataChanged(topLeft, bottomRight, roles);
|
||||
}
|
||||
|
||||
void FeedView::updateGeometries()
|
||||
{
|
||||
void FeedView::updateGeometries() {
|
||||
//qDebug() << "updateGeometries";
|
||||
QScrollBar* bar = verticalScrollBar();
|
||||
|
||||
@ -260,8 +224,7 @@ void FeedView::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;
|
||||
QDateTime lastDate;
|
||||
for (int i = 0, size = m->rowCount(); i < size; ++i) {
|
||||
@ -307,9 +270,7 @@ bool FeedView::tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewIt
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void FeedView::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
void FeedView::paintEvent(QPaintEvent* event) {
|
||||
//qDebug() << "paint" << event->rect();
|
||||
const QAbstractItemModel* m = model();
|
||||
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();
|
||||
QRect r(QPoint(0, top), QSize(viewport()->width(), divisionHeight));
|
||||
painter.save();
|
||||
@ -398,8 +358,7 @@ void FeedView::drawDateDevider(int top, const QDateTime& date, QPainter& painter
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
void FeedView::verticalScrollbarValueChanged(int value)
|
||||
{
|
||||
void FeedView::verticalScrollbarValueChanged(int value) {
|
||||
vo = verticalScrollBar()->maximum() - value;
|
||||
|
||||
positionProgress();
|
||||
@ -415,8 +374,7 @@ void FeedView::verticalScrollbarValueChanged(int value)
|
||||
QAbstractItemView::verticalScrollbarValueChanged(vo);
|
||||
}
|
||||
|
||||
void FeedView::setAnchorHovered(Shared::Hover type)
|
||||
{
|
||||
void FeedView::setAnchorHovered(Shared::Hover type) {
|
||||
if (hovered != type) {
|
||||
hovered = type;
|
||||
switch (hovered) {
|
||||
@ -433,8 +391,7 @@ void FeedView::setAnchorHovered(Shared::Hover type)
|
||||
}
|
||||
}
|
||||
|
||||
void FeedView::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
void FeedView::mouseMoveEvent(QMouseEvent* event) {
|
||||
if (!isVisible()) {
|
||||
return;
|
||||
}
|
||||
@ -479,8 +436,7 @@ void FeedView::mouseMoveEvent(QMouseEvent* event)
|
||||
}
|
||||
}
|
||||
|
||||
void FeedView::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
void FeedView::mousePressEvent(QMouseEvent* event) {
|
||||
QAbstractItemView::mousePressEvent(event);
|
||||
|
||||
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);
|
||||
mousePressed = event->button() == Qt::LeftButton;
|
||||
if (mousePressed) {
|
||||
@ -530,8 +485,7 @@ void FeedView::mouseDoubleClickEvent(QMouseEvent* event)
|
||||
}
|
||||
}
|
||||
|
||||
void FeedView::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
void FeedView::mouseReleaseEvent(QMouseEvent* event) {
|
||||
QAbstractItemView::mouseReleaseEvent(event);
|
||||
|
||||
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);
|
||||
if (key_event->matches(QKeySequence::Copy)) {
|
||||
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);
|
||||
|
||||
positionProgress();
|
||||
emit resized();
|
||||
}
|
||||
|
||||
void FeedView::positionProgress()
|
||||
{
|
||||
void FeedView::positionProgress() {
|
||||
QSize layoutBounds = maximumViewportSize();
|
||||
int progressPosition = layoutBounds.height() - progressSize;
|
||||
std::deque<Hint>::size_type size = hints.size();
|
||||
@ -585,13 +536,7 @@ void FeedView::positionProgress()
|
||||
progress.move((width() - progressSize) / 2, progressPosition);
|
||||
}
|
||||
|
||||
QFont FeedView::getFont() const
|
||||
{
|
||||
return viewOptions().font;
|
||||
}
|
||||
|
||||
void FeedView::setItemDelegate(QAbstractItemDelegate* delegate)
|
||||
{
|
||||
void FeedView::setItemDelegate(QAbstractItemDelegate* delegate) {
|
||||
if (specialDelegate) {
|
||||
MessageDelegate* del = static_cast<MessageDelegate*>(itemDelegate());
|
||||
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) {
|
||||
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
|
||||
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) {
|
||||
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
|
||||
feed->downloadAttachment(messageId);
|
||||
}
|
||||
}
|
||||
|
||||
void FeedView::onMessageInvalidPath(const QString& messageId)
|
||||
{
|
||||
void FeedView::onMessageInvalidPath(const QString& messageId) {
|
||||
if (specialModel) {
|
||||
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
|
||||
feed->reportLocalPathInvalid(messageId);
|
||||
}
|
||||
}
|
||||
|
||||
void FeedView::onModelSyncStateChange(Models::MessageFeed::SyncState state)
|
||||
{
|
||||
void FeedView::onModelSyncStateChange(Models::MessageFeed::SyncState state) {
|
||||
bool needToUpdateGeometry = false;
|
||||
if (modelState != state) {
|
||||
if (state == Models::MessageFeed::complete || modelState == Models::MessageFeed::complete) {
|
||||
@ -671,8 +612,3 @@ void FeedView::onModelSyncStateChange(Models::MessageFeed::SyncState state)
|
||||
scheduleDelayedItemsLayout();
|
||||
}
|
||||
}
|
||||
|
||||
QString FeedView::getSelectedText() const
|
||||
{
|
||||
return selectedText;
|
||||
}
|
||||
|
@ -50,7 +50,6 @@ public:
|
||||
void setItemDelegate(QAbstractItemDelegate* delegate);
|
||||
void setModel(QAbstractItemModel * model) override;
|
||||
|
||||
QFont getFont() const;
|
||||
QString getSelectedText() const;
|
||||
|
||||
signals:
|
||||
@ -100,8 +99,8 @@ private:
|
||||
bool clearWidgetsMode;
|
||||
Models::MessageFeed::SyncState modelState;
|
||||
Progress progress;
|
||||
QFont dividerFont;
|
||||
QFontMetrics dividerMetrics;
|
||||
static QFont dividerFont;
|
||||
static QFontMetrics dividerMetrics;
|
||||
bool mousePressed;
|
||||
bool dragging;
|
||||
Shared::Hover hovered;
|
||||
|
@ -24,29 +24,40 @@
|
||||
#include <QAbstractItemView>
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
#include <QTextBlock>
|
||||
#include <QFontDatabase>
|
||||
#include <cmath>
|
||||
|
||||
#include "messagedelegate.h"
|
||||
#include "messagefeed.h"
|
||||
|
||||
int MessageDelegate::avatarHeight(50);
|
||||
int MessageDelegate::margin(6);
|
||||
QFont getFont (QFontDatabase::SystemFont type, bool bold, bool italic) {
|
||||
QFont font = QFontDatabase::systemFont(type);
|
||||
if (bold)
|
||||
font.setBold(true);
|
||||
if (italic)
|
||||
font.setItalic(true);
|
||||
|
||||
return font;
|
||||
}
|
||||
constexpr int textMargin = 2;
|
||||
constexpr int statusIconSize = 16;
|
||||
constexpr float nickFontMultiplier = 1.1;
|
||||
constexpr float dateFontMultiplier = 0.8;
|
||||
|
||||
constexpr int bubbleMargin = 6;
|
||||
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):
|
||||
QStyledItemDelegate(parent),
|
||||
bodyFont(),
|
||||
nickFont(),
|
||||
dateFont(),
|
||||
bodyRenderer(new QTextDocument()),
|
||||
nickMetrics(nickFont),
|
||||
dateMetrics(dateFont),
|
||||
buttonHeight(0),
|
||||
buttonWidth(0),
|
||||
barHeight(0),
|
||||
@ -60,7 +71,13 @@ MessageDelegate::MessageDelegate(QObject* parent):
|
||||
currentId(""),
|
||||
selection(0, 0)
|
||||
{
|
||||
if (!fontsInitialized) {
|
||||
fontsInitialized = true;
|
||||
initializeFonts();
|
||||
}
|
||||
|
||||
bodyRenderer->setDocumentMargin(0);
|
||||
bodyRenderer->setDefaultFont(bodyFont);
|
||||
|
||||
QPushButton btn(QCoreApplication::translate("MessageLine", "Download"));
|
||||
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
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
//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);
|
||||
}
|
||||
|
@ -53,7 +53,6 @@ public:
|
||||
QSize sizeHint(const QStyleOptionViewItem& option, 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;
|
||||
void endClearWidgets();
|
||||
void beginClearWidgets();
|
||||
@ -94,6 +93,9 @@ protected:
|
||||
|
||||
protected slots:
|
||||
void onButtonPushed() const;
|
||||
|
||||
private:
|
||||
static void initializeFonts();
|
||||
|
||||
private:
|
||||
class FeedButton : public QPushButton {
|
||||
@ -101,12 +103,13 @@ private:
|
||||
QString messageId;
|
||||
};
|
||||
|
||||
QFont bodyFont;
|
||||
QFont nickFont;
|
||||
QFont dateFont;
|
||||
static bool fontsInitialized;
|
||||
static QFont bodyFont;
|
||||
static QFont nickFont;
|
||||
static QFont dateFont;
|
||||
QTextDocument* bodyRenderer;
|
||||
QFontMetrics nickMetrics;
|
||||
QFontMetrics dateMetrics;
|
||||
static QFontMetrics nickMetrics;
|
||||
static QFontMetrics dateMetrics;
|
||||
|
||||
int buttonHeight;
|
||||
int buttonWidth;
|
||||
|
@ -18,11 +18,18 @@
|
||||
|
||||
#include "preview.h"
|
||||
|
||||
#include <QFontDatabase>
|
||||
|
||||
constexpr int margin = 6;
|
||||
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);
|
||||
|
||||
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),
|
||||
actualPreview(false)
|
||||
{
|
||||
|
||||
initializeElements();
|
||||
if (fileReachable) {
|
||||
positionElements();
|
||||
}
|
||||
}
|
||||
|
||||
void Preview::initializeFont(const QFont& newFont)
|
||||
{
|
||||
font = newFont;
|
||||
font.setBold(true);
|
||||
metrics = QFontMetrics(font);
|
||||
}
|
||||
|
||||
Preview::~Preview()
|
||||
{
|
||||
clean();
|
||||
|
@ -48,7 +48,6 @@ public:
|
||||
bool isFileReachable() const;
|
||||
QSize size() const;
|
||||
|
||||
static void initializeFont(const QFont& newFont);
|
||||
static QSize constrainAttachSize(QSize src, QSize bounds);
|
||||
static QSize calculateAttachSize(const QString& path, const QRect& bounds);
|
||||
static bool canVisualize(const Shared::Global::FileInfo& info);
|
||||
|
@ -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…
Reference in New Issue
Block a user