mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Use the correct avatar size for HiDPI displays
This commit is contained in:
parent
05585ff8cf
commit
18061f0600
9 changed files with 48 additions and 34 deletions
|
@ -84,11 +84,3 @@ private:
|
||||||
|
|
||||||
RippleOverlay *rippleOverlay_;
|
RippleOverlay *rippleOverlay_;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void
|
|
||||||
CommunitiesListItem::setAvatar(const QImage &img)
|
|
||||||
{
|
|
||||||
communityAvatar_ = QPixmap::fromImage(
|
|
||||||
img.scaled(IconSize, IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "timeline/widgets/VideoItem.h"
|
#include "timeline/widgets/VideoItem.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QPixmap>
|
||||||
#include <mtx/events/collections.hpp>
|
#include <mtx/events/collections.hpp>
|
||||||
|
|
||||||
namespace utils {
|
namespace utils {
|
||||||
|
@ -168,4 +169,7 @@ message_body(const mtx::events::collections::TimelineEvents &event)
|
||||||
//! Calculate the Levenshtein distance between two strings with character skipping.
|
//! Calculate the Levenshtein distance between two strings with character skipping.
|
||||||
int
|
int
|
||||||
levenshtein_distance(const std::string &s1, const std::string &s2);
|
levenshtein_distance(const std::string &s1, const std::string &s2);
|
||||||
|
|
||||||
|
QPixmap
|
||||||
|
scaleImageToPixmap(const QImage &img, int size);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,21 +22,8 @@ class TopSection : public QWidget
|
||||||
Q_PROPERTY(QColor textColor WRITE setTextColor READ textColor)
|
Q_PROPERTY(QColor textColor WRITE setTextColor READ textColor)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TopSection(const RoomInfo &info, const QImage &img, QWidget *parent = nullptr)
|
TopSection(const RoomInfo &info, const QImage &img, QWidget *parent = nullptr);
|
||||||
: QWidget{parent}
|
QSize sizeHint() const override;
|
||||||
, info_{std::move(info)}
|
|
||||||
{
|
|
||||||
textColor_ = palette().color(QPalette::Text);
|
|
||||||
avatar_ = QPixmap::fromImage(img.scaled(
|
|
||||||
AvatarSize, AvatarSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize sizeHint() const override
|
|
||||||
{
|
|
||||||
QFont font;
|
|
||||||
font.setPixelSize(18);
|
|
||||||
return QSize(200, AvatarSize + QFontMetrics(font).ascent() + 6 * Padding);
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor textColor() const { return textColor_; }
|
QColor textColor() const { return textColor_; }
|
||||||
void setTextColor(QColor &color) { textColor_ = color; }
|
void setTextColor(QColor &color) { textColor_ = color; }
|
||||||
|
|
|
@ -88,3 +88,10 @@ CommunitiesListItem::paintEvent(QPaintEvent *)
|
||||||
p.restore();
|
p.restore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CommunitiesListItem::setAvatar(const QImage &img)
|
||||||
|
{
|
||||||
|
communityAvatar_ = utils::scaleImageToPixmap(img, IconSize);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
|
@ -59,6 +59,8 @@ MatrixClient::MatrixClient(QObject *parent)
|
||||||
, mediaApiUrl_{"/_matrix/media/r0"}
|
, mediaApiUrl_{"/_matrix/media/r0"}
|
||||||
, serverProtocol_{"https"}
|
, serverProtocol_{"https"}
|
||||||
{
|
{
|
||||||
|
qRegisterMetaType<mtx::responses::Sync>();
|
||||||
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
txn_id_ = settings.value("client/transaction_id", 1).toInt();
|
txn_id_ = settings.value("client/transaction_id", 1).toInt();
|
||||||
|
|
||||||
|
@ -344,8 +346,7 @@ MatrixClient::sync() noexcept
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mtx::responses::Sync response = nlohmann::json::parse(data);
|
emit syncCompleted(nlohmann::json::parse(std::move(data)));
|
||||||
emit syncCompleted(response);
|
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
qWarning() << "Sync error: " << e.what();
|
qWarning() << "Sync error: " << e.what();
|
||||||
}
|
}
|
||||||
|
@ -461,7 +462,6 @@ MatrixClient::initialSync() noexcept
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qRegisterMetaType<mtx::responses::Sync>();
|
|
||||||
QtConcurrent::run([data = reply->readAll(), this]() {
|
QtConcurrent::run([data = reply->readAll(), this]() {
|
||||||
try {
|
try {
|
||||||
emit initialSyncCompleted(nlohmann::json::parse(std::move(data)));
|
emit initialSyncCompleted(nlohmann::json::parse(std::move(data)));
|
||||||
|
|
|
@ -368,8 +368,7 @@ RoomInfoListItem::mousePressEvent(QMouseEvent *event)
|
||||||
void
|
void
|
||||||
RoomInfoListItem::setAvatar(const QImage &img)
|
RoomInfoListItem::setAvatar(const QImage &img)
|
||||||
{
|
{
|
||||||
roomAvatar_ = QPixmap::fromImage(
|
roomAvatar_ = utils::scaleImageToPixmap(img, IconSize);
|
||||||
img.scaled(IconSize, IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
src/Utils.cc
11
src/Utils.cc
|
@ -1,5 +1,8 @@
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QDesktopWidget>
|
||||||
|
|
||||||
#include <variant.hpp>
|
#include <variant.hpp>
|
||||||
|
|
||||||
using TimelineEvent = mtx::events::collections::TimelineEvents;
|
using TimelineEvent = mtx::events::collections::TimelineEvents;
|
||||||
|
@ -138,3 +141,11 @@ utils::event_body(const mtx::events::collections::TimelineEvents &event)
|
||||||
|
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPixmap
|
||||||
|
utils::scaleImageToPixmap(const QImage &img, int size)
|
||||||
|
{
|
||||||
|
const int sz = QApplication::desktop()->screen()->devicePixelRatio() * size;
|
||||||
|
return QPixmap::fromImage(
|
||||||
|
img.scaled(sz, sz, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||||
|
}
|
||||||
|
|
|
@ -15,6 +15,22 @@
|
||||||
|
|
||||||
using namespace dialogs;
|
using namespace dialogs;
|
||||||
|
|
||||||
|
TopSection::TopSection(const RoomInfo &info, const QImage &img, QWidget *parent)
|
||||||
|
: QWidget{parent}
|
||||||
|
, info_{std::move(info)}
|
||||||
|
{
|
||||||
|
textColor_ = palette().color(QPalette::Text);
|
||||||
|
avatar_ = utils::scaleImageToPixmap(img, AvatarSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize
|
||||||
|
TopSection::sizeHint() const
|
||||||
|
{
|
||||||
|
QFont font;
|
||||||
|
font.setPixelSize(18);
|
||||||
|
return QSize(200, AvatarSize + QFontMetrics(font).ascent() + 6 * Padding);
|
||||||
|
}
|
||||||
|
|
||||||
RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
|
RoomSettings::RoomSettings(const QString &room_id, QWidget *parent)
|
||||||
: QFrame(parent)
|
: QFrame(parent)
|
||||||
, room_id_{std::move(room_id)}
|
, room_id_{std::move(room_id)}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#include "Avatar.h"
|
#include "Avatar.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
Avatar::Avatar(QWidget *parent)
|
Avatar::Avatar(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
@ -64,10 +65,8 @@ Avatar::setSize(int size)
|
||||||
{
|
{
|
||||||
size_ = size;
|
size_ = size;
|
||||||
|
|
||||||
if (!image_.isNull()) {
|
if (!image_.isNull())
|
||||||
pixmap_ = QPixmap::fromImage(
|
pixmap_ = utils::scaleImageToPixmap(image_, size_);
|
||||||
image_.scaled(size_, size_, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
|
||||||
}
|
|
||||||
|
|
||||||
QFont _font(font());
|
QFont _font(font());
|
||||||
_font.setPointSizeF(size_ * (ui::FontSize) / 40);
|
_font.setPointSizeF(size_ * (ui::FontSize) / 40);
|
||||||
|
@ -89,8 +88,7 @@ Avatar::setImage(const QImage &image)
|
||||||
{
|
{
|
||||||
image_ = image;
|
image_ = image;
|
||||||
type_ = ui::AvatarType::Image;
|
type_ = ui::AvatarType::Image;
|
||||||
pixmap_ = QPixmap::fromImage(
|
pixmap_ = utils::scaleImageToPixmap(image_, size_);
|
||||||
image_.scaled(size_, size_, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue