00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #include <QDialog>
00026 #include <QTextEdit>
00027 #include <QFont>
00028
00029 #include <QVDefaultGUI>
00030 #include <QVVideoReaderBlock>
00031 #include <QVImageCanvas>
00032
00033 #ifdef GSL_AVAILABLE
00034 #include <QV3DCanvas>
00035 #endif
00036
00037 #include "qvplot.h"
00038 #include "qvparamsinspectorwidget.h"
00039 #include "qvblockinterfacesmall.h"
00040 #include "qvvideoreaderblockwidget.h"
00041
00042 QVDefaultGUI::QVDefaultGUI(QWidget *parent): QWidget(parent)
00043 {
00044 if (qvApp == NULL)
00045 {
00046 QString str = "QVDefaultGUI::QVDefaultGUI(): the QVDefaultGUI cannot be created before the QVApplication instance. Aborting now.";
00047 std::cerr << qPrintable(str) << std::endl;
00048 exit(1);
00049 }
00050
00051
00052 if (qvApp->forHelp()) return;
00053
00054
00055 connect(this,SIGNAL(closed()),qvApp,SLOT(quit()));
00056
00057
00058 setWindowTitle("QVision default GUI for " + qApp->applicationName());
00059
00060
00061 vboxlayout = new QVBoxLayout(this);
00062 menubar = new QMenuBar(this);
00063 windowmenu = new QMenu("&Window",menubar);
00064 QAction *quit_action = menubar->addAction("&Quit");
00065 connect(quit_action,SIGNAL(triggered()),qvApp,SLOT(quit()));
00066 menubar->addMenu(windowmenu);
00067 QAction *help_action = menubar->addAction("&Help");
00068 connect(help_action,SIGNAL(triggered()),this,SLOT(showHelp()));
00069
00070
00071 qvApp->registerGUI(this);
00072 }
00073
00074 void QVDefaultGUI::showHelp()
00075 {
00076 QDialog dialog;
00077 QString help_string = QVApplication::instance()->getHelp().trimmed();
00078 dialog.setWindowTitle("QVision help for " + qApp->applicationName());
00079 QVBoxLayout vboxlayout(&dialog);
00080 QTextEdit textedit;
00081 QFont font("Courier");
00082 textedit.setReadOnly(TRUE);
00083 textedit.setFont(font);
00084 textedit.setPlainText(help_string);
00085 QFontMetrics fontmetrics = textedit.font();
00086 int w = qMin(fontmetrics.size(0,help_string).width() + 30,800);
00087 int h = qMin(fontmetrics.size(0,help_string).height() + 30,500);
00088 textedit.setMinimumSize(QSize(w,h));
00089 vboxlayout.addWidget(&textedit);
00090 QPushButton button("OK");
00091 QHBoxLayout hboxlayout;
00092 hboxlayout.addStretch();
00093 hboxlayout.addWidget(&button);
00094 hboxlayout.addStretch();
00095 vboxlayout.addLayout(&hboxlayout);
00096 connect(&button,SIGNAL(pressed()),&dialog,SLOT(close()));
00097 dialog.exec();
00098 }
00099
00100 void QVDefaultGUI::init()
00101 {
00102 QVBoxLayout *groupboxcameraslayout,*groupboxblockslayout;
00103 QMenu *menu_imagecanvas = NULL, *menu_glcanvas = NULL, *menu_qvplot = NULL;
00104 bool some_block = FALSE, some_camera = FALSE;
00105
00106
00107 foreach(QVPropertyContainer* qvp, qvApp->getQVPropertyContainers())
00108 {
00109
00110 QVProcessingBlock* block;
00111 if(((block = dynamic_cast<QVProcessingBlock*>(qvp)) != NULL) and (dynamic_cast<QVVideoReaderBlock*>(qvp) == NULL))
00112 {
00113 if(not some_block)
00114 {
00115 some_block = TRUE;
00116 groupboxblocks = new QGroupBox("Blocks and windows",this);
00117 toolboxblocks = new QToolBox(groupboxblocks);
00118 }
00119 QVProcessingBlockInterfaceSmall *blockWidget = new QVProcessingBlockInterfaceSmall(block,this);
00120 QVParamsInspectorWidget *qvparamsinspectorwidget = new QVParamsInspectorWidget(block,this);
00121 QWidget *widget = new QWidget(this);
00122 QVBoxLayout *vboxlayout2 = new QVBoxLayout(widget);
00123 vboxlayout2->setSpacing(0);
00124 vboxlayout2->setMargin(0);
00125 vboxlayout2->addWidget(blockWidget);
00126 vboxlayout2->addWidget(qvparamsinspectorwidget);
00127 toolboxblocks->addItem(widget,block->getName());
00128
00129 continue;
00130 }
00131
00132 QVVideoReaderBlock* camera;
00133 if((camera = dynamic_cast<QVVideoReaderBlock*>(qvp)) != NULL)
00134 {
00135 if(not some_camera)
00136 {
00137 some_camera = TRUE;
00138 groupboxcameras = new QGroupBox("Cameras",this);
00139 groupboxcameras->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Fixed);
00140 toolboxcameras = new QToolBox(groupboxcameras);
00141 }
00142 QVVideoReaderBlockWidget *cameraWidget = new QVVideoReaderBlockWidget(camera,this);
00143 toolboxcameras->addItem(cameraWidget, camera->getName());
00144 continue;
00145 }
00146
00147 QVImageCanvas *imageCanvas;
00148 if((imageCanvas = dynamic_cast<QVImageCanvas*>(qvp)) != NULL)
00149 {
00150 if(menu_imagecanvas == NULL)
00151 menu_imagecanvas = windowmenu->addMenu("&Image windows");
00152 QAction *action = menu_imagecanvas->addAction(imageCanvas->getName());
00153 action->setCheckable(TRUE);
00154 action->setChecked(imageCanvas->isVisible());
00155 connect(action,SIGNAL(toggled(bool)),imageCanvas,SLOT(setVisible(bool)));
00156 connect(imageCanvas,SIGNAL(closed()),action,SLOT(toggle()));
00157
00158 if(not some_block)
00159 {
00160 some_block = TRUE;
00161 groupboxblocks = new QGroupBox("Blocks and windows",this);
00162 toolboxblocks = new QToolBox(groupboxblocks);
00163 }
00164 QVParamsInspectorWidget *qvparamsinspectorwidget = new QVParamsInspectorWidget(imageCanvas,this);
00165 QWidget *widget = new QWidget(this);
00166 QVBoxLayout *vboxlayout2 = new QVBoxLayout(widget);
00167 vboxlayout2->setSpacing(0);
00168 vboxlayout2->setMargin(0);
00169 vboxlayout2->addWidget(qvparamsinspectorwidget);
00170 toolboxblocks->addItem(widget,imageCanvas->getName());
00171
00172
00173 continue;
00174 }
00175 #ifdef GSL_AVAILABLE
00176
00177 QV3DCanvas *glCanvas;
00178 if((glCanvas = dynamic_cast<QV3DCanvas*>(qvp)) != NULL)
00179 {
00180 if(menu_glcanvas == NULL)
00181 menu_glcanvas = windowmenu->addMenu("&OpenGL windows");
00182 QAction *action = menu_glcanvas->addAction(glCanvas->getName());
00183 action->setCheckable(TRUE);
00184 action->setChecked(glCanvas->isVisible());
00185 connect(action,SIGNAL(toggled(bool)),glCanvas,SLOT(setVisible(bool)));
00186 connect(glCanvas,SIGNAL(closed()),action,SLOT(toggle()));
00187 continue;
00188 }
00189 #endif
00190
00191 QVPlot *qvplot;
00192 if((qvplot = dynamic_cast<QVPlot*>(qvp)) != NULL)
00193 {
00194 if(menu_qvplot == NULL)
00195 menu_qvplot = windowmenu->addMenu("&Plot windows");
00196 QAction *action = menu_qvplot->addAction(qvplot->getName());
00197 action->setCheckable(TRUE);
00198
00199
00200 action->setChecked(TRUE);
00201 connect(action,SIGNAL(toggled(bool)),qvplot,SLOT(setVisible(bool)));
00202 connect(qvplot,SIGNAL(closed()),action,SLOT(toggle()));
00203 continue;
00204 }
00205 }
00206
00207 vboxlayout->setSpacing(5);
00208 vboxlayout->setMargin(5);
00209 vboxlayout->addWidget(menubar);
00210
00211 if(some_block)
00212 {
00213 groupboxblockslayout = new QVBoxLayout(groupboxblocks);
00214 groupboxblockslayout->addWidget(toolboxblocks);
00215 vboxlayout->addWidget(groupboxblocks);
00216 }
00217
00218 if(some_camera)
00219 {
00220 groupboxcameraslayout = new QVBoxLayout(groupboxcameras);
00221 groupboxcameraslayout->addWidget(toolboxcameras);
00222 vboxlayout->addWidget(groupboxcameras);
00223 }
00224
00225 }
00226
00227 void QVDefaultGUI::show()
00228 {
00229 QWidget::show();
00230 }
00231
00232 void QVDefaultGUI::closeEvent(QCloseEvent *event)
00233 {
00234 Q_UNUSED(event);
00235 qvApp->deregisterGUI();
00236 emit closed();
00237 }