diff options
author | David Robillard <d@drobilla.net> | 2013-12-30 17:57:07 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2013-12-30 17:57:07 +0000 |
commit | 45d31b52da05ce362794e84e259910d9c9c0512b (patch) | |
tree | 88ae0ee99b5f7060501c0c58d7deabd2f493d442 /src | |
parent | cfdfb4606a7dac2e25f5ca6b12375cbdcfbb46b2 (diff) | |
download | jalv-45d31b52da05ce362794e84e259910d9c9c0512b.tar.gz jalv-45d31b52da05ce362794e84e259910d9c9c0512b.tar.bz2 jalv-45d31b52da05ce362794e84e259910d9c9c0512b.zip |
Preset menu support for Qt (patch from Timo Westkämper) (#930).
git-svn-id: http://svn.drobilla.net/lad/trunk/jalv@5227 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r-- | src/jalv_qt4.cpp | 57 | ||||
-rw-r--r-- | src/jalv_qt4_meta.hpp | 92 |
2 files changed, 142 insertions, 7 deletions
diff --git a/src/jalv_qt4.cpp b/src/jalv_qt4.cpp index b082233..cbccdd2 100644 --- a/src/jalv_qt4.cpp +++ b/src/jalv_qt4.cpp @@ -1,5 +1,5 @@ /* - Copyright 2007-2011 David Robillard <http://drobilla.net> + Copyright 2007-2013 David Robillard <http://drobilla.net> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -24,6 +24,31 @@ static QApplication* app = NULL; +class PresetAction : public QAction { + + Q_OBJECT + +public: + PresetAction(QObject* parent, Jalv* jalv, LilvNode* preset) + : QAction(parent) + , _jalv(jalv) + , _preset(preset) + { + connect(this, SIGNAL(triggered()), + this, SLOT(presetChosen())); + } + + Q_SLOT void presetChosen() { + jalv_apply_preset(_jalv, _preset); + } + +private: + Jalv* _jalv; + LilvNode* _preset; +}; + +#include "jalv_qt4_meta.hpp" + extern "C" { int @@ -62,22 +87,38 @@ jalv_ui_port_event(Jalv* jalv, class Timer : public QTimer { public: - explicit Timer(Jalv* j) : jalv(j) {} + explicit Timer(Jalv* jalv) : _jalv(jalv) {} void timerEvent(QTimerEvent* e) { - jalv_emit_ui_events(jalv); + jalv_emit_ui_events(_jalv); } private: - Jalv* jalv; + Jalv* _jalv; }; +static int +add_preset_to_menu(Jalv* jalv, + const LilvNode* node, + const LilvNode* title, + void* data) +{ + QMenu* menu = (QMenu*)data; + const char* label = lilv_node_as_string(title); + + QAction* action = new PresetAction(menu, jalv, lilv_node_duplicate(node)); + action->setText(label); + menu->addAction(action); + return 0; +} + int jalv_open_ui(Jalv* jalv) { - QMainWindow* win = new QMainWindow(); - QMenu* file_menu = win->menuBar()->addMenu("&File"); - QAction* quit_action = new QAction("&Quit", win); + QMainWindow* win = new QMainWindow(); + QMenu* file_menu = win->menuBar()->addMenu("&File"); + QMenu* presets_menu = win->menuBar()->addMenu("&Presets"); + QAction* quit_action = new QAction("&Quit", win); QObject::connect(quit_action, SIGNAL(triggered()), win, SLOT(close())); quit_action->setShortcuts(QKeySequence::Quit); @@ -85,6 +126,8 @@ jalv_open_ui(Jalv* jalv) file_menu->addAction(quit_action); jalv->has_ui = TRUE; + jalv_load_presets(jalv, add_preset_to_menu, presets_menu); + if (jalv->ui) { jalv_ui_instantiate(jalv, jalv_native_ui_type(jalv), win); } diff --git a/src/jalv_qt4_meta.hpp b/src/jalv_qt4_meta.hpp new file mode 100644 index 0000000..f61fe16 --- /dev/null +++ b/src/jalv_qt4_meta.hpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** Meta object code from reading C++ file 'jalv_qt4.cpp' +** +** Created by: The Qt Meta Object Compiler version 63 (Qt 4.8.6) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#if !defined(Q_MOC_OUTPUT_REVISION) +#error "The header file 'jalv_qt4.cpp' doesn't include <QObject>." +#elif Q_MOC_OUTPUT_REVISION != 63 +#error "This file was generated using the moc from 4.8.6. It" +#error "cannot be used with the include files from this version of Qt." +#error "(The moc has changed too much.)" +#endif + +QT_BEGIN_MOC_NAMESPACE +static const uint qt_meta_data_PresetAction[] = { + + // content: + 6, // revision + 0, // classname + 0, 0, // classinfo + 1, 14, // methods + 0, 0, // properties + 0, 0, // enums/sets + 0, 0, // constructors + 0, // flags + 0, // signalCount + + // slots: signature, parameters, type, tag, flags + 14, 13, 13, 13, 0x0a, + + 0 // eod +}; + +static const char qt_meta_stringdata_PresetAction[] = { + "PresetAction\0\0presetChosen()\0" +}; + +void PresetAction::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) +{ + if (_c == QMetaObject::InvokeMetaMethod) { + Q_ASSERT(staticMetaObject.cast(_o)); + PresetAction *_t = static_cast<PresetAction *>(_o); + switch (_id) { + case 0: _t->presetChosen(); break; + default: ; + } + } + Q_UNUSED(_a); +} + +const QMetaObjectExtraData PresetAction::staticMetaObjectExtraData = { + 0, qt_static_metacall +}; + +const QMetaObject PresetAction::staticMetaObject = { + { &QAction::staticMetaObject, qt_meta_stringdata_PresetAction, + qt_meta_data_PresetAction, &staticMetaObjectExtraData } +}; + +#ifdef Q_NO_DATA_RELOCATION +const QMetaObject &PresetAction::getStaticMetaObject() { return staticMetaObject; } +#endif //Q_NO_DATA_RELOCATION + +const QMetaObject *PresetAction::metaObject() const +{ + return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; +} + +void *PresetAction::qt_metacast(const char *_clname) +{ + if (!_clname) return 0; + if (!strcmp(_clname, qt_meta_stringdata_PresetAction)) + return static_cast<void*>(const_cast< PresetAction*>(this)); + return QAction::qt_metacast(_clname); +} + +int PresetAction::qt_metacall(QMetaObject::Call _c, int _id, void **_a) +{ + _id = QAction::qt_metacall(_c, _id, _a); + if (_id < 0) + return _id; + if (_c == QMetaObject::InvokeMetaMethod) { + if (_id < 1) + qt_static_metacall(this, _c, _id, _a); + _id -= 1; + } + return _id; +} +QT_END_MOC_NAMESPACE |