OBSPreviewScalingComboBox.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /******************************************************************************
  2. Copyright (C) 2024 by Taylor Giampaolo <[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 "OBSPreviewScalingComboBox.hpp"
  15. #include <OBSApp.hpp>
  16. #include "moc_OBSPreviewScalingComboBox.cpp"
  17. void OBSPreviewScalingComboBox::PreviewFixedScalingChanged(bool fixed)
  18. {
  19. if (fixedScaling == fixed)
  20. return;
  21. fixedScaling = fixed;
  22. UpdateSelection();
  23. }
  24. void OBSPreviewScalingComboBox::CanvasResized(uint32_t width, uint32_t height)
  25. {
  26. SetCanvasSize(width, height);
  27. UpdateCanvasText();
  28. }
  29. void OBSPreviewScalingComboBox::OutputResized(uint32_t width, uint32_t height)
  30. {
  31. SetOutputSize(width, height);
  32. bool canvasMatchesOutput = output_width == canvas_width && output_height == canvas_height;
  33. SetScaleOutputEnabled(!canvasMatchesOutput);
  34. UpdateOutputText();
  35. }
  36. void OBSPreviewScalingComboBox::PreviewScaleChanged(float scale)
  37. {
  38. previewScale = scale;
  39. if (fixedScaling) {
  40. UpdateSelection();
  41. UpdateAllText();
  42. } else {
  43. UpdateScaledText();
  44. }
  45. }
  46. void OBSPreviewScalingComboBox::SetScaleOutputEnabled(bool show)
  47. {
  48. if (scaleOutputEnabled == show)
  49. return;
  50. scaleOutputEnabled = show;
  51. if (scaleOutputEnabled) {
  52. addItem(QTStr("Basic.MainMenu.Edit.Scale.Output"));
  53. } else {
  54. removeItem(2);
  55. }
  56. }
  57. void OBSPreviewScalingComboBox::UpdateAllText()
  58. {
  59. UpdateCanvasText();
  60. UpdateOutputText();
  61. UpdateScaledText();
  62. }
  63. void OBSPreviewScalingComboBox::UpdateCanvasText()
  64. {
  65. QString text = QTStr("Basic.MainMenu.Edit.Scale.Canvas");
  66. text = text.arg(QString::number(canvas_width), QString::number(canvas_height));
  67. setItemText(1, text);
  68. }
  69. void OBSPreviewScalingComboBox::UpdateOutputText()
  70. {
  71. if (scaleOutputEnabled) {
  72. QString text = QTStr("Basic.MainMenu.Edit.Scale.Output");
  73. text = text.arg(QString::number(output_width), QString::number(output_height));
  74. setItemText(2, text);
  75. }
  76. }
  77. void OBSPreviewScalingComboBox::UpdateScaledText()
  78. {
  79. QString text = QTStr("Basic.MainMenu.Edit.Scale.Manual");
  80. text = text.arg(QString::number(floor(canvas_width * previewScale)),
  81. QString::number(floor(canvas_height * previewScale)));
  82. setPlaceholderText(text);
  83. }
  84. void OBSPreviewScalingComboBox::UpdateSelection()
  85. {
  86. QSignalBlocker sb(this);
  87. float outputScale = float(output_width) / float(canvas_width);
  88. if (!fixedScaling) {
  89. setCurrentIndex(0);
  90. } else {
  91. if (previewScale == 1.0f) {
  92. setCurrentIndex(1);
  93. } else if (scaleOutputEnabled && (previewScale == outputScale)) {
  94. setCurrentIndex(2);
  95. } else {
  96. setCurrentIndex(-1);
  97. }
  98. }
  99. }