CaptureWidget.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. #include "CaptureWidget.h"
  2. #include <qvariant.h>
  3. #include <qpushbutton.h>
  4. #include <q3buttongroup.h>
  5. #include <qradiobutton.h>
  6. #include <qcheckbox.h>
  7. #include <qlabel.h>
  8. #include <qlineedit.h>
  9. #include <qlayout.h>
  10. #include <qtooltip.h>
  11. #include <q3whatsthis.h>
  12. #include <qcombobox.h>
  13. //Added by qt3to4:
  14. #include <Q3HBoxLayout>
  15. #include <Q3VBoxLayout>
  16. namespace NICE {
  17. CaptureWidget::CaptureWidget(QWidget* parent, const char* name, Qt::WFlags fl)
  18. : QWidget(parent, name, fl) {
  19. if (name == NULL) {
  20. setName("CaptureWidget");
  21. }
  22. //setSizeGripEnabled( TRUE );
  23. CaptureWidgetLayout = new Q3VBoxLayout( this, 11, 6, "CaptureWidgetLayout");
  24. layout15 = new Q3HBoxLayout( 0, 0, 6, "layout15");
  25. textLabel1 = new QLabel( this, "textLabel1" );
  26. layout15->addWidget( textLabel1 );
  27. editFormat = new QComboBox( true, this, "editFormat" );
  28. editFormat->insertItem("ppm");
  29. editFormat->insertItem("pgm");
  30. editFormat->insertItem("png");
  31. editFormat->insertItem("jpg");
  32. QToolTip::add(editFormat,
  33. "Format specified by filename extension (without dot)");
  34. layout15->addWidget( editFormat );
  35. checkBuffered = new QCheckBox( this, "checkBuffered" );
  36. QToolTip::add(checkBuffered,
  37. "Buffer images in memory and write after capturing (stop)");
  38. layout15->addWidget( checkBuffered );
  39. buttonStart = new QPushButton( this, "buttonStart" );
  40. layout15->addWidget( buttonStart );
  41. buttonStop = new QPushButton( this, "buttonStop" );
  42. buttonStop->setEnabled( FALSE );
  43. layout15->addWidget( buttonStop );
  44. buttonCancel = new QPushButton( this, "buttonCancel" );
  45. buttonCancel->setAutoDefault( TRUE );
  46. buttonCancel->hide();
  47. layout15->addWidget( buttonCancel );
  48. //spacer5 = new QSpacerItem( 20, 44, QSizePolicy::Minimum, QSizePolicy::Expanding );
  49. //layout15->addItem( spacer5 );
  50. // layout15 = new QHBoxLayout( 0, 0, 6, "layout15");
  51. //
  52. // boxFormat = new QButtonGroup( this, "boxFormat" );
  53. // //boxFormat->setInsideMargin(0);
  54. // //boxFormat->setInsideSpacing(2);
  55. //
  56. // radioPPM = new QRadioButton( boxFormat, "radioPPM" );
  57. // radioPPM->setGeometry( QRect( 11, 26, 267, 25 ) );
  58. // radioPPM->setChecked( TRUE );
  59. //
  60. // radioJPG = new QRadioButton( boxFormat, "radioJPG" );
  61. // radioJPG->setGeometry( QRect( 11, 119, 267, 25 ) );
  62. //
  63. // radioPGM = new QRadioButton( boxFormat, "radioPGM" );
  64. // radioPGM->setGeometry( QRect( 11, 57, 267, 25 ) );
  65. //
  66. // radioPNG = new QRadioButton( boxFormat, "radioPNG" );
  67. // radioPNG->setGeometry( QRect( 11, 88, 267, 25 ) );
  68. // layout15->addWidget( boxFormat );
  69. //
  70. // layout14 = new QVBoxLayout( 0, 0, 6, "layout14");
  71. //
  72. // buttonStart = new QPushButton( this, "buttonStart" );
  73. // layout14->addWidget( buttonStart );
  74. //
  75. // buttonStop = new QPushButton( this, "buttonStop" );
  76. // buttonStop->setEnabled( FALSE );
  77. // layout14->addWidget( buttonStop );
  78. //
  79. // buttonCancel = new QPushButton( this, "buttonCancel" );
  80. // buttonCancel->setAutoDefault( TRUE );
  81. // buttonCancel->hide();
  82. // layout14->addWidget( buttonCancel );
  83. // spacer5 = new QSpacerItem( 20, 44, QSizePolicy::Minimum, QSizePolicy::Expanding );
  84. // layout14->addItem( spacer5 );
  85. //
  86. // checkBuffered = new QCheckBox( this, "checkBuffered" );
  87. // layout14->addWidget( checkBuffered );
  88. // layout15->addLayout( layout14 );
  89. CaptureWidgetLayout->addLayout( layout15 );
  90. layout11 = new Q3HBoxLayout( 0, 0, 6, "layout11");
  91. textLabel2 = new QLabel( this, "textLabel2" );
  92. layout11->addWidget( textLabel2 );
  93. editDirectory = new QLineEdit( this, "editDirectory" );
  94. layout11->addWidget( editDirectory );
  95. buttonBrowse = new QPushButton( this, "buttonBrowse" );
  96. layout11->addWidget( buttonBrowse );
  97. CaptureWidgetLayout->addLayout( layout11 );
  98. buttonBrowse->setFlat(true);
  99. QSize size = buttonBrowse->size();
  100. size.setHeight(editDirectory->size().height() - 5);
  101. size.setWidth(20);//buttonBrowse->size().width() - 20);
  102. buttonBrowse->setMaximumSize(size);
  103. buttonBrowse->setMinimumSize(size);
  104. buttonBrowse->resize(size);
  105. languageChange();
  106. resize( QSize(542, 253).expandedTo(minimumSizeHint()) );
  107. // clearWState( WState_Polished ); // Qt4
  108. // signals and slots connections
  109. // connect(buttonCancel, SIGNAL(clicked()),
  110. // this, SLOT(buttonCancelClicked()));
  111. connect(buttonCancel, SIGNAL(clicked()),
  112. this, SIGNAL(cancelled()));
  113. connect(buttonBrowse, SIGNAL(clicked()),
  114. this, SLOT(buttonBrowseClicked()));
  115. connect(buttonStart, SIGNAL(clicked()),
  116. this, SLOT(buttonStartClicked()));
  117. connect(buttonStop, SIGNAL(clicked()),
  118. this, SLOT(buttonStopClicked()));
  119. }
  120. void CaptureWidget::showCancelButton() {
  121. buttonCancel->show();
  122. }
  123. /*
  124. * Destroys the object and frees any allocated resources
  125. */
  126. CaptureWidget::~CaptureWidget()
  127. {
  128. // no need to delete child widgets, Qt does it all for us
  129. }
  130. /*
  131. * Sets the strings of the subwidgets using the current
  132. * language.
  133. */
  134. void CaptureWidget::languageChange()
  135. {
  136. setCaption( tr( "Capture Image Sequence" ) );
  137. // boxFormat->setTitle( tr( "Image file format" ) );
  138. // radioPPM->setText( tr( "PPM" ) );
  139. // radioJPG->setText( tr( "JPEG" ) );
  140. // radioPGM->setText( tr( "PGM (gray)" ) );
  141. // radioPNG->setText( tr( "PNG" ) );
  142. buttonStart->setText( tr( "Start" ) );
  143. buttonStop->setText( tr( "Stop" ) );
  144. buttonCancel->setText( tr( "&Cancel" ) );
  145. buttonCancel->setAccel( QKeySequence( QString::null ) );
  146. checkBuffered->setText( tr( "Buffer" ) );
  147. textLabel1->setText( tr( "Format" ) );
  148. textLabel2->setText( tr( "Directory" ) );
  149. buttonBrowse->setText( tr( "..." ) );
  150. }
  151. #include <q3filedialog.h>
  152. void CaptureWidget::buttonBrowseClicked()
  153. {
  154. Q3FileDialog dialog("",
  155. "",
  156. this,
  157. "Save to directory dialog");
  158. dialog.setCaption("Choose an output directory");
  159. dialog.setMode(Q3FileDialog::AnyFile); // QFileDialog::DirectoryOnly
  160. if (dialog.exec() == QDialog::Accepted) {
  161. editDirectory->setText(dialog.selectedFile());
  162. }
  163. }
  164. void CaptureWidget::buttonStartClicked()
  165. {
  166. if (!isCapturing()) {
  167. if (directoryName().size() == 0) {
  168. return;
  169. }
  170. enableGUI(false);
  171. emit(started());
  172. }
  173. }
  174. void CaptureWidget::buttonStopClicked()
  175. {
  176. if (isCapturing()) {
  177. enableGUI(true);
  178. emit(stopped());
  179. }
  180. }
  181. void CaptureWidget::enableGUI(bool enable)
  182. {
  183. const bool value = enable;
  184. buttonStart->setEnabled(value);
  185. buttonCancel->setEnabled(value);
  186. editDirectory->setEnabled(value);
  187. buttonBrowse->setEnabled(value);
  188. checkBuffered->setEnabled(value);
  189. // boxFormat->setEnabled(value);
  190. buttonStop->setEnabled(!value);
  191. }
  192. std::string CaptureWidget::directoryName()
  193. {
  194. return std::string(editDirectory->text().local8Bit());
  195. }
  196. bool CaptureWidget::isBuffered() {
  197. return checkBuffered->isChecked();
  198. }
  199. std::string CaptureWidget::extensionName()
  200. {
  201. // if (radioPPM->isChecked()) {
  202. // return ".ppm";
  203. // } else if (radioPGM->isChecked()) {
  204. // return ".pgm";
  205. // } else if (radioPNG->isChecked()) {
  206. // return ".png";
  207. // } else if (radioJPG->isChecked()) {
  208. // return ".jpg";
  209. // } else {
  210. // return ".ppm";
  211. // }
  212. return "." + std::string(editFormat->currentText().local8Bit());
  213. }
  214. bool CaptureWidget::isCapturing() {
  215. return buttonStop->isEnabled();
  216. }
  217. void CaptureWidget::setDirectoryName(const std::string& dir) {
  218. editDirectory->setText(dir.c_str());
  219. }
  220. void CaptureWidget::setExtensionName(const std::string& ext) {
  221. editFormat->setCurrentText(ext.c_str());
  222. }
  223. void CaptureWidget::setBuffered(bool buffer) {
  224. checkBuffered->setChecked(buffer);
  225. }
  226. }