2022-10-22 19:55:08 +00:00
# include "controllersetup.h"
# include "ui_controllersetup.h"
2021-08-28 22:27:18 +00:00
# include "logcategories.h"
2022-10-22 19:55:08 +00:00
controllerSetup : : controllerSetup ( QWidget * parent ) :
2021-08-28 22:27:18 +00:00
QDialog ( parent ) ,
2022-10-22 19:55:08 +00:00
ui ( new Ui : : controllerSetup )
2021-08-28 22:27:18 +00:00
{
ui - > setupUi ( this ) ;
2023-03-17 23:35:40 +00:00
ui - > tabWidget - > clear ( ) ;
ui - > tabWidget - > hide ( ) ;
noControllersText = new QLabel ( " No USB controller found " ) ;
noControllersText - > setStyleSheet ( " QLabel { color : gray; } " ) ;
ui - > hboxLayout - > addWidget ( noControllersText ) ;
2022-10-16 23:29:11 +00:00
this - > resize ( this - > sizeHint ( ) ) ;
2021-08-28 22:27:18 +00:00
}
2022-10-22 19:55:08 +00:00
controllerSetup : : ~ controllerSetup ( )
2021-08-28 22:27:18 +00:00
{
2023-02-10 00:27:01 +00:00
if ( onEventProxy ! = Q_NULLPTR ) {
2023-03-17 23:35:40 +00:00
delete onEventProxy ;
2023-02-10 00:27:01 +00:00
delete onEvent ;
}
2023-03-17 23:35:40 +00:00
2023-02-10 00:27:01 +00:00
if ( offEventProxy ! = Q_NULLPTR ) {
2023-03-17 23:35:40 +00:00
delete offEventProxy ;
2023-02-10 00:27:01 +00:00
delete offEvent ;
2021-08-28 22:27:18 +00:00
}
2023-03-17 23:35:40 +00:00
2023-02-10 00:27:01 +00:00
if ( knobEventProxy ! = Q_NULLPTR ) {
2023-03-17 23:35:40 +00:00
delete knobEventProxy ;
2023-02-10 00:27:01 +00:00
delete knobEvent ;
}
2023-02-10 09:52:51 +00:00
2023-02-10 00:27:01 +00:00
delete ui ;
2021-08-28 22:27:18 +00:00
}
2023-03-17 23:35:40 +00:00
void controllerSetup : : mousePressed ( controllerScene * scene , QPoint p )
2022-04-22 10:11:21 +00:00
{
// Receive mouse event from the scene
qDebug ( ) < < " Looking for button Point x= " < < p . x ( ) < < " y= " < < p . y ( ) ;
2023-02-10 00:27:01 +00:00
if ( onEvent = = Q_NULLPTR | | offEvent = = Q_NULLPTR | | knobEvent = = Q_NULLPTR )
{
qInfo ( logUsbControl ( ) ) < < " Event missing, cannot continue... " ;
return ;
}
2022-04-22 10:11:21 +00:00
bool found = false ;
2023-02-10 15:23:57 +00:00
QMutexLocker locker ( mutex ) ;
2023-03-17 23:35:40 +00:00
2022-04-22 10:11:21 +00:00
for ( BUTTON & b : * buttons )
{
2023-03-17 23:35:40 +00:00
if ( ui - > tabWidget - > currentWidget ( ) - > objectName ( ) = = b . devicePath & & b . pos . contains ( p ) )
2022-04-22 10:11:21 +00:00
{
found = true ;
currentButton = & b ;
2022-05-12 23:11:34 +00:00
qDebug ( ) < < " Button " < < currentButton - > num < < " On Event " < < currentButton - > onCommand - > text < < " Off Event " < < currentButton - > offCommand - > text ;
2023-02-10 00:27:01 +00:00
onEvent - > blockSignals ( true ) ;
onEvent - > move ( p ) ;
onEvent - > setCurrentIndex ( onEvent - > findData ( currentButton - > onCommand - > index ) ) ;
onEvent - > show ( ) ;
onEvent - > blockSignals ( false ) ;
2022-04-22 10:11:21 +00:00
p . setY ( p . y ( ) + 40 ) ;
2023-02-10 00:27:01 +00:00
offEvent - > blockSignals ( true ) ;
offEvent - > move ( p ) ;
offEvent - > setCurrentIndex ( offEvent - > findData ( currentButton - > offCommand - > index ) ) ;
offEvent - > show ( ) ;
offEvent - > blockSignals ( false ) ;
knobEvent - > hide ( ) ;
2023-02-09 13:21:51 +00:00
break ;
}
}
2023-02-10 00:27:01 +00:00
2023-02-09 13:21:51 +00:00
if ( ! found ) {
for ( KNOB & k : * knobs )
{
2023-03-17 23:35:40 +00:00
if ( ui - > tabWidget - > currentWidget ( ) - > objectName ( ) = = k . devicePath & & k . pos . contains ( p ) )
2023-02-09 13:21:51 +00:00
{
found = true ;
currentKnob = & k ;
qDebug ( ) < < " Knob " < < currentKnob - > num < < " Event " < < currentKnob - > command - > text ;
2023-02-10 00:27:01 +00:00
knobEvent - > blockSignals ( true ) ;
knobEvent - > move ( p ) ;
knobEvent - > setCurrentIndex ( knobEvent - > findData ( currentKnob - > command - > index ) ) ;
knobEvent - > show ( ) ;
knobEvent - > blockSignals ( false ) ;
onEvent - > hide ( ) ;
offEvent - > hide ( ) ;
2023-02-09 13:21:51 +00:00
break ;
}
2022-04-22 10:11:21 +00:00
}
}
2023-03-17 23:35:40 +00:00
if ( found )
{
found = false ;
foreach ( QGraphicsItem * item , scene - > items ( ) )
{
QGraphicsProxyWidget * node = dynamic_cast < QGraphicsProxyWidget * > ( item ) ;
if ( node ) {
found = true ;
break ;
}
}
if ( ! found ) {
scene - > addItem ( offEvent - > graphicsProxyWidget ( ) ) ;
scene - > addItem ( onEvent - > graphicsProxyWidget ( ) ) ;
scene - > addItem ( knobEvent - > graphicsProxyWidget ( ) ) ;
}
}
else
{
2023-02-10 00:27:01 +00:00
onEvent - > hide ( ) ;
offEvent - > hide ( ) ;
knobEvent - > hide ( ) ;
2022-04-22 10:11:21 +00:00
}
}
2022-10-22 19:55:08 +00:00
void controllerSetup : : onEventIndexChanged ( int index ) {
2023-02-09 13:21:51 +00:00
Q_UNUSED ( index ) ;
2023-02-10 15:23:57 +00:00
2023-02-10 00:27:01 +00:00
if ( currentButton ! = Q_NULLPTR & & onEvent - > currentData ( ) . toInt ( ) < commands - > size ( ) ) {
2023-02-10 15:23:57 +00:00
QMutexLocker locker ( mutex ) ;
2023-02-10 00:27:01 +00:00
currentButton - > onCommand = & commands - > at ( onEvent - > currentData ( ) . toInt ( ) ) ;
2022-04-27 11:56:54 +00:00
currentButton - > onText - > setPlainText ( currentButton - > onCommand - > text ) ;
2023-02-12 16:45:21 +00:00
currentButton - > onText - > setPos ( currentButton - > pos . center ( ) . x ( ) - currentButton - > onText - > boundingRect ( ) . width ( ) / 2 ,
( currentButton - > pos . center ( ) . y ( ) - currentButton - > onText - > boundingRect ( ) . height ( ) / 2 ) - 6 ) ;
// Signal that any button programming on the device should be completed.
2023-03-17 23:35:40 +00:00
emit programButton ( currentButton - > devicePath , currentButton - > num , currentButton - > onCommand - > text ) ;
2022-04-22 10:11:21 +00:00
}
}
2022-10-22 19:55:08 +00:00
void controllerSetup : : offEventIndexChanged ( int index ) {
2023-02-09 13:21:51 +00:00
Q_UNUSED ( index ) ;
2023-02-10 00:27:01 +00:00
if ( currentButton ! = Q_NULLPTR & & offEvent - > currentData ( ) . toInt ( ) < commands - > size ( ) ) {
2023-02-10 15:23:57 +00:00
QMutexLocker locker ( mutex ) ;
2023-02-10 00:27:01 +00:00
currentButton - > offCommand = & commands - > at ( offEvent - > currentData ( ) . toInt ( ) ) ;
2022-04-27 11:56:54 +00:00
currentButton - > offText - > setPlainText ( currentButton - > offCommand - > text ) ;
2023-02-12 16:45:21 +00:00
currentButton - > offText - > setPos ( currentButton - > pos . center ( ) . x ( ) - currentButton - > offText - > boundingRect ( ) . width ( ) / 2 ,
( currentButton - > pos . center ( ) . y ( ) - currentButton - > offText - > boundingRect ( ) . height ( ) / 2 ) + 6 ) ;
2022-04-22 10:11:21 +00:00
}
}
2023-02-09 13:21:51 +00:00
void controllerSetup : : knobEventIndexChanged ( int index ) {
Q_UNUSED ( index ) ;
2023-02-10 00:27:01 +00:00
if ( currentKnob ! = Q_NULLPTR & & knobEvent - > currentData ( ) . toInt ( ) < commands - > size ( ) ) {
2023-02-10 15:23:57 +00:00
QMutexLocker locker ( mutex ) ;
2023-02-10 00:27:01 +00:00
currentKnob - > command = & commands - > at ( knobEvent - > currentData ( ) . toInt ( ) ) ;
2023-02-09 13:21:51 +00:00
currentKnob - > text - > setPlainText ( currentKnob - > command - > text ) ;
2023-02-12 16:45:21 +00:00
currentKnob - > text - > setPos ( currentKnob - > pos . center ( ) . x ( ) - currentKnob - > text - > boundingRect ( ) . width ( ) / 2 ,
( currentKnob - > pos . center ( ) . y ( ) - currentKnob - > text - > boundingRect ( ) . height ( ) / 2 ) ) ;
2023-02-09 13:21:51 +00:00
}
}
2023-03-17 23:35:40 +00:00
void controllerSetup : : removeDevice ( USBDEVICE * dev )
{
QMutexLocker locker ( mutex ) ;
int remove = - 1 ;
for ( int i = 0 ; i < ui - > tabWidget - > count ( ) ; i + + ) {
auto widget = ui - > tabWidget - > widget ( i ) ;
if ( widget - > objectName ( ) = = dev - > path ) {
qDeleteAll ( widget - > findChildren < QWidget * > ( " " , Qt : : FindDirectChildrenOnly ) ) ;
remove = i ;
}
}
2022-04-22 10:11:21 +00:00
2023-03-17 23:35:40 +00:00
if ( remove ! = - 1 ) {
qInfo ( logUsbControl ( ) ) < < " Removing tab " < < dev - > product ;
ui - > tabWidget - > removeTab ( remove ) ;
}
if ( ui - > tabWidget - > count ( ) = = 0 )
{
ui - > tabWidget - > hide ( ) ;
noControllersText - > show ( ) ;
this - > adjustSize ( ) ;
}
}
void controllerSetup : : newDevice ( USBDEVICE * dev , CONTROLLER * cntrl , QVector < BUTTON > * but , QVector < KNOB > * kb , QVector < COMMAND > * cmd , QMutex * mut )
2021-08-28 22:27:18 +00:00
{
2022-04-22 10:11:21 +00:00
buttons = but ;
2023-02-09 13:21:51 +00:00
knobs = kb ;
2022-04-25 16:40:41 +00:00
commands = cmd ;
2023-02-10 15:23:57 +00:00
mutex = mut ;
2023-02-11 11:39:18 +00:00
QMutexLocker locker ( mutex ) ;
2022-10-16 23:29:11 +00:00
2023-03-20 15:32:04 +00:00
qDebug ( logUsbControl ( ) ) < < " Adding new tab for " < < dev - > product ;
2023-03-17 23:35:40 +00:00
noControllersText - > hide ( ) ;
2023-03-20 15:32:04 +00:00
2023-03-17 23:35:40 +00:00
QWidget * tab = new QWidget ( ) ;
tab - > setObjectName ( dev - > path ) ;
2023-03-20 15:32:04 +00:00
ui - > tabWidget - > addTab ( tab , dev - > product ) ;
ui - > tabWidget - > show ( ) ;
2023-03-18 16:38:24 +00:00
QVBoxLayout * mainlayout = new QVBoxLayout ( ) ;
mainlayout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
tab - > setLayout ( mainlayout ) ;
2023-03-20 15:32:04 +00:00
2023-03-18 16:38:24 +00:00
QHBoxLayout * toplayout = new QHBoxLayout ( ) ;
mainlayout - > addLayout ( toplayout ) ;
toplayout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
QWidget * widget = new QWidget ( ) ;
mainlayout - > addWidget ( widget ) ;
2023-03-17 23:35:40 +00:00
QVBoxLayout * layout = new QVBoxLayout ( widget ) ;
layout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
2023-03-18 16:38:24 +00:00
QCheckBox * disabled = new QCheckBox ( ) ;
disabled - > setText ( " Disable " ) ;
toplayout - > addWidget ( disabled ) ;
2023-03-20 15:32:04 +00:00
dev - > message = new QLabel ( ) ;
2023-03-18 16:38:24 +00:00
if ( dev - > connected ) {
2023-03-20 15:32:04 +00:00
dev - > message - > setStyleSheet ( " QLabel { color : green; } " ) ;
dev - > message - > setText ( " Connected " ) ;
2023-03-18 16:38:24 +00:00
} else {
2023-03-20 15:32:04 +00:00
dev - > message - > setStyleSheet ( " QLabel { color : red; } " ) ;
dev - > message - > setText ( " Not Connected " ) ;
2023-03-18 16:38:24 +00:00
}
2023-03-20 15:32:04 +00:00
toplayout - > addWidget ( dev - > message ) ;
dev - > message - > setAlignment ( Qt : : AlignRight ) ;
2023-03-18 16:38:24 +00:00
connect ( disabled , qOverload < bool > ( & QCheckBox : : clicked ) ,
2023-03-20 15:32:04 +00:00
[ dev , this , widget ] ( bool checked ) { this - > disableClicked ( dev - > path , checked , widget ) ; } ) ;
2023-03-18 16:38:24 +00:00
disabled - > setChecked ( dev - > disabled ) ;
QGraphicsView * view = new QGraphicsView ( ) ;
2023-03-17 23:35:40 +00:00
layout - > addWidget ( view ) ;
2023-03-18 16:38:24 +00:00
QHBoxLayout * senslayout = new QHBoxLayout ( ) ;
2023-03-17 23:35:40 +00:00
layout - > addLayout ( senslayout ) ;
QLabel * senslabel = new QLabel ( " Sensitivity " ) ;
senslayout - > addWidget ( senslabel ) ;
2023-03-18 16:38:24 +00:00
QSlider * sens = new QSlider ( ) ;
2023-03-17 23:35:40 +00:00
sens - > setMinimum ( 1 ) ;
sens - > setMaximum ( 21 ) ;
sens - > setOrientation ( Qt : : Horizontal ) ;
sens - > setInvertedAppearance ( true ) ;
senslayout - > addWidget ( sens ) ;
sens - > setValue ( cntrl - > sensitivity ) ;
connect ( sens , & QSlider : : valueChanged ,
[ dev , this ] ( int val ) { this - > sensitivityMoved ( dev - > path , val ) ; } ) ;
2023-03-18 16:38:24 +00:00
QImage image ;
switch ( dev - > usbDevice ) {
case shuttleXpress :
image . load ( " :/resources/shuttlexpress.png " ) ;
break ;
case shuttlePro2 :
image . load ( " :/resources/shuttlepro.png " ) ;
break ;
case RC28 :
image . load ( " :/resources/rc28.png " ) ;
break ;
case xBoxGamepad :
image . load ( " :/resources/xbox.png " ) ;
break ;
case eCoderPlus :
image . load ( " :/resources/ecoder.png " ) ;
break ;
case QuickKeys :
image . load ( " :/resources/quickkeys.png " ) ;
break ;
default :
//ui->graphicsView->setSceneRect(scene->itemsBoundingRect());
this - > adjustSize ( ) ;
break ;
}
QGraphicsItem * bgImage = new QGraphicsPixmapItem ( QPixmap : : fromImage ( image ) ) ;
view - > setMinimumSize ( bgImage - > boundingRect ( ) . width ( ) + 2 , bgImage - > boundingRect ( ) . height ( ) + 2 ) ;
2023-03-20 15:32:04 +00:00
// This command causes the window to disappear in Linux?
# if !defined(Q_OS_LINUX)
2023-03-18 16:38:24 +00:00
this - > setMinimumSize ( bgImage - > boundingRect ( ) . width ( ) + 370 , bgImage - > boundingRect ( ) . height ( ) + 250 ) ;
2023-03-20 15:32:04 +00:00
# endif
2023-03-18 16:38:24 +00:00
controllerScene * scene = new controllerScene ( ) ;
view - > setScene ( scene ) ;
connect ( scene , SIGNAL ( mousePressed ( controllerScene * , QPoint ) ) , this , SLOT ( mousePressed ( controllerScene * , QPoint ) ) ) ;
scene - > addItem ( bgImage ) ;
QGridLayout * grid = new QGridLayout ( ) ;
layout - > addLayout ( grid ) ;
2023-03-17 23:35:40 +00:00
if ( dev - > usbDevice = = QuickKeys )
2022-10-16 23:29:11 +00:00
{
2023-03-17 23:35:40 +00:00
// Add QuickKeys section
QLabel * brightlabel = new QLabel ( " Brightness " ) ;
grid - > addWidget ( brightlabel , 0 , 0 ) ;
2023-03-18 16:38:24 +00:00
QComboBox * brightness = new QComboBox ( ) ;
2023-03-17 23:35:40 +00:00
brightness - > addItem ( " Off " ) ;
brightness - > addItem ( " Low " ) ;
brightness - > addItem ( " Medium " ) ;
brightness - > addItem ( " High " ) ;
brightness - > setCurrentIndex ( cntrl - > brightness ) ;
grid - > addWidget ( brightness , 1 , 0 ) ;
connect ( brightness , qOverload < int > ( & QComboBox : : currentIndexChanged ) ,
[ dev , this ] ( int index ) { this - > brightnessChanged ( dev - > path , index ) ; } ) ;
QLabel * speedlabel = new QLabel ( " Speed " ) ;
grid - > addWidget ( speedlabel , 0 , 1 ) ;
2023-03-18 16:38:24 +00:00
QComboBox * speed = new QComboBox ( ) ;
2023-03-17 23:35:40 +00:00
speed - > addItem ( " Fastest " ) ;
speed - > addItem ( " Faster " ) ;
speed - > addItem ( " Normal " ) ;
speed - > addItem ( " Slower " ) ;
speed - > addItem ( " Slowest " ) ;
speed - > setCurrentIndex ( cntrl - > speed ) ;
grid - > addWidget ( speed , 1 , 1 ) ;
connect ( speed , qOverload < int > ( & QComboBox : : currentIndexChanged ) ,
[ dev , this ] ( int index ) { this - > speedChanged ( dev - > path , index ) ; } ) ;
QLabel * orientlabel = new QLabel ( " Orientation " ) ;
grid - > addWidget ( orientlabel , 0 , 2 ) ;
2023-03-18 16:38:24 +00:00
QComboBox * orientation = new QComboBox ( ) ;
2023-03-17 23:35:40 +00:00
orientation - > addItem ( " Rotate 0 " ) ;
orientation - > addItem ( " Rotate 90 " ) ;
orientation - > addItem ( " Rotate 180 " ) ;
orientation - > addItem ( " Rotate 270 " ) ;
orientation - > setCurrentIndex ( cntrl - > orientation ) ;
grid - > addWidget ( orientation , 1 , 2 ) ;
connect ( orientation , qOverload < int > ( & QComboBox : : currentIndexChanged ) ,
[ dev , this ] ( int index ) { this - > orientationChanged ( dev - > path , index ) ; } ) ;
QLabel * colorlabel = new QLabel ( " Dial Color " ) ;
grid - > addWidget ( colorlabel , 0 , 3 ) ;
QPushButton * color = new QPushButton ( " Select " ) ;
grid - > addWidget ( color , 1 , 3 ) ;
connect ( color , & QPushButton : : clicked ,
[ dev , this ] ( ) { this - > colorPicker ( dev - > path ) ; } ) ;
QLabel * timeoutlabel = new QLabel ( " Timeout " ) ;
grid - > addWidget ( timeoutlabel , 0 , 4 ) ;
2023-03-18 16:38:24 +00:00
QSpinBox * timeout = new QSpinBox ( ) ;
2023-03-17 23:35:40 +00:00
timeout - > setValue ( cntrl - > timeout ) ;
grid - > addWidget ( timeout , 1 , 4 ) ;
connect ( timeout , qOverload < int > ( & QSpinBox : : valueChanged ) ,
[ dev , this ] ( int index ) { this - > timeoutChanged ( dev - > path , index ) ; } ) ;
// Finally update the device with the default values
emit programSensitivity ( dev - > path , cntrl - > sensitivity ) ;
emit programBrightness ( dev - > path , cntrl - > brightness ) ;
emit programOrientation ( dev - > path , cntrl - > orientation ) ;
emit programSpeed ( dev - > path , cntrl - > speed ) ;
emit programTimeout ( dev - > path , cntrl - > timeout ) ;
emit programWheelColour ( dev - > path , cntrl - > color . red ( ) , cntrl - > color . green ( ) , cntrl - > color . blue ( ) ) ;
2022-10-16 23:29:11 +00:00
}
2023-03-18 16:38:24 +00:00
QLabel * helpText = new QLabel ( ) ;
2023-03-17 23:35:40 +00:00
helpText - > setText ( " <p><b>Button configuration:</b> Right-click on each button to configure it.</p><p>Top selection is command to send when button is pressed and bottom is (optional) command to send when button is released.</p> " ) ;
helpText - > setAlignment ( Qt : : AlignCenter ) ;
layout - > addWidget ( helpText ) ;
2023-02-10 00:27:01 +00:00
2023-03-17 23:35:40 +00:00
if ( dev - > usbDevice ! = usbNone )
2023-02-12 16:45:21 +00:00
{
offEvent = new QComboBox ;
onEvent = new QComboBox ;
knobEvent = new QComboBox ;
onEvent - > blockSignals ( true ) ;
offEvent - > blockSignals ( true ) ;
knobEvent - > blockSignals ( true ) ;
onEvent - > clear ( ) ;
offEvent - > clear ( ) ;
knobEvent - > clear ( ) ;
onEvent - > setMaxVisibleItems ( 5 ) ;
offEvent - > setMaxVisibleItems ( 5 ) ;
knobEvent - > setMaxVisibleItems ( 5 ) ;
onEvent - > view ( ) - > setVerticalScrollBarPolicy ( Qt : : ScrollBarAlwaysOn ) ;
offEvent - > view ( ) - > setVerticalScrollBarPolicy ( Qt : : ScrollBarAlwaysOn ) ;
knobEvent - > view ( ) - > setVerticalScrollBarPolicy ( Qt : : ScrollBarAlwaysOn ) ;
onEvent - > setStyleSheet ( " combobox-popup: 0; " ) ;
offEvent - > setStyleSheet ( " combobox-popup: 0; " ) ;
knobEvent - > setStyleSheet ( " combobox-popup: 0; " ) ;
for ( COMMAND & c : * commands ) {
if ( c . cmdType = = commandButton | | c . text = = " None " ) {
onEvent - > addItem ( c . text , c . index ) ;
offEvent - > addItem ( c . text , c . index ) ;
}
2023-02-09 13:21:51 +00:00
2023-02-12 16:45:21 +00:00
if ( c . cmdType = = commandKnob | | c . text = = " None " ) {
knobEvent - > addItem ( c . text , c . index ) ;
}
2023-02-09 13:21:51 +00:00
}
2023-02-12 16:45:21 +00:00
onEvent - > blockSignals ( false ) ;
offEvent - > blockSignals ( false ) ;
knobEvent - > blockSignals ( false ) ;
2023-02-10 00:27:01 +00:00
2023-02-12 16:45:21 +00:00
onEvent - > hide ( ) ;
offEvent - > hide ( ) ;
knobEvent - > hide ( ) ;
2022-04-25 16:40:41 +00:00
2023-02-12 16:45:21 +00:00
// Set button text
for ( BUTTON & b : * buttons )
{
2022-10-16 23:29:11 +00:00
2023-03-17 23:35:40 +00:00
if ( b . devicePath = = dev - > path ) {
2023-02-12 16:45:21 +00:00
b . onText = new QGraphicsTextItem ( b . onCommand - > text ) ;
b . onText - > setDefaultTextColor ( b . textColour ) ;
scene - > addItem ( b . onText ) ;
b . onText - > setPos ( b . pos . center ( ) . x ( ) - b . onText - > boundingRect ( ) . width ( ) / 2 ,
( b . pos . center ( ) . y ( ) - b . onText - > boundingRect ( ) . height ( ) / 2 ) - 6 ) ;
2023-03-17 23:35:40 +00:00
emit programButton ( b . devicePath , b . num , b . onCommand - > text ) ; // Program the button with ontext if supported
2023-02-12 16:45:21 +00:00
b . offText = new QGraphicsTextItem ( b . offCommand - > text ) ;
b . offText - > setDefaultTextColor ( b . textColour ) ;
scene - > addItem ( b . offText ) ;
b . offText - > setPos ( b . pos . center ( ) . x ( ) - b . offText - > boundingRect ( ) . width ( ) / 2 ,
( b . pos . center ( ) . y ( ) - b . onText - > boundingRect ( ) . height ( ) / 2 ) + 6 ) ;
}
2022-09-18 20:00:44 +00:00
}
2022-10-16 23:29:11 +00:00
2023-02-12 16:45:21 +00:00
// Set knob text
2023-02-09 13:21:51 +00:00
2023-02-12 16:45:21 +00:00
for ( KNOB & k : * knobs )
{
2023-03-17 23:35:40 +00:00
if ( k . devicePath = = dev - > path ) {
2023-02-12 16:45:21 +00:00
k . text = new QGraphicsTextItem ( k . command - > text ) ;
k . text - > setDefaultTextColor ( k . textColour ) ;
scene - > addItem ( k . text ) ;
k . text - > setPos ( k . pos . center ( ) . x ( ) - k . text - > boundingRect ( ) . width ( ) / 2 ,
( k . pos . center ( ) . y ( ) - k . text - > boundingRect ( ) . height ( ) / 2 ) ) ;
}
}
2023-03-17 23:35:40 +00:00
view - > setSceneRect ( scene - > itemsBoundingRect ( ) ) ;
2023-02-12 16:45:21 +00:00
// Add comboboxes to scene after everything else.
connect ( offEvent , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( offEventIndexChanged ( int ) ) ) ;
connect ( onEvent , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( onEventIndexChanged ( int ) ) ) ;
connect ( knobEvent , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( knobEventIndexChanged ( int ) ) ) ;
2023-03-17 23:35:40 +00:00
onEventProxy = new QGraphicsProxyWidget ( ) ;
onEventProxy - > setWidget ( onEvent ) ;
offEventProxy = new QGraphicsProxyWidget ( ) ;
offEventProxy - > setWidget ( offEvent ) ;
knobEventProxy = new QGraphicsProxyWidget ( ) ;
knobEventProxy - > setWidget ( knobEvent ) ;
this - > adjustSize ( ) ;
2023-03-18 16:38:24 +00:00
2023-02-09 13:21:51 +00:00
}
2023-03-17 23:35:40 +00:00
numTabs + + ;
2023-02-07 09:32:33 +00:00
}
2022-10-16 23:29:11 +00:00
2023-03-17 23:35:40 +00:00
void controllerSetup : : sensitivityMoved ( QString path , int val )
2023-02-07 09:32:33 +00:00
{
2023-03-17 23:35:40 +00:00
qInfo ( logUsbControl ( ) ) < < " Setting sensitivity " < < val < < " for device " < < path ;
emit programSensitivity ( path , val ) ;
2023-02-07 18:41:02 +00:00
}
2023-02-12 16:45:21 +00:00
2023-03-17 23:35:40 +00:00
void controllerSetup : : brightnessChanged ( QString path , int index )
2023-02-12 16:45:21 +00:00
{
2023-03-17 23:35:40 +00:00
emit programBrightness ( path , ( quint8 ) index ) ;
2023-02-12 16:45:21 +00:00
}
2023-03-17 23:35:40 +00:00
void controllerSetup : : orientationChanged ( QString path , int index )
2023-02-12 16:45:21 +00:00
{
2023-03-17 23:35:40 +00:00
emit programOrientation ( path , ( quint8 ) index ) ;
2023-02-12 16:45:21 +00:00
}
2023-03-17 23:35:40 +00:00
void controllerSetup : : speedChanged ( QString path , int index )
2023-02-12 16:45:21 +00:00
{
2023-03-17 23:35:40 +00:00
emit programSpeed ( path , ( quint8 ) index ) ;
2023-02-12 16:45:21 +00:00
}
2023-03-17 23:35:40 +00:00
void controllerSetup : : colorPicker ( QString path )
2023-02-12 16:45:21 +00:00
{
QColorDialog : : ColorDialogOptions options ;
options . setFlag ( QColorDialog : : ShowAlphaChannel , false ) ;
options . setFlag ( QColorDialog : : DontUseNativeDialog , false ) ;
QColor selColor = QColorDialog : : getColor ( initialColor , this , " Select Color " , options ) ;
if ( ! selColor . isValid ( ) )
{
selColor = initialColor ;
}
initialColor = selColor ;
2023-03-17 23:35:40 +00:00
emit programWheelColour ( path , ( quint8 ) selColor . red ( ) , ( quint8 ) selColor . green ( ) , ( quint8 ) initialColor . blue ( ) ) ;
2023-02-12 16:45:21 +00:00
}
2023-03-17 23:35:40 +00:00
void controllerSetup : : timeoutChanged ( QString path , int val )
2023-02-12 16:45:21 +00:00
{
2023-03-17 23:35:40 +00:00
emit programTimeout ( path , ( quint8 ) val ) ;
emit programOverlay ( path , 3 , QString ( " Sleep timeout set to %0 minutes " ) . arg ( val ) ) ;
2023-02-12 16:45:21 +00:00
}
2023-03-20 15:32:04 +00:00
void controllerSetup : : disableClicked ( QString path , bool clicked , QWidget * widget )
2023-03-18 16:38:24 +00:00
{
// Disable checkbox has been clicked
emit programDisable ( path , clicked ) ;
widget - > setEnabled ( ! clicked ) ;
}