PageRenderTime 30ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llpanelsnapshot.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 201 lines | 136 code | 29 blank | 36 comment | 13 complexity | 1cc7b108ce025923933a8083310a3a6d MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpanelsnapshot.cpp
  3. * @brief Snapshot panel base class
  4. *
  5. * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2011, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llpanelsnapshot.h"
  28. // libs
  29. #include "llcombobox.h"
  30. #include "llsliderctrl.h"
  31. #include "llspinctrl.h"
  32. #include "lltrans.h"
  33. // newview
  34. #include "llsidetraypanelcontainer.h"
  35. #include "llviewercontrol.h" // gSavedSettings
  36. // virtual
  37. BOOL LLPanelSnapshot::postBuild()
  38. {
  39. getChild<LLUICtrl>(getImageSizeComboName())->setCommitCallback(boost::bind(&LLPanelSnapshot::onResolutionComboCommit, this, _1));
  40. getChild<LLUICtrl>(getWidthSpinnerName())->setCommitCallback(boost::bind(&LLPanelSnapshot::onCustomResolutionCommit, this));
  41. getChild<LLUICtrl>(getHeightSpinnerName())->setCommitCallback(boost::bind(&LLPanelSnapshot::onCustomResolutionCommit, this));
  42. getChild<LLUICtrl>(getAspectRatioCBName())->setCommitCallback(boost::bind(&LLPanelSnapshot::onKeepAspectRatioCommit, this, _1));
  43. updateControls(LLSD());
  44. return TRUE;
  45. }
  46. // virtual
  47. void LLPanelSnapshot::onOpen(const LLSD& key)
  48. {
  49. S32 old_format = gSavedSettings.getS32("SnapshotFormat");
  50. S32 new_format = (S32) getImageFormat();
  51. gSavedSettings.setS32("SnapshotFormat", new_format);
  52. setCtrlsEnabled(true);
  53. // Switching panels will likely change image format.
  54. // Not updating preview right away may lead to errors,
  55. // e.g. attempt to send a large BMP image by email.
  56. if (old_format != new_format)
  57. {
  58. LLFloaterSnapshot::getInstance()->notify(LLSD().with("image-format-change", true));
  59. }
  60. updateCustomResControls();
  61. }
  62. LLFloaterSnapshot::ESnapshotFormat LLPanelSnapshot::getImageFormat() const
  63. {
  64. return LLFloaterSnapshot::SNAPSHOT_FORMAT_JPEG;
  65. }
  66. void LLPanelSnapshot::enableControls(BOOL enable)
  67. {
  68. setCtrlsEnabled(enable);
  69. if (enable)
  70. {
  71. // Make sure only relevant controls are enabled/shown.
  72. updateCustomResControls();
  73. }
  74. }
  75. LLSpinCtrl* LLPanelSnapshot::getWidthSpinner()
  76. {
  77. return getChild<LLSpinCtrl>(getWidthSpinnerName());
  78. }
  79. LLSpinCtrl* LLPanelSnapshot::getHeightSpinner()
  80. {
  81. return getChild<LLSpinCtrl>(getHeightSpinnerName());
  82. }
  83. S32 LLPanelSnapshot::getTypedPreviewWidth() const
  84. {
  85. return getChild<LLUICtrl>(getWidthSpinnerName())->getValue().asInteger();
  86. }
  87. S32 LLPanelSnapshot::getTypedPreviewHeight() const
  88. {
  89. return getChild<LLUICtrl>(getHeightSpinnerName())->getValue().asInteger();
  90. }
  91. void LLPanelSnapshot::enableAspectRatioCheckbox(BOOL enable)
  92. {
  93. getChild<LLUICtrl>(getAspectRatioCBName())->setEnabled(enable);
  94. }
  95. LLSideTrayPanelContainer* LLPanelSnapshot::getParentContainer()
  96. {
  97. LLSideTrayPanelContainer* parent = dynamic_cast<LLSideTrayPanelContainer*>(getParent());
  98. if (!parent)
  99. {
  100. llwarns << "Cannot find panel container" << llendl;
  101. return NULL;
  102. }
  103. return parent;
  104. }
  105. // virtual
  106. void LLPanelSnapshot::updateCustomResControls()
  107. {
  108. // Only show width/height spinners and the aspect ratio checkbox
  109. // when a custom resolution is chosen.
  110. LLComboBox* combo = getChild<LLComboBox>(getImageSizeComboName());
  111. const bool show = combo->getFirstSelectedIndex() == (combo->getItemCount() - 1);
  112. getChild<LLUICtrl>(getImageSizePanelName())->setVisible(show);
  113. }
  114. void LLPanelSnapshot::updateImageQualityLevel()
  115. {
  116. LLSliderCtrl* quality_slider = getChild<LLSliderCtrl>("image_quality_slider");
  117. S32 quality_val = llfloor((F32) quality_slider->getValue().asReal());
  118. std::string quality_lvl;
  119. if (quality_val < 20)
  120. {
  121. quality_lvl = LLTrans::getString("snapshot_quality_very_low");
  122. }
  123. else if (quality_val < 40)
  124. {
  125. quality_lvl = LLTrans::getString("snapshot_quality_low");
  126. }
  127. else if (quality_val < 60)
  128. {
  129. quality_lvl = LLTrans::getString("snapshot_quality_medium");
  130. }
  131. else if (quality_val < 80)
  132. {
  133. quality_lvl = LLTrans::getString("snapshot_quality_high");
  134. }
  135. else
  136. {
  137. quality_lvl = LLTrans::getString("snapshot_quality_very_high");
  138. }
  139. getChild<LLTextBox>("image_quality_level")->setTextArg("[QLVL]", quality_lvl);
  140. }
  141. void LLPanelSnapshot::goBack()
  142. {
  143. LLSideTrayPanelContainer* parent = getParentContainer();
  144. if (parent)
  145. {
  146. parent->openPreviousPanel();
  147. parent->getCurrentPanel()->onOpen(LLSD());
  148. }
  149. }
  150. void LLPanelSnapshot::cancel()
  151. {
  152. goBack();
  153. LLFloaterSnapshot::getInstance()->notify(LLSD().with("set-ready", true));
  154. }
  155. void LLPanelSnapshot::onCustomResolutionCommit()
  156. {
  157. LLSD info;
  158. info["w"] = getChild<LLUICtrl>(getWidthSpinnerName())->getValue().asInteger();
  159. info["h"] = getChild<LLUICtrl>(getHeightSpinnerName())->getValue().asInteger();
  160. LLFloaterSnapshot::getInstance()->notify(LLSD().with("custom-res-change", info));
  161. }
  162. void LLPanelSnapshot::onResolutionComboCommit(LLUICtrl* ctrl)
  163. {
  164. updateCustomResControls();
  165. LLSD info;
  166. info["combo-res-change"]["control-name"] = ctrl->getName();
  167. LLFloaterSnapshot::getInstance()->notify(info);
  168. }
  169. void LLPanelSnapshot::onKeepAspectRatioCommit(LLUICtrl* ctrl)
  170. {
  171. LLFloaterSnapshot::getInstance()->notify(LLSD().with("keep-aspect-change", ctrl->getValue().asBoolean()));
  172. }