void ishara::on_comboSelectCam_currentIndexChanged(int index) { if(devSelActive == 0) { devSelActive = 1; } else { CAM_INDEX = index; capture.release(); camOpen(); } }
ishara::ishara(QWidget *parent) : QMainWindow(parent), ui(new Ui::ishara) { if (QSystemTrayIcon::isSystemTrayAvailable()) { /* * init system tray */ maximizeAction = new QAction(tr("&Show"), this); connect(maximizeAction, SIGNAL(triggered()), this, SLOT(show())); quitAction = new QAction(tr("&Quit"), this); connect(quitAction, SIGNAL(triggered()), this, SLOT(on_actionQuit_triggered())); startStopAction = new QAction(tr("S&tart"), this); connect(startStopAction, SIGNAL(triggered()), this, SLOT(startStop())); trayIconMenu = new QMenu(this); trayIconMenu->addAction(maximizeAction); trayIconMenu->addSeparator(); trayIconMenu->addAction(startStopAction); trayIconMenu->addSeparator(); trayIconMenu->addAction(quitAction); trayIcon = new QSystemTrayIcon(this); trayIcon->setContextMenu(trayIconMenu); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); const QIcon *icon = new QIcon(":/prefix1/res/ishara.ico"); trayIcon->setIcon(*icon); trayIcon->hide(); } /* * initializing some variables from the configuration file */ settings.sync(); hMin1 = settings.value("hMin1", 0).toInt(); hMax1 = settings.value("hMax1", 179).toInt(); sMin1 = settings.value("sMin1", 0).toInt(); sMax1 = settings.value("sMax1", 255).toInt(); vMin1 = settings.value("vMin1", 0).toInt(); vMax1 = settings.value("vMax1", 255).toInt(); hMin2 = settings.value("hMin2", 0).toInt(); hMax2 = settings.value("hMax2", 179).toInt(); sMin2 = settings.value("sMin2", 0).toInt(); sMax2 = settings.value("sMax2", 255).toInt(); vMin2 = settings.value("vMin2", 0).toInt(); vMax2 = settings.value("vMax2", 255).toInt(); pinchR = settings.value("pinchR", 66).toInt(); rightClickDealy = settings.value("rightClickDealy", 20).toInt(); smoothFac = settings.value("smoothFac", 8).toInt(); cfgScroll = settings.value("cfgScroll", 2).toInt(); cfgLClick = settings.value("cfgLClick", 2).toInt(); cfgRClick = settings.value("cfgRClick", 2).toInt(); /* * initializing some more variables */ CAM_INDEX = -1; mcorInit_X = 0; mcorInit_Y = 0; msPoint_X = 0; msPoint_Y = 0; xScreenHeight = 0; xScreenWidth = 0; startEmulation = 0; motionEnable = 0; tmpX = 0; tmpY = 0; waitCountRC = 0; pinch = 0; ifScrollUp = 0; ifScrollDwn = 0; btnPress = 1; btnRel = 1; devSelActive = 0; iteration = 0; /* * setting up the user interface */ ui->setupUi(this); /* * setting up smoothness factor slider; smoothness factor is the maximum allowable * distance the index finger can move without effecting any change in the mouse * cursor position; a reasonable value for this would be 6 to 8 depending on the user */ ui->sliderSmoothFac->setRange(2, 12); ui->sliderSmoothFac->setValue(smoothFac); /* * setting up color selection sliders; the HSV range for the two color markers to be * detected are set using these sliders */ ui->sliderHMin1->setRange(0, 179); ui->sliderHMax1->setRange(0, 179); ui->sliderSMin1->setRange(0, 255); ui->sliderSMax1->setRange(0, 255); ui->sliderVMin1->setRange(0, 255); ui->sliderVMax1->setRange(0, 255); ui->sliderHMin2->setRange(0, 179); ui->sliderHMax2->setRange(0, 179); ui->sliderSMin2->setRange(0, 255); ui->sliderSMax2->setRange(0, 255); ui->sliderVMin2->setRange(0, 255); ui->sliderVMax2->setRange(0, 255); ui->sliderHMin1->setValue(hMin1); ui->sliderHMax1->setValue(hMax1); ui->sliderSMin1->setValue(sMin1); ui->sliderSMax1->setValue(sMax1); ui->sliderVMin1->setValue(vMin1); ui->sliderVMax1->setValue(vMax1); ui->sliderHMin2->setValue(hMin2); ui->sliderHMax2->setValue(hMax2); ui->sliderSMin2->setValue(sMin2); ui->sliderSMax2->setValue(sMax2); ui->sliderVMin2->setValue(vMin2); ui->sliderVMax2->setValue(vMax2); /* * setting up color selection spinboxes; the values determining the HSV range can * also be altered using the spin boxes */ ui->spnHMin1->setRange(0, 179); ui->spnHMax1->setRange(0, 179); ui->spnSMin1->setRange(0, 255); ui->spnSMax1->setRange(0, 255); ui->spnVMin1->setRange(0, 255); ui->spnVMax1->setRange(0, 255); ui->spnHMin2->setRange(0, 179); ui->spnHMax2->setRange(0, 179); ui->spnSMin2->setRange(0, 255); ui->spnSMax2->setRange(0, 255); ui->spnVMin2->setRange(0, 255); ui->spnVMax2->setRange(0, 255); ui->spnHMin1->setValue(hMin1); ui->spnHMax1->setValue(hMax1); ui->spnSMin1->setValue(sMin1); ui->spnSMax1->setValue(sMax1); ui->spnVMin1->setValue(vMin1); ui->spnVMax1->setValue(vMax1); ui->spnHMin2->setValue(hMin2); ui->spnHMax2->setValue(hMax2); ui->spnSMin2->setValue(sMin2); ui->spnSMax2->setValue(sMax2); ui->spnVMin2->setValue(vMin2); ui->spnVMax2->setValue(vMax2); /* * setting up pinchR slider; the pinchR variable determines the maximum distance * between the center co-ordinates of the two color markers when detecting a Pinch */ ui->sliderPinchR->setRange(10, 120); ui->sliderPinchR->setValue(pinchR); /* * setting up pinchR spinbox; the value of pinchR can also be altered using a spinbox */ ui->spnPinchR->setRange(10, 120); ui->spnPinchR->setValue(pinchR); /* * setting up rightClickDealy slider; the variables rightClickDealy * determines the loop count while determining a right click */ ui->sliderRCRC->setRange(10, 30); ui->sliderRCRC->setValue(rightClickDealy); /* * setting up rightClickDealy spinbox, the usage is obvious */ ui->spnRCRC->setRange(10, 30); ui->spnRCRC->setValue(rightClickDealy); /* * setting up check boxes to enable/disable functionalities */ if(cfgScroll > 0) { ui->chkEnableScroll->setChecked(true); } else { ui->chkEnableScroll->setChecked(false); } if(cfgLClick > 0) { ui->chkEnableLeftClick->setChecked(true); } else { ui->chkEnableLeftClick->setChecked(false); } if(cfgRClick > 0) { ui->chkEnableRightClick->setChecked(true); } else { ui->chkEnableRightClick->setChecked(false); } /* * camera selection in Linux */ for(deviceIndex = 0 ; deviceIndex < 64 ; ++deviceIndex) { QString device = "/dev/video" + QString::number(deviceIndex); QByteArray array = device.toLocal8Bit(); char *buffer = array.data(); if((fd = open(buffer, O_RDONLY)) != -1) { if(ioctl(fd, VIDIOC_QUERYCAP, &vidiocap) == -1) { ui->comboSelectCam->addItem(device); } else { ui->comboSelectCam->addItem(QString::fromLocal8Bit(reinterpret_cast<const char*>(vidiocap.card))); } if(CAM_INDEX == -1) { CAM_INDEX = deviceIndex; } } } /* * camera operations */ camOpen(); capture.read(src); if(src.empty() == true) { ui->statusBar->showMessage("Read error!"); return; } /* * get the screen size */ getxScreenSize(); /* * time warp - make it so */ timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(processFrameAndUpdateGUI())); timer->start(20); /* * clean up the crap */ src.release(); frame.release(); imgHSV.release(); }
ishara::ishara(QWidget *parent) : QMainWindow(parent), ui(new Ui::ishara) { /** * Initializing some variables from the configuration file. */ QString f = QDir::homePath() + QDir::separator() + ".ishara"; QFile conf(f); if(conf.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(&conf); for(linecount = 0 ; linecount < 18 ; ++linecount) { QString line = in.readLine(); storedval[linecount] = line.toInt(); } hMin1 = storedval[0]; hMax1 = storedval[1]; sMin1 = storedval[2]; sMax1 = storedval[3]; vMin1 = storedval[4]; vMax1 = storedval[5]; hMin2 = storedval[6]; hMax2 = storedval[7]; sMin2 = storedval[8]; sMax2 = storedval[9]; vMin2 = storedval[10]; vMax2 = storedval[11]; pinchR = storedval[12]; rightClkCount = storedval[13]; smoothFac = storedval[14]; cfgScroll = storedval[15]; cfgLClick = storedval[16]; cfgRClick = storedval[17]; } else { hMin1 = 0; hMax1 = 179; sMin1 = 0; sMax1 = 255; vMin1 = 0; vMax1 = 255; hMin2 = 0; hMax2 = 179; sMin2 = 0; sMax2 = 255; vMin2 = 0; vMax2 = 255; pinchR = 66; rightClkCount = 20; smoothFac = 8; cfgScroll = 2; cfgLClick = 2; cfgRClick = 2; } /** * Initializing some more variables. */ CAM_INDEX = -1; mcorInit_X = 0; mcorInit_Y = 0; msPoint_X = 0; msPoint_Y = 0; xScreenHeight = 0; xScreenWidth = 0; startEmulation = 0; tmpX = 0; tmpY = 0; waitCount = 0; pinch = 0; ifScrollUp = 0; ifScrollDwn = 0; btnPress = 1; btnRel = 1; devSelActive = 0; /** * Setting up the user interface. */ ui->setupUi(this); /** * Setting up smoothness factor slider. Smoothness factor is the maximum allowable * distance the index finger can move without effecting any change in the mouse * cursor position. A reasonable value for this would be 6 to 8 depending on the user. */ ui->sliderSmoothFac->setRange(4, 12); ui->sliderSmoothFac->setValue(smoothFac); /** * Setting up color selection sliders. The HSV range for the two color markers to be * detected are set using these sliders. */ ui->sliderHMin1->setRange(0, 179); ui->sliderHMax1->setRange(0, 179); ui->sliderSMin1->setRange(0, 255); ui->sliderSMax1->setRange(0, 255); ui->sliderVMin1->setRange(0, 255); ui->sliderVMax1->setRange(0, 255); ui->sliderHMin2->setRange(0, 179); ui->sliderHMax2->setRange(0, 179); ui->sliderSMin2->setRange(0, 255); ui->sliderSMax2->setRange(0, 255); ui->sliderVMin2->setRange(0, 255); ui->sliderVMax2->setRange(0, 255); ui->sliderHMin1->setValue(hMin1); ui->sliderHMax1->setValue(hMax1); ui->sliderSMin1->setValue(sMin1); ui->sliderSMax1->setValue(sMax1); ui->sliderVMin1->setValue(vMin1); ui->sliderVMax1->setValue(vMax1); ui->sliderHMin2->setValue(hMin2); ui->sliderHMax2->setValue(hMax2); ui->sliderSMin2->setValue(sMin2); ui->sliderSMax2->setValue(sMax2); ui->sliderVMin2->setValue(vMin2); ui->sliderVMax2->setValue(vMax2); /** * Setting up color selection spinboxes. The values determining the HSV range can * also be altered using the spin boxes. */ ui->spnHMin1->setRange(0, 179); ui->spnHMax1->setRange(0, 179); ui->spnSMin1->setRange(0, 255); ui->spnSMax1->setRange(0, 255); ui->spnVMin1->setRange(0, 255); ui->spnVMax1->setRange(0, 255); ui->spnHMin2->setRange(0, 179); ui->spnHMax2->setRange(0, 179); ui->spnSMin2->setRange(0, 255); ui->spnSMax2->setRange(0, 255); ui->spnVMin2->setRange(0, 255); ui->spnVMax2->setRange(0, 255); ui->spnHMin1->setValue(hMin1); ui->spnHMax1->setValue(hMax1); ui->spnSMin1->setValue(sMin1); ui->spnSMax1->setValue(sMax1); ui->spnVMin1->setValue(vMin1); ui->spnVMax1->setValue(vMax1); ui->spnHMin2->setValue(hMin2); ui->spnHMax2->setValue(hMax2); ui->spnSMin2->setValue(sMin2); ui->spnSMax2->setValue(sMax2); ui->spnVMin2->setValue(vMin2); ui->spnVMax2->setValue(vMax2); /** * Setting up pinchR slider. The pinchR variable determines the maximum distance * between the center co-ordinates of the two color markers when detecting a Pinch. */ ui->sliderPinchR->setRange(10, 120); ui->sliderPinchR->setValue(pinchR); /** * Setting up pinchR spinbox. The value of pinchR can also be altered using a spinbox. */ ui->spnPinchR->setRange(10, 120); ui->spnPinchR->setValue(pinchR); /** * Setting up rightClkCount slider. The variable rightClkCount * determines the loop count while determining a right click. */ ui->sliderRCRC->setRange(10, 30); ui->sliderRCRC->setValue(rightClkCount); /** * Setting up rightClkCount spinbox, the usage is obvious. */ ui->spnRCRC->setRange(10, 30); ui->spnRCRC->setValue(rightClkCount); /** * Setting up check boxes to enable/disable functionalities. */ if(cfgScroll > 0) { ui->chkEnableScroll->setChecked(true); } else { ui->chkEnableScroll->setChecked(false); } if(cfgLClick > 0) { ui->chkEnableLeftClick->setChecked(true); } else { ui->chkEnableLeftClick->setChecked(false); } if(cfgRClick > 0) { ui->chkEnableRightClick->setChecked(true); } else { ui->chkEnableRightClick->setChecked(false); } /** * Camera selection in Linux. */ for(deviceIndex = 0 ; deviceIndex < 64 ; ++deviceIndex) { QString device = "/dev/video" + QString::number(deviceIndex); QByteArray array = device.toLocal8Bit(); char *buffer = array.data(); if((fd = open(buffer, O_RDONLY)) != -1) { if(ioctl(fd, VIDIOC_QUERYCAP, &vidiocap) == -1) { ui->comboSelectCam->addItem(device); } else { ui->comboSelectCam->addItem(QString::fromLocal8Bit(reinterpret_cast<const char*>(vidiocap.card))); } if(CAM_INDEX == -1) { CAM_INDEX = deviceIndex; } } } /** * Camera operations. */ camOpen(); capture.read(src); if(src.empty() == true) { ui->statusBar->showMessage("Read error!"); return; } /** * Time warp. */ timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(processFrameAndUpdateGUI())); timer->start(20); /** * Clean up the crap. */ src.release(); frame.release(); imgHSV.release(); }