mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 02:36:54 +02:00
More coding standard
This commit is contained in:
parent
732e9723cd
commit
44efcdf82a
3 changed files with 39 additions and 33 deletions
|
@ -239,17 +239,17 @@ void OffscreenUi::updateQuick() {
|
||||||
emit textureUpdated(fbo->texture());
|
emit textureUpdated(fbo->texture());
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF OffscreenUi::mapWindowToUi(const QPointF& p, QObject* dest) {
|
QPointF OffscreenUi::mapWindowToUi(const QPointF& sourcePosition, QObject* sourceObject) {
|
||||||
vec2 sourceSize;
|
vec2 sourceSize;
|
||||||
if (dynamic_cast<QWidget*>(dest)) {
|
if (dynamic_cast<QWidget*>(sourceObject)) {
|
||||||
sourceSize = toGlm(((QWidget*)dest)->size());
|
sourceSize = toGlm(((QWidget*)sourceObject)->size());
|
||||||
} else if (dynamic_cast<QWindow*>(dest)) {
|
} else if (dynamic_cast<QWindow*>(sourceObject)) {
|
||||||
sourceSize = toGlm(((QWindow*)dest)->size());
|
sourceSize = toGlm(((QWindow*)sourceObject)->size());
|
||||||
}
|
}
|
||||||
vec2 pos = toGlm(p);
|
vec2 offscreenPosition = toGlm(sourcePosition);
|
||||||
pos /= sourceSize;
|
offscreenPosition /= sourceSize;
|
||||||
pos *= vec2(toGlm(_quickWindow->size()));
|
offscreenPosition *= vec2(toGlm(_quickWindow->size()));
|
||||||
return QPointF(pos.x, pos.y);
|
return QPointF(offscreenPosition.x, offscreenPosition.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
|
@ -257,39 +257,42 @@ QPointF OffscreenUi::mapWindowToUi(const QPointF& p, QObject* dest) {
|
||||||
// Event handling customization
|
// Event handling customization
|
||||||
//
|
//
|
||||||
|
|
||||||
bool OffscreenUi::eventFilter(QObject* dest, QEvent* e) {
|
bool OffscreenUi::eventFilter(QObject* originalDestination, QEvent* event) {
|
||||||
// Only intercept events while we're in an active state
|
// Only intercept events while we're in an active state
|
||||||
if (_paused) {
|
if (_paused) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't intercept our own events, or we enter an infinite recursion
|
// Don't intercept our own events, or we enter an infinite recursion
|
||||||
if (dest == _quickWindow) {
|
if (originalDestination == _quickWindow) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (e->type()) {
|
switch (event->type()) {
|
||||||
case QEvent::Resize: {
|
case QEvent::Resize: {
|
||||||
QResizeEvent* re = (QResizeEvent*)e;
|
QResizeEvent* resizeEvent = (QResizeEvent*)event;
|
||||||
QGLWidget* widget = dynamic_cast<QGLWidget*>(dest);
|
QGLWidget* widget = dynamic_cast<QGLWidget*>(originalDestination);
|
||||||
if (widget) {
|
if (widget) {
|
||||||
this->resize(re->size());
|
this->resize(resizeEvent->size());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
case QEvent::KeyPress:
|
case QEvent::KeyPress:
|
||||||
case QEvent::KeyRelease: {
|
case QEvent::KeyRelease: {
|
||||||
e->ignore();
|
event->ignore();
|
||||||
if (QCoreApplication::sendEvent(_quickWindow, e)) {
|
if (QCoreApplication::sendEvent(_quickWindow, event)) {
|
||||||
return e->isAccepted();
|
return event->isAccepted();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case QEvent::Wheel: {
|
case QEvent::Wheel: {
|
||||||
QWheelEvent* we = (QWheelEvent*)e;
|
QWheelEvent* wheelEvent = (QWheelEvent*)event;
|
||||||
QWheelEvent mappedEvent(mapWindowToUi(we->pos(), dest), we->delta(), we->buttons(), we->modifiers(), we->orientation());
|
QWheelEvent mappedEvent(
|
||||||
|
mapWindowToUi(wheelEvent->pos(), originalDestination),
|
||||||
|
wheelEvent->delta(), wheelEvent->buttons(),
|
||||||
|
wheelEvent->modifiers(), wheelEvent->orientation());
|
||||||
QCoreApplication::sendEvent(_quickWindow, &mappedEvent);
|
QCoreApplication::sendEvent(_quickWindow, &mappedEvent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -299,12 +302,15 @@ bool OffscreenUi::eventFilter(QObject* dest, QEvent* e) {
|
||||||
case QEvent::MouseButtonPress:
|
case QEvent::MouseButtonPress:
|
||||||
case QEvent::MouseButtonRelease:
|
case QEvent::MouseButtonRelease:
|
||||||
case QEvent::MouseMove: {
|
case QEvent::MouseMove: {
|
||||||
QMouseEvent* me = (QMouseEvent *)e;
|
QMouseEvent* mouseEvent = (QMouseEvent *)event;
|
||||||
QPointF originalPos = me->localPos();
|
QPointF originalPos = mouseEvent->localPos();
|
||||||
QPointF transformedPos = _mouseTranslator(originalPos);
|
QPointF transformedPos = _mouseTranslator(originalPos);
|
||||||
QMouseEvent mappedEvent(e->type(), mapWindowToUi(transformedPos, dest), me->screenPos(), me->button(), me->buttons(), me->modifiers());
|
QMouseEvent mappedEvent(mouseEvent->type(),
|
||||||
|
mapWindowToUi(transformedPos, originalDestination),
|
||||||
|
mouseEvent->screenPos(), mouseEvent->button(),
|
||||||
|
mouseEvent->buttons(), mouseEvent->modifiers());
|
||||||
QCoreApplication::sendEvent(_quickWindow, &mappedEvent);
|
QCoreApplication::sendEvent(_quickWindow, &mappedEvent);
|
||||||
return QObject::event(e);
|
return QObject::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -352,7 +358,7 @@ void OffscreenUi::show(const QUrl& url, const QString& name) {
|
||||||
void OffscreenUi::toggle(const QUrl& url, const QString& name) {
|
void OffscreenUi::toggle(const QUrl& url, const QString& name) {
|
||||||
QQuickItem* item = _rootItem->findChild<QQuickItem*>(name);
|
QQuickItem* item = _rootItem->findChild<QQuickItem*>(name);
|
||||||
// First load?
|
// First load?
|
||||||
if (nullptr == item) {
|
if (!item) {
|
||||||
load(url);
|
load(url);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,16 +67,16 @@ public:
|
||||||
void toggle(const QUrl& url, const QString& name);
|
void toggle(const QUrl& url, const QString& name);
|
||||||
void setBaseUrl(const QUrl& baseUrl);
|
void setBaseUrl(const QUrl& baseUrl);
|
||||||
void addImportPath(const QString& path);
|
void addImportPath(const QString& path);
|
||||||
QQmlContext * qmlContext();
|
QQmlContext* qmlContext();
|
||||||
|
|
||||||
void pause();
|
void pause();
|
||||||
void resume();
|
void resume();
|
||||||
bool isPaused() const;
|
bool isPaused() const;
|
||||||
void setProxyWindow(QWindow* window);
|
void setProxyWindow(QWindow* window);
|
||||||
QPointF mapWindowToUi(const QPointF& p, QObject* dest);
|
QPointF mapWindowToUi(const QPointF& sourcePosition, QObject* sourceObject);
|
||||||
virtual bool eventFilter(QObject* dest, QEvent* e);
|
virtual bool eventFilter(QObject* originalDestination, QEvent* event);
|
||||||
void setMouseTranslator(MouseTranslator mt) {
|
void setMouseTranslator(MouseTranslator mouseTranslator) {
|
||||||
_mouseTranslator = mt;
|
_mouseTranslator = mouseTranslator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ private:
|
||||||
FboCache _fboCache;
|
FboCache _fboCache;
|
||||||
bool _polish{ true };
|
bool _polish{ true };
|
||||||
bool _paused{ true };
|
bool _paused{ true };
|
||||||
MouseTranslator _mouseTranslator{ [](const QPointF & p) { return p; } };
|
MouseTranslator _mouseTranslator{ [](const QPointF& p) { return p; } };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -37,7 +37,7 @@ void withProjectionIdentity(F f) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
void withProjectionMatrix(GLfloat * matrix, F f) {
|
void withProjectionMatrix(GLfloat* matrix, F f) {
|
||||||
withProjectionPush([&] {
|
withProjectionPush([&] {
|
||||||
glLoadMatrixf(matrix);
|
glLoadMatrixf(matrix);
|
||||||
f();
|
f();
|
||||||
|
@ -58,7 +58,7 @@ void withModelviewIdentity(F f) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
void withModelviewMatrix(GLfloat * matrix, F f) {
|
void withModelviewMatrix(GLfloat* matrix, F f) {
|
||||||
withModelviewPush([&] {
|
withModelviewPush([&] {
|
||||||
glLoadMatrixf(matrix);
|
glLoadMatrixf(matrix);
|
||||||
f();
|
f();
|
||||||
|
|
Loading…
Reference in a new issue