mirror of https://github.com/CGAL/cgal
Hello QJSEngine [skip ci]
This commit is contained in:
parent
0574c6ba4c
commit
7e160aa2bb
|
|
@ -24,7 +24,7 @@ include_directories(BEFORE ./ ./include)
|
|||
find_package(CGAL REQUIRED OPTIONAL_COMPONENTS Qt6)
|
||||
|
||||
# Find Qt6 itself
|
||||
find_package(Qt6 QUIET COMPONENTS OpenGLWidgets Gui Svg)
|
||||
find_package(Qt6 QUIET COMPONENTS OpenGLWidgets Gui Svg Qml)
|
||||
|
||||
if(CGAL_Qt6_FOUND AND Qt6_FOUND)
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ if(CGAL_Qt6_FOUND AND Qt6_FOUND)
|
|||
#${CGAL_Qt6_MOC_FILES}
|
||||
)
|
||||
# Link with Qt libraries
|
||||
target_link_libraries(AABB_demo PRIVATE Qt6::OpenGLWidgets Qt6::Gui
|
||||
target_link_libraries(AABB_demo PRIVATE Qt6::OpenGLWidgets Qt6::Gui Qt6::Qml
|
||||
CGAL::CGAL CGAL::CGAL_Qt6)
|
||||
|
||||
add_to_cached_list(CGAL_EXECUTABLE_TARGETS AABB_demo)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
#include "ui_MainWindow.h"
|
||||
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget* parent)
|
||||
: CGAL::Qt::DemosMainWindow(parent)
|
||||
{
|
||||
|
|
@ -38,12 +40,25 @@ MainWindow::MainWindow(QWidget* parent)
|
|||
connect(this, SIGNAL(openRecentFile(QString)),
|
||||
this, SLOT(open(QString)));
|
||||
|
||||
QJSValue mainWindow = myEngine.newQObject(this);
|
||||
myEngine.globalObject().setProperty("main_window", mainWindow);
|
||||
readSettings();
|
||||
std::ifstream script("init.js");
|
||||
if(script.good()){
|
||||
std::string line;
|
||||
while(getline(script, line)){
|
||||
myEngine.evaluate(line.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
m_pViewer->makeCurrent();
|
||||
// AF I thought this helps to avoid the exception when the program
|
||||
// terminates, but it does not
|
||||
myEngine.globalObject().setProperty("main_window", QJSValue());
|
||||
myEngine.collectGarbage();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
|
@ -65,6 +80,13 @@ void MainWindow::dropEvent(QDropEvent *event)
|
|||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::hello() const
|
||||
{
|
||||
std::cout << "Hhello world" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::updateViewerBBox()
|
||||
{
|
||||
m_pScene->update_bbox();
|
||||
|
|
@ -418,7 +440,3 @@ void MainWindow::on_actionCopy_snapshot_triggered()
|
|||
qb->setImage(snapshot);
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define MAINWINDOW_H
|
||||
|
||||
#include <QOpenGLWidget>
|
||||
#include <QJSEngine>
|
||||
#include <CGAL/Qt/DemosMainWindow.h>
|
||||
|
||||
class QDragEnterEvent;
|
||||
|
|
@ -12,6 +13,36 @@ namespace Ui {
|
|||
class MainWindow;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
struct Foo : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
QJSEngine myEngine;
|
||||
|
||||
Foo()
|
||||
{
|
||||
QJSValue baz = myEngine.newQObject(this);
|
||||
myEngine.globalObject().setProperty("baz", baz);
|
||||
}
|
||||
|
||||
void bar()
|
||||
{
|
||||
std::cout << "bar()" << std::endl;
|
||||
myEngine.evaluate("baz.hello()");
|
||||
}
|
||||
|
||||
public slots:
|
||||
void hello() const // if not a slot it must be
|
||||
{
|
||||
std::cout << "called hello()" << std::endl;
|
||||
}
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
class MainWindow :
|
||||
public CGAL::Qt::DemosMainWindow
|
||||
|
|
@ -22,6 +53,8 @@ public:
|
|||
~MainWindow();
|
||||
|
||||
public slots:
|
||||
|
||||
void hello() const;
|
||||
void updateViewerBBox();
|
||||
void open(QString filename);
|
||||
void setAddKeyFrameKeyboardModifiers(Qt::KeyboardModifiers);
|
||||
|
|
@ -79,6 +112,7 @@ public:
|
|||
void on_actionView_cutting_plane_triggered();
|
||||
|
||||
private:
|
||||
QJSEngine myEngine;
|
||||
Scene* m_pScene;
|
||||
Viewer* m_pViewer;
|
||||
Ui::MainWindow* ui;
|
||||
|
|
|
|||
Loading…
Reference in New Issue