PageRenderTime 983ms CodeModel.GetById 526ms app.highlight 152ms RepoModel.GetById 184ms app.codeStats 0ms

/indra/newview/lltoastpanel.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 115 lines | 56 code | 16 blank | 43 comment | 8 complexity | 2f8c758b8fa5bab4b312cf5580ac5cb0 MD5 | raw file
  1/** 
  2 * @file lltoastpanel.cpp
  3 * @brief Creates a panel of a specific kind for a toast
  4 *
  5 * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, 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 "llpanelgenerictip.h"
 30#include "llpanelonlinestatus.h"
 31#include "llnotifications.h"
 32#include "lltoastpanel.h"
 33
 34//static
 35const S32 LLToastPanel::MIN_PANEL_HEIGHT = 40; // VPAD(4)*2 + ICON_HEIGHT(32)
 36
 37LLToastPanel::LLToastPanel(const LLNotificationPtr& notification)
 38{
 39	mNotification = notification;
 40}
 41
 42LLToastPanel::~LLToastPanel() 
 43{
 44}
 45
 46//virtual
 47std::string LLToastPanel::getTitle()
 48{
 49	// *TODO: create Title and localize it. If it will be required.
 50	return mNotification->getMessage();
 51}
 52
 53//virtual
 54const LLUUID& LLToastPanel::getID()
 55{
 56	return mNotification->id();
 57}
 58
 59//snap to the message height if it is visible
 60void LLToastPanel::snapToMessageHeight(LLTextBase* message, S32 maxLineCount)
 61{
 62	if(!message)
 63	{
 64		return;
 65	}
 66
 67	//Add message height if it is visible
 68	if (message->getVisible())
 69	{
 70		S32 heightDelta = 0;
 71		S32 maxTextHeight = (S32)(message->getDefaultFont()->getLineHeight() * maxLineCount);
 72
 73		LLRect messageRect = message->getRect();
 74		S32 oldTextHeight = messageRect.getHeight();
 75
 76		//Knowing the height is set to max allowed, getTextPixelHeight returns needed text height
 77		//Perhaps we need to pass maxLineCount as parameter to getTextPixelHeight to avoid previous reshape.
 78		S32 requiredTextHeight = message->getTextBoundingRect().getHeight();
 79		S32 newTextHeight = llmin(requiredTextHeight, maxTextHeight);
 80
 81		//Calculate last delta height deducting previous heightDelta 
 82		heightDelta = newTextHeight - oldTextHeight - heightDelta;
 83
 84		//reshape the panel with new height
 85		reshape( getRect().getWidth(), llmax(getRect().getHeight() + heightDelta, MIN_PANEL_HEIGHT));
 86	}
 87}
 88
 89// static
 90LLToastPanel* LLToastPanel::buidPanelFromNotification(
 91		const LLNotificationPtr& notification)
 92{
 93	LLToastPanel* res = NULL;
 94
 95	//process tip toast panels
 96	if ("notifytip" == notification->getType())
 97	{
 98		// if it is online/offline notification
 99		if ("FriendOffline" == notification->getName() || "FriendOnline" == notification->getName())
100		{
101			res = new LLPanelOnlineStatus(notification);
102		}
103		// in all other case we use generic tip panel
104		else
105		{
106			res = new LLPanelGenericTip(notification);
107		}
108	}
109	/*
110	 else if(...)
111	 create all other specific non-public toast panel
112	 */
113
114	return res;
115}