OptionsForm.cpp 2.9 KB

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