Rework BtConnector: add properties for buttons. Partially move code to *.cpp file.
[qzeecontrol] / btconnector.h
1 /*
2  *  Copyright 2012 Ruediger Gad
3  *
4  *  This file is part of QZeeControl.
5  *
6  *  QZeeControl 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 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  QZeeControl 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 QZeeControl.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef BTCONNECTOR_H
21 #define BTCONNECTOR_H
22
23 #include <QObject>
24 #include <QtConnectivity/QBluetoothAddress>
25 #include <QtConnectivity/QBluetoothSocket>
26
27 QTM_USE_NAMESPACE
28 class BtConnector : public QObject
29 {
30     Q_OBJECT
31
32     Q_PROPERTY(bool a READ a NOTIFY aChanged)
33     Q_PROPERTY(bool b READ b NOTIFY bChanged)
34     Q_PROPERTY(bool c READ c NOTIFY cChanged)
35     Q_PROPERTY(bool d READ d NOTIFY dChanged)
36
37     Q_PROPERTY(int x READ x NOTIFY xChanged)
38     Q_PROPERTY(int y READ y NOTIFY yChanged)
39 public:
40     explicit BtConnector(QObject *parent = 0);
41
42     ~BtConnector(){
43         if(socket)
44             delete socket;
45     }
46
47     Q_INVOKABLE void connect(QString address, int port);
48
49     bool a(){return _a;}
50     bool b(){return _b;}
51     bool c(){return _c;}
52     bool d(){return _d;}
53
54     int x(){return _x;}
55     int y(){return _y;}
56
57 public slots:
58     void disconnect(){
59         if(!socket)
60             return;
61
62         if(socket->isOpen())
63             socket->close();
64
65         delete socket;
66         socket = 0;
67     }
68
69 signals:
70     void connected();
71     void disconnected();
72     void error(QBluetoothSocket::SocketError errorCode);
73
74     void stickMoved(int x, int y);
75     void buttonsChanged(bool a, bool b, bool c, bool d);
76
77     void aChanged(bool val);
78     void bChanged(bool val);
79     void cChanged(bool val);
80     void dChanged(bool val);
81
82     void xChanged(int val);
83     void yChanged(int val);
84
85 private slots:
86     void readData();
87
88 private:
89     QBluetoothSocket *socket;
90
91     bool _a;
92     bool _b;
93     bool _c;
94     bool _d;
95
96     int _x;
97     int _y;
98     char oldButtonMap;
99 };
100
101 #endif // BTCONNECTOR_H