File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77#include < Editor/Widget/WebWidget.h>
88
99namespace Editor {
10+ class ProjectHub ;
11+
12+ class ProjectHubBridge final : public QObject {
13+ Q_OBJECT
14+
15+ public:
16+ explicit ProjectHubBridge (ProjectHub* parent = nullptr );
17+
18+ public Q_SLOTS:
19+ void CreateProject () const ;
20+ };
21+
1022 class ProjectHub final : public WebWidget {
1123 Q_OBJECT
1224
1325 public:
1426 explicit ProjectHub (QWidget* inParent = nullptr );
27+
28+ private:
29+ ProjectHubBridge* bridge;
1530 };
1631}
Original file line number Diff line number Diff line change 44
55#pragma once
66
7+ #include < QWebChannel>
78#include < QWebEngineView>
89
910namespace Editor {
@@ -15,5 +16,11 @@ namespace Editor {
1516 ~WebWidget () override ;
1617
1718 void Load (const std::string& inUrl);
19+
20+ protected:
21+ QWebChannel* GetWebChannel () const ;
22+
23+ private:
24+ QWebChannel* webChannel;
1825 };
1926}
Original file line number Diff line number Diff line change 22// Created by johnk on 2025/8/3.
33//
44
5+ #include < QWebChannel>
6+
57#include < Editor/Widget/ProjectHub.h>
68#include < Editor/Widget/moc_ProjectHub.cpp>
9+ #include < Core/Log.h>
710
811namespace Editor {
12+ ProjectHubBridge::ProjectHubBridge (ProjectHub* parent)
13+ : QObject(parent)
14+ {
15+ }
16+
17+ void ProjectHubBridge::CreateProject () const
18+ {
19+ // TODO
20+ LogInfo (ProjectHub, " ProjectHubBridge::CreateProject" );
21+ }
22+
923 ProjectHub::ProjectHub (QWidget* inParent)
1024 : WebWidget(inParent)
1125 {
1226 setFixedSize (800 , 600 );
1327 Load (" /project-hub" );
28+
29+ bridge = new ProjectHubBridge (this );
30+ GetWebChannel ()->registerObject (" bridge" , bridge);
1431 }
1532} // namespace Editor
Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ namespace Editor {
1818 WebWidget::WebWidget (QWidget* inParent)
1919 : QWebEngineView(inParent)
2020 {
21+ webChannel = new QWebChannel (this );
22+ page ()->setWebChannel (webChannel);
2123 }
2224
2325 WebWidget::~WebWidget () = default ;
@@ -31,4 +33,9 @@ namespace Editor {
3133 const std::string fullUrl = baseUrl + inUrl;
3234 load (QUrl (fullUrl.c_str ()));
3335 }
36+
37+ QWebChannel* WebWidget::GetWebChannel () const
38+ {
39+ return webChannel;
40+ }
3441} // namespace Editor
Original file line number Diff line number Diff line change 1+ import { useEffect } from "react" ;
2+ import { QWebChannel } from '@/qwebchannel'
13import { Tabs , Tab } from '@heroui/tabs' ;
24import { User } from '@heroui/user' ;
35import { Form } from '@heroui/form' ;
46import { Button } from '@heroui/button' ;
57import { Input } from '@heroui/input' ;
68
79export default function ProjectHubPage ( ) {
10+ useEffect ( ( ) => {
11+ new QWebChannel ( window . qt . webChannelTransport , ( channel : QWebChannel ) : void => {
12+ window . bridge = channel . objects . bridge ;
13+ } )
14+ } , [ ] ) ;
15+
16+ function onCreateProject ( ) : void
17+ {
18+ window . bridge . CreateProject ( ) ;
19+ }
20+
821 return (
922 < div className = 'h-screen p-6' >
1023 < div className = 'mb-4' >
@@ -23,7 +36,7 @@ export default function ProjectHubPage() {
2336 < Input fullWidth isRequired label = 'Project Name' labelPlacement = 'outside' placeholder = 'HelloExplosion' />
2437 < Input fullWidth isRequired label = 'Project Description' labelPlacement = 'outside' placeholder = 'A simple explosion game project.' />
2538 < Input fullWidth isRequired label = 'Project Path' labelPlacement = 'outside' placeholder = '/path/to/your/project' />
26- < Button color = 'primary' > Create</ Button >
39+ < Button color = 'primary' onPress = { onCreateProject } > Create</ Button >
2740 </ Form >
2841 </ Tab >
2942 < Tab title = 'Recently Projects' >
Original file line number Diff line number Diff line change 1+ export { QWebChannel } from './qwebchannel.js' ;
2+
3+ declare global {
4+ interface Window {
5+ qt : any ;
6+ bridge : any ;
7+ }
8+ }
Original file line number Diff line number Diff line change @@ -448,8 +448,8 @@ QObject.prototype.toJSON = function() {
448448} ;
449449
450450//required for use with nodejs
451- if ( typeof module === 'object' ) {
452- module . exports = {
453- QWebChannel : QWebChannel
454- } ;
451+ //++[kindem] use ES6 export
452+ export {
453+ QWebChannel
455454}
455+ //--[kindem]
You can’t perform that action at this time.
0 commit comments