fix: 多显示器大图显示居中

This commit is contained in:
Pluto 2023-03-08 16:18:59 +00:00 committed by Gitee
commit 28326b37c7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 34 additions and 8 deletions

1
.gitignore vendored

@ -52,3 +52,4 @@ debian/files
debian/*.substvars
debian/spark-store
.vscode/*

@ -22,13 +22,13 @@ void image_show::setImage(QPixmap image)
QImage re_screen1;
QImage re_screen0 = screen0.scaled(QSize(400, 300), Qt::KeepAspectRatio, Qt::SmoothTransformation);
// 获取主屏幕尺寸
desktop_w = QGuiApplication::primaryScreen()->geometry().width();
desktop_h = QGuiApplication::primaryScreen()->geometry().height();
// 获取当前app所在的主屏幕尺寸
desktop_w = QGuiApplication::screenAt(QCursor().pos())->geometry().width();
desktop_h = QGuiApplication::screenAt(QCursor().pos())->geometry().height();
if (screen0.width() > (desktop_w - 20) || screen0.height() > (desktop_h - 20))
if (screen0.width() > int(desktop_w / 3 * 2) || screen0.height() > int(desktop_h / 3 * 2))
{
re_screen1 = screen0.scaled(QSize(desktop_w - 20, desktop_h - 20), Qt::KeepAspectRatio, Qt::SmoothTransformation);
re_screen1 = screen0.scaled(QSize(int(desktop_w / 3 * 2), int(desktop_h / 3 * 2)), Qt::KeepAspectRatio, Qt::SmoothTransformation);
m_image = QPixmap::fromImage(re_screen1);
}
else
@ -42,12 +42,12 @@ void image_show::setImage(QPixmap image)
void image_show::mousePressEvent(QMouseEvent *)
{
m_dialog->setimage(m_image);
m_dialog->showFullScreen();
m_dialog->show();
// 识别主屏幕尺寸并设置 widget 大小
m_dialog->setFixedSize(desktop_w, desktop_h);
m_dialog->setFixedSize(qMin(desktop_w, m_image.width() + int(desktop_h / 16 * m_image.width() / m_image.height())), qMin(desktop_h, m_image.height() + int(desktop_h / 16)));
m_dialog->move(0, 0);
m_dialog->move(QGuiApplication::screenAt(QCursor().pos())->geometry().center() - m_dialog->rect().center());
}
image_show::~image_show()
{

@ -43,8 +43,33 @@ int main(int argc, char *argv[])
// 浏览器开启 GPU 支持
#ifdef __sw_64__
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--no-sandbox");
#elif __aarch64__
if (!Utils::isWayland()) {
QString env = QString::fromUtf8(qgetenv("QTWEBENGINE_CHROMIUM_FLAGS"));
env = env.trimmed();
/**
* NOTE: ARM CPU
* --disable-gpu X11
* --single-process X11 QtWebEngine
*/
env += " --disable-gpu";
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", env.trimmed().toUtf8());
QSurfaceFormat format;
format.setRenderableType(QSurfaceFormat::OpenGLES);
QSurfaceFormat::setDefaultFormat(format);
/**
* NOTE: https://zhuanlan.zhihu.com/p/550285855
* X11 QtWebEngine 退 QWidget
*/
qputenv("QMLSCENE_DEVICE", "softwarecontext");
DApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
}
#endif
/**
* FIXME: CPU QtWebEngine
* CPU wayland