OBSPreviewScalingLabel.cpp 3.4 KB

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