1 /*	Copyright 2008 Filipe Azevedo <pasnox@gmail.com>
2 	Copyright 2013 Theo Berkau <cwx@cyberwarriorx.com>
3 
4         This file is part of Yabause.
5 
6         Yabause is free software; you can redistribute it and/or modify
7         it under the terms of the GNU General Public License as published by
8         the Free Software Foundation; either version 2 of the License, or
9         (at your option) any later version.
10 
11         Yabause is distributed in the hope that it will be useful,
12         but WITHOUT ANY WARRANTY; without even the implied warranty of
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14         GNU General Public License for more details.
15 
16         You should have received a copy of the GNU General Public License
17         along with Yabause; if not, write to the Free Software
18         Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
19 */
20 #include "UITwinStickSetting.h"
21 #include "UIPortManager.h"
22 #include "../Settings.h"
23 
24 #include <QKeyEvent>
25 #include <QTimer>
26 #include <QStylePainter>
27 #include <QStyleOptionToolButton>
28 
29 // Make a parent class for all controller setting classes
30 
31 
UITwinStickSetting(PerInterface_struct * core,uint port,uint pad,uint perType,QWidget * parent)32 UITwinStickSetting::UITwinStickSetting( PerInterface_struct* core, uint port, uint pad, uint perType, QWidget* parent )
33 	: UIControllerSetting( core, port, pad, perType, parent )
34 {
35    setupUi( this );
36    setInfos(lInfos);
37 
38 	mButtons[ tbLeftStickUp ] = PERPAD_UP;
39 	mButtons[ tbLeftStickRight ] = PERPAD_RIGHT;
40 	mButtons[ tbLeftStickDown ] = PERPAD_DOWN;
41 	mButtons[ tbLeftStickLeft ] = PERPAD_LEFT;
42 	mButtons[ tbLeftButton ] = PERPAD_RIGHT_TRIGGER;
43 	mButtons[ tbLeftTrigger ] = PERPAD_LEFT_TRIGGER;
44 	mButtons[ tbStart ] = PERPAD_START;
45 	mButtons[ tbRightTrigger ] = PERPAD_A;
46 	mButtons[ tbRightStickDown ] = PERPAD_B;
47 	mButtons[ tbRightButton ] = PERPAD_C;
48 	mButtons[ tbRightStickLeft ] = PERPAD_X;
49 	mButtons[ tbRightStickUp ] = PERPAD_Y;
50 	mButtons[ tbRightStickRight ] = PERPAD_Z;
51 
52 	mNames[ PERPAD_UP ] = QtYabause::translate( "Left Stick Up" );
53 	mNames[ PERPAD_RIGHT ] = QtYabause::translate( "Left Stick Right" );
54 	mNames[ PERPAD_DOWN ] = QtYabause::translate( "Left Stick Down" );
55 	mNames[ PERPAD_LEFT ] = QtYabause::translate( "Left Stick Left" );
56 	mNames[ PERPAD_RIGHT_TRIGGER ] = QtYabause::translate( "Left Button" );
57 	mNames[ PERPAD_LEFT_TRIGGER ] = QtYabause::translate( "Left Trigger" );
58 	mNames[ PERPAD_START ] = "Start";
59 	mNames[ PERPAD_A ] = "Right Trigger";
60 	mNames[ PERPAD_B ] = "Right Stick Down";
61 	mNames[ PERPAD_C ] = "Right Button";
62 	mNames[ PERPAD_X ] = "Right Stick Left";
63 	mNames[ PERPAD_Y ] = "Right Stick Up";
64 	mNames[ PERPAD_Z ] = "Right Stick Right";
65 
66    //PERSF_AXIS so LT and RT can be used as normal buttons
67    mScanMasks[ PERPAD_UP ] = PERSF_KEY | PERSF_BUTTON | PERSF_HAT | PERSF_AXIS;
68    mScanMasks[ PERPAD_RIGHT ] = PERSF_KEY | PERSF_BUTTON | PERSF_HAT | PERSF_AXIS;
69    mScanMasks[ PERPAD_DOWN ] = PERSF_KEY | PERSF_BUTTON | PERSF_HAT | PERSF_AXIS;
70    mScanMasks[ PERPAD_LEFT ] = PERSF_KEY | PERSF_BUTTON | PERSF_HAT | PERSF_AXIS;
71    mScanMasks[ PERPAD_RIGHT_TRIGGER ] = PERSF_KEY | PERSF_BUTTON | PERSF_HAT | PERSF_AXIS;
72    mScanMasks[ PERPAD_LEFT_TRIGGER ] = PERSF_KEY | PERSF_BUTTON | PERSF_HAT | PERSF_AXIS;
73    mScanMasks[ PERPAD_START ] = PERSF_KEY | PERSF_BUTTON | PERSF_HAT | PERSF_AXIS;
74    mScanMasks[ PERPAD_A ] = PERSF_KEY | PERSF_BUTTON | PERSF_HAT | PERSF_AXIS;
75    mScanMasks[ PERPAD_B ] = PERSF_KEY | PERSF_BUTTON | PERSF_HAT | PERSF_AXIS;
76    mScanMasks[ PERPAD_C ] = PERSF_KEY | PERSF_BUTTON | PERSF_HAT | PERSF_AXIS;
77    mScanMasks[ PERPAD_X ] = PERSF_KEY | PERSF_BUTTON | PERSF_HAT | PERSF_AXIS;
78    mScanMasks[ PERPAD_Y ] = PERSF_KEY | PERSF_BUTTON | PERSF_HAT | PERSF_AXIS;
79    mScanMasks[ PERPAD_Z ] = PERSF_KEY | PERSF_BUTTON | PERSF_HAT | PERSF_AXIS;
80 
81 	loadPadSettings();
82 
83 	foreach ( QToolButton* tb, findChildren<QToolButton*>() )
84 	{
85 		tb->installEventFilter( this );
86 		connect( tb, SIGNAL( clicked() ), this, SLOT( tbButton_clicked() ) );
87 	}
88 
89 	connect( mTimer, SIGNAL( timeout() ), this, SLOT( timer_timeout() ) );
90 
91 	QtYabause::retranslateWidget( this );
92 }
93 
~UITwinStickSetting()94 UITwinStickSetting::~UITwinStickSetting()
95 {
96 }
97