time_dock.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * time_dock.cpp - time dock
  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 "time_dock.h"
  19. #include "ui_time_dock.h"
  20. namespace studio {
  21. TimeDock::TimeDock(std::shared_ptr<core::Context> context_, QWidget* parent) :
  22. QDockWidget(parent),
  23. ContextListener(context_),
  24. ui(std::make_unique<Ui::TimeDock>()),
  25. destroy_detector(std::make_shared<Null>())
  26. {
  27. ui->setupUi(this);
  28. connect(ui->time_box, SIGNAL(editingFinished()), this, SLOT(change_time()));
  29. connect(ui->fps_box, SIGNAL(editingFinished()), this, SLOT(change_fps()));
  30. set_context(get_context());
  31. }
  32. TimeDock::~TimeDock() {
  33. }
  34. void TimeDock::time_changed(core::Time time) {
  35. set_time(time);
  36. }
  37. void TimeDock::fps_changed(core::Time::fps_type fps) {
  38. ui->fps_box->setValue(fps);
  39. }
  40. void TimeDock::closeEvent(QCloseEvent* event) {
  41. QDockWidget::closeEvent(event);
  42. deleteLater();
  43. }
  44. void TimeDock::change_time() {
  45. if (auto context = get_context())
  46. context->set_time(core::Time(0, context->get_fps(), ui->time_box->value()));
  47. }
  48. void TimeDock::change_fps() {
  49. if (auto context = get_context())
  50. context->set_fps(ui->fps_box->value());
  51. }
  52. void TimeDock::set_time(core::Time time) {
  53. ui->time_box->setValue(time.get_frames());
  54. }
  55. }