1
0

OBSSourceLabel.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /******************************************************************************
  2. Copyright (C) 2015 by Ruwen Hahn <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "OBSSourceLabel.hpp"
  15. #include "moc_OBSSourceLabel.cpp"
  16. OBSSourceLabel::OBSSourceLabel(const obs_source_t *source, QWidget *parent, Qt::WindowFlags f)
  17. : QLabel(obs_source_get_name(source), parent, f),
  18. renamedSignal(obs_source_get_signal_handler(source), "rename", &OBSSourceLabel::obsSourceRenamed, this),
  19. removedSignal(obs_source_get_signal_handler(source), "remove", &OBSSourceLabel::obsSourceRemoved, this),
  20. destroyedSignal(obs_source_get_signal_handler(source), "destroy", &OBSSourceLabel::obsSourceDestroyed, this)
  21. {
  22. }
  23. void OBSSourceLabel::obsSourceRenamed(void *data, calldata_t *params)
  24. {
  25. auto &label = *static_cast<OBSSourceLabel *>(data);
  26. const char *name = calldata_string(params, "new_name");
  27. label.setText(name);
  28. emit label.renamed(name);
  29. }
  30. void OBSSourceLabel::obsSourceRemoved(void *data, calldata_t *)
  31. {
  32. auto &label = *static_cast<OBSSourceLabel *>(data);
  33. emit label.removed();
  34. }
  35. void OBSSourceLabel::obsSourceDestroyed(void *data, calldata_t *)
  36. {
  37. auto &label = *static_cast<OBSSourceLabel *>(data);
  38. emit label.destroyed();
  39. label.destroyedSignal.Disconnect();
  40. label.removedSignal.Disconnect();
  41. label.renamedSignal.Disconnect();
  42. }
  43. void OBSSourceLabel::mousePressEvent(QMouseEvent *event)
  44. {
  45. emit clicked();
  46. QLabel::mousePressEvent(event);
  47. }