Radium Engine  1.5.28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WidgetFactory.cpp
1#include <Dataflow/QtGui/GraphEditor/WidgetFactory.hpp>
2
3namespace Ra {
4namespace Dataflow {
5namespace QtGui {
6namespace GraphEditor {
7
8void WidgetFactory::operator()( const std::string& name, std::string& p ) {
9 auto line = new QLineEdit();
10 line->setObjectName( QString::fromStdString( name ) );
11 QLineEdit::connect(
12 line, &QLineEdit::textEdited, [&p]( const QString& string ) { p = string.toStdString(); } );
13 variable_set_editor()->addWidget( line );
14}
15
16#if HAS_TRANSFER_FUNCTION
17/*
18 * Transfer function
19 */
20WidgetFactory::registerWidget<std::array<float, 256 * 4>>(
21 []( EditableParameterBase* editableParameter ) {
22 auto editableTransferFunction =
23 dynamic_cast<EditableParameter<std::array<float, 256 * 4>>*>( editableParameter );
24 // TODO, give a name to the widget so that they can be updated automatically when
25 // loading a node
26 auto button = new QPushButton( "Open widget" );
27 auto transferEditor = new TransferEditor();
28 TransferEditor::connect(
29 transferEditor,
30 &TransferEditor::propertiesChanged,
31 [editableTransferFunction, transferEditor]() {
32 int pos = 0;
33 for ( int i = 0; i < 256; i++ ) {
34 unsigned int color = transferEditor->colorAt( i );
35 editableTransferFunction->m_data.at( pos ) =
36 (unsigned char)( ( 0x00ff0000 & color ) >> 16 ) / 255.f;
37 editableTransferFunction->m_data.at( pos + 1 ) =
38 (unsigned char)( ( 0x0000ff00 & color ) >> 8 ) / 255.f;
39 editableTransferFunction->m_data.at( pos + 2 ) =
40 (unsigned char)( ( 0x000000ff & color ) ) / 255.f;
41 editableTransferFunction->m_data.at( pos + 3 ) =
42 (unsigned char)( ( 0xff000000 & color ) >> 24 ) / 255.f;
43 pos = pos + 4;
44 }
45 } );
46 QPushButton::connect(
47 button, &QPushButton::clicked, [transferEditor]() { transferEditor->show(); } );
48 return button;
49 },
50 []( QWidget*, EditableParameterBase* ) -> bool { return false; } );
51#endif
52
53} // namespace GraphEditor
54} // namespace QtGui
55} // namespace Dataflow
56} // namespace Ra
void addWidget(QWidget *newWidget)
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:4