LineEditForm.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * LineEditForm.cpp
  3. *
  4. * Created on: Oct 6, 2011
  5. * Author: Gapchich Vlad
  6. */
  7. #include "LineEditForm.h"
  8. #include <QLineEdit>
  9. #include <QPushButton>
  10. #include <QBoxLayout>
  11. #include <QMessageBox>
  12. #include <QApplication>
  13. #include <QDesktopWidget>
  14. #include <QKeyEvent>
  15. LineEditForm::LineEditForm(QWidget *aParent)
  16. : QWidget(aParent)
  17. {
  18. //setWindowTitle(tr("Image Description"));
  19. purpose_ = NoPurpose;
  20. layout_v_ = new QVBoxLayout(this);
  21. layout_h_ = new QHBoxLayout;
  22. data_ = new QLineEdit(this);
  23. button_ok_ = new QPushButton(this);
  24. button_ok_->setText(tr("OK"));
  25. button_cancel_ = new QPushButton(this);
  26. button_cancel_->setText(tr("Cancel"));
  27. layout_v_->addWidget(data_);
  28. layout_v_->addLayout(layout_h_);
  29. layout_h_->addWidget(button_ok_);
  30. layout_h_->addWidget(button_cancel_);
  31. connect(
  32. button_ok_,
  33. SIGNAL(clicked()),
  34. this,
  35. SLOT(setData())
  36. );
  37. connect(
  38. button_cancel_,
  39. SIGNAL(clicked()),
  40. this,
  41. SLOT(hide())
  42. );
  43. adjustSize();
  44. move(QApplication::desktop()->screen()->rect().center() - rect().center());
  45. }
  46. LineEditForm::~LineEditForm()
  47. {
  48. delete data_;
  49. delete button_ok_;
  50. delete button_cancel_;
  51. delete layout_v_;
  52. }
  53. void
  54. LineEditForm::setData()
  55. {
  56. if (!data_->text().isEmpty()) {
  57. emit dataSet(data_->text());
  58. hide();
  59. }
  60. else
  61. QMessageBox::warning(
  62. this,
  63. tr("Warning!"),
  64. tr("Image description is empty"),
  65. QMessageBox::Ok,
  66. QMessageBox::Cancel
  67. );
  68. }
  69. void
  70. LineEditForm::setDescription()
  71. {
  72. data_->clear();
  73. purpose_ = ImageDescriptionPurpose;
  74. setWindowTitle(tr("Image Description"));
  75. show();
  76. }
  77. void
  78. LineEditForm::setTags()
  79. {
  80. data_->clear();
  81. purpose_ = TaggingPurpose;
  82. setWindowTitle(tr("Tagging"));
  83. show();
  84. }
  85. FormPurpose
  86. LineEditForm::purpose()
  87. {
  88. return purpose_;
  89. }
  90. void
  91. LineEditForm::keyPressEvent(QKeyEvent *anEvent)
  92. {
  93. if ((Qt::Key_Enter == anEvent->key() ||
  94. Qt::Key_Return == anEvent->key())) {
  95. setData();
  96. }
  97. }
  98. /*
  99. *
  100. */