Vuo  2.4.1
VuoInputEditorColor.cc
Go to the documentation of this file.
1
11
16{
17 return new VuoInputEditorColor();
18}
19
23VuoColor VuoInputEditorColor::vuoColorFromQColor(const QColor &qtColor)
24{
25 return VuoColor_makeWithRGBA(qtColor.redF(), qtColor.greenF(), qtColor.blueF(), qtColor.alphaF());
26}
27
33json_object *VuoInputEditorColor::show(QPoint portLeftCenter, json_object *originalValue, json_object *details, map<QString, json_object *> portNamesAndValues)
34{
35 QColorDialog dialog;
36
37 VuoColor colorVuo = VuoColor_makeFromJson(originalValue);
38 QColor colorQt;
39 colorQt.setRedF(colorVuo.r);
40 colorQt.setGreenF(colorVuo.g);
41 colorQt.setBlueF(colorVuo.b);
42 colorQt.setAlphaF(colorVuo.a);
43 dialog.setCurrentColor(colorQt);
44 dialog.setOption(QColorDialog::ShowAlphaChannel);
45
46 // Position the right center of the dialog at the left center of the port.
47 // Estimate the dialog size, since QColorDialog doesn't report its actual size.
48 QPoint dialogTopLeft = portLeftCenter - QPoint(250, 400/2) /*QPoint(dialog.childrenRect().width(), dialog.childrenRect().height()/2.)*/;
49 dialog.move(dialogTopLeft);
50
51 connect(&dialog, &QColorDialog::currentColorChanged, this, &VuoInputEditorColor::currentColorChanged);
52
53 dialog.exec();
54
55 if (dialog.result() == QDialog::Accepted)
56 return VuoColor_getJson(vuoColorFromQColor(dialog.selectedColor()));
57
58 return json_object_get(originalValue);
59}
60
64void VuoInputEditorColor::currentColorChanged(const QColor &color)
65{
66 json_object *valueAsJson = VuoColor_getJson(vuoColorFromQColor(color));
67 emit valueChanged(valueAsJson);
68 json_object_put(valueAsJson);
69}