#include "qv4l2.h" #include "general-tab.h" #include "v4l2.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "fileopen.xpm" ApplicationWindow::ApplicationWindow() : QMainWindow( 0, "V4L2 main window", WDestructiveClose | WGroupLeader ) { QPixmap openIcon, saveIcon; fd = -1; sigMapper = NULL; QToolBar * fileTools = new QToolBar( this, "file operations" ); fileTools->setLabel( "File Operations" ); openIcon = QPixmap( fileopen ); QToolButton * fileOpen = new QToolButton( openIcon, "Open File", QString::null, this, SLOT(choose()), fileTools, "open file" ); (void)QWhatsThis::whatsThisButton( fileTools ); const char * fileOpenText = "

" "Click this button to open a new v4l device.
" "You can also select the Open command " "from the File menu.

"; QWhatsThis::add( fileOpen, fileOpenText ); QMimeSourceFactory::defaultFactory()->setPixmap( "fileopen", openIcon ); QPopupMenu * file = new QPopupMenu( this ); menuBar()->insertItem( "&File", file ); int id; id = file->insertItem( openIcon, "&Open...", this, SLOT(choose()), CTRL+Key_O ); file->setWhatsThis( id, fileOpenText ); file->insertSeparator(); file->insertItem( "&Close", this, SLOT(close()), CTRL+Key_W ); file->insertItem( "&Quit", qApp, SLOT( closeAllWindows() ), CTRL+Key_Q ); menuBar()->insertSeparator(); QPopupMenu * help = new QPopupMenu( this ); menuBar()->insertItem( "&Help", help ); help->insertItem( "&About", this, SLOT(about()), Key_F1 ); help->insertItem( "What's &This", this, SLOT(whatsThis()), SHIFT+Key_F1 ); statusBar()->message( "Ready", 2000 ); tabs = new QTabWidget(this); tabs->setMargin(3); //resize( 450, 600 ); } ApplicationWindow::~ApplicationWindow() { if (fd >= 0) ::close(fd); } void ApplicationWindow::setDevice(const QString &device) { if (fd >= 0) ::close(fd); while (QWidget *page = tabs->page(0)) { tabs->removePage(page); delete page; } delete tabs; delete sigMapper; tabs = new QTabWidget(this); tabs->setMargin(3); sigMapper = new QSignalMapper(this); connect(sigMapper, SIGNAL(mapped(int)), this, SLOT(ctrlAction(int))); ctrlMap.clear(); widgetMap.clear(); classMap.clear(); fd = ::open(device, O_RDONLY); if (fd >= 0) { tabs->addTab(new GeneralTab(device, fd, 4, tabs), "General"); addTabs(); } if (QWidget *current = tabs->currentPage()) { current->show(); } tabs->show(); tabs->setFocus(); setCentralWidget(tabs); } void ApplicationWindow::choose() { QString fn = QFileDialog::getOpenFileName( "/dev/v4l", QString::null, this); if ( !fn.isEmpty() ) { setDevice(fn); } else statusBar()->message( "Loading aborted", 2000 ); } void ApplicationWindow::closeEvent( QCloseEvent* ce ) { ce->accept(); } bool ApplicationWindow::doIoctl(QString descr, unsigned cmd, void *arg) { statusBar()->clear(); int err = ioctl(fd, cmd, arg); if (err == -1) { QString s = strerror(errno); statusBar()->message(descr + ": " + s, 10000); } return err != -1; } void ApplicationWindow::about() { QMessageBox::about( this, "V4L2 Control Panel", "This program allows easy experimenting with video4linux devices."); } ApplicationWindow *g_mw; int main(int argc, char **argv) { QApplication a(argc, argv); g_mw = new ApplicationWindow(); g_mw->setCaption( "V4L2 Control Panel" ); g_mw->setDevice("/dev/video0"); g_mw->show(); a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) ); return a.exec(); }