Skip to content

Commit

Permalink
Add method for reloading viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
RadhiFadlillah committed Oct 12, 2018
1 parent c003b4b commit 35f761c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Exclude generated file
cgo.go
moc*.h

# Exclude sample dir
sample/
66 changes: 42 additions & 24 deletions viewer/viewer.cpp
Original file line number Diff line number Diff line change
@@ -1,122 +1,140 @@
#include "viewer.h"
#include <QQuickView>
#include <QString>
#include <QUrl>
#include <QWindow>
#include <QIcon>
#include <QQmlEngine>
#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<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->setSource(QUrl(QString(url)));
}

void Viewer_SetResizeMode(void* ptr, int resizeMode) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->setResizeMode(QQuickView::ResizeMode(resizeMode));
}

void Viewer_SetFlags(void* ptr, int flags) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->setFlags(Qt::WindowFlags(flags));
}

void Viewer_SetHeight(void* ptr, int height) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->setHeight(height);
}

void Viewer_SetWidth(void* ptr, int width) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->setWidth(width);
}

void Viewer_SetMaximumHeight(void* ptr, int height) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->setMaximumHeight(height);
}

void Viewer_SetMaximumWidth(void* ptr, int width) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->setMaximumWidth(width);
}

void Viewer_SetMinimumHeight(void* ptr, int height) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->setMinimumHeight(height);
}

void Viewer_SetMinimumWidth(void* ptr, int width) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->setMinimumWidth(width);
}

void Viewer_SetOpacity(void* ptr, double opacity) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->setOpacity(opacity);
}

void Viewer_SetTitle(void* ptr, char* title) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->setTitle(QString(title));
}

void Viewer_SetVisible(void* ptr, bool visible) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->setVisible(visible);
}

void Viewer_SetPosition(void* ptr, int x, int y) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->setPosition(x, y);
}

void Viewer_SetIcon(void* ptr, char* fileName) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
QIcon icon = QIcon(QString(fileName));
view->setIcon(icon);
}

void Viewer_Show(void* ptr) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->show();
}

void Viewer_ShowMaximized(void* ptr) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->showMaximized();
}

void Viewer_ShowMinimized(void* ptr) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->showMinimized();
}

void Viewer_ShowFullScreen(void* ptr) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->showFullScreen();
}

void Viewer_ShowNormal(void* ptr) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->showNormal();
}

void Viewer_SetWindowStates(void* ptr, int state) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->setWindowStates(Qt::WindowStates(state));
}

void Viewer_ClearComponentCache(void* ptr) {
QQuickView *view = static_cast<QQuickView*>(ptr);
QamelView *view = static_cast<QamelView*>(ptr);
view->engine()->clearComponentCache();
}

void Viewer_Reload(void* ptr) {
QMetaObject::invokeMethod(static_cast<QamelView*>(ptr), "reload");
}
9 changes: 9 additions & 0 deletions viewer/viewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 5 additions & 0 deletions viewer/viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#define QAMEL_VIEWER_H

#ifdef __cplusplus

// Class
class QamelView;

extern "C" {
#endif

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 35f761c

Please sign in to comment.