1
0
Fork 0
mirror of https://github.com/EdgeTX/edgetx.git synced 2025-07-21 15:25:12 +03:00

[Simulator] Virtual joystick tweaks. (#4666)

* [Simulator] Create a reusable RadioTrimWidget; Move all trim-related enums to boards.h; Make sure aux trims are accounted for in SimulatorInterface; Trims now use toolbuttons with icons instead of pushbuttons with text.

* [Simulator] New buttons & icons for virtual joystick axis hold/fix toggles; Joystick ball is now slightly scaled to stick area.

* [Simulator] Virtual joystick now "follows" mouse clicks within the stick area (left-click on empty space will attract the control node).
This commit is contained in:
Max Paperno 2017-03-22 16:05:27 -04:00 committed by Bertrand Songis
parent 919e8eb962
commit d68778ec81
23 changed files with 556 additions and 254 deletions

View file

@ -66,6 +66,42 @@ namespace Board {
SWITCH_3POS
};
enum TrimAxes {
TRIM_AXIS_LH = 0,
TRIM_AXIS_LV,
TRIM_AXIS_RV,
TRIM_AXIS_RH,
TRIM_AXIS_T5,
TRIM_AXIS_T6,
};
enum TrimSwitchIndex
{
TRIM_SW_LH_DEC,
TRIM_SW_LH_INC,
TRIM_SW_LV_DEC,
TRIM_SW_LV_INC,
TRIM_SW_RV_DEC,
TRIM_SW_RV_INC,
TRIM_SW_RH_DEC,
TRIM_SW_RH_INC,
TRIM_SW_T5_DEC,
TRIM_SW_T5_INC,
TRIM_SW_T6_DEC,
TRIM_SW_T6_INC,
TRIM_SW_ENUM_END
};
enum Capability {
Pots,
Sliders,
MouseAnalogs,
Switches,
FactoryInstalledSwitches,
NumTrims,
NumTrimSwitches
};
struct SwitchInfo
{
SwitchType config;
@ -82,15 +118,6 @@ namespace Board {
unsigned int position;
};
enum Capability {
Pots,
Sliders,
MouseAnalogs,
Switches,
FactoryInstalledSwitches,
NumTrims,
NumTrimSwitches
};
}
// TODO remove all those constants

View file

@ -17,6 +17,14 @@
<file>images/simulator/icons/svg/console.svg</file>
<file>images/simulator/icons/svg/eraser.svg</file>
<file>images/simulator/icons/svg/eraser-active.svg</file>
<file>images/simulator/icons/svg/fixed_x.svg</file>
<file>images/simulator/icons/svg/fixed_x-on.svg</file>
<file>images/simulator/icons/svg/fixed_y.svg</file>
<file>images/simulator/icons/svg/fixed_y-on.svg</file>
<file>images/simulator/icons/svg/hold_x.svg</file>
<file>images/simulator/icons/svg/hold_x-on.svg</file>
<file>images/simulator/icons/svg/hold_y.svg</file>
<file>images/simulator/icons/svg/hold_y-on.svg</file>
<file>images/simulator/icons/svg/info.svg</file>
<file>images/simulator/icons/svg/info-active.svg</file>
<file>images/simulator/icons/svg/joystick_settings.svg</file>

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.2" width="24" height="24" viewBox="0 0 24 24" id="svg2">
<metadata id="metadata12">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs id="defs10" />
<g id="g4">
<path d="m 8.6983048,19.732203 c 0,1.839023 1.4965692,3.335593 3.3355932,3.335593 1.839024,0 3.335594,-1.49657 3.335594,-3.335593 0,-1.447648 -0.932854,-2.669587 -2.223729,-3.129899 l 0,-9.3051922 c 1.290875,-0.461423 2.223729,-1.683362 2.223729,-3.13101 0,-1.839024 -1.49657,-3.33559301 -3.335594,-3.33559301 -1.839024,-1e-8 -3.3355932,1.49656901 -3.3355932,3.33559301 0,1.447648 0.932854,2.669587 2.2237292,3.13101 l 0,9.3040812 c -1.2908752,0.461423 -2.2237292,1.683362 -2.2237292,3.13101 z m 3.3355932,1.111864 c -0.613749,0 -1.111864,-0.499227 -1.111864,-1.111864 0,-0.612638 0.498115,-1.111865 1.111864,-1.111865 0.613749,0 1.111865,0.499227 1.111865,1.111865 0,0.612637 -0.498116,1.111864 -1.111865,1.111864 z m 0,-17.7898292 c 0.613749,0 1.111865,0.499227 1.111865,1.111864 0,0.612637 -0.498116,1.111865 -1.111865,1.111865 -0.613749,0 -1.111864,-0.499228 -1.111864,-1.111865 0,-0.612637 0.498115,-1.111864 1.111864,-1.111864 z" id="path6" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.2" width="24" height="24" viewBox="0 0 24 24" id="svg2">
<metadata id="metadata12">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs id="defs10" />
<g id="g4">
<path d="M 18.719627,16.714495 C 18.255424,13.416386 15.423783,10.867797 12,10.867797 9.8080542,10.867797 7.9784136,9.3042237 7.5617627,7.2345559 8.8298305,6.7409153 9.7355932,5.514739 9.7355932,4.0745763 c 0,-1.8726644 -1.5239457,-3.3966102 -3.3966101,-3.3966102 -1.8726645,0 -3.3966102,1.5239458 -3.3966102,3.3966102 0,1.5013017 0.9850169,2.7625762 2.338,3.2109288 C 5.7445763,10.583614 8.5762169,13.132203 12,13.132203 c 2.191946,0 4.021586,1.563573 4.438237,3.633241 -1.268068,0.493641 -2.17383,1.719817 -2.17383,3.15998 0,1.872664 1.523946,3.39661 3.39661,3.39661 1.872664,0 3.39661,-1.523946 3.39661,-3.39661 0,-1.501302 -0.985017,-2.762577 -2.338,-3.210929 z M 6.3389831,2.9423729 c 0.6249762,0 1.1322033,0.5083593 1.1322033,1.1322034 0,0.623844 -0.5072271,1.1322034 -1.1322033,1.1322034 -0.6249763,0 -1.1322034,-0.5083594 -1.1322034,-1.1322034 0,-0.6238441 0.5072271,-1.1322034 1.1322034,-1.1322034 z M 17.661017,21.057627 c -0.624976,0 -1.132203,-0.508359 -1.132203,-1.132203 0,-0.623844 0.507227,-1.132204 1.132203,-1.132204 0.624976,0 1.132203,0.50836 1.132203,1.132204 0,0.623844 -0.507227,1.132203 -1.132203,1.132203 z" id="path6" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.2" width="24" height="24" viewBox="0 0 24 24" id="svg2">
<metadata id="metadata12">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs id="defs10" />
<g id="g4">
<path d="m 4.2508478,8.6135588 c -1.839023,0 -3.33559301,1.4965692 -3.33559301,3.3355932 0,1.839024 1.49657001,3.335594 3.33559301,3.335594 1.447648,0 2.669587,-0.932854 3.129899,-2.223729 l 9.3051922,0 c 0.461423,1.290875 1.683362,2.223729 3.13101,2.223729 1.839024,0 3.335593,-1.49657 3.335593,-3.335594 0,-1.839024 -1.496569,-3.3355932 -3.335593,-3.3355932 -1.447648,0 -2.669587,0.932854 -3.13101,2.2237292 l -9.3040812,0 C 6.9204348,9.5464128 5.6984958,8.6135588 4.2508478,8.6135588 z m -1.111864,3.3355932 c 0,-0.613749 0.499227,-1.111864 1.111864,-1.111864 0.612638,0 1.111865,0.498115 1.111865,1.111864 0,0.613749 -0.499227,1.111865 -1.111865,1.111865 -0.612637,0 -1.111864,-0.498116 -1.111864,-1.111865 z m 17.7898292,0 c 0,0.613749 -0.499227,1.111865 -1.111864,1.111865 -0.612637,0 -1.111865,-0.498116 -1.111865,-1.111865 0,-0.613749 0.499228,-1.111864 1.111865,-1.111864 0.612637,0 1.111864,0.498115 1.111864,1.111864 z" id="path6" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.2" width="24" height="24" viewBox="0 0 24 24" id="svg2">
<metadata id="metadata12">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs id="defs10" />
<g id="g4">
<path d="M 16.714495,5.280373 C 13.416386,5.744576 10.867797,8.576217 10.867797,12 c 0,2.191946 -1.5635734,4.021586 -3.6332412,4.438237 -0.4936406,-1.268067 -1.7198169,-2.17383 -3.1599796,-2.17383 -1.8726644,0 -3.3966102,1.523946 -3.3966102,3.39661 0,1.872664 1.5239458,3.39661 3.3966102,3.39661 1.5013017,0 2.7625762,-0.985017 3.2109288,-2.338 3.298109,-0.464203 5.846698,-3.295844 5.846698,-6.719627 0,-2.191946 1.563573,-4.021586 3.633241,-4.438237 0.493641,1.268068 1.719817,2.17383 3.15998,2.17383 1.872664,0 3.39661,-1.523946 3.39661,-3.39661 0,-1.872664 -1.523946,-3.39661 -3.39661,-3.39661 -1.501302,0 -2.762577,0.985017 -3.210929,2.338 z M 2.9423728,17.661017 c 0,-0.624976 0.5083593,-1.132203 1.1322034,-1.132203 0.623844,0 1.1322034,0.507227 1.1322034,1.132203 0,0.624976 -0.5083594,1.132203 -1.1322034,1.132203 -0.6238441,0 -1.1322034,-0.507227 -1.1322034,-1.132203 z M 21.057627,6.338983 c 0,0.624976 -0.508359,1.132203 -1.132203,1.132203 -0.623844,0 -1.132204,-0.507227 -1.132204,-1.132203 0,-0.624976 0.50836,-1.132203 1.132204,-1.132203 0.623844,0 1.132203,0.507227 1.132203,1.132203 z" id="path6" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.2" width="24" height="24" viewBox="0 0 24 24" id="svg2">
<metadata id="metadata12">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs id="defs10" />
<g id="g4">
<path d="m 4.2508478,1.2237283 c -1.839023,0 -3.33559301,1.4965692 -3.33559301,3.3355927 0,1.839025 1.49657001,3.335595 3.33559301,3.335595 1.447648,0 2.669587,-0.932855 3.129899,-2.22373 l 9.3051922,0 c 0.461423,1.290875 1.683362,2.22373 3.13101,2.22373 1.839024,0 3.335593,-1.49657 3.335593,-3.335595 0,-1.8390235 -1.496569,-3.3355927 -3.335593,-3.3355927 -1.447648,0 -2.669587,0.932854 -3.13101,2.2237292 l -9.3040812,0 C 6.9204348,2.1565823 5.6984958,1.2237283 4.2508478,1.2237283 z M 3.1389838,4.559321 c 0,-0.6137485 0.499227,-1.1118635 1.111864,-1.1118635 0.612638,0 1.111865,0.498115 1.111865,1.1118635 0,0.61375 -0.499227,1.111865 -1.111865,1.111865 -0.612637,0 -1.111864,-0.498115 -1.111864,-1.111865 z m 17.7898292,0 c 0,0.61375 -0.499227,1.111865 -1.111864,1.111865 -0.612637,0 -1.111865,-0.498115 -1.111865,-1.111865 0,-0.6137485 0.499228,-1.1118635 1.111865,-1.1118635 0.612637,0 1.111864,0.498115 1.111864,1.1118635 z" id="path6" />
<path d="m 11.881357,9.7203386 c -2.0268766,0 -3.6852308,1.6583534 -3.6852308,3.6852304 v 1.842616 H 6.3535111 v 7.370458 H 17.409201 v -7.370458 h -1.842613 v -1.842616 c 0,-2.026877 -1.658354,-3.6852304 -3.685231,-3.6852304 z m 0,1.8426154 c 1.031864,0 1.842614,0.81075 1.842614,1.842615 v 1.842616 h -3.685228 v -1.842616 c 0,-1.031865 0.81075,-1.842615 1.842614,-1.842615 z" id="path3043" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2 KiB

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.2" width="24" height="24" viewBox="0 0 24 24" id="svg2">
<metadata id="metadata12">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs id="defs10" />
<g id="g4">
<path d="m 4.2508478,1.2237283 c -1.839023,0 -3.33559301,1.4965692 -3.33559301,3.3355927 0,1.839025 1.49657001,3.335595 3.33559301,3.335595 1.447648,0 2.669587,-0.932855 3.129899,-2.22373 l 9.3051922,0 c 0.461423,1.290875 1.683362,2.22373 3.13101,2.22373 1.839024,0 3.335593,-1.49657 3.335593,-3.335595 0,-1.8390235 -1.496569,-3.3355927 -3.335593,-3.3355927 -1.447648,0 -2.669587,0.932854 -3.13101,2.2237292 l -9.3040812,0 C 6.9204348,2.1565823 5.6984958,1.2237283 4.2508478,1.2237283 z M 3.1389838,4.559321 c 0,-0.6137485 0.499227,-1.1118635 1.111864,-1.1118635 0.612638,0 1.111865,0.498115 1.111865,1.1118635 0,0.61375 -0.499227,1.111865 -1.111865,1.111865 -0.612637,0 -1.111864,-0.498115 -1.111864,-1.111865 z m 17.7898292,0 c 0,0.61375 -0.499227,1.111865 -1.111864,1.111865 -0.612637,0 -1.111865,-0.498115 -1.111865,-1.111865 0,-0.6137485 0.499228,-1.1118635 1.111865,-1.1118635 0.612637,0 1.111864,0.498115 1.111864,1.1118635 z" id="path6" />
<path d="m 11.999999,8.1864411 c -1.999576,0 -3.6355917,1.6360178 -3.6355917,3.6355939 h 1.8177947 c 0,-1.017967 0.799831,-1.817797 1.817797,-1.817797 1.017966,0 1.817797,0.79983 1.817797,1.817797 v 3.635593 H 6.5466099 v 7.271187 H 17.453389 v -7.271187 h -1.817796 v -3.635593 c 0,-1.9995761 -1.636018,-3.6355939 -3.635594,-3.6355939 z" id="path3014" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2 KiB

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.2" width="24" height="24" viewBox="0 0 24 24" id="svg2">
<metadata id="metadata12">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs id="defs10" />
<g id="g4">
<path d="m 2.2915249,19.783051 c 0,1.839023 1.4965695,3.335593 3.3355925,3.335593 1.839025,0 3.335595,-1.49657 3.335595,-3.335593 0,-1.447648 -0.932855,-2.669587 -2.22373,-3.129899 l 0,-9.3051925 c 1.290875,-0.461423 2.22373,-1.683362 2.22373,-3.13101 0,-1.839024 -1.49657,-3.33559299 -3.335595,-3.33559299 -1.839023,0 -3.3355925,1.49656899 -3.3355925,3.33559299 0,1.447648 0.932854,2.669587 2.2237295,3.13101 l 0,9.3040815 c -1.2908755,0.461423 -2.2237295,1.683362 -2.2237295,3.13101 z m 3.3355925,1.111864 c -0.613748,0 -1.111863,-0.499227 -1.111863,-1.111864 0,-0.612638 0.498115,-1.111865 1.111863,-1.111865 0.61375,0 1.111865,0.499227 1.111865,1.111865 0,0.612637 -0.498115,1.111864 -1.111865,1.111864 z m 0,-17.7898295 c 0.61375,0 1.111865,0.499227 1.111865,1.111864 0,0.612637 -0.498115,1.111865 -1.111865,1.111865 -0.613748,0 -1.111863,-0.499228 -1.111863,-1.111865 0,-0.612637 0.498115,-1.111864 1.111863,-1.111864 z" id="path6" />
<path d="m 17.135593,5.4491533 c -2.026877,0 -3.685231,1.6583532 -3.685231,3.6852302 v 1.8426155 h -1.842615 v 7.370459 h 11.05569 V 10.976999 H 20.820824 V 9.1343835 c 0,-2.026877 -1.658354,-3.6852302 -3.685231,-3.6852302 z m 0,1.8426152 c 1.031864,0 1.842614,0.81075 1.842614,1.842615 V 10.976999 H 15.292979 V 9.1343835 c 0,-1.031865 0.81075,-1.842615 1.842614,-1.842615 z" id="path3043" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2 KiB

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.2" width="24" height="24" viewBox="0 0 24 24" id="svg2">
<metadata id="metadata12">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs id="defs10" />
<g id="g4">
<path d="m 2.2915249,19.783051 c 0,1.839023 1.4965695,3.335593 3.3355925,3.335593 1.839025,0 3.335595,-1.49657 3.335595,-3.335593 0,-1.447648 -0.932855,-2.669587 -2.22373,-3.129899 l 0,-9.3051925 c 1.290875,-0.461423 2.22373,-1.683362 2.22373,-3.13101 0,-1.839024 -1.49657,-3.33559299 -3.335595,-3.33559299 -1.839023,0 -3.3355925,1.49656899 -3.3355925,3.33559299 0,1.447648 0.932854,2.669587 2.2237295,3.13101 l 0,9.3040815 c -1.2908755,0.461423 -2.2237295,1.683362 -2.2237295,3.13101 z m 3.3355925,1.111864 c -0.613748,0 -1.111863,-0.499227 -1.111863,-1.111864 0,-0.612638 0.498115,-1.111865 1.111863,-1.111865 0.61375,0 1.111865,0.499227 1.111865,1.111865 0,0.612637 -0.498115,1.111864 -1.111865,1.111864 z m 0,-17.7898295 c 0.61375,0 1.111865,0.499227 1.111865,1.111864 0,0.612637 -0.498115,1.111865 -1.111865,1.111865 -0.613748,0 -1.111863,-0.499228 -1.111863,-1.111865 0,-0.612637 0.498115,-1.111864 1.111863,-1.111864 z" id="path6" />
<path d="m 17.084745,3.7627115 c -1.999576,0 -3.635591,1.6360178 -3.635591,3.6355939 h 1.817794 c 0,-1.017967 0.799831,-1.817797 1.817797,-1.817797 1.017966,0 1.817797,0.79983 1.817797,1.817797 v 3.6355926 h -7.271186 v 7.271188 H 22.538135 V 11.033898 H 20.720339 V 7.3983054 c 0,-1.9995761 -1.636018,-3.6355939 -3.635594,-3.6355939 z" id="path3014" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2 KiB

View file

@ -60,8 +60,11 @@ class Node : public QGraphicsObject
void setFixedY(bool val) { fixedY = val; }
bool getFixedX() { return fixedX; }
bool getFixedY() { return fixedY; }
void setMinX(int val) {minX = val;};
void setMaxX(int val) {maxX = val;};
void setMinX(int val) { minX = val; }
void setMaxX(int val) { maxX = val; }
void setPressed(bool pressed) { bPressed = pressed; }
bool isPressed() const { return bPressed; }
void setColor(const QColor & color);
signals:

View file

@ -69,20 +69,6 @@ enum FailsafeModes {
FAILSAFE_LAST = FAILSAFE_RECEIVER
};
#define TRIM_LH_L 0
#define TRIM_LH_R 1
#define TRIM_LV_DN 2
#define TRIM_LV_UP 3
#define TRIM_RV_DN 4
#define TRIM_RV_UP 5
#define TRIM_RH_L 6
#define TRIM_RH_R 7
#define TRIM_T5_DN 8
#define TRIM_T5_UP 9
#define TRIM_T6_DN 10
#define TRIM_T6_UP 11
#define TRIM_NONE 12
#define CHAR_FOR_NAMES " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-."
#define CHAR_FOR_NAMES_REGEX "[ A-Za-z0-9_.-,]*"

View file

@ -51,6 +51,7 @@ set(simulation_HDRS
widgets/radiofaderwidget.h
widgets/radioknobwidget.h
widgets/radioswitchwidget.h
widgets/radiotrimwidget.h
widgets/sliderwidget.h
widgets/virtualjoystickwidget.h
)

View file

@ -57,7 +57,7 @@ class TxOutputs
struct Trims
{
int values[CPN_MAX_STICKS]; /* lh lv rv rh */
int values[CPN_MAX_STICKS + CPN_MAX_AUX_TRIMS]; /* lh lv rv rh t5 t6 */
bool extended;
};

View file

@ -55,7 +55,7 @@ SimulatorWidget::SimulatorWidget(QWidget * parent, SimulatorInterface *simulator
flags(flags),
lastPhase(-1),
buttonPressed(0),
trimPressed(TRIM_NONE),
trimPressed(255),
startupFromFile(false),
deleteTempRadioData(false),
saveTempRadioData(false),
@ -113,13 +113,13 @@ SimulatorWidget::SimulatorWidget(QWidget * parent, SimulatorInterface *simulator
vJoyRight = new VirtualJoystickWidget(this, 'R');
ui->rightStickLayout->addWidget(vJoyRight);
connect(vJoyLeft, SIGNAL(trimButtonPressed(int)), this, SLOT(onTrimPressed(int)));
connect(vJoyLeft, SIGNAL(trimButtonReleased()), this, SLOT(onTrimReleased()));
connect(vJoyLeft, SIGNAL(trimSliderMoved(int,int)), this, SLOT(onTrimSliderMoved(int,int)));
connect(vJoyLeft, &VirtualJoystickWidget::trimButtonPressed, this, &SimulatorWidget::onTrimPressed);
connect(vJoyLeft, &VirtualJoystickWidget::trimButtonReleased, this, &SimulatorWidget::onTrimReleased);
connect(vJoyLeft, &VirtualJoystickWidget::trimSliderMoved, this, &SimulatorWidget::onTrimSliderMoved);
connect(vJoyRight, SIGNAL(trimButtonPressed(int)), this, SLOT(onTrimPressed(int)));
connect(vJoyRight, SIGNAL(trimButtonReleased()), this, SLOT(onTrimReleased()));
connect(vJoyRight, SIGNAL(trimSliderMoved(int,int)), this, SLOT(onTrimSliderMoved(int,int)));
connect(vJoyRight, &VirtualJoystickWidget::trimButtonPressed, this, &SimulatorWidget::onTrimPressed);
connect(vJoyRight, &VirtualJoystickWidget::trimButtonReleased, this, &SimulatorWidget::onTrimReleased);
connect(vJoyRight, &VirtualJoystickWidget::trimSliderMoved, this, &SimulatorWidget::onTrimSliderMoved);
timer->setInterval(10);
connect(timer, SIGNAL(timeout()), this, SLOT(onTimerEvent()));
@ -739,19 +739,19 @@ void SimulatorWidget::getValues()
// Read stick trim values from firmware simulator and set joystick widgets as needed.
void SimulatorWidget::setTrims()
{
typedef VirtualJoystickWidget VJW;
using namespace Board;
static Trims lastTrims;
Trims trims;
simulator->getTrims(trims);
if (trims.values[VJW::TRIM_AXIS_L_X] != lastTrims.values[VJW::TRIM_AXIS_L_X])
vJoyLeft->setTrimValue(VJW::TRIM_AXIS_L_X, trims.values[VJW::TRIM_AXIS_L_X]);
if (trims.values[VJW::TRIM_AXIS_L_Y] != lastTrims.values[VJW::TRIM_AXIS_L_Y])
vJoyLeft->setTrimValue(VJW::TRIM_AXIS_L_Y, trims.values[VJW::TRIM_AXIS_L_Y]);
if (trims.values[VJW::TRIM_AXIS_R_Y] != lastTrims.values[VJW::TRIM_AXIS_R_Y])
vJoyRight->setTrimValue(VJW::TRIM_AXIS_R_Y, trims.values[VJW::TRIM_AXIS_R_Y]);
if (trims.values[VJW::TRIM_AXIS_R_X] != lastTrims.values[VJW::TRIM_AXIS_R_X])
vJoyRight->setTrimValue(VJW::TRIM_AXIS_R_X, trims.values[VJW::TRIM_AXIS_R_X]);
if (trims.values[TRIM_AXIS_LH] != lastTrims.values[TRIM_AXIS_LH])
vJoyLeft->setTrimValue(TRIM_AXIS_LH, trims.values[TRIM_AXIS_LH]);
if (trims.values[TRIM_AXIS_LV] != lastTrims.values[TRIM_AXIS_LV])
vJoyLeft->setTrimValue(TRIM_AXIS_LV, trims.values[TRIM_AXIS_LV]);
if (trims.values[TRIM_AXIS_RV] != lastTrims.values[TRIM_AXIS_RV])
vJoyRight->setTrimValue(TRIM_AXIS_RV, trims.values[TRIM_AXIS_RV]);
if (trims.values[TRIM_AXIS_RH] != lastTrims.values[TRIM_AXIS_RH])
vJoyRight->setTrimValue(TRIM_AXIS_RH, trims.values[TRIM_AXIS_RH]);
if (trims.extended != lastTrims.extended) {
int trimMin = -125, trimMax = +125;
@ -759,10 +759,10 @@ void SimulatorWidget::setTrims()
trimMin = -500;
trimMax = +500;
}
vJoyLeft->setTrimRange(VJW::TRIM_AXIS_L_X, trimMin, trimMax);
vJoyLeft->setTrimRange(VJW::TRIM_AXIS_L_Y, trimMin, trimMax);
vJoyRight->setTrimRange(VJW::TRIM_AXIS_R_Y, trimMin, trimMax);
vJoyRight->setTrimRange(VJW::TRIM_AXIS_R_X, trimMin, trimMax);
vJoyLeft->setTrimRange(TRIM_AXIS_LH, trimMin, trimMax);
vJoyLeft->setTrimRange(TRIM_AXIS_LV, trimMin, trimMax);
vJoyRight->setTrimRange(TRIM_AXIS_RV, trimMin, trimMax);
vJoyRight->setTrimRange(TRIM_AXIS_RH, trimMin, trimMax);
}
lastTrims = trims;
}
@ -771,17 +771,6 @@ void SimulatorWidget::setTrims()
* Event handlers/private slots
*/
//void SimulatorDialog::showEvent(QShowEvent *)
//{
// if (firstShow && isVisible()) {
// firstShow = false;
// }
//}
//void SimulatorDialog::closeEvent(QCloseEvent *)
//{
//}
void SimulatorWidget::mousePressEvent(QMouseEvent *event)
{
if (radioUiWidget)
@ -819,19 +808,19 @@ void SimulatorWidget::onTimerEvent()
}
}
void SimulatorWidget::onTrimPressed(int which)
void SimulatorWidget::onTrimPressed(int index)
{
trimPressed = which;
trimPressed = index;
}
void SimulatorWidget::onTrimReleased()
void SimulatorWidget::onTrimReleased(int)
{
trimPressed = TRIM_NONE;
trimPressed = 255;
}
void SimulatorWidget::onTrimSliderMoved(int which, int value)
void SimulatorWidget::onTrimSliderMoved(int index, int value)
{
simulator->setTrim(which, value);
simulator->setTrim(index, value);
}
void SimulatorWidget::centerSticks()

View file

@ -140,16 +140,14 @@ class SimulatorWidget : public QWidget
#endif
private slots:
//virtual void showEvent(QShowEvent *);
//virtual void closeEvent(QCloseEvent *);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void wheelEvent(QWheelEvent *event);
void onTimerEvent();
void onTrimPressed(int which);
void onTrimReleased();
void onTrimSliderMoved(int which, int value);
void onTrimPressed(int index);
void onTrimReleased(int);
void onTrimSliderMoved(int index, int value);
void centerSticks();
void onjoystickAxisValueChanged(int axis, int value);

View file

@ -0,0 +1,134 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _RADIOTRIMWIDGET_H_
#define _RADIOTRIMWIDGET_H_
#include "radiowidget.h"
#include "sliderwidget.h"
#include <QToolButton>
class RadioTrimWidget : public RadioWidget
{
Q_OBJECT
public:
explicit RadioTrimWidget(Qt::Orientation orientation = Qt::Vertical, QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) :
RadioWidget(parent, f),
m_slider(NULL)
{
init(orientation);
}
explicit RadioTrimWidget(const QString & labelText, Qt::Orientation orientation = Qt::Vertical, int value = 0, QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) :
RadioWidget(labelText, value, parent, f),
m_slider(NULL)
{
init(orientation);
}
void setIndices(int sliderIdx = -1, int decrBtnIdx = -1, int incrBtnIdx = -1)
{
setIndex(sliderIdx);
m_btnDecIndex = decrBtnIdx;
m_btnIncIndex = incrBtnIdx;
}
void setTrimRange(int min, int max)
{
if (m_slider)
m_slider->setRange(min, max);
}
signals:
void trimButtonPressed(int index);
void trimButtonReleased(int index);
void trimSliderMoved(int index, int value);
protected slots:
void init(Qt::Orientation orientation)
{
m_type = RADIO_WIDGET_TRIM;
m_slider = new SliderWidget(this);
m_slider->setOrientation(orientation);
setTrimRange(-125, 125);
setIndices();
QSize btnIcnSz(12, 12);
QWidget * trimWidget = new QWidget(this);
QBoxLayout * trimLayout = new QVBoxLayout(trimWidget);
trimLayout->setSpacing(5);
trimLayout->setContentsMargins(8, 8, 8, 8);
QToolButton * trimBtnInc = new QToolButton(trimWidget);
trimBtnInc->setIconSize(btnIcnSz);
QToolButton * trimBtnDec = new QToolButton(trimWidget);
trimBtnDec->setIconSize(btnIcnSz);
Qt::Alignment algn;
if (orientation == Qt::Horizontal) {
trimWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
trimLayout->setDirection(QBoxLayout::RightToLeft);
trimBtnInc->setArrowType(Qt::RightArrow);
trimBtnDec->setArrowType(Qt::LeftArrow);
algn = Qt::AlignVCenter;
}
else {
trimWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
trimLayout->setDirection(QBoxLayout::TopToBottom);
trimBtnInc->setArrowType(Qt::UpArrow);
trimBtnDec->setArrowType(Qt::DownArrow);
algn = Qt::AlignHCenter;
}
trimLayout->addWidget(trimBtnInc, 0, algn);
trimLayout->addWidget(m_slider, 1, algn);
trimLayout->addWidget(trimBtnDec, 0, algn);
setWidget(trimWidget, algn);
connect(m_slider, &SliderWidget::valueChanged, this, &RadioWidget::setValue);
connect(this, &RadioWidget::valueChanged, this, &RadioTrimWidget::onValueChanged);
connect(trimBtnInc, &QToolButton::pressed, [this]() { emit trimButtonPressed(m_btnIncIndex); });
connect(trimBtnInc, &QToolButton::released, [this]() { emit trimButtonReleased(m_btnIncIndex); });
connect(trimBtnDec, &QToolButton::pressed, [this]() { emit trimButtonPressed(m_btnDecIndex); });
connect(trimBtnDec, &QToolButton::released, [this]() { emit trimButtonReleased(m_btnDecIndex); });
}
void onValueChanged(int value)
{
m_slider->blockSignals(true);
m_slider->setValue(value);
m_slider->blockSignals(false);
emit trimSliderMoved(m_index, m_value);
}
protected:
SliderWidget * m_slider;
int m_btnDecIndex;
int m_btnIncIndex;
};
#endif // _RADIOTRIMWIDGET_H_

View file

@ -58,7 +58,7 @@ void RadioWidget::setValue(int value)
{
if (value != m_value) {
m_value = value;
emit valueChanged(m_value);
emit valueChanged(value);
}
}
@ -166,7 +166,7 @@ void RadioWidget::addLabel()
}
}
void RadioWidget::setWidget(QWidget * widget)
void RadioWidget::setWidget(QWidget * widget, Qt::Alignment align)
{
if (m_controlWidget) {
m_gridLayout->removeWidget(m_controlWidget);
@ -174,7 +174,7 @@ void RadioWidget::setWidget(QWidget * widget)
}
m_controlWidget = widget;
if (widget) {
m_gridLayout->addWidget(widget, 0, 0, 1, 1, Qt::AlignHCenter);
m_gridLayout->addWidget(widget, 0, 0, 1, 1, align);
m_gridLayout->setRowStretch(0, 1);
}
}

View file

@ -41,6 +41,7 @@ class RadioWidget : public QWidget
RADIO_WIDGET_SWITCH,
RADIO_WIDGET_KNOB,
RADIO_WIDGET_FADER,
RADIO_WIDGET_TRIM,
RADIO_WIDGET_STICK // actually one axis of a stick
};
@ -76,7 +77,6 @@ class RadioWidget : public QWidget
void setStateData(const QByteArray & data);
void changeVisibility(bool visible);
virtual int getValue() const;
int getIndex() const;
int getType() const;
@ -87,7 +87,7 @@ class RadioWidget : public QWidget
void init();
void addLabel();
void setWidget(QWidget * widget = NULL);
void setWidget(QWidget * widget = NULL, Qt::Alignment align = Qt::AlignHCenter);
int m_value;
int m_index;
@ -105,7 +105,7 @@ class RadioWidget : public QWidget
signals:
void valueChanged(int m_value);
void valueChanged(int value);
void flagsChanged(quint16 flags);
};

View file

@ -42,6 +42,7 @@ class SliderWidget : public QSlider
{
if (event->button() == Qt::RightButton && event->type() == QEvent::MouseButtonDblClick) {
setValue(0);
emit sliderMoved(0);
event->accept();
}
QSlider::mousePressEvent(event);

View file

@ -18,27 +18,32 @@
* GNU General Public License for more details.
*/
#define GBALL_SIZE 20
#define RESX 1024
#define GBALL_SIZE 25
#define GBALL_SIZE_MN 20
#define GBALL_SIZE_MX 35
#include "virtualjoystickwidget.h"
#include "boards.h"
#include "constants.h"
#include "sliderwidget.h"
#include "modeledit/node.h"
#include "helpers.h"
#include "radiotrimwidget.h"
#include "simulator.h"
VirtualJoystickWidget::VirtualJoystickWidget(QWidget *parent, QChar side, bool showTrims, bool showBtns, bool showValues, QSize size) :
QWidget(parent),
stickSide(side),
prefSize(size),
hTrimSlider(NULL),
vTrimSlider(NULL),
hTrimWidget(NULL),
vTrimWidget(NULL),
btnHoldX(NULL),
btnHoldY(NULL),
btnFixX(NULL),
btnFixY(NULL),
nodeLabelX(NULL),
nodeLabelY(NULL)
nodeLabelY(NULL),
m_stickPressed(false)
{
ar = (float)size.width() / size.height();
extraSize = QSize(0, 0);
@ -54,12 +59,11 @@ VirtualJoystickWidget::VirtualJoystickWidget(QWidget *parent, QChar side, bool s
gv = new QGraphicsView(this);
gv->setSizePolicy(sizePolicy);
gv->setMinimumSize(size);
// gv->setMaximumSize(size + size * 3);
// gv->setFixedSize(prefSize);
gv->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
gv->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
gv->setRenderHints(QPainter::Antialiasing);
scene = new QGraphicsScene(gv);
scene = new CustomGraphicsScene(gv);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
gv->setScene(scene);
@ -83,14 +87,12 @@ VirtualJoystickWidget::VirtualJoystickWidget(QWidget *parent, QChar side, bool s
}
if (showTrims) {
QWidget * hTrimWidget = createTrimWidget('H');
QWidget * vTrimWidget = createTrimWidget('V');
hTrimWidget = createTrimWidget('H');
vTrimWidget = createTrimWidget('V');
layout->addWidget(vTrimWidget, 1, colvt, 1, 1);
layout->addWidget(hTrimWidget, 2, 2, 1, 1);
hTrimSlider = hTrimWidget->findChild<SliderWidget *>();
vTrimSlider = vTrimWidget->findChild<SliderWidget *>();
extraSize += QSize(vTrimWidget->sizeHint().width(), hTrimWidget->sizeHint().height());
}
else {
@ -131,10 +133,12 @@ VirtualJoystickWidget::VirtualJoystickWidget(QWidget *parent, QChar side, bool s
layout->addItem(new QSpacerItem(0, 0), 1, 0, 2, 1); // r1-2 c0: left h spacer
layout->addWidget(gv, 1, 2, 1, 1); // r1 c2: stick widget
layout->addItem(new QSpacerItem(0, 0), 1, 4, 2, 1); // r1-2 c4: right h spacer
layout->addItem(new QSpacerItem(0, 0), 3, 0, 1, 5); // r3 c0-4: bot v spacer
layout->addItem(new QSpacerItem(0, 0), 3, 0, 1, 5); // r4 c0-4: bot v spacer
connect(node, SIGNAL(xChanged()), this, SLOT(updateNodeValueLabels()));
connect(node, SIGNAL(yChanged()), this, SLOT(updateNodeValueLabels()));
connect(node, &Node::xChanged, this, &VirtualJoystickWidget::updateNodeValueLabels);
connect(node, &Node::yChanged, this, &VirtualJoystickWidget::updateNodeValueLabels);
connect(scene, &CustomGraphicsScene::mouseEvent, this, &VirtualJoystickWidget::onGsMouseEvent);
setSize(prefSize, frameSize());
}
@ -176,25 +180,25 @@ QPointF VirtualJoystickWidget::getStickPos()
void VirtualJoystickWidget::setTrimValue(int which, int value)
{
SliderWidget * slider = getTrimSlider(which);
if (slider) {
slider->setValue(value);
RadioTrimWidget * trim = getTrimWidget(which);
if (trim) {
trim->setValue(value);
}
}
void VirtualJoystickWidget::setTrimRange(int which, int min, int max)
{
SliderWidget * slider = getTrimSlider(which);
if (slider) {
slider->setRange(min, max);
RadioTrimWidget * trim = getTrimWidget(which);
if (trim) {
trim->setTrimRange(min, max);
}
}
int VirtualJoystickWidget::getTrimValue(int which)
{
SliderWidget * slider = getTrimSlider(which);
if (slider) {
return slider->value();
RadioTrimWidget * trim = getTrimWidget(which);
if (trim) {
return trim->getValue();
}
return 0;
}
@ -269,13 +273,15 @@ void VirtualJoystickWidget::setSize(const QSize & size, const QSize &)
layout->setColumnStretch(2, newGvSz);
layout->setRowStretch(1, newGvSz);
//prefSize = QSize(newGvSz + extraSize.width(), newGvSz + extraSize.height());
gv->resize(newGvSz, newGvSz);
gv->updateGeometry();
int ballSize = (newGvSz * GBALL_SIZE * 0.005f);
ballSize = qMin(GBALL_SIZE_MX, qMax(ballSize, GBALL_SIZE_MN));
QRectF qr = (QRectF)gv->contentsRect();
qreal w = qr.width() - GBALL_SIZE;
qreal h = qr.height() - GBALL_SIZE;
qreal w = qr.width() - ballSize;
qreal h = qr.height() - ballSize;
qreal cx = qr.width() / 2;
qreal cy = qr.height() / 2;
qreal nodeX = node->getX();
@ -283,120 +289,64 @@ void VirtualJoystickWidget::setSize(const QSize & size, const QSize &)
scene->setSceneRect(-cx,-cy,w,h);
node->setBallSize(ballSize);
node->setX(nodeX);
node->setY(nodeY);
//qDebug() << thisAspectRatio << size << newGvSz << spacerSz << extraSize << gv->geometry() << gv->contentsRect() << gv->frameRect() << getStickPos();
}
QWidget *VirtualJoystickWidget::createTrimWidget(QChar type)
RadioTrimWidget * VirtualJoystickWidget::createTrimWidget(QChar type)
{
QSizePolicy sp;
QString btnAlabel, btnBlabel;
RadioTrimWidget * trimWidget = new RadioTrimWidget(type == 'H' ? Qt::Horizontal : Qt::Vertical);
trimWidget->setIndices(getTrimSliderType(type), getTrimButtonType(type, 0), getTrimButtonType(type, 1));
QString btnAname = QString("%1TrimBtnA_%2").arg(type.toLower()).arg(stickSide);
QString btnBname = QString("%1TrimBtnB_%2").arg(type.toLower()).arg(stickSide);
QString sliderName = QString("%1TrimAdj_%2").arg(type.toLower()).arg(stickSide);
QWidget * trimWidget = new QWidget(this);
QBoxLayout * trimLayout = new QVBoxLayout(trimWidget);
SliderWidget * trimSlider = new SliderWidget(trimWidget);
QPushButton * trimBtnA = new QPushButton(trimWidget);
QPushButton * trimBtnB = new QPushButton(trimWidget);
if (type == 'H') {
sp = QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
trimLayout->setDirection(QBoxLayout::LeftToRight);
trimSlider->setFixedHeight(23);
trimSlider->setOrientation(Qt::Horizontal);
trimBtnA->setText(ARROW_LEFT);
trimBtnB->setText(ARROW_RIGHT);
}
else {
sp = QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
trimLayout->setDirection(QBoxLayout::TopToBottom);
trimSlider->setFixedWidth(23);
trimSlider->setOrientation(Qt::Vertical);
trimBtnA->setText(ARROW_UP);
trimBtnB->setText(ARROW_DOWN);
}
trimWidget->setSizePolicy(sp);
trimSlider->setObjectName(sliderName);
trimSlider->setProperty("trimType", getTrimSliderType(type));
trimSlider->setSizePolicy(sp);
trimSlider->setMinimum(-125);
trimSlider->setMaximum(125);
trimBtnA->setObjectName(btnAname);
trimBtnA->setProperty("btnType", getTrimButtonType(type, 0));
trimBtnA->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
trimBtnA->setMaximumSize(QSize(23, 23));
trimBtnA->setAutoDefault(false);
trimBtnB->setObjectName(btnBname);
trimBtnB->setProperty("btnType", getTrimButtonType(type, 1));
trimBtnB->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
trimBtnB->setMaximumSize(QSize(23, 23));
trimBtnB->setAutoDefault(false);
trimLayout->setSpacing(6);
trimLayout->setContentsMargins(8, 9, 8, 9);
trimLayout->addWidget(trimBtnA);
trimLayout->addWidget(trimSlider);
trimLayout->addWidget(trimBtnB);
connect(trimBtnA, SIGNAL(pressed()), SLOT(onTrimPressed()));
connect(trimBtnB, SIGNAL(pressed()), SLOT(onTrimPressed()));
connect(trimBtnA, SIGNAL(released()), SIGNAL(trimButtonReleased()));
connect(trimBtnB, SIGNAL(released()), SIGNAL(trimButtonReleased()));
connect(trimSlider, SIGNAL(valueChanged(int)), SLOT(onSliderChange(int)));
connect(trimWidget, &RadioTrimWidget::trimButtonPressed, this, &VirtualJoystickWidget::trimButtonPressed);
connect(trimWidget, &RadioTrimWidget::trimButtonReleased, this, &VirtualJoystickWidget::trimButtonReleased);
connect(trimWidget, &RadioTrimWidget::trimSliderMoved, this, &VirtualJoystickWidget::trimSliderMoved);
return trimWidget;
}
QPushButton * VirtualJoystickWidget::createButtonWidget(int type)
QToolButton * VirtualJoystickWidget::createButtonWidget(int type)
{
QString btnRole, btnLabel;
QString btnLabel, tooltip;
QIcon icon;
switch (type) {
case HOLD_Y:
btnLabel = tr("Hold Y");
btnLabel = tr("Hld Y");
tooltip = tr("Hold Vertical stick position.");
icon = Simulator::SimulatorIcon("hold_y");
break;
case FIX_Y:
btnLabel = tr("Fix Y");
tooltip = tr("Prevent Vertical movement of stick.");
icon = Simulator::SimulatorIcon("fixed_y");
break;
case FIX_X:
btnLabel = tr("Fix X");
tooltip = tr("Prevent Horizontal movement of stick.");
icon = Simulator::SimulatorIcon("fixed_x");
break;
case HOLD_X:
default:
btnLabel = tr("Hold X");
btnLabel = tr("Hld X");
tooltip = tr("Hold Horizontal stick position.");
icon = Simulator::SimulatorIcon("hold_x");
break;
default:
return NULL;
}
QPushButton * btn = new QPushButton(this);
btn->setObjectName(QString("%1_%2").arg(btnLabel.replace(" ", "_")).arg(stickSide));
QToolButton * btn = new QToolButton(this);
btn->setProperty("btnType", type);
btn->setIcon(icon);
btn->setIconSize(QSize(20, 20));
btn->setToolButtonStyle(Qt::ToolButtonIconOnly);
btn->setText(btnLabel);
QFont font;
font.setPointSize(8);
btn->setFont(font);
btn->setStyleSheet(QLatin1String( \
"QPushButton {"
" background-color: #EEEEEE;"
" border-style: outset;"
" border-width: 1px;"
" border-radius: 4px;"
" border-color: black;"
" padding: 2px;"
"}"
"QPushButton:checked {\n"
" background-color: #4CC417;\n"
" border-style: inset;\n"
"}" ));
btn->setToolTip(tooltip);
btn->setCheckable(true);
btn->setAutoRaise(true);
connect(btn, SIGNAL(toggled(bool)), SLOT(onButtonChange(bool)));
connect(btn, &QToolButton::toggled, this, &VirtualJoystickWidget::onButtonChange);
return btn;
}
@ -423,76 +373,63 @@ QLayout *VirtualJoystickWidget::createNodeValueLayout(QChar type, QLabel *& valL
int VirtualJoystickWidget::getTrimSliderType(QChar type)
{
using namespace Board;
if (stickSide == 'L') {
if (type == 'H')
return TRIM_AXIS_L_X;
return TRIM_AXIS_LH;
else
return TRIM_AXIS_L_Y;
return TRIM_AXIS_LV;
}
else {
if (type == 'H')
return TRIM_AXIS_R_X;
return TRIM_AXIS_RH;
else
return TRIM_AXIS_R_Y;
return TRIM_AXIS_RV;
}
}
int VirtualJoystickWidget::getTrimButtonType(QChar type, int pos)
{
using namespace Board;
if (stickSide == 'L') {
if (type == 'H') {
if (pos == 0)
return TRIM_LH_L;
return TRIM_SW_LH_DEC;
else
return TRIM_LH_R;
return TRIM_SW_LH_INC;
}
else {
if (pos == 0)
return TRIM_LV_UP;
return TRIM_SW_LV_DEC;
else
return TRIM_LV_DN;
return TRIM_SW_LV_INC;
}
}
// right side
else {
if (type == 'H') {
if (pos == 0)
return TRIM_RH_L;
return TRIM_SW_RH_DEC;
else
return TRIM_RH_R;
return TRIM_SW_RH_INC;
}
else {
if (pos == 0)
return TRIM_RV_UP;
return TRIM_SW_RV_DEC;
else
return TRIM_RV_DN;
return TRIM_SW_RV_INC;
}
}
}
SliderWidget *VirtualJoystickWidget::getTrimSlider(int which)
RadioTrimWidget * VirtualJoystickWidget::getTrimWidget(int which)
{
if (which == TRIM_AXIS_L_X || which == TRIM_AXIS_R_X)
return hTrimSlider;
if (which == Board::TRIM_AXIS_LH || which == Board::TRIM_AXIS_RH)
return hTrimWidget;
else
return vTrimSlider;
}
void VirtualJoystickWidget::onTrimPressed()
{
if (!sender() || !sender()->property("btnType").isValid())
return;
emit trimButtonPressed(sender()->property("btnType").toInt());
}
void VirtualJoystickWidget::onSliderChange(int value)
{
if (!sender() || !sender()->property("trimType").isValid())
return;
emit trimSliderMoved(sender()->property("trimType").toInt(), value);
updateNodeValueLabels();
return vTrimWidget;
}
void VirtualJoystickWidget::onButtonChange(bool checked)
@ -523,3 +460,57 @@ void VirtualJoystickWidget::updateNodeValueLabels()
if (nodeLabelY)
nodeLabelY->setText(QString("%1").arg((qreal)node->getY() * -100 + getTrimValue(1) / 5, 2, 'f', 0));
}
void VirtualJoystickWidget::onGsMouseEvent(QGraphicsSceneMouseEvent * event)
{
if (!node)
return;
//qDebug() << event->type() << event->scenePos() << event->buttons() << event->isAccepted() << m_stickPressed;
if (event->type() == QEvent::GraphicsSceneMouseRelease && m_stickPressed) {
node->setPressed(false);
m_stickPressed = false;
return;
}
if (!(event->buttons() & Qt::LeftButton))
return;
if (event->type() == QEvent::GraphicsSceneMousePress) {
node->setPressed(true);
m_stickPressed = true;
}
else if (!m_stickPressed || event->type() != QEvent::GraphicsSceneMouseMove) {
return;
}
node->setPos(event->scenePos());
}
/*
* CustomGraphicsScene
*/
void CustomGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent * event)
{
QGraphicsScene::mousePressEvent(event);
if (!event->isAccepted()) {
event->accept();
emit mouseEvent(event);
}
}
void CustomGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
{
QGraphicsScene::mouseReleaseEvent(event);
emit mouseEvent(event);
}
void CustomGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
{
QGraphicsScene::mouseMoveEvent(event);
if (!event->isAccepted() && (event->buttons() & Qt::LeftButton)) {
event->accept();
emit mouseEvent(event);
}
}

View file

@ -27,24 +27,18 @@
#include <QGridLayout>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QPushButton>
#include <QToolButton>
#include <QLabel>
class CustomGraphicsScene;
class Node;
class SliderWidget;
class RadioTrimWidget;
class VirtualJoystickWidget : public QWidget
{
Q_OBJECT
public:
enum TrimAxes {
TRIM_AXIS_L_X = 0,
TRIM_AXIS_L_Y,
TRIM_AXIS_R_Y,
TRIM_AXIS_R_X,
};
enum ConstraintTypes {
HOLD_X = 0,
HOLD_Y,
@ -73,38 +67,60 @@ class VirtualJoystickWidget : public QWidget
virtual void resizeEvent(QResizeEvent *event);
signals:
void trimButtonPressed(int which);
void trimButtonReleased();
void trimSliderMoved(int which, int value);
void trimButtonPressed(int index);
void trimButtonReleased(int index);
void trimSliderMoved(int index, int value);
protected slots:
void onTrimPressed();
void onSliderChange(int value);
void onButtonChange(bool checked);
void updateNodeValueLabels();
void onGsMouseEvent(QGraphicsSceneMouseEvent * event);
protected:
void setSize(const QSize & size, const QSize &);
QWidget * createTrimWidget(QChar type);
QPushButton * createButtonWidget(int type);
RadioTrimWidget * createTrimWidget(QChar type);
QToolButton * createButtonWidget(int type);
QLayout * createNodeValueLayout(QChar type, QLabel *& valLabel);
int getTrimSliderType(QChar type);
int getTrimButtonType(QChar type, int pos);
SliderWidget * getTrimSlider(int which);
RadioTrimWidget * getTrimWidget(int which);
QChar stickSide;
QSize prefSize;
QGridLayout * layout;
QGraphicsView * gv;
QGraphicsScene * scene;
CustomGraphicsScene * scene;
Node * node;
SliderWidget * hTrimSlider, * vTrimSlider;
QPushButton * btnHoldX, * btnHoldY;
QPushButton * btnFixX, * btnFixY;
RadioTrimWidget * hTrimWidget;
RadioTrimWidget * vTrimWidget;
QToolButton * btnHoldX, * btnHoldY;
QToolButton * btnFixX, * btnFixY;
QLabel * nodeLabelX, * nodeLabelY;
QSize extraSize;
float ar; // aspect ratio
bool m_stickPressed;
};
/*
* Custom GraphicsScene for mouse handling
*/
class CustomGraphicsScene : public QGraphicsScene
{
Q_OBJECT
public:
CustomGraphicsScene(QObject *parent = Q_NULLPTR) :
QGraphicsScene(parent)
{}
signals:
void mouseEvent(QGraphicsSceneMouseEvent * event);
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent * event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
};
#endif // VIRTUALJOYSTICKWIDGET_H

View file

@ -134,7 +134,7 @@ void OpenTxSimulator::getTrims(Trims & trims)
{
uint8_t phase = getFlightMode();
trims.extended = hasExtendedTrims();
for (uint8_t idx=0; idx<4; idx++) {
for (uint8_t idx=0; idx < CPN_MAX_STICKS + CPN_MAX_AUX_TRIMS; idx++) {
trims.values[idx] = getTrimValue(getTrimFlightMode(phase, idx), idx);
}