mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +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_;
|
||||
};
|
||||
|
||||
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 <QDateTime>
|
||||
#include <QPixmap>
|
||||
#include <mtx/events/collections.hpp>
|
||||
|
||||
namespace utils {
|
||||
|
@ -168,4 +169,7 @@ message_body(const mtx::events::collections::TimelineEvents &event)
|
|||
//! Calculate the Levenshtein distance between two strings with character skipping.
|
||||
int
|
||||
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)
|
||||
|
||||
public:
|
||||
TopSection(const RoomInfo &info, const QImage &img, QWidget *parent = nullptr)
|
||||
: QWidget{parent}
|
||||
, 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);
|
||||
}
|
||||
TopSection(const RoomInfo &info, const QImage &img, QWidget *parent = nullptr);
|
||||
QSize sizeHint() const override;
|
||||
|
||||
QColor textColor() const { return textColor_; }
|
||||
void setTextColor(QColor &color) { textColor_ = color; }
|
||||
|
|
|
@ -88,3 +88,10 @@ CommunitiesListItem::paintEvent(QPaintEvent *)
|
|||
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"}
|
||||
, serverProtocol_{"https"}
|
||||
{
|
||||
qRegisterMetaType<mtx::responses::Sync>();
|
||||
|
||||
QSettings settings;
|
||||
txn_id_ = settings.value("client/transaction_id", 1).toInt();
|
||||
|
||||
|
@ -344,8 +346,7 @@ MatrixClient::sync() noexcept
|
|||
}
|
||||
|
||||
try {
|
||||
mtx::responses::Sync response = nlohmann::json::parse(data);
|
||||
emit syncCompleted(response);
|
||||
emit syncCompleted(nlohmann::json::parse(std::move(data)));
|
||||
} catch (std::exception &e) {
|
||||
qWarning() << "Sync error: " << e.what();
|
||||
}
|
||||
|
@ -461,7 +462,6 @@ MatrixClient::initialSync() noexcept
|
|||
return;
|
||||
}
|
||||
|
||||
qRegisterMetaType<mtx::responses::Sync>();
|
||||
QtConcurrent::run([data = reply->readAll(), this]() {
|
||||
try {
|
||||
emit initialSyncCompleted(nlohmann::json::parse(std::move(data)));
|
||||
|
|
|
@ -368,8 +368,7 @@ RoomInfoListItem::mousePressEvent(QMouseEvent *event)
|
|||
void
|
||||
RoomInfoListItem::setAvatar(const QImage &img)
|
||||
{
|
||||
roomAvatar_ = QPixmap::fromImage(
|
||||
img.scaled(IconSize, IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||
roomAvatar_ = utils::scaleImageToPixmap(img, IconSize);
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
11
src/Utils.cc
11
src/Utils.cc
|
@ -1,5 +1,8 @@
|
|||
#include "Utils.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
|
||||
#include <variant.hpp>
|
||||
|
||||
using TimelineEvent = mtx::events::collections::TimelineEvents;
|
||||
|
@ -138,3 +141,11 @@ utils::event_body(const mtx::events::collections::TimelineEvents &event)
|
|||
|
||||
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;
|
||||
|
||||
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)
|
||||
: QFrame(parent)
|
||||
, room_id_{std::move(room_id)}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <QPainter>
|
||||
|
||||
#include "Avatar.h"
|
||||
#include "Utils.h"
|
||||
|
||||
Avatar::Avatar(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
|
@ -64,10 +65,8 @@ Avatar::setSize(int size)
|
|||
{
|
||||
size_ = size;
|
||||
|
||||
if (!image_.isNull()) {
|
||||
pixmap_ = QPixmap::fromImage(
|
||||
image_.scaled(size_, size_, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
}
|
||||
if (!image_.isNull())
|
||||
pixmap_ = utils::scaleImageToPixmap(image_, size_);
|
||||
|
||||
QFont _font(font());
|
||||
_font.setPointSizeF(size_ * (ui::FontSize) / 40);
|
||||
|
@ -89,8 +88,7 @@ Avatar::setImage(const QImage &image)
|
|||
{
|
||||
image_ = image;
|
||||
type_ = ui::AvatarType::Image;
|
||||
pixmap_ = QPixmap::fromImage(
|
||||
image_.scaled(size_, size_, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
pixmap_ = utils::scaleImageToPixmap(image_, size_);
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue