mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +08:00
MainWindow: decide DPI on the screen where vnote starts
This commit is contained in:
parent
956842f102
commit
fa238b3e22
26
src/main.cpp
26
src/main.cpp
@ -8,6 +8,8 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QSysInfo>
|
#include <QSysInfo>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
#include <QWebEngineSettings>
|
||||||
|
#include <QWindow>
|
||||||
|
|
||||||
#include <core/configmgr.h>
|
#include <core/configmgr.h>
|
||||||
#include <core/mainconfig.h>
|
#include <core/mainconfig.h>
|
||||||
@ -17,8 +19,8 @@
|
|||||||
#include <core/vnotex.h>
|
#include <core/vnotex.h>
|
||||||
#include <core/logger.h>
|
#include <core/logger.h>
|
||||||
#include <widgets/mainwindow.h>
|
#include <widgets/mainwindow.h>
|
||||||
#include <QWebEngineSettings>
|
|
||||||
#include <core/exception.h>
|
#include <core/exception.h>
|
||||||
|
#include <utils/widgetutils.h>
|
||||||
#include <widgets/messageboxhelper.h>
|
#include <widgets/messageboxhelper.h>
|
||||||
#include "commandlineoptions.h"
|
#include "commandlineoptions.h"
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
@ -145,17 +147,8 @@ int main(int argc, char *argv[])
|
|||||||
// Should set the correct locale before VNoteX::getInst().
|
// Should set the correct locale before VNoteX::getInst().
|
||||||
loadTranslators(app);
|
loadTranslators(app);
|
||||||
|
|
||||||
if (app.styleSheet().isEmpty()) {
|
|
||||||
auto style = VNoteX::getInst().getThemeMgr().fetchQtStyleSheet();
|
|
||||||
if (!style.isEmpty()) {
|
|
||||||
app.setStyleSheet(style);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MainWindow window;
|
MainWindow window;
|
||||||
|
|
||||||
window.show();
|
window.show();
|
||||||
VNoteX::getInst().getThemeMgr().setBaseBackground(window.palette().color(QPalette::Base));
|
|
||||||
|
|
||||||
QObject::connect(&guard, &SingleInstanceGuard::showRequested,
|
QObject::connect(&guard, &SingleInstanceGuard::showRequested,
|
||||||
&window, &MainWindow::showMainWindow);
|
&window, &MainWindow::showMainWindow);
|
||||||
@ -167,6 +160,19 @@ int main(int argc, char *argv[])
|
|||||||
window.openFiles(QStringList() << p_filePath);
|
window.openFiles(QStringList() << p_filePath);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Let MainWindow show first to decide the screen on which app is running.
|
||||||
|
WidgetUtils::calculateScaleFactor(window.windowHandle()->screen());
|
||||||
|
|
||||||
|
if (app.styleSheet().isEmpty()) {
|
||||||
|
auto style = VNoteX::getInst().getThemeMgr().fetchQtStyleSheet();
|
||||||
|
if (!style.isEmpty()) {
|
||||||
|
app.setStyleSheet(style);
|
||||||
|
WidgetUtils::updateStyle(&window);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VNoteX::getInst().getThemeMgr().setBaseBackground(window.palette().color(QPalette::Base));
|
||||||
|
|
||||||
window.kickOffOnStart(cmdOptions.m_pathsToOpen);
|
window.kickOffOnStart(cmdOptions.m_pathsToOpen);
|
||||||
|
|
||||||
int ret = app.exec();
|
int ret = app.exec();
|
||||||
|
@ -45,12 +45,14 @@ void WidgetUtils::updateStyle(QWidget *p_widget)
|
|||||||
p_widget->update();
|
p_widget->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal WidgetUtils::calculateScaleFactor(bool p_update)
|
qreal WidgetUtils::calculateScaleFactor(const QScreen *p_screen)
|
||||||
{
|
{
|
||||||
static qreal factor = -1;
|
static qreal factor = -1;
|
||||||
|
|
||||||
if (factor < 0 || p_update) {
|
if (factor < 0 || p_screen) {
|
||||||
factor = QGuiApplication::primaryScreen()->devicePixelRatio();
|
auto screen = p_screen ? p_screen : QGuiApplication::primaryScreen();
|
||||||
|
factor = screen->devicePixelRatio();
|
||||||
|
qDebug() << screen->name() << "dpi" << factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
return factor;
|
return factor;
|
||||||
|
@ -21,6 +21,7 @@ class QLineEdit;
|
|||||||
class QLayout;
|
class QLayout;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
class QSplitter;
|
class QSplitter;
|
||||||
|
class QScreen;
|
||||||
|
|
||||||
namespace vnotex
|
namespace vnotex
|
||||||
{
|
{
|
||||||
@ -35,7 +36,7 @@ namespace vnotex
|
|||||||
|
|
||||||
static void updateStyle(QWidget *p_widget);
|
static void updateStyle(QWidget *p_widget);
|
||||||
|
|
||||||
static qreal calculateScaleFactor(bool p_update = false);
|
static qreal calculateScaleFactor(const QScreen *p_screen = nullptr);
|
||||||
|
|
||||||
static bool isScrollBarVisible(QAbstractScrollArea *p_widget, bool p_horizontal);
|
static bool isScrollBarVisible(QAbstractScrollArea *p_widget, bool p_horizontal);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user