point_value_editor.cpp 1.9 KB

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