Merge pull request #12777 from ctrlaltdavid/21813

Fix Window API position and size reporting
This commit is contained in:
John Conklin II 2018-04-11 13:48:21 -07:00 committed by GitHub
commit 7a905ed420
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 7 deletions

View file

@ -51,7 +51,7 @@ WindowScriptingInterface::WindowScriptingInterface() {
}
});
connect(qApp->getWindow(), &MainWindow::windowGeometryChanged, this, &WindowScriptingInterface::geometryChanged);
connect(qApp->getWindow(), &MainWindow::windowGeometryChanged, this, &WindowScriptingInterface::onWindowGeometryChanged);
}
WindowScriptingInterface::~WindowScriptingInterface() {
@ -390,11 +390,22 @@ glm::vec2 WindowScriptingInterface::getDeviceSize() const {
}
int WindowScriptingInterface::getX() {
return qApp->getWindow()->x();
return qApp->getWindow()->geometry().x();
}
int WindowScriptingInterface::getY() {
return qApp->getWindow()->y();
auto menu = qApp->getPrimaryMenu();
int menuHeight = menu ? menu->geometry().height() : 0;
return qApp->getWindow()->geometry().y() + menuHeight;
}
void WindowScriptingInterface::onWindowGeometryChanged(const QRect& windowGeometry) {
auto geometry = windowGeometry;
auto menu = qApp->getPrimaryMenu();
if (menu) {
geometry.setY(geometry.y() + menu->geometry().height());
}
emit geometryChanged(geometry);
}
void WindowScriptingInterface::copyToClipboard(const QString& text) {

View file

@ -33,8 +33,10 @@
* @property {number} innerHeight - The height of the drawable area of the Interface window (i.e., without borders or other
* chrome), in pixels. <em>Read-only.</em>
* @property {object} location - Provides facilities for working with your current metaverse location. See {@link location}.
* @property {number} x - The x coordinate of the top left corner of the Interface window on the display. <em>Read-only.</em>
* @property {number} y - The y coordinate of the top left corner of the Interface window on the display. <em>Read-only.</em>
* @property {number} x - The x display coordinate of the top left corner of the drawable area of the Interface window.
* <em>Read-only.</em>
* @property {number} y - The y display coordinate of the top left corner of the drawable area of the Interface window.
* <em>Read-only.</em>
*/
class WindowScriptingInterface : public QObject, public Dependency {
@ -522,6 +524,7 @@ public slots:
void closeMessageBox(int id);
private slots:
void onWindowGeometryChanged(const QRect& geometry);
void onMessageBoxSelected(int button);
void disconnectedFromDomain();

View file

@ -79,12 +79,12 @@ void MainWindow::closeEvent(QCloseEvent* event) {
}
void MainWindow::moveEvent(QMoveEvent* event) {
emit windowGeometryChanged(QRect(event->pos(), size()));
emit windowGeometryChanged(QRect(QPoint(geometry().x(), geometry().y()), size())); // Geometry excluding the window frame.
QMainWindow::moveEvent(event);
}
void MainWindow::resizeEvent(QResizeEvent* event) {
emit windowGeometryChanged(QRect(QPoint(x(), y()), event->size()));
emit windowGeometryChanged(QRect(QPoint(geometry().x(), geometry().y()), size())); // Geometry excluding the window frame.
QMainWindow::resizeEvent(event);
}