Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ ApplicationWindow {

Component.onCompleted: {
if (IV.FileControl.isCheckOnly()) {
setX(screen.width / 2 - width / 2);
setY(screen.height / 2 - height / 2);
setX(IV.FileControl.getPrimaryScreenCenterX(width));
setY(IV.FileControl.getPrimaryScreenCenterY(height));
}
}
onClosing: {
Expand All @@ -61,6 +61,10 @@ ApplicationWindow {
Connections {
function onCurrentSourceChanged() {
window.title = IV.FileControl.slotGetFileName(IV.GControl.currentSource) + IV.FileControl.slotFileSuffix(IV.GControl.currentSource);
if (window.visibility !== Window.FullScreen && window.visibility !== Window.Maximized) {
setX(IV.FileControl.getPrimaryScreenCenterX(width));
setY(IV.FileControl.getPrimaryScreenCenterY(height));
}
}

target: IV.GControl
Expand Down
20 changes: 20 additions & 0 deletions src/src/filecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,26 @@ int FileControl::getlastHeight()
return reHeight;
}

int FileControl::getPrimaryScreenCenterX(int windowWidth)
{
QScreen *screen = QGuiApplication::primaryScreen();
if (!screen) {
return 0;
}
QRect geometry = screen->geometry();
return geometry.x() + geometry.width() / 2 - windowWidth / 2;
}

int FileControl::getPrimaryScreenCenterY(int windowHeight)
{
QScreen *screen = QGuiApplication::primaryScreen();
if (!screen) {
return 0;
}
QRect geometry = screen->geometry();
return geometry.y() + geometry.height() / 2 - windowHeight / 2;
}

void FileControl::setSettingWidth(int width)
{
qCDebug(logImageViewer) << "FileControl::setSettingWidth() called with width: " << width;
Expand Down
3 changes: 3 additions & 0 deletions src/src/filecontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class FileControl : public QObject
Q_INVOKABLE int getlastHeight();
Q_INVOKABLE void setSettingWidth(int width);
Q_INVOKABLE void setSettingHeight(int height);
// 获取主屏幕中心坐标
Q_INVOKABLE int getPrimaryScreenCenterX(int windowWidth);
Q_INVOKABLE int getPrimaryScreenCenterY(int windowHeight);
Q_INVOKABLE void setEnableNavigation(bool b); // 设置是否允许展示导航窗口
Q_INVOKABLE bool isEnableNavigation();

Expand Down
Loading