PARP Research Group University of Murcia, Spain


src/qvgui/qvdefaultgui.cpp

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007, 2008, 2009. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00024 
00025 #include <QDialog>
00026 #include <QTextEdit>
00027 #include <QFont>
00028 
00029 #include <qvgui/qvdefaultgui.h>
00030 #include <qvgui/qvparamsinspectorwidget.h>
00031 #include <qvgui/qvworkerinterfacesmall.h>
00032 #include <qvgui/qvcameraworkerwidget.h>
00033 
00034 #include <QVCameraWorker>
00035 #include <QVImageCanvas>
00036 #include <QV3DCanvas>
00037 #include <qvgui/qvplot.h>
00038 
00039 QVDefaultGUI::QVDefaultGUI(QWidget *parent): QWidget(parent)
00040         {
00041         if (qvApp == NULL)
00042                 {
00043                 QString str =   "QVDefaultGUI::QVDefaultGUI(): the QVDefaultGUI cannot be created before the QVApplication instance. Aborting now.";
00044                 std::cerr << qPrintable(str) << std::endl;
00045                 exit(1);
00046                 }
00047 
00048         // If its a --help call, do nothing:
00049         if (qvApp->forHelp()) return;
00050 
00051         // On closing, quit application:
00052         connect(this,SIGNAL(closed()),qvApp,SLOT(quit()));
00053 
00054         // Window title
00055         setWindowTitle("QVision default GUI for " + qApp->applicationName());
00056 
00057         // Lay out menu bar, and cameras and worker groupbox vertically:
00058         vboxlayout = new QVBoxLayout(this);
00059         menubar = new QMenuBar(this);
00060         windowmenu = new QMenu("&Window",menubar);
00061         QAction *quit_action = menubar->addAction("&Quit");
00062         connect(quit_action,SIGNAL(triggered()),qvApp,SLOT(quit()));
00063         menubar->addMenu(windowmenu);
00064         QAction *help_action = menubar->addAction("&Help");
00065         connect(help_action,SIGNAL(triggered()),this,SLOT(showHelp()));
00066 
00067         // Register GUI in QVApplication:
00068         qvApp->registerGUI(this);
00069         }
00070 
00071 void QVDefaultGUI::showHelp()
00072         {
00073         QDialog dialog;
00074         QString help_string = QVApplication::instance()->getHelp().trimmed();
00075         dialog.setWindowTitle("QVision help for " + qApp->applicationName());
00076         QVBoxLayout vboxlayout(&dialog);
00077         QTextEdit textedit;
00078         QFont font("Courier");
00079         textedit.setReadOnly(TRUE);
00080         textedit.setFont(font);
00081         textedit.setPlainText(help_string);
00082         QFontMetrics fontmetrics = textedit.font();
00083         int w = qMin(fontmetrics.size(0,help_string).width() + 30,800);
00084         int h = qMin(fontmetrics.size(0,help_string).height() + 30,500);
00085         textedit.setMinimumSize(QSize(w,h));
00086         vboxlayout.addWidget(&textedit);
00087         QPushButton button("OK");
00088         QHBoxLayout hboxlayout;
00089         hboxlayout.addStretch();
00090         hboxlayout.addWidget(&button);
00091         hboxlayout.addStretch();
00092         vboxlayout.addLayout(&hboxlayout);
00093         connect(&button,SIGNAL(pressed()),&dialog,SLOT(close()));
00094         dialog.exec();
00095         }
00096 
00097 void QVDefaultGUI::init()
00098         {
00099         QVBoxLayout *groupboxcameraslayout,*groupboxworkerslayout;
00100         QMenu *menu_imagecanvas = NULL, *menu_glcanvas = NULL, *menu_qvplot = NULL;
00101         bool some_worker = FALSE, some_camera = FALSE;
00102 
00103         // We run through every qvApp property container and create the corresponding widgets and/or menus:
00104         foreach(QVPropertyContainer* qvp, qvApp->getQVPropertyContainers())
00105                 {
00106                 // QVWorkers (which are not QVCameraWorkers):
00107                 QVWorker* worker;
00108                 if(((worker = dynamic_cast<QVWorker*>(qvp)) != NULL) and (dynamic_cast<QVCameraWorker*>(qvp) == NULL))
00109                         {
00110                         if(not some_worker)
00111                                 {
00112                                 some_worker = TRUE;
00113                                 groupboxworkers = new QGroupBox("Workers",this);
00114                                 toolboxworkers = new QToolBox(groupboxworkers);
00115                                 }
00116                         QVWorkerInterfaceSmall *workerWidget = new QVWorkerInterfaceSmall(worker,this);
00117                         QVParamsInspectorWidget *qvparamsinspectorwidget = new QVParamsInspectorWidget(worker,this);
00118                         QWidget *widget = new QWidget(this);
00119                         QVBoxLayout *vboxlayout2 = new QVBoxLayout(widget);
00120                         vboxlayout2->setSpacing(0);
00121                         vboxlayout2->setMargin(0);
00122                         vboxlayout2->addWidget(workerWidget);
00123                         vboxlayout2->addWidget(qvparamsinspectorwidget);
00124                         toolboxworkers->addItem(widget,worker->getName());
00125                         //qvparamsinspectorwidget->updateGeometry();
00126                         continue;
00127                         }
00128                 // QVCameraWorkers:
00129                 QVCameraWorker* camera;
00130                 if((camera = dynamic_cast<QVCameraWorker*>(qvp)) != NULL)
00131                         {
00132                         if(not some_camera)
00133                                 {
00134                                 some_camera = TRUE;
00135                                 groupboxcameras = new QGroupBox("Cameras",this);
00136                                 groupboxcameras->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Fixed);
00137                                 toolboxcameras = new QToolBox(groupboxcameras);
00138                                 }
00139                         QVCameraWorkerWidget *cameraWidget = new QVCameraWorkerWidget(camera,this);
00140                         toolboxcameras->addItem(cameraWidget, camera->getName());
00141                         continue;
00142                         }
00143                 // QVImageCanvas:
00144                 QVImageCanvas *imageCanvas;
00145                 if((imageCanvas = dynamic_cast<QVImageCanvas*>(qvp)) != NULL)
00146                         {
00147                         if(menu_imagecanvas == NULL)
00148                                 menu_imagecanvas = windowmenu->addMenu("&Image windows");
00149                         QAction *action = menu_imagecanvas->addAction(imageCanvas->getName());
00150                         action->setCheckable(TRUE);
00151                         action->setChecked(imageCanvas->isVisible());
00152                         connect(action,SIGNAL(toggled(bool)),imageCanvas,SLOT(setVisible(bool)));
00153                         connect(imageCanvas,SIGNAL(closed()),action,SLOT(toggle()));
00154                         continue;
00155                         }
00156                 // QV3DCanvas:
00157                 QV3DCanvas *glCanvas;
00158                 if((glCanvas = dynamic_cast<QV3DCanvas*>(qvp)) != NULL)
00159                         {
00160                         if(menu_glcanvas == NULL)
00161                                 menu_glcanvas = windowmenu->addMenu("&OpenGL windows");
00162                         QAction *action = menu_glcanvas->addAction(glCanvas->getName());
00163                         action->setCheckable(TRUE);
00164                         action->setChecked(glCanvas->isVisible());
00165                         connect(action,SIGNAL(toggled(bool)),glCanvas,SLOT(setVisible(bool)));
00166                         connect(glCanvas,SIGNAL(closed()),action,SLOT(toggle()));
00167                         continue;
00168                         }
00169                 // QVPlots:
00170                 QVPlot *qvplot;
00171                 if((qvplot = dynamic_cast<QVPlot*>(qvp)) != NULL)
00172                         {
00173                         if(menu_qvplot == NULL)
00174                                 menu_qvplot = windowmenu->addMenu("&Plot windows");
00175                         QAction *action = menu_qvplot->addAction(qvplot->getName());
00176                         action->setCheckable(TRUE);
00177                         //FIXME:  It should be: action->setChecked(qvplot->isVisible());
00178                         // but, for any reason, qvplots are not shown until later (ask Antonio)
00179                         action->setChecked(TRUE);
00180                         connect(action,SIGNAL(toggled(bool)),qvplot,SLOT(setVisible(bool)));
00181                         connect(qvplot,SIGNAL(closed()),action,SLOT(toggle()));
00182                         continue;
00183                         }
00184                 }
00185 
00186 
00187         vboxlayout->setSpacing(5);
00188         vboxlayout->setMargin(5);
00189         vboxlayout->addWidget(menubar);
00190 
00191         if(some_worker)
00192                 {
00193                 groupboxworkerslayout = new QVBoxLayout(groupboxworkers);
00194                 groupboxworkerslayout->addWidget(toolboxworkers);
00195                 vboxlayout->addWidget(groupboxworkers);
00196                 }
00197 
00198         if(some_camera)
00199                 {
00200                 groupboxcameraslayout = new QVBoxLayout(groupboxcameras);
00201                 groupboxcameraslayout->addWidget(toolboxcameras);
00202                 vboxlayout->addWidget(groupboxcameras);
00203                 }
00204         }
00205 
00206 void QVDefaultGUI::closeEvent(QCloseEvent *event)
00207         {
00208         Q_UNUSED(event);
00209         qvApp->deregisterGUI();
00210         emit closed();
00211         }



QVision framework. PARP research group, copyright 2007, 2008.