mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:04:13 +02:00
Merge pull request #5569 from ctrlaltdavid/webwindow-extras
Add size and position properties, methods, and events to WebWindow
This commit is contained in:
commit
494fd6035a
2 changed files with 53 additions and 0 deletions
|
@ -58,6 +58,7 @@ WebWindowClass::WebWindowClass(const QString& title, const QString& url, int wid
|
|||
auto dialogWidget = new QDialog(Application::getInstance()->getWindow(), Qt::Window);
|
||||
dialogWidget->setWindowTitle(title);
|
||||
dialogWidget->resize(width, height);
|
||||
dialogWidget->installEventFilter(this);
|
||||
connect(dialogWidget, &QDialog::finished, this, &WebWindowClass::hasClosed);
|
||||
|
||||
auto layout = new QVBoxLayout(dialogWidget);
|
||||
|
@ -93,6 +94,19 @@ WebWindowClass::WebWindowClass(const QString& title, const QString& url, int wid
|
|||
WebWindowClass::~WebWindowClass() {
|
||||
}
|
||||
|
||||
bool WebWindowClass::eventFilter(QObject* sender, QEvent* event) {
|
||||
if (sender == _windowWidget) {
|
||||
if (event->type() == QEvent::Move) {
|
||||
emit moved(getPosition());
|
||||
}
|
||||
if (event->type() == QEvent::Resize) {
|
||||
emit resized(getSize());
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void WebWindowClass::hasClosed() {
|
||||
emit closed();
|
||||
}
|
||||
|
@ -122,6 +136,32 @@ void WebWindowClass::setURL(const QString& url) {
|
|||
_webView->setUrl(url);
|
||||
}
|
||||
|
||||
QSizeF WebWindowClass::getSize() const {
|
||||
QSizeF size = _windowWidget->size();
|
||||
return size;
|
||||
}
|
||||
|
||||
void WebWindowClass::setSize(QSizeF size) {
|
||||
setSize(size.width(), size.height());
|
||||
}
|
||||
|
||||
void WebWindowClass::setSize(int width, int height) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "setSize", Qt::AutoConnection, Q_ARG(int, width), Q_ARG(int, height));
|
||||
return;
|
||||
}
|
||||
_windowWidget->resize(width, height);
|
||||
}
|
||||
|
||||
glm::vec2 WebWindowClass::getPosition() const {
|
||||
QPoint position = _windowWidget->pos();
|
||||
return glm::vec2(position.x(), position.y());
|
||||
}
|
||||
|
||||
void WebWindowClass::setPosition(glm::vec2 position) {
|
||||
setPosition(position.x, position.y);
|
||||
}
|
||||
|
||||
void WebWindowClass::setPosition(int x, int y) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "setPosition", Qt::AutoConnection, Q_ARG(int, x), Q_ARG(int, y));
|
||||
|
|
|
@ -35,6 +35,9 @@ class WebWindowClass : public QObject {
|
|||
Q_OBJECT
|
||||
Q_PROPERTY(QObject* eventBridge READ getEventBridge)
|
||||
Q_PROPERTY(QString url READ getURL)
|
||||
Q_PROPERTY(glm::vec2 position READ getPosition WRITE setPosition);
|
||||
Q_PROPERTY(QSizeF size READ getSize WRITE setSize);
|
||||
|
||||
public:
|
||||
WebWindowClass(const QString& title, const QString& url, int width, int height, bool isToolWindow = false);
|
||||
~WebWindowClass();
|
||||
|
@ -43,7 +46,12 @@ public:
|
|||
|
||||
public slots:
|
||||
void setVisible(bool visible);
|
||||
glm::vec2 getPosition() const;
|
||||
void setPosition(int x, int y);
|
||||
void setPosition(glm::vec2 position);
|
||||
QSizeF getSize() const;
|
||||
void setSize(QSizeF size);
|
||||
void setSize(int width, int height);
|
||||
QString getURL() const { return _webView->url().url(); }
|
||||
void setURL(const QString& url);
|
||||
void raise();
|
||||
|
@ -52,8 +60,13 @@ public slots:
|
|||
void setTitle(const QString& title);
|
||||
|
||||
signals:
|
||||
void moved(glm::vec2 position);
|
||||
void resized(QSizeF size);
|
||||
void closed();
|
||||
|
||||
protected:
|
||||
virtual bool eventFilter(QObject* sender, QEvent* event);
|
||||
|
||||
private slots:
|
||||
void hasClosed();
|
||||
|
||||
|
|
Loading…
Reference in a new issue