History

Add size and position properties, methods, and events to WebWindow

David Rowe committed 11 years ago

Commit bb2c48e1 parent ea685f42 files · +53 −0Browse files

Showing the changes to interface/src/scripting/WebWindowClass.cpp (1 of 2 files). Show all

Unified · Split

interface/src/scripting/WebWindowClass.cpp+40−0
@@ -58,6 +58,7 @@ WebWindowClass::WebWindowClass(const QString& title, const QString& url, int wid · 57 unmodified lines
5858 auto dialogWidget = new QDialog(Application::getInstance()->getWindow(), Qt::Window);
5959 dialogWidget->setWindowTitle(title);
6060 dialogWidget->resize(width, height);
61+ dialogWidget->installEventFilter(this);
6162 connect(dialogWidget, &QDialog::finished, this, &WebWindowClass::hasClosed);
6263
6364 auto layout = new QVBoxLayout(dialogWidget);
@@ -93,6 +94,19 @@ WebWindowClass::WebWindowClass(const QString& title, const QString& url, int wid · 29 unmodified lines
9394 WebWindowClass::~WebWindowClass() {
9495 }
9596
97+bool WebWindowClass::eventFilter(QObject* sender, QEvent* event) {
98+ if (sender == _windowWidget) {
99+ if (event->type() == QEvent::Move) {
100+ emit moved(getPosition());
101+ }
102+ if (event->type() == QEvent::Resize) {
103+ emit resized(getSize());
104+ }
105+ }
106+
107+ return false;
108+}
109+
96110 void WebWindowClass::hasClosed() {
97111 emit closed();
98112 }
@@ -122,6 +136,32 @@ void WebWindowClass::setURL(const QString& url) { · 23 unmodified lines
122136 _webView->setUrl(url);
123137 }
124138
139+QSizeF WebWindowClass::getSize() const {
140+ QSizeF size = _windowWidget->size();
141+ return size;
142+}
143+
144+void WebWindowClass::setSize(QSizeF size) {
145+ setSize(size.width(), size.height());
146+}
147+
148+void WebWindowClass::setSize(int width, int height) {
149+ if (QThread::currentThread() != thread()) {
150+ QMetaObject::invokeMethod(this, "setSize", Qt::AutoConnection, Q_ARG(int, width), Q_ARG(int, height));
151+ return;
152+ }
153+ _windowWidget->resize(width, height);
154+}
155+
156+glm::vec2 WebWindowClass::getPosition() const {
157+ QPoint position = _windowWidget->pos();
158+ return glm::vec2(position.x(), position.y());
159+}
160+
161+void WebWindowClass::setPosition(glm::vec2 position) {
162+ setPosition(position.x, position.y);
163+}
164+
125165 void WebWindowClass::setPosition(int x, int y) {
126166 if (QThread::currentThread() != thread()) {
127167 QMetaObject::invokeMethod(this, "setPosition", Qt::AutoConnection, Q_ARG(int, x), Q_ARG(int, y));