Added setGeometry script command.

This commit is contained in:
NissimHadar 2018-11-02 13:09:07 -07:00
parent 70c0addc3f
commit 51272d8fec
4 changed files with 32 additions and 0 deletions

View file

@ -3636,6 +3636,12 @@ void Application::onPresent(quint32 frameCount) {
if (_renderEventHandler && !isAboutToQuit() && _pendingRenderEvent.compare_exchange_strong(expected, true)) {
postEvent(_renderEventHandler, new QEvent((QEvent::Type)ApplicationEvent::Render));
}
// This is done here so it won't be during a resize/move event
if (_setGeometryRequested) {
_setGeometryRequested = false;
_window->setGeometry(requestedGeometry);
}
}
static inline bool isKeyEvent(QEvent::Type type) {
@ -8578,6 +8584,12 @@ void Application::copyToClipboard(const QString& text) {
QApplication::clipboard()->setText(text);
}
void Application::setGeometry(int x, int y, int width, int height) {
// Note that calling setGeometry inside resizeEvent() or moveEvent() can cause infinite recursion
requestedGeometry = QRect(x, y, width, height);
_setGeometryRequested = true;
}
#if defined(Q_OS_ANDROID)
void Application::beforeEnterBackground() {
auto nodeList = DependencyManager::get<NodeList>();

View file

@ -315,6 +315,8 @@ public:
Q_INVOKABLE void copyToClipboard(const QString& text);
void setGeometry(int x, int y, int width, int height);
int getOtherAvatarsReplicaCount() { return DependencyManager::get<AvatarHashMap>()->getReplicaCount(); }
void setOtherAvatarsReplicaCount(int count) { DependencyManager::get<AvatarHashMap>()->setReplicaCount(count); }
@ -784,5 +786,9 @@ private:
bool _showTrackedObjects { false };
bool _prevShowTrackedObjects { false };
// Data for the setGeometry script command
bool _setGeometryRequested{ false };
QRect requestedGeometry;
};
#endif // hifi_Application_h

View file

@ -209,3 +209,7 @@ QString TestScriptingInterface::getOperatingSystemType() {
return "UNKNOWN";
#endif
}
void TestScriptingInterface::setGeometry(int x, int y, int width, int height) {
qApp->setGeometry(x, y, width, height);
}

View file

@ -170,6 +170,16 @@ public slots:
*/
QString getOperatingSystemType();
/**jsdoc
* Sets the position and size of the window on desktop. All units are pixels
* @function Test.setGeometry
* @param {int} x - Distance of window from left edge
* @param {int} y - Distance of window from top edge
* @param {int} width - Width of window
* @param {int} height - Height of window
*/
void setGeometry(int x, int y, int width, int height);
private:
bool waitForCondition(qint64 maxWaitMs, std::function<bool()> condition);
QString _testResultsLocation;