-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaemoUI.cpp
executable file
·261 lines (226 loc) · 8.31 KB
/
MaemoUI.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#include "MaemoUI.h"
//#include "FeaturesWizard.h"
#include "Viewfinder.h"
#include <QFileDialog>
#include <QWidget>
#include <QMessageBox>
#include <QStatusBar>
#include <QHBoxLayout>
#include <QComboBox>
#include <QVBoxLayout>
#include <QPushButton>
#include <QDialog>
#include <sstream>
#include <iostream>
#include "N900Helpers.h"
#include "ObjDetect.h"
#include "mce/mode-names.h"
#include "mce/dbus-names.h"
#include <QtDBus>
// Create and initialize the Maemo.
MaemoUI::MaemoUI ( QWidget * parent ) : QMainWindow ( parent ),
featureType ( SURF ), matchType ( Ratio ), panorama ( false )
{
QStatusBar * statusBar = new QStatusBar ( this );
QObject::connect ( this, SIGNAL ( alert ( const QString & ) ),
statusBar, SLOT ( showMessage ( const QString & ) ) );
setStatusBar ( statusBar );
// Create the main window.
setWindowTitle ( tr ( "ObjDetect" ) );
stack = new QStackedWidget ( this );
setCentralWidget ( stack );
udpSender = new Sender;
// // Create the menu bar.
// QMenuBar * menuBar = new QMenuBar ( this );
// QAction * setFeatureType = new QAction ( tr ( "Set Feature Type" ), menuBar );
// QObject::connect ( setFeatureType, SIGNAL ( triggered () ),
// this, SLOT ( setFeatureTypeAction () ) );
// menuBar->addAction ( setFeatureType );
// QAction * setMatchType = new QAction ( tr ( "Set Match Type" ), menuBar );
// QObject::connect ( setMatchType, SIGNAL ( triggered () ),
// this, SLOT ( setMatchTypeAction () ) );
// menuBar->addAction ( setMatchType );
// QAction * setMode = new QAction ( tr ( "Set Mode" ), menuBar );
// QObject::connect ( setMode, SIGNAL ( triggered () ),
// this, SLOT ( setModeAction () ) );
// menuBar->addAction ( setMode );
// setMenuBar ( menuBar );
viewFinder = new Viewfinder ( this );
stack->addWidget ( viewFinder );
featureTypes ["Dummy"] = Dummy;
featureTypes ["MOPS"] = MOPS;
featureTypes ["SURF"] = SURF;
matchTypes ["SSD"] = SSD;
matchTypes ["Ratio"] = Ratio;
QObject::connect ( viewFinder, SIGNAL ( alert ( const QString & ) ),
statusBar, SLOT ( showMessage ( const QString & ) ) );
activateViewfinder ();
}
void MaemoUI::activateViewfinder ()
{
stack->setCurrentIndex ( 0 );
qRegisterMetaType<FCam::Frame>( "FCam::Frame" );
QObject::connect ( &CameraThread::getInstance (),
SIGNAL ( imageCaptured ( const FCam::Frame & ) ), this,
SLOT ( pictureTaken ( const FCam::Frame & ) ) );
viewFinder->show ();
}
void MaemoUI::deactivateViewfinder ()
{
QObject::disconnect ( &CameraThread::getInstance (),
SIGNAL ( imageCaptured ( const FCam::Frame & ) ), this,
SLOT ( pictureTaken ( const FCam::Frame & ) ) );
stack->setCurrentIndex ( 1 );
}
Viewfinder * MaemoUI::getViewfinder()
{
// printf("[MaemoUI] getViewfinder\n");
return viewFinder;
}
FeatureType MaemoUI::getFeatureType ()
{
return featureType;
}
MatchType MaemoUI::getMatchType ()
{
return matchType;
}
void MaemoUI::setFeatureTypeAction ()
{
QDialog * dialog = new QDialog ( this );
dialog->setModal ( true );
dialog->setWindowTitle ( tr ( "Feature Type" ) );
QVBoxLayout * layout = new QVBoxLayout ( dialog );
QPushButton * okay = new QPushButton ( tr ( "Okay" ), dialog );
QComboBox * combobox = new QComboBox ( dialog );
for ( std::map<QString, FeatureType>::iterator i = featureTypes.begin ();
i != featureTypes.end (); ++i )
{
combobox->addItem ( i->first );
if ( featureType == i->second )
{
combobox->setCurrentIndex ( combobox->count () - 1 );
}
}
QObject::connect ( combobox, SIGNAL ( currentIndexChanged ( const QString & ) ),
this, SLOT ( updateFeatureType ( const QString & ) ) );
layout->addWidget ( combobox );
layout->addWidget ( okay );
QObject::connect ( okay, SIGNAL ( clicked () ),
dialog, SLOT ( close () ) );
dialog->setLayout ( layout );
dialog->show ();
}
void MaemoUI::setModeAction ()
{
QDialog * dialog = new QDialog ( this );
dialog->setModal ( true );
dialog->setWindowTitle ( tr ( "Mode" ) );
QVBoxLayout * layout = new QVBoxLayout ( dialog );
QPushButton * okay = new QPushButton ( tr ( "Okay" ), dialog );
QComboBox * combobox = new QComboBox ( dialog );
combobox->addItem ( "Object Detection" );
combobox->addItem ( "Panorama" );
combobox->setEditable ( false );
combobox->setCurrentIndex ( panorama ? 1 : 0 );
QObject::connect ( combobox, SIGNAL ( currentIndexChanged ( const QString & ) ),
this, SLOT ( updateMode ( const QString & ) ) );
layout->addWidget ( combobox );
layout->addWidget ( okay );
QObject::connect ( okay, SIGNAL ( clicked () ),
dialog, SLOT ( close () ) );
dialog->setLayout ( layout );
dialog->show ();
}
void MaemoUI::updateFeatureType ( const QString & name )
{
featureType = featureTypes [name];
std::stringstream ss;
ss << "Feature type set to " << name.toStdString ();
emit alert ( tr ( ss.str ().c_str () ) );
}
void MaemoUI::updateMode ( const QString & name )
{
panorama = ( name == "Panorama" );
std::stringstream ss;
ss << "Mode set to " << name.toStdString ();
emit alert ( tr ( ss.str ().c_str () ) );
}
void MaemoUI::setMatchTypeAction ()
{
QDialog * dialog = new QDialog ( this );
dialog->setModal ( true );
dialog->setWindowTitle ( tr ( "Match Type" ) );
QVBoxLayout * layout = new QVBoxLayout ( dialog );
QPushButton * okay = new QPushButton ( tr ( "Okay" ), dialog );
QComboBox * combobox = new QComboBox ( dialog );
for ( std::map<QString, MatchType>::iterator i = matchTypes.begin ();
i != matchTypes.end (); ++i )
{
combobox->addItem ( i->first );
if ( matchType == i->second )
{
combobox->setCurrentIndex ( combobox->count () - 1 );
}
}
combobox->setEditable ( false );
QObject::connect ( combobox, SIGNAL ( currentIndexChanged ( const QString & ) ),
this, SLOT ( updateMatchType ( const QString & ) ) );
layout->addWidget ( combobox );
layout->addWidget ( okay );
QObject::connect ( okay, SIGNAL ( clicked () ),
dialog, SLOT ( close () ) );
dialog->setLayout ( layout );
dialog->show ();
}
void MaemoUI::updateMatchType ( const QString & name )
{
matchType = matchTypes [name];
std::stringstream ss;
ss << "Match type set to " << name.toStdString ();
emit alert ( tr ( ss.str ().c_str () ) );
}
void MaemoUI::pictureTaken ( const FCam::Frame & frame )
{
// printf("[pictureTaken]: you got here!\n");
QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE,
MCE_REQUEST_PATH,MCE_REQUEST_IF, MCE_PREVENT_BLANK_REQ));
if ( stack->count () == 2 )
{
QWidget * widget = stack->widget ( 1 );
stack->removeWidget ( widget );
}
// if ( !panorama )
// {
//// QWidget * wizard = new FeaturesWizard ( this, frame );
//// stack->addWidget ( wizard );
//// QObject::connect ( wizard, SIGNAL ( alert ( const QString & ) ),
//// statusBar (), SLOT ( showMessage ( const QString & ) ) );
//// wizard->show ();
// deactivateViewfinder ();
// }
// else
// {
// if ( !objdetect_widget || objdetect_widget->ready () )
if ( !objdetect_widget )
{
// printf("[pictureTaken]: create objdetect_widget\n");
objdetect_widget = new ObjDetect ( this );
}
// printf("[pictureTaken]: going imageCaptured\n");
objdetect_widget->imageCaptured ( frame );
// printf("[pictureTaken]: done imageCaptured\n");
if ( objdetect_widget->ready () )
{
// stack->addWidget ( objdetect_widget );
QObject::connect ( objdetect_widget, SIGNAL ( alert ( const QString & ) ),
statusBar (), SLOT ( showMessage ( const QString & ) ) );
// objdetect_widget->show ();
// deactivateViewfinder ();
// activateViewfinder ();
this->viewFinder->repaint();
objdetect_widget->unready();
CameraThread::getInstance().okayToCapture();
}
// }
}