better way to solve yesterday font problem, small visual avatar rendering fix

This commit is contained in:
Blue 2023-01-12 20:56:01 +03:00
parent 15fb4bbd62
commit d4bf7e599a
Signed by: blue
GPG Key ID: 9B203B252A63EE38
9 changed files with 62 additions and 56 deletions

View File

@ -17,6 +17,7 @@
*/
#include "global.h"
#include <QFontDatabase>
#include "enums.h"
#include "ui/models/roster.h"
@ -26,6 +27,25 @@ constexpr bool OMEMO_SUPPORT = true;
constexpr bool OMEMO_SUPPORT = false
#endif
QFont getFont (QFontDatabase::SystemFont type, bool bold = false, bool italic = false, qreal factor = 1.0) {
QFont font = QFontDatabase::systemFont(type);
if (bold)
font.setBold(true);
if (italic)
font.setItalic(true);
if (factor != 1.0) {
float ps = font.pointSizeF();
if (ps != -1) {
font.setPointSizeF(ps * factor);
} else {
font.setPointSize(font.pointSize() * factor);
}
}
return font;
}
Shared::Global* Shared::Global::instance = 0;
const std::set<QString> Shared::Global::supportedImagesExts = {"png", "jpg", "webp", "jpeg", "gif", "svg"};
@ -102,6 +122,14 @@ Shared::Global::Global():
defaultSystemStyle(QApplication::style()->objectName()),
defaultSystemPalette(QApplication::palette()),
omemoSupport(OMEMO_SUPPORT),
defaultFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont)),
smallFont(getFont(QFontDatabase::SmallestReadableFont, false, true)),
headerFont(getFont(QFontDatabase::TitleFont, true, false, 1.1)),
titleFont(getFont(QFontDatabase::TitleFont, true, false, 1.3)),
defaultFontMetrics(defaultFont),
smallFontMetrics(smallFont),
headerFontMetrics(headerFont),
titleFontMetrics(titleFont),
pluginSupport({
{"KWallet", false},
{"openFileManagerWindowJob", false},

View File

@ -42,6 +42,8 @@
#include <QProcess>
#include <QDesktopServices>
#include <QRegularExpression>
#include <QFont>
#include <QFontMetrics>
namespace Shared {
@ -100,6 +102,14 @@ namespace Shared {
static void setTheme(const QString& path);
static void setStyle(const QString& style);
const bool omemoSupport;
QFont defaultFont;
QFont smallFont;
QFont headerFont;
QFont titleFont;
QFontMetrics defaultFontMetrics;
QFontMetrics smallFontMetrics;
QFontMetrics headerFontMetrics;
QFontMetrics titleFontMetrics;
template<typename T>
static T fromInt(int src);

View File

@ -371,7 +371,7 @@ void Conversation::setAvatar(const QString& path)
if (path.size() == 0) {
pixmap = Shared::icon("user", true).pixmap(avatarSize);
} else {
pixmap = QPixmap(path).scaled(avatarSize);
pixmap = QPixmap(path).scaled(avatarSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}

View File

@ -24,7 +24,6 @@
#include <QApplication>
#include <QClipboard>
#include <QDebug>
#include <QFontDatabase>
#include "messagedelegate.h"
#include "messagefeed.h"
@ -41,8 +40,6 @@ 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),
@ -54,6 +51,8 @@ FeedView::FeedView(QWidget* parent):
clearWidgetsMode(false),
modelState(Models::MessageFeed::complete),
progress(),
dividerFont(Shared::Global::getInstance()->titleFont),
dividerMetrics(Shared::Global::getInstance()->titleFontMetrics),
mousePressed(false),
dragging(false),
hovered(Shared::Hover::nothing),

View File

@ -99,8 +99,8 @@ private:
bool clearWidgetsMode;
Models::MessageFeed::SyncState modelState;
Progress progress;
static QFont dividerFont;
static QFontMetrics dividerMetrics;
const QFont& dividerFont;
const QFontMetrics& dividerMetrics;
bool mousePressed;
bool dragging;
Shared::Hover hovered;

View File

@ -24,21 +24,11 @@
#include <QAbstractItemView>
#include <QAbstractTextDocumentLayout>
#include <QTextBlock>
#include <QFontDatabase>
#include <cmath>
#include "messagedelegate.h"
#include "messagefeed.h"
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;
@ -48,15 +38,13 @@ 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(Shared::Global::getInstance()->defaultFont),
nickFont(Shared::Global::getInstance()->headerFont),
dateFont(Shared::Global::getInstance()->smallFont),
nickMetrics(Shared::Global::getInstance()->headerFontMetrics),
dateMetrics(Shared::Global::getInstance()->smallFontMetrics),
bodyRenderer(new QTextDocument()),
buttonHeight(0),
buttonWidth(0),
@ -71,11 +59,6 @@ MessageDelegate::MessageDelegate(QObject* parent):
currentId(""),
selection(0, 0)
{
if (!fontsInitialized) {
fontsInitialized = true;
initializeFonts();
}
bodyRenderer->setDocumentMargin(0);
bodyRenderer->setDefaultFont(bodyFont);
@ -812,11 +795,3 @@ 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

@ -93,9 +93,6 @@ protected:
protected slots:
void onButtonPushed() const;
private:
static void initializeFonts();
private:
class FeedButton : public QPushButton {
@ -103,13 +100,12 @@ private:
QString messageId;
};
static bool fontsInitialized;
static QFont bodyFont;
static QFont nickFont;
static QFont dateFont;
const QFont& bodyFont;
const QFont& nickFont;
const QFont& dateFont;
const QFontMetrics& nickMetrics;
const QFontMetrics& dateMetrics;
QTextDocument* bodyRenderer;
static QFontMetrics nickMetrics;
static QFontMetrics dateMetrics;
int buttonHeight;
int buttonWidth;

View File

@ -16,22 +16,20 @@
#include "keydelegate.h"
#include <QPainter>
#include <QFontDatabase>
#include "keysmodel.h"
#include <shared/global.h>
constexpr int minHeight = 50;
constexpr int minWidth = 400;
constexpr uint8_t margin = 10;
constexpr uint8_t partSize = 8;
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),
fingerPrintFont(Shared::Global::getInstance()->defaultFont),
labelFont(Shared::Global::getInstance()->smallFont),
fingerPrintMetrics(Shared::Global::getInstance()->defaultFontMetrics),
labelFontMetrics(Shared::Global::getInstance()->smallFontMetrics),
spaceWidth(fingerPrintMetrics.horizontalAdvance(" "))
{}

View File

@ -33,10 +33,10 @@ public:
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
private:
QFont fingerPrintFont;
QFont labelFont;
QFontMetrics fingerPrintMetrics;
QFontMetrics labelFontMetrics;
const QFont& fingerPrintFont;
const QFont& labelFont;
const QFontMetrics& fingerPrintMetrics;
const QFontMetrics& labelFontMetrics;
int spaceWidth;
private: