Skip to content

Commit

Permalink
[Quick-Event#905 fixed] ERR Windows: Modal okna mimo zobrazitelnou pl…
Browse files Browse the repository at this point in the history
…ochu
  • Loading branch information
Fanda Vacek committed Aug 29, 2023
1 parent 74a60b2 commit 5a3b444
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
10 changes: 5 additions & 5 deletions libqf/libqfqmlwidgets/src/dialogs/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ void Dialog::loadPersistentSettings()
QRect geometry = settings.value("geometry").toRect();
if(geometry.isValid()) {
if(isSavePersistentPosition()) {
geometry = qf::qmlwidgets::internal::DesktopUtils::moveRectToVisibleDesktopScreen(geometry);
this->setGeometry(geometry);
}
else {
this->resize(geometry.size());
if(auto geometry2 = qf::qmlwidgets::internal::DesktopUtils::moveRectToVisibleDesktopScreen(geometry); geometry2.isValid()) {
setGeometry(geometry2);
return;
}
}
this->resize(geometry.size());
}
}
}
Expand Down
24 changes: 19 additions & 5 deletions libqf/libqfqmlwidgets/src/internal/desktoputils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,33 @@ namespace qf {
namespace qmlwidgets {
namespace internal {

QRect DesktopUtils::moveRectToVisibleDesktopScreen(const QRect &r)
QRect DesktopUtils::moveRectToVisibleDesktopScreen(const QRect &rect)
{
QRect ret = r;
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
QScreen *scr = QApplication::screenAt(ret.topLeft());
QRect screen_rect = scr? scr->geometry(): QRect();
QScreen *scr = QApplication::screenAt(rect.topLeft());
if(!scr) {
scr = QApplication::primaryScreen();
}
if(!scr) {
return {};
}
QRect screen_rect = scr->geometry();
if(screen_rect.contains(rect.topLeft())) {
return rect;
}
else {
auto ret = rect;
ret.moveCenter(screen_rect.center());
return ret;
}
#else
auto ret = rect;
QDesktopWidget *dw = QApplication::desktop();
QRect screen_rect = dw->screenGeometry(ret.topLeft());
#endif
if(screen_rect.isValid() && !screen_rect.contains(ret.topLeft()))
ret.moveTopLeft(screen_rect.topLeft());
return ret;
#endif
}


Expand Down
2 changes: 1 addition & 1 deletion libqf/libqfqmlwidgets/src/internal/desktoputils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace internal {
class DesktopUtils
{
public:
static QRect moveRectToVisibleDesktopScreen(const QRect &r);
static QRect moveRectToVisibleDesktopScreen(const QRect &rect);
};

} // namespace internal
Expand Down

0 comments on commit 5a3b444

Please sign in to comment.