PageRenderTime 32ms CodeModel.GetById 9ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llbadgeowner.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 131 lines | 75 code | 23 blank | 33 comment | 12 complexity | ca5ea4ca4d59591f9113611e43b59bca MD5 | raw file
  1/** 
  2 * @file llbadgeowner.cpp
  3 * @brief Class to manage badges attached to a UI control
  4 *
  5 * $LicenseInfo:firstyear=2001&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 "linden_common.h"
 28
 29#include "llbadgeholder.h"
 30#include "llbadgeowner.h"
 31#include "llpanel.h"
 32
 33//
 34// Classes
 35//
 36
 37LLBadgeOwner::LLBadgeOwner(LLHandle< LLView > viewHandle)
 38	: mBadge(NULL)
 39	, mBadgeOwnerView(viewHandle)
 40{
 41}
 42
 43void LLBadgeOwner::initBadgeParams(const LLBadge::Params& p)
 44{
 45	if (!p.equals(LLUICtrlFactory::getDefaultParams<LLBadge>()))
 46	{
 47		mBadge = createBadge(p);
 48	}
 49}
 50
 51void LLBadgeOwner::setBadgeLabel(const LLStringExplicit& label)
 52{
 53	if (mBadge == NULL)
 54	{
 55		mBadge = createBadge(LLUICtrlFactory::getDefaultParams<LLBadge>());
 56
 57		addBadgeToParentPanel();
 58	}
 59
 60	if (mBadge)
 61	{
 62		mBadge->setLabel(label);
 63
 64		//
 65		// Push the badge to the front so it renders on top
 66		//
 67
 68		LLView * parent = mBadge->getParent();
 69
 70		if (parent)
 71		{
 72			parent->sendChildToFront(mBadge);
 73		}
 74	}
 75}
 76
 77void LLBadgeOwner::setBadgeVisibility(bool visible)
 78{
 79	if (mBadge)
 80	{
 81		mBadge->setVisible(visible);
 82	}
 83}
 84
 85bool LLBadgeOwner::addBadgeToParentPanel()
 86{
 87	bool badge_added = false;
 88
 89	LLView * owner_view = mBadgeOwnerView.get();
 90	
 91	if (mBadge && owner_view)
 92	{
 93		LLBadgeHolder * badge_holder = NULL;
 94
 95		// Find the appropriate holder for the badge
 96		LLView * parent = owner_view->getParent();
 97
 98		while (parent)
 99		{
100			LLBadgeHolder * badge_holder_panel = dynamic_cast<LLBadgeHolder *>(parent);
101
102			if (badge_holder_panel && badge_holder_panel->acceptsBadge())
103			{
104				badge_holder = badge_holder_panel;
105				break;
106			}
107
108			parent = parent->getParent();
109		}
110
111		if (badge_holder)
112		{
113			badge_added = badge_holder->addBadge(mBadge);
114		}
115		else
116		{
117			// Badge parent is fallback badge owner if no valid holder exists in the hierarchy
118			badge_added = mBadge->addToView(owner_view);
119		}
120	}
121
122	return badge_added;
123}
124
125LLBadge* LLBadgeOwner::createBadge(const LLBadge::Params& p)
126{
127	LLBadge::Params badge_params(p);
128	badge_params.owner = mBadgeOwnerView;
129
130	return LLUICtrlFactory::create<LLBadge>(badge_params);
131}