diff --git a/src/accountitemdelegate.cpp b/src/accountitemdelegate.cpp index 96ce2a39f735e835b680b03fc0679fba2a84cc23..49db13cd593f11b542318e569dcb8a75e5ca85fa 100644 --- a/src/accountitemdelegate.cpp +++ b/src/accountitemdelegate.cpp @@ -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); diff --git a/src/callwidget.cpp b/src/callwidget.cpp index e793d4217df92b499887976b5a1cbeb58e58b188..8bfc450e268efa190a6459d71c970d8049ad2d5a 100644 --- a/src/callwidget.cpp +++ b/src/callwidget.cpp @@ -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 diff --git a/src/contactpickeritemdelegate.cpp b/src/contactpickeritemdelegate.cpp index f0c0e8e650c5890738e2c5d2c543642ec18856e6..e8ae4d58dae4a16261c1c5cc532a40bfb8dbc1bb 100644 --- a/src/contactpickeritemdelegate.cpp +++ b/src/contactpickeritemdelegate.cpp @@ -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 { diff --git a/src/conversationitemdelegate.cpp b/src/conversationitemdelegate.cpp index 19f953ca725b2f57c53ea7ad3bfda14ce7d267e0..97692a01274789aa60b48bb3ce30729466569eb4 100644 --- a/src/conversationitemdelegate.cpp +++ b/src/conversationitemdelegate.cpp @@ -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) { diff --git a/src/currentaccountcombobox.cpp b/src/currentaccountcombobox.cpp index e66026341c3a21d4414d27355fc2d29d0ad32b01..69b228217ead62b73727d7d4d8ec907fa2b7bb16 100644 --- a/src/currentaccountcombobox.cpp +++ b/src/currentaccountcombobox.cpp @@ -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); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index aca3b70e54a6ed14a902688c36e1325bd7b88a2f..f5da61097cafd64e204fa8497516a71259e52e08 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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); diff --git a/src/mainwindow.h b/src/mainwindow.h index 75a6c3d4b0ef2839cc74f6bf0f61e260623522f0..cd019c74dddbd1d6c388609cd963e38f07963036 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -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(); diff --git a/src/utils.cpp b/src/utils.cpp index 92c556b117b99861dd3043e2fca82db6a7d81e47..4253d666c142ce5dec946b52f544e84cdb5da191 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -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) { diff --git a/src/utils.h b/src/utils.h index 8d638987f44db5b412699c4594ec7b91990750b8..c9f4076fd64d8a468e867314c3e20f89b95126bf 100644 --- a/src/utils.h +++ b/src/utils.h @@ -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();