Rev Author Line No. Line
178 kaklik 1 #include <QtGui/QMessageBox>
2 #include "mandoWindow.hh"
3 #include "mandoWizard.hh"
4 #include <X11/extensions/XTest.h>
5  
6 using namespace mimas;
7 using namespace std;
8  
9 MandoWindow::MandoWindow( QWidget *parent, Qt::WFlags f ):
10 QWidget( parent, f ), mandoWizard(NULL), timer(0)
11 {
12 ui.setupUi( this );
13 connect( ui.quitButton, SIGNAL(clicked()),
14 this, SLOT(close()) );
15 connect( ui.aboutButton, SIGNAL(clicked()),
16 this, SLOT(about()) );
17 connect( ui.configureButton, SIGNAL(clicked()),
18 this, SLOT(configure()) );
19 connect( ui.activateCheckBox, SIGNAL(toggled(bool)),
20 this, SLOT(activate(bool)) );
21 }
22  
23 void MandoWindow::about()
24 {
25 QMessageBox::about
26 ( this, "About mando",
27 "<p>Copyright &copy; 2006. <b>mando</b> is free software; you can "
28 "redistribute it and/or modify it under the terms of the <em>GNU "
29 "General Public License</em> as published by the Free Software "
30 "Foundation; either version 2 of the License, or (at your option) any "
31 "later version.</p>"
32 "<p><b>mando</b> is distributed in the hope that it will be useful, but "
33 "<em>without any warranty</em>; without even the implied warranty of "
34 "<em>merchantibility</em> or <em>fitness for a particular "
35 "purpose</em>. See the GNU General Public License for more details.</p>"
36 "<p>You should have received a copy of the GNU General Public License "
37 "along with <b>mando</b>; if not, contact one of the authors of this "
38 "software.</p>"
39 "<ul><li>Juan Roldan <a href=\"mailto:juan.roldanREMOVETHIS@gmail.com\">juan.roldanREMOVETHIS@gmail.com</a></li>"
40 "<li>Ushakiran Soutapalli <a href=\"mailto:ushakiron_sREMOVETHIS@yahoo.co.in\">ushakiron_sREMOVETHIS@yahoo.co.in</a></li>"
41 "<li>Julien Faucher <a href=\"faucherjREMOVETHIS@gmail.com\">faucherjREMOVETHIS@gmail.com</a></li>"
42 "<li>Jan Wedekind\n <a href=\"mailto:janREMOVETHIS@wedesoft.de\">janREMOVETHIS@wedesoft.de</a></li></ul>" );
43 }
44  
45 void MandoWindow::configure()
46 {
47 input.reset();
48 pointerRecognition.reset();
49 ui.activateCheckBox->setEnabled( false );
50 activate(false);
51 MandoWizard mandoWizard( this );
52 }
53  
54 void MandoWindow::activate( bool on )
55 {
56 if ( on ) {
57 if ( timer == 0 )
58 timer = startTimer( 0 );
59 } else
60 if ( timer != 0 ) {
61 killTimer( timer );
62 timer = 0;
63 };
64 }
65  
66 void MandoWindow::startDrag(void)
67 {
68 Display *display = XOpenDisplay(NULL);
69 XTestFakeButtonEvent( display, 1, True, 0 );
70 XCloseDisplay( display );
71 }
72  
73 void MandoWindow::stopDrag(void)
74 {
75 Display *display = XOpenDisplay(NULL);
76 XTestFakeButtonEvent( display, 1, False, 0 );
77 XCloseDisplay( display );
78 // ui.singleClickRadio->setChecked( true );
79 }
80  
81 void MandoWindow::click(void)
82 {
83 Display *display = XOpenDisplay(NULL);
84 XTestFakeButtonEvent( display, 1, True, 0 );
85 XTestFakeButtonEvent( display, 1, False, 250 );
86 XCloseDisplay( display );
87 }
88  
89 void MandoWindow::mouseMove( int x, int y )
90 {
91 Display *display = XOpenDisplay(NULL);
92 int screen = DefaultScreen( display );
93 XTestFakeMotionEvent( display, screen, x, y, 0 );
94 XCloseDisplay( display );
95 }
96  
97 void MandoWindow::timerEvent( QTimerEvent *e )
98 {
99 if ( e->timerId() == timer ) {
100 try {
101 assert( pointerRecognition );
102 Vector camPos( 3 ), pos( 3 );
103 image< rgba< unsigned char > > frame( grabColourFrame() );
104 } catch ( exception & ) {
105 assert( timer != 0 );
106 killTimer( timer );
107 ui.activateCheckBox->setChecked( false );
108 };
109 } else
110 QWidget::timerEvent( e );
111 }
112  
113 image< rgba< unsigned char > > MandoWindow::grabColourFrame(void)
114 throw (mimasexception)
115 {
116 assert( input );
117 image< rgba< unsigned char > > retVal;
118 (*input) >> retVal;
119 return retVal;
120 }
121