diff --git a/.gitignore b/.gitignore index 1d659d5..645e075 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,6 @@ examples/app examples/color examples/demo examples/images +examples/qt-embed examples/rectangles examples/shapes diff --git a/examples/Makefile b/examples/Makefile index 2ef70c8..58d5fd6 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -59,10 +59,13 @@ shapes: shapes.cpp ../dpf/dgl/* # -------------------------------------------------------------- -cairo: cairo.cpp ../dgl/* +cairo: cairo.cpp ../dpf/dgl/* $(CXX) $< $(BUILD_CXX_FLAGS) $(shell pkg-config --cflags --libs cairo) $(LINK_FLAGS) -o $@ -text: text.cpp ../dgl/* +qt-embed: qt-embed.cpp ../dpf/dgl/* + $(CXX) $< $(BUILD_CXX_FLAGS) $(shell pkg-config --cflags --libs QtCore QtGui) $(LINK_FLAGS) -o $@ + +text: text.cpp ../dpf/dgl/* $(CXX) $< $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ # -------------------------------------------------------------- diff --git a/examples/app.cpp b/examples/app.cpp index f6e6bd6..cec66d1 100644 --- a/examples/app.cpp +++ b/examples/app.cpp @@ -23,7 +23,8 @@ // ------------------------------------------------------ // use namespace -using namespace DGL; +using DGL::App; +using DGL::Window; // ------------------------------------------------------ // main entry point diff --git a/examples/qt-embed.cpp b/examples/qt-embed.cpp new file mode 100644 index 0000000..21965b2 --- /dev/null +++ b/examples/qt-embed.cpp @@ -0,0 +1,133 @@ +/* + * DISTRHO Plugin Framework (DPF) + * Copyright (C) 2012-2014 Filipe Coelho + * + * Permission to use, copy, modify, and/or distribute this software for any purpose with + * or without fee is hereby granted, provided that the above copyright notice and this + * permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD + * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +// ------------------------------------------------------ +// DGL Stuff + +#include "App.hpp" +#include "Window.hpp" +#include "widgets/ExampleRectanglesWidget.hpp" + +// ------------------------------------------------------ +// Qt Stuff + +#include +#include +#include + +#if DISTRHO_OS_LINUX +# include +typedef QX11EmbedContainer QWidgetContainer; +#elif DISTRHO_OS_MAC +# include +typedef QMacCocoaViewContainer QWidgetContainer; +#else +# define DISTRHO_NEEDS_WINDOW_SIZE +# include +typedef QWidget QWidgetContainer; +#endif + +// ------------------------------------------------------ +// use namespace + +using DGL::App; +using DGL::Window; + +// ------------------------------------------------------ +// Qt widget + +template +class DGLtoQtWidget : public QWidgetContainer +{ +public: + DGLtoQtWidget(QWidget* const qParent = nullptr) +#if DISTRHO_OS_MAC + : QWidgetContainer(nullptr, qParent), + glApp(), + glWindow(glApp, 0), +#else + : QWidgetContainer(qParent), + glApp(), + glWindow(glApp, winId()), +#endif + glWidget(glWindow), + qTimerId(startTimer(30)) + { +#if DISTRHO_OS_MAC + //NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + //[pool release]; + setCocoaView((void*)glWindow.getWindowId()); +#endif + } + + ~DGLtoQtWidget() override + { + killTimer(qTimerId); + glWindow.close(); + } + +protected: + void resizeEvent(QResizeEvent* const event) override + { + const QSize& size(event->size()); + + glWidget.setSize(size.width(), size.height()); + +#ifdef DISTRHO_NEEDS_WINDOW_SIZE + // only needed if not handled by qt + glWindow.setSize(size.width(), size.height()); +#endif + + QWidgetContainer::resizeEvent(event); + } + + void timerEvent(QTimerEvent* const event) override + { + if (event->timerId() == qTimerId) + glApp.idle(); + + QWidgetContainer::timerEvent(event); + } + +private: + App glApp; + Window glWindow; + DGLWidget glWidget; + + const int qTimerId; +}; + +#ifdef DISTRHO_NEEDS_WINDOW_SIZE +# undef DISTRHO_NEEDS_WINDOW_SIZE +#endif + +// ------------------------------------------------------ +// main entry point + +int main(int argc, char* argv[]) +{ + QApplication app(argc, argv); + app.setWindowIcon(QIcon::fromTheme("firefox")); + + DGLtoQtWidget widget; + widget.setWindowIcon(QIcon::fromTheme("firefox")); + widget.resize(300, 300); + widget.show(); + + return app.exec(); +} + +// ------------------------------------------------------