Browse Source

Add qt-embed test app

pull/1/head
falkTX 11 years ago
parent
commit
9bf5fd0323
4 changed files with 141 additions and 3 deletions
  1. +1
    -0
      .gitignore
  2. +5
    -2
      examples/Makefile
  3. +2
    -1
      examples/app.cpp
  4. +133
    -0
      examples/qt-embed.cpp

+ 1
- 0
.gitignore View File

@@ -13,5 +13,6 @@ examples/app
examples/color
examples/demo
examples/images
examples/qt-embed
examples/rectangles
examples/shapes

+ 5
- 2
examples/Makefile View File

@@ -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 $@

# --------------------------------------------------------------


+ 2
- 1
examples/app.cpp View File

@@ -23,7 +23,8 @@
// ------------------------------------------------------
// use namespace

using namespace DGL;
using DGL::App;
using DGL::Window;

// ------------------------------------------------------
// main entry point


+ 133
- 0
examples/qt-embed.cpp View File

@@ -0,0 +1,133 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
*
* 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 <QtGui/QApplication>
#include <QtGui/QIcon>
#include <QtGui/QResizeEvent>

#if DISTRHO_OS_LINUX
# include <QtGui/QX11EmbedContainer>
typedef QX11EmbedContainer QWidgetContainer;
#elif DISTRHO_OS_MAC
# include <QtGui/QMacCocoaViewContainer>
typedef QMacCocoaViewContainer QWidgetContainer;
#else
# define DISTRHO_NEEDS_WINDOW_SIZE
# include <QtGui/QWidget>
typedef QWidget QWidgetContainer;
#endif

// ------------------------------------------------------
// use namespace

using DGL::App;
using DGL::Window;

// ------------------------------------------------------
// Qt widget

template<class DGLWidget>
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<ExampleRectanglesWidget> widget;
widget.setWindowIcon(QIcon::fromTheme("firefox"));
widget.resize(300, 300);
widget.show();

return app.exec();
}

// ------------------------------------------------------

Loading…
Cancel
Save