PageRenderTime 41ms CodeModel.GetById 23ms app.highlight 15ms RepoModel.GetById 2ms 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
  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
 27#include "llviewerprecompiledheaders.h"
 28#include "llpanelsnapshot.h"
 29
 30// libs
 31#include "llcombobox.h"
 32#include "llsliderctrl.h"
 33#include "llspinctrl.h"
 34#include "lltrans.h"
 35
 36// newview
 37#include "llsidetraypanelcontainer.h"
 38#include "llviewercontrol.h" // gSavedSettings
 39
 40// virtual
 41BOOL LLPanelSnapshot::postBuild()
 42{
 43	getChild<LLUICtrl>(getImageSizeComboName())->setCommitCallback(boost::bind(&LLPanelSnapshot::onResolutionComboCommit, this, _1));
 44	getChild<LLUICtrl>(getWidthSpinnerName())->setCommitCallback(boost::bind(&LLPanelSnapshot::onCustomResolutionCommit, this));
 45	getChild<LLUICtrl>(getHeightSpinnerName())->setCommitCallback(boost::bind(&LLPanelSnapshot::onCustomResolutionCommit, this));
 46	getChild<LLUICtrl>(getAspectRatioCBName())->setCommitCallback(boost::bind(&LLPanelSnapshot::onKeepAspectRatioCommit, this, _1));
 47
 48	updateControls(LLSD());
 49	return TRUE;
 50}
 51
 52// virtual
 53void LLPanelSnapshot::onOpen(const LLSD& key)
 54{
 55	S32 old_format = gSavedSettings.getS32("SnapshotFormat");
 56	S32 new_format = (S32) getImageFormat();
 57
 58	gSavedSettings.setS32("SnapshotFormat", new_format);
 59	setCtrlsEnabled(true);
 60
 61	// Switching panels will likely change image format.
 62	// Not updating preview right away may lead to errors,
 63	// e.g. attempt to send a large BMP image by email.
 64	if (old_format != new_format)
 65	{
 66		LLFloaterSnapshot::getInstance()->notify(LLSD().with("image-format-change", true));
 67	}
 68
 69	updateCustomResControls();
 70}
 71
 72LLFloaterSnapshot::ESnapshotFormat LLPanelSnapshot::getImageFormat() const
 73{
 74	return LLFloaterSnapshot::SNAPSHOT_FORMAT_JPEG;
 75}
 76
 77void LLPanelSnapshot::enableControls(BOOL enable)
 78{
 79	setCtrlsEnabled(enable);
 80	if (enable)
 81	{
 82		// Make sure only relevant controls are enabled/shown.
 83		updateCustomResControls();
 84	}
 85}
 86
 87LLSpinCtrl* LLPanelSnapshot::getWidthSpinner()
 88{
 89	return getChild<LLSpinCtrl>(getWidthSpinnerName());
 90}
 91
 92LLSpinCtrl* LLPanelSnapshot::getHeightSpinner()
 93{
 94	return getChild<LLSpinCtrl>(getHeightSpinnerName());
 95}
 96
 97S32 LLPanelSnapshot::getTypedPreviewWidth() const
 98{
 99	return getChild<LLUICtrl>(getWidthSpinnerName())->getValue().asInteger();
100}
101
102S32 LLPanelSnapshot::getTypedPreviewHeight() const
103{
104	return getChild<LLUICtrl>(getHeightSpinnerName())->getValue().asInteger();
105}
106
107void LLPanelSnapshot::enableAspectRatioCheckbox(BOOL enable)
108{
109	getChild<LLUICtrl>(getAspectRatioCBName())->setEnabled(enable);
110}
111
112LLSideTrayPanelContainer* LLPanelSnapshot::getParentContainer()
113{
114	LLSideTrayPanelContainer* parent = dynamic_cast<LLSideTrayPanelContainer*>(getParent());
115	if (!parent)
116	{
117		llwarns << "Cannot find panel container" << llendl;
118		return NULL;
119	}
120
121	return parent;
122}
123
124// virtual
125void LLPanelSnapshot::updateCustomResControls()
126{
127	// Only show width/height spinners and the aspect ratio checkbox
128	// when a custom resolution is chosen.
129	LLComboBox* combo = getChild<LLComboBox>(getImageSizeComboName());
130	const bool show = combo->getFirstSelectedIndex() == (combo->getItemCount() - 1);
131	getChild<LLUICtrl>(getImageSizePanelName())->setVisible(show);
132}
133
134void LLPanelSnapshot::updateImageQualityLevel()
135{
136	LLSliderCtrl* quality_slider = getChild<LLSliderCtrl>("image_quality_slider");
137	S32 quality_val = llfloor((F32) quality_slider->getValue().asReal());
138
139	std::string quality_lvl;
140
141	if (quality_val < 20)
142	{
143		quality_lvl = LLTrans::getString("snapshot_quality_very_low");
144	}
145	else if (quality_val < 40)
146	{
147		quality_lvl = LLTrans::getString("snapshot_quality_low");
148	}
149	else if (quality_val < 60)
150	{
151		quality_lvl = LLTrans::getString("snapshot_quality_medium");
152	}
153	else if (quality_val < 80)
154	{
155		quality_lvl = LLTrans::getString("snapshot_quality_high");
156	}
157	else
158	{
159		quality_lvl = LLTrans::getString("snapshot_quality_very_high");
160	}
161
162	getChild<LLTextBox>("image_quality_level")->setTextArg("[QLVL]", quality_lvl);
163}
164
165void LLPanelSnapshot::goBack()
166{
167	LLSideTrayPanelContainer* parent = getParentContainer();
168	if (parent)
169	{
170		parent->openPreviousPanel();
171		parent->getCurrentPanel()->onOpen(LLSD());
172	}
173}
174
175void LLPanelSnapshot::cancel()
176{
177	goBack();
178	LLFloaterSnapshot::getInstance()->notify(LLSD().with("set-ready", true));
179}
180
181void LLPanelSnapshot::onCustomResolutionCommit()
182{
183	LLSD info;
184	info["w"] = getChild<LLUICtrl>(getWidthSpinnerName())->getValue().asInteger();
185	info["h"] = getChild<LLUICtrl>(getHeightSpinnerName())->getValue().asInteger();
186	LLFloaterSnapshot::getInstance()->notify(LLSD().with("custom-res-change", info));
187}
188
189void LLPanelSnapshot::onResolutionComboCommit(LLUICtrl* ctrl)
190{
191	updateCustomResControls();
192
193	LLSD info;
194	info["combo-res-change"]["control-name"] = ctrl->getName();
195	LLFloaterSnapshot::getInstance()->notify(info);
196}
197
198void LLPanelSnapshot::onKeepAspectRatioCommit(LLUICtrl* ctrl)
199{
200	LLFloaterSnapshot::getInstance()->notify(LLSD().with("keep-aspect-change", ctrl->getValue().asBoolean()));
201}