point_editor.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * point_editor.cpp - 2d point editor widget
  3. * Copyright (C) 2017 caryoscelus
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <QLayout>
  19. #include "point_editor.h"
  20. #define MAX_POINT_COORD 10000
  21. namespace studio {
  22. PointEditor::PointEditor(QWidget* parent) :
  23. QWidget(parent),
  24. x_input(new QDoubleSpinBox()),
  25. y_input(new QDoubleSpinBox())
  26. {
  27. x_input->setRange(-MAX_POINT_COORD, +MAX_POINT_COORD);
  28. y_input->setRange(-MAX_POINT_COORD, +MAX_POINT_COORD);
  29. auto vlayout = new QVBoxLayout();
  30. vlayout->addWidget(x_input);
  31. vlayout->addWidget(y_input);
  32. setLayout(vlayout);
  33. connect(x_input, SIGNAL(editingFinished()), this, SLOT(write_x()));
  34. connect(y_input, SIGNAL(editingFinished()), this, SLOT(write_y()));
  35. }
  36. void PointEditor::setReadOnly(bool ro) {
  37. x_input->setReadOnly(ro);
  38. y_input->setReadOnly(ro);
  39. }
  40. void PointEditor::update_value(Geom::Point value_) {
  41. _value = value_;
  42. x_input->setValue(value_.x());
  43. y_input->setValue(value_.y());
  44. }
  45. void PointEditor::write_x() {
  46. _value.x() = x_input->value();
  47. Q_EMIT editingFinished();
  48. }
  49. void PointEditor::write_y() {
  50. _value.y() = y_input->value();
  51. Q_EMIT editingFinished();
  52. }
  53. } // namespace studio