commit 1ce31c8124a706204807b68027e88e8613fee7bf
parent 0e352f612564092b385d489eb2a415e416f7c20e
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date: Thu, 5 Aug 2021 06:50:40 +0200
Worked out the embedding code for clap-gui
Diffstat:
3 files changed, 43 insertions(+), 11 deletions(-)
diff --git a/examples/gui/CMakeLists.txt b/examples/gui/CMakeLists.txt
@@ -1,9 +1,7 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
-find_package(Qt6Core REQUIRED)
-find_package(Qt6Widgets REQUIRED)
-find_package(Qt6Qml REQUIRED)
+find_package(Qt6 COMPONENTS Quick REQUIRED)
add_executable(clap-gui
main.cc
@@ -11,7 +9,7 @@ add_executable(clap-gui
application.hh
application.cc
)
-target_link_libraries(clap-gui clap-io Qt6::Qml Qt6::Widgets Qt6::Core)
+target_link_libraries(clap-gui clap-io Qt6::Quick)
set_target_properties(clap-gui PROPERTIES CXX_STANDARD 17)
install(TARGETS clap-gui DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
\ No newline at end of file
diff --git a/examples/gui/application.cc b/examples/gui/application.cc
@@ -1,11 +1,12 @@
#include <QCommandLineParser>
-#include <QQmlApplicationEngine>
+#include <QQuickView>
+#include <QWindow>
#include "../io/messages.hh"
#include "application.hh"
Application::Application(int argc, char **argv)
- : QGuiApplication(argc, argv), qmlEngine_(new QQmlApplicationEngine(this)) {
+ : QGuiApplication(argc, argv), quickView_(new QQuickView()) {
QCommandLineParser parser;
@@ -18,9 +19,7 @@ Application::Application(int argc, char **argv)
parser.process(*this);
- qmlEngine_->load(parser.value(qmlOpt));
- if (qmlEngine_->rootObjects().empty())
- throw std::invalid_argument("bad qml file");
+ quickView_->setSource(parser.value(qmlOpt));
auto socket = parser.value(socketOpt).toULongLong();
@@ -62,6 +61,38 @@ void Application::onMessage(const clap::RemoteChannel::Message &msg) {
case clap::messages::kDefineParameterRequest: {
clap::messages::DefineParameterRequest rq;
msg.get(rq);
+ // TODO
+ break;
+ }
+
+ case clap::messages::kAttachX11Request: {
+ clap::messages::AttachX11Request rq;
+ msg.get(rq);
+ hostWindow_.reset(QWindow::fromWinId(rq.window));
+ quickView_->setParent(hostWindow_.get());
+
+ clap::messages::AttachResponse rp;
+ remoteChannel_->sendMessageAsync(rp);
+ break;
+ }
+
+ case clap::messages::kShowRequest: {
+ clap::messages::ShowRequest rq;
+ msg.get(rq);
+
+ quickView_->show();
+ clap::messages::ShowResponse rp;
+ remoteChannel_->sendMessageAsync(rp);
+ break;
+ }
+
+ case clap::messages::kHideRequest: {
+ clap::messages::HideRequest rq;
+ msg.get(rq);
+
+ quickView_->hide();
+ clap::messages::HideResponse rp;
+ remoteChannel_->sendMessageAsync(rp);
break;
}
}
diff --git a/examples/gui/application.hh b/examples/gui/application.hh
@@ -2,10 +2,11 @@
#include <QGuiApplication>
#include <QSocketNotifier>
+#include <QWindow>
#include "../io/remote-channel.hh"
-class QQmlApplicationEngine;
+class QQuickView;
class Application : public QGuiApplication, public clap::RemoteChannel::EventControl {
Q_OBJECT;
@@ -17,10 +18,12 @@ public:
void onMessage(const clap::RemoteChannel::Message& msg);
private:
- QQmlApplicationEngine *qmlEngine_ = nullptr;
+ QQuickView *quickView_ = nullptr;
QSocketNotifier *socketReadNotifier_ = nullptr;
QSocketNotifier *socketWriteNotifier_ = nullptr;
QSocketNotifier *socketErrorNotifier_ = nullptr;
+ std::unique_ptr<QWindow> hostWindow_ = nullptr;
+
std::unique_ptr<clap::RemoteChannel> remoteChannel_;
};
\ No newline at end of file