Commit 637b7d64 authored by Ming Rui Zhang's avatar Ming Rui Zhang

misc: better dpi scaling performance

Gitlab: #302

On X11 based,
https://bugreports.qt.io/browse/QTBUG-84082

Change-Id: Id775a6a31fc9f6f9493556fca458555c5962727e
parent 2a9e6240
......@@ -18,9 +18,10 @@
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Window 2.14
import net.jami.Adapters 1.0
import net.jami.Constants 1.0
import net.jami.Models 1.0
Item {
id: root
......@@ -98,6 +99,16 @@ Item {
saveAvatarToConfig()
}
function reloadImageSource() {
var tempEnableAnimation = enableAnimation
var tempImageSource = rootImage.source
enableAnimation = false
rootImage.source = ""
rootImage.source = tempImageSource
enableAnimation = tempEnableAnimation
}
Image {
id: rootImage
......@@ -208,4 +219,12 @@ Item {
radius: 30
color: JamiTheme.notificationRed
}
Connections {
target: ScreenInfo
function onDevicePixelRatioChanged(){
reloadImageSource()
}
}
}
......@@ -19,7 +19,8 @@
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtGraphicalEffects 1.14
import QtQuick.Window 2.14
import net.jami.Models 1.0
Image {
id: root
......@@ -34,7 +35,6 @@ Image {
property string checkedSource
property string color: "transparent"
property real pixelDensity: Screen.pixelDensity
property bool isSvg: {
var match = /[^.]+$/.exec(source)
return match !== null && match[0] === 'svg'
......@@ -62,12 +62,20 @@ Image {
function setSourceSize() {
if (isSvg) {
sourceSize.width = width
sourceSize.height = height
} else
sourceSize = Qt.size(0, 0)
sourceSize = Qt.size(width, height)
}
else
sourceSize = undefined
}
onPixelDensityChanged: setSourceSize()
Connections {
target: ScreenInfo
function onDevicePixelRatioChanged(){
setSourceSize()
}
}
Component.onCompleted: setSourceSize()
}
......@@ -36,7 +36,6 @@
#include <QFontDatabase>
#include <QMenu>
#include <QQmlContext>
#include <QWindow>
#include <locale.h>
......@@ -120,6 +119,29 @@ fileDebug(QFile* debugFile)
});
}
void
ScreenInfo::setCurrentFocusWindow(QWindow* window)
{
if (window && !currentFocusWindow_) {
currentFocusWindow_ = window;
setDevicePixelRatio(currentFocusWindow_->screen()->devicePixelRatio());
disconnect(devicePixelRatioConnection_);
disconnect(currentFocusWindowScreenConnection_);
currentFocusWindowScreenConnection_
= connect(currentFocusWindow_, &QWindow::screenChanged, [this] {
currentFocusWindowScreen_ = currentFocusWindow_->screen();
setDevicePixelRatio(currentFocusWindowScreen_->devicePixelRatio());
devicePixelRatioConnection_ = connect(
currentFocusWindowScreen_, &QScreen::physicalDotsPerInchChanged, [this] {
setDevicePixelRatio(currentFocusWindowScreen_->devicePixelRatio());
});
});
}
}
MainApplication::MainApplication(int& argc, char** argv)
: QApplication(argc, argv)
, engine_(new QQmlApplicationEngine())
......@@ -185,11 +207,14 @@ MainApplication::init()
}
#endif
connect(connectivityMonitor_, &ConnectivityMonitor::connectivityChanged, [] {
LRCInstance::connectivityChanged();
});
connect(this, &QGuiApplication::focusWindowChanged, [this] {
screenInfo_.setCurrentFocusWindow(this->focusWindow());
});
QObject::connect(
&LRCInstance::instance(),
&LRCInstance::quitEngineRequested,
......@@ -241,37 +266,27 @@ MainApplication::loadTranslations()
QTranslator* lrcTranslator_lang = new QTranslator(this);
QTranslator* lrcTranslator_name = new QTranslator(this);
if (locale_name != locale_lang) {
if (lrcTranslator_lang->load(appDir
+ QDir::separator() + "libringclient"
+ QDir::separator() + "translations"
+ QDir::separator() + "lrc_"
+ locale_lang)) {
if (lrcTranslator_lang->load(appDir + QDir::separator() + "libringclient" + QDir::separator()
+ "translations" + QDir::separator() + "lrc_" + locale_lang)) {
installTranslator(lrcTranslator_lang);
}
}
if (lrcTranslator_name->load(appDir
+ QDir::separator() + "libringclient"
+ QDir::separator() + "translations"
+ QDir::separator() + "lrc_"
+ locale_name)) {
if (lrcTranslator_name->load(appDir + QDir::separator() + "libringclient" + QDir::separator()
+ "translations" + QDir::separator() + "lrc_" + locale_name)) {
installTranslator(lrcTranslator_name);
}
QTranslator* mainTranslator_lang = new QTranslator(this);
QTranslator* mainTranslator_name = new QTranslator(this);
if (locale_name != locale_lang) {
if (mainTranslator_lang->load(appDir
+ QDir::separator() + "ring"
+ QDir::separator() + "translations"
+ QDir::separator() + "ring_client_windows_"
if (mainTranslator_lang->load(appDir + QDir::separator() + "ring" + QDir::separator()
+ "translations" + QDir::separator() + "ring_client_windows_"
+ locale_lang)) {
installTranslator(mainTranslator_lang);
}
}
if (mainTranslator_name->load(appDir
+ QDir::separator() + "ring"
+ QDir::separator() + "translations"
+ QDir::separator() + "ring_client_windows_"
if (mainTranslator_name->load(appDir + QDir::separator() + "ring" + QDir::separator()
+ "translations" + QDir::separator() + "ring_client_windows_"
+ locale_name)) {
installTranslator(mainTranslator_name);
}
......@@ -381,6 +396,8 @@ MainApplication::initQmlEngine()
engine_->addImageProvider(QLatin1String("tintedPixmap"), new TintedButtonImageProvider());
engine_->addImageProvider(QLatin1String("avatarImage"), new AvatarImageProvider());
engine_->rootContext()->setContextProperty("ScreenInfo", &screenInfo_);
engine_->setObjectOwnership(&LRCInstance::avModel(), QQmlEngine::CppOwnership);
engine_->setObjectOwnership(&LRCInstance::pluginModel(), QQmlEngine::CppOwnership);
engine_->setObjectOwnership(LRCInstance::getUpdateManager(), QQmlEngine::CppOwnership);
......
/*!
/*!
* Copyright (C) 2020 by Savoir-faire Linux
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>
* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
......@@ -24,11 +24,42 @@
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQmlEngine>
#include <QScreen>
#include <QWindow>
#include <memory>
class ConnectivityMonitor;
// Provides information about the screen the app is displayed on
class ScreenInfo : public QObject
{
Q_OBJECT
Q_PROPERTY(double devicePixelRatio MEMBER devicePixelRatio_ NOTIFY devicePixelRatioChanged)
public:
void setCurrentFocusWindow(QWindow* window);
void setDevicePixelRatio(double ratio)
{
if (ratio != devicePixelRatio_) {
devicePixelRatio_ = ratio;
emit devicePixelRatioChanged();
}
}
signals:
void devicePixelRatioChanged();
private:
double devicePixelRatio_ {0.0};
QMetaObject::Connection currentFocusWindowScreenConnection_;
QMetaObject::Connection devicePixelRatioConnection_;
QWindow* currentFocusWindow_ {nullptr};
QScreen* currentFocusWindowScreen_ {nullptr};
};
class MainApplication : public QApplication
{
Q_OBJECT
......@@ -52,5 +83,7 @@ private:
private:
QScopedPointer<QFile> debugFile_;
QScopedPointer<QQmlApplicationEngine> engine_;
ConnectivityMonitor* connectivityMonitor_;
ConnectivityMonitor* connectivityMonitor_ {nullptr};
ScreenInfo screenInfo_;
};
......@@ -49,8 +49,8 @@ Rectangle {
id: jamiLogoImage
Layout.alignment: Qt.AlignCenter
Layout.preferredWidth: welcomePageColumnLayout.width
Layout.preferredHeight: 100
Layout.preferredWidth: Math.min(welcomePageColumnLayout.width, 330)
Layout.preferredHeight: Math.min(welcomePageColumnLayout.width / 3, 110)
Layout.bottomMargin: 10
smooth: true
......
......@@ -65,13 +65,13 @@ Rectangle {
id: welcomeLogo
Layout.alignment: Qt.AlignCenter
Layout.preferredWidth: 300
Layout.preferredHeight: 150
Layout.preferredWidth: 330
Layout.preferredHeight: 110
smooth: true
antialiasing: true
source: JamiTheme.darkTheme? "qrc:/images/logo-jami-standard-coul-white.svg" : "qrc:/images/logo-jami-standard-coul.svg"
source: JamiTheme.darkTheme ? "qrc:/images/logo-jami-standard-coul-white.svg" : "qrc:/images/logo-jami-standard-coul.svg"
}
MaterialButton {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment