OptionsForm.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * ImageDescriptionForm.cpp
  3. *
  4. * Created on: Oct 11, 2011
  5. * Author: Gapchich Vlad
  6. */
  7. #include "OptionsForm.h"
  8. #include <QCheckBox>
  9. #include <QPushButton>
  10. #include <QLabel>
  11. #include <QLineEdit>
  12. #include <QBoxLayout>
  13. #include <QMessageBox>
  14. #include <QApplication>
  15. #include <QDesktopWidget>
  16. #include <QFileDialog>
  17. #include <QKeyEvent>
  18. OptionsForm::OptionsForm(QWidget *aParent)
  19. : QWidget(aParent)
  20. {
  21. setWindowTitle(tr("Options"));
  22. PASCALpath_ = 0;
  23. layout_v_ = new QVBoxLayout(this);
  24. layout_PASCAL_root_ = new QHBoxLayout;
  25. layout_h_ = new QHBoxLayout;
  26. auto_color_generation_ = new QCheckBox(this);
  27. auto_color_generation_->setText(tr("Automatic label color generation"));
  28. button_set_PASCAL_root_ = new QPushButton(this);
  29. button_set_PASCAL_root_->setText(tr("set PASCAL root path"));
  30. edit_PASCAL_root_ = new QLineEdit("", this);
  31. button_ok_ = new QPushButton(this);
  32. button_ok_->setText(tr("OK"));
  33. button_cancel_ = new QPushButton(this);
  34. button_cancel_->setText(tr("Cancel"));
  35. layout_v_->addWidget(auto_color_generation_);
  36. layout_v_->addLayout(layout_PASCAL_root_);
  37. layout_v_->addLayout(layout_h_);
  38. layout_PASCAL_root_->addWidget(button_set_PASCAL_root_);
  39. layout_PASCAL_root_->addWidget(edit_PASCAL_root_);
  40. layout_h_->addWidget(button_ok_);
  41. layout_h_->addWidget(button_cancel_);
  42. connect(
  43. button_set_PASCAL_root_,
  44. SIGNAL(clicked()),
  45. this,
  46. SLOT(newPascalPath())
  47. );
  48. connect(
  49. button_ok_,
  50. SIGNAL(clicked()),
  51. this,
  52. SLOT(setOptions())
  53. );
  54. connect(
  55. button_cancel_,
  56. SIGNAL(clicked()),
  57. this,
  58. SLOT(hide())
  59. );
  60. adjustSize();
  61. move(QApplication::desktop()->screen()->rect().center() - rect().center());
  62. }
  63. OptionsForm::~OptionsForm()
  64. {
  65. delete auto_color_generation_;
  66. delete button_set_PASCAL_root_;
  67. delete edit_PASCAL_root_;
  68. delete button_ok_;
  69. delete button_cancel_;
  70. delete layout_v_;
  71. }
  72. void
  73. OptionsForm::setOptions()
  74. {
  75. emit optionsSet();
  76. hide();
  77. }
  78. void
  79. OptionsForm::setPASCALpath(QString *aPath)
  80. {
  81. if (!aPath) {
  82. return;
  83. /* NOTREACHED */
  84. }
  85. PASCALpath_ = aPath;
  86. }
  87. void
  88. OptionsForm::newPascalPath()
  89. {
  90. QString newPath;
  91. QFileDialog fileDialog(0, tr("root directory for the PASCAL files"));
  92. fileDialog.setFileMode(QFileDialog::Directory);
  93. if (fileDialog.exec())
  94. newPath = fileDialog.selectedFiles().last();
  95. else {
  96. return;
  97. /* NOTREACHED */
  98. }
  99. if (newPath.isEmpty()) {
  100. return;
  101. /* NOTREACHED */
  102. }
  103. *PASCALpath_ = newPath;
  104. edit_PASCAL_root_->setText(newPath);
  105. }
  106. bool
  107. OptionsForm::autoColorGeneration()
  108. {
  109. return auto_color_generation_->isChecked();
  110. }
  111. void
  112. OptionsForm::setAutoColorGeneration(bool flag)
  113. {
  114. auto_color_generation_->setChecked(flag);
  115. }
  116. void
  117. OptionsForm::showOptions()
  118. {
  119. if (!PASCALpath_) {
  120. return;
  121. /* NOTREACHED */
  122. }
  123. if (PASCALpath_->isEmpty())
  124. edit_PASCAL_root_->setText(tr("root path is not set yet"));
  125. else
  126. edit_PASCAL_root_->setText(*PASCALpath_);
  127. adjustSize();
  128. show();
  129. }
  130. void
  131. OptionsForm::keyPressEvent(QKeyEvent *anEvent)
  132. {
  133. if ((Qt::Key_Enter == anEvent->key() ||
  134. Qt::Key_Return == anEvent->key())) {
  135. setOptions();
  136. }
  137. }
  138. /*
  139. *
  140. */