PageRenderTime 29ms CodeModel.GetById 15ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #include "llviewerprecompiledheaders.h"
  27. #include "llpanelgenerictip.h"
  28. #include "llpanelonlinestatus.h"
  29. #include "llnotifications.h"
  30. #include "lltoastpanel.h"
  31. //static
  32. const S32 LLToastPanel::MIN_PANEL_HEIGHT = 40; // VPAD(4)*2 + ICON_HEIGHT(32)
  33. LLToastPanel::LLToastPanel(const LLNotificationPtr& notification)
  34. {
  35. mNotification = notification;
  36. }
  37. LLToastPanel::~LLToastPanel()
  38. {
  39. }
  40. //virtual
  41. std::string LLToastPanel::getTitle()
  42. {
  43. // *TODO: create Title and localize it. If it will be required.
  44. return mNotification->getMessage();
  45. }
  46. //virtual
  47. const LLUUID& LLToastPanel::getID()
  48. {
  49. return mNotification->id();
  50. }
  51. //snap to the message height if it is visible
  52. void LLToastPanel::snapToMessageHeight(LLTextBase* message, S32 maxLineCount)
  53. {
  54. if(!message)
  55. {
  56. return;
  57. }
  58. //Add message height if it is visible
  59. if (message->getVisible())
  60. {
  61. S32 heightDelta = 0;
  62. S32 maxTextHeight = (S32)(message->getDefaultFont()->getLineHeight() * maxLineCount);
  63. LLRect messageRect = message->getRect();
  64. S32 oldTextHeight = messageRect.getHeight();
  65. //Knowing the height is set to max allowed, getTextPixelHeight returns needed text height
  66. //Perhaps we need to pass maxLineCount as parameter to getTextPixelHeight to avoid previous reshape.
  67. S32 requiredTextHeight = message->getTextBoundingRect().getHeight();
  68. S32 newTextHeight = llmin(requiredTextHeight, maxTextHeight);
  69. //Calculate last delta height deducting previous heightDelta
  70. heightDelta = newTextHeight - oldTextHeight - heightDelta;
  71. //reshape the panel with new height
  72. reshape( getRect().getWidth(), llmax(getRect().getHeight() + heightDelta, MIN_PANEL_HEIGHT));
  73. }
  74. }
  75. // static
  76. LLToastPanel* LLToastPanel::buidPanelFromNotification(
  77. const LLNotificationPtr& notification)
  78. {
  79. LLToastPanel* res = NULL;
  80. //process tip toast panels
  81. if ("notifytip" == notification->getType())
  82. {
  83. // if it is online/offline notification
  84. if ("FriendOffline" == notification->getName() || "FriendOnline" == notification->getName())
  85. {
  86. res = new LLPanelOnlineStatus(notification);
  87. }
  88. // in all other case we use generic tip panel
  89. else
  90. {
  91. res = new LLPanelGenericTip(notification);
  92. }
  93. }
  94. /*
  95. else if(...)
  96. create all other specific non-public toast panel
  97. */
  98. return res;
  99. }