00001 #if 0 // Removed support for this screen; will probably remove code altogether eventually
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <qapplication.h>
00012
00013 #include <stdlib.h>
00014 #include <unistd.h>
00015 #include <iostream>
00016
00017 using namespace std;
00018
00019 #include <linux/videodev.h>
00020 #include <mythtv/mythcontext.h>
00021
00022 #include "config.h"
00023 #include "webcam.h"
00024 #include "h263.h"
00025 #include "webcam_set.h"
00026
00027
00028
00029 WebcamSettingsBox::WebcamSettingsBox(MythMainWindow *parent, QString window_name,
00030 QString theme_filename, const char *name)
00031
00032 : MythThemedDialog(parent, window_name, theme_filename, name)
00033 {
00034
00035
00036
00037
00038
00039
00040 brightness = 32768;
00041 contrast = 32768;
00042 colour = 32768;
00043 hue = 32768;
00044 fps = 10;
00045
00046 settingDisplayTimer = 0;
00047
00048
00049
00050
00051
00052
00053
00054 wireUpTheme();
00055
00056
00057
00058 webcam = new Webcam(this);
00059
00060 WebcamDevice = gContext->GetSetting("WebcamDevice");
00061 TxResolution = gContext->GetSetting("TxResolution");
00062 if (WebcamDevice.length() < 1)
00063 {
00064 DialogBox *NoDeviceDialog = new DialogBox(gContext->GetMainWindow(),
00065 QObject::tr("\n\nYou need to go to settings and configure the WEBCAM device."));
00066 NoDeviceDialog->AddButton(QObject::tr("OK"));
00067 NoDeviceDialog->exec();
00068 delete NoDeviceDialog;
00069 }
00070 else
00071 {
00072 if (webcam->camOpen(WebcamDevice, 352, 288))
00073 {
00074 int pal = webcam->GetPalette();
00075 checkPaletteModes();
00076 webcam->SetPalette(pal);
00077
00078
00079
00080
00081 webcam->SetTargetFps(fps);
00082
00083
00084 connect(webcam, SIGNAL(webcamFrameReady(uchar *, int, int)), this, SLOT(DrawLocalWebcamImage(uchar *, int, int)));
00085 }
00086
00087 settingDisplayTimer = new QTimer(this);
00088 settingDisplayTimer->start(1000);
00089 connect(settingDisplayTimer, SIGNAL(timeout()), this,
00090 SLOT(SettingDisplayTimerExpiry()));
00091 }
00092 }
00093
00094
00095
00096 void WebcamSettingsBox::keyPressEvent(QKeyEvent *e)
00097 {
00098 bool handled = false;
00099 QStringList actions;
00100 gContext->GetMainWindow()->TranslateKeyPress("Phone", e, actions);
00101
00102 for (unsigned int i = 0; i < actions.size() && !handled; i++)
00103 {
00104 QString action = actions[i];
00105 handled = true;
00106
00107 if (action == "Up")
00108 {
00109 activeSlider = activeSlider->prev();
00110 }
00111 else if (action == "Down")
00112 {
00113 activeSlider = activeSlider->next();
00114 }
00115 else if (action == "Left")
00116 {
00117 activeSlider->down();
00118 }
00119 else if (action == "Right")
00120 {
00121 activeSlider->up();
00122 }
00123 else if (action == "9")
00124 {
00125 cout << "9 Pressed" << endl;
00126 if (save_button)
00127 save_button->push();
00128 }
00129 else
00130 handled = false;
00131 }
00132
00133 if (!handled)
00134 MythThemedDialog::keyPressEvent(e);
00135 }
00136
00137
00138 void WebcamSettingsBox::DrawLocalWebcamImage(uchar *yuv, int w, int h)
00139 {
00140 QPixmap Pixmap;
00141
00142 YUV420PtoRGB32(w, h, w, yuv, localRgbBuffer, sizeof(localRgbBuffer));
00143 QImage Image((uchar *)localRgbBuffer, w, h, 32, (QRgb *)0, 0, QImage::LittleEndian);
00144 QRect puthere = webcamArea->getScreenArea();
00145 QImage ScaledImage = Image.scale(puthere.width(), puthere.height(), QImage::ScaleMax);
00146 Pixmap = ScaledImage;
00147 bitBlt(this, puthere.x(), puthere.y(), &Pixmap);
00148 }
00149
00150
00151 void WebcamSettingsBox::saveSettings()
00152 {
00153 cout << "Save Settings selected" << endl;
00154 }
00155
00156
00157 void WebcamSettingsBox::brightnessUp()
00158 {
00159 brightness = webcam->SetBrightness(brightness+2048);
00160 brightnessUI->SetUsed(brightness);
00161 }
00162
00163
00164 void WebcamSettingsBox::brightnessDown()
00165 {
00166 brightness = webcam->SetBrightness(brightness-2048);
00167 brightnessUI->SetUsed(brightness);
00168 }
00169
00170
00171 void WebcamSettingsBox::contrastUp()
00172 {
00173 contrast = webcam->SetContrast(contrast+2048);
00174 contrastUI->SetUsed(contrast);
00175 }
00176
00177
00178 void WebcamSettingsBox::contrastDown()
00179 {
00180 contrast = webcam->SetContrast(contrast-2048);
00181 contrastUI->SetUsed(contrast);
00182 }
00183
00184
00185 void WebcamSettingsBox::colourUp()
00186 {
00187 colour = webcam->SetColour(colour+2048);
00188 colourUI->SetUsed(colour);
00189 }
00190
00191
00192 void WebcamSettingsBox::colourDown()
00193 {
00194 colour = webcam->SetColour(colour-2048);
00195 colourUI->SetUsed(colour);
00196 }
00197
00198
00199 void WebcamSettingsBox::hueUp()
00200 {
00201 hue = webcam->SetHue(hue+2048);
00202 hueUI->SetUsed(hue);
00203 }
00204
00205
00206 void WebcamSettingsBox::hueDown()
00207 {
00208 hue = webcam->SetHue(hue-2048);
00209 hueUI->SetUsed(hue);
00210 }
00211
00212
00213 void WebcamSettingsBox::fpsUp()
00214 {
00215 fps+=2;
00216 fps = webcam->SetTargetFps(fps);
00217 fpsUI->SetUsed(fps);
00218 }
00219
00220
00221 void WebcamSettingsBox::fpsDown()
00222 {
00223 fps-=2;
00224 fps = webcam->SetTargetFps(fps);
00225 fpsUI->SetUsed(fps);
00226 }
00227
00228
00229 void WebcamSettingsBox::SettingDisplayTimerExpiry()
00230 {
00231 if (webcam_name_text)
00232 {
00233 QString Name = "Name : " + webcam->GetName();
00234 webcam_name_text->SetText(Name);
00235 }
00236
00237 if (webcam_maxsize_text)
00238 {
00239 int x,y,x2,y2;
00240 webcam->GetMaxSize(&x2, &y2);
00241 QString x2s, y2s, xs, ys;
00242 x2s.setNum(x2);
00243 y2s.setNum(y2);
00244 webcam->GetMinSize(&x, &y);
00245 xs.setNum(x);
00246 ys.setNum(y);
00247 QString Size = "Supported Sizes : " + xs + "x" + ys +
00248 " to " + x2s + "x" + y2s;
00249 webcam_maxsize_text->SetText(Size);
00250 }
00251
00252 if (webcam_cursize_text)
00253 {
00254 int x,y;
00255 webcam->GetCurSize(&x, &y);
00256 QString xs, ys;
00257 xs.setNum(x);
00258 ys.setNum(y);
00259 QString Size = "Current Size : " + xs + "x" + ys;
00260 webcam_cursize_text->SetText(Size);
00261 }
00262
00263 if (webcam_colour_bw_text)
00264 {
00265 if (webcam->isGreyscale())
00266 webcam_colour_bw_text->SetText("Type : Monochrome (not supported!)");
00267 else
00268 {
00269 int pal = webcam->GetPalette();
00270 QString colourMode = QString("Type : %1 (%2)").arg(pal).arg(palModes);
00271 webcam_colour_bw_text->SetText(colourMode);
00272 }
00273 }
00274
00275 if (webcam_brightness_text)
00276 {
00277 int v;
00278 v = webcam->GetBrightness();
00279 QString vs;
00280 vs.setNum(v);
00281 vs.insert(0, "Brightness : ");
00282 webcam_brightness_text->SetText(vs);
00283 }
00284
00285 if (webcam_contrast_text)
00286 {
00287 int v;
00288 v = webcam->GetContrast();
00289 QString vs;
00290 vs.setNum(v);
00291 vs.insert(0, "Contrast : ");
00292 webcam_contrast_text->SetText(vs);
00293 }
00294
00295 if (webcam_colour_text)
00296 {
00297 int v;
00298 v = webcam->GetColour();
00299 QString vs;
00300 vs.setNum(v);
00301 vs.insert(0, "Colour : ");
00302 webcam_colour_text->SetText(vs);
00303 }
00304
00305 if (webcam_hue_text)
00306 {
00307 int v;
00308 v = webcam->GetHue();
00309 QString vs;
00310 vs.setNum(v);
00311 vs.insert(0, "Hue : ");
00312 webcam_hue_text->SetText(vs);
00313 }
00314
00315 if (webcam_fps_text)
00316 {
00317 QString vs;
00318 vs.setNum(webcam->GetActualFps());
00319 vs.insert(0, "Frames / Second : ");
00320 webcam_fps_text->SetText(vs);
00321 }
00322 }
00323
00324
00325 void WebcamSettingsBox::checkPaletteModes()
00326 {
00327 palModes = "";
00328 for (int p=1; p<16; p++)
00329 {
00330 if (webcam->SetPalette(p))
00331 {
00332 QString temp = QString("%1 ").arg(p);
00333 palModes += temp;
00334 }
00335 }
00336 }
00337
00338
00339 void WebcamSettingsBox::wireUpTheme()
00340 {
00341 brightnessUI = getUIStatusBarType("brightness");
00342 if(brightnessUI)
00343 {
00344 brightnessUI->SetTotal(65535);
00345 brightnessUI->SetUsed(brightness);
00346 }
00347
00348 contrastUI = getUIStatusBarType("contrast");
00349 if(contrastUI)
00350 {
00351 contrastUI->SetTotal(65535);
00352 contrastUI->SetUsed(contrast);
00353 }
00354
00355 colourUI = getUIStatusBarType("colour");
00356 if(colourUI)
00357 {
00358 colourUI->SetTotal(65535);
00359 colourUI->SetUsed(colour);
00360 }
00361
00362 hueUI = getUIStatusBarType("hue");
00363 if(hueUI)
00364 {
00365 hueUI->SetTotal(65535);
00366 hueUI->SetUsed(hue);
00367 }
00368
00369 fpsUI = getUIStatusBarType("fps");
00370 if(fpsUI)
00371 {
00372 fpsUI->SetTotal(MAX_FPS);
00373 fpsUI->SetUsed(fps);
00374 }
00375
00376 webcam_name_text = getUITextType("webcam_name_text");
00377 webcam_maxsize_text = getUITextType("webcam_maxsize_text");
00378 webcam_cursize_text = getUITextType("webcam_cursize_text");
00379 webcam_colour_bw_text = getUITextType("webcam_colour_bw_text");
00380 webcam_brightness_text = getUITextType("webcam_brightness_text");
00381 webcam_contrast_text = getUITextType("webcam_contrast_text");
00382 webcam_colour_text = getUITextType("webcam_colour_text");
00383 webcam_hue_text = getUITextType("webcam_hue_text");
00384 webcam_fps_text = getUITextType("webcam_fps_text");
00385
00386 webcamArea = getUIBlackHoleType("visual_blackhole");
00387
00388 br_up_button = getUIPushButtonType("br_up_button");
00389 if(br_up_button)
00390 connect(br_up_button, SIGNAL(pushed()), this, SLOT(brightnessUp()));
00391
00392 br_down_button = getUIPushButtonType("br_down_button");
00393 if(br_down_button)
00394 connect(br_down_button, SIGNAL(pushed()), this, SLOT(brightnessDown()));
00395
00396 con_up_button = getUIPushButtonType("con_up_button");
00397 if(con_up_button)
00398 connect(con_up_button, SIGNAL(pushed()), this, SLOT(contrastUp()));
00399
00400 con_down_button = getUIPushButtonType("con_down_button");
00401 if(con_down_button)
00402 connect(con_down_button, SIGNAL(pushed()), this, SLOT(contrastDown()));
00403
00404 col_up_button = getUIPushButtonType("col_up_button");
00405 if(col_up_button)
00406 connect(col_up_button, SIGNAL(pushed()), this, SLOT(colourUp()));
00407
00408 col_down_button = getUIPushButtonType("col_down_button");
00409 if(col_down_button)
00410 connect(col_down_button, SIGNAL(pushed()), this, SLOT(colourDown()));
00411
00412 hue_up_button = getUIPushButtonType("hue_up_button");
00413 if(hue_up_button)
00414 connect(hue_up_button, SIGNAL(pushed()), this, SLOT(hueUp()));
00415
00416 hue_down_button = getUIPushButtonType("hue_down_button");
00417 if(hue_down_button)
00418 connect(hue_down_button, SIGNAL(pushed()), this, SLOT(hueDown()));
00419
00420 fps_up_button = getUIPushButtonType("fps_up_button");
00421 if(fps_up_button)
00422 connect(fps_up_button, SIGNAL(pushed()), this, SLOT(fpsUp()));
00423
00424 fps_down_button = getUIPushButtonType("fps_down_button");
00425 if(fps_down_button)
00426 connect(fps_down_button, SIGNAL(pushed()), this, SLOT(fpsDown()));
00427
00428 brightnessSlider = new WebcamSettingSlider (brightnessUI, br_up_button, br_down_button, 0);
00429 contrastSlider = new WebcamSettingSlider (contrastUI, con_up_button, con_down_button, brightnessSlider);
00430 colourSlider = new WebcamSettingSlider (colourUI, col_up_button, col_down_button, contrastSlider);
00431 hueSlider = new WebcamSettingSlider (hueUI, hue_up_button, hue_down_button, colourSlider);
00432 fpsSlider = new WebcamSettingSlider (fpsUI, fps_up_button, fps_down_button, hueSlider);
00433 activeSlider = brightnessSlider;
00434
00435 save_button = getUITextButtonType("save_button");
00436 if(save_button)
00437 {
00438 save_button->setText(tr("9 Save"));
00439 connect(save_button, SIGNAL(pushed()), this, SLOT(saveSettings()));
00440 }
00441 else
00442 cerr << "Can't get button save" << endl;
00443 }
00444
00445 WebcamSettingsBox::~WebcamSettingsBox(void)
00446 {
00447 if (settingDisplayTimer != 0)
00448 settingDisplayTimer->stop();
00449 }
00450
00451
00452
00453 #endif