diff --git a/.gitignore b/.gitignore index 49f33b4..24c62ec 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ # Exclude generated file cgo.go +moc*.h # Exclude sample dir sample/ \ No newline at end of file diff --git a/viewer/viewer.cpp b/viewer/viewer.cpp index 384f53a..3edf7f2 100644 --- a/viewer/viewer.cpp +++ b/viewer/viewer.cpp @@ -1,122 +1,140 @@ -#include "viewer.h" #include #include #include #include #include #include +#include "viewer.h" + +class QamelView : public QQuickView { + Q_OBJECT + +public: + QamelView(QWindow *parent = 0) : QQuickView(parent) {} + QamelView(const QUrl &source, QWindow *parent = nullptr) : QQuickView(source, parent) {} + +public slots: + void reload() { + engine()->clearComponentCache(); + setSource(source()); + } +}; void* Viewer_NewViewer() { - return new QQuickView(); + return new QamelView(); } void* Viewer_NewViewerWithSource(char* source) { QUrl url = QUrl(QString(source)); - return new QQuickView(url); + return new QamelView(url); } void Viewer_SetSource(void* ptr, char* url) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->setSource(QUrl(QString(url))); } void Viewer_SetResizeMode(void* ptr, int resizeMode) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->setResizeMode(QQuickView::ResizeMode(resizeMode)); } void Viewer_SetFlags(void* ptr, int flags) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->setFlags(Qt::WindowFlags(flags)); } void Viewer_SetHeight(void* ptr, int height) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->setHeight(height); } void Viewer_SetWidth(void* ptr, int width) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->setWidth(width); } void Viewer_SetMaximumHeight(void* ptr, int height) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->setMaximumHeight(height); } void Viewer_SetMaximumWidth(void* ptr, int width) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->setMaximumWidth(width); } void Viewer_SetMinimumHeight(void* ptr, int height) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->setMinimumHeight(height); } void Viewer_SetMinimumWidth(void* ptr, int width) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->setMinimumWidth(width); } void Viewer_SetOpacity(void* ptr, double opacity) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->setOpacity(opacity); } void Viewer_SetTitle(void* ptr, char* title) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->setTitle(QString(title)); } void Viewer_SetVisible(void* ptr, bool visible) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->setVisible(visible); } void Viewer_SetPosition(void* ptr, int x, int y) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->setPosition(x, y); } void Viewer_SetIcon(void* ptr, char* fileName) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); QIcon icon = QIcon(QString(fileName)); view->setIcon(icon); } void Viewer_Show(void* ptr) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->show(); } void Viewer_ShowMaximized(void* ptr) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->showMaximized(); } void Viewer_ShowMinimized(void* ptr) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->showMinimized(); } void Viewer_ShowFullScreen(void* ptr) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->showFullScreen(); } void Viewer_ShowNormal(void* ptr) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->showNormal(); } void Viewer_SetWindowStates(void* ptr, int state) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->setWindowStates(Qt::WindowStates(state)); } void Viewer_ClearComponentCache(void* ptr) { - QQuickView *view = static_cast(ptr); + QamelView *view = static_cast(ptr); view->engine()->clearComponentCache(); } + +void Viewer_Reload(void* ptr) { + QMetaObject::invokeMethod(static_cast(ptr), "reload"); +} diff --git a/viewer/viewer.go b/viewer/viewer.go index 1aa1a7e..dc4e77b 100644 --- a/viewer/viewer.go +++ b/viewer/viewer.go @@ -255,3 +255,12 @@ func (view Viewer) ClearComponentCache() { C.Viewer_ClearComponentCache(view.ptr) } + +// Reload reloads the active QML view. +func (view Viewer) Reload() { + if view.ptr == nil { + return + } + + C.Viewer_Reload(view.ptr) +} diff --git a/viewer/viewer.h b/viewer/viewer.h index f4d7729..05437ec 100644 --- a/viewer/viewer.h +++ b/viewer/viewer.h @@ -4,6 +4,10 @@ #define QAMEL_VIEWER_H #ifdef __cplusplus + +// Class +class QamelView; + extern "C" { #endif @@ -33,6 +37,7 @@ void Viewer_ShowFullScreen(void* ptr); void Viewer_ShowNormal(void* ptr); void Viewer_SetWindowStates(void* ptr, int state); void Viewer_ClearComponentCache(void* ptr); +void Viewer_Reload(void* ptr); #ifdef __cplusplus }