PageRenderTime 58ms CodeModel.GetById 26ms 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
Possible License(s): LGPL-2.1
  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. #include "linden_common.h"
  27. #include "llbadgeholder.h"
  28. #include "llbadgeowner.h"
  29. #include "llpanel.h"
  30. //
  31. // Classes
  32. //
  33. LLBadgeOwner::LLBadgeOwner(LLHandle< LLView > viewHandle)
  34. : mBadge(NULL)
  35. , mBadgeOwnerView(viewHandle)
  36. {
  37. }
  38. void LLBadgeOwner::initBadgeParams(const LLBadge::Params& p)
  39. {
  40. if (!p.equals(LLUICtrlFactory::getDefaultParams<LLBadge>()))
  41. {
  42. mBadge = createBadge(p);
  43. }
  44. }
  45. void LLBadgeOwner::setBadgeLabel(const LLStringExplicit& label)
  46. {
  47. if (mBadge == NULL)
  48. {
  49. mBadge = createBadge(LLUICtrlFactory::getDefaultParams<LLBadge>());
  50. addBadgeToParentPanel();
  51. }
  52. if (mBadge)
  53. {
  54. mBadge->setLabel(label);
  55. //
  56. // Push the badge to the front so it renders on top
  57. //
  58. LLView * parent = mBadge->getParent();
  59. if (parent)
  60. {
  61. parent->sendChildToFront(mBadge);
  62. }
  63. }
  64. }
  65. void LLBadgeOwner::setBadgeVisibility(bool visible)
  66. {
  67. if (mBadge)
  68. {
  69. mBadge->setVisible(visible);
  70. }
  71. }
  72. bool LLBadgeOwner::addBadgeToParentPanel()
  73. {
  74. bool badge_added = false;
  75. LLView * owner_view = mBadgeOwnerView.get();
  76. if (mBadge && owner_view)
  77. {
  78. LLBadgeHolder * badge_holder = NULL;
  79. // Find the appropriate holder for the badge
  80. LLView * parent = owner_view->getParent();
  81. while (parent)
  82. {
  83. LLBadgeHolder * badge_holder_panel = dynamic_cast<LLBadgeHolder *>(parent);
  84. if (badge_holder_panel && badge_holder_panel->acceptsBadge())
  85. {
  86. badge_holder = badge_holder_panel;
  87. break;
  88. }
  89. parent = parent->getParent();
  90. }
  91. if (badge_holder)
  92. {
  93. badge_added = badge_holder->addBadge(mBadge);
  94. }
  95. else
  96. {
  97. // Badge parent is fallback badge owner if no valid holder exists in the hierarchy
  98. badge_added = mBadge->addToView(owner_view);
  99. }
  100. }
  101. return badge_added;
  102. }
  103. LLBadge* LLBadgeOwner::createBadge(const LLBadge::Params& p)
  104. {
  105. LLBadge::Params badge_params(p);
  106. badge_params.owner = mBadgeOwnerView;
  107. return LLUICtrlFactory::create<LLBadge>(badge_params);
  108. }