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