PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llpanelsnapshotlocal.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 168 lines | 110 code | 25 blank | 33 comment | 12 complexity | 6450c2affeeae1a930cd66944739dcd4 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpanelsnapshotlocal.cpp
  3. * @brief The panel provides UI for saving snapshot to a local folder.
  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 "llcombobox.h"
  28. #include "llsidetraypanelcontainer.h"
  29. #include "llsliderctrl.h"
  30. #include "llspinctrl.h"
  31. #include "llfloatersnapshot.h" // FIXME: replace with a snapshot storage model
  32. #include "llpanelsnapshot.h"
  33. #include "llviewercontrol.h" // gSavedSettings
  34. #include "llviewerwindow.h"
  35. /**
  36. * The panel provides UI for saving snapshot to a local folder.
  37. */
  38. class LLPanelSnapshotLocal
  39. : public LLPanelSnapshot
  40. {
  41. LOG_CLASS(LLPanelSnapshotLocal);
  42. public:
  43. LLPanelSnapshotLocal();
  44. /*virtual*/ BOOL postBuild();
  45. /*virtual*/ void onOpen(const LLSD& key);
  46. private:
  47. /*virtual*/ std::string getWidthSpinnerName() const { return "local_snapshot_width"; }
  48. /*virtual*/ std::string getHeightSpinnerName() const { return "local_snapshot_height"; }
  49. /*virtual*/ std::string getAspectRatioCBName() const { return "local_keep_aspect_check"; }
  50. /*virtual*/ std::string getImageSizeComboName() const { return "local_size_combo"; }
  51. /*virtual*/ std::string getImageSizePanelName() const { return "local_image_size_lp"; }
  52. /*virtual*/ LLFloaterSnapshot::ESnapshotFormat getImageFormat() const;
  53. /*virtual*/ void updateControls(const LLSD& info);
  54. void onFormatComboCommit(LLUICtrl* ctrl);
  55. void onQualitySliderCommit(LLUICtrl* ctrl);
  56. void onSaveFlyoutCommit(LLUICtrl* ctrl);
  57. };
  58. static LLRegisterPanelClassWrapper<LLPanelSnapshotLocal> panel_class("llpanelsnapshotlocal");
  59. LLPanelSnapshotLocal::LLPanelSnapshotLocal()
  60. {
  61. mCommitCallbackRegistrar.add("Local.Cancel", boost::bind(&LLPanelSnapshotLocal::cancel, this));
  62. }
  63. // virtual
  64. BOOL LLPanelSnapshotLocal::postBuild()
  65. {
  66. getChild<LLUICtrl>("image_quality_slider")->setCommitCallback(boost::bind(&LLPanelSnapshotLocal::onQualitySliderCommit, this, _1));
  67. getChild<LLUICtrl>("local_format_combo")->setCommitCallback(boost::bind(&LLPanelSnapshotLocal::onFormatComboCommit, this, _1));
  68. getChild<LLUICtrl>("save_btn")->setCommitCallback(boost::bind(&LLPanelSnapshotLocal::onSaveFlyoutCommit, this, _1));
  69. return LLPanelSnapshot::postBuild();
  70. }
  71. // virtual
  72. void LLPanelSnapshotLocal::onOpen(const LLSD& key)
  73. {
  74. LLPanelSnapshot::onOpen(key);
  75. }
  76. // virtual
  77. LLFloaterSnapshot::ESnapshotFormat LLPanelSnapshotLocal::getImageFormat() const
  78. {
  79. LLFloaterSnapshot::ESnapshotFormat fmt = LLFloaterSnapshot::SNAPSHOT_FORMAT_PNG;
  80. LLComboBox* local_format_combo = getChild<LLComboBox>("local_format_combo");
  81. const std::string id = local_format_combo->getValue().asString();
  82. if (id == "PNG")
  83. {
  84. fmt = LLFloaterSnapshot::SNAPSHOT_FORMAT_PNG;
  85. }
  86. else if (id == "JPEG")
  87. {
  88. fmt = LLFloaterSnapshot::SNAPSHOT_FORMAT_JPEG;
  89. }
  90. else if (id == "BMP")
  91. {
  92. fmt = LLFloaterSnapshot::SNAPSHOT_FORMAT_BMP;
  93. }
  94. return fmt;
  95. }
  96. // virtual
  97. void LLPanelSnapshotLocal::updateControls(const LLSD& info)
  98. {
  99. LLFloaterSnapshot::ESnapshotFormat fmt =
  100. (LLFloaterSnapshot::ESnapshotFormat) gSavedSettings.getS32("SnapshotFormat");
  101. getChild<LLComboBox>("local_format_combo")->selectNthItem((S32) fmt);
  102. const bool show_quality_ctrls = (fmt == LLFloaterSnapshot::SNAPSHOT_FORMAT_JPEG);
  103. getChild<LLUICtrl>("image_quality_slider")->setVisible(show_quality_ctrls);
  104. getChild<LLUICtrl>("image_quality_level")->setVisible(show_quality_ctrls);
  105. getChild<LLUICtrl>("image_quality_slider")->setValue(gSavedSettings.getS32("SnapshotQuality"));
  106. updateImageQualityLevel();
  107. const bool have_snapshot = info.has("have-snapshot") ? info["have-snapshot"].asBoolean() : true;
  108. getChild<LLUICtrl>("save_btn")->setEnabled(have_snapshot);
  109. }
  110. void LLPanelSnapshotLocal::onFormatComboCommit(LLUICtrl* ctrl)
  111. {
  112. // will call updateControls()
  113. LLFloaterSnapshot::getInstance()->notify(LLSD().with("image-format-change", true));
  114. }
  115. void LLPanelSnapshotLocal::onQualitySliderCommit(LLUICtrl* ctrl)
  116. {
  117. updateImageQualityLevel();
  118. LLSliderCtrl* slider = (LLSliderCtrl*)ctrl;
  119. S32 quality_val = llfloor((F32)slider->getValue().asReal());
  120. LLSD info;
  121. info["image-quality-change"] = quality_val;
  122. LLFloaterSnapshot::getInstance()->notify(info);
  123. }
  124. void LLPanelSnapshotLocal::onSaveFlyoutCommit(LLUICtrl* ctrl)
  125. {
  126. if (ctrl->getValue().asString() == "save as")
  127. {
  128. gViewerWindow->resetSnapshotLoc();
  129. }
  130. LLFloaterSnapshot* floater = LLFloaterSnapshot::getInstance();
  131. floater->notify(LLSD().with("set-working", true));
  132. BOOL saved = LLFloaterSnapshot::saveLocal();
  133. if (saved)
  134. {
  135. LLFloaterSnapshot::postSave();
  136. goBack();
  137. floater->notify(LLSD().with("set-finished", LLSD().with("ok", true).with("msg", "local")));
  138. }
  139. else
  140. {
  141. cancel();
  142. }
  143. }