Commit af00f1be authored by Ming Rui Zhang's avatar Ming Rui Zhang
Browse files

utils: move scaling ratio into utils

Change-Id: Iead560e5fb38981ce899532577e5b7e4cba24f22
parent f66deea3
......@@ -26,7 +26,6 @@
#include "accountlistmodel.h"
#include "ringthemeutils.h"
#include "lrcinstance.h"
#include "mainwindow.h"
#undef REGISTERED
......@@ -71,7 +70,7 @@ AccountItemDelegate::paint(QPainter* painter,
QFont fontPrimary = painter->font();
QFont fontSecondary = painter->font();
fontPrimary.setWeight(QFont::ExtraLight);
auto scalingRatio = MainWindow::instance().getCurrentScalingRatio();
auto scalingRatio = Utils::getCurrentScalingRatio();
if (scalingRatio > 1.0) {
fontPrimary.setPointSize(fontSize_ - 1);
fontSecondary.setPointSize(fontSize_ - 2);
......
......@@ -290,13 +290,12 @@ CallWidget::navigated(bool to)
void
CallWidget::updateCustomUI()
{
auto scalingRatio = MainWindow::instance().getCurrentScalingRatio();
auto scalingRatio = Utils::getCurrentScalingRatio();
if (scalingRatio > 1.0) {
ui->messageView->setZoomFactor(1.15);
} else {
ui->messageView->setZoomFactor(1.0);
}
}
void
......
......@@ -27,7 +27,6 @@
#include "ringthemeutils.h"
#include "utils.h"
#include "lrcinstance.h"
#include "mainwindow.h"
#include <ciso646>
......@@ -64,7 +63,7 @@ ContactPickerItemDelegate::paint(QPainter* painter
painter->fillRect(option.rect, RingTheme::lightGrey_);
QFont font(painter->font());
QPen pen(painter->pen());
auto scalingRatio = MainWindow::instance().getCurrentScalingRatio();
auto scalingRatio = Utils::getCurrentScalingRatio();
if (scalingRatio > 1.0) {
font.setPointSize(fontSize_ - 2);
} else {
......@@ -156,7 +155,7 @@ ContactPickerItemDelegate::paintRingContactItem(QPainter* painter,
QFont font(painter->font());
QPen pen(painter->pen());
auto scalingRatio = MainWindow::instance().getCurrentScalingRatio();
auto scalingRatio = Utils::getCurrentScalingRatio();
if (scalingRatio > 1.0) {
font.setPointSize(fontSize_ - 2);
} else {
......@@ -217,7 +216,7 @@ ContactPickerItemDelegate::paintSIPContactItem(QPainter* painter,
QPen pen(painter->pen());
painter->setPen(pen);
auto scalingRatio = MainWindow::instance().getCurrentScalingRatio();
auto scalingRatio = Utils::getCurrentScalingRatio();
if (scalingRatio > 1.0) {
font.setPointSize(fontSize_ - 2);
} else {
......
......@@ -29,7 +29,6 @@
#include "ringthemeutils.h"
#include "utils.h"
#include "lrcinstance.h"
#include "mainwindow.h"
#include <ciso646>
......@@ -186,7 +185,7 @@ ConversationItemDelegate::paintConversationItem(QPainter* painter,
int infoTextWidthModifier = 0;
int infoText2HeightModifier = 0;
auto scalingRatio = MainWindow::instance().getCurrentScalingRatio();
auto scalingRatio = Utils::getCurrentScalingRatio();
if (scalingRatio > 1.0) {
font.setPointSize(fontSize_ - 2);
infoTextWidthModifier = 12;
......@@ -361,7 +360,7 @@ ConversationItemDelegate::paintInvitationItem(QPainter* painter,
auto leftMargin = dx_ + sizeImage_ + dx_;
auto rightMargin = dx_;
auto scalingRatio = MainWindow::instance().getCurrentScalingRatio();
auto scalingRatio = Utils::getCurrentScalingRatio();
font.setPointSize(scalingRatio > 1.0 ? fontSize_ - 2 : fontSize_);
if (option.state & QStyle::State_MouseOver) {
......
......@@ -24,7 +24,6 @@
#include "utils.h"
#include "ringthemeutils.h"
#include "lrcinstance.h"
#include "mainwindow.h"
#include <QPixmap>
#include <QMessageBox>
......@@ -133,7 +132,7 @@ CurrentAccountComboBox::paintEvent(QPaintEvent* e)
QFont fontPrimary = QFont(QStringLiteral("Segoe UI Emoji"));
QFont fontSecondary = painter.font();
fontPrimary.setWeight(QFont::ExtraLight);
auto scalingRatio = MainWindow::instance().getCurrentScalingRatio();
auto scalingRatio = Utils::getCurrentScalingRatio();
fontPrimary.setPointSize(scalingRatio > 1.0 ? 10 : 11);
fontSecondary.setPointSize(scalingRatio > 1.0 ? 9 : 10);
......
......@@ -400,7 +400,7 @@ void MainWindow::show()
void MainWindow::slotScreenChanged(QScreen* screen)
{
currentScalingRatio_ = screen->logicalDotsPerInchX() / 96;
Utils::setCurrentScalingRatio(screen->logicalDotsPerInchX() / 96);
qobject_cast<NavWidget*>(ui->navStack->currentWidget())->updateCustomUI();
adjustSize();
updateGeometry();
......@@ -412,11 +412,6 @@ void MainWindow::resizeEvent(QResizeEvent* event)
qobject_cast<NavWidget*>(ui->navStack->currentWidget())->updateCustomUI();
}
float MainWindow::getCurrentScalingRatio()
{
return currentScalingRatio_;
}
void MainWindow::keyReleaseEvent(QKeyEvent* ke)
{
emit keyReleased(ke);
......
......@@ -52,7 +52,6 @@ public:
}
bool init();
void show();
float getCurrentScalingRatio();
void showWindow();
void darken();
void lighten();
......@@ -88,7 +87,6 @@ private:
ScreenEnum lastScr_;
int lastAccountCount_;
Qt::WindowFlags flags_;
float currentScalingRatio_;
Qt::WindowState currentWindowState_{ Qt::WindowState::WindowNoState };
void readSettingsFromRegistry();
......
......@@ -757,6 +757,18 @@ Utils::setupQRCode(QString ringID, int margin)
return result;
}
float
Utils::getCurrentScalingRatio()
{
return CURRENT_SCALING_RATIO;
}
void
Utils::setCurrentScalingRatio(float ratio)
{
CURRENT_SCALING_RATIO = ratio;
}
QString
Utils::formattedTime(int duration)
{
......
......@@ -48,6 +48,7 @@
#include "api/contact.h"
static const QSize IMAGE_SIZE{ 128, 128 };
static float CURRENT_SCALING_RATIO{ 1.0 };
#ifdef BETA
static constexpr bool isBeta = true;
......@@ -75,6 +76,8 @@ void showSystemNotification(QWidget* widget, const QString& sender, const QStrin
QSize getRealSize(QScreen* screen);
void forceDeleteAsync(const QString& path);
QString getChangeLog();
float getCurrentScalingRatio();
void setCurrentScalingRatio(float ratio);
// updates
void cleanUpdateFiles();
......
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